Click here to Skip to main content
15,904,023 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
private void CheckTotalHours()
    {
        //This function is for calculating hours and Total hours of Weekend and Calculating Rotational Shift Time //
        //-------------------------------------------------------------------------------------------------------//

        foreach (GridViewRow gv in gvScheduling.Rows)
        {


            //-------For Finding IN OUT TextBoxes-------------//
            //------------------------------------------------//
            TextBox txIn1 = ((TextBox)gv.FindControl("tIn1"));
            TextBox txOut1 = ((TextBox)gv.FindControl("tOut1"));
            TextBox txIn2 = ((TextBox)gv.FindControl("tIn2"));
            TextBox txOut2 = ((TextBox)gv.FindControl("tOut2"));
            TextBox txIn3 = ((TextBox)gv.FindControl("tIn3"));
            TextBox txOut3 = ((TextBox)gv.FindControl("tOut3"));
            TextBox txIn4 = ((TextBox)gv.FindControl("tIn4"));
            TextBox txOut4 = ((TextBox)gv.FindControl("tOut4"));
            TextBox txIn5 = ((TextBox)gv.FindControl("tIn5"));
            TextBox txOut5 = ((TextBox)gv.FindControl("tOut5"));
            TextBox txIn6 = ((TextBox)gv.FindControl("tIn6"));
            TextBox txOut6 = ((TextBox)gv.FindControl("tOut6"));
            TextBox txIn7 = ((TextBox)gv.FindControl("tIn7"));
            TextBox txOut7 = ((TextBox)gv.FindControl("tOut7"));

            Label lb1 = ((Label)gv.FindControl("lblHours1"));
            Label lb2 = ((Label)gv.FindControl("lblHours2"));
            Label lb3 = ((Label)gv.FindControl("lblHours3"));
            Label lb4 = ((Label)gv.FindControl("lblHours4"));
            Label lb5 = ((Label)gv.FindControl("lblHours5"));
            Label lb6 = ((Label)gv.FindControl("lblHours6"));
            Label lb7 = ((Label)gv.FindControl("lblHours7"));
            Label lb8 = ((Label)gv.FindControl("lblHours8"));


            //------For Finding BreakSart BreakEnd TextBoxes------------//
            //--------------------------------------------------------
            TextBox tbIn1 = ((TextBox)gv.FindControl("tBIn1"));
            TextBox tbOut1 = ((TextBox)gv.FindControl("tBOut1"));
            TextBox tbIn2 = ((TextBox)gv.FindControl("tBIn2"));
            TextBox tbOut2 = ((TextBox)gv.FindControl("tBOut2"));
            TextBox tbIn3 = ((TextBox)gv.FindControl("tBIn3"));
            TextBox tbOut3 = ((TextBox)gv.FindControl("tBOut3"));
            TextBox tbIn4 = ((TextBox)gv.FindControl("tBIn4"));
            TextBox tbOut4 = ((TextBox)gv.FindControl("tBOut4"));
            TextBox tbIn5 = ((TextBox)gv.FindControl("tBIn5"));
            TextBox tbOut5 = ((TextBox)gv.FindControl("tBOut5"));
            TextBox tbIn6 = ((TextBox)gv.FindControl("tBIn6"));
            TextBox tbOut6 = ((TextBox)gv.FindControl("tBOut6"));
            TextBox tbIn7 = ((TextBox)gv.FindControl("tBIn7"));
            TextBox tbOut7 = ((TextBox)gv.FindControl("tBOut7"));


            Label PositionName = ((Label)gv.FindControl("lblPositionName"));




            if (txOut1.Text != "" && txIn1.Text != "")
            {
                if (txIn1.Text.Contains("PM") && txOut1.Text.Contains("AM"))
                {
                    dt1 = Convert.ToDateTime(LWed.Text + ' ' + txIn1.Text); //Assiging value In In Time
                    dt2 = Convert.ToDateTime(LThu.Text + ' ' + txOut1.Text); //Assigning value In Out Time
                    dt3 = Convert.ToDateTime(LWed.Text + ' ' + sTime);  //Assigning value for Upto 11:59 PM
                    dt4 = Convert.ToDateTime(LThu.Text + ' ' + sDTime); //Assigning value from 12:OOAM

                    total_IN = dt3.Subtract(dt1);
                    total_IN = total_IN.Add(TimeSpan.FromMinutes(1));  //Adding 1 min in 59 min to make it one hour
                    total_OUT = dt2.Subtract(dt4);
                    Total1 = total_IN + total_OUT;

                    //For Checking Break acc to total hours if hours greater than 6 detect half hour  or if hours greater than 12 detect 1 hours//
                    if (Total1.Hours >= 12)
                    {
                        Total1 = Total1.Add(TimeSpan.FromHours(-1));

                    }
                    else if (Total1.Hours >= 6)
                    {
                        Total1 = Total1.Add(TimeSpan.FromMinutes(-30));

                        //----------Assigning Break BreakStart and BreakEnd Textboxes----------------------------------------------------------------------------------------------//
                        //-----------------------------------------------------------------------------------------------------------------------//


                        //if (PositionName.Text == "Sandwich Artist" || PositionName.Text == "Sandwich artist")
                        //{
                        //    if (status1 == "")
                        //    {
                        //        dt1 = dt1.AddHours(3);           //Add 3 hours From Starting Time Comming From CheckTotalHours();                
                        //        tbIn1.Text = dt1.ToShortTimeString();
                        //        dt1 = dt1.AddMinutes(30);
                        //        tbOut1.Text = dt1.ToShortTimeString();
                        //        status1 = "1";
                        //    }
                        //    else if (status1 == "1")
                        //    {
                        //        dt1 = dt1.AddHours(3);           //Add 3 hours 30 Minutes From Starting Time Comming From CheckTotalHours();                
                        //        tbIn1.Text = dt1.ToShortTimeString();
                        //        dt1 = dt1.AddMinutes(30);
                        //        tbOut1.Text = dt1.ToShortTimeString();
                        //        status1 ="2";
                        //    }
                        //    else if (status1 == "2")
                        //    {
                        //        status1 = "3";
                        //    }
                        //    else if (status1 == "3")
                        //    {
                        //        status1 = "";
                        //    }

                        //}
                        //else
                        //{
                        //}


                    }

                    //Total1.TotalMinutes calculate hours + minutes in minutes and then divide by 60
                    lb1.Text = (Total1.TotalMinutes / 60).ToString() == "" ? "0" : (Total1.TotalMinutes / 60).ToString();

                    //Calculate Total Hours of whole  Weekend from Wednesday to Tuesday
                    iTime += Convert.ToDecimal(lb1.Text);
                    lb8.Text = iTime.ToString();

                    //Calculate Total Hours of All Employee of Wednesday
                    TotalH1 += Convert.ToDecimal(lb1.Text);
                    lblTotalHours1.Text = TotalH1.ToString();

                }
                else
                {
                    dt1 = Convert.ToDateTime(LWed.Text + ' ' + txIn1.Text);
                    dt2 = Convert.ToDateTime(LWed.Text + ' ' + txOut1.Text);
                    Total1 = dt2.Subtract(dt1);

                    //For Checking Break acc to total hours if hours greater than 6 detect half hour  or if hours greater than 12 detect 1 hours//
                    if (Total1.Hours >= 12)
                    {
                        Total1 = Total1.Add(TimeSpan.FromHours(-1));

                    }
                    else if (Total1.Hours >= 6)
                    {
                        Total1 = Total1.Add(TimeSpan.FromMinutes(-30));
                    }

                    //Total1.TotalMinutes calculate hours + minutes in minutes and then divide by 60
                    lb1.Text = (Total1.TotalMinutes / 60).ToString() == "" ? "0" : (Total1.TotalMinutes / 60).ToString();

                    //Calculate Total Hours of whole  Weekend from Wednesday to Tuesday
                    iTime += Convert.ToDecimal(lb1.Text);
                    lb8.Text = iTime.ToString();

                    //Calculate Total Hours of All Employee of Wednesday
                    TotalH1 += Convert.ToDecimal(lb1.Text);
                    lblTotalHours1.Text = TotalH1.ToString();
                }


            }
           
            

        }
    }
Posted
Updated 11-Jun-13 1:36am
v2
Comments
mahinder.singh.chauhan 11-Jun-13 7:36am    
I want to use this functionality in javascript so please give some ideas regarding this function
[no name] 11-Jun-13 8:47am    
yeah, u can do it, do something like...

1.get gridViewID from view source of your page in browser,here
2.for labels use :var labels = gridViewID.getElementsByTagName('span');
for (var i = 0; i < labels.length; i++) { .... }
3.for input use :var textboxes= gridViewID.getElementsByTagName('text');
4.loop through and put your logic.
mahinder.singh.chauhan 11-Jun-13 9:48am    
sir but it is possible to calculate the hours of intime textboxs and outtime textbox then calculate hours row wise and calculate hour acc to column wise because in above my question what i was doing is i m just find all the controls of textbox on textchanged calculate the hours and calculate the time between InTime textbox or Out Time textbox so this logic will work for it please suggest me so i can start working on your idea thanks in advance
mahinder.singh.chauhan 11-Jun-13 9:49am    
if this question is not clearifying all the scenario can i post both code behind and aspx part
Maryami.bagheri 11-Jun-13 8:55am    
if you have masterpage maybe the solution does not work properly, for this reason you should set the clienidtmode of 'text' element to 'static' in 'asp' code

1 solution

C#
var gridViewID = "<%=grdMenu.ClientID %>";
           var gridView = document.getElementById(gridViewID);
           var Menuitem = new Ncoretech.Business.Data.MenuType();
           var e = document.getElementById("<%= ddlRestaurantName.ClientID%>");
           var gridViewControls = gridView.getElementsByTagName("input");
           for (i = 0; i < gridViewControls.length; i++) {
               if (gridViewControls[i].id.search("txtNewMenuName") != "-1") {
                   Menuitem.MenuName = gridViewControls[i].value;
               }
           }
           gridViewControls = gridView.getElementsByTagName("textarea");
           for (i = 0; i < gridViewControls.length; i++) {
               if (gridViewControls[i].id.search("txtNewMenuDescription") != "-1") {
                   Menuitem.MenuDescription = gridViewControls[i].value;
               }
           }
           Menuitem.RestaurantIndex_Id = e.options[e.selectedIndex].value;
           if (Menuitem.MenuName == "") {
               alert("Item name has to be enter.");
               return false;
           }
           if (Menuitem.MenuDescription == "") {
               Menuitem.MenuDescription = "none";
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900