public FrmAddPurchaseBill(Action <int> updateDel, int curPage, bool is4Modify = false, SteelManagement.Model.PurchaseBill model = null) { this.StartPosition = FormStartPosition.CenterParent; InitializeComponent(); _updateDel = updateDel; _curPage = curPage; _is4Modify = is4Modify; _model = model; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SteelManagement.Model.PurchaseBill model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update PurchaseBill set "); strSql.Append("EntryTime=@EntryTime,"); strSql.Append("SerialNo=@SerialNo,"); strSql.Append("Corporation=@Corporation,"); strSql.Append("Project=@Project,"); strSql.Append("OperatorId=@OperatorId,"); strSql.Append("Supplier=@Supplier,"); strSql.Append("Amount=@Amount,"); strSql.Append("Payer=@Payer"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@EntryTime", SqlDbType.DateTime), new SqlParameter("@SerialNo", SqlDbType.VarChar, 50), new SqlParameter("@Corporation", SqlDbType.VarChar, 50), new SqlParameter("@Project", SqlDbType.VarChar, 50), new SqlParameter("@OperatorId", SqlDbType.Int, 4), new SqlParameter("@Supplier", SqlDbType.VarChar, 50), new SqlParameter("@Amount", SqlDbType.Money, 8), new SqlParameter("@Payer", SqlDbType.VarChar, 50), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.EntryTime; parameters[1].Value = model.SerialNo; parameters[2].Value = model.Corporation; parameters[3].Value = model.Project; parameters[4].Value = model.OperatorId; parameters[5].Value = model.Supplier; parameters[6].Value = model.Amount; parameters[7].Value = model.Payer; parameters[8].Value = model.Id; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SteelManagement.Model.PurchaseBill DataRowToModel(DataRow row) { SteelManagement.Model.PurchaseBill model = new SteelManagement.Model.PurchaseBill(); 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["SerialNo"] != null) { model.SerialNo = row["SerialNo"].ToString(); } if (row["Corporation"] != null) { model.Corporation = row["Corporation"].ToString(); } if (row["Project"] != null) { model.Project = row["Project"].ToString(); } if (row["OperatorId"] != null && row["OperatorId"].ToString() != "") { model.OperatorId = int.Parse(row["OperatorId"].ToString()); } if (row["Supplier"] != null) { model.Supplier = row["Supplier"].ToString(); } if (row["Amount"] != null && row["Amount"].ToString() != "") { model.Amount = decimal.Parse(row["Amount"].ToString()); } if (row["Payer"] != null) { model.Payer = row["Payer"].ToString(); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(SteelManagement.Model.PurchaseBill model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into PurchaseBill("); strSql.Append("EntryTime,SerialNo,Corporation,Project,OperatorId,Supplier,Amount,Payer)"); strSql.Append(" values ("); strSql.Append("@EntryTime,@SerialNo,@Corporation,@Project,@OperatorId,@Supplier,@Amount,@Payer)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@EntryTime", SqlDbType.DateTime), new SqlParameter("@SerialNo", SqlDbType.VarChar, 50), new SqlParameter("@Corporation", SqlDbType.VarChar, 50), new SqlParameter("@Project", SqlDbType.VarChar, 50), new SqlParameter("@OperatorId", SqlDbType.Int, 4), new SqlParameter("@Supplier", SqlDbType.VarChar, 50), new SqlParameter("@Amount", SqlDbType.Money, 8), new SqlParameter("@Payer", SqlDbType.VarChar, 50) }; parameters[0].Value = model.EntryTime; parameters[1].Value = model.SerialNo; parameters[2].Value = model.Corporation; parameters[3].Value = model.Project; parameters[4].Value = model.OperatorId; parameters[5].Value = model.Supplier; parameters[6].Value = model.Amount; parameters[7].Value = model.Payer; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public SteelManagement.Model.PurchaseBill GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,EntryTime,SerialNo,Corporation,Project,OperatorId,Supplier,Amount,Payer from PurchaseBill "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; SteelManagement.Model.PurchaseBill model = new SteelManagement.Model.PurchaseBill(); 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.Corporation = txtCorporation.Text; if (string.IsNullOrEmpty(txtProject.Text)) { MessageBoxEx.Show("必须填写项目名称!"); return; } _model.Project = txtProject.Text; _model.Supplier = txtSupplier.Text; _model.Amount = DecimalHandler.Parse(txtAmount.Text); _model.Payer = txtPayer.Text; //下面的字段暂时不进行修改 //_model.EntryTime = DateTime.Now; //_model.SerialNo = SerialNoGenerator.GetSerialNo(SerialNoGenerator.Type.Type03Receipt); //_model.OperatorId = GlobalUtils.LoginUser.Id; if (!_bllPurchaseBill.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.PurchaseBill model = new SteelManagement.Model.PurchaseBill(); try { model.Corporation = txtCorporation.Text; if (string.IsNullOrEmpty(txtProject.Text)) { MessageBoxEx.Show("必须填写项目名称!"); return; } model.Project = txtProject.Text; model.Supplier = txtSupplier.Text; model.Amount = DecimalHandler.Parse(txtAmount.Text); model.Payer = txtPayer.Text; model.EntryTime = DateTime.Now; model.SerialNo = SerialNoGenerator.GetSerialNo(SerialNoGenerator.Type.Type04PurchaseBill); model.OperatorId = GlobalUtils.LoginUser.Id; if (_bllPurchaseBill.Add(model) <= 0) { MessageBoxEx.Show("添加失败,请稍后重试!"); return; } MessageBoxEx.Show("添加成功"); _updateDel(_curPage); this.DialogResult = DialogResult.OK; this.Close(); } catch (Exception) { MessageBoxEx.Show("请检查输入是否有误,价格为0请填入0!"); //throw; } } }