/// <summary> /// 批量生成静态网页 /// </summary> /// <param name="url"></param> /// <param name="city"></param> /// <returns></returns> private string getHtmls(string url, string city) { if (String.IsNullOrEmpty(url)) { return(HtmlGenerate.GetHtmls(city, _queryString)); } else { return(WebHelper.WSInvokeMethod(url + "WebService.asmx", "MyQuery.Web", "GetHtmls", new object[] { city }).ToString()); } }
protected void btnSubmit_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(Content.Text) || Content.Text.Length < 10) { Alert("内容不能为空并且必须10个字以上!"); return; } XmlDocument doc = null; if (txtXml.Text.Length > 0) { string msg = null; doc = new XmlDocument(); try { doc.LoadXml(txtXml.Text); if (!XmlHelper.HasChildNode(doc.DocumentElement, "myquery") || !XmlHelper.HasChildNode(doc.DocumentElement, "myquery/sql")) { msg = "XML配置文件不符合系统规范"; } } catch (Exception ex) { msg = "xml语法错误:" + ex.Message; } if (!String.IsNullOrEmpty(msg)) { Alert(msg); return; } } bool isOk = false; MySqlParameters mySql = new MySqlParameters("HtmlTemplate"); if (String.IsNullOrEmpty(name)) { mySql.EditSqlMode = SqlMode.Insert; } else { mySql.EditSqlMode = SqlMode.Update; mySql.Add("whereHtmlUrl", name, "HtmlUrl={0}"); } string htmlUrl = HtmlUrl.Text; if (!htmlUrl.EndsWith(DepId.SelectedValue)) { htmlUrl += DepId.SelectedValue; } mySql.Add("HtmlUrl", htmlUrl); string aspxUrl = AspxUrl.Text; if (String.IsNullOrEmpty(aspxUrl)) { aspxUrl = HtmlGenerate.GetAspxUrl(htmlUrl); } mySql.Add("AspxUrl", aspxUrl); mySql.Add("Title", txtTitle.Text); mySql.Add("depid", DepId.SelectedValue); mySql.Add("optime", DateTime.Now); mySql.Add("userid", CurrentUser.Id); DataFrom data = new DataFrom(); try { data.SqlExecute(mySql); TxtHelper.WriteToFile(WebHelper.GetMyXmlPath() + "\\tpl\\" + name + Constants.HTML_SUFFIX, Content.Text, true); if (doc != null) { doc.Save(WebHelper.GetMyXmlPath() + "\\query\\" + name + Constants.XML_SUFFIX); } isOk = true; } catch (Exception ex) { Logger.Error(SqlHelper.GetSql(mySql, data.Dbtype), ex); RedirectError("提交失败,请稍候再试。原因:" + ex.Message); return; } if (isOk) { Redirect("Tmp/MyQuery.aspx?" + Constants.MYQUERY_NAME + "=listHtmlTemplate&sy=1"); } }
protected void btnUp_Click(object sender, EventArgs e) { if (fileHtml.Value.Length > 0) { int p = fileHtml.Value.IndexOf("\\web\\", StringComparison.CurrentCultureIgnoreCase); string fileName = Path.GetFileName(fileHtml.PostedFile.FileName); if (p == -1) { if (fileName.EndsWith(Constants.HTML_SUFFIX, StringComparison.CurrentCultureIgnoreCase)) { //上传htm模板 string rootPath = WebHelper.GetMyXmlPath() + "\\tpl\\"; try { fileHtml.PostedFile.SaveAs(rootPath + fileName); DataFrom data = new DataFrom(); MySqlParameters mySql = HtmlGenerate.GetHtmlTemplate(data, fileName, CurrentUser.Id); if (mySql != null) { data.SqlExecute(mySql); } name = fileName.ToLower().Replace(Constants.HTML_SUFFIX, ""); } catch (Exception ex) { Logger.Error("上传HTML模板错误", ex); RedirectError("上传HTML模板失败,请稍后重试。原因:" + ex.Message); return; } } else if (fileName.EndsWith(Constants.XML_SUFFIX, StringComparison.CurrentCultureIgnoreCase)) { string rootPath = WebHelper.GetMyXmlPath() + "\\query\\"; try { fileHtml.PostedFile.SaveAs(rootPath + fileName); } catch (Exception ex) { Logger.Error("上传XML配置错误", ex); RedirectError("上传XML配置失败,请稍后重试。原因:" + ex.Message); return; } } else { Alert("请选择HTML模板"); return; } } else { //上传web 目录文件 try { string rootPath = WebHelper.GetRootServerPath() + fileHtml.Value.Substring(p + 5, fileHtml.Value.LastIndexOf("\\") - p - 4); fileHtml.PostedFile.SaveAs(rootPath + fileName); } catch (Exception ex) { Logger.Error("上传覆盖错误", ex); RedirectError("上传覆盖失败,请稍后重试。原因:" + ex.Message); return; } } } else { Alert("请选择HTML模板"); } if (fileXml.Value.Length > 0 && fileXml.PostedFile.FileName.EndsWith(Constants.XML_SUFFIX, StringComparison.CurrentCultureIgnoreCase) && !String.IsNullOrEmpty(name)) { string rootPath = WebHelper.GetMyXmlPath() + "\\query\\"; try { fileXml.PostedFile.SaveAs(rootPath + name + Constants.XML_SUFFIX); } catch (Exception ex) { Logger.Error("上传XML配置错误", ex); RedirectError("上传XML配置失败,请稍后重试。原因:" + ex.Message); return; } } if (!String.IsNullOrEmpty(name)) { Redirect("Tmp/EditHtml.aspx?" + Constants.MYQUERY_NAME + "=" + name + "&sy=1"); } }
/// <summary> /// 返回运行的脚本则执行之 空或空字符串则忽略 /// 注意当case多于10个时建议再仿照此类另建一个实现类,配置中配成新实现的类名即可 /// </summary> /// <returns></returns> public string Deal() { string result = null; Dao dao = new Dao(); switch (Name.ToLower()) { case "listuser": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if (!"admin".Equals(Id) && "0".Equals(dao.GetScalar("select count(*) from loginfo where userid='" + Id + "'"))) { if (dao.SqlExecute("delete from s_user where id='" + Id + "';delete from S_UserTransfer where userid='" + Id + "'") > 0) { result = "alert('选择记录删除成功!');"; } else { result = "alert('选择记录删除失败,请稍后重试');"; } } else { if (dao.SqlExecute("update s_user set Iflag='0' where id='" + Id + "'") > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } } break; case "listdep": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if ("0".Equals(dao.GetScalar("select count(*) from s_user where depid='" + Id + "'"))) { if (dao.SqlExecute("delete from s_dep where id='" + Id + "'") > 0) { result = "alert('选择记录删除成功!');"; } else { result = "alert('选择记录删除失败,请稍后重试');"; } } else { if (dao.SqlExecute("update s_dep set Iflag=0 where id='" + Id + "'") > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } } break; case "listfun": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if ("0".Equals(dao.GetScalar("select count(*) from s_rolefun where funid=" + Id))) { if (dao.SqlExecute("delete from s_fun where id=" + Id) > 0) { result = "alert('选择记录删除成功!');"; } else { result = "alert('选择记录删除失败,请稍后重试');"; } } else { if (dao.SqlExecute("update s_fun set Iflag=0 where id=" + Id) > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } } break; case "listrole": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if ("0".Equals(dao.GetScalar("select count(*) from s_rolefun where roleid=" + Id))) { if (dao.SqlExecute("delete from s_role where id=" + Id) > 0) { result = "alert('选择记录删除成功!');"; } else { result = "alert('选择记录删除失败,请稍后重试');"; } } else { if (dao.SqlExecute("update s_role set Iflag=0 where id=" + Id) > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } } break; case "listcodelib": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if ("0".Equals(dao.GetScalar("select count(*) from f_code where id='" + Id + "'"))) { if (dao.SqlExecute("delete from f_code where id='" + Id + "';delete from f_codelib where id='" + Id + "'") > 0) { result = "alert('选择记录删除成功!');"; } else { result = "alert('选择记录删除失败,请稍后重试');"; } } else { if (dao.SqlExecute("update f_codelib set iflag=1 where id='" + Id + "'") > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } } break; case "listcode": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if (dao.SqlExecute("update f_code set iflag=0 where code='" + Id + "' and id='" + QueryString["id"] + "'") > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } break; case "listinfo": if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if ("0".Equals(dao.GetScalar("select count(*) from infonews where fid=" + Id))) { if (dao.SqlExecute("delete from f_info where id=" + Id) > 0) { result = "alert('选择记录删除成功!');"; } else { result = "alert('选择记录删除失败,请稍后重试');"; } } else { if (dao.SqlExecute("update f_info set Iflag=0 where id=" + Id) > 0) { result = "alert('选择记录停用成功!');"; } else { result = "alert('选择记录停用失败,请稍后重试');"; } } } break; case "listhtmltemplate": if ("btnhtml".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { string url = WebHelper.GetAppConfig("GenerateStaticHtml_Url"); if (!String.IsNullOrEmpty(url)) { if (!url.EndsWith("/")) { url += "/"; } } if (MyUser.IsAdmin(_User)) { //循环生成所有城市的 DataTable dt = dao.GetDataTable("select distinct depid from HtmlTemplate"); if (dt == null || dt.Rows.Count == 0) { result = "alert('没有页面需要生成')"; } else { result = ""; string msg = ""; foreach (DataRow dr in dt.Rows) { msg = getHtmls(url, dr[0].ToString()); result += dr[0].ToString() + "、"; } result = "alert('" + result + WebHelper.GetSafeScript(msg) + "')"; } } else { result = "alert('" + WebHelper.GetSafeScript(getHtmls(url, _User.DepID)) + "');"; } } else if (MyUser.IsAdmin(_User)) { if ("btnfind".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { int amount = 0; string rootPath = WebHelper.GetMyXmlPath() + "\\tpl"; if (Directory.Exists(rootPath)) { //获得其下所有.aspx页面 DirectoryInfo dir = new DirectoryInfo(rootPath); foreach (FileInfo f in dir.GetFiles("*" + Constants.HTML_SUFFIX)) { MySqlParameters mySql = HtmlGenerate.GetHtmlTemplate(dao, f.Name, _User.Id); if (mySql != null) { amount += dao.SqlExecute(mySql, true); } } } result = "alert('发现并成功增加" + amount + "个!');"; } else if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { string filename = WebHelper.GetMyXmlPath() + "\\tpl\\" + Id + Constants.HTML_SUFFIX; File.Delete(filename); File.Delete(filename.Replace("\\tpl\\", "\\query\\").Replace(Constants.HTML_SUFFIX, Constants.XML_SUFFIX)); if (dao.SqlExecute("delete from HtmlTemplate where HtmlUrl='" + Id + "'") > 0) { result = "alert('选择HTML模板删除成功!');"; } else { result = "alert('选择HTML模板删除失败,请稍后重试');"; } } } else { result = "alert('您无权执行此操作!');"; } break; case "listinfonews": result = ""; string ids = SqlHelper.GetSqlInWhere(Id); if ("html".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { if (dao.SqlExecute("update infonews set iflag=1 where id " + ids) > 0) { result += "选择记录审核成功!"; } else { result += "选择记录审核失败"; } } else { //非生成则先作废 if (dao.SqlExecute("update infonews set iflag=4 where id " + ids) > 0) { if ("cencel".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { result = "选择记录作废成功!"; } } else if ("cencel".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { result = "选择记录作废失败!"; } } //生成 string url1 = WebHelper.GetAppConfig("GenerateStaticHtml_Url"); if (String.IsNullOrEmpty(url1)) { result += HtmlGenerate.GetHtmls(QueryString["fid"], null, "id " + ids, _User); } else { if (!url1.EndsWith("/")) { url1 += "/"; } result += WebHelper.WSInvokeMethod(url1 + "WebService.asmx", "WWW", "GetHtml", new object[] { QueryString["fid"], null, "id " + ids, _User.Id }).ToString(); } if ("delete".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { List <String> sqls = new List <string>(); sqls.Add("delete from InfoAdds where infoid " + ids); sqls.Add("delete from InfoBrowsers where infoid " + ids); sqls.Add("delete from InfoDeals where infoid " + ids); sqls.Add("delete from InfoKeys where infoid " + ids); sqls.Add("update wf_instance set instancestatus=4,notes='信息删除' where processid in (select process from InfoNews where process is not null and id " + ids + ")"); sqls.Add("update wf_process set processstatuss=4,notes='信息删除' where processid in (select process from InfoNews where process is not null and id " + ids + ")"); sqls.Add("delete from infonews where id " + ids); if (dao.SqlExecute(sqls)) { result += "选择记录删除成功!"; } else { result += "选择记录删除失败,请稍后重试"; } } if (result.Length > 0) { result = "alert('" + result + "');"; } break; case "querylogimport": if ("deldata".Equals(Button.Name, StringComparison.CurrentCultureIgnoreCase)) { string[] tables = DataHelper.GetStrings(Id); if (tables == null || tables.Length <= 1) { result = "alert('配置错误,请稍后重试');"; } else { List <String> sqls = new List <string>(); for (int i = 1; i < tables.Length; i++) { sqls.Add("delete from " + tables[i] + " where ImportId=" + tables[0]); } sqls.Add("update LogImport set upcount=0 where id=" + tables[0]); if (dao.SqlExecute(sqls)) { result = "alert('删除本次导入数据成功!');"; } else { result = "alert('删除本次导入数据失败,请稍后重试');"; } } } break; } return(result); }