/// <summary> /// 获取表的列头数据(输出EasyUI的列头格式) /// </summary> public virtual void GetHeader() { MDataTable dt = GridConfig.GetList(ObjName, GridConfig.SelectType.All); if (dt == null || dt.Rows.Count == 0) { dt = GridConfig.Create(ObjName, ObjCode, dt.GetSchema(false)); if (p.UrlMenuID != string.Empty && dt.Rows.Count > 0)//仅处理配置了菜单的数据。 { //顺带处理视图语句与菜单名称的绑定 KeyValueConfig.SetTableDescription(ObjName, p.MenuName); } } if (Query <string>("reflesh") == "1")//刷新表结构 { string msg; bool result = GridConfig.Flesh(ObjName, ObjCode, dt, out msg); jsonResult = JsonHelper.OutResult(result, msg); } else if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i][Config_Grid.Field].Value = dt.Rows[i].Get <string>(Config_Grid.Field).ToLower(); } jsonResult = dt.ToJson(false, false, RowOp.None, true); } else { string err = dt.DynamicData != null?dt.DynamicData.ToString() : "Init Column Header Fail!"; jsonResult = JsonHelper.OutResult(false, err); } }
public static string GetAllProduct(int page, int limit, string key) { MAction action = new MAction("ProductFinance"); MDataTable mt = action.Select(page, limit, " Name like '%" + key + "%'"); return(mt.ToJson()); }
/// <summary> /// 获取表的列头数据(输出EasyUI的列头格式) /// </summary> public void GetHeader() { MDataTable dt = GridConfig.GetList(ObjName, GridConfig.SelectType.All); if (dt == null || dt.Rows.Count == 0) { dt = GridConfig.Create(ObjName, ObjCode, dt.GetSchema(false)); if (p.UrlMenuID != string.Empty)//仅处理配置了菜单的数据。 { //顺带处理视图语句与菜单名称的绑定 KeyValueConfig.SetTableDescription(ObjName, p.MenuName); } } else { //dt = GridConfig.Check(ObjName,ObjCode, dt); } if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { dt.Rows[i][Config_Grid.Field].Value = dt.Rows[i].Get <string>(Config_Grid.Field).ToLower(); } jsonResult = dt.ToJson(false, false, true); } else { jsonResult = JsonHelper.OutResult(false, "Init Column Header Fail!"); } }
/// <summary> /// MDataTable 转为json字符串, 只包含数据信息 /// </summary> /// <param name="dt"></param> /// <param name="isArray">是否为数组形式(用[]包裹,如[{a:1},{a:2}])</param> /// <returns></returns> public static string ToRowJson(this MDataTable dt, bool isArray = true) { if (isArray) { return(dt.ToJson(false, false)); } return(dt.ToTopOneJson()); }
public void select() { String con = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.16)(PORT = 1521)))(CONNECT_DATA =(SID = hdwms)(SERVICE_NAME=hdWMS)));User ID=HD40;password=dgsjwms9076"; MDataTable dt = null; using (MAction action = new MAction("MIS_WM_TALCNTC", con)) { dt = action.Select(); } Console.WriteLine("123"); Console.WriteLine(dt.ToJson()); }
/// <summary> /// 获取表的列头数据(输出EasyUI的列头格式) /// </summary> public void GetHeader() { MDataTable dt = GridConfig.GetList(ObjName, GridConfig.SelectType.All); if (dt == null || dt.Rows.Count == 0) { dt = GridConfig.Create(ObjCode, dt.GetSchema(false)); } else { //dt = GridConfig.Check(ObjCode, dt); } //顺带处理视图语句与菜单名称的绑定 KeyValueConfig.SetTableDescription(ObjName, p.MenuName); jsonResult = dt.ToJson(false, false, true); }
//public void GetUserInfo() //{ // jsonResult = UserAuth.User.ToJson(); //} /// <summary> /// 用户首页呈现的菜单数据 /// </summary> public void GetUserMenu() { MDataTable dt = p.UserMenu; if (IsUseUISite)//格式化菜单数据。 { string ui = AppConfig.GetApp("UI").Trim('/'); for (int i = 0; i < dt.Rows.Count; i++) { MDataRow row = dt.Rows[i]; string url = row.Get <string>(Sys_Menu.MenuUrl).TrimStart('/'); if (url != "#" && !url.ToLower().StartsWith(ui.ToLower() + "/")) { row.Set(Sys_Menu.MenuUrl, "/" + ui + "/" + url); } } } jsonResult = dt.ToJson(false, false, true); }
private void btnTo_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); string json = dt.ToJson(); sb.AppendLine("ToJson:" + json); MDataTable t = MDataTable.CreateFrom(json); sb.AppendLine("从Josn还原了------------------"); string xml = t.ToXml(); sb.AppendLine("ToXml:" + xml); t = MDataTable.CreateFrom(xml); sb.AppendLine("从Xml还原了--------------------"); sb.AppendLine("还可以和List<T>,Dictionary,ArrayList,HasTable等几乎所有的常用类或数组交互"); rtxtText.Text = sb.ToString(); }
private static string GetResult(NameValueCollection queryString, int page, MDataTable result, string colName) { if (page != 0 || queryString["page"].IsNullOrEmpty()) { return(result.ToJson().Replace(" 00:00:00", "")); } //更改列名为中文名 var colNames = colName.Split('~'); var shouldRemoveColNames = new List <string>(); foreach (var column in result.Columns) { var dtColName = column.ColumnName; var index = colNames.IndexOf(dtColName); if (index >= 0) { column.ColumnName = colNames[index + 1]; continue; } shouldRemoveColNames.Add(dtColName); } //移除无需导出的列 foreach (var removeColName in shouldRemoveColNames) { result.Columns.Remove(removeColName); } var tablename = result.TableName; var filename = SAction.GetOneValue <string>("SysTableFilename", "tablename".ToWhere(tablename), "Filename"); filename = filename.IsNullOrEmpty() ? tablename : filename; var workbook = result.ToWorkbook(); workbook.SetSheetName(0, filename); ExportExcel.WriteExcel(workbook, filename); return(null); }