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
using BLL;
using Common;
using FastReport.Web;
using Lib;
using Model;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Json;
 
namespace WMS.Areas.Business.Controllers
{
    public class ErpInController : MasterPage
    {
        // GET: Business/ErpIn
        [LoginFilter]
        public ActionResult Index()
        {
            ViewBag.StatuList = LocalHelper.GetDictionaryCodeHtml("CDStatu");
            ViewBag.Title = "入库单管理";
            return View();
        }
 
        [LoginFilter]
        public ActionResult Add()
        {
            string OrdNo = Request.QueryString.Get("OrdNo");
            Session["SEL_ERPIN_LIST"] = null;
            if (string.IsNullOrEmpty(OrdNo))
            {
                ViewBag.Admin = new Erp();
                ViewBag.OrdTypeList = LocalHelper.GetDictionaryCodeHtml("CDStatu");
            }
            else
            {
                IDALErpIn provider = new DALErpIn();
                IList<ErpMat> erpMats = new List<ErpMat>();
                ErpIn entity = provider.GetModel(OrdNo, ref erpMats);
                Session["TEMPDATA_CACHE_INSTORDETAIL"] = erpMats;
                entity = entity == null ? new ErpIn() : entity;
                ViewBag.OrdTypeList = LocalHelper.GetOrdTypeList(entity.OrdType);
                ViewBag.Admin = entity;
 
            }
 
            return View();
        }
        [LoginFilter]
        public ActionResult AddProduct()
        {
            Session["SEL_ERPIN_LIST"] = null; //清空入库选物料.
 
            string MatNo = Request.QueryString.Get("MatNo");
            string palno = Request.QueryString.Get("palno");
 
            if (string.IsNullOrEmpty(MatNo))
            {
                ViewBag.Admin = new ErpMat();
            }
            else
            {
                List<ErpMat> list = Session["TEMPDATA_CACHE_INSTORDETAIL"] as List<ErpMat>;
                List<ErpMat> list1 = new List<ErpMat>();
                if (palno == "")
                {
                    list1 = list.Where(a => a.MatNo == MatNo && a.Palno == null).ToList<ErpMat>();
                    if (list1.Count <= 0)
                    {
                        list1 = list.Where(a => a.MatNo == MatNo && a.Palno == "").ToList<ErpMat>();
                    }
                }
                else
                {
                    list1 = list.Where(a => a.MatNo == MatNo && a.Palno == palno).ToList<ErpMat>();
                }
                ViewBag.Admin = list1[0];
                ViewBag.Palnolist = LocalHelper.GetPalnoList(list1[0].addreNo, list1[0].Palno);
 
            }
            return View();
        }
        [LoginFilter]
        public ActionResult Detail(string OrdNo)
        {
            if (!string.IsNullOrEmpty(OrdNo))
            {
                Erp entity = new Erp();
                IDALErpIn provider = new DALErpIn();
                entity = provider.GetModel(OrdNo);
 
                ViewBag.Admin = entity;
            }
            return View();
        }
 
 
        public ActionResult Position()
        {
            return View();
        }
        [LoginFilter]
        public ActionResult ReportShow()
        {
            string ReportNo = Request["ReportNo"];
            string OrdNo = Request["OrdNo"];
            string[] ordNos = new string[] { OrdNo };
 
            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 = "航天入库单";
                DALErpIn purchase = new DALErpIn();
                ds = purchase.GetPrintData(OrdNo);
            }
            else if (ReportNo.IndexOf("出库单") >= 0)
            {
                ReportNo = "出库单";
                IDALErpIn purchase = new DALErpIn();
                ds = purchase.GetPrintData(OrdNo);
            }
 
            string path = "~/Report/" + ReportNo + ".frx";
            path = Server.MapPath(path);
 
            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 = DALErpIn.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();
                    }
            }
        }
 
 
    }
}