public static void SaveBarCode(BarCodeDTO dto, string barCodeValue, string relativePath) { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string cmdText = DBConstants.usp_saveBarCode; SqlCommand sqlCommand = new SqlCommand(cmdText, connection) { CommandType = CommandType.StoredProcedure }; sqlCommand.Parameters.AddWithValue("@mrp", dto.Mrp); sqlCommand.Parameters.AddWithValue("@dept", dto.Dept); sqlCommand.Parameters.AddWithValue("@craft", dto.Craft); sqlCommand.Parameters.AddWithValue("@size", dto.Size); sqlCommand.Parameters.AddWithValue("@quality", dto.Quality); sqlCommand.Parameters.AddWithValue("@actualCost", dto.ActualCost); sqlCommand.Parameters.AddWithValue("@sellingPrice", dto.SellingPrice); sqlCommand.Parameters.AddWithValue("@vendor", dto.Vendor); sqlCommand.Parameters.AddWithValue("@barCodeValue", barCodeValue); sqlCommand.Parameters.AddWithValue("@relativePath", relativePath); sqlCommand.ExecuteNonQuery(); } }
public static void ValidateBarCodeProperties(BarCodeDTO dto) { var depts = GetAllDepts(); if (depts.All(d => d.Text != dto.Dept)) { BarCodeDAL.SaveBarCodeProperties("Dept", dto.Dept); } var crafts = GetAllCrafts(); if (crafts.All(d => d.Text != dto.Craft)) { BarCodeDAL.SaveBarCodeProperties("Craft", dto.Craft); } var qualitys = GetAllQualitys(); if (qualitys.All(d => d.Text != dto.Quality)) { BarCodeDAL.SaveBarCodeProperties("Quality", dto.Quality); } var sizes = GetAllSizes(); if (sizes.All(d => d.Text != dto.Size)) { BarCodeDAL.SaveBarCodeProperties("Size", dto.Size); } var vendors = GetAllVendors(); if (vendors.All(d => d.Text != dto.Vendor)) { BarCodeDAL.SaveBarCodeProperties("Vendor", dto.Vendor); } }
public static void SaveBarCode(BarCodeDTO dto, string barCodeValue, string relativePath) { BarCodeDAL.SaveBarCode(dto, barCodeValue, relativePath); }
public JsonResult GetBarCode(BarCodeDTO dto) { try { dto.Count = 0; ValidateBarCodeProperties(dto); while (!dto.IsValid) { dto.Count++; var currentBarCode = dto.BarCodeValue; var status = ValidateOrCreateBarCode(currentBarCode, dto.Mrp); if (status == "EXACT") { string imagePath = BarCodeBLL.GetBarCodeFilePathByBarCode(currentBarCode); List <string> response = new List <string> { currentBarCode, imagePath }; return(Json(response, JsonRequestBehavior.AllowGet)); } else if (status == "PARTIAL") { dto.IsValid = false; } else { dto.IsValid = true; } } var barCodeValue = dto.BarCodeValue; var dir = Server.MapPath("/Images/BarCode"); string fileName = DateTime.Now.ToString("ddMMyyyyHHmmss") + ".jpg"; string filePath = dir + "/" + fileName; string relativePath = "/Images/BarCode/" + fileName; BarcodeLib.Barcode b = new BarcodeLib.Barcode { IncludeLabel = true }; Image img = b.Encode(BarcodeLib.TYPE.CODE128, barCodeValue, Color.Black, Color.White, 290, 200); PointF companyLocation = new PointF(0f, 25f); PointF firstLocation = new PointF(18f, 0f); PointF secondLocation = new PointF(320f, 0f); StringFormat drawFormat = new StringFormat { FormatFlags = StringFormatFlags.DirectionVertical }; string firstText = dto.Craft + " - INR:" + dto.Mrp.ToString(CultureInfo.InvariantCulture); string companyString = "KAMALASAREE.COM"; Bitmap bitmap = (Bitmap)img; Bitmap bigImage = new Bitmap(350, 200); using (Graphics graphics = Graphics.FromImage(bigImage)) { using (Font companyFont = new Font("Arial Black", 10, FontStyle.Bold)) { graphics.DrawString(companyString, companyFont, Brushes.Black, companyLocation, drawFormat); } using (Font arialFont = new Font("Arial", 14)) { graphics.DrawImage(bitmap, new Point() { X = 35, Y = 0 }); graphics.DrawLine(Pens.Black, new PointF(19, 0), new PointF(19, 200)); graphics.DrawString(firstText, arialFont, Brushes.Black, firstLocation, drawFormat); graphics.DrawString("Vendor: " + dto.Vendor.ToString(CultureInfo.InvariantCulture), arialFont, Brushes.Black, secondLocation, drawFormat); } } bigImage.Save(filePath);//save the image file bigImage.Dispose(); List <string> result = new List <string> { barCodeValue, relativePath }; Console.WriteLine($"Home/GetBarCode. result: {result}"); BarCodeBLL.SaveBarCode(dto, barCodeValue, relativePath); return(Json(result, JsonRequestBehavior.AllowGet)); } catch (Exception e) { Console.WriteLine(e); throw; } }
private void ValidateBarCodeProperties(BarCodeDTO dto) { BarCodeBLL.ValidateBarCodeProperties(dto); }