//public ICollection<ErrorHandler> SaveCustomer_Tax(Customer_Tax argCustomer_Tax)
        //{
        //    List<ErrorHandler> lstErr = new List<ErrorHandler>();
        //    DataAccess da = new DataAccess();
        //    try
        //    {
        //        if (blnIsCustomer_TaxExists(argCustomer_Tax.CustomerCode, argCustomer_Tax.CountryCode, argCustomer_Tax.TaxCategoryCode, argCustomer_Tax.TaxClassCode, argCustomer_Tax.ClientCode) == false)
        //        {

        //            da.Open_Connection();
        //            da.BEGIN_TRANSACTION();
        //            InsertCustomer_Tax(argCustomer_Tax, da, lstErr);
        //            foreach (ErrorHandler objerr in lstErr)
        //            {
        //                if (objerr.Type == "E")
        //                {
        //                    da.ROLLBACK_TRANSACTION();
        //                    return lstErr;
        //                }
        //            }
        //        }
        //        else
        //        {
        //            da.Open_Connection();
        //            da.BEGIN_TRANSACTION();
        //            UpdateCustomer_Tax(argCustomer_Tax, da, lstErr);
        //            foreach (ErrorHandler objerr in lstErr)
        //            {
        //                if (objerr.Type == "E")
        //                {
        //                    da.ROLLBACK_TRANSACTION();
        //                    return lstErr;
        //                }
        //            }
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        if (da != null)
        //        {
        //            da.ROLLBACK_TRANSACTION();
        //        }
        //        objErrorHandler.Type = ErrorConstant.strAboartType;
        //        objErrorHandler.MsgId = 0;
        //        objErrorHandler.Module = ErrorConstant.strInsertModule;
        //        objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
        //        objErrorHandler.Message = ex.Message.ToString();
        //        objErrorHandler.RowNo = 0;
        //        objErrorHandler.FieldName = "";
        //        objErrorHandler.LogCode = "";
        //        lstErr.Add(objErrorHandler);
        //    }
        //    finally
        //    {
        //        if (da != null)
        //        {
        //            da.Close_Connection();
        //            da = null;
        //        }
        //    }
        //    return lstErr;
        //}

        public void SaveCustomer_Tax(Customer_Tax argCustomer_Tax, DataAccess da, List <ErrorHandler> lstErr)
        {
            try
            {
                if (blnIsCustomer_TaxExists(argCustomer_Tax.CustomerCode, argCustomer_Tax.CountryCode, argCustomer_Tax.TaxCategoryCode, argCustomer_Tax.TaxClassCode, argCustomer_Tax.ClientCode, da) == false)
                {
                    InsertCustomer_Tax(argCustomer_Tax, da, lstErr);
                }
                else
                {
                    UpdateCustomer_Tax(argCustomer_Tax, da, lstErr);
                }
            }
            catch (Exception ex)
            {
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strDetailModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
            }
        }
        private Customer_Tax objCreateCustomer_Tax(DataRow dr)
        {
            Customer_Tax tCustomer_Tax = new Customer_Tax();

            tCustomer_Tax.SetObjectInfo(dr);
            return(tCustomer_Tax);
        }
        public Customer_Tax objGetCustomer_Tax(string argCustomerCode, string argCountryCode, string argTaxCategoryCode, string argTaxClassCode, string argClientCode)
        {
            Customer_Tax argCustomer_Tax = new Customer_Tax();
            DataSet      DataSetToFill   = new DataSet();

            if (argCustomerCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            if (argCountryCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            if (argTaxCategoryCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            if (argTaxClassCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            if (argClientCode.Trim() == "")
            {
                goto ErrorHandlers;
            }

            DataSetToFill = this.GetCustomer_Tax(argCustomerCode, argCountryCode, argTaxCategoryCode, argTaxClassCode, argClientCode);

            if (DataSetToFill.Tables[0].Rows.Count <= 0)
            {
                goto Finish;
            }
            argCustomer_Tax = this.objCreateCustomer_Tax((DataRow)DataSetToFill.Tables[0].Rows[0]);

            goto Finish;

ErrorHandlers:

Finish:
            DataSetToFill = null;

            return(argCustomer_Tax);
        }
        public ICollection <Customer_Tax> colGetCustomer_Tax(DataTable dt, string argUserName, string clientCode)
        {
            List <Customer_Tax> lst             = new List <Customer_Tax>();
            Customer_Tax        objCustomer_Tax = null;

            foreach (DataRow dr in dt.Rows)
            {
                objCustomer_Tax = new Customer_Tax();
                objCustomer_Tax.CustomerCode    = Convert.ToString(dr["CustomerCode"]).Trim();
                objCustomer_Tax.CountryCode     = Convert.ToString(dr["CountryCode"]).Trim();
                objCustomer_Tax.TaxCategoryCode = Convert.ToString(dr["TaxCategoryCode"]).Trim();
                objCustomer_Tax.TaxClassCode    = Convert.ToString(dr["TaxClassCode"]).Trim();
                objCustomer_Tax.IsDeleted       = Convert.ToInt32(dr["IsDeleted"]);
                objCustomer_Tax.ModifiedBy      = Convert.ToString(argUserName).Trim();
                objCustomer_Tax.CreatedBy       = Convert.ToString(argUserName).Trim();
                objCustomer_Tax.ClientCode      = Convert.ToString(clientCode).Trim();
                lst.Add(objCustomer_Tax);
            }
            return(lst);
        }
        public void InsertCustomer_Tax(Customer_Tax argCustomer_Tax, DataAccess da, List <ErrorHandler> lstErr)
        {
            SqlParameter[] param = new SqlParameter[10];
            param[0] = new SqlParameter("@CustomerCode", argCustomer_Tax.CustomerCode);
            param[1] = new SqlParameter("@CountryCode", argCustomer_Tax.CountryCode);
            param[2] = new SqlParameter("@TaxCategoryCode", argCustomer_Tax.TaxCategoryCode);
            param[3] = new SqlParameter("@TaxClassCode", argCustomer_Tax.TaxClassCode);
            param[4] = new SqlParameter("@ClientCode", argCustomer_Tax.ClientCode);
            param[5] = new SqlParameter("@CreatedBy", argCustomer_Tax.CreatedBy);
            param[6] = new SqlParameter("@ModifiedBy", argCustomer_Tax.ModifiedBy);

            param[7]           = new SqlParameter("@Type", SqlDbType.Char);
            param[7].Size      = 1;
            param[7].Direction = ParameterDirection.Output;

            param[8]           = new SqlParameter("@Message", SqlDbType.VarChar);
            param[8].Size      = 255;
            param[8].Direction = ParameterDirection.Output;

            param[9]           = new SqlParameter("@returnvalue", SqlDbType.VarChar);
            param[9].Size      = 20;
            param[9].Direction = ParameterDirection.Output;

            int i = da.NExecuteNonQuery("Proc_InsertCustomer_Tax", param);

            string strMessage  = Convert.ToString(param[8].Value);
            string strType     = Convert.ToString(param[7].Value);
            string strRetValue = Convert.ToString(param[9].Value);

            objErrorHandler.Type        = strType;
            objErrorHandler.MsgId       = 0;
            objErrorHandler.Module      = ErrorConstant.strInsertModule;
            objErrorHandler.ModulePart  = ErrorConstant.strMasterModule;
            objErrorHandler.Message     = strMessage.ToString();
            objErrorHandler.RowNo       = 0;
            objErrorHandler.FieldName   = "";
            objErrorHandler.LogCode     = "";
            objErrorHandler.ReturnValue = strRetValue;
            lstErr.Add(objErrorHandler);
        }
        public ICollection <Customer_Tax> colGetCustomer_Tax(string argCustomerCode, string argClientCode)
        {
            List <Customer_Tax> lst           = new List <Customer_Tax>();
            DataSet             DataSetToFill = new DataSet();
            Customer_Tax        tCustomer_Tax = new Customer_Tax();

            DataSetToFill = this.GetCustomer_Tax(argCustomerCode, argClientCode);

            if (DataSetToFill != null)
            {
                foreach (DataRow dr in DataSetToFill.Tables[0].Rows)
                {
                    lst.Add(objCreateCustomer_Tax(dr));
                }
            }
            goto Finish;

Finish:
            DataSetToFill = null;

            return(lst);
        }
        //public ICollection<ErrorHandler> SaveCustomer_SalesArea(Customer_SalesArea argCustomer_SalesArea)
        //{
        //    List<ErrorHandler> lstErr = new List<ErrorHandler>();
        //    DataAccess da = new DataAccess();
        //    SalesAreaManager ObjSalesAreaManager = new SalesAreaManager();
        //    try
        //    {
        //        if (ObjSalesAreaManager.blnIsSalesAreaExists(argCustomer_SalesArea.SalesOrganizationCode, argCustomer_SalesArea.DistChannelCode, argCustomer_SalesArea.DivisionCode, argCustomer_SalesArea.ClientCode) == true)
        //        {

        //            if (blnIsCustomer_SalesAreaExists(argCustomer_SalesArea.CustomerCode, argCustomer_SalesArea.SalesOrganizationCode, argCustomer_SalesArea.DivisionCode, argCustomer_SalesArea.DistChannelCode, argCustomer_SalesArea.ClientCode) == false)
        //            {

        //                da.Open_Connection();
        //                da.BEGIN_TRANSACTION();
        //                InsertCustomer_SalesArea(argCustomer_SalesArea, da, lstErr);
        //                foreach (ErrorHandler objerr in lstErr)
        //                {
        //                    if (objerr.Type == "E")
        //                    {
        //                        da.ROLLBACK_TRANSACTION();
        //                        return lstErr;
        //                    }
        //                }
        //                da.COMMIT_TRANSACTION();
        //            }
        //            else
        //            {
        //                da.Open_Connection();
        //                da.BEGIN_TRANSACTION();
        //                UpdateCustomer_SalesArea(argCustomer_SalesArea, da, lstErr);
        //                foreach (ErrorHandler objerr in lstErr)
        //                {
        //                    if (objerr.Type == "E")
        //                    {
        //                        da.ROLLBACK_TRANSACTION();
        //                        return lstErr;
        //                    }
        //                }
        //                da.COMMIT_TRANSACTION();
        //            }
        //        }
        //        else
        //        {
        //            objErrorHandler.Type = "E";
        //            objErrorHandler.MsgId = 0;
        //            objErrorHandler.Module = ErrorConstant.strInsertModule;
        //            objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
        //            objErrorHandler.Message = "Sales Area does not exists.";
        //            objErrorHandler.RowNo = 0;
        //            objErrorHandler.FieldName = "";
        //            objErrorHandler.LogCode = "";
        //            lstErr.Add(objErrorHandler);
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        if (da != null)
        //        {
        //            da.ROLLBACK_TRANSACTION();
        //        }
        //        objErrorHandler.Type = ErrorConstant.strAboartType;
        //        objErrorHandler.MsgId = 0;
        //        objErrorHandler.Module = ErrorConstant.strInsertModule;
        //        objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
        //        objErrorHandler.Message = ex.Message.ToString();
        //        objErrorHandler.RowNo = 0;
        //        objErrorHandler.FieldName = "";
        //        objErrorHandler.LogCode = "";
        //        lstErr.Add(objErrorHandler);
        //    }
        //    finally
        //    {
        //        if (da != null)
        //        {
        //            da.Close_Connection();
        //            da = null;
        //        }
        //    }
        //    return lstErr;
        //}

        public ICollection <ErrorHandler> SaveCustomer_SalesArea(ICollection <Customer_SalesArea> colGetCustomer_SalesArea, DataTable dtCustomer_Tax, DataTable dtCustomer_Partner)
        {
            List <ErrorHandler> lstErr = new List <ErrorHandler>();
            DataAccess          da     = new DataAccess();

            try
            {
                da.Open_Connection();
                da.BEGIN_TRANSACTION();
                string           strretValue         = "";
                SalesAreaManager ObjSalesAreaManager = new SalesAreaManager();

                foreach (Customer_SalesArea argCustomer_SalesArea in colGetCustomer_SalesArea)
                {
                    if (ObjSalesAreaManager.blnIsSalesAreaExists(argCustomer_SalesArea.SalesOrganizationCode, argCustomer_SalesArea.DistChannelCode, argCustomer_SalesArea.DivisionCode, argCustomer_SalesArea.ClientCode) == true)
                    {
                        if (blnIsCustomer_SalesAreaExists(argCustomer_SalesArea.CustomerCode, argCustomer_SalesArea.SalesOrganizationCode, argCustomer_SalesArea.DivisionCode, argCustomer_SalesArea.DistChannelCode, argCustomer_SalesArea.ClientCode, da) == false)
                        {
                            strretValue = InsertCustomer_SalesArea(argCustomer_SalesArea, da, lstErr);
                        }
                        else
                        {
                            strretValue = UpdateCustomer_SalesArea(argCustomer_SalesArea, da, lstErr);
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                da.ROLLBACK_TRANSACTION();
                                return(lstErr);
                            }

                            if (objerr.Type == "A")
                            {
                                da.ROLLBACK_TRANSACTION();
                                return(lstErr);
                            }
                        }
                    }
                    else
                    {
                        objErrorHandler.Type       = "E";
                        objErrorHandler.MsgId      = 0;
                        objErrorHandler.Module     = ErrorConstant.strInsertModule;
                        objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                        objErrorHandler.Message    = "Sales Area does not exists.";
                        objErrorHandler.RowNo      = 0;
                        objErrorHandler.FieldName  = "";
                        objErrorHandler.LogCode    = "";
                        lstErr.Add(objErrorHandler);
                    }
                }

                if (strretValue != "")
                {
                    if (dtCustomer_Tax.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtCustomer_Tax.Rows)
                        {
                            if (Convert.ToInt32(dr["IsDeleted"]) == 0)
                            {
                                Customer_Tax objCustomer_Tax = new Customer_Tax();
                                objCustomer_Tax.CustomerCode    = strretValue.Trim();
                                objCustomer_Tax.CountryCode     = Convert.ToString(dr["CountryCode"]).Trim();
                                objCustomer_Tax.TaxCategoryCode = Convert.ToString(dr["TaxCategoryCode"]).Trim();
                                objCustomer_Tax.TaxClassCode    = Convert.ToString(dr["TaxClassCode"]).Trim();
                                objCustomer_Tax.ClientCode      = Convert.ToString(dr["ClientCode"]).Trim();
                                objCustomer_Tax.CreatedBy       = Convert.ToString(dr["CreatedBy"]).Trim();
                                objCustomer_Tax.ModifiedBy      = Convert.ToString(dr["ModifiedBy"]).Trim();
                                objCustomer_TaxManager.SaveCustomer_Tax(objCustomer_Tax, da, lstErr);
                            }
                            else
                            {
                                objCustomer_TaxManager.DeleteCustomer_Tax(strretValue.ToString().Trim(), Convert.ToString(dr["CountryCode"]).Trim(), Convert.ToString(dr["TaxCategoryCode"]).Trim(), Convert.ToString(dr["TaxClassCode"]).Trim(), Convert.ToString(dr["ClientCode"]).Trim(), 1, da);
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                da.ROLLBACK_TRANSACTION();
                                return(lstErr);
                            }

                            if (objerr.Type == "A")
                            {
                                da.ROLLBACK_TRANSACTION();
                                return(lstErr);
                            }
                        }
                    }

                    if (dtCustomer_Partner.Rows.Count > 0)
                    {
                        foreach (DataRow dr in dtCustomer_Partner.Rows)
                        {
                            if (Convert.ToInt32(dr["IsDeleted"]) == 0)
                            {
                                Customer_PartnerFunction objCustomer_Partner = new Customer_PartnerFunction();
                                objCustomer_Partner.CustomerCode          = strretValue.Trim();
                                objCustomer_Partner.SalesOrganizationCode = Convert.ToString(dr["SalesOrganizationCode"]).Trim();
                                objCustomer_Partner.DivisionCode          = Convert.ToString(dr["DivisionCode"]).Trim();
                                objCustomer_Partner.DistChannelCode       = Convert.ToString(dr["DistChannelCode"]).Trim();
                                objCustomer_Partner.PFunctionCode         = Convert.ToString(dr["PFunctionCode"]).Trim();
                                objCustomer_Partner.PartnerCounter        = Convert.ToInt32(dr["PartnerCounter"]);
                                objCustomer_Partner.PartnerTable          = Convert.ToString(dr["PartnerTable"]).Trim();
                                objCustomer_Partner.PartnerCode           = Convert.ToString(dr["PartnerCode"]).Trim();
                                objCustomer_Partner.ClientCode            = Convert.ToString(dr["ClientCode"]).Trim();
                                objCustomer_Partner.CreatedBy             = Convert.ToString(dr["CreatedBy"]).Trim();
                                objCustomer_Partner.ModifiedBy            = Convert.ToString(dr["ModifiedBy"]).Trim();
                                objCustomer_PartnerFunctionManager.SaveCustomer_PartnerFunction(objCustomer_Partner, da, lstErr);
                            }
                            else
                            {
                                objCustomer_PartnerFunctionManager.DeleteCustomer_PartnerFunction(strretValue.ToString().Trim(), Convert.ToString(dr["PFunctionCode"]).Trim(), Convert.ToString(dr["ClientCode"]).Trim(), 1, da);
                            }
                        }

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                da.ROLLBACK_TRANSACTION();
                                return(lstErr);
                            }

                            if (objerr.Type == "A")
                            {
                                da.ROLLBACK_TRANSACTION();
                                return(lstErr);
                            }
                        }
                    }
                }
                da.COMMIT_TRANSACTION();
            }
            catch (Exception ex)
            {
                if (da != null)
                {
                    da.ROLLBACK_TRANSACTION();
                }
                objErrorHandler.Type       = ErrorConstant.strAboartType;
                objErrorHandler.MsgId      = 0;
                objErrorHandler.Module     = ErrorConstant.strInsertModule;
                objErrorHandler.ModulePart = ErrorConstant.strMasterModule;
                objErrorHandler.Message    = ex.Message.ToString();
                objErrorHandler.RowNo      = 0;
                objErrorHandler.FieldName  = "";
                objErrorHandler.LogCode    = "";
                lstErr.Add(objErrorHandler);
            }
            finally
            {
                if (da != null)
                {
                    da.Close_Connection();
                    da = null;
                }
            }
            return(lstErr);
        }