Ejemplo n.º 1
0
 private void UpdateDateEventUI(CustomDateEvent de, List <Users> list_users, List <EventCalendar> list_event_calendar, List <TrainingCalendar> list_training_calendar, NoteCalendar note_calendar, int current_month)
 //private void UpdateDateEventUI()
 {
     de.list_users = list_users;
     de.SetEventList(list_event_calendar);
     de.SetTrainingList(list_training_calendar);
     de.note_calendar = note_calendar;
     de.TargetMonth   = current_month;
     de.RefreshView();
     //Console.WriteLine(list_users[0]);
 }
Ejemplo n.º 2
0
        private void LoadCalendar(int month, int year)
        {
            DateTime out_firstday;

            if (DateTime.TryParse(year.ToString() + "/" + month.ToString() + "/1", cinfo_us, DateTimeStyles.None, out out_firstday))
            {
                this.btnPrevMonth.Enabled = false;
                this.btnNextMonth.Enabled = false;
                this.cbMonth.Enabled      = false;
                this.cbYear.Enabled       = false;

                #region Set calendar ready to false
                for (int i = 0; i <= 5; i++)
                {
                    for (int j = 0; j <= 6; j++)
                    {
                        CustomDateEvent de = (CustomDateEvent)this.tableLayout1.GetControlFromPosition(j, i);
                        de.Ready = false;
                    }
                }
                #endregion Set calendar ready to false

                #region Create calendar
                this.first_day  = out_firstday;
                this.curr_year  = out_firstday.Year;
                this.curr_month = out_firstday.Month;

                int days_in_month = DateTime.DaysInMonth(year, month);
                for (int i = out_firstday.GetDayIntOfWeek() - 1; i > 0; i--)
                {
                    CustomDateEvent de = (CustomDateEvent)this.tableLayout1.GetControlFromPosition(i - 1, 0);
                    de.Date                = out_firstday.AddDays(i - out_firstday.GetDayIntOfWeek());
                    de.TargetMonth         = out_firstday.Month;
                    de.G                   = this.main_form.G;
                    de.calendar_window     = this;
                    de.btnAdd.Enabled      = (this.main_form.G.loged_in_user_level < GlobalVar.USER_LEVEL_SUPERVISOR ? false : Enabled);
                    de.btnDetail.Enabled   = (this.main_form.G.loged_in_user_level < GlobalVar.USER_LEVEL_SUPERVISOR ? false : Enabled);
                    de.btnTraining.Enabled = (this.main_form.G.loged_in_user_training_expert == true || this.main_form.G.loged_in_user_level >= GlobalVar.USER_LEVEL_SUPERVISOR ? true : false);
                    //de.RefreshView();
                }

                int row_index = 0;
                for (int i = 0; i < days_in_month; i++)
                {
                    int             col_index = out_firstday.AddDays(i).GetDayIntOfWeek();
                    CustomDateEvent de        = (CustomDateEvent)this.tableLayout1.GetControlFromPosition(col_index - 1, row_index);
                    de.Date                = out_firstday.AddDays(i);
                    de.TargetMonth         = out_firstday.Month;
                    de.G                   = this.main_form.G;
                    de.calendar_window     = this;
                    de.btnAdd.Enabled      = (this.main_form.G.loged_in_user_level < GlobalVar.USER_LEVEL_SUPERVISOR ? false : Enabled);
                    de.btnDetail.Enabled   = (this.main_form.G.loged_in_user_level < GlobalVar.USER_LEVEL_SUPERVISOR ? false : Enabled);
                    de.btnTraining.Enabled = (this.main_form.G.loged_in_user_training_expert == true || this.main_form.G.loged_in_user_level >= GlobalVar.USER_LEVEL_SUPERVISOR ? true : false);
                    // increase row_index
                    row_index += (out_firstday.AddDays(i).GetDayIntOfWeek() == 7 ? 1 : 0);
                }

                int add_date    = 0;
                int day_of_week = out_firstday.AddDays(days_in_month).GetDayIntOfWeek(); // first day of next month
                for (int i = row_index; i < 6; i++)
                {
                    for (int j = day_of_week; j <= 7; j++)
                    {
                        int col_index = j - 1;
                        add_date++;
                        CustomDateEvent de = (CustomDateEvent)this.tableLayout1.GetControlFromPosition(col_index, row_index);
                        de.Date                = out_firstday.AddDays(days_in_month + (add_date - 1));
                        de.TargetMonth         = out_firstday.Month;
                        de.G                   = this.main_form.G;
                        de.calendar_window     = this;
                        de.btnAdd.Enabled      = (this.main_form.G.loged_in_user_level < GlobalVar.USER_LEVEL_SUPERVISOR ? false : Enabled);
                        de.btnDetail.Enabled   = (this.main_form.G.loged_in_user_level < GlobalVar.USER_LEVEL_SUPERVISOR ? false : Enabled);
                        de.btnTraining.Enabled = (this.main_form.G.loged_in_user_training_expert == true || this.main_form.G.loged_in_user_level >= GlobalVar.USER_LEVEL_SUPERVISOR ? true : false);
                    }
                    row_index++;
                    day_of_week = 1;
                }
                #endregion Create calendar

                #region Set event_list for each date
                string from_date = DateTime.Parse(year.ToString() + "/" + month.ToString() + "/1", cinfo_us, DateTimeStyles.None).ToMysqlDate();
                string to_date   = DateTime.Parse(year.ToString() + "/" + month.ToString() + "/" + days_in_month.ToString(), cinfo_us, DateTimeStyles.None).ToMysqlDate();

                bool   get_success = false;
                string err_msg     = "";

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += delegate
                {
                    CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "eventcalendar/get_event&from_date=" + from_date + "&to_date=" + to_date);
                    ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);
                    if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                    {
                        get_success         = true;
                        this.month_event    = sr.event_calendar;
                        this.month_training = sr.training_calendar;
                        this.month_note     = sr.note_calendar;
                    }
                    else
                    {
                        get_success = false;
                        err_msg     = sr.message;
                    }
                };
                worker.RunWorkerCompleted += delegate
                {
                    if (get_success)
                    {
                        for (int i = 0; i <= 5; i++)
                        {
                            for (int j = 0; j <= 6; j++)
                            {
                                CustomDateEvent  de        = (CustomDateEvent)this.tableLayout1.GetControlFromPosition(j, i);
                                BackgroundWorker subworker = new BackgroundWorker();
                                subworker.DoWork += delegate
                                {
                                    de.RefreshView(this.list_users, this.month_event.Where <EventCalendar>(t => t.date == de.Date.ToMysqlDate()).ToList <EventCalendar>(), this.month_training.Where <TrainingCalendar>(t => t.date == de.Date.ToMysqlDate()).ToList <TrainingCalendar>(), this.month_note.Find(t => t.date == de.Date.ToMysqlDate()), this.curr_month);
                                };
                                subworker.RunWorkerCompleted += delegate
                                {
                                };
                                subworker.RunWorkerAsync();

                                /******************/

                                //de.list_users = this.list_users;
                                //de.SetEventList(this.month_event.Where<EventCalendar>(t => t.date == de.Date.ToMysqlDate()).ToList<EventCalendar>());
                                //de.SetTrainingList(this.month_training.Where<TrainingCalendar>(t => t.date == de.Date.ToMysqlDate()).ToList<TrainingCalendar>());
                                //de.note_calendar = this.month_note.Find(t => t.date == de.Date.ToMysqlDate());
                                //de.TargetMonth = this.curr_month;
                                //de.RefreshView();
                            }
                        }
                        this.btnPrevMonth.Enabled = true;
                        this.btnNextMonth.Enabled = true;
                        this.cbMonth.Enabled      = true;
                        this.cbYear.Enabled       = true;
                    }
                    else
                    {
                        this.btnPrevMonth.Enabled = true;
                        this.btnNextMonth.Enabled = true;
                        this.cbMonth.Enabled      = true;
                        this.cbYear.Enabled       = true;
                        MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                    }
                };
                worker.RunWorkerAsync();

                #endregion Set event_list for each date
            }
        }