|
|
@@ -1170,118 +1170,134 @@ namespace Dongke.WinForm.Controls.InvoiceLayout
|
|
|
{
|
|
|
if (this._itemStyle == ItemStyle.Barcode)
|
|
|
{
|
|
|
- if (isPrint)
|
|
|
+ if (this._barcodeFormat == "EAN_13")
|
|
|
{
|
|
|
- OneDDrawingOptions ops = new OneDDrawingOptions();
|
|
|
- //ops.DrawGraphics = graphics;
|
|
|
- ops.ShowType = (this.Wrap ? BarcodeShowType.Zoom : BarcodeShowType.Show);
|
|
|
- //ops.ImageWidth = this.SimpleShape.Width;
|
|
|
- //ops.ImageHeight = this.SimpleShape.Height;
|
|
|
- ops.ImageWidth = LayoutCommon.MillimeterToPixelDpi(rectangleM.Width, graphics.DpiX);
|
|
|
- ops.ImageHeight = LayoutCommon.MillimeterToPixelDpi(rectangleM.Height, graphics.DpiX);
|
|
|
- ops.DpiX = graphics.DpiX;
|
|
|
- ops.DpiY = graphics.DpiY;
|
|
|
- //string vv = value + "";
|
|
|
- //if (vv.StartsWith("69"))
|
|
|
- try
|
|
|
- {
|
|
|
- //if (this.ItemCode == "ZWLJC")
|
|
|
- //{
|
|
|
- // using (Image pic1 = OneDHelper.GetOneDImage(value.ToString(), ops, OneDFormat.EAN_13))
|
|
|
- // {
|
|
|
- // graphics.DrawImage(pic1, rectangleM, ops.ImageRect, GraphicsUnit.Pixel);
|
|
|
- // }
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // using (Image pic1 = OneDHelper.GetOneDImage(value.ToString(), ops))
|
|
|
- // {
|
|
|
- // graphics.DrawImage(pic1, rectangleM, ops.ImageRect, GraphicsUnit.Pixel);
|
|
|
- // }
|
|
|
- //}
|
|
|
- using (Image pic1 = OneDHelper.GetOneDImage(value.ToString(), ops, GetOneDFormat(this._barcodeFormat)))
|
|
|
- {
|
|
|
- graphics.DrawImage(pic1, rectangleM, ops.ImageRect, GraphicsUnit.Pixel);
|
|
|
- }
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- }
|
|
|
+ string vv = EAN13((value + "").PadLeft(12, '0'));
|
|
|
+ //graphics.DrawString(vv, _fontDraw, Brushes.Black, this.SimpleShape.Bounds);
|
|
|
+
|
|
|
+ Rectangle rr = new Rectangle();
|
|
|
+ rr.X = LayoutCommon.MillimeterToPixelDpi(rectangleM.X, graphics.DpiX);
|
|
|
+ rr.Y = LayoutCommon.MillimeterToPixelDpi(rectangleM.Y, graphics.DpiY);
|
|
|
+ rr.Width = LayoutCommon.MillimeterToPixelDpi(rectangleM.Width, graphics.DpiX);
|
|
|
+ rr.Height = LayoutCommon.MillimeterToPixelDpi(rectangleM.Height, graphics.DpiX);
|
|
|
+ graphics.DrawString(vv, _font, Brushes.Black, rr);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- Image pic = null;
|
|
|
- if (!isPrint && this.SimpleShape.Width == this._picCodeWidth &&
|
|
|
- this.SimpleShape.Height == this._picCodeHeight &&
|
|
|
- value.ToString() == _picCodeValue)
|
|
|
- {
|
|
|
- pic = this._picCode;
|
|
|
- }
|
|
|
-
|
|
|
- if (pic == null)
|
|
|
+ else
|
|
|
{
|
|
|
- OneDDrawingOptions ops = new OneDDrawingOptions();
|
|
|
- //ops.DrawGraphics = graphics;
|
|
|
- ops.ShowType = (this.Wrap ? BarcodeShowType.Zoom : BarcodeShowType.Show);
|
|
|
- //ops.ImageWidth = this.SimpleShape.Width;
|
|
|
- //ops.ImageHeight = this.SimpleShape.Height;
|
|
|
- ops.ImageWidth = LayoutCommon.MillimeterToPixelDpi(rectangleM.Width, graphics.DpiX);
|
|
|
- ops.ImageHeight = LayoutCommon.MillimeterToPixelDpi(rectangleM.Height, graphics.DpiX);
|
|
|
- ops.DpiX = graphics.DpiX;
|
|
|
- ops.DpiY = graphics.DpiY;
|
|
|
- //string vv = value + "";
|
|
|
- //if (vv.StartsWith("69"))
|
|
|
- try
|
|
|
+ if (isPrint)
|
|
|
{
|
|
|
- //if (this.ItemCode == "ZWLJC")
|
|
|
- //{
|
|
|
- // pic = OneDHelper.GetOneDImage(value.ToString(), ops, OneDFormat.EAN_13);
|
|
|
- //}
|
|
|
- //else
|
|
|
- //{
|
|
|
- // pic = OneDHelper.GetOneDImage(value.ToString(), ops);
|
|
|
- //}
|
|
|
- pic = OneDHelper.GetOneDImage(value.ToString(), ops, GetOneDFormat(this._barcodeFormat));
|
|
|
+ OneDDrawingOptions ops = new OneDDrawingOptions();
|
|
|
+ //ops.DrawGraphics = graphics;
|
|
|
+ ops.ShowType = (this.Wrap ? BarcodeShowType.Zoom : BarcodeShowType.Show);
|
|
|
+ //ops.ImageWidth = this.SimpleShape.Width;
|
|
|
+ //ops.ImageHeight = this.SimpleShape.Height;
|
|
|
+ ops.ImageWidth = LayoutCommon.MillimeterToPixelDpi(rectangleM.Width, graphics.DpiX);
|
|
|
+ ops.ImageHeight = LayoutCommon.MillimeterToPixelDpi(rectangleM.Height, graphics.DpiY);
|
|
|
+ ops.DpiX = graphics.DpiX;
|
|
|
+ ops.DpiY = graphics.DpiY;
|
|
|
+ //string vv = value + "";
|
|
|
+ //if (vv.StartsWith("69"))
|
|
|
+ try
|
|
|
+ {
|
|
|
+ //if (this.ItemCode == "ZWLJC")
|
|
|
+ //{
|
|
|
+ // using (Image pic1 = OneDHelper.GetOneDImage(value.ToString(), ops, OneDFormat.EAN_13))
|
|
|
+ // {
|
|
|
+ // graphics.DrawImage(pic1, rectangleM, ops.ImageRect, GraphicsUnit.Pixel);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // using (Image pic1 = OneDHelper.GetOneDImage(value.ToString(), ops))
|
|
|
+ // {
|
|
|
+ // graphics.DrawImage(pic1, rectangleM, ops.ImageRect, GraphicsUnit.Pixel);
|
|
|
+ // }
|
|
|
+ //}
|
|
|
+ using (Image pic1 = OneDHelper.GetOneDImage(value.ToString(), ops, GetOneDFormat(this._barcodeFormat)))
|
|
|
+ {
|
|
|
+ graphics.DrawImage(pic1, rectangleM, ops.ImageRect, GraphicsUnit.Pixel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
- catch
|
|
|
+
|
|
|
+ Image pic = null;
|
|
|
+ if (!isPrint && this.SimpleShape.Width == this._picCodeWidth &&
|
|
|
+ this.SimpleShape.Height == this._picCodeHeight &&
|
|
|
+ value.ToString() == _picCodeValue)
|
|
|
{
|
|
|
- pic = null;
|
|
|
+ pic = this._picCode;
|
|
|
}
|
|
|
- if (!isPrint)
|
|
|
+
|
|
|
+ if (pic == null)
|
|
|
{
|
|
|
+ OneDDrawingOptions ops = new OneDDrawingOptions();
|
|
|
+ //ops.DrawGraphics = graphics;
|
|
|
+ ops.ShowType = (this.Wrap ? BarcodeShowType.Zoom : BarcodeShowType.Show);
|
|
|
+ //ops.ImageWidth = this.SimpleShape.Width;
|
|
|
+ //ops.ImageHeight = this.SimpleShape.Height;
|
|
|
+ ops.ImageWidth = LayoutCommon.MillimeterToPixelDpi(rectangleM.Width, graphics.DpiX);
|
|
|
+ ops.ImageHeight = LayoutCommon.MillimeterToPixelDpi(rectangleM.Height, graphics.DpiX);
|
|
|
+ ops.DpiX = graphics.DpiX;
|
|
|
+ ops.DpiY = graphics.DpiY;
|
|
|
+ //string vv = value + "";
|
|
|
+ //if (vv.StartsWith("69"))
|
|
|
try
|
|
|
{
|
|
|
- this._picCode?.Dispose();
|
|
|
+ //if (this.ItemCode == "ZWLJC")
|
|
|
+ //{
|
|
|
+ // pic = OneDHelper.GetOneDImage(value.ToString(), ops, OneDFormat.EAN_13);
|
|
|
+ //}
|
|
|
+ //else
|
|
|
+ //{
|
|
|
+ // pic = OneDHelper.GetOneDImage(value.ToString(), ops);
|
|
|
+ //}
|
|
|
+ pic = OneDHelper.GetOneDImage(value.ToString(), ops, GetOneDFormat(this._barcodeFormat));
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
+ pic = null;
|
|
|
+ }
|
|
|
+ if (!isPrint)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ this._picCode?.Dispose();
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ }
|
|
|
+ this._picCode = pic;
|
|
|
+ _picCodeValue = value.ToString();
|
|
|
+ _picCodeWidth = this.SimpleShape.Width;
|
|
|
+ _picCodeHeight = this.SimpleShape.Height;
|
|
|
}
|
|
|
- this._picCode = pic;
|
|
|
- _picCodeValue = value.ToString();
|
|
|
- _picCodeWidth = this.SimpleShape.Width;
|
|
|
- _picCodeHeight = this.SimpleShape.Height;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- if (pic != null)
|
|
|
+ try
|
|
|
{
|
|
|
- //graphics.DrawImage(pic, this.SimpleShape.Bounds, new Rectangle(0, 0, pic.Width, pic.Height), GraphicsUnit.Pixel);
|
|
|
- graphics.DrawImage(pic, this.SimpleShape.Bounds);
|
|
|
+ if (pic != null)
|
|
|
+ {
|
|
|
+ //graphics.DrawImage(pic, this.SimpleShape.Bounds, new Rectangle(0, 0, pic.Width, pic.Height), GraphicsUnit.Pixel);
|
|
|
+ graphics.DrawImage(pic, this.SimpleShape.Bounds);
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
- if (pic != null && isPrint)
|
|
|
+ catch
|
|
|
{
|
|
|
- pic.Dispose();
|
|
|
}
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ if (pic != null && isPrint)
|
|
|
+ {
|
|
|
+ pic.Dispose();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
- return;
|
|
|
}
|
|
|
if (this._itemStyle == ItemStyle.QRCode)
|
|
|
{
|
|
|
@@ -1648,6 +1664,90 @@ namespace Dongke.WinForm.Controls.InvoiceLayout
|
|
|
return QRECLevel.H;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 12位条码补齐校验位生成13位的条码
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="chaine"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static string EAN13(string chaine)
|
|
|
+ {
|
|
|
+ int i;
|
|
|
+ int first;
|
|
|
+ int checkSum = 0;
|
|
|
+ string Barcode = "";
|
|
|
+ bool tableA;
|
|
|
+ //if (Regex.IsMatch(chaine, "^\\d{12}$"))
|
|
|
+ {
|
|
|
+ for (i = 1; i < 12; i += 2)
|
|
|
+ {
|
|
|
+ //System.Diagnostics.Debug.WriteLine(chaine.Substring(i, 1));
|
|
|
+ checkSum += Convert.ToInt32(chaine.Substring(i, 1));
|
|
|
+ }
|
|
|
+ checkSum *= 3;
|
|
|
+ for (i = 0; i < 12; i += 2)
|
|
|
+ {
|
|
|
+ checkSum += Convert.ToInt32(chaine.Substring(i, 1));
|
|
|
+ }
|
|
|
+ chaine += (10 - checkSum % 10) % 10;
|
|
|
+ string Barcode13Digits = chaine.ToString();
|
|
|
+ Barcode = chaine.Substring(0, 1) + (char)(65 + Convert.ToInt32(chaine.Substring(1, 1)));
|
|
|
+ first = Convert.ToInt32(chaine.Substring(0, 1));
|
|
|
+ for (i = 2; i <= 6; i++)
|
|
|
+ {
|
|
|
+ tableA = false;
|
|
|
+ switch (i)
|
|
|
+ {
|
|
|
+ case 2:
|
|
|
+ if (first >= 0 && first <= 3)
|
|
|
+ {
|
|
|
+ tableA = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ if (first == 0 || first == 4 || first == 7 || first == 8)
|
|
|
+ {
|
|
|
+ tableA = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ if (first == 0 || first == 1 || first == 4 || first == 5 || first == 9)
|
|
|
+ {
|
|
|
+ tableA = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 5:
|
|
|
+ if (first == 0 || first == 2 || first == 5 || first == 6 || first == 7)
|
|
|
+ {
|
|
|
+ tableA = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 6:
|
|
|
+ if (first == 0 || first == 3 || first == 6 || first == 8 || first == 9)
|
|
|
+ {
|
|
|
+ tableA = true;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ if (tableA)
|
|
|
+ {
|
|
|
+ Barcode += (char)(65 + Convert.ToInt32(chaine.Substring(i, 1)));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Barcode += (char)(75 + Convert.ToInt32(chaine.Substring(i, 1)));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Barcode += "*";
|
|
|
+ for (i = 7; i <= 12; i++)
|
|
|
+ {
|
|
|
+ Barcode += (char)(97 + Convert.ToInt32(chaine.Substring(i, 1)));
|
|
|
+ }
|
|
|
+ Barcode += "+";
|
|
|
+ }
|
|
|
+ return Barcode;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public class QRCodeWriterMy : Writer
|