333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using wcftest.orm;
using wcftest.EnumDefine;
using logtxtWrite;
using OfficeOpenXml.Drawing;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using wcftest.sapEntity;
using System.IO;
using System.Drawing;
using Newtonsoft.Json;
using wcftest.EnumDefine.Sys;
 
 
namespace wcftest.sql
{
    public static class baseData
    {
        public static List<T> findStorage<T>(string Name, string name, string No, string no, string tableName)
        {
            List<T> tableList = new List<T>();
            try
            {
                using (dbModel mod = new dbModel())
                {//SELECT * FROM [weicai_LA20001].[dbo].[tool] where toolName like '%工%' and toolNo like '%%' 
                    string sql = "select * from [dbo].[" + tableName + "] where " + Name + " like '%" + name + "%' and " + No + " like '%" + no + "%'";
                    tableList = mod.Database.SqlQuery<T>(sql).ToList();
                }
            }
            catch (Exception ex)
            {
                logtxt.txtWrite("类名:baseData/函数名:findStorage/ name:" + name.ToString() + "no:" + no.ToString()
                    + "tableName" + tableName.ToString() + logtxt.oneRow(ex.ToString()), 2);
                return null;
            }
 
            return tableList;
        }
        public static void analyse(wirteExcel excelInfo)
        {
            #region 验证
            if (excelInfo.body.Count < 1)
            {
                logtxt.txtWrite("类名: baseData 方法名: analyse  缺料明细数量为空", 2);
                return;
            }
            //DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")
            string path = @"D:\缺料分析报表\" + excelInfo.head.workCode + "#第" + excelInfo.head.cequenceQuantity + "套缺料分析表.xlsx";
            if (!Directory.Exists(Path.GetDirectoryName(path))) Directory.CreateDirectory(Path.GetDirectoryName(path));
            FileInfo newFile = new FileInfo(path);
            if (newFile.Exists)
            {
                newFile.Delete();
                newFile = new FileInfo(path);
            }
            #endregion
 
 
            try
            {
                using (ExcelPackage package = new ExcelPackage(newFile))
                {
                    ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("PICK缺料分析");
 
                    Image tablelogo = Properties.Resources.siemensLogo;//获取图片资源
                    //设置表头格式
                    #region 设置表头格式
                    worksheet.Cells[1, 2, 1, 9].Merge = true;//合并单元格 起始行,起始列,目标行,目标列
                    //worksheet.Cells[1, 3].Style.Font.Bold = true;// 字体为粗体
                    worksheet.Row(1).Style.Font.Bold = true;// 字体为粗体;
                    worksheet.Row(2).Style.Font.Bold = true;// 字体为粗体;
                    worksheet.Row(3).Style.Font.Bold = true;// 字体为粗体;
                    worksheet.Cells[1, 3].Style.Font.Color.SetColor(Color.Black);//设置字体为黑色
 
                    worksheet.Cells[1, 2].Style.Font.Size = 16;//字体大小
                    worksheet.Cells[2, 1, 2, 8].Style.Font.Size = 12;//字体大小
                    worksheet.Cells[3, 1, 3, 8].Style.Font.Size = 10;//字体大小
                    worksheet.Row(1).Height = 40;
                    worksheet.Row(2).Height = 25;
                    worksheet.Cells[1, 2].Value = "广州西门子配变智能化工厂-立库区PICKLIST缺料报表";//给指定位置赋值
                    //表头
                    //  worksheet.Cells[2, 1, 2, 2].Merge = true;//合并单元格 起始行,起始列,目标行,目标列
                    string productionCode = excelInfo.head.workCode;//生产订单号
                    string saleCode = excelInfo.head.saleCode;//销售单号
                    string groupCode = excelInfo.head.tatalQuantity.ToString();//总套数
                    string groupNumber = excelInfo.head.cequenceQuantity.ToString();//第几套
                    worksheet.Cells[2, 1].Value = "生产订单号:";
                    worksheet.Cells[2, 2].Value = productionCode;
                    worksheet.Cells[2, 3].Value = "跟踪号:";
                    worksheet.Cells[2, 4].Value = saleCode;
                    worksheet.Cells[2, 5].Value = "总套数:";
                    worksheet.Cells[2, 6].Value = groupCode;
                    worksheet.Cells[2, 7].Value = "第几套:";
                    worksheet.Cells[2, 8].Value = groupNumber;
                    for (int j = 0; j < 2; j++)
                    {
                        worksheet.Cells[1, 1, 3, 8].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                        worksheet.Cells[1, 1, 3, 8].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                        worksheet.Cells[1, 1, 3, 8].Style.Border.Right.Style = ExcelBorderStyle.Thin;
                        worksheet.Cells[1, 1, 3, 8].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                    }
                    #endregion
 
                    #region 列名和图片
                    string[] tableTop = { "销售单号", "销售项号", "物料编号", "物料名称", "缺料数量", "暂存区数量", "立库区数量", "库存单位" };
                    for (int i = 0; i < 8; i++)
                    {
                        if (i < 5)
                        {
                            worksheet.Column(i + 1).Width = 15;//设置列宽
                        }
                        else
                        {
                            worksheet.Column(i + 1).Width = 12;
                        }
                        worksheet.Column(i + 1).Style.Font.Name = "宋体";//字体
                        worksheet.Column(i + 1).Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;//水平居中
                        worksheet.Column(i + 1).Style.VerticalAlignment = ExcelVerticalAlignment.Center;//垂直居中
                        // worksheet.Cells[1, 1].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(191, 191, 191));
                        worksheet.Cells[3, i + 1].Value = tableTop[i];
                    }
                    //  worksheet.Cells[1, 1, 20, 20].Style.Fill.PatternType = ExcelFillStyle.Solid;//
                    // worksheet.Cells.Style.WrapText = true;//自动换行
                    //  worksheet.Cells[1, 20].Style.Fill.BackgroundColor.SetColor(Color.FromArgb(128,128,128));//设置背景颜色
                    ExcelPicture pic = worksheet.Drawings.AddPicture("logo", tablelogo);//插入图片
                    pic.SetSize(105, 53);//设置图片尺寸
                    pic.SetPosition(0, 0, 0, 0);//设置图片位置,以单元格为单位
                    #endregion
 
                    #region 明细
                    for (int k = 0; k < excelInfo.body.Count; k++)
                    {
                        worksheet.Cells[k + 4, 1, k + 4, 8].Style.Border.Top.Style = ExcelBorderStyle.Thin;
                        worksheet.Cells[k + 4, 1, k + 4, 8].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
                        worksheet.Cells[k + 4, 1, k + 4, 8].Style.Border.Left.Style = ExcelBorderStyle.Thin;
                        worksheet.Cells[k + 4, 1, k + 4, 8].Style.Border.Right.Style = ExcelBorderStyle.Thin;
 
                        worksheet.Cells[k + 4, 1].Value = excelInfo.body[k].saleCode;
                        worksheet.Cells[k + 4, 2].Value = excelInfo.body[k].saleCodeItem;
                        // worksheet.Cells[k + 4, 3].Value = excelInfo.body[k].trackNumber;
                        worksheet.Cells[k + 4, 3].Value = excelInfo.body[k].materalCode;
                        worksheet.Cells[k + 4, 4].Value = excelInfo.body[k].materalName;
                        worksheet.Cells[k + 4, 5].Value = excelInfo.body[k].lackQuantity;
                        worksheet.Cells[k + 4, 6].Value = excelInfo.body[k].tempoarayQuantity;
                        worksheet.Cells[k + 4, 7].Value = excelInfo.body[k].stockQuantity;
                        worksheet.Cells[k + 4, 8].Value = excelInfo.body[k].stockUnit;
                    }
                    #endregion
 
                    package.Save();
                    worksheet.PrinterSettings.Orientation = eOrientation.Portrait;
                }
            }
            catch (Exception ex)
            {
                logtxt.txtWrite("类名: baseData 方法名: analyse  产生异常" + JsonConvert.SerializeObject(excelInfo) + ex.Message, 2);
            }
 
        }
        /// <summary>
        /// 增加用户操作日志
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="operationInfo">操作内容</param>
        /// <param name="OperateType">操作名称</param>
        public static void addOperation(string userName, string operationInfo, OperateTypeEnum OperateType, string _remark = "")
        {
            try
            {
                using (dbModel mod = new dbModel())
                {
                    Sys_User_Log moveStocklog = new Sys_User_Log();
                    moveStocklog.UserTrueName = userName;
                    moveStocklog.OperateType = OperateType.ToString();
                    moveStocklog.Action = operationInfo;
                    moveStocklog.Creator = userName;
                    moveStocklog.CreateDate = DateTime.Now;
                    moveStocklog.UserProduct_Id = 1007;
                    moveStocklog.UserProductCode = "100000001";
                    moveStocklog.Remark = _remark;
                    mod.Sys_User_Log.Add(moveStocklog);
                    int result = mod.SaveChanges();
                    if (result == 0)//失败再保存一次
                    {
                        result = mod.SaveChanges();
                        if (result == 0)
                        {
                            logtxt.txtWrite("添加日志保存失败 用户名" + userName + "操作内容" + operationInfo, 2);
                        }
 
                    }
                }
            }
            catch (Exception)
            {
 
                logtxt.txtWrite("添加日志保存失败 用户名" + userName + "操作内容" + operationInfo, 2);
            }
 
        }
    }
}