public SalesGroup objGetSalesGroup(string argSalesGroupCode, string argClientCode)
        {
            SalesGroup argSalesGroup = new SalesGroup();
            DataSet    DataSetToFill = new DataSet();

            if (argSalesGroupCode.Trim() == "")
            {
                goto ErrorHandlers;
            }
            DataSetToFill = this.GetSalesGroup(argSalesGroupCode, argClientCode);

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

            goto Finish;

ErrorHandlers:

Finish:
            DataSetToFill = null;

            return(argSalesGroup);
        }
        private SalesGroup objCreateSalesGroup(DataRow dr)
        {
            SalesGroup tSalesGroup = new SalesGroup();

            tSalesGroup.SetObjectInfo(dr);
            return(tSalesGroup);
        }
 /*************/
 public void SaveSalesGroup(SalesGroup argSalesGroup, DataAccess da, List <ErrorHandler> lstErr)
 {
     try
     {
         if (blnIsSalesGroupExists(argSalesGroup.SalesGroupCode, argSalesGroup.ClientCode, da) == false)
         {
             InsertSalesGroup(argSalesGroup, da, lstErr);
         }
         else
         {
             UpdateSalesGroup(argSalesGroup, da, lstErr);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
        public ICollection <SalesGroup> colGetSalesGroup(string argClientCode)
        {
            List <SalesGroup> lst           = new List <SalesGroup>();
            DataSet           DataSetToFill = new DataSet();
            SalesGroup        tSalesGroup   = new SalesGroup();

            DataSetToFill = this.GetSalesGroup(argClientCode);

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

Finish:
            DataSetToFill = null;

            return(lst);
        }
        public void UpdateSalesGroup(SalesGroup argSalesGroup, DataAccess da, List <ErrorHandler> lstErr)
        {
            SqlParameter[] param = new SqlParameter[8];
            param[0] = new SqlParameter("@SalesGroupCode", argSalesGroup.SalesGroupCode);
            param[1] = new SqlParameter("@SalesGroupName", argSalesGroup.SalesGroupName);
            param[2] = new SqlParameter("@ClientCode", argSalesGroup.ClientCode);
            param[3] = new SqlParameter("@CreatedBy", argSalesGroup.CreatedBy);
            param[4] = new SqlParameter("@ModifiedBy", argSalesGroup.ModifiedBy);

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

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

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

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

            string strMessage  = Convert.ToString(param[6].Value);
            string strType     = Convert.ToString(param[5].Value);
            string strRetValue = Convert.ToString(param[7].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    = "";
            lstErr.Add(objErrorHandler);
        }
        public ICollection <ErrorHandler> BulkInsert(string argExcelPath, string argQuery, string strTableName, string argFileExt, string argUserName, string argClientCode)
        {
            DataTable           dtExcel        = null;
            SalesGroup          ObjSalesGroup  = null;
            string              xConnStr       = "";
            string              strSheetName   = "";
            DataSet             dsExcel        = new DataSet();
            DataTable           dtTableSchema  = new DataTable();
            OleDbConnection     objXConn       = null;
            OleDbDataAdapter    objDataAdapter = new OleDbDataAdapter();
            List <ErrorHandler> lstErr         = new List <ErrorHandler>();

            if (argFileExt.ToString() == ".xls")
            {
                xConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                           "Data Source=" + argExcelPath.Trim() + ";" +
                           "Extended Properties=Excel 8.0";
            }
            else
            {
                xConnStr = "Provider=Microsoft.ACE.OLEDB.12.0;" +
                           "Data Source=" + argExcelPath.Trim() + ";" +
                           "Extended Properties=Excel 12.0";
            }

            try
            {
                objXConn = new OleDbConnection(xConnStr);
                objXConn.Open();
                dtTableSchema = objXConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

                if (argFileExt.ToString() == ".xls")
                {
                    strSheetName = Convert.ToString(dtTableSchema.Rows[0]["TABLE_NAME"]);
                }
                else
                {
                    strSheetName = Convert.ToString(dtTableSchema.Rows[0]["TABLE_NAME"]);

                    if (strSheetName.IndexOf(@"_xlnm#_FilterDatabase") >= 0)
                    {
                        strSheetName = Convert.ToString(dtTableSchema.Rows[1]["TABLE_NAME"]);
                    }
                }
                argQuery = argQuery + " [" + strSheetName + "]";
                OleDbCommand objCommand = new OleDbCommand(argQuery, objXConn);
                objDataAdapter.SelectCommand = objCommand;
                objDataAdapter.Fill(dsExcel);
                dtExcel = dsExcel.Tables[0];

                /*****************************************/
                DataAccess da = new DataAccess();
                da.Open_Connection();
                da.BEGIN_TRANSACTION();

                try
                {
                    foreach (DataRow drExcel in dtExcel.Rows)
                    {
                        ObjSalesGroup = new SalesGroup();
                        ObjSalesGroup.SalesGroupCode = Convert.ToString(drExcel["SalesGroupCode"]).Trim();
                        ObjSalesGroup.SalesGroupName = Convert.ToString(drExcel["SalesGroupName"]).Trim();
                        ObjSalesGroup.CreatedBy      = Convert.ToString(argUserName);
                        ObjSalesGroup.ModifiedBy     = Convert.ToString(argUserName);
                        ObjSalesGroup.ClientCode     = Convert.ToString(argClientCode);
                        SaveSalesGroup(ObjSalesGroup, da, lstErr);

                        foreach (ErrorHandler objerr in lstErr)
                        {
                            if (objerr.Type == "E")
                            {
                                da.ROLLBACK_TRANSACTION();
                                break;
                            }
                        }
                    }
                    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;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                objXConn.Close();
            }
            return(lstErr);
        }
        public ICollection <ErrorHandler> SaveSalesGroup(SalesGroup argSalesGroup)
        {
            List <ErrorHandler> lstErr = new List <ErrorHandler>();
            DataAccess          da     = new DataAccess();

            try
            {
                if (blnIsSalesGroupExists(argSalesGroup.SalesGroupCode, argSalesGroup.ClientCode) == false)
                {
                    da.Open_Connection();
                    da.BEGIN_TRANSACTION();
                    InsertSalesGroup(argSalesGroup, 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();
                    UpdateSalesGroup(argSalesGroup, da, lstErr);
                    foreach (ErrorHandler objerr in lstErr)
                    {
                        if (objerr.Type == "E")
                        {
                            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);
        }