public FrmAddReceiptInfo(Action <int> updateDel, int curPage, SteelManagement.Model.PurchaseInfo model) { this.StartPosition = FormStartPosition.CenterParent; InitializeComponent(); _updateDel = updateDel; _curPage = curPage; _purchaseInfoModel = model; }
/// <summary> /// 添加和修改 /// </summary> /// <param name="updateDel"></param> /// <param name="curPage"></param> /// <param name="is4Modify"></param> /// <param name="model"></param> public FrmAddPurchaseInfo(Action <int> updateDel, int curPage, bool is4Modify = false, SteelManagement.Model.PurchaseInfo model = null) { this.StartPosition = FormStartPosition.CenterParent; InitializeComponent(); _updateDel = updateDel; _curPage = curPage; _is4Modify = is4Modify; _model = model; }
/// <summary> /// 得到一个对象实体 /// </summary> public SteelManagement.Model.PurchaseInfo GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,EntryTime,Project,Dateline,Supplier,Brand,TransportWay,Size,Texture,Amount,Quote,Fluctuation1,TransportCost,Price,TotalMoney,FuYuDate,Money1,InvoiceDate,Money2,SerialNo,OperatorId,DiaoZhuang,LiXi,ChengDui,OtherCost,TieXi,Corporation from PurchaseInfo "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; SteelManagement.Model.PurchaseInfo model = new SteelManagement.Model.PurchaseInfo(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
private void btnOK_Click(object sender, EventArgs e) { if (_is4Modify) { try { _model.DiaoZhuang = DecimalHandler.Parse(txtDiaoZhuang.Text); _model.LiXi = DecimalHandler.Parse(txtLiXi.Text); _model.ChengDui = DecimalHandler.Parse(txtChengDui.Text); _model.OtherCost = DecimalHandler.Parse(txtOtherCost.Text); _model.TieXi = DecimalHandler.Parse(txtTieXi.Text); _model.Corporation = txtCorporation.Text; if (string.IsNullOrEmpty(txtProject.Text)) { MessageBoxEx.Show("必须填写项目名称!"); return; } _model.Project = txtProject.Text; _model.Dateline = DateTime.Parse(txtDateline.Text); _model.Supplier = txtSupplier.Text; _model.Brand = txtBrand.Text; _model.TransportWay = txtTransportWay.Text; _model.Size = txtSize.Text; _model.Texture = txtTexture.Text; _model.Amount = DecimalHandler.Parse(txtAmount.Text); _model.Quote = DecimalHandler.Parse(txtQuote.Text); _model.Fluctuation1 = DecimalHandler.Parse(txtFluctuation1.Text); _model.TransportCost = DecimalHandler.Parse(txtTransportCost.Text); _model.Price = DecimalHandler.Parse(txtPrice.Text); _model.TotalMoney = DecimalHandler.Parse(txtTotalMoney.Text); _model.FuYuDate = DateTime.Parse(txtFuYuDate.Text); _model.Money1 = DecimalHandler.Parse(txtMoney1.Text); _model.InvoiceDate = DateTime.Parse(txtInvoiceDate.Text); _model.Money2 = DecimalHandler.Parse(txtMoney2.Text); if (!_bllPurchaseInfo.Update(_model)) { MessageBoxEx.Show("更新失败,请稍后重试!"); return; } MessageBoxEx.Show("更新成功!"); _updateDel(_curPage); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception) { MessageBoxEx.Show("请检查输入是否有误,价格为0请填入0!"); //throw; } } else { SteelManagement.Model.PurchaseInfo model = new SteelManagement.Model.PurchaseInfo(); try { model.Corporation = txtCorporation.Text; if (string.IsNullOrEmpty(txtProject.Text)) { MessageBoxEx.Show("必须填写项目名称!"); return; } model.Project = txtProject.Text; model.Dateline = DateTime.Parse(txtDateline.Text); model.Supplier = txtSupplier.Text; model.Brand = txtBrand.Text; model.TransportWay = txtTransportWay.Text; model.Size = txtSize.Text; model.Texture = txtTexture.Text; model.Amount = DecimalHandler.Parse(txtAmount.Text); model.Quote = DecimalHandler.Parse(txtQuote.Text); model.Fluctuation1 = DecimalHandler.Parse(txtFluctuation1.Text); model.TransportCost = DecimalHandler.Parse(txtTransportCost.Text); model.Price = DecimalHandler.Parse(txtPrice.Text); model.TotalMoney = DecimalHandler.Parse(txtTotalMoney.Text); model.FuYuDate = DateTime.Parse(txtFuYuDate.Text); model.Money1 = DecimalHandler.Parse(txtMoney1.Text); model.InvoiceDate = DateTime.Parse(txtInvoiceDate.Text); model.Money2 = DecimalHandler.Parse(txtMoney2.Text); model.EntryTime = DateTime.Now; model.SerialNo = SerialNoGenerator.GetSerialNo(SerialNoGenerator.Type.Type01Purchase);//生成流水号 model.OperatorId = GlobalUtils.LoginUser.Id; model.DiaoZhuang = DecimalHandler.Parse(txtDiaoZhuang.Text); model.LiXi = DecimalHandler.Parse(txtLiXi.Text); model.ChengDui = DecimalHandler.Parse(txtChengDui.Text); model.OtherCost = DecimalHandler.Parse(txtOtherCost.Text); model.TieXi = DecimalHandler.Parse(txtTieXi.Text); if (_bllPurchaseInfo.Add(model) <= 0) { MessageBoxEx.Show("添加失败,请稍后重试!"); return; } MessageBoxEx.Show("添加成功"); _updateDel(_curPage); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception) { MessageBoxEx.Show("请检查输入是否有误,价格为0请填入0!"); //throw; } } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SteelManagement.Model.PurchaseInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into PurchaseInfo("); strSql.Append("EntryTime,Project,Dateline,Supplier,Brand,TransportWay,Size,Texture,Amount,Quote,Fluctuation1,TransportCost,Price,TotalMoney,FuYuDate,Money1,InvoiceDate,Money2,SerialNo,OperatorId,DiaoZhuang,LiXi,ChengDui,OtherCost,TieXi,Corporation)"); strSql.Append(" values ("); strSql.Append("@EntryTime,@Project,@Dateline,@Supplier,@Brand,@TransportWay,@Size,@Texture,@Amount,@Quote,@Fluctuation1,@TransportCost,@Price,@TotalMoney,@FuYuDate,@Money1,@InvoiceDate,@Money2,@SerialNo,@OperatorId,@DiaoZhuang,@LiXi,@ChengDui,@OtherCost,@TieXi,@Corporation)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@EntryTime", SqlDbType.DateTime), new SqlParameter("@Project", SqlDbType.VarChar, 50), new SqlParameter("@Dateline", SqlDbType.DateTime, 3), new SqlParameter("@Supplier", SqlDbType.VarChar, 50), new SqlParameter("@Brand", SqlDbType.VarChar, 50), new SqlParameter("@TransportWay", SqlDbType.VarChar, 50), new SqlParameter("@Size", SqlDbType.VarChar, 50), new SqlParameter("@Texture", SqlDbType.VarChar, 50), new SqlParameter("@Amount", SqlDbType.Money, 8), new SqlParameter("@Quote", SqlDbType.Money, 8), new SqlParameter("@Fluctuation1", SqlDbType.Money, 8), new SqlParameter("@TransportCost", SqlDbType.Money, 8), new SqlParameter("@Price", SqlDbType.Money, 8), new SqlParameter("@TotalMoney", SqlDbType.Money, 8), new SqlParameter("@FuYuDate", SqlDbType.DateTime, 3), new SqlParameter("@Money1", SqlDbType.Money, 8), new SqlParameter("@InvoiceDate", SqlDbType.DateTime, 3), new SqlParameter("@Money2", SqlDbType.Money, 8), new SqlParameter("@SerialNo", SqlDbType.VarChar, 50), new SqlParameter("@OperatorId", SqlDbType.Int, 4), new SqlParameter("@DiaoZhuang", SqlDbType.Money, 8), new SqlParameter("@LiXi", SqlDbType.Money, 8), new SqlParameter("@ChengDui", SqlDbType.Money, 8), new SqlParameter("@OtherCost", SqlDbType.Money, 8), new SqlParameter("@TieXi", SqlDbType.Money, 8), new SqlParameter("@Corporation", SqlDbType.VarChar, 50) }; parameters[0].Value = model.EntryTime; parameters[1].Value = model.Project; parameters[2].Value = model.Dateline; parameters[3].Value = model.Supplier; parameters[4].Value = model.Brand; parameters[5].Value = model.TransportWay; parameters[6].Value = model.Size; parameters[7].Value = model.Texture; parameters[8].Value = model.Amount; parameters[9].Value = model.Quote; parameters[10].Value = model.Fluctuation1; parameters[11].Value = model.TransportCost; parameters[12].Value = model.Price; parameters[13].Value = model.TotalMoney; parameters[14].Value = model.FuYuDate; parameters[15].Value = model.Money1; parameters[16].Value = model.InvoiceDate; parameters[17].Value = model.Money2; parameters[18].Value = model.SerialNo; parameters[19].Value = model.OperatorId; parameters[20].Value = model.DiaoZhuang; parameters[21].Value = model.LiXi; parameters[22].Value = model.ChengDui; parameters[23].Value = model.OtherCost; parameters[24].Value = model.TieXi; parameters[25].Value = model.Corporation; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SteelManagement.Model.PurchaseInfo DataRowToModel(DataRow row) { SteelManagement.Model.PurchaseInfo model = new SteelManagement.Model.PurchaseInfo(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["EntryTime"] != null && row["EntryTime"].ToString() != "") { model.EntryTime = DateTime.Parse(row["EntryTime"].ToString()); } if (row["Project"] != null) { model.Project = row["Project"].ToString(); } if (row["Dateline"] != null && row["Dateline"].ToString() != "") { model.Dateline = DateTime.Parse(row["Dateline"].ToString()); } if (row["Supplier"] != null) { model.Supplier = row["Supplier"].ToString(); } if (row["Brand"] != null) { model.Brand = row["Brand"].ToString(); } if (row["TransportWay"] != null) { model.TransportWay = row["TransportWay"].ToString(); } if (row["Size"] != null) { model.Size = row["Size"].ToString(); } if (row["Texture"] != null) { model.Texture = row["Texture"].ToString(); } if (row["Amount"] != null && row["Amount"].ToString() != "") { model.Amount = decimal.Parse(row["Amount"].ToString()); } if (row["Quote"] != null && row["Quote"].ToString() != "") { model.Quote = decimal.Parse(row["Quote"].ToString()); } if (row["Fluctuation1"] != null && row["Fluctuation1"].ToString() != "") { model.Fluctuation1 = decimal.Parse(row["Fluctuation1"].ToString()); } if (row["TransportCost"] != null && row["TransportCost"].ToString() != "") { model.TransportCost = decimal.Parse(row["TransportCost"].ToString()); } if (row["Price"] != null && row["Price"].ToString() != "") { model.Price = decimal.Parse(row["Price"].ToString()); } if (row["TotalMoney"] != null && row["TotalMoney"].ToString() != "") { model.TotalMoney = decimal.Parse(row["TotalMoney"].ToString()); } if (row["FuYuDate"] != null && row["FuYuDate"].ToString() != "") { model.FuYuDate = DateTime.Parse(row["FuYuDate"].ToString()); } if (row["Money1"] != null && row["Money1"].ToString() != "") { model.Money1 = decimal.Parse(row["Money1"].ToString()); } if (row["InvoiceDate"] != null && row["InvoiceDate"].ToString() != "") { model.InvoiceDate = DateTime.Parse(row["InvoiceDate"].ToString()); } if (row["Money2"] != null && row["Money2"].ToString() != "") { model.Money2 = decimal.Parse(row["Money2"].ToString()); } if (row["SerialNo"] != null) { model.SerialNo = row["SerialNo"].ToString(); } if (row["OperatorId"] != null && row["OperatorId"].ToString() != "") { model.OperatorId = int.Parse(row["OperatorId"].ToString()); } if (row["DiaoZhuang"] != null && row["DiaoZhuang"].ToString() != "") { model.DiaoZhuang = decimal.Parse(row["DiaoZhuang"].ToString()); } if (row["LiXi"] != null && row["LiXi"].ToString() != "") { model.LiXi = decimal.Parse(row["LiXi"].ToString()); } if (row["ChengDui"] != null && row["ChengDui"].ToString() != "") { model.ChengDui = decimal.Parse(row["ChengDui"].ToString()); } if (row["OtherCost"] != null && row["OtherCost"].ToString() != "") { model.OtherCost = decimal.Parse(row["OtherCost"].ToString()); } if (row["TieXi"] != null && row["TieXi"].ToString() != "") { model.TieXi = decimal.Parse(row["TieXi"].ToString()); } if (row["Corporation"] != null) { model.Corporation = row["Corporation"].ToString(); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SteelManagement.Model.PurchaseInfo model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update PurchaseInfo set "); strSql.Append("EntryTime=@EntryTime,"); strSql.Append("Project=@Project,"); strSql.Append("Dateline=@Dateline,"); strSql.Append("Supplier=@Supplier,"); strSql.Append("Brand=@Brand,"); strSql.Append("TransportWay=@TransportWay,"); strSql.Append("Size=@Size,"); strSql.Append("Texture=@Texture,"); strSql.Append("Amount=@Amount,"); strSql.Append("Quote=@Quote,"); strSql.Append("Fluctuation1=@Fluctuation1,"); strSql.Append("TransportCost=@TransportCost,"); strSql.Append("Price=@Price,"); strSql.Append("TotalMoney=@TotalMoney,"); strSql.Append("FuYuDate=@FuYuDate,"); strSql.Append("Money1=@Money1,"); strSql.Append("InvoiceDate=@InvoiceDate,"); strSql.Append("Money2=@Money2,"); strSql.Append("SerialNo=@SerialNo,"); strSql.Append("OperatorId=@OperatorId,"); strSql.Append("DiaoZhuang=@DiaoZhuang,"); strSql.Append("LiXi=@LiXi,"); strSql.Append("ChengDui=@ChengDui,"); strSql.Append("OtherCost=@OtherCost,"); strSql.Append("TieXi=@TieXi,"); strSql.Append("Corporation=@Corporation"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@EntryTime", SqlDbType.DateTime), new SqlParameter("@Project", SqlDbType.VarChar, 50), new SqlParameter("@Dateline", SqlDbType.DateTime, 3), new SqlParameter("@Supplier", SqlDbType.VarChar, 50), new SqlParameter("@Brand", SqlDbType.VarChar, 50), new SqlParameter("@TransportWay", SqlDbType.VarChar, 50), new SqlParameter("@Size", SqlDbType.VarChar, 50), new SqlParameter("@Texture", SqlDbType.VarChar, 50), new SqlParameter("@Amount", SqlDbType.Money, 8), new SqlParameter("@Quote", SqlDbType.Money, 8), new SqlParameter("@Fluctuation1", SqlDbType.Money, 8), new SqlParameter("@TransportCost", SqlDbType.Money, 8), new SqlParameter("@Price", SqlDbType.Money, 8), new SqlParameter("@TotalMoney", SqlDbType.Money, 8), new SqlParameter("@FuYuDate", SqlDbType.DateTime, 3), new SqlParameter("@Money1", SqlDbType.Money, 8), new SqlParameter("@InvoiceDate", SqlDbType.DateTime, 3), new SqlParameter("@Money2", SqlDbType.Money, 8), new SqlParameter("@SerialNo", SqlDbType.VarChar, 50), new SqlParameter("@OperatorId", SqlDbType.Int, 4), new SqlParameter("@DiaoZhuang", SqlDbType.Money, 8), new SqlParameter("@LiXi", SqlDbType.Money, 8), new SqlParameter("@ChengDui", SqlDbType.Money, 8), new SqlParameter("@OtherCost", SqlDbType.Money, 8), new SqlParameter("@TieXi", SqlDbType.Money, 8), new SqlParameter("@Corporation", SqlDbType.VarChar, 50), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.EntryTime; parameters[1].Value = model.Project; parameters[2].Value = model.Dateline; parameters[3].Value = model.Supplier; parameters[4].Value = model.Brand; parameters[5].Value = model.TransportWay; parameters[6].Value = model.Size; parameters[7].Value = model.Texture; parameters[8].Value = model.Amount; parameters[9].Value = model.Quote; parameters[10].Value = model.Fluctuation1; parameters[11].Value = model.TransportCost; parameters[12].Value = model.Price; parameters[13].Value = model.TotalMoney; parameters[14].Value = model.FuYuDate; parameters[15].Value = model.Money1; parameters[16].Value = model.InvoiceDate; parameters[17].Value = model.Money2; parameters[18].Value = model.SerialNo; parameters[19].Value = model.OperatorId; parameters[20].Value = model.DiaoZhuang; parameters[21].Value = model.LiXi; parameters[22].Value = model.ChengDui; parameters[23].Value = model.OtherCost; parameters[24].Value = model.TieXi; parameters[25].Value = model.Corporation; parameters[26].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }