网页在On_Unload事件后挂起

时间:2010-11-24 08:59:13

标签: c# asp.net nhibernate

需要你的帮助。

我有一个Web应用程序,在单击设置为autopostback的复选框后挂起。这个复选框应该做一些处理。

它没有触发OnPreLoad和OnLoad事件。

以下是代码

    protected override void BindReference()
    {
        BindComboBox(ref rcbPortfolioId, CNPL_Portfolio.GetPortfolioDicWithAll());
        BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll());
        BindComboBox(ref rcbNewAgencyId, CNPL_Agency.GetAgencyDicWithAll());
        BindComboBox(ref rcbPreviousAgencyId, CNPL_Agency.GetAgencyDicWithAll());
        BindComboBox(ref rcbAccountStatusId, CNPL_AccountStatus.GetStatusDic());
        BindComboBox(ref rcbAgencyHeader, CNPL_Agency.GetAgencyDic());

    }
    protected override void SetViewStates()
    {
        ViewState["ETemp"] = eTemp;
        ViewState["AgencyIDRgTemp"] = _AgencyIDRgTemp;
        ViewState["PreviousIDRgTemp"] = _PreviousIDRgTemp;
        ViewState["ProductIDRgTemp"] = _ProductIDRgTemp;
        ViewState["IsRetainedRgTemp"] = _IsRetainedRgTemp;
    }
    protected override void GetViewStates()
    {
        if (ViewState["ETemp"] != null)
        {
            eTemp = (List<CNPL_EndorsementTemp>)ViewState["ETemp"];
        }
        if (ViewState["AgencyIDRgTemp"] != null)
        {
            _AgencyIDRgTemp = (int)ViewState["AgencyIDRgTemp"];
        }
        if (ViewState["PreviousIDRgTemp"] != null)
        {
            _PreviousIDRgTemp = (int)ViewState["PreviousIDRgTemp"];
        }
        if (ViewState["ProductIDRgTemp"] != null)
        {
            _ProductIDRgTemp = (int)ViewState["ProductIDRgTemp"];
        }
        if (ViewState["IsRetainedRgTemp"] != null)
        {
            _IsRetainedRgTemp = (bool)ViewState["IsRetainedRgTemp"];
        }
   }

    protected void chkEndorseAuto_OnCheckChange(object sender, EventArgs e)
    {
        DirectDBAccess db = new DirectDBAccess();
        SqlCommand cmd = new SqlCommand("dbo.Proc_UpdateIsIncludedEndorsementTemp");

        Int32 _AgencyID=0;
        Int32 _PreviousAgencyID=0;
        Int32 _IsRetained=0;
        Int32 _ProductID=0;
        Int32 _IsIncluded=0;
        Int32 _NewIsIncluded = 0;
        CheckBox cBox = (sender as CheckBox);
        GridDataItem item = (cBox.Parent.Parent as GridDataItem);

        if (!Int32.TryParse(item["AgencyID"].Text, out _AgencyID))
            throw new Exception("Endorsement: Error in parsing");
        if (!Int32.TryParse(item["PreviousAgencyID"].Text, out _PreviousAgencyID))
            throw new Exception("Endorsement: Error in parsing");
        if (!Int32.TryParse(item["ProductID"].Text, out _ProductID))
            throw new Exception("Endorsement: Error in parsing");

        if (item["IsRetained"].Text.ToLower() == "true")
            _IsRetained = 1;
        else if (item["IsRetained"].Text.ToLower() == "false")
            _IsRetained = 0;
        else
            throw new Exception("Endorsement: Error in parsing");

        if (cBox.Checked)
        {
            _NewIsIncluded = 1;
            _IsIncluded = 0;
        }
        else
        {
            _NewIsIncluded = 0;
            _IsIncluded = 1;
        }

        cmd.CommandTimeout = 9500;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add(new SqlParameter("@AgencyID",_AgencyID));
        cmd.Parameters.Add(new SqlParameter("@PreviousAgencyID", _PreviousAgencyID));
        cmd.Parameters.Add(new SqlParameter("@IsRetained", _IsRetained));
        cmd.Parameters.Add(new SqlParameter("@ProductID", _ProductID));
        cmd.Parameters.Add(new SqlParameter("@IsIncluded", _IsIncluded));
        cmd.Parameters.Add(new SqlParameter("@NewIsIncluded", _NewIsIncluded));

        db.Open();
        db.CommandExecuteNonQuery(cmd,CommandType.StoredProcedure);
        db.Close();
    }

    void rcbPortfolioId_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Int32 _PortfolioID;
        _PortfolioID = Int32.Parse(rcbPortfolioId.SelectedValue);
        if(_PortfolioID >0)
            BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll(_PortfolioID));
        else
            BindComboBox(ref rcbProductId, CNPL_Product.GetProductDicWithAll());
    }

    private void InitializeEndorsementDate()
    { 
        int curingDays;
        if (!Int32.TryParse(CNPL_DataSettings.GetSettingValue("CuringPeriod").ToString(), out curingDays))
            curingDays = 120;
        rdpEndorsementDateFrom.SelectedDate = DateTime.Now;
        rdpEndorsementDateTo.SelectedDate = DateTime.Now.AddDays(curingDays - 1);
    }
    private void InitializeGrids()
    {
        rgEndorsements.DataSource = new List<CNPL_EndorsementTemp>();
        rgEndorsements.DataBind();

        //Added by Ryan Estandarte 11/2/2010
        rgEndorsements.AllowPaging = true;
        rgEndorsements.PageSize = 10;

        rgEndorsementTemp.DataSource = new List<CNPL_EndorsementTemp>();
        rgEndorsementTemp.DataBind();
    }
    public Dictionary<int, string> PopulateRgAgencyId()
    {
        return CNPL_Agency.GetAgencyDic();
    }
    void btnSearch_Click(object sender, EventArgs e)
    {
        AssignAccountToEndorsementTemp();
        RadAjaxManager1.Alert("finished automatic distribution");
    }
    private void BindRgEndorsements()
    {
        rgEndorsements.DataSource = CNPL_EndorsementTemp.GetGroupedEndorsementTemp();
        rgEndorsements.DataBind();
    }

    private void ClearTotals()
    {
        rntbTotalAccounts.Text = "";
        rntbTotalPrincipal.Text = "";
        rntbTotalPenalty.Text = "";
        rntbTotalInterest.Text = "";
        rntbTotalOutstandingBalance.Text = "";
    }
    private void ShuffleAgencies(ref List<CNPL_Agency> agencyToShuffle)
    {
        int N = agencyToShuffle.Count;
        Random random = new System.Random();
        for (int index = 0; index < N; ++index)
        {
            int randomIndex = index + (int)(random.Next(N - index));
            CNPL_Agency _agencyTemp = agencyToShuffle[randomIndex];
            agencyToShuffle[randomIndex] = agencyToShuffle[index];
            agencyToShuffle[index] = _agencyTemp;
        }
    }

    private void AssignAccountToEndorsementTemp()
    {
        DirectDBAccess db = new DirectDBAccess();
        SqlCommand cmd = new SqlCommand();
        string sql;
        InitializeGrids();
        sql = "dbo.Proc_AssignAccountsForEndorsement";
        cmd.CommandText = sql;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 59500;
        cmd.Parameters.Add(new SqlParameter("@PortfolioID_Criteria",Int32.Parse(rcbPortfolioId.SelectedValue)));
        cmd.Parameters.Add(new SqlParameter("@ProductID_Criteria",Int32.Parse(rcbProductId.SelectedValue)));
        cmd.Parameters.Add(new SqlParameter("@NewAgencyID_Criteria",Int32.Parse(rcbNewAgencyId.SelectedValue)));
        cmd.Parameters.Add(new SqlParameter("@PreviousAgencyID_Criteria",Int32.Parse(rcbPreviousAgencyId.SelectedValue)));

        db.Open();
        db.CommandExecuteNonQuery(cmd,CommandType.StoredProcedure);
        db.Close();

        BindRgEndorsements();
    }

    void rgEndorsements_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "btnDetails")
        {
            int pageSize = 10;
            if (chkPagingManual.Checked == true)
            {
               rgEndorsementTemp.AllowPaging = true;
                Int32.TryParse(rntbPageSizeManual.Text, out pageSize);
                rgEndorsementTemp.PageSize = pageSize;
            }
            else
                rgEndorsementTemp.AllowPaging = false;

            _AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["AgencyId"].Text);
            _PreviousIDRgTemp = Int32.Parse((e.Item as GridDataItem)["PreviousAgencyId"].Text);
            _ProductIDRgTemp = Int32.Parse((e.Item as GridDataItem)["ProductID"].Text);
            _IsRetainedRgTemp = Boolean.Parse((e.Item as GridDataItem)["IsRetained"].Text);

            BindRgEndorsementTemp();
        }
        else if (e.CommandName == "btnChange")
        {
            IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
            RadComboBox rcbAgencyId = (RadComboBox)(e.Item as GridDataItem).FindControl("rcbAgency");
            int _AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);

            UpdateEndorsement(e.Item as GridDataItem);
            Helper.SaveList(endorsementTemps,this.Web.CurrentUser.LoginName);
            //rebind rgEndosements
            BindRgEndorsements();
            //rebind RgEndorsementTemp w/ respect to agencyid being edited
            _AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["AgencyId"].Text);
            _PreviousIDRgTemp = Int32.Parse((e.Item as GridDataItem)["PreviousAgencyId"].Text);
            BindRgEndorsementTemp();
            RadAjaxManager1.Alert("Updated");
        }
    }
    protected void chkEndorseAutoHeader_OnCheckChange(object sender, EventArgs e)
    {
        CheckBox chk = new CheckBox();
        CheckBox chkHeader = sender as CheckBox;
        foreach (GridDataItem item in rgEndorsements.Items)
        {
            chk = (CheckBox)item.FindControl("chkEndorseAuto");
            chk.Checked = chkHeader.Checked;
        }
        IncludeAll(chkHeader.Checked);
    }
    private void IncludeAll(Boolean chk)
    {
        DirectDBAccess db = new DirectDBAccess();
        string sql;

        if(chk == true)
            sql = "update CNPL_EndorsementTemp set IsIncluded='True'";
        else
            sql = "update CNPL_EndorsementTemp set IsIncluded='False'";

        SqlCommand cmd = new SqlCommand(sql);
        db.Open();
        db.CommandExecuteNonQuery(cmd, CommandType.Text);
        db.Close();
    }

    private IList<CNPL_EndorsementTemp> UpdateEndorsement(GridDataItem tempGridDataItem)
    {
        //update endorsementtemp to database
        IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
        RadComboBox rcbAgencyId = (RadComboBox)tempGridDataItem.FindControl("rcbAgency");
        Int32 _AgencyID = Int32.Parse(tempGridDataItem["AgencyID"].Text);
        Int32 _PreviousAgencyID = Int32.Parse(tempGridDataItem["PreviousAgencyID"].Text);
        string _IsRetained = tempGridDataItem["IsRetained"].Text;
        Int32 _ProductID = Int32.Parse(tempGridDataItem["ProductID"].Text);
        string filter = string.Format("Where AgencyID={0} And PreviousAgencyID={1} And IsRetained='{2}' And ProductID={3}", _AgencyID, _PreviousAgencyID, _IsRetained, _ProductID);
        endorsementTemps = CNPL_EndorsementTemp.GetAllWithFilter(filter);
        foreach (CNPL_EndorsementTemp endorsementTemp in endorsementTemps)
        {
            endorsementTemp.AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
        }
        return endorsementTemps;
    }

    private IList<CNPL_EndorsementTemp> UpdateEndorsementAllChecked(GridDataItem tempGridDataItem)
    {
        //update endorsementtemp to database
        IList<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
        Int32 _AgencyID = Int32.Parse(tempGridDataItem["AgencyID"].Text);
        Int32 _PreviousAgencyID = Int32.Parse(tempGridDataItem["PreviousAgencyID"].Text);
        string filter = string.Format("Where AgencyID={0} And PreviousAgencyID={1}", _AgencyID, _PreviousAgencyID);
        endorsementTemps = CNPL_EndorsementTemp.GetAllWithFilter(filter);
        foreach (CNPL_EndorsementTemp endorsementTemp in endorsementTemps)
        {
            endorsementTemp.AgencyID = Int32.Parse(rcbAgencyUpdateAuto.SelectedValue);
        }
        return endorsementTemps;
    }
    void btnUpdateAutoAll_Click(object sender, EventArgs e)
    {
        List<CNPL_EndorsementTemp> endorsementTemps = new List<CNPL_EndorsementTemp>();
        //IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
        foreach (GridDataItem item in rgEndorsements.Items)
        {
            CheckBox chk = new CheckBox();

            chk = (CheckBox)item.FindControl("chkEndorseAuto");
            if (chk.Checked == true)
            {
                endorsementTemps.AddRange(UpdateEndorsementAllChecked(item));
            }
        }
        if (endorsementTemps.Count > 0)
            Helper.SaveList(endorsementTemps, this.Web.CurrentUser.LoginName);
        BindRgEndorsements();
        _AgencyIDRgTemp = 0;
        _PreviousIDRgTemp = 0;
        BindRgEndorsementTemp();
        RadAjaxManager1.Alert("Updated");

    }

    void btnEndorse_Click(object sender, EventArgs e)
    {
        EndorseToAgencies();
        RadAjaxManager1.Alert("finished endorsement");
    }
    private void EndorseToAgencies()
    {
        DirectDBAccess db = new DirectDBAccess();
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "dbo.Proc_EndorseToAgencies";
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 59500;
        cmd.Parameters.Add(new SqlParameter("@User", Web.CurrentUser.LoginName));
        cmd.Parameters.Add(new SqlParameter("@EndorsementDateFrom", rdpEndorsementDateFrom.SelectedDate));
        cmd.Parameters.Add(new SqlParameter("@EndorsementDateTo", rdpEndorsementDateTo.SelectedDate));

        db.Open();
        db.CommandExecuteNonQuery(cmd, CommandType.StoredProcedure);
        db.Close();

        BindRgEndorsements();
        _AgencyIDRgTemp = 0;
        _PreviousIDRgTemp = 0;
        BindRgEndorsementTemp();
    }

    private IList<CNPL_EndorsementDetail> ConvertEndorsementTempToDetails()
    {
        IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
        IList<CNPL_EndorsementDetail> details = new List<CNPL_EndorsementDetail>();

        temps = CNPL_EndorsementTemp.GetAll();
        details.Clear();
        foreach (CNPL_EndorsementTemp temp in temps)
        {
            CNPL_EndorsementDetail detail = new CNPL_EndorsementDetail();
            CNPL_Account _account = new CNPL_Account();
            _account = CNPL_Account.GetByID(temp.AccountID);
            detail.Account = _account;
            detail.Account.IsCurrentlyEndorsed = true;

            if (detail.Account.NewAgencyID != 0)
            {
                detail.Account.PreviousAgencyID = detail.Account.NewAgencyID;
            }
            detail.Account.EndorsementDateTo = rdpEndorsementDateTo.SelectedDate;
            detail.Account.EndorsementDateFrom = rdpEndorsementDateFrom.SelectedDate;
            detail.Account.NewAgencyID = temp.AgencyID;
            detail.AccountID = temp.AccountID;
            detail.AgencyID = temp.AgencyID;

            detail.CreatedBy = this.Web.CurrentUser.LoginName;
            detail.CreatedDate = DateTime.Now;

            details.Add(detail);
        }
        return details;
    }

    void rgEndorsementTemp_ItemCommand(object source, GridCommandEventArgs e)
    {
        if (e.CommandName == "btnChange")
        {
            RadComboBox rcbAgencyId = (RadComboBox)(e.Item as GridDataItem).FindControl("rcbAgency");
            int _AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
            UpdateEndorsementTemp(e.Item as GridDataItem);

            BindRgEndorsements();

            _AgencyIDRgTemp = Int32.Parse((e.Item as GridDataItem)["OldAgencyID"].Text);
            BindRgEndorsementTemp();

            RadAjaxManager1.Alert("Updated");
        }
    }
    private void BindRgEndorsementTemp()
    {
        rgEndorsementTemp.DataSource = CNPL_EndorsementTemp.GetDetailsEndorsementTemp(_AgencyIDRgTemp,_PreviousIDRgTemp,_ProductIDRgTemp,_IsRetainedRgTemp);
        rgEndorsementTemp.DataBind();
    }
    private void UpdateEndorsementTemp(GridDataItem tempGridDataItem)
    {

        CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
        Int32 _ID = Int32.Parse(tempGridDataItem["EndorsementTempID"].Text);
        _EndorsementTemp = CNPL_EndorsementTemp.GetByID(_ID);
        RadComboBox rcbAgencyId = (RadComboBox)tempGridDataItem.FindControl("rcbAgency");
        _EndorsementTemp.AgencyID = Int32.Parse(rcbAgencyId.SelectedValue);
        _EndorsementTemp.AccountID = Int32.Parse(tempGridDataItem["AccountID"].Text);
        _EndorsementTemp.Save();
    }
    protected void chkEndorseManualHeader_OnCheckChange(object sender, EventArgs e)
    {
        CheckBox chk = new CheckBox();
        CheckBox chkHeader = sender as CheckBox;
        foreach (GridDataItem item in rgEndorsementTemp.Items)
        {
            chk = (CheckBox)item.FindControl("chkEndorseManual");
            chk.Checked = chkHeader.Checked;
        }
    }

    void rgEndorsementTemp_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
    {
        rgEndorsementTemp.DataSource = CNPL_EndorsementTemp.GetDetailsEndorsementTemp(_AgencyIDRgTemp, _PreviousIDRgTemp, _ProductIDRgTemp, _IsRetainedRgTemp);
    }
    void btnUpdateManualAll_Click(object sender, EventArgs e)
    {
        IList<CNPL_EndorsementTemp> temps = new List<CNPL_EndorsementTemp>();
       foreach (GridDataItem item in rgEndorsementTemp.Items)
        {
            CheckBox chk = new CheckBox();
            chk = (CheckBox)item.FindControl("chkEndorseManual");
            if(chk.Checked == true)
            {
                CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
                Int32 _ID = Int32.Parse(item["EndorsementTempID"].Text);
                _EndorsementTemp = CNPL_EndorsementTemp.GetByID(_ID);
                _EndorsementTemp.AgencyID = Int32.Parse(rcbAgencyHeader.SelectedValue);
                _EndorsementTemp.AccountID = Int32.Parse(item["AccountID"].Text);
                temps.Add(_EndorsementTemp);
            }
        }
        if (temps.Count > 0)
            Helper.SaveList(temps, this.Web.CurrentUser.LoginName);
        BindRgEndorsements();
        BindRgEndorsementTemp();
        RadAjaxManager1.Alert("Updated");
  }

    private void GetAccountPerCollectorRatio()
    {
        accountCollectorRatios = CNPL_AccountCollectorRatio.GetAll();
    }       

    void btnSearchManualAdd_Click(object sender, EventArgs e)
    {
        if (rbAccountNoMA.Checked == true)
        {
            if (txtAccountNoMA.Text.Length > 0)
                accounts = CNPL_Account.GetAccountLikeAccountNo(txtAccountNoMA.Text);
            else
                RadAjaxManager1.Alert("Requires search parameter");
        }
        else if (rbAccountNameMA.Checked == true)
        {
            if(txtAccountNameMA.Text.Length > 0)
                accounts = CNPL_Account.GetAccountLikeAccountName(txtAccountNameMA.Text);
            else
                RadAjaxManager1.Alert("Requires search parameter");
        }
        BindRgManualAdd();
    }

    private void BindRgManualAdd()
    {
        rgManualAdd.DataSource = accounts;
        rgManualAdd.DataBind();
    }

    void rgManualAdd_ItemCommand(object source, GridCommandEventArgs e)
    {
        CNPL_Account _Account = CNPL_Account.GetByID(Int32.Parse((e.Item as GridDataItem)["AccountID"].Text));
        if (e.CommandName == "btnAdd")
        {
            CNPL_EndorsementTemp _EndorsementTemp = new CNPL_EndorsementTemp();
            List<CNPL_EndorsementTemp> _EndorsementTemps = (List<CNPL_EndorsementTemp>)CNPL_EndorsementTemp.GetAll();

            _EndorsementTemp.AccountID = _Account.Id; 
            _EndorsementTemp.ProductID = _Account.ProductID;
            _EndorsementTemp.CurrentBalance = _Account.CurrentBalance;
            _EndorsementTemp.AgencyID = _Account.NewAgencyID; Int32.Parse((e.Item as GridDataItem)["NewAgencyID"].Text);
            _EndorsementTemp.PreviousAgencyID = _Account.NewAgencyID; Int32.Parse((e.Item as GridDataItem)["PreviousAgencyID"].Text);
            _EndorsementTemp.IsRetained = _Account.IsCurrentlyEndorsed==true?true:false;
            _EndorsementTemp.IsIncluded = true;

            if (_EndorsementTemps.Exists(delegate(CNPL_EndorsementTemp temp) { return temp.AccountID == _EndorsementTemp.AccountID; }))
            {
                RadAjaxManager1.Alert(_Account.AccountName + " already exists");
            }
            else
            {
                _EndorsementTemp.Save(Web.CurrentUser.LoginName);
                BindRgEndorsements();
            }
        }
    }

    void chkUseManualAdd_CheckedChanged(object sender, EventArgs e)
    {
        if (!CNPL_EndorsementTemp.DeleteEndorsementTemp())
            throw new Exception("endorsement: cannot clear temporary table");

        if (chkUseManualAdd.Checked == true)
        {
            pnlManualAdd.Visible = true;
            btnSearch.Enabled = false;
            BindRgEndorsements();
            BindRgManualAdd();
        }
        else
        {
            pnlManualAdd.Visible = false;
            btnSearch.Enabled = true;
        }
    }

   protected override void OnInit(EventArgs e)
   {
       try
       {
           rcbPortfolioId.SelectedIndexChanged += new RadComboBoxSelectedIndexChangedEventHandler(rcbPortfolioId_SelectedIndexChanged);
           btnSearch.Click += new EventHandler(btnSearch_Click);
           btnEndorse.Click += new EventHandler(btnEndorse_Click);

            tnUpdateManualAll.Click += new EventHandler(btnUpdateManualAll_Click);
           rgEndorsements.ItemCommand += new GridCommandEventHandler(rgEndorsements_ItemCommand);
           rgEndorsements.NeedDataSource += new GridNeedDataSourceEventHandler(rgEndorsements_NeedDataSource);

           rgEndorsementTemp.ItemCommand += new GridCommandEventHandler(rgEndorsementTemp_ItemCommand);
           rgEndorsementTemp.NeedDataSource += new GridNeedDataSourceEventHandler(rgEndorsementTemp_NeedDataSource);
           rgEndorsements.ItemEvent += new GridItemEventHandler(rgEndorsements_ItemEvent);


           btnSearchManualAdd.Click += new EventHandler(btnSearchManualAdd_Click);
           rgManualAdd.ItemCommand += new GridCommandEventHandler(rgManualAdd_ItemCommand);
           chkUseManualAdd.CheckedChanged += new EventHandler(chkUseManualAdd_CheckedChanged);
           btnViewDistributed.Click += new EventHandler(btnViewDistributed_Click);

           btnPullout.Click += new EventHandler(btnPullout_Click);
           base.OnInit(e);
       }
       catch (Exception ex)
       {
           string message = ex.Message;
       }
   }

    protected void UpdateAgency(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
       int newAgencyID = 0;

       RadComboBox newAgencyDropdown = sender as RadComboBox;

       foreach (GridDataItem item in rgEndorsements.Items)
       {
           newAgencyDropdown = (RadComboBox)item.FindControl("rcbAgency");

           Int32 _AgencyID = Int32.Parse(item["AgencyID"].Text);

           newAgencyID = int.Parse(newAgencyDropdown.SelectedValue);

           if (_AgencyID != newAgencyID)
           {
                Int32 _PreviousAgencyID = Int32.Parse(item["PreviousAgencyID"].Text);
                string _IsRetained = item["IsRetained"].Text;
                Int32 _ProductID = Int32.Parse(item["ProductID"].Text);

                DirectDBAccess db = new DirectDBAccess();
                string sqlEndorse = string.Format("UPDATE CNPL_EndorsementTemp SET AgencyID={0} Where AgencyID={1} And PreviousAgencyID={2} And IsRetained='{3}' And ProductID={4}", newAgencyID, _AgencyID, _PreviousAgencyID, _IsRetained, _ProductID);

                SqlCommand cmd = new SqlCommand(sqlEndorse);
                db.Open();
                db.CommandExecuteNonQuery(cmd, CommandType.Text);
                db.Close();

                break;
           }
       }

       BindRgEndorsements();
   }

    protected override void OnUnload(EventArgs e)
    {
        try
        {
            base.OnUnload(e);
            Locker.inUse = false;
            Locker.isCompleted = true;
            Locker.user = "";
        }
        catch (Exception ex)
        {
            string message = ex.Message;
        }
    }

   protected override void OnLoad(EventArgs e)
   {
       try
       {
           Server.ScriptTimeout = 9500;

           if (Locker.inUse == true && Locker.isCompleted == false && Locker.user.ToLower() != this.Web.CurrentUser.LoginName.ToLower())
           {
               Response.Redirect("error.aspx?innerException=Another User is already accessing endorsement&pageFrom=Endorsement To Agency"); //throw new Exception("Another user is already processing endorsement");
           }
           Locker.inUse = true;
           Locker.isCompleted = false;
           Locker.user = this.Web.CurrentUser.LoginName;

           security = new Security(this.Web.CurrentUser);
           userGroups = security.GetUserGroups();
           if (userGroups.Contains(SecurityGroups.Star))
           {
               ;
           }
           else if (userGroups.Contains(SecurityGroups.Agency))
           {
               Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
           }
           else if (userGroups.Contains(SecurityGroups.TeamCollector))
           {
               Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");
           }
           else
               Response.Redirect("Error.aspx?innerException=" + "Unauthorized Access." + "&pageFrom=AgencyProfile");


           if (!Page.IsPostBack)
           {
               BindReference();
               InitializeGrids();
               InitializeEndorsementDate();

               rbAccountNoMA.Checked = true;
               chkUseManualAdd.Checked = false;
               pnlManualAdd.Visible = false;
           }
           else
           {
               GetViewStates();
           }
           base.OnLoad(e);
       }
       catch (Exception ex)
       {
           string message = ex.Message;
       }
   }
   protected override void OnPreRender(EventArgs e)
   {
       try
       {
           ComputeEndorsementTotals();
           SetViewStates();
           base.OnPreRender(e);
       }
       catch (Exception ex)
       {
           string message = ex.Message;
       }
   }

}

2 个答案:

答案 0 :(得分:0)

OnInit

中存在错误

尝试在每个步骤周围放置try catch块,然后单步执行(而不是结束)每个函数,看看是否有任何问题。

我的猜测是你有一个尝试...捕获一个空的catch语句 - 否则你有一个例外来处理。

我们真的需要看到背后的代码,当我们看到代码时,这对我们中的一些人来说可能是显而易见的。

答案 1 :(得分:0)

我找到了问题的答案。

有一个未使用的事件,就是这个。

rgEndorsements.ItemEvent += new GridItemEventHandler(rgEndorsements_ItemEvent);

似乎我们必须检查是否正在使用所有“实例化”的事件。谢谢你的建议!非常感谢。