public WeighModel GetWeigh(long seq) { WeighModel weigh = null; try { using (DataTable dt = FillTable(string.Concat("SELECT Plate,Weight1,Weight2,Net,FirmName,MaterialName,WaybillNo FROM dbo.Weigh2 WITH (NOLOCK) WHERE seq = ", seq))) { if (dt != null && dt.Rows.Count > 0) { weigh = new WeighModel(); weigh.FirmName = dt.Rows[0]["FirmName"].GetString(); weigh.WaybillNo = dt.Rows[0]["WaybillNo"].GetString(); weigh.MaterialName = dt.Rows[0]["MaterialName"].GetString(); weigh.Plate = dt.Rows[0]["Plate"].GetString(); weigh.Weight1 = dt.Rows[0]["FirmName"].GetDecimal(); weigh.Weight2 = dt.Rows[0]["FirmName"].GetDecimal(); weigh.Net = dt.Rows[0]["FirmName"].GetDecimal(); } } } catch (Exception exc) { Logger.E(exc); } return(weigh); }
private void AddImage(long seq, List <byte[]> images) { try { using (WeighProvider db = new WeighProvider(AppSettingHelper.Default.GetSqlConnectionString())) { Image bitmap; WeighModel weigh = db.GetWeigh(seq); for (int loop = 0; loop < images.Count; loop++) { byte[] imagebuff = images[loop]; if (weigh != null) { using (var ms = new MemoryStream(images[loop])) { bitmap = Image.FromStream(ms); } using (Graphics graphics = Graphics.FromImage(bitmap)) { SolidBrush brush = new SolidBrush(Color.White); graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.SmoothingMode = SmoothingMode.AntiAlias; int y = 152, x = 110; graphics.DrawString(weigh.FirmNameText, font, brush, new Point(x, y)); y += Convert.ToInt32(graphics.MeasureString(weigh.FirmNameText, font).Height + 2); graphics.DrawString(weigh.PlateText, font, brush, new Point(x, y)); y += Convert.ToInt32(graphics.MeasureString(weigh.PlateText, font).Height + 2); graphics.DrawString(weigh.WaybillNoText, font, brush, new Point(x, y)); y += Convert.ToInt32(graphics.MeasureString(weigh.WaybillNoText, font).Height + 2); graphics.DrawString(weigh.MaterialNameText, font, brush, new Point(x, y)); y += Convert.ToInt32(graphics.MeasureString(weigh.MaterialNameText, font).Height + 2); graphics.DrawString(weigh.Weight1Text, font, brush, new Point(x, y)); y += Convert.ToInt32(graphics.MeasureString(weigh.Weight1Text, font).Height + 2); graphics.DrawString(weigh.Weight2Text, font, brush, new Point(x, y)); y += Convert.ToInt32(graphics.MeasureString(weigh.Weight2Text, font).Height + 2); graphics.DrawString(weigh.NetText, font, brush, new Point(x, y)); graphics.Flush(); graphics.Dispose(); MemoryStream m = new MemoryStream(); bitmap.Save(m, System.Drawing.Imaging.ImageFormat.Jpeg); MemoryStream memoryStream = new MemoryStream(); bitmap.Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); imagebuff = memoryStream.ToArray(); } db.AddImage(seq, imagebuff); } } } } catch (NullReferenceException nullexcinsert) { Logger.E(nullexcinsert); } catch (SqlException sqlexcinsert) { Logger.E(sqlexcinsert); } catch (Exception excinsert) { Logger.E(excinsert); } finally { SqlConnection.ClearAllPools(); } }