private void ProductMasterEditForm_Load(object sender, EventArgs e) { if(!string.IsNullOrEmpty(this.ProductMasterId)) { ProductMasterEventArgs eventArgs = new ProductMasterEventArgs(); eventArgs.ProductMasterId = ProductMasterId; EventUtility.fireEvent(LoadProductMasters,this,eventArgs); ProductMasterView = eventArgs.ProductMasterView; txtProductName.Text = ProductMasterView.ProductName; txtDescription.Text = ProductMasterView.Description; } }
void form_CloseProductMasterEvent(object sender, ProductMasterEventArgs e) { List<ProductMaster> productMasters = e.CreatedProductMasterList; //PopulateGridByProductMaster(productMasters[0]); // close ProductMasterCreateForm ((Form)sender).Close(); LoadProductMasterToComboBox(); }
private void productMasterView_InitProductMasterEvent(object sender, ProductMasterEventArgs e) { var criteria = new ObjectCriteria(); criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO); e.ProductTypeList = ProductTypeLogic.FindAll(criteria); e.ProductTypeList.Insert(0, new ProductType()); e.ProductSizeList = ProductSizeLogic.FindAll(criteria); e.ProductSizeList.Insert(0, new ProductSize()); e.ProductColorList = ProductColorLogic.FindAll(criteria); e.ProductColorList.Insert(0, new ProductColor()); e.CountryList = CountryLogic.FindAll(criteria); e.CountryList.Insert(0, new Country()); e.ManufacturerList = ManufacturerLogic.FindAll(criteria); e.ManufacturerList.Insert(0, new Manufacturer()); e.PackagerList = PackagerLogic.FindAll(criteria); e.PackagerList.Insert(0, new Packager()); e.DistributorList = DistributorLogic.FindAll(criteria); e.DistributorList.Insert(0, new Distributor()); if (e.ProductMasterForInit != null) { criteria = new ObjectCriteria(); criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO); criteria.AddEqCriteria("ProductName", e.ProductMasterForInit.ProductName); criteria.AddEqCriteria("ProductType", e.ProductMasterForInit.ProductType); criteria.AddEqCriteria("Manufacturer", e.ProductMasterForInit.Manufacturer); criteria.AddEqCriteria("Distributor", e.ProductMasterForInit.Distributor); criteria.AddEqCriteria("Packager", e.ProductMasterForInit.Packager); criteria.AddEqCriteria("Country", e.ProductMasterForInit.Country); e.SameProductMasterList = ProductMasterLogic.FindAll(criteria); } }
void productMasterEditView_SaveProductMasters(object sender, ProductMasterEventArgs e) { //ProductMasterLogic.FindAll(); }
void productMasterEditView_LoadProductMasters(object sender, ProductMasterEventArgs e) { }
public void productMasterView_SaveProductMasterEvent(object sender, ProductMasterEventArgs e) { try { if (e.ProductMaster != null && !string.IsNullOrEmpty(e.ProductMaster.ProductMasterId)) { ProductMasterLogic.Update(e.ProductMaster); ClientUtility.Log(logger, e.ProductMaster.ToString(), CommonConstants.ACTION_SAVE_PRODUCT_MASTER); } else { if (e.CreatedProductMasterList != null) { ProductMasterLogic.AddAll(e.CreatedProductMasterList); StringBuilder sb = new StringBuilder("Tổng số lượng sản phẩm: ") .Append(e.CreatedProductMasterList.Count).Append("\r\n"); foreach (ProductMaster pm in e.CreatedProductMasterList) { sb.Append(pm.ToString()).Append("\r\n"); } ClientUtility.Log(logger, sb.ToString(), CommonConstants.ACTION_SAVE_PRODUCT_MASTER); } else if (e.ProductMaster != null) { e.ProductMaster = ProductMasterLogic.Add(e.ProductMaster); ClientUtility.Log(logger, e.ProductMaster.ToString(), CommonConstants.ACTION_SAVE_PRODUCT_MASTER); } } e.EventResult = "Success"; } catch (Exception ex) { throw; } }
public void productMasterView_LoadProductMasterEvent(object sender, ProductMasterEventArgs e) { if (!string.IsNullOrEmpty(e.ProductMasterId)) { e.ProductMaster = ProductMasterLogic.FindById(e.ProductMasterId); if (e.ProductMaster != null) { // all the dept has same price var criteria = new ObjectCriteria(); criteria.AddEqCriteria("DepartmentPricePK.ProductMasterId", e.ProductMasterId); criteria.AddEqCriteria("DelFlg", CommonConstants.DEL_FLG_NO); IList list = DepartmentPriceLogic.FindAll(criteria); if (list.Count > 0) { e.DepartmentPrice = (DepartmentPrice)list[0]; } } } }
private void ProductMasterExtraForm_Load(object sender, EventArgs e) { var eventArgs = new ProductMasterEventArgs(); eventArgs.ProductMasterForInit = ProductMaster; EventUtility.fireEvent(InitProductMasterEvent, this, eventArgs); if (eventArgs.ProductTypeList.Count > 1) { eventArgs.ProductTypeList.RemoveAt(0); typeBindingSource.DataSource = eventArgs.ProductTypeList; cbbProductType.DisplayMember = "TypeName"; } if (eventArgs.ProductSizeList.Count > 1) { eventArgs.ProductSizeList.RemoveAt(0); sizeBindingSource.DataSource = eventArgs.ProductSizeList; } //productMasterControl.cbbProductSize.DisplayMember = "SizeName"; if (eventArgs.ProductColorList.Count > 1) { eventArgs.ProductColorList.RemoveAt(0); colorBindingSource.DataSource = eventArgs.ProductColorList; } //productMasterControl.cbbProductColor.DisplayMember = "ColorName"; countryBindingSource.DataSource = eventArgs.CountryList; cbbCountry.DisplayMember = "CountryName"; distributorBindingSource.DataSource = eventArgs.DistributorList; cbbDistributor.DisplayMember = "DistributorName"; manufacturerBindingSource.DataSource = eventArgs.ManufacturerList; cbbManufacturer.DisplayMember = "ManufacturerName"; packagerBindingSource.DataSource = eventArgs.PackagerList; cbbPackager.DisplayMember = "PackagerName"; if (ProductMaster != null) { OldProductMasterList = new ArrayList(); OldColorList = new ArrayList(); OldSizeList = new ArrayList(); txtDescription.Text = ProductMaster.Description; txtProductMasterId.Text = ProductMaster.ProductMasterId; txtProductName.Text = ProductMaster.ProductName; int i = 0; if (ProductMaster.Country != null) { foreach (Country country in eventArgs.CountryList) { if (country.CountryId == ProductMaster.Country.CountryId) { cbbCountry.SelectedIndex = i; } i++; } } cbbCountry.Enabled = false; i = 0; if (ProductMaster.Distributor != null) { foreach (Distributor distributor in eventArgs.DistributorList) { if (distributor.DistributorId == ProductMaster.Distributor.DistributorId) { cbbDistributor.SelectedIndex = i; } i++; } } cbbDistributor.Enabled = false; i = 0; if (ProductMaster.ProductType != null) { foreach (ProductType productType in eventArgs.ProductTypeList) { if (productType.TypeId == ProductMaster.ProductType.TypeId) { cbbProductType.SelectedIndex = i; } i++; } } cbbProductType.Enabled = false; i = 0; if (ProductMaster.Manufacturer != null) { foreach (Manufacturer manufacturer in eventArgs.ManufacturerList) { if (manufacturer.ManufacturerId == ProductMaster.Manufacturer.ManufacturerId) { cbbManufacturer.SelectedIndex = i; } i++; } } cbbManufacturer.Enabled = false; i = 0; if (ProductMaster.Packager != null) { foreach (Packager packager in eventArgs.PackagerList) { if (packager.PackagerId == ProductMaster.Packager.PackagerId) { cbbPackager.SelectedIndex = i; } i++; } } cbbPackager.Enabled = false; i = 0; if (ProductMaster.Packager != null) { foreach (Packager packager in eventArgs.PackagerList) { if (packager.PackagerId == ProductMaster.Packager.PackagerId) { cbbPackager.SelectedIndex = i; } i++; } } if (eventArgs.SameProductMasterList != null && eventArgs.SameProductMasterList.Count > 0) { IList disableColorList = new ArrayList(); IList disableSizeList = new ArrayList(); foreach (ProductMaster master in eventArgs.SameProductMasterList) { if (!ExistInList(OldProductMasterList, master)) { OldProductMasterList.Add(master); } if (!ExistInList(OldColorList, master.ProductColor)) { OldColorList.Add(master.ProductColor); } if (!ExistInList(OldSizeList, master.ProductSize)) { OldSizeList.Add(master.ProductSize); } disableColorList.Add(master.ProductColor); disableSizeList.Add(master.ProductSize); } bdsColors.DataSource = OldColorList; lstProductColors.DisplayMember = "ColorName"; lstProductColors.DisabledRows = disableColorList; lstProductSizes.DisabledRows = disableSizeList; lstProductSizes.DisplayMember = "SizeName"; bdsSizes.DataSource = OldSizeList; bdsColors.ResetBindings(false); bdsSizes.ResetBindings(false); lstProductColors.Refresh(); lstProductColors.Invalidate(); lstProductSizes.Refresh(); lstProductSizes.Invalidate(); } btnCreateCountry.Enabled = false; btnCreateDistributor.Enabled = false; btnCreateManufacturer.Enabled = false; btnCreatePackager.Enabled = false; btnCreateType.Enabled = false; btnCreateType.Enabled = false; btnSelect.Enabled = true; txtImagePath.Text = ProductMaster.ImagePath; ShowProductImage(); } }
private void ProductMasterForm_Load(object sender, EventArgs e) { var eventArgs = new ProductMasterEventArgs {ProductMasterId = ProductMasterId}; EventUtility.fireEvent(InitProductMasterEvent, sender, eventArgs); productMasterControl.cbbProductType.DataSource = eventArgs.ProductTypeList; productMasterControl.cbbProductType.DisplayMember = "TypeName"; productMasterControl.cbbProductSize.DataSource = eventArgs.ProductSizeList; productMasterControl.cbbProductSize.DisplayMember = "SizeName"; productMasterControl.cbbProductColor.DataSource = eventArgs.ProductColorList; productMasterControl.cbbProductColor.DisplayMember = "ColorName"; productMasterControl.cbbCountry.DataSource = eventArgs.CountryList; productMasterControl.cbbCountry.DisplayMember = "CountryName"; productMasterControl.cbbDistributor.DataSource = eventArgs.DistributorList; productMasterControl.cbbDistributor.DisplayMember = "DistributorName"; productMasterControl.cbbManufacturer.DataSource = eventArgs.ManufacturerList; productMasterControl.cbbManufacturer.DisplayMember = "ManufacturerName"; productMasterControl.cbbPackager.DataSource = eventArgs.PackagerList; productMasterControl.cbbPackager.DisplayMember = "PackagerName"; if (!string.IsNullOrEmpty(ProductMasterId)) { eventArgs = new ProductMasterEventArgs { ProductMasterId = ProductMasterId }; EventUtility.fireEvent(LoadProductMasterEvent, sender, eventArgs); if (eventArgs.ProductMaster != null) { productMasterControl.txtProductMasterId.Text = ProductMasterId; productMasterControl.txtProductName.Text = eventArgs.ProductMaster.ProductName; productMasterControl.txtDescription.Text = eventArgs.ProductMaster.Description; productMasterControl.txtImagePath.Text = eventArgs.ProductMaster.ImagePath; SetSelectedValuedForCombo(MasterType.PRODUCT_TYPE, productMasterControl.cbbProductType, eventArgs.ProductMaster.ProductType); SetSelectedValuedForCombo(MasterType.PRODUCT_SIZE, productMasterControl.cbbProductSize, eventArgs.ProductMaster.ProductSize); SetSelectedValuedForCombo(MasterType.PRODUCT_COLOR, productMasterControl.cbbProductColor, eventArgs.ProductMaster.ProductColor); SetSelectedValuedForCombo(MasterType.COUNTRY, productMasterControl.cbbCountry, eventArgs.ProductMaster.Country); SetSelectedValuedForCombo(MasterType.DISTRIBUTOR, productMasterControl.cbbDistributor, eventArgs.ProductMaster.Distributor); SetSelectedValuedForCombo(MasterType.MANUFACTURER, productMasterControl.cbbManufacturer, eventArgs.ProductMaster.Manufacturer); SetSelectedValuedForCombo(MasterType.PACKAGER, productMasterControl.cbbPackager, eventArgs.ProductMaster.Packager); ShowProductImage(); //DrawBarcode(eventArgs.ProductMaster.Barcode); //DepartmentPrice = eventArgs.DepartmentPrice; if (ClientInfo.getInstance().LoggedUser.Name.Equals("admin")) { btnDelete.Visible = true; } } } else { btnDelete.Visible = false; } }
private void btnSave_Click(object sender, EventArgs e) { var productMaster = new ProductMaster { ProductMasterId = ProductMasterId, ProductName = productMasterControl.txtProductName.Text, Description = productMasterControl.txtDescription.Text, ImagePath = productMasterControl.txtImagePath.Text, Packager = productMasterControl.cbbPackager.SelectedIndex > 0 ? ((Packager)productMasterControl.cbbPackager.SelectedItem) : null, ProductSize = productMasterControl.cbbProductSize.SelectedIndex > 0 ? ((ProductSize)productMasterControl.cbbProductSize.SelectedItem) : null, ProductType = productMasterControl.cbbProductType.SelectedIndex > 0 ? ((ProductType)productMasterControl.cbbProductType.SelectedItem) : null, ProductColor = productMasterControl.cbbProductColor.SelectedIndex > 0 ? ((ProductColor)productMasterControl.cbbProductColor.SelectedItem) : null, Country = productMasterControl.cbbCountry.SelectedIndex > 0 ? ((Country)productMasterControl.cbbCountry.SelectedItem) : null, Manufacturer = productMasterControl.cbbManufacturer.SelectedIndex > 0 ? ((Manufacturer)productMasterControl.cbbManufacturer.SelectedItem) : null, Distributor = productMasterControl.cbbDistributor.SelectedIndex > 0 ? ((Distributor)productMasterControl.cbbDistributor.SelectedItem) : null }; var eventArgs = new ProductMasterEventArgs {ProductMaster = productMaster}; EventUtility.fireEvent(SaveProductMasterEvent, sender, eventArgs); productMaster.ProductMasterId = eventArgs.ProductMaster.ProductMasterId; productMasterControl.txtProductMasterId.Text = productMaster.ProductMasterId; //DrawBarcode(productMaster.Barcode); if (isNeedClosing) { this.Close(); } if (ClientInfo.getInstance().LoggedUser.Name.Equals("admin")) { btnDelete.Visible = true; } }
private void btnDelete_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(ProductMasterId)) { DialogResult result = MessageBox.Show("Bạn có muốn xóa không?", "", MessageBoxButtons.YesNo); if (result.Equals(DialogResult.Yes)) { var eventArgs = new ProductMasterEventArgs{ProductMasterId = ProductMasterId}; EventUtility.fireEvent(DeleteProductMasterEvent, this, eventArgs); MessageBox.Show("Xóa thành công"); Close(); } } }
public void productMasterView_SaveProductMasterEvent(object sender, ProductMasterEventArgs e) { try { if (e.ProductMaster != null && !string.IsNullOrEmpty(e.ProductMaster.ProductMasterId)) { string realPath = ""; if (e.ProductMaster.ImagePath.Contains(":")) { realPath = e.ProductMaster.ImagePath; e.ProductMaster.ImagePath = e.ProductMaster.ProductMasterId + ".jpg"; } ProductMasterLogic.Update(e.ProductMaster); if (!string.IsNullOrEmpty(realPath)) { CopyAndCreateImage(e.ProductMaster, realPath); } ClientUtility.Log(logger, e.ProductMaster.ToString(), CommonConstants.ACTION_SAVE_PRODUCT_MASTER); } else // add new ... { // update existing product master string imagePath = null; if (e.UpdateProductMasterList != null && e.UpdateProductMasterList.Count > 0) { if (string.IsNullOrEmpty(imagePath)) { ProductMaster first = (ProductMaster) e.UpdateProductMasterList[0]; if (!string.IsNullOrEmpty(first.ImagePath) && first.ImagePath.Contains(":")) { imagePath = first.ImagePath; CopyAndCreateImage(first, imagePath); } } foreach (ProductMaster productMaster in e.UpdateProductMasterList) { if (!string.IsNullOrEmpty(productMaster.ImagePath)) { productMaster.ImagePath = StringUtility.ConvertUniStringToHexChar(productMaster.ProductName) + ".jpg"; } ProductMasterLogic.Update(productMaster); } } if (e.CreatedProductMasterList != null) { string realPath = ""; if (string.IsNullOrEmpty(imagePath)) { if (e.CreatedProductMasterList.Count > 0 && e.CreatedProductMasterList[0].ImagePath.Contains(":")) { realPath = e.CreatedProductMasterList[0].ImagePath; } } ProductMasterLogic.AddAll(e.CreatedProductMasterList); if (!string.IsNullOrEmpty(realPath)) { CopyAndCreateImage(e.CreatedProductMasterList[0], realPath); } StringBuilder sb = new StringBuilder("Tổng số lượng sản phẩm: ") .Append(e.CreatedProductMasterList.Count).Append("\r\n"); foreach (ProductMaster pm in e.CreatedProductMasterList) { sb.Append(pm.ToString()).Append("\r\n"); } ClientUtility.Log(logger, sb.ToString(), CommonConstants.ACTION_SAVE_PRODUCT_MASTER); } else if (e.ProductMaster != null) { string realPath = ""; if (!string.IsNullOrEmpty(e.ProductMaster.ImagePath) && e.ProductMaster.ImagePath.Contains(":")) { realPath = e.ProductMaster.ImagePath; } e.ProductMaster = ProductMasterLogic.Add(e.ProductMaster); if (!string.IsNullOrEmpty(realPath)) { CopyAndCreateImage(e.ProductMaster, realPath); } ClientUtility.Log(logger, e.ProductMaster.ToString(), CommonConstants.ACTION_SAVE_PRODUCT_MASTER); } } e.EventResult = "Success"; } catch (Exception ex) { throw; } }
private void btnSave_Click(object sender, EventArgs e) { var productMaster = new ProductMaster { ProductMasterId = ProductMasterId, ProductName = productMasterControl.txtProductName.Text, Barcode = string.IsNullOrEmpty(txtBarcode.Text) ? ProductMasterId : txtBarcode.Text, Packager = productMasterControl.cbbPackager.SelectedIndex > 0 ? ((Packager)productMasterControl.cbbPackager.SelectedItem) : null, ProductSize = productMasterControl.cbbProductSize.SelectedIndex > 0 ? ((ProductSize)productMasterControl.cbbProductSize.SelectedItem) : null, ProductType = productMasterControl.cbbProductType.SelectedIndex > 0 ? ((ProductType)productMasterControl.cbbProductType.SelectedItem) : null, ProductColor = productMasterControl.cbbProductColor.SelectedIndex > 0 ? ((ProductColor)productMasterControl.cbbProductColor.SelectedItem) : null, Country = productMasterControl.cbbCountry.SelectedIndex > 0 ? ((Country)productMasterControl.cbbCountry.SelectedItem) : null, Manufacturer = productMasterControl.cbbManufacturer.SelectedIndex > 0 ? ((Manufacturer)productMasterControl.cbbManufacturer.SelectedItem) : null, Distributor = productMasterControl.cbbDistributor.SelectedIndex > 0 ? ((Distributor)productMasterControl.cbbDistributor.SelectedItem) : null }; var eventArgs = new ProductMasterEventArgs {ProductMaster = productMaster}; EventUtility.fireEvent(SaveProductMasterEvent, sender, eventArgs); productMaster.ProductMasterId = eventArgs.ProductMaster.ProductMasterId; productMasterControl.txtProductMasterId.Text = productMaster.ProductMasterId; txtBarcode.Text = productMaster.Barcode; DrawBarcode(productMaster.Barcode); if (isNeedClosing) { this.Close(); } btnPrint.Visible = true; numericUpDown.Visible = true; btnPreview.Visible = true; lblMaVach.Visible = true; if (ClientInfo.getInstance().LoggedUser.Name.Equals("admin")) { btnDelete.Visible = true; } }
private void btnSave_Click(object sender, EventArgs e) { IList productSizeList = productMasterControl.lbxProductSize.SelectedItems; IList productColorList = productMasterControl.lbxProductColor.SelectedItems; var productMasters = new List<ProductMaster>(); if(string.IsNullOrEmpty(productMasterControl.txtProductName.Text)) { MessageBox.Show("Hãy nhập tên sản phẩm !"); return; } if(productMasterControl.cbbProductType.SelectedIndex < 0 ) { MessageBox.Show("Hãy chọn loại sản phẩm !"); return; } if (ProductMaster == null) { if (productSizeList.Count == 0 || productColorList.Count == 0) { MessageBox.Show("Hãy chọn màu sắc và kích cỡ sản phẩm"); return; } if (productSizeList.Count > 0) { foreach (ProductSize size in productSizeList) { bool addFlag = false; foreach (ProductColor color in productColorList) { productMasters.Add(CreateProductMaster(size, color)); addFlag = true; } if (!addFlag) { productMasters.Add(CreateProductMaster(size, null)); } } } else if (productColorList.Count > 0) { foreach (ProductColor color in productColorList) { productMasters.Add(CreateProductMaster(null, color)); } } else { productMasters.Add(CreateProductMaster(null, null)); } } else { // make sure that the product master can not be deleted int count = 0; IList newColorList = new ArrayList(); IList newSizeList = new ArrayList(); foreach (ProductColor colorNew in productMasterControl.lbxProductColor.SelectedItems) { bool found = false; foreach (ProductColor color in OldColorList) { if (color.ColorId == colorNew.ColorId) { count++; found = true; break; } } if (!found) { newColorList.Add(colorNew); } } if (count != OldColorList.Count) { MessageBox.Show("Không thể bỏ đi màu sắc sản phẩm.Bấm nút Trở về như cũ để hiển thị lại"); return; } count = 0; foreach (ProductSize sizeNew in productMasterControl.lbxProductSize.SelectedItems) { bool found = false; foreach (ProductSize size in OldSizeList) { if (size.SizeId == sizeNew.SizeId) { count++; found = true; break; } } if (!found) { newSizeList.Add(sizeNew); } } if (count != OldSizeList.Count) { MessageBox.Show("Không thể bỏ đi kích cỡ sản phẩm.Bấm nút Trở về như cũ để hiển thị lại"); return; } if (newColorList.Count > 0) { foreach (ProductColor color in newColorList) { foreach (ProductSize size in OldSizeList) { productMasters.Add(CreateProductMaster(size, color)); } foreach (ProductSize size in newSizeList) { productMasters.Add(CreateProductMaster(size, color)); } } } if (newSizeList.Count > 0) { foreach (ProductSize size in newSizeList) { foreach (ProductColor color in OldColorList) { productMasters.Add(CreateProductMaster(size, color)); } } } } var eventArgs = new ProductMasterEventArgs { CreatedProductMasterList = productMasters}; EventUtility.fireEvent(SaveProductMasterEvent, sender, eventArgs); if (eventArgs.EventResult != null) { MessageBox.Show("Lưu thành công"); ClearForm(); if (Status == ViewStatus.OPENDIALOG) { EventUtility.fireEvent(CloseProductMasterEvent, this, eventArgs); } } }
public void productMasterView_DeleteProductMasterEvent(object sender, ProductMasterEventArgs e) { if (!string.IsNullOrEmpty(e.ProductMasterId)) { ProductMasterLogic.Delete(new ProductMaster { ProductMasterId = e.ProductMasterId }); } }
private void LoadProductMaster() { var eventArgs = new ProductMasterEventArgs(); eventArgs.ProductMasterForInit = ProductMaster; EventUtility.fireEvent(InitProductMasterEvent, this, eventArgs); productMasterControl.typeBindingSource.DataSource = eventArgs.ProductTypeList; productMasterControl.cbbProductType.DisplayMember = "TypeName"; if (eventArgs.ProductSizeList.Count > 1) { eventArgs.ProductSizeList.RemoveAt(0); productMasterControl.sizeBindingSource.DataSource = eventArgs.ProductSizeList; } //productMasterControl.cbbProductSize.DisplayMember = "SizeName"; if (eventArgs.ProductColorList.Count > 1) { eventArgs.ProductColorList.RemoveAt(0); productMasterControl.colorBindingSource.DataSource = eventArgs.ProductColorList; } //productMasterControl.cbbProductColor.DisplayMember = "ColorName"; productMasterControl.countryBindingSource.DataSource = eventArgs.CountryList; productMasterControl.cbbCountry.DisplayMember = "CountryName"; productMasterControl.distributorBindingSource.DataSource = eventArgs.DistributorList; productMasterControl.cbbDistributor.DisplayMember = "DistributorName"; productMasterControl.manufacturerBindingSource.DataSource = eventArgs.ManufacturerList; productMasterControl.cbbManufacturer.DisplayMember = "ManufacturerName"; productMasterControl.packagerBindingSource.DataSource = eventArgs.PackagerList; productMasterControl.cbbPackager.DisplayMember = "PackagerName"; if (ProductMaster != null) { btnRevert.Visible = true; OldColorList = new ArrayList(); OldSizeList = new ArrayList(); productMasterControl.txtDescription.Text = ProductMaster.Description; productMasterControl.txtProductMasterId.Text = ProductMaster.ProductMasterId; productMasterControl.txtProductName.Text = ProductMaster.ProductName; int i = 0; if (ProductMaster.Country != null) { foreach (Country country in eventArgs.CountryList) { if (country.CountryId == ProductMaster.Country.CountryId) { productMasterControl.cbbCountry.SelectedIndex = i; } i++; } } productMasterControl.cbbCountry.Enabled = false; i = 0; if (ProductMaster.Distributor != null) { foreach (Distributor distributor in eventArgs.DistributorList) { if (distributor.DistributorId == ProductMaster.Distributor.DistributorId) { productMasterControl.cbbDistributor.SelectedIndex = i; } i++; } } productMasterControl.cbbDistributor.Enabled = false; i = 0; if (ProductMaster.ProductType != null) { foreach (ProductType productType in eventArgs.ProductTypeList) { if (productType.TypeId == ProductMaster.ProductType.TypeId) { productMasterControl.cbbProductType.SelectedIndex = i; } i++; } } productMasterControl.cbbProductType.Enabled = false; i = 0; if (ProductMaster.Manufacturer != null) { foreach (Manufacturer manufacturer in eventArgs.ManufacturerList) { if (manufacturer.ManufacturerId == ProductMaster.Manufacturer.ManufacturerId) { productMasterControl.cbbManufacturer.SelectedIndex = i; } i++; } } productMasterControl.cbbManufacturer.Enabled = false; i = 0; if (ProductMaster.Packager != null) { foreach (Packager packager in eventArgs.PackagerList) { if (packager.PackagerId == ProductMaster.Packager.PackagerId) { productMasterControl.cbbPackager.SelectedIndex = i; } i++; } } productMasterControl.cbbPackager.Enabled = false; i = 0; if (ProductMaster.Packager != null) { foreach (Packager packager in eventArgs.PackagerList) { if (packager.PackagerId == ProductMaster.Packager.PackagerId) { productMasterControl.cbbPackager.SelectedIndex = i; } i++; } } if (eventArgs.SameProductMasterList != null && eventArgs.SameProductMasterList.Count > 0) { foreach (ProductMaster master in eventArgs.SameProductMasterList) { i = 0; foreach (ProductColor color in eventArgs.ProductColorList) { if (master.ProductColor != null && master.ProductColor.ColorId == color.ColorId) { productMasterControl.lbxProductColor.SetSelected(i, true); bool add = true; foreach (ProductColor oldColor in OldColorList) { if (oldColor.ColorId == master.ProductColor.ColorId) { add = false; break; } } if (add) { OldColorList.Add(master.ProductColor); } break; } i++; } i = 0; foreach (ProductSize size in eventArgs.ProductSizeList) { if (master.ProductSize != null && master.ProductSize.SizeId == size.SizeId) { productMasterControl.lbxProductSize.SetSelected(i, true); bool add = true; foreach (ProductSize oldSize in OldSizeList) { if (oldSize.SizeId == master.ProductSize.SizeId) { add = false; break; } } if (add) { OldSizeList.Add(master.ProductSize); } break; } i++; } } } productMasterControl.btnCreateCountry.Enabled = false; productMasterControl.btnCreateDistributor.Enabled = false; productMasterControl.btnCreateManufacturer.Enabled = false; productMasterControl.btnCreatePackager.Enabled = false; productMasterControl.btnCreateType.Enabled = false; productMasterControl.btnSelect.Enabled = false; productMasterControl.txtImagePath.Text = ProductMaster.ImagePath; ShowProductImage(); } }
private void btnSave_Click(object sender, EventArgs e) { IList productSizeList = lstProductSizes.Items; IList productColorList = lstProductColors.Items; var productMasters = new List<ProductMaster>(); if (string.IsNullOrEmpty(txtProductName.Text)) { MessageBox.Show("Hãy nhập tên sản phẩm !"); return; } if (cbbProductType.SelectedIndex < 0) { MessageBox.Show("Hãy chọn loại sản phẩm !"); return; } if (Status == ViewStatus.ADD || Status == ViewStatus.OPENDIALOG) { if (productSizeList.Count == 0 || productColorList.Count == 0) { MessageBox.Show("Hãy chọn màu sắc và kích cỡ sản phẩm"); return; } if (productSizeList.Count > 0) { foreach (ProductSize size in productSizeList) { bool addFlag = false; foreach (ProductColor color in productColorList) { productMasters.Add(CreateProductMaster(size, color)); addFlag = true; } if (!addFlag) { productMasters.Add(CreateProductMaster(size, null)); } } } else if (productColorList.Count > 0) { foreach (ProductColor color in productColorList) { productMasters.Add(CreateProductMaster(null, color)); } } else { productMasters.Add(CreateProductMaster(null, null)); } } else // update ProductMasters { // make sure that the product master can not be deleted int count = 0; IList newColorList = new ArrayList(); IList newSizeList = new ArrayList(); newColorList = lstProductColors.EnabledItems; newSizeList = lstProductSizes.EnabledItems; if (newColorList.Count > 0) { foreach (ProductColor color in newColorList) { foreach (ProductSize size in OldSizeList) { productMasters.Add(CreateProductMaster(size, color)); } } } if (newSizeList.Count > 0) { foreach (ProductSize size in newSizeList) { foreach (ProductColor color in OldColorList) { productMasters.Add(CreateProductMaster(size, color)); } } } } var eventArgs = new ProductMasterEventArgs { CreatedProductMasterList = productMasters }; // get old product master if (OldProductMasterList != null) { foreach (ProductMaster master in OldProductMasterList) { master.ProductName = txtProductName.Text.Trim(); master.Description = txtDescription.Text.Trim(); master.ImagePath = txtImagePath.Text; } eventArgs.UpdateProductMasterList = OldProductMasterList; } EventUtility.fireEvent(SaveProductMasterEvent, sender, eventArgs); if (eventArgs.EventResult != null) { MessageBox.Show("Lưu thành công"); if (Status == ViewStatus.OPENDIALOG || Status == ViewStatus.EDIT) { EventUtility.fireEvent(CloseProductMasterEvent, this, eventArgs); } else { ClearForm(); } } }