private void btnSearch_Click(object sender, EventArgs e) { if (txtCode.Text.Trim() == "") { MessageBoxEx.Show("请输入商品编码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Dong.BLL.GoodsInfo bGoods = new Dong.BLL.GoodsInfo(); Dong.Model.GoodsInfo mGoods = new Dong.Model.GoodsInfo(); mGoods = bGoods.GetModel(txtCode.Text.Trim()); if (mGoods != null) { txtCategory.Text = mGoods.CategoryName; txtFactory.Text = mGoods.Factory; txtName.Text = mGoods.GoodsName; txtKC.Text = mGoods.Counts.ToString(); txtSJ.Text = mGoods.Price0.ToString(); txtJJ.Text = mGoods.Price1.ToString(); txtCB.Text = mGoods.Price2.ToString(); txtSuppier.Text = mGoods.SupplierName; txtUnit.Text = mGoods.UnitName; } else { MessageBoxEx.Show("对不起,该商品不存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void frmEditGoods_Load(object sender, EventArgs e) { Dong.BLL.Category catebll = new Dong.BLL.Category(); ddlCategory.DataSource = catebll.GetAllList().Tables[0]; ddlCategory.DisplayMember = "Name"; ddlCategory.ValueMember = "Id"; //绑定单位 Dong.BLL.Unit unitbll = new Dong.BLL.Unit(); ddlUnit.DataSource = unitbll.GetAllList().Tables[0]; ddlUnit.DisplayMember = "Name"; ddlUnit.ValueMember = "Id"; //绑定供应商 Dong.BLL.Supplier supplierbll = new Dong.BLL.Supplier(); ddlSupper.DataSource = supplierbll.GetAllList().Tables[0]; ddlSupper.DisplayMember = "Name"; ddlSupper.ValueMember = "Id"; Dong.BLL.GoodsInfo bll = new Dong.BLL.GoodsInfo(); Dong.Model.GoodsInfo model = new Dong.Model.GoodsInfo(); model = bll.GetModelById(int.Parse(this.Tag.ToString())); if (model != null) { tbCode.Text = model.Code; tbName.Text = model.GoodsName; tbFactory.Text = model.Factory; ddlCategory.SelectedValue = model.Category; ddlUnit.SelectedValue = model.Unit; ddlSupper.SelectedValue = model.Supplier; txtPrice0.Text = model.Price0 == null ? "" : model.Price0.ToString(); txtPrice1.Text = model.Price1 == null ? "" : model.Price1.ToString(); txtPrice2.Text = model.Price2 == null ? "" : model.Price2.ToString(); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(Dong.Model.GoodsInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into GoodsInfo("); strSql.Append("Code,GoodName,Category,CategoryName,Unit,UnitName,Factory,Supplier,SupplierName,Price0,Price1,Price2,Counts)"); strSql.Append(" values ("); strSql.Append("@Code,@GoodName,@Category,@CategoryName,@Unit,@UnitName,@Factory,@Supplier,@SupplierName,@Price0,@Price1,@Price2,@Counts)"); OleDbParameter[] parameters = { new OleDbParameter("@Code", OleDbType.VarChar, 50), new OleDbParameter("@GoodName", OleDbType.VarChar, 50), new OleDbParameter("@Category", OleDbType.Integer, 4), new OleDbParameter("@CategoryName", OleDbType.VarChar, 50), new OleDbParameter("@Unit", OleDbType.Integer, 4), new OleDbParameter("@UnitName", OleDbType.VarChar, 50), new OleDbParameter("@Factory", OleDbType.VarChar, 50), new OleDbParameter("@Supplier", OleDbType.Integer, 4), new OleDbParameter("@SupplierName", OleDbType.VarChar, 50), new OleDbParameter("@Price0", OleDbType.Double), new OleDbParameter("@Price1", OleDbType.Double), new OleDbParameter("@Price2", OleDbType.Double), new OleDbParameter("@Counts", OleDbType.Integer, 4) }; parameters[0].Value = model.Code; parameters[1].Value = model.GoodsName; parameters[2].Value = model.Category; parameters[3].Value = model.CategoryName; parameters[4].Value = model.Unit; parameters[5].Value = model.UnitName; parameters[6].Value = model.Factory; parameters[7].Value = model.Supplier; parameters[8].Value = model.SupplierName; parameters[9].Value = model.Price0; parameters[10].Value = model.Price1; parameters[11].Value = model.Price2; parameters[12].Value = model.Counts; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 进货单保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSave_Click(object sender, EventArgs e) { Dong.BLL.InGoods bInGoods = new Dong.BLL.InGoods(); Dong.Model.InGoods mInGoods = new Dong.Model.InGoods(); Dong.BLL.GoodsInfo bGoodsInfo = new Dong.BLL.GoodsInfo(); Dong.Model.GoodsInfo mGoodsInfo = new Dong.Model.GoodsInfo(); for (int i = 0; i < dGV.Rows.Count; i++) { //添加进货信息 mGoodsInfo = bGoodsInfo.GetModel(dGV.Rows[i].Cells[1].Value.ToString()); mInGoods.PCode = lblCode.Text; mInGoods.GoodsCode = dGV.Rows[i].Cells[1].Value.ToString(); mInGoods.Price = double.Parse(dGV.Rows[i].Cells[3].Value.ToString()); mInGoods.Counts = int.Parse(dGV.Rows[i].Cells[4].Value.ToString()); mInGoods.IDate = DateTime.Now.Date; mInGoods.Oper = txtOper.Text; mInGoods.Supplier = mGoodsInfo.Supplier; mInGoods.Remark = ""; bInGoods.Add(mInGoods); //修改商品信息 //进货价格 double oldPrice1 = (double)mGoodsInfo.Price1; mGoodsInfo.Price1 = double.Parse(dGV.Rows[i].Cells[3].Value.ToString()); //数量 mGoodsInfo.Counts = mGoodsInfo.Counts + int.Parse(dGV.Rows[i].Cells[4].Value.ToString()); //成本价 int totalCount = (int)mGoodsInfo.Counts + int.Parse(dGV.Rows[i].Cells[4].Value.ToString()); double totalPrice = (oldPrice1 * (int)mGoodsInfo.Counts) + (double.Parse(dGV.Rows[i].Cells[3].Value.ToString()) * int.Parse(dGV.Rows[i].Cells[4].Value.ToString())); double cbPrice = totalPrice / totalCount; mGoodsInfo.Price2 = cbPrice; bGoodsInfo.Update(mGoodsInfo); } frmInput frm = (frmInput)this.Owner; frm.refreshData(); this.Close(); }
protected void addGoods() { Dong.BLL.GoodsInfo bGoods = new Dong.BLL.GoodsInfo(); Dong.Model.GoodsInfo mGoods = new Dong.Model.GoodsInfo(); mGoods = bGoods.GetModel(tbCode.Text.Trim()); if (mGoods != null) { if (mGoods.Counts > 0) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(dGV); row.Cells[0].Value = mGoods.Code; row.Cells[1].Value = mGoods.GoodsName; row.Cells[2].Value = string.Format("{0:F2}", mGoods.Price0); row.Cells[3].Value = "1"; row.Cells[4].Value = string.Format("{0:F2}", (mGoods.Price0 * int.Parse(row.Cells[3].Value.ToString()))); dGV.Rows.Add(row); row.Selected = true; tbCode.Text = ""; //计算总钱数 sumCash(); lblGoodsName.Text = mGoods.GoodsName; lblStock.Text = mGoods.Counts.ToString(); } else { MessageBox.Show("对不起,此商品缺货!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } else { MessageBox.Show("对不起,没有此商品!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void btnSearch_Click(object sender, EventArgs e) { string code = txtCode.Text.Trim(); Dong.Model.GoodsInfo model = goodbll.GetModel(code); if (model == null) { buttonX2_Click(null, null); } else { txtCode.Text = model.Code; txtName.Text = model.GoodsName; txtFactory.Text = model.Factory; txtCategory.Text = model.CategoryName; txtUnit.Text = model.UnitName; txtSuppier.Text = model.SupplierName; txtKC.Text = model.Counts == null ? "" : model.Counts.ToString(); txtSJ.Text = model.Price0 == null ? "" : model.Price0.ToString(); txtJJ.Text = model.Price1 == null ? "" : model.Price1.ToString(); txtCB.Text = model.Price2 == null ? "" : model.Price2.ToString(); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Dong.Model.GoodsInfo GetModelById(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select Id,Code,GoodName,Category,CategoryName,Unit,UnitName,Factory,Supplier,SupplierName,Price0,Price1,Price2,Counts from GoodsInfo "); strSql.Append(" where Id=@Id"); OleDbParameter[] parameters = { new OleDbParameter("@Id", OleDbType.Integer, 4) }; parameters[0].Value = id; Dong.Model.GoodsInfo model = new Dong.Model.GoodsInfo(); DataSet ds = DbHelperOleDb.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void btnSave_Click(object sender, EventArgs e) { //验证商品编号 if (tbCode.Text.Trim() == "") { MessageBoxEx.Show("请输入商品编码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); tbCode.Focus(); return; } //验证商品名称 if (tbName.Text.Trim() == "") { MessageBoxEx.Show("请输入商品名称!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); tbName.Focus(); return; } if (tbFactory.Text.Trim() == "") { MessageBoxEx.Show("请输入商品生产厂家!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); tbFactory.Focus(); return; } if (txtPrice0.Text.Trim() == "") { MessageBoxEx.Show("请输入零售价!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice0.Focus(); return; } double price0; if (!double.TryParse(txtPrice0.Text, out price0)) { MessageBoxEx.Show("零售价必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice0.Focus(); return; } if (txtPrice1.Text.Trim() == "") { MessageBoxEx.Show("请输入进货价!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice1.Focus(); return; } double price1; if (!double.TryParse(txtPrice1.Text, out price1)) { MessageBoxEx.Show("进货价必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice1.Focus(); return; } if (txtPrice2.Text.Trim() == "") { MessageBoxEx.Show("请输入成本价!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice2.Focus(); return; } double price2; if (!double.TryParse(txtPrice2.Text, out price2)) { MessageBoxEx.Show("成本价必须为数字!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPrice2.Focus(); return; } Dong.BLL.GoodsInfo bll = new Dong.BLL.GoodsInfo(); Dong.Model.GoodsInfo model = new Dong.Model.GoodsInfo(); model.Code = tbCode.Text; model.GoodsName = tbName.Text; if (ddlCategory.SelectedValue != null && !string.IsNullOrEmpty(ddlCategory.SelectedValue.ToString())) { model.Category = Int32.Parse(ddlCategory.SelectedValue.ToString()); model.CategoryName = ddlCategory.Text; } else { model.CategoryName = ""; } if (ddlUnit.SelectedValue != null && !string.IsNullOrEmpty(ddlUnit.SelectedValue.ToString())) { model.Unit = Int32.Parse(ddlUnit.SelectedValue.ToString()); model.UnitName = ddlUnit.Text; } else { model.UnitName = ""; } if (ddlSupper.SelectedValue != null && !string.IsNullOrEmpty(ddlSupper.SelectedValue.ToString())) { model.Supplier = Int32.Parse(ddlSupper.SelectedValue.ToString()); model.SupplierName = ddlSupper.Text; } else { model.SupplierName = ""; } model.Factory = tbFactory.Text; model.Counts = 0; model.Price0 = price0; model.Price1 = price1; model.Price2 = price2; if (bll.Add(model)) { MessageBoxEx.Show("添加成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); frmGoods frm = (frmGoods)this.Owner; frm.refreshData(); this.Close(); } else { MessageBoxEx.Show("保存失败!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// 得到一个对象实体 /// </summary> public Dong.Model.GoodsInfo DataRowToModel(DataRow row) { Dong.Model.GoodsInfo model = new Dong.Model.GoodsInfo(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Code"] != null) { model.Code = row["Code"].ToString(); } if (row["GoodName"] != null) { model.GoodsName = row["GoodName"].ToString(); } if (row["Category"] != null && row["Category"].ToString() != "") { model.Category = int.Parse(row["Category"].ToString()); } if (row["CategoryName"] != null) { model.CategoryName = row["CategoryName"].ToString(); } if (row["Unit"] != null && row["Unit"].ToString() != "") { model.Unit = int.Parse(row["Unit"].ToString()); } if (row["UnitName"] != null) { model.UnitName = row["UnitName"].ToString(); } if (row["Factory"] != null) { model.Factory = row["Factory"].ToString(); } if (row["Supplier"] != null && row["Supplier"].ToString() != "") { model.Supplier = int.Parse(row["Supplier"].ToString()); } if (row["SupplierName"] != null) { model.SupplierName = row["SupplierName"].ToString(); } if (row["Price0"] != null && row["Price0"].ToString() != "") { model.Price0 = double.Parse(row["Price0"].ToString()); } if (row["Price1"] != null && row["Price1"].ToString() != "") { model.Price1 = double.Parse(row["Price1"].ToString()); } if (row["Price2"] != null && row["Price2"].ToString() != "") { model.Price2 = double.Parse(row["Price2"].ToString()); } if (row["Counts"] != null && row["Counts"].ToString() != "") { model.Counts = int.Parse(row["Counts"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Dong.Model.GoodsInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update GoodsInfo set "); strSql.Append("Code=@Code,"); strSql.Append("GoodName=@GoodsName,"); strSql.Append("Category=@Category,"); strSql.Append("CategoryName=@CategoryName,"); strSql.Append("Unit=@Unit,"); strSql.Append("UnitName=@UnitName,"); strSql.Append("Factory=@Factory,"); strSql.Append("Supplier=@Supplier,"); strSql.Append("SupplierName=@SupplierName,"); strSql.Append("Price0=@Price0,"); strSql.Append("Price1=@Price1,"); strSql.Append("Price2=@Price2,"); strSql.Append("Counts=@Counts"); strSql.Append(" where Id=@Id "); OleDbParameter[] parameters = { new OleDbParameter("@Code", OleDbType.VarChar, 50), new OleDbParameter("@GoodsName", OleDbType.VarChar, 50), new OleDbParameter("@Category", OleDbType.Integer, 4), new OleDbParameter("@CategoryName", OleDbType.VarChar, 50), new OleDbParameter("@Unit", OleDbType.Integer, 4), new OleDbParameter("@UnitName", OleDbType.VarChar, 50), new OleDbParameter("@Factory", OleDbType.VarChar, 50), new OleDbParameter("@Supplier", OleDbType.Integer, 4), new OleDbParameter("@SupplierName", OleDbType.VarChar, 50), new OleDbParameter("@Price0", OleDbType.Double), new OleDbParameter("@Price1", OleDbType.Double), new OleDbParameter("@Price2", OleDbType.Double), new OleDbParameter("@Counts", OleDbType.Integer, 4), new OleDbParameter("@Id", OleDbType.Integer, 4) }; parameters[0].Value = model.Code; parameters[1].Value = model.GoodsName; parameters[2].Value = model.Category; parameters[3].Value = model.CategoryName; parameters[4].Value = model.Unit; parameters[5].Value = model.UnitName; parameters[6].Value = model.Factory; parameters[7].Value = model.Supplier; parameters[8].Value = model.SupplierName; parameters[9].Value = model.Price0; parameters[10].Value = model.Price1; parameters[11].Value = model.Price2; parameters[12].Value = model.Counts; parameters[13].Value = model.Id; int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }