public int InsertAgent(CompetitorAgentMasterBDto objCompetitorAgentMasterBDto)
        {
            Database db = null;
            DbCommand dbCmd = null;
            int Result = 0;
            try
            {
                db = DatabaseFactory.CreateDatabase(DALHelper.CRM_CONNECTION_STRING);
                dbCmd = db.GetStoredProcCommand(DALHelper.USP_ADMINISTRATION_COMPETITOR_AGENT_INSERT);

                db.AddInParameter(dbCmd, "@AGENT_NAME", DbType.String, objCompetitorAgentMasterBDto.AgentName);
                db.AddInParameter(dbCmd, "@AGENT_ADDRESS", DbType.String, objCompetitorAgentMasterBDto.AgentAddress);
                db.AddInParameter(dbCmd, "@CITY_ID", DbType.Int32, objCompetitorAgentMasterBDto.CityId);
                db.AddInParameter(dbCmd, "@STATE_ID", DbType.Int32, objCompetitorAgentMasterBDto.StateId);
                db.AddInParameter(dbCmd, "@COUNTRY_ID", DbType.Int32, objCompetitorAgentMasterBDto.CountryId);
                db.AddInParameter(dbCmd, "@PHONE_NO", DbType.String, objCompetitorAgentMasterBDto.Phone);
                db.AddInParameter(dbCmd, "@OWNER_COMPANY_ID", DbType.Int32, objCompetitorAgentMasterBDto.OwnerCompanyId);
                db.AddInParameter(dbCmd, "@USER_ID", DbType.Int32, objCompetitorAgentMasterBDto.UserId);
                db.AddOutParameter(dbCmd, "@ISEXIST", DbType.Int32, 1);

                db.ExecuteNonQuery(dbCmd);
                Result = Convert.ToInt32(db.GetParameterValue(dbCmd, "@ISEXIST"));
            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, DALHelper.DAL_EXP_POLICYNAME);
                if (rethrow)
                {
                    throw ex;
                }
            }
            finally
            {
                DALHelper.Destroy(ref dbCmd);
            }
            return Result;
        }
        protected void acbAgent_SaveClick(object sender, EventArgs e)
        {
            objCompetitorAgentMasterBDto = new CompetitorAgentMasterBDto();


            try
            {
                int result = 0;
                objCompetitorAgentMasterDal = new CompetitorAgentMasterDal();
                switch (acbAgent.SaveButton.CommandName)
                {
                    case "Save":
                      
                        SaveCompetitor();
                        pnlAddNewMode.Visible = false;
                        acbAgent.EditableMode = false;
                        BindGrid();
                        break;

                    case "Update":
                        Update();
                        break;
                }
            }


            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, DALHelper.DAL_EXP_POLICYNAME);
                if (rethrow)
                { throw ex; }
            }
        }
        private void Update()
        {
            try
            {
                int result = 0;
                objCompetitorAgentMasterDal = new CompetitorAgentMasterDal();
                objCompetitorAgentMasterBDto = new CompetitorAgentMasterBDto();
                objCompetitorAgentMasterBDto.AgentName = txtAgentName.Text.Trim();
                objCompetitorAgentMasterBDto.AgentAddress = txtAddress.Text.Trim();
                objCompetitorAgentMasterBDto.CityId = Convert.ToInt32(radCmbCity.SelectedValue);
                objCompetitorAgentMasterBDto.StateId = Convert.ToInt32(radCmbState.SelectedValue);
                objCompetitorAgentMasterBDto.CountryId = Convert.ToInt32(radCmbCountry.SelectedValue);
                objCompetitorAgentMasterBDto.Phone = txtphone.Text.Trim();
                objCompetitorAgentMasterBDto.OwnerCompanyId = objAuthorizationBDto.UserSelectedCompanyId;
                objCompetitorAgentMasterBDto.UserId = objAuthorizationBDto.UserProfile.UserId;
                objCompetitorAgentMasterBDto.AgentId = Convert.ToInt32(ViewState["AgentId"]);

                result = objCompetitorAgentMasterDal.UpdateAgent(objCompetitorAgentMasterBDto);
                if (result >= 1)
                {
                    pnlAddNewMode.Visible = false;
                    acbAgent.EditableMode = false;
                    BindGrid();
                    Reset();

                    Master.DisplayMessage(ConfigurationSettings.AppSettings[SuccessMessage.Save].ToString());
                    Master.MessageCssClass = "successMessage";
                }
                else
                {
                    Master.DisplayMessage("Agent Name Already Exist");
                    //Master.DisplayMessage(ConfigurationSettings.AppSettings[FailureMessage.Save].ToString());
                    Master.MessageCssClass = "errorMessage";
                }

            }
            catch (Exception ex)
            {
                bool rethrow = ExceptionPolicy.HandleException(ex, DALHelper.DAL_EXP_POLICYNAME);
                if (rethrow)
                { throw ex; }
            }
        }