1
wtt
2024-08-16 b2910c43e8204c411f638349e610be95060290ef
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Pub_Class;
using System;
using System.Data;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Runtime.InteropServices;
using System.Web.Http;
using System.Windows.Forms;
using WebAPI.Models;
//using Excel = Microsoft.Office.Interop.Excel;
 
 
namespace WebAPI.Controllers.基础资料.基础资料
{
    public class Gy_SOPBillListController : ApiController
    {
        public DBUtility.ClsPub.Enum_BillStatus BillStatus;
 
        private json objJsonResult = new json();
        SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
        DataSet ds;
        DAL.ClsGy_SOPBill oBill = new DAL.ClsGy_SOPBill();
        Pub_Class.ClsXt_SystemParameter oSystemParameter = new Pub_Class.ClsXt_SystemParameter();
 
        public DataGridView grdMain = new System.Windows.Forms.DataGridView();
 
        #region 作业指导书列表
        [Route("Gy_SOPBill/list")]
        [HttpGet]
        public object getSOPBillList(string sWhere, string user)
        {
            try
            {
                //查看权限
                //if (!DBUtility.ClsPub.Security_Log("Gy_SOPBillMain", 1, false, user))
                //{
                //    objJsonResult.code = "0";
                //    objJsonResult.count = 0;
                //    objJsonResult.Message = "无查看权限!";
                //    objJsonResult.data = null;
                //    return objJsonResult;
                //}
 
                if (sWhere == null || sWhere.Equals(""))
                {
                    ds = oCN.RunProcReturn("select * from h_v_Gy_SOPBillList order by hmainid ", "h_v_Gy_SOPBillList");
                }
                else
                {
                    string sql1 = "select * from h_v_Gy_SOPBillList where 1 = 1 ";
                    string sql = sql1 + sWhere + " order by hmainid ";
                    ds = oCN.RunProcReturn(sql, "h_v_Gy_SOPBillList");
                }
 
                //if (ds.Tables[0].Rows.Count != 0 || ds != null)
                //{
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
                //}
                //else
                //{
                //objJsonResult.code = "0";
                //objJsonResult.count = 0;
                //objJsonResult.Message = "无数据";
                //objJsonResult.data = null;
                //return objJsonResult;
                //}
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
 
        /// <summary>
        /// 作业指导书删除
        /// </summary>
        /// <returns></returns>
        [Route("Gy_SOPBill/Del")]
        [HttpGet]
        public object Del(string hmainid, string hsubid, string user)
        {
            DataSet ds;
            try
            {
                //删除权限
                if (!DBUtility.ClsPub.Security_Log("Gy_SOPBill_Drop", 1, false, user))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "无删除权限!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                SQLHelper.ClsCN oCN = new SQLHelper.ClsCN();
                if (string.IsNullOrWhiteSpace(hmainid))
                {
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "资料内码为空!";
                    objJsonResult.data = null;
                    return objJsonResult;
                }
 
                oCN.BeginTran();//开始事务
                ds = oCN.RunProcReturn("select * from Gy_SOPBillSub where HInterID=" + hmainid + " and HEntryID=" + hsubid, "Gy_SOPBillSub");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    oCN.RollBack();
                    objJsonResult.code = "0";
                    objJsonResult.count = 0;
                    objJsonResult.Message = "没有数据,无法删除!";
                    objJsonResult.data = null;
                    return objJsonResult; ;
                }
 
                oCN.RunProc("delete Gy_SOPBillSub where HInterID=" + hmainid + " and HEntryID=" + hsubid);
                oCN.RunProc("delete Gy_SOPBillSub2 where HInterID=" + hmainid + " and HEntryID=" + hsubid);
                oCN.Commit();//提交事务
 
                objJsonResult.code = "0";
                objJsonResult.count = 1;
                objJsonResult.Message = "作业指导书删除成功!";
                objJsonResult.data = null;
                return objJsonResult; ;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "删除失败!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        #region 引出
        [Route("Gy_SOPBill/SetExcel")]
        [HttpGet]
        public HttpResponseMessage Sc_StationInBillSetExcel(string sWhere)
        {
            HSSFWorkbook workbook = new HSSFWorkbook();
            ISheet sheet = workbook.CreateSheet("sheet1");
            IRow row = sheet.CreateRow(0);
 
 
            row.CreateCell(0).SetCellValue("单据号");
            row.CreateCell(1).SetCellValue("单据类型");
            row.CreateCell(2).SetCellValue("工艺名称");
            row.CreateCell(3).SetCellValue("物料代码");
            row.CreateCell(4).SetCellValue("物料名称");
            row.CreateCell(5).SetCellValue("规格型号");
            row.CreateCell(6).SetCellValue("计量单位代码");
            row.CreateCell(7).SetCellValue("计量单位");
            row.CreateCell(8).SetCellValue("默认指导书");
            row.CreateCell(9).SetCellValue("表头备注");
            row.CreateCell(10).SetCellValue("工序号");
            row.CreateCell(11).SetCellValue("工序代码");
            row.CreateCell(12).SetCellValue("工序");
            row.CreateCell(13).SetCellValue("工作中心代码");
            row.CreateCell(14).SetCellValue("工作中心名称");
            row.CreateCell(15).SetCellValue("工位代码");
            row.CreateCell(16).SetCellValue("工位");
            row.CreateCell(17).SetCellValue("表体备注");
            row.CreateCell(18).SetCellValue("使用标记");
            row.CreateCell(19).SetCellValue("启用人");
            row.CreateCell(20).SetCellValue("启用日期");
            row.CreateCell(21).SetCellValue("制单人");
            row.CreateCell(22).SetCellValue("制单日期");
            row.CreateCell(23).SetCellValue("审核人");
            row.CreateCell(24).SetCellValue("审核日期");
            row.CreateCell(25).SetCellValue("修改人");
            row.CreateCell(26).SetCellValue("修改日期");
            row.CreateCell(27).SetCellValue("作废人");
            row.CreateCell(28).SetCellValue("作废日期");
 
 
            //精确控制列宽
            sheet.SetColumnWidth(1, 5000);
            sheet.SetColumnWidth(2, 5000);
            sheet.SetColumnWidth(3, 5000);
            sheet.SetColumnWidth(4, 5000);
            sheet.SetColumnWidth(5, 5000);
            sheet.SetColumnWidth(6, 5000);
            sheet.SetColumnWidth(7, 5000);
            sheet.SetColumnWidth(8, 5000);
            sheet.SetColumnWidth(9, 5000);
            sheet.SetColumnWidth(10, 5000);
            sheet.SetColumnWidth(11, 5000);
            sheet.SetColumnWidth(12, 5000);
            sheet.SetColumnWidth(13, 5000);
            sheet.SetColumnWidth(14, 5000);
            sheet.SetColumnWidth(15, 5000);
            sheet.SetColumnWidth(16, 5000);
            sheet.SetColumnWidth(17, 5000);
            sheet.SetColumnWidth(18, 5000);
            sheet.SetColumnWidth(19, 5000);
            sheet.SetColumnWidth(20, 5000);
            sheet.SetColumnWidth(21, 5000);
            sheet.SetColumnWidth(22, 5000);
            sheet.SetColumnWidth(23, 5000);
            sheet.SetColumnWidth(24, 5000);
            sheet.SetColumnWidth(25, 5000);
            sheet.SetColumnWidth(26, 5000);
            sheet.SetColumnWidth(27, 5000);
            sheet.SetColumnWidth(28, 5000);
            sheet.SetColumnWidth(29, 5000);
 
 
            DataSet ds = oCN.RunProcReturn("select * from h_v_Gy_SOPBillList" + sWhere + " order by hmainid desc", "h_v_Gy_SOPBillList");
            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                IRow row1 = sheet.CreateRow(i + 1);
                row1.CreateCell(0).SetCellValue(ds.Tables[0].Rows[i]["单据号"].ToString());
                row1.CreateCell(1).SetCellValue(ds.Tables[0].Rows[i]["单据类型"].ToString());
                row1.CreateCell(2).SetCellValue(ds.Tables[0].Rows[i]["工艺名称"].ToString());
                row1.CreateCell(3).SetCellValue(ds.Tables[0].Rows[i]["物料代码"].ToString());
                row1.CreateCell(4).SetCellValue(ds.Tables[0].Rows[i]["物料名称"].ToString());
                row1.CreateCell(5).SetCellValue(ds.Tables[0].Rows[i]["规格型号"].ToString());
                row1.CreateCell(6).SetCellValue(ds.Tables[0].Rows[i]["计量单位代码"].ToString());
                row1.CreateCell(7).SetCellValue(ds.Tables[0].Rows[i]["计量单位"].ToString());
                row1.CreateCell(8).SetCellValue(ds.Tables[0].Rows[i]["默认指导书"].ToString());
                row1.CreateCell(9).SetCellValue(ds.Tables[0].Rows[i]["表头备注"].ToString());
                row1.CreateCell(10).SetCellValue(ds.Tables[0].Rows[i]["工序号"].ToString());
                row1.CreateCell(11).SetCellValue(ds.Tables[0].Rows[i]["工序代码"].ToString());
                row1.CreateCell(12).SetCellValue(ds.Tables[0].Rows[i]["工序"].ToString());
                row1.CreateCell(13).SetCellValue(ds.Tables[0].Rows[i]["工作中心代码"].ToString());
                row1.CreateCell(14).SetCellValue(ds.Tables[0].Rows[i]["工作中心名称"].ToString());
                row1.CreateCell(15).SetCellValue(ds.Tables[0].Rows[i]["工位代码"].ToString());
                row1.CreateCell(16).SetCellValue(ds.Tables[0].Rows[i]["工位"].ToString());
                row1.CreateCell(17).SetCellValue(ds.Tables[0].Rows[i]["表体备注"].ToString());
                row1.CreateCell(18).SetCellValue(ds.Tables[0].Rows[i]["使用标记"].ToString());
                row1.CreateCell(19).SetCellValue(ds.Tables[0].Rows[i]["启用人"].ToString());
                row1.CreateCell(20).SetCellValue(ds.Tables[0].Rows[i]["启用日期"].ToString());
                row1.CreateCell(21).SetCellValue(ds.Tables[0].Rows[i]["制单人"].ToString());
                row1.CreateCell(22).SetCellValue(ds.Tables[0].Rows[i]["制单日期"].ToString());
                row1.CreateCell(23).SetCellValue(ds.Tables[0].Rows[i]["审核人"].ToString());
                row1.CreateCell(24).SetCellValue(ds.Tables[0].Rows[i]["审核日期"].ToString());
                row1.CreateCell(25).SetCellValue(ds.Tables[0].Rows[i]["修改人"].ToString());
                row1.CreateCell(26).SetCellValue(ds.Tables[0].Rows[i]["修改日期"].ToString());
                row1.CreateCell(27).SetCellValue(ds.Tables[0].Rows[i]["作废人"].ToString());
                row1.CreateCell(28).SetCellValue(ds.Tables[0].Rows[i]["作废日期"].ToString());
 
            }
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            workbook.Write(ms);
            ms.Position = 0;
 
            var response = new HttpResponseMessage(HttpStatusCode.OK);
            response.Content = new StreamContent(ms);
 
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
            var fileName = "作业指导书列表.xls";
 
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = System.Web.HttpUtility.UrlEncode(fileName)
            };
            return response;
        }
        #endregion
 
        //
        private Int32 Fun_GetCol(string sCol)
        {
            return DBUtility.Xt_BaseBillFun.Fun_GetCol(sCol, grdMain);
        }
        #region 使用
        [Route("Gy_SOPBill/BatchUse")]
        [HttpGet]
        public object sy_Click()
        {
            long sOldInterID = 0;
            for (int i = 0; i <= grdMain.SelectedRows.Count - 1; i++)
            {
                long HInterID = DBUtility.ClsPub.isLong(grdMain.SelectedRows[i].Cells[Fun_GetCol("HMainID")].Value);
                if (HInterID == 0 || HInterID == sOldInterID)
                {
                    continue;
                }
                else
                {
                    sOldInterID = HInterID;
                }
                if (!oBill.Sub_RoutingCheckAndUsed(HInterID))
                {
                    continue;
                }
            }
            objJsonResult.count = 1;
            objJsonResult.Message = "批量使用完毕!";
            return objJsonResult;
        }
        #endregion
 
 
        #region 打印查询数据
        [Route("Gy_SOPBillList/WindowPrintList")]
        [HttpGet]
        public object WindowPrintList(string sWhere)
        {
            try
            {
                ds = oCN.RunProcReturn(sWhere, "WindowPrint");
 
                //客户制定
                string sErr = "";
                if (oSystemParameter.ShowBill(ref sErr))
                {
                    if (oSystemParameter.omodel.WMS_CampanyName == "乔一")
                    {
                        if (ds.Tables[0].Columns.Count > 8) {
                            LogService.CustomWriteLog("单据号:"+ ds.Tables[0].Rows[0][7].ToString(),"CS"+ DateTime.Now.ToString("yyyyMMdd"));
                        }
                    }
                  
                }
               
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = ds.Tables[0];
                return objJsonResult;
            }
            catch (Exception e)
            {
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
 
        /// <summary>
        /// 对数据库进行操作
        /// </summary>
        /// <param name="sWhere"></param>
        /// <returns></returns>
        [Route("Gy_SOPBillList/UpDelSQL")]
        [HttpGet]
        public object UpDelSQL(string sWhere)
        {
            try
            {
                oCN.BeginTran();
                oCN.RunProc(sWhere);
                oCN.Commit();
 
                objJsonResult.code = "1";
                objJsonResult.count = 1;
                objJsonResult.Message = "Sucess!";
                objJsonResult.data = null;
                return objJsonResult;
            }
            catch (Exception e)
            {
                oCN.RollBack();
                objJsonResult.code = "0";
                objJsonResult.count = 0;
                objJsonResult.Message = "Exception!" + e.ToString();
                objJsonResult.data = null;
                return objJsonResult;
            }
        }
        #endregion
    }
}