Exemple #1
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        STD_ClassTime sTD_ClassTime = new STD_ClassTime ();

        bool is12PMIssueEnd = false;
        if (ddlEndHour.SelectedValue == "12" && ddlEndAMPM.SelectedValue == "PM")
        {
            is12PMIssueEnd = true;
            txtEndTime.Text = "0:" + ddlEndMin.SelectedValue + " " + ddlEndAMPM.SelectedValue;
        }
        else
        {
            txtEndTime.Text = ddlEndHour.SelectedValue + ":" + ddlEndMin.SelectedValue + " " + ddlEndAMPM.SelectedValue;
        }

        bool is12PMIssueStart = false;
        if (ddlStartHour.SelectedValue == "12" && ddlStartAMPM.SelectedValue == "PM")
        {
            is12PMIssueStart = true;
            txtStartTime.Text = "0:" + ddlStartMin.SelectedValue + " " + ddlStartAMPM.SelectedValue;
        }
        else
        {
            txtStartTime.Text = ddlStartHour.SelectedValue + ":" + ddlStartMin.SelectedValue + " " + ddlStartAMPM.SelectedValue;
        }
            //txtEndTime.Text = ddlEndHour.SelectedValue + ":" + ddlEndMin.SelectedValue + " " + ddlEndAMPM.SelectedValue;
        txtClassTimeName.Text = (is12PMIssueStart ? "12:" + txtStartTime.Text.ToString().Split(':')[1] : txtStartTime.Text.ToString()) + " - " + (is12PMIssueEnd ? "12:" + txtEndTime.Text.ToString().Split(':')[1] : txtEndTime.Text.ToString());

            TimeList timeList = new TimeList();
            List<Time> times = new List<Time>();
            times = timeList.getTimeList();
            foreach (Time t in times)
            {
                if (txtStartTime.Text == t.TimeName) txtExtraField1.Text = t.TimeID.ToString();
                if (txtEndTime.Text == t.TimeName) txtExtraField2.Text = t.TimeID.ToString();
            }
            txtDuration.Text = ((int.Parse(txtExtraField2.Text) - int.Parse(txtExtraField1.Text)) * 5).ToString();

        //Check in the group
            //DataSet classTimesAll = STD_ClassTimeManager.GetSTD_ClassTimeByClassTimeGroupID();
            DataSet classTimes = STD_ClassTimeManager.GetSTD_ClassTimeByClassTimeGroupID(int.Parse(ddlClassTimeGroupID.SelectedValue));
            bool isConfict = false;

            foreach (DataRow dr in classTimes.Tables[0].Rows)
            {
                if ((int.Parse(dr["ExtraField1"].ToString()) <= int.Parse(txtExtraField1.Text) && int.Parse(dr["ExtraField2"].ToString()) >= int.Parse(txtExtraField1.Text))
                    || (int.Parse(dr["ExtraField1"].ToString()) <= int.Parse(txtExtraField2.Text) && int.Parse(dr["ExtraField2"].ToString()) >= int.Parse(txtExtraField2.Text)))
                {
                    isConfict = true;
                    divNewRoutineTimeGourp.Visible = true;
                    lblMessage.Text = "</br>There is a conflict with the Class Time Group-<span style='color:red;'>" + ddlClassTimeGroupID.SelectedItem.Text + "</span>. Please change it<br/>OR<br/>Click on the following button to set # System Generated";
                    try
                    {
                        if (ddlClassTimeGroupID.SelectedValue != ddlClassTimeGroupID.Items[ddlClassTimeGroupID.Items.Count - 1].Value)
                        {
                            ddlClassTimeGroupID.SelectedValue = (int.Parse(ddlClassTimeGroupID.SelectedValue) + 1).ToString();
                            btnAdd_Click(this, new EventArgs());
                        }
                        else
                        {
                            btnAddWithNewTimeGroup_Click(this, new EventArgs());
                        }
                    }
                    catch (Exception ex)
                    {
                        btnAddWithNewTimeGroup_Click(this, new EventArgs());
                    }
                    return;
                }
            }

            foreach (DataRow dr in classTimes.Tables[1].Rows)
            {
                if ((int.Parse(dr["ExtraField1"].ToString()) <= int.Parse(txtExtraField1.Text) && int.Parse(dr["ExtraField2"].ToString()) >= int.Parse(txtExtraField1.Text))
                    || (int.Parse(dr["ExtraField1"].ToString()) <= int.Parse(txtExtraField2.Text) && int.Parse(dr["ExtraField2"].ToString()) >= int.Parse(txtExtraField2.Text)))
                {
                    txtExtraField3.Text += dr["ClassTimeID"].ToString() + ";";
                }
            }

            divNewRoutineTimeGourp.Visible = false;
            lblMessage.Text = "";

        //	sTD_ClassTime.ClassTimeID=  int.Parse(ddlClassTimeID.SelectedValue);
        sTD_ClassTime.ClassTimeName=  txtClassTimeName.Text;
        sTD_ClassTime.Duration=  decimal.Parse(txtDuration.Text);
        sTD_ClassTime.AddedBy=  Profile.card_id;
        sTD_ClassTime.AddedDate=  DateTime.Now;
        sTD_ClassTime.UpdatedBy=  Profile.card_id;
        sTD_ClassTime.UpdateDate=  DateTime.Now;
        sTD_ClassTime.Order=  int.Parse(txtOrder.Text);
        sTD_ClassTime.ClassTimeGroupID=  int.Parse(ddlClassTimeGroupID.SelectedValue);
        sTD_ClassTime.StartTime = (is12PMIssueStart ? "12:" + txtStartTime.Text.ToString().Split(':')[1] : txtStartTime.Text.ToString());
        sTD_ClassTime.EndTime = (is12PMIssueEnd ? "12:" + txtEndTime.Text.ToString().Split(':')[1] : txtEndTime.Text.ToString());
        sTD_ClassTime.ExtraField1=  txtExtraField1.Text;
        sTD_ClassTime.ExtraField2=  txtExtraField2.Text;
        sTD_ClassTime.ExtraField3=  txtExtraField3.Text;
        sTD_ClassTime.ExtraField4=  txtExtraField4.Text;
        sTD_ClassTime.ExtraField5=  txtExtraField5.Text;
        sTD_ClassTime.RowStatusID=  int.Parse(ddlRowStatusID.SelectedValue);
        int resutl =STD_ClassTimeManager.InsertSTD_ClassTime(sTD_ClassTime);
        Response.Redirect("AdminDisplaySTD_ClassTime.aspx");
    }