protected void txtBarcodeScan_OnTextChanged(object sender, EventArgs e) { int rowIndex = 0; try { if (!String.IsNullOrEmpty(txtBarcodeScan.Text) && txtBarcodeScan.Text.Length == 11 && IsDigitsOnly(txtBarcodeScan.Text)) { BLBarcode blBarcode = new BLBarcode(); DataSet ds = blBarcode.GetBarcodeVoidReturn(txtBarcodeScan.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(); actionResult = true; } else { //Barcode Dupplicate actionResult = false; msg = "Barcode ถูกยิงไปแล้ว กรุณาลองใหม่!"; } } else { if (ds.Tables[0].Rows.Count == 0) { //after delete all SetInitialRow(txtBarcodeScan.Text); actionResult = true; } else { //Barcode Dupplicate actionResult = false; msg = "Barcode ถูกยิงไปแล้ว กรุณาลองใหม่!"; } } } else { if (ds.Tables[0].Rows.Count == 0) { //First Record SetInitialRow(txtBarcodeScan.Text); actionResult = true; } else { //Barcode Dupplicate actionResult = false; msg = "Barcode ถูกยิงไปแล้ว กรุณาลองใหม่!"; } } if (gridBarcodeScan.Rows.Count > 0 || actionResult) { btnSave.Visible = true; btnCancel.Visible = true; } else { btnSave.Visible = false; btnCancel.Visible = false; } } else { //Barcode invalid actionResult = false; msg = "รูปแบบ Barcode ไม่ถูกต้อง กรุณาลองใหม่!"; } //Set Focus txtBarcodeScan.Focus(); txtBarcodeScan.Text = ""; } catch (Exception ex) { throw ex; } }
protected void btnSave_ServerClick(object sender, EventArgs e) { try { bool result = false; BLBarcode blBarcode = new BLBarcode(); 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 = blBarcode.InsertBarcodeVoidReturn(barcode, users.UserName, users.DeptName); if (result) { var spBarcode = barcode.Split(','); DataTable dt = (DataTable)ViewState["gridBarcodeScan"]; foreach (var bc in spBarcode) { DataSet ds = blBarcode.GetBarcodeVoidReturn(bc); foreach (DataRow dr in dt.Rows) { if (dr["Barcode"].ToString().Equals(bc)) { dr["Status"] = ds.Tables[0].Rows[0]["STATUS"]; } } } ViewState["gridBarcodeScan"] = dt; //ViewState["gridBarcodeScan"] = null; gridBarcodeScan.Columns[3].Visible = true; gridBarcodeScan.Columns[2].Visible = false; gridBarcodeScan.DataSource = dt; gridBarcodeScan.DataBind(); gridBarcodeScan.HeaderRow.Cells[0].CssClass = "visiblecol"; btnSave.Visible = false; btnCancel.Visible = false; btnBack.Visible = true; actionResult = true; msg = "บันทึกข้อมูลสำเร็จ"; } else { actionResult = false; msg = "เกิดข้อผิดพลาด กรุณาตรวจสอบ!"; } } catch (Exception ex) { throw ex; } }