public int CreateInjectionBoxLabel(BoxLabel newBoxLabel) { int result = -1; try { conn = db.openConn(); tr = conn.BeginTransaction(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append("INSERT INTO box_labels(barcode,complete_no,model_no,product_date,quantity,serial,mold_no,storaged,suplier,print_date,user_create_name,status)"); sb.Append(" VALUES (@barcode,@complete_no,@model_no,@product_date,@quantity,@serial,@mold_no,@storaged,@suplier,@print_date,@user_create_name,@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 = newBoxLabel.BarCodeNo; comm.Parameters.Add("@complete_no", SqlDbType.NVarChar).Value = newBoxLabel.CompleteNo; comm.Parameters.Add("@model_no", SqlDbType.NVarChar).Value = newBoxLabel.ModelNo; comm.Parameters.Add("@product_date", SqlDbType.NVarChar).Value = newBoxLabel.ProductDate; comm.Parameters.Add("@quantity", SqlDbType.NVarChar).Value = newBoxLabel.Quantity; comm.Parameters.Add("@serial", SqlDbType.NVarChar).Value = newBoxLabel.Serial; comm.Parameters.Add("@mold_no", SqlDbType.NVarChar).Value = newBoxLabel.MoldNo; comm.Parameters.Add("@storaged", SqlDbType.NVarChar).Value = newBoxLabel.Storaged; comm.Parameters.Add("@suplier", SqlDbType.NVarChar).Value = newBoxLabel.Suplier; comm.Parameters.Add("@print_date", SqlDbType.DateTime).Value = newBoxLabel.PrintDate; comm.Parameters.Add("@user_create_name", SqlDbType.NVarChar).Value = newBoxLabel.UserCreateName; comm.Parameters.Add("@status", SqlDbType.NVarChar).Value = newBoxLabel.Status; comm.ExecuteNonQuery(); tr.Commit(); result = 1; } catch (Exception ex) { tr.Rollback(); conn.Close(); return result; throw ex; } finally { conn.Close(); } return result; }
private void btnGen_Click(object sender, EventArgs e) { if (cbomold.Text.Trim() == "") { MessageBox.Show("กรุณาเลือก Mold ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); cbomold.Focus(); return; } if (txtproductqty.Text.Trim() == "") { MessageBox.Show("กรุณาป้อน จำนวนสินค้า ก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtproductqty.Focus(); return; } if (txtnumprint.Text.Trim() == "") { MessageBox.Show("กรุณาป้อน จำนวนก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtnumprint.Focus(); return; } BoxLabel boxLabel = new BoxLabel(); int _genNumber = 0; // completeNo boxLabel.CompleteNo = cboComplete.SelectedValue.ToString(); // date string _date = String.Format("{0:dd/MM/yyyy}", dtbDate.Value); boxLabel.ProductDate = _date; boxLabel.MoldNo = cbomold.Text.Trim(); boxLabel.Quantity = lblqty.Text.Trim(); boxLabel.ModelNo = lblmodel.Text.Trim(); boxLabel.Storaged = "0"; boxLabel.Suplier = lblsuplier.Text.Trim(); // number run _genNumber = Convert.ToInt32(txtnumprint.Text.Trim()); boxLabels = boxLabelService.GenBarcode(boxLabel, _genNumber); dgvList.DataSource = boxLabels; dgvList.ReadOnly = true; FormatdgvList(); }
public List<BoxLabel> GetByBarCodes(string _completeno,string _date) { List<BoxLabel> boxLabels = new List<BoxLabel>(); BoxLabel fbl = null; try { conn = db.openConn(); sb = new StringBuilder(); sb.Remove(0, sb.Length); sb.Append(" select barcode,complete_no,model_no,product_date,quantity,serial,mold_no,storaged,print_date,user_create_name,status from dbo.box_labels"); sb.Append(" where complete_no ='" + _completeno + "'"); 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 BoxLabel(); fbl.ID = 0; fbl.BarCodeNo = drw["barcode"].ToString(); fbl.CompleteNo = drw["complete_no"].ToString(); fbl.ModelNo = drw["model_no"].ToString(); fbl.ProductDate = drw["product_date"].ToString(); fbl.Quantity = drw["quantity"].ToString(); fbl.Serial = drw["serial"].ToString(); fbl.MoldNo = drw["mold_no"].ToString(); fbl.Storaged = drw["storaged"].ToString(); fbl.PrintDate = Convert.ToDateTime(drw["print_date"].ToString()); fbl.UserCreateName = drw["user_create_name"].ToString(); fbl.Status = drw["status"].ToString(); boxLabels.Add(fbl); } } } catch (Exception ex) { dr.Close(); conn.Close(); return null; throw ex; } finally { conn.Close(); } return boxLabels; }
public List<BoxLabel> GenBarcode(BoxLabel _boxLabel, int genNumber) { List<BoxLabel> boxLabels = new List<BoxLabel>(); string[] arr = Regex.Split(_boxLabel.ProductDate, "/"); int _year = Convert.ToInt32(arr[2])/* - 543*/; _boxLabel.ProductDate = arr[0] + "/" + arr[1] + "/" + _year; //_boxLabel.ModelNo = "TH-P42ST30W"; //_boxLabel.Storaged = "0"; BoxLabel boxLabel; // หา serialNo ล่าสุด int _lastSerial = this.GetLastSerial(_boxLabel.CompleteNo, _boxLabel.ProductDate, _boxLabel.Quantity); if (_lastSerial == 0) { _lastSerial = 1; } else { _lastSerial++; } int j = 0; genNumber = genNumber + _lastSerial; for (j = _lastSerial; j < genNumber; j++) { boxLabel = new BoxLabel(); boxLabel.BarCodeNo = _boxLabel.CompleteNo+"!"+_boxLabel.ModelNo+"!"+_boxLabel.ProductDate+"!"+_boxLabel.Quantity+"!"; boxLabel.BarCodeNo += Convert.ToString(j) + "!" + _boxLabel.MoldNo; boxLabel.CompleteNo=_boxLabel.CompleteNo; boxLabel.ModelNo=_boxLabel.ModelNo; boxLabel.ProductDate=_boxLabel.ProductDate; boxLabel.Quantity=_boxLabel.Quantity; boxLabel.Serial = Convert.ToString(j); boxLabel.MoldNo=_boxLabel.MoldNo; boxLabel.Storaged=_boxLabel.Storaged; boxLabel.Suplier = _boxLabel.Suplier; boxLabel.PrintDate = DateTime.Now; boxLabel.UserCreateName="admin"; boxLabel.Status = "1"; boxLabels.Add(boxLabel); } return boxLabels; }
private void dgvList_CellMouseUp(object sender, DataGridViewCellMouseEventArgs e) { if (e.RowIndex == -1) { return; } string _barcode = ""; _barcode = dgvList.Rows[e.RowIndex].Cells[1].Value.ToString(); boxLabel = injectinBoxLabelService.GetByBarCode(_barcode); }