示例#1
0
 private void setSelectedItem(Istab selected_item = null)
 {
     if (selected_item == null)
     {
         foreach (DataGridViewRow row in this.dgvIstab.Rows)
         {
             if (string.CompareOrdinal(this.selected_typcod, ((Istab)row.Tag).typcod) <= 0)
             {
                 row.Cells[1].Selected = true;
                 break;
             }
         }
     }
     else
     {
         foreach (DataGridViewRow row in this.dgvIstab.Rows)
         {
             if (((Istab)row.Tag).typcod == selected_item.typcod)
             {
                 row.Cells[1].Selected = true;
                 break;
             }
         }
     }
     this.dgvIstab.Focus();
 }
示例#2
0
        private void returnSelectedResult()
        {
            this.istab = (Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag;

            this.DialogResult = DialogResult.OK;
            this.Close();
        }
示例#3
0
        private void IstabAddEditForm_Load(object sender, EventArgs e)
        {
            if (this.mode == FORM_MODE.ADD)
            {
                this.Text = "Add data : " + Istab.getTabtypTitle(this.tabtyp);
                this.txtTypcod.Focus();
            }
            else
            {
                this.Text = "Edit data : " + Istab.getTabtypTitle(this.tabtyp);
                this.txtTypcod.Enabled = false;
                this.txtAbbreviate_th.Focus();

                CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "istab/get_by_id&id=" + this.istab.id);
                ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);
                if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                {
                    if (sr.istab != null)
                    {
                        this.istab                 = sr.istab.First <Istab>();
                        this.txtTypcod.Text        = this.istab.typcod;
                        this.txtAbbreviate_en.Text = this.istab.abbreviate_en;
                        this.txtAbbreviate_th.Text = this.istab.abbreviate_th;
                        this.txtTypdes_en.Text     = this.istab.typdes_en;
                        this.txtTypdes_th.Text     = this.istab.typdes_th;
                    }
                }
            }
        }
示例#4
0
        private void toolStripDelete_Click(object sender, EventArgs e)
        {
            if (this.dgvIstab.CurrentCell == null)
            {
                return;
            }

            if (this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag is Istab)
            {
                this.dgvIstab.Tag = DGV_TAG.DELETE;

                if (MessageAlert.Show(StringResource.CONFIRM_DELETE, "", MessageAlertButtons.OK_CANCEL, MessageAlertIcons.QUESTION) == DialogResult.OK)
                {
                    this.FormProcessing();

                    Istab  delete_item    = (Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag;
                    bool   delete_success = false;
                    string err_msg        = "";

                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork += delegate
                    {
                        CRUDResult   delete = ApiActions.DELETE(PreferenceForm.API_MAIN_URL() + "istab/delete&id=" + ((Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].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)
                        {
                            int delete_row_index = this.dgvIstab.Rows.Cast <DataGridViewRow>().Where(r => ((Istab)r.Tag).id == delete_item.id).First <DataGridViewRow>().Cells[1].RowIndex;
                            this.GetIstabData(null, false, delete_row_index);
                        }
                        else
                        {
                            MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                            this.dgvIstab.Tag = DGV_TAG.NORMAL;
                            this.FormRead();
                        }
                    };
                    worker.RunWorkerAsync();
                }
                else
                {
                    this.FillInDatagrid((Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag);
                }
            }
        }
示例#5
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            if (this.txtTypcod.Text.Length > 0)
            {
                CRUDResult post;
                if (this.mode == FORM_MODE.ADD) // Add
                {
                    Console.WriteLine("current tabtyp = " + Istab.getTabtypString(this.tabtyp));
                    string json_data = "{\"tabtyp\":\"" + Istab.getTabtypString(this.tabtyp) + "\",";
                    json_data += "\"typcod\":\"" + this.txtTypcod.Text.cleanString() + "\",";
                    json_data += "\"abbreviate_en\":\"" + this.txtAbbreviate_en.Text.cleanString() + "\",";
                    json_data += "\"abbreviate_th\":\"" + this.txtAbbreviate_th.Text.cleanString() + "\",";
                    json_data += "\"typdes_en\":\"" + this.txtTypdes_en.Text.cleanString() + "\",";
                    json_data += "\"typdes_th\":\"" + this.txtTypdes_th.Text.cleanString() + "\"}";

                    Console.WriteLine(json_data);
                    post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "istab/create", json_data);
                }
                else // Edit
                {
                    string json_data = "{\"id\":" + this.istab.id.ToString() + ",";
                    json_data += "\"tabtyp\":\"" + this.istab.tabtyp + "\",";
                    json_data += "\"typcod\":\"" + this.istab.typcod + "\",";
                    json_data += "\"abbreviate_en\":\"" + this.txtAbbreviate_en.Text.cleanString() + "\",";
                    json_data += "\"abbreviate_th\":\"" + this.txtAbbreviate_th.Text.cleanString() + "\",";
                    json_data += "\"typdes_en\":\"" + this.txtTypdes_en.Text.cleanString() + "\",";
                    json_data += "\"typdes_th\":\"" + this.txtTypdes_th.Text.cleanString() + "\"}";

                    Console.WriteLine(json_data);
                    post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "istab/submit_change", json_data);
                }

                ServerResult sr = JsonConvert.DeserializeObject <ServerResult>(post.data);
                Console.WriteLine(post.data);
                if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                {
                    if (sr.istab != null)
                    {
                        this.istab = sr.istab[0];
                    }
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageAlert.Show(sr.message, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                }
            }
            else
            {
                MessageAlert.Show(StringResource.PLEASE_FILL_CODE, "Warning", MessageAlertButtons.OK, MessageAlertIcons.WARNING);
                this.txtTypcod.Focus();
            }
        }
示例#6
0
        protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == Keys.Escape)
            {
                this.btnCancel.PerformClick();
                return(true);
            }
            if (keyData == Keys.Enter)
            {
                this.btnOK.PerformClick();
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.A))
            {
                this.btnAdd.PerformClick();
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.E))
            {
                this.btnEdit.PerformClick();
                return(true);
            }
            if (keyData == (Keys.Alt | Keys.D))
            {
                Istab istab = (Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag;
                this.showConfirmDelete(istab);
                return(true);
            }
            if (keyData == (Keys.Tab))
            {
                // do re-order column
                Istab current_item = (Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag;

                if (this.sort_by == SORT_TYPCOD)
                {
                    this.sort_by = SORT_TYPDES;
                    this.fillInDataGrid(this.WhichDataToUse());
                    this.dgvIstab.Columns[2].HeaderCell.Style.BackColor = Color.OliveDrab;
                    this.dgvIstab.Columns[1].HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_NOT_SORTABLE_GREEN;
                }
                else if (this.sort_by == SORT_TYPDES)
                {
                    this.sort_by = SORT_TYPCOD;
                    this.fillInDataGrid(this.WhichDataToUse());
                    this.dgvIstab.Columns[1].HeaderCell.Style.BackColor = Color.OliveDrab;
                    this.dgvIstab.Columns[2].HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_NOT_SORTABLE_GREEN;
                }
                this.setSelectedItem(current_item);

                return(true);
            }
            return(base.ProcessCmdKey(ref msg, keyData));
        }
示例#7
0
        /// <summary>
        /// Form for Add/Edit istab data
        /// </summary>
        /// <param name="mode">Specify mode (add or edit)</param>
        /// <param name="tabtyp">Tabtyp value</param>
        /// <param name="istab_data">istab data to edit(for edit mode only)</param>
        public IstabAddEditForm(FORM_MODE mode, Istab.TABTYP tabtyp, Istab istab_data = null)
        {
            InitializeComponent();
            this.istab  = istab_data;
            this.tabtyp = tabtyp;

            EscapeKeyToCloseDialog.ActiveEscToClose(this);
            EnterKeyManager.Active(this);

            this.mode = mode;

            this.initializeForm();
        }
示例#8
0
        private void UpdateData()
        {
            this.FormProcessing();
            Istab data = this.GetDataInForm();

            bool   post_success = false;
            string err_msg      = "";

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate
            {
                string json_data = "{\"id\":" + data.id.ToString() + ",";
                json_data += "\"tabtyp\":\"" + Istab.getTabtypString(this.tabtyp) + "\",";
                json_data += "\"typcod\":\"" + data.typcod.cleanString() + "\",";
                json_data += "\"abbreviate_th\":\"" + data.abbreviate_th.cleanString() + "\",";
                json_data += "\"abbreviate_en\":\"" + data.abbreviate_en.cleanString() + "\",";
                json_data += "\"typdes_th\":\"" + data.typdes_th.cleanString() + "\",";
                json_data += "\"typdes_en\":\"" + data.typdes_en.cleanString() + "\"}";

                CRUDResult   post = ApiActions.POST(PreferenceForm.API_MAIN_URL() + "istab/submit_change", json_data);
                ServerResult sr   = JsonConvert.DeserializeObject <ServerResult>(post.data);
                if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                {
                    post_success = true;
                }
                else
                {
                    post_success = false;
                    err_msg      = sr.message;
                }
            };
            worker.RunWorkerCompleted += delegate
            {
                if (post_success)
                {
                    this.GetIstabData(data);
                }
                else
                {
                    MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                    this.FormEdit();
                    if (this.dgvIstab.Parent.Controls.Find("inline_typdes_en", true).Length > 0)
                    {
                        ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_typdes_en", true)[0]).textBox1.Focus();
                    }
                }
            };
            worker.RunWorkerAsync();
        }
示例#9
0
        private void showEditForm(Istab istab)
        {
            IstabAddEditForm wind = new IstabAddEditForm(IstabAddEditForm.FORM_MODE.EDIT, this.tabtyp, istab);

            if (wind.ShowDialog() == DialogResult.OK)
            {
                this.main_form.data_resource.Refresh();
                this.fillInDataGrid(this.WhichDataToUse());
                this.setSelectedItem(wind.istab);
                this.dgvIstab.Focus();
            }
            else
            {
                this.dgvIstab.Focus();
            }
        }
示例#10
0
        private void dgvIstab_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            foreach (DataGridViewColumn col in ((DataGridView)sender).Columns)
            {
                col.HeaderCell.Style.BackColor = ColorResource.COLUMN_HEADER_NOT_SORTABLE_GREEN;
            }
            ((DataGridView)sender).Columns[e.ColumnIndex].HeaderCell.Style.BackColor = Color.OliveDrab;

            Istab current_item = (Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag;

            if (e.ColumnIndex == 1)
            {
                this.sort_by = SORT_TYPCOD;
                this.fillInDataGrid(this.WhichDataToUse());
            }
            else if (e.ColumnIndex == 2)
            {
                this.sort_by = SORT_TYPDES;
                this.fillInDataGrid(this.WhichDataToUse());
            }

            this.setSelectedItem(current_item);
        }
示例#11
0
 private void showConfirmDelete(Istab istab)
 {
     if (MessageAlert.Show(StringResource.CONFIRM_DELETE, "", MessageAlertButtons.YES_NO, MessageAlertIcons.QUESTION) == DialogResult.Yes)
     {
         CRUDResult   delete = ApiActions.DELETE(PreferenceForm.API_MAIN_URL() + "istab/delete&id=" + istab.id);
         ServerResult sr     = JsonConvert.DeserializeObject <ServerResult>(delete.data);
         if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
         {
             this.main_form.data_resource.Refresh();
             this.fillInDataGrid(this.WhichDataToUse());
             this.dgvIstab.Focus();
         }
         else
         {
             MessageAlert.Show(sr.message, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
             this.dgvIstab.Focus();
         }
     }
     else
     {
         this.dgvIstab.Focus();
     }
 }
示例#12
0
        private Istab GetDataInForm()
        {
            Istab data = new Istab();

            if (this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag is Istab) // edit mode return row_id
            {
                data.id = ((Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag).id;
            }
            else // add mode return -1
            {
                data.id = -1;
            }

            if (this.dgvIstab.Parent.Controls.Find("inline_typcod", true).Length > 0)
            {
                data.typcod = ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_typcod", true)[0]).Texts;
            }
            if (this.dgvIstab.Parent.Controls.Find("inline_abbr_th", true).Length > 0)
            {
                data.abbreviate_th = ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_abbr_th", true)[0]).Texts;
            }
            if (this.dgvIstab.Parent.Controls.Find("inline_abbr_en", true).Length > 0)
            {
                data.abbreviate_en = ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_abbr_en", true)[0]).Texts;
            }
            if (this.dgvIstab.Parent.Controls.Find("inline_typdes_th", true).Length > 0)
            {
                data.typdes_th = ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_typdes_th", true)[0]).Texts;
            }
            if (this.dgvIstab.Parent.Controls.Find("inline_typdes_en", true).Length > 0)
            {
                data.typdes_en = ((CustomTextBox)this.dgvIstab.Parent.Controls.Find("inline_typdes_en", true)[0]).Texts;
            }

            return(data);
        }
示例#13
0
        private void performEdit(object sender, EventArgs e)
        {
            Istab istab = (Istab)((MenuItem)sender).Tag;

            this.showEditForm(istab);
        }
示例#14
0
        private void performDelete(object sender, EventArgs e)
        {
            Istab istab = (Istab)((MenuItem)sender).Tag;

            this.showConfirmDelete(istab);
        }
示例#15
0
        private void GetIstabData(Istab selected_item = null, bool performadd = false, int selected_row_index_after_delete = -1)
        {
            this.FormProcessing();

            string sort = "";

            switch (this.sort)
            {
            case SORT_BY.TYPCOD:
                sort = "typcod";
                break;

            case SORT_BY.ABBR_TH:
                sort = "abbreviate_th";
                break;

            case SORT_BY.ABBR_EN:
                sort = "abbreviate_en";
                break;

            case SORT_BY.DESC_TH:
                sort = "typdes_th";
                break;

            case SORT_BY.DESC_EN:
                sort = "typdes_en";
                break;

            default:
                sort = "typcod";
                break;
            }
            bool   get_success = false;
            string err_msg     = "";

            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += delegate
            {
                CRUDResult   get = ApiActions.GET(PreferenceForm.API_MAIN_URL() + "istab/get_all&tabtyp=" + this.tabtyp.ToTabtypString() + "&sort=" + sort);
                ServerResult sr  = JsonConvert.DeserializeObject <ServerResult>(get.data);
                if (sr.result == ServerResult.SERVER_RESULT_SUCCESS)
                {
                    get_success = true;
                    this.istabs = sr.istab;
                    this.main_form.data_resource.Refresh();
                }
                else
                {
                    get_success = false;
                    err_msg     = sr.message;
                }
            };
            worker.RunWorkerCompleted += delegate
            {
                if (get_success)
                {
                    this.FillInDatagrid(selected_item);
                    this.FormRead();
                    if (performadd)
                    {
                        this.toolStripAdd.PerformClick();
                    }
                    if (selected_row_index_after_delete > -1)
                    {
                        this.dgvIstab.Rows[selected_row_index_after_delete].Cells[1].Selected = true;
                    }
                }
                else
                {
                    MessageAlert.Show(err_msg, "Error", MessageAlertButtons.OK, MessageAlertIcons.ERROR);
                    this.FormRead();
                }
            };
            worker.RunWorkerAsync();
        }
示例#16
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            Istab istab = (Istab)this.dgvIstab.Rows[this.dgvIstab.CurrentCell.RowIndex].Tag;

            this.showEditForm(istab);
        }
        private void KeyPressEventHandler(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.F6)
            {
                Control control = sender as Control;
                //int ndx = this.list_tb.FindIndex(new System.Predicate<TextBox>((value) => { return value == tb; }));
                //int ndx = this.list_tb.FindIndex(new Predicate<TextBox>((value) => { return value == tb; }));
                int ndx = this.list_tb.FindIndex(t => t.Equals(control));
                this.list_btn[ndx].PerformClick();
            }
            else if (e.KeyCode == Keys.Enter)
            {
                string str_input = ((TextBox)sender).Text;
                int    ndx       = list_tb.FindIndex(t => t.Equals((TextBox)sender));
                switch (this.list_select[ndx])
                {
                    #region Case Area
                case SELECTION_DATA.AREA:
                    if (str_input.Length > 0)
                    {
                        Istab area = this.list_area.Find(t => t.typcod == str_input);
                        if (area != null)
                        {
                            list_lbl[ndx].Text = area.typdes_th;
                        }
                        else
                        {
                            this.list_btn[ndx].PerformClick();
                        }
                    }
                    else
                    {
                        this.list_lbl[ndx].Text = "";
                    }
                    break;

                    #endregion Case Area
                    #region Case Verext
                case SELECTION_DATA.VEREXT:
                    if (str_input.Length > 0)
                    {
                        Istab verext = this.list_verext.Find(t => t.typcod == str_input);
                        if (verext != null)
                        {
                            list_lbl[ndx].Text = verext.typdes_th;
                        }
                        else
                        {
                            this.list_btn[ndx].PerformClick();
                        }
                    }
                    else
                    {
                        this.list_lbl[ndx].Text = "";
                    }
                    break;

                    #endregion Case Verext
                    #region Case Howknown
                case SELECTION_DATA.HOWKNOWN:
                    if (str_input.Length > 0)
                    {
                        Istab howknown = this.list_howknown.Find(t => t.typcod == str_input);
                        if (howknown != null)
                        {
                            list_lbl[ndx].Text = howknown.typdes_th;
                        }
                        else
                        {
                            this.list_btn[ndx].PerformClick();
                        }
                    }
                    else
                    {
                        this.list_lbl[ndx].Text = "";
                    }
                    break;

                    #endregion Case Howknown
                    #region Case Busityp
                case SELECTION_DATA.BUSITYP:
                    if (str_input.Length > 0)
                    {
                        Istab busityp = this.list_busityp.Find(t => t.typcod == str_input);
                        if (busityp != null)
                        {
                            list_lbl[ndx].Text = busityp.typdes_th;
                        }
                        else
                        {
                            this.list_btn[ndx].PerformClick();
                        }
                    }
                    else
                    {
                        this.list_lbl[ndx].Text = "";
                    }
                    break;

                    #endregion Case Busityp
                    #region Case Problem_code
                case SELECTION_DATA.PROBLEM_CODE:
                    if (str_input.Length > 0)
                    {
                        Istab problem_code = this.list_problem_code.Find(t => t.typcod == str_input);
                        if (problem_code != null)
                        {
                            list_lbl[ndx].Text = problem_code.typdes_th;
                        }
                        else
                        {
                            this.list_btn[ndx].PerformClick();
                        }
                    }
                    else
                    {
                        this.list_lbl[ndx].Text = "";
                    }
                    break;

                    #endregion Case Problem_code
                    #region Case Dealer
                case SELECTION_DATA.DEALER:
                    if (str_input.Length > 0)
                    {
                        Dealer dealer = this.list_dealer.Find(t => t.dealer == str_input);
                        if (dealer != null)
                        {
                            list_lbl[ndx].Text = dealer.prenam + " " + dealer.compnam;
                        }
                        else
                        {
                            this.list_btn[ndx].PerformClick();
                        }
                    }
                    else
                    {
                        this.list_lbl[ndx].Text = "";
                    }
                    break;

                    #endregion Case Dealer
                default:
                    break;
                }
            }
        }
示例#18
0
        private void FillInDatagrid(Istab selected_item = null)
        {
            this.dgvIstab.Rows.Clear();
            this.dgvIstab.Columns.Clear();
            this.dgvIstab.Tag = DGV_TAG.NORMAL;
            this.dgvIstab.EnableHeadersVisualStyles = false;

            DataGridViewTextBoxColumn col0 = new DataGridViewTextBoxColumn();

            col0.HeaderText       = "ID";
            col0.Width            = 0;
            col0.HeaderCell.Style = new DataGridViewCellStyle()
            {
                Font      = new Font("Tahoma", 9.75f, FontStyle.Bold),
                BackColor = Color.YellowGreen,
                Padding   = new Padding(0, 3, 0, 3),
                Alignment = DataGridViewContentAlignment.MiddleCenter
            };
            col0.Visible = false;
            this.dgvIstab.Columns.Add(col0);

            DataGridViewTextBoxColumn col1 = new DataGridViewTextBoxColumn();

            col1.HeaderText       = "รหัส";
            col1.Width            = 80;
            col1.HeaderCell.Style = new DataGridViewCellStyle()
            {
                Font      = new Font("Tahoma", 9.75f, FontStyle.Bold),
                BackColor = this.sorted_column_header,
                Padding   = new Padding(0, 3, 0, 3),
                Alignment = DataGridViewContentAlignment.MiddleCenter
            };
            this.dgvIstab.Columns.Add(col1);

            DataGridViewTextBoxColumn col2 = new DataGridViewTextBoxColumn();

            col2.HeaderText       = "ชื่อย่อไทย";
            col2.Width            = 100;
            col2.HeaderCell.Style = new DataGridViewCellStyle()
            {
                Font      = new Font("Tahoma", 9.75f, FontStyle.Bold),
                BackColor = this.general_column_header,
                Padding   = new Padding(0, 3, 0, 3),
                Alignment = DataGridViewContentAlignment.MiddleCenter
            };
            this.dgvIstab.Columns.Add(col2);

            DataGridViewTextBoxColumn col3 = new DataGridViewTextBoxColumn();

            col3.HeaderText       = "ชื่อย่อEng";
            col3.Width            = 100;
            col3.HeaderCell.Style = new DataGridViewCellStyle()
            {
                Font      = new Font("Tahoma", 9.75f, FontStyle.Bold),
                BackColor = this.general_column_header,
                Padding   = new Padding(0, 3, 0, 3),
                Alignment = DataGridViewContentAlignment.MiddleCenter
            };
            this.dgvIstab.Columns.Add(col3);

            DataGridViewTextBoxColumn col4 = new DataGridViewTextBoxColumn();

            col4.HeaderText       = "ชื่อเต็มไทย";
            col4.AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
            col4.HeaderCell.Style = new DataGridViewCellStyle()
            {
                Font      = new Font("Tahoma", 9.75f, FontStyle.Bold),
                BackColor = this.general_column_header,
                Padding   = new Padding(0, 3, 0, 3),
                Alignment = DataGridViewContentAlignment.MiddleCenter
            };
            this.dgvIstab.Columns.Add(col4);

            DataGridViewTextBoxColumn col5 = new DataGridViewTextBoxColumn();

            col5.HeaderText       = "ชื่อเต็มEng";
            col5.AutoSizeMode     = DataGridViewAutoSizeColumnMode.Fill;
            col5.HeaderCell.Style = new DataGridViewCellStyle()
            {
                Font      = new Font("Tahoma", 9.75f, FontStyle.Bold),
                BackColor = this.general_column_header,
                Padding   = new Padding(0, 3, 0, 3),
                Alignment = DataGridViewContentAlignment.MiddleCenter
            };
            this.dgvIstab.Columns.Add(col5);

            foreach (Istab istab in this.istabs)
            {
                int r = this.dgvIstab.Rows.Add();
                this.dgvIstab.Rows[r].Tag = istab;
                DataGridViewRow row = this.dgvIstab.Rows[r];
                row.Height   = 25;
                row.ReadOnly = true;

                row.Cells[0].ValueType = typeof(int);
                row.Cells[0].Tag       = "ID";
                row.Cells[0].Value     = istab.id;
                row.Cells[0].Style     = new DataGridViewCellStyle()
                {
                    Font               = new Font("Tahoma", 9.75f),
                    BackColor          = Color.White,
                    ForeColor          = Color.Black,
                    SelectionBackColor = Color.White,
                    SelectionForeColor = Color.Black,
                };

                row.Cells[1].ValueType = typeof(string);
                row.Cells[1].Value     = istab.typcod;
                row.Cells[1].Style     = new DataGridViewCellStyle()
                {
                    Font               = new Font("Tahoma", 9.75f),
                    BackColor          = Color.White,
                    ForeColor          = Color.Black,
                    SelectionBackColor = Color.White,
                    SelectionForeColor = Color.Black,
                };

                row.Cells[2].ValueType = typeof(string);
                row.Cells[2].Value     = istab.abbreviate_th;
                row.Cells[2].Style     = new DataGridViewCellStyle()
                {
                    Font               = new Font("Tahoma", 9.75f),
                    BackColor          = Color.White,
                    ForeColor          = Color.Black,
                    SelectionBackColor = Color.White,
                    SelectionForeColor = Color.Black,
                };

                row.Cells[3].ValueType = typeof(string);
                row.Cells[3].Value     = istab.abbreviate_en;
                row.Cells[3].Style     = new DataGridViewCellStyle()
                {
                    Font               = new Font("Tahoma", 9.75f),
                    BackColor          = Color.White,
                    ForeColor          = Color.Black,
                    SelectionBackColor = Color.White,
                    SelectionForeColor = Color.Black,
                };

                row.Cells[4].ValueType = typeof(string);
                row.Cells[4].Value     = istab.typdes_th;
                row.Cells[4].Style     = new DataGridViewCellStyle()
                {
                    Font               = new Font("Tahoma", 9.75f),
                    BackColor          = Color.White,
                    ForeColor          = Color.Black,
                    SelectionBackColor = Color.White,
                    SelectionForeColor = Color.Black,
                };

                row.Cells[5].ValueType = typeof(string);
                row.Cells[5].Value     = istab.typdes_en;
                row.Cells[5].Style     = new DataGridViewCellStyle()
                {
                    Font               = new Font("Tahoma", 9.75f),
                    BackColor          = Color.White,
                    ForeColor          = Color.Black,
                    SelectionBackColor = Color.White,
                    SelectionForeColor = Color.Black,
                };
            }

            this.dgvIstab.FillLine(this.istabs.Count);

            if (selected_item == null)
            {
                return;
            }

            if (this.dgvIstab.Rows.Cast <DataGridViewRow>().Where(t => t.Tag is Istab).Where(t => ((Istab)t.Tag).id == selected_item.id).Count() > 0)
            {
                this.dgvIstab.Rows.Cast <DataGridViewRow>().Where(t => t.Tag is Istab).Where(t => ((Istab)t.Tag).id == selected_item.id).First <DataGridViewRow>().Cells[1].Selected = true;
            }
        }
示例#19
0
 private void IstabWindow_Load(object sender, EventArgs e)
 {
     this.Text = Istab.getTabtypTitle(this.tabtyp);
     this.GetIstabData();
     this.BindControlEventHandler();
 }
示例#20
0
 private void setTitleText()
 {
     this.Text = Istab.getTabtypTitle(this.tabtyp);
 }
示例#21
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.GetCultureInfo("th-TH"));
            int      days_in_month     = DateTime.DaysInMonth((this.year - 543), 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.GetCultureInfo("th-TH"), DateTimeStyles.None).ToMysqlDate();
            string to_date   = DateTime.Parse(this.year.ToString() + "/" + this.month.ToString() + "/" + days_in_month.ToString(), CultureInfo.GetCultureInfo("th-TH"), 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;
        }