Exemple #1
0
        private void AddEventHandler()
        {
            #region Draw red line for current row & enable/disable toolstrip button
            this.dgvNote.Paint += delegate
            {
                if (this.dgvNote.Rows.Count > 0)
                {
                    this.toolStripPrint.Enabled = (this.form_mode == FORM_MODE.READ ? true : false);
                    this.toolStripExport.Enabled = (this.form_mode == FORM_MODE.READ ? true : false);
                    this.toolStripEdit.Enabled = (this.dgvNote.Parent.Controls.Find("txt_inline_remark", true).Length > 0 ? false : true);

                    Rectangle row_rect = this.dgvNote.GetRowDisplayRectangle(this.dgvNote.CurrentCell.RowIndex, false);
                    using (Pen p = new Pen(Color.Red))
                    {
                        this.dgvNote.CreateGraphics().DrawLine(p, row_rect.X, row_rect.Y, row_rect.X + row_rect.Width, row_rect.Y);
                        this.dgvNote.CreateGraphics().DrawLine(p, row_rect.X, row_rect.Y + row_rect.Height - 1, row_rect.X + row_rect.Width, row_rect.Y + row_rect.Height - 1);
                    }
                }
                else
                {
                    this.toolStripPrint.Enabled = false;
                    this.toolStripExport.Enabled = false;
                    this.toolStripEdit.Enabled = false;
                }
            };
            #endregion Draw red line for current row & enable/disable toolstrip button

            this.dgvNote.RowPostPaint += delegate(object sender, DataGridViewRowPostPaintEventArgs e)
            {
                this.SetRowBackground(((DataGridView)sender).Rows[e.RowIndex]);
            };

            this.dgvNote.CellPainting += delegate(object sender, DataGridViewCellPaintingEventArgs e)
            {
                if (e.RowIndex == -1)
                {
                    e.PaintBackground(e.CellBounds, true);
                    e.PaintContent(e.CellBounds);
                    if (e.ColumnIndex >= 11 && e.ColumnIndex <= 26)
                    {
                        RectangleF summary_bound = new RectangleF(e.CellBounds.X + 1, (e.CellBounds.Y + e.CellBounds.Height) - 18, e.CellBounds.Width - 2, 17);

                        using (SolidBrush brush_bg = new SolidBrush(Color.LightGray))
                        {
                            e.Graphics.FillRectangle(brush_bg, summary_bound);
                        }
                        using (Pen p = new Pen(Color.Gray))
                        {
                            e.Graphics.DrawLine(p, summary_bound.X, summary_bound.Y, summary_bound.X + summary_bound.Width, summary_bound.Y);
                        }

                        using (SolidBrush brush = new SolidBrush(Color.Blue))
                        {
                            using (Font font = new Font("tahoma", 7f))
                            {
                                using (StringFormat format = new StringFormat() { Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Center, FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.NoWrap })
                                {
                                    if (e.ColumnIndex == 11) // map drive
                                    {
                                        int sum = this.note_list.Where(r => r.map_drive.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 12) // install update
                                    {
                                        int sum = this.note_list.Where(r => r.install.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 13) // Error
                                    {
                                        int sum = this.note_list.Where(r => r.error.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 14) // install fonts
                                    {
                                        int sum = this.note_list.Where(r => r.fonts.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 15) // print
                                    {
                                        int sum = this.note_list.Where(r => r.print.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 16) // อบรม
                                    {
                                        int sum = this.note_list.Where(r => r.training.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 17) // สินค้า
                                    {
                                        int sum = this.note_list.Where(r => r.stock.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 18) // form,report
                                    {
                                        int sum = this.note_list.Where(r => r.form.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 19) // report->excel
                                    {
                                        int sum = this.note_list.Where(r => r.rep_excel.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 20) // สร้างงบ
                                    {
                                        int sum = this.note_list.Where(r => r.statement.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 21) // ทรัพย์สิน/ค่าเสื่อม
                                    {
                                        int sum = this.note_list.Where(r => r.asset.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 22) // secure
                                    {
                                        int sum = this.note_list.Where(r => r.secure.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 23) // year end
                                    {
                                        int sum = this.note_list.Where(r => r.year_end.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 24) // วันที่ไม่อยู่ในงวด
                                    {
                                        int sum = this.note_list.Where(r => r.period.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 25) // Mail,รอสาย
                                    {
                                        int sum = this.note_list.Where(r => r.mail_wait.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                    if (e.ColumnIndex == 26) // โอนฝ่ายขาย
                                    {
                                        int sum = this.note_list.Where(r => r.transfer_mkt.Length > 0).Count<Note>();
                                        e.Graphics.DrawString(sum.ToString(), font, brush, summary_bound, format);
                                    }
                                }
                            }
                        }
                    }
                    e.Handled = true;
                }
            };

            #region Adjust Inline Form Control position while datagridview is resized
            this.dgvNote.Resize += delegate
            {
                this.AdjustInlineFormPositon();
            };
            #endregion Adjust Inline Form Control position while datagridview is resized

            #region Show Inline Form When Double-click cell
            this.dgvNote.CellDoubleClick += delegate(object sender, DataGridViewCellEventArgs e)
            {
                if (this.dgvNote.CurrentCell != null)
                {
                    if (e.RowIndex > -1)
                    {
                        this.toolStripEdit.PerformClick();
                    }
                }
            };
            #endregion Show Inline Form When Double-click cell

            #region Re-order datagridview by click column header
            //this.dgvNote.ColumnHeaderMouseClick += delegate(object sender, DataGridViewCellMouseEventArgs e)
            //{
            //    if (e.ColumnIndex == 3)
            //    {
            //        this.sorted_column = 3;
            //        this.FillDataGrid();
            //    }
            //    if (e.ColumnIndex == 6)
            //    {
            //        this.sorted_column = 6;
            //        this.FillDataGrid();
            //    }
            //};
            this.dgvNote.ColumnHeaderMouseClick += delegate(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.RowIndex == -1 && e.Button == MouseButtons.Left)
                {
                    if (e.ColumnIndex == 5)
                    {
                        this.sorted_column = 5;
                        this.FillDataGrid();
                        this.dgvNote.Columns[5].HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_ACTIVE_BROWN;
                        this.dgvNote.Columns[8].HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_BROWN;
                    }

                    if (e.ColumnIndex == 8)
                    {
                        //this.dgvNote.Rows.Cast<DataGridViewRow>().OrderBy(r => ((SupportNote)r.Cells[0].Value).duration);
                        this.sorted_column = 8;
                        this.FillDataGrid();
                        this.dgvNote.Columns[8].HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_ACTIVE_BROWN;
                        this.dgvNote.Columns[5].HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_BROWN;
                    }
                }
            };
            #endregion Re-order datagridview by click column header

            #region DgvNote context menu
            this.dgvNote.MouseClick += delegate(object sender, MouseEventArgs e)
            {
                int row_index = this.dgvNote.HitTest(e.X, e.Y).RowIndex;
                int col_index = this.dgvNote.HitTest(e.X, e.Y).ColumnIndex;

                if (row_index == -1)
                    return;

                if (!(this.dgvNote.Rows[row_index].Cells[0].Value is SupportNote))
                    return;

                this.dgvNote.Rows[row_index].Cells[col_index].Selected = true;
                if (e.Button == MouseButtons.Right)
                {
                    ContextMenu mnu = new ContextMenu();

                    MenuItem add_talk = new MenuItem("บันทึกสายสนทนา");
                    add_talk.Click += delegate
                    {
                        SupportNoteDialog sd = new SupportNoteDialog(this, false);
                        if (sd.ShowDialog() == DialogResult.OK)
                        {
                            this.GetNote(0, sd.note.date, sd.note.start_time, sd.note.end_time);
                        }
                    };
                    MenuItem add_break = new MenuItem("พักสาย");
                    add_break.Click += delegate
                    {
                        SupportNoteDialog sd = new SupportNoteDialog(this, true);
                        if (sd.ShowDialog() == DialogResult.OK)
                        {
                            this.GetNote(0, sd.note.date, sd.note.start_time, sd.note.end_time);
                        }
                    };
                    MenuItem m_add = new MenuItem("เพิ่ม...", new MenuItem[]{ add_talk, add_break });
                    mnu.MenuItems.Add(m_add);

                    MenuItem m_remark = new MenuItem("แก้ไข");
                    m_remark.Click += delegate
                    {
                        this.toolStripEdit.PerformClick();
                    };
                    mnu.MenuItems.Add(m_remark);

                    MenuItem m_comment = new MenuItem("Comment/Complain");
                    m_comment.Click += delegate
                    {
                        this.ShowCommentForm();
                    };
                    mnu.MenuItems.Add(m_comment);

                    mnu.Show(this.dgvNote, new Point(e.X, e.Y));

                }
            };
            #endregion DgvNote context menu

            #region chApplyCondition CheckState Change
            this.chApplyCondition.CheckStateChanged += delegate
            {
                if (this.chApplyCondition.CheckState == CheckState.Unchecked)
                {
                    this.txtSernum.Read_Only = true;
                    this.chComment.Enabled = false;
                    this.cbProblem.Enabled = false;
                    this.cbReason.Enabled = false;
                    this.btnAddProblem.Enabled = false;
                    this.btnAddAllProblem.Enabled = false;
                    this.btnRemoveAllProblem.Enabled = false;
                    this.dgvProblem.Enabled = false;
                    this.btnAddReason.Enabled = false;
                    this.btnAddAllReason.Enabled = false;
                    this.btnRemoveAllReason.Enabled = false;
                    this.dgvReason.Enabled = false;
                }
                else
                {
                    this.txtSernum.Read_Only = false;
                    this.chComment.Enabled = true;
                    this.cbProblem.Enabled = true;
                    this.cbReason.Enabled = true;
                    this.btnAddProblem.Enabled = true;
                    this.btnAddAllProblem.Enabled = true;
                    this.btnRemoveAllProblem.Enabled = true;
                    this.dgvProblem.Enabled = true;
                    this.btnAddReason.Enabled = true;
                    this.btnAddAllReason.Enabled = true;
                    this.btnRemoveAllReason.Enabled = true;
                    this.dgvReason.Enabled = true;
                }
                this.FillDataGrid();
            };
            #endregion chApplyCondition CheckState Change

            #region Trigger by condition control
            this.txtSernum.textBox1.TextChanged += delegate
            {
                this.FillDataGrid();
                this.txtSernum.textBox1.Focus();
                this.txtSernum.SelectionStart = this.txtSernum.Texts.Length;
            };

            this.chComment.CheckStateChanged += delegate
            {
                this.FillDataGrid();
            };

            this.btnAddProblem.Click += delegate
            {
                if (this.cbProblem.SelectedItem == null)
                    return;

                this.AddProblemCondition((ComboboxItem)this.cbProblem.SelectedItem);

                this.FillDataGrid();
            };

            this.btnAddReason.Click += delegate
            {
                if (this.cbReason.SelectedItem == null)
                    return;

                this.AddReasonCondition((ComboboxItem)this.cbReason.SelectedItem);

                this.FillDataGrid();
            };

            this.btnAddAllProblem.Click += delegate
            {
                for (int i = this.list_problem_all.Count - 1; i >= 0; i--)
                {
                    this.AddProblemCondition(this.list_problem_all[i]);
                }

                this.FillDataGrid();
            };

            this.btnAddAllReason.Click += delegate
            {
                for (int i = this.list_reason_all.Count - 1; i >= 0; i--)
                {
                    this.AddReasonCondition(this.list_reason_all[i]);
                }

                this.FillDataGrid();
            };
            this.btnRemoveAllProblem.Click += delegate
            {
                for (int i = this.dgvProblem.Rows.Count - 1; i >= 0; i--)
                {
                    this.RemoveProblemCondition((ComboboxItem)this.dgvProblem.Rows[i].Tag);
                }

                this.FillDataGrid();
            };
            this.btnRemoveAllReason.Click += delegate
            {
                for (int i = this.dgvReason.Rows.Count - 1; i >= 0; i--)
                {
                    this.RemoveReasonCondition((ComboboxItem)this.dgvReason.Rows[i].Tag);
                }

                this.FillDataGrid();
            };
            this.dgvProblem.CellMouseClick += delegate(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.RowIndex < 0)
                    return;

                if (e.ColumnIndex != 1)
                    return;

                if (this.dgvProblem.Rows[e.RowIndex].Tag is ComboboxItem)
                {
                    this.RemoveProblemCondition((ComboboxItem)this.dgvProblem.Rows[e.RowIndex].Tag);
                }

                this.FillDataGrid();
            };
            this.dgvReason.CellMouseClick += delegate(object sender, DataGridViewCellMouseEventArgs e)
            {
                if (e.RowIndex < 0)
                    return;

                if (e.ColumnIndex != 1)
                    return;

                if (this.dgvReason.Rows[e.RowIndex].Tag is ComboboxItem)
                {
                    this.RemoveReasonCondition((ComboboxItem)this.dgvReason.Rows[e.RowIndex].Tag);
                }

                this.FillDataGrid();
            };
            #endregion Trigger by condition control
        }
Exemple #2
0
 private void btnAddTalk_Click(object sender, EventArgs e)
 {
     SupportNoteDialog sd = new SupportNoteDialog(this, false);
     if (sd.ShowDialog() == DialogResult.OK)
     {
         this.GetNote(0, sd.note.date, sd.note.start_time, sd.note.end_time);
     }
 }
Exemple #3
0
        private void toolStripEdit_Click(object sender, EventArgs e)
        {
            //this.FormEdit();
            //string remark = (string)this.dgvNote.Rows[this.dgvNote.CurrentCell.RowIndex].Cells[27].Value;

            //CustomTextBox ct = new CustomTextBox();
            //ct.Read_Only = false;
            //ct.BorderStyle = BorderStyle.None;
            //ct.Name = "txt_inline_remark";
            //ct.Texts = remark;

            //this.dgvNote.Parent.Controls.Add(ct);
            //this.AdjustInlineFormPositon();

            //this.dgvNote.Enabled = false;
            //this.dgvNote.SendToBack();
            //ct.BringToFront();
            //ct.Focus();
            //ct.SelectionStart = 0;
            //ct.SelectionLength = 0;
            if (this.dgvNote.CurrentCell == null)
                return;

            SupportNoteDialog sd;
            if (((SupportNote)this.dgvNote.Rows[this.dgvNote.CurrentCell.RowIndex].Cells[0].Value).is_break == "Y")
            {
                sd = new SupportNoteDialog(this, true, (SupportNote)this.dgvNote.Rows[this.dgvNote.CurrentCell.RowIndex].Cells[0].Value);
            }
            else
            {
                sd = new SupportNoteDialog(this, false, (SupportNote)this.dgvNote.Rows[this.dgvNote.CurrentCell.RowIndex].Cells[0].Value);
            }

            if (sd.ShowDialog() == DialogResult.OK)
            {
                this.GetNote(0, sd.note.date, sd.note.start_time, sd.note.end_time);
            }
        }