tijian_tieying/web/dccdc.hstmdy/Main.cs
2025-02-20 12:14:39 +08:00

144 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using FastReport;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ZXing;
using ZXing.Common;
namespace dccdc.hstmdy
{
public partial class Main : Form
{
public static FastReport.EnvironmentSettings eSet = new EnvironmentSettings();
public Main()
{
InitializeComponent();
}
private void btn_yl_Click(object sender, EventArgs e)
{
if (!check())
{
return;
}
/*
var b = BarcodeWriter.CreateBarcode("HS" + txt_cyglx.Text + "IN1" + int.Parse(txt_b.Text).ToString().PadLeft(int.Parse(txt_tmyxws.Text)), BarcodeEncoding.Code128);
b= b.AddBarcodeValueTextBelowBarcode();
var tp= b.ToWindowsBitmapStream();
pic_yl.Image = new Bitmap(tp);
*/
EncodingOptions encodeOption = new EncodingOptions();
encodeOption.Height = 60; // 必须制定高度、宽度
encodeOption.Width = 180;
// 2.生成条形码图片并保存
ZXing.BarcodeWriter wr = new BarcodeWriter();
wr.Options = encodeOption;
wr.Format = BarcodeFormat.CODE_128; // 条形码规格EAN13规格12无校验位或13位数字 //把Barcode128 字体设置成null就没有下面的文字了。
encodeOption.PureBarcode = false; // 是否是纯码,如果为 false则会在图片下方显示数字
//System.Threading.Thread.Sleep(100); //间隔
string data = "HS" + txt_cyglx.Text + "IN1" + int.Parse(txt_b.Text).ToString().PadLeft(int.Parse(txt_tmyxws.Text), '0');
Bitmap img = wr.Write(data); // 生成图片
pic_yl.Image = img;
}
private bool check()
{
int itemp;
int ib;
int ie;
if (!int.TryParse(txt_cyglx.Text, out itemp))
{
MessageBox.Show("采样管类型必须是数字");
return false;
}
if (!int.TryParse(txt_tmyxws.Text, out itemp))
{
MessageBox.Show("条码有有效位数必须是数字");
return false;
}
if (!int.TryParse(txt_b.Text, out ib))
{
MessageBox.Show("条码开始编号必须是数字");
return false;
}
if (!int.TryParse(txt_e.Text, out ie))
{
MessageBox.Show("条码结束编号必须是数字");
return false;
}
if (ie < ib)
{
MessageBox.Show("结束编号必须大于开始编号");
return false;
}
//throw new NotImplementedException();
return true;
}
List<zprint> ps = new List<zprint>();
private void Main_Load(object sender, EventArgs e)
{
eSet.ReportSettings.ShowProgress = false;
ps.Add(new zprint { name = "默认打印机", value = "" });
foreach (string p in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
{
ps.Add(new zprint { name = p, value = p });
}
comb_dyj.DataSource = ps;
comb_dyj.SelectedValue = "";
}
class zprint
{
public string name { get; set; }
public string value { get; set; }
}
class OperationResult
{
public int state { get; set; }
public string msg { get; set; }
public string tag { get; set; }
}
private void btn_dy_Click(object sender, EventArgs e)
{
if (!check())
{
return;
}
WebClient wc = new WebClient();
wc.Encoding = System.Text.Encoding.UTF8;
int c = 0;
for (int i = int.Parse(txt_b.Text); i <= int.Parse(txt_e.Text); i++)
{
string result = wc.DownloadString(System.Configuration.ConfigurationManager.AppSettings["uploadurl"] + "?barcode=" + "HS" + txt_cyglx.Text + "IN1" + i.ToString().PadLeft(int.Parse(txt_tmyxws.Text), '0'));
OperationResult op = Newtonsoft.Json.JsonConvert.DeserializeObject<OperationResult>(result);
if(op.state==1)
{
c++;
DataTable dt = new DataTable();
dt.Columns.Add("tm");
DataRow dr = dt.NewRow();
dr["tm"] = "HS" + txt_cyglx.Text + "IN1" + i.ToString().PadLeft(int.Parse(txt_tmyxws.Text),'0');
dt.Rows.Add(dr);
FastReport.Report re = new FastReport.Report();
re.Load(Application.StartupPath + "\\report\\tm.frx");
re.RegisterData(dt, "dt");
re.PrintSettings.Printer = comb_dyj.SelectedValue.ToString();
re.PrintSettings.ShowDialog = false;
re.Print();
}
}
MessageBox.Show("一共成功生成"+c+"个条码");
}
}
}