private void txtFormula_Click(object sender, EventArgs e)
 {
     Dialog.frmDialogFormular frm = new Dialog.frmDialogFormular();
     frm.dataGridView2.Visible = false;
     frm.dataGridView1.Dock = DockStyle.Fill;
     frm.tableLayoutPanel1.SetColumnSpan(frm.dataGridView1, 2);
     frm.toolStrip1.Enabled = false;
     frm.ShowDialog();
     if (frm.DialogResult == DialogResult.OK)
     {
         if (frm.getStatus() == "อนุมัติ")
         {
             Fm = frm.getFormularId();
             this.txtFormula.Text = frm.getFormularName();
         }
         else
         {
             MessageBox.Show("สูตรที่เลือกยังไม่อนุมัติ");
         }
     }
 }
        private void txtFormula_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Dialog.frmDialogFormular r = new Dialog.frmDialogFormular(txtFormula.Text);
                r.StartPosition = FormStartPosition.CenterScreen;
                r.ShowDialog();

                if (r.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    txtFormula.Text = "["+r.getFormularId()+"] " + r.getFormularName() + "";
                    label7.Text = r.getUnit();
                }
            }
        }
        private void txtFormula_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Dialog.frmDialogFormular frm = new Dialog.frmDialogFormular(txtFormula.Text);
                frm.dataGridView2.Visible = false;
                frm.dataGridView1.Dock = DockStyle.Fill;
                frm.tableLayoutPanel1.SetColumnSpan(frm.dataGridView1, 2);
                frm.toolStrip1.Enabled = false;
                frm.ShowDialog();

                if (frm.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    txtFormula.Text = "[" + frm.getFormularId() + "] " + frm.getFormularName() + "";
                    label7.Text = frm.getUnit();
                }
            }
        }
        private void loadDialog(String strFormular)
        {
            Dialog.frmDialogFormular frm = new Dialog.frmDialogFormular(strFormular);//เรียกหน้าเพิ่มสูตรผลิต
            frm.dataGridView2.Visible = false;
            frm.dataGridView1.Dock = DockStyle.Fill;
            frm.tableLayoutPanel1.SetColumnSpan(frm.dataGridView1, 2);
            //frm.dataGridView1.MultiSelect = true;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                if (frm.getStatus() == "อนุมัติ")
                {
                    String t = "";
                    String t2 = "";
                    if (rdoNetWell.Checked)
                    {
                        t = "อวนสามชั้นดี";
                        t2 = "1";
                    }
                    else if (rdoNetFail.Checked)
                    {
                        t = "อวนสามชั้นซ่อม";
                        t2 = "2";
                    }

                    string sql = "select p.pvwid,p.pvwnetprice from ProductionVillagerWage p inner join ProductionSize s on p.sizetypeid = s.szid where pvwstatusid = 4 and supplierid = " + Class.Function.GetTextIdx(txtVillager.Text) + " and szname = '" + frm.getFormularSize() + "' ";
                    DataTable pvwnetprice = Class.DBConnString.clsDB.QueryDataTable(sql);
                    if (pvwnetprice.Rows.Count > 0)
                    {
                        foreach (DataRow r in pvwnetprice.Rows)
                        {
                            dataGridView2.Rows.Add(frm.getFormularId(), frm.getFormularName(), "", "", r["pvwid"].ToString(), r["pvwnetprice"].ToString(), "", "", 4, t2, t);
                        }
                    }
                    else
                    {
                        MessageBox.Show("ชาวบ้านนี้ยังไม่มีสูตร " + frm.getFormularName());
                        return;
                    }

                    if (t == "อวนสามชั้นดี") dataGridView2.Rows[dataGridView2.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Black;
                    if (t == "อวนสามชั้นซ่อม") dataGridView2.Rows[dataGridView2.Rows.Count - 1].DefaultCellStyle.ForeColor = Color.Red;
                }
                else
                {
                    MessageBox.Show("สูตรที่เลือกยังไม่อนุมัติ");
                }
            }
        }
 private void txtFormula_KeyDown(object sender, KeyEventArgs e)
 {
     if (Class.Function.GetTextIdx(txtJ.Text) != "")
     {
         if (e.KeyCode == Keys.Enter)
         {
             Dialog.frmDialogFormular Formular = new Dialog.frmDialogFormular(txtFormula.Text);
             Formular.ShowDialog();
             if (Formular.DialogResult == DialogResult.OK)
             {
                 string sql = "select pw.pwn7,pw.pwoutside from ProductionPrisonWage pw                  \n" +
                             "inner join ProductionSize ps on pw.SizeTypeId = ps.SzId                    \n" +
                             "where pw.employerid = " + Class.Function.GetTextIdx(txtJ.Text) + " AND szname = '" + Formular.getFormularSize() + "'";
                 DataTable pw = Class.DBConnString.clsDB.QueryDataTable(sql);
                 if (pw.Rows.Count > 0)
                 {
                     foreach (DataRow r in pw.Rows)
                     {
                         dgvItem.Rows.Add(Formular.getFormularId(), Formular.getFormularName(), 0, 0, r["PwN7"].ToString(), r["PwOutSide"].ToString(), 0, 0, "", "", "", 1, 1);
                     }
                 }
                 else
                 {
                     MessageBox.Show(Class.Function.GetTextName(txtJ.Text) + " ไม่มีสูตรผลิต " + Formular.getFormularName());
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("กรุณาเลือกเรือนจำก่อน");
     }
 }
        /*เรียก Dialog สูตรผลิต*/
        private void loadDialog()
        {
            Dialog.frmDialogFormular frm = new Dialog.frmDialogFormular(1);
            frm.dataGridView2.Visible = false;
            frm.dataGridView1.Dock = DockStyle.Fill;
            frm.tableLayoutPanel1.SetColumnSpan(frm.dataGridView1, 2);
            //frm.toolStrip1.Enabled = false;
            frm.dataGridView1.MultiSelect = true;
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                if (frm.getStatusList().Count != 0)
                {
                    if (frm.getStatusList()[0] == "อนุมัติ")
                    {
                        this.textBox2.Text = "[" +frm.getFormularId() + "] " + frm.getFormularName();
                    }
                    else
                    {
                        MessageBox.Show("สูตรที่เลือกยังไม่อนุมัติ");
                    }
                }

            }
        }
 private void loadDialog()
 {
     /*เรียกหน้าจัดการสูตรผลิต*/
     Dialog.frmDialogFormular frm = new Dialog.frmDialogFormular(textBox7.Text);
     frm.dataGridView2.Visible = false;
     frm.dataGridView1.Dock = DockStyle.Fill;
     frm.tableLayoutPanel1.SetColumnSpan(frm.dataGridView1, 2);
     frm.toolStrip1.Enabled = false;
     frm.ShowDialog();
     if (frm.DialogResult == DialogResult.OK)
     {
         if (frm.getStatus() == "อนุมัติ")
         {
             textBox7.Text = frm.getFormularId();
             textBox8.Text = frm.getFormularName();
             textBox9.Text = frm.getCateName();
             CateId = frm.getCateId();
             textBox10.Focus();
         }
         else {
             MessageBox.Show("สูตรที่เลือกยังไม่อนุมัติ");
         }
     }
 }