public void ProcessRequest(HttpContext context) { //检查是否登录后上传操作 //if (context.Session["AdminNo"] == null) //{ // context.Response.Write("{\"msg\": 0, \"msbox\": \"请登录后再进行上传文件!\"}"); // return; //} HttpPostedFile _upfile = context.Request.Files["FileUpload"]; string _delfile = context.Request.Params["txtImgUrl"]; if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msbox\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, 0); //删除已存在的旧文件 if (!string.IsNullOrEmpty(_delfile)) { string _filename = HttpContext.Current.Server.MapPath(_delfile); if (File.Exists(_filename)) { File.Delete(_filename); } } //返回成功信息 context.Response.Write(msg); }
private void UpLoadFile(HttpContext context) { string _delfile = MXRequest.GetString("DelFilePath"); HttpPostedFile _upfile = context.Request.Files["Filedata"]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (MXRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (MXRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater); //删除已存在的旧文件 if (!string.IsNullOrEmpty(_delfile)) { Utils.DeleteUpFile(_delfile); } //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void UpLoadFile(HttpContext context) { Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(); string _delfile = DTRequest.GetString("DelFilePath"); HttpPostedFile _upfile = context.Request.Files["Filedata"]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (DTRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (DTRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater); //删除已存在的旧文件,旧文件不为空且应是上传文件,防止跨目录删除 if (!string.IsNullOrEmpty(_delfile) && _delfile.IndexOf("../") == -1 && _delfile.ToLower().StartsWith(siteConfig.webpath.ToLower() + siteConfig.filepath.ToLower())) { Utils.DeleteUpFile(_delfile); } //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void MultipleFile(HttpContext context) { string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上傳的對象名稱 HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _iswater = false; //默認不打浮水印 bool _isthumbnail = false; //默認不生成縮略圖 if (context.Request.QueryString["IsWater"] == "1") { _iswater = true; } if (context.Request.QueryString["IsThumbnail"] == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"請選擇要上傳文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, false); //返回成功資訊 context.Response.Write(msg); context.Response.End(); }
private void SingleFile(HttpContext context) { string _refilepath = context.Request.QueryString["ReFilePath"]; //取得返回的对象名称 string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称 string _delfile = context.Request.Params[_refilepath]; HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (context.Request.QueryString["IsWater"] == "1") { _iswater = true; } if (context.Request.QueryString["IsThumbnail"] == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{msg: 0, msbox: \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater); //删除已存在的旧文件 Utils.DeleteUpFile(_delfile); //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void UpLoadFile(HttpContext context) { string _delfile = GetString("DelFilePath"); HttpPostedFile _upfile = context.Request.Files["Filedata"]; string filepath = GetQueryString("filepath"); string filetypes = GetQueryString("filetypes"); //文件类型 string filetype = GetQueryString("filetype"); //上传类型 3-任务上传 bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (GetQueryString("IsWater") == "1") { _iswater = true; } if (GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, filepath, filetypes, filetype); //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void MultipleFile(HttpContext context) { string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称 HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (ContextRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (ContextRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater); //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void EditorFile(HttpContext context) { bool _iswater = false; //默认不打水印 if (context.Request.QueryString["IsWater"] == "1") { _iswater = true; } HttpPostedFile imgFile = context.Request.Files["imgFile"]; if (imgFile == null) { showError(context, "请选择要上传文件!"); return; } UpLoad upFiles = new UpLoad(); string remsg = upFiles.fileSaveAs(imgFile, false, _iswater); Dictionary <string, object> dic = JsonHelper.DataRowFromJSON(remsg); string status = dic["status"].ToString(); string msg = dic["msg"].ToString(); if (status == "0") { showError(context, msg); return; } string filePath = dic["path"].ToString(); //取得上传后的路径 Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = filePath; context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonHelper.ObjectToJSON(hash)); context.Response.End(); }
public void ProcessRequest(HttpContext context) { //检查是否登录后上传操作 //if (context.Session["AdminNo"] == null) //{ // context.Response.Write("{msg: 0, msbox: \"请登录后再进行上传文件!\"}"); // return; //} string _refilepath = context.Request.QueryString["ReFilePath"]; //取得返回的对象名称 string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称 int _iswater; //默认打水印 if (!int.TryParse(context.Request.QueryString["IsWater"] as string, out _iswater)) { _iswater = 1; } int _maxFileSize; if (!int.TryParse(context.Request.QueryString["MaxFileSize"] as string, out _maxFileSize)) { _maxFileSize = 1000; } HttpPostedFile _upfile = context.Request.Files[_upfilepath]; string _delfile = context.Request.Params[_refilepath]; if (_upfile == null) { context.Response.Write("{msg: 0, msbox: \"请选择要上传文件!\"}"); return; } if (_upfile.ContentLength > _maxFileSize * 1024) { context.Response.Write("{msg: 0, msbox: \"文件大小超过限制!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _iswater); //删除已存在的旧文件 if (!string.IsNullOrEmpty(_delfile)) { string _filename = Utils.GetMapPath(_delfile); if (File.Exists(_filename)) { File.Delete(_filename); } } //返回成功信息 context.Response.Write(msg); }
private void UpLoadFile(HttpContext context) { string _delfile = RequestHelper.GetString("DelFilePath"); HttpPostedFile _upfile = context.Request.Files["File"]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (RequestHelper.GetQueryString("IsWater") == "1") { _iswater = true; } if (RequestHelper.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } string upLoadPath = RequestHelper.GetQueryString("UpLoadPath"); string fileType = ""; if (RequestHelper.GetQueryString("FileType") != null) { fileType = RequestHelper.GetQueryString("FileType"); } UpLoad upFiles = new UpLoad(); string remsg = upFiles.fileSaveAs(_upfile, upLoadPath, _isthumbnail, _iswater, fileType); //删除已存在的旧文件 if (!string.IsNullOrEmpty(_delfile)) { Utils.DeleteUpFile(_delfile); } ResponseInfo(context, remsg); ////返回成功信息 //context.Response.Write(remsg); //context.Response.End(); }
private void WordExtract(HttpContext context) { string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称 HttpPostedFile _upfile = context.Request.Files[_upfilepath]; var extension = Path.GetExtension(_upfile.FileName); if (extension != ".docx" && extension != ".doc") { context.Response.Write("{\"msg\": 0, \"msgbox\": \"请您选择word文件上传!\"}"); return; } bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, false, false); JsonData msgJson = JsonMapper.ToObject(msg); //word文件上传成功,进行word抽取 if (msgJson["msg"].ToString() == "1") { String wordPath = msgJson["msgbox"].ToString(); String wordContent; try { wordContent = new WordExtrator().GetHtmlFromWord(wordPath, true); } catch (Exception ex) { msgJson["msg"] = "0";//失败 wordContent = "word文档导入失败,可能是word格式不兼容。请您在编辑器中编辑信息!"; } //msgJson["msgbox"] = HttpContext.Current.Server.HtmlEncode(wordContent); //msgJson["msgbox"] = Utils.DropHTML(wordContent); msgJson["msgbox"] = HttpUtility.UrlEncode(wordContent).Replace("+", "%20"); msg = msgJson.ToJson(); } context.Response.Write(msg); context.Response.End(); }
/// <summary> /// 上传图片的方法 /// 返回缩略图的路劲 /// </summary> /// <param name="context"></param> private string UpLoadFile(HttpContext context) { HttpPostedFile _upfile = context.Request.Files["header_img_id"]; // HttpFileCollection files = HttpContext.Current.Request.Files; bool _iswater = false; //默认不打水印 bool _isthumbnail = true; //默认生成缩略图 _isthumbnail = true; if (_upfile == null) { return(""); } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater); //返回成功信息 return(msg); }
private void AttachFile(HttpContext context) { string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称 HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (_upfile == null) { context.Response.Write("{msg: 0, msgbox: \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, true); //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void UpLoadFile(HttpContext context) { try { Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(); string _delfile = RequestHelper.GetString("DelFilePath"); HttpPostedFile _upfile = context.Request.Files["Filedata"]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (RequestHelper.GetQueryString("IsWater") == "1") { _iswater = true; } if (RequestHelper.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string folder = RequestHelper.GetQueryString("folder"); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, folder); //删除已存在的旧文件,旧文件不为空且应是上传文件,防止跨目录删除 if (!string.IsNullOrEmpty(_delfile) && _delfile.IndexOf("../") == -1 && _delfile.ToLower().StartsWith(siteConfig.webpath.ToLower() + siteConfig.filepath.ToLower())) { Utils.DeleteUpFile(_delfile); } //NetLog.WriteTextLog("UpLoadFile", msg, System.DateTime.Now, "img"); //返回成功信息 context.Response.Write(msg); context.Response.End(); } catch (Exception e) { Utils.StringToTxt("UpLoadFile上传文件发生异常:" + e.TargetSite); } }
public void ProcessRequest(HttpContext context) { //检查是否登录后上传操作 if (!new ManagePage().IsAdminLogin()) { context.Response.Write("{msg: 0, msbox: \"请登录后再进行上传文件!\"}"); return; } HttpPostedFile _upfile = context.Request.Files["FileUpload"]; string _delfile = context.Request.Params["txtImgUrl"]; if (_upfile == null) { context.Response.Write("{msg: 0, msbox: \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string remsg = upFiles.fileSaveAs(_upfile, 1); string pattern = @"^{\s*msg:\s*(.*)\s*,\s*msbox:\s*\""(.*)\""\s*}$"; //键名前和键值前后都允许出现空白字符 Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //正则表达式实例,不区分大小写 Match m = r.Match(remsg); //搜索匹配项 string msg = m.Groups[1].Value; //msg的值,正则表达式中第1个圆括号捕获的值 string msbox = m.Groups[2].Value; //msbox的值,正则表达式中第2个圆括号捕获的值 //如果是修改,则上传文件后同时写进数据库 string _pid = context.Request.Params["album_parent_id"]; if (!string.IsNullOrEmpty(_pid) && msg == "1") { DtCms.BLL.PicturesAlbum bll = new DtCms.BLL.PicturesAlbum(); DtCms.Model.PicturesAlbum model = new DtCms.Model.PicturesAlbum(); model.PictureId = int.Parse(_pid); model.ImgUrl = msbox; int _reid = bll.Add(model); context.Response.Write("{msg: 1, msgid: \"" + _reid + "\", msbox: \"" + msbox + "\"}"); return; } //返回成功信息 context.Response.Write(remsg); }
private void EditorFile(HttpContext context) { bool _iswater = false; //默认不打水印 if (context.Request.QueryString["IsWater"] == "1") { _iswater = true; } HttpPostedFile imgFile = context.Request.Files["imgFile"]; string upLoadPath = RequestHelper.GetQueryString("UpLoadPath"); if (imgFile == null) { showError(context, "请选择要上传文件!"); return; } UpLoad upFiles = new UpLoad(); string remsg = upFiles.fileSaveAs(imgFile, upLoadPath, false, _iswater, ""); ResponseInfo(context, remsg); }
private void Excelfile(HttpContext context) { string _refilepath = ContextRequest.GetQueryString("ReFilePath"); //取得返回的对象名称 string _upfilepath = ContextRequest.GetQueryString("UpFilePath"); //取得上传的对象名称 string _delfile = ContextRequest.GetString(_refilepath); HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _isExcel = false; //默认不打水印 if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isExcel); //删除已存在的旧文件 Utils.DeleteUpFile(_delfile); //返回成功信息 context.Response.Write(msg); context.Response.End(); }
public void ProcessRequest(HttpContext context) { //检查是否登录后上传操作 if (!new ManagePage().IsAdminLogin()) { context.Response.Write("{msg: 0, msbox: \"请登录后再进行上传文件!\"}"); return; } string _refilepath = context.Request.QueryString["ReFilePath"]; //取得返回的对象名称 string _upfilepath = context.Request.QueryString["UpFilePath"]; //取得上传的对象名称 int _iswater; //默认打水印 if (!int.TryParse(context.Request.QueryString["IsWater"] as string, out _iswater)) { _iswater = 1; } HttpPostedFile _upfile = context.Request.Files[_upfilepath]; string _delfile = context.Request.Params[_refilepath]; if (_upfile == null) { context.Response.Write("{msg: 0, msbox: \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _iswater); //删除已存在的旧文件 if (!string.IsNullOrEmpty(_delfile)) { string _filename = Utils.GetMapPath(_delfile); if (File.Exists(_filename)) { File.Delete(_filename); } } //返回成功信息 context.Response.Write(msg); }
private void EditorFile(HttpContext context) { bool _iswater = false; //默認不打浮水印 if (context.Request.QueryString["IsWater"] == "1") { _iswater = true; } HttpPostedFile imgFile = context.Request.Files["imgFile"]; if (imgFile == null) { showError(context, "請選擇要上傳文件!"); return; } UpLoad upFiles = new UpLoad(); string remsg = upFiles.fileSaveAs(imgFile, false, _iswater, true); //string pattern = @"^{\s*msg:\s*(.*)\s*,\s*msgbox:\s*\""(.*)\""\s*}$"; //鍵名前和鍵值前後都允許出現空白字元 //Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //規則運算式實例,不區分大小寫 //Match m = r.Match(remsg); //搜索匹配項 //string msg = m.Groups[1].Value; //msg的值,規則運算式中第1個圓括號捕獲的值 //string msgbox = m.Groups[2].Value; //msgbox的值,規則運算式中第2個圓括號捕獲的值 JsonData jd = JsonMapper.ToObject(remsg); string msg = jd["msg"].ToString(); string msgbox = jd["msgbox"].ToString(); if (msg == "0") { showError(context, msgbox); return; } Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = msgbox; context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonMapper.ToJson(hash)); context.Response.End(); }
private void SingleFile(HttpContext context) { string _refilepath = DTRequest.GetQueryString("ReFilePath"); //取得返回的對象名稱 string _upfilepath = DTRequest.GetQueryString("UpFilePath"); //取得上傳的對象名稱 string _delfile = DTRequest.GetString(_refilepath); HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _iswater = false; //默認不打浮水印 bool _isthumbnail = false; //默認不生成縮略圖 bool _isimage = false; //預設不限制圖片上傳 if (DTRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (DTRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (DTRequest.GetQueryString("IsImage") == "1") { _isimage = true; } if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"請選擇要上傳文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, _isimage, false); //刪除已存在的舊檔 Utils.DeleteUpFile(_delfile); //返回成功資訊 context.Response.Write(msg); context.Response.End(); }
private void SingleFile(HttpContext context) { string _refilepath = ContextRequest.GetQueryString("ReFilePath"); //取得返回的对象名称 string _upfilepath = ContextRequest.GetQueryString("UpFilePath"); //取得上传的对象名称 string _delfile = ContextRequest.GetString(_refilepath); HttpPostedFile _upfile = context.Request.Files[_upfilepath]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 bool _isimage = false; if (ContextRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (ContextRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (ContextRequest.GetQueryString("IsImage") == "1") { _isimage = true; } if (_upfile == null) { context.Response.Write("{\"msg\": 0, \"msgbox\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, _isimage); //删除已存在的旧文件 Utils.DeleteUpFile(_delfile); //返回成功信息 context.Response.Write(msg); context.Response.End(); }
private void EditorFile(HttpContext context) { bool _iswater = false; //默认不打水印 if (context.Request.QueryString["IsWater"] == "1") { _iswater = true; } HttpPostedFile imgFile = context.Request.Files["imgFile"]; if (imgFile == null) { showError(context, "请选择要上传文件!"); return; } UpLoad upFiles = new UpLoad(); string remsg = upFiles.fileSaveAs(imgFile, false, _iswater); string pattern = @"^{\s*msg:\s*(.*)\s*,\s*msbox:\s*\""(.*)\""\s*}$"; //键名前和键值前后都允许出现空白字符 Regex r = new Regex(pattern, RegexOptions.IgnoreCase); //正则表达式实例,不区分大小写 Match m = r.Match(remsg); //搜索匹配项 string msg = m.Groups[1].Value; //msg的值,正则表达式中第1个圆括号捕获的值 string msbox = m.Groups[2].Value; //msbox的值,正则表达式中第2个圆括号捕获的值 if (msg == "0") { showError(context, msbox); return; } Hashtable hash = new Hashtable(); hash["error"] = 0; hash["url"] = msbox; context.Response.AddHeader("Content-Type", "text/html; charset=UTF-8"); context.Response.Write(JsonMapper.ToJson(hash)); context.Response.End(); }
private void ExcelFile(HttpContext context) { string _delfile = AXRequest.GetString("DelFilePath"); HttpPostedFile _upfile = context.Request.Files["Filedata"]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 int id = 0; if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } // Common.Log.LogMsg("1", "admin"); StringBuilder sb = new StringBuilder(220000); StringBuilder info = new StringBuilder(220000); // Common.Log.LogMsg("start", "super"); UpLoad upFiles = new UpLoad(); string newpath = ""; string msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater, ref newpath); // Common.Log.LogMsg("newpath:" + newpath, "super"); DataTable dt = Common.ExcelHelper.ConvertExcelFileToTable(newpath); BLL.article bll = new BLL.article(); BLL.article_category bbc = new BLL.article_category(); // Common.Log.LogMsg("count:"+dt.Rows.Count.ToString(), "super"); // Common.Log.LogMsg("row:" + dt.Rows[0][0].ToString().Trim(), "super"); for (int i = 1; i < dt.Rows.Count; i++) { int type = 0; string no = ""; if (dt.Rows[i]["Name"].ToString().Trim() == "" && dt.Rows[i]["Barcode"].ToString().Trim() == "") { continue; } if (dt.Rows[i]["Name"].ToString().Trim() == "") { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"失败\","); sb.Append("\"reason\":\"中文名不能为空\""); sb.Append("},"); continue; } if (dt.Rows[i]["Barcode"].ToString().Trim() == "") { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"失败\","); sb.Append("\"reason\":\"条形码不能为空\""); sb.Append("},"); continue; } else { if (bll.ExistsBarcode(dt.Rows[i]["Barcode"].ToString().Trim())) { // sb.Append("{"); // sb.Append("\"id\":\"" + i + "\","); //sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); //sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); //sb.Append("\"result\":\"失败\","); // sb.Append("\"reason\":\"此商品已存在\""); // sb.Append("},"); // continue; type = 1; } } if (dt.Rows[i]["ProductTypeNo"].ToString().Trim() == "") { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"失败\","); sb.Append("\"reason\":\"商品类型不能为空\""); sb.Append("},"); continue; } else { try { no = dt.Rows[i]["ProductTypeNo"].ToString().Trim(); if (string.IsNullOrEmpty(no)) { id = 0; } else { id = bbc.GetID(no); } if (id == 0) { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"失败\","); sb.Append("\"reason\":\"商品类型不存在\""); sb.Append("},"); continue; } } catch (Exception ex) { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"失败\","); sb.Append("\"reason\":\"商品类型:" + ex.Message + "\""); sb.Append("},"); continue; } } // Common.Log.LogMsg("1", "super"); Model.article model = new Model.article(); Dictionary <string, string> dn = new Dictionary <string, string>(); if (type == 1) { model = bll.GetModelNew(" where Barcode='" + dt.Rows[i]["Barcode"].ToString().Trim() + "'"); dn = model.fields; if (dt.Rows[i]["Quantity"].ToString().Trim() == "") { // dn.Add("stock_quantity", "0"); } else { Decimal d = Convert.ToDecimal(model.fields["stock_quantity"]) + Convert.ToDecimal(dt.Rows[i]["Quantity"].ToString().Trim()); dn["stock_quantity"] = d.ToString(); } if (dt.Rows[i]["PriceMode"].ToString().Trim() == "") { dn["PriceMode"] = "0"; } else { dn["PriceMode"] = dt.Rows[i]["PriceMode"].ToString().Trim(); } if (dt.Rows[i]["PurchasePrice"].ToString().Trim() == "") { dn["PurchasePrice"] = "0"; } else { dn["PurchasePrice"] = dt.Rows[i]["PurchasePrice"].ToString().Trim(); } if (dt.Rows[i]["WholesalePrice"].ToString().Trim() == "") { dn["WholesalePrice"] = "0"; } else { dn["WholesalePrice"] = dt.Rows[i]["WholesalePrice"].ToString().Trim(); } if (dt.Rows[i]["SpecialPrice"].ToString().Trim() == "") { dn["SpecialPrice"] = "0"; } else { dn["SpecialPrice"] = dt.Rows[i]["SpecialPrice"].ToString().Trim(); } if (dt.Rows[i]["DiscountRate"].ToString().Trim() == "") { dn["DiscountRate"] = "0"; } else { dn["DiscountRate"] = dt.Rows[i]["DiscountRate"].ToString().Trim(); } dn["Barcode"] = dt.Rows[i]["Barcode"].ToString().Trim(); dn["goods_no"] = dt.Rows[i]["No"].ToString().Trim(); dn["english_name"] = dt.Rows[i]["NameP"].ToString().Trim(); dn["ProductTypeNo"] = dt.Rows[i]["ProductTypeNo"].ToString().Trim(); dn["sub_title"] = dt.Rows[i]["Name"].ToString().Trim(); } else { model.img_url = "/upload/templates/default.jpg"; model.sort_id = 99; model.click = 0; model.status = 0; model.is_msg = 0; model.is_top = 0; model.is_red = 0; model.is_hot = 0; model.is_slide = 0; if (dt.Rows[i]["Quantity"].ToString().Trim() == "") { dn.Add("stock_quantity", "0"); } else { dn.Add("stock_quantity", dt.Rows[i]["Quantity"].ToString().Trim()); } if (dt.Rows[i]["PriceMode"].ToString().Trim() == "") { dn.Add("PriceMode", "0"); } else { dn.Add("PriceMode", dt.Rows[i]["PriceMode"].ToString().Trim()); } if (dt.Rows[i]["PurchasePrice"].ToString().Trim() == "") { dn.Add("PurchasePrice", "0"); } else { dn.Add("PurchasePrice", dt.Rows[i]["PurchasePrice"].ToString().Trim()); } if (dt.Rows[i]["WholesalePrice"].ToString().Trim() == "") { dn.Add("WholesalePrice", "0"); } else { dn.Add("WholesalePrice", dt.Rows[i]["WholesalePrice"].ToString().Trim()); } if (dt.Rows[i]["SpecialPrice"].ToString().Trim() == "") { dn.Add("SpecialPrice", "0"); } else { dn.Add("SpecialPrice", dt.Rows[i]["SpecialPrice"].ToString().Trim()); } //if (dt.Rows[i]["RetailPrice"].ToString().Trim() == "") //{ // dn.Add("RetailPrice", "0"); //} //else //{ // dn.Add("RetailPrice", dt.Rows[i]["RetailPrice"].ToString().Trim()); //} //if (dt.Rows[i]["TaxRate"].ToString().Trim() == "") //{ // dn.Add("TaxRate", "0"); //} //else //{ // dn.Add("TaxRate", dt.Rows[i]["TaxRate"].ToString().Trim()); //} if (dt.Rows[i]["DiscountRate"].ToString().Trim() == "") { dn.Add("DiscountRate", "0"); } else { dn.Add("DiscountRate", dt.Rows[i]["DiscountRate"].ToString().Trim()); } dn.Add("Barcode", dt.Rows[i]["Barcode"].ToString().Trim()); dn.Add("goods_no", dt.Rows[i]["No"].ToString().Trim()); dn.Add("english_name", dt.Rows[i]["NameP"].ToString().Trim()); dn.Add("ProductTypeNo", dt.Rows[i]["ProductTypeNo"].ToString().Trim()); dn.Add("sub_title", dt.Rows[i]["Name"].ToString().Trim()); model.fields = dn; } model.channel_id = 2; model.category_id = id; model.title = dt.Rows[i]["Name"].ToString(); model.zhaiyao = dt.Rows[i]["Remark"].ToString().Trim(); model.add_time = DateTime.Now; model.is_sys = 1; //管理员发布 model.user_name = "super"; //获得当前登录" + Resources.lang.username+ " // Common.Log.LogMsg("2", "super"); model.fields["sell_price"] = GetPrice(model.fields); List <Model.user_group_price> priceList = new List <Model.user_group_price>(); decimal _price = Convert.ToDecimal(model.fields["sell_price"]); priceList.Add(new Model.user_group_price { group_id = 1, price = _price }); priceList.Add(new Model.user_group_price { group_id = 2, price = _price }); model.group_price = priceList; if (type == 1) { if (!bll.Update(model)) { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"更新失败\","); sb.Append("\"reason\":\"请检查数据格式\""); sb.Append("},"); continue; } type = 0; } else { if (bll.Add(model) == 0) { sb.Append("{"); sb.Append("\"id\":\"" + i + "\","); sb.Append("\"code\":\"" + dt.Rows[i]["Barcode"].ToString().Trim() + "\","); sb.Append("\"name\":\"" + dt.Rows[i]["Name"].ToString().Trim() + "\","); sb.Append("\"result\":\"新增失败\","); sb.Append("\"reason\":\"请检查数据格式\""); sb.Append("},"); continue; } } } string data = sb.ToString(); if (data.Length > 0) { data = data.Substring(0, data.Length - 1); msg = "{\"status\": 1, \"msg\": \"导入成功!\",\"data\":[" + data + "]}"; } else { msg = "{\"status\": 1, \"msg\": \"部分数据导入失败!\",\"data\":[" + data + "]}"; } // Common.Log.LogMsg(msg, "admin"); ////删除已存在的旧文件 //if (!string.IsNullOrEmpty(_delfile)) //{ // Utils.DeleteUpFile(_delfile); //} //返回成功信息 context.Response.Write(msg); context.Response.End(); }
protected void Button1_Click(object sender, EventArgs e) { Button1.Attributes.Add("onclick", "this.value='正在提交中,请稍等……';this.disabled=true;" + this.GetPostBackEventReference(Button1) + ";"); string _title = title.Text.ToString(); string _number = number.Text.ToString(); int _dp_priority = Convert.ToInt32(dp_priority.SelectedValue); string _txtImgUrl = "", _img_url = ""; HttpPostedFile _upfile = FileUpload1.PostedFile; if (FileUpload1.HasFile == true) { UpLoad upFiles = new UpLoad(); _txtImgUrl = upFiles.fileSaveAs(_upfile, false, false); _img_url = _txtImgUrl.Substring(2); string userAgent = Request.UserAgent; if (userAgent.ToLower().Contains("micromessenger")) { _img_url += ".jpg"; } } string _name = name.Text.ToString(); string _tel = tel.Text.ToString(); string _address = address.Text.ToString(); string _details = details.Text.ToString(); string _username = Session["user_name"].ToString(); string group_id = Session["group_id"].ToString(); int _state = 0; string _add_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); string _type = type.SelectedItem.Value; string _OADeptID = null; string tbAssinger = null; string _assets = null; string _ddpAddress = dp_dress.SelectedValue; string _floor = getDDPAddress(); if (String.IsNullOrEmpty(_title) || String.IsNullOrEmpty(_name) || String.IsNullOrEmpty(_tel) || String.IsNullOrEmpty(_address) || String.IsNullOrEmpty(_details) || _type == "0" || String.IsNullOrEmpty(_ddpAddress)) { //JscriptMsg("haha", "content.aspx", "Success");$.dialog.alert('标题不能为空!'); //Response.Write("<script>$.dialog.alert('提交失败,请填写完整!');</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>SetUIStyle();</script>"); } else { //判断选哪个类别 string ddpItem = ddp_item.Items.Count.ToString(); string ddpItemChild = ddp_item_child.Items.Count.ToString(); if (ddpItem != "1" && ddp_item.SelectedValue != "0") { _type = ddp_item.SelectedItem.Value; if (ddpItemChild != "1" && ddp_item_child.SelectedValue != "0") { _type = ddp_item_child.SelectedItem.Value; } } //OA用户登录的情况 if (_username == group_id) { _OADeptID = getOADeptID(_username); } else { _OADeptID = group_id; } group_id = getGroupID(_type); //判断是否有指定人 if (!String.IsNullOrEmpty(TbAssinger.Text.ToString().Trim())) { tbAssinger = TbAssinger.Text.ToString().Trim(); } //判断固定资产号是否为空 if (!String.IsNullOrEmpty(assets.Text.ToString().Trim())) { _assets = assets.Text.ToString().Trim(); } ResultDataSet Rs2 = new ResultDataSet(); database_inte db2 = new database_inte(); string sql2 = "insert into dt_order (title,number,img_url,name,telephone,address,details,username,priority,state,add_time,type,group_id,AppointUser,deptID,fixedAssets,floor,flevel) values ('" + _title + "','" + _number + "','" + _img_url + "','" + _name + "','" + _tel + "','" + _address + "','" + _details + "','" + _username + "','" + _dp_priority + "','" + _state + "','" + _add_time + "','" + _type + "','" + group_id + "','" + tbAssinger + "','" + _OADeptID + "','" + _assets + "','" + _floor + "','" + _ddpAddress + "') SELECT @@IDENTITY as ID"; if (db2.DB2Obj.GetRs(sql2, out Rs2)) { title.Text = ""; string _OrderId = ""; if (Rs2.RowCount > 0) { _OrderId = Rs2[0, "ID"].ToString(); } string _SmsUrl = ConfigurationManager.AppSettings["SmsUrl"].ToString(); RequestHelper.SendGet(string.Format("http://{0}/Handler/TestHandler.ashx?action=ProblemInfo&OrderId={1}", _SmsUrl, _OrderId)); Response.Write("<script>alert('恭喜您,提交成功啦!维保人员正在路上,请耐心等待!');window.location.href ='content.aspx'</script>"); //ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>SetUIStyle2();</script>"); } else { //Response.Write("<script>alert('提交失败,请稍后重试!');window.location.href ='content.aspx'</script>"); ClientScript.RegisterStartupScript(ClientScript.GetType(), "myscript", "<script>SetUIStyle3();</script>"); } } }
private void UpLoadFile(HttpContext context) { Model.siteconfig siteConfig = new BLL.siteconfig().loadConfig(); string _delfile = DTRequest.GetString("DelFilePath"); string guid = DTRequest.GetString("guid"); HttpPostedFile _upfile = context.Request.Files["Filedata"]; bool _iswater = false; //默认不打水印 bool _isthumbnail = false; //默认不生成缩略图 if (DTRequest.GetQueryString("IsWater") == "1") { _iswater = true; } if (DTRequest.GetQueryString("IsThumbnail") == "1") { _isthumbnail = true; } if (_upfile == null) { context.Response.Write("{\"status\": 0, \"msg\": \"请选择要上传文件!\"}"); return; } UpLoad upFiles = new UpLoad(); string msg = string.Empty; if (context.Request.Form.AllKeys.Any(m => m == "chunk")) { //取得chunk和chunks int chunk = Convert.ToInt32(context.Request.Form["chunk"]); //当前分片在上传分片中的顺序(从0开始) int chunks = Convert.ToInt32(context.Request.Form["chunks"]); //总分片数 //根据GUID创建用该GUID命名的临时文件夹 string folder = context.Server.MapPath("~/Temp/" + context.Request["guid"] + "/"); string path = folder + chunk; //建立临时传输文件夹 if (!Directory.Exists(Path.GetDirectoryName(folder))) { Directory.CreateDirectory(folder); } FileStream addFile = new FileStream(path, FileMode.Append, FileAccess.Write); BinaryWriter AddWriter = new BinaryWriter(addFile); //获得上传的分片数据流 HttpPostedFile file = context.Request.Files[0]; Stream stream = file.InputStream; BinaryReader TempReader = new BinaryReader(stream); //将上传的分片追加到临时文件末尾 AddWriter.Write(TempReader.ReadBytes((int)stream.Length)); //关闭BinaryReader文件阅读器 TempReader.Close(); stream.Close(); AddWriter.Close(); addFile.Close(); TempReader.Dispose(); stream.Dispose(); AddWriter.Dispose(); addFile.Dispose(); msg = ("{\"chunked\" : true, \"hasError\" : false, \"f_ext\" : \"" + Path.GetExtension(file.FileName) + "\"}"); } else { msg = upFiles.fileSaveAs(_upfile, _isthumbnail, _iswater); } //删除已存在的旧文件,旧文件不为空且应是上传文件,防止跨目录删除 if (!string.IsNullOrEmpty(_delfile) && _delfile.IndexOf("../") == -1 && _delfile.ToLower().StartsWith(siteConfig.webpath.ToLower() + siteConfig.filepath.ToLower())) { Utils.DeleteUpFile(_delfile); } //返回成功信息 context.Response.Write(msg); context.Response.End(); }