private void dataGridView2_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView2.Rows.Count == 0) return;
            if (e.ColumnIndex == 4)
            {

                var item = (from i in qty
                            where Convert.ToInt32(i.ProductionWaitDetailId) == Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["Id"].Value)
                            select i).ToList();

                DialogReceiveQtyOnPalet f = new DialogReceiveQtyOnPalet(dataGridView2.Rows[e.RowIndex].Cells["FmName"].Value.ToString(),
                    dataGridView2.Rows[e.RowIndex].Cells["Pallet"].Value.ToString(),
                    item);//เรียก Dialog จำนวนรับต่อพาเลต

                f.StartPosition = FormStartPosition.CenterScreen;
                f.ShowDialog();
                if (f.DialogResult == System.Windows.Forms.DialogResult.OK)
                {
                    item = (from i in qty
                            where Convert.ToInt32(i.ProductionWaitDetailId) == Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["Id"].Value)
                            select i).ToList();
                    foreach (var i in item)
                    {
                        qty.Remove(i);
                    }

                    int qtyall = 0;

                    for (int i = 0; i < f.dgvQty.Rows.Count - 1; ++i)
                    {
                        qtyall += Convert.ToInt32(f.dgvQty.Rows[i].Cells[1].Value);
                        QtyOnPalet q = new QtyOnPalet(Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["Id"].Value),
                                                        Convert.ToInt32(f.dgvQty.Rows[i].Cells[0].Value),
                                                        Convert.ToInt32(f.dgvQty.Rows[i].Cells[1].Value));//เรียกใช้ฟังก์ชัน QtyOnPalet
                        qty.Add(q);
                    }

                    dataGridView2.Rows[e.RowIndex].Cells["Quantity"].Value = qtyall;
                    Calculate(e.ColumnIndex, e.RowIndex);
                }
            }

            var QtyShow = qty.Where(q => Convert.ToInt32(q.ProductionWaitDetailId) == Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells["Id"].Value)).ToList();

            dgvQty.Rows.Clear();

            foreach (var i in QtyShow)
            {
                dgvQty.Rows.Add(new object[] { i.No, i.Qty });//เก็บค่าลงใน Datagridview
            }
        }
        private void checkType(string type)
        {
            switch (type)
            {
                case "2":
                    {
                        Dialog.DialogAmnt p = new Dialog.DialogAmnt();
                        p.ShowDialog();
                        if (p.DialogResult == System.Windows.Forms.DialogResult.OK)
                        {
                            int value = Convert.ToInt32(p.txtAmnt.Text);
                            dataGridView2.CurrentRow.Cells["WaitDetailQuantity"].Value = value;

                            Calculate(value);
                        }

                        break;
                    }
                case "3":
                    {
                        var item = (from i in qty
                                    where Convert.ToInt32(i.ProductionWaitDetailId) == Convert.ToInt32(dataGridView2.CurrentRow.Cells["WaitDetailId"].Value)
                                    select i).ToList();

                        DialogReceiveQtyOnPalet f = new DialogReceiveQtyOnPalet(dataGridView2.CurrentRow.Cells["FmName"].Value.ToString(),
                            dataGridView2.CurrentRow.Cells["WaitDetailPallet"].Value.ToString(),
                            item);

                        f.StartPosition = FormStartPosition.CenterScreen;
                        f.ShowDialog();
                        if (f.DialogResult == System.Windows.Forms.DialogResult.OK)
                        {
                            item = (from i in qty
                                    where Convert.ToInt32(i.ProductionWaitDetailId) == Convert.ToInt32(dataGridView2.CurrentRow.Cells["WaitDetailId"].Value)
                                    select i).ToList();
                            foreach (var i in item)
                            {
                                qty.Remove(i);
                            }

                            int qtyall = 0;

                            for (int i = 0; i < f.dgvQty.Rows.Count - 1; ++i)
                            {
                                qtyall += Convert.ToInt32(f.dgvQty.Rows[i].Cells[1].Value);
                                QtyOnPalet q = new QtyOnPalet(Convert.ToInt32(dataGridView2.CurrentRow.Cells["WaitDetailId"].Value),
                                                                Convert.ToInt32(f.dgvQty.Rows[i].Cells[0].Value),
                                                                Convert.ToInt32(f.dgvQty.Rows[i].Cells[1].Value));
                                qty.Add(q);
                            }

                            dataGridView2.CurrentRow.Cells["WaitDetailQuantity"].Value = qtyall;

                            Calculate(qtyall);
                        }
                        break;
                    }
            }
        }