Exemple #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            FormEmployee check = new FormEmployee();

            check.Show();
            Hide();
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                using (var context = new Trainee1334Entities())
                {
                    string   check_Date1 = dateTimePicker1.Text;
                    DateTime oDate       = Convert.ToDateTime(check_Date1);
                    int      DateExist1  = context.Holidays.Where(c => c.HolidayDate == oDate).ToList().Count();
                    if (DateExist1 > 0)
                    {
                        string message = "HoliDay! Cannot Book Appointment";
                        MessageBox.Show(message);
                    }
                    else
                    {
                        var empname        = comboBox1.Text;
                        var Employeecheck1 = context.Employees.Where(c => c.EmpName == empname).FirstOrDefault();
                        var empid          = Employeecheck1.EmpID;

                        var hrname   = comboBox2.Text;
                        var hrcheck1 = context.Employees.Where(c => c.EmpName == hrname).FirstOrDefault();
                        var hrid     = hrcheck1.EmpID;

                        var slotdatecheck1 = comboBox3.Text;
                        var Exist1         = context.Appointments.Where(c => c.AppointmentDate == check_Date1 && c.HRID == hrid && c.Slot == slotdatecheck1).ToList();

                        if (Exist1.Any())
                        {
                            string message = "Appointment Already Exists ";
                            MessageBox.Show(message);
                        }
                        else
                        {
                            var Exist2 = context.Appointments.Where(c => c.AppointmentDate == check_Date1 && c.EmpID == empid && c.Slot == slotdatecheck1).ToList();
                            if (Exist2.Any())
                            {
                                string message = "Appointment Already Exists ";
                                MessageBox.Show(message);
                            }
                            else
                            {
                                var Exist3 = context.Appointments.Where(c => c.AppointmentDate == check_Date1 && c.EmpID == hrid && c.Slot == slotdatecheck1).ToList();
                                if (Exist3.Any())
                                {
                                    string message = "Appointment Already Exists ";
                                    MessageBox.Show(message);
                                }
                                else
                                {
                                    DayOfWeek selectedDay = DateTime.Parse(this.dateTimePicker1.Text).Date.DayOfWeek;
                                    if (dateTimePicker1.Value < DateTime.Today)
                                    {
                                        string message = "Past Date!";
                                        MessageBox.Show(message);
                                        FormEmployee check = new FormEmployee();
                                        check.Show();
                                        Hide();
                                    }
                                    else if (selectedDay == DayOfWeek.Saturday || selectedDay == DayOfWeek.Sunday || selectedDay == DayOfWeek.Wednesday)
                                    {
                                        MessageBox.Show("Bookings cannot be done on Wednesday and Weekends !");
                                        FormEmployee back = new FormEmployee();
                                        back.Show();
                                        Hide();
                                    }
                                    else
                                    {
                                        Appointment App = new Appointment();
                                        App.AppointmentDate = check_Date1;
                                        App.EmpID           = empid;
                                        App.HRID            = hrid;
                                        App.Slot            = slotdatecheck1;
                                        try
                                        {
                                            context.Appointments.Add(App);
                                            context.SaveChanges();
                                            string message = "Appointment Created!";
                                            MessageBox.Show(message);
                                        }

                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.Message);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch
            {
                string message = "Enter all Columns!";
                MessageBox.Show(message);
            }
        }