private void LoadUpdateSupplier(Supplier obj) { if (obj == null) return; this.Tag = obj; this.NameTxt.Text = obj.Name; this.ContactTxt.Text = obj.Contact; this.AddressTxt.Text = obj.Address; this.RemarkTxt.Text = obj.Remark; }
public List<Supplier> DataTableToSupplierList(DataTable dt) { List<Supplier> list = new List<Supplier>(); foreach (DataRow row in dt.Rows) { Supplier info = new Supplier(); info.Id = Convert.ToInt32(row["Id"]); info.Name = (string)row["Name"]; info.Contact = (string)row["Contact"]; info.Remark = (string)row["Remark"]; info.Address = (string)row["Address"]; list.Add(info); } return list; }
private void ConfirmButton_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(this.NameTxt.Text)) { MessageBox.Show("供应商名称不能为空。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.Tag == null) { UpdateSupplier = new Supplier(); } UpdateSupplier.Name = this.NameTxt.Text; UpdateSupplier.Contact = this.ContactTxt.Text; UpdateSupplier.Address = this.AddressTxt.Text; UpdateSupplier.Remark = this.RemarkTxt.Text; manager.InsertOrUpdateSupplier(UpdateSupplier); this.Close(); }
public void InsertOrUpdateSupplier(Supplier obj) { supplierDao.InsertOrUpdateSupplier(obj); FireEditSupplierEvent(obj); }
public void InsertOrUpdateSupplier(Supplier item) { string InsSql = @"INSERT INTO Supplier(Name,Contact,Remark,Address,CreatedTime,ModifiedTime) " + " VALUES(@Name,@Contact,@Remark,@Address,@CreatedTime,@ModifiedTime)"; string UpdSql = @"UPDATE Supplier set Name=@Name,Contact=@Contact,Remark=@Remark,Address=@Address,ModifiedTime=@ModifiedTime " + " WHERE Id = @Id"; string ExistRecordSql = "SELECT count(1) FROM Supplier WHERE Id = " + item.Id; DateTime CurrentTime = DateTime.Now; MySqlParameter[] parameter = new MySqlParameter[] { new MySqlParameter("@Id",item.Id), new MySqlParameter("@Name",item.Name), new MySqlParameter("@Contact",item.Contact), new MySqlParameter("@Remark",item.Remark), new MySqlParameter("@Address",item.Address), new MySqlParameter("@CreatedTime", CurrentTime), new MySqlParameter("@ModifiedTime",CurrentTime) }; int record = Convert.ToInt32(dbHelper.ExecuteScalar(ExistRecordSql, null)); if (record == 0) { dbHelper.ExecuteNonQuery(InsSql, parameter); } else { dbHelper.ExecuteNonQuery(UpdSql, parameter); } }