Exemple #1
0
 /*ดึงรายการสินค้าจาก dialog แสดงรายการสินค้า*/
 private void ProductAction(KeyEventArgs e)
 {
     if (txtProduct.Text != "" && e == null)
     {
         //ProductPut();
     }
     else if (e.KeyData == Keys.Enter && txtProduct.Text != "")
     {
         Dialog.frmDialogSearchProduct Product = new Dialog.frmDialogSearchProduct(txtProduct.Text);
         Product.MultiCase = true;
         Product.ShowDialog();
         if (Product.DialogResult == System.Windows.Forms.DialogResult.OK)
         {
             foreach (DataGridViewRow r in Product.DgvOutputReturn.Rows)
             {
                 //txtProduct.Text = "[" + Product.GetProductId() + "] " + Product.GetProductName();
                 txtProduct.Text = "[" + r.Cells[0].Value.ToString() + "] " + r.Cells[1].Value.ToString();
                 ProductPut();
             }
         }
         txtProduct.Text = "";
     }
 }
        private void BtnNew_Click(object sender, EventArgs e)
        {
            string ProductFind = TxtProductFind.Text.Trim();
            string sql = "SELECT PRODUCT.ProductId, PRODUCT.ProductName, UNITPACK.UnitPackName, UNITSALE.UnitSaleName " +
                         "FROM PRODUCT INNER JOIN " +
                         "UNITPACK ON PRODUCT.UnitPackId = UNITPACK.UnitPackId INNER JOIN " +
                         "UNITSALE ON PRODUCT.UnitSaleId = UNITSALE.UnitSaleId " +
                         "WHERE PRODUCT.ProductId = '" + ProductFind + "' ";
            if (ProductFind != "")
            {
                sql += "OR ProductIdExternal = '" + ProductFind + "' OR ProductIdExternal2 = '" + ProductFind + "'";
            }
            DataSet ds = sqlquery(sql);
            DataTable dt = ds.Tables[0];
            if (dt.Rows.Count != 0)
            {
                string ProductId = dt.Rows[0][0].ToString();
                string ProductName = dt.Rows[0][1].ToString();
                string UnitPackName = dt.Rows[0][2].ToString();
                string UnitSaleName = dt.Rows[0][3].ToString();

                DialogNewAddProduct(ProductId, ProductName, UnitPackName, UnitSaleName);
            }
            else
            {
                Dialog.frmDialogSearchProduct d = new Dialog.frmDialogSearchProduct(ProductFind);
                d.ShowDialog();
                if (d.DialogResult == DialogResult.OK)
                {
                    string ProductId = d.DgvOutputReturn.Rows[0].Cells[0].Value.ToString();
                    string ProductName = d.DgvOutputReturn.Rows[0].Cells[1].Value.ToString();
                    string UnitPackName = d.DgvOutputReturn.Rows[0].Cells[4].Value.ToString();
                    string UnitSaleName = d.DgvOutputReturn.Rows[0].Cells[3].Value.ToString();

                    TxtProductFind.Text = ProductName;
                    DialogNewAddProduct(ProductId, ProductName, UnitPackName, UnitSaleName);
                }
            }
        }
 //เหตการณเมื่อป้อนข้อมูลลง TbxProductName ให้ตรวจว่ามีการกดแป้น Enter ไหม เพื่อเปิดไดอะลอกฟอร์มเพิ่มสิ้ค้าใหม่
 private void TbxProductName_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Return)
     {
         Dialog.frmDialogSearchProduct d = new Dialog.frmDialogSearchProduct(TbxProductName.Text.Trim());
         d.ShowDialog();
         if (d.DialogResult == DialogResult.OK)
         {
             String ProductId = d.DgvOutputReturn.Rows[0].Cells[0].Value.ToString();
             String ProductName = d.DgvOutputReturn.Rows[0].Cells[1].Value.ToString();
             TbxProductId.Text = ProductId;
             TbxProductName.Text = ProductName;
             BtnAdd_Click(sender, e);
         }
     }
 }