Пример #1
0
        private void Print(string sn, bool mandatory)
        {
            if (!template.Open(tempFile))
            {
                printResultCallback?.Invoke("", 0, "打开Excel模板失败");
                errorCallback?.Invoke(template.ErrorString);
                return;
            }

            var controller = new ModifyTestInfo();

            printResultCallback?.Invoke(sn, 0, $"正在获取{sn}数据");
            var last = controller.GetLastTestInfo(_productID, _stationID, sn, _printPass);

            if (!last.Status)
            {
                printResultCallback?.Invoke(sn, 2, $"获取{sn}数据失败:{last.Message}");
                return;
            }
            var info = controller.GetTestInfo(last.Data);

            if (!info.Status)
            {
                printResultCallback?.Invoke(sn, 2, $"获取{sn}数据失败:{info.Message}");
                return;
            }
            if (!string.IsNullOrEmpty(_workID))
            {
                if (!_workID.Equals(info.Data.WorkInfo.WorkOrderID, StringComparison.OrdinalIgnoreCase))
                {
                    printResultCallback?.Invoke(sn, 2, $"核对{sn}数据失败:当前工单为{info.Data.WorkInfo.WorkOrderID}");
                    return;
                }
            }

            try
            {
                var tempData = new TemplateData();
                tempData.SetData(info.Data, exData);

                printResultCallback?.Invoke(sn, 0, $"正在制作{sn}模板");
                if (!template.Compile(tempData))
                {
                    printResultCallback?.Invoke(sn, 2, $"{sn}模板制作失败:{template.ErrorString}");
                    return;
                }
                if (!_onlySave)
                {
                    printResultCallback?.Invoke(sn, 0, $"正在打印{sn}模板");
                    if (!template.Print(mandatory))
                    {
                        printResultCallback?.Invoke(sn, 2, $"{sn}打印失败:{template.ErrorString}");
                        return;
                    }
                }


                var savePath = $"{_savePath}/{sn}.xls";
                if (System.IO.File.Exists(savePath))
                {
                    AppFramework.Context.Execute(new Action(() =>
                    {
                        AppFramework.Context.ShowError($"{sn}重复打印,将覆盖原来的模板。");
                    }));
                }

                if (!template.SaveAs($"{_savePath}/{sn}.xls"))
                {
                    printResultCallback?.Invoke(sn, 2, $"{sn}保存:{template.ErrorString}");
                    return;
                }
                if (listTemp != null)
                {
                    listTemp.Compile(tempData);
                    if (!_onlySave)
                    {
                        listTemp.Print(mandatory);
                    }
                    listTemp.SaveAs($"{_savePath}/{prodcutCode}.xls");
                }
            }
            catch (Exception ex)
            {
                printResultCallback?.Invoke(sn, 2, $"打印{sn}失败:{ex.Message}");
                return;
            }

            printResultCallback?.Invoke(sn, 1, $"打印{sn}成功");
        }