Ejemplo n.º 1
0
 /// <summary>
 /// Thêm mới hoặc Cập nhật thông tin Nhà Cung Cấp
 /// </summary>
 /// <param name="supplierName"></param>
 private Data.Supplier InsertOrUpdateSupplier(string supplierName)
 {
     if (!string.IsNullOrEmpty(supplierName))
     {
         Supplier supplier;
         if (!_suppliersService.CheckSupplierNameExit(supplierName))
         {
             supplier = _suppliersService.GetSupplierByName(supplierName);
         }
         else
         {
             supplier = new Supplier()
             {
                 SupplierID = _suppliersService.NextId(),
                 SupplierName = supplierName,
                 CreatedBy = _userName,
                 CreatedDate = DateTime.Now,
                 IsActive = true,
             };
             try
             {
                 _suppliersService.Add(supplier);
             }
             catch (Exception ex)
             {
                 XtraMessageBox.Show(string.Format("Lỗi thêm Nhà Cung Cấp \n{0}", ex.Message));
             }
         }
         return supplier;
     }
     return null;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Thêm mới
 /// </summary>
 /// <param name="supplier"></param>
 /// <returns></returns>
 public void Add(Supplier supplier)
 {
     _context.Suppliers.Add(supplier);
     SaveChanges();
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Cập nhật thông tin
 /// </summary>
 /// <param name="supplier"></param>
 public void Update(Supplier supplier)
 {
     _context.Suppliers.Attach(supplier);
     _context.Entry(supplier).State = EntityState.Modified;
     SaveChanges();
 }
Ejemplo n.º 4
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtSupplierID.Text))
            {
                txtSupplierID.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Mã Nhà cung cấp không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSupplierID.Focus();
            }
            else if (string.IsNullOrEmpty(txtSupplierName.Text))
            {
                txtSupplierName.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Tên Nhà cung cấp không được bỏ trống!", "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtSupplierName.Focus();
            }
            else if (string.IsNullOrEmpty(gridLookUpEdit1.Text))
            {
                gridLookUpEdit1.Properties.Appearance.BorderColor = System.Drawing.Color.Red;
                XtraMessageBox.Show("Bạn phải chọn một Khu vực cho Nhà cung cấp này!", "THÔNG BÁO", MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
                gridLookUpEdit1.Focus();
            }
            else
            {
                var supplier = new Supplier
                {
                    SupplierID = txtSupplierID.Text,
                    AreaID = gridLookUpEdit1View.GetFocusedRowCellValue("AreaID").ToString(),
                    SupplierName = txtSupplierName.Text,
                    PhoneNumber = txtPhone.Text,
                    Mobile = txtMoblie.Text,
                    Address = txtAddress.Text,
                    Email = txtEmail.Text,
                    AccountNumber = txtAccountNumber.Text,
                    Bank = txtBank.Text,
                    Fax = txtFax.Text,
                    Website = txtWebsite.Text,
                    IsActive = checkActive.Checked,
                    CreatedDate = DateTime.Now,
                    CreatedBy = null,

                };
                try
                {
                    _suppliersService.Add(supplier);
                    InsertSysLog(txtSupplierName.Text);
                    if (XtraMessageBox.Show("Thêm thành công.\n Bạn có muốn thêm mới Nhà cung cấp nữa không?", "HỎI", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        ResetControls();
                    }
                    else
                    {
                        DialogResult = DialogResult.No;
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show(string.Format("Lỗi {0}", ex.Message), "THÔNG BÁO", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
            }
        }