public void DataBind()//定义一个函数用于绑定数据到DataGridView { BLL.JHGoodsInfo bll = new BLL.JHGoodsInfo(); DataSet ds = new DataSet(); ds = bll.GetList(); //执行SQL语句,将结果存在ds中 dataGridView1.DataSource = ds.Tables[0]; //将ds中的表作为DataGridView的数据源 }
private void btnSelect_Click(object sender, EventArgs e) { string strSelect = this.cboQueryRequire.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.JHGoodsInfo bll = new BLL.JHGoodsInfo(); //实例化BLL层 DataSet ds = new DataSet(); ds = bll.GetList(strWhere); //执行带参数SQL语句,将结果存在ds中 dataGridView1.DataSource = ds.Tables[0]; //将ds中的表作为DataGridView的数据源 }
private void toolSave_Click(object sender, EventArgs e) { if (txtGoodsID.Text == "" || txtGoodsName.Text == "" || cboComName.Text == "" || cboDepotName.Text == "") { MessageBox.Show("请将信息添加完整!"); return; } Model.JHGoodsInfo model = new Model.JHGoodsInfo();//实例化model层 model.GoodsID = txtGoodsID.Text.Trim(); model.EmployeeID = cboEmployeeID.Text.Trim(); model.CompanyName = cboComName.Text.Trim(); model.DepotName = cboDepotName.Text.Trim(); model.GoodsName = txtGoodsName.Text; model.GoodsNum = int.Parse(numGoodsNum.Value.ToString()); model.GoodsUnit = cmbGoodsUnit.Text.Trim(); model.GoodsJHPrice = float.Parse(txtGoodsJHPrice.Text.Trim()); model.GoodsSellPrice = float.Parse(txtSellGoodsPrice.Text.Trim()); model.GoodsNeedPay = float.Parse(txtGoodsNeedPrice.Text.Trim()); model.GoodsHasPay = float.Parse(txtGoodsHasPay.Text.Trim()); model.GoodsRemark = txtRemarks.Text; model.GoodsTime = DateTime.Parse(dateTimePicker1.Text); BLL.JHGoodsInfo bll = new BLL.JHGoodsInfo();//实例化BLL层 Model.KCInfo kcInfo = new Model.KCInfo(); kcInfo.GoodsID = txtGoodsID.Text.Trim(); kcInfo.GoodsName = txtGoodsName.Text; kcInfo.CompanyName = cboComName.Text.Trim(); kcInfo.DepotName = cboDepotName.Text.Trim(); kcInfo.GoodsNum = int.Parse(numGoodsNum.Value.ToString()); BLL.KCInfo bllkcInfo = new BLL.KCInfo();//实例化BLL层 switch (flag) { case 0: { } break; case 1: { if (bll.Add(model)) //将员工信息添加到数据库中,根据返回值判断是否添加成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } if (!bllkcInfo.Add(kcInfo)) { MessageBox.Show("未能够把数据添加到仓库中"); } } break; case 2: { if (bll.Update(model)) //根据返回布尔值判断是否修改数据成功 { DataBind(); //窗体登录时绑定数据到DataGridView ControlStatus(); } if (!bllkcInfo.Update(kcInfo)) { MessageBox.Show("未能够把数据修改到仓库中"); } } break; } }