예제 #1
0
    private bool CheckData(DataTable dt)
    {
        int    TotalCount = 0, SuccessCount = 0, FailCount = 0;
        string Message = string.Empty;

        try
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                TotalCount++;
                bool IsValid = true;
                int  CountryId = 0, StateId = 0, CityId = 0;

                string Connecter = " in Record-" + TotalCount.ToString() + ".<br />";

                #region Value Initialization

                CountryName = dt.Rows[i][CountryNameColumn].ToString().Trim();
                StateName   = dt.Rows[i][StateNameColumn].ToString().Trim();
                CityName    = dt.Rows[i][CityNameColumn].ToString().Trim();
                AreaName    = dt.Rows[i][AreaNameColumn].ToString().Trim();

                #endregion

                #region Check Country Name

                if (IsValid)
                {
                    if (CountryName.zIsNullOrEmpty())
                    {
                        Message += CS.Arrow + "Country Name Is Empty" + Connecter;
                        IsValid  = false;
                    }
                }

                if (IsValid)
                {
                    var lstCountry = new Country()
                    {
                        CountryName = CountryName.ToLower(), eStatus = (int)eStatus.Active,
                    }.SelectList <Country>();
                    if (lstCountry.Count == 0)
                    {
                        Message += CS.Arrow + "Country is Invalid" + Connecter;
                        IsValid  = false;
                    }
                    else
                    {
                        CountryId = lstCountry[0].CountryId.Value;
                    }
                }

                #endregion

                #region Check State Name

                if (IsValid)
                {
                    if (StateName.zIsNullOrEmpty())
                    {
                        Message += CS.Arrow + "State Name Is Empty" + Connecter;
                        IsValid  = false;
                    }
                }

                if (IsValid)
                {
                    var lstState = new State()
                    {
                        StateName = StateName.ToLower(), CountryId = CountryId, eStatus = (int)eStatus.Active
                    }.SelectList <State>();
                    if (lstState.Count == 0)
                    {
                        Message += CS.Arrow + "State is Invalid" + Connecter;
                        IsValid  = false;
                    }
                    else
                    {
                        StateId = lstState[0].StateId.Value;
                    }
                }

                #endregion

                #region Check City Name

                if (IsValid)
                {
                    if (CityName.zIsNullOrEmpty())
                    {
                        Message += CS.Arrow + "City Name Is Empty" + Connecter;
                        IsValid  = false;
                    }
                }

                if (IsValid)
                {
                    var lstCity = new City()
                    {
                        CityName = CityName.ToLower(), StateId = StateId, eStatus = (int)eStatus.Active
                    }.SelectList <City>();
                    if (lstCity.Count == 0)
                    {
                        Message += CS.Arrow + "City is Invalid" + Connecter;
                        IsValid  = false;
                    }
                    else
                    {
                        CityId = lstCity[0].StateId.Value;
                    }
                }

                #endregion

                #region Check Area Name

                if (IsValid)
                {
                    if (AreaName.zIsNullOrEmpty())
                    {
                        Message += CS.Arrow + "Area Name Is Empty" + Connecter;
                        IsValid  = false;
                    }
                }

                if (IsValid)
                {
                    string RepeateColumn = string.Empty;
                    if (CU.IsRepeateExcelRow(dt, i, AreaName, AreaNameColumn, CityName, CityNameColumn, StateName, StateNameColumn, ref RepeateColumn))
                    {
                        Message += CS.Arrow + "Area " + AreaName + " is Repeating in Record-" + RepeateColumn;
                        IsValid  = false;
                    }
                }

                if (IsValid)
                {
                    DataTable dtAreaName = new Query()
                    {
                        CountryId  = CountryId,
                        StateId    = StateId,
                        CityId     = CityId,
                        AreaName   = AreaName,
                        eStatusNot = (int)eStatus.Delete
                    }.Select(eSP.qry_Area);

                    if (dtAreaName.Rows.Count > 0 && !chkReplace.Checked)
                    {
                        string Status = dtAreaName.Rows[0][CS.eStatus].zToInt().Value == (int)eStatus.Deactive ? "(Deactive)" : string.Empty;
                        Message += CS.Arrow + AreaName + " Area is already exist" + Status + "." + Connecter;
                        IsValid  = false;
                    }
                }

                #endregion

                #region Check Pincode

                if (!Pincode.zIsNullOrEmpty())
                {
                    if (IsValid)
                    {
                        string RepeateColumn = string.Empty;
                        if (CU.IsRepeateExcelRow(dt, i, Pincode, PincodeColumn, string.Empty, null, string.Empty, null, ref RepeateColumn))
                        {
                            Message += CS.Arrow + "Pincode " + Pincode + " is Repeating in Record-" + RepeateColumn;
                            IsValid  = false;
                        }
                    }

                    if (IsValid)
                    {
                        DataTable dtAreaPincode = new Query()
                        {
                            Pincode    = Pincode,
                            eStatusNot = (int)eStatus.Delete
                        }.Select(eSP.qry_Area);

                        if (dtAreaPincode.Rows.Count > 0 && !chkReplace.Checked)
                        {
                            string Status = dtAreaPincode.Rows[0][CS.eStatus].zToInt().Value == (int)eStatus.Deactive ? "(Deactive)" : string.Empty;
                            Message += CS.Arrow + Pincode + " Pincode is already exist" + Status + "." + Connecter;
                            IsValid  = false;
                        }
                    }
                }

                #endregion

                if (IsValid)
                {
                    SuccessCount++;
                }
                else
                {
                    FailCount++;
                    if (FailCount >= 10)
                    {
                        break;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            CU.ZMessage(eMsgType.Error, string.Empty, ex.Message, 0);
            return(false);
        }

        if (FailCount == 0)
        {
            return(true);
        }
        else
        {
            CU.SetErrorExcelMessage(Message, SuccessCount, FailCount);
            return(false);
        }
    }