public void DataBind()//定义一个函数用于绑定数据到DataGridView { BLL.KCInfo bll = new BLL.KCInfo(); DataSet ds = new DataSet(); ds = bll.GetList(); //执行SQL语句,将结果存在ds中 dataGridView1.DataSource = ds.Tables[0]; //将ds中的表作为DataGridView的数据源 }
private void toolSave_Click(object sender, EventArgs e) { if (txtThGoodsID.Text == "" || txtSellID.Text == "" || txtGoodsID.Text == "" || txtSellID.Text == "" || txtThGoodsName.Text == "" || numSellGoodsNum.Text == "" || txtThHasPay.Text == "" || txtThNeedPay.Text == "" || cboEmpID.Text == "") { MessageBox.Show("请将信息添加完整!"); return; } Model.THGoodsInfo model = new Model.THGoodsInfo();//实例化model层 model.THGoodsID = txtThGoodsID.Text.Trim(); model.KCID = ""; model.GoodsID = txtGoodsID.Text.Trim(); model.SellID = txtSellID.Text.Trim(); model.EmploayeeID = cboEmpID.Text.Trim(); model.THGoodsName = txtThGoodsName.Text.Trim(); model.THGoodsNum = int.Parse(numSellGoodsNum.Text.Trim()); model.THGoodsTime = DateTime.Parse(daThGoodsTime.Value.ToString()); model.THGoodsPrice = float.Parse(txtThGoodsPrice.Text.Trim()); model.THNeedPay = float.Parse(txtThNeedPay.Text.Trim()); model.THHasPay = float.Parse(txtThHasPay.Text.Trim()); model.THGoodsResult = txtThGoodsResult.Text; BLL.THGoodsInfo bll = new BLL.THGoodsInfo();//实例化BLL层 Model.KCInfo kcInfo = new Model.KCInfo(); kcInfo.GoodsID = txtGoodsID.Text.Trim(); kcInfo.GoodsName = txtThGoodsName.Text.Trim(); kcInfo.DepotName = txtDepotName.Text.Trim(); kcInfo.CompanyName = txtCompanyName.Text.Trim(); string strWhere = " GoodsID = '" + kcInfo.GoodsID + "'"; BLL.KCInfo bllkcInfo = new BLL.KCInfo();//实例化BLL层 DataSet ds = new DataSet(); ds = bllkcInfo.GetList(strWhere); int sum = int.Parse(ds.Tables[0].Rows[0]["商品数量"].ToString()); kcInfo.GoodsNum = sum + int.Parse(numSellGoodsNum.Value.ToString()); switch (flag) { case 0: { } break; case 1: { if (bll.Add(model)) //将员工信息添加到数据库中,根据返回值判断是否添加成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } if (!bllkcInfo.Update(kcInfo)) { MessageBox.Show("未能够把数据添加到仓库中"); } } break; } }
private void btnSelect_Click(object sender, EventArgs e) { string strSelect = this.cboQuery.Text.Trim(); if (strSelect == "") { MessageBox.Show("请选择查询条件!"); return; } if (this.txtContent.Text == "") { MessageBox.Show("输入查询条件!"); return; } //商品编号 //商品名称 string strWhere = "1=1"; string goodsID = txtContent.Text; string goodsName = txtContent.Text; switch (strSelect) { case "商品编号": { strWhere = strWhere + " and GoodsID like '%" + goodsID + "%'"; } break; case "商品名称": { strWhere = strWhere + " and GoodsName like '%" + goodsName + "%'"; } break; } BLL.KCInfo bll = new BLL.KCInfo(); //实例化BLL层 DataSet ds = new DataSet(); ds = bll.GetList(strWhere); //执行带参数SQL语句,将结果存在ds中 dataGridView1.DataSource = ds.Tables[0]; //将ds中的表作为DataGridView的数据源 }