private void btnEditPrice_Click(object sender, EventArgs e)
 {
     if (RecId == null)
     {
         MessageBox.Show("กรุณาเลือกรายการก่อนค่ะ");
     }
     else
     {
         if (userId == "1012" || userId == "2011" || userId == "2010" || userId == "2005" || userId == "2004" || userId == "2002" || userId == "3001" || userId == "2019" || userId == "2018" || userId == "2014" || userId == "2003" || userId == "2033" || userId == "2004" || userId == "2038" || userId == "1026" || userId == "2108" || userId == "0154" || userId == "2049" || userId == "0153" || userId == "2062" || userId == "2068" || userId == "2074" || userId == "2071" || userId == "2066" )
         {
             if (Confirm == "อนุมัติ")
             {
                 MessageBox.Show("รายการรับนี้ไม่สามารถแก้ไขได้  เนื่องจากรายการรับได้อนุมัติแล้ว");
             }
             else
             {
                 receive.frmReceivePrice frm = new frmReceivePrice();
                 frm.setReceiveId = RecId.ToString();
                 frm.ShowDialog();
                 GetData();
             }
         }
         else
         {
             MessageBox.Show("คุณไม่มีสิทธิเข้าดูรายการนี้ได้ !! >_< ");
         }
     }
 }
        private void dgvHead_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex == -1) { return; }
            if (dgvHead.Rows[e.RowIndex].Cells[20].Value.ToString() + "" != "-")
            {
                if (dgvHead.Rows[e.RowIndex].Cells[6].Value.ToString() + "" != "")
                {
                    receive.FrmNewReceive frm = new receive.FrmNewReceive(dgvHead.Rows[e.RowIndex].Cells[0].Value.ToString());
                    frm.ShowDialog();
                    if (frm.DialogResult == DialogResult.OK)
                    {
                        FindSearch();
                    }
                }
                else {
                    receive.FrmNewReceiveDep frm = new receive.FrmNewReceiveDep(dgvHead.Rows[e.RowIndex].Cells[0].Value.ToString());
                    frm.ShowDialog();
                    if (frm.DialogResult == DialogResult.OK)
                    {
                        dgvHead.DataSource = callHeadDep(FSearchDep());
                        formatDgvHead();
                        callGrid();
                    }
                }
            }
            else {
                if (dgvHead.Rows[e.RowIndex].Cells[6].Value.ToString() + "" != "")
                {
                    receive.frmReceivePrice frm = new frmReceivePrice();
                    frm.setReceiveId = dgvHead.Rows[e.RowIndex].Cells[0].Value.ToString();
                    frm.ShowDialog();
                }
                else {
                    StockAsiaDrink.frmPriceReceiveAsiaDrink frm = new StockAsiaDrink.frmPriceReceiveAsiaDrink();
                    frm.setEditId = dgvHead.Rows[e.RowIndex].Cells[0].Value.ToString();
                    frm.ShowDialog();
                }

            }
        }
 private void dgvHead_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Down || e.KeyCode == Keys.Up)
     {
         if (dgvHead.Rows.Count > 0)
         {
             int a = 0;
             if (e.KeyCode == Keys.Down)
             {
                 a = (dgvHead.CurrentRow.Index + 1 > dgvHead.Rows.Count - 1) ? dgvHead.Rows.Count - 1 : dgvHead.CurrentRow.Index + 1;
             }
             if (e.KeyCode == Keys.Up)
             {
                 a = (dgvHead.CurrentRow.Index - 1 < 0) ? 0 : dgvHead.CurrentRow.Index - 1;
             }
             try
             {
                 callDgvDetail(dgvHead.Rows[a].Cells[0].Value.ToString());
                 if (dgvDetail.Rows.Count < 1)
                 {
                     dgvDetail.DataSource = null;
                     dgvWeight.DataSource = null;
                     return;
                 }
                 if (dgvDetail.Rows[0].Cells[17].Value.ToString() + "" != "")
                 {
                     callDgvWeight(dgvDetail.Rows[0].Cells[1].Value.ToString(), dgvDetail.Rows[0].Cells[17].Value.ToString(), dgvDetail.Rows[0].Cells["ProductId"].Value.ToString());
                 }
                 else
                 {
                     callDgvWeightProduct(dgvDetail.Rows[0].Cells[1].Value.ToString(), dgvDetail.Rows[0].Cells[4].Value.ToString(), dgvDetail.Rows[0].Cells["ProductId"].Value.ToString());
                 }
             }
             catch { }
         }
     }
     if (e.KeyCode == Keys.Enter)
     {
         if (dgvHead.Rows.Count > 0)
         {
             dgvHead.Select();
             dgvHead.CellClick += new DataGridViewCellEventHandler(dgvHead_CellClick);
             if (dgvHead.CurrentRow.Cells[20].Value.ToString() + "" != "-")
             {
                 receive.FrmNewReceive frm = new receive.FrmNewReceive(dgvHead.CurrentRow.Cells[0].Value.ToString());
                 frm.Show();
             }
             else
             {
                 receive.frmReceivePrice frm = new frmReceivePrice();
                 frm.setReceiveId = dgvHead.CurrentRow.Cells[0].Value.ToString();
                 frm.ShowDialog();
             }
         }
     }
 }
        private void txtreceive_KeyUp(object sender, KeyEventArgs e)
        {
            FindSearch2();
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    if (dgvHead.CurrentRow.Cells[20].Value.ToString() + "" != "-")
                    {
                        if (dgvHead.CurrentRow.Cells[6].Value.ToString() + "" != "")
                        {
                            receive.FrmNewReceive frm = new receive.FrmNewReceive(dgvHead.CurrentRow.Cells[0].Value.ToString());
                            frm.Show();
                        }
                        else
                        {
                            receive.FrmNewReceiveDep frm = new receive.FrmNewReceiveDep(dgvHead.CurrentRow.Cells[0].Value.ToString());
                            frm.Show();
                        }
                    }
                    else
                    {
                        if (dgvHead.CurrentRow.Cells[6].Value.ToString() + "" != "")
                        {
                            receive.frmReceivePrice frm = new frmReceivePrice();
                            frm.setReceiveId = dgvHead.CurrentRow.Cells[0].Value.ToString();
                            frm.ShowDialog();
                        }
                        else
                        {
                            StockAsiaDrink.frmPriceReceiveAsiaDrink frm = new StockAsiaDrink.frmPriceReceiveAsiaDrink();
                            frm.setEditId = dgvHead.CurrentRow.Cells[0].Value.ToString();
                            frm.ShowDialog();
                        }

                    }
                }
                catch { }
                dgvHead.Select();
            }
        }