/// <summary> /// 获取打印机状态 /// </summary> /// <param name="Type">打印机型号</param> /// <returns></returns> public string GetStatusDYJ(string Type) { int state = -99; string msg = ""; try { state = Msprint.GetState(Type); if (state != 0) { if (state == 1) { msg = "打印机未连接,或未初始化,请联系管理员"; //......\n错误码[001] } if (state == 2) { msg = "色带已用完,请联系管理员"; //......\n错误码[002] } if (state == 3) { msg = "本机病历本已发完,请联系管理员"; //......\n错误码[003] } if (state == 4) { msg = "病历本堵塞,请联系管理员"; //......\n错误码[004] } if (state == 5) { msg = "本机病历本已经发完,请联系管理员"; //......\n错误码[005] } if (state == 6) { msg = "打印头温度异常,请联系管理员"; //......\n错误码[006] } if (state == 7) { msg = "抬压头异常,请联系管理员"; //......\n错误码[007] } if (state == 8) { msg = "打印机正在忙,请稍候重试"; //......\n错误码[008] } Msprint.Close(Type); return("{\"Code\":" + state + ",\"msg\":\"" + msg + "\"}"); } return("{\"Code\":" + state + ",\"msg\":\"" + msg + "\"}"); } catch (Exception e) { return("{\"Code\":-3,\"msg\":\"获取打印机状态异常!" + e.Message + "\"}"); } }
/// <summary> /// 直接打印 /// </summary> /// <param name="Type">打印机型号</param> /// <param name="BMPPathAndFileName">打印内容</param> /// <returns></returns> public string PrintOne(string Type, string BMPPathAndFileName) { try { int iret = Msprint.PrintBmp8(Type, BMPPathAndFileName);//开始打印 return("{\"Code\":" + iret + ",\"msg\":\"\"}"); } catch { return("{\"Code\":-7,\"msg\":\"直接打印失败\"}"); //"{\"Code\":-7,\"msg\":\"" + ee.Message.ToString() + "\"}"; } }
/// <summary> /// 打开打印机 /// </summary> /// <param name="Type">打印机型号</param> /// <returns></returns> public string OpenDYJ(string Type) { int ret = -99; try { ret = Msprint.Open(Type); if (ret != 0) { return("{\"Code\":-5,\"msg\":\"打开打印机串口失败\"}"); } } catch { //"{\"Code\":-6,\"msg\":\"" + ee.Message.ToString() + "\"}"; return("{\"Code\":-6,\"msg\":\"打开打印机串口失败\"}"); } return("{\"Code\":" + ret + ",\"msg\":\"打开打印机成功\"}"); }
/// <summary> /// 关闭打印机 /// </summary> /// <param name="Type">打印机型号</param> /// <returns></returns> public string CloseDYJ(string Type) { int ret = -99; try { ret = Msprint.Close(Type); if (ret != 0) { return("{\"Code\":-5,\"msg\":\"关闭打印机串口失败\"}"); } } catch { return("{\"Code\":-6,\"msg\":\"关闭打印机失败\"}"); //"{\"Code\":-6,\"msg\":\"" + ee.Message + "\"}"; } return("{\"Code\":" + ret + ",\"msg\":\"关闭打印机成功\"}"); }
/// <summary> /// 空打印 /// </summary> /// <param name="Type"></param> /// <returns></returns> public string PrintEmpty(string Type) { try { int iret = -99; Font font2 = new Font("微软雅黑", 22, FontStyle.Regular); Bitmap Img = new Bitmap(new Bitmap(100, 100)); Graphics DrawingBoard = Graphics.FromImage(Img); DrawingBoard.FillRectangle(Brushes.White, new Rectangle(0, 0, 100, 100)); DrawingBoard.DrawString("", font2, Brushes.Black, new PointF((float)(8), (float)(10))); string BMPPath = "D:/ZZJ/Debug/cache/"; string BMPPathAndFileName = string.Format("{0}{1}.Bmp", BMPPath, "0098030479"); try { Directory.CreateDirectory(BMPPath); using (Bitmap bm = Convert24bppTo1bpp(Img.Clone() as Bitmap)) { bm.RotateFlip(RotateFlipType.Rotate90FlipNone); bm.Save(BMPPathAndFileName, ImageFormat.Bmp); } } catch { return("{\"Code\":-5,\"msg\":\"转格式时异常\"}"); } //开始打印 iret = Msprint.PrintBmp8("STT420", BMPPathAndFileName); return("{\"Code\":" + iret + ",\"msg\":\"\"}"); } catch { return("{\"Code\":-7,\"msg\":\"打印失败\"}"); } }
/// <summary> /// 打印方法 /// </summary> /// <param name="Type">打印机型号</param> /// <param name="PatientName">患者姓名</param> /// <param name="Sex">性别</param> /// <param name="DOB">出生日期</param> /// <param name="CardNo">卡号</param> /// <param name="Phone">手机号</param> /// <param name="Address">地址</param> /// <param name="Nation">名族</param> /// <returns></returns> public string Print(string Type, string PatientName, string Sex, string DOB, string CardNo, string Phone, string Address, string Nation) { //生成条形码 Bitmap TM = Generate2(CardNo, 250, 100); try { int iret = -99; Font font = new Font("微软雅黑", 25, FontStyle.Regular); Font font2 = new Font("微软雅黑", 22, FontStyle.Regular); Font font3 = new Font("微软雅黑", 18, FontStyle.Regular); Font fontAddr = new Font("微软雅黑", 28, FontStyle.Regular); Bitmap Img = new Bitmap(new Bitmap(1400, 1450)); Graphics DrawingBoard = Graphics.FromImage(Img); DrawingBoard.FillRectangle(Brushes.White, new Rectangle(0, 0, 1400, 1450)); #region 画图 //姓名 int h = 0; int w = 0; //条码 DrawingBoard.DrawImage(TM, new PointF((float)(5 + w), (float)(105 + h))); DrawingBoard.DrawString(CardNo, font3, Brushes.Black, new PointF((float)(55 + w), (float)(205 + h))); DrawingBoard.DrawString("顺德区妇幼保健院", font2, Brushes.Black, new PointF((float)(8 + w), (float)(235 + h))); //姓名 性别 DrawingBoard.DrawString(PatientName, font, Brushes.Black, new PointF((float)(190 + w), (float)(930 + h))); DrawingBoard.DrawString(Sex, font, Brushes.Black, new PointF((float)(540 + w), (float)(930 + h))); if (DOB.Length == 8) { DrawingBoard.DrawString(DOB.Substring(0, 4), font, Brushes.Black, new PointF((float)(820 + w), (float)(930 + h))); DrawingBoard.DrawString(DOB.Substring(4, 2), font, Brushes.Black, new PointF((float)(975 + w), (float)(930 + h))); DrawingBoard.DrawString(DOB.Substring(6, 2), font, Brushes.Black, new PointF((float)(1080 + w), (float)(930 + h))); } if (Address.Length >= 12) { Address = Address.Substring(0, 12); } //DrawingBoard.DrawString(Nation, font, Brushes.Black, new PointF((float)(180 + w), (float)(1030 + h))); DrawingBoard.DrawString(Address, font, Brushes.Black, new PointF((float)(265 + w), (float)(1290 + h))); DrawingBoard.DrawString(Phone, font, Brushes.Black, new PointF((float)(855 + w), (float)(1290 + h))); string BMPPath = "D:/ZZJ/Debug/cache/"; string BMPPathAndFileName = string.Format("{0}{1}.Bmp", BMPPath, CardNo);//ZZJCore.Public_Var.SerialNumber流水号不能有汉字 try { Directory.CreateDirectory(BMPPath); using (Bitmap bm = Convert24bppTo1bpp(Img.Clone() as Bitmap)) { bm.RotateFlip(RotateFlipType.Rotate90FlipNone); bm.Save(BMPPathAndFileName, ImageFormat.Bmp); } } catch { return("{\"Code\":-5,\"msg\":\"转格式时异常\"}"); } #endregion //开始打印 iret = Msprint.PrintBmp8(Type, BMPPathAndFileName); return("{\"Code\":" + iret + ",\"msg\":\"\"}"); } catch (Exception ex) { //StreamWriter sw1 = new StreamWriter(@"D:/ZZJ/Debug/cache\" + CardNo + ".txt",true); //sw1.Write(ex.Message.ToString()); //sw1.Close(); return("{\"Code\":-7,\"msg\":\"打印失败\"}"); //"{\"Code\":-7,\"msg\":\"" + ex.Message.ToString() + "\"}"; } }