yl
2023-02-27 adc65b06d255664c2f7b763aad04572d5a96ff46
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using Dapper;
using FastReport;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Management;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using VueWebApi.DLL.BLL;
using VueWebApi.Tools;
 
namespace VueWebApi.Controllers
{
    [RoutePrefix(prefix: "api/GridReport")]
    [ControllerGroup("单据打印", "在线接口")]
    public class GridReportController : ApiController
    {
        //定义全局信息返回变量
        ToMessage mes = new ToMessage();
        RedisHelper redis = new RedisHelper();
 
 
        #region[MES工单打印]
        /// <summary>
        /// MES工单打印
        /// </summary>
        /// <param name="username">登录用户</param>
        /// <param name="mesordercode">工单编号</param>
        [Route(template: "MesOrderPrintSearch")]
        [HttpPost]
        public HttpResponseMessage MesOrderPrintSearch(string username,string mesordercode)
        {
            mes = GridReportBLL.MesOrderPrintSearch(username,mesordercode);
            return TJson.toJson(mes);
        }
        #endregion
 
        #region[MES工单打印1]
        /// <summary>
        /// MES工单打印1
        /// </summary>
        /// <param name="obj">提交数据</param>
        /// <returns></returns>
        [Route(template: "MesOrderPrintSearch1")]
        [HttpPost]
        public HttpResponseMessage MesOrderPrintSearch1([FromBody] JObject obj)
        {
            string username = obj["username"].ToString();    //登录用户
            string mesordercode = obj["mesordercode"].ToString();    //工单状态码
            mes = GridReportBLL.MesOrderPrintSearch(username, mesordercode);
            return TJson.toJson(mes);
        }
        #endregion
 
        #region[FastReport打印]
        [Route(template: "PrintOrder")]
        [HttpPost]
        [HiddenApi]
        public void PrintOrder([FromBody] JObject obj)
        {
            try
            {
                string username = obj["username"].ToString();    //登录用户
                string mesordercode = obj["mesordercode"].ToString();    //工单状态码
                PrintMessage dt = GridReportBLL.MesOrderFastReportPrintSearch(username, mesordercode);
                if (dt.data == null)
                {
                    throw new Exception(dt.Message);
                }
                Report report = new Report();
                //report.PrintSettings.Printer = ((String)report.GetColumnValue("Microsoft XPS Document Writer"));
                //默认不显示打印机选择页面
                //string filename = this.Server.MapPath("~/bin/YLDH.frx");//调用报表 
                //report.PrintSettings.Printer = ((String)report.GetColumnValue("Microsoft XPS Document Writer"));
                //report.PrintSettings.Printer = ((String)report.GetColumnValue("192.168.1.109/Canon G2010 series"));
                report.PrintSettings.Printer = ((String)report.GetColumnValue(""));  //获取本地默认打印机
                string reportLabel = System.Web.HttpContext.Current.Server.MapPath("/grf/Rework.frx");
                LogHelper.WriteLogData("文件地址:"+ reportLabel);
                //FastReport.EnvironmentSettings eSet = new EnvironmentSettings();
                //eSet.ReportSettings.ShowProgress = false;
                report.Load(reportLabel);
                report.PrintSettings.ShowDialog = true;
                //report.Load(filename);
                dt.data.TableName = "Table1"; // 一定要设置表名称
                DataSet ds = new DataSet();
                ds.Tables.Add(dt.data);
                report.RegisterData(ds);
                report.Print();
                report.Dispose();
                LogHelper.WriteLogData("序列化通过5");
            }
            catch (Exception e)
            {
 
                throw;
            }
           
        }
        #endregion
    }
}