private int AddBarCode(ViewCreateBarCodeModel model, long barCodeMasterId) { int i = 0; foreach (var item in model.BarCodes) { CommandObj.CommandText = "UDSP_AddBarCode"; CommandObj.CommandType = CommandType.StoredProcedure; CommandObj.Parameters.Clear(); CommandObj.Parameters.AddWithValue("@BarCode", item.Barcode); CommandObj.Parameters.AddWithValue("@BarCodeMasterId", barCodeMasterId); CommandObj.Parameters.Add("@RowAffected", SqlDbType.Int); CommandObj.Parameters["@RowAffected"].Direction = ParameterDirection.Output; CommandObj.ExecuteNonQuery(); i += Convert.ToInt32(CommandObj.Parameters["@RowAffected"].Value); } return(i); }
public int SaveBarCodes(ViewCreateBarCodeModel model) { ConnectionObj.Open(); SqlTransaction sqlTransaction = ConnectionObj.BeginTransaction(); try { CommandObj.Transaction = sqlTransaction; CommandObj.CommandText = "UDSP_AddBarCodeMaster"; CommandObj.CommandType = CommandType.StoredProcedure; CommandObj.Parameters.AddWithValue("@ProductId", model.ProductId); CommandObj.Parameters.AddWithValue("@ProductionDate", model.ProductionDate); CommandObj.Parameters.AddWithValue("@LineNumber", model.ProductionLineId.ToString("D2")); CommandObj.Parameters.AddWithValue("@Quantity", model.BarCodes.Count); CommandObj.Parameters.AddWithValue("@GenerateByUserId", model.GenerateByUserId); CommandObj.Parameters.Add("@BarCodeMasterId", SqlDbType.BigInt); CommandObj.Parameters["@BarCodeMasterId"].Direction = ParameterDirection.Output; CommandObj.ExecuteNonQuery(); var barCodeMasterId = Convert.ToInt64(CommandObj.Parameters["@BarCodeMasterId"].Value); int result = AddBarCode(model, barCodeMasterId); if (result > 0) { sqlTransaction.Commit(); } return(result); } catch (SqlException sqlException) { sqlTransaction.Rollback(); throw new Exception("Could not Save Order due to sql exception", sqlException); } catch (Exception exception) { sqlTransaction.Rollback(); throw new Exception("Could not Save Order", exception); } finally { CommandObj.Parameters.Clear(); CommandObj.Dispose(); ConnectionObj.Close(); } }
public ActionResult Generate(ViewCreateBarCodeModel model) { var monthYear = DateTime.Now.Month.ToString("D2") + Convert.ToInt32(DateTime.Now.Year.ToString().Substring(2, 2)).ToString("D2"); var productionDateCodes = _iCommonManager.GetProductionDateCodeByMonthYear(monthYear).ToList(); var productionLines = _iCommonManager.GetAllProductionLines().ToList(); string barCodePrefix = model.ProductId.ToString("D3") + productionDateCodes.Find(n => n.ProductionDateCodeId.Equals(3)) .Code + DateTime.Now.Day + productionLines.Find(n => n.ProductionLineId == model.ProductionLineId).LineNumber; var maxSl = _iBarCodeManager.GetMaxBarCodeSlByPrefix(barCodePrefix); var user = (ViewUser)Session["user"]; model.GenerateByUserId = user.UserId; for (int i = 1; i <= model.Total; i++) { var barcode = barCodePrefix + (maxSl + i).ToString("D4"); BarCodeModel aBarCodeModel = new BarCodeModel { Barcode = barcode, PrintByUserId = user.UserId }; model.BarCodes.Add(aBarCodeModel); GenerateBarCodeFromaGivenString(barcode); } bool result = _iBarCodeManager.SaveBarCodes(model); if (result) { ModelState.Clear(); } ViewBag.ProductionDateCodeId = new SelectList(productionDateCodes, "ProductionDateCodeId", "Code", productionDateCodes.First().ProductionDateCodeId); ViewBag.ProductionLineId = new SelectList(productionLines, "ProductionLineId", "LineNumber"); return(View()); }
public ActionResult PrintBarCode(ViewCreateBarCodeModel model) { var monthYear = DateTime.Now.Month.ToString("D2") + Convert.ToInt32(DateTime.Now.Year.ToString().Substring(2, 2)).ToString("D2"); var productionDateCodes = _iCommonManager.GetProductionDateCodeByMonthYear(monthYear).ToList(); var productionLines = _iCommonManager.GetAllProductionLines().ToList(); for (int i = 1; i <= model.Total; i++) { var barcode = model.ProductId.ToString("D3") + productionDateCodes.Find(n => n.ProductionDateCodeId.Equals(3)) .Code + DateTime.Now.Day + model.ProductionLineId + i.ToString("D5"); GenerateBarCodeFromaGivenString(barcode); } ViewBag.ProductionDateCodeId = new SelectList(productionDateCodes, "ProductionDateCodeId", "Code", productionDateCodes.First().ProductionDateCodeId); ViewBag.ProductionLineId = new SelectList(productionLines, "ProductionLineId", "LineNumber"); return(View()); }
public bool SaveBarCodes(ViewCreateBarCodeModel model) { int rowAffected = _iBarCodeGateway.SaveBarCodes(model); return(rowAffected > 0); }
public ActionResult Generate(ViewCreateBarCodeModel model) { try { var monthYear = DateTime.Now.Month.ToString("D2") + Convert.ToInt32(DateTime.Now.Year.ToString().Substring(2, 2)).ToString("D2"); var productionDateCodes = _iCommonManager.GetAllProductionDateCode().ToList(); var courrentCode = _iCommonManager.GetProductionDateCodeByMonthYear(monthYear).ToList().First(); var productionLines = _iCommonManager.GetAllProductionLines().ToList(); var lineNo = productionLines.Find(n => n.ProductionLineId == model.ProductionLineId).LineNumber; var selecteDatecode = productionDateCodes.Find(n => n.ProductionDateCodeId == model.ProductionDateCodeId) .Code; var date = Convert.ToDateTime(model.ProductionDate).Day.ToString("D2"); string barCodePrefix = lineNo + model.ShiftNo + model.ProductId.ToString("D3") + date + selecteDatecode; //string barCodePrefix = productionLines.Find(n => n.ProductionLineId == model.ProductionLineId).LineNumber + model.ProductId.ToString("D3") + "09" + productionDateCodes.First().Code; string infix = date + selecteDatecode; var maxSl = _iBarCodeManager.GetMaxBarCodeSlByInfixAndByLineNo(infix, lineNo); //var maxSl = 413; if (maxSl == 0 && lineNo.Equals("1")) { maxSl = 1000; } else if (maxSl == 0 && lineNo.Equals("2")) { maxSl = 2000; } else if (maxSl == 0 && lineNo.Equals("3")) { maxSl = 3000; } else if (maxSl == 0 && lineNo.Equals("4")) { maxSl = 4000; } else if (maxSl == 0 && lineNo.Equals("5")) { maxSl = 5000; } var user = (ViewUser)Session["user"]; model.GenerateByUserId = user.UserId; for (int i = 1; i <= model.Total; i++) { var barcode = barCodePrefix + (maxSl + i).ToString("D4"); BarCodeModel aBarCodeModel = new BarCodeModel { Barcode = barcode, PrintByUserId = user.UserId }; model.BarCodes.Add(aBarCodeModel); GenerateBarCodeFromaGivenString(barcode); } //for (int i = 3001; i <= 3158; i++) //{ // var barcode = "3B07428FN" + i.ToString("D4"); // BarCodeModel aBarCodeModel = new BarCodeModel // { // Barcode = barcode, // PrintByUserId = user.UserId // }; // model.BarCodes.Add(aBarCodeModel); // GenerateBarCodeFromaGivenString(barcode); //} bool result = _iBarCodeManager.SaveBarCodes(model); if (result) { ModelState.Clear(); } ViewBag.ProductionDateCodeId = new SelectList(productionDateCodes, "ProductionDateCodeId", "Code", courrentCode.ProductionDateCodeId); ViewBag.ProductionLineId = new SelectList(productionLines, "ProductionLineId", "LineNumber"); return(View()); } catch (Exception exception) { Log.WriteErrorLog(exception); return(PartialView("_ErrorPartial", exception)); } }