/// <summary> /// 匯入會計入帳時間 /// </summary> /// <returns></returns> public HttpResponseBase OrderMasterImport() { string json = string.Empty;//json字符串 //string shipment = Request.Params["shipment"].ToString(); //int total = 0; try { if (Request.Files["ImportFileMsg"] != null && Request.Files["ImportFileMsg"].ContentLength > 0)//判斷文件是否為空 { HttpPostedFileBase excelFile = Request.Files["ImportFileMsg"];//獲取文件流 FileManagement fileManagement = new FileManagement();//實例化 FileManagement string fileLastName = excelFile.FileName; string newExcelName = Server.MapPath(excelPath) + "會計賬款實收時間" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名 excelFile.SaveAs(newExcelName);//上傳文件 DataTable dt = new DataTable(); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); dt = helper.SheetData(); List<OrderAccountCollection> oacli = new List<OrderAccountCollection>(); string errorStr = string.Empty; Int64[] orderArr = new Int64[dt.Rows.Count]; for (int j = 0; j < dt.Rows.Count; j++) { OrderAccountCollection model = new OrderAccountCollection(); uint order_id = 0; if (!string.IsNullOrEmpty(dt.Rows[j][0].ToString())) { if (uint.TryParse(dt.Rows[j][0].ToString(), out order_id)) { model.order_id = order_id; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } if (!string.IsNullOrEmpty(dt.Rows[j][1].ToString())) { DateTime st; if (DateTime.TryParse(dt.Rows[j][1].ToString(), out st)) { model.account_collection_time = st; } else { string strtime = Regex.Replace(dt.Rows[j][1].ToString().Trim(), "/(\\s+)|(,)|(-)|(,)|(.)/g", "/"); if (DateTime.TryParse(strtime, out st)) { model.account_collection_time = st; } else { string[] str = dt.Rows[j][1].ToString().Split('/'); int year = 0; if (str.Length == 3) { if (str[2].Length == 2) { year = Convert.ToInt32("20" + str[2]); } else { year = Convert.ToInt32(str[2]); } int month = Convert.ToInt32(str[0]); int day = Convert.ToInt32(str[1]); if (DateTime.TryParse(year + "/" + month + "/" + day, out st)) { model.account_collection_time = st; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } } } if (!string.IsNullOrEmpty(dt.Rows[j][2].ToString())) { int account_collection_money = 0; if (int.TryParse(dt.Rows[j][2].ToString(), out account_collection_money)) { model.account_collection_money = account_collection_money; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } if (!string.IsNullOrEmpty(dt.Rows[j][3].ToString())) { int poundage = 0; if (int.TryParse(dt.Rows[j][3].ToString(), out poundage)) { model.poundage = poundage; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } } if (!string.IsNullOrEmpty(dt.Rows[j][4].ToString())) { DateTime streturn; if (DateTime.TryParse(dt.Rows[j][4].ToString(), out streturn)) { model.return_collection_time = streturn; } else { string strtimeR = Regex.Replace(dt.Rows[j][4].ToString().Trim(), "/(\\s+)|(,)|(-)|(,)|(.)/g", "/"); if (DateTime.TryParse(strtimeR.ToString(), out streturn)) { model.return_collection_time = streturn; } else { string[] strR = dt.Rows[j][4].ToString().Split('/'); int yearR = 0; if (strR.Length == 3) { if (strR[2].Length == 2) { yearR = Convert.ToInt32("20" + strR[2]); } else { yearR = Convert.ToInt32(strR[2]); } int monthR = Convert.ToInt32(strR[0]); int dayR = Convert.ToInt32(strR[1]); if (DateTime.TryParse(yearR + "/" + monthR + "/" + dayR, out streturn)) { model.return_collection_time = streturn; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } } } if (!string.IsNullOrEmpty(dt.Rows[j][5].ToString())) { int return_collection_money = 0; if (int.TryParse(dt.Rows[j][5].ToString(), out return_collection_money)) { model.return_collection_money = return_collection_money; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } if (!string.IsNullOrEmpty(dt.Rows[j][6].ToString())) { int return_poundage = 0; if (int.TryParse(dt.Rows[j][6].ToString(), out return_poundage)) { model.return_poundage = return_poundage; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } } if (!string.IsNullOrEmpty(dt.Rows[j][7].ToString())) { DateTime st; if (DateTime.TryParse(dt.Rows[j][7].ToString(), out st)) { model.invoice_date_manual = st; } else { string strtime = Regex.Replace(dt.Rows[j][1].ToString().Trim(), "/(\\s+)|(,)|(-)|(,)|(.)/g", "/"); if (DateTime.TryParse(strtime, out st)) { model.invoice_date_manual = st; } else { string[] str = dt.Rows[j][7].ToString().Split('/'); int year = 0; if (str.Length == 3) { if (str[2].Length == 2) { year = Convert.ToInt32("20" + str[2]); } else { year = Convert.ToInt32(str[2]); } int month = Convert.ToInt32(str[0]); int day = Convert.ToInt32(str[1]); if (DateTime.TryParse(year + "/" + month + "/" + day, out st)) { model.invoice_date_manual = st; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } } } if (!string.IsNullOrEmpty(dt.Rows[j][8].ToString())) { int invoice_sale_manual = 0; if (int.TryParse(dt.Rows[j][8].ToString(), out invoice_sale_manual)) { model.invoice_sale_manual = invoice_sale_manual; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } if (!string.IsNullOrEmpty(dt.Rows[j][9].ToString())) { int invoice_tax_manual = 0; if (int.TryParse(dt.Rows[j][9].ToString(), out invoice_tax_manual)) { model.invoice_tax_manual = invoice_tax_manual; } else { errorStr += (j + 2) + ","; continue; } } else { errorStr += (j + 2) + ","; continue; } } model.remark = dt.Rows[j][10].ToString(); if (model != null && !(model.account_collection_time == model.return_collection_time && model.account_collection_time == model.invoice_date_manual && model.return_collection_time == DateTime.MinValue)) { if (!orderArr.Contains(model.order_id)) { orderArr[j] = order_id; oacli.Add(model); } else { errorStr += (j + 2) + ","; } } } int rowsnum = oacli.Count; if (!string.IsNullOrEmpty(errorStr)) { errorStr = errorStr.Remove(errorStr.Length - 1); } if (rowsnum > 0)//判斷是否是這個表 { _OrderMasterMgr = new OrderMasterMgr(connectionString); int i = _OrderMasterMgr.OrderMasterImport(oacli); if (i > 0) { if (i == 99999) { if (!string.IsNullOrEmpty(errorStr)) { json = "{success:true,msg:\"" + "無數據可匯入!另文件第" + errorStr + "行數據異常\"}"; } else { json = "{success:true,msg:\"" + "無數據可匯入!\"}"; } } else { if (!string.IsNullOrEmpty(errorStr)) { json = "{success:true,msg:\"" + "匯入成功!另文件第" + errorStr + "行數據異常\"}"; } else { json = "{success:true,msg:\"" + "匯入成功!\"}"; } } } else { if (!string.IsNullOrEmpty(errorStr)) { json = "{success:true,msg:\"" + "操作失敗!另文件第" + errorStr + "行數據異常\"}"; } else { json = "{success:true,msg:\"" + "操作失敗!\"}"; } } } else { json = "{success:true,total:0,msg:\"" + "此表內沒有數據或數據有誤,請檢查后再次匯入!" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else//當直接點擊時會產生, { json = "{success:true,msg:\"" + "操作失敗!" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } 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:true,msg:\"" + "操作失敗!" + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public ActionResult upLoadImg() { HttpPostedFileBase file = Request.Files["Filedata"]; int type = Request["appOrexplain"] == null ? 0 : Convert.ToInt32(Request["appOrexplain"]); string nameType = Request.Params["nameType"];// 將 nametype 提前 使其判斷傳入的圖片是否為商品主圖 edit by zhuoqin0830w 2015/01/29 int prodCheck = file.FileName.LastIndexOf("prod_");// 將 proCheck 提前 使其判斷批量上傳的圖片中是否存在商品主圖 edit by zhuoqin0830w 2015/01/30 if (prodCheck == 0 && type == 0) { type = 3; } int mobileCheck = file.FileName.LastIndexOf("mobile_"); if (mobileCheck == 0 && type == 0) { type = 4; } string path = Server.MapPath(xmlPath); siteConfigMgr = new SiteConfigMgr(path); ViewBag.moreFileOneTime = false; SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = null; //判斷 批量上傳 或 單個上傳 的圖片是否為 商品主圖 或 手機商品圖 edit by zhuoqin0830w 2015/03/24 switch (nameType) { //如果 nameType == prod 則表示 是 單個上傳 商品主圖 case "prod": maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max"); break; //如果 nameType == mobile 則表示 是 單個上傳 手機商品圖 case "mobile": maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); break; //如果 nameType == null 則表示 是 批量上傳 case null: //如果 prodCheck == 0 則表示 是 單個上傳 商品主圖 if (prodCheck == 0) { maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max"); } //如果 mobileCheck == 0 則表示 是 單個上傳 手機商品圖 else if (mobileCheck == 0) { maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); } else { maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); } break; default: maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); break; } SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; if ((nameType == "mobile" && type == 4) || (mobileCheck == 0 && type == 4)) //add by wwei0216w 2015/4/1 添加原因:手機圖片要放在640*640路徑下 { prodPath = prodMobile640; } string localProdPath = imgLocalPath + prodPath; //string localProd50Path = imgLocalPath + prod50Path; //string localProd150Path = imgLocalPath + prod150Path; //string localProd280Path = imgLocalPath + prod280Path; string localSpecPath = imgLocalPath + specPath; //string localSpec100Path = imgLocalPath + spec100Path; //string localSpec280Path = imgLocalPath + spec280Path; string[] Mappath = new string[2]; FileManagement fileLoad = new FileManagement(); string fileName = string.Empty; string fileExtention = string.Empty; ViewBag.spec_id = -1; if (nameType != null) { fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower(); } else { #region 批次上傳圖片操作 //此處由批次上傳進入. //判斷文件名格式是否正確 ViewBag.moreFileOneTime = true; //int prodCheck = file.FileName.LastIndexOf("prod_"); //int specCheck = file.FileName.LastIndexOf("spec_"); int descCheck = file.FileName.LastIndexOf("desc_"); int appCheck = file.FileName.LastIndexOf("app_"); string errorMsg = "ERROR/"; if (prodCheck == -1 && descCheck == -1 && appCheck == -1 && mobileCheck == -1) { errorMsg += "[" + file.FileName + "] "; errorMsg += Resources.Product.FILE_NAME_ERROR; ViewBag.fileName = errorMsg; return View("~/Views/Product/upLoad.cshtml"); } else { nameType = file.FileName.Split('_')[0]; if (nameType == "app") { type = 2; } else if (nameType == "desc") { type = 1; } fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')); } #endregion } SetPath(type);//設定圖片路徑 string localDescPath = imgLocalPath + descPath; //string localDesc400Path = imgLocalPath + desc400Path; string returnName = imgServerPath; bool result = false; string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; string ServerPath = string.Empty; if (nameType == "desc" || nameType == "app") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localDescPath, Mappath); //CreateFolder(localDesc400Path, Mappath); localDescPath += firstFolder + secondFolder; //localDesc400Path += firstFolder + secondFolder; descPath += firstFolder + secondFolder; //localDesc400Path += NewFileName + fileExtention; returnName += descPath + NewFileName + fileExtention; NewFileName = localDescPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + descPath); } else { Mappath[0] = firstFolder; Mappath[1] = secondFolder; //Data:2014/06/26 //author:Castle //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!! CreateFolder(localProdPath, Mappath); localProdPath += firstFolder + secondFolder; prodPath += firstFolder + secondFolder; returnName += prodPath + NewFileName + fileExtention; NewFileName = localProdPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + prodPath); } string ErrorMsg = string.Empty; Resource.CoreMessage = new CoreResource("Product"); try { //上傳圖片 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); //上傳對應大小圖片 //压缩图片至其它规格 } 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); } if (string.IsNullOrEmpty(ErrorMsg)) { ViewBag.fileName = returnName; ViewBag.Type = type; //獲取文件長度 add by zhuoqin0830w 2015/01/29 string[] strFile = file.FileName.Split('_'); //判斷文件名的長度是否大於 1 如果大於 1 則再次進行判斷是否為數字 如果不是則進行強制轉換 int image_sort = 0; int.TryParse(strFile.Length > 1 ? strFile[1] : "0", out image_sort); ViewBag.image_sort = image_sort; } else { // 判斷 批量上傳中 是否存在 商品圖 或 手機商品圖 edit by zhuoqin0830w 2015/03/24 if (prodCheck == 0 || mobileCheck == 0) { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; } else { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; } Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = "ERROR/" + ErrorMsg; logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } return View("~/Views/Product/upLoad.cshtml"); }
//public DataSet ExecleDs(string filenameurl, string table) //{ // try //如果存在問題 比如說隨便輸入一個execl檔 // { // string strConn = "Provider=Microsoft.Jet.OleDb.4.0;" + "data source=" + filenameurl + ";Extended Properties='Excel 8.0; HDR=YES; IMEX=1'"; // OleDbConnection conn = new OleDbConnection(strConn); // conn.Open(); // DataSet ds = new DataSet(); // string tablename = "象印"; // //這裡表可能是漢字.解決方法("select * from ["+ tablename+"$]") // OleDbDataAdapter odda = new OleDbDataAdapter("select * from [" + tablename + "$]", conn); // //OleDbDataAdapter odda = new OleDbDataAdapter("select * from [Sheet1$]", conn); // odda.Fill(ds, table); // return ds; // } // catch(Exception ex) // { // DataSet dsSet = new DataSet(); // DataTable dtTable = new DataTable(); // dtTable = dsSet.Tables.Add(); // return dsSet; // } //} #endregion public HttpResponseBase InsertBoilerMessage() { int j = 0; string json = string.Empty;//json字符串 int total=0; try { if (Request.Files["ImportFileMsg"] != null && Request.Files["ImportFileMsg"].ContentLength > 0)//判斷文件是否為空 { HttpPostedFileBase excelFile = Request.Files["ImportFileMsg"];//獲取文件流 FileManagement fileManagement = new FileManagement();//實例化 FileManagement //string fileLastName = excelFile.FileName.Substring((excelFile.FileName).LastIndexOf('.')).ToLower().Trim(); string fileLastName = excelFile.FileName; string newExcelName = Server.MapPath(excelPath) + "BoilerRelation" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名 excelFile.SaveAs(newExcelName);//上傳文件 DataTable dt = new DataTable(); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); dt = helper.SheetData(); //DataSet ds = ExecleDs(newExcelName, fileLastName);//调用自定义方法 ////excelHelper = new NPOI4ExcelHelper(newExcelName); DataRow[] dr = dt.Select(); //定义一个DataRow数组,读取ds里面所有行 int rowsnum = dt.Rows.Count; if(rowsnum !=0)//判斷是否是這個表 { if (dr[0][2].ToString().Trim() != "外鍋型號 (依款式&字母順序排列)" && dr[0][3].ToString().Trim() != "內鍋型號" && dr[0][4].ToString().Trim() != "對應安康內鍋型號" && dr[0][5].ToString().Trim() != "備註") { rowsnum = 0; } } if (rowsnum == 0) { json = "{success:true,total:0,msg:\"" + "此表內沒有數據或數據有誤,請檢查后再次匯入!" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } else { _boillationMgr = new BoilerrelationMgr(mySqlConnectionString); j = _boillationMgr.GetintoBoilerrelation(dr,out total); if (j > 0) { json = "{success:true,total:\"" + total + "\",msg:\"" + "匯入安康內鍋型號對照表成功!" + "\"}"; } else { json = "{success:true,total:\"" + total + "\",msg:\"" + "匯入數據標準不對,請嚴格按照模板匯入!" + "\"}"; } } } else//當直接點擊時會產生, { json = "{success:true,msg:\"" + "請匯入安康內鍋型號對照表" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } 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,msg:\"" + ex.ToString() + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
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; }
public void InsertIntoPromoShareCon(PromoShareCondition query) { List<PromoShareCondition> list = new List<PromoShareCondition>(); PshareConMgr = new PromoShareConditionMgr(mySqlConnectionString); string json = string.Empty; DataTable _dt=new DataTable(); try { for (int i = 0; i < condition.Length; i++) { if (!string.IsNullOrEmpty(Request.Params[condition[i]])) { query = new PromoShareConditionQuery(); query.promo_id = Convert.ToInt32(Request.Params["promo_id"]); query.condition_name = condition[i]; query.condition_value = Request.Params[ condition[i]]; if (query.condition_name == "picture") { #region 上傳圖片 string ErrorMsg = string.Empty; string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + promoPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; HashEncrypt hash = new HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - promoPath.Length + 1), promoPath.Substring(1, promoPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + promoPath); //上傳之前刪除已有的圖片 if (query.promo_id != 0) { _dt = PshareConMgr.Get(condition, query); if (_dt.Rows[0]["picture"].ToString() != "") { string oldFileName = _dt.Rows[0]["picture"].ToString(); CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product"); bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.condition_value = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); } } } else { query.condition_value = _dt.Rows[0]["picture"].ToString(); } #endregion } list.Add(query); } } PshareConMgr.AddSql(list); } 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}"; } }
public HttpResponseBase AddorEdit() { string json = string.Empty; string errorInfo = string.Empty; uint brand_id = 0; bool result = false; try { _promotionBannerMgr = new PromotionBannerMgr(mySqlConnectionString); int i = 0; PromotionBannerQuery query = new PromotionBannerQuery(); PromotionBannerQuery oldquery = new PromotionBannerQuery(); if (!string.IsNullOrEmpty(Request.Params["pb_id"])) { oldquery.pb_id = Convert.ToInt32(Request.Params["pb_id"]); List<PromotionBannerQuery> oldModel = _promotionBannerMgr.GetModelById(oldquery.pb_id); if (oldModel != null) { query.pb_image = oldModel[0].pb_image; } } #region 上傳圖片 string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + brandPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); for (int j = 0; j < Request.Files.Count; j++) { string fileName = string.Empty;//當前文件名 HttpPostedFileBase file = Request.Files[j]; fileName = Path.GetFileName(file.FileName); if (string.IsNullOrEmpty(fileName)) { continue; } fileLoad = new FileManagement(); string oldFileName = string.Empty; //舊文件名 string fileExtention = string.Empty;//當前文件的擴展名 string NewFileName = string.Empty; string ServerPath = string.Empty; string newRand = string.Empty; string ErrorMsg = string.Empty; newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; string folder1 = NewFileName.Substring(0, 2) + "/"; //圖片名前兩碼 string folder2 = NewFileName.Substring(2, 2) + "/"; //圖片名第三四碼 FTP f_cf = new FTP(); localPromoPath = imgLocalPath + brandPath + folder1 + folder2; //圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (brandPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (brandPath + folder1 + folder2).Substring(1, (brandPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + brandPath + folder1 + folder2); fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.pb_image = fileName; } else { errorInfo += ErrorMsg; } } #endregion if (!string.IsNullOrEmpty(Request.Params["image_link"])) { query.pb_image_link = Request.Params["image_link"]; } if (!string.IsNullOrEmpty(Request.Params["begin_time"])) { query.pb_startdate = Convert.ToDateTime(Request.Params["begin_time"]); } if (!string.IsNullOrEmpty(Request.Params["end_time"])) { query.pb_enddate = Convert.ToDateTime(Request.Params["end_time"]); } if (!string.IsNullOrEmpty(Request.Params["vb_ids"])) { query.brandIDS = Request.Params["vb_ids"].Substring(0, Request.Params["vb_ids"].LastIndexOf(',')); } if (!string.IsNullOrEmpty(Request.Params["multi"])) { query.multi = Convert.ToInt32(Request.Params["multi"]); } if (!string.IsNullOrEmpty(Request.Params["pb_id"])) { //編輯 query.pb_id = Convert.ToInt32(Request.Params["pb_id"]); query.pb_muser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); result = _promotionBannerMgr.UpdateImageInfo(query, out brand_id); if (result && string.IsNullOrEmpty(errorInfo)) { json = "{success:true}"; } else if (result == false && brand_id != 0) { json = "{success:false,msg:\"" + brand_id + "\"}";//brand_id重複 } else if (result && !string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"數據保存成功<br/>但圖片保存失敗 <br/>" + errorInfo + "\"}"; } else { json = "{success:false}"; } } else { //新增 query.pb_kuser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); query.pb_muser = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); result = _promotionBannerMgr.AddImageInfo(query, out brand_id); if (result && string.IsNullOrEmpty(errorInfo)) { json = "{success:true}"; } else if (result == false && brand_id != 0) { json = "{success:false,msg:\"" + brand_id + "\"}";//brand_id重複 } else if (result && !string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"數據保存成功<br/>但圖片保存失敗 <br/>" + errorInfo + "\"}"; } else { json = "{success:false}"; } } } 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}"; } this.Response.Clear(); this.Response.Write(json.ToString()); this.Response.End(); return this.Response; }
public HttpResponseBase upLoadImg() { string json = string.Empty; string errorInfo = string.Empty; VendorBrandSetQuery query = new VendorBrandSetQuery(); query.Brand_Id = uint.Parse(Request.Params["brand_id"]); query.image_sort = 0; query.image_state = 1; query.image_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()); _IvendorBrandSet = new VendorBrandSetMgr(connectionString); ImagePathConfig(); string fileName = String.Empty, fileExtention = String.Empty, newFileName = String.Empty, oldFileName = String.Empty; //string localPromoPath = imgLocalPath + vendorPath;//圖片存儲地址 string localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址 FileManagement fileLoad;//+++++++++++++++++ Boolean sort_repeat = false; for (int i = 0; i < Request.Files.Count; i++) { fileLoad = new FileManagement();//+++++++++++++++ HttpPostedFileBase file = Request.Files[i]; fileName = Path.GetFileName(file.FileName); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); string[] arrary = fileName.Split('_'); if (arrary.Length < 3) { errorInfo += "[" + file.FileName + "] "; errorInfo += Resources.Product.FILE_NAME_ERROR; errorInfo += " 例:brand_1_tupian" + fileExtention; continue; } string brandStr = fileName.Split('_')[0].ToString(); string sortStr = fileName.Split('_')[1].ToString(); string filenameStr = fileName.Split('_')[2].ToString(); Regex reg = new Regex("^?[1-9][0-9]*$"); if (!brandStr.Equals("brand") || !reg.IsMatch(sortStr)) { errorInfo += "[" + file.FileName + "] "; errorInfo += Resources.Product.FILE_NAME_ERROR; errorInfo += " 例:brand_1_tupian" + fileExtention; continue; } query.image_sort = Convert.ToUInt32(sortStr); if (query.image_sort > 255) query.image_sort = 0; //大於數據庫存儲範圍時,默認為0; string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); newFileName = newRand + fileExtention; string folder1 = newFileName.Substring(0, 2) + "/";//圖片名前兩碼 string folder2 = newFileName.Substring(2, 2) + "/";//圖片名第三四碼 string ServerPath = string.Empty; FTP f_cf = new FTP(); localPromoPath = imgLocalPath + vendorOriginalPath + folder1 + folder2;//圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (vendorOriginalPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (vendorOriginalPath + folder1 + folder2).Substring(1, (vendorOriginalPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + vendorOriginalPath + folder1 + folder2); fileName = newFileName; newFileName = localPromoPath + newFileName;//絕對路徑 string ErrorMsg = string.Empty; //錯誤消息 //Resource.CoreMessage = new CoreResource("Vendor");//尋找product.resx中的資源文件 try { bool result = fileLoad.UpLoadFile(file, ServerPath, newFileName, extention, 150, int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { //查詢image_sort是否存在重複 if (_IvendorBrandSet.GetSortIsRepeat(query)) { sort_repeat = true; } query.image_filename = fileName; _IvendorBrandSet.SaveBrandStory(query); errorInfo += "[" + file.FileName + "] " + "上傳成功!"; } else { errorInfo += "[" + file.FileName + "] " + ErrorMsg; } } 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); errorInfo += "[" + file.FileName + "] 上傳失敗<br/>"; //json = "{success:false,msg:\"操作失敗,請稍后再試!\"}"; //if (!string.IsNullOrEmpty(errorInfo)) //{ // json = "{success:false,msg:\"<div>操作失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}"; //} } fileName = String.Empty; fileExtention = String.Empty; newFileName = String.Empty; oldFileName = String.Empty;//++++++++++++++++++ localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址//++++++++++++++++++++ } if (sort_repeat)// json = "{success:true,sort_repeat:true,msg:\"<div>" + errorInfo + "</div>\"}"; else json = "{success:true,sort_repeat:false,msg:\"<div>" + errorInfo + "</div>\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase PaperEdit() { string json = string.Empty; Paper p = new Paper(); _paperMgr = new PaperMgr(mySqlConnectionString); string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localBannerPath = imgLocalPath + PaperPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); try { List<Paper> store = new List<Paper>(); if (!string.IsNullOrEmpty(Request.Params["paper_id"])) { int totalCount = 0; p.IsPage = false; p.paperID = int.Parse(Request.Params["paper_id"]); store = _paperMgr.GetPaperList(p, out totalCount); } string oldImg = string.Empty; foreach (var item in store) { oldImg = item.paperBanner; } p = new Paper(); p.paperName = Request.Params["paper_name"]; p.paperMemo = Request.Params["paper_memo"]; p.bannerUrl = Request.Params["banner_url"]; if (!string.IsNullOrEmpty(Request.Params["paper_start"])) { p.paperStart = DateTime.Parse(DateTime.Parse(Request.Params["paper_start"]).ToString("yyyy-MM-dd HH:mm:ss")); } if (!string.IsNullOrEmpty(Request.Params["paper_end"])) { p.paperEnd = DateTime.Parse(DateTime.Parse(Request.Params["paper_end"]).ToString("yyyy-MM-dd HH:mm:ss")); } p.event_ID = Request.Params["eventid"]; if (!string.IsNullOrEmpty(Request.Params["isRepeatGift"])) { p.isRepeatGift = int.Parse(Request.Params["isRepeatGift"]); } //if (!string.IsNullOrEmpty(Request.Params["isPromotion"])) //{ // p.isPromotion = int.Parse(Request.Params["isPromotion"]); // if (p.isPromotion == 1) // { // p.promotionUrl = Request.Params["promotion_url"]; // } //} //if (!string.IsNullOrEmpty(Request.Params["isPromotion"])) //{ // p.isPromotion = int.Parse(Request.Params["isPromotion"]); // if (p.isPromotion == 1) // { // p.promotionUrl = Request.Params["promotion_url"]; // } //} //if (!string.IsNullOrEmpty(Request.Params["isGiveBonus"])) //{ // p.isGiveBonus = int.Parse(Request.Params["isGiveBonus"]); // if (p.isGiveBonus == 1) // { // if (!string.IsNullOrEmpty(Request.Params["bonus_num"])) // { // p.bonusNum = int.Parse(Request.Params["bonus_num"]); // } // } //} //if (!string.IsNullOrEmpty(Request.Params["isGiveProduct"])) //{ // p.isGiveProduct = int.Parse(Request.Params["isGiveProduct"]); // if (p.isGiveProduct == 1) // { // if (!string.IsNullOrEmpty(Request.Params["product_id"])) // { // p.productID = int.Parse(Request.Params["product_id"]); // } // } //} if (!string.IsNullOrEmpty(Request.Params["isRepeatWrite"])) { p.isRepeatWrite = int.Parse(Request.Params["isRepeatWrite"]); } if (!string.IsNullOrEmpty(Request.Params["isNewMember"])) { p.isNewMember = int.Parse(Request.Params["isNewMember"]); } p.creator = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); System.Net.IPAddress[] addlist = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList; if (addlist.Length > 0) { p.ipfrom = addlist[0].ToString(); } if (!string.IsNullOrEmpty(Request.Params["paper_id"]) && Request.Params["paper_banner"] == oldImg) { p.paperBanner = oldImg; } else { string ServerPath = string.Empty; ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); if (Request.Files.Count > 0)//單個圖片上傳 { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑 string ErrorMsg = string.Empty; bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { p.paperBanner = fileName; //上傳新圖片成功后,再刪除舊的圖片 CommonFunction.DeletePicFile(ServerPath + oldImg);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldImg)) { FTP ftps = new FTP(localBannerPath + oldImg, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldImg);//刪除ftp:71.159上的舊圖片 } } else { p.paperBanner = oldImg; } } else { //上傳之前刪除已有的圖片 CommonFunction.DeletePicFile(ServerPath + oldImg);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldImg)) { FTP ftps = new FTP(localBannerPath + oldImg, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldImg);//刪除ftp:71.159上的舊圖片 } p.paperBanner = ""; } } } #region 新增 if (String.IsNullOrEmpty(Request.Params["paper_id"])) { if (_paperMgr.Add(p) > 0) { json = "{success:true,msg:\"" + "新增成功!" + "\"}"; } } #endregion #region 編輯 else { p.paperID = int.Parse(Request.Params["paper_id"]); p.modifier = int.Parse((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id.ToString()); if (_paperMgr.Update(p) > 0) { json = "{success:true,msg:\"" + "修改成功!" + "\"}"; } } #endregion } catch (Exception ex) { json = "{success:false,msg:\"" + "異常" + "\"}"; 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase ImportCsv() { string json = ""; string errorMsg = ""; string repeatMsg = ""; _userGroupMgr = new VipUserGroupMgr(mySqlConnectionString); string sqlwhere = string.Empty; VipUser query = new VipUser(); int add = 0; int repeat = 0; int error = 0; string newCSVName = string.Empty; string check_iden = string.Empty; List<string> emp_id = new List<string>(); if (!string.IsNullOrEmpty(Request.Params["group_id"])) { query.group_id = Convert.ToUInt32(Request.Params["group_id"]); } if (!string.IsNullOrEmpty(Request.Params["check_iden"])) { check_iden = Request.Params["check_iden"]; } siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath)); try { if (Request.Files["ImportCsvFile"] != null && Request.Files["ImportCsvFile"].ContentLength > 0) { //一些文件的方法,包括获取文件的类型、长度、保存 HttpPostedFileBase excelFile = Request.Files["ImportCsvFile"]; //自定义的类,其中包括一些文件的处理方法 FileManagement fileManagement = new FileManagement(); //文件重命名,然後設置存儲的路徑 newCSVName = Server.MapPath(excelPath) + "user_io" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名 System.Data.DataTable _dt = new DataTable(); excelFile.SaveAs(newCSVName);// _dt = CsvHelper.ReadCsvToDataTable(newCSVName, true); //匯入員工編號 DataTable btopEmp = _userGroupMgr.BtobEmp(query.group_id.ToString()); for (int k = 0; k < btopEmp.Rows.Count; k++) { if (!string.IsNullOrEmpty(btopEmp.Rows[k]["emp_id"].ToString())) { emp_id.Add(btopEmp.Rows[k]["emp_id"].ToString()); } } //郵箱的格式 Regex num = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"); for (int i = 0; i < _dt.Rows.Count; i++) { //只讀第一列,其餘列忽略 for (int j = 0; j < 1; j++) { //匯入員工編號 if (!string.IsNullOrEmpty(check_iden)) { int u1 = _userGroupMgr.UpdateEmp(query.group_id.ToString(), _dt.Rows[i][j].ToString(), 1); if (emp_id.Contains(_dt.Rows[i][j].ToString())) { int u2 = _userGroupMgr.UpdateEmp(query.group_id.ToString(), _dt.Rows[i][j].ToString(), 2); json = "{success:true,msg:\"" + "上傳成功!" + "\"}"; } else { int h = _userGroupMgr.InsertEmp(query.group_id.ToString(), _dt.Rows[i][j].ToString()); json = "{success:true,msg:\"" + "上傳成功!" + "\"}"; } } //匯入郵箱 else { //郵箱的格式驗證 if (!num.IsMatch(_dt.Rows[i][j].ToString())) { errorMsg += "<br/>第" + (i + 1) + "條第" + (j + 1) + "列數據錯誤"; error++; } else { sqlwhere = _dt.Rows[i][j].ToString(); DataTable dtUser = _userGroupMgr.GetUser(sqlwhere); //判斷郵箱是否是存在于users表中 if (dtUser.Rows.Count > 0) { query.user_email = _dt.Rows[i][j].ToString(); DataTable VipUserExist = _userGroupMgr.GetVipUser(query); //根據郵箱和group_id來判斷vip_user表中是否存在此數據,若不存在,就添加,若存在,就不添加 if (VipUserExist.Rows.Count == 0) { query.vuser_email = _dt.Rows[i][j].ToString(); query.createdate = (uint)CommonFunction.GetPHPTime(DateTime.Now.ToString()); if (!string.IsNullOrEmpty(dtUser.Rows[0][0].ToString())) { query.User_Id = Convert.ToUInt32(dtUser.Rows[0][0]); } int k = _userGroupMgr.InsertVipUser(query); if (k > 0) { add++; } } else { //json = "{success:false,msg:\"" + "第" + i + 1 + "條第" + j + "列數據重複" + "\"}"; repeatMsg += "<br/>第" + (i + 1) + "條第" + (j + 1) + "列數據重複"; repeat++; } } else { //json = "{success:false,msg:\"" + "第" + i + 1 + "條第" + j + "列數據錯誤" + "\"}"; errorMsg += "<br/>第" + (i + 1) + "條第" + (j + 1) + "列數據錯誤"; error++; } } } } } //string[] colname = new string[_dt.Columns.Count]; //for (int i = 0; i < _dt.Columns.Count; i++) //{ // colname[i] = _dt.Columns[i].ColumnName; //} //CsvHelper.ExportDataTableToCsv(_dt, newExcelName, colname, true); json = "{success:true,msg:\"" + errorMsg + repeatMsg + "<br/>" + "上傳成功!<br/>新增:" + add + "<br/>重複:" + repeat + "<br/>錯誤:" + error + "<br/>總計:" + _dt.Rows.Count + "\"}"; } else { json = "{success:false,msg:\"" + "請匯入檔案" + "\"}"; } } 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); //出現異常后,刪除上傳的文件 if (System.IO.File.Exists(newCSVName)) { //設置文件的屬性,以防刪除文件的時候因為文件的屬性造成無法刪除 System.IO.File.SetAttributes(newCSVName, FileAttributes.Normal); System.IO.File.Delete(newCSVName); } json = "{success:false,msg:\"" + errorMsg + repeatMsg + "上傳失敗!" + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase ImportExcel() { string json = string.Empty; try { BLL.gigade.Model.SiteAnalytics query = new BLL.gigade.Model.SiteAnalytics(); if (Request.Files.Count > 0) { string path = Request.Params["ImportExcel"]; HttpPostedFileBase excelFile = Request.Files["ImportExcel"]; FileManagement fileManagement = new FileManagement(); string newExcelName = Server.MapPath(excelPath) + "analytics" + fileManagement.NewFileName(excelFile.FileName); excelFile.SaveAs(newExcelName); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); DataTable _dt = helper.ExcelToTableForXLSX(); _siteAnalytics = new SiteAnalyticsMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["search_con"])) { query.search_con = Convert.ToInt32(Request.Params["search_con"]); } if (!string.IsNullOrEmpty(Request.Params["serch_sa_date"])) { query.s_sa_date = (Convert.ToDateTime(Request.Params["serch_sa_date"]).ToString("yyyy-MM-dd")); } json = _siteAnalytics.ImportExcelToDt(_dt);//匯入成功 } } 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}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public ActionResult upLoadImg() { BLL.gigade.Model.Vendor vendorModel = (BLL.gigade.Model.Vendor)Session["vendor"];//獲取當前登入的供應商 int writerID = (int)vendorModel.vendor_id; string path = Server.MapPath(xmlPath); siteConfigMgr = new SiteConfigMgr(path); ViewBag.moreFileOneTime = false; SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localProdPath = imgLocalPath + prodPath; //string localProd50Path = imgLocalPath + prod50Path; //string localProd150Path = imgLocalPath + prod150Path; //string localProd280Path = imgLocalPath + prod280Path; string localSpecPath = imgLocalPath + specPath; //string localSpec100Path = imgLocalPath + spec100Path; //string localSpec280Path = imgLocalPath + spec280Path; string localDescPath = imgLocalPath + descPath; //string localDesc400Path = imgLocalPath + desc400Path; string[] Mappath = new string[2]; FileManagement fileLoad = new FileManagement(); HttpPostedFileBase file = Request.Files["Filedata"]; string nameType = Request.Params["nameType"]; string fileName = string.Empty; string fileExtention = string.Empty; ViewBag.spec_id = -1; if (nameType != null) { fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower(); } else { #region 批次上傳圖片操作 //此處由批次上傳進入. //判斷文件名格式是否正確 ViewBag.moreFileOneTime = true; int prodCheck = file.FileName.LastIndexOf("prod_"); int specCheck = file.FileName.LastIndexOf("spec_"); int descCheck = file.FileName.LastIndexOf("desc_"); string errorMsg = "ERROR/"; if (prodCheck == -1 && specCheck == -1 && descCheck == -1) { errorMsg += "[" + file.FileName + "] "; errorMsg += Resources.VendorProduct.FILE_NAME_ERROR; ViewBag.fileName = errorMsg; return View("~/Views/VendorProduct/upLoad.cshtml"); } else { nameType = file.FileName.Split('_')[0]; fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')); } if (specCheck == 0) { //Caller _caller = (Session["caller"] as Caller); ProductSpecTemp proSpecTemp = new ProductSpecTemp(); string spec = file.FileName.Split('_')[1].Split('.')[0]; bool checkStatus = true; if (!string.IsNullOrEmpty(Request.Params["product_id"].Split(';')[0].ToString())) { //product_spec proSpecTemp.product_id = Request.Params["product_id"].Split(';')[0].ToString(); } //product_spec_temp _specTempMgr = new ProductSpecTempMgr(connectionString); List<ProductSpecTemp> pSpecTempList = _specTempMgr.VendorQuery(new ProductSpecTemp { Writer_Id = writerID, spec_type = 1 }); foreach (var item in pSpecTempList) { if (item.spec_name == spec) { checkStatus = false; ViewBag.spec_id = item.spec_id; } } if (checkStatus)//表示沒有要上傳圖片規格相同的規格一 { errorMsg += "[" + file.FileName + "] " + Resources.VendorProduct.SPEC_NOT_FIND; ViewBag.fileName = errorMsg; return View("~/Views/VendorProduct/upLoad.cshtml"); } } #endregion } string returnName = imgServerPath; bool result = false; string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; string ServerPath = string.Empty; if (nameType == "spec") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localSpecPath, Mappath); //CreateFolder(localSpec100Path, Mappath); //CreateFolder(localSpec280Path, Mappath); localSpecPath += firstFolder + secondFolder; //localSpec100Path += firstFolder + secondFolder; //localSpec280Path += firstFolder + secondFolder; specPath += firstFolder + secondFolder; returnName += specPath + NewFileName + fileExtention; //localSpec100Path += NewFileName + fileExtention; //localSpec280Path += NewFileName + fileExtention; NewFileName = localSpecPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + specPath); } else if (nameType == "desc") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localDescPath, Mappath); //CreateFolder(localDesc400Path, Mappath); localDescPath += firstFolder + secondFolder; //localDesc400Path += firstFolder + secondFolder; descPath += firstFolder + secondFolder; //localDesc400Path += NewFileName + fileExtention; returnName += descPath + NewFileName + fileExtention; NewFileName = localDescPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + descPath); } else { Mappath[0] = firstFolder; Mappath[1] = secondFolder; //Data:2014/06/26 //author:Castle //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!! CreateFolder(localProdPath, Mappath); //CreateFolder(localProd50Path, Mappath); //CreateFolder(localProd150Path, Mappath); //CreateFolder(localProd280Path, Mappath); localProdPath += firstFolder + secondFolder; //localProd50Path += firstFolder + secondFolder; //localProd150Path += firstFolder + secondFolder; //localProd280Path += firstFolder + secondFolder; prodPath += firstFolder + secondFolder; //localProd50Path += NewFileName + fileExtention; //localProd150Path += NewFileName + fileExtention; //localProd280Path += NewFileName + fileExtention; returnName += prodPath + NewFileName + fileExtention; NewFileName = localProdPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + prodPath); } string ErrorMsg = string.Empty; Resource.CoreMessage = new CoreResource("VendorProduct"); try { //上傳圖片 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); //上傳對應大小圖片 //压缩图片至其它规格 } 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); } if (string.IsNullOrEmpty(ErrorMsg)) { ViewBag.fileName = returnName; } else { ViewBag.fileName = "ERROR/" + ErrorMsg; Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = "ERROR/" + ErrorMsg; logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } return View("~/Views/VendorProduct/upLoad.cshtml"); }
public HttpResponseBase GetSiteStatisticsList() { string json = string.Empty; try { if (Request.Files.Count > 0) { string path = Request.Params["ImportExcel"]; HttpPostedFileBase excelFile = Request.Files["ImportExcel"]; FileManagement fileManagement = new FileManagement(); string savePath=Server.MapPath(excelPath) + "statistics"; string newExcelName = savePath+ fileManagement.NewFileName(excelFile.FileName); excelFile.SaveAs(newExcelName); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); DataTable _dt = helper.ExcelToTableForXLSX(); ssMgr = new SiteStatisticsMgr(mySqlConnectionString); json = ssMgr.ImportExcelToDt(_dt);//匯入成功 } else { SiteStatistics query = new SiteStatistics(); ssMgr = new SiteStatisticsMgr(mySqlConnectionString); query.Start = Convert.ToInt32(Request.Params["start"] ?? "0"); query.Limit = Convert.ToInt32(Request.Params["limit"] ?? "25"); query.ss_code = Request.Params["ss_code"]; if (!string.IsNullOrEmpty(Request.Params["startdate"])) { query.sss_date = Convert.ToDateTime(DateTime.Parse(Request.Params["startdate"]).ToString("yyyy-MM-dd 00:00:00")); } if (!string.IsNullOrEmpty(Request.Params["enddate"])) { query.ess_date = Convert.ToDateTime(DateTime.Parse(Request.Params["enddate"]).ToString("yyyy-MM-dd 23:59:59")); } #region 用來判斷相同的廠家代碼和時間是否已經存在 if (!string.IsNullOrEmpty(Request.Params["ss_id"])) { query.ss_id = int.Parse(Request.Params["ss_id"]); } if (!string.IsNullOrEmpty(Request.Params["ss_date"])) { query.ss_date = DateTime.Parse(Request.Params["ss_date"]); } if (!string.IsNullOrEmpty(Request.Params["ispage"])) { query.IsPage = bool.Parse(Request.Params["ispage"]); } #endregion int totalCount = 0; DataTable dt = ssMgr.GetSiteStatisticsList(query, out totalCount); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); //这里使用自定义日期格式,如果不使用的话,默认是ISO8601格式 timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; //listUser是准备转换的对象 json = "{success:true,totalCount:" + totalCount + ",data:" + JsonConvert.SerializeObject(dt, Formatting.Indented, timeConverter) + "}";//返回json數據 } } 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,totalCount:0,data:[]}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public ActionResult UpLoadImg() { string path = Server.MapPath(xmlPath); siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string elementPath = ConfigurationManager.AppSettings["elementPath"]; FileManagement fileLoad = new FileManagement(); HttpPostedFileBase file = Request.Files["Filedata"]; string fileName = string.Empty; string fileExtention = string.Empty; string[] Mappath = new string[2]; fileName = fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower(); string localElePath = imgLocalPath + elementPath; string returnName = imgServerPath;////"http://192.168.71.159:8080" bool result = false; string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; string ServerPath = string.Empty; Mappath[0] = firstFolder; Mappath[1] = secondFolder; //CreateFolder(localElePath, Mappath); // localElePath += firstFolder + secondFolder; // elementPath += firstFolder + secondFolder; returnName += elementPath + NewFileName + fileExtention; NewFileName = localElePath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + elementPath); string ErrorMsg = string.Empty; try { result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); } 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); } if (string.IsNullOrEmpty(ErrorMsg)) { ViewBag.fileName = returnName; ViewBag.Type = "pic"; } else { ViewBag.fileName = "ERROR/" + ErrorMsg; Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = "ERROR/" + ErrorMsg; logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } return View("~/Views/PromotionsAmountTrial/upLoad.cshtml"); }
/// <summary> /// 上傳圖片 /// </summary> /// <returns></returns> public ActionResult SaveCourseImg() { string xmlPath = ConfigurationManager.AppSettings["SiteConfig"]; try { ViewBag.status = false; string path = Server.MapPath(xmlPath); ///<add key="SiteConfig" value="/Config.xml"/> ISiteConfigImplMgr siteConfigMgr; siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; HttpPostedFileBase file = Request.Files["Filedata"]; //int courseCheck = file.FileName.LastIndexOf("course_"); string nameType = "course"; string imgServerPath = Unitle.GetImgGigade100ComSitePath(Unitle.ImgPathType.server); string coursePath = Unitle.GetImgGigade100ComPath(Unitle.ImgGigade100ComType.coursePath); string imgLocalPath = Unitle.GetImgGigade100ComSitePath(Unitle.ImgPathType.local);//<add key="imglocalpath" value=" ftp://192.168.18.166:2121/img"/> FTP路徑 string coursePicturePath = imgLocalPath + coursePath;//課程圖片保存路徑 string imgLocalServerPath = ConfigurationManager.AppSettings["imgLocalServerPath"]; string[] Mappath = new string[2]; FileManagement fileLoad = new FileManagement(); string fileName = string.Empty; string fileExtention = string.Empty; ViewBag.moreFileOneTime = true;//圖片狀態判斷 int courseNameCheck = file.FileName.LastIndexOf("course_");//獲取圖片前綴名稱 string errorMsg = "ERROR/"; //if (courseNameCheck==-1) //{ // errorMsg += "[" + file.FileName + "] "; // errorMsg += Resources.Product.FILE_NAME_ERROR; // ViewBag.fileName = errorMsg; // //return View("~/Views/Product/upLoad.cshtml"); // return View("~/Views/Course/upLoad.cshtml"); //} fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')); string NewFileName = string.Empty; string returnName = imgServerPath; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; string ServerPath = string.Empty; if (nameType == "course") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(coursePicturePath, Mappath); coursePicturePath += firstFolder + secondFolder; coursePath += firstFolder + secondFolder; returnName += coursePath + NewFileName + fileExtention; NewFileName = coursePicturePath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + coursePath); } string ErrorMsg = string.Empty; Resource.CoreMessage = new CoreResource("Product"); //上傳圖片 bool result = false; result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (string.IsNullOrEmpty(ErrorMsg)) { ViewBag.fileName = returnName; ViewBag.Type = nameType; ViewBag.status = true; //獲取文件長度 add by zhuoqin0830w 2015/01/29 string[] strFile = file.FileName.Split('_'); //判斷文件名的長度是否大於 1 如果大於 1 則再次進行判斷是否為數字 如果不是則進行強制轉換 int image_sort = 0; int.TryParse(strFile.Length > 1 ? strFile[1] : "0", out image_sort); ViewBag.image_sort = image_sort; } else { Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = "ERROR/" + ErrorMsg; logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } } 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); } return View("~/Views/Course/upLoad.cshtml"); }
public HttpResponseBase ImportExcel() { string json = string.Empty; string excelPath = "../ImportUserIOExcel/"; try { if (Request.Files.Count > 0) { int group_id = Convert.ToInt32(Request.Params["group_id"]); HttpPostedFileBase excelFile = Request.Files["ImportExcel"]; FileManagement fileManagement = new FileManagement(); string newExcelName = Server.MapPath(excelPath) + "email_group" + fileManagement.NewFileName(excelFile.FileName); excelFile.SaveAs(newExcelName); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); DataTable _dt = helper.SheetData(); _emailGroupMgr = new EmailGroupMgr(mySqlConnectionString); _newDt.Clear(); int totalCount = 0; _newDt = _emailGroupMgr.ImportEmailList(_dt, group_id, out totalCount);//匯入失敗的數據 if (_newDt.Rows.Count > 0 && _newDt != null) { int totalCountData = totalCount; int wrongCount = _newDt.Rows.Count; json = "{success:true,totalCount:'" + totalCountData + "',wrongCount:'" + wrongCount + "'}"; } else { json = "{success:true,wrongCount:'" + 0 + "'}"; } } } 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}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase ExportCsv() { string filename = string.Empty; string json = "{success:false}";//json字符串 userioMgr = new UserIOMgr(mySqlConnectionString); usersMgr = new UsersMgr(mySqlConnectionString); siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath)); try { if (Request.Files["ImportCsvFile"] != null && Request.Files["ImportCsvFile"].ContentLength > 0)//判斷文件是否為空 { HttpPostedFileBase excelFile = Request.Files["ImportCsvFile"];//獲取文件流 FileManagement fileManagement = new FileManagement();//實例化 FileManagement string fileLastName = excelFile.FileName.Substring((excelFile.FileName).LastIndexOf('.')).ToLower().Trim(); if (fileLastName.Equals(".csv")) { string newExcelName = Server.MapPath(excelPath) + "user_io" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名 System.Data.DataTable _dt = new DataTable(); excelFile.SaveAs(newExcelName);//上傳文件 //excelHelper = new NPOI4ExcelHelper(newExcelName); _dt = CsvHelper.ReadCsvToDataTable(newExcelName, true);//獲取csv里的數據 Regex num = new System.Text.RegularExpressions.Regex("^[0-9]+$"); string sqlAdition = ""; for (int i = 0; i < _dt.Rows.Count; i++) { if (_dt.Rows[i][0].ToString() != "") { if (!num.IsMatch(_dt.Rows[i][0].ToString()))//判斷是否匹配正則表達式 { System.IO.File.Delete(newExcelName);//刪除上傳過的excle int rows = i + 2; int cloumns = 1; json = "{success:false,msg:\"" + "第" + rows + "條第" + cloumns + "列數據錯誤" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } else { if (i == 0) { sqlAdition = _dt.Rows[i][0].ToString(); } else { sqlAdition += "," + Convert.ToUInt32(_dt.Rows[i][0].ToString());//獲取id,以,隔開id } } } } DataTable dtexcel = userioMgr.GetExcelTable(sqlAdition);//從數據庫里獲取csv里的id的數據 #region 讀取會員資料 json = string.Empty; if (!System.IO.Directory.Exists(Server.MapPath(excelPath))) { System.IO.Directory.CreateDirectory(Server.MapPath(excelPath)); } try { string[] colname = new string[dtexcel.Columns.Count]; filename = "user_io" + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".csv"; string newExcelfilename = Server.MapPath(excelPath) + filename; for (int i = 0; i < dtexcel.Columns.Count; i++) { colname[i] = dtexcel.Columns[i].ColumnName; } if (System.IO.File.Exists(newExcelfilename)) { System.IO.File.Delete(newExcelfilename); } excelFile.SaveAs(newExcelfilename);//上傳文件 CsvHelper.ExportDataTableToCsv(dtexcel, newExcelfilename, colname, true); IsoDateTimeConverter timeConverter = new IsoDateTimeConverter(); timeConverter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss"; json = "true"; } 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 = "false,"; } #endregion #region ///更改前的內容 //string[] colname = new string[dtexcel.Columns.Count];//定義一個數組 //for (int i = 0; i < dtexcel.Columns.Count; i++) //{ // colname[i] = dtexcel.Columns[i].ColumnName;//獲取列名 //} //CsvHelper.ExportDataTableToCsv(dtexcel, newExcelName, colname, true); ////打開導出的Excel 文件 //System.Diagnostics.Process Excelopen = new System.Diagnostics.Process(); //Excelopen.StartInfo.FileName = newExcelName; //Excelopen.Start(); #endregion json = "{success:true,msg:\"" + filename + "\"}"; } else { json = "{success:false,msg:\"" + "請匯入CSV格式檔案" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { json = "{success:false,msg:\"" + "請匯入檔案" + "\"}"; } } 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveVipUserGroup() { string json = string.Empty; try { VipUserGroupQuery query = new VipUserGroupQuery(); if (!string.IsNullOrEmpty(Request.Params["group_id"])) { query.group_id = Convert.ToUInt32(Request.Params["group_id"]); } if (!string.IsNullOrEmpty(Request.Params["group_name"])) { query.group_name = Request.Params["group_name"]; } if (!string.IsNullOrEmpty(Request.Params["eng_name"])) { query.eng_name = Request.Params["eng_name"]; } if (!string.IsNullOrEmpty(Request.Params["tax_id"])) { query.tax_id = Request.Params["tax_id"]; } if (!string.IsNullOrEmpty(Request.Params["group_code"])) { query.group_code = Request.Params["group_code"]; } if (!string.IsNullOrEmpty(Request.Params["group_capital"])) { query.group_capital = Convert.ToInt32(Request.Params["group_capital"]); } if (!string.IsNullOrEmpty(Request.Params["check_iden"])) { query.check_iden = Convert.ToInt32(Request.Params["check_iden"]); } if (!string.IsNullOrEmpty(Request.Params["group_emp_number"])) { query.group_emp_number = Convert.ToInt32(Request.Params["group_emp_number"]); } if (!string.IsNullOrEmpty(Request.Params["group_emp_age"])) { query.group_emp_age = Request.Params["group_emp_age"]; } if (!string.IsNullOrEmpty(Request.Params["group_emp_gender"])) { query.group_emp_gender = Convert.ToInt32(Request.Params["group_emp_gender"]); } if (!string.IsNullOrEmpty(Request.Params["group_benefit_type"])) { query.group_benefit_type = Request.Params["group_benefit_type"]; } if (!string.IsNullOrEmpty(Request.Params["group_benefit_desc"])) { query.group_benefit_desc = Request.Params["group_benefit_desc"].Replace("\\", "\\\\"); ; } if (!string.IsNullOrEmpty(Request.Params["group_subsidiary"])) { query.group_subsidiary = Convert.ToInt32(Request.Params["group_subsidiary"]); } if (!string.IsNullOrEmpty(Request.Params["group_hq_name"])) { query.group_hq_name = Request.Params["group_hq_name"]; } if (!string.IsNullOrEmpty(Request.Params["group_hq_code"])) { query.group_hq_code = Request.Params["group_hq_code"]; } if (!string.IsNullOrEmpty(Request.Params["group_committe_name"])) { query.group_committe_name = Request.Params["group_committe_name"]; } if (!string.IsNullOrEmpty(Request.Params["group_committe_code"])) { query.group_committe_code = Request.Params["group_committe_code"]; } if (!string.IsNullOrEmpty(Request.Params["group_committe_chairman"])) { query.group_committe_chairman = Request.Params["group_committe_chairman"]; } if (!string.IsNullOrEmpty(Request.Params["group_committe_phone"])) { query.group_committe_phone = (Request.Params["group_committe_phone"]); } if (!string.IsNullOrEmpty(Request.Params["group_committe_mail"])) { query.group_committe_mail = (Request.Params["group_committe_mail"]); } if (!string.IsNullOrEmpty(Request.Params["group_committe_promotion"])) { query.group_committe_promotion = (Request.Params["group_committe_promotion"]); } if (!string.IsNullOrEmpty(Request.Params["group_committe_other"])) { query.group_committe_other = (Request.Params["group_committe_other"]); } if (!string.IsNullOrEmpty(Request.Params["group_committe_desc"])) { query.group_committe_desc = (Request.Params[@"group_committe_desc"]).Replace("\\", "\\\\"); } DataTable _dt=new DataTable(); if (Request.Files.Count > 0) { HttpPostedFileBase excelFile = Request.Files["employee_list"]; query.file_name= excelFile.FileName; FileManagement fileManagement = new FileManagement(); string newExcelName = Server.MapPath(excelPath) + "vip_user_group" + fileManagement.NewFileName(excelFile.FileName); excelFile.SaveAs(newExcelName); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); _dt = helper.SheetData(); } _vipUserGroup = new VipUserGroupMgr(mySqlConnectionString); json = _vipUserGroup.SaveVipUserGroup(query, _dt); } 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,msg:'0'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveElementDetaiil() { string resultJson = "{success:false}"; ElementDetail model = new ElementDetail(); ElementDetail oldModel = new ElementDetail(); _detailMgr = new ElementDetailMgr(mySqlConnectionString); #region 獲取圖片信息 string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localBannerPath = imgLocalPath + ElementPath;//圖片存儲地址 #endregion if (!String.IsNullOrEmpty(Request.Params["element_id"]))//如果不存在該id說明是添加頁面 { model.element_id = Convert.ToInt32(Request.Params["element_id"].ToString()); oldModel = _detailMgr.GetModel(model); } #region 獲取數據 int isTranInt = 0; //if (Int32.TryParse(Request.Params["element_area_id"].ToString(), out isTranInt)) //{ // model.element_area_id = Convert.ToInt32(Request.Params["element_area_id"].ToString()); //} //else //{ // model.element_area_id = oldModel.element_area_id; //} if (!string.IsNullOrEmpty(Request.Params["element_name"].ToString())) { model.element_name = Request.Params["element_name"].ToString(); } else { model.element_name = oldModel.element_name; } if (!string.IsNullOrEmpty(Request.Params["packet_id"])) { model.packet_id = Convert.ToInt32(Request.Params["packet_id"]); } if (Int32.TryParse(Request.Params["element_type"].ToString(), out isTranInt)) { model.element_type = Convert.ToInt32(Request.Params["element_type"]); } if (model.element_type == 1) { #region 上傳圖片 try { FileManagement fileLoad = new FileManagement(); //if (Request.Files.Count > 0)//單個圖片上傳 for (int iFile = 0; iFile < Request.Files.Count; iFile++)//多個上傳圖片 { HttpPostedFileBase file = Request.Files[iFile];//單個Request.Files[0] string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.FileName); if (iFile == 0 && fileName == oldModel.element_content) { fileName = ""; } if(iFile == 1 && string.IsNullOrEmpty(Request.Params["element_img_big"].ToString()) ) { fileName = Request.Params["element_img_big"].ToString(); } if (!String.IsNullOrEmpty(fileName)) { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - ElementPath.Length + 1), ElementPath.Substring(1, ElementPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + ElementPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (model.element_id != 0) { string oldFileName = oldModel.element_content; if (iFile == 1) { oldFileName = oldModel.element_img_big; } CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localBannerPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldFileName);//刪除ftp:71.159上的舊圖片 } } try { //上傳 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { if (iFile == 0) { model.element_content = fileName; } else { model.element_img_big = fileName; } } } 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); model.element_content = oldModel.element_content; } if (!string.IsNullOrEmpty(ErrorMsg)) { if (iFile == 0) { ErrorMsg = "元素圖 " + ErrorMsg; } else { ErrorMsg = "元素圖(大) " + ErrorMsg; } string json = string.Empty; json = "{success:true,msg:\""+ ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { if (iFile == 0) { model.element_content = oldModel.element_content; } else { if (Request.Params["element_img_big"].ToString() == "") {//編輯時如果傳過來空值則直接刪除 model.element_img_big = ""; } else { model.element_img_big = oldModel.element_img_big; } //model.element_img_big = oldModel.element_img_big; } } } } 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); model.element_content = oldModel.element_content; } #endregion } else if (model.element_type == 2) { if (!string.IsNullOrEmpty(Request.Params["element_content"].ToString())) { model.element_content = Request.Params["element_content"].ToString(); } else { model.element_content = oldModel.element_content; } } else if (model.element_type == 3) { if (int.TryParse(Request.Params["element_product_id"].ToString(), out isTranInt)) { model.element_content = Request.Params["element_product_id"].ToString(); } else { model.element_content = oldModel.element_content; } #region 上傳圖片 try { FileManagement fileLoad = new FileManagement(); //if (Request.Files.Count > 0)//單個圖片上傳 for (int iFile = 1; iFile < Request.Files.Count; iFile++)//多個上傳圖片 { HttpPostedFileBase file = Request.Files[iFile];//單個Request.Files[0] string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 //獲取圖片名稱 fileName = fileLoad.NewFileName(file.FileName); if (!String.IsNullOrEmpty(fileName) && !String.IsNullOrEmpty(Request.Params["element_img_big"].ToString())) {//可獲取文件,名稱不為空則變更圖片 fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; //判斷目錄是否存在,不存在則創建 FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localBannerPath.Substring(0, localBannerPath.Length - ElementPath.Length + 1), ElementPath.Substring(1, ElementPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localBannerPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + ElementPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (model.element_id != 0) { string oldFileName = oldModel.element_img_big; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localBannerPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localBannerPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localBannerPath + oldFileName);//刪除ftp:71.159上的舊圖片 } } try { //上傳 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { model.element_img_big = fileName; } } 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); model.element_img_big = oldModel.element_img_big; } if (!string.IsNullOrEmpty(ErrorMsg)) { ErrorMsg = "元素圖(大)" + ErrorMsg; string json = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { if (Request.Params["element_img_big"].ToString() == "") {//編輯時如果傳過來空值則直接刪除 model.element_img_big = ""; } else { model.element_img_big = oldModel.element_img_big; } } } } 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); model.element_img_big = oldModel.element_img_big; } #endregion } if (int.TryParse(Request.Params["category_id_s"].ToString(), out isTranInt)) { model.category_id = uint.Parse(Request.Params["category_id_s"].ToString()); } else { model.category_id = 0; } model.category_name = Server.HtmlDecode(Request.Params["category_name_s"].ToString()); if (!string.IsNullOrEmpty(Request.Params["element_link_url"].ToString())) { model.element_link_url = Request.Params["element_link_url"].ToString(); } //else //{ // model.element_link_url = oldModel.element_link_url; //} if (int.TryParse(Request.Params["element_link_mode"].ToString(), out isTranInt)) { model.element_link_mode = Convert.ToInt32(Request.Params["element_link_mode"]); } else { model.element_link_mode = oldModel.element_link_mode; } if (!string.IsNullOrEmpty(Request.Params["element_sort"].ToString())) { model.element_sort = Convert.ToInt32(Request.Params["element_sort"].ToString()); } //else //{ // model.element_sort = oldModel.element_sort; //} if (!string.IsNullOrEmpty(Request.Params["element_start"].ToString())) { model.element_start = Convert.ToDateTime(Request.Params["element_start"].ToString()); } else { model.element_start = oldModel.element_start; } if (!string.IsNullOrEmpty(Request.Params["element_end"].ToString())) { model.element_end = Convert.ToDateTime(Request.Params["element_end"].ToString()); } else { model.element_end = oldModel.element_end; } model.element_remark = (Request.Params["element_remark"].ToString()); model.element_status = 0;//默認為不啟用 #endregion try { //判斷是否能夠獲取到rowid if (String.IsNullOrEmpty(Request.Params["element_id"]))//如果不存在該id說明是添加頁面 { model.element_createdate = DateTime.Now; model.element_updatedate = model.element_createdate; model.create_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; model.update_userid = model.create_userid; //這裡加上各種參數 if (_detailMgr.Save(model) > 0) { resultJson = "{success:true}";//返回json數據 } } else { //model.element_createdate = oldModel.element_createdate; model.element_updatedate = DateTime.Now; model.update_userid = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; // model.create_userid = oldModel.create_userid; //這裡加上各種參數 if (_detailMgr.Update(model) > 0)//如果可以獲取到rowid則進行修改 { resultJson = "{success:true}";//返回json數據 } } } 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); resultJson = "{success:false}"; } this.Response.Clear(); this.Response.Write(resultJson); this.Response.End(); return this.Response; }
/// <summary> /// 圖檔維護中上傳圖片 /// </summary> /// <returns></returns> public HttpResponseBase UploadPicture() { string json = string.Empty; string errorInfo = string.Empty; VendorBrandSetQuery query = new VendorBrandSetQuery(); query.Brand_Id = uint.Parse(Request.Params["brand_id"]); query.image_sort = 0; query.image_state = 1; query.image_createdate = (uint)BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString()); _IvendorBrandSet = new VendorBrandSetMgr(connectionString); ImagePathConfig(); string fileName = String.Empty, fileExtention = String.Empty, newFileName = String.Empty, oldFileName = String.Empty; //string localPromoPath = imgLocalPath + vendorPath;//圖片存儲地址 string localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址 FileManagement fileLoad;//+++++++++++++++++ for (int i = 0; i < Request.Files.Count; i++) { fileLoad = new FileManagement();//+++++++++++++++ HttpPostedFileBase file = Request.Files[i]; fileName = Path.GetFileName(file.FileName); string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); newFileName = newRand + fileExtention; string folder1 = newFileName.Substring(0, 2) + "/";//圖片名前兩碼 string folder2 = newFileName.Substring(2, 2) + "/";//圖片名第三四碼 string ServerPath = string.Empty; FTP f_cf = new FTP(); localPromoPath = imgLocalPath + vendorOriginalPath + folder1 + folder2;//圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (vendorOriginalPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (vendorOriginalPath + folder1 + folder2).Substring(1, (vendorOriginalPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + vendorOriginalPath + folder1 + folder2); fileName = newFileName; newFileName = localPromoPath + newFileName;//絕對路徑 string ErrorMsg = string.Empty; //錯誤消息 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 try { //bool result = fileLoad.UpLoadFile(file, ServerPath, newFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); bool result = fileLoad.UpLoadFile(file, ServerPath, newFileName, extention, 150, int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.image_filename = fileName; _IvendorBrandSet.SaveBrandStory(query); //json = "{success:true,msg:\"圖片上傳成功!\"}"; } else { errorInfo += "第" + (i + 1) + "張" + ErrorMsg + "<br/>"; //json = "{success:false,msg:\"<div>圖片上傳成功!<br/>但第" + countError + "張" + ErrorMsg + "</div>\"}"; } json = "{success:true,msg:\"圖片上傳成功!\"}"; if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"<div>操作完成!<br/>但<br/>" + errorInfo + "</div>\"}"; } } 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,msg:\"操作失敗,請稍后再試!\"}"; if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:false,msg:\"<div>操作失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}"; } } fileName = String.Empty; fileExtention = String.Empty; newFileName = String.Empty; oldFileName = String.Empty;//++++++++++++++++++ localPromoPath = imgLocalPath + vendorOriginalPath;//圖片存儲地址//++++++++++++++++++++ } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase InsertkucunMessage() { int j = 0; string json = string.Empty;//json字符串 int iialgtotal = 0; int iinvdtotal = 0; try { if (Request.Files["ImportFileMsg"] != null && Request.Files["ImportFileMsg"].ContentLength > 0)//判斷文件是否為空 { HttpPostedFileBase excelFile = Request.Files["ImportFileMsg"];//獲取文件流 FileManagement fileManagement = new FileManagement();//實例化 FileManagement //string fileLastName = excelFile.FileName.Substring((excelFile.FileName).LastIndexOf('.')).ToLower().Trim(); string fileLastName = excelFile.FileName; string newExcelName = Server.MapPath(excelPath) + "Kucuntiaozheng" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名 excelFile.SaveAs(newExcelName);//上傳文件 DataTable dt = new DataTable(); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); dt = helper.SheetData(); DataRow[] dr = dt.Select(); //定义一个DataRow数组,读取ds里面所有行 int rowsnum = dt.Rows.Count; if (rowsnum == 0) { json = "{success:true,iialgtotal:\"" + 0 + "\",iinvdtotal:\"" + 0 + "\",msg:\"" + "匯入盤點報表中沒有數據" + "\"}"; } if (dr[0][0].ToString().Trim() == "編號" && dr[0][1].ToString().Trim() == "料位" && dr[0][2].ToString().Trim() == "料位狀態" && dr[0][11].ToString().Trim() == "有效日期" && dt.Columns.Count == 12) { _iagMgr = new IialgMgr(mySqlConnectionString); j = _iagMgr.HuiruInsertiialg(dr, out iialgtotal, out iinvdtotal); if (j > 0) { json = "{success:true,iialgtotal:\"" + iialgtotal + "\",iinvdtotal:\"" + iinvdtotal + "\",msg:\"" + "匯入盤點報表對照表成功!" + "\"}"; } else { json = "{success:true,iialgtotal:\"" + iialgtotal + "\",iinvdtotal:\"" + iinvdtotal + "\",msg:\"" + "匯入數據標準不對,請嚴格按照模板匯入!" + "\"}"; } } else { json = "{success:true,iialgtotal:\"" + 0 + "\",iinvdtotal:\"" + 0 + "\",msg:\"" + "匯入盤點報表格式不正確!" + "\"}"; } } } 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,msg:\"" + ex.ToString() + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 新增或修改供應商品牌信息 /// </summary> /// <returns></returns> public HttpResponseBase UpdVendorBrand() { List<VendorBrandSetQuery> stores = new List<VendorBrandSetQuery>(); query = new VendorBrandSetQuery(); VendorBrandSetQuery oldquery = new VendorBrandSetQuery(); _IvendorBrandSet = new VendorBrandSetMgr(connectionString); _productMgr = new ProductMgr(connectionString); string json = string.Empty; string errorInfo = string.Empty; try { #region 獲取數據 query.Brand_Id = UInt32.Parse(Request.Params["Brand_Id"]); oldquery = _IvendorBrandSet.GetModelById(Int32.Parse(Request.Params["Brand_Id"])); try { query.Brand_Name = Request.Params["brandName"].ToString(); } catch (Exception) { query.Brand_Name = oldquery.Brand_Name; } try { query.vendor_id = uint.Parse(Request.Params["vendorid"].ToString()); } catch (Exception) { query.vendor_id = oldquery.vendor_id; } try { query.Brand_Sort = uint.Parse(Request.Params["brandsort"].ToString()); } catch (Exception) { query.Brand_Sort = oldquery.Brand_Sort; } try { query.Brand_Status = uint.Parse(Request.Params["brandstatus"].ToString()); } catch (Exception) { query.Brand_Status = oldquery.Brand_Status; } try { query.Image_Status = uint.Parse(Request.Params["imagestatus"].ToString()); } catch (Exception) { query.Image_Status = oldquery.Image_Status; } try { query.Image_Link_Mode = uint.Parse(Request.Params["imagelinkmode"].ToString()); } catch (Exception) { query.Image_Link_Mode = oldquery.Image_Link_Mode; } try { query.Image_Link_Url = Request.Params["imagelinkurl"].ToString(); } catch (Exception) { query.Image_Link_Url = oldquery.Image_Link_Url; } try { query.Resume_Image_Link = Request.Params["resumeimagelink"].ToString(); } catch (Exception) { query.Resume_Image_Link = oldquery.Resume_Image_Link; } try { query.Media_Report_Link_Url = Request.Params["mediareportlinkurl"].ToString(); } catch (Exception) { query.Media_Report_Link_Url = oldquery.Media_Report_Link_Url; } try { query.Brand_Msg = Request.Params["brandmsg"].ToString(); } catch (Exception) { query.Brand_Msg = oldquery.Brand_Msg; } long start = CommonFunction.GetPHPTime(Request.Params["begin_time"].ToString()); long end = CommonFunction.GetPHPTime(Request.Params["end_time"].ToString()); try { query.Brand_Msg_Start_Time = uint.Parse(start.ToString()); } catch (Exception) { query.Brand_Msg_Start_Time = oldquery.Brand_Msg_Start_Time; } try { query.Brand_Msg_End_Time = uint.Parse(end.ToString()); } catch (Exception) { query.Brand_Msg_End_Time = oldquery.Brand_Msg_End_Time; } try { query.Brand_Createdate = uint.Parse(CommonFunction.GetPHPTime(DateTime.Now.ToString()).ToString()); } catch (Exception) { query.Brand_Createdate = oldquery.Brand_Createdate; } try { query.classIds = Request["shopclass"].ToString(); } catch (Exception) { query.classIds = oldquery.classIds; } query.Brand_Ipfrom = Request.UserHostAddress; try { query.Cucumber_Brand = uint.Parse(Request.Params["cucumberbrand"].ToString()); } catch { query.Cucumber_Brand = oldquery.Cucumber_Brand; } try { query.Image_Name = Request.Params["imagename"].ToString(); } catch (Exception) { query.Image_Name = oldquery.Image_Name; } try { query.Promotion_Banner_Image_Link = Request.Params["promotionbannerimagelink"].ToString(); } catch (Exception) { query.Promotion_Banner_Image_Link = oldquery.Promotion_Banner_Image_Link; } try { query.short_description = Request.Params["short_description"].ToString(); } catch (Exception) { query.short_description = oldquery.short_description; } query.Image_Name = oldquery.Image_Name; query.Resume_Image = oldquery.Resume_Image; query.Promotion_Banner_Image = oldquery.Promotion_Banner_Image; query.brand_logo = oldquery.brand_logo; #endregion #region 上傳圖片 string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + brandPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); for (int i = 0; i < Request.Files.Count; i++) { string fileName = string.Empty; //當前文件名 HttpPostedFileBase file = Request.Files[i]; fileName = Path.GetFileName(file.FileName); if (string.IsNullOrEmpty(fileName)) { continue; } fileLoad = new FileManagement(); string oldFileName = string.Empty; //舊文件名 string fileExtention = string.Empty;//當前文件的擴展名 bool result = false; string NewFileName = string.Empty; string ServerPath = string.Empty; string newRand = string.Empty; string ErrorMsg = string.Empty; newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName) + DateTime.Now.ToString(), "32"); fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; string folder1 = NewFileName.Substring(0, 2) + "/"; //圖片名前兩碼 string folder2 = NewFileName.Substring(2, 2) + "/"; //圖片名第三四碼 FTP f_cf = new FTP(); localPromoPath = imgLocalPath + brandPath + folder1 + folder2; //圖片存儲地址 string s = localPromoPath.Substring(0, localPromoPath.Length - (brandPath + folder1 + folder2).Length + 1); f_cf.MakeMultiDirectory(s, (brandPath + folder1 + folder2).Substring(1, (brandPath + folder1 + folder2).Length - 2).Split('/'), ftpuser, ftppwd); ServerPath = Server.MapPath(imgLocalServerPath + brandPath + folder1 + folder2); fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { //圖片上傳成功后記錄新圖片名稱 switch (i) { case 0: query.Image_Name = fileName; break; case 1: query.Resume_Image = fileName; break; case 2: query.Promotion_Banner_Image = fileName; break; case 3: query.brand_logo = fileName; break; default: break; } //圖片上傳成功后如果存在舊圖片則根據舊圖片名刪除舊圖片 if (!string.IsNullOrEmpty(oldFileName)) { switch (i) { case 0: oldFileName = oldquery.Image_Name; break; case 1: oldFileName = oldquery.Resume_Image; break; case 2: oldFileName = oldquery.Promotion_Banner_Image; break; case 3: oldFileName = oldquery.brand_logo; break; default: break; } DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } } else { //圖片上傳失敗則圖片名稱為原有圖片名稱 switch (i) { case 0: query.Image_Name = oldquery.Image_Name;//形象圖片 break; case 1: query.Resume_Image = oldquery.Resume_Image;//安心聲明圖片 break; case 2: query.Promotion_Banner_Image = oldquery.Promotion_Banner_Image;//促銷圖片 break; case 3: query.brand_logo = oldquery.brand_logo;//品牌logo break; default: break; } errorInfo += "第" + (i + 1) + "張" + ErrorMsg + "<br/>"; //json = "{success:false,msg:\"第" + i + "張" + ErrorMsg + ",之後圖片未作處理" + "\"}"; } } #endregion //更新數據庫記錄 if (_IvendorBrandSet.Update(query) > 0) { if (_productMgr.UpdateSaleStatusByCondition(new Product { Vendor_Id = query.vendor_id, Brand_Id = query.Brand_Id })) { json = "{success:true,msg:\"數據保存成功!\"}"; } } if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:true,msg:\"<div>數據保存成功!<br/>但<br/>" + errorInfo + "</div>\"}"; } } 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,msg:\"保存失敗,請稍后再試!\"}"; if (!string.IsNullOrEmpty(errorInfo)) { json = "{success:false,msg:\"<div>保存失敗,請稍后再試!<br/>" + errorInfo + "</div>\"}"; } } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase HuiruPiciAddwuliufei() { string json = string.Empty;//json字符串 string shipment = Request.Params["shipment"].ToString(); //int total = 0; try { if (Request.Files["ImportFileMsg"] != null && Request.Files["ImportFileMsg"].ContentLength > 0)//判斷文件是否為空 { HttpPostedFileBase excelFile = Request.Files["ImportFileMsg"];//獲取文件流 FileManagement fileManagement = new FileManagement();//實例化 FileManagement string fileLastName = excelFile.FileName; string newExcelName = Server.MapPath(excelPath) + "PiCiAddWuliufei" + fileManagement.NewFileName(excelFile.FileName);//處理文件名,獲取新的文件名 excelFile.SaveAs(newExcelName);//上傳文件 DataTable dt = new DataTable(); NPOI4ExcelHelper helper = new NPOI4ExcelHelper(newExcelName); dt = helper.SheetData(); DataRow[] dr = dt.Select(); //定义一个DataRow数组,读取ds里面所有行 int rowsnum = dt.Rows.Count; if (rowsnum > 0)//判斷是否是這個表 { DeliverMasterQuery dmQuery = new DeliverMasterQuery(); StringBuilder str = new StringBuilder(); DataTable dtMaster = new DataTable(); DataTable ExcelDt = new DataTable(); string filenameExcel = string.Empty; ExcelDt.Columns.Add("訂單編號", typeof(String)); ExcelDt.Columns.Add("物流單號", typeof(String)); ExcelDt.Columns.Add("物流費", typeof(String)); ExcelDt.Columns.Add("應收帳款", typeof(String)); ExcelDt.Columns.Add("異常信息", typeof(String)); int i = 0; int j = 0; int x = 0; string y = string.Empty; int successcount = 0; int failcount = 0; string create_dtim = CommonFunction.DateTimeToString(DateTime.Now); //創建時間 int create_user = (System.Web.HttpContext.Current.Session["caller"] as Caller).user_id; _DeliverMsterMgr = new DeliverMasterMgr(mySqlConnectionString); #region 循環excel表中的數據 并判斷是否滿足條件和失敗的個數 for (int z = 0; z < dr.Length; z++) { x = Convert.ToInt32(dr[z][0].ToString());//訂單編號 y = dr[z][1].ToString();//托運單號 i = Convert.ToInt32(dr[z][2].ToString());//運送金額 j = Convert.ToInt32(dr[z][3].ToString());//代收金額--也就是購物應該付款總金額 dmQuery.delivery_code = y;//托運單號 dtMaster = _DeliverMsterMgr.GetMessageByDeliveryCode(dmQuery); string errorstring = string.Empty; bool behavior = true; if (dtMaster.Rows.Count <= 0) { errorstring = "物流單號不存在"; behavior = false; } else if (Convert.ToInt32(dtMaster.Rows[0]["delivery_store"]) != Convert.ToInt32(shipment))//如果物流方式不對應 { errorstring = "物流廠商不相符,此物流單對應物流為:" + dtMaster.Rows[0]["parameterName"].ToString(); behavior = false; } //else if (y != dtMaster.Rows[0]["delivery_code"].ToString()) //{ // errorstring = "物流單號不相符"; // behavior = false; //} else if (dtMaster.Rows[0]["order_id"].ToString() != x.ToString()) { errorstring = "定單編號不相符,此物流單對應的定單編號為:" + dtMaster.Rows[0]["order_id"].ToString(); behavior = false; } else if (dtMaster.Rows.Count > 1) { errorstring = "物流單號重複"; behavior = false; } //10表示黑貓貨到付款 order_amount購物應付總金額(加運費,扣除扺用紅利等金額) else if (Convert.ToInt32(dtMaster.Rows[0]["delivery_store"]) == 10 && j != Convert.ToInt32(dtMaster.Rows[0]["order_amount"])) { errorstring = "應收帳款金額不符"; behavior = false; } //4表示已出貨 9 表示待取貨 else if (Convert.ToInt32(dtMaster.Rows[0]["order_status"]) != 4 && Convert.ToInt32(dtMaster.Rows[0]["order_status"]) != 9) { _ptersrc = new ParameterMgr(mySqlConnectionString); int types = Convert.ToInt32(dtMaster.Rows[0]["order_status"]); string endresult = _ptersrc.GetOrderStatus(types); errorstring = "出貨狀態異常:出貨狀態為" + endresult; behavior = false; } if (behavior == true)//如果數據不存在這些問題 如果failcount大於0就表示匯入信息有不正確的 { successcount = successcount + 1; //DataRow Execldr = ExcelDt.NewRow(); //Execldr[0] = x; //Execldr[1] = y; //Execldr[2] = i; //Execldr[3] = dtMaster.Rows[0]["order_amount"]; //Execldr[4] = "數據正常"; //ExcelDt.Rows.Add(Execldr); str.AppendFormat(" set sql_safe_updates = 0;update deliver_master set delivery_freight_cost='{0}',creator='{1}',modified='{2}' where delivery_code='{3}' ;set sql_safe_updates = 1;", i, create_user, create_dtim, y); } else { failcount = failcount + 1; DataRow Execldr = ExcelDt.NewRow(); Execldr[0] = x; Execldr[1] = y; Execldr[2] = i; Execldr[3] = j;//dtMaster.Rows[0]["order_amount"]; Execldr[4] = errorstring; ExcelDt.Rows.Add(Execldr); //此次上傳資料有異請下載差異檔 } } #endregion #region 判斷失敗個數 成功個數 當失敗個數大於0時 直接匯出excel if (failcount > 0)//存在失敗的情況 直接匯出數據 { string fileName = DateTime.Now.ToString("匯出批次上傳物流費不規則數據_yyyyMMddHHmm") + ".xls"; MemoryStream ms = ExcelHelperXhf.ExportDT(ExcelDt, "匯出批次上傳物流費不規則數據"); Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName); Response.BinaryWrite(ms.ToArray()); return this.Response; } else if (failcount == 0 && successcount > 0) { if (_DeliverMsterMgr.Updatedeliveryfreightcost(str) > 0) { json = "{success:true,total:" + successcount + ",msg:\"" + "匯入成功" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } else { json = "{success:false}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { json = "{success:true,msg:\"" + "此表內沒有數據或數據有誤,請檢查后再次匯入!" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } #endregion } else { json = "{success:true,total:0,msg:\"" + "此表內沒有數據或數據有誤,請檢查后再次匯入!" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else//當直接點擊時會產生, { json = "{success:true,msg:\"" + "請匯入批次上傳物流費表" + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } 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,msg:\"" + ex.ToString() + "\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
/// <summary> /// 會員活動新增編輯 /// </summary> /// <returns></returns> public HttpResponseBase SaveMemberEvent() { string json = string.Empty; try { MemberEventQuery query = new MemberEventQuery(); _memberEvent = new MemberEventMgr(mySqlConnectionString); if (!string.IsNullOrEmpty(Request.Params["rowID"])) { query.rowID = int.Parse(Request.Params["rowID"]); } query.me_name = Request.Params["me_name"]; query.me_desc = Request.Params["me_desc"]; query.event_id = Request.Params["event_id"]; if (!string.IsNullOrEmpty(Request.Params["me_startdate"])) { query.me_startdate = DateTime.Parse(Request.Params["me_startdate"]); } if (!string.IsNullOrEmpty(Request.Params["me_enddate"])) { query.me_enddate = DateTime.Parse(Request.Params["me_enddate"]); } if (!string.IsNullOrEmpty(Request.Params["me_birthday"])) { //query.me_birthday = int.Parse(Request.Params["me_birthday"]); if (Request.Params["me_birthday"] == "1") { query.me_birthday = 1; } else { query.me_birthday = 0; } } if (!string.IsNullOrEmpty(Request.Params["me_bonus_onetime"])) { if (Request.Params["me_bonus_onetime"] == "1") { query.me_bonus_onetime = 1; } else { query.me_bonus_onetime = 0; } } if (!string.IsNullOrEmpty(Request.Params["me_banner_link"])) { query.me_banner_link = Request.Params["me_banner_link"]; } if (!string.IsNullOrEmpty(Request.Params["code"])) { query.ml_code = Request.Params["code"].TrimEnd(','); } else { query.ml_code = "0"; } if (!string.IsNullOrEmpty(Request.Params["et_id"])) { query.et_id = int.Parse(Request.Params["et_id"]); } //query.et_name = Request.Params["et_name"]; switch (Request.Params["et_name"]) { case "1": query.et_name = "DD"; query.et_date_parameter = ""; break; case "2": query.et_name = "WW"; if (!string.IsNullOrEmpty(Request.Params["week"])) { query.et_date_parameter = Request.Params["week"].TrimEnd(','); } break; case "3": query.et_name = "MM"; if (!string.IsNullOrEmpty(Request.Params["month"])) { query.et_date_parameter = Request.Params["month"].TrimEnd(','); } break; } #region 處理每天的開始結束時間 query.et_starttime = Request.Params["et_starttime"]; query.et_endtime = Request.Params["et_endtime"]; #endregion query.k_user = (Session["caller"] as Caller).user_id; query.m_user = (Session["caller"] as Caller).user_id; query.k_date = DateTime.Now; query.m_date = query.k_date; string event_json=_memberEvent.IsGetEventID(query.event_id); if (event_json.IndexOf("true") > 0) { #region 判斷數據不能重複 if (_memberEvent.IsRepeat(query))//不重複 { #region 上傳圖片 string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localMemberEventPath = imgLocalPath + MemberEventPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); int totalCount = 0; MemberEventQuery oldQuery = _memberEvent.Query(new MemberEventQuery { rowID = query.rowID }, out totalCount).FirstOrDefault(); if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string[] dirPath = new string[2]; //dirPath[0] = NewFileName.Substring(0, 2)+"/"; //dirPath[1] = NewFileName.Substring(2, 2)+"/"; string ServerPath = string.Empty; FTP f_cf = new FTP(); CreateFolder(localMemberEventPath, dirPath); fileName = NewFileName + fileExtention; NewFileName = localMemberEventPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + MemberEventPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (query.rowID != 0) { if (oldQuery.me_big_banner != "") { string oldFileName = oldQuery.me_big_banner; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localMemberEventPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localMemberEventPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localMemberEventPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.me_big_banner = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } else { query.me_big_banner = oldQuery.me_big_banner; } } #endregion if (_memberEvent.MemberEventSave(query) > 0) { //json = "{success:true}"; if (!string.IsNullOrEmpty(Request.Params["rowID"])) { json = "{success:true,msg:'修改成功!'}"; } else { json = "{success:true,msg:'新增成功!'}"; } } else { if (!string.IsNullOrEmpty(Request.Params["rowID"])) { json = "{success:false,msg:'修改失敗!'}"; } else { json = "{success:false,msg:'新增失敗!'}"; } } } else { json = "{success:false,msg:'數據重複!'}"; } #endregion } else { json = "{success:false,msg:'促銷編號錯誤或促銷活動未啟用'}"; } } 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,msg:'異常!'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveChinatrust() { string json = string.Empty; try { _eventChinatrust = new EventChinatrustMgr(mySqlConnectionString); FileManagement fileLoad = new FileManagement(); EventChinatrustQuery query = new EventChinatrustQuery(); EventChinatrustQuery oldModel = new EventChinatrustQuery(); List<EventChinatrustQuery> store = new List<EventChinatrustQuery>(); if (!string.IsNullOrEmpty(Request.Params["row_id"])) {//如果是編輯獲取該id數據 int totalCount = 0; query.IsPage = false; query.event_active = -1; query.row_id = int.Parse(Request.Params["row_id"]); store = _eventChinatrust.GetEventChinatrustList(query, out totalCount); } #region 需要更改的屬性 if (!string.IsNullOrEmpty(Request.Params["row_id"])) { query.row_id = Convert.ToInt32(Request.Params["row_id"]); } if (!string.IsNullOrEmpty(Request.Params["event_name"])) { query.event_name = Request.Params["event_name"]; } if (!string.IsNullOrEmpty(Request.Params["event_desc"])) { query.event_desc = Request.Params["event_desc"]; } if (!string.IsNullOrEmpty(Request.Params["event_start_time"])) { query.event_start_time = DateTime.Parse(Request.Params["event_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["event_end_time"])) { query.event_end_time = DateTime.Parse(Request.Params["event_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["user_register_time"])) { query.user_register_time=DateTime.Parse(Request.Params["user_register_time"]); } if (!string.IsNullOrEmpty(Request.Params["event_banner"])) { query.event_banner = Request.Params["event_banner"]; } #endregion query.event_type = "EC"; #region 上傳圖片 string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + PaperPath;//圖片存儲地址 if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string ErrorMsg = string.Empty; //上傳之前刪除已有的圖片 if (query.row_id != 0) { oldModel = store.FirstOrDefault(); if (oldModel.event_banner != "") { string oldFileName = oldModel.event_banner; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.event_banner = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } } #endregion if (query.row_id == 0) { query.event_create_time = DateTime.Now; query.event_update_time = query.event_create_time; query.event_create_user = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); query.event_update_user = query.event_create_user; if (_eventChinatrust.AddEventChinatrust(query) > 0) { json = "{success:true }"; } else { json = "{success:false,msg:'新增失敗!'}"; } } else { query.event_update_time = DateTime.Now; query.event_update_user = Convert.ToInt32((System.Web.HttpContext.Current.Session["caller"] as Caller).user_id); if (_eventChinatrust.UpdateEventChinatrust(query) > 0) { json = "{success:true }"; } else { json = "{success:false,msg:'修改失敗!'}"; } } } 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}"; } this.Response.Clear(); this.Response.Write(json.ToString()); this.Response.End(); return this.Response; }
public ActionResult upLoadImg() { try { HttpPostedFileBase file = Request.Files["Filedata"]; int type = Request["appOrexplain"] == null ? 0 : Convert.ToInt32(Request["appOrexplain"]); string nameType = Request.Params["nameType"]; // 將 nametype 提前 使其判斷傳入的圖片是否為商品主圖 edit by zhuoqin0830w 2015/01/29 int prodCheck = file.FileName.LastIndexOf("prod_"); // 將 proCheck 提前 使其判斷批量上傳的圖片中是否存在商品主圖 edit by zhuoqin0830w 2015/01/30 if (nameType == "spec") { type = 5; } if (prodCheck == 0 && type == 0) //批量上傳時type才會 ==0,其他單獨上傳時是不需要根據prod處理圖片的 { type = 3; } int mobileCheck = file.FileName.LastIndexOf("mobile_");//批量上傳時type才會 ==0,其他單獨上傳時是不需要根據prod處理圖片的 if (mobileCheck == 0 && type == 0) { type = 4; } string path = Server.MapPath(xmlPath); siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = null; //判斷 批量上傳 或 單個上傳 的圖片是否為 商品主圖 或 手機商品圖 edit by zhuoqin0830w 2015/03/24 switch (nameType) { //如果 nameType == prod 則表示 是 單個上傳 商品主圖 case "prod": maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max"); break; //如果 nameType == mobile 則表示 是 單個上傳 手機商品圖 case "mobile": maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); break; //如果 nameType == null 則表示 是 批量上傳 case null: //如果 prodCheck == 0 則表示 是 批量上傳 中包含 商品主圖 if (prodCheck == 0) { maxValue_config = siteConfigMgr.GetConfigByName("PIC_280_Length_Max"); } //如果 mobileCheck == 0 則表示 是 批量上傳 中包含 手機商品圖 else if (mobileCheck == 0) { maxValue_config = siteConfigMgr.GetConfigByName("PIC_640_Length_Max"); } else { maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); } break; default: maxValue_config = siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); break; } string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; if ((nameType == "mobile" && type == 4) || (mobileCheck == 0 && type == 4)) //add by wwei0216w 2015/4/1 添加原因:手機圖片要放在640*640路徑下 { prodPath = prodMobile640; } string localProdPath = imgLocalPath + prodPath; //string localProd50Path = imgLocalPath + prod50Path; //string localProd150Path = imgLocalPath + prod150Path; //string localProd280Path = imgLocalPath + prod280Path; string localSpecPath = imgLocalPath + specPath; //string localSpec100Path = imgLocalPath + spec100Path; //string localSpec280Path = imgLocalPath + spec280Path; string[] Mappath = new string[2]; FileManagement fileLoad = new FileManagement(); string fileName = string.Empty; string fileExtention = string.Empty; ViewBag.spec_id = -1; if (nameType != null) { fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower(); } else { #region 批次上傳圖片操作 //此處由批次上傳進入. //判斷文件名格式是否正確 ViewBag.moreFileOneTime = true; //int prodCheck = file.FileName.LastIndexOf("prod_"); int specCheck = file.FileName.LastIndexOf("spec_"); int descCheck = file.FileName.LastIndexOf("desc_"); int appCheck = file.FileName.LastIndexOf("app_"); string errorMsg = "ERROR/"; if (prodCheck == -1 && specCheck == -1 && descCheck == -1 && appCheck == -1 && mobileCheck == -1) { errorMsg += "[" + file.FileName + "] "; errorMsg += Resources.Product.FILE_NAME_ERROR; ViewBag.fileName = errorMsg; return View("~/Views/Product/upLoad.cshtml"); } else { nameType = file.FileName.Split('_')[0]; if (nameType == "app") { type = 2; } else if (nameType == "desc") { type = 1; } else if (nameType == "spec") { type = 5; } fileName = nameType + fileLoad.NewFileName(file.FileName); fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')); } if (specCheck == 0) { Caller _caller = (Session["caller"] as Caller); string spec = file.FileName.Split('_')[1].Split('.')[0]; bool checkStatus = true; if (!string.IsNullOrEmpty(Request.Params["product_id"].Split(';')[0].ToString())) { //product_spec uint pid = uint.Parse(Request.Params["product_id"].Split(';')[0].ToString()); _specMgr = new ProductSpecMgr(connectionString); List<ProductSpec> pSpecList = _specMgr.Query(new ProductSpec { product_id = pid, spec_type = 1 }); foreach (var item in pSpecList) { if (item.spec_name == spec) { checkStatus = false; ViewBag.spec_id = item.spec_id; } } } else { //product_spec_temp _specTempMgr = new ProductSpecTempMgr(connectionString); List<ProductSpecTemp> pSpecTempList = _specTempMgr.Query(new ProductSpecTemp { Writer_Id = _caller.user_id, spec_type = 1 }); foreach (var item in pSpecTempList) { if (item.spec_name == spec) { checkStatus = false; ViewBag.spec_id = item.spec_id; } } } if (checkStatus)//表示沒有要上傳圖片規格相同的規格一 { errorMsg += "[" + file.FileName + "] " + Resources.Product.SPEC_NOT_FIND; ViewBag.fileName = errorMsg; return View("~/Views/Product/upLoad.cshtml"); } } #endregion } SetPath(type);//設定圖片路徑 string localDescPath = imgLocalPath + descPath; //string localDesc400Path = imgLocalPath + desc400Path; string returnName = imgServerPath; bool result = false; string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string firstFolder = NewFileName.Substring(0, 2) + "/"; string secondFolder = NewFileName.Substring(2, 2) + "/"; string ServerPath = string.Empty; if (nameType == "spec") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localSpecPath, Mappath); //CreateFolder(localSpec100Path, Mappath); //CreateFolder(localSpec280Path, Mappath); localSpecPath += firstFolder + secondFolder; //localSpec100Path += firstFolder + secondFolder; //localSpec280Path += firstFolder + secondFolder; specPath += firstFolder + secondFolder; returnName += specPath + NewFileName + fileExtention; //localSpec100Path += NewFileName + fileExtention; //localSpec280Path += NewFileName + fileExtention; NewFileName = localSpecPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + specPath); } else if (nameType == "desc" || nameType == "app") { Mappath[0] = firstFolder; Mappath[1] = secondFolder; CreateFolder(localDescPath, Mappath); //CreateFolder(localDesc400Path, Mappath); localDescPath += firstFolder + secondFolder; //localDesc400Path += firstFolder + secondFolder; descPath += firstFolder + secondFolder; //localDesc400Path += NewFileName + fileExtention; returnName += descPath + NewFileName + fileExtention; NewFileName = localDescPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + descPath); } else { Mappath[0] = firstFolder; Mappath[1] = secondFolder; //Data:2014/06/26 //author:Castle //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!! CreateFolder(localProdPath, Mappath); //CreateFolder(localProd50Path, Mappath); //CreateFolder(localProd150Path, Mappath); //CreateFolder(localProd280Path, Mappath); localProdPath += firstFolder + secondFolder; //localProd50Path += firstFolder + secondFolder; //localProd150Path += firstFolder + secondFolder; //localProd280Path += firstFolder + secondFolder; prodPath += firstFolder + secondFolder; //localProd50Path += NewFileName + fileExtention; //localProd150Path += NewFileName + fileExtention; //localProd280Path += NewFileName + fileExtention; returnName += prodPath + NewFileName + fileExtention; NewFileName = localProdPath + NewFileName + fileExtention; ServerPath = Server.MapPath(imgLocalServerPath + prodPath); } string ErrorMsg = string.Empty; Resource.CoreMessage = new CoreResource("Product"); //上傳圖片 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); #region // //上傳對應大小圖片 //压缩图片至其它规格 //Data:2014/06/26 //author:Castle //在前台如果各种尺寸的图档没有的时候,前台会自动产生!!! //if (result) //{ // FTP ftp = null; // string newFileName = NewFileName.Substring(NewFileName.LastIndexOf("/")); // GigadeService.TransImageClient transImg = new GigadeService.TransImageClient(); // if (nameType == "spec") // { // string sourceImgPath = Server.MapPath(imgLocalServerPath + specPath + NewFileName.Substring(NewFileName.LastIndexOf("/"))); // ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder), newFileName, 100, 100, admin_userName.Value, admin_passwd.Value); // if (string.IsNullOrWhiteSpace(ErrorMsg)) // { // file.SaveAs(Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder + newFileName)); // ftp = new FTP(localSpec100Path, ftpuser, ftppwd); // ftp.UploadFile(Server.MapPath(imgLocalServerPath + spec100Path + firstFolder + secondFolder + newFileName)); // } // if (!Directory.Exists(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder))) // Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder)); // ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder), newFileName, 280, 280, admin_userName.Value, admin_passwd.Value); // if (string.IsNullOrWhiteSpace(ErrorMsg)) // { // file.SaveAs(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder + newFileName)); // ftp = new FTP(localSpec100Path, ftpuser, ftppwd); // ftp.UploadFile(Server.MapPath(imgLocalServerPath + spec280Path + firstFolder + secondFolder + newFileName)); // } // } // else if (nameType == "desc") // { // string sourceImgPath = Server.MapPath(imgLocalServerPath + descPath + NewFileName.Substring(NewFileName.LastIndexOf("/"))); // ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder), newFileName, 400, 400, admin_userName.Value, admin_passwd.Value); // if (string.IsNullOrWhiteSpace(ErrorMsg)) // { // file.SaveAs(Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder + newFileName)); // ftp = new FTP(localSpec100Path, ftpuser, ftppwd); // ftp.UploadFile(Server.MapPath(imgLocalServerPath + desc400Path + firstFolder + secondFolder + newFileName)); // } // } // else // { // //string sourceImgPath = Server.MapPath(imgLocalServerPath + prodPath + NewFileName.Substring(NewFileName.LastIndexOf("/"))); // //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder), newFileName, 50, 50, admin_userName.Value, admin_passwd.Value); // //if (string.IsNullOrWhiteSpace(ErrorMsg)) // //{ // // file.SaveAs(Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder + newFileName)); // // ftp = new FTP(localProd50Path, ftpuser, ftppwd); // // ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod50Path + firstFolder + secondFolder + newFileName)); // //} // //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder), newFileName, 150, 150, admin_userName.Value, admin_passwd.Value); // //if (string.IsNullOrWhiteSpace(ErrorMsg)) // //{ // // file.SaveAs(Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder + newFileName)); // // ftp = new FTP(localProd150Path, ftpuser, ftppwd); // // ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod150Path + firstFolder + secondFolder + newFileName)); // //} // ////if (!Directory.Exists(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder))) // //// Directory.CreateDirectory(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder)); // ////ImageClass iC280 = new ImageClass(sourceImgPath); // //////iC280.ImageMagick(sourceImgPath, Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + NewFileName.Substring(NewFileName.LastIndexOf("/"))), 280, 280, ref error); // ////iC150.MakeThumbnail(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + NewFileName.Substring(NewFileName.LastIndexOf("/"))), 280, 280, ref error); // //ErrorMsg = transImg.Trans(sourceImgPath, Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder), newFileName, 280, 280, admin_userName.Value, admin_passwd.Value); // //if (string.IsNullOrWhiteSpace(ErrorMsg)) // //{ // // file.SaveAs(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + newFileName)); // // ftp = new FTP(localProd280Path, ftpuser, ftppwd); // // ftp.UploadFile(Server.MapPath(imgLocalServerPath + prod280Path + firstFolder + secondFolder + newFileName)); // //} // } //} #endregion if (string.IsNullOrEmpty(ErrorMsg)) { ViewBag.fileName = returnName; ViewBag.Type = type; //獲取文件長度 add by zhuoqin0830w 2015/01/29 string[] strFile = file.FileName.Split('_'); //判斷文件名的長度是否大於 1 如果大於 1 則再次進行判斷是否為數字 如果不是則進行強制轉換 int image_sort = 0; int.TryParse(strFile.Length > 1 ? strFile[1] : "0", out image_sort); ViewBag.image_sort = image_sort; } else { // 判斷 批量上傳中 是否存在 商品圖 或 手機商品圖 edit by zhuoqin0830w 2015/03/24 if (prodCheck == 0 || mobileCheck == 0) { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; } else { ViewBag.fileName = "ERROR/" + "[" + file.FileName + "] " + ErrorMsg; } Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage(); logMessage.Content = "ERROR/" + ErrorMsg; logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name; log.Error(logMessage); } } 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); } return View("~/Views/Product/upLoad.cshtml"); }
public HttpResponseBase EventChinaTrustBagSave() { string json = string.Empty; EventChinaTrustBagQuery query = new EventChinaTrustBagQuery(); EventChinaTrustBagQuery oldModel = new EventChinaTrustBagQuery(); try { if (!string.IsNullOrEmpty(Request.Params["event_id"])) { query.event_id = Request.Params["event_id"]; } if (!string.IsNullOrEmpty(Request.Params["bag_name"])) { query.bag_name = Request.Params["bag_name"]; } if (!string.IsNullOrEmpty(Request.Params["bag_desc"])) { query.bag_desc = Request.Params["bag_desc"]; } if (!string.IsNullOrEmpty(Request.Params["bag_banner"])) { query.bag_banner = Request.Params["bag_banner"]; } if (!string.IsNullOrEmpty(Request.Params["bag_start_time"])) { query.bag_start_time =Convert.ToDateTime( Request.Params["bag_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["bag_end_time"])) { query.bag_end_time = Convert.ToDateTime(Request.Params["bag_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["bag_show_start_time"])) { query.bag_show_start_time = Convert.ToDateTime(Request.Params["bag_show_start_time"]); } if (!string.IsNullOrEmpty(Request.Params["bag_show_end_time"])) { query.bag_show_end_time =Convert.ToDateTime(Request.Params["bag_show_end_time"]); } if (!string.IsNullOrEmpty(Request.Params["product_number"])) { query.product_number =Convert.ToInt32(Request.Params["product_number"]); } if (string.IsNullOrEmpty(Request.Params["bag_id"]))//新增 { query.bag_create_user=(Session["caller"] as Caller).user_id; query.bag_update_user = (Session["caller"] as Caller).user_id; query.bag_create_time = DateTime.Now; query.bag_update_time = query.bag_create_time; } else//編輯 { query.bag_id = Convert.ToInt32(Request.Params["bag_id"]); query.bag_update_time = DateTime.Now; query.bag_update_user = (Session["caller"] as Caller).user_id; } _eventChinaTrustBag = new EventChinaTrustBagMgr(mySqlConnectionString); #region 上傳圖片 string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + PaperPath;//圖片存儲地址 if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 FileManagement fileLoad = new FileManagement(); fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), PaperPath.Substring(1, PaperPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string ErrorMsg = string.Empty; if (query.bag_id != 0) { oldModel = _eventChinaTrustBag.GetSinggleData(query); if (oldModel.bag_banner != "") { string oldFileName = oldModel.bag_banner; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product"); bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.bag_banner = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); } } } else { query.bag_banner = oldModel.bag_banner; } #endregion if (_eventChinaTrustBag.EventChinaTrustBagSave(query) > 0) { json = "{success:true}"; } else { json = "{success:false}"; } } 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}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase GetUploadArchives() { string json = string.Empty; try { #region 上傳 string ErrorMsg = string.Empty; string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string fileName = string.Empty;//當前文件名 _ITicketDetail = new TicketDetailMgr(mySqlConnectionString); FileManagement fileLoad = new FileManagement(); if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileExtention = string.Empty;//當前文件的擴展名 string oldFileName = file.FileName.Substring(0, file.FileName.LastIndexOf('.')); fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { string filepathday = fileName.Substring(0, fileName.LastIndexOf("."));//每天建立一個文件夾保存村的文件; fileName = oldFileName + "_" + filepathday;//上傳文檔為以前的名字+年月日時分秒.後綴名 filepathday = filepathday.Substring(0, 8); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); // string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); // NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; FTP f_cf = new FTP(); archives = archives + filepathday + "/";//創建多層路徑 string localPromoPath = imgLocalPath + archives;//圖片存儲地址 f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - archives.Length + 1), archives.Substring(1, archives.Length - 2).Split('/'), ftpuser, ftppwd); // fileName = NewFileName + fileExtention; fileName = localPromoPath + fileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + archives); Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = _ITicketDetail.UpLoadFile(file, ServerPath, fileName, extention, (int.MaxValue / 1024) - 1, 0, ref ErrorMsg, ftpuser, ftppwd); if (result) { json = "{\"success\":\"true\"}"; } else { json = "{\"success\":\"false\",\"msg\":\"上傳失败\"}"; } } } #endregion } 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\",\"msg\":\"參數出錯\"}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveChinaTrustBagMap() { string json = string.Empty; bool pic = true; DataTable dt = new DataTable(); try { _ChinatrustBMMgr = new EventChinaTrustBagMapMgr(mySqlConnectionString); EventChinaTrustBagMapQuery store = new EventChinaTrustBagMapQuery(); EventChinaTrustBagMapQuery query = new EventChinaTrustBagMapQuery(); if (!string.IsNullOrEmpty(Request.Params["id"])) {//如果是編輯獲取該id數據 int totalCount = 0; query.IsPage = false; query.map_id = int.Parse(Request.Params["id"]); store = _ChinatrustBMMgr.GetChinaTrustBagMapList(query, out totalCount).FirstOrDefault(); query = store; } //product_id if (!string.IsNullOrEmpty(Request.Params["product_id"])) { query.product_id = Convert.ToUInt32(Request.Params["product_id"]); } else { query.product_id = 0; } if (!string.IsNullOrEmpty(Request.Params["bag_id"])) { query.bag_id = Convert.ToInt32(Request.Params["bag_id"]); } if (!string.IsNullOrEmpty(Request.Params["linkurl"])) { query.linkurl = Request.Params["linkurl"]; } if (!string.IsNullOrEmpty(Request.Params["product_forbid_banner"])) { query.product_forbid_banner = Request.Params["product_forbid_banner"]; } if (!string.IsNullOrEmpty(Request.Params["product_active_banner"])) { query.product_active_banner = Request.Params["product_active_banner"]; } if (!string.IsNullOrEmpty(Request.Params["ad_product_id"])) { string p_id = Request.Params["ad_product_id"]; RegexOptions options = RegexOptions.None; Regex regex = new Regex(@"[ ]{2,}", options); p_id = regex.Replace(p_id, @" "); p_id = p_id.Replace(" ", ","); for (int i = p_id.Length - 1; i > 0; i--) { if (p_id.Substring(p_id.Length - 1, 1) == ",") { p_id = p_id.Substring(0, p_id.Length - 1); } } string[] pr_id = p_id.Split(',').Distinct().ToArray(); ; string pro_id = ""; for (int i = 0; i < pr_id.Length; i++) { if (_ChinatrustBMMgr.IsProductId(pr_id[i].ToString())) { pro_id += pr_id[i].ToString() + ","; } } if (pro_id.Length > 0) { query.ad_product_id = pro_id.Substring(0, pro_id.Length - 1); } else { query.ad_product_id = null; } } else { query.ad_product_id = null; } if (!string.IsNullOrEmpty(Request.Params["product_desc"])) { query.product_desc = Request.Params["product_desc"]; } else { query.product_desc = null; } #region 上傳圖片 try { string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MinValue"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + PaperPath;//圖片存儲地址 Random rand = new Random(); FileManagement fileLoad = new FileManagement(); for (int iFile = 0; iFile < Request.Files.Count; iFile++) { //int newRand = rand.Next(1000, 9999); HttpPostedFileBase file = Request.Files[iFile]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 bool result = false; string NewFileName = string.Empty; string ServerPath = string.Empty; fileName = Path.GetFileName(file.FileName); string newRand = hash.Md5Encrypt(fileLoad.NewFileName(fileName), "32"); string ErrorMsg = string.Empty; if (iFile == 0) { if (string.IsNullOrEmpty(file.FileName)) { query.product_forbid_banner = store.product_forbid_banner; } else { fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; //判斷目錄是否存在,不存在則創建 string[] mapPath = new string[1]; mapPath[0] = PaperPath.Substring(1, PaperPath.Length - 1); string s = localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1); CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), mapPath); // returnName += PaperPath + NewFileName; fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string oldFileName = ""; oldFileName = store.product_forbid_banner; if (!string.IsNullOrEmpty(oldFileName)) { DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } try { //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.product_forbid_banner = fileName; } else { pic = false; } } catch (Exception) { query.product_forbid_banner = store.product_forbid_banner; query.product_active_banner = store.product_active_banner; } } } if (iFile == 1) { if (string.IsNullOrEmpty(file.FileName)) { query.product_active_banner = store.product_active_banner; } else { fileExtention = fileName.Substring(fileName.LastIndexOf(".")).ToLower(); NewFileName = newRand + fileExtention; //判斷目錄是否存在,不存在則創建 string[] mapPath = new string[1]; mapPath[0] = PaperPath.Substring(1, PaperPath.Length - 1); string s = localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1); CreateFolder(localPromoPath.Substring(0, localPromoPath.Length - PaperPath.Length + 1), mapPath); // returnName += PaperPath + NewFileName; fileName = NewFileName; NewFileName = localPromoPath + NewFileName;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + PaperPath); string oldFileName = ""; oldFileName = store.product_active_banner; if (!string.IsNullOrEmpty(oldFileName)) { DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 } try { //上傳 result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result)//上傳成功 { query.product_active_banner = fileName; } else { pic = false; } } catch (Exception) { query.product_forbid_banner = store.product_forbid_banner; query.product_active_banner = store.product_active_banner; } } } } } catch (Exception) { query.product_forbid_banner = store.product_forbid_banner; query.product_active_banner = store.product_active_banner; } #endregion if (pic) { if (query.map_id > 0) {//編輯 if (!string.IsNullOrEmpty(Request.Params["map_sort"])) { query.map_sort = Convert.ToInt32(Request.Params["map_sort"]); } if (_ChinatrustBMMgr.Update(query) > 0) { json = "{success:true,msg:'修改成功!'}"; } else { json = "{success:false,msg:'修改失敗!'}"; } } else {//新增 dt = _ChinatrustBMMgr.GetMapSort(query); if (dt.Rows.Count > 0) { query.map_sort = int.Parse(dt.Rows[0]["map_sort"].ToString()) + 1; } else { query.map_sort = 0; } query.map_active = 0;//默認不啟用 if (_ChinatrustBMMgr.Save(query) > 0) { json = "{success:true,msg:'新增成功!'}"; } else { json = "{success:false,msg:'新增失敗!'}"; } } } else { json = "{success:false,msg:'圖片上傳失敗!'}"; } } 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,msg:'操作失敗!'}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase InsertNewPromoCarnet() { NewPromoCarnetQuery query = new NewPromoCarnetQuery(); NewPromoCarnetQuery oldModel = new NewPromoCarnetQuery(); _INewPromoCarnetMgr = new NewPromoCarnetMgr(mySqlConnectionString); string json = string.Empty; try { if (!string.IsNullOrEmpty(Request.Params["row_id"])) { query.row_id = Convert.ToInt32(Request.Params["row_id"].ToString()); } if (!string.IsNullOrEmpty(Request.Params["present_event_id"])) { query.present_event_id = Request.Params["present_event_id"].ToString(); } if (!string.IsNullOrEmpty(Request.Params["group_id"])) { query.group_id = Convert.ToInt32(Request.Params["group_id"]); } if (!string.IsNullOrEmpty(Request.Params["new_user"])) { query.new_user = Convert.ToInt32(Request.Params["new_user"]); } if (!string.IsNullOrEmpty(Request.Params["new_user_date"])) { query.new_user_date = Convert.ToDateTime(Request.Params["new_user_date"]); } if (!string.IsNullOrEmpty(Request.Params["count_by"])) { query.count_by = Convert.ToInt32(Request.Params["count_by"]); } if (!string.IsNullOrEmpty(Request.Params["count"])) { query.count = Convert.ToInt32(Request.Params["count"]); } if (!string.IsNullOrEmpty(Request.Params["device"])) { query.device = (Request.Params["device"]); } if (!string.IsNullOrEmpty(Request.Params["message_mode"])) { query.message_mode = Convert.ToInt32(Request.Params["message_mode"]); } if (!string.IsNullOrEmpty(Request.Params["message_content"])) { query.message_content = (Request.Params["message_content"]); } if (!string.IsNullOrEmpty(Request.Params["link_url"])) { query.link_url = (Request.Params["link_url"]); } if (!string.IsNullOrEmpty(Request.Params["promo_image"])) { query.promo_image = Request.Params["promo_image"]; } if (!string.IsNullOrEmpty(Request.Params["active_now"])) { query.active_now = Convert.ToInt32(Request.Params["active_now"]); } #region 上傳圖片 string ErrorMsg = string.Empty; string path = Server.MapPath(xmlPath); SiteConfigMgr _siteConfigMgr = new SiteConfigMgr(path); SiteConfig extention_config = _siteConfigMgr.GetConfigByName("PIC_Extention_Format"); SiteConfig minValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_Min_Element"); SiteConfig maxValue_config = _siteConfigMgr.GetConfigByName("PIC_Length_MaxValue"); SiteConfig admin_userName = _siteConfigMgr.GetConfigByName("ADMIN_USERNAME"); SiteConfig admin_passwd = _siteConfigMgr.GetConfigByName("ADMIN_PASSWD"); //擴展名、最小值、最大值 string extention = extention_config.Value == "" ? extention_config.DefaultValue : extention_config.Value; string minValue = minValue_config.Value == "" ? minValue_config.DefaultValue : minValue_config.Value; string maxValue = maxValue_config.Value == "" ? maxValue_config.DefaultValue : maxValue_config.Value; string localPromoPath = imgLocalPath + NewPromoPath;//圖片存儲地址 FileManagement fileLoad = new FileManagement(); if (Request.Files.Count > 0) { HttpPostedFileBase file = Request.Files[0]; string fileName = string.Empty;//當前文件名 string fileExtention = string.Empty;//當前文件的擴展名 fileName = fileLoad.NewFileName(file.FileName); if (fileName != "") { fileName = fileName.Substring(0, fileName.LastIndexOf(".")); fileExtention = file.FileName.Substring(file.FileName.LastIndexOf('.')).ToLower().ToString(); string NewFileName = string.Empty; BLL.gigade.Common.HashEncrypt hash = new BLL.gigade.Common.HashEncrypt(); NewFileName = hash.Md5Encrypt(fileName, "32"); string ServerPath = string.Empty; FTP f_cf = new FTP(); f_cf.MakeMultiDirectory(localPromoPath.Substring(0, localPromoPath.Length - NewPromoPath.Length + 1), NewPromoPath.Substring(1, NewPromoPath.Length - 2).Split('/'), ftpuser, ftppwd); fileName = NewFileName + fileExtention; NewFileName = localPromoPath + NewFileName + fileExtention;//絕對路徑 ServerPath = Server.MapPath(imgLocalServerPath + NewPromoPath); //上傳之前刪除已有的圖片 if (query.row_id != 0) { oldModel = _INewPromoCarnetMgr.GetModel(query); if (oldModel.promo_image != "") { string oldFileName = oldModel.promo_image; CommonFunction.DeletePicFile(ServerPath + oldFileName);//刪除本地圖片 FTP ftp = new FTP(localPromoPath, ftpuser, ftppwd); List<string> tem = ftp.GetFileList(); if (tem.Contains(oldFileName)) { FTP ftps = new FTP(localPromoPath + oldFileName, ftpuser, ftppwd); ftps.DeleteFile(localPromoPath + oldFileName); } } } try { Resource.CoreMessage = new CoreResource("Product");//尋找product.resx中的資源文件 bool result = fileLoad.UpLoadFile(file, ServerPath, NewFileName, extention, int.Parse(maxValue), int.Parse(minValue), ref ErrorMsg, ftpuser, ftppwd); if (result) { query.promo_image = fileName; } } 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); } if (!string.IsNullOrEmpty(ErrorMsg)) { string jsonStr = string.Empty; json = "{success:true,msg:\"" + ErrorMsg + "\"}"; this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; } } } else { query.promo_image = oldModel.promo_image; } #endregion if (!string.IsNullOrEmpty(Request.Params["event_name"])) { query.event_name = Request.Params["event_name"]; } if (!string.IsNullOrEmpty(Request.Params["event_desc"])) { query.event_desc = Request.Params["event_desc"]; } if (!string.IsNullOrEmpty(Request.Params["start"])) { query.start = Convert.ToDateTime(Request.Params["start"]); } if (!string.IsNullOrEmpty(Request.Params["end"])) { query.end = Convert.ToDateTime(Request.Params["end"]); } if (query.row_id == 0) { query.kuser = (Session["caller"] as Caller).user_id; query.muser = query.kuser; query.created = DateTime.Now; query.modified = query.created; query.row_id = _INewPromoCarnetMgr.GetNewPromoCarnetMaxId(); query.event_id = BLL.gigade.Common.CommonFunction.GetEventId("F2", query.row_id.ToString()); if (_INewPromoCarnetMgr.InsertNewPromoCarnet(query) > 0) { json = "{success:true}"; } else { json = "{success:false}"; } } else { query.muser = (Session["caller"] as Caller).user_id; query.modified = DateTime.Now; if (_INewPromoCarnetMgr.UpdateNewPromoCarnet(query)) { json = "{success:true}"; } else { json = "{success:false}"; } } } 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}"; } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }
public HttpResponseBase SaveImportFile() { Session["import"] = null; string json = "{success:false}"; siteConfigMgr = new SiteConfigMgr(Server.MapPath(xmlPath)); try { if (Request.Files["channelFile"] != null && Request.Files["channelFile"].ContentLength > 0) { HttpPostedFileBase excelFile = Request.Files["channelFile"]; FileManagement fileManagement = new FileManagement(); string newExcelName = fileManagement.NewFileName(excelFile.FileName); string oldExcelName = excelFile.FileName.Split('\\').LastOrDefault(); #region Excel文件限制 SiteConfig excellConfig = siteConfigMgr.GetConfigByName("Excel_Extension_Filter"); string excelEx = string.IsNullOrEmpty(excellConfig.Value) ? excellConfig.DefaultValue : excellConfig.Value; SiteConfig minConfig = siteConfigMgr.GetConfigByName("Excel_Length_Min"); SiteConfig maxConfig = siteConfigMgr.GetConfigByName("Excel_Length_Max"); int excelMin = Convert.ToInt32(DataCheck.IsNumeric(minConfig.Value) ? minConfig.Value : minConfig.DefaultValue); int excelMax = Convert.ToInt32(DataCheck.IsNumeric(maxConfig.Value) ? maxConfig.Value : maxConfig.DefaultValue); #endregion Resource.CoreMessage = new CoreResource("Product"); if (fileManagement.UpLoadFile(excelFile, Server.MapPath(excelPath) + "/" + newExcelName, excelEx, excelMax, excelMin))//保存導入訂單excel文件 { if (!string.IsNullOrEmpty(Request.Form["importType"]) && Request.Form["importType"] == "2") { if (Request.Files["dispatch"] != null && Request.Files["dispatch"].ContentLength > 0) { HttpPostedFileBase dispatchFile = Request.Files["dispatch"]; string newPDFName = fileManagement.NewFileName(dispatchFile.FileName); #region PDF文件限制 SiteConfig pdfConfig = siteConfigMgr.GetConfigByName("PDF_Extension_Filter"); string pdfEx = string.IsNullOrEmpty(pdfConfig.Value) ? pdfConfig.DefaultValue : pdfConfig.Value; minConfig = siteConfigMgr.GetConfigByName("PDF_Length_Min"); maxConfig = siteConfigMgr.GetConfigByName("PDF_Length_Max"); int pdfMin = Convert.ToInt32(DataCheck.IsNumeric(minConfig.Value) ? minConfig.Value : minConfig.DefaultValue); int pdfMax = Convert.ToInt32(DataCheck.IsNumeric(maxConfig.Value) ? maxConfig.Value : maxConfig.DefaultValue); #endregion if (fileManagement.UpLoadFile(dispatchFile, Server.MapPath(pdfPath) + "/" + newPDFName, pdfEx, pdfMax, pdfMin))//保存選擇 ‘超商取貨’ 時需上傳的取貨單文件 { json = "{success:true,msg:\"" + newExcelName + "|" + oldExcelName + "|" + newPDFName + "\"}"; } } } else { json = "{success:true,msg:\"" + newExcelName + "|" + oldExcelName + "\"}"; } } } } 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); } this.Response.Clear(); this.Response.Write(json); this.Response.End(); return this.Response; }