Ejemplo n.º 1
0
        private void btn_Save_Click(object sender, EventArgs e)
        {
            DateTime startDate = calendarView.DateSelectionStart.GetValueOrDefault();
            DateTime endDate = calendarView.DateSelectionEnd.GetValueOrDefault();

            if (txt_Name.Text != "")
            {
                int insert = 0;
                int update = 0;
                for (DateTime date = startDate; date < endDate; date = date.AddDays(1.0))
                {
                    Appointment appointment = (from ap in calendarView.CalendarModel.Appointments where ap.StartTime == date select ap).SingleOrDefault();

                    //create new appointment
                    if (appointment == null)
                    {
                        AddAppointment(txt_Name.Text, date, date, "", "");

                        CpHoliday holiday = new CpHoliday();
                        holiday.Date = date;
                        holiday.Reason = txt_Name.Text;

                        db.CpHolidays.Add(holiday);

                        insert++;

                    }
                    else if (txt_Name.Text != appointment.Subject)
                    {
                        appointment.Subject = txt_Name.Text;
                        CpHoliday holiday = (from h in db.CpHolidays where h.Date == date select h).SingleOrDefault();
                        holiday.Reason = txt_Name.Text;
                        db.SaveChanges();
                        update++;

                    }
                }
                if (insert > 0)
                {
                    db.SaveChanges();
                    MessageBox.Show("Create holiday successfull");
                    txt_Name.Text = "";
                }
                else if (update > 0)
                {
                    MessageBox.Show("Update holiday successfull");
                }
                //string wACode = "haha";
                //var a = from p in db.CpTimeZones where wACode == p.Code.Trim() select p;
            }
        }
Ejemplo n.º 2
0
        private void advTree1_NodeClick(object sender, DevComponents.AdvTree.TreeNodeMouseEventArgs e)
        {
            int year = int.Parse(cb_year.SelectedValue.ToString());
            if (year == 0)
            {
                year = DateTime.Now.Year;
            }

            try
            {

                if (e.Node.Name == "node_weeken")
                {

                    List<DateTime> weekensInYear = getAllWeekDates(year);

                    int count = 0;
                    foreach (DateTime dt in weekensInYear)
                    {

                        DateTime sunday = dt;
                        DateTime saturday = dt.AddDays(-1);
                        var check_sunday = (from h in db.CpHolidays where h.Date == sunday select h).SingleOrDefault();
                        var check_saturday = (from h in db.CpHolidays where h.Date == saturday select h).SingleOrDefault();

                        if (saturday.Year == year && (check_saturday == null))
                        {
                            AddAppointment("Saturday", saturday, saturday, "#FF0000", "");
                            CpHoliday holiday = new CpHoliday();
                            holiday.Date = saturday;
                            holiday.Reason = "Saturday";
                            holiday.SchoolId = D_SCHOOL_ID;
                            db.CpHolidays.Add(holiday);
                            //db.SaveChanges();
                            count++;
                        }

                        if (check_sunday == null)
                        {
                            AddAppointment("Sunday", sunday, sunday, "#FF0000", "");
                            CpHoliday holiday = new CpHoliday();
                            holiday.Date = sunday;
                            holiday.Reason = "Sunday";
                            holiday.SchoolId = D_SCHOOL_ID;
                            db.CpHolidays.Add(holiday);

                            count++;
                        }

                    }
                    db.SaveChanges();

                } if (e.Node.Name == "holiday")
                {

                    var listJanpanHolidays = (from jh in db.JapanHolidays where jh.Year == year select jh).ToList();

                    int c = 1;
                    foreach (var holiday in listJanpanHolidays)
                    {
                        var check_holiday = (from h in db.CpHolidays where h.Date == holiday.Date && h.SchoolId == D_SCHOOL_ID select h).SingleOrDefault();

                        if (check_holiday == null)
                        {
                            AddAppointment(holiday.Name.ToString(), (DateTime)holiday.Date, (DateTime)holiday.Date, "", "");
                            CpHoliday new_holiday = new CpHoliday();
                            new_holiday.Date = holiday.Date;
                            new_holiday.Reason = holiday.Name;
                            new_holiday.SchoolId = D_SCHOOL_ID;
                            db.CpHolidays.Add(new_holiday);

                            c++;
                        }

                    }

                    db.SaveChanges();

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }