private bool IsValid() { bool result = true; errorProvider.SetError(txtCode, string.Empty); #region Class Code 唔可以吉 if (txtCode.Text.Length == 0) { errorProvider.SetError(txtCode, "Cannot be blank!"); errorProvider.SetIconAlignment(txtCode, ErrorIconAlignment.TopLeft); result = false; } #endregion #region 新增,要 check Tag Code 係咪 in use if (_AppendixId == Guid.Empty) { switch (_AppendixType) { case ProductHelper.Appendix.Appendix1: #region ProductAppendix1 if (ProductAppendix1Ex.IsAppendixCodeInUse(txtCode.Text.Trim())) { errorProvider.SetError(txtCode, "Class Code in use"); errorProvider.SetIconAlignment(txtCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Appendix.Appendix2: #region ProductAppendix2 if (ProductAppendix2Ex.IsAppendixCodeInUse(txtCode.Text.Trim())) { errorProvider.SetError(txtCode, "Class Code in use"); errorProvider.SetIconAlignment(txtCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion case ProductHelper.Appendix.Appendix3: #region ProductAppendix3 if (ProductAppendix3Ex.IsAppendixCodeInUse(txtCode.Text.Trim())) { errorProvider.SetError(txtCode, "Class Code in use"); errorProvider.SetIconAlignment(txtCode, ErrorIconAlignment.TopLeft); result = false; } break; #endregion } } #endregion return(result); }
// 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()); }