Exemple #1
0
    public static void Appointment()
    {
        //look for all the appointments in database
        //check if the date of the appointment has already had, if so, delete the appointment
        //check if the doctor is not in vacation in this day(i think i already did it but check again)

        AppointmentService appser = new AppointmentService();
        VacationService    vc = new VacationService();
        MessageService     ms = new MessageService();
        string             s = "SELECT * from Apointment", whereclout = "";
        string             tabels = "Apointment";
        DataSet            ds     = appser.GetApointmentAndSort(s, tabels, "");
        DataSet            vacationDs;
        DateTime           timeOfAppointment;
        DateTime           startVacDate, endVacDate;
        string             doctorId, userId, content = "";
        int     AppointmentId;
        Message m = new Message();
        Doctor  d;

        if (ds.Tables[0].Rows.Count != 0)
        {
            //check all the Appointments
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                AppointmentId     = Convert.ToInt32(ds.Tables[0].Rows[i]["ApointmentId"].ToString());
                timeOfAppointment = Convert.ToDateTime(ds.Tables[0].Rows[i]["ApointmentDate"].ToString());
                doctorId          = ds.Tables[0].Rows[i]["ApointmentDoctorId"].ToString();
                userId            = ds.Tables[0].Rows[i]["ApointmentUserId"].ToString();
                //if the date has been past, then delete the appointment
                if (timeOfAppointment < DateTime.Now)
                {
                    //delete the appointment
                    appser.DeleteAppointment(AppointmentId);
                    break;
                }
                //check if the doctor is in vacation in this date
                d          = GetAllDoctorDataById(doctorId);
                vacationDs = vc.IsDoctorOnVacation(doctorId);
                if (vacationDs.Tables[0].Rows.Count != 0)
                {
                    for (int j = 0; j < vacationDs.Tables[0].Rows.Count; j++)
                    {
                        startVacDate = Convert.ToDateTime(vacationDs.Tables[0].Rows[j]["VacationStartDate"].ToString());
                        endVacDate   = Convert.ToDateTime(vacationDs.Tables[0].Rows[j]["VacationEndDate"].ToString());
                        if (startVacDate <= timeOfAppointment && timeOfAppointment <= endVacDate)
                        {
                            //create a message from manager to user that says the appointment is canceled
                            //because the doctor is on vacation
                            m.CMessageUserId    = userId;
                            m.CMessageManagerId = "325132850";
                            m.CMessageSendDate  = DateTime.Now;
                            m.CMessageTheme     = "ביטול תור";
                            content             = "התור שהיה אמור להתקיים בתאריך " + timeOfAppointment + " עם הרופא " + d.CDoctorName + " התבטל בעקבות זה שהרופא יצא לחופשה";
                            m.CMessageContent   = content;
                            m.CMessageWhoSent   = "manager";
                            //Inseart the message to the database
                            whereclout  = "INSERT INTO Messages(MessageUserId,MessageManagerId,MessageTheme,MessageContent,MessageSendDate,MessageWhoSent)";
                            whereclout += " VALUES('" + m.CMessageUserId + "','" + m.CMessageManagerId + "','" + m.CMessageTheme + "','" + m.CMessageContent + "',#" + m.CMessageSendDate + "#,'" + m.CMessageWhoSent + "')";
                            ms.InseartMessageToDatabase(whereclout);
                        }
                    }
                }
            }
        }
    }
Exemple #2
0
    public static void VacationsForDoctor()
    {
        VacationService vs = new VacationService();
        DoctorService   docser = new DoctorService();
        DataSet         ds = docser.GetDoctors(), temp;
        DateTime        start, end;
        string          docId = "";
        int             vacId;

        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            docId = ds.Tables[0].Rows[i]["DoctorId"].ToString();
            if (Convert.ToBoolean(ds.Tables[0].Rows[i]["DoctorIsOnVacation"].ToString()))
            {
                temp = vs.IsDoctorOnVacation(docId);
                if (temp.Tables[0].Rows.Count != 0)
                {
                    //loop runs on all the doctors possible vacations
                    for (int j = 0; j < temp.Tables[0].Rows.Count; j++)
                    {
                        start = Convert.ToDateTime(temp.Tables[0].Rows[j]["VacationStartDate"].ToString());
                        end   = Convert.ToDateTime(temp.Tables[0].Rows[j]["VacationEndDate"].ToString());
                        if (DateTime.Now > end || DateTime.Now < start)
                        {
                            //update doctor
                            docser.UpdateDoctorVacation(false, docId);
                            //delete the vacation from database
                            if (DateTime.Now > end)
                            {
                                vacId = Convert.ToInt32(temp.Tables[0].Rows[j]["VacationId"].ToString());
                                vs.DeleteVacation(vacId);
                            }
                        }
                        else
                        {
                            docser.UpdateDoctorVacation(true, docId);
                            break;
                        }
                    }
                }
                else
                {
                    //update doctor
                    docser.UpdateDoctorVacation(false, docId);
                }
            }
            else
            {
                //if the doctors have vacations but DoctorIsOnVacation=false
                temp = vs.IsDoctorOnVacation(docId);
                if (temp.Tables[0].Rows.Count != 0)
                {
                    for (int j = 0; j < temp.Tables[0].Rows.Count; j++)
                    {
                        start = Convert.ToDateTime(temp.Tables[0].Rows[j]["VacationStartDate"].ToString());
                        end   = Convert.ToDateTime(temp.Tables[0].Rows[j]["VacationEndDate"].ToString());
                        if (DateTime.Now <= end && DateTime.Now >= start)
                        {
                            //update DoctorIsOnVacation=True
                            docser.UpdateDoctorVacation(true, docId);
                        }
                        else
                        {
                            //if the doctor have future vacation
                            if (DateTime.Now > end)
                            {
                                vacId = Convert.ToInt32(temp.Tables[0].Rows[j]["VacationId"].ToString());
                                vs.DeleteVacation(vacId);
                            }
                        }
                    }
                }
            }
        }
    }