private bool IsValid() { bool result = true; #region Class Code 唔可以吉 errorProvider.SetError(txtCode, string.Empty); if (txtCode.Text.Length == 0) { errorProvider.SetError(txtCode, "Cannot be blank!"); return(false); } #endregion #region 新增,要 check Class Code 係咪 in use errorProvider.SetError(txtCode, string.Empty); var isClassCodeInUse = _ClassMode == ProductHelper.Classes.Class1 ? ProductClass1Ex.IsClassCodeInUse(txtCode.Text.Trim()) : _ClassMode == ProductHelper.Classes.Class2 ? ProductClass2Ex.IsClassCodeInUse(txtCode.Text.Trim()) : _ClassMode == ProductHelper.Classes.Class3 ? ProductClass3Ex.IsClassCodeInUse(txtCode.Text.Trim()) : _ClassMode == ProductHelper.Classes.Class4 ? ProductClass4Ex.IsClassCodeInUse(txtCode.Text.Trim()) : _ClassMode == ProductHelper.Classes.Class5 ? ProductClass5Ex.IsClassCodeInUse(txtCode.Text.Trim()) : _ClassMode == ProductHelper.Classes.Class6 ? ProductClass6Ex.IsClassCodeInUse(txtCode.Text.Trim()) : false; if (_ClassId == Guid.Empty && isClassCodeInUse) { errorProvider.SetError(txtCode, "Class Code in use"); return(false); } #endregion return(result); }
private void Delete() { bool result = false; switch (_ClassType) { case ProductHelper.Classes.Class1: result = ProductClass1Ex.Delete(_ClassId); break; case ProductHelper.Classes.Class2: result = ProductClass2Ex.Delete(_ClassId); break; case ProductHelper.Classes.Class3: result = ProductClass3Ex.Delete(_ClassId); break; case ProductHelper.Classes.Class4: result = ProductClass4Ex.Delete(_ClassId); break; case ProductHelper.Classes.Class5: result = ProductClass5Ex.Delete(_ClassId); break; case ProductHelper.Classes.Class6: result = ProductClass6Ex.Delete(_ClassId); break; } MessageBox.Show(result ? "Record Removed" : "Can't Delete Record...", "Delete Result"); }
private void FillClass6() { ProductClass6Ex.LoadCombo(ref cboClass6, "Class6Code", false, true, "", ""); /** * cboClass6.Items.Clear(); * * string[] orderBy = new string[] { "Class6Code" }; * ProductClass6Collection oC6List = ProductClass6.LoadCollection(orderBy, true); * oC6List.Add(new ProductClass6()); * cboClass6.DataSource = oC6List; * cboClass6.DisplayMember = "Class6Code"; * cboClass6.ValueMember = "Class6Id"; */ }
private void FillFromClass6List() { ProductClass6Ex.LoadCombo(ref cboClass6_From, "Class6Code", false, true, "", ""); /** * cboClass6_From.Items.Clear(); * * string[] orderBy = new string[] { "Class6Code" }; * ProductClass6Collection prodCls6List = ProductClass6.LoadCollection(orderBy, true); * prodCls6List.Add(new ProductClass6()); * cboClass6_From.DataSource = prodCls6List; * cboClass6_From.DisplayMember = "Class6Code"; * cboClass6_From.ValueMember = "Class6Id"; */ cboClass6_From.SelectedIndex = cboClass6_From.Items.Count - 1; }
private void FillClasses() { /** * FillClass1(); * FillClass2(); * FillClass3(); * FillClass4(); * FillClass5(); * FillClass6(); */ ProductClass1Ex.LoadCombo(ref cboClass1, "Class1Code", false, true, "", ""); ProductClass2Ex.LoadCombo(ref cboClass2, "Class2Code", false, true, "", ""); ProductClass3Ex.LoadCombo(ref cboClass3, "Class3Code", false, true, "", ""); ProductClass4Ex.LoadCombo(ref cboClass4, "Class4Code", false, true, "", ""); ProductClass5Ex.LoadCombo(ref cboClass5, "Class5Code", false, true, "", ""); ProductClass6Ex.LoadCombo(ref cboClass6, "Class6Code", false, true, "", ""); }
private void FillComboBox() { string fieldText = this.ClassType.Trim() + "Code"; switch (this.ClassType.Trim().ToUpper()) { case "CLASS1": ProductClass1Ex.LoadCombo(ref cmbFrom, fieldText, false); ProductClass1Ex.LoadCombo(ref cmbTo, fieldText, false); break; case "CLASS2": ProductClass2Ex.LoadCombo(ref cmbFrom, fieldText, false); ProductClass2Ex.LoadCombo(ref cmbTo, fieldText, false); break; case "CLASS3": ProductClass3Ex.LoadCombo(ref cmbFrom, fieldText, false); ProductClass3Ex.LoadCombo(ref cmbTo, fieldText, false); break; case "CLASS4": ProductClass4Ex.LoadCombo(ref cmbFrom, fieldText, false); ProductClass4Ex.LoadCombo(ref cmbTo, fieldText, false); break; case "CLASS5": ProductClass5Ex.LoadCombo(ref cmbFrom, fieldText, false); ProductClass5Ex.LoadCombo(ref cmbTo, fieldText, false); break; case "CLASS6": ProductClass6Ex.LoadCombo(ref cmbFrom, fieldText, false); ProductClass6Ex.LoadCombo(ref cmbTo, fieldText, false); break; } cmbTo.SelectedIndex = cmbTo.Items.Count - 1; }
// Verify the data from excel file exists or not private string VerifyDuplicatedData(int iCount, DataRow row) { iCount = iCount + 1; StringBuilder returnResult = new StringBuilder(); StringBuilder verifiedResult = new StringBuilder(); verifiedResult.Append("Row#").Append(iCount.ToString()).Append(":"); int iLen = verifiedResult.ToString().Length; // Check whether the StockCode is duplicate or not //string sql = @"STKCODE = '" + Utility.VerifyQuotes(row[colSTKCode].ToString().Trim()) + "' AND APPENDIX1 = '" + Utility.VerifyQuotes(row[colAppendix1].ToString().Trim()) // + "' AND APPENDIX2 = '" + Utility.VerifyQuotes(row[colAppendix2].ToString().Trim()) + "' AND APPENDIX3 = '" + Utility.VerifyQuotes(row[colAppendix3].ToString().Trim()) + "'"; //RT2020.DAL.Product oStockItem = RT2020.DAL.Product.LoadWhere(sql); //if (oStockItem != null) if (ProductHelper.IsDuplicated( Utility.VerifyQuotes(row[colSTKCode].ToString().Trim()), Utility.VerifyQuotes(row[colAppendix1].ToString().Trim()), Utility.VerifyQuotes(row[colAppendix2].ToString().Trim()), Utility.VerifyQuotes(row[colAppendix3].ToString().Trim()))) { returnResult.Append("Duplicated Stock Code;"); } // Appendix1 //sql = "Appendix1Code = '" + Utility.VerifyQuotes(row[colAppendix1].ToString().Trim()) + "'"; //ProductAppendix1 oApp1 = ProductAppendix1.LoadWhere(sql); //if (oApp1 != null) if (ProductAppendix1Ex.IsAppendixCodeInUse(Utility.VerifyQuotes(row[colAppendix3].ToString()))) { verifiedResult.Append(colAppendix1).Append(";"); } // Appendix2 //sql = "Appednix2Code = '" + Utility.VerifyQuotes(row[colAppendix2].ToString().Trim()) + "'"; //ProductAppendix2 oApp2 = ProductAppendix2.LoadWhere(sql); //if (oApp2 != null) if (ProductAppendix2Ex.IsAppendixCodeInUse(Utility.VerifyQuotes(row[colAppendix3].ToString()))) { verifiedResult.Append(colAppendix2).Append(";"); } // Appendix3 //sql = "Appendix3Code = '" + Utility.VerifyQuotes(row[colAppendix3].ToString().Trim()) + "'"; //ProductAppendix3 oApp3 = ProductAppendix3.LoadWhere(sql); //if (oApp3 != null) if (ProductAppendix3Ex.IsAppendixCodeInUse(Utility.VerifyQuotes(row[colAppendix3].ToString()))) { verifiedResult.Append(colAppendix3).Append(";"); } // Class1 //sql = "Class1Code = '" + Utility.VerifyQuotes(row[colClass1].ToString().Trim()) + "'"; //ProductClass1 oCls1 = ProductClass1.LoadWhere(sql); //if (oCls1 != null) if (ProductClass1Ex.IsClassCodeInUse(Utility.VerifyQuotes(row[colClass1].ToString().Trim()))) { verifiedResult.Append(colClass1).Append(";"); } // Class2 //sql = "Class2Code = '" + Utility.VerifyQuotes(row[colClass2].ToString().Trim()) + "'"; //ProductClass2 oCls2 = ProductClass2.LoadWhere(sql); //if (oCls2 != null) if (ProductClass2Ex.IsClassCodeInUse(Utility.VerifyQuotes(row[colClass2].ToString().Trim()))) { verifiedResult.Append(colClass2).Append(";"); } // Class3 //sql = "Class3Code = '" + Utility.VerifyQuotes(row[colClass3].ToString().Trim()) + "'"; //ProductClass3 oCls3 = ProductClass3.LoadWhere(sql); //if (oCls3 != null) if (ProductClass3Ex.IsClassCodeInUse(Utility.VerifyQuotes(row[colClass3].ToString().Trim()))) { verifiedResult.Append(colClass3).Append(";"); } // Class4 //sql = "Class4Code = '" + Utility.VerifyQuotes(row[colClass4].ToString().Trim()) + "'"; //ProductClass4 oCls4 = ProductClass4.LoadWhere(sql); //if (oCls4 != null) if (ProductClass4Ex.IsClassCodeInUse(Utility.VerifyQuotes(row[colClass4].ToString().Trim()))) { verifiedResult.Append(colClass4).Append(";"); } // Class5 //sql = "Class5Code = '" + Utility.VerifyQuotes(row[colClass5].ToString().Trim()) + "'"; //ProductClass5 oCls5 = ProductClass5.LoadWhere(sql); //if (oCls5 != null) if (ProductClass5Ex.IsClassCodeInUse(Utility.VerifyQuotes(row[colClass5].ToString().Trim()))) { verifiedResult.Append(colClass5).Append(";"); } // Class6 //sql = "Class6Code = '" + Utility.VerifyQuotes(row[colClass6].ToString().Trim()) + "'"; //ProductClass6 oCls6 = ProductClass6.LoadWhere(sql); //if (oCls6 != null) if (ProductClass6Ex.IsClassCodeInUse(Utility.VerifyQuotes(row[colClass6].ToString().Trim()))) { verifiedResult.Append(colClass6).Append(";"); } // Barcode var barcode = Utility.VerifyQuotes(row[colSTKCode].ToString().Trim()) + Utility.VerifyQuotes(row[colAppendix1].ToString().Trim()) + Utility.VerifyQuotes(row[colAppendix2].ToString().Trim()) + Utility.VerifyQuotes(row[colAppendix3].ToString().Trim()); var sql = "BARCODE = '" + barcode + "'"; if (ProductBarcodeEx.IsBarcodeInUse(barcode)) { returnResult.Append("Duplicated Barcode;"); } if (verifiedResult.ToString().Length > iLen) { duplicatedRec.Add(verifiedResult.ToString()); } return(returnResult.ToString()); }
private void CreateProducts(ListViewItem listItem) { using (var ctx = new EF6.RT2020Entities()) { // Check BatchId(listItem.SubItems[1].Text) and Stock Code(listItem.SubItems[2].Text) Guid batchId = Guid.Empty; if (IsValid() && Guid.TryParse(listItem.SubItems[1].Text, out batchId) && listItem.SubItems[2].Text.Length > 0) { var oBatch = ctx.ProductBatch.Find(batchId); if (oBatch != null) { string a1 = listItem.SubItems[3].Text.Trim(); string a2 = listItem.SubItems[4].Text.Trim(); string a3 = listItem.SubItems[5].Text.Trim(); Guid a1Id = Guid.Empty, a2Id = Guid.Empty, a3Id = Guid.Empty; Guid.TryParse(listItem.SubItems[6].Text, out a1Id); Guid.TryParse(listItem.SubItems[7].Text, out a2Id); Guid.TryParse(listItem.SubItems[8].Text, out a3Id); string prodCode = listItem.SubItems[2].Text + a1 + a2 + a3; if (prodCode.Length <= 22) { var stkcode = listItem.SubItems[2].Text.Trim(); StringBuilder sql = new StringBuilder(); sql.Append(" STKCODE = '").Append(listItem.SubItems[2].Text.Trim()).Append("' "); sql.Append(" AND APPENDIX1 = '").Append(a1.Trim()).Append("' "); sql.Append(" AND APPENDIX2 = '").Append(a2.Trim()).Append("' "); sql.Append(" AND APPENDIX3 = '").Append(a3.Trim()).Append("' "); var oItem = ctx.Product.Where(x => x.STKCODE == stkcode && x.APPENDIX1 == a1 && x.APPENDIX2 == a2 && x.APPENDIX3 == a3).FirstOrDefault(); if (oItem == null) { #region add new Product oItem = new EF6.Product(); oItem.ProductId = Guid.NewGuid(); oItem.STKCODE = listItem.SubItems[2].Text; oItem.APPENDIX1 = a1; oItem.APPENDIX2 = a2; oItem.APPENDIX3 = a3; oItem.Status = Convert.ToInt32(EnumHelper.Status.Active.ToString("d")); oItem.CLASS1 = oBatch.CLASS1; oItem.CLASS2 = oBatch.CLASS2; oItem.CLASS3 = oBatch.CLASS3; oItem.CLASS4 = oBatch.CLASS4; oItem.CLASS5 = oBatch.CLASS5; oItem.CLASS6 = oBatch.CLASS6; oItem.ProductName = oBatch.Description; oItem.ProductName_Chs = oBatch.Description; oItem.ProductName_Cht = oBatch.Description; oItem.Remarks = oBatch.REMARKS; oItem.NormalDiscount = oBatch.NRDISC.Value; oItem.UOM = oBatch.MAINUNIT; oItem.NatureId = ProductNatureEx.GetIdByCode(oBatch.NATURE); oItem.FixedPriceItem = false; oItem.CreatedBy = ConfigHelper.CurrentUserId; oItem.CreatedOn = DateTime.Now; oItem.ModifiedBy = ConfigHelper.CurrentUserId; oItem.ModifiedOn = DateTime.Now; ctx.Product.Add(oItem); var productId = oItem.ProductId; #endregion #region SaveProductBarcode(oBatch, productId, prodCode); var oBarcode = ctx.ProductBarcode.Where(x => x.ProductId == productId).FirstOrDefault(); if (oBarcode == null) { oBarcode = new EF6.ProductBarcode(); oBarcode.ProductBarcodeId = Guid.NewGuid(); oBarcode.ProductId = productId; oBarcode.Barcode = prodCode; oBarcode.BarcodeType = "INTER"; oBarcode.PrimaryBarcode = true; oBarcode.DownloadToPOS = (oBatch.RETAILITEM == "F") ? false : true; oBarcode.DownloadToCounter = (oBatch.COUNTER_ITEM == "F") ? false : true; ctx.ProductBarcode.Add(oBarcode); ctx.SaveChanges(); } #endregion #region Appendix / Class System.Guid c1Id = ProductClass1Ex.GetClassIdByCode(oBatch.CLASS1); System.Guid c2Id = ProductClass2Ex.GetClassIdByCode(oBatch.CLASS2); System.Guid c3Id = ProductClass3Ex.GetClassIdByCode(oBatch.CLASS3); System.Guid c4Id = ProductClass4Ex.GetClassIdByCode(oBatch.CLASS4); System.Guid c5Id = ProductClass5Ex.GetClassIdByCode(oBatch.CLASS5); System.Guid c6Id = ProductClass6Ex.GetClassIdByCode(oBatch.CLASS6); // SaveProductCode(productId, a1Id, a2Id, a3Id, c1Id, c2Id, c3Id, c4Id, c5Id, c6Id); var oCode = ctx.ProductCode.Where(x => x.ProductId == productId).FirstOrDefault(); if (oCode == null) { oCode = new EF6.ProductCode(); oCode.CodeId = Guid.NewGuid(); oCode.ProductId = productId; oCode.Appendix1Id = a1Id; oCode.Appendix2Id = a2Id; oCode.Appendix3Id = a3Id; ctx.ProductCode.Add(oCode); } oCode.Class1Id = c1Id; oCode.Class2Id = c2Id; oCode.Class3Id = c3Id; oCode.Class4Id = c4Id; oCode.Class5Id = c5Id; oCode.Class6Id = c6Id; ctx.SaveChanges(); #endregion // Product Price #region SaveProductSupplement(oBatch, oItem.ProductId); //string sql = "ProductId = '" + productId.ToString() + "'"; var oProdSupp = ctx.ProductSupplement.Where(x => x.ProductId == productId).FirstOrDefault(); if (oProdSupp == null) { oProdSupp = new EF6.ProductSupplement(); oProdSupp.SupplementId = Guid.NewGuid(); oProdSupp.ProductId = productId; ctx.ProductSupplement.Add(oProdSupp); } oProdSupp.VendorCurrencyCode = oBatch.VCURR; oProdSupp.VendorPrice = oBatch.VPRC; oProdSupp.ProductName_Memo = oBatch.DESC_MEMO; oProdSupp.ProductName_Pole = oBatch.DESC_POLE; ctx.SaveChanges(); #endregion #region SaveProductPrice(oBatch, oItem.ProductId); SaveProductPrice(productId, ProductHelper.Prices.BASPRC.ToString(), "HKD", oBatch.BASPRC.ToString()); SaveProductPrice(productId, ProductHelper.Prices.ORIPRC.ToString(), "HKD", oBatch.ORIPRC.ToString()); SaveProductPrice(productId, ProductHelper.Prices.VPRC.ToString(), oBatch.VCURR, oBatch.VPRC.ToString()); SaveProductPrice(productId, ProductHelper.Prices.WHLPRC.ToString(), "HKD", oBatch.WHLPRC.ToString()); #endregion // Remarks #region SaveProductRemarks(oBatch, oItem.ProductId); var oRemarks = ctx.ProductRemarks.Where(x => x.ProductId == productId).FirstOrDefault(); if (oRemarks == null) { oRemarks = new EF6.ProductRemarks(); oRemarks.ProductRemarksId = Guid.NewGuid(); oRemarks.ProductId = productId; ctx.ProductRemarks.Add(oRemarks); } oRemarks.Photo = oBatch.PHOTO; oRemarks.BinX = oBatch.BINX; oRemarks.BinY = oBatch.BINY; oRemarks.BinZ = oBatch.BINZ; oRemarks.DownloadToShop = (oBatch.RETAILITEM == "F") ? false : true; oRemarks.OffDisplayItem = (oBatch.OFF_DISPLAY_ITEM == "F") ? false : true; oRemarks.DownloadToCounter = (oBatch.COUNTER_ITEM == "F") ? false : true; oRemarks.REMARK1 = oBatch.REMARK1; oRemarks.REMARK2 = oBatch.REMARK2; oRemarks.REMARK3 = oBatch.REMARK3; oRemarks.REMARK4 = oBatch.REMARK4; oRemarks.REMARK5 = oBatch.REMARK5; oRemarks.REMARK6 = oBatch.REMARK6; ctx.SaveChanges(); #endregion oBatch.STATUS = "OK"; ctx.SaveChanges(); } } } } } }
private bool IsValid() { bool result = true; errorProvider.SetError(txtClassCode, string.Empty); #region Class Code 唔可以吉 if (txtClassCode.Text.Length == 0) { errorProvider.SetError(txtClassCode, "Cannot be blank!"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } #endregion #region 新增,要 check Tag Code 係咪 in use if (_ClassId == Guid.Empty) { switch (_ClassType) { case ProductHelper.Classes.Class1: #region ProductClass1 if (ProductClass1Ex.IsClassCodeInUse(txtClassCode.Text.Trim())) { errorProvider.SetError(txtClassCode, "Class Code in use"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Classes.Class2: #region ProductClass2 if (ProductClass2Ex.IsClassCodeInUse(txtClassCode.Text.Trim())) { errorProvider.SetError(txtClassCode, "Class Code in use"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Classes.Class3: #region ProductClass3 if (ProductClass3Ex.IsClassCodeInUse(txtClassCode.Text.Trim())) { errorProvider.SetError(txtClassCode, "Class Code in use"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Classes.Class4: #region ProductClass4 if (ProductClass4Ex.IsClassCodeInUse(txtClassCode.Text.Trim())) { errorProvider.SetError(txtClassCode, "Class Code in use"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Classes.Class5: #region ProductClass5 if (ProductClass5Ex.IsClassCodeInUse(txtClassCode.Text.Trim())) { errorProvider.SetError(txtClassCode, "Class Code in use"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Classes.Class6: #region ProductClass6 if (ProductClass6Ex.IsClassCodeInUse(txtClassCode.Text.Trim())) { errorProvider.SetError(txtClassCode, "Class Code in use"); errorProvider.SetIconAlignment(txtClassCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion } } #endregion return(result); }
private void FillParentClassList() { string sql; string[] orderBy; switch (_ClassMode) { case ProductHelper.Classes.Class1: #region fill Class1 combo sql = "Class1Id NOT IN ('" + _ClassId.ToString() + "')"; orderBy = new string[] { "Class1Code" }; ProductClass1Ex.LoadCombo(ref cboParentClass, "Class1Code", false, true, "", sql, orderBy); ProductClass1Ex.LoadCombo(ref cboAltClass, "Class1Code", false, true, "", sql, orderBy); break; #endregion case ProductHelper.Classes.Class2: #region fill Class2 combo sql = "Class2Id NOT IN ('" + _ClassId.ToString() + "')"; orderBy = new string[] { "Class2Code" }; ProductClass2Ex.LoadCombo(ref cboParentClass, "Class2Code", false, true, "", sql, orderBy); ProductClass2Ex.LoadCombo(ref cboAltClass, "Class2Code", false, true, "", sql, orderBy); break; #endregion case ProductHelper.Classes.Class3: #region fill Class3 combo sql = "Class3Id NOT IN ('" + _ClassId.ToString() + "')"; orderBy = new string[] { "Class3Code" }; ProductClass3Ex.LoadCombo(ref cboParentClass, "Class3Code", false, true, "", sql, orderBy); ProductClass3Ex.LoadCombo(ref cboAltClass, "Class3Code", false, true, "", sql, orderBy); break; #endregion case ProductHelper.Classes.Class4: #region fill Class4 combo sql = "Class4Id NOT IN ('" + _ClassId.ToString() + "')"; orderBy = new string[] { "Class4Code" }; ProductClass4Ex.LoadCombo(ref cboParentClass, "Class4Code", false, true, "", sql, orderBy); ProductClass4Ex.LoadCombo(ref cboAltClass, "Class4Code", false, true, "", sql, orderBy); break; #endregion case ProductHelper.Classes.Class5: #region fill Class5 combo sql = "Class5Id NOT IN ('" + _ClassId.ToString() + "')"; orderBy = new string[] { "Class5Code" }; ProductClass5Ex.LoadCombo(ref cboParentClass, "Class5Code", false, true, "", sql, orderBy); ProductClass5Ex.LoadCombo(ref cboAltClass, "Class5Code", false, true, "", sql, orderBy); break; #endregion case ProductHelper.Classes.Class6: #region fill Class6 combo sql = "Class6Id NOT IN ('" + _ClassId.ToString() + "')"; orderBy = new string[] { "Class6Code" }; ProductClass6Ex.LoadCombo(ref cboParentClass, "Class6Code", false, true, "", sql, orderBy); ProductClass6Ex.LoadCombo(ref cboAltClass, "Class6Code", false, true, "", sql, orderBy); break; #endregion } }