//Sửa thông tin nhà cung cấp public void updateSupplier(eSupplier sup) { nhaCungCap suptemp = db.nhaCungCaps.Where(x => x.maNCC.ToString().Equals(sup.SupplierId)).FirstOrDefault(); // Cập nhật dữ liệu suptemp.maNCC = int.Parse(sup.SupplierId); suptemp.tenNCC = sup.SupplierName; suptemp.diaChi = sup.Address; suptemp.phone = sup.Phone; db.SubmitChanges(); }
//Nhập nhà cung cấp mới vào database public int insertSupplier(eSupplier sup) { if (checkIDExist(sup.SupplierId)) { return(0); } nhaCungCap suptemp = new nhaCungCap(); suptemp.maNCC = int.Parse(sup.SupplierId); suptemp.tenNCC = sup.SupplierName; suptemp.diaChi = sup.Address; suptemp.phone = sup.Phone; db.nhaCungCaps.InsertOnSubmit(suptemp); db.SubmitChanges(); return(1); }
//Lấy toàn bộ khách hàng có trong database public List <eSupplier> getAllSupplier() { var listCus = (from m in db.nhaCungCaps select m).ToList(); List <eSupplier> ls = new List <eSupplier>(); foreach (var m in listCus) { eSupplier e = new eSupplier(); e.SupplierId = m.maNCC.ToString(); e.SupplierName = m.tenNCC; e.Address = m.diaChi; e.Phone = m.phone; ls.Add(e); } return(ls); }
public void updateSupplier(eSupplier sup) { dSup.updateSupplier(sup); }
public int insertSupplier(eSupplier sup) { return(dSup.insertSupplier(sup)); }
private void btnSave_Click(object sender, EventArgs e) { if (txtSupID.Text.Length == 0 || txtSupName.Text.Length == 0 || txtPhone.Text.Length == 0 || txtAddress.Text.Length == 0) { MessageBox.Show("Không chừa trống dữ liệu nhập !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (txtSupID.Text.KiemTraMaNCC() == false) { MessageBox.Show("Mã máy có 4 chữ số !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } eSupplier sup = new eSupplier(); sup.SupplierId = txtSupID.Text; sup.SupplierName = txtSupName.Text; sup.Address = txtAddress.Text; sup.Phone = txtPhone.Text; if (btnSave.Text.Equals("Lưu thêm")) { try { int result = bSup.insertSupplier(sup); if (result == 1) { clearTextbox(); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnNew.Text = "Thêm"; btnNew.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); btnSave.ForeColor = Color.Black; btnNew.ForeColor = Color.Black; btnUpdate.Enabled = true; btnDelete.Enabled = true; MessageBox.Show("Thêm nhà cung cấp mới thành công !", "Thêm NCC", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvSupList.DataSource = bSup.getAllSupplier(); } else { MessageBox.Show("Mã nhà cung cấp bị trùng ! Vui lòng thử lại !", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { bSup.updateSupplier(sup); btnSave.Enabled = false; btnSave.Text = "Lưu"; btnSave.BackColor = Color.Gainsboro; btnUpdate.Text = "Sửa"; btnUpdate.BackColor = Color.Gainsboro; label2.Text = ""; setOnOffEditTextbox(0); btnSave.ForeColor = Color.Black; btnUpdate.ForeColor = Color.Black; btnNew.Enabled = true; btnDelete.Enabled = true; MessageBox.Show("Cập nhập nhà cung cấp thành công !", "Cập nhập", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvSupList.DataSource = bSup.getAllSupplier(); } }