bklLiudl
2024-07-23 277bbae216debe7e6c04e8cc6ee6e1ba9763e14b
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
using BLL;
using Common;
using Model;
using System.Collections.Generic;
using System.Linq;
using Lib;
using System.Web.Mvc;
using FastReport.Web;
using System.Data;
using System.Web;
using System;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;
using System.IO;
using NPOI.XSSF.UserModel;
 
namespace WMS.Areas.Business.Controllers
{
    public class ErpOutController : MasterPage
    {
        // GET: Business/ErpOut
        [LoginFilter]
        public ActionResult Index()
        {
            ViewBag.StatuList = LocalHelper.GetDictionaryCodeHtml("CDStatu");
            //ViewBag.AccessCode = LocalHelper.GetDictionaryCodeHtml("Access", this.LoginAccessCode);
            ViewBag.AccessCode = LocalHelper.GetDictionaryCodeHtml("Access");
            ViewBag.Title = "出库单管理";
            return View();
        }
 
        [LoginFilter]
        public ActionResult SetErpOutDetail()
        {
            string ordNo = Request.QueryString.Get("OrdNo");
            Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = null;
            if (string.IsNullOrEmpty(ordNo))
            {
                ViewBag.Admin = new ErpOut();
            }
            else
            {
                // 编辑出库单
                IDALErpOut provider = new DALErpOut();
                IList<StorePalno> erpMats = new List<StorePalno>();
                ErpOut entity = provider.GetModel(ordNo, ref erpMats);
                Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = erpMats;
                entity = entity == null ? new ErpOut() : entity;
                ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(entity.OrdType);
                ViewBag.Admin = entity;
            }
            ViewBag.AccessCode = LocalHelper.GetDictionaryCodeHtml("Access", this.LoginAccessCode);
            return View();
        }
 
 
 
 
 
        public ActionResult Add()
        {
            string OrdNo = Request.QueryString.Get("OrdNo");
            Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = null;
            if (string.IsNullOrEmpty(OrdNo))
            {
                ViewBag.Admin = new ErpOut();
                ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(string.Empty);
            }
            else
            {
                IDALErpOut provider = new DALErpOut();
                IList<StorePalno> erpMats = new List<StorePalno>();
                ErpOut entity = provider.GetModel(OrdNo, ref erpMats);
                Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] = erpMats;
                entity = entity == null ? new ErpOut() : entity;
                ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(entity.OrdType);
                ViewBag.Admin = entity;
            }
 
            return View();
        }
        public ActionResult AddProduct()
        {
            string MatNo = Request.QueryString.Get("MatNo");
            string palno = Request.QueryString.Get("palno");
            string Certificate = Request.QueryString.Get("Certificate");
            if (MatNo.IsEmpty())
            {
                ViewBag.Admin = new StorePalno();
            }
            else
            {
                List<StorePalno> list = Session["TEMPDATA_CACHE_ERPOUTPRODUCT"] as List<StorePalno>;
                List<StorePalno> list1 = new List<StorePalno>();
                if (palno == "")
                {
                    list1 = list.Where(a => a.MatNo == MatNo && a.Palno == null).ToList<StorePalno>();
                    if (list1.Count <= 0)
                    {//lijiangang修改:增加合格证Certificate条件
                        list1 = list.Where(a => a.MatNo == MatNo && a.Palno == "" && a.Certificate == Certificate).ToList<StorePalno>();
                    }
                }
                else
                {//lijiangang修改:增加合格证Certificate条件
                    list1 = list.Where(a => a.MatNo == MatNo && a.Palno == palno && a.Certificate == Certificate).ToList<StorePalno>();
                    if (list1.Count == 0)
                    {
                        list1 = list.Where(a => a.MatNo == MatNo && a.Palno == palno && a.Certificate == null).ToList<StorePalno>();
                    }
                }
                DALErpOut provider = new DALErpOut();
                //lijiangang修改:增加合格证Certificate条件
                list1[0].Quant = provider.GetLogStore(MatNo, palno, Certificate);
                ViewBag.Admin = list1[0];
            }
            return View();
        }
 
        public ActionResult Detail(string OrdNo)
        {
            if (!string.IsNullOrEmpty(OrdNo))
            {
                IDALErpOut provider = new DALErpOut();
                ErpOut entity = provider.GetModel(OrdNo);
                entity = entity == null ? new ErpOut() : entity;
                ViewBag.Admin = entity;
            }
            return View();
        }
 
        public ActionResult ReportShow()
        {
            string ReportNo = Request["ReportNo"];
            string OrdNo = Request["OrdNo"];
 
            string[] ordNos = new string[] { OrdNo };
            //点击打印更改状态为正在执行
            //IDALErpOut dalErpin = new DALErpOut();
            //bool result = dalErpin.UpdateClose(ordNos, "ER02");
            //if (!result) { return Content(null); }
 
            WebReport webReport = new WebReport();
            webReport.Width = System.Web.UI.WebControls.Unit.Percentage(100);
            webReport.Height = 600;
            webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
            webReport.ToolbarIconsStyle = ToolbarIconsStyle.Black;
 
            webReport.PrintInBrowser = false;
            webReport.PrintInPdf = false;
            webReport.ShowExports = false;
            webReport.SinglePage = false;
            //webReport.ToolbarStyle = ToolbarStyle.Small;
            webReport.PrintInPdf = true;
            webReport.ShowPrint = true;
            webReport.PreviewMode = true;
 
            DataSet ds = null;
 
            if (ReportNo.IndexOf("采购单") >= 0)
            {
                ReportNo = "采购单2";
                IDALPurchase purchase = new DALPurchase();
                ds = purchase.GetPrintData(OrdNo);
            }
            else if (ReportNo.IndexOf("入库单") >= 0)
            {
                ReportNo = "入库单";
                //ReportNo = "采购单2";
                DALErpIn purchase = new DALErpIn();
                ds = purchase.GetPrintData(OrdNo);
            }
            else if (ReportNo.IndexOf("出库单") >= 0)
            {
                ReportNo = "出库单";
                //ReportNo = "采购单2";
                DALErpOut purchase = new DALErpOut();
                ds = purchase.GetPrintData(OrdNo);
            }
 
            //ds = new ReportProvider().GetDataSource(entity, list, orderType, orderNum);
            string path = "~/Report/" + ReportNo + ".frx";
            path = Server.MapPath(path);
            //if (!Directory.Exists(path))
            //{
            //    string template = Server.MapPath("~Report/Report.frx");
            //    System.IO.File.Copy(template, path, true);
            //}
            webReport.Report.Load(path);
            if (ds != null && ds.Tables != null && ds.Tables.Count > 0)
            {
                webReport.Report.RegisterData(ds);
                for (int i = 0; i < ds.Tables.Count; i++)
                {
                    webReport.Report.GetDataSource(ds.Tables[i].TableName).Enabled = true;
                }
            }
            webReport.ID = ReportNo;
            ViewBag.WebReport = webReport;
 
            return View();
 
        }
        /// <summary>
        /// 导入Excel
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult ExcelToUpload(HttpPostedFileBase file)
        {
            DataTable excelTable = new DataTable();
            string msg = string.Empty;
            if (Request.Files.Count > 0)
            {
                try
                {
                    HttpPostedFileBase mypost = Request.Files[0];
                    string fileName = Request.Files[0].FileName;
                    //在文件夹Report 用来接收上传的文件
                    string serverpath = Server.MapPath(string.Format("~/{0}", "Report/") + fileName);
                    mypost.SaveAs(serverpath);
                    //  excelTable = GetExcelDataTable(serverpath);
                    NPOIExcel nPOI = new NPOIExcel("", "", "");
                    excelTable = NPOIExcel.InputExcel(serverpath);
                    //删除服务器生成的文件
                    System.IO.File.Delete(serverpath);
                    //注意Excel表内容格式,第一行必须为列名与数据库列名匹配
                    //接下来为各列名对应下来的内容
                    string CreateUser = this.LoginUserCode;
                    msg = DALErpOut.ImportExcel(excelTable, CreateUser);// 写入基础数据
 
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                }
            }
            else
            {
                msg = "请选择文件";
            }
            return Json(msg);
        }
        public static DataTable GetExcelDataTable(string filePath)
        {
            IWorkbook Workbook;
            DataTable table = new DataTable();
            try
            {
                using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
 
                    //XSSFWorkbook 适用XLSX格式,HSSFWorkbook 适用XLS格式
                    string fileExt = System.IO.Path.GetExtension(filePath).ToLower();
 
                    if (fileExt == ".xls")
                    {
                        Workbook = new HSSFWorkbook(fileStream);
                    }
                    else if (fileExt == ".xlsx")
                    {
 
                        Workbook = new XSSFWorkbook(fileStream);
                    }
                    else
                    {
                        Workbook = null;
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
 
            //定位在第一个sheet
            ISheet sheet = Workbook.GetSheetAt(0);
            //第一行为标题行
            IRow headerRow = sheet.GetRow(0);
            int cellCount = headerRow.LastCellNum;
            int rowCount = sheet.LastRowNum;
 
            //循环添加标题列
            for (int i = headerRow.FirstCellNum; i < cellCount; i++)
            {
                DataColumn column = new DataColumn(headerRow.GetCell(i).StringCellValue);
                table.Columns.Add(column);
 
 
            }
 
            //数据
            for (int i = (sheet.FirstRowNum + 1); i <= rowCount; i++)
            {
                IRow row = sheet.GetRow(i);
                DataRow dataRow = table.NewRow();
                if (row != null)
                {
                    for (int j = row.FirstCellNum; j < cellCount; j++)
                    {
                        if (row.GetCell(j) != null)
                        {
                            dataRow[j] = GetCellValue(row.GetCell(j));
                        }
                    }
                }
                table.Rows.Add(dataRow);
            }
            return table;
        }
 
        private static string GetCellValue(ICell cell)
        {
            if (cell == null)
            {
                return string.Empty;
            }
 
            switch (cell.CellType)
            {
                case CellType.Blank:
                    return string.Empty;
                case CellType.Boolean:
                    return cell.BooleanCellValue.ToString();
                case CellType.Error:
                    return cell.ErrorCellValue.ToString();
                case CellType.Numeric:
                case CellType.Unknown:
                default:
                    return cell.ToString();
                case CellType.String:
                    return cell.StringCellValue;
                case CellType.Formula:
                    try
                    {
                        HSSFFormulaEvaluator e = new HSSFFormulaEvaluator(cell.Sheet.Workbook);
                        e.EvaluateInCell(cell);
                        return cell.ToString();
                    }
                    catch
                    {
                        return cell.NumericCellValue.ToString();
                    }
            }
        }
    }
}