Example #1
0
        public static void CreateTable(Dictionary <string, object> tableInfo)
        {
            string str;
            BaseDbActionService service = DbAction.CurrentDB();;

            SQLHelper helper;

            str = ResolveCreateTableSql(tableInfo);

            try
            {
                helper = new SQLHelper(str, Array.Empty <object>());
                service.ExecuteNonQuery(helper);
            }
            catch (Exception e)
            {
                throw new Exception("数据表创建失败:执行语句\n" + str, e);
            }
            finally
            {
                service.Dispose();
            }



            return;
        }
Example #2
0
        /// <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;
        }