Exemple #1
0
        public int InsertBarTenderPrintConfig(BarTenderPrintConfigModel model)
        {
            string sql = @" insert into SJBarTenderPrintConfig(UserId,HostName,TemplateTypeId,TemplateTypeName,TemplateFullName,TemplateFileName,TemplatePerPage,PrinterName,TemplateFolderPath,TemplateTotalPage)
                            values(@UserId,@HostName,@TemplateTypeId,@TemplateTypeName,@TemplateFullName,@TemplateFileName,@TemplatePerPage,@PrinterName,@TemplateFolderPath,@TemplateTotalPage);select SCOPE_IDENTITY() as Id;";

            using (var connection = SqlDb.UpdateConnection)
            {
                return(Convert.ToInt32(connection.ExecuteScalar(sql, model)));
            }
        }
Exemple #2
0
        public bool UpdateBarTenderPrintConfig(BarTenderPrintConfigModel model)
        {
            string sql = @" update SJBarTenderPrintConfig set TemplateTypeId=@TemplateTypeId,TemplateTypeName=@TemplateTypeName,TemplateFullName=@TemplateFullName,
                            TemplateFileName=@TemplateFileName,TemplatePerPage=@TemplatePerPage,PrinterName=@PrinterName,TemplateTotalPage=@TemplateTotalPage where Id=@Id; ";

            using (var connection = SqlDb.UpdateConnection)
            {
                return(connection.Execute(sql, model) > 0);
            }
        }
Exemple #3
0
        private void GetOilSamplePrintConfig()
        {
            OilSampleTemplateSelectedItem = new BarTenderTemplateModel();

            OilSamplePrintConfig = CommonService.GetBarTenderPrintConfig(User.ID, 2, HostName);
            if (OilSamplePrintConfig != null)
            {
                OilSampleTemplates = CommonService.GetTenderPrintTemplates(OilSamplePrintConfig.TemplateFolderPath);

                //验证打印机和模板路径是否存在
                if (!File.Exists(OilSamplePrintConfig.TemplateFullName))
                {
                    MessageBox.Show(" 模板路径不存在,请手动选择模板目录 \r\n");
                    OilSampleTemplateSelectedItem           = null;
                    OilSamplePrintConfig.TemplateFullName   = null;
                    OilSamplePrintConfig.TemplateFileName   = null;
                    OilSamplePrintConfig.TemplateFolderPath = null;
                    OilSamplePrintConfig.TemplatePerPage    = 0;
                    return;
                }
                if (!ComputerPrinters.Contains(OilSamplePrintConfig.PrinterName))
                {
                    MessageBox.Show("打印机错误或不存在,请手动选择 打印机 \r\n");
                    OilSamplePrintConfig.PrinterName = null;
                    return;
                }
                OilSampleTemplateSelectedItem.TemplatePerPage    = OilSamplePrintConfig.TemplatePerPage;
                OilSampleTemplateSelectedItem.TemplateFileName   = OilSamplePrintConfig.TemplateFileName;
                OilSampleTemplateSelectedItem.TemplateFullName   = OilSamplePrintConfig.TemplateFullName;
                OilSampleTemplateSelectedItem.TemplateFolderPath = OilSamplePrintConfig.TemplateFolderPath;
            }
            else
            {
                OilSamplePrintConfig = new BarTenderPrintConfigModel();
            }
        }
Exemple #4
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);
                }
            }
        }
Exemple #5
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);
                }
            }
        }