예제 #1
0
        private string GetTrainerName()
        {
            string trainer = "";

            if (this.training_list != null)
            {
                trainer += (this.training_list.Count > 0 ? "อบรม(" : "");

                int trainer_count = 0;
                foreach (TrainingCalendar t in this.training_list)
                {
                    CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "users/get_realname&username="******"," + sr.users[0].name);
                    }
                    else
                    {
                        trainer += "";
                    }
                }
                trainer += (training_list.Count > 0 ? ")" : "");
            }

            return(trainer);
        }
예제 #2
0
        public void RefreshData()
        {
            CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "eventcalendar/get_event&from_date=" + this.date.Value.ToMysqlDate() + "&to_date=" + this.date.Value.ToMysqlDate());
            ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);

            if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
            {
                this.absent_list  = sr.event_calendar.ToAbsentViewModel(this.absent_cause, this.users_list, this.max_leave);
                this.trainer_list = sr.training_calendar;
                this.note         = sr.note_calendar.Where(t => t.date == this.date.Value.ToMysqlDate()).FirstOrDefault();
            }
        }
예제 #3
0
        public void RefreshData()
        {
            CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "eventcalendar/get_event&from_date=" + this.date.ToMysqlDate() + "&to_date=" + this.date.ToMysqlDate());
            ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);

            if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
            {
                this.event_list    = sr.event_calendar;
                this.training_list = sr.training_calendar;
                this.note_calendar = sr.note_calendar.Find(t => t.date == this.date.ToMysqlDate());
            }
        }
예제 #4
0
        private List <Users> GetUserInGroup(string usergroup)
        {
            CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "users/get_user_in_group&usergroup=" + usergroup);
            ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);

            if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
            {
                return(sr.users);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public string GetEventAbbreviate(string event_type, string event_code)
        {
            CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "istab/get_by_typcod&typcod=" + event_code + "&tabtyp=" + event_type);
            ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);

            if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
            {
                return(sr.istab[0].abbreviate_th);
            }
            else
            {
                return("");
            }
        }
예제 #6
0
        private List <Dealer> getDealerDataFromServer()
        {
            CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "dealer/get_list");
            ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);

            if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
            {
                if (sr.dealer.Count > 0)
                {
                    return(sr.dealer);
                }
                else
                {
                    return(new List <Dealer>());
                }
            }
            else
            {
                return(new List <Dealer>());
            }
        }
예제 #7
0
        private List <Istab> getIstabDataFromServer(Istab.TABTYP tabtyp)
        {
            CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "istab/get_all&tabtyp=" + tabtyp.ToTabtypString() + "&sort=typcod");
            ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);

            if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
            {
                if (sr.istab.Count > 0)
                {
                    return(sr.istab);
                }
                else
                {
                    return(new List <Istab>());
                }
            }
            else
            {
                return(new List <Istab>());
            }
        }
예제 #8
0
        private void ShowContextMenu(object sender, int x_pos = -1, int y_pos = -1)
        {
            if (((DataGridView)sender).Rows.Count == 0)
            {
                return;
            }

            int row_index = ((DataGridView)sender).CurrentCell.RowIndex;

            EventCalendar event_calendar = null;
            var           ev             = ((DataGridView)sender).Rows[row_index].Cells[0].Value;

            if (ev != null)
            {
                event_calendar = ev as EventCalendar;
            }

            ContextMenu cm = new ContextMenu();

            MenuItem mnu_add = new MenuItem();

            mnu_add.Text   = "เพิ่ม";
            mnu_add.Click += delegate
            {
                DateEventWindow date_event = new DateEventWindow(this, true);
                date_event.ShowDialog();
            };
            cm.MenuItems.Add(mnu_add);

            MenuItem mnu_edit = new MenuItem();

            mnu_edit.Text    = "แก้ไข";
            mnu_edit.Enabled = event_calendar != null ? true : false;
            mnu_edit.Click  += delegate
            {
                DateEventWindow date_event = new DateEventWindow(this, true, event_calendar);
                date_event.ShowDialog();
            };
            cm.MenuItems.Add(mnu_edit);

            MenuItem mnu_copy = new MenuItem();

            mnu_copy.Text    = "คัดลอกรายการนี้ไปยังวันที่ ...";
            mnu_copy.Enabled = event_calendar != null ? true : false;
            mnu_copy.Click  += delegate
            {
                DateSelectorDialog ds = new DateSelectorDialog(this.date.Value);
                if (ds.ShowDialog() == DialogResult.OK)
                {
                    this.DoCopy(ds.selected_date, (EventCalendar)this.dgv.Rows[row_index].Cells[0].Value);
                }
            };
            cm.MenuItems.Add(mnu_copy);

            MenuItem mnu_delete = new MenuItem();

            mnu_delete.Text    = "ลบ";
            mnu_delete.Enabled = event_calendar != null ? true : false;
            mnu_delete.Click  += delegate
            {
                if (MessageAlert.Show(StringResource.CONFIRM_DELETE, "", MessageAlertButtons.OK_CANCEL, MessageAlertIcons.QUESTION) == DialogResult.OK)
                {
                    bool             delete_success = false;
                    string           err_msg        = "";
                    BackgroundWorker worker         = new BackgroundWorker();
                    worker.DoWork += delegate
                    {
                        CRUDResult   delete = ApiActions.DELETE(PreferenceForm.API_MAIN_URL() + "eventcalendar/delete&id=" + ((EventCalendar)this.dgv.Rows[row_index].Cells[0].Value).id.ToString());
                        ServerResult sr     = JsonConvert.DeserializeObject <ServerResult>(delete.data);

                        if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                        {
                            delete_success = true;
                        }
                        else
                        {
                            delete_success = false;
                            err_msg        = sr.message;
                        }
                    };
                    worker.RunWorkerCompleted += delegate
                    {
                        if (delete_success)
                        {
                            this.RefreshData();
                            this.RefreshView();
                        }
                        else
                        {
                            this.RefreshData();
                            this.RefreshView();
                            MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                        }
                    };
                    worker.RunWorkerAsync();
                }
            };
            cm.MenuItems.Add(mnu_delete);

            if (x_pos < 0 || y_pos < 0)
            {
                x_pos = ((DataGridView)sender).GetCellDisplayRectangle(2, row_index, true).X;
                y_pos = ((DataGridView)sender).GetCellDisplayRectangle(2, row_index, true).Y;
            }

            cm.Show((DataGridView)sender, new Point(x_pos, y_pos));
        }
예제 #9
0
        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();
        }
예제 #10
0
        public void SetVisualControl(NoteCalendar note_calendar = null, List <TrainingCalendar> training_list = null)
        {
            this.note_calendar = note_calendar;
            this.training_list = training_list;

            if (this.note_calendar != null)
            {
                if (this.note_calendar.group_maid.Trim().Length > 0)
                {
                    this.picMaid.Visible = true;
                    this.lblMaid.Visible = true;
                    this.lblMaid.Text    = note_calendar.group_maid;
                    //this.lblMaid.Click += delegate
                    //{

                    //};
                }
                else
                {
                    this.picMaid.Visible = false;
                    this.lblMaid.Text    = "";
                }

                if (this.note_calendar.group_weekend.Trim().Length > 0)
                {
                    this.picWeekend.Visible = true;
                    this.lblWeekend.Visible = true;
                    this.lblWeekend.Text    = note_calendar.group_weekend;
                    //this.lblWeekend.Click += delegate
                    //{

                    //};
                }
                else
                {
                    this.picWeekend.Visible = false;
                    this.lblWeekend.Text    = "";
                }
            }
            else
            {
                this.picMaid.Visible    = false;
                this.picWeekend.Visible = false;
                this.lblMaid.Visible    = false;
                this.lblWeekend.Visible = false;
            }

            if (this.training_list != null)
            {
                this.lblTrainer.Visible = true;
                string trainer = (this.training_list.Count > 0 ? "อบรม(" : "");

                int trainer_count = 0;
                foreach (TrainingCalendar t in this.training_list)
                {
                    CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "users/get_realname&username="******"," + sr.users[0].name);
                    }
                    else
                    {
                        trainer += "";
                    }
                }
                trainer += (this.training_list.Count > 0 ? ")" : "");

                this.lblTrainer.Text = trainer;
            }
            else
            {
                this.lblTrainer.Visible = false;
            }
        }
예제 #11
0
        private void DoCopy(DateTime date, EventCalendar event_calendar)
        {
            bool   post_success = false;
            string err_msg      = "";
            int    inserted_id  = -1;

            this.Ready = false;

            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.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 (CustomDateEvent ct in this.Parent.Controls)
                    {
                        if (ct.Date.ToDMYDateValue() == date.ToDMYDateValue())
                        {
                            ct.RefreshData();
                            ct.RefreshView();
                        }
                    }
                    if (this.Date.ToDMYDateValue() == date.ToDMYDateValue())
                    {
                        this.RefreshData();
                        this.RefreshView();
                        this.dgv.Rows[this.event_list.FindIndex(t => t.id == inserted_id)].Cells[1].Selected = true;
                    }
                    this.Ready = true;
                }
                else
                {
                    if (MessageAlert.Show(err_msg, "Error", MessageAlertButtons.RETRY_CANCEL, MessageAlertIcons.ERROR) == DialogResult.Retry)
                    {
                        this.DoCopy(date, event_calendar);
                    }
                    this.Ready = true;
                }
            };
            worker.RunWorkerAsync();
        }
예제 #12
0
        private void BindingControlEvent()
        {
            #region Nulling current dgv current cell when it's leave
            this.dgv.Leave += delegate
            {
                this.dgv.CurrentCell = null;
            };
            #endregion Nulling current dgv current cell when it's leave

            #region Show dgv row context menu
            this.dgv.MouseClick += delegate(object sender, MouseEventArgs e)
            {
                if (!this.read_only)
                {
                    if (e.Button == MouseButtons.Right)
                    {
                        this.dgv.Focus();
                        int row_index = this.dgv.HitTest(e.X, e.Y).RowIndex;
                        if (row_index > -1 && this.G.loged_in_user_level >= GlobalVar.USER_LEVEL_SUPERVISOR && this.dgv.Rows[row_index].Tag is EventCalendar)
                        {
                            this.dgv.Rows[row_index].Cells[1].Selected = true;
                            ContextMenu m      = new ContextMenu();
                            MenuItem    m_edit = new MenuItem("แก้ไข");
                            m_edit.Click += delegate
                            {
                                //DateEventWindow wind = new DateEventWindow(this, true, (EventCalendar)this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag);
                                //wind.ShowDialog();
                            };
                            m.MenuItems.Add(m_edit);

                            MenuItem m_copy = new MenuItem("คัดลอกไปยังวันที่ ...");
                            m_copy.Click += delegate
                            {
                                DateSelectorDialog ds = new DateSelectorDialog(this.Date);
                                if (ds.ShowDialog() == DialogResult.OK)
                                {
                                    this.DoCopy(ds.selected_date, (EventCalendar)this.dgv.Rows[row_index].Tag);
                                }
                            };
                            m.MenuItems.Add(m_copy);

                            MenuItem m_delete = new MenuItem("ลบ");
                            m_delete.Click += delegate
                            {
                                if (MessageAlert.Show(StringResource.CONFIRM_DELETE, "", MessageAlertButtons.OK_CANCEL, MessageAlertIcons.QUESTION) == DialogResult.OK)
                                {
                                    this.Ready = false;

                                    bool             delete_success = false;
                                    string           err_msg        = "";
                                    BackgroundWorker worker         = new BackgroundWorker();
                                    worker.DoWork += delegate
                                    {
                                        CRUDResult   delete = ApiActions.DELETE(PreferenceForm.API_MAIN_URL() + "eventcalendar/delete&id=" + ((EventCalendar)this.dgv.Rows[row_index].Tag).id.ToString());
                                        ServerResult sr     = JsonConvert.DeserializeObject <ServerResult>(delete.data);

                                        if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                                        {
                                            delete_success = true;
                                        }
                                        else
                                        {
                                            delete_success = false;
                                            err_msg        = sr.message;
                                        }
                                    };
                                    worker.RunWorkerCompleted += delegate
                                    {
                                        if (delete_success)
                                        {
                                            this.RefreshData();
                                            this.RefreshView();
                                            this.Ready = true;
                                        }
                                        else
                                        {
                                            this.RefreshData();
                                            this.RefreshView();
                                            MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                                        }
                                    };
                                    worker.RunWorkerAsync();
                                }
                            };
                            m.MenuItems.Add(m_delete);

                            m.Show(this.dgv, new Point(e.X, e.Y));
                        }
                    }
                }
            };
            #endregion Show dgv row context menu
        }