예제 #1
0
 private void btnDetail_Click(object sender, EventArgs e)
 {
     DateEventWindow wind = new DateEventWindow(this);
     wind.ShowDialog();
 }
예제 #2
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));
        }
예제 #3
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     DateEventWindow wind = new DateEventWindow(this, true);
     wind.ShowDialog();
 }