Example #1
0
        /// <summary>
        /// Called before the page is rendered.  This is used for the save functionality.<br />
        /// First the current data is archived to: BMcBillTrackerArchive<br />
        /// Then, the data is saved to BMcBillTracker
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_PreRender(object sender, EventArgs e)
        {
            if (Page.IsPostBack)
            {
                String sessionResetCookie = "false";
                if (Session["resetCookie"] != null)
                {
                    sessionResetCookie = Session["resetCookie"].ToString();
                }

                if (sessionResetCookie.Equals("true"))
                {
                    Session["resetCookie"] = "false";
                }

                int totalRows = dataGridView.Rows.Count;
                for (int r = 0; r < totalRows; r++)
                {
                    if (utility.GetRowChanged()[r])
                    {
                        Session["rowEdited"] = r;

                        GridViewRow thisGridViewRow = dataGridView.Rows[r];

                        int  billingPeriod    = Int32.Parse(Request["billpd"].ToString());
                        bool thresholdApplied = Convert.ToBoolean(Request["threshold"].ToString());

                        String reversalCode        = "";
                        String id                  = "";
                        String comment             = "";
                        String exceptionReason     = "";
                        int    review1_DraftSent   = 0;
                        int    review2_ReadyToBill = 0;
                        int    exception           = 0;

                        try
                        {
                            id                  = thisGridViewRow.Cells[columnID].Text;
                            reversalCode        = ((TextBox)thisGridViewRow.FindControl("reversalTB")).Text.Replace("'", "''");
                            review1_DraftSent   = ((CheckBox)thisGridViewRow.FindControl("review1CB")).Checked == true ? 1 : 0;
                            review2_ReadyToBill = ((CheckBox)thisGridViewRow.FindControl("review2CB")).Checked == true ? 1 : 0;
                            comment             = ((TextBox)thisGridViewRow.FindControl("notesTB")).Text.Replace("'", "''");
                            if (utility.IsAdminUser)
                            {
                                exceptionReason = ((TextBox)thisGridViewRow.FindControl("ReasonTB")).Text.Replace("'", "''");
                                if (exceptionReason.Equals(""))
                                {
                                    exception = 0;
                                }
                                else
                                {
                                    exception = 1;
                                }
                            }
                        }
                        catch (FormatException)
                        {
                            //this is to catch when set to a nonNumber
                            //non numbers are converted to zero
                        }
                        catch (ArgumentOutOfRangeException ae)
                        {
                            //when using paging
                            Logger.QuickLog(errorLogFileName, ae.Message, "Page_PreRender()", "");
                        }

                        SqlConnection con = null;

                        String sqlArchive = " INSERT INTO BMcBillTrackerArchive "
                                            + " SELECT ID "
                                            + " ,readyToBill "
                                            + " ,readyToBillDate "
                                            + " ,draftSent "
                                            + " ,draftSentDate "
                                            + " ,reversalCode "
                                            + " ,comment "
                                            + " ,exception "
                                            + " ,reason "
                                            + " ,billing_attorney "
                                            + " ,invoice_attorney "
                                            + " ,rate_code "
                                            + " ,tmatter "
                                            + " ,clnum "
                                            + " ,billingPeriod "
                                            + " ,updatedBy "
                                            + " ,updateTime "
                                            + " FROM BMcBillTracker "
                                            + " WHERE ID = " + id;


                        String sqlUpdate = " UPDATE BMcBillTracker "
                                           + " SET readyToBill = " + review2_ReadyToBill
                                           + " ,draftSent = " + review1_DraftSent
                                           + " ,reversalCode = '" + reversalCode + "' "
                                           + " ,comment = '" + comment + "' ";
                        if (utility.IsAdminUser)
                        {
                            sqlUpdate = sqlUpdate
                                        + " ,reason = '" + exceptionReason + "'"
                                        + " ,exception = " + exception;
                        }

                        sqlUpdate = sqlUpdate
                                    + " ,updatedBy = '" + Page.User.Identity.Name.ToString().Substring(8) + "' "
                                    + " ,updateTime = '" + DateTime.Now + "' "
                                    + " WHERE ID = " + id;



                        try
                        {
                            con = new SqlConnection(
                                ConfigurationManager.ConnectionStrings["eliteConnectionString"].ConnectionString);
                            con.Open();
                            SqlCommand command = con.CreateCommand();
                            command.CommandType = CommandType.Text;
                            command.CommandText = sqlArchive;
                            command.ExecuteNonQuery();

                            try
                            {
                                command.CommandText = sqlUpdate;
                                command.ExecuteNonQuery();
                            }
                            catch (SqlException sqleUpdate)
                            {
                                Logger.QuickLog(errorLogFileName, sqleUpdate.Message, "Page_PreRender()", sqlUpdate);
                            }
                        }
                        catch (SqlException sqleArchive)
                        {
                            Logger.QuickLog(errorLogFileName, sqleArchive.Message, "Page_PreRender()", sqlArchive);
                        }
                        finally
                        {
                            if (con != null)
                            {
                                con.Close();
                            }
                        }
                    } //end "if (rowChanged[r])"
                }     //end "for (int r = 0; r < totalRows; r++)"
                dataGridView.DataBind();
            }         //end if (Page.IsPostBack)
            else
            {
                dataGridView.SelectedIndex = -1;
            }
        } //end Page_PreRender()