コード例 #1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                this.CheckIfFieldEmpty();

                PersonRepo p = new PersonRepo();
                p.Name       = this.txtFullName.Text;
                p.Age        = Convert.ToInt32(this.txtAge.Text);
                p.Gender     = this.cmbGender.Text;
                p.BloodGroup = this.cmbBloodGrp.Text;
                p.Phone      = this.txtPhoneNumber.Text;


                EmployeeRepo e1 = new EmployeeRepo();

                e1.Salary      = Convert.ToInt32(this.txtSalary.Text);
                e1.Designation = this.cmbDesignation.Text;
                //e1.PersonIdOfEmp = Convert.ToInt32(this.txtId.Text);

                DoctorRepo dr = new DoctorRepo();
                dr.Specialty     = this.txtSpecialty.Text;
                dr.AvailableDays = this.cmbAvailableDays.Text;
                //dr.EmployeeIdOfDoctor = Convert.ToInt32(this.txtEmpId.Text);

                //person created
                p.CreatePerson(p.Name, p.Age, p.Gender, p.BloodGroup, p.Phone);
                this.PopulatePersonTable();
                //refrsh

                //get last person
                DataTable lastperson = p.GetLastPerson();

                //DataTable lastperson = p.GetLastPerson();
                this.personID = Convert.ToInt32(lastperson.Rows[0]["personid"].ToString());

                //getpersonid
                //this.personID = Convert.ToInt32(lastperson.Rows[0]["personid"].ToString());
                //create emplyee
                e1.CreateEmployee(e1.Designation, e1.Salary, this.personID);
                if (this.cmbDesignation.Text == "Doctor")
                {
                    DataTable lastemp = e1.GetLastEmployee();
                    this.empID = Convert.ToInt32(lastemp.Rows[0]["empid"].ToString());

                    //create doctor
                    dr.CreateDoctor(dr.Specialty, dr.AvailableDays, empID);
                }

                MessageBox.Show("Successfully added!");
                this.PopulatePersonTable();
                this.ClearAll();
            }
            catch (Exception exc)
            {
                MessageBox.Show("error!" + exc);
            }
        }
コード例 #2
0
        private void btnConfirmAppointment_Click(object sender, EventArgs e)
        {
            try
            {
                // Check if text field contains value
                this.CheckTextField();

                if (this.dtpAppointmentDate.Value.Date < DateTime.Today)
                {
                    throw new Exception("Selected date must be of today or future");
                }

                DoctorRepo doctorRepo = new DoctorRepo();
                DataTable  doctorData = doctorRepo.GetIndividualDoctorsInfo(Convert.ToInt32(this.txtDoctorID.Text));
                doctorRepo.DoctorID           = Convert.ToInt32(doctorData.Rows[0]["doctorid"].ToString());
                doctorRepo.Specialty          = doctorData.Rows[0]["specialty"].ToString();
                doctorRepo.AvailableDays      = doctorData.Rows[0]["availabledays"].ToString();
                doctorRepo.EmployeeIdOfDoctor = Convert.ToInt32(doctorData.Rows[0]["empid"].ToString());

                // Check if available day of doctor matches with appointment day
                string[] daysAvailabe  = doctorRepo.AvailableDays.Split(' ');
                bool     checkValidDay = false;
                //string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3).ToLower();
                string selectedDay = dtpAppointmentDate.Value.DayOfWeek.ToString().Substring(0, 3);

                foreach (string days in daysAvailabe)
                {
                    if (days.Equals(selectedDay))
                    {
                        checkValidDay = true;
                        break;
                    }
                    else
                    {
                        checkValidDay = false;
                    }
                }
                // If its a invalid day
                if (!checkValidDay)
                {
                    throw new Exception("Doctor not available on this day. Check Available days");
                }

                // Get the person id of the doctor

                string sql = @"select employee.personid from employee 
                        where employee.empid = '" + doctorRepo.EmployeeIdOfDoctor + "' ";

                DataTable  data = DataAccess.GetDataTable(sql);
                int        id   = Convert.ToInt32(data.Rows[0]["personid"].ToString());
                PersonRepo p    = new PersonRepo();
                DataTable  ds   = p.GetIndividualPerson(id);
                string     a    = ds.Rows[0]["personid"].ToString();

                // should not be able to confirm appointment if doctor and patient are same person
                if (a.Equals(this.txtPersonID.Text))
                {
                    //MessageBox.Show("Doctor and Patient cannot be the same person");
                    throw (new Exception("Doctor and patient cannot be the same person"));
                }

                AppointmentRepo ap         = new AppointmentRepo();
                string          apTime     = this.cmbAppointmentTime.Text.ToString();
                string          apDate     = this.dtpAppointmentDate.Value.ToString("MM/dd/yyyy");
                int             apDoctorid = Convert.ToInt32(this.txtDoctorID.Text);

                if (ap.RowExits(apTime, apDate, apDoctorid))
                {
                    //this.txtPersonID.Text = this.PatientID.ToString();
                    throw new Exception("Clash Appointment");
                }

                var result = MessageBox.Show("Confirm appointment?", "Confirm", MessageBoxButtons.YesNoCancel);
                if (result == DialogResult.Yes)
                {
                    if (this.txtPersonID.Text == string.Empty)
                    {
                        // Person p = new Person();
                        p.Name       = this.txtName.Text;
                        p.Age        = Int32.Parse(this.txtAge.Text);
                        p.Gender     = this.cmbGender.Text;
                        p.BloodGroup = this.cmbBloodGroup.Text;
                        p.Phone      = this.txtPhone.Text;

                        // Create a new person
                        int personCreated = p.CreatePerson(p.Name, p.Age, p.Gender, p.BloodGroup, p.Phone);
                        // Refresh the person table
                        this.PopulatePersonTable();
                        // If person created successfully get his/her id to insert into appointment table
                        if (personCreated == 1)
                        {
                            DataTable lastPersonInsertedDT = p.GetLastPerson();
                            this.PatientID = Convert.ToInt32(lastPersonInsertedDT.Rows[0]["personid"].ToString());
                            int appointmentCreated = ap.CreateAppointment(this.cmbAppointmentTime.Text.ToString(), this.dtpAppointmentDate.Value.ToString("MM/dd/yyyy"), this.PatientID, Convert.ToInt32(this.txtDoctorID.Text));
                            if (appointmentCreated == 1)
                            {
                                MessageBox.Show("Appointment Confirmed");
                                this.CLearAll();
                            }
                        }
                    }
                    else
                    {
                        // Person already exists in database, so no need to create newly
                        this.PatientID = Convert.ToInt32(txtPersonID.Text);
                        int appointmentCreated = ap.CreateAppointment(apTime, apDate, this.PatientID, apDoctorid);
                        if (appointmentCreated == 1)
                        {
                            MessageBox.Show("Appointment Confirmed");
                            this.CLearAll();
                        }
                    }
                }
            }
            catch (Exception msg)
            {
                MessageBox.Show(msg.Message, "ERROR");
            }
        }