界面层代码:
private void btnAdd_Click(object sender, EventArgs e)
{
//创建AccountBook实体
AccountBook item = new AccountBook();
item.Id = -1;
item.Name = this.txtName.Text;
item.BillId = this.txtBill.Text;
item.Buyer = this.txtBuyer.Text;
item.Number = Convert.ToInt32(this.txtNum.Text);
item.Price = Convert.ToSingle(this.txtPrice.Text);
item.ShopName = this.txtShop.Text;
item.Message = this.txtMessage.Text;
item.BuyDate = this.timeBuy.Value;
item.Type = this.cbClass.SelectedValue.ToString();
//创建业务对象,添加实体
AccountBookManager mb = new AccountBookManager();
mb.AddAccountBook(item);
}
业务层代码:
public class AccountBookManager
{
//添加到数据库
public bool AddAccountBook(AccountBook item)
{
//创建数据层操作对象,并添加数据到数据库
AccountBookData accountData = new AccountBookData();
return accountData.Insert(item);
数据层代码:
public bool Insert(AccountBook t)
{
//构造插入数据的SQL语句
string sql = string.Format("INSERT INTO Accountbook VALUES('{0}','{1}',{2},{3},'{4}','{5}','{6}','{7}','{8}')",
t.Name,t.Type,t.Number,t.Price, t.BillId,t.ShopName, t.Buyer, t.BuyDate, t.Message
);
SqlCommand cmd = new SqlCommand(sql, Connection);
try
{
//插入数据库
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
return false;
}
finally
{
cmd.Connection.Close();
}
return true;
}
数据传输通道
public class AccountBook
{
private int id;
private string name;
private string type;
private int number;
private float price;
private string billid;
private string shopname;
private string buyer;
private DateTime buydate;
private string message;
public int Id
{
get { return id; }
set { id = value;}
}
public string Name
{
get { return name; }
set { name = value;}
}
public string Type
{
get { return type; }
set { type = value;}
}
public int Number
{
get { return number; }
set { number = value;}
}
public float Price
{
get { return price; }
set { price = value;}
}
public string BillId
{
get { return billid; }
set { billid = value;}
}
public string ShopName
{
get { return shopname; }
set { shopname = value;}
}
public string Buyer
{
get { return buyer; }
set { buyer = value;}
}
public DateTime BuyDate
{
get { return buydate; }
set { buydate = value;}
}
public string Message
{
get { return message; }
set { message = value;}
}
}请帮忙看哈,谢谢。
private void btnAdd_Click(object sender, EventArgs e)
{
//创建AccountBook实体
AccountBook item = new AccountBook();
item.Id = -1;
item.Name = this.txtName.Text;
item.BillId = this.txtBill.Text;
item.Buyer = this.txtBuyer.Text;
item.Number = Convert.ToInt32(this.txtNum.Text);
item.Price = Convert.ToSingle(this.txtPrice.Text);
item.ShopName = this.txtShop.Text;
item.Message = this.txtMessage.Text;
item.BuyDate = this.timeBuy.Value;
item.Type = this.cbClass.SelectedValue.ToString();
//创建业务对象,添加实体
AccountBookManager mb = new AccountBookManager();
mb.AddAccountBook(item);
}
业务层代码:
public class AccountBookManager
{
//添加到数据库
public bool AddAccountBook(AccountBook item)
{
//创建数据层操作对象,并添加数据到数据库
AccountBookData accountData = new AccountBookData();
return accountData.Insert(item);
数据层代码:
public bool Insert(AccountBook t)
{
//构造插入数据的SQL语句
string sql = string.Format("INSERT INTO Accountbook VALUES('{0}','{1}',{2},{3},'{4}','{5}','{6}','{7}','{8}')",
t.Name,t.Type,t.Number,t.Price, t.BillId,t.ShopName, t.Buyer, t.BuyDate, t.Message
);
SqlCommand cmd = new SqlCommand(sql, Connection);
try
{
//插入数据库
cmd.Connection.Open();
cmd.ExecuteNonQuery();
}
catch (SqlException e)
{
Console.WriteLine(e.Message);
return false;
}
finally
{
cmd.Connection.Close();
}
return true;
}
数据传输通道
public class AccountBook
{
private int id;
private string name;
private string type;
private int number;
private float price;
private string billid;
private string shopname;
private string buyer;
private DateTime buydate;
private string message;
public int Id
{
get { return id; }
set { id = value;}
}
public string Name
{
get { return name; }
set { name = value;}
}
public string Type
{
get { return type; }
set { type = value;}
}
public int Number
{
get { return number; }
set { number = value;}
}
public float Price
{
get { return price; }
set { price = value;}
}
public string BillId
{
get { return billid; }
set { billid = value;}
}
public string ShopName
{
get { return shopname; }
set { shopname = value;}
}
public string Buyer
{
get { return buyer; }
set { buyer = value;}
}
public DateTime BuyDate
{
get { return buydate; }
set { buydate = value;}
}
public string Message
{
get { return message; }
set { message = value;}
}
}请帮忙看哈,谢谢。
解决方案 »
- 问一个XML的问题
- 深复制咋那别扭呢
- DataGridView如何做到左键或者右键只要是单击(双击)DataGridView以外区域就取消行的选中(设置为未选中状态)
- 谁来看一下我这个DES加解密有什么问题么。解密出来不正确。谢谢了!!
- if判断问题
- 怎样用BAT得到周一至周日之间的所有文件夹,并删除这些文件夹下面jpg文件
- 怎么让他翻页的时候第一行不是文本框的状态??
- 想学C#只学了语法,想从案例着手,但发现知识不够
- 请大家帮忙给出几个API的参数说明
- 怎样让一个程序在后台运行
- 为什么我用slider的valuechanged事件给SpeechSynthesizer.Volume赋值后运行拖动根本音量没有改变……
- 如何动态的给datagridview的combobox列添加数据?
{}会不管,因此要重新添加click事件,重新添加后会变成这样private void btnAdd_Click_1(object sender, EventArgs e){}。我至今也不明白是什么原因,只有重新添加click事件
{
//创建数据层操作对象,并添加数据到数据库
AccountBookData accountData = new AccountBookData();
return accountData.Insert(item);
数据层代码:
public bool Insert(AccountBook t)中间少东西了 ,,,AccountBookData 的定义呢