protected SuppliersUserLinkFacade(SuppliersUserLinkModel model) : base(model) { }
void save() { if (IsNew) { MessageBox.Show("Bạn không thể tạo mới nhà cung cấp!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop); return; } ProcessTransaction pt = new ProcessTransaction(); pt.OpenConnection(); pt.BeginTransaction(); try { if (!ValidateForm()) { return; } #region NCC if (IsNew) { Supplier = new SuppliersModel(); } Supplier.Address = txtAddress.Text; Supplier.Agency = txtAgency.Text; Supplier.BangDanhGia = chkBangDanhGia.Checked; Supplier.BankAcount = txtBankAccount.Text; Supplier.BankAcountName = txtBankAccountName.Text; Supplier.BankName = txtBankName.Text; Supplier.ContactPerson = txtContactPerson.Text; Supplier.ContactPhone = txtContactPhone.Text; Supplier.Discount = TextUtils.ToDecimal(txtDiscount.Text); Supplier.DKKD = chkDKKD.Checked; Supplier.Email = txtEmail.Text; Supplier.HopDongNguyenTac = chkHopDongNguyenTac.Checked; Supplier.MaterialGroup = cboMaterialGroup.SelectedIndex; Supplier.MST = txtMST.Text; //Supplier.NhanTinStatus = 0; Supplier.Note = txtNote.Text; Supplier.Office = txtOffice.Text; Supplier.PaymentTerm = txtPaymentTerm.Text; Supplier.Phone = txtPhone.Text; Supplier.ProductProvided = txtProductProvided.Text; Supplier.StatusDisable = cboStatus.SelectedIndex; Supplier.SupplierCode = txtCode.Text; //Supplier.SupplierERPId = _supplierId; //Supplier.SupplierId = _supplierId; Supplier.SupplierName = txtName.Text; //Supplier.UserId = TextUtils.ToString(cboUser.EditValue); Supplier.UyQuyenHang = chkUyQuyenHang.Checked; Supplier.UpdatedDate = DateTime.Now; if (IsNew) { Supplier.DateArising = DateTime.Now; pt.InsertQLSX(Supplier); } else { pt.UpdateQLSX(Supplier); } #endregion #region Nguoi phu trach foreach (DataGridViewRow row in grvUser.Rows) { int id = TextUtils.ToInt(row.Cells["colULinkId"].Value); SuppliersUserLinkModel linkModel = new SuppliersUserLinkModel(); if (id > 0) { linkModel = (SuppliersUserLinkModel)SuppliersUserLinkBO.Instance.FindByPK(id); } linkModel.SupplierId = Supplier.SupplierId; linkModel.UserId = TextUtils.ToString(row.Cells["colUId"].Value); if (id > 0) { pt.Update(linkModel); } else { pt.Insert(linkModel); } } #endregion #region Hang cung cap foreach (DataGridViewRow row in grvHang.Rows) { int id = TextUtils.ToInt(row.Cells["colHLinkID"].Value); SuppliersManufacturerLinkModel linkModel = new SuppliersManufacturerLinkModel(); if (id > 0) { linkModel = (SuppliersManufacturerLinkModel)SuppliersManufacturerLinkBO.Instance.FindByPK(id); } linkModel.SupplierId = Supplier.SupplierId; linkModel.ManufacturerId = TextUtils.ToString(row.Cells["colHid"].Value); if (id > 0) { pt.Update(linkModel); } else { pt.Insert(linkModel); } } #endregion #region Hợp đồng foreach (DataGridViewRow row in grvContract.Rows) { int id = TextUtils.ToInt(row.Cells["colContractID"].Value); SupplierContractModel model = new SupplierContractModel(); if (id > 0) { model = (SupplierContractModel)SupplierContractBO.Instance.FindByPK(id); } model.SupplierId = Supplier.SupplierId; model.ContractType = TextUtils.ToInt(row.Cells["colContractType"].Value); model.SignDate = TextUtils.ToDate2(row.Cells["colSignDate"].Value); model.OutDate = TextUtils.ToDate2(row.Cells["colOutDate"].Value); if (id > 0) { pt.Update(model); } else { pt.Insert(model); } } #endregion #region Nhóm vật tư foreach (DataGridViewRow row in grvMaterialGroup.Rows) { int id = TextUtils.ToInt(row.Cells["colGroupLinkID"].Value); SupplierMaterialGroupLinkModel model = new SupplierMaterialGroupLinkModel(); if (id > 0) { model = (SupplierMaterialGroupLinkModel)SupplierMaterialGroupLinkBO.Instance.FindByPK(id); } model.SupplierId = Supplier.SupplierId; model.MaterialGroupID = TextUtils.ToInt(row.Cells["colMaterialGroupID"].Value); if (id > 0) { pt.Update(model); } else { pt.Insert(model); } } #endregion pt.CommitTransaction(); IsNew = false; _isSaved = true; loadHangGrid(); loadUserGrid(); loadContractGrid(); loadMaterialGroupGrid(); MessageBox.Show("Lưu trữ thành công!", TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { pt.CloseConnection(); } }