using FastReport; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Net; using System.Reflection; using System.Text; using System.Threading; using System.Windows.Forms; namespace dccdc.Selfhelp { public partial class frm_bgdy : Form { public frm_bgdy() { InitializeComponent(); } public static FastReport.EnvironmentSettings eSet = new EnvironmentSettings(); private void frm_bgdy_MouseClick(object sender, MouseEventArgs e) { Rectangle rect = new Rectangle(30, 30, 170, 56); if (rect.Contains(e.Location)) { this.Close(); } } private void frm_bgdy_MouseMove(object sender, MouseEventArgs e) { Rectangle rect = new Rectangle(30, 30, 170, 56); if (rect.Contains(e.Location)) { Cursor = Cursors.Hand; } else { Cursor = Cursors.Default; } } private void frm_bgdy_Load(object sender, EventArgs e) { eSet.ReportSettings.ShowProgress = false; //int a = extend.test(1, 2); this.TopLevel = true; int port = 0; string sport = System.Configuration.ConfigurationManager.AppSettings["commPort"]; if (!int.TryParse(sport, out port)) { port = 1; } try { extend.close_comm(); extend.open_comm(port); extend.send_comm(13); } catch (Exception ex) { Status s = new Status(ex.Message); s.ShowDialog(); this.Close(); } } /// /// 没有读到卡 /// int readcard = 0; /// /// 身份证信息 /// IDCardInfo info = new IDCardInfo(); int returncode = 0; int messagecode = 0; string errmsg = ""; private void t_readcard() { //MessageBox.Show("1"); IDCardData CardMsg = new IDCardData(); //extend.Init(); int code = 0; byte[] photoPath = new byte[260]; int r = extend.Read_IDCard(ref CardMsg, ref photoPath[0], ref code); if (r == 0 || r == 1) { info.Name = CardMsg.Name; info.Nation = CardMsg.Nation; info.IDCardNo = CardMsg.IDCardNo; info.GrantDept = CardMsg.GrantDept; info.Born = CardMsg.Born; info.Address = CardMsg.Address; info.UserLifeEnd = CardMsg.UserLifeEnd; info.UserLifeBegin = CardMsg.UserLifeBegin; info.Sex = CardMsg.Sex; info.reserved = CardMsg.reserved; info.PhotoFileName = CardMsg.PhotoFileName; info.FPInfo = System.Text.Encoding.ASCII.GetString(photoPath); info.FPInfo = info.FPInfo.Replace("\0", ""); if (!string.IsNullOrEmpty(info.PhotoFileName) && System.IO.File.Exists(info.PhotoFileName)) { FileStream fs = new FileStream(info.PhotoFileName, FileMode.Open); byte[] bs = new byte[fs.Length]; fs.Read(bs, 0, bs.Length); fs.Close(); info.Photo = System.Drawing.Image.FromStream(new MemoryStream(bs)); File.Delete(info.PhotoFileName); } extend.Close_IDCard(); readcard = 1; } else { readcard = 1; returncode = r; messagecode = code; extend.send_comm(14); } } private void t_readCard_Tick(object sender, EventArgs e) { t_readCard.Enabled = false; try { //int r = extend.Read_IDCard(ref CardMsg, ref photoPath[0], ref code); readcard = 0; Thread t = new Thread(t_readcard); t.Start(); for (int i = 0; i <= 10 * 100; i++) { Thread.CurrentThread.Join(10); Application.DoEvents(); if (readcard == 1) { break; } } t.Abort(); if (readcard != 1) { extend.Close_IDCard(); Status s = new Status("没有检测到身份证"); s.ShowDialog(); s.Close(); this.Close(); return; } int r = returncode; int code = messagecode; if (r == 0 || r == 1) { /* IDCardInfo info = new IDCardInfo(); info.Name = CardMsg.Name; info.Nation = CardMsg.Nation; info.IDCardNo = CardMsg.IDCardNo; info.GrantDept = CardMsg.GrantDept; info.Born = CardMsg.Born; info.Address = CardMsg.Address; info.UserLifeEnd = CardMsg.UserLifeEnd; info.UserLifeBegin = CardMsg.UserLifeBegin; info.Sex = CardMsg.Sex; info.reserved = CardMsg.reserved; info.PhotoFileName = CardMsg.PhotoFileName; info.FPInfo = System.Text.Encoding.ASCII.GetString(photoPath); info.FPInfo = info.FPInfo.Replace("\0", ""); if (!string.IsNullOrEmpty(info.PhotoFileName) && System.IO.File.Exists(info.PhotoFileName)) { FileStream fs = new FileStream(info.PhotoFileName, FileMode.Open); byte[] bs = new byte[fs.Length]; fs.Read(bs, 0, bs.Length); fs.Close(); info.Photo = System.Drawing.Image.FromStream(new MemoryStream(bs)); File.Delete(info.PhotoFileName); } */ Status s = new Status("正在查询您的报告信息请稍后", false); s.Show(); Application.DoEvents(); WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; string jsonData = wc.DownloadString(extend.URL + "zzj/getBGXX?id=" + info.IDCardNo); var list = Newtonsoft.Json.JsonConvert.DeserializeObject>(jsonData); if (list.Count == 0) { //MessageBox.Show("aaaaa"); s.update("没有您的健康证明"); Application.DoEvents(); Thread.Sleep(2000); s.Close(); this.Close(); return; } foreach (var m in list) { extend.open_comm(3); extend.send_comm(15); /* * if (rows[i].physical_category == '公共场所') { if (window.top.Formium.external.Print.finit( "zzjtjzm_gg.frx")) { window.top.Formium.external.Print.PrintJKZM_GG(rows[i].id, "false"); } } else if (rows[i].physical_category == '食品从业') { if (window.top.Formium.external.Print.finit( "zzjtjzm_sp.frx")) { window.top.Formium.external.Print.PrintJKZM_SP(rows[i].id, "false"); } } else if (rows[i].physical_category == '药品从业') { if (window.top.Formium.external.Print.finit( "zzjtjzm_yp.frx")) { window.top.Formium.external.Print.PrintJKZM_YP(rows[i].id, "false"); } }*/ if (m.physical_category == "食品从业") { try { jsonData = wc.DownloadString(extend.URL + "professional/getjkzm_sp?zzj=1&ids=" + m.id); } catch (Exception ex) { MessageBox.Show(ex.Message); } DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); dt.Columns.Add("photo", typeof(byte[])); dt.Columns.Add("yzewm", typeof(byte[])); foreach (DataRow dr in dt.Rows) { dr["photo"] = Convert.FromBase64String(dr["img"].ToString()); dr["yzewm"] = Convert.FromBase64String(dr["ewm"].ToString()); } FastReport.Report re = new FastReport.Report(); re.Load(Application.StartupPath + "\\report\\zzjtjzm_sp.frx"); re.RegisterData(dt, "table"); re.PrintSettings.ShowDialog = false; try { re.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (m.physical_category == "公共场所") { try { jsonData = wc.DownloadString(extend.URL + "professional/getjkzm_gg?zzj=1&ids=" + m.id); } catch (Exception ex) { MessageBox.Show(ex.Message); } DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); dt.Columns.Add("photo", typeof(byte[])); dt.Columns.Add("yzewm", typeof(byte[])); foreach (DataRow dr in dt.Rows) { dr["photo"] = Convert.FromBase64String(dr["img"].ToString()); dr["yzewm"] = Convert.FromBase64String(dr["ewm"].ToString()); } FastReport.Report re = new FastReport.Report(); re.Load(Application.StartupPath + "\\report\\zzjtjzm_gg.frx"); //re.Load(_reportPath); re.RegisterData(dt, "table"); re.PrintSettings.ShowDialog = false; try { re.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else if (m.physical_category == "药品从业") { try { jsonData = wc.DownloadString(extend.URL + "professional/getjkzm_yp?zzj=1&ids=" + m.id); } catch (Exception ex) { MessageBox.Show(ex.Message); } DataTable dt = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonData); dt.Columns.Add("photo", typeof(byte[])); dt.Columns.Add("yzewm", typeof(byte[])); foreach (DataRow dr in dt.Rows) { dr["photo"] = Convert.FromBase64String(dr["img"].ToString()); dr["yzewm"] = Convert.FromBase64String(dr["ewm"].ToString()); } FastReport.Report re = new FastReport.Report(); //re.Load(_reportPath); re.Load(Application.StartupPath + "\\report\\zzjtjzm_yp.frx"); re.RegisterData(dt, "table"); re.PrintSettings.ShowDialog = false; try { re.Print(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } /* var loger = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); for (int i = 0; i < 20; i++) { try { string path = @"win32_printer.DeviceId='" + readc + "'"; ManagementObject printer = new ManagementObject(path); printer.Get(); string strRow = ""; //ret = (PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value); PropertyDataCollection.PropertyDataEnumerator pde = printer.Properties.GetEnumerator(); while (pde.MoveNext()) { strRow += pde.Current.Name + " : " + Newtonsoft.Json.JsonConvert.SerializeObject(pde.Current.Value) + "\r\n"; //MessageBox.Show(pde.Current.Name + " : " + pde.Current.Value); //显示的是 属性名 : 属性值 的形式 } } catch (Exception ex) { loger.Info("A4打印机异常:" + ex.Message); } Thread.Sleep(500); Application.DoEvents(); } */ s.update("打印体检证明成功!"); Application.DoEvents(); Thread.Sleep(2000); extend.send_comm(16); s.Close(); this.Close(); //extend.close_comm(); } else { if (r != -1) { Status s = new Status("读取身份证失败:" + code + "_" + r); s.ShowDialog(); } this.Close(); } } catch (Exception ex) { Status s = new Status(ex.Message); s.ShowDialog(); this.Close(); } finally { extend.send_comm(14); extend.Close_IDCard(); } } private void frm_bgdy_FormClosing(object sender, FormClosingEventArgs e) { extend.Close_IDCard(); extend.send_comm(14); extend.send_comm(16); extend.close_comm(); } private void label1_Click(object sender, EventArgs e) { } } }