Exemplo n.º 1
0
        protected void delLink_Click(object sender, EventArgs e)
        {
            LinkButton  del    = (LinkButton)sender;
            GridViewRow gvr    = (GridViewRow)del.NamingContainer;
            int         delRow = gvr.RowIndex;


            string delete = string.Format(@"DELETE FROM [PAYOUTschedule] WHERE [Id] = '{0}';"
                                          , GridView1.Rows[delRow].Cells[0].Text);

            Queries.ExecuteFromQueryString(delete);



            //using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
            //{
            //    string delete = string.Format(@"DELETE FROM [PAYOUTschedule] WHERE [Id] = '{0}'", GridView1.Rows[delRow].Cells[0].Text);
            //    con.Open();
            //    using (SqlCommand cmd = new SqlCommand(delete, con))
            //    {
            //        SqlDataReader reader = cmd.ExecuteReader();
            //    }
            //    con.Close();
            //}

            GridView1.DataBind();
        }
Exemplo n.º 2
0
        protected void Apply_Click(object sender, EventArgs e)
        {
            string SQLstring;

            if (HiddenIdTextBox.Text != "")
            {
                SQLstring = string.Format(@"UPDATE PAYOUTRoleCommission
                                            SET StoreName = '{0}', Program = '{1}', RoleId = {2}, StandardComm = {3}
                                            WHERE Id = {4}",
                                          sstoreAddDDL.SelectedValue,
                                          programAddDDL.SelectedValue,
                                          roleAddDDL.SelectedValue,
                                          CommissionTxt.Text == "" ? "NULL" :CommissionTxt.Text,
                                          HiddenIdTextBox.Text);
            }
            else
            {
                SQLstring = string.Format(@"INSERT INTO PAYOUTRoleCommission (StoreName, Program, RoleId, StandardComm, EffectiveDate) 
                                            VALUES ('{0}','{1}',{2},{3},'{4}')",
                                          sstoreAddDDL.SelectedValue,
                                          programAddDDL.SelectedValue,
                                          roleAddDDL.SelectedValue,
                                          CommissionTxt.Text == "" ? "NULL" : CommissionTxt.Text,
                                          lblEffectiveDate.Text == "" ? Common.ApplyDateFormat(DateTime.Now) : lblEffectiveDate.Text);
            }


            Queries.ExecuteFromQueryString(SQLstring);
            //BindGridData();
        }
Exemplo n.º 3
0
        private int InsertRecord(string ScheduleId, string TrainerId, string TrainStartDate, string TrainEndDate)
        {
            try
            {
                if (TrainerId != "0")
                {
                    string SQLString = string.Format(@" SELECT COUNT(*)
                                                FROM [PAYOUTScheduleTrainer]
                                                WHERE ([TrainStartDate] BETWEEN '{0}' AND '{1}'
                                                OR [TrainEndDate] BETWEEN '{0}' AND '{1}'
                                                OR ([TrainStartDate] <= '{0}' AND [TrainEndDate] >= '{1}')) 
                                                AND [TrainerId] = {2}", TrainStartDate, TrainEndDate, TrainerId);

                    if (Queries.GetResultsFromQueryString(SQLString).Rows[0][0].ToString() == "0")
                    {
                        SQLString = string.Format(@"INSERT INTO PAYOUTScheduleTrainer
                                            (ScheduleId, TrainerId, TrainStartDate, TrainEndDate)
                                            VALUES
                                            ({0},{1},'{2}','{3}')", ScheduleId, TrainerId, TrainStartDate, TrainEndDate);

                        Queries.ExecuteFromQueryString(SQLString);
                        return(1);
                    }
                }
            }
            catch
            {
                return(-1);
            }
            return(0);
        }
Exemplo n.º 4
0
        protected void addBtn_Click(object sender, EventArgs e)
        {
            string Firstname = Request.Form["TxtFName"].ToString();
            string lastname  = Request.Form["TxtLname"].ToString();

            bool Active = true;

            if (CHKActive.Checked)
            {
                Active = true;
            }
            else
            {
                Active = false;
            }

            DataTable dt = Queries.GetResultsFromQueryString("select MAX(ID) + 1 from [PAYOUTtrainManager]");

            string SQLstring = string.Format(@"INSERT INTO [PAYOUTtrainManager] (Firstname, Lastname, Active) 
                                VALUES ('{0}', '{1}', {2})", Firstname, lastname, Convert.ToInt32(Active));

            Queries.ExecuteFromQueryString(SQLstring);

            Response.Redirect("TrainerManager.aspx", true);
        }
Exemplo n.º 5
0
        protected void BtnDelete_Click(object sender, EventArgs e)
        {
            string      ScheduleTrainerId = string.Empty;
            GridViewRow gvr = (GridViewRow)((Control)sender).Parent.Parent;

            for (int i = 0; i < gvr.Cells.Count; i++)
            {
                if (gvr.Cells[i].Controls.Count == 0)
                {
                    switch (((DataControlFieldCell)(gvr.Cells[i])).ContainingField.HeaderText)
                    {
                    case "scheduleTrainerId":
                        ScheduleTrainerId = (gvr.Cells[i]).Text;
                        break;
                    }
                }
            }

            if (ScheduleTrainerId != "&nbsp;")
            {
                try
                {
                    string SQLString = string.Format(@" DELETE
                                                FROM [PAYOUTScheduleTrainer]
                                                WHERE [Id] = {0}", ScheduleTrainerId);

                    Queries.ExecuteFromQueryString(SQLString);
                    BindGridData();
                }
                catch {}
            }
        }
Exemplo n.º 6
0
        protected void FieldChanged(Object sender, EventArgs e)
        {
            TextBox     txt = (TextBox)sender;
            GridViewRow gvr = (GridViewRow)txt.NamingContainer;

            rowindex = gvr.RowIndex;
            string update;

            if (txt.ID == "OwnerFirstname" || txt.ID == "OwnerLastname" || txt.ID == "HubFirstname" || txt.ID == "HubLastname")
            {
                update = string.Format("UPDATE [PAYOUTschedule] SET {0} = {1} WHERE [Id] = '{2}'",
                                       txt.ID,
                                       txt.Text.Trim() == "" ? "NULL" : "'" + txt.Text + "'",
                                       GridView1.Rows[rowindex].Cells[0].Text);
            }
            else
            {
                update = string.Format("UPDATE [PAYOUTschedule] SET {0} = '{1}' WHERE [Id] = '{2}'",
                                       txt.ID,
                                       txt.Text,
                                       GridView1.Rows[rowindex].Cells[0].Text);
            }


            if (txt.ID == "EventId")
            {
                if (txt.Text.All(char.IsNumber))
                {
                    Queries.ExecuteFromQueryString(update);
                }
            }
            else
            {
                Queries.ExecuteFromQueryString(update);
            }



            //using (SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString()))
            //{
            //    string update = "UPDATE [PAYOUTschedule] SET " + txt.ID + " = '" + txt.Text + "' WHERE [Id] = '" + GridView1.Rows[rowindex].Cells[0].Text + "' " /*+ updateR*/;
            //    con.Open();
            //    using (SqlCommand cmd = new SqlCommand(update, con))
            //    {
            //        SqlDataReader reader = cmd.ExecuteReader();
            //    }
            //    con.Close();
            //}

            GridView1.DataBind();
        }
Exemplo n.º 7
0
        protected void delLink_Click(object sender, EventArgs e)
        {
            LinkButton  del    = (LinkButton)sender;
            GridViewRow gvr    = (GridViewRow)del.NamingContainer;
            int         delRow = gvr.RowIndex;


            string delete = string.Format(@"DELETE FROM [PAYOUTschedule] WHERE [Id] = '{0}';"
                                          , GridView1.Rows[delRow].Cells[0].Text);

            Queries.ExecuteFromQueryString(delete);

            GridView1.DataBind();
        }
        public static void JSONRequestFromClient(string CheckDate)
        {
            DateTime date = new DateTime();

            DateTime.TryParse(CheckDate, out date);

            if (date.Year > 0001)
            {
                string SQLString = string.Format(@"INSERT INTO PAYOUTPMCheckDates (WeekEnding, YearBalance) VALUES ('{0}', {1})", CheckDate, date.Year);

                Queries.ExecuteFromQueryString(SQLString);
            }

            // I want it here!
        }
Exemplo n.º 9
0
        protected void delLink_Click(object sender, EventArgs e)
        {
            LinkButton  del    = (LinkButton)sender;
            GridViewRow gvr    = (GridViewRow)del.NamingContainer;
            int         delRow = gvr.RowIndex;

            //Cascade deleting
            string SQLstring = string.Format("DELETE FROM [PAYOUTtrainerManager] WHERE TrainManagerId = {0}", GridView1.Rows[delRow].Cells[0].Text);

            Queries.ExecuteFromQueryString(SQLstring);

            SQLstring = "DELETE FROM [PAYOUTtrainManager] WHERE [Id] = '" + GridView1.Rows[delRow].Cells[0].Text + "'";
            Queries.ExecuteFromQueryString(SQLstring);

            GridView1.DataBind();
        }
Exemplo n.º 10
0
        protected void addBtn_Click(object sender, EventArgs e)
        {
            string Firstname = Request.Form["TxtFName"].ToString();
            string lastname  = Request.Form["TxtLname"].ToString();
            string Email     = Request.Form["Txtemail"].ToString();
            string Role      = Request.Form["DDLRole"].ToString();
            string Salary    = Request.Form["TxtSalary"].ToString();
            string Manager   = Request.Form["DDLManager"].ToString();


            bool Active = true;

            if (CHKActive.Checked)
            {
                Active = true;
            }
            else
            {
                Active = false;
            }


            DataTable dt = Queries.GetResultsFromQueryString("select MAX(ID) + 1 from [PAYOUTtrainer]");

            decimal OUTresult = 0;

            if (!decimal.TryParse(Salary, out OUTresult))
            {
                Salary = OUTresult.ToString("F2");
            }

            string SQLstring = string.Format(@"INSERT INTO [PAYOUTtrainer] (ID, Firstname, Lastname, EmailAddress, Active, Role, Salary) 
                                VALUES ({0}, '{1}', '{2}', '{3}', {4}, '{5}', {6})", dt.Rows[0][0].ToString(), Firstname, lastname, Email, Convert.ToInt32(Active), Role, Salary);

            Queries.ExecuteFromQueryString(SQLstring);

            SQLstring = string.Format(@"INSERT INTO [PAYOUTtrainerManager] ([TrainerId], [TrainManagerId]) VALUES ({0}, (SELECT TOP 1 Id 
                                                                                                                        FROM [PAYOUTtrainManager] 
                                                                                                                        WHERE FirstName + ' ' + LastName = '{1}'))",
                                      dt.Rows[0][0].ToString(),
                                      Manager);

            Queries.ExecuteFromQueryString(SQLstring);

            Response.Redirect("Trainer.aspx", true);
        }
Exemplo n.º 11
0
        protected void addBtn_Click(object sender, EventArgs e)
        {
            string start   = Request.Form["StartDateT"].ToString();
            string end     = Request.Form["EndDateT"].ToString();
            string program = progDDL.SelectedValue;
            string city    = Request.Form["CityT"].ToString();
            string state   = Request.Form["StateT"].ToString();
            //string country = Request.Form["CountryT"].ToString();
            string club    = Request.Form["ClubT"].ToString();
            string owf     = Request.Form["OFN"].ToString();
            string owl     = Request.Form["OLN"].ToString();
            string hbf     = Request.Form["HFN"].ToString();
            string hbl     = Request.Form["HLN"].ToString();
            string eventid = Request.Form["EventIdT"] == null ? "NULL" : Request.Form["EventIdT"].ToString();

            int IdConvert = 0;

            int.TryParse(eventid, out IdConvert);
            eventid = IdConvert == 0 ? "NULL" : IdConvert.ToString();

            string retailer = storeDDL.SelectedValue;
            string Id       = string.Empty;

            string update = string.Format(@"declare @MaxId as int = (SELECT MAX(Id) + 1 FROM [PAYOUTschedule]);

                                          INSERT INTO [PAYOUTschedule] 
                                            (Id, Program, StartDate, EndDate, StoreName, StoreNumber, City, State, OwnerFirstname, OwnerLastname, 
                                            HubFirstname, HubLastname, ImportedBy, EventId, ImportedOn, Archive)
                                            VALUES (@MaxId, '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', {7}, {8}, {9}, {10}, '{11}', {12}, CURRENT_TIMESTAMP, 0);
		
                                            /*And then RESEED Temp table*/
                                            DBCC CHECKIDENT ('[Payout].[dbo].[PAYOUTscheduleTemp]', RESEED, @MaxId);",
                                          program, start, end, retailer, club, city, state,
                                          owf.Trim() == "" ? "NULL" : "'" + owf + "'",
                                          owl.Trim() == "" ? "NULL" : "'" + owl + "'",
                                          hbf.Trim() == "" ? "NULL" : "'" + hbf + "'",
                                          hbl.Trim() == "" ? "NULL" : "'" + hbl + "'",
                                          user, eventid
                                          );

            Queries.ExecuteFromQueryString(update);

            Response.Redirect("Schedule.aspx", true);
        }
Exemplo n.º 12
0
        protected void FieldChanged(Object sender, EventArgs e)
        {
            TextBox     txt = (TextBox)sender;
            GridViewRow gvr = (GridViewRow)txt.NamingContainer;

            rowindex = gvr.RowIndex;
            string update;

            if (txt.ID == "OwnerFirstname" || txt.ID == "OwnerLastname" || txt.ID == "HubFirstname" || txt.ID == "HubLastname")
            {
                update = string.Format("UPDATE [PAYOUTschedule] SET {0} = {1} WHERE [Id] = '{2}'",
                                       txt.ID,
                                       txt.Text.Trim() == "" ? "NULL" : "'" + txt.Text + "'",
                                       GridView1.Rows[rowindex].Cells[0].Text);
            }
            else
            {
                update = string.Format("UPDATE [PAYOUTschedule] SET {0} = '{1}' WHERE [Id] = '{2}'",
                                       txt.ID,
                                       txt.Text,
                                       GridView1.Rows[rowindex].Cells[0].Text);
            }

            if (txt.ID == "EventId")
            {
                if (txt.Text.All(char.IsNumber))
                {
                    Queries.ExecuteFromQueryString(update);
                }
            }
            else
            {
                Queries.ExecuteFromQueryString(update);
            }


            if (txt.ID == "StartDate" || txt.ID == "EndDate")
            {
                Payout.FullSalesAuditCls.SchedBuildCommentSalesAuditFull(GridView1.Rows[rowindex].Cells[0].Text, txt.ID, user);
            }

            GridView1.DataBind();
        }
Exemplo n.º 13
0
        private int UpdateScheduleRecord(DateTime?TrainStartDate, DateTime?TrainEndDate, DateTime?ScheduleStartDate, DateTime?ScheduleEndDate, string trainerId, string scheduleTrainerId)
        {
            if (trainerId != "0)")
            {
                string SQLstring = string.Empty;
                SQLstring = string.Format(@" SELECT COUNT(*)
                                            FROM [PAYOUTScheduleTrainer]
                                            WHERE ([TrainStartDate] BETWEEN '{0}' AND '{1}'
                                            OR [TrainEndDate] BETWEEN '{0}' AND '{1}'
                                            OR ([TrainStartDate] <= '{0}' AND [TrainEndDate] >= '{1}')) 
                                            AND [TrainerId] = {2}", TrainStartDate, TrainEndDate, trainerId);

                try
                {
                    if (Queries.GetResultsFromQueryString(SQLstring).Rows[0][0].ToString() != "0")
                    {
                        SQLstring = "UPDATE [PAYOUTScheduleTrainer] SET";

                        if (TrainStartDate != null && TrainEndDate != null && trainerId != null && trainerId != "0")
                        {
                            SQLstring += string.Format(" {0} = {1},", "TrainStartDate", "'" + TrainStartDate + "'");
                            SQLstring += string.Format(" {0} = {1},", "TrainEndDate", "'" + TrainEndDate + "'");
                            SQLstring += string.Format(" {0} = {1}", "TrainerID", "'" + trainerId + "'");
                        }
                        else
                        {
                            SQLstring += string.Format(" {0} = {1},", "TrainStartDate", "NULL");
                            SQLstring += string.Format(" {0} = {1},", "TrainEndDate", "NULL");
                            SQLstring += string.Format(" {0} = {1}", "TrainerID", "NULL");
                        }

                        SQLstring += " WHERE [Id] = '" + scheduleTrainerId + "' ";
                        Queries.ExecuteFromQueryString(SQLstring);
                        return(1);
                    }
                }
                catch
                {
                    return(-1);
                }
            }
            return(0);
        }
Exemplo n.º 14
0
        protected void DropDownChanged(Object sender, EventArgs e)
        {
            DropDownList DDL      = (DropDownList)sender;
            GridViewRow  gvr      = (GridViewRow)DDL.NamingContainer;
            string       DDLValue = string.Empty;

            if (DDL.DataValueField.ToLower() == "active")
            {
                DDLValue = DDL.SelectedValue.ToLower().Replace("true", "1").Replace("false", "0");
            }

            rowindex = gvr.RowIndex;

            string SQLstring = string.Format("UPDATE [PAYOUTtrainManager] SET {0} = {1} WHERE [Id] = '{2}'",
                                             DDL.DataValueField.ToLower(),
                                             DDLValue,
                                             GridView1.Rows[rowindex].Cells[0].Text);

            Queries.ExecuteFromQueryString(SQLstring);
        }
Exemplo n.º 15
0
        protected void delLink_Click(object sender, EventArgs e)
        {
            LinkButton  del    = (LinkButton)sender;
            GridViewRow gvr    = (GridViewRow)del.NamingContainer;
            int         delRow = gvr.RowIndex;

            string SQLstring = string.Empty;

            SQLstring = string.Format(@"SELECT COUNT(*) FROM[PAYOUTtrainerManager] WHERE TrainerId = {0}", GridView1.Rows[rowindex].Cells[0].Text);
            DataTable dt = Queries.GetResultsFromQueryString(SQLstring);

            if (dt.Rows[0][0].ToString() == "0")
            {
                SQLstring = "DELETE FROM [PAYOUTtrainerManager] WHERE [TrainerId] = " + GridView1.Rows[delRow].Cells[0].Text;
                Queries.ExecuteFromQueryString(SQLstring);
            }

            SQLstring = "DELETE FROM [PAYOUTtrainer] WHERE [Id] = " + GridView1.Rows[delRow].Cells[0].Text;
            Queries.ExecuteFromQueryString(SQLstring);


            GridView1.DataBind();
        }
Exemplo n.º 16
0
        protected void Apply_Click(object sender, EventArgs e)
        {
            decimal  weeklycompensation = -1, Override = -1;
            DateTime EffDate = new DateTime();

            decimal.TryParse(WeeklyCompensationTxt.Text, out weeklycompensation);
            decimal.TryParse(OverrideTxt.Text, out Override);
            DateTime.TryParse(EffectiveDate.Text, out EffDate);

            if (weeklycompensation == 0 || Override == 0 || EffDate.Year == 1)
            {
                WeeklyCompensationTxt.BackColor = Color.White;
                OverrideTxt.BackColor           = Color.White;
                EffectiveDate.BackColor         = Color.White;
                ValidateCompensation.InnerText  = "";
                ValidateOverride.InnerText      = "";
                ValidateEffectiveDate.InnerText = "";


                UpdatePanelUpperBox.Update();
                if (weeklycompensation == 0)
                {
                    ValidateCompensation.InnerText  = "Please enter a valid value";
                    WeeklyCompensationTxt.BackColor = Color.Salmon;
                }

                if (Override == 0)
                {
                    ValidateOverride.InnerText = "Please enter a valid value";
                    OverrideTxt.BackColor      = Color.Salmon;
                }

                if (EffDate.Year == 1)
                {
                    ValidateEffectiveDate.InnerText = "Please enter a valid value";
                    EffectiveDate.BackColor         = Color.Salmon;
                }
            }
            else
            {
                UpdatePanelTopWrapper.Update();
                UpdatePanelUpperBox.Update();

                string SQLstring;
                if (HiddenIdTextBox.Text != "")
                {
                    SQLstring = string.Format(@"UPDATE PAYOUTOverridesPM
                                                SET TrainerId = {0}, StoreName = '{1}', Program = '{2}', WeeklyCompensation = {3}, Override = {4}
                                                WHERE Id = {5}",
                                              trainerAddDDL.SelectedValue,
                                              sstoreAddDDL.SelectedValue,
                                              programAddDDL.SelectedValue,
                                              weeklycompensation,
                                              Override,
                                              HiddenIdTextBox.Text);
                }
                else
                {
                    SQLstring = string.Format(@"INSERT INTO PAYOUTOverridesPM (TrainerId, StoreName, Program, WeeklyCompensation, Override, EffectiveDate) 
                                                VALUES ({0},'{1}','{2}',{3},{4},'{5}')",
                                              trainerAddDDL.SelectedValue,
                                              sstoreAddDDL.SelectedValue,
                                              programAddDDL.SelectedValue,
                                              weeklycompensation,
                                              Override,
                                              EffectiveDate.Text);
                }


                Queries.ExecuteFromQueryString(SQLstring);
                Response.Redirect(Request.RawUrl);
                //BindGridData();
            }
        }
Exemplo n.º 17
0
        protected void DropDownChanged(Object sender, EventArgs e)
        {
            DropDownList DDL      = (DropDownList)sender;
            GridViewRow  gvr      = (GridViewRow)DDL.NamingContainer;
            string       DDLValue = string.Empty;

            if (DDL.DataValueField.ToLower() == "role")
            {
                DDLValue = "'" + DDL.SelectedValue + "'";
            }

            if (DDL.DataValueField.ToLower() == "manager")
            {
                DDLValue = "'" + DDL.SelectedValue + "'";
            }

            if (DDL.DataValueField.ToLower() == "active")
            {
                DDLValue = DDL.SelectedValue.ToLower().Replace("true", "1").Replace("false", "0");
            }



            rowindex = gvr.RowIndex;
            string SQLstring = string.Empty;

            if (DDL.DataValueField.ToLower() == "manager")
            {
                SQLstring = string.Format(@"SELECT COUNT(*) FROM[PAYOUTtrainerManager] WHERE TrainerId = {0}", GridView1.Rows[rowindex].Cells[0].Text);
                DataTable dt = Queries.GetResultsFromQueryString(SQLstring);

                if (dt.Rows[0][0].ToString() == "0")
                {
                    SQLstring = string.Format(@"INSERT INTO [PAYOUTtrainerManager] ([TrainerId], [TrainManagerId]) VALUES ({0}, (SELECT TOP 1 Id 
                                                                                                                                  FROM [PAYOUTtrainManager] 
                                                                                                                                  WHERE FirstName + ' ' + LastName = {1}))",
                                              GridView1.Rows[rowindex].Cells[0].Text,
                                              DDLValue);
                }
                else
                {
                    if (DDLValue == "'Unassigned'")
                    {
                        SQLstring = string.Format(@"DELETE FROM [PAYOUTtrainerManager] WHERE TrainerId = {0}", GridView1.Rows[rowindex].Cells[0].Text);
                    }
                    else
                    {
                        SQLstring = string.Format(@"UPDATE [PAYOUTtrainerManager] SET TrainManagerId = (SELECT TOP 1 Id 
                                                                                                  FROM [PAYOUTtrainManager] 
                                                                                                  WHERE FirstName + ' ' + LastName = {0}) WHERE [TrainerId] = '{1}'",
                                                  DDLValue,
                                                  GridView1.Rows[rowindex].Cells[0].Text);
                    }
                }
            }
            else
            {
                SQLstring = string.Format("UPDATE [PAYOUTTrainer] SET {0} = {1} WHERE [Id] = '{2}'",
                                          DDL.DataValueField.ToLower(),
                                          DDLValue,
                                          GridView1.Rows[rowindex].Cells[0].Text);
            }

            Queries.ExecuteFromQueryString(SQLstring);
        }
        protected void SubmitPayroll_Click(object sender, EventArgs e)
        {
            string SQLstring;
            string SQLstringDates = string.Format(@"SELECT COUNT(*)
                                              FROM[PAYOUTPMPayroll]
                                              WHERE[CheckDate] = '{0}'", GRVCheckPeriod.Rows[0].Cells[0].Text);

            List <PMPaycheck> CheckPeriodToInsertUpdate = ((List <PMPaycheck>)Session["CheckPeriodTable"]).Where(f => f.CheckDate == GRVCheckPeriod.Rows[0].Cells[0].Text).ToList();


            StringBuilder sb = new StringBuilder();

            foreach (PMPaycheck item in CheckPeriodToInsertUpdate)
            {
                if (sb.Length > 0)
                {
                    sb.Append(" UNION ALL");
                }

                SQLstring = string.Format(@"(SELECT {0} CheckDate, {1} TrainerId, {2} TrainerName, {3} Manager, {4} [Role], {5} Salary, 
                                                        {6} Override, {7} Commission, {8} OverPay, {9} UnderPay,{10}  OTPremium, 
                                                        {11} VacationPay, {12} TravelTime, {13} ClawBack, {14} Adjustment, 
                                                        {15} AdjustmentComment, {16} PayCheck, GETDATE() CreatedOn)",
                                          "'" + item.CheckDate + "'",
                                          item.TrainerId,
                                          "'" + item.TrainerName + "'",
                                          item.Manager == null ? "null" : "'" + item.Manager + "'",
                                          item.Role == null ? "null" : "'" + item.Role + "'",
                                          item.Salary == null ? "null" : item.Salary.Value.ToString("F2"),
                                          item.Override == null ? "null" : item.Override.Value.ToString("F2"),
                                          item.Commission == null ? "null" : item.Commission.Value.ToString("F2"),
                                          item.OverPay == null ? "null" : item.OverPay.Value.ToString("F2"),
                                          item.UnderPay == null ? "null" : item.UnderPay.Value.ToString("F2"),
                                          item.OTPremium == null ? "null" : item.OTPremium.Value.ToString("F2"),
                                          item.VacationPay == null ? "null" : item.VacationPay.Value.ToString("F2"),
                                          item.TravelTime == null ? "null" : item.TravelTime.Value.ToString("F2"),
                                          item.ClawBack == null ? "null" : item.ClawBack.Value.ToString("F2"),
                                          item.Adjustment == null ? "null" : "'" + item.Adjustment + "'",
                                          item.AdjustmentComment == null ? "null" : "'" + item.AdjustmentComment + "'",
                                          item.Paycheck == null ? "null" : item.Paycheck.Value.ToString("F2")
                                          );

                sb.Append(SQLstring);
            }

            //Here we have the table we are going to insert or update
            SQLstring = sb.ToString();

            if (Queries.GetResultsFromQueryString(SQLstringDates).Rows[0][0].ToString() == "0")
            {
                //Insert Values
                SQLstring = @"INSERT INTO PAYOUTPMPayroll
                         (CheckDate, TrainerId, TrainerName, Manager, Role, Salary, Override, Commission, OverPay, 
                        UnderPay, OTPremium, VacationPay, TravelTime, ClawBack, Adjustment, AdjustmentComment, PayCheck, CreatedOn)" + SQLstring;

                try
                {
                    Queries.ExecuteFromQueryString(SQLstring);
                    SubmitCommissionOverrideSummaries(Convert.ToDateTime(GRVCheckPeriod.Rows[0].Cells[0].Text));

                    SQLstring = string.Format(@"UPDATE PAYOUTPMCheckDates 
                                                SET ClosedPeriodDate = GETDATE(), ClosedBy = {0}
                                                WHERE WeekEnding = '{1}'",
                                              user == null ? "NULL" : "'" + user + "'",
                                              GRVCheckPeriod.Rows[0].Cells[0].Text);
                    Queries.ExecuteFromQueryString(SQLstring);
                    FindOpenCheckDates();
                    Session["BiweekTable"] = null;

                    MessageAlert.InnerText           = "Records Inserted successfully";
                    MessageAlert.Attributes["style"] = "color:green; font-weight:bold";
                }
                catch (Exception ex)
                {
                    MessageAlert.InnerText           = "Error Inserting Values";
                    MessageAlert.Attributes["style"] = "color:red; font-weight:bold";
                }
            }
            else
            {
                SQLstringDates = "SELECT COUNT(*) FROM [Payout].[dbo].[PAYOUTPMCheckDates] WHERE [WeekEnding] >= GETDATE()";
                if (Queries.GetResultsFromQueryString(SQLstringDates).Rows[0][0].ToString() == "1")
                {
                    try
                    {
                        SQLstring = string.Format(@"UPDATE p
                                                    SET p.OTPremium = v.OTPremium, 
                                                    p.VacationPay = v.VacationPay, 
                                                    p.TravelTime = v.TravelTime, 
                                                    p.ClawBack = v.ClawBack, 
                                                    p.Adjustment = v.Adjustment, 
                                                    p.AdjustmentComment = v.AdjustmentComment,
                                                    p.PayCheck = v.PayCheck
                                                    FROM PAYOUTPMPayroll p INNER JOIN
                                                    ({0}) v ON p.CheckDate = v.CheckDate AND p.TrainerId = v.TrainerId", SQLstring);
                        Queries.ExecuteFromQueryString(SQLstring);

                        MessageAlert.InnerText           = "Records Updated successfully";
                        MessageAlert.Attributes["style"] = "color:green; font-weight:bold";
                    }
                    catch (Exception ex)
                    {
                        MessageAlert.InnerText           = "Error Updating Values";
                        MessageAlert.Attributes["style"] = "color:red; font-weight:bold";
                    }
                }
                else
                {
                    MessageAlert.InnerText           = "Operation Denied";
                    MessageAlert.Attributes["style"] = "color:red; font-weight:bold";
                }
            }

            if (ddlCheckPeriod.SelectedValue == "0" || ddlCheckPeriod.SelectedValue == "")
            {
                Session["DDLShow"] = "Close";
                CheckPeriodResults();
            }
            else
            {
                SetSession_PeriodIsOpenOrClosed();
                CheckPeriodResults(ddlCheckPeriod.SelectedItem.Text);
            }

            MessageAlert.Visible = true;
        }