Beispiel #1
0
 public DateEventWindow(CustomDateEvent2 cde, bool begin_edit_at_first_show, EventCalendar ev)
     : this()
 {
     this.cde = cde;
     this.begin_edit_at_first_show = begin_edit_at_first_show;
     this.current_event = ev;
 }
        private void DoCopy(DateTime date, EventCalendar event_calendar)
        {
            bool   post_success = false;
            string err_msg      = "";
            int    inserted_id  = -1;

            string json_data = "{\"users_name\":\"" + event_calendar.users_name + "\",";

            json_data += "\"date\":\"" + date.ToMysqlDate() + "\",";
            json_data += "\"from_time\":\"" + event_calendar.from_time + "\",";
            json_data += "\"to_time\":\"" + event_calendar.to_time + "\",";
            json_data += "\"event_type\":\"" + event_calendar.event_type + "\",";
            json_data += "\"event_code\":\"" + event_calendar.event_code + "\",";
            json_data += "\"customer\":\"" + event_calendar.customer + "\",";
            json_data += "\"status\":\"" + event_calendar.status.ToString() + "\",";
            json_data += "\"med_cert\":\"" + event_calendar.med_cert + "\",";
            json_data += "\"fine\":" + event_calendar.fine.ToString() + ",";
            json_data += "\"rec_by\":\"" + this.main_form.G.loged_in_user_name + "\"}";

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate
            {
                CRUDResult   post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "eventcalendar/create", json_data);
                ServerResult sr   = JsonConvert.DeserializeObject <ServerResult>(post.data);

                if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                {
                    post_success = true;
                    inserted_id  = Convert.ToInt32(sr.message);
                }
                else
                {
                    post_success = false;
                    err_msg      = sr.message;
                }
            };
            worker.RunWorkerCompleted += delegate
            {
                if (post_success)
                {
                    foreach (Control ct in this.ParentForm.Controls["tableLayoutPanel1"].Controls)
                    {
                        if (ct.GetType() == typeof(CustomDateEvent2))
                        {
                            CustomDateEvent2 date_event = ct as CustomDateEvent2;
                            if (date_event.date.Value.ToString("dd/MM/yyyy") == date.ToString("dd/MM/yyyy"))
                            {
                                date_event.RefreshData();
                                date_event.RefreshView();

                                DataGridViewRow target_row = ((CustomDateEvent2)ct).dgv.Rows.Cast <DataGridViewRow>().Where(r => r.Cells[0].Value != null && ((EventCalendar)r.Cells[0].Value).id == inserted_id).FirstOrDefault();
                                if (target_row != null)
                                {
                                    date_event.dgv.Focus();
                                    date_event.dgv.CurrentCell = target_row.Cells[1];
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (MessageAlert.Show(err_msg, "Error", MessageAlertButtons.RETRY_CANCEL, MessageAlertIcons.ERROR) == DialogResult.Retry)
                    {
                        this.DoCopy(date, event_calendar);
                    }
                }
            };
            worker.RunWorkerAsync();
        }
Beispiel #3
0
 public TrainingExpertWindow(CustomDateEvent2 date_event)
 {
     InitializeComponent();
     this.date_event2 = date_event;
     this.current_event_date = date_event.date.Value;
 }
Beispiel #4
0
 public DateEventWindow(CustomDateEvent2 cde, bool begin_add_at_first_show)
     : this()
 {
     this.cde = cde;
     this.begin_add_at_first_show = begin_add_at_first_show;
 }
Beispiel #5
0
 //public DateEventWindow(CustomDateEvent cde)
 //    : this()
 //{
 //    this.cde = cde;
 //}
 //public DateEventWindow(CustomDateEvent cde, bool begin_add_at_first_show)
 //    : this()
 //{
 //    this.cde = cde;
 //    this.begin_add_at_first_show = begin_add_at_first_show;
 //}
 //public DateEventWindow(CustomDateEvent cde, bool begin_edit_at_first_show, EventCalendar ev)
 //    : this()
 //{
 //    this.cde = cde;
 //    this.begin_edit_at_first_show = begin_edit_at_first_show;
 //    this.current_event = ev;
 //}
 public DateEventWindow(CustomDateEvent2 cde)
     : this()
 {
     this.cde = cde;
 }
Beispiel #6
0
        private void btnGo_Click(object sender, EventArgs e)
        {
            this.tableLayoutPanel1.Visible = false;

            DateTime first_date = DateTime.Parse(this.year.ToString() + "-" + this.month.ToString() + "-1", CultureInfo.CurrentCulture);
            int days_in_month = DateTime.DaysInMonth(this.year, this.month);
            DateTime last_date = first_date.AddDays(days_in_month - 1);
            int first_day_of_week = first_date.GetDayIntOfWeek();

            string from_date = DateTime.Parse(this.year.ToString() + "/" + this.month.ToString() + "/1", CultureInfo.CurrentCulture, DateTimeStyles.None).ToMysqlDate();
            string to_date = DateTime.Parse(this.year.ToString() + "/" + this.month.ToString() + "/" + days_in_month.ToString(), CultureInfo.CurrentCulture, DateTimeStyles.None).ToMysqlDate();

            List<EventCalendar> event_cal;
            List<TrainingCalendar> training_cal;
            List<NoteCalendar> note_cal;

            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)
            {
                event_cal = sr.event_calendar;
                training_cal = sr.training_calendar;
                note_cal = sr.note_calendar;
            }
            else
            {
                event_cal = new List<EventCalendar>();
                training_cal = new List<TrainingCalendar>();
                note_cal = new List<NoteCalendar>();
            }

            List<Istab> absent_cause = IstabWindow.GetIstab(Istab.getTabtypString(Istab.TABTYP.ABSENT_CAUSE));
            List<Users> users_list = UsersList.GetUsers();

            int increase_date = 0 + ((first_day_of_week - 1) * -1);
            for (int i = 1; i < this.tableLayoutPanel1.RowCount; i++)
            {
                for (int j = 0; j < this.tableLayoutPanel1.ColumnCount; j++)
                {
                    // remove existing control
                    if (this.tableLayoutPanel1.GetControlFromPosition(j, i) != null)
                        this.tableLayoutPanel1.Controls.Remove(this.tableLayoutPanel1.GetControlFromPosition(j, i));

                    // create new control
                    NoteCalendar note = note_cal.Where(n => n.date == first_date.AddDays(increase_date).ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"))).FirstOrDefault();
                    int max_leave = note != null ? note.max_leave : -1;
                    List<AbsentVM> absent_list = event_cal.Where(ev => ev.date == first_date.AddDays(increase_date).ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"))).ToAbsentViewModel(absent_cause, users_list, max_leave);
                    var trainer = training_cal.Where(t => t.date == first_date.AddDays(increase_date).ToString("yyyy-MM-dd", CultureInfo.GetCultureInfo("en-US"))).ToList();
                    //var note = note_cal;

                    CustomDateEvent2 de = new CustomDateEvent2(this.main_form, this, first_date.AddDays(increase_date), this.month, absent_list, absent_cause, trainer, note, users_list, max_leave);
                    this.tableLayoutPanel1.Controls.Add(de, j, i);
                    increase_date++;
                }
            }

            this.tableLayoutPanel1.Visible = true;
        }