예제 #1
0
        public bool BarTenderOilSampleEntryMergePrint(BarTenderPrintConfigModel config, ObservableCollection <OilSampleEntryModel> data, int printTotalNum, List <BarTenderTemplateModel> barTenderTemplates)
        {
            string printerName = config.PrinterName;

            string templateName = barTenderTemplates.FirstOrDefault(m => m.TemplatePerPage == printTotalNum && m.TemplateTotalPage == 4).TemplateFullName;
            List <OilSampleFlowPrintLogModel> logs = new List <OilSampleFlowPrintLogModel>();

            BarTender.Application btApp = new BarTender.Application();
            try
            {
                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;
                int z = 0;
                for (int i = 0; i < data.Count; i++)
                {
                    var    entry   = data[i];
                    string batchNo = new OilSampleService().GetOilSampleEntryBatchNo(entry.Id);
                    if (string.IsNullOrEmpty(batchNo))
                    {
                        var seq = new CommonService().GetCurrentDateNextSerialNumber(entry.ProductionDate, "OilSamplePrintBatchNo");
                        batchNo = entry.ProductionDate.ToString("yyMMdd") + seq.ToString().PadLeft(3, '0');
                    }
                    entry.BatchNo = batchNo;
                    logs.Add(new OilSampleFlowPrintLogModel
                    {
                        FormsonId    = entry.Id,
                        FormmainId   = entry.FormmainId,
                        EntryId      = entry.EntryId,
                        PrintCount   = entry.CurrencyPrintCount,
                        PrintedCount = entry.PrintedCount + entry.CurrencyPrintCount,
                        BatchNo      = entry.BatchNo,
                        TypeId       = config.TemplateTypeId,
                        TypeDesc     = config.TemplateTypeName
                    });

                    for (int j = 0; j < entry.CurrencyPrintCount; j++)
                    {
                        z++;
                        if (entry.PrintedCount + entry.CurrencyPrintCount >= entry.PrintTotalCount && j == entry.CurrencyPrintCount - 1 && entry.TotalWeight % entry.WeightPerBucket != 0)
                        {
                            entry.WeightPerBucket = (float)Math.Round(entry.TotalWeight % entry.WeightPerBucket, 2);
                        }
                        switch (z)
                        {
                        case 1: SetTemplateNamedSubStringValueToPart1(btFormat, list, entry); break;

                        case 2: SetTemplateNamedSubStringValueToPart2(btFormat, list, entry); break;

                        case 3: SetTemplateNamedSubStringValueToPart3(btFormat, list, entry); break;

                        case 4: SetTemplateNamedSubStringValueToPart4(btFormat, list, entry); break;

                        default: break;
                        }
                    }
                }

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

                // 写日志
                foreach (var item in logs)
                {
                    var result = new OilSampleService().InsertOilSampleFlowLog2(item);
                    if (!result)
                    {
                        return(false);
                    }
                }


                btFormat.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                return(true);
            }
            catch (Exception ex)
            {
                btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                throw new Exception(ex.Message);
            }
            finally
            {
                if (btApp != null)
                {
                    btApp.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
                }
            }
        }
예제 #2
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);
                }
            }
        }