qinqi hace 2 años
padre
commit
fac8edd7b0

+ 144 - 8
DK.Service/PMModuleLogic/PMModuleLogicDAL.cs

@@ -25,6 +25,7 @@ using Dongke.IBOSS.PRD.Service.CMNModuleService;
 using Dongke.IBOSS.PRD.Service.DataModels;
 using Dongke.IBOSS.PRD.WCF.DataModels;
 using Newtonsoft.Json.Linq;
+using Dongke.WinForm.Controls.InvoiceLayout;
 
 using Oracle.ManagedDataAccess.Client;
 using static Dongke.IBOSS.PRD.Service.SAPHegiiDataService.SAPDataLogic;
@@ -11196,20 +11197,155 @@ namespace Dongke.IBOSS.PRD.Service.PMModuleLogic
                     //三车间打印拆开后,通过工控屏装配后调用打印接口 152:3#条码打印
                     if (procedure.ProcedureID ==  152)
                     {
+                        string printerName = null;
+                        int printtype = 0;
                         try
                         {
-                            BarcodePrintLogic.PrintBarcode_3C(productionData.Barcode, 1, null, sUserInfo, 0); 
+                            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.Message;
+                            }
+
+                            List<OracleParameter> parameters = new List<OracleParameter>();
+
+                                    
+                            // 打印
+                            //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.Message;
+                            }
+                            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.Message;
+                            }
+                                    
+                            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.Message;
+                            }
+
+                            string sqlString = @"select FUN_CMN_GetBarCode(:barcode,null,:accountid) From DUAL";
+                            OracleParameter[] paras1 = new OracleParameter[]{
+                                new OracleParameter(":barcode",OracleDbType.Varchar2, productionData.Barcode,ParameterDirection.Input),
+                                new OracleParameter(":accountid",OracleDbType.Int32, sUserInfo.AccountID,ParameterDirection.Input),
+                            };
+                            string 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, 1, 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[5].Value.ToString());
+                            if (status < 0)
+                            {
+                                sre.Status = Constant.ServiceResultStatus.Other;
+                                sre.Message = parameters[6].Value.ToString();
+                                return sre.Message;
+                            }
+
+                            if (data == null || data.Tables.Count != 2)
+                            {
+                                sre.Status = Constant.ServiceResultStatus.Other;
+                                sre.Message = "没有打印数据";
+                                return sre.Message;
+                            }
+
+                            DataTable layoutData = data.Tables[0];
+                            DataTable printData = data.Tables[1];
+
+                            if (printData.Rows.Count == 0)
+                            {
+                                sre.Status = Constant.ServiceResultStatus.Other;
+                                sre.Message = "此条码不存在";
+                                return sre.Message;
+                            }
+
+                            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.Message;
+                            }
+
+
+                            int layoutID = Convert.ToInt32(layoutData.Rows[0]["LayoutID"]);
+                            byte[] bytes = layoutData.Rows[0]["LayoutData"] as byte[];
+
+                            //生成电子票据
+                            InvoiceLayoutPrinter.Print(printerName, Convert.ToInt16(1), bytes, printData.Rows[0], printData);
+
+                            sre.Result = printData;
+
+                            // 打印记录
+                            BarcodePrintLogic.SetPrintLog(layoutID, printData, sUserInfo, printtype, 1, printerName);
+
+                            return sre.Message;
                         }
                         catch (Exception ex)
                         {
-                            OutputLog.TraceLog(LogPriority.Error, "",
-                                            System.Reflection.MethodBase.GetCurrentMethod().Name,
-                                            ex.ToString(),
-                                            LocalPath.LogExePath); 
-                            errMsg = "条码打印异常";
-                            return errMsg;
+                            Dongke.IBOSS.PRD.Basics.Library.OutputLog.TraceLog(Dongke.IBOSS.PRD.Basics.Library.LogPriority.Debug,
+                                                "PrintBarcode_3C",
+                                                "barcode  --  " + productionData.Barcode + System.Environment.NewLine +
+                                                "copies  --  " + 1 + System.Environment.NewLine +
+                                                "printerID  --  " + "" + System.Environment.NewLine +
+                                                "printerName  --  " + printerName + System.Environment.NewLine +
+                                                "printType  --  " + printtype + System.Environment.NewLine +
+                                                "printWay  --  " + 1,
+                                                ex.ToString(),
+                                                Dongke.IBOSS.PRD.Basics.Library.LocalPath.LogExePath + @"printdebug\");
+                            throw ex;
                         }
-                        
                     }
                 }
                  

+ 23 - 9
DK.Service/PMModuleLogic/PMModuleLogicPartial.cs

@@ -2346,15 +2346,29 @@ namespace Dongke.IBOSS.PRD.Service.PMModuleLogic
 					//}
 					foreach (DataRow item in ds.Tables[0].Rows)
 					{
-						sqlString = "select * from " +
-									"(" +
-									"select procedureid, arriveprocedureid,ltrim(sys_connect_by_path(procedureid,'->')||'->'||arriveprocedureid) sybp from " +
-									"( " +
-									" 	  select * from TP_PC_PROCEDUREFLOW where arriveprocedureid<>:missProcedureid and flowflag=2 " +
-									")" +
-									"	   start with procedureid=:missProcedureid" +
-									"	  connect by nocycle procedureid=prior arriveprocedureid" +
-									") where arriveprocedureid=:judgeProcedureid ";
+						//sqlString = "select * from " +
+						//			"(" +
+						//			"select procedureid, arriveprocedureid,ltrim(sys_connect_by_path(procedureid,'->')||'->'||arriveprocedureid) sybp from " +
+						//			"( " +
+						//			" 	  select * from TP_PC_PROCEDUREFLOW where arriveprocedureid<>:missProcedureid and flowflag=2 " +
+						//			")" +
+						//			"	   start with procedureid=:missProcedureid" +
+						//			"	  connect by nocycle procedureid=prior arriveprocedureid" +
+						//			") where arriveprocedureid=:judgeProcedureid ";
+
+						sqlString = "SELECT procedureid\n" +
+						"              ,arriveprocedureid\n" +
+						"              ,ltrim(sys_connect_by_path(procedureid, '->') || '->' || arriveprocedureid) sybp\n" +
+						"  FROM (SELECT procedureid\n" +
+						"              ,arriveprocedureid\n" +
+						"          FROM (SELECT *\n" +
+						"                  FROM tp_pc_procedureflow\n" +
+						"                 WHERE arriveprocedureid <> :missProcedureid\n" +
+						"                   AND flowflag = 2)\n" +
+						"         WHERE arriveprocedureid = :judgeProcedureid )\n" +
+						"         START WITH procedureid = :missProcedureid\n" +
+						"        CONNECT BY nocycle procedureid = PRIOR arriveprocedureid";
+						 
 						paras = new OracleParameter[]{
 									new OracleParameter(":missProcedureid",OracleDbType.Int32,Convert.ToInt32(item["ProcedureID"]),ParameterDirection.Input),
 									new OracleParameter(":judgeProcedureid",OracleDbType.Int32,produceid,ParameterDirection.Input),