public static long Insert(Customers cus) { string sql = @"INSERT INTO Customers ([Code] ,[LastName] ,[FirstName] ,[CallName] ,[Address] ,[Email] ,[Phone] ,[Fax] ,[Note] ,[Type]) VALUES ('" + cus.Code + @"' ,'" + cus.LastName + @"' ,'" + cus.FirstName + @"' ,'" + cus.CallName + @"' ,'" + cus.Address + @"' ,'" + cus.Email + @"' ,'" + cus.Phone + @"' ,'" + cus.Fax + @"' ,'" + cus.Note + @"' ," + cus.Type + @")"; Provider.ExecuteNonQuery(sql); return long.Parse(Provider.ExecuteScalar("Select @@IDENTITY").ToString()); }
public static void Update(Customers cus) { string sql = @"UPDATE [Customers] SET [Code] = '" + cus.Code + @"' ,[LastName] = '" + cus.LastName + @"' ,[FirstName] = '" + cus.FirstName + @"' ,[CallName] = '" + cus.CallName + @"' ,[Address] = '" + cus.Address + @"' ,[Email] = '" + cus.Email + @"' ,[Phone] = '" + cus.Phone + @"' ,[Fax] = '" + cus.Fax + @"' ,[Note] = '" + cus.Note + @"' ,[Type] = " + cus.Type + @" WHERE ID=" + cus.ID; Provider.ExecuteNonQuery(sql); }
private void _ClearForm() { txtMa.Text = ""; lookUpEdit_Nhom.EditValue = null; txtHo.Text = ""; txtTenGoi.Text = ""; txtTen.Text = ""; txtDiaChi.Text = ""; txtDienThoai.Text = ""; txtFax.Text = ""; txtEmail.Text = ""; txtGhiChu.Text = ""; _cus = null; txtMa.Focus(); }
private Customers _getFormInfo() { Customers temp = null ; if (txtMa.Text != "") { if (lookUpEdit_Nhom.EditValue != null) { if (txtHo.Text != "") { temp = new Customers(); temp.Code = txtMa.Text; temp.Type = (int)lookUpEdit_Nhom.EditValue; temp.LastName = txtHo.Text; temp.FirstName = txtTen.Text; temp.CallName = txtTenGoi.Text; temp.Address = txtDiaChi.Text; temp.Phone = txtDienThoai.Text; temp.Fax = txtFax.Text; temp.Type = long.Parse(lookUpEdit_Nhom.EditValue.ToString()); temp.Email = txtEmail.Text; temp.Note = txtGhiChu.Text; } else { MessageBox.Show("Nhập tên đối tác", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); txtHo.Focus(); } } else { MessageBox.Show("Chọn nhóm đối tác", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); lookUpEdit_Nhom.Focus(); } } else { MessageBox.Show("Nhập mã đối tác", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); txtMa.Focus(); } return temp; }
private void btnLuu_Click(object sender, EventArgs e) { Customers temp = _getFormInfo(); if (temp != null) { if (_cus == null) //thêm mới { if (!Customers.CheckExits(temp.Code,0)) { _cus = temp; Customers.Insert( _cus); DialogResult = DialogResult.OK; if (chkCloseAlterSave.Checked) { this.Close(); return; } _setFormStatus(-1); } else { MessageBox.Show("Mã khách hàng đã tồn tại!"); } } else //cập nhật { if (!Customers.CheckExits(temp.Code, _cus.ID)) { temp.ID = _cus.ID; _cus = temp; Customers.Update(_cus); DialogResult = DialogResult.OK; if (chkCloseAlterSave.Checked) { this.Close(); return; } _setFormStatus(-1); } else { MessageBox.Show("Mã khách hàng đã tồn tại!"); } } } }
public static Customers Get(long ID) { Type type = typeof(Customers); string sql = @"select * from Customers where ID=" + ID; DataTable dtTable = Provider.ExecuteToDataTable(sql); if (dtTable.Rows.Count > 0) { Customers cus = new Customers(); return (Customers)Common.GetObjectValue(dtTable.Rows[0], type, cus); } return null; }
public static Customers GetObject(DataRow dtRow) { Customers hh = new Customers(); if (dtRow["ID"] != null) hh.ID = long.Parse(dtRow["ID"].ToString()); if (dtRow["Code"] != null) hh.Code = (dtRow["Code"].ToString()); if (dtRow["FirstName"] != null) hh.FirstName = dtRow["FirstName"].ToString(); if (dtRow["LastName"] != null) hh.LastName = (dtRow["LastName"].ToString()); if (dtRow["CallName"] != null) hh.CallName = (dtRow["CallName"].ToString()); if (dtRow["Address"] != null) hh.Address = (dtRow["Address"].ToString()); if (dtRow["Email"] != null) hh.Email = (dtRow["Email"].ToString()); if (dtRow["Phone"] != null) hh.Phone = (dtRow["Phone"].ToString()); if (dtRow["Fax"]!=null) hh.Fax = (dtRow["Fax"].ToString()); if (dtRow["Note"] != null) hh.Note = (dtRow["Note"].ToString()); if (dtRow["Type"] != null) hh.Type = long.Parse(dtRow["Type"].ToString()); return hh; }