Beispiel #1
0
        public HttpResponseBase ImportVendorBank()
        {

            string json = "{success:false}";
            try
            {
                if (Request.Files["importFile"] != null && Request.Files["importFile"].ContentLength > 0)
                {
                    HttpPostedFileBase excelFile = Request.Files["importFile"];
                    FileManagement fileManagement = new FileManagement();
                    string i = excelFile.FileName;
                    string newExcelName = Server.MapPath(excelPath_export) + "供應商銀行代碼" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名
                    string oldExcelName = excelFile.FileName.Split('\\').LastOrDefault();
                    excelFile.SaveAs(newExcelName);//上傳文件
                    DataTable dt = new DataTable();
                    NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName);
                    dt = helper.SheetData();
                    string s = dt.Rows[0][0].ToString();
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        _vendorMgr = new VendorMgr(connectionString);
                        string result = _vendorMgr.ImportVendorBank(dt);
                        if (result == "")
                        {
                            json = "{success:true,error:\"0\"}";
                        }
                        else
                        {
                            json = "{success:true,error:\"" + result + "\"}";
                        }
                    }
                    FileInfo file = new FileInfo(newExcelName);
                    file.Delete();
                }

            }
            catch (Exception ex)
            {
                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                log.Error(logMessage);
                json = "{success:false,error:\"" + BLL.gigade.Common.CommonFunction.MySqlException(ex) + "\"}";

            }
            this.Response.Clear();
            this.Response.Write(json);
            this.Response.End();
            return this.Response;
        }