コード例 #1
0
        private Output CreateOutput(WMSBusinessObject entity, string reportCode, decimal?mandantcode, string printerCode,
                                    IEnumerable <OutputParam> paramExt, out PrinterLogical printerLogical)
        {
            if (string.IsNullOrEmpty(reportCode))
            {
                throw new ArgumentNullException("reportCode");
            }

            Output output = null;

            printerLogical = null;

            //Формируем задание для EPS
            using (var outputManager = GetManager <Output>())
                output = outputManager.New();
            output.Login_R      = WMSEnvironment.Instance.AuthenticatedUser == null ? null : WMSEnvironment.Instance.AuthenticatedUser.GetSignature();
            output.Host_R       = WMSEnvironment.Instance.ClientCode;
            output.OutputStatus = OutputStatus.OS_NEW.ToString();

            //Определяем отчет
            //Используем вариант 2: RR -> SC
            var reportCodeInternal = reportCode;
            //1. RR
            var     reportRedefinition       = GetDefaultReport(entity, output.Host_R, reportCode, mandantcode);
            decimal reportRedefinitionCopies = 1;

            if (reportRedefinition != null && !reportRedefinition.ReportRedefinitionLocked && !string.IsNullOrEmpty(reportRedefinition.ReportRedefinitionReport))
            {
                reportCodeInternal       = reportRedefinition.ReportRedefinitionReport;
                reportRedefinitionCopies = reportRedefinition.ReportRedefinitionCopies;
            }

            Report report;

            using (var reportManager = GetManager <Report>())
                report = reportManager.Get(reportCodeInternal);
            if (report == null)
            {
                return(output);
            }
            if (report.ReportLocked)
            {
                return(output);
            }
            output.EpsHandler = report.EpsHandler;

            //получаем файл отчета
            ReportFile reportFile;

            using (var mgr = IoC.Instance.Resolve <IBaseManager <ReportFile> >())
                reportFile = ((IReportFileManager)mgr).GetByReportFile(report.ReportFile_R);
            if (reportFile != null)
            {
                output.ReportFileSubfolder_R = reportFile.ReportFileSubfolder;
            }

            //Параметры отчета
            if (output.ReportParams == null)
            {
                output.ReportParams = new WMSBusinessCollection <OutputParam>();
            }

            output.ReportParams.Add(new OutputParam
            {
                OutputParamCode  = EpsTaskParams.EpsReport.ToString(),
                OutputParamValue = report.ReportFile_R,
                OutputParamType  = EpsParamType.REP.ToString()
            });

            if (report.ConfigRep != null && entity != null)
            {
                CheckParam(output, entity, report);
            }

            if (paramExt != null)
            {
                foreach (var p in paramExt)
                {
                    output.ReportParams.Add(new OutputParam
                    {
                        OutputParamCode     = p.OutputParamCode,
                        OutputParamValue    = p.OutputParamValue,
                        OutputParamSubvalue = report.ReportFile_R,
                        OutputParamType     = EpsParamType.REP.ToString()
                    });
                }
            }

            //Задача на печать
            if (output.OutputTasks == null)
            {
                output.OutputTasks = new WMSBusinessCollection <OutputTask>();
            }

            var outputTasks = new OutputTask
            {
                OutputTaskCode  = EpsTaskType.OTC_PRINT.ToString(),
                OutputTaskOrder = 1,
                TaskParams      = new WMSBusinessCollection <OutputParam>()
            };

            //Определяем принтер
            //2. SC
            //Если ШК задан, то ищем логический принтер по ШК
            decimal printStreamConfigCopies = 1;

            using (var printerLogicalManager = GetManager <PrinterLogical>())
            {
                if (!string.IsNullOrEmpty(printerCode))
                {
                    var filter = string.Format("({1} = '{0}' OR {2} = '{0}') AND {3} = 0",
                                               printerCode,
                                               SourceNameHelper.Instance.GetPropertySourceName(typeof(PrinterLogical), PrinterLogical.LOGICALPRINTERPropertyName).ToUpper(),
                                               SourceNameHelper.Instance.GetPropertySourceName(typeof(PrinterLogical), PrinterLogical.LogicalPrinterBarCodePropertyName).ToUpper(),
                                               SourceNameHelper.Instance.GetPropertySourceName(typeof(PrinterLogical), PrinterLogical.LogicalPrinterLockedPropertyName).ToUpper());

                    var printers = printerLogicalManager.GetFiltered(filter, GetModeEnum.Partial).ToArray();
                    if (printers.Length > 1)
                    {
                        throw new OperationException("По коду '{0}' найдено более одного принтера: {1}", printerCode, string.Join(",", printers.Select(i => i.GetKey())));
                    }
                    if (printers.Length == 1)
                    {
                        printerLogical = printers[0];
                    }
                }

                //Если ШК задан и нашли логический принтер по ШК, то не используем SC
                if (printerLogical == null)
                {
                    var printStreamConfig = GetDefaultPrinter(output.Host_R, output.Login_R, reportCodeInternal, mandantcode);
                    if (printStreamConfig == null)
                    {
                        return(output);
                    }

                    if (printStreamConfig.PrintStreamLocked)
                    {
                        return(output);
                    }

                    if (string.IsNullOrEmpty(printStreamConfig.LogicalPrinter_R))
                    {
                        return(output);
                    }

                    printStreamConfigCopies = printStreamConfig.PrintStreamCopies;
                    printerLogical          = printerLogicalManager.Get(printStreamConfig.LogicalPrinter_R, GetModeEnum.Partial);
                }
            }

            if (printerLogical == null)
            {
                return(output);
            }

            if (printerLogical.LogicalPrinterLocked)
            {
                return(output);
            }

            //Проверяем физический принтер
            PrinterPhysical printerPhysical;

            using (var printerPhysicalManager = GetManager <PrinterPhysical>())
                printerPhysical = printerPhysicalManager.Get(printerLogical.PhysicalPrinter_R, GetModeEnum.Partial);

            if (printerPhysical == null)
            {
                return(output);
            }

            if (printerPhysical.PhysicalPrinterLocked)
            {
                return(output);
            }

            outputTasks.TaskParams.Add(new OutputParam
            {
                OutputParamCode  = EpsTaskParams.PhysicalPrinter.ToString(),
                OutputParamValue = printerLogical.PhysicalPrinter_R,
                OutputParamType  = EpsParamType.TSK.ToString()
            });

            decimal copies = report.ReportCopies * reportRedefinitionCopies * printStreamConfigCopies * printerLogical.LogicalPrinterCopies;

            outputTasks.TaskParams.Add(new OutputParam
            {
                OutputParamCode  = EpsTaskParams.Copies.ToString(),
                OutputParamValue = copies.ToString(CultureInfo.InvariantCulture),
                OutputParamType  = EpsParamType.TSK.ToString()
            });

            output.OutputTasks.Add(outputTasks);
            return(output);
        }
コード例 #2
0
        private static void FillOutputParams(EpsJob epsJob, string executor, Output output, DataRow row)
        {
            var epsJobId = epsJob.GetKey();

            //Параметры EPS
            var lstReports = new List <Report>();

            if (epsJob.ConfigEps == null)
            {
                _log.DebugFormat("EpsJob.ConfigEps is null in EpsJob '{0}' of Executor '{1}'.", epsJobId, executor);
            }
            else
            {
                if (output.EpsParams == null)
                {
                    output.EpsParams = new WMSBusinessCollection <OutputParam>();
                }

                if (output.ReportParams == null)
                {
                    output.ReportParams = new WMSBusinessCollection <OutputParam>();
                }

                var configs = epsJob.ConfigEps.Where(p => p != null && !string.IsNullOrEmpty(p.EpsConfigParamCode) && !p.EpsConfigLocked);
                foreach (var configEps in configs)
                {
                    var configEpsId = configEps.GetKey();
                    switch (Extensions.To(configEps.EpsConfigParamCode, EpsTaskParams.None))
                    {
                    //case EpsTaskParams.None:
                    //    _log.DebugFormat("Can't convert EpsConfigParamCode '{0}' to enum: EpsTaskParams in ConfigEps '{1}' of EpsJob '{2}' of Executor '{3}'.",
                    //        configEps.EpsConfigParamCode, configEpsId, epsJobId, executor);
                    //    continue;

                    //Параметры отчета
                    case EpsTaskParams.EpsReport:
                        if (!string.IsNullOrEmpty(configEps.EpsConfigValue))
                        {
                            // получаем отчет
                            Report report;

                            // TODO: сделать поддержку маски для вложенных коллекций
                            // формируем шаблон получения отчета
                            //                                var attrEntity = FilterHelper.GetAttrEntity<Report>(
                            //                                    Report.ReportCodePropertyName
                            //                                    , Report.ReportFile_RPropertyName
                            //                                    , Report.ReportLockedPropertyName
                            //                                    , Report.ConfigRepPropertyName
                            //                                    , Report.ReportCopiesPropertyName
                            //                                    );
                            //
                            //                                var configAttrEntity = FilterHelper.GetAttrEntity<ReportCfg>(
                            //                                    ReportCfg.EpsConfigParamCodePropertyName,
                            //                                    ReportCfg.EpsConfigValuePropertyName
                            //
                            //                                    );
                            //
                            //                                var cfgAttr = TypeDescriptor.GetProperties(typeof(Report))
                            //                                    .OfType<DynamicPropertyDescriptor>()
                            //                                    .Single(p => p.Name == Report.ConfigRepPropertyName)
                            //                                    .SourceName;
                            //                                var replaceWith = string.Format("<{0}>{1}</{0}>", cfgAttr, configAttrEntity);
                            //
                            //                                attrEntity = attrEntity.Replace(string.Format("<{0} />", cfgAttr), replaceWith);
                            //
                            //                                // получаем отчет
                            using (var mgr = IoC.Instance.Resolve <IBaseManager <Report> >())
                                report = mgr.Get(configEps.EpsConfigValue);    //, attrEntity);

                            if (report == null)
                            {
                                continue;
                            }

                            if (report.ReportLocked)
                            {
                                _log.WarnFormat("Report '{0}' is locked in ConfigEps '{1}' of EpsJob '{2}' of Executor '{3}'.",
                                                configEps.EpsConfigValue, configEpsId, epsJobId, executor);
                                continue;
                            }

                            if (string.IsNullOrEmpty(report.ReportFile_R))
                            {
                                _log.WarnFormat("Undefined report file name in report '{0}' of ConfigEps '{1}' of EpsJob '{2}' of Executor '{3}'.",
                                                configEps.EpsConfigValue, configEpsId, epsJobId, executor);
                                continue;
                            }

                            //получаем файл отчета
                            ReportFile reportFile;
                            using (var mgr = IoC.Instance.Resolve <IBaseManager <ReportFile> >())
                                reportFile = ((IReportFileManager)mgr).GetByReportFile(report.ReportFile_R);
                            if (reportFile != null)
                            {
                                output.ReportFileSubfolder_R = reportFile.ReportFileSubfolder;
                            }

                            lstReports.Add(report);
                            output.ReportParams.Add(new OutputParam
                            {
                                OutputParamCode  = configEps.EpsConfigParamCode,
                                OutputParamValue = report.ReportFile_R,
                                OutputParamType  = EpsParamType.REP.ToString()
                            });

                            if (report.ConfigRep == null)
                            {
                                _log.DebugFormat("Report.ConfigRep is null in report '{0}' of ConfigEps '{1}' of EpsJob '{2}' of Executor '{3}'.",
                                                 configEps.EpsConfigValue, configEpsId, epsJobId, executor);
                            }
                            else
                            {
                                foreach (var configRep in report.ConfigRep.Where(p => p != null && !p.EpsConfigLocked))
                                {
                                    switch (Extensions.To(configRep.EpsConfigParamCode, EpsTaskParams.None))
                                    {
                                    case EpsTaskParams.ResultReportFile:
                                    case EpsTaskParams.ChangeODBC:
                                        break;

                                    case EpsTaskParams.None:         //Variable
                                        if (string.IsNullOrEmpty(configRep.EpsConfigParamCode))
                                        {
                                            continue;
                                        }
                                        break;

                                    default:
                                        _log.DebugFormat("Illegal EpsConfigParamCode '{0}'.", configRep.EpsConfigParamCode);
                                        break;
                                    }

                                    var name = configRep.EpsConfigParamCode;
                                    if (!string.IsNullOrEmpty(name) && name[0] == '{' && name[name.Length - 1] == '}')
                                    {
                                        name = name.Substring(1, name.Length - 2);
                                    }

                                    var val = configRep.EpsConfigValue;
                                    // если передали строку, пытаемся из нее взять значение парметра
                                    if (row != null)
                                    {
                                        var col = row.Table.Columns.Cast <DataColumn>().FirstOrDefault(i => Extensions.EqIgnoreCase(i.ColumnName, name));
                                        if (col != null)
                                        {
                                            val = row[(DataColumn)col] == null ? null : row[(DataColumn)col].ToString();
                                        }
                                    }

                                    output.ReportParams.Add(new OutputParam
                                    {
                                        OutputParamCode     = name,
                                        OutputParamValue    = val,
                                        OutputParamSubvalue = report.ReportFile_R,
                                        OutputParamType     = EpsParamType.REP.ToString()
                                    });
                                }
                            }
                        }
                        break;

                    default:
                        output.EpsParams.Add(new OutputParam
                        {
                            OutputParamCode  = configEps.EpsConfigParamCode,
                            OutputParamValue = configEps.EpsConfigValue,
                            OutputParamType  = EpsParamType.EPS.ToString()
                        });
                        break;
                    }
                }
                if (!output.EpsParams.Any())
                {
                    output.EpsParams = null;
                }
                if (!output.ReportParams.Any())
                {
                    output.ReportParams = null;
                }
            }

            //Задачи
            if (epsJob.Job2Task == null)
            {
                _log.DebugFormat("EpsJob.Job2Tas is null in EpsJob '{0}' of Executor '{1}'.", epsJobId, executor);
            }
            else
            {
                if (output.OutputTasks == null)
                {
                    output.OutputTasks = new WMSBusinessCollection <OutputTask>();
                }

                using (var epsTaskManager = IoC.Instance.Resolve <IBaseManager <EpsTask> >())
                    using (var printerLogicalManager = IoC.Instance.Resolve <IBaseManager <PrinterLogical> >())
                        using (var printerPhysicalManager = IoC.Instance.Resolve <IBaseManager <PrinterPhysical> >())
                            foreach (var job2Task in epsJob.Job2Task.Where(p => p != null && !string.IsNullOrEmpty(p.EpsTask2JobTaskCode)))
                            {
                                PrinterLogical printerLogical = null;
                                var            epsTask        = epsTaskManager.Get(job2Task.EpsTask2JobTaskCode);
                                if (epsTask == null)
                                {
                                    _log.DebugFormat("Can't get EpsTask by key '{0}'.", job2Task.EpsTask2JobTaskCode);
                                    continue;
                                }

                                if (epsTask.TaskLocked)
                                {
                                    _log.DebugFormat("Task '{0}' is locked.", epsTask.GetKey());
                                    continue;
                                }

                                EpsTaskType taskType;
                                try
                                {
                                    taskType = ConvertToEpsTaskType(epsTask.TaskType);
                                }
                                catch (Exception ex)
                                {
                                    _log.Error(ex.Message, ex);
                                    continue;
                                }

                                if (taskType == EpsTaskType.None)
                                {
                                    _log.Debug("Undefined EPS Task type.");
                                    continue;
                                }

                                var outputTasks = new OutputTask
                                {
                                    OutputTaskCode  = taskType.ToString(),
                                    OutputTaskOrder = job2Task.Task2JobOrder,
                                    TaskParams      = new WMSBusinessCollection <OutputParam>()
                                };

                                if (epsTask.ConfigTsk != null)
                                {
                                    foreach (var configTsk in epsTask.ConfigTsk.Where(p => p != null && !string.IsNullOrEmpty(p.EpsConfigParamCode) && !p.EpsConfigLocked))
                                    {
                                        var epsConfigParamCode = configTsk.EpsConfigParamCode;
                                        var paramCod           = Extensions.To(epsConfigParamCode, EpsTaskParams.None);
                                        var epsConfigValue     = configTsk.EpsConfigValue;

                                        switch (paramCod)
                                        {
                                        case EpsTaskParams.PhysicalPrinter:
                                            continue;

                                        case EpsTaskParams.None:
                                            if (Extensions.EqIgnoreCase(epsConfigParamCode, EpsLogicalPrinter, true))
                                            {
                                                //Задан логический принтер
                                                if (!string.IsNullOrEmpty(epsConfigValue))
                                                {
                                                    printerLogical = printerLogicalManager.Get(epsConfigValue);
                                                    if (printerLogical == null)
                                                    {
                                                        _log.DebugFormat("Can't get PrinterLogical by key '{0}'.", configTsk.EpsConfigValue);
                                                        continue;
                                                    }

                                                    //Проверяем физический принтер
                                                    var printerPhysical = printerPhysicalManager.Get(printerLogical.PhysicalPrinter_R);
                                                    if (printerPhysical == null)
                                                    {
                                                        var message = string.Format("Can't get PrinterPhysical by key '{0}'.", printerLogical.PhysicalPrinter_R);
                                                        _log.Debug(message);
                                                        continue;
                                                    }

                                                    if (printerPhysical.PhysicalPrinterLocked)
                                                    {
                                                        _log.DebugFormat("Physical printer '{0}' is locked.", printerPhysical.GetKey());
                                                        continue;
                                                    }

                                                    epsConfigParamCode = EpsTaskParams.PhysicalPrinter.ToString();
                                                    epsConfigValue     = printerLogical.PhysicalPrinter_R;
                                                }
                                            }
                                            else
                                            {
                                                _log.DebugFormat("Can't convert EpsConfigParamCode '{0}' to enum: EpsTaskParams.", configTsk.EpsConfigParamCode);
                                                continue;
                                            }
                                            break;
                                        }

                                        outputTasks.TaskParams.Add(new OutputParam
                                        {
                                            OutputParamCode  = epsConfigParamCode,
                                            OutputParamValue = epsConfigValue,
                                            OutputParamType  = EpsParamType.TSK.ToString()
                                        });
                                    }

                                    //Проверяем наличие физ. принтера
                                    if (taskType == EpsTaskType.OTC_PRINT)
                                    {
                                        if (!outputTasks.TaskParams.Any(p => p != null && Extensions.To(p.OutputParamCode, EpsTaskParams.None) == EpsTaskParams.PhysicalPrinter))
                                        {
                                            _log.DebugFormat("PhysicalPrinter parameter is not present for task '{0}'.", job2Task.GetKey());
                                        }

                                        //Добавляем copies для задачи Print
                                        if (lstReports != null)
                                        {
                                            var copies = outputTasks.TaskParams.Where(p => p != null && Extensions.To(p.OutputParamCode, EpsTaskParams.None) == EpsTaskParams.Copies).ToArray();
                                            if (copies.Any()) //Удаляем
                                            {
                                                foreach (var p in copies)
                                                {
                                                    outputTasks.TaskParams.Remove(p);
                                                }

                                                //Определяем новые copies с учетом отчета и принтера
                                                var copy = copies.Select(p => Extensions.To(p.OutputParamValue, 0)).First();
                                                foreach (var report in lstReports.Where(p => p != null && !string.IsNullOrEmpty(p.ReportFile_R)))
                                                {
                                                    outputTasks.TaskParams.Add(new OutputParam
                                                    {
                                                        OutputParamCode     = EpsTaskParams.Copies.ToString(),
                                                        OutputParamValue    = (report.ReportCopies * copy * (printerLogical == null ? 0 : printerLogical.LogicalPrinterCopies)).ToString(CultureInfo.InvariantCulture),
                                                        OutputParamSubvalue = report.ReportFile_R,
                                                        OutputParamType     = EpsParamType.TSK.ToString()
                                                    });
                                                }
                                            }
                                        }
                                    }
                                }
                                if (outputTasks.TaskParams.Count == 0)
                                {
                                    outputTasks.TaskParams = null;
                                }

                                output.OutputTasks.Add(outputTasks);
                            }

                if (output.OutputTasks.Count == 0)
                {
                    output.OutputTasks = null;
                }
            }
        }