//上傳廠商報價單 public string FileUpload(HttpPostedFileBase file) { log.Info("Upload form from supplier:" + Request["projectid"]); string projectid = Request["projectid"]; string iswage = "N"; if (null != Request["isWage"]) { log.Debug("isWage:" + Request["isWage"]); iswage = "Y"; } int i = 0; //上傳至廠商報價單目錄 if (null != file && file.ContentLength != 0) { var fileName = Path.GetFileName(file.FileName); string dir = ContextService.strUploadPath + "/" + projectid + "/" + ContextService.quotesFolder; ZipFileCreator.CreateDirectory(dir); var path = Path.Combine(dir, fileName); file.SaveAs(path); log.Info("Parser Excel File Begin:" + file.FileName); InquiryFormToExcel quoteFormService = new InquiryFormToExcel(); try { quoteFormService.convertInquiry2Project(path, projectid, iswage); } catch (Exception ex) { log.Error(ex.StackTrace); } //如果詢價單編號為空白,新增詢價單資料,否則更新相關詢價單資料-new log.Debug("Parser Excel File Finish!"); if (null != quoteFormService.form.FORM_ID && quoteFormService.form.FORM_ID != "") { log.Info("Update Form for Inquiry:" + quoteFormService.form.FORM_ID); i = service.refreshSupplierForm(quoteFormService.form.FORM_ID, quoteFormService.form, quoteFormService.formItems); } else { log.Info("Create New Form for Inquiry:"); i = service.createInquiryFormFromSupplier(quoteFormService.form, quoteFormService.formItems); } log.Info("add supplier form record count=" + i); } if (i == -1) { return("檔案匯入失敗!!"); } else { return("檔案匯入成功!!"); } }
/// <summary> /// 下載空白詢價單 /// </summary> public void downLoadInquiryForm() { string formid = Request["formid"]; service.getInqueryForm(formid); if (null != service.formInquiry) { InquiryFormToExcel poi = new InquiryFormToExcel(); //檔案位置 string fileLocation = poi.exportExcel(service.formInquiry, service.formInquiryItem, false); //檔案名稱 HttpUtility.UrlEncode預設會以UTF8的編碼系統進行QP(Quoted-Printable)編碼,可以直接顯示的7 Bit字元(ASCII)就不用特別轉換。 string filename = HttpUtility.UrlEncode(Path.GetFileName(fileLocation)); Response.Clear(); Response.Charset = "utf-8"; Response.ContentType = "text/xls"; Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", filename)); ///"\\" + form.PROJECT_ID + "\\" + ContextService.quotesFolder + "\\" + form.FORM_ID + ".xlsx" Response.WriteFile(fileLocation); Response.End(); } }