private void btnGen_Click(object sender, EventArgs e) { if (txtNumber.Text.Trim() == "") { MessageBox.Show("กรุณาป้อน จำนวน ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtNumber.Focus(); return; } PrintingLabels pl = new PrintingLabels(); int _genNumber =0; pl.Part = cbopart.Text.Trim(); string _date = String.Format("{0:dd/MM/yyyy}", dtbDate.Value); pl.ProductDate = _date; pl.Shift = cboShift.Text.Trim(); pl.Mold = cbomold.Text.Trim(); pl.Rev = lblRevision.Text.Trim(); pl.ColorNo = lblColor.Text.Trim(); pl.Process = lblProcess.Text.Trim(); _genNumber = Convert.ToInt32(txtNumber.Text.Trim()); printingLabels = printingService.GenBarcode(pl, _genNumber); dgvList.DataSource = printingLabels; dgvList.ReadOnly = true; FormatdgvList(); }
public int CreatePringtingLabel(PrintingLabels newPrintingLabels) { int result = -1; try { conn = db.openConn(); tr = conn.BeginTransaction(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append("INSERT INTO printing_labels(barcode,part,product_date,serial,shift,rev,color_no,process,mold_no,user_create_name,create_date,status)"); sb.Append(" VALUES (@barcode,@part,@product_date,@serial,@shift,@rev,@color_no,@process,@mold_no,@user_create_name,@create_date,@status)"); string sqlsave; sqlsave = sb.ToString(); comm = new SqlCommand(); comm.Connection = conn; comm.Transaction = tr; comm.CommandText = sqlsave; comm.Parameters.Clear(); comm.Parameters.Add("@barcode", SqlDbType.NVarChar).Value = newPrintingLabels.BarCode; comm.Parameters.Add("@part", SqlDbType.NVarChar).Value = newPrintingLabels.Part; comm.Parameters.Add("@product_date", SqlDbType.NVarChar).Value = newPrintingLabels.ProductDate; comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newPrintingLabels.Serial; comm.Parameters.Add("@shift", SqlDbType.NVarChar).Value = newPrintingLabels.Shift; comm.Parameters.Add("@rev", SqlDbType.NVarChar).Value = newPrintingLabels.Rev; comm.Parameters.Add("@color_no", SqlDbType.NVarChar).Value = newPrintingLabels.ColorNo; comm.Parameters.Add("@process", SqlDbType.NVarChar).Value = newPrintingLabels.Process; comm.Parameters.Add("@mold_no", SqlDbType.NVarChar).Value = newPrintingLabels.Mold; comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newPrintingLabels.UserCreateName; comm.Parameters.Add("@create_date", SqlDbType.DateTime).Value = newPrintingLabels.CreateDate; comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newPrintingLabels.Status; comm.ExecuteNonQuery(); tr.Commit(); result = 1; } catch (Exception ex) { tr.Rollback(); conn.Close(); return result; throw ex; } finally { conn.Close(); } return result; }
public List<PrintingLabels> GetByBarCodes(string _part,string _date) { List<PrintingLabels> printingLabels = new List<PrintingLabels>(); PrintingLabels fbl = null; try { conn = db.openConn(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append(" select barcode,part,product_date,serial,shift,rev,color_no,process,mold_no,user_create_name,create_date,status from printing_labels"); sb.Append(" where part ='" + _part + "'"); sb.Append(" and product_date ='" + _date + "'"); string sql; sql = sb.ToString(); comm = new SqlCommand(); comm.CommandText = sql; comm.CommandType = CommandType.Text; comm.Connection = conn; dr = comm.ExecuteReader(); if (dr.HasRows) { DataTable dt = new DataTable(); dt.Load(dr); foreach (DataRow drw in dt.Rows) { fbl = new PrintingLabels(); fbl.BarCode = drw["barcode"].ToString(); fbl.Part = drw["part"].ToString(); fbl.ProductDate = drw["product_date"].ToString(); fbl.Serial = drw["serial"].ToString(); fbl.Shift = drw["shift"].ToString(); fbl.Rev = drw["rev"].ToString(); fbl.ColorNo = drw["color_no"].ToString(); fbl.Process = drw["process"].ToString(); fbl.Mold = drw["mold_no"].ToString(); fbl.UserCreateName = drw["user_create_name"].ToString(); fbl.CreateDate = Convert.ToDateTime(drw["create_date"].ToString()); fbl.Status = drw["status"].ToString(); printingLabels.Add(fbl); } } } catch (Exception ex) { dr.Close(); conn.Close(); return null; throw ex; } finally { conn.Close(); } return printingLabels; }
public List<PrintingLabels> GenBarcode(PrintingLabels _printingLabels, int genNumber) { List<PrintingLabels> printingLabels = new List<PrintingLabels>(); string[] arr = Regex.Split(_printingLabels.ProductDate, "/"); int _year = Convert.ToInt32(arr[2]) /*- 543*/; _printingLabels.ProductDate = arr[0] + "/" + arr[1] + "/" + _year; /* _printingLabels.Rev = "00"; _printingLabels.ColorNo = "BLC-1"; _printingLabels.Process = "N5N7";*/ PrintingLabels flabel; // หา serialNo ล่าสุด int _lastSerial = this.GetLastSerial(_printingLabels.Part, _printingLabels.ProductDate, _printingLabels.Shift); if (_lastSerial == 0) { _lastSerial = 1; } else { _lastSerial++; } int j = 0; genNumber = genNumber + _lastSerial; for (j = _lastSerial; j < genNumber; j++) { flabel = new PrintingLabels(); flabel.BarCode = _printingLabels.Part + "!" + _printingLabels.ProductDate+"!"; flabel.BarCode += j.ToString("00000") + "!" + _printingLabels.Shift + "!"; flabel.BarCode += _printingLabels.Rev + "!" + _printingLabels.ColorNo+"!Print,"; flabel.BarCode += _printingLabels.Process ; flabel.Part = _printingLabels.Part; flabel.ProductDate = _printingLabels.ProductDate; flabel.Serial = Convert.ToString(j); flabel.Shift = _printingLabels.Shift; flabel.Rev = _printingLabels.Rev; flabel.ColorNo = _printingLabels.ColorNo; flabel.Process = _printingLabels.Process; flabel.Mold = _printingLabels.Mold; flabel.UserCreateName ="admin"; flabel.CreateDate = DateTime.Now; flabel.Status = "1"; printingLabels.Add(flabel); } return printingLabels; }
private void txtSearch_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (e.KeyValue == 13) { List<PrintingLabels> printingLabels = new List<PrintingLabels>(); printingLabels = printingService.GetByBarCodes(txtSearch.Text.Trim()); if (printingLabels != null && printingLabels.Count > 0) { dgvList.DataSource = printingLabels; dgvList.ReadOnly = true; FormatdgvList(); } else { dgvList.DataSource = null; lblresult.Visible = true; lblresult.Text = " ไม่พบข้อมูล"; } } }
private void dgvList_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1) { return; } string _barcode = ""; _barcode = dgvList.Rows[e.RowIndex].Cells[1].Value.ToString(); printingLabels = printingService.GetByBarCode(_barcode); }