Ejemplo n.º 1
0
        protected override void OnExit(ExitEventArgs e)
        {
            try
            {
                AppPreferences.Save(App.AppName);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(ex.StackTrace);
            }

            try
            {
                RecycleBin.Instance.DeleteContent();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(ex.StackTrace);
            }

            try
            {
                BatchAction.DeleteUndoFiles();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.WriteLine(ex.StackTrace);
            }

            base.OnExit(e);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查询表
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="lstScope">条件</param>
        /// <returns></returns>
        public List <E> SelectList <E>(ScopeList lstScope)
            where E : EntityBase, new()
        {
            Type                 eType   = typeof(E);
            List <E>             retlist = null;
            BQLEntityTableHandle table   = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }
            BQLQuery BQL = GetSelectSql(lstScope, table);

            if (!lstScope.HasPage)
            {
                retlist = QueryList <E>(BQL, lstScope.ShowEntity, lstScope.UseCache);
                DataAccessCommon.FillEntityChidList(retlist, lstScope);
                return(retlist);
            }
            using (BatchAction ba = _oper.StarBatchAction())
            {
                retlist = QueryPageList <E>(BQL, lstScope.PageContent, lstScope.ShowEntity, lstScope.UseCache);
                DataAccessCommon.FillEntityChidList(retlist, lstScope);
                return(retlist);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取所有关系
        /// </summary>
        /// <param name="chileName">null则查询所有表</param>
        /// <returns></returns>
        public List <TableRelationAttribute> GetRelation(DataBaseOperate oper, DBInfo info, IEnumerable <string> childNames)
        {
            List <TableRelationAttribute> lst = new List <TableRelationAttribute>();

            using (BatchAction ba = oper.StarBatchAction())
            {
                OleDbConnection conn = oper.Connection as OleDbConnection;
                oper.ConnectDataBase();
                DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, null);

                foreach (DataRow dr in dt.Rows)
                {
                    TableRelationAttribute tinfo = new TableRelationAttribute();
                    tinfo.CreateName();
                    tinfo.SourceTable = dr["FK_TABLE_NAME"] as string;
                    tinfo.SourceName  = dr["FK_COLUMN_NAME"] as string;
                    tinfo.TargetTable = dr["PK_TABLE_NAME"] as string;
                    tinfo.TargetName  = dr["PK_COLUMN_NAME"] as string;
                    tinfo.IsParent    = true;
                    lst.Add(tinfo);

                    tinfo = new TableRelationAttribute();
                    tinfo.CreateName();
                    tinfo.SourceTable = dr["PK_TABLE_NAME"] as string;
                    tinfo.SourceName  = dr["PK_COLUMN_NAME"] as string;
                    tinfo.TargetTable = dr["FK_TABLE_NAME"] as string;
                    tinfo.TargetName  = dr["FK_COLUMN_NAME"] as string;
                    tinfo.IsParent    = false;
                    lst.Add(tinfo);
                }
            }
            return(lst);
        }
Ejemplo n.º 4
0
        private void UMHSDataERBBatchEntryHandler_DefineActions(object sender, EventArgs e)
        {
            BatchActionRegion actionRegion = new BatchActionRegion("CUSTOM_TASK_REGION", "Custom");
            BatchActionGroup  actionGroup  = new BatchActionGroup("REVENUE_GROUP", "MIMED Data");

            findFriendAction         = new BatchAction(BUTTON_KEY, "Find Friends", IMAGE_KEY);
            findFriendAction.Size    = BatchActionSize.Small;
            findFriendAction.Enabled = true;

            //searchmimed = new BatchAction(BUTTON_KEY_SRCH, "Find Friends", IMAGE_KEY_SECH);
            searchmimed = new BatchShowSearchFormUIAction(BUTTON_KEY_SRCH, "MIMED Constituent Search", IMAGE_KEY_SECH,
                                                          Guid.Parse("747530a1-be80-4054-a021-d2a599248261"));
            // searchArgs.SearchModel.Fields["PATIENTSONLY"].ValueObject = true;

            searchmimed.Size    = BatchActionSize.Small;
            searchmimed.Enabled = true;

            UpdateContactForFriend         = new BatchAction(BUTTON_KEY_CON, "Save Contact Info for Friends", IMAGE_KEY_CON);
            UpdateContactForFriend.Size    = BatchActionSize.Small;
            UpdateContactForFriend.Enabled = true;


            actionGroup.Add(findFriendAction);
            actionGroup.Add(searchmimed);
            actionGroup.Add(UpdateContactForFriend);

            actionRegion.Add(actionGroup);
            this.Actions.Add(actionRegion);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 直接查询数据库视图
        /// </summary>
        /// <param name="table">表</param>
        /// <param name="lstScope">条件</param>
        /// <param name="vParams">字段列表</param>
        /// <param name="lstSort">排序类型</param>
        /// <param name="objPage">分页对象</param>
        /// <returns></returns>
        public DataSet SelectTable(BQLOtherTableHandle table, ScopeList lstScope)
        {
            List <BQLParamHandle> lstParams = GetParam(table, lstScope);

            List <BQLParamHandle> lstOrders = new List <BQLParamHandle>();
            BQLParamHandle        order     = null;

            foreach (Sort objSort in lstScope.OrderBy)
            {
                order = table[objSort.PropertyName];
                if (objSort.SortType == SortType.ASC)
                {
                    order = order.ASC;
                }
                else
                {
                    order = order.DESC;
                }
                lstOrders.Add(order);
            }

            BQLCondition where = BQLCondition.TrueValue;
            where = FillCondition(where, table, lstScope, null);

            BQLQuery bql = BQL.Select(lstParams.ToArray()).From(table).Where(where).OrderBy(lstOrders.ToArray());

            if (lstScope.HasPage)
            {
                using (BatchAction ba = _oper.StarBatchAction())
                {
                    return(QueryDataSet(bql, null, lstScope.PageContent, lstScope.UseCache));
                }
            }
            return(QueryDataSet(bql, null, lstScope.UseCache));
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 执行sql语句,分页返回DataSet
        /// </summary>
        /// <param name="BQL">sql语句</param>
        /// <param name="objPage">分页对象</param>
        public DataSet QueryDataSet(BQLQuery bql, Type tableType, PageContent objPage, bool useCache)
        {
            AbsCondition con = ToCondition(bql, null, true, tableType);
            Dictionary <string, bool> cacheTables = null;

            if (useCache)
            {
                cacheTables = con.CacheTables;
            }
            DataSet ds = null;

            using (BatchAction ba = _oper.StarBatchAction())
            {
                if (con.DbParamList != null)
                {
                    con.PageContent = objPage;
                    con.Oper        = _oper;
                    string sql = con.GetSql(useCache);
                    ds = _oper.QueryDataSet(sql, con.DbParamList, cacheTables);
                }
                else
                {
                    SelectCondition sCon = con as SelectCondition;
                    DataTable       dt   = con.DBinfo.CurrentDbAdapter.QueryDataTable(sCon.GetSelect(), objPage, _oper, null);
                    dt.TableName = "newTable";
                    ds           = new DataSet();
                    ds.Tables.Add(dt);
                }
            }
            return(ds);
        }
Ejemplo n.º 7
0
        public void Handle(NotifyKeyGroupCollectionChangedEventArgs <TKey, TItem> arg)
        {
            switch (arg.Action)
            {
            case NotifyCollectionChangedAction.Reset:
                HandleGroupsReset();
                break;

            case NotifyCollectionChangedAction.Replace:
                HandleGroupsReplace(arg);
                break;

            default:
                if (BatchAction == null)
                {
                    Update(arg);
                }
                else
                {
                    BatchAction.Invoke(() => Update(arg));
                }

                break;
            }
        }
Ejemplo n.º 8
0
 private void Rollback()
 {
     this.transaction.Undo();
     this.transaction = null;
     this.OnChanged(EventArgs.Empty);
     this.NotifyOfPropertyChange(nameof(this.CanUndo));
     this.NotifyOfPropertyChange(nameof(this.CanRedo));
 }
Ejemplo n.º 9
0
 public Received(Guid batchId, BatchAction action, Guid[] orderIds, int activeThreshold, int?delayInSeconds = null)
 {
     BatchId         = batchId;
     Timestamp       = DateTime.UtcNow;
     Action          = action;
     OrderIds        = orderIds;
     ActiveThreshold = activeThreshold;
     DelayInSeconds  = delayInSeconds;
 }
Ejemplo n.º 10
0
 public void End()
 {
     if (BatchAction != null)
     {
         Tuple <String, DynamicParameters> tuple = null;
         if (Tuples.TryDequeue(out tuple))
         {
             BatchAction.Invoke(tuple.Item1, tuple.Item2);
         }
     }
 }
Ejemplo n.º 11
0
 private void Commit()
 {
     if (this.transaction.Items.Any())
     {
         this.undoItems.Insert(0, this.transaction);
     }
     this.redoItems.Clear();
     this.transaction = null;
     this.OnChanged(EventArgs.Empty);
     this.NotifyOfPropertyChange(nameof(this.CanUndo));
     this.NotifyOfPropertyChange(nameof(this.CanRedo));
 }
Ejemplo n.º 12
0
 public IUndoTransaction BeginTransaction(string name)
 {
     try
     {
         this.ValidateBeginTransaction(name);
         this.transaction = new BatchAction(this, name);
         return(this.transaction);
     }
     finally
     {
         this.NotifyOfPropertyChange(nameof(this.CanUndo));
         this.NotifyOfPropertyChange(nameof(this.CanRedo));
     }
 }
Ejemplo n.º 13
0
        private void OnBatch(BatchCommand command)
        {
            History.Instance.ExecuteInTransaction(
                delegate()
            {
                BatchAction action = new BatchAction(command);

                action.Id          = Editor.Transaction.CurrentId;
                action.OnFinished += OnAfterBatch;

                History.Instance.Execute(action);
            },
                Editor.Transaction.CurrentId,
                "Document.OnBatch");
        }
Ejemplo n.º 14
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            IEnumerable <DBTableInfo> lst = gvTables.DataSource as IEnumerable <DBTableInfo>;

            if (lst == null)
            {
                return;
            }
            List <string> selection = new List <string>();

            foreach (DBTableInfo info in lst)
            {
                if (info.IsGenerate)
                {
                    selection.Add(info.Name);
                }
            }
            DBInfo db = DbInfo.CreateDBInfo();


            using (BatchAction ba = db.DefaultOperate.StarBatchAction())
            {
                using (FrmProcess frmPro = FrmProcess.ShowProcess())
                {
                    string      file = DesignerInfo.SelectDocView.DocData.FileName;
                    XmlDocument doc  = DBEntityInfo.GetClassDiagram(file);

                    frmPro.UpdateProgress(0, 10, "正在读取类信息");
                    List <DBTableInfo> lstGen          = TableChecker.GetTableInfo(db, selection);
                    string             entityNamespace = DesignerInfo.GetNameSpace();
                    for (int i = 0; i < lstGen.Count; i++)
                    {
                        frmPro.UpdateProgress(i, lstGen.Count, "正在生成");
                        string baseType = cmbBaseType.Text;
                        if (string.IsNullOrEmpty(baseType))
                        {
                            baseType = GetDefaultBaseType();
                        }
                        DBEntityInfo info = new DBEntityInfo(entityNamespace, lstGen[i], DesignerInfo, DbInfo, baseType);
                        info.GreanCode(doc);
                    }
                    //拷贝备份
                    File.Copy(file, file + ".bak", true);
                    EntityMappingConfig.SaveXML(file, doc);
                }
            }
            this.Close();
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 分页查询表(返回List)
        /// </summary>
        /// <param name="scopeList">范围查找的集合</param>
        /// <returns></returns>
        public List <T> SelectList(ScopeList scopeList)
        {
            if (scopeList.HasPage)
            {
                if (!scopeList.HasSort)
                {
                    foreach (EntityPropertyInfo pInfo in CurEntityInfo.PrimaryProperty)
                    {
                        scopeList.OrderBy.Add(pInfo.PropertyName, SortType.ASC);
                    }
                }
            }

            if (scopeList.HasInner)
            {
                return(_cdal.SelectList <T>(scopeList));
            }

            ParamList list = null;

            list = new ParamList();
            string sql = null;

            using (BatchAction ba = Oper.StarBatchAction())
            {
                if (!scopeList.HasPage)//判断是否分页查询
                {
                    sql = GetSelectContant(list, scopeList, GetSelectParams(scopeList)).GetSql(scopeList.UseCache);
                }
                else
                {
                    sql = GetSelectPageContant(list, scopeList);
                }

                List <T> retlist = null;

                Dictionary <string, bool> cacheTables = null;
                if (scopeList.UseCache)
                {
                    cacheTables = _oper.DBInfo.QueryCache.CreateMap(CurEntityInfo.TableName);
                }
                retlist = QueryList(sql, list, CommandType.Text, cacheTables);
                DataAccessCommon.FillEntityChidList(retlist, scopeList);
                return(retlist);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 获取类的创建语句
        /// </summary>
        /// <param name="type"></param>
        private void GetClassSQL()
        {
            _lstSql = new List <string>();
            List <KeyWordTableParamItem> lstTable = new List <KeyWordTableParamItem>();
            DBConfigInfo dbcinfo = FrmDBSetting.GetDBConfigInfo(DesignerInfo, "DataAccess.");
            DBInfo       dbInfo  = dbcinfo.CreateDBInfo();

            foreach (ClrClass curType in SelectedClass)
            {
                EntityConfig entity = new EntityConfig(curType, DesignerInfo);

                if (string.IsNullOrEmpty(entity.TableName) || !entity.IsTable)
                {
                    continue;
                }
                string typeName = null;
                Stack <EntityConfig>          stkConfig   = EntityConfig.GetEntity(entity, DesignerInfo);
                List <EntityParam>            lstParam    = new List <EntityParam>();
                List <TableRelationAttribute> lstRelation = new List <TableRelationAttribute>();
                string lastTableName = null;
                string lastSummary   = null;
                while (stkConfig.Count > 0)
                {
                    EntityConfig centity = stkConfig.Pop();
                    FillParams(centity, lstParam, lstRelation);
                    lastTableName = centity.TableName;
                    lastSummary   = centity.Summary;
                }
                KeyWordTableParamItem table = new KeyWordTableParamItem(lstParam, lstRelation, lastTableName, null);
                table.Description = lastSummary;
                lstTable.Add(table);
            }
            try
            {
                using (BatchAction ba = dbInfo.DefaultOperate.StarBatchAction())
                {
                    _lstSql = TableChecker.CheckTable(dbInfo, lstTable);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成语句失败:" + ex.Message);
            }
            ShowSql();
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 查询表
        /// </summary>
        /// <param name="scopeList">范围查找的集合</param>
        /// <returns></returns>
        public DataSet Select(ScopeList scopeList)
        {
            if (scopeList.HasInner)
            {
                if (scopeList.OrderBy.Count <= 0 && scopeList.HasPage)
                {
                    foreach (EntityPropertyInfo pInfo in CurEntityInfo.PrimaryProperty)
                    {
                        scopeList.OrderBy.Add(pInfo.PropertyName, SortType.ASC);
                    }
                }
                return(_cdal.SelectDataSet <T>(scopeList));
            }

            ParamList list = null;

            list = new ParamList();

            string      sql     = null;
            PageContent objPage = scopeList.PageContent;

            using (BatchAction ba = Oper.StarBatchAction())
            {
                if (objPage == null)//判断是否分页查询
                {
                    sql = GetSelectContant(list, scopeList, GetSelectParams(scopeList)).GetSql(scopeList.UseCache);
                }
                else
                {
                    sql = GetSelectPageContant(list, scopeList);
                }


                DataSet ds = null;
                Dictionary <string, bool> cacheTables = null;
                if (scopeList.UseCache)
                {
                    cacheTables = _oper.DBInfo.QueryCache.CreateMap(CurEntityInfo.TableName);
                }
                ds = _oper.QueryDataSet(sql, list, CommandType.Text, cacheTables);

                return(ds);
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 执行SQL语句
        /// </summary>
        /// <param name="oper">数据库连接</param>
        /// <param name="lstSQL">SQL语句</param>
        /// <returns></returns>
        public static List <string> ExecuteSQL(DataBaseOperate oper, List <string> lstSQL)
        {
            List <string> resaults = new List <string>();

            using (BatchAction ba = oper.StarBatchAction())
            {
                foreach (string sql in lstSQL)
                {
                    try
                    {
                        int row = oper.Execute(sql, new Buffalo.DB.DbCommon.ParamList(), null);
                        resaults.Add("执行完毕;");
                    }
                    catch (Exception ex)
                    {
                        resaults.Add("执行错误:" + ex.Message);
                    }
                }
            }
            return(resaults);
        }
Ejemplo n.º 19
0
        //private static string _sqlTables = "SELECT [name],[xtype] FROM [sysobjects] Where [xtype] in ('U','V') and [name] not in('dtproperties','sysdiagrams') ORDER BY [xtype],[crdate] desc";

        /// <summary>
        /// 获取所有用户表
        /// </summary>
        /// <returns></returns>
        public virtual List <DBTableInfo> GetAllTableName(DataBaseOperate oper, DBInfo info)
        {
            ParamList lstParam = new ParamList();
            //DataBaseOperate oper = info.DefaultOperate;
            List <DBTableInfo> lstName = new List <DBTableInfo>();

            using (BatchAction ba = oper.StarBatchAction())
            {
                OleDbConnection conn = oper.Connection as OleDbConnection;
                oper.ConnectDataBase();


                DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                foreach (DataRow row in dt.Rows)
                {
                    DBTableInfo tableInfo = new DBTableInfo();
                    if (row.IsNull("TABLE_NAME"))
                    {
                        continue;
                    }
                    tableInfo.Name   = row["TABLE_NAME"].ToString();
                    tableInfo.IsView = false;
                    lstName.Add(tableInfo);
                }
                dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "VIEW" });

                foreach (DataRow row in dt.Rows)
                {
                    DBTableInfo tableInfo = new DBTableInfo();
                    if (row.IsNull("TABLE_NAME"))
                    {
                        continue;
                    }
                    tableInfo.Name   = row["TABLE_NAME"].ToString();
                    tableInfo.IsView = true;
                    lstName.Add(tableInfo);
                }
            }
            return(lstName);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// 执行sql语句,返回List
        /// </summary>
        /// <typeparam name="E">实体类型</typeparam>
        /// <param name="BQL">BQL</param>
        /// <returns></returns>
        public List <E> QueryList <E>(BQLQuery BQL, IEnumerable <BQLEntityTableHandle> outPutTables, bool useCache)
            where E : EntityBase, new()
        {
            AbsCondition con     = ToCondition(BQL, outPutTables, false, typeof(E));
            List <E>     retlist = null;

            using (BatchAction ba = _oper.StarBatchAction())
            {
                IDataReader reader = null;
                try
                {
                    con.Oper = _oper;
                    Dictionary <string, bool> cacheTables = null;
                    if (useCache)
                    {
                        cacheTables = con.CacheTables;
                    }
                    if (con.DbParamList != null)
                    {
                        reader = _oper.Query(con.GetSql(useCache), con.DbParamList, cacheTables);
                    }
                    else
                    {
                        SelectCondition sCon = con as SelectCondition;
                        reader = con.DBinfo.CurrentDbAdapter.Query(sCon.GetSelect(), con.PageContent, _oper);
                    }
                    retlist = LoadFromReader <E>(con.AliasManager, reader);
                }

                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }
            return(retlist);
        }
Ejemplo n.º 21
0
        public void UpdateServer(BatchAction batchAction, int updateType)
        {
            try
            {
                if (batchAction.type != ActionIdentifier.ACTION_SELECT)
                {
                    lock (sendLock)
                    {
                        MapUpdate mapUpdate = new MapUpdate();
                        mapUpdate.batchAction = batchAction;
                        mapUpdate.updateType  = updateType;

                        stream.WriteByte(MessageType.MAP_UPDATE);
                        stream.Flush();
                        Serializer.SerializeWithLengthPrefix <MapUpdate>(stream, mapUpdate, PrefixStyle.Base128);
                    }
                }
            }
            catch (Exception ex)
            {
                Generic.AjustError(ex);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// 查询并返回DataSet
        /// </summary>
        /// <typeparam name="E"></typeparam>
        /// <param name="lstScope">条件集合</param>
        /// <returns></returns>
        public DataSet SelectDataSet <E>(ScopeList lstScope)
        {
            Type eType = typeof(E);
            BQLEntityTableHandle table = _oper.DBInfo.FindTable(eType);

            if (CommonMethods.IsNull(table))
            {
                _oper.DBInfo.ThrowNotFondTable(eType);
            }
            // List<BQLParamHandle> lstParams = GetParam(table, lstScope);
            // BQLCondition where = BQLCondition.TrueValue;
            // where = FillCondition(where, table, lstScope);
            // BQLQuery BQL = BQL.Select(lstParams.ToArray())
            //.From(table)
            //.Where(where);

            // if (lstScope.GroupBy.Count > 0)
            // {
            //     BQL = new KeyWordGroupByItem(lstScope.GroupBy, BQL);
            // }
            // if (lstScope.OrderBy != null && lstScope.OrderBy.Count > 0)
            // {
            //     BQL = new KeyWordOrderByItem(GetSort(lstScope.OrderBy, table), BQL);
            // }
            BQLQuery BQL = GetSelectSql(lstScope, table);

            //.OrderBy(GetSort(lstScope.OrderBy, table));
            if (!lstScope.HasPage)
            {
                return(QueryDataSet <E>(BQL, lstScope.UseCache));
            }
            using (BatchAction ba = _oper.StarBatchAction())
            {
                return(QueryDataSet <E>(BQL, lstScope.PageContent, lstScope.UseCache));
            }
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 获取表信息
        /// </summary>
        /// <param name="oper"></param>
        /// <param name="info"></param>
        /// <param name="tableNames"></param>
        /// <returns></returns>
        public List <DBTableInfo> GetTablesInfo(DataBaseOperate oper, DBInfo info, IEnumerable <string> tableNames)
        {
            Dictionary <string, DBTableInfo> dicTables = new Dictionary <string, DBTableInfo>();
            List <DBTableInfo> lst = new List <DBTableInfo>();


            using (BatchAction ba = oper.StarBatchAction())
            {
                OleDbConnection conn = oper.Connection as OleDbConnection;
                oper.ConnectDataBase();
                DataTable dtpk = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary_Keys, null);    //主键
                Dictionary <string, bool> dicPk = new Dictionary <string, bool>();
                foreach (DataRow row in dtpk.Rows)
                {
                    string key = row["TABLE_NAME"].ToString() + ":" + row["COLUMN_NAME"].ToString();
                    dicPk[key.ToLower()] = true;
                }

                foreach (string tableName in tableNames)
                {
                    DBTableInfo tableinfo = new DBTableInfo();
                    tableinfo.Params        = new List <EntityParam>();
                    tableinfo.RelationItems = new List <TableRelationAttribute>();

                    tableinfo.IsView = false;
                    DataTable dtStr = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, tableName, "TABLE" });
                    if (dtStr.Rows.Count <= 0)
                    {
                        dtStr            = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, tableName, "VIEW" });
                        tableinfo.IsView = true;
                    }
                    if (dtStr.Rows.Count <= 0)
                    {
                        continue;
                    }
                    tableinfo.Name        = dtStr.Rows[0]["TABLE_NAME"] as string;
                    tableinfo.Description = dtStr.Rows[0]["DESCRIPTION"] as string;
                    DataTable dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, tableName, null });



                    //获取表结构
                    DataTable dtData = null;
                    string    sql    = "select * from [" + tableName + "]";
                    using (OleDbCommand comm = new OleDbCommand(sql, conn))
                    {
                        using (OleDbDataReader dr = comm.ExecuteReader(CommandBehavior.KeyInfo))
                        {
                            dtData = dr.GetSchemaTable();
                        }
                    }
                    DataView dv = dt.DefaultView;
                    dv.Sort = "ORDINAL_POSITION asc";
                    foreach (DataRowView row in dv)
                    {
                        FillParam(tableinfo, row.Row, dicPk, dtData);
                    }
                    lst.Add(tableinfo);
                }
            }
            foreach (DBTableInfo table in lst)
            {
                dicTables[table.Name] = table;
            }
            List <TableRelationAttribute> lstRelation = GetRelation(oper, info, tableNames);

            FillRelation(dicTables, lstRelation);
            return(lst);
        }
Ejemplo n.º 24
0
        /// <summary>
        /// 进行插入操作
        /// </summary>
        /// <param name="obj">要插入的对象</param>
        /// <param name="fillIdentity">是否要填充刚插入的实体的ID</param>
        /// <returns></returns>
        protected internal int DoInsert(EntityBase obj, ValueSetList setList, bool fillIdentity)
        {
            StringBuilder sqlParams = new StringBuilder(1000);
            StringBuilder sqlValues = new StringBuilder(1000);
            ParamList     list      = new ParamList();
            string        param     = null;
            string        svalue    = null;

            List <EntityPropertyInfo> identityInfo = new List <EntityPropertyInfo>();

            KeyWordInfomation keyinfo = BQLValueItem.GetKeyInfo().Clone() as KeyWordInfomation;

            keyinfo.ParamList = list;

            foreach (EntityPropertyInfo info in EntityInfo.PropertyInfo)
            {
                //EntityPropertyInfo info = enums.Current.Value;
                object curValue = info.GetValue(obj);

                if (info.Identity)
                {
                    if (info.SqlType == DbType.Guid && info.FieldType == DefaultType.GUIDType)
                    {
                        curValue = Guid.NewGuid();
                        info.SetValue(obj, curValue);

                        DBParameter prm = list.NewParameter(info.SqlType, curValue, EntityInfo.DBInfo);

                        sqlParams.Append(",");
                        sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName));
                        sqlValues.Append(",");
                        sqlValues.Append(prm.ValueName);
                        continue;
                    }
                    else
                    {
                        if (fillIdentity)
                        {
                            identityInfo.Add(info);
                        }
                        param = EntityInfo.DBInfo.CurrentDbAdapter.GetIdentityParamName(info);
                        if (!string.IsNullOrEmpty(param))
                        {
                            sqlParams.Append(",");
                            sqlParams.Append(param);
                        }
                        svalue = EntityInfo.DBInfo.CurrentDbAdapter.GetIdentityParamValue(EntityInfo, info);
                        if (!string.IsNullOrEmpty(svalue))
                        {
                            sqlValues.Append(",");
                            sqlValues.Append(svalue);
                        }
                        continue;
                    }
                }
                else if (info.IsVersion) //版本初始值
                {
                    object conValue = curValue;
                    if (conValue == null)
                    {
                        conValue = GetDefaultConcurrency(info);
                    }
                    if (conValue != null)
                    {
                        DBParameter prm = list.NewParameter(info.SqlType, conValue, EntityInfo.DBInfo);

                        sqlParams.Append(",");
                        sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName));
                        sqlValues.Append(",");
                        sqlValues.Append(prm.ValueName);

                        continue;
                    }
                }
                else
                {
                    BQLValueItem bvalue = null;
                    if (setList != null && setList.TryGetValue(info.PropertyName, out bvalue))
                    {
                        sqlParams.Append(",");
                        sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName));
                        sqlValues.Append(",");
                        sqlValues.Append(bvalue.DisplayValue(keyinfo));
                        continue;
                    }
                    else if (curValue == null)
                    {
                        continue;
                    }
                    else
                    {
                        DBParameter prmValue = list.NewParameter(info.SqlType, curValue, EntityInfo.DBInfo);
                        sqlParams.Append(",");
                        sqlParams.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatParam(info.ParamName));
                        sqlValues.Append(",");
                        sqlValues.Append(prmValue.ValueName);
                    }
                }
            }
            if (sqlParams.Length > 0)
            {
                sqlParams.Remove(0, 1);
            }
            else
            {
                return(0);
            }
            if (sqlValues.Length > 0)
            {
                sqlValues.Remove(0, 1);
            }
            else
            {
                return(0);
            }

            InsertCondition con = new InsertCondition(EntityInfo.DBInfo);

            con.Tables.Append(EntityInfo.DBInfo.CurrentDbAdapter.FormatTableName(EntityInfo.TableName));
            con.SqlParams.Append(sqlParams.ToString());
            con.SqlValues.Append(sqlValues.ToString());
            int ret = -1;

            con.DbParamList = list;


            using (BatchAction ba = _oper.StarBatchAction())
            {
                string sql = con.GetSql(true);
                Dictionary <string, bool> cacheTables = null;

                cacheTables = _oper.DBInfo.QueryCache.CreateMap(EntityInfo.TableName);

                ret = ExecuteCommand(sql, list, CommandType.Text, cacheTables);
                if (identityInfo.Count > 0 && fillIdentity)
                {
                    foreach (EntityPropertyInfo pkInfo in identityInfo)
                    {
                        sql = EntityInfo.DBInfo.CurrentDbAdapter.GetIdentitySQL(pkInfo);
                        using (IDataReader reader = _oper.Query(sql, new ParamList(), null))
                        {
                            if (reader.Read())
                            {
                                if (!reader.IsDBNull(0))
                                {
                                    EntityInfo.DBInfo.CurrentDbAdapter.SetObjectValueFromReader(reader, 0, obj, pkInfo, !pkInfo.TypeEqual(reader, 0));
                                    //obj.PrimaryKeyChange();
                                    ret = 1;
                                }
                            }
                        }
                    }
                }
            }

            return(ret);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// 开启非事务的批量操作
        /// </summary>
        /// <returns></returns>
        public BatchAction StarBatchAction()
        {
            BatchAction action = new BatchAction(this);

            return(action);
        }