/// <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 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() + "\"}"; } }