Esempio n. 1
0
        /*ตรวจสอบประเภทน้ำหนักและรับค่าจาก Dialog เพิ่มจำนวนและน้ำหนักสินค้า*/
        private void checkType(String type)
        {
            String Mid = dataGridView2.CurrentRow.Cells["Mid"].Value.ToString();
            String ID = dataGridView2.CurrentRow.Cells["ProductID"].Value.ToString();//รหัสสินค้า
            String qtyp = dataGridView2.CurrentRow.Cells["QuantityPack"].Value.ToString();//จำนวนแพ็ค
            String qty = dataGridView2.CurrentRow.Cells["Quantity"].Value.ToString();//จำนวน
            String tw = dataGridView2.CurrentRow.Cells["Detail"].Value.ToString();//รหัสรายการ
            String Rnd = dataGridView2.CurrentRow.Cells["RndId"].Value.ToString();//รหัสรายการ
            //DataTable dt = Class.Function.GetContentAsDataTable(dataGridView1);
            //DataRow r = dt.Select("mid = " + dataGridView2.CurrentRow.Cells["Mid"].Value.ToString()).FirstOrDefault();
            String q = "";
            String d = "";
            foreach (DataGridViewRow dd in dataGridView1.Rows) {
                if (dd.Cells[0].Value.ToString() == dataGridView2.CurrentRow.Cells["Mid"].Value.ToString()) {
                    q = dd.Cells[2].Value.ToString();
                    d = dd.Cells[0].Value.ToString();
                }
            }

            //for (int i = 0; i < r.Length; i++)
            //{
                //q = r[2].ToString();
                //d = r[0].ToString();
            //}
            Double sum = 0;
            foreach( DataGridViewRow row in dataGridView2.Rows ){
                if (d == row.Cells["Mid"].Value.ToString() && row.Cells["ProductID"].Value.ToString() != ID)
                {
                    sum += (row.Cells["Quantity"].Value.ToString() == "") ? 0 : Convert.ToDouble(row.Cells["Quantity"].Value);
                }
            }
            ProductionNew.frmAddReq FrmAddReq = new ProductionNew.frmAddReq(type, ID, tw, qtyp, qty, q,sum);/*Dialog เพิ่มจำนวนและน้ำหนัก*/
            FrmAddReq.ShowDialog();
            if (FrmAddReq.DialogResult == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    if (row.Cells["ProductID"].Value.ToString() == ID && row.Cells["Mid"].Value.ToString() == Mid && row.Cells["RndId"].Value.ToString() == Rnd)
                    {
                        row.Cells["QuantityPack"].Value = "";
                        row.Cells["QuantityPack"].Value = FrmAddReq.txtPack.Text;//รับค่าจำนวนแพ็ค
                        row.Cells["Quantity"].Value = "";
                        row.Cells["Quantity"].Value = FrmAddReq.txtSale.Text;//รับค่าจำนวน
                        row.Cells["Weight"].Value = "";
                        row.Cells["Weight"].Value = FrmAddReq.txtWeight.Text;//รับค่าน้ำหนัก
                        row.Cells["Type"].Value = type;//ประเภทรายการ
                        row.Cells["Detail"].Value = "";
                        row.Cells["Note"].Value = FrmAddReq.txtNote.Text;//หมายเหตุ
                        row.Cells["Total"].Value = (Convert.ToDouble(row.Cells["Quantity"].Value) *
                            Convert.ToDouble(row.Cells["CostPrice"].Value)).ToString();//ต้นทุนรวม

                        foreach (DataGridViewRow roww in FrmAddReq.dgvWeight.Rows)
                        {
                            foreach (DataGridViewCell cell in roww.Cells)
                            {
                                if (roww.Index < FrmAddReq.dgvWeight.RowCount - 1)
                                    if (!cell.Size.IsEmpty) row.Cells["Detail"].Value += cell.Value + "#";//เก็บข้อมูลจำนวนและน้ำหนักลงใน cell
                            }
                        }
                        SetDgvWeightH(row.Cells["Detail"].Value.ToString(), dataGridView3, type);//แสดงข้อมูลจำนวนและน้ำหนัก
                        textBox11.Text = sumTotal("Total");//คำนวณหาต้นทุนรวม
                    }
                }
            }
        }
        /*ตรวจสอบประเภทน้ำหนักและเก็บจำนวนและน้ำหนักจาก Dialog*/
        private void checkType(String type)
        {
            String ID = dataGridView2.CurrentRow.Cells["ProductID"].Value.ToString();//เก็บรหัสสินค้า
            String qtyp = dataGridView2.CurrentRow.Cells["QuantityPack"].Value.ToString();//เก็บจำนวนแพ็ค
            String qty = dataGridView2.CurrentRow.Cells["Quantity"].Value.ToString();//เก็บจำนวน
            String tw = dataGridView2.CurrentRow.Cells["Detail"].Value.ToString();//เก็บรหัสรายการ
            DataTable dt = Class.Function.GetContentAsDataTable(dataGridView1);
            DataRow[] r = dt.Select("mid = " + dataGridView2.CurrentRow.Cells["Mid"].Value.ToString());
            String q = "";
            String d = "";
            for (int i = 0; i < r.Length; i++)
            {
                q = r[i][2].ToString();
                d = r[i][0].ToString();
            }
            Double sum = 0;
            foreach( DataGridViewRow row in dataGridView2.Rows ){
                if (d == row.Cells["Mid"].Value.ToString() && row.Cells["ProductID"].Value.ToString() != ID)
                {
                    sum += (row.Cells["Quantity"].Value.ToString() == "") ? 0 : Convert.ToDouble(row.Cells["Quantity"].Value);//หาผลรวมของจำนวน
                }
            }
            ProductionNew.frmAddReq FrmAddReq = new ProductionNew.frmAddReq(type, ID, tw, qtyp, qty, q,sum);
            FrmAddReq.ShowDialog();//เรียก dialog เพิ่มจำนวนและน้ำหนักสินค้า
            if (FrmAddReq.DialogResult == DialogResult.Yes)
            {
                foreach (DataGridViewRow row in dataGridView2.Rows)
                {
                    if (row.Cells["ProductID"].Value.ToString() == ID)
                    {
                        row.Cells["QuantityPack"].Value = "";
                        row.Cells["QuantityPack"].Value = FrmAddReq.txtPack.Text;//จำนวนแพ็ค
                        row.Cells["Quantity"].Value = "";
                        row.Cells["Quantity"].Value = FrmAddReq.txtSale.Text;//จำนวน
                        row.Cells["Weight"].Value = "";
                        row.Cells["Weight"].Value = FrmAddReq.txtWeight.Text;//น้ำหนัก
                        row.Cells["Type"].Value = type;//ประเภท
                        row.Cells["Detail"].Value = "";
                        row.Cells["Note"].Value = FrmAddReq.txtNote.Text;//หมายเหตุ
                        row.Cells["Total"].Value = (Convert.ToDouble(row.Cells["Quantity"].Value) *
                            Convert.ToDouble(row.Cells["CostPrice"].Value)).ToString();//ต้นทุน

                        foreach (DataGridViewRow roww in FrmAddReq.dgvWeight.Rows)
                        {
                            foreach (DataGridViewCell cell in roww.Cells)
                            {
                                if (roww.Index < FrmAddReq.dgvWeight.RowCount - 1)
                                    if (!cell.Size.IsEmpty) row.Cells["Detail"].Value += cell.Value + "#";//เก็บค่าจำนวนและน้ำหนักลงใน cell
                            }
                        }
                        SetDgvWeightH(row.Cells["Detail"].Value.ToString(), dataGridView3, type);//แสดงน้ำหนักสินค้า
                        textBox11.Text = sumTotal("Total");
                    }
                }
            }
        }