chenxy 6 yıl önce
ebeveyn
işleme
050280aa15

+ 273 - 5
DK.Service/BarcodePrintService/BarcodePrintLogic.cs

@@ -31,7 +31,7 @@ namespace Dongke.IBOSS.PRD.Service.BarcodePrintService
     public static class BarcodePrintLogic
     public static class BarcodePrintLogic
     {
     {
         /// <summary>
         /// <summary>
-        /// 打印条码(扫描工序时自动打印、或经过打印工序后补打)
+        /// 打印条码
         /// </summary>
         /// </summary>
         /// <param name="barcode">条码</param>
         /// <param name="barcode">条码</param>
         /// <param name="copies">打印份数</param>
         /// <param name="copies">打印份数</param>
@@ -500,11 +500,279 @@ namespace Dongke.IBOSS.PRD.Service.BarcodePrintService
         }
         }
 
 
         // 服务码打印、补打 (打印时重新生成onlycode,补打时onlycode不能为空)
         // 服务码打印、补打 (打印时重新生成onlycode,补打时onlycode不能为空)
-        //FUN_CMN_GetOnlyCodeBySeq(:new.accountid
-        //                                          ,:new.GroutingDailyDetailID
-        //                                          ,:new.createuserid)
 
 
+        /// <summary>
+        /// 打印条码 3车间
+        /// 0:工序打印(根据工号绑定打印机的打印类型选择打印模版,要求onlycode已存在),
+        /// 1:直接打印(根据工号绑定打印机的打印类型选择打印模版,重新分配onlycode),
+        /// 2:补打(根据选择打印机的打印类型选择打印模版,要求onlycode已存在)
+        /// </summary>
+        /// <param name="barcode">条码</param>
+        /// <param name="copies">打印份数</param>
+        /// <param name="printerID">工序打印时:null;补打时:打印机ID</param>
+        /// <param name="sUserInfo"></param>
+        /// <returns></returns>
+        public static ServiceResultEntity PrintBarcode_3C(string barcode, int copies, int? printerID, SUserInfo sUserInfo, int printWay)
+        {
+            int err_lable = 0;
+            IDBTransaction oracleTrConn = null;
+            string printerName = null;
+            int printtype = 0;
+            LayoutBox layoutBox = null;
+            try
+            {
+                ServiceResultEntity sre = new ServiceResultEntity();
+
+                System.Drawing.Printing.PrinterSettings.StringCollection installedPrinters =
+                    System.Drawing.Printing.PrinterSettings.InstalledPrinters;
+                if (installedPrinters.Count < 1)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = "服务器没有安装打印驱动";
+                    return sre;
+                }
+
+                oracleTrConn = ClsDbFactory.CreateDBTransaction(Basics.DataAccess.DataBaseType.ORACLE, DataManager.ConnectionString);
+                oracleTrConn.Connect();
+                List<OracleParameter> parameters = new List<OracleParameter>();
+
+                if (printerID == null)
+                {
+                    // 打印
+                    printWay = 1;
+                    string sqlPrinterName =
+                       "SELECT p.printername, p.printtype\n" +
+                       "  FROM tp_mst_user u\n" +
+                       " INNER JOIN tp_mst_barcodeprinter p\n" +
+                       "    ON p.printerid = u.barcodeprinterid\n" +
+                       " WHERE u.userid = :userid\n" +
+                       "   AND p.valueflag = '1'";
+                    OracleParameter[] pps = new OracleParameter[]{
+                        new OracleParameter(":userid", OracleDbType.Int32, sUserInfo.UserID, ParameterDirection.Input),
+                    };
+                    //printerName = oracleTrConn.GetSqlResultToStr(sqlPrinterName, pps);
+                    DataTable dataTable = oracleTrConn.GetSqlResultToDt(sqlPrinterName, pps);
+                    if (dataTable == null || dataTable.Rows.Count == 0)
+                    {
+                        sre.Status = Constant.ServiceResultStatus.Other;
+                        sre.Message = "此工号没有关联打印机";
+                        return sre;
+                    }
+                    printerName = dataTable.Rows[0]["printername"] + "";
+                    if (string.IsNullOrWhiteSpace(printerName) ||
+                        !int.TryParse(dataTable.Rows[0]["printtype"] + "", out printtype))
+                    {
+                        sre.Status = Constant.ServiceResultStatus.Other;
+                        sre.Message = "此工号没有关联打印机类型";
+                        return sre;
+                    }
+                }
+
+                // 补打时,获得打印机名
+                if (printerID.HasValue)
+                {
+                    string sqlPrinterName =
+                       "SELECT p.printername, p.printtype\n" +
+                       "  FROM tp_mst_barcodeprinter p\n" +
+                       " WHERE p.printerID = :printerID\n" +
+                       "   AND p.valueflag = '1'";
+
+                    parameters.Clear();
+                    parameters.Add(new OracleParameter(":printerID", OracleDbType.Int32, printerID.Value, ParameterDirection.Input));
+
+                    //printerName = oracleTrConn.GetSqlResultToStr(sqlPrinterName, parameters.ToArray());
+                    DataTable dataTable = oracleTrConn.GetSqlResultToDt(sqlPrinterName, parameters.ToArray());
+                    if (dataTable == null || dataTable.Rows.Count == 0)
+                    {
+                        sre.Status = Constant.ServiceResultStatus.Other;
+                        sre.Message = "选择的打印机不存在";
+                        return sre;
+                    }
+                    printerName = dataTable.Rows[0]["printername"] + "";
+                    if (string.IsNullOrWhiteSpace(printerName) ||
+                        !int.TryParse(dataTable.Rows[0]["printtype"] + "", out printtype))
+                    {
+                        sre.Status = Constant.ServiceResultStatus.Other;
+                        sre.Message = "此打印机没有关联类型";
+                        return sre;
+                    }
+                }
+
+                //if (string.IsNullOrWhiteSpace(printerName))
+                //{
+                //    sre.Status = Constant.ServiceResultStatus.Other;
+                //    sre.Message = "此用户没有设置打印机";
+                //    return sre;
+                //}
+
+                bool hasPrinter = false;
+                foreach (string item in installedPrinters)
+                {
+                    if (item == printerName)
+                    {
+                        hasPrinter = true;
+                        break;
+                    }
+                }
+
+                if (!hasPrinter)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = "服务器没有连接相应打印机【" + printerName + "】";
+                    return sre;
+                }
+
+                // 打印
+                //LayoutBox layoutBox = new LayoutBox();
+                layoutBox = new LayoutBox();
+
+                layoutBox.Name = "layoutBox";
+                layoutBox.LayoutMode = LayoutMode.Preview;
+                // 设置打印机
+                layoutBox.PrinterSettings.PrinterName = printerName;
+                layoutBox.NumberOfCopies = copies;
+
+                string message = layoutBox.CheckPrintSettingIn(PrintType.Print);
+                if (!string.IsNullOrWhiteSpace(message))
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = message;
+                    return sre;
+                }
 
 
-        // 
+                if (printerID != null)
+                {
+                    string sqlString = @"select FUN_CMN_GetBarCode(:barcode,null,:accountid) From DUAL";
+                    OracleParameter[] paras1 = new OracleParameter[]{
+                                    new OracleParameter(":barcode",OracleDbType.Varchar2, barcode,ParameterDirection.Input),
+                                    new OracleParameter(":accountid",OracleDbType.Int32, sUserInfo.AccountID,ParameterDirection.Input),
+                                };
+                    barcode = oracleTrConn.GetSqlResultToStr(sqlString, paras1);
+                }
+
+                // 获取打印数据
+                parameters.Clear();
+                parameters.Add(new OracleParameter("in_Barcode", OracleDbType.NVarchar2, barcode, ParameterDirection.Input));
+                parameters.Add(new OracleParameter("in_AccountID", OracleDbType.Int32, sUserInfo.AccountID, ParameterDirection.Input));
+                parameters.Add(new OracleParameter("in_UserID", OracleDbType.Int32, sUserInfo.UserID, ParameterDirection.Input));
+                parameters.Add(new OracleParameter("in_PrintTypeID", OracleDbType.Int32, printtype, ParameterDirection.Input));
+                parameters.Add(new OracleParameter("in_PrintWay", OracleDbType.Int32, printWay, ParameterDirection.Input));
+                parameters.Add(new OracleParameter("out_Status", OracleDbType.Int32, ParameterDirection.Output));
+                parameters.Add(new OracleParameter("out_Message", OracleDbType.NVarchar2, 2000, null, ParameterDirection.Output));
+                parameters.Add(new OracleParameter("out_LayoutData", OracleDbType.RefCursor, ParameterDirection.Output));
+                parameters.Add(new OracleParameter("out_PrintData", OracleDbType.RefCursor, ParameterDirection.Output));
+
+                DataSet data = oracleTrConn.ExecStoredProcedure("PRO_PM_GETBarCodePrintDATA_3C", parameters.ToArray());
+
+                int status = Convert.ToInt32(parameters[3].Value.ToString());
+                if (status < 0)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = parameters[4].Value.ToString();
+                    return sre;
+                }
+
+                if (data == null || data.Tables.Count != 2)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = "没有打印数据";
+                    return sre;
+                }
+
+                DataTable layoutData = data.Tables[0];
+                DataTable printData = data.Tables[1];
+
+                if (printData.Rows.Count == 0)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = "此条码不存在";
+                    return sre;
+                }
+
+                if (layoutData.Rows.Count == 0)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = string.Format("此产品类别【{0}】或商标【{1}】没有对应的打印模板",
+                        printData.Rows[0]["goodstypename"],
+                        printData.Rows[0]["logoname"]
+                        );
+                    return sre;
+                }
+
+                //if (printerID == null && printData.Rows.Count > 0)
+                //{
+                //    int goodsCopies = Convert.ToInt32(printData.Rows[0]["printcopies"]);
+                //    if (goodsCopies > 0)
+                //    {
+                //        copies = goodsCopies;
+                //        layoutBox.NumberOfCopies = copies;
+                //    }
+                //}
+
+                int layoutID = Convert.ToInt32(layoutData.Rows[0]["LayoutID"]);
+                byte[] bytes = layoutData.Rows[0]["LayoutData"] as byte[];
+                if (bytes != null)
+                {
+                    //try
+                    //{
+                    //    layoutBox.ReadLayout(bytes);
+                    //}
+                    //catch (Exception ex)
+                    //{
+                    //    throw new Exception("ReadLayout", ex);
+                    //}
+                    layoutBox.ReadLayout(bytes);
+                }
+
+                bool isPrint = false;
+                layoutBox.PrintDataSource = printData;
+                layoutBox.PrintAreaVisible = false;
+                layoutBox.PrintBackground = false;
+                isPrint = layoutBox.Print(false);
+
+                if (!isPrint)
+                {
+                    sre.Status = Constant.ServiceResultStatus.Other;
+                    sre.Message = "打印失败";
+                    return sre;
+                }
+                sre.Result = printData;
+
+                oracleTrConn.Commit();
+
+                // 打印记录
+                SetPrintLog(layoutID, printData, sUserInfo, printtype, printWay);
+
+                return sre;
+            }
+            catch (Exception ex)
+            {
+                //if (oracleTrConn != null &&
+                //       oracleTrConn.ConnState == ConnectionState.Open)
+                //{
+                //    oracleTrConn.Rollback();
+                //}
+                // TODO 异常分析
+                Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
+                                   "PrintBarcode --- " + err_lable,
+                                   "barcode  --  " + barcode + System.Environment.NewLine +
+                                   "copies  --  " + copies + System.Environment.NewLine +
+                                   "printerID  --  " + printerID + System.Environment.NewLine +
+                                   "printerName  --  " + printerName + System.Environment.NewLine
+                                   ,
+                                   DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"),
+                                   Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
+                throw ex;
+            }
+            finally
+            {
+                if (oracleTrConn != null &&
+                    oracleTrConn.ConnState == ConnectionState.Open)
+                {
+                    oracleTrConn.Disconnect();
+                }
+                layoutBox?.Dispose();
+            }
+        }
     }
     }
 }
 }

+ 2 - 2
WCF.Service/WCF.Contracts/IPDAModule.cs

@@ -2086,8 +2086,8 @@ namespace Dongke.IBOSS.PRD.WCF.Contracts
         [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest
         [WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest
             , ResponseFormat = WebMessageFormat.Json
             , ResponseFormat = WebMessageFormat.Json
             , RequestFormat = WebMessageFormat.Json)]
             , RequestFormat = WebMessageFormat.Json)]
-        ActionResult PrintBarcodeLayout(string accountCode, string userCode, string userPassword, string sessionKey
-            , string barcode, int copies, int printerID);
+        ActionResult PrintBarcodeLayout(string accountCode, string userCode, string userPassword, string sessionKey,
+            string barcode, int copies, int printerID, int printWay = 2);
 
 
         #endregion PDA条码打印
         #endregion PDA条码打印
 
 

+ 1 - 1
WCF.Service/WCF.Contracts/IPDAModuleGet.cs

@@ -2086,7 +2086,7 @@ namespace Dongke.IBOSS.PRD.WCF.Contracts
             , ResponseFormat = WebMessageFormat.Json
             , ResponseFormat = WebMessageFormat.Json
             , RequestFormat = WebMessageFormat.Json)]
             , RequestFormat = WebMessageFormat.Json)]
         ActionResult PrintBarcodeLayoutGet(string accountCode, string userCode, string userPassword, string sessionKey
         ActionResult PrintBarcodeLayoutGet(string accountCode, string userCode, string userPassword, string sessionKey
-            , string barcode, int copies, int printerID);
+            , string barcode, int copies, int printerID, int printWay = 2);
 
 
         #endregion PDA条码打印
         #endregion PDA条码打印
 
 

+ 12 - 8
WCF.Service/WCF.Services/PDAModuleService.cs

@@ -726,9 +726,11 @@ namespace Dongke.IBOSS.PRD.WCF.Services
 						}
 						}
 						else
 						else
 						{
 						{
-							ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(dtProductionData.Rows[0]["barcode"].ToString(),
-									   procedureInfo.BarCodePrintCopies, null, sUserInfo);
-							if (sre.Status != Constant.ServiceResultStatus.Success)
+							//ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(dtProductionData.Rows[0]["barcode"].ToString(),
+							//		   procedureInfo.BarCodePrintCopies, null, sUserInfo);
+                            ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode_3C(dtProductionData.Rows[0]["barcode"].ToString(),
+                                       procedureInfo.BarCodePrintCopies, null, sUserInfo, 0);
+                            if (sre.Status != Constant.ServiceResultStatus.Success)
 							{
 							{
 								actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 								actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 								actionResult.Message = sre.Message;
 								actionResult.Message = sre.Message;
@@ -7758,8 +7760,8 @@ namespace Dongke.IBOSS.PRD.WCF.Services
 		/// <param name="userPassword"></param>
 		/// <param name="userPassword"></param>
 		/// <param name="sessionKey"></param>
 		/// <param name="sessionKey"></param>
 		/// <returns></returns>
 		/// <returns></returns>
-		public ActionResult PrintBarcodeLayout(string accountCode, string userCode, string userPassword, string sessionKey
-			, string barcode, int copies, int printerID)
+		public ActionResult PrintBarcodeLayout(string accountCode, string userCode, string userPassword, string sessionKey,
+            string barcode, int copies, int printerID, int printWay=2)
 		{
 		{
 			ActionResult actionResult = new ActionResult();
 			ActionResult actionResult = new ActionResult();
 			try
 			try
@@ -7773,9 +7775,11 @@ namespace Dongke.IBOSS.PRD.WCF.Services
 					return actionResult;
 					return actionResult;
 				}
 				}
 
 
-				ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(barcode,
-									   copies, printerID, sUserInfo);
-				if (sre.Status != Constant.ServiceResultStatus.Success)
+				//ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(barcode,
+				//					   copies, printerID, sUserInfo);
+                ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode_3C(barcode,
+                           copies, printerID, sUserInfo, printWay);
+                if (sre.Status != Constant.ServiceResultStatus.Success)
 				{
 				{
 					actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 					actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 					actionResult.Message = sre.Message;
 					actionResult.Message = sre.Message;

+ 11 - 7
WCF.Service/WCF.Services/PDAModuleServiceGet.cs

@@ -698,9 +698,11 @@ namespace Dongke.IBOSS.PRD.WCF.Services
 						}
 						}
 						else
 						else
 						{
 						{
-							ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(dtProductionData.Rows[0]["barcode"].ToString(),
-									   procedureInfo.BarCodePrintCopies, null, sUserInfo);
-							if (sre.Status != Constant.ServiceResultStatus.Success)
+                            //ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(dtProductionData.Rows[0]["barcode"].ToString(),
+                            //		   procedureInfo.BarCodePrintCopies, null, sUserInfo);
+                            ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode_3C(dtProductionData.Rows[0]["barcode"].ToString(),
+                                       procedureInfo.BarCodePrintCopies, null, sUserInfo, 0);
+                            if (sre.Status != Constant.ServiceResultStatus.Success)
 							{
 							{
 								actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 								actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 								actionResult.Message = sre.Message;
 								actionResult.Message = sre.Message;
@@ -7719,7 +7721,7 @@ namespace Dongke.IBOSS.PRD.WCF.Services
 		/// <param name="sessionKey"></param>
 		/// <param name="sessionKey"></param>
 		/// <returns></returns>
 		/// <returns></returns>
 		public ActionResult PrintBarcodeLayoutGet(string accountCode, string userCode, string userPassword, string sessionKey
 		public ActionResult PrintBarcodeLayoutGet(string accountCode, string userCode, string userPassword, string sessionKey
-			, string barcode, int copies, int printerID)
+			, string barcode, int copies, int printerID, int printWay=2)
 		{
 		{
 			ActionResult actionResult = new ActionResult();
 			ActionResult actionResult = new ActionResult();
 			try
 			try
@@ -7733,9 +7735,11 @@ namespace Dongke.IBOSS.PRD.WCF.Services
 					return actionResult;
 					return actionResult;
 				}
 				}
 
 
-				ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(barcode,
-									   copies, printerID, sUserInfo);
-				if (sre.Status != Constant.ServiceResultStatus.Success)
+				//ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode(barcode,
+				//					   copies, printerID, sUserInfo);
+                ServiceResultEntity sre = BarcodePrintLogic.PrintBarcode_3C(barcode,
+                           copies, printerID, sUserInfo, printWay);
+                if (sre.Status != Constant.ServiceResultStatus.Success)
 				{
 				{
 					actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 					actionResult.Status = (int)Constant.ServiceResultStatus.Other;
 					actionResult.Message = sre.Message;
 					actionResult.Message = sre.Message;