Beispiel #1
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
        }
Beispiel #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));
        }
Beispiel #3
0
        private void BindingControlEvent()
        {
            this.dgv.Paint += delegate
            {
                if (this.dgv.CurrentCell != null)
                {
                    Rectangle rect = this.dgv.GetRowDisplayRectangle(this.dgv.CurrentCell.RowIndex, false);
                    using (Pen p = new Pen(Color.Red))
                    {
                        this.dgv.CreateGraphics().DrawLine(p, rect.X, rect.Y, rect.X + rect.Width, rect.Y);
                        this.dgv.CreateGraphics().DrawLine(p, rect.X, rect.Y + rect.Height - 2, rect.X + rect.Width, rect.Y + rect.Height - 2);

                        if ((DGV_TAG)this.dgv.Tag == DGV_TAG.DELETE)
                        {
                            for (int i = rect.Left - 16; i < rect.Right; i += 8)
                            {
                                this.dgv.CreateGraphics().DrawLine(p, i, rect.Bottom - 2, i + 23, rect.Top);
                            }
                        }
                    }
                }
            };

            this.dgv.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs e)
            {
                if (this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag is EventCalendar)
                {
                    this.FormEditItem();
                }
                else
                {
                    this.FormAddItem();
                    this.dgv.Rows[this.cde.absent_list.ExtractToEventCalendar().Count].Cells[1].Selected = true;
                }
                this.ShowInlineForm();
            };

            this.dgv.MouseClick += delegate(object sender, MouseEventArgs e)
            {
                if (e.Button == MouseButtons.Right)
                {
                    if (this.form_mode == FORM_MODE.READ || this.form_mode == FORM_MODE.READ_ITEM)
                    {
                        if (this.form_mode == FORM_MODE.READ)
                        {
                            this.FormReadItem();
                        }

                        int row_index = this.dgv.HitTest(e.X, e.Y).RowIndex;
                        this.dgv.Rows[row_index].Cells[1].Selected = true;

                        ContextMenu m = new ContextMenu();
                        MenuItem m_add = new MenuItem("เพิ่ม <Alt+A>");
                        m_add.Click += delegate
                        {
                            this.dgv.Rows[this.cde.absent_list.ExtractToEventCalendar().Count].Cells[1].Selected = true;
                            this.FormAddItem();
                            this.ShowInlineForm();
                        };
                        m_add.Enabled = true;
                        m.MenuItems.Add(m_add);

                        MenuItem m_edit = new MenuItem("แก้ไข <Alt+E>");
                        m_edit.Click += delegate
                        {
                            this.FormEditItem();
                            this.ShowInlineForm();
                        };
                        m_edit.Enabled = (this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag is EventCalendar ? true : false);
                        m.MenuItems.Add(m_edit);

                        MenuItem m_copy = new MenuItem("คัดลอกไปยังวันที่ ... <Alt+C>");
                        m_copy.Click += delegate
                        {
                            DateSelectorDialog ds = new DateSelectorDialog(this.cde.date.Value);
                            if (ds.ShowDialog() == DialogResult.OK)
                            {
                                this.DoCopy(ds.selected_date, (EventCalendar)this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag);
                            }
                        };
                        m_copy.Enabled = (this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag is EventCalendar ? true : false);
                        m.MenuItems.Add(m_copy);

                        MenuItem m_delete = new MenuItem("ลบ <Alt+D>");
                        m_delete.Click += delegate
                        {
                            this.DeleteItem();
                        };
                        m_delete.Enabled = (this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag is EventCalendar ? true : false);
                        m.MenuItems.Add(m_delete);

                        m.Show(this.dgv, new Point(e.X, e.Y));
                    }
                }
            };

            List<Control> ct = new List<Control>();
            ct.Add(this.txtHoliday.label1);
            ct.Add(this.cbGroupMaid.label1);
            ct.Add(this.cbGroupWeekend.label1);
            ct.Add(this.leaveMax);
            foreach (Control c in ct)
            {
                c.DoubleClick += delegate
                {
                    this.toolStripEdit.PerformClick();
                };
            }

            this.rbHoliday.EnabledChanged += delegate
            {
                if (this.rbHoliday.Enabled && this.rbHoliday.Checked)
                {
                    this.txtHoliday.Read_Only = false;
                }
                else
                {
                    this.txtHoliday.Read_Only = true;
                }
            };

            this.rbWeekday.EnabledChanged += delegate
            {
                if (this.rbWeekday.Enabled && this.rbWeekday.Checked)
                {
                    this.cbGroupWeekend.Read_Only = false;
                    this.cbGroupMaid.Read_Only = false;
                    this.leaveMax.Enabled = true;
                }
                else
                {
                    this.cbGroupWeekend.Read_Only = true;
                    this.cbGroupMaid.Read_Only = true;
                    this.leaveMax.Enabled = false;
                }
            };

            this.rbHoliday.CheckedChanged += delegate
            {
                if (this.rbHoliday.Checked && this.rbHoliday.Enabled)
                {
                    this.txtHoliday.Read_Only = false;
                    this.leaveMax.Enabled = false;
                }
                else
                {
                    this.txtHoliday.Read_Only = true;
                }
            };

            this.rbWeekday.CheckedChanged += delegate
            {
                if (this.rbWeekday.Checked && this.rbWeekday.Enabled)
                {
                    this.cbGroupWeekend.Read_Only = false;
                    this.cbGroupMaid.Read_Only = false;
                    this.leaveMax.Enabled = true;
                }
                else
                {
                    this.cbGroupWeekend.Read_Only = true;
                    this.cbGroupMaid.Read_Only = true;
                    this.leaveMax.Enabled = false;
                }
            };

            this.txtHoliday.textBox1.TextChanged += delegate
            {
                if (this.txtHoliday.Texts.Length > 0)
                {
                    this.cbGroupMaid.comboBox1.SelectedIndex = 0;
                    this.cbGroupWeekend.comboBox1.SelectedIndex = 0;
                }
            };

            //this.txtRemark.textBox1.TextChanged += delegate
            //{
            //    if (this.txtRemark.Texts.Length > 0)
            //    {
            //        this.txtHoliday.Texts = "";
            //    }
            //};

            this.leaveMax.GotFocus += delegate
            {
                this.leaveMax.Select(0, this.leaveMax.Text.Length);
            };
        }
Beispiel #4
0
 private void toolStripButton1_Click(object sender, EventArgs e)
 {
     DateSelectorDialog ds = new DateSelectorDialog();
     if (ds.ShowDialog() == DialogResult.OK)
     {
         this.DoCopyTrainer(ds.selected_date);
     }
 }
Beispiel #5
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Enter)
            {
                if (this.form_mode == FORM_MODE.ADD_ITEM || this.form_mode == FORM_MODE.EDIT_ITEM)
                {
                    //if (this.dgv.Parent.Controls.Find("inline_customer", true).Length > 0)
                    //{
                        //CustomTextBox inline_customer = (CustomTextBox)this.dgv.Parent.Controls.Find("inline_customer", true)[0];
                        //if (inline_customer.textBox1.Focused)
                        //{
                        //    DateEventSubWindow subwind = (this.form_mode == FORM_MODE.ADD_ITEM ? new DateEventSubWindow() : new DateEventSubWindow((EventCalendar)this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag));
                        //    if (subwind.ShowDialog() == DialogResult.OK)
                        //    {
                        //        this.toolStripSave.PerformClick();
                        //    }
                        //    else
                        //    {
                        //        inline_customer.textBox1.Focus();
                        //    }
                        //    return true;
                        //}
                    //}
                    if (this.dgv.Parent.Controls.Find("inline_fine", true).Length > 0)
                    {
                        NumericUpDown inline_fine = (NumericUpDown)this.dgv.Parent.Controls.Find("inline_fine", true)[0];
                        if (inline_fine.Focused)
                        {
                            this.toolStripSave.PerformClick();
                            return true;
                        }
                    }
                }
                if (this.form_mode == FORM_MODE.EDIT)
                {
                    if (this.rbHoliday.Checked && this.txtHoliday.textBox1.Focused)
                    {
                        this.toolStripSave.PerformClick();
                        return true;
                    }
                    else if (this.rbWeekday.Checked && this.leaveMax.Focused)
                    {
                        this.toolStripSave.PerformClick();
                        return true;
                    }
                }
                if (this.form_mode == FORM_MODE.READ || this.form_mode == FORM_MODE.READ_ITEM)
                {
                    return true;
                }
                SendKeys.Send("{TAB}");
                return true;
            }
            if (keyData == Keys.Escape)
            {
                this.toolStripStop.PerformClick();
                return true;
            }
            if (keyData == Keys.F8)
            {
                this.toolStripItem.PerformClick();
                return true;
            }
            if (keyData == Keys.F9)
            {
                this.toolStripSave.PerformClick();
                return true;
            }
            if (keyData == (Keys.Alt | Keys.E))
            {
                if (this.form_mode == FORM_MODE.READ)
                {
                    this.toolStripEdit.PerformClick();
                    return true;
                }
                else if(this.form_mode == FORM_MODE.READ_ITEM)
                {
                    if (this.dgv.CurrentCell != null)
                    {
                        if (this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag is EventCalendar)
                        {
                            this.FormEditItem();
                            this.ShowInlineForm();
                            return true;
                        }
                    }
                }
            }
            if (keyData == (Keys.Alt | Keys.A))
            {
                if (this.form_mode == FORM_MODE.READ_ITEM)
                {
                    this.dgv.Rows[this.cde.absent_list.ExtractToEventCalendar().Count].Cells[1].Selected = true;
                    this.FormAddItem();
                    this.ShowInlineForm();
                    return true;
                }
            }
            if (keyData == (Keys.Alt | Keys.D))
            {
                if (this.form_mode == FORM_MODE.READ_ITEM)
                {
                    this.DeleteItem();
                }
            }

            if (keyData == (Keys.Alt | Keys.C))
            {
                if (this.form_mode == FORM_MODE.READ_ITEM)
                {
                    if (this.dgv.CurrentCell == null)
                        return true;

                    if (this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag is EventCalendar)
                    {
                        DateSelectorDialog ds = new DateSelectorDialog(this.cde.date.Value);
                        if (ds.ShowDialog() == DialogResult.OK)
                        {
                            this.DoCopy(ds.selected_date, (EventCalendar)this.dgv.Rows[this.dgv.CurrentCell.RowIndex].Tag);
                        }
                    }

                    return true;
                }
            }

            return base.ProcessCmdKey(ref msg, keyData);
        }