protected void grdvwViewServiceWindow_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int servicewindowid;

        servicewindowid = Convert.ToInt16(grdvwViewServiceWindow.Rows[e.RowIndex].Cells[0].Text);
        objservicehrs.Delete(servicewindowid);
        objserviceday.Delete(servicewindowid);
        objservicewindow.Delete(servicewindowid);
        BindGridAll();
    }
Beispiel #2
0
    // Handler btnSave_click to handle event
    protected void btnSave_Click(object sender, EventArgs e)
    {
        lblErrorMsgWorkingTime.Text = "";
        lblErrorMsgWorkingDays.Text = "";
        // Declare local variables FlagStartEndTime and FlagDaysCheck and varSiteId and FlagInsert
        int FlagStartEndTime = 0;
        int FlagDaysCheck    = 0;
        int varSiteId;
        int FlagInsert;
        // Declare locl variables starthr,startmin,endhr and endmin
        int starthr, startmin, endhr, endmin;

        // Check radio button 24 hr has checked
        if (rdbtn24hr.Checked == true)
        {
            starthr  = 0;
            startmin = 1;
            endhr    = 23;
            endmin   = 59;
        }
        // Select other check box
        else
        {
            starthr  = Convert.ToInt16(drpStarthour.SelectedValue);
            startmin = Convert.ToInt16(drpStartmin.SelectedValue);
            endhr    = Convert.ToInt16(drpEndhr.SelectedValue);
            endmin   = Convert.ToInt16(drpEndmin.SelectedValue);
        }

        // Check Start time Should be less than End Time
        if (rdbtn24hr.Checked == true)
        {
            FlagStartEndTime = 1;
        }
        else
        {
            // Check condition start hour  shoild less than End hour
            if (starthr < endhr)
            {
                FlagStartEndTime = 1;
            }
            // Check condition start hour and end hour is equal,then start min should less than End min
            else if (starthr == endhr && startmin < endmin)
            {
                FlagStartEndTime = 1;
            }
            else
            {
                FlagStartEndTime = 0;
            }
        }


        // Check At Least one Working Days has been Selected
        if (chkMonday.Checked == false && chkTuesday.Checked == false && chkWednesday.Checked == false && chkThursday.Checked == false && chkFriday.Checked == false && chkSaturday.Checked == false && chkSunday.Checked == false)
        {
            FlagDaysCheck = 0;
        }
        else
        {
            FlagDaysCheck = 1;
        }
        // If FlagStartEndTime is zeros then display error message,start time should less than end time
        if (FlagStartEndTime == 0)
        {
            lblErrorMsgWorkingTime.Text = Resources.MessageResource.errWorkingTime.ToString();
            lblErrorMsg.Text            = "";
        }
        // If FlagDaysCheck is zeros then display error message,select at least one check box
        if (FlagDaysCheck == 0)
        {
            lblErrorMsgWorkingDays.Text = Resources.MessageResource.errWorkingDays.ToString();
            lblErrorMsg.Text            = "";
        }

        // If FlagStartEndTime is one and FlagDaysCheck is one then
        if (FlagStartEndTime == 1 && FlagDaysCheck == 1)
        {
            // Declare local variable varSiteId
            varSiteId = Convert.ToInt16(drpSites.SelectedValue);
            // to get the object objSerWindow by calling function Get_By_id(varSiteId)
            objSerWindow = objSerWindow.Get_By_id(varSiteId);
            // If objSerWindow.Siteid  is not zero then object exist
            if (objSerWindow.Siteid == 0)
            {
                objSerWindow.Siteid = varSiteId;
                FlagInsert          = objSerWindow.Insert();
                // If Flag Insert is 1,then inser operation performed successfully
                if (FlagInsert == 1)
                {
                    // Definition of Service hours insertion -Start
                    // Declare local variable
                    int FlagHrInsert;
                    int FlagDayInsert;

                    objSerWindow = objSerWindow.Get_By_id(varSiteId);
                    objSerHours.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerHours.Starthour       = starthr;
                    objSerHours.Startmin        = startmin;
                    objSerHours.Endhour         = endhr;
                    objSerHours.Endmin          = endmin;
                    FlagHrInsert = objSerHours.Insert();
                    // Definition of Service hours insertion -End

                    // Definition of Service Day insertion -Start

                    // find  which check box has been selected
                    if (chkMonday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Monday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Monday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    if (chkTuesday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Tuesday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Tuesday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    if (chkWednesday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Wednesday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Wednesday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    if (chkThursday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Thursday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Thursday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    if (chkFriday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Friday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Friday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    if (chkSaturday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Saturday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Saturday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    if (chkSunday.Checked == true)
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Sunday";
                        objSerDay.Isworking       = true;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    else
                    {
                        objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                        objSerDay.Weekday         = "Sunday";
                        objSerDay.Isworking       = false;
                        FlagDayInsert             = objSerDay.Insert();
                    }
                    // if FlagHrInsert and FlagDayInsert is one ie data hase been inserted successfully
                    if (FlagHrInsert == 1 && FlagDayInsert == 1)
                    {
                        lblErrorMsg.Text = Resources.MessageResource.errServiceWindParm.ToString();
                    }
                    else
                    {
                        objSerDay.Delete(objSerWindow.Servicewindowid);
                        objSerHours.Delete(objSerWindow.Servicewindowid);
                        objSerWindow.Delete(objSerWindow.Servicewindowid);
                        lblErrorMsg.Text = Resources.MessageResource.errOccured.ToString();
                    }


                    // Definition of Service Day insertion -End
                }
                else
                {
                    lblErrorMsg.Text = Resources.MessageResource.errOccured.ToString();
                }
            }
            else
            {
                // Definition of Service hours Update -Start
                int FlagHrUpdate;
                int FlagDayUpdate;

                objSerWindow = objSerWindow.Get_By_id(varSiteId);
                objSerHours.Servicewindowid = objSerWindow.Servicewindowid;
                objSerHours.Starthour       = starthr;
                objSerHours.Startmin        = startmin;
                objSerHours.Endhour         = endhr;
                objSerHours.Endmin          = endmin;
                FlagHrUpdate = objSerHours.Update();
                // Definition of Service hours Update -End


                // Definition of Service Day Updation -Start

                if (chkMonday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Monday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Monday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (chkTuesday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Tuesday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Tuesday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (chkWednesday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Wednesday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Wednesday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (chkThursday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Thursday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Thursday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (chkFriday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Friday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Friday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (chkSaturday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Saturday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Saturday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (chkSunday.Checked == true)
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Sunday";
                    objSerDay.Isworking       = true;
                    FlagDayUpdate             = objSerDay.Update();
                }
                else
                {
                    objSerDay.Servicewindowid = objSerWindow.Servicewindowid;
                    objSerDay.Weekday         = "Sunday";
                    objSerDay.Isworking       = false;
                    FlagDayUpdate             = objSerDay.Update();
                }
                if (FlagHrUpdate == 1 && FlagDayUpdate == 1)
                {
                    lblErrorMsg.Text = Resources.MessageResource.errServiceWindParm.ToString();
                }



                // Definition of Service Day insertion -End
            }
            if (Request.QueryString.Count != 0)
            {
                Response.Redirect("~/admin/ViewServiceWindow.aspx");
            }
        }
    }