Beispiel #1
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            IPVCService us  = new PVCService(Settings.Default.db, Session["user"] as User);
            PVC         pvc = us.FindById(id);

            try
            {
                bool isSucceed = us.DeleteById(id);

                if (isSucceed)
                {
                    ViewBag.msg = "删除成功";

                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.msg = "删除失败";

                    return(View(pvc));
                }
            }
            catch (Exception)
            {
                ViewBag.msg = "删除异常";

                return(View(pvc));
            }
        }
Beispiel #2
0
        public ActionResult Edit(int id)
        {
            IPVCService us   = new PVCService(Settings.Default.db, Session["user"] as User);
            PVC         user = us.FindById(id);

            return(View(user));
        }
Beispiel #3
0
        // GET: PVC/Delete/5
        public ActionResult Delete(int id)
        {
            IPVCService us = new PVCService(Settings.Default.db, Session["user"] as User);

            PVC pvc = us.FindById(id);

            return(View(pvc));
        }
        /// <summary>
        /// 导入
        /// </summary>
        /// <returns></returns>
        public ImportMessage Import()
        {
            ImportMessage msg = new ImportMessage()
            {
                Success = true
            };

            try
            {
                FileInfo             fileInfo = new FileInfo(this.FilePath);
                List <PVCExcelModel> records  = new List <PVCExcelModel>();
                string sheetName = "Tmp";
                /// 读取excel文件
                using (ExcelPackage ep = new ExcelPackage(fileInfo))
                {
                    if (ep.Workbook.Worksheets.Count > 0)
                    {
                        ExcelWorksheet ws = ep.Workbook.Worksheets.First();
                        sheetName = ws.Name;

                        for (int i = 2; i <= ws.Dimension.End.Row; i++)
                        {
                            records.Add(new PVCExcelModel()
                            {
                                name       = ws.Cells[i, 1].Value == null ? string.Empty : ws.Cells[i, 1].Value.ToString().Trim(),
                                shipDate   = ws.Cells[i, 2].Value == null ? string.Empty : ws.Cells[i, 2].Value.ToString().Trim(),
                                shipAmount = Convert.ToInt32(ws.Cells[i, 3].Value == null ? string.Empty : ws.Cells[i, 3].Value),
                                unit       = ws.Cells[i, 4].Value == null ? string.Empty : ws.Cells[i, 4].Value.ToString().Trim(),
                                batchNo    = ws.Cells[i, 5].Value == null ? string.Empty : ws.Cells[i, 5].Value.ToString().Trim(),
                                startTime  = ws.Cells[i, 6].Value == null ? string.Empty : ws.Cells[i, 6].Value.ToString().Trim(),
                                endTime    = ws.Cells[i, 7].Value == null ? string.Empty : ws.Cells[i, 7].Value.ToString().Trim(),
                                brand      = ws.Cells[i, 8].Value == null ? string.Empty : ws.Cells[i, 8].Value.ToString().Trim()
                            });
                        }
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Content = "文件不包含数据表,请检查";
                    }
                }

                if (msg.Success)
                {
                    /// 验证数据
                    if (records.Count > 0)
                    {
                        Validates(records);
                        if (records.Where(s => s.ValidateMessage.Success == false).Count() > 0)
                        {
                            /// 创建错误文件
                            msg.Success = false;
                            /// 写入文件夹,然后返回
                            string tmpFile = FileHelper.CreateFullTmpFilePath(Path.GetFileName(this.FilePath), true);
                            msg.Content       = FileHelper.GetDownloadTmpFilePath(tmpFile);
                            msg.ErrorFileFeed = true;

                            FileInfo tmpFileInfo = new FileInfo(tmpFile);
                            using (ExcelPackage ep = new ExcelPackage(tmpFileInfo))
                            {
                                ExcelWorksheet sheet = ep.Workbook.Worksheets.Add(sheetName);
                                ///写入Header
                                for (int i = 0; i < PVCExcelModel.Headers.Count(); i++)
                                {
                                    sheet.Cells[1, i + 1].Value = PVCExcelModel.Headers[i];
                                }
                                ///写入错误数据
                                for (int i = 0; i < records.Count(); i++)
                                {
                                    sheet.Cells[i + 2, 1].Value = records[i].name;
                                    sheet.Cells[i + 2, 2].Value = records[i].shipDate;
                                    sheet.Cells[i + 2, 3].Value = records[i].shipAmount;
                                    sheet.Cells[i + 2, 4].Value = records[i].unit;
                                    sheet.Cells[i + 2, 5].Value = records[i].batchNo;
                                    sheet.Cells[i + 2, 6].Value = records[i].startTime;
                                    sheet.Cells[i + 2, 7].Value = records[i].endTime;
                                    sheet.Cells[i + 2, 8].Value = records[i].brand;

                                    foreach (var content in records[i].ValidateMessage.Contents)
                                    {
                                        sheet.Cells[i + 2, 9].Value += " [" + content + "] ";
                                    }
                                }

                                /// 保存
                                ep.Save();
                            }
                        }
                        else
                        {
                            for (var i = 0; i < records.Count; i++)
                            {
                                PVC detail = new PVC();
                                detail.name       = records[i].name;
                                detail.shipDate   = records[i].shipDateTime.Value;
                                detail.shipAmount = records[i].shipAmount.Value;
                                detail.unit       = records[i].unit;
                                detail.batchNo    = records[i].batchNo;
                                detail.startTime  = records[i].startDateTime.Value;
                                detail.endTime    = records[i].endDateTime.Value;
                                detail.brand      = records[i].brand;

                                //新增车辆
                                IPVCService pvcs = new PVCService(this.DbString, UserSession);

                                //TODO:判断PENum 是否可以重复
                                //PVC temp_pvc = pvcs.FindByPeNum(detail.vin);
                                detail.peNum     = detail.batchNo + "." + records[i].startTime + "-" + records[i].endTime;
                                detail.createdAt = DateTime.Now;
                                detail.userId    = UserSession.id;

                                var CarResult = pvcs.Create(detail);
                                if (CarResult)
                                {
                                    msg.Content = "导入成功";
                                }
                                else
                                {
                                    msg.Content = "数据有问题";
                                }
                            }
                        }
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Content = "文件不包含数据,请检查";
                    }
                }
            }
            catch (Exception e)
            {
                msg.Success = false;
                msg.Content = "导入失败:" + e.Message + ",请联系系统管理员";
                LogUtil.Logger.Error(e.Message);
                LogUtil.Logger.Error(e.StackTrace);
            }
            return(msg);
        }
Beispiel #5
0
 public bool Update(PVC pvc)
 {
     //string salt=string.IsNullOrEmpty( pvc.pwdSalt) ? pvc.GenSalt() : pvc.pwdSalt;
     //pvc.pwd = MD5Helper.Encryt(string.Format("{0}{1}", pvc.pwd, pvc.pwdSalt));
     return(rep.Update(pvc));
 }
Beispiel #6
0
 public bool Create(PVC pvc)
 {
     return(rep.Create(pvc));
 }
Beispiel #7
0
        public ActionResult Create([Bind(Include = "name, shipDate, shipAmount, unit, batchNo, startTimeStr, endTimeStr, brand")] PVC pvc)
        {
            try
            {
                // TODO: Add insert logic here
                if (string.IsNullOrWhiteSpace(pvc.name))
                {
                    ViewBag.msg = "收货人姓名 不能为空";
                    return(View());
                }
                if (string.IsNullOrWhiteSpace(pvc.shipDate.ToString()))
                {
                    ViewBag.msg = "发货日期 不能为空";
                    return(View());
                }
                if (string.IsNullOrWhiteSpace(pvc.shipAmount.ToString()))
                {
                    ViewBag.msg = "发货数量 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(pvc.batchNo))
                {
                    ViewBag.msg = "线别/批号 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(Request.Form["startTimeStr"].ToString()))
                {
                    ViewBag.msg = "开始时间 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(Request.Form["endTimeStr"].ToString()))
                {
                    ViewBag.msg = "结束时间 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(pvc.brand))
                {
                    ViewBag.msg = "品名 不能为空";
                    return(View());
                }

                User        user    = Session["user"] as User;
                IPVCService service = new PVCService(Settings.Default.db, user);

                pvc.peNum = pvc.batchNo.Trim() + "." + Request.Form["startTimeStr"].Trim().ToString() + "-" + Request.Form["endTimeStr"].Trim().ToString();

                pvc.startTime = DateTime.ParseExact(Request.Form["startTimeStr"].Trim().ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                pvc.endTime   = DateTime.ParseExact(Request.Form["endTimeStr"].Trim().ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);

                pvc.createdAt = DateTime.Now;
                pvc.userId    = user.id;

                bool result = service.Create(pvc);

                if (result)
                {
                    ViewBag.msg = "新建成功";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.msg = "新建失败";
                    return(View());
                }
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex;
                return(View());
            }
        }
Beispiel #8
0
        public ActionResult Edit([Bind(Include = "id, name, shipDate, shipAmount, unit, batchNo, startTimeStr, endTimeStr, brand")] PVC pvc)
        {
            ResultMessage msg  = new ResultMessage();
            IPVCService   us   = new PVCService(Settings.Default.db, Session["user"] as User);
            PVC           pvcs = us.FindById(pvc.id);

            try
            {
                if (string.IsNullOrWhiteSpace(pvc.name))
                {
                    ViewBag.msg = "收货人姓名 不能为空";
                    return(View());
                }
                if (string.IsNullOrWhiteSpace(pvc.shipDate.ToString()))
                {
                    ViewBag.msg = "发货日期 不能为空";
                    return(View());
                }
                if (string.IsNullOrWhiteSpace(pvc.shipAmount.ToString()))
                {
                    ViewBag.msg = "发货数量 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(pvc.batchNo))
                {
                    ViewBag.msg = "线别/批号 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(Request.Form["startTimeStr"].ToString()))
                {
                    ViewBag.msg = "开始时间 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(Request.Form["endTimeStr"].ToString()))
                {
                    ViewBag.msg = "结束时间 不能为空";
                    return(View());
                }

                if (string.IsNullOrWhiteSpace(pvc.brand))
                {
                    ViewBag.msg = "品名 不能为空";
                    return(View());
                }

                User        user    = Session["user"] as User;
                IPVCService service = new PVCService(Settings.Default.db, user);

                pvc.peNum = pvc.batchNo.Trim() + "." + Request.Form["startTimeStr"].Trim().ToString() + "-" + Request.Form["endTimeStr"].Trim().ToString();

                pvc.startTime = DateTime.ParseExact(Request.Form["startTimeStr"].Trim().ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);
                pvc.endTime   = DateTime.ParseExact(Request.Form["endTimeStr"].Trim().ToString(), "yyyyMMddHHmmss", System.Globalization.CultureInfo.CurrentCulture);

                //pvcs.name = pvc.name;
                //pvcs.shipDate = pvc.shipDate;
                //pvcs.shipAmount = pvc.shipAmount;
                //pvcs.unit = pvc.unit;
                //pvcs.peNum = pvc.peNum;
                //pvcs.batchNo = pvc.batchNo;
                //pvcs.startTime = pvc.startTime;
                //pvcs.endTime = pvc.endTime;
                //pvcs.brand = pvc.brand;
                //pvcs.name = pvc.name;

                //可以添加操作日志
                bool isSucceed = us.Update(pvc);

                if (isSucceed)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.msg = "更新失败";
                    return(View(pvcs));
                }
            }
            catch (Exception ex)
            {
                ViewBag.msg = ex;

                return(View(pvcs));
            }
        }