Esempio n. 1
0
        private bool SetTemplateNamedSubStringValueToPart4(BarTender.Format btFormat, List <string> list, OilSampleEntryModel data)
        {
            if (list.Contains("ProductionDate4"))
            {
                btFormat.SetNamedSubStringValue("ProductionDate4", data.ProductionDate.ToString("yyyy-MM-dd"));
            }
            if (list.Contains("ProductionModel4"))
            {
                btFormat.SetNamedSubStringValue("ProductionModel4", data.ProductionModel);
            }
            if (list.Contains("ProductionName4"))
            {
                btFormat.SetNamedSubStringValue("ProductionName4", data.ProductionName);
            }
            if (list.Contains("ExpirationMonth4"))
            {
                btFormat.SetNamedSubStringValue("ExpirationMonth4", data.ExpirationMonth);
            }
            if (list.Contains("BatchNo4"))
            {
                btFormat.SetNamedSubStringValue("BatchNo4", data.BatchNo);
            }
            if (list.Contains("CheckNo4"))
            {
                btFormat.SetNamedSubStringValue("CheckNo4", data.CheckNo);
            }
            if (list.Contains("RoughWeight4"))
            {
                btFormat.SetNamedSubStringValue("RoughWeight4", data.RoughWeight);
            }
            if (list.Contains("WeightPerBucket4"))
            {
                btFormat.SetNamedSubStringValue("WeightPerBucket4", data.WeightPerBucket.ToString());
            }

            return(true);
        }
Esempio n. 2
0
 public void WithParam(OilSampleEntryModel entry, Action <int, OilSampleEntryModel> callBack)
 {
     OilSampleEntry = entry;
     _callBack      = callBack;
 }
Esempio n. 3
0
        public string BarTenderOilSamplePrint(BarTenderPrintConfigModel config, OilSampleEntryModel data)
        {
            string weightPerBucket     = string.Empty;
            string weightPerBucketLast = string.Empty;
            string printerName         = config.PrinterName;
            string templateName        = config.TemplateFullName;

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                // 获取批次号(先获取打印记录的,如果没有就获取新的)
                string batchNo = new OilSampleService().GetOilSampleEntryBatchNo(data.Id);
                if (string.IsNullOrEmpty(batchNo))
                {
                    var seq = new CommonService().GetCurrentDateNextSerialNumber(data.ProductionDate, "OilSamplePrintBatchNo");
                    batchNo = data.ProductionDate.ToString("yyMMdd") + seq.ToString().PadLeft(3, '0');
                }

                //int printCount = data.CurrencyPrintCount % config.TemplatePerPage == 0 ? data.CurrencyPrintCount / config.TemplatePerPage : data.CurrencyPrintCount / config.TemplatePerPage + 1;

                BarTender.Format btFormat = btApp.Formats.Open(templateName, false, "");
                btFormat.PrintSetup.Printer = printerName;

                string nameValues = "," + btFormat.NamedSubStrings.GetAll("|", ",");
                Regex  rg         = new Regex(@",([^|]*)", RegexOptions.IgnoreCase);
                var    list       = GetTendarFieldName(nameValues.Replace(Environment.NewLine, ""), rg);
                btFormat.PrintSetup.NumberSerializedLabels = 1;
                btFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
                weightPerBucket     = data.WeightPerBucket.ToString();
                weightPerBucketLast = data.WeightPerBucket.ToString();

                //for (int i = 0; i < printCount; i++)
                //{
                // 最后一张(已打张数+本次打印数量 >=总张数  的最后一页)
                if (data.TotalWeight % data.WeightPerBucket != 0 && data.PrintedCount + data.CurrencyPrintCount >= data.PrintTotalCount)
                {
                    weightPerBucketLast = (Math.Round(data.TotalWeight % data.WeightPerBucket, 2)).ToString();
                }
                if (list.Contains("ProductionDate"))
                {
                    btFormat.SetNamedSubStringValue("ProductionDate", data.ProductionDate.ToString("yyyy-MM-dd"));
                }
                if (list.Contains("ProductionModel"))
                {
                    btFormat.SetNamedSubStringValue("ProductionModel", data.ProductionModel);
                }
                if (list.Contains("ProductionName"))
                {
                    btFormat.SetNamedSubStringValue("ProductionName", data.ProductionName);
                }
                if (list.Contains("ExpirationMonth"))
                {
                    btFormat.SetNamedSubStringValue("ExpirationMonth", data.ExpirationMonth);
                }
                if (list.Contains("BatchNo"))
                {
                    btFormat.SetNamedSubStringValue("BatchNo", batchNo);
                }
                if (list.Contains("CheckNo"))
                {
                    btFormat.SetNamedSubStringValue("CheckNo", data.CheckNo);
                }
                if (list.Contains("RoughWeight"))
                {
                    btFormat.SetNamedSubStringValue("RoughWeight", data.RoughWeight);
                }

                if (list.Contains("WeightPerBucket"))
                {
                    btFormat.SetNamedSubStringValue("WeightPerBucket", weightPerBucket);
                }

                if (list.Contains("WeightPerBucketLast"))
                {
                    btFormat.SetNamedSubStringValue("WeightPerBucketLast", weightPerBucketLast);
                }

                var s = btFormat.PrintOut(false, false);
                //}

                btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                return(batchNo);
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
Esempio n. 4
0
        public OilSamplePrintViewModel()
        {
            OilSampleFlows             = new ObservableCollection <OilSampleFlowModel>();
            OilSampleFlowLogs          = new ObservableCollection <OilSampleFlowPrintLogModel>();
            OilSampleEntries           = new ObservableCollection <OilSampleEntryModel>();
            OilSamplePaperNames        = new ObservableCollection <PageSizeModel>();
            ExpressPaperNames          = new ObservableCollection <PageSizeModel>();
            OilSampleEntrySelectedItem = new OilSampleEntryModel();
            InitData();


            ExpressPrintCommand           = new DelegateCommand(PrintExpress);
            ExpressPrintConfigSaveCommand = new DelegateCommand(SaveExpressPrintConfig);

            OilSamplePrintCommand                   = new DelegateCommand(PrintOilSample);
            OilSamplePrintConfigSaveCommand         = new DelegateCommand(SaveOilSamplePrintConfig);
            OilSampleFlowLogModifyCommand           = new DelegateCommand(ModifyOilSampleFlowLog);
            OilSampleFlowSelectionChangedCommand    = new DelegateCommand(ChangeOilSampleFlowSelection);
            OilSampleFlowLogSelectionChangedCommand = new DelegateCommand(ChangeOilSampleFlowLogSelection);
            OilSampleEntryModifyCommand             = new DelegateCommand(ModifyOilSampleEntry);

            OilSampleTemplateSelectCommand = new DelegateCommand(SelectOilSampleTemplate);
            ExpressTemplateSelectCommand   = new DelegateCommand(SelectExpressTemplate);

            TemplateSelectionChangedCommand = new DelegateCommand((obj) =>
            {
                OilSampleTemplateSelectedItem           = (BarTenderTemplateModel)obj;
                OilSamplePrintConfig.TemplatePerPage    = OilSampleTemplateSelectedItem.TemplatePerPage;
                OilSamplePrintConfig.TemplateFileName   = OilSampleTemplateSelectedItem.TemplateFileName;
                OilSamplePrintConfig.TemplateFullName   = OilSampleTemplateSelectedItem.TemplateFullName;
                OilSamplePrintConfig.TemplateFolderPath = OilSampleTemplateSelectedItem.TemplateFolderPath;
            });

            OilSampleEntryPrintLogModifyCommand = new DelegateCommand(ModifyOilSampleEntryPrintLog);
            OilSampleEntryCheckedCommand        = new DelegateCommand(CheckOilSampleEntry);
            OilSampleEntryMergePrintCommand     = new DelegateCommand(MergePrintOilSampleEntry);
            OilSampleEntryOrderPrintCommand     = new DelegateCommand(OrderPrintOilSampleEntry);
            DealingFlowShowCommand = new DelegateCommand(ShowDealingFlow);
            DealedFlowShowCommand  = new DelegateCommand(ShowDealedFlow);

            A4PrintCommand = new DelegateCommand((obj) =>
            {
                int printCount     = 0;
                int previousCounts = 0;

                string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration);
                if (string.IsNullOrEmpty(msg))
                {
                    if (OilSampleEntries.Count > 0)
                    {
                        int templatePerPage = PrintConfiguration.TemplateSelectedItem.TemplatePerPage;
                        var data            = new ObservableCollection <OilSampleEntryModel>();
                        foreach (var item in OilSampleEntries)
                        {
                            if (item.CurrencyPrintCount > 0)
                            {
                                printCount += item.CurrencyPrintCount;

                                if (printCount >= templatePerPage)
                                {
                                    item.CurrencyPrintCount = templatePerPage - previousCounts;
                                    printCount = templatePerPage;
                                    data.Add(item);
                                    break;
                                }
                                else
                                {
                                    previousCounts += item.CurrencyPrintCount;
                                    data.Add(item);
                                }
                            }
                        }
                        if (printCount == 0 || printCount > templatePerPage)
                        {
                            MessageBox.Show("本流程明细已经全部打印完毕");
                            return;
                        }
                        //string result = new PrintService().BarTenderPrintA4(OilSampleEntries, PrintConfiguration, printCount);
                        //if (string.IsNullOrEmpty(result))
                        //{
                        //    // 重新加载明细
                        //    OilSampleEntries.Clear();
                        //    OilSampleFlowLogs.Clear();
                        //    _oilSampleService.GetOilSampleEntries(OilSampleFlowSelectedItem.Id).ToList().ForEach(x => OilSampleEntries.Add(x));
                        //    _oilSampleService.GetOilSampleFlowLog().ToList().ForEach(x => OilSampleFlowLogs.Add(x));
                        //}
                        //else
                        //    MessageBox.Show(result);
                    }
                    else
                    {
                        MessageBox.Show("先选择行数据,【CTRL】或【SHFIT】 多选行");
                    }
                }
                else
                {
                    MessageBox.Show(msg);
                }
            });

            PrintConfigurationSaveBaseCommand = new DelegateCommand((obj) =>
            {
                string msg = PrintHelper.VerifyPrintConfiguration(PrintConfiguration);
                if (string.IsNullOrEmpty(msg))
                {
                    int id = CommonService.SaveBarTenderPrintConfigXX(PrintConfiguration);
                    if (id > 0)
                    {
                        PrintConfiguration.Id = id;
                        MessageBox.Show("保存成功");
                    }

                    else
                    {
                        MessageBox.Show("保存失败,请联系管理员");
                    }
                }
                else
                {
                    MessageBox.Show(msg);
                }
            });

            TemplateSelectBaseCommand = new DelegateCommand((obj) =>
            {
                System.Windows.Forms.FolderBrowserDialog fbd = new System.Windows.Forms.FolderBrowserDialog();
                if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    PirntTemplates = PrintHelper.GetTenderPrintA4Templates(fbd.SelectedPath);
                }
            });
        }