Beispiel #1
0
    protected void DateTB_TextChanged(object sender, EventArgs e)
    {
        HoursGridView.Visible = false;

        /*
         * ברגע שהמשתמש בוחר איזה תאריך הוא רוצה יופיעו ברשימה הנגללת למטה
         * כל השעות שהוא יכול לבחור לעשות את התור, כל עוד התור לא תפוס
         * אם המשתמש בחר תאריך שבו לרופא הספציפי שהוא בחר אין תורים פנויים
         * בלייבל למטה יהיה כתוב "ביום זה לרופא (שם הרופא) אין תורים, אנא בחר תאריך אחר
         */

        DateValid.Text = "";

        if (DateTB.Text == "")
        {
            Response.Write("<script>alert('תאריך לא תקין')</script>");
            AppHour.Visible      = false;
            SubmitButton.Visible = false;
            ResetButton.Visible  = false;
            return;
        }

        DateTime selectedDate = Convert.ToDateTime(DateTB.Text);

        if (selectedDate < DateTime.Now.Date)
        {
            Response.Write("<script>alert('תאריך לא תקין')</script>");
            AppHour.Visible      = false;
            SubmitButton.Visible = false;
            ResetButton.Visible  = false;
            return;
        }

        string day       = Convert.ToString(Convert.ToDateTime(DateTB.Text).DayOfWeek);
        int    dayNumber = 0;

        if (day == "Sunday")
        {
            dayNumber = 1;
        }
        else if (day == "Monday")
        {
            dayNumber = 2;
        }
        else if (day == "Tuesday")
        {
            dayNumber = 3;
        }
        else if (day == "Wednesday")
        {
            dayNumber = 4;
        }
        else if (day == "Thursday")
        {
            dayNumber = 5;
        }
        else if (day == "Friday")
        {
            dayNumber = 6;
        }
        Session["dayNumber"] = dayNumber;

        ////////////////////////////////////////////////////////

        string          doctorId = (string)Session["doctorId"];
        WorkDaysService wds      = new WorkDaysService();
        DataSet         ds       = wds.GetAllWorkingDaysForDoctor(doctorId);
        int             count    = 0;

        //put all the days the doctor works in a list
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            if (Convert.ToInt32(ds.Tables[0].Rows[i]["WorkDay"]) == dayNumber)
            {
                break;
            }
            count++;
        }
        if (count >= ds.Tables[0].Rows.Count)
        {
            Response.Write("<script>alert('הרופא שבחרת לא עובד ביום זה אנא בחר רופא אחר או יום אחר')</script>");
            AppHour.Visible      = false;
            SubmitButton.Visible = false;
            ResetButton.Visible  = false;
            return;
        }

        /*
         * להציג ברשימה הנגללת את כל השעות הפנויות של הרופא ביום הנבחר
         * לרשום שאילתה שעוברת על הטבלה של תורים בדאטאבייס ובודקת האם יש תור כזה כבר
         * אם יש היא לא מציגה את התור ברישמה הנגללת
         * אם לא קיים היא מציגה אותו ברשימה הנגללת
         */

        ds = wds.GetStartAndEndHour(doctorId, dayNumber);
        int StartTime = Convert.ToInt32(ds.Tables[0].Rows[0]["DoctorStartTime"].ToString());
        int EndTime   = Convert.ToInt32(ds.Tables[0].Rows[0]["DoctorEndTime"].ToString());

        /*
         * לעשות שאילתה בשעות שמקבלת שעת התחלה וסיום ומחזירה את כל התורים האפשריים
         * לעשות קודם בדיקות תקינות פשוטות למרות שאין כל כך צורך
         * לשים את כל הנתונים בגריד וויו
         */
        HourService hs = new HourService();

        ds = hs.GetApointmentTime(StartTime, EndTime);
        Appointment a = new Appointment();

        //הלולאה מוחקת את כל השעות שבהם לרופא זה כבר יש תורים

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            a.CApointmentDate     = selectedDate;
            a.CApointmentHour     = Convert.ToInt32(ds.Tables[0].Rows[i]["HourNumber"].ToString());
            a.CApointmentDoctorId = DoctorDropDownList.SelectedValue;
            //לרשום שאילתה שבודקת האם תור כזה קיים
            AppointmentService ap   = new AppointmentService();
            DataSet            temp = ap.IsAppointmentExist(a.CApointmentDoctorId, a.CApointmentDate, a.CApointmentHour);
            if (temp.Tables[0].Rows.Count != 0)
            {
                //delete the line i from the dataset
                ds.Tables[0].Rows[i].Delete();
            }
        }
        //שם את השעות הפנויות בגריד וויו

        HoursGridView.Visible    = true;
        HoursGridView.DataSource = ds;
        HoursGridView.DataBind();

        AppHour.Visible = true;

        Session["ApDate"] = selectedDate;
    }