示例#1
0
        /// <summary>
        /// 执行命令,检查是否符合给定要求
        /// 如发生<see cref="DBConcurrencyException"/>, return false
        /// </summary>
        /// <param name="cmd">Command</param>
        public bool ExecuteMyCommand(MyDbCommand cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            IList <MyDbCommand> cmds = new List <MyDbCommand>();

            cmds.Add(cmd);

            DbTransaction txn = null;

            try
            {
                txn = BeginTransaction();
                UpdateTransaction(cmds, txn);
                CommitTransaction(txn);
            }
            catch (DBConcurrencyException)
            {
                RollbackTransaction(txn);
                return(false);
            }
            catch (Exception)
            {
                RollbackTransaction(txn);
                throw;
            }

            return(true);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public override void Update(object entity)
        {
            System.Data.DataRowView row = entity as System.Data.DataRowView;
            System.Diagnostics.Debug.Assert(row != null, "DataTableDao's entity shold be DataRowView!");

            System.Data.Common.DbCommand cmd = GenerateUpdateCommand(row.Row);
            MyDbCommand mCmd = new MyDbCommand(cmd, ExpectedResultTypes.Special, "1");

            if (m_isBatchOperation)
            {
                m_batchCmds.Add(mCmd);
                m_batchDataRows.Add(new Tuple <OperateType, System.Data.DataRow>(OperateType.Update, row.Row));
            }
            else
            {
                bool ret = DbHelper.Instance.ExecuteMyCommand(mCmd);
                if (ret)
                {
                    row.Row.AcceptChanges();
                }
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="entity"></param>
        public override void Delete(object entity)
        {
            System.Data.DataRowView row = entity as System.Data.DataRowView;
            System.Diagnostics.Debug.Assert(row != null, "DataTableDao's entity shold be DataRowView!");

            System.Data.Common.DbCommand cmd = GenerateDeleteCommand(row.Row);
            MyDbCommand mCmd = new MyDbCommand(cmd, ExpectedResultTypes.Special, "1");

            if (m_isBatchOperation)
            {
                m_batchCmds.Add(mCmd);
                m_batchDataRows.Add(new Tuple<OperateType, System.Data.DataRow>(OperateType.Delete, row.Row));
            }
            else
            {
                bool ret = DbHelper.Instance.ExecuteMyCommand(mCmd);
                if (ret)
                {
                    // 不需要在这里删除,会在DisplayManager里删除
                    //row.Row.Delete();
                }
            }
        }
示例#4
0
        /// <summary>
        /// ִ���������Ƿ���ϸ���Ҫ��
        /// �緢��<see cref="DBConcurrencyException"/>, return false
        /// </summary>
        /// <param name="cmd">Command</param>
        public bool ExecuteMyCommand(MyDbCommand cmd)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            IList<MyDbCommand> cmds = new List<MyDbCommand>();
            cmds.Add(cmd);

            DbTransaction txn = null;
            try
            {
                txn = BeginTransaction();
                UpdateTransaction(cmds, txn);
                CommitTransaction(txn);
            }
            catch (DBConcurrencyException)
            {
                RollbackTransaction(txn);
                return false;
            }
            catch (Exception)
            {
                RollbackTransaction(txn);
                throw;
            }

            return true;
        }