第8章 项目案例 超市商品管理

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1、当表名与关键字冲突时需要使用中括号括引来

string sql = string.Format("Select count(*) from [User] where UserName='{0}' and PassWord='{1}'", txtUserName.Text.Trim(), txtPwd.Text.Trim());

2、新增商品信息事件

private void tsmiAdd_Click(object sender, EventArgs e)

{

FrmEditComodity frmEditCommodity = new FrmEditComodity();

frmEditCommodity.ShowDialog();

FillTable();

}

3、是否是特价

private void chkIsDIscount_CheckedChanged(object sender, EventArgs e)

{

if (chkIsDIscount.Checked)

{

numReducedPrice.Enabled = true;

}

else

{

numReducedPrice.Enabled = false;

numReducedPrice.Value = numPrice.Value;

}

}

4、显示商品信息

private void ShowCommodity()

{

DBHelper dbh = new DBHelper();

string sql = string.Format("select CommodityName,SortName,CommodityPrice,IsDiscount,reducedPrice from Commodity as C inner join CommoditySort as S on C.SortId=S.SortId where commodityId={0}",modityId);

dbh.OpenConnection();

SqlCommand comm = new SqlCommand(sql,dbh.Conn);

SqlDataReader reader = comm.ExecuteReader();

while(reader.Read())

{

this.txtName.Text = reader["CommodityName"].ToString();

this.cboSort.DisplayMember = reader["SortName"].ToString();

this.numPrice.Value = Convert.ToDecimal(reader["CommodityPrice"]);

this.chkIsDIscount.Checked = Convert.ToBoolean(reader["IsDiscount"]);

this.numReducedPrice.Value = Convert.ToDecimal(reader["ReducedPrice"]);

}

}

5、新增商品信息方法

private void InsertCommodity()

{

DBHelper dbhelper = new DBHelper();

StringBuilder sb = new StringBuilder();

sb.AppendFormat("insert into Commodity values ('{0}',{1},{2},{3},{4})",this.txtName.Text.Trim(), Convert.ToInt32(cboSort.SelectedValue),numPrice.Value,this.chkIsDIscount.Checked ? 1:0,numReducedPrice.Value);

SqlCommand comm = new SqlCommand(sb.ToString(),dbhelper.Conn);

dbhelper.OpenConnection();

int result = comm.ExecuteNonQuery();

if (result == 1)

{

MessageBox.Show("增加信息成功");

this.Close();

}

else

{

MessageBox.Show("增加信息失败");

}

}

相关文档
最新文档