/// <summary> /// 上載現有標單資料 /// </summary> public string uploadProjectItem(HttpPostedFileBase file1) { string projectid = Request["id"]; logger.Debug("ProjectID=" + projectid + ",Upload ProjectItem=" + file1.FileName); TnderProjectService service = new TnderProjectService(); service.getProjectById(projectid); SYS_USER u = (SYS_USER)Session["user"]; if (null != file1 && file1.ContentLength != 0) { try { //2.解析Excel logger.Info("Parser Excel data:" + file1.FileName); //2.1 將上傳檔案存檔 var fileName = Path.GetFileName(file1.FileName); var path = Path.Combine(ContextService.strUploadPath + "/" + projectid, fileName); logger.Info("save excel file:" + path); file1.SaveAs(path); //2.2 解析Excel 檔案 //poiservice.ConvertDataForTenderProject(prj.PROJECT_ID, (int)prj.START_ROW_NO); ProjectItem2Excel poiservice = new ProjectItem2Excel(); poiservice.InitializeWorkbook(path); poiservice.ConvertDataForTenderProject(projectid); //2.3 記錄錯誤訊息 // < button type = "button" class="btn btn-primary" onclick="location.href='@Url.Action("ManagePlanItem","Plan", new { id = @Model.tndProject.PROJECT_ID})'; ">標單明細</button> //2.4 logger.Info("Delete Project_Item By Project ID"); service.delAllItemByProject(); //2.5 logger.Info("Add All Project_ITEM to DB"); service.refreshProjectItem(poiservice.lstProjectItem); } catch (Exception ex) { logger.Error(ex.StackTrace); return(ex.Message); } } if (service.strMessage != null) { return(service.strMessage); } else { return("匯入成功!!"); } }
public ActionResult Create(TND_PROJECT prj, HttpPostedFileBase file) { logger.Info("create project process! project =" + prj.ToString()); TnderProjectService service = new TnderProjectService(); SYS_USER u = (SYS_USER)Session["user"]; string message = ""; //1.更新或新增專案基本資料 if (prj.PROJECT_ID == "" || prj.PROJECT_ID == null) { //新增專案 prj.CREATE_USER_ID = u.USER_ID; prj.OWNER_USER_ID = u.USER_ID; prj.CREATE_DATE = DateTime.Now; service.newProject(prj); message = "建立專案:" + service.project.PROJECT_ID + "<br/>"; } else { //修改專案基本資料 prj.MODIFY_USER_ID = u.USER_ID; prj.MODIFY_DATE = DateTime.Now; service.updateProject(prj); message = "專案基本資料修改:" + prj.PROJECT_ID + "<br/>"; } //若使用者有上傳標單資料,則增加標單資料 if (null != file && file.ContentLength != 0) { //2.解析Excel logger.Info("Parser Excel data:" + file.FileName); //2.1 設定Excel 檔案名稱 prj.EXCEL_FILE_NAME = file.FileName; //2.2 將上傳檔案存檔 var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(ContextService.strUploadPath + "/" + prj.PROJECT_ID, fileName); logger.Info("save excel file:" + path); file.SaveAs(path); try { //2.2 解析Excel 檔案 ProjectItemFromExcel poiservice = new ProjectItemFromExcel(); poiservice.InitializeWorkbook(path); poiservice.ConvertDataForTenderProject(prj.PROJECT_ID, (int)prj.START_ROW_NO); //2.3 記錄錯誤訊息 message = message + "標單品項:共" + poiservice.lstProjectItem.Count + "筆資料,"; message = message + "<a target=\"_blank\" href=\"/Tender/ManageProjectItem?id=" + prj.PROJECT_ID + "\"> 標單明細檢視畫面單</a><br/>" + poiservice.errorMessage; // < button type = "button" class="btn btn-primary" onclick="location.href='@Url.Action("ManageProjectItem","Tender", new { id = @Model.tndProject.PROJECT_ID})'; ">標單明細</button> //2.4 logger.Info("Delete TND_PROJECT_ITEM By Project ID"); service.delAllItemByProject(); //2.5 logger.Info("Add All TND_PROJECT_ITEM to DB"); service.refreshProjectItem(poiservice.lstProjectItem); } catch (Exception ex) { logger.Error("Error Message:" + ex.Message + "." + ex.StackTrace); message = ex.Message; } } ViewBag.projectId = service.project.PROJECT_ID; ViewBag.result = message; return(View(service.project)); }