CNCEC_SUBQHSE_WUHUAN/SGGL/FineUIPro.Web/common/PageBase.cs

1071 lines
95 KiB
C#
Raw Normal View History

2021-04-30 10:28:37 +08:00
using BLL;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Web;
using System.Web.UI;
using AspNet = System.Web.UI.WebControls;
namespace FineUIPro.Web
{
public class PageBase : System.Web.UI.Page
{
/// <summary>
/// 当前登录人信息。
/// </summary>
public Model.Sys_User CurrUser
{
get
{
if (Session["CurrUser"] == null)
{
string account = string.Empty;
string password = string.Empty;
if (Request.Cookies["u"] != null)
{
account = HttpUtility.UrlDecode(Request.Cookies["u"].Value);
}
if (Request.Cookies["p"] != null)
{
password = Request.Cookies["p"].Value;
}
Session["CurrUser"] = BLL.Funs.DB.Sys_User.FirstOrDefault(x => x.Account == account && x.Password == Funs.EncryptionPassword(password));
}
return (Model.Sys_User)Session["CurrUser"];
}
}
#region OnInit
protected override void OnInit(EventArgs e)
{
var pm = PageManager.Instance;
if (pm != null)
{
HttpCookie themeCookie = Request.Cookies["Theme"];
if (themeCookie != null)
{
string themeValue = themeCookie.Value;
if (themeValue != "Cupertino")
{
themeValue = "Cupertino";
Response.Cookies.Remove("Theme");
HttpCookie cookie = new HttpCookie("Theme", themeValue)
{
Expires = DateTime.Now.AddYears(1)
};
Response.Cookies.Add(cookie);
}
// 是否为内置主题
if (IsSystemTheme(themeValue))
{
pm.CustomTheme = String.Empty;
pm.Theme = (Theme)Enum.Parse(typeof(Theme), themeValue, true);
}
else
{
pm.CustomTheme = themeValue;
}
}
HttpCookie langCookie = Request.Cookies["Language"];
if (langCookie != null)
{
string langValue = langCookie.Value;
try
{
// 是否为内置语言
pm.Language = (Language)Enum.Parse(typeof(Language), langValue, true);
}
catch (Exception)
{
pm.CustomLanguage = langValue;
}
}
// 1. 仅显示基础版示例, 2. 基础版
// 上述两种情况都要禁用EnableAnimation、DisplayMode、MobileAdaption
bool showOnlyBase = false;
HttpCookie menuShowOnlyBase = Request.Cookies["ShowOnlyBase"];
if (menuShowOnlyBase != null)
{
showOnlyBase = Convert.ToBoolean(menuShowOnlyBase.Value);
}
if (showOnlyBase || Constants.IS_BASE)
{
pm.EnableAnimation = false;
pm.DisplayMode = DisplayMode.Normal;
pm.MobileAdaption = false;
}
else
{
HttpCookie modeCookie = Request.Cookies["DisplayMode"];
if (modeCookie != null)
{
string modeValue = modeCookie.Value;
try
{
pm.DisplayMode = (DisplayMode)Enum.Parse(typeof(DisplayMode), modeValue, true);
}
catch (Exception)
{
pm.DisplayMode = DisplayMode.Normal;
}
}
}
HttpCookie loadingCookie = Request.Cookies["Loading"];
if (loadingCookie != null)
{
int loadingNumber = Convert.ToInt32(loadingCookie.Value);
pm.LoadingImageNumber = loadingNumber;
}
// SaveFStateToServer是页面上自定义的一个属性
if (SaveFStateToServer)
{
//// FState保存到服务器文件
//pm.EnableFStatePersistence = true;
//pm.LoadFStateFromPersistenceMedium = LoadFStateFromPersistenceMedium;
//pm.SaveFStateToPersistenceMedium = SaveFStateToPersistenceMedium;
//FState保存到服务器缓存
pm.EnableFStatePersistence = true;
pm.LoadFStateFromPersistenceMedium = LoadFStateFromPersistenceMedium_Cache;
pm.SaveFStateToPersistenceMedium = SaveFStateToPersistenceMedium_Cache;
}
// 为所有页面添加公共CSS<link rel="stylesheet" type="text/css" href="res/css/common.css" />
System.Web.UI.HtmlControls.HtmlGenericControl linkCtrl = new System.Web.UI.HtmlControls.HtmlGenericControl("link");
linkCtrl.Attributes["rel"] = "stylesheet";
linkCtrl.Attributes["type"] = "text/css";
linkCtrl.Attributes["href"] = ResolveClientUrl("~/res/css/common.css?v" + GlobalConfig.ProductVersion);
Header.Controls.AddAt(GetHeadStyleCSSIndex(), linkCtrl);
// 为所有页面添加公共JS<script type="text/css" href="res/js/common.js"></script>
var commonJSPath = String.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", ResolveClientUrl("~/res/js/common.js?v" + GlobalConfig.ProductVersion));
PageContext.RegisterStartupScript("FineUIPro_Examples_common_js", commonJSPath, false);
//var jqueryMigrateJSPath = String.Format("<script type=\"text/javascript\" src=\"{0}\"></script>", ResolveClientUrl("~/res/js/jquery-migrate-3.0.1.js?v" + GlobalConfig.ProductVersion));
//PageContext.RegisterPreStartupScript("FineUIPro_Examples_jquery-migrate_js", jqueryMigrateJSPath, false);
// 禁用表单的自动完成功能
// v5.4.0 - 无需手工设置每个表单字段的autoComplete默认为false
//Form.Attributes["autocomplete"] = "off";
}
this.Load += new EventHandler(this.PageBase_Load);
this.Unload += new EventHandler(this.PageBase_UNLoad);
base.OnInit(e);
}
/// <summary>
/// 页面登录成功
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void PageBase_Load(object sender, EventArgs e)
{
//这是后置式的权限管理策略.
//页面装载完成以后才检查是否有权限打开此页....
//anyway,its ok.
this.Title = BLL.Funs.SystemName;
//if (CurrUser == null)
//{
// if (this.Page.Request.AppRelativeCurrentExecutionFilePath != "~/Login.aspx")
// Response.Redirect("~/Login.aspx");
//}
}
/// <summary>
/// UNLOAD事件发生在页面装载顺序的最后。
/// 在这里处理的是DBLIST数据库连接字典。
/// </summary>
/// <param name="sender">S</param>
/// <param name="e">E</param>
protected void PageBase_UNLoad(object sender, EventArgs e)
{
if (BLL.Funs.DBList.ContainsKey(System.Threading.Thread.CurrentThread.ManagedThreadId))
{
BLL.Funs.DBList.Remove(System.Threading.Thread.CurrentThread.ManagedThreadId);
}
}
private bool IsSystemTheme(string themeName)
{
themeName = themeName.ToLower();
string[] themes = Enum.GetNames(typeof(Theme));
foreach (string theme in themes)
{
if (theme.ToLower() == themeName)
{
return true;
}
}
return false;
}
private int GetHeadStyleCSSIndex()
{
var theIndex = 0;
for (var i = 0; i < Header.Controls.Count; i++)
{
var ctrl = Header.Controls[i];
if (ctrl is LiteralControl)
{
if ((ctrl as LiteralControl).Text.Trim().ToLower().StartsWith("<style"))
{
theIndex = i;
break;
}
}
else if (ctrl is System.Web.UI.HtmlControls.HtmlLink)
{
var theCtrl = ctrl as System.Web.UI.HtmlControls.HtmlLink;
if (theCtrl.TagName == "link")
{
var typeAttr = theCtrl.Attributes["type"];
var relAttr = theCtrl.Attributes["rel"];
if ((typeAttr != null && typeAttr.ToLower() == "text/css")
|| (relAttr != null && relAttr.ToLower() == "stylesheet"))
{
theIndex = i;
break;
}
}
}
}
return theIndex;
}
/// <summary>
/// 是否将FState保存到服务器
/// </summary>
protected virtual bool SaveFStateToServer
{
get
{
return false;
}
}
#endregion
#region FState保存到服务端文件
private static readonly string FSTATE_FILE_KEY = "__FSTATE_KEY";
private static readonly string FSTATE_FILE_BASE_PATH = "~/App_Data/FState/";
private JObject LoadFStateFromPersistenceMedium()
{
string filePath = GetFStateFilePath();
string fileContent;
using (StreamReader sr = new StreamReader(filePath, System.Text.Encoding.UTF8))
{
fileContent = sr.ReadToEnd();
}
return JObject.Parse(fileContent);
}
private void SaveFStateToPersistenceMedium(JObject fstate)
{
string filePath = GenerateFStateFilePath();
using (StreamWriter streamW = new StreamWriter(filePath, false, System.Text.Encoding.UTF8))
{
streamW.Write(fstate.ToString(Formatting.None));
}
}
private string GenerateFStateFilePath()
{
string filePath = String.Empty;
string fileName = String.Empty;
string cacheKey = Page.Request.Form[FSTATE_FILE_KEY];
if (String.IsNullOrEmpty(cacheKey))
{
DateTime now = DateTime.Now;
string folderName = now.ToString("yyyyMMddHH");
fileName = String.Format("{0}_{1}",
HttpContext.Current.Session.SessionID,
now.Ticks.ToString());
string folderPath = Page.Server.MapPath(Path.Combine(FSTATE_FILE_BASE_PATH, folderName));
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
filePath = folderPath + "/" + fileName + ".config";
}
else
{
fileName = cacheKey;
filePath = GetFStateFilePath();
}
if (!PageManager.Instance.IsFineUIAjaxPostBack)
{
PageContext.RegisterStartupScript(String.Format("F.setHidden('{0}','{1}');", FSTATE_FILE_KEY, fileName));
}
return filePath;
}
private string GetFStateFilePath()
{
string fileName = Request.Form[FSTATE_FILE_KEY];
string[] fileNames = fileName.Split('_');
string folderName = new DateTime(Convert.ToInt64(fileNames[1])).ToString("yyyyMMddHH");
return Page.Server.MapPath(Path.Combine(FSTATE_FILE_BASE_PATH, folderName)) + "/" + fileName + ".config";
}
#endregion
#region FState保存到服务端缓存
private static readonly string FSTATE_CACHE_KEY = "__FSTATE_KEY";
private JObject LoadFStateFromPersistenceMedium_Cache()
{
string cacheKey = Page.Request.Form[FSTATE_CACHE_KEY];
return HttpRuntime.Cache[cacheKey] as JObject;
}
private void SaveFStateToPersistenceMedium_Cache(JObject fstate)
{
string cacheKey = Page.Request.Form[FSTATE_CACHE_KEY];
if (String.IsNullOrEmpty(cacheKey))
{
cacheKey = String.Format("{0}_{1}",
HttpContext.Current.Session.SessionID,
DateTime.Now.Ticks.ToString());
}
// 页面第一次加载或者回发时需要设置客户端隐藏字段AJAX回发时无需设置因为客户端已经存在了
if (!PageManager.Instance.IsFineUIAjaxPostBack)
{
PageContext.RegisterStartupScript(String.Format("F.setHidden('{0}','{1}');", FSTATE_CACHE_KEY, cacheKey));
}
// 指定时间后过期Session.Timeout
HttpRuntime.Cache.Insert(cacheKey, fstate, null,
DateTime.Now.AddMinutes(HttpContext.Current.Session.Timeout),
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Default, null);
}
#endregion
#region FRAME跳转到新地址
/// <summary>
/// 最外层FRAME跳转到新地址
/// </summary>
/// <param name="urlstr">URL</param>
public static void PageRefresh(string urlstr)
{
HttpContext.Current.Response.Write("<script>top.location.href='" + "/" + urlstr.TrimStart('/') + "';</script>");
HttpContext.Current.Response.End();
}
#endregion
#region IEnumerable<T>DataTable类型
/// <summary>
/// 将IEnumerable<T>类型的集合转换为DataTable类型
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="varlist"></param>
/// <returns></returns>
protected DataTable LINQToDataTable<T>(IEnumerable<T> varlist)
{ //定义要返回的DataTable对象
DataTable dtReturn = new DataTable();
// 保存列集合的属性信息数组
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;//安全性检查
//循环遍历集合,使用反射获取类型的属性信息
foreach (T rec in varlist)
{
//使用反射获取T类型的属性信息返回一个PropertyInfo类型的集合
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
//循环PropertyInfo数组
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;//得到属性的类型
//如果属性为泛型类型
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{ //获取泛型类型的参数
colType = colType.GetGenericArguments()[0];
}
//将类型的属性名称与属性类型作为DataTable的列数据
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
//新建一个用于添加到DataTable中的DataRow对象
DataRow dr = dtReturn.NewRow();
//循环遍历属性集合
foreach (PropertyInfo pi in oProps)
{ //为DataRow中的指定列赋值
dr[pi.Name] = pi.GetValue(rec, null) == null ?
DBNull.Value : pi.GetValue(rec, null);
}
//将具有结果值的DataRow添加到DataTable集合中
dtReturn.Rows.Add(dr);
}
return dtReturn;//返回DataTable对象
}
#endregion
#region
/// <summary>
/// 模拟数据库分页
/// </summary>
/// <typeparam name="T">IEnumerable类型</typeparam>
/// <param name="Grid1">Grid表格</param>
/// <param name="varlist">IEnumerable类型的集合</param>
/// <returns>数据表</returns>
protected DataTable GetPagedDataTable<T>(Grid Grid1, IEnumerable<T> varlist)
{
int pageIndex = Grid1.PageIndex;
int pageSize = Grid1.PageSize;
string sortField = Grid1.SortField;
string sortDirection = Grid1.SortDirection;
DataTable tb = this.LINQToDataTable(varlist);
DataView view = tb.DefaultView;
if (view.Count > 0)
{
view.Sort = String.Format("{0} {1}", sortField, sortDirection);
}
DataTable table = view.ToTable();
DataTable paged = table.Clone();
int rowbegin = pageIndex * pageSize;
int rowend = (pageIndex + 1) * pageSize;
if (rowend > table.Rows.Count)
{
rowend = table.Rows.Count;
}
for (int i = rowbegin; i < rowend; i++)
{
paged.ImportRow(table.Rows[i]);
}
return paged;
}
/// <summary>
/// 模拟数据库分页
/// </summary>
/// <param name="Grid1">Grid表格</param>
/// <param name="tb">数据表</param>
/// <returns>数据表</returns>
protected DataTable GetPagedDataTable(FineUIPro.Grid Grid1, DataTable tb)
{
int pageIndex = Grid1.PageIndex;
int pageSize = Grid1.PageSize;
string sortField = Grid1.SortField;
string sortDirection = Grid1.SortDirection;
//DataTable table2 = DataSourceUtil.GetDataTable2();
DataView view = tb.DefaultView;
// view.Sort = String.Format("{0} {1}", sortField, sortDirection);
if (!string.IsNullOrEmpty(sortField) && view.Count > 0)
{
view.Sort = String.Format("{0} {1}", sortField, sortDirection);
}
DataTable table = view.ToTable();
DataTable paged = table.Clone();
int rowbegin = pageIndex * pageSize;
int rowend = (pageIndex + 1) * pageSize;
if (rowend > table.Rows.Count)
{
rowend = table.Rows.Count;
}
for (int i = rowbegin; i < rowend; i++)
{
paged.ImportRow(table.Rows[i]);
}
return paged;
}
#endregion
#region
// 表格过滤
protected DataTable GetFilteredTable(JArray filteredData, DataTable source)
{
DataTable result = source.Clone();
foreach (DataRow row in source.Rows)
{
bool filtered = true;
foreach (JObject filteredObj in filteredData)
{
if (!CheckDataRow(row, filteredObj))
{
filtered = false;
break;
}
}
if (filtered)
{
result.Rows.Add(row.ItemArray);
}
}
return result;
}
private bool CheckDataRow(DataRow row, JObject filteredObj)
{
// 在 ASPX 中设置列的 ColumnID 属性,约定 ColumnID 和数据库的字段名称一样
string columnID = filteredObj.Value<string>("column");
object rowitemData = row[columnID];
bool multi = filteredObj.Value<bool>("multi");
if (multi)
{
string matcher = filteredObj.Value<string>("matcher");
JArray items = filteredObj.Value<JArray>("items");
bool valid = false;
if (matcher == "all")
{
valid = true;
}
foreach (JObject item in items)
{
string itemOperator = item.Value<string>("operator");
object itemValue = item.Value<object>("value");
if (FilterDataRowItem(rowitemData, itemOperator, itemValue, columnID))
{
if (matcher == "any")
{
valid = true;
break;
}
}
else
{
if (matcher == "all")
{
valid = false;
break;
}
}
}
return valid;
}
else
{
JObject item = filteredObj.Value<JObject>("item");
string itemOperator = item.Value<string>("operator");
object itemValue = item.Value<object>("value");
return FilterDataRowItem(rowitemData, itemOperator, itemValue, columnID);
}
}
public delegate bool FilterDataRowItemDelegate(object sourceObj, string fillteredOperator, object fillteredObj, string column);
public FilterDataRowItemDelegate FilterDataRowItem
{
get;
set;
}
#endregion
#region
protected readonly static List<string> VALID_FILE_TYPES = new List<string> { "jpg", "bmp", "gif", "jpeg", "png" };
protected static bool ValidateFileType(string fileName)
{
string fileType = String.Empty;
int lastDotIndex = fileName.LastIndexOf(".");
if (lastDotIndex >= 0)
{
fileType = fileName.Substring(lastDotIndex + 1).ToLower();
}
if (VALID_FILE_TYPES.Contains(fileType))
{
return true;
}
else
{
return false;
}
}
#endregion
#region
/// <summary>
/// 可执行文件类型
/// </summary>
protected readonly static List<string> VALID_FILE_ExecutableTYPES = new List<string> { "exe", "com", "bat" };
/// <summary>
/// 是否包含可执行文件类型
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
protected static bool ValidateFileTypes(string fileName)
{
string fileType = String.Empty;
int lastDotIndex = fileName.LastIndexOf(".");
if (lastDotIndex >= 0)
{
fileType = fileName.Substring(lastDotIndex + 1).ToLower();
}
if (VALID_FILE_ExecutableTYPES.Contains(fileType))
{
return true;
}
else
{
return false;
}
}
#endregion
#region
protected readonly static JArray SHENG_JSON = JArray.Parse("[\"北京\",\"天津\",\"上海\",\"重庆\",\"河北\",\"山西\",\"辽宁\",\"吉林\",\"黑龙江\",\"江苏\",\"浙江\",\"安徽\",\"福建\",\"江西\",\"山东\",\"河南\",\"湖北\",\"湖南\",\"广东\",\"海南\",\"四川\",\"贵州\",\"云南\",\"陕西\",\"甘肃\",\"青海\",\"内蒙古\",\"广西\",\"西藏\",\"宁夏\",\"新疆\",\"香港\",\"澳门\",\"台湾\"]");
protected readonly static JObject SHI_JSON = JObject.Parse("{\"北京\":[\"北京市\"],\"天津\":[\"天津市\"],\"上海\":[\"上海市\"],\"重庆\":[\"重庆市\"],\"河北\":[\"石家庄市\",\"唐山市\",\"秦皇岛市\",\"邯郸市\",\"邢台市\",\"保定市\",\"张家口市\",\"承德市\",\"沧州市\",\"廊坊市\",\"衡水市\"],\"山西\":[\"太原市\",\"大同市\",\"阳泉市\",\"长治市\",\"晋城市\",\"朔州市\",\"晋中市运城市忻州市\",\"临汾市\",\"吕梁市\"],\"辽宁\":[\"沈阳市\",\"大连市\",\"鞍山市\",\"抚顺市\",\"本溪市\",\"丹东市\",\"锦州市\",\"营口市\",\"阜新市\",\"辽阳市\",\"盘锦市\",\"铁岭市\",\"朝阳市\",\"葫芦岛市\"],\"吉林\":[\"长春市\",\"吉林市\",\"四平市\",\"辽源市\",\"通化市\",\"白山市\",\"松原市\",\"白城市\",\"延边朝鲜族自治州\"],\"黑龙江\":[\"哈尔滨市\",\"齐齐哈尔市\",\"鹤岗市\",\"双鸭山市\",\"鸡西市\",\"大庆市\",\"伊春市\",\"牡丹江市\",\"佳木斯市\",\"七台河市\",\"黑河市\",\"绥化市\",\"大兴安岭地区\"],\"江苏\":[\"南京市\",\"苏州市\",\"无锡市\",\"常州市\",\"镇江市\",\"南通市\",\"泰州市\",\"扬州市\",\"盐城市\",\"连云港市\",\"徐州市\",\"淮安市\",\"宿迁市\"],\"浙江\":[\"杭州市\",\"宁波市\",\"温州市\",\"嘉兴市\",\"湖州市\",\"绍兴市\",\"金华市\",\"衢州市\",\"舟山市\",\"台州市\",\"丽水市\"],\"安徽\":[\"合肥市\",\"芜湖市\",\"蚌埠市\",\"淮南市\",\"马鞍山市\",\"淮北市\",\"铜陵市\",\"安庆市\",\"黄山市\",\"滁州市\",\"阜阳市\",\"宿州市\",\"巢湖市\",\"六安市\",\"亳州市\",\"池州市\",\"宣城市\"],\"福建\":[\"福州市\",\"厦门市\",\"莆田市\",\"三明市\",\"泉州市\",\"漳州市\",\"南平市\",\"龙岩市\",\"宁德市\"],\"江西\":[\"南昌市\",\"景德镇市\",\"萍乡市\",\"九江市\",\"新余市\",\"鹰潭市\",\"赣州市\",\"吉安市\",\"宜春市\",\"抚州市\",\"上饶市\"],\"山东\":[\"济南市\",\"青岛市\",\"淄博市\",\"枣庄市\",\"东营市\",\"烟台市\",\"潍坊市\",\"济宁市\",\"泰安市\",\"威海市\",\"日照市\",\"莱芜市\",\"临沂市\",\"德州市\",\"聊城市\",\"滨州市\",\"菏泽市\"],\"河南\":[\"郑州市\",\"开封市\",\"洛阳市\",\"平顶山市\",\"安阳市\",\"鹤壁市\",\"新乡市\",\"焦作市\",\"濮阳市\",\"许昌市\",\"漯河市\",\"三门峡市\",\"南阳市\",\"商丘市\",\"信阳市\",\"周口市\",\"驻马店市\",\"济源市\"],\"湖北\":[\"武汉市\",\"黄石市\",\"十堰市\",\"荆州市\",\"宜昌市\",\"襄樊市\",\"鄂州市\",\"荆门市\",\"孝感市\",\"黄冈市\",\"咸宁市\",\"随州市\",\"恩施土家族苗族自治州\",\"仙桃市\",\"天门市\",\"潜江市\",\"神农架林区\"],\"湖南\":[\"长沙市\",\"株洲市\",\"湘潭市\",\"衡阳市\",\"邵阳市\",\"岳阳市\",\"常德市\",\"张家界市\",\"益阳市\",\"郴州市\",\"永州市\",\"怀化市\",\"娄底市\",\"湘西土家族苗族自治州\"],\"广东\":[\"广州市\",\"深圳市\",\"珠海市\",\"汕头市\",\"韶关市\",\"佛山市\",\"江门市\",\"湛江市\",\"茂名市\",\"肇庆市\",\"惠州市\",\"梅州市\",\"汕尾市\",\"河源市\",\"阳江市\",\"清远市\",\"东莞市\",\"中山市\",\"潮州市\",\"揭阳市\",\"云浮市\"],\"海南\":[\"海口市\",\"三亚市\",\"五指山市\",\"琼海市\",\"儋州市\",\"文昌市\",\"万宁市\",\"东方市\",\"澄迈县\",\"定安县\",\"屯昌县\",\"临高县\",\"白沙黎族自治县\",\"昌江黎族自治县\",\"乐东黎族自治县\",\"陵水黎族自治县\",\"保亭黎族苗族自治县\",\"琼中黎族苗族自治县\"],\"四川\":[\"成都市\",\"自贡市\",\"攀枝花市\",\"泸州市\",\"德阳市\",\"绵阳市\",\"广元市\",\"遂宁市\",\"内江市\",\"乐山市\",\"南充市\",\"眉山市\",\"宜宾市\",\"广安市\",\"达州市\",\"雅安市\",\"巴中市\",\"资阳市\",\"阿坝藏族羌族自治州\",\"甘孜藏族自治州\",\"凉山彝族自治州\"],\"贵州\":[\"<22><>
protected readonly static JObject XIAN_JSON = JObject.Parse("{\"北京市\":[\"东城区\",\"西城区\",\"崇文区\",\"宣武区\",\"朝阳区\",\"丰台区\",\"石景山区\",\"海淀区\",\"门头沟区\",\"房山区\",\"通州区\",\"顺义区\",\"昌平区\",\"大兴区\",\"怀柔区\",\"平谷区\",\"密云县\",\"延庆县\"],\"天津市\":[\"和平区\",\"河东区\",\"河西区\",\"南开区\",\"河北区\",\"红桥区\",\"塘沽区\",\"汉沽区\",\"大港区\",\"东丽区\",\"西青区\",\"北辰区\",\"津南区\",\"武清区\",\"宝坻区\",\"静海县\",\"宁河县\",\"蓟县\"],\"上海市\":[\"黄浦区\",\"卢湾区\",\"徐汇区\",\"长宁区\",\"静安区\",\"普陀区\",\"闸北区\",\"虹口区\",\"杨浦区\",\"宝山区\",\"闵行区\",\"嘉定区\",\"松江区\",\"金山区\",\"青浦区\",\"奉贤区\",\"浦东新区\",\"崇明县\"],\"重庆市\":[\"渝中区\",\"大渡口区\",\"江北区\",\"南岸区\",\"北碚区\",\"渝北区\",\"巴南区\",\"长寿区\",\"双桥区\",\"沙坪坝区\",\"万盛区\",\"万州区\",\"涪陵区\",\"黔江区\",\"永川区\",\"合川区\",\"江津区\",\"九龙坡区\",\"南川区\",\"綦江县\",\"潼南县\",\"荣昌县\",\"璧山县\",\"大足县\",\"铜梁县\",\"梁平县\",\"开县\",\"忠县\",\"城口县\",\"垫江县\",\"武隆县\",\"丰都县\",\"奉节县\",\"云阳县\",\"巫溪县\",\"巫山县\",\"石柱土家族自治县\",\"秀山土家族苗族自治县\",\"酉阳土家族苗族自治县\",\"彭水苗族土家族自治县\"],\"石家庄市\":[\"长安区\",\"桥东区\",\"桥西区\",\"新华区\",\"裕华区\",\"井陉矿区\",\"鹿泉市\",\"辛集市\",\"藁城市\",\"晋州市\",\"新乐市\",\"深泽县\",\"无极县\",\"赵县\",\"灵寿县\",\"高邑县\",\"元氏县\",\"赞皇县\",\"平山县\",\"井陉县\",\"栾城县\",\"正定县\",\"行唐县\"],\"唐山市\":[\"路北区\",\"路南区\",\"古冶区\",\"开平区\",\"丰南区\",\"丰润区\",\"遵化市\",\"迁安市\",\"迁西县\",\"滦南县\",\"玉田县\",\"唐海县\",\"乐亭县\",\"滦县\",\"汉沽管理区\"],\"秦皇岛市\":[\"海港区\",\"山海关区\",\"北戴河区\",\"昌黎县\",\"抚宁县\",\"卢龙县\",\"青龙满族自治县\"],\"邯郸市\":[\"邯山区\",\"丛台区\",\"复兴区\",\"峰峰矿区\",\"武安市\",\"邱县\",\"大名县\",\"魏县\",\"曲周县\",\"鸡泽县\",\"肥乡县\",\"广平县\",\"成安县\",\"临漳县\",\"磁县\",\"涉县\",\"永年县\",\"馆陶县\",\"邯郸县\"],\"邢台市\":[\"桥东区\",\"桥西区\",\"南宫市\",\"沙河市\",\"临城县\",\"内丘县\",\"柏乡县\",\"隆尧县\",\"任县\",\"南和县\",\"宁晋县\",\"巨鹿县\",\"新河县\",\"广宗县\",\"平乡县\",\"威县\",\"清河县\",\"临西县\",\"邢台县\"],\"保定市\":[\"新市区\",\"北市区\",\"南市区\",\"定州市\",\"涿州市\",\"安国市\",\"高碑店市\",\"易县\",\"徐水县\",\"涞源县\",\"顺平县\",\"唐县\",\"望都县\",\"涞水县\",\"高阳县\",\"安新县\",\"雄县\",\"容城县\",\"蠡县\",\"曲阳县\",\"阜平县\",\"博野县\",\"满城县\",\"清苑县\",\"定兴县\"],\"张家口市\":[\"桥东区\",\"桥西区\",\"宣化区\",\"下花园区\",\"张北县\",\"康保县\",\"沽源县\",\"尚义县\",\"蔚县\",\"阳原县\",\"怀安县\",\"万全县\",\"怀来县\",\"赤城县\",\"崇礼县\",\"宣化县\",\"涿鹿县\",\"塞北管理区\"],\"承德市\":[\"双桥区\",\"双滦区\",\"鹰手营子矿区\",\"兴隆县\",\"平泉县\",\"滦平县\",\"隆化县\",\"承德县\",\"丰宁满族自治县\",\"宽城满族自治县\",\"围场满族蒙古族自治县\"],\"沧州市\":[\"新华区\",\"运河区\",\"泊头市\",\"任丘市\",\"黄骅市\",\"河间市\",\"献县\",\"吴桥县\",\"沧县\",\"东光县\",\"肃宁县\",\"南皮县\",\"盐山县\",\"青县\",\"海兴县\",\"孟村回族自治县\"],\"廊坊市\":[\"安次区\",\"广阳区\",\"霸州市\",\"三河市\",\"香河县\",\"永清县\",\"固安县\",\"文安县\",\"大城县\",\"大厂回族自治县\"],\"衡水市\":[\"桃城区\",\"冀<>
#endregion
#region
/// <summary>
/// 选中了哪些行
/// </summary>
/// <param name="grid">表格对象</param>
/// <returns>选中行的描述信息</returns>
protected string HowManyRowsAreSelected(Grid grid)
{
StringBuilder sb = new StringBuilder();
int selectedCount = grid.SelectedRowIndexArray.Length;
if (selectedCount > 0)
{
sb.AppendFormat("<p><strong>共选中了 {0} 行:</strong></p>", selectedCount);
sb.Append("<table class=\"result\">");
sb.Append("<tr><th>序号</th>");
foreach (string datakey in grid.DataKeyNames)
{
sb.AppendFormat("<th>{0}</th>", datakey);
}
sb.Append("</tr>");
for (int i = 0; i < selectedCount; i++)
{
int rowIndex = grid.SelectedRowIndexArray[i];
sb.Append("<tr>");
int rownumber = rowIndex + 1;
if (grid.AllowPaging)
{
rownumber += grid.PageIndex * grid.PageSize;
}
sb.AppendFormat("<td>{0}</td>", rownumber);
// 如果是内存分页所有分页的数据都存在rowIndex 就是在全部数据中的顺序,而不是当前页的顺序
if (grid.AllowPaging && !grid.IsDatabasePaging)
{
rowIndex = grid.PageIndex * grid.PageSize + rowIndex;
}
object[] dataKeys = grid.DataKeys[rowIndex];
for (int j = 0; j < dataKeys.Length; j++)
{
sb.AppendFormat("<td>{0}</td>", dataKeys[j]);
}
sb.Append("</tr>");
}
sb.Append("</table>");
}
else
{
sb.Append("<strong>没有选中任何一行!</strong>");
}
return sb.ToString();
}
/// <summary>
/// 获取性别的字面值,在 ASPX 中调用
/// </summary>
/// <param name="gender"></param>
/// <returns></returns>
protected string GetGender(object gender)
{
string value = string.Empty;
if (gender != null)
{
int? gValue = BLL.Funs.GetNewInt(gender.ToString());
if (gValue.HasValue)
{
if (gValue == 1)
{
value = "男";
}
else
{
value = "女";
}
}
}
return value;
}
/// <summary>
/// 获取项目状态的字面值,在 ASPX 中调用
/// </summary>
/// <param name="gender"></param>
/// <returns></returns>
protected string GetProjectState(object state)
{
if (state != null)
{
if (state.ToString() == "3")
{
return "完工";
}
else if (state.ToString() == "2")
{
return "暂停";
}
else
{
return "施工";
}
}
else
{
return null;
}
}
#endregion
#region ViewState
//protected override object LoadPageStateFromPersistenceMedium()
//{
// string gzippedState = Request.Form[StringUtil.GZIPPED_VIEWSTATE_ID];
// return StringUtil.LoadGzippedViewState(gzippedState);
//}
//protected override void SavePageStateToPersistenceMedium(object viewState)
//{
// ClientScript.RegisterHiddenField(StringUtil.GZIPPED_VIEWSTATE_ID, StringUtil.GenerateGzippedViewState(viewState));
//}
#endregion
#region
/// <summary>
/// 获取回发的参数
/// </summary>
/// <returns></returns>
public string GetRequestEventArgument()
{
return Request.Form["__EVENTARGUMENT"];
}
/// <summary>
/// 显示通知对话框
/// </summary>
/// <param name="message"></param>
public void ShowNotify(string message)
{
ShowNotify(message, MessageBoxIcon.Information);
}
/// <summary>
/// 显示通知对话框
/// </summary>
/// <param name="message"></param>
/// <param name="messageIcon"></param>
public void ShowNotify(string message, MessageBoxIcon messageIcon)
{
Notify n = new Notify
{
Target = Target.Top,
Message = message,
MessageBoxIcon = messageIcon,
PositionX = Position.Center,
PositionY = Position.Top,
DisplayMilliseconds = 3000,
ShowHeader = false
};
n.Show();
}
#endregion
#region
/// <summary>
/// 页面下载附件方法
/// </summary>
/// <param name="attachUrl"></param>
public static void ShowFileEvent(string attachUrl)
{
string url = BLL.Funs.RootPath + attachUrl;
FileInfo info = new FileInfo(url);
if (!info.Exists || string.IsNullOrEmpty(attachUrl))
{
url = BLL.Funs.RootPath + "Images//Null.jpg";
info = new FileInfo(url);
}
string fileName = Path.GetFileName(url);
long fileSize = info.Length;
System.Web.HttpContext.Current.Response.Clear();
System.Web.HttpContext.Current.Response.ContentType = "application/x-zip-compressed";
System.Web.HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
System.Web.HttpContext.Current.Response.AddHeader("Content-Length", fileSize.ToString());
System.Web.HttpContext.Current.Response.TransmitFile(url, 0, fileSize);
System.Web.HttpContext.Current.Response.Flush();
System.Web.HttpContext.Current.Response.Close();
}
#endregion
#region
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public static string GetGridTableHtml(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfNumber" && (row.FindControl("labNumber") as AspNet.Label) != null)
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
if (column.ColumnID == "tfTeamType" && (row.FindControl("lbTeamType") as AspNet.Label) != null)
{
html = (row.FindControl("lbTeamType") as AspNet.Label).Text;
}
if (column.ColumnID == "tfI" && (row.FindControl("tfI") as AspNet.Label) != null)
{
html = (row.FindControl("lbI") as AspNet.Label).Text;
}
if (column.ColumnID == "tfCompileMan" && (row.FindControl("tfCompileMan") as AspNet.Label) != null)
{
html = (row.FindControl("lblCompileMan") as AspNet.Label).Text;
}
if (column.ColumnID == "tfSpecialEquipmentId")
{
html = (row.FindControl("lblSpecialEquipmentId") as AspNet.Label).Text;
}
2021-05-20 17:16:01 +08:00
if (column.ColumnID == "CheckManNames")
{
html = (row.FindControl("lbCheckManNames") as AspNet.Label).Text;
}
2021-04-30 10:28:37 +08:00
// 处理CheckBox
if (html.Contains("f-grid-static-checkbox"))
{
if (!html.Contains("f-checked"))
{
html = "×";
}
else
{
html = "√";
}
}
sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;width:140px;'>{0}</td>", html);
// sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
2021-05-20 17:16:01 +08:00
/// <summary>
/// 导出方法
/// </summary>
/// <param name="grid"></param>
/// <returns></returns>
public static string GetGridTableHtml2(Grid grid)
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
if (column.ColumnID != "AttachFile" && column.ColumnID!= "lbfAction1" && column.ColumnID != "AttachFile2")
{
sb.AppendFormat("<td>{0}</td>", column.HeaderText);
}
}
sb.Append("</tr>");
foreach (GridRow row in grid.Rows)
{
sb.Append("<tr>");
foreach (GridColumn column in grid.Columns)
{
if (column.ColumnID != "AttachFile" && column.ColumnID != "lbfAction1" && column.ColumnID != "AttachFile2")
{
string html = row.Values[column.ColumnIndex].ToString();
if (column.ColumnID == "tfPageIndex" && (row.FindControl("lblPageIndex") as AspNet.Label) != null)
{
html = (row.FindControl("lblPageIndex") as AspNet.Label).Text;
}
if (column.ColumnID == "UnitWorkName" && (row.FindControl("lbUnitWorkName") as AspNet.Label) != null)
{
html = (row.FindControl("lbUnitWorkName") as AspNet.Label).Text;
}
if (column.ColumnID == "UnitName" && (row.FindControl("lbUnitName") as AspNet.Label) != null)
{
html = (row.FindControl("lbUnitName") as AspNet.Label).Text;
}
if (column.ColumnID == "UnitNames" && (row.FindControl("lbUnitNames") as AspNet.Label) != null)
{
html = (row.FindControl("lbUnitNames") as AspNet.Label).Text;
}
if (column.ColumnID == "tfNumber" && (row.FindControl("labNumber") as AspNet.Label) != null)
{
html = (row.FindControl("labNumber") as AspNet.Label).Text;
}
if (column.ColumnID == "tfTeamType" && (row.FindControl("lbTeamType") as AspNet.Label) != null)
{
html = (row.FindControl("lbTeamType") as AspNet.Label).Text;
}
if (column.ColumnID == "tfI" && (row.FindControl("tfI") as AspNet.Label) != null)
{
html = (row.FindControl("lbI") as AspNet.Label).Text;
}
if (column.ColumnID == "tfCompileMan" && (row.FindControl("tfCompileMan") as AspNet.Label) != null)
{
html = (row.FindControl("lblCompileMan") as AspNet.Label).Text;
}
if (column.ColumnID == "tfSpecialEquipmentId")
{
html = (row.FindControl("lblSpecialEquipmentId") as AspNet.Label).Text;
}
if (column.ColumnID == "CheckManNames")
{
html = (row.FindControl("lbCheckManNames") as AspNet.Label).Text;
}
// 处理CheckBox
if (html.Contains("f-grid-static-checkbox"))
{
if (!html.Contains("f-checked"))
{
html = "×";
}
else
{
html = "√";
}
}
sb.AppendFormat("<td style='vnd.ms-excel.numberformat:@;width:140px;'>{0}</td>", html);
// sb.AppendFormat("<td>{0}</td>", html);
}
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
2021-04-30 10:28:37 +08:00
/// <summary>
/// DataTable转HTML
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
public static string GetTableHtml(DataTable table)
{
StringBuilder sb = new StringBuilder();
sb.Append("<meta http-equiv=\"content-type\" content=\"application/excel; charset=UTF-8\"/>");
sb.Append("<table cellspacing=\"0\" rules=\"all\" border=\"1\" style=\"border-collapse:collapse;\">");
sb.Append("<tr>");
foreach (var column in table.Columns)
{
sb.AppendFormat("<td>{0}</td>", column.ToString());
}
sb.Append("</tr>");
for (int i = 0; i < table.Rows.Count; i++)
{
sb.Append("<tr>");
for (int j = 0; j < table.Columns.Count; j++)
{
string html = table.Rows[i][j].ToString();
sb.AppendFormat("<td>{0}</td>", html);
}
sb.Append("</tr>");
}
sb.Append("</table>");
return sb.ToString();
}
#endregion
}
}