/// <summary> /// 获取数据表名 /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public static string GetClassTable <T>() { TargetTbaleAttribute attribute = GetClassTargetTbaleAttribute <T>(); Type type = typeof(T); string str = type.Name; if (!string.IsNullOrWhiteSpace(attribute.Name)) { str = attribute.Name; } return(str); }
/// <summary> /// 解析实体 /// </summary> /// <param name="classType"></param> /// <returns></returns> public static Dictionary <string, object> ResolveObj(Type classType) { TargetTbaleAttribute attribute = GetClassAttribute <TargetTbaleAttribute>(classType); Dictionary <string, object> dictionary = new Dictionary <string, object>(); string tableName = classType.Name; if (!string.IsNullOrWhiteSpace(attribute.Name)) { tableName = attribute.Name; } dictionary.Add(TABLE_NAME, tableName); List <ClassFiledInfo> list = GetClassFiedlAttributeInfo(classType); dictionary.Add(COLUNM_INFO, list); return(dictionary); }
/// <summary> /// 系统基本数据数据集检查 /// </summary> /// <returns></returns> private void CheckedDataTable() { OnCheckInitListener(this); string assembly_path = AppConfigManage.GetConfigValue <string>("system_model_Assembly"); var db = DbAction.CurrentDB(); SQLHelper helper = new SQLHelper(db.ShowAllDataBaseTables()); DataTable table = new DataTable(); try { table = db.ExecuteToDataTable(helper); } catch (Exception e) { OnCheckExceptionListener(this, e); OnCheckEndListener(this); return; //throw new Exception("系统数据集自检失败", e); } if (table != null || table.Columns.Count < 1) { table.Columns[0].ColumnName = "NAME"; } Assembly assembly = Assembly.LoadFrom(AppDomain.CurrentDomain.BaseDirectory + "bin\\" + assembly_path); Type[] types = assembly.GetTypes(); List <Dictionary <string, object> > fixList = new List <Dictionary <string, object> >(); fixList.Clear(); OnCheckStartListener(this, types.Length); int index = 0; foreach (Type type in types) { OnCheckIngListener(this, types.Length, index); if (!type.IsClass) { continue; } TargetTbaleAttribute targetTbale = type.GetCustomAttribute <TargetTbaleAttribute>(); if (targetTbale == null) { continue; } ObjectResolverManage resolverManage = ObjectResolverManage.GetInstance(); Dictionary <string, object> object_data = resolverManage.ResolverObject(type); if (object_data == null) { continue; } DataRow[] rows = table.Select("NAME='" + object_data[ObjectAttrResolver.TABLE_NAME] + "'"); if (rows.Count() > 0) { continue; } fixList.Add(object_data); index++; } index = 0; foreach (Dictionary <string, object> tableInfo in fixList) { try { TableUlits.CreateTable(tableInfo); OnFixListener(this, fixList.Count, index); } catch (Exception e) { } index++; } OnCheckEndListener(this); Control.CheckForIllegalCrossThreadCalls = true; return; }