1

我对使用这个网站和 C# .Net 很陌生,所以要温柔!

我的项目是什么? 我正在为我父母的副业创建一个时间表,医生可以在线填写。我创建了通话时间和常规时间,用于将通话时间和常规时间等同起来。

我想完成什么? 我希望用户单击一个提交按钮,并让与每一天相对应的每组下拉列表通过方程式运行并给出总数。

我的问题是什么?我如何首先关闭 - 对一组下拉列表进行分组,然后 - 代码看起来如何像“对于某些标签(LabelMondayCALL.Text),使用该组(DDL_In_Monday、DDL_OutBreak_Monday 等)的下拉列表找出标签是什么。”

我为什么要这样做?为了避免在每一天复制和粘贴代码页面,并尝试保持事情的清洁和简单,以应对未来可能的变化。

这是一些代码:

    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 <= FromCompHours) & (MondayDDL4 <= 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") & (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();
        } 
    }

感谢您提供的任何帮助,如果您看到其他可以简化的内容,请告诉我,就像我说我对这些东西还很陌生。


这是更多代码和实际站点的图片,但这里是对我正在做的事情的更多描述:基本上这些方程式决定了医生休息的时间(通话时间或常规时间)应该减去来自,一周中的一天,来自一排下拉菜单。但是,我不希望为每组下拉列表复制此代码。所以我想知道是否有一种方法可以创建一个实例,让通话时间和常规时间标签仅使用与它们被标记的日期相对应的下拉菜单。

所以MondayDDL1, 2, ,3 和4 贯穿等式,它们的答案填写在LabelMondayCall 和LabelMondayReg

接着

TuesdayDDL1, 2, ,3 和 4 贯穿等式,它们的答案填写在 LabelTuesdayCall 和 LabelTuesdayReg

没关系没有形象我没有足够的声誉

这里有一些布局的样子

星期一DDL1 星期一DDL2 星期一DDL3 星期一DDL4 LABELmondayREG LABELmondayCALL

星期二DDL1 星期二DDL2 星期二DDL3 星期二DDL4 LABELtuesdayREG LABELtuesdayCALL

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 <= FromCompHours) & (MondayDDL4 >= 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")) & (BreakEndDT != DateTime.Parse("00:00:00")))
        {
            //DateTime MondayBreak = MondayDDL3.Subtract(MondayDDL2);

            if ((MondayDDL2 <= FromCompHours) & (MondayDDL3 <= 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 >= MondayDDL2) & (MondayDDL2 >= FromCompHours) & (ToCompHours >= MondayDDL3) & (MondayDDL3 >= 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 >= ToCompHours) & (MondayDDL3 >= 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 <= FromCompHours) & (MondayDDL3 >= FromCompHours) & (MondayDDL3 <= 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 <= ToCompHours) & (MondayDDL2 >= FromCompHours) & (MondayDDL3 >= ToCompHours))
            {
                LabelMondayCALL.Text = TimeSpan.Parse(LabelMondayCALL.Text).Subtract(ToCompHours.Subtract(MondayDDL2)).ToString();
                LabelMondayREG.Text = TimeSpan.Parse(LabelMondayREG.Text).Subtract(MondayDDL3.Subtract(ToCompHours)).ToString();
            }
        }
4

0 回答 0