/// <summary> /// 格式化Excel列头和Config_KeyValue数据。 /// </summary> protected bool FormatExcel(MDataTable dt, MDataRow excelInfo) { //翻译列头。 Dictionary <string, string> formatterDic = ExcelConfig.FormatterTitle(dt, excelInfo, ObjName);// //翻译字典值,处理默认值。 bool result = KeyValueConfig.FormatNameValue(dt, formatterDic, false); //校验基础数据类型。 result = ExcelConfig.ValidateData(dt, excelInfo) && result; if (result)//验证是否存在有错误信息 { int index = dt.Columns.GetIndex("错误信息"); if (index > -1) { foreach (var row in dt.Rows) { if (!row[index].IsNullOrEmpty) { result = false; break; } } } } dt.SetState(2, BreakOp.NullOrEmpty); return(result); }
/// <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); } }
/// <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!"); } }
public void Export() { MDataTable dt = Select(GridConfig.SelectType.Export); dt.TableName = ObjName; dt.DynamicData = GridConfig.GetList(ObjName, GridConfig.SelectType.All); Dictionary <string, string> formatParas = GridConfig.SetHeaderDescription(dt); //格式化列头(描述)(需要修改列头的数据格式) KeyValueConfig.FormatNameValue(dt, formatParas, true); //格式化配置项 WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + "_" + DateTime.Now.ToString("yyyyMMdd") + ".xls", ExcelHelper.CreateExcel(dt)); //ExcelHelper.CreateExcel(dt) }
public virtual void Export() { MDataTable dt = Select(GridConfig.SelectType.Export); dt.TableName = ObjName; dt.DynamicData = GridConfig.GetList(ObjName, GridConfig.SelectType.Export); Dictionary <string, string> formatParas = GridConfig.GetFormatter(dt); //格式化列头(描述)(需要修改列头的数据格式) KeyValueConfig.FormatNameValue(dt, formatParas, true); //格式化配置项 string fix = ExcelHelper.BookType == ExcelHelper.WorkBookType.High ? ".xlsx" : ".xls"; WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + "_" + DateTime.Now.ToString("yyyyMMdd") + fix, ExcelHelper.CreateExcel(dt));//ExcelHelper.CreateExcel(dt) }
/// <summary> /// 获取Config_Grid的某配置项的脚本 /// </summary> public void GetGridConfigScript() { string script = SqlScript.GetGridConfigScript(ObjName); bool result = !string.IsNullOrEmpty(script); if (result) { WebHelper.SendFile("sys_Grid配置_" + KeyValueConfig.GetTableDescription(ObjName, TableName) + ".sql", script); } else { jsonResult = JsonHelper.OutResult(result, script); } }
/// <summary> /// 获取Config_ExcelInfo的某配置项的脚本 /// </summary> public void GetExcelConfigScript() { string script = SQLScript.GetExcelConfigScript(GetID); bool result = !string.IsNullOrEmpty(script); if (result) { CommonHelper.SendFile("sys_Excel配置_" + KeyValueConfig.GetTableDescription(ObjName, TableName) + ".sql", script); } else { jsonResult = JsonHelper.OutResult(result, script); } }
/// <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); }
/// <summary> /// 获取导入数据的模板(支持2007以上) /// </summary> public void ExcelTemplate() { string path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + ObjName + ".xls"); if (!File.Exists(path)) { path = path + "x"; if (!File.Exists(path)) { path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + TableName + ".xls"); if (!File.Exists(path)) { path = path + "x"; } } } MemoryStream ms = null; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ms = new MemoryStream(data, 0, data.Length, false, true); } string fix = "_模板"; if (ms == null) { fix = "-模板"; string objName = ObjName; MDataTable dt = GridConfig.GetList(objName, GridConfig.SelectType.All);//获取所有列的字段名。 if (dt.Rows.Count > 0) { ms = ExcelHelper.CreateExcelHeader(dt, KeyValueConfig.GetValidationData(dt)); } } WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + fix + Path.GetExtension(path), ms); }
/// <summary> /// 获取导入数据的模板(支持2007以上) /// </summary> public void ExcelTemplate() { string path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + ObjName + ".xls"); if (!File.Exists(path)) { path = path + "x"; if (!File.Exists(path) && ObjName != TableName) { path = HttpContext.Current.Server.MapPath("~/Resource/Excel/" + TableName + ".xls"); if (!File.Exists(path)) { path = path + "x"; } } } MemoryStream ms = null; string fix = ExcelHelper.BookType == ExcelHelper.WorkBookType.High ? ".xlsx" : ".xls"; if (File.Exists(path)) { byte[] data = File.ReadAllBytes(path); ms = new MemoryStream(data, 0, data.Length, false, true); fix = Path.GetExtension(path); } if (ms == null) { string objName = ObjName; MDataTable header = GridConfig.GetList(objName, GridConfig.SelectType.Import);//获取所有列的字段名。 if (header.Rows.Count > 0) { ms = ExcelHelper.CreateExcelHeader(header, KeyValueConfig.GetValidationData(header)); } } WebHelper.SendFile(KeyValueConfig.GetTableDescription(ObjName, TableName) + fix, ms); }
/// <summary> /// 获取Config_KeyValue的配置值。 /// </summary> public void GetKeyValueConfig() { jsonResult = KeyValueConfig.GetJson(); }