private void textBox8_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (Class.Function.GetTextId(textBox3.Text) == "") {
                    MetroFramework.MetroMessageBox.Show(this, "กรุณาเลือกเรือนจำ", "ผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList(textBox8.Text.Trim(), "and PRODUCT.ProductId in(select ProductId from productiondraw_detail where NewProductionId = '" + textBox9.Text + "') ");
                frm.ShowDialog();
                List<string> ProductId = new List<string>();
                List<string> ProductName = new List<string>();
                List<string> UnitSaleName = new List<string>();
                List<string> UnitPackname = new List<string>();
                List<string> CostPrice = new List<string>();

                List<ProductListRp> ProductList = new List<ProductListRp>();

                if (frm.DialogResult == DialogResult.OK)
                {
                    ProductId = frm.GetProductId();
                    ProductName = frm.GetProductName();
                    UnitSaleName = frm.GetUnitSaleName();
                    UnitPackname = frm.GetUnitPackName();

                    foreach (String n in ProductId)
                    {
                        String sql = "select top 1 case when d.receivedetailPriceUnit = null then 0 when d.receivedetailPriceUnit = '' " +
                        "then 0 else d.receivedetailPriceUnit end as receivedetailPriceUnit from receive_detail d " +
                        "inner join receive_head h on d.receiveheadid = h.receiveheadid " +
                        "where d.productid = '" + n + "' order by h.receiveheaddate desc";
                        CostPrice.Add((Class.DBConnString.clsDB.QueryExecuteScalarNonAlert(sql) == null) ? "0" : Class.DBConnString.clsDB.QueryExecuteScalarNonAlert(sql));
                    }

                    int count = ProductId.Count;
                    AddCol();

                    for (int i = 0; i < count; i++)
                    {
                        ProductList.Add(new ProductListRp
                        {
                            ProductId = ProductId[i],
                            ProductName = ProductName[i],
                            UnitPackname = UnitPackname[i],
                            UnitSaleName = UnitSaleName[i],
                            CostPrice = CostPrice[i]
                        });
                        //ShowDialogAddProductDetail(ProductId[i], ProductName[i], "", UnitPackname[i], "", UnitSaleName[i], "", "กก.");
                    }
                    var listPro = ProductList.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName,i.CostPrice }).Distinct().ToList();

                    if (ProductListOld == null)
                    {
                        foreach (var list in listPro)
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", list.CostPrice);
                            ProductListOld.Add(new ProductListRp
                            {
                                ProductId = list.ProductId,
                                ProductName = list.ProductName,
                                UnitPackname = list.UnitPackname,
                                UnitSaleName = list.UnitSaleName,
                                CostPrice = list.CostPrice
                            });
                        }
                    }
                    else
                    {
                        foreach (var list in listPro.Except(ProductListOld.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName, i.CostPrice }).Distinct().ToList()))
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", list.CostPrice);
                            ProductListOld.Add(new ProductListRp
                            {
                                ProductId = list.ProductId,
                                ProductName = list.ProductName,
                                UnitPackname = list.UnitPackname,
                                UnitSaleName = list.UnitSaleName,
                                CostPrice = list.CostPrice
                            });
                        }
                    }

                }
            }
        }
Example #2
0
        private void txtProductName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (textBox4.Text == "")
                {
                    MessageBox.Show("กรุณาเลือกผู้ขาย");
                    return;
                }
                if (Class.Function.GetTextId(textBox4.Text) == null)
                {
                    MessageBox.Show("กรุณาเลือกผู้ขาย");
                    return;
                }

                Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList(txtProductName.Text.Trim());
                frm.ShowDialog();
                List<string> ProductId = new List<string>();
                List<string> ProductName = new List<string>();
                List<string> UnitSaleName = new List<string>();
                List<string> UnitPackname = new List<string>();

                List<ProductList> ProductList = new List<ProductList>();

                if (frm.DialogResult == DialogResult.OK)
                {
                    ProductId = frm.GetProductId();
                    ProductName = frm.GetProductName();
                    UnitSaleName = frm.GetUnitSaleName();
                    UnitPackname = frm.GetUnitPackName();

                    int count = ProductId.Count;
                    HeadGrid();

                    for (int i = 0; i < count; i++)
                    {
                        ProductList.Add(new ProductList { ProductId = ProductId[i], ProductName = ProductName[i],
                        UnitPackname = UnitPackname[i], UnitSaleName = UnitSaleName[i] });
                        //ShowDialogAddProductDetail(ProductId[i], ProductName[i], "", UnitPackname[i], "", UnitSaleName[i], "", "กก.");
                    }
                    var listPro = ProductList.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName }).Distinct().ToList();

                    if (ProductListOld == null)
                    {
                        foreach (var list in listPro)
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", "กก.");
                            ProductListOld.Add(new ProductList{ProductId = list.ProductId,ProductName = list.ProductName,UnitPackname = list.UnitPackname,
                                UnitSaleName = list.UnitSaleName});
                        }
                    }
                    else
                    {
                        foreach (var list in listPro.Except(ProductListOld.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName }).Distinct().ToList()))
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", "กก.");
                            ProductListOld.Add(new ProductList{ProductId = list.ProductId,ProductName = list.ProductName,UnitPackname = list.UnitPackname,
                                UnitSaleName = list.UnitSaleName});
                        }
                    }
                }
                ProductListOld.Clear();
            }
        }
Example #3
0
        /*เลือกรายการสินค้าที่อยู่ในใบสั่งซื้อ*/
        private void TxtProductName_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (TxtSuplier.Text=="")
                {
                    MessageBox.Show("กรุณาเลือกผู้ขาย");
                    return;
                }
                if (Class.Function.GetTextId(TxtSuplier.Text) == null) {
                    MessageBox.Show("กรุณาเลือกผู้ขาย");
                    return;
                }

                Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList(TxtProductName.Text.Trim());
                frm.ShowDialog();
                if (frm.DialogResult == DialogResult.OK)
                {
                    List<string> ProductId = frm.GetProductId();
                    List<string> ProductName = frm.GetProductName();
                    List<string> UnitSaleName = frm.GetUnitSaleName();

                    //TxtProductId.Text = ProductId;
                    //TxtProductName.Text = ProductName;
                    /*
                    if (IsHaveProductInDgvPODetail(ProductId))
                    {
                        MessageBox.Show("ไม่อนุญาติเพิ่มสินค้าซ้ำได้ !!!");
                        TxtProductName.Focus();
                        TxtProductName.SelectAll();
                        return;
                    }*/
                    int count = ProductId.Count;
                    for (int i = 0; i < count;i++ )
                    {
                        String sql = "select top 1 isnull(pd.priceperunit,0) as priceperunit,isnull(pd.distext,'0') as distext,isnull(pd.disperunit,0) as disperunit from purchaseorder po " +
                        "inner join purchaseorderdetail pd " +
                        "on po.purchaseorderid = pd.purchaseorderid " +
                        "where pd.productid = '" + ProductId[i] + "' and po.supplierid = " + Class.Function.GetTextId(TxtSuplier.Text) + " " +
                        "order by po.purchaseorderdate desc";
                        DataTable dt = Class.DBConnString.clsDB.QueryDataTable(sql);
                        if (dt.Rows.Count > 0)
                        {
                            ShowDialogAddProductDetail(ProductId[i], ProductName[i], UnitSaleName[i], String.Format("{0:0.0000}", dt.Rows[0][0]), String.Format("{0:0.00}", dt.Rows[0][1]), String.Format("{0:0.00}", dt.Rows[0][2]));
                        }
                        else {
                            ShowDialogAddProductDetail(ProductId[i], ProductName[i], UnitSaleName[i], "0.0000", "0.0000","0.0000");
                        }
                        setDgvRead(i);
                    }
                    DgvPODetail.ClearSelection();
                    DgvPODetail.Select();
                    DgvPODetail.Rows[0].Cells[2].Selected = true;
                    DgvPODetail.BeginEdit(true);
                }
            }
        }
Example #4
0
        private void txtProduct_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList(txtProduct.Text.Trim());//เรียก Dialog เลือกสินค้า
                frm.ShowDialog();
                List<string> ProductId = new List<string>();//เก็บรหัสสินค้า
                List<string> ProductName = new List<string>();//เก็บชื่อสินค้า
                List<string> UnitSaleName = new List<string>();//เก็บหน่วยขาย
                List<string> UnitPackname = new List<string>();//เก็บหน่วยแพ็ค
                List<string> CostPrice = new List<string>();//เก็บต้นทุนของสินค้า

                if (frm.DialogResult == DialogResult.OK)
                {
                    ProductId = frm.GetProductId();//เก็บรหัสสินค้าลงใน list
                    ProductName = frm.GetProductName();//เก็บชื่อสินค้าลงใน list
                    UnitSaleName = frm.GetUnitSaleName();//เก็บหน่วยขายลงใน list
                    UnitPackname = frm.GetUnitPackName();//เก็บหน่วยแพ็คลงใน list

                    foreach (String n in ProductId)
                    {
                        String sql = "select top 1 case when d.receivedetailPriceUnit = null then 0 when d.receivedetailPriceUnit = '' " +
                        "then 0 else d.receivedetailPriceUnit end as receivedetailPriceUnit from receive_detail d " +
                        "inner join receive_head h on d.receiveheadid = h.receiveheadid " +
                        "where d.productid = '" + n + "' order by h.receiveheaddate desc";
                        CostPrice.Add((Class.DBConnString.clsDB.QueryExecuteScalarNonAlert(sql) == null) ? "0" : Class.DBConnString.clsDB.QueryExecuteScalarNonAlert(sql));
                    }

                    int count = ProductId.Count;
                    AddCol();

                    for (int i = 0; i < count; i++)
                    {
                        ProductList.Add(new ProductListRp /*เก็บรายการสินค้าลงตัวแปรประเภท list*/
                        {
                            ProductId = ProductId[i],//เก็บรหัสสินค้า
                            ProductName = ProductName[i],//เก็บชื่อสินค้า
                            UnitPackname = UnitPackname[i],//เก็บหน่วยแพ็ค
                            UnitSaleName = UnitSaleName[i],//เก็บหน่วยขาย
                            CostPrice = CostPrice[i]//เก็บต้นทุนสินค้า
                        });
                        //ShowDialogAddProductDetail(ProductId[i], ProductName[i], "", UnitPackname[i], "", UnitSaleName[i], "", "กก.");
                    }
                    var listPro = ProductList.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName, i.CostPrice }).Distinct().ToList();

                    if (ProductListOld == null)
                    {
                        foreach (var list in listPro)
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", list.CostPrice);
                            ProductListOld.Add(new ProductListRp /*เก็บรายการสินค้าลงตัวแปรประเภท list กรณีที่ไม่มีรายการสินค้าใน ProductlistOld*/
                            {
                                ProductId = list.ProductId,//เก็บรหัสสินค้า
                                ProductName = list.ProductName,//เก็บชื่อสินค้า
                                UnitPackname = list.UnitPackname,//เก็บหน่วยแพ็ค
                                UnitSaleName = list.UnitSaleName,//เก็บหน่วยขาย
                                CostPrice = list.CostPrice//เก็บต้นทุนสินค้า
                            });
                        }
                    }
                    else
                    {
                        foreach (var list in listPro.Except(ProductListOld.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName, i.CostPrice }).Distinct().ToList()))
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", list.CostPrice);
                            ProductListOld.Add(new ProductListRp /*เก็บรายการสินค้าลงตัวแปรประเภท list กรณีที่มีรายการสินค้าใน ProductlistOld*/
                            {
                                ProductId = list.ProductId,//เก็บรหัสสินค้า
                                ProductName = list.ProductName,//เก็บชื่อสินค้า
                                UnitPackname = list.UnitPackname,//เก็บหน่วยแพ็ค
                                UnitSaleName = list.UnitSaleName,//เก็บหน่วยขาย
                                CostPrice = list.CostPrice//เก็บต้นทุนสินค้า
                            });
                        }
                    }

                }
            }
        }
Example #5
0
 private void textBox4_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Enter)
     {
         Dialog.frmDialogSearchProductList d = new Dialog.frmDialogSearchProductList(textBox3.Text);
         d.ShowDialog();
         if (d.DialogResult == DialogResult.OK)
         {
             headgrid(dataGridView2);
             for (int i = 0; i < d.GetProductId().Count; i++)
             {
                 dataGridView2.Rows.Add(new string[] { d.GetProductId()[i], d.GetProductName()[i], Class.Function.stockqty(d.GetProductId()[i], "qtyp"), d.GetUnitPackName()[i], Class.Function.stockqty(d.GetProductId()[i], "qty"), d.GetUnitSaleName()[i], Class.Function.CostTopReturn(d.GetProductId()[i]).ToString() });
             }
         }
     }
 }
Example #6
0
        /*ค้นหาสินค้าตามใบสั่งซื้อเก็บใน list และ แสดงใน datagridview*/
        private void SearchPobyProduct(TextBox name)
        {
            Dialog.frmDialogSearchPoFromSupplier frm;
            if (txtRec.Enabled == true)
            {
                frm = new Dialog.frmDialogSearchPoFromSupplier(name.Text.Trim(), Class.Function.GetTextId(txtSupplier.Text), GetStrPoId(), GetStrSum(), 1, txtRec.Text);
            }
            else
            {
                frm = new Dialog.frmDialogSearchPoFromSupplier(name.Text.Trim(), Class.Function.GetTextId(txtSupplier.Text), GetStrPoId(), GetStrSum(), 0, "");
            }
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                dgvReceive.ColumnCount = 24;
                FormatdgvReceiveAdding();
                foreach (String id in frm.PoDetailId())
                {
                    String sql = "";
                    if (txtRec.Enabled == true)
                    {
                        sql += "SELECT pod.PurchaseOrderDetailId,pod.ProductId, CASE when pod.ProductId = '0000000000-00' then pod.ProductNameWait " +
                        "ELSE p.ProductName END AS ProductName , " +
                        "convert(varchar,cast(CASE when ISNULL((SELECT sum(ReceiveDetailQuantity) FROM Receive_Detail Where PurchaseOrderDetailId = " + id + " And ReceiveHeadId = " + txtRec.Text + "),0) != 0 " +
                        "THEN pod.Quantity -((select isnull(sum(ReceiveDetailQuantity),0) FROM Receive_Detail " +
                        "Where PurchaseOrderDetailId = " + id + ") - (SELECT isnull(sum(ReceiveDetailQuantity),0) FROM Receive_Detail " +
                        "Where PurchaseOrderDetailId = " + id + " And ReceiveHeadId = " + txtRec.Text + ")) " +
                        "ELSE " +
                        "pod.Quantity -((select isnull(sum(ReceiveDetailQuantity),0) FROM Receive_Detail Where PurchaseOrderDetailId = " + id + ") - 0) END as money),1) as Quantity , " +
                        "'' AS Qpack,up.UnitPackName,'' AS Qsale,us.UnitSaleName,'' as Weight,'กก.' as UnitWeight,pod.PricePerUnit,pod.priceQuantity,pod.DisText,isnull(pod.DisPerUnit,0) as DisPerUnit, " +
                        "pod.Dis,(pod.priceQuantity - pod.Dis) as sumPriceDis,'' as TotalperUnit,'' AS Total,po.PurchaseOrderId,'' as w,'' as t,po.branchid,b.branchname,'' as shipperunit " +
                        "from PurchaseOrderDetail pod INNER JOIN PRODUCT p " +
                        "ON pod.ProductId = p.ProductId INNER JOIN UNITPACK up " +
                        "ON p.UnitPackId = up.UnitPackId INNER JOIN UNITSALE us " +
                        "ON p.UnitSaleId = us.UnitSaleId INNER JOIN PurchaseOrder po " +
                        "ON po.PurchaseOrderId = pod.PurchaseOrderId INNER JOIN Branch b " +
                        "ON po.branchid = b.branchid " +
                        "where pod.PurchaseOrderDetailId = " + id;
                    }
                    else
                    {
                        sql += "SELECT pod.PurchaseOrderDetailId,pod.ProductId, CASE when pod.ProductId = '0000000000-00' then pod.ProductNameWait " +
                        "ELSE p.ProductName END AS ProductName , convert(varchar,cast((pod.Quantity - pod.QuantityRecieve) as money),1) as Quantity ," +
                        "'' AS Qpack,up.UnitPackName,'' AS Qsale,us.UnitSaleName,'' as Weight,'กก.' as UnitWeight,pod.PricePerUnit,pod.priceQuantity,pod.DisText,isnull(pod.DisPerUnit,0) as DisPerUnit, " +
                        "pod.Dis,(pod.priceQuantity - pod.Dis) as sumPriceDis,'' as TotalperUnit,'' AS Total,po.PurchaseOrderId,'' as w,'' as t,po.branchid,b.branchname,'' as shipperunit  " +
                        "from PurchaseOrderDetail pod INNER JOIN PRODUCT p " +
                        "ON pod.ProductId = p.ProductId INNER JOIN UNITPACK up " +
                        "ON p.UnitPackId = up.UnitPackId INNER JOIN UNITSALE us " +
                        "ON p.UnitSaleId = us.UnitSaleId INNER JOIN PurchaseOrder po " +
                        "ON po.PurchaseOrderId = pod.PurchaseOrderId INNER JOIN Branch b " +
                        "ON po.branchid = b.branchid " +
                        "where pod.PurchaseOrderDetailId = " + id;
                    }
                    DataTable dtNew = Class.DBConnString.clsDB.QueryDataTable(sql);
                    foreach (DataRow row in dtNew.Rows)
                    {
                        if (row[1].ToString() == "0000000000-00")
                        {
                            Dialog.frmDialogSearchProductList frmProduct = new Dialog.frmDialogSearchProductList(txtProductName.Text.Trim());
                            frmProduct.ShowDialog();
                            if (frmProduct.DialogResult == DialogResult.OK)
                            {
                                List<string> ProductId = frmProduct.GetProductId();
                                List<string> ProductName = frmProduct.GetProductName();
                                List<string> UnitSaleName = frmProduct.GetUnitSaleName();
                                List<string> UnitPackName = frmProduct.GetUnitSaleName();

                                int count = ProductId.Count;
                                for (int i = 0; i < count; i++)
                                {
                                    if (i != 0)
                                    {
                                        dgvReceive.Rows.Add(row.ItemArray);
                                    }
                                    row[1] = ProductId[i];
                                    row[2] = ProductName[i];
                                    row[5] = UnitPackName[i];
                                    row[7] = UnitSaleName[i];
                                }
                            }
                        }
                        dgvReceive.Rows.Add(row.ItemArray);

                        foreach (DataGridViewRow r in dgvReceive.Rows)
                        {
                            if (r.Index % 2 == 0)
                            {
                                r.DefaultCellStyle.BackColor = Color.WhiteSmoke;
                            }
                            else
                            {
                                r.DefaultCellStyle.BackColor = Color.SkyBlue;
                            }
                        }

                    }
                }

            }
        }
        private void textBox8_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList(textBox8.Text.Trim());//เรียก Dialog เลือกสินค้า
                frm.ShowDialog();
                List<string> ProductId = new List<string>();//เก็บรหัสสินค้า
                List<string> ProductName = new List<string>();//เก็บชื่อสินค้า
                List<string> UnitSaleName = new List<string>();//เก็บหน่วยขาย
                List<string> UnitPackname = new List<string>();//เก็บหน่วยแพ็ค
                List<string> CostPrice = new List<string>();//เก็บต้นทุนของสินค้า

                List<ProductListRp> ProductList = new List<ProductListRp>();

                if (frm.DialogResult == DialogResult.OK)
                {
                    ProductId = frm.GetProductId();//เก็บรหัสสินค้าลงใน list
                    ProductName = frm.GetProductName();//เก็บชื่อสินค้าลงใน list
                    UnitSaleName = frm.GetUnitSaleName();//เก็บหน่วยขายลงใน list
                    UnitPackname = frm.GetUnitPackName();//เก็บหน่วยแพ็คลงใน list

                    foreach (String n in ProductId)
                    {
                        object vv = Class.Function.CostTopReturn(n);
                        CostPrice.Add(vv == null ? "0" : vv.ToString());
                    }

                    int count = ProductId.Count;
                    AddCol();

                    for (int i = 0; i < count; i++)
                    {
                        ProductList.Add(new ProductListRp /*เก็บรายการสินค้าลงตัวแปรประเภท list*/
                        {
                            ProductId = ProductId[i],//เก็บรหัสสินค้า
                            ProductName = ProductName[i],//เก็บชื่อสินค้า
                            UnitPackname = UnitPackname[i],//เก็บหน่วยแพ็ค
                            UnitSaleName = UnitSaleName[i],//เก็บหน่วยขาย
                            CostPrice = CostPrice[i]//เก็บต้นทุนสินค้า
                        });
                        //ShowDialogAddProductDetail(ProductId[i], ProductName[i], "", UnitPackname[i], "", UnitSaleName[i], "", "กก.");
                    }
                    var listPro = ProductList.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName,i.CostPrice }).Distinct().ToList();

                    if (ProductListOld == null)
                    {
                        foreach (var list in listPro)
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", list.CostPrice);
                            ProductListOld.Add(new ProductListRp /*เก็บรายการสินค้าลงตัวแปรประเภท list กรณีที่ไม่มีรายการสินค้าใน ProductlistOld*/
                            {
                                ProductId = list.ProductId,//เก็บรหัสสินค้า
                                ProductName = list.ProductName,//เก็บชื่อสินค้า
                                UnitPackname = list.UnitPackname,//เก็บหน่วยแพ็ค
                                UnitSaleName = list.UnitSaleName,//เก็บหน่วยขาย
                                CostPrice = list.CostPrice//เก็บต้นทุนสินค้า
                            });
                        }
                    }
                    else
                    {
                        foreach (var list in listPro.Except(ProductListOld.Select(i => new { i.ProductId, i.ProductName, i.UnitPackname, i.UnitSaleName, i.CostPrice }).Distinct().ToList()))
                        {
                            ShowDialogAddProductDetail(list.ProductId, list.ProductName, "", list.UnitPackname, "", list.UnitSaleName, "", list.CostPrice);
                            ProductListOld.Add(new ProductListRp /*เก็บรายการสินค้าลงตัวแปรประเภท list กรณีที่มีรายการสินค้าใน ProductlistOld*/
                            {
                                ProductId = list.ProductId,//เก็บรหัสสินค้า
                                ProductName = list.ProductName,//เก็บชื่อสินค้า
                                UnitPackname = list.UnitPackname,//เก็บหน่วยแพ็ค
                                UnitSaleName = list.UnitSaleName,//เก็บหน่วยขาย
                                CostPrice = list.CostPrice//เก็บต้นทุนสินค้า
                            });
                        }
                    }

                }
            }
        }
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            DataTable dt;
            if (e.KeyCode == Keys.Enter)
            {
                String sqlProduct = "SELECT PRODUCT.ProductId, PRODUCT.ProductName, UNITCHILD.UnitChildName, UNITSALE.UnitSaleName, UNITPACK.UnitPackName " +
                    "FROM PRODUCT INNER JOIN UNITCHILD ON PRODUCT.UnitChildId = UNITCHILD.UnitChildId INNER JOIN UNITSALE " +
                    "ON PRODUCT.UnitSaleId = UNITSALE.UnitSaleId LEFT JOIN UNITPACK ON PRODUCT.UnitPackId = UNITPACK.UnitPackId " +
                    "WHERE PRODUCT.ProductId = '" + textBox1.Text + "' ";
                dt = Class.DBConnString.clsDB.QueryDataTable(sqlProduct);//แสดงใบบขาย กรณีขายเชื่อ
                //DataTable dtc = Class.DBConnString.clsDB.QueryDataTable(sql);
                //Int32 Count = Convert.ToInt32(dtc.Rows[0][0].ToString());
                if (dt.Rows.Count > 0)
                {
                    dataGridView1.Rows.Add(dt.Rows[0][0].ToString(), dt.Rows[0][1].ToString(), "", "", dt.Rows[0][3].ToString(), "");
                    textBox1.Text = "";
                }
                else
                {
                    Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList(textBox1.Text.Trim());
                    frm.ShowDialog();
                    if (frm.DialogResult == DialogResult.OK)
                    {
                        List<string> ProductId = frm.GetProductId();
                        List<string> ProductName = frm.GetProductName();
                        List<string> UnitSaleName = frm.GetUnitSaleName();
                        int count = ProductId.Count;
                        for (int i = 0; i < count; i++)
                        {
                            dataGridView1.Rows.Add(ProductId[i], ProductName[i], "", "", UnitSaleName[i], "");
                        }
                    }
                }

                LoadHead();
                AddCol();
            }
        }
Example #9
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Rows.Count < 1) return;
            if ((dataGridView1.CurrentRow.Cells["mquantity"].Value.ToDouble()) <= 0) return;
            mqty = (dataGridView1.CurrentRow.Cells["mquantity"].Value.ToDouble());
            //foreach( DataGridViewRow r in dataGridView2.Rows ){
            //    if (dataGridView1.CurrentRow.Cells["mid"].Value.IsNullAsEmpty() == r.Cells["Mid"].Value.IsNullAsEmpty()) {
            //        return;
            //    }
            //}
            List<string> ProductId = new List<string>();//กำหนดตัวแปรประเภท list เก็บค่า รหัสสินค้า
            List<string> ProductName = new List<string>();//กำหนดตัวแปรประเภท list เก็บค่า ชื่อสินค้า
            List<string> UnitSaleName = new List<string>();//กำหนดตัวแปรประเภท list เก็บค่า หน่วยขาย
            List<string> UnitPackName = new List<string>();//กำหนดตัวแปรประเภท list เก็บค่า หน่วยแพ็ค
            List<string> CostPrice = new List<string>();//กำหนดตัวแปรประเภท list เก็บค่า ต้นทุน
            Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList("",
                "and PRODUCT.ProductId in(select ProductId from productiondraw_detail where NewProductionId = '" +
                dgvDraw.SelectedRows[0].Cells[0].Value.IsNullAsEmpty() + "' and Mid = " +
                dataGridView1.SelectedRows[0].Cells[0].Value.IsNullAsEmpty() + ") ");
            //Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList("",
            //    "and PRODUCT.ProductId in(select ProductId from productiondraw_detail where NewProductionId = '" + dgvDraw.CurrentRow .Cells[0].Value.IsNullAsEmpty() + "' and Mid = " +
            //    dataGridView1.CurrentRow.Cells[0].Value.IsNullAsEmpty() + ") ");
            frm.ShowDialog();//เรียก Dailog เลือกสินค้า
            if (frm.DialogResult == DialogResult.OK)
            {
                ProductId = frm.GetProductId();//เก็บรหัสสินค้า
                ProductName = frm.GetProductName();//เก็บชื่อสินค้า
                UnitPackName = frm.GetUnitPackName();//เก็บหน่วยแพ็ค
                UnitSaleName = frm.GetUnitSaleName();//เก็บหน่วยขาย

                foreach (String n in ProductId)
                {
                    CostPrice.Add(Class.Function.CostTopReturn(n).IsNullAsEmpty());
                }

                Dialog.DialogSelectMtr mtr = new Dialog.DialogSelectMtr();
                mtr.ShowDialog();
                if (mtr.DialogResult == DialogResult.OK)
                {
                    int chkType;
                    if (mtr.checkBox1.Checked)
                    {
                        chkType = 1;
                        AddColWellHead(dataGridView2, chkType);
                    }
                    if (mtr.checkBox2.Checked)
                    {
                        chkType = 2;
                        AddColWellHead(dataGridView4, chkType);
                    }
                    if (mtr.checkBox3.Checked)
                    {
                        chkType = 3;
                        AddColWellHead(dgvMetLost, chkType);
                    }

                    //dataGridView5.ColumnCount = 1;
                    //dataGridView5.Columns[0].Name = "Mid";
                    //dataGridView5.Columns[0].HeaderText = "รหัสใบเบิก";

                    for (int x = 0; x < ProductId.Count; x++)
                    {
                        if (mtr.checkBox1.Checked)
                        {
                            dataGridView2.Rows.Add(dataGridView1.CurrentRow.Cells["Mid"].Value.IsNullAsEmpty(), ProductId[x], ProductName[x],
                                "", UnitPackName[x], "", UnitSaleName[x], "", CostPrice[x], "", "", "", "", dgvDraw.CurrentRow.Cells[0].Value.IsNullAsEmpty());
                            listwell.Add(new listsetIn
                            {
                                id = dgvDraw.CurrentRow.Cells[0].Value.IsNullAsEmpty(),
                                mid = dataGridView1.CurrentRow.Cells["Mid"].Value.IsNullAsEmpty(),
                                ProductID = ProductId[x],
                                ProductName = ProductName[x],
                                QuantityPack = "",
                                UnitPack = UnitPackName[x],
                                Quantity = "",
                                UnitSale = UnitSaleName[x],
                                Weight = "",
                                CostPrice = CostPrice[x],
                                Total = "",
                                Detail = "",
                                Type = "",
                                Note = "",
                            });
                            AddColWell();
                        }
                        if (mtr.checkBox2.Checked)
                        {
                            dataGridView4.Rows.Add(dataGridView1.CurrentRow.Cells["Mid"].Value.IsNullAsEmpty(), ProductId[x], ProductName[x],
                                "", UnitPackName[x], "", UnitSaleName[x], "", CostPrice[x], "", "", "", "", "", "", dgvDraw.CurrentRow.Cells[0].Value.IsNullAsEmpty());
                            listfail.Add(new listsetIn
                            {
                                id = dgvDraw.CurrentRow.Cells[0].Value.IsNullAsEmpty(),
                                mid = dataGridView1.CurrentRow.Cells["Mid"].Value.IsNullAsEmpty(),
                                ProductID = ProductId[x],
                                ProductName = ProductName[x],
                                QuantityPack = "",
                                UnitPack = UnitPackName[x],
                                Quantity = "",
                                UnitSale = UnitSaleName[x],
                                Weight = "",
                                CostPrice = CostPrice[x],
                                Total = "",
                                Detail = "",
                                Type = "",
                                Note = "",
                                NetFName="",
                                NetFId=""
                            });
                            AddColFail();
                        }
                        if (mtr.checkBox3.Checked)
                        {
                            dgvMetLost.Rows.Add(dataGridView1.CurrentRow.Cells["Mid"].Value.IsNullAsEmpty(), ProductId[x], ProductName[x],
                                "", UnitPackName[x], "", UnitSaleName[x], "", CostPrice[x], "", "", "", "", "", "", dgvDraw.CurrentRow.Cells[0].Value.IsNullAsEmpty());
                            listfail.Add(new listsetIn
                            {
                                id = dgvDraw.CurrentRow.Cells[0].Value.IsNullAsEmpty(),
                                mid = dataGridView1.CurrentRow.Cells["Mid"].Value.IsNullAsEmpty(),
                                ProductID = ProductId[x],
                                ProductName = ProductName[x],
                                QuantityPack = "",
                                UnitPack = UnitPackName[x],
                                Quantity = "",
                                UnitSale = UnitSaleName[x],
                                Weight = "",
                                CostPrice = CostPrice[x],
                                Total = "",
                                Detail = "",
                                Type = "",
                                Note = "",
                                NetFName = "",
                                NetFId = ""
                            });
                            AddColLost();
                        }
                        //dataGridView5.Rows[dataGridView5.Rows.Count-1].Cells[0] = dc;
                    }
                }
            }
        }
Example #10
0
        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dataGridView1.Rows.Count < 1) return;
            if (Convert.ToDouble(dataGridView1.CurrentRow.Cells["mquantity"].Value.ToString()) <= 0) return;
            List<string> ProductId = new List<string>();/*กำหนดตัวแปรประเภท list รหัสสินค้า*/
            List<string> ProductName = new List<string>();/*กำหนดตัวแปรประเภท list ชื่อสินค้า*/
            List<string> UnitSaleName = new List<string>();/*กำหนดตัวแปรประเภท list หน่วยขาย*/
            List<string> UnitPackName = new List<string>();/*กำหนดตัวแปรประเภท list หน่วยแพ็ค*/
            List<string> CostPrice = new List<string>();/*กำหนดตัวแปรประเภท list ต้นทุน*/
            Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList();//Dialog เลือกสินค้า
            frm.ShowDialog();
            if (frm.DialogResult == DialogResult.OK)
            {
                ProductId = frm.GetProductId();//เก็บรหัสสินค้า
                ProductName = frm.GetProductName();//เก็บชื่อสินค้า
                UnitPackName = frm.GetUnitPackName();//เก็บหน่วยแพ็ค
                UnitSaleName = frm.GetUnitSaleName();//เก็บหน่วยขาย
                foreach (String n in ProductId)//ดึงสินค้าจาก Dailog ที่เลือก
                {

                    object vv = Class.Function.CostTopReturn(n);
                    CostPrice.Add((vv == null) ? "0" : vv.ToString());
                }
                AddCol();

                for (int x = 0; x < ProductId.Count; x++)//เพิ่มรายการสินค้าใน Datagridview ของข้อมูลเบิกวัตถุดิบ
                {
                    dataGridView2.Rows.Add(dataGridView1.CurrentRow.Cells["Mid"].Value.ToString(), ProductId[x], ProductName[x],
                        "", UnitPackName[x], "", UnitSaleName[x], "", CostPrice[x], "", "", "", "", ++Rnd);

                }
            }
        }
 private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     if (dataGridView1.Rows.Count < 1) return;
     if (Convert.ToDouble(dataGridView1.CurrentRow.Cells["mquantity"].Value.ToString()) <= 0) return;
     List<string> ProductId = new List<string>();//กำหนดตัวแปรประเภท list เก็บรหัสสินค้า
     List<string> ProductName = new List<string>();//กำหนดตัวแปรประเภท list เก็บชื่อสินค้า
     List<string> UnitSaleName = new List<string>();//กำหนดตัวแปรประเภท list เก็บหน่วยขาย
     List<string> UnitPackName = new List<string>();//กำหนดตัวแปรประเภท list เก็บหน่วยแพ็ค
     List<string> CostPrice = new List<string>();//กำหนดตัวแปรประเภท list เก็บต้นทุน
     Dialog.frmDialogSearchProductList frm = new Dialog.frmDialogSearchProductList();//เรียก dailog เลือกสินค้า
     frm.ShowDialog();
     if (frm.DialogResult == DialogResult.OK)
     {
         ProductId = frm.GetProductId();//รับค่ารหัสสินค้าจาก Dialog ที่เลือก
         ProductName = frm.GetProductName();//รับค่าชื่อสินค้าจาก Dialog ที่เลือก
         UnitPackName = frm.GetUnitPackName();//รับค่าหน่วยขายจาก Dialog ที่เลือก
         UnitSaleName = frm.GetUnitSaleName();//รับค่าหน่วยแพ็คจาก Dialog ที่เลือก
         foreach (String n in ProductId)
         {
             object vv = Class.Function.CostTopReturn(n);
             CostPrice.Add(vv == null ? "0" : vv.ToString());
         }
         AddCol();
         for (int x = 0; x < ProductId.Count; x++)
         {
             dataGridView2.Rows.Add(dataGridView1.CurrentRow.Cells["Mid"].Value.ToString(), ProductId[x], ProductName[x],
                 "", UnitPackName[x], "", UnitSaleName[x], "", CostPrice[x], "", "", "", "");//เก็บข้อมูลรายการสินค้าลงใน Datagridview ของวัตถุดิบที่ต้องใช้
         }
     }
 }