private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.KeyCode == Keys.Return)
                {
                    Param.BarcodeNo = txtBarcode.Text;

                    DataTable dt = Util.DBQuery(string.Format(@"SELECT b.OrderNo, p.ID, p.CoverImage, IFNULL(b.ReceivedDate, '') ReceivedDate
                    FROM Barcode b LEFT JOIN Product p ON b.product = p.id WHERE b.Barcode = '{0}'", txtBarcode.Text));

                    if (dt.Rows.Count == 0)
                    {
                        dt = Util.DBQuery(string.Format(@"SELECT Barcode FROM Product WHERE Barcode LIKE '%{0}%'", txtBarcode.Text));
                        Console.WriteLine(txtBarcode.Text + " " + Param.BarcodeNo + " " + dt.Rows.Count.ToString());
                        if (dt.Rows.Count == 0)
                        {
                            lblStatus.Text = "ไม่พบข้อมูลสินค้าชิ้นนี้ในระบบ";
                            lblStatus.ForeColor = Color.Red;
                        }
                        else
                        {
                            Param.status = "Cancel";
                            FmSelectProduct frm = new FmSelectProduct();
                            var result = frm.ShowDialog(this);
                            if (result == System.Windows.Forms.DialogResult.OK)
                            {
                                Param.UcSell.LoadData();
                                txtBarcode.Text = "";
                            }

                        }
                    }
                    else
                    {
                        lblStatus.Visible = false;
                        dt = Util.DBQuery(string.Format(@"SELECT p.Name, p.ID, IFNULL(p.Price, 0) Price, IFNULL(p.Price1, 0) Price1, IFNULL(p.Price2, 0) Price2, ReceivedDate, ReceivedBy, SellDate, SellBy
                        FROM Barcode b LEFT JOIN Product p ON b.Product = p.ID
                        WHERE b.Barcode = '{0}' AND p.Shop = '{1}' AND SellBy <> '' ", txtBarcode.Text, Param.ShopId));

                        if (dt.Rows.Count == 1)
                        {
                            Util.DBExecute(string.Format(@"UPDATE Barcode SET SellPrice = '0',SellBy = '', Sync = 1 WHERE SellBy = '{0}' AND Barcode = '{1}'", Param.CpuId, txtBarcode.Text));
                            Param.UcSell.LoadData();
                            txtBarcode.Text = "";
                        }
                        else
                        {
                            txtBarcode.Text = "";
                            lblStatus.Visible = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#2
0
        private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                //if (txtBarcode.Text != "")
                //{
                    lblStatus.Visible = false;
                    Param.BarcodeNo = txtBarcode.Text;
                    if (e.KeyCode == Keys.Return)
                    {
                        barcode = txtBarcode.Text;

                        DataTable dt = Util.DBQuery(string.Format(@"SELECT p.Name, p.ID, IFNULL(p.Price, 0) Price, IFNULL(p.Price1, 0) Price1, IFNULL(p.Price2, 0) Price2, ReceivedDate, ReceivedBy, SellDate, SellBy, Comment
                    FROM Barcode b
                        LEFT JOIN Product p
                        ON b.Product = p.ID
                    WHERE b.Barcode = '{0}' AND p.Shop = '{1}'", txtBarcode.Text, Param.ShopId));
                        lblStatus.Visible = true;

                        //string[] claim = dt.Rows[0]["Comment"].ToString().Split('(');
                        //string[] change = dt.Rows[0]["Comment"].ToString().Split('[');

                        if (dt.Rows.Count == 0)
                        {
                            dt = Util.DBQuery(string.Format(@"SELECT Barcode FROM Product WHERE Barcode LIKE '%{0}%'", txtBarcode.Text));
                            Console.WriteLine(txtBarcode.Text + "" + Param.BarcodeNo + "" + dt.Rows.Count.ToString());
                            if (dt.Rows.Count == 0)
                            {
                                lblStatus.Text = "ไม่พบข้อมูลสินค้าชิ้นนี้ในระบบ";
                                lblStatus.ForeColor = Color.Red;
                            }
                            else
                            {
                                Param.status = "Sell";
                                FmSelectProduct frm = new FmSelectProduct();
                                var result = frm.ShowDialog(this);
                                if (result == System.Windows.Forms.DialogResult.OK)
                                {
                                    LoadData();
                                }

                            }
                        }
                        else if (dt.Rows[0]["ReceivedDate"].ToString() == "")
                        {
                            lblStatus.Text = "สินค้าชิ้นนี้ยังไม่ได้รับเข้าระบบ";
                            lblStatus.ForeColor = Color.Red;
                            var confirm = MessageBox.Show("สินค้าชิ้นนี้ยังไม่ได้รับเข้าระบบ\nคุณต้องการไปที่หน้าจอรับสินค้าเข้าระบบหรือไม่ ?", "แจ้งเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                            if (confirm)
                            {
                                Util.ShowScreen(Param.Screen.ReceiveProduct);
                                Param.SelectedScreen = (int)Param.Screen.ReceiveProduct;
                            }
                        }
                        else if (dt.Rows[0]["ReceivedBy"].ToString() == "")
                        {
                            lblStatus.Text = "สินค้าชิ้นนี้ยังไม่ได้กำหนดต้นทุน";
                            lblStatus.ForeColor = Color.Red;
                            var confirm = MessageBox.Show("สินค้าชิ้นนี้ยังไม่ได้กำหนดต้นทุน\nคุณต้องการไปที่หน้าจอรับสินค้าเข้าระบบหรือไม่ ?", "แจ้งเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                            if (confirm)
                            {
                                Util.ShowScreen(Param.Screen.ReceiveProduct);
                                Param.SelectedScreen = (int)Param.Screen.ReceiveProduct;
                            }
                        }
                        //else if (claim[0].ToString() == "เคลมสินค้า" || change[0].ToString() == "เปลี่ยนสินค้า")
                        //{
                        //    lblStatus.Text = "สินค้าชิ้นนี้ได้ทำการเคลมแล้ว";
                        //    lblStatus.ForeColor = Color.Red;
                        //}
                        else if (dt.Rows[0]["SellDate"].ToString() != "")
                        {
                            lblStatus.Text = "สินค้าชิ้นนี้ได้ขายออกจากระบบไปแล้ว";
                            lblStatus.ForeColor = Color.Red;
                        }
                        else if (dt.Rows[0]["SellBy"].ToString() == Param.CpuId)
                        {
                            lblStatus.Text = "มีสินค้าชิ้นนี้ในรายการขายแล้ว";
                            lblStatus.ForeColor = Color.Red;
                        }
                        else if (int.Parse(dt.Rows[0]["Price"].ToString()) == 0 || int.Parse(dt.Rows[0]["Price1"].ToString()) == 0)
                        {
                            lblStatus.Text = "สินค้าชิ้นนี้ยังไม่ได้กำหนดราคาขาย";
                            lblStatus.ForeColor = Color.Red;
                            var confirm = MessageBox.Show("สินค้าชิ้นนี้ยังไม่ได้กำหนดราคาขาย\nคุณต้องการไปที่หน้าจอข้อมูลสินค้าหรือไม่ ?", "แจ้งเตือน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                            if (confirm)
                            {
                                Util.ShowScreen(Param.Screen.Product);
                                Param.SelectedScreen = (int)Param.Screen.Product;
                            }
                        }
                        else
                        {
                            Util.DBExecute(string.Format(@"UPDATE Barcode SET SellPrice = (SELECT p.Price{3} FROM Product p
                            WHERE Barcode.product = p.ID AND p.shop = '{2}'), SellBy = '{0}', Sync = 1 WHERE Barcode = '{1}'", Param.CpuId, txtBarcode.Text, Param.ShopId, Param.SelectCustomerSellPrice == 0 ? "" : "" + Param.SelectCustomerSellPrice));
                            LoadData();
                            txtBarcode.Focus();
                            lblStatus.Text = "เพิ่มสินค้าในรายการขายแล้ว";
                            lblStatus.ForeColor = Color.Green;
                        }

                        txtBarcode.Text = "";
                    }
                    else if (e.KeyCode == Keys.F1)
                    {
                        btnConfirm_Click(sender, (e));
                    }
                    else if (e.KeyCode == Keys.F11)
                    {
                        btnCancelProduct_Click(sender, (e));
                    }
                    else if (e.KeyCode == Keys.F12)
                    {
                        btnCancel_Click(sender, (e));
                    }
                //}
                //else
                //{
                //    MessageBox.Show("กรุณากรอกข้อมูลบาร์โค้ด", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //}
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                //if (txtBarcode.Text != "")
                //{
                    if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return)
                    {
                        Param.BarcodeNo = txtBarcode.Text;

                        DataTable dt = Util.DBQuery(string.Format(@"SELECT b.OrderNo, p.ID, p.CoverImage, IFNULL(b.ReceivedDate, '') ReceivedDate
                    FROM Barcode b LEFT JOIN Product p ON b.product = p.id WHERE b.Barcode = '{0}'", txtBarcode.Text));

                        lblStatus.Visible = true;

                        if (dt.Rows.Count == 0)
                        {
                            dt = Util.DBQuery(string.Format(@"SELECT Barcode FROM Product WHERE Barcode LIKE '%{0}%'", txtBarcode.Text));
                            Console.WriteLine(txtBarcode.Text + "" + Param.BarcodeNo + "" + dt.Rows.Count.ToString());
                            if (dt.Rows.Count == 0)
                            {
                                lblStatus.ForeColor = Color.Red;
                                lblStatus.Text = "ไม่พบข้อมูลสินค้าชิ้นนี้ในระบบ";
                            }
                            else
                            {
                                Param.status = "Received";
                                OrderNo = cbbOrderNoSerial.SelectedItem.ToString();
                                FmSelectProduct frm = new FmSelectProduct();
                                var result = frm.ShowDialog(this);
                                if (result == System.Windows.Forms.DialogResult.OK)
                                {
                                    SearchDataNoSerial();
                                }

                                //lblStatus.ForeColor = Color.Pink;
                                //lblStatus.Text = "พบข้อมูลสินค้าชิ้นนี้ในระบบ";
                            }
                            //_SKU = "0";
                        }
                        else
                        {
                            Param.ProductId = dt.Rows[0]["ID"].ToString();

                            if (cbbOrderNo.SelectedItem.ToString() != dt.Rows[0]["OrderNo"].ToString())
                            {
                                cbbOrderNo.SelectedIndex = cbbOrderNo.FindString(dt.Rows[0]["OrderNo"].ToString());
                            }

                            if (dt.Rows[0]["ReceivedDate"].ToString() != "")
                            {
                                lblStatus.ForeColor = Color.Red;
                                lblStatus.Text = "เคยรับสินค้าชิ้นนี้เข้าระบบแล้ว";
                                SearchData();
                            }
                            else
                            {
                                Util.DBExecute(string.Format(@"UPDATE Barcode SET ReceivedDate = STRFTIME('%Y-%m-%d %H:%M:%S', 'NOW'), ReceivedBy = '{1}', Sync = 1
                        WHERE Barcode = '{0}'", txtBarcode.Text, Param.UserId));
                                SearchData();

                                lblStatus.ForeColor = Color.Green;
                                lblStatus.Text = "รับสินค้าเข้าระบบเรียบร้อยแล้ว";

                                ptbProduct.Visible = true;
                                ptbProduct.Image = null;

                                var filename = @"Resource/Images/Product/" + Param.ProductId + ".jpg";
                                if (!File.Exists(filename))
                                {
                                    if (dt.Rows[0]["CoverImage"].ToString() != "")
                                    {
                                        DownloadImage(dt.Rows[0]["CoverImage"].ToString(), @"Resource/Images/Product/", Param.ProductId + ".jpg");
                                    }
                                }
                                else
                                {
                                    try { ptbProduct.Image = Image.FromFile(filename); }
                                    catch
                                    {
                                        if (dt.Rows[0]["CoverImage"].ToString() != "")
                                        {
                                            DownloadImage(dt.Rows[0]["CoverImage"].ToString(), @"Resource/Images/Product/", Param.ProductId + ".jpg");
                                        }
                                    }
                                }

                            }

                        }
                        txtBarcode.Text = "";
                        txtBarcode.Focus();
                    }
                //}
                //else
                //{
                //    MessageBox.Show("กรุณากรอกข้อมูลบาร์โค้ด", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                //}
            }
            catch { }
        }
示例#4
0
        private void txtBarcode_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                lblStatus.Visible = false;

                if (e.KeyCode == Keys.Return)
                {
                    Param.BarcodeNo = txtBarcode.Text;

                    DataTable dt = Util.DBQuery(string.Format(@"SELECT b.OrderNo, p.ID, p.CoverImage, IFNULL(b.ReceivedDate, '') ReceivedDate
                    FROM Barcode b LEFT JOIN Product p ON b.product = p.id WHERE b.Barcode = '{0}'", txtBarcode.Text));

                    if (dt.Rows.Count == 0)
                    {
                        dt = Util.DBQuery(string.Format(@"SELECT Barcode FROM Product WHERE Barcode LIKE '%{0}%'", txtBarcode.Text));
                        Console.WriteLine(txtBarcode.Text + "" + Param.BarcodeNo + "" + dt.Rows.Count.ToString());
                        if (dt.Rows.Count == 0)
                        {
                            lblStatus.ForeColor = Color.Red;
                            lblStatus.Text = "ไม่พบข้อมูลสินค้าชิ้นนี้ในระบบ";
                        }
                        else
                        {
                            Param.status = "Return";
                            FmSelectProduct frm = new FmSelectProduct();
                            var result = frm.ShowDialog(this);
                            if (result == System.Windows.Forms.DialogResult.OK)
                            {
                                lblStatus.Visible = false;
                                txtBarcode.Enabled = true;

                                table1.BeginUpdate();
                                tableModel1.Rows.Clear();
                                tableModel1.RowHeight = 22;
                                if (FmSelectProduct.amount != "")
                                {
                                    for (int i = 0; i < 1; i++)
                                    {
                                        string customer = FmReturnSellDetail.customer;
                                        string SellDate = FmReturnSellDetail.sellDate;
                                        int Amount = int.Parse(FmSelectProduct.amount);
                                        string SellP = (int.Parse(FmReturnSellDetail.sellP) * int.Parse(FmSelectProduct.amount)).ToString();
                                        tableModel1.Rows.Add(new Row(
                                            new Cell[] {
                                    new Cell("" + (i+1)),
                                    new Cell(SellDate),
                                    new Cell(customer),
                                    new Cell(Amount),
                                    new Cell(SellP)
                                          }));
                                    }
                                }
                                table1.EndUpdate();

                                var remain = (DateTime.Now - Convert.ToDateTime(FmReturnSellDetail.sellDate)).TotalDays;

                                btnReturn.Visible = remain > 0;

                                int day = Convert.ToInt32(remain);
                                if (day == 0)
                                {
                                    lblWarranty.Text = "สินค้าชิ้นนี้ขายไปแล้วในวันนี้";
                                }
                                else
                                {
                                    lblWarranty.Text = "สินค้าชิ้นนี้" + ((day > 0) ? " ขายไปแล้ว " + day.ToString("#,###") + " วัน" : " ขายไปแล้ว " + (day * -1).ToString("#,###") + " วัน");
                                }
                                lblWarranty.Visible = true;

                            }
                        }

                        //lblStatus.ForeColor = Color.Pink;
                        //lblStatus.Text = "พบข้อมูลสินค้าชิ้นนี้ในระบบ";
                        //_SKU = "0";
                    }
                    else
                    {
                        _TABLE_RETURN = Util.DBQuery(string.Format(@"SELECT p.Name, p.ID product, IFNULL(p.Price, 0) Price, IFNULL(p.Price1, 0) Price1, IFNULL(p.Price2, 0) Price2,
                        b.ReceivedDate, b.ReceivedBy, b.SellDate, b.SellBy,b.Comment , sh.SellNo, c.ID customer, c.firstname , c.lastname, b.SellPrice, p.CoverImage
                        FROM Barcode b
                            LEFT JOIN Product p
                            ON b.Product = p.ID
                             LEFT JOIN SellHeader sh
                            ON b.SellNo = sh.SellNo
                            LEFT JOIN Customer c
                            ON sh.Customer = c.ID
                        WHERE b.Barcode = '{0}' AND (b.SellDate IS NOT NULL OR b.SellDate = '') AND p.shop = '{1}'", txtBarcode.Text, Param.ShopId));
                        lblStatus.Visible = true;

                        if (_TABLE_RETURN.Rows.Count == 0)
                        {
                            lblStatus.Text = "สินค้าชิ้นนี้ยังไม่ได้ทำการขาย";
                            lblStatus.ForeColor = Color.Red;
                            lblStatus.Visible = true;
                            txtBarcode.Enabled = true;
                        }
                        else
                        {
                            lblStatus.Visible = false;
                            txtBarcode.Enabled = true;
                            //txtBarcode.Text = "";

                            table1.BeginUpdate();
                            tableModel1.Rows.Clear();
                            tableModel1.RowHeight = 22;
                            //shopList = new List<string>();
                            //customerList = new List<string>();
                            if (_TABLE_RETURN.Rows[0]["SellNo"].ToString() != "")
                            {
                                for (int i = 0; i < _TABLE_RETURN.Rows.Count; i++)
                                {
                                    string customer = _TABLE_RETURN.Rows[i]["firstname"].ToString() + " " + _TABLE_RETURN.Rows[i]["lastname"].ToString();
                                    string SellDate = Convert.ToDateTime(_TABLE_RETURN.Rows[i]["SellDate"]).ToLocalTime().ToString("dd MMMM yyyy", CultureInfo.CreateSpecificCulture("th-TH"));
                                    string SellPrice = Convert.ToDouble(_TABLE_RETURN.Rows[i]["SellPrice"]).ToString();

                                    tableModel1.Rows.Add(new Row(
                                        new Cell[] {
                                    new Cell("" + (i+1)),
                                    new Cell(SellDate),
                                    new Cell(customer),
                                    new Cell(1),
                                    new Cell(SellPrice)
                                      }));
                                }
                            }
                            table1.EndUpdate();

                            var remain = (DateTime.Now - Convert.ToDateTime(_TABLE_RETURN.Rows[0]["SellDate"])).TotalDays;

                            btnReturn.Visible = remain > 0;

                            int day = Convert.ToInt32(remain);
                            if (day == 0)
                            {
                                lblWarranty.Text = "สินค้าชิ้นนี้ขายไปแล้วในวันนี้";
                            }
                            else
                            {
                                lblWarranty.Text = "สินค้าชิ้นนี้" + ((day > 0) ? " ขายไปแล้ว " + day.ToString("#,###") + " วัน" : " ขายไปแล้ว " + (day * -1).ToString("#,###") + " วัน");
                            }
                            lblWarranty.Visible = true;

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            //if (e.KeyCode == Keys.Return && barcode != txtBarcode.Text.Trim())
            //{
            //    lblStatus.Visible = true;
            //    lblStatus.Text = "กำลังค้นหาข้อมูลค่ะ";
            //    lblStatus.ForeColor = Color.Green;
            //    txtBarcode.Enabled = false;
            //    barcode = txtBarcode.Text.Trim();

            //    table1.BeginUpdate();
            //    tableModel1.Rows.Clear();
            //    table1.EndUpdate();

            //    lblName.Visible = false;
            //    lblWarrantyStatus.Visible = false;
            //    lblWarranty.Visible = false;
            //    ptbProduct.Visible = false;
            //    btnReturn.Visible = false;

            //    bwSearch.RunWorkerAsync();
            //}
        }