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);
        }
        // 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());
        }
Exemple #3
0
        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);
        }