|
|
@@ -23,7 +23,7 @@ namespace UAS_PRINT
|
|
|
|
|
|
static DataTable dt = new DataTable("VENDORBARCODE_VIEW");
|
|
|
|
|
|
- public static void zplprint(string str,string PrinterName)
|
|
|
+ public static void zplprint(string str, string PrinterName)
|
|
|
{
|
|
|
Dictionary<string, object> data = PrintHelper.ToDictionary(str);
|
|
|
//获取所有的打印格式数据
|
|
|
@@ -57,12 +57,13 @@ namespace UAS_PRINT
|
|
|
//获取所有的打印格式数据
|
|
|
if (data.ContainsKey("data"))
|
|
|
{
|
|
|
- string PrintCode = data["data"].ToString().Replace(" ", "").Replace("\"", "").Replace("\\n","");
|
|
|
+ string PrintCode = data["data"].ToString().Replace(" ", "").Replace("\"", "").Replace("\\n", "");
|
|
|
string PrinterName = data["uid"].ToString().Replace("\"", "");
|
|
|
if (!PrintCode.StartsWith("^XA"))
|
|
|
{
|
|
|
return;
|
|
|
}
|
|
|
+ Console.WriteLine(PrintCode);
|
|
|
PrintHelper.SendStringToPrinter(PrinterName, PrintCode);
|
|
|
PrintDocument pd = new PrintDocument();
|
|
|
pd.PrinterSettings.PrinterName = PrinterName;
|
|
|
@@ -70,51 +71,50 @@ namespace UAS_PRINT
|
|
|
}
|
|
|
else if (data.ContainsKey("exceptionInfo"))
|
|
|
{
|
|
|
- //string PrintCode = data["exceptionInfo"].ToString();
|
|
|
- //MessageBox.Show(PrintCode);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void vendorZplPrint( PrinterList print, string PrinterName,string str) {
|
|
|
+ public static void vendorZplPrint( string str)
|
|
|
+ {
|
|
|
Report Report = new Report();
|
|
|
- RadioButton PRFR = (RadioButton)print.Controls["PRFR"];
|
|
|
- RadioButton PRPIC = (RadioButton)print.Controls["PRPIC"];
|
|
|
- if (PRFR.Checked)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- Report.Load(System.AppDomain.CurrentDomain.BaseDirectory + "GD.frx");
|
|
|
- }
|
|
|
- catch
|
|
|
- {
|
|
|
- MessageBox.Show("未找到可使用的标签文件");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- bitmaps.Clear();
|
|
|
+ string chooseprintername;
|
|
|
Dictionary<string, object> data = PrintHelper.ToDictionary(str);
|
|
|
List<Dictionary<string, object>> parameter = new List<Dictionary<string, object>>();
|
|
|
List<Dictionary<string, object>> barcode = new List<Dictionary<string, object>>();
|
|
|
- parameter = (List<Dictionary<string, object>>)data["parameter"];
|
|
|
- barcode = (List<Dictionary<string, object>>)data["barcode"];
|
|
|
+ try
|
|
|
+ {
|
|
|
+ parameter = (List<Dictionary<string, object>>)data["parameter"];
|
|
|
+ barcode = (List<Dictionary<string, object>>)data["barcode"];
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ MessageBox.Show("打印数据解析异常,请联系管理员进行处理");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ chooseprintername = ((string)data["chooseprintername"]).Replace("\"", "");
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ chooseprintername = "no";
|
|
|
+ }
|
|
|
+ try
|
|
|
+ {
|
|
|
+ Report.Load(System.AppDomain.CurrentDomain.BaseDirectory + "库存条码打印.frx");
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ MessageBox.Show("未找到可使用的标签文件");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
int la_width = int.Parse(parameter.First()["LA_WIDTH"].ToString());
|
|
|
int la_height = int.Parse(parameter.First()["LA_HEIGHT"].ToString());
|
|
|
|
|
|
foreach (var item in barcode)
|
|
|
{
|
|
|
- Bitmap bit = new Bitmap(la_width * 10, la_height * 4);
|
|
|
-
|
|
|
-
|
|
|
- using (Graphics g = Graphics.FromImage(bit))
|
|
|
- {
|
|
|
- //g.CompositingQuality = CompositingQuality.HighQuality;
|
|
|
- //g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
- //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
|
- ////定义一枝画笔
|
|
|
- //Pen pen = new Pen(Color.Black);
|
|
|
- ////用这个画笔在左上角画一个矩形
|
|
|
- //g.DrawRectangle(pen, new Rectangle(10, 10, 50, 20));
|
|
|
foreach (var itemc in item)
|
|
|
{
|
|
|
Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
|
|
|
@@ -145,122 +145,76 @@ namespace UAS_PRINT
|
|
|
itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
}
|
|
|
}
|
|
|
- if (PRFR.Checked)
|
|
|
- {
|
|
|
- DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
|
|
|
- if (!dt.Columns.Contains(itemc.Key))
|
|
|
- dt.Columns.Add(DC);
|
|
|
- }
|
|
|
- if (PRPIC.Checked)
|
|
|
- {
|
|
|
- PrintHelper.Printstring(itemc.Value != null ? itemstr : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()));
|
|
|
- }
|
|
|
+ DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
|
|
|
+ if (!dt.Columns.Contains(itemc.Key))
|
|
|
+ dt.Columns.Add(DC);
|
|
|
}
|
|
|
else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
|
|
|
{
|
|
|
- if (PRFR.Checked)
|
|
|
- {
|
|
|
- DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
|
|
|
- if (!dt.Columns.Contains(itemc.Key))
|
|
|
- dt.Columns.Add(DC);
|
|
|
- }
|
|
|
- if (PRPIC.Checked)
|
|
|
- {
|
|
|
- PrintHelper.DrawBarcode(itemc.Value != null ? itemc.Value.ToString().Replace("\"", "") : " ", ref bit, double.Parse(Sidc["LP_LEFTRATE"].ToString()), double.Parse(Sidc["LP_TOPRATE"].ToString()), double.Parse(Sidc["LP_WIDTH"].ToString()), double.Parse(Sidc["LP_HEIGHT"].ToString()) - 2);
|
|
|
- PrintHelper.Printstring(itemc.Value != null ? itemc.Value.ToString().Replace("\"", "") : " ", int.Parse(Sidc["LP_SIZE"].ToString()), g, int.Parse(Sidc["LP_LEFTRATE"].ToString()), int.Parse(Sidc["LP_TOPRATE"].ToString()) + double.Parse(Sidc["LP_HEIGHT"].ToString()) - 2);
|
|
|
- }
|
|
|
+ DataColumn DC = new DataColumn(itemc.Key, Type.GetType("System.String"));
|
|
|
+ if (!dt.Columns.Contains(itemc.Key))
|
|
|
+ dt.Columns.Add(DC);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- bitmaps.Add(bit);
|
|
|
+
|
|
|
}
|
|
|
- if (PRFR.Checked)
|
|
|
+ foreach (var item in barcode)
|
|
|
{
|
|
|
- foreach (var item in barcode)
|
|
|
+ DataRow dr = dt.NewRow();
|
|
|
+ foreach (var itemc in item)
|
|
|
{
|
|
|
- DataRow dr = dt.NewRow();
|
|
|
- //g.CompositingQuality = CompositingQuality.HighQuality;
|
|
|
- //g.SmoothingMode = SmoothingMode.HighQuality;
|
|
|
- //g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
|
|
- ////定义一枝画笔
|
|
|
- //Pen pen = new Pen(Color.Black);
|
|
|
- ////用这个画笔在左上角画一个矩形
|
|
|
- //g.DrawRectangle(pen, new Rectangle(10, 10, 50, 20));
|
|
|
- foreach (var itemc in item)
|
|
|
+ Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
|
|
|
+ if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
|
|
|
{
|
|
|
- Dictionary<string, object> Sidc = parameter.Find(p => p["LP_NAME"].ToString().Replace(" ", "").Replace("\"", "").ToUpper() == itemc.Key.ToUpper());
|
|
|
- if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "text")
|
|
|
+ string itemstr = "";
|
|
|
+ if (itemc.Value != null)
|
|
|
{
|
|
|
- string itemstr = "";
|
|
|
- if (itemc.Value != null)
|
|
|
+ itemstr = itemc.Value.ToString();
|
|
|
+ while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
|
|
|
{
|
|
|
- itemstr = itemc.Value.ToString();
|
|
|
- while (itemstr.StartsWith("\f") || itemstr.StartsWith("\v") || itemstr.StartsWith("\t") || itemstr.StartsWith("\r") || itemstr.StartsWith("\n"))
|
|
|
- {
|
|
|
- itemstr = itemstr.Remove(0, 2);
|
|
|
- }
|
|
|
- if (itemstr.StartsWith("\""))
|
|
|
- {
|
|
|
- itemstr = itemstr.Remove(0, 1);
|
|
|
- }
|
|
|
- while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
|
|
|
- {
|
|
|
- itemstr = itemstr.Remove(itemstr.Length - 2);
|
|
|
- }
|
|
|
- if (itemstr.EndsWith("\""))
|
|
|
- {
|
|
|
- itemstr = itemstr.Remove(itemstr.Length - 1);
|
|
|
- }
|
|
|
- if (itemstr.Contains("\\\""))
|
|
|
- {
|
|
|
- itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
- Console.WriteLine(itemstr);
|
|
|
- }
|
|
|
+ itemstr = itemstr.Remove(0, 2);
|
|
|
+ }
|
|
|
+ if (itemstr.StartsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(0, 1);
|
|
|
+ }
|
|
|
+ while (itemstr.EndsWith("\f") || itemstr.EndsWith("\v") || itemstr.EndsWith("\t") || itemstr.EndsWith("\r") || itemstr.EndsWith("\n"))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 2);
|
|
|
+ }
|
|
|
+ if (itemstr.EndsWith("\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Remove(itemstr.Length - 1);
|
|
|
+ }
|
|
|
+ if (itemstr.Contains("\\\""))
|
|
|
+ {
|
|
|
+ itemstr = itemstr.Replace("\\\"", "\"");
|
|
|
+ Console.WriteLine(itemstr);
|
|
|
}
|
|
|
- dr[itemc.Key] = itemstr;
|
|
|
- }
|
|
|
- else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
|
|
|
- {
|
|
|
- dr[itemc.Key] = itemc.Value.ToString().Replace("\"", "");
|
|
|
}
|
|
|
+ dr[itemc.Key] = itemstr;
|
|
|
+ }
|
|
|
+ else if (Sidc["LP_VALUETYPE"].ToString().Replace(" ", "").Replace("\"", "") == "barcode")
|
|
|
+ {
|
|
|
+ dr[itemc.Key] = itemc.Value.ToString().Replace("\"", "");
|
|
|
}
|
|
|
- dt.Rows.Add(dr);
|
|
|
}
|
|
|
+ dt.Rows.Add(dr);
|
|
|
}
|
|
|
- if (PRPIC.Checked)
|
|
|
+ try
|
|
|
{
|
|
|
- imagecount = bitmaps.Count;
|
|
|
- ////设置打印机名称
|
|
|
- print.PrintDoc.PrintPage += PrintPage;
|
|
|
- print.PrintDoc.Print();
|
|
|
- }
|
|
|
- if (PRFR.Checked)
|
|
|
- {
|
|
|
- Report.RegisterData(dt, "VENDORBARCODE_VIEW");
|
|
|
- Report.GetDataSource("VENDORBARCODE_VIEW").Enabled = true;
|
|
|
+
|
|
|
+ Report.RegisterData(dt, "BARCODE_PRINT_VIEW");
|
|
|
+ Report.GetDataSource("BARCODE_PRINT_VIEW").Enabled = true;
|
|
|
Report.PrintSettings.ShowDialog = false;
|
|
|
- Report.PrintSettings.Printer = PrinterName;
|
|
|
+ Report.PrintSettings.Printer = chooseprintername;
|
|
|
Report.Print();
|
|
|
- dt.Clear();
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- private static void PrintPage(object sender, PrintPageEventArgs e)
|
|
|
- {
|
|
|
- Image i = bitmaps[index];
|
|
|
- Graphics g = e.Graphics;
|
|
|
- g.DrawImage(i, 4, 10, i.Width, i.Height);
|
|
|
- if (index < imagecount - 1)
|
|
|
- {
|
|
|
- e.HasMorePages = true;
|
|
|
- index++;
|
|
|
}
|
|
|
- else
|
|
|
+ catch
|
|
|
{
|
|
|
- index = 0;
|
|
|
- e.HasMorePages = false;
|
|
|
+ MessageBox.Show("打印出现错误,请检查标签文件选择是否正确");
|
|
|
}
|
|
|
+ dt.Clear();
|
|
|
}
|
|
|
}
|
|
|
}
|