public ActionResult Upload(FormCollection forms, HttpPostedFileBase excelfile) { #region "Start Checkpoint" CheckPointApi checkPointApi = new CheckPointApi(); var watch = new Stopwatch(); watch.Start(); checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "ImportExcel", "Start", 0); #endregion //ViewBag.Filename = fileUpload.FileName; if (excelfile.FileName.EndsWith(".xls") || excelfile.FileName.EndsWith(".xlsx")) { var importInfo = new ImportExcelInfo { UserId = UserContext.GetCurrentUser().UserID, Status = ConvertHelper.ToInt32(forms["Status"]), LevelId = ConvertHelper.ToInt32(forms["LevelId"]), BranchId = ConvertHelper.ToInt32(forms["BranchId"]), ChannelId = ConvertHelper.ToInt32(forms["ChannelId"]), TypeId = ConvertHelper.ToInt32(forms["SourceTypeId"]), CollectorId = ConvertHelper.ToInt32(forms["CollectorId"]), }; var now = DateTime.Now; var fullFileDir = Server.MapPath("/Uploads"); var fullFilePath = Server.MapPath("/Uploads/") + string.Format("{0}_{1}_{2}_{3}_{4}_{5}_", now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second) + excelfile.FileName; if (!Directory.Exists(fullFileDir)) { Directory.CreateDirectory(fullFileDir); } excelfile.SaveAs(fullFilePath); importInfo.TotalRow = 0; importInfo.CheckCount = 0; importInfo.ErrorCount = 0; importInfo.DuplicateCount = 0; importInfo.FilePath = fullFilePath; importInfo.ImportedDate = DateTime.Now; var id = ImportExcelRepository.Create(importInfo); var socketClient = new SocketClient("localhost", Constant.PortImportExcel); socketClient.SendMessage(id.ToString()); ViewBag.Message = id; } else { ViewBag.Message = "InvalidFileFormat"; } #region "End CheckPoint" watch.Stop(); checkPointApi.CheckPointNew(UserContext.GetCurrentUser().UserName, "ImportExcel", "End", watch.ElapsedMilliseconds); #endregion return(View()); }
public string Edit(FormDataCollection form) { var retVal = string.Empty; var operation = form.Get("oper"); var id = ConvertHelper.ToInt32(form.Get("ImportExcelId")); if (!string.IsNullOrEmpty(operation)) { ImportExcelInfo info; switch (operation) { case "edit": info = ImportExcelRepository.GetInfo(id); if (info != null) { /* * * info.ImportId = form.Get("ImportId"); * * info.UserId = form.Get("UserId"); * * info.TypeId = form.Get("TypeId"); * * info.ChannelId = form.Get("ChannelId"); * * info.CollectorId = form.Get("CollectorId"); * * info.BranchId = form.Get("BranchId"); * * info.Status = form.Get("Status"); * * info.FilePath = form.Get("FilePath"); * * info.TotalRow = form.Get("TotalRow"); * * info.CheckCount = form.Get("CheckCount"); * * info.ErrorCount = form.Get("ErrorCount"); * * info.DuplicateCount = form.Get("DuplicateCount"); * * info.ImportedDate = form.Get("ImportedDate"); * * ImportExcelRepository.Update(info); */ } break; case "add": info = new ImportExcelInfo(); /* * * info.ImportId = form.Get("ImportId"); * * info.UserId = form.Get("UserId"); * * info.TypeId = form.Get("TypeId"); * * info.ChannelId = form.Get("ChannelId"); * * info.CollectorId = form.Get("CollectorId"); * * info.BranchId = form.Get("BranchId"); * * info.Status = form.Get("Status"); * * info.FilePath = form.Get("FilePath"); * * info.TotalRow = form.Get("TotalRow"); * * info.CheckCount = form.Get("CheckCount"); * * info.ErrorCount = form.Get("ErrorCount"); * * info.DuplicateCount = form.Get("DuplicateCount"); * * info.ImportedDate = form.Get("ImportedDate"); * */ ImportExcelRepository.Create(info); break; case "del": ImportExcelRepository.Delete(id); break; } } return(retVal); }