Esempio n. 1
0
        protected void btnSave2_ServerClick(object sender, EventArgs e)
        {
            try
            {
                bool           result    = false;
                BLProcessOrder blPrOrder = new BLProcessOrder();
                string         barcode   = "";

                var users = (User)Session["User"];

                var bcStart = txtBarcodeStart.Text;
                var bcEnd   = txtBarcodeEnd.Text;

                var format     = bcStart.Substring(0, 7);
                int stRunning  = Convert.ToInt32(bcStart.Substring(bcStart.Length - 4));
                int endRunning = Convert.ToInt32(bcEnd.Substring(bcStart.Length - 4));

                for (int i = stRunning; i <= endRunning; i++)
                {
                    var running = i.ToString().PadLeft(4, '0');
                    barcode = barcode + format + running + ",";
                }

                barcode = barcode.Substring(0, barcode.Length - 1);

                result = blPrOrder.InsertProcessOrderMatch(txtProcessOrder.Text, barcode, users.UserName, users.DeptName);

                if (result)
                {
                    var spBarcode = barcode.Split(',');

                    DataTable dt = new DataTable();
                    DataRow   dr = null;
                    dt.Columns.Add(new DataColumn("No", typeof(string)));
                    dt.Columns.Add(new DataColumn("Barcode", typeof(string)));
                    dt.Columns.Add(new DataColumn("Delete", typeof(string)));
                    dt.Columns.Add(new DataColumn("Status", typeof(string)));

                    var n = 1;
                    foreach (var bc in spBarcode)
                    {
                        DataSet ds = blPrOrder.GetProcessOrderMatch(bc, txtProcessOrder.Text);

                        if (ds.Tables.Count > 0)
                        {
                            if (ds.Tables[0].Rows.Count > 0)
                            {
                                dr            = dt.NewRow();
                                dr["No"]      = n;
                                dr["Barcode"] = bc;
                                dr["Delete"]  = string.Empty;
                                dr["Status"]  = ds.Tables[0].Rows[0]["STATUS"];
                                dt.Rows.Add(dr);
                                n++;
                            }
                        }
                    }

                    ViewState["gridBarcodeScan"]       = dt;
                    gridBarcodeScan.Columns[3].Visible = true;
                    gridBarcodeScan.Columns[2].Visible = false;

                    gridBarcodeScan.DataSource = dt;
                    gridBarcodeScan.DataBind();

                    gridBarcodeScan.HeaderRow.Cells[0].CssClass = "visiblecol";

                    var countMatch = 0;
                    foreach (GridViewRow item in gridBarcodeScan.Rows)
                    {
                        var status = item.Cells[3].Text;

                        if (status.Equals("Matched"))
                        {
                            item.Cells[3].Style["background-color"] = "green";
                            countMatch++;
                        }
                        else
                        {
                            item.Cells[3].Style["background-color"] = "red";
                        }
                    }

                    btnSaveTemp.Visible          = false;
                    btnCancelScanBarcode.Visible = false;
                    btnBack.Visible = true;

                    txtBarcodeScan.Style["display"] = "none";

                    //Next Step

                    dvProcessOrder.Style["display"]  = "none";
                    dvScanBarcode.Style["display"]   = "block";
                    dvRangesBarcode.Style["display"] = "none";

                    lbPrOrder.InnerText  = txtProcessOrder.Text;
                    lbBtfs.InnerText     = txtBtfs.Text;
                    lbOrderQty.InnerText = txtOrderQty.Text;

                    var orderQty  = Convert.ToInt32(txtOrderQty.Text);
                    var matchQty  = Convert.ToInt32(lbMatchQty.InnerText) + countMatch;
                    var remainQty = orderQty - matchQty;

                    lbMatchQty.InnerText  = matchQty.ToString();
                    lbRemainQty.InnerText = remainQty.ToString();

                    btnBack.Visible = true;

                    actionResult = true;
                    msg          = "บันทึกข้อมูลสำเร็จ";
                }
                else
                {
                    actionResult = false;
                    msg          = "เกิดข้อผิดพลาด กรุณาตรวจสอบ!";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        protected void txtBarcodeScan_OnTextChanged(object sender, EventArgs e)
        {
            int rowIndex = 0;

            try
            {
                if (!String.IsNullOrEmpty(txtBarcodeScan.Text) && txtBarcodeScan.Text.Length == 11 && IsDigitsOnly(txtBarcodeScan.Text))
                {
                    BLProcessOrder blPrOrder = new BLProcessOrder();
                    DataSet        ds        = blPrOrder.GetProcessOrderMatch(txtBarcodeScan.Text.Trim(), txtProcessOrder.Text.Trim());

                    if (ViewState["gridBarcodeScan"] != null)
                    {
                        DataTable dt = (DataTable)ViewState["gridBarcodeScan"];
                        DataRow   dr = null;


                        if (dt.Rows.Count > 0)
                        {
                            if (!IsDupplicateBarcode(dt, txtBarcodeScan.Text) && ds.Tables[0].Rows.Count == 0)
                            {
                                dr            = dt.NewRow();
                                dr["No"]      = dt.Rows.Count + 1;
                                dr["Barcode"] = txtBarcodeScan.Text;

                                dt.Rows.Add(dr);

                                ViewState["gridBarcodeScan"] = dt;

                                gridBarcodeScan.DataSource = dt;
                                gridBarcodeScan.DataBind();

                                //var orderQty = Convert.ToInt32(txtOrderQty.Text);
                                //var matchQty = dt.Rows.Count;
                                //var remainQty = orderQty - matchQty;

                                //lbMatchQty.InnerText = matchQty.ToString();
                                //lbRemainQty.InnerText = remainQty.ToString();

                                actionResult = true;
                            }
                            else
                            {
                                //Barcode Dupplicate
                                actionResult = false;
                                msg          = "Barcode ถูกยิงไปแล้ว กรุณาลองใหม่!";
                            }
                        }
                        else
                        {
                            if (ds.Tables[0].Rows.Count == 0)
                            {
                                //after delete all
                                SetInitialRow(txtBarcodeScan.Text);

                                //var orderQty = Convert.ToInt32(txtOrderQty.Text);
                                //var matchQty = 1;
                                //var remainQty = orderQty - matchQty;

                                //lbMatchQty.InnerText = matchQty.ToString();
                                //lbRemainQty.InnerText = remainQty.ToString();

                                actionResult = true;
                            }
                            else
                            {
                                //Barcode Dupplicate
                                actionResult = false;
                                msg          = "Barcode ถูกยิงไปแล้ว กรุณาลองใหม่!";
                            }
                        }
                    }
                    else
                    {
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            //First Record
                            SetInitialRow(txtBarcodeScan.Text);
                            //var orderQty = Convert.ToInt32(txtOrderQty.Text);
                            //var matchQty = 1;
                            //var remainQty = orderQty - matchQty;

                            //lbMatchQty.InnerText = matchQty.ToString();
                            //lbRemainQty.InnerText = remainQty.ToString();
                            actionResult = true;
                        }
                        else
                        {
                            //Barcode Dupplicate
                            actionResult = false;
                            msg          = "Barcode ถูกยิงไปแล้ว กรุณาลองใหม่!";
                        }
                    }

                    if (gridBarcodeScan.Rows.Count > 0 || actionResult)
                    {
                        btnSaveTemp.Visible          = true;
                        btnCancelScanBarcode.Visible = true;
                    }
                    else
                    {
                        btnSaveTemp.Visible          = false;
                        btnCancelScanBarcode.Visible = false;
                    }
                }
                else
                {
                    //Barcode invalid
                    actionResult = false;
                    msg          = "รูปแบบ Barcode ไม่ถูกต้อง กรุณาลองใหม่!";
                }

                //Set Focus
                txtBarcodeScan.Focus();
                txtBarcodeScan.Text = "";
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 3
0
        protected void btnSave_ServerClick(object sender, EventArgs e)
        {
            try
            {
                bool           result    = false;
                BLProcessOrder blPrOrder = new BLProcessOrder();
                string         barcode   = "";

                var users = (User)Session["User"];

                if (ViewState["gridBarcodeScan"] != null)
                {
                    DataTable dt = (DataTable)ViewState["gridBarcodeScan"];

                    foreach (DataRow dr in dt.Rows)
                    {
                        barcode = barcode + dr["Barcode"].ToString() + ",";
                    }

                    barcode = barcode.Substring(0, barcode.Length - 1);
                }

                result = blPrOrder.InsertProcessOrderMatch(txtProcessOrder.Text, barcode, users.UserName, users.DeptName);

                if (result)
                {
                    var       spBarcode = barcode.Split(',');
                    DataTable dt        = (DataTable)ViewState["gridBarcodeScan"];
                    foreach (var bc in spBarcode)
                    {
                        DataSet ds = blPrOrder.GetProcessOrderMatch(bc, txtProcessOrder.Text);

                        foreach (DataRow dr in dt.Rows)
                        {
                            if (dr["Barcode"].ToString().Equals(bc))
                            {
                                dr["Status"] = ds.Tables[0].Rows[0]["STATUS"];
                            }
                        }
                    }

                    ViewState["gridBarcodeScan"]       = null;
                    gridBarcodeScan.Columns[3].Visible = true;
                    gridBarcodeScan.Columns[2].Visible = false;

                    gridBarcodeScan.DataSource = dt;
                    gridBarcodeScan.DataBind();

                    gridBarcodeScan.HeaderRow.Cells[0].CssClass = "visiblecol";

                    var countMatch = 0;
                    foreach (GridViewRow item in gridBarcodeScan.Rows)
                    {
                        var status = item.Cells[3].Text;

                        if (status.Equals("Matched"))
                        {
                            item.Cells[3].Style["background-color"] = "green";
                            countMatch++;
                        }
                        else
                        {
                            item.Cells[3].Style["background-color"] = "red";
                        }
                    }

                    btnSaveTemp.Visible          = false;
                    btnCancelScanBarcode.Visible = false;
                    btnBack.Visible = true;

                    txtBarcodeScan.Style["display"] = "none";
                    lbBarcodeScan.Style["display"]  = "none";

                    var orderQty  = Convert.ToInt32(txtOrderQty.Text);
                    var matchQty  = Convert.ToInt32(lbMatchQty.InnerText) + countMatch;
                    var remainQty = orderQty - matchQty;

                    lbMatchQty.InnerText  = matchQty.ToString();
                    lbRemainQty.InnerText = remainQty.ToString();

                    actionResult = true;
                    msg          = "บันทึกข้อมูลสำเร็จ";
                }
                else
                {
                    actionResult = false;
                    msg          = "เกิดข้อผิดพลาด กรุณาตรวจสอบ!";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }