Note that there are some explanatory texts on larger screens.

plurals
  1. POGrouping drop down list and applying them to a set of equations
    text
    copied!<p>I'm very new to using this site and to C# .Net so be gentle!</p> <p><strong>What is my project?</strong> I am creating a timesheet for my parents side business that doctors can fill out online. There are call hours and regular hours that I have created if statements for to equate the correct hours for both call and regular.</p> <p><strong>What am I trying to accomplish?</strong> I would like the user to click one submit button and have each group of drop down lists corresponding to each day run through the equations and give a total.</p> <p><strong>What is my question</strong>? How can I first off - group a set of Drop Down Lists and then - how would the code look to say something like "for some label(LabelMondayCALL.Text), use this group (DDL_In_Monday, DDL_OutBreak_Monday, etc.) of drop downs to find what the label would be." </p> <p><strong>Why do I want to do this?</strong> To avoid copy and pasting pages of code for each individual day and to try and keep things clean and simple for possible future changes.</p> <p>Here is some code:</p> <pre><code> DateTime MondayDDL4 = DateTime.Parse(DDL_Out_Monday.SelectedValue); DateTime MondayDDL3 = DateTime.Parse(DDL_InBreak_Monday.SelectedValue); DateTime MondayDDL2 = DateTime.Parse(DDL_OutBreak_Monday.SelectedValue); DateTime MondayDDL1 = DateTime.Parse(DDL_In_Monday.SelectedValue); else if ((MondayDDL1 &lt;= FromCompHours) &amp; (MondayDDL4 &lt;= FromCompHours)) //comp time earlier than 6:30 { LabelMondayREG.Text = "00:00:00";//works LabelMondayCALL.Text = MondayDDL4.Subtract(MondayDDL1).ToString();//works if ((BreakStart != "00:00:00") &amp; (BreakEnd != "00:00:00")) { LabelMondayREG.Text = "00:00:00"; String CompTimeBreakHours = (BreakEndDT.Subtract(BreakStartDT)).ToString(); LabelMondayCALL.Text = ((DateTime.Parse(LabelMondayCALL.Text)) - (DateTime.Parse(CompTimeBreakHours))).ToString(); } } </code></pre> <p>Thanks for any help you can provide and please let me know if you see anything else that I could simplify, like I said I'm fairly new to this stuff.</p> <hr> <p><strong>Here is some more code</strong> and a picture of the actual site, but here is a little bit more of a description of what I'm doing: Basically these equations are deciding what time (Call hours or Regular Hours) the doctors break should be subtracted from, for one day of the week, from a row of drop down menus. However I would prefer not to copy this code for each set of drop down lists. So I wanted to know if there was a way to create an instance to have the call hours and regular hours labels use only the drop downs that correspond to the day they are labeled.</p> <p>so MondayDDL1, 2, ,3 and 4 run through the equation and their answers fill in LabelMondayCall and LabelMondayReg</p> <p>and then</p> <p>TuesdayDDL1, 2, ,3 and 4 run through the equation and their answers fill in LabelTuesdayCall and LabelTuesdayReg</p> <p>Never mind no image I don't have enough reputation </p> <p>here is a bit of what the layout looks like though</p> <p>mondayDDL1 mondayDDL2 mondayDDL3 mondayDDL4 LABELmondayREG LABELmondayCALL</p> <p>tuesdayDDL1 tuesdayDDL2 tuesdayDDL3 tuesdayDDL4 LABELtuesdayREG LABELtuesdayCALL</p> <pre><code>protected void ButtonCalculate_Click(object sender, EventArgs e) { //DropDownList2.Items.Clear(); //DropDownList2.SelectedValue = null; //DropDownList3.Items.Clear(); //DropDownList3.SelectedValue = null; if (DDL_OutBreak_Monday.SelectedValue == "----") { DDL_OutBreak_Monday.SelectedValue = DateTime.Parse("00:00:00").ToShortTimeString(); } if (DDL_InBreak_Monday.SelectedValue == "----") { DDL_InBreak_Monday.SelectedValue = DateTime.Parse("00:00:00").ToShortTimeString(); } DateTime MondayDDL4 = DateTime.Parse(DDL_Out_Monday.SelectedValue); DateTime MondayDDL3 = DateTime.Parse(DDL_InBreak_Monday.SelectedValue); DateTime MondayDDL2 = DateTime.Parse(DDL_OutBreak_Monday.SelectedValue); DateTime MondayDDL1 = DateTime.Parse(DDL_In_Monday.SelectedValue); //DDL1 = DateTime.Parse(DDL_In_Tuesday.SelectedValue);// END POINT---------------------------END POINT String BreakStart = DDL_OutBreak_Monday.SelectedValue; String BreakEnd = DDL_InBreak_Monday.SelectedValue; DateTime BreakStartDT = DateTime.Parse(BreakStart); DateTime BreakEndDT = DateTime.Parse(BreakEnd); DateTime FromCompHours = DateTime.Parse("6:30:00"); DateTime ToCompHours = DateTime.Parse("16:30:00"); Label1.Text = ""; Label2.Text = ""; Label3.Text = ""; LabelMondayREG.Text = ""; LabelMondayCALL.Text = ""; //int result = DateTime.Compare(DDL1, DDL2); if ((MondayDDL1 &lt;= FromCompHours) &amp; (MondayDDL4 &gt;= ToCompHours))//Comp time at both ends { Label2.Text = FromCompHours.Subtract(MondayDDL1).ToString(); //finds comp hours before 6:30 WORKS Label3.Text = MondayDDL4.Subtract(ToCompHours).ToString(); //finds comp hours after 16:30 WORKS LabelMondayREG.Text = ("10:00:00"); //LabelHolder.Text = (DateTime.Parse(Label2.Text)) + (DateTime.Parse(Label3.Text)).ToString(); //adds the two comp hours together //TimeSpan SubtractReg = DDL2.Subtract(DDL1); //finds the difference of from minus to DateTime To = DateTime.Parse(Label2.Text);//convert text to datetime of earlier time DateTime From = DateTime.Parse(Label3.Text);//convert text to datetime of later time LabelMondayCALL.Text = (To.TimeOfDay + From.TimeOfDay).ToString(); //LabelMondayCALL.Text = "10:00:00"; if ((BreakStartDT != DateTime.Parse("00:00:00")) &amp; (BreakEndDT != DateTime.Parse("00:00:00"))) { //DateTime MondayBreak = MondayDDL3.Subtract(MondayDDL2); if ((MondayDDL2 &lt;= FromCompHours) &amp; (MondayDDL3 &lt;= FromCompHours)) //Start before 6:30 end after 16:30 w/ break before 6:30 { LabelMondayCALL.Text = TimeSpan.Parse(LabelMondayCALL.Text).Subtract(MondayDDL3.Subtract(MondayDDL2)).ToString(); //LabelMondayCALL.Text = "error1"; //(DateTime.Parse(LabelMondayCALL.Text)).ToString(); } if ((ToCompHours &gt;= MondayDDL2) &amp; (MondayDDL2 &gt;= FromCompHours) &amp; (ToCompHours &gt;= MondayDDL3) &amp; (MondayDDL3 &gt;= FromCompHours)) //Start before 6:30 end after 16:30 /w break between 6:30 and 16:30 { LabelMondayREG.Text = TimeSpan.Parse(LabelMondayREG.Text).Subtract(MondayDDL3.Subtract(MondayDDL2)).ToString(); } if ((MondayDDL2 &gt;= ToCompHours) &amp; (MondayDDL3 &gt;= ToCompHours)) //Start before 6:30 end after 16:30 /w break after 16:30 { LabelMondayCALL.Text = TimeSpan.Parse(LabelMondayCALL.Text).Subtract(MondayDDL3.Subtract(MondayDDL2)).ToString(); } if ((MondayDDL2 &lt;= FromCompHours) &amp; (MondayDDL3 &gt;= FromCompHours) &amp; (MondayDDL3 &lt;= ToCompHours)) { LabelMondayCALL.Text = TimeSpan.Parse(LabelMondayCALL.Text).Subtract(FromCompHours.Subtract(MondayDDL2)).ToString(); LabelMondayREG.Text = TimeSpan.Parse(LabelMondayREG.Text).Subtract(MondayDDL3.Subtract(FromCompHours)).ToString(); } if ((MondayDDL2 &lt;= ToCompHours) &amp; (MondayDDL2 &gt;= FromCompHours) &amp; (MondayDDL3 &gt;= ToCompHours)) { LabelMondayCALL.Text = TimeSpan.Parse(LabelMondayCALL.Text).Subtract(ToCompHours.Subtract(MondayDDL2)).ToString(); LabelMondayREG.Text = TimeSpan.Parse(LabelMondayREG.Text).Subtract(MondayDDL3.Subtract(ToCompHours)).ToString(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload