示例#1
0
 public void ExecuteSqlTran(Hashtable SQLStringList)
 {
     using (MySqlTransaction trans = this.DbConn.BeginTransaction())
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             try
             {
                 foreach (object obj in SQLStringList)
                 {
                     DictionaryEntry  myDE     = (DictionaryEntry)obj;
                     string           cmdText  = myDE.Key.ToString();
                     MySqlParameter[] cmdParms = (MySqlParameter[])myDE.Value;
                     MyDbConnection2.PrepareCommand(cmd, this.DbConn, trans, cmdText, cmdParms);
                     int val = cmd.ExecuteNonQuery();
                     cmd.Parameters.Clear();
                 }
                 trans.Commit();
             }
             catch
             {
                 trans.Rollback();
                 throw;
             }
         }
     }
 }
示例#2
0
        public DataSet Query(string SQLString, params MySqlParameter[] cmdParms)
        {
            DataSet      ds  = new DataSet();
            MySqlCommand cmd = new MySqlCommand();

            MyDbConnection2.PrepareCommand(cmd, this.DbConn, null, SQLString, cmdParms);
            DataSet result;

            using (MySqlDataAdapter da = new MySqlDataAdapter(cmd))
            {
                try
                {
                    da.Fill(ds, "ds");
                    cmd.Parameters.Clear();
                }
                catch (MySqlException ex)
                {
                    throw new Exception(ex.Message);
                }
                finally
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
                result = ds;
            }
            return(result);
        }
示例#3
0
 public object GetSingle(string sql, int commandTimeout = 0, params MySqlParameter[] cmdParms)
 {
     try
     {
         using (MySqlCommand cmd = new MySqlCommand(sql, this.DbConn))
         {
             if (commandTimeout > 0)
             {
                 cmd.CommandTimeout = commandTimeout;
             }
             if (cmdParms.Length > 0)
             {
                 MyDbConnection2.PrepareCommand(cmd, this.DbConn, null, sql, cmdParms);
             }
             object obj = cmd.ExecuteScalar();
             if (cmdParms.Length > 0)
             {
                 cmd.Parameters.Clear();
             }
             if (object.Equals(obj, null) || object.Equals(obj, DBNull.Value))
             {
                 return(null);
             }
             return(obj);
         }
     }
     catch (Exception ex)
     {
         LogManager.WriteExceptionUseCache(sql + "\r\n" + ex.ToString());
     }
     return(null);
 }
示例#4
0
        public int ExecuteSql(string sql, params MySqlParameter[] cmdParms)
        {
            int result = 0;

            try
            {
                using (MySqlCommand cmd = new MySqlCommand(sql, this.DbConn))
                {
                    MyDbConnection2.PrepareCommand(cmd, this.DbConn, null, sql, cmdParms);
                    result = cmd.ExecuteNonQuery();
                    cmd.Parameters.Clear();
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteExceptionUseCache(sql + "\r\n" + ex.ToString());
            }
            return(result);
        }
示例#5
0
 public void ExecuteSqlTranWithIndentity(Hashtable SQLStringList)
 {
     using (MySqlTransaction trans = this.DbConn.BeginTransaction())
     {
         using (MySqlCommand cmd = new MySqlCommand())
         {
             try
             {
                 int indentity = 0;
                 foreach (object obj in SQLStringList)
                 {
                     DictionaryEntry  myDE     = (DictionaryEntry)obj;
                     string           cmdText  = myDE.Key.ToString();
                     MySqlParameter[] cmdParms = (MySqlParameter[])myDE.Value;
                     foreach (MySqlParameter q in cmdParms)
                     {
                         if (q.Direction == ParameterDirection.InputOutput)
                         {
                             q.Value = indentity;
                         }
                     }
                     MyDbConnection2.PrepareCommand(cmd, this.DbConn, trans, cmdText, cmdParms);
                     int val = cmd.ExecuteNonQuery();
                     foreach (MySqlParameter q in cmdParms)
                     {
                         if (q.Direction == ParameterDirection.Output)
                         {
                             indentity = Convert.ToInt32(q.Value);
                         }
                     }
                     cmd.Parameters.Clear();
                 }
                 trans.Commit();
             }
             catch
             {
                 trans.Rollback();
                 throw;
             }
         }
     }
 }
示例#6
0
 public MySqlDataReader ExecuteReader(string sql, params MySqlParameter[] cmdParms)
 {
     try
     {
         using (MySqlCommand cmd = new MySqlCommand(sql, this.DbConn))
         {
             if (cmdParms.Length > 0)
             {
                 MyDbConnection2.PrepareCommand(cmd, this.DbConn, null, sql, cmdParms);
             }
             MySqlDataReader myReader = cmd.ExecuteReader();
             if (cmdParms.Length > 0)
             {
                 cmd.Parameters.Clear();
             }
             return(myReader);
         }
     }
     catch (Exception ex)
     {
         LogManager.WriteExceptionUseCache(sql + "\r\n" + ex.ToString());
     }
     return(null);
 }
示例#7
0
        public int ExecuteSqlTran(List <CommandInfo> cmdList)
        {
            int result;

            using (MySqlTransaction trans = this.DbConn.BeginTransaction())
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    try
                    {
                        int count = 0;
                        foreach (CommandInfo myDE in cmdList)
                        {
                            string           cmdText  = myDE.CommandText;
                            MySqlParameter[] cmdParms = (MySqlParameter[])myDE.Parameters;
                            MyDbConnection2.PrepareCommand(cmd, this.DbConn, trans, cmdText, cmdParms);
                            if (myDE.EffentNextType == EffentNextType.WhenHaveContine || myDE.EffentNextType == EffentNextType.WhenNoHaveContine)
                            {
                                if (myDE.CommandText.ToLower().IndexOf("count(") == -1)
                                {
                                    trans.Rollback();
                                    return(0);
                                }
                                object obj = cmd.ExecuteScalar();
                                if (obj == null && obj == DBNull.Value)
                                {
                                }
                                bool isHave = Convert.ToInt32(obj) > 0;
                                if (myDE.EffentNextType == EffentNextType.WhenHaveContine && !isHave)
                                {
                                    trans.Rollback();
                                    return(0);
                                }
                                if (myDE.EffentNextType == EffentNextType.WhenNoHaveContine && isHave)
                                {
                                    trans.Rollback();
                                    return(0);
                                }
                            }
                            else
                            {
                                int val = cmd.ExecuteNonQuery();
                                count += val;
                                if (myDE.EffentNextType == EffentNextType.ExcuteEffectRows && val == 0)
                                {
                                    trans.Rollback();
                                    return(0);
                                }
                                cmd.Parameters.Clear();
                            }
                        }
                        trans.Commit();
                        result = count;
                    }
                    catch
                    {
                        trans.Rollback();
                        throw;
                    }
                }
            }
            return(result);
        }
示例#8
0
        public int ExecuteSqlTran(List <CommandInfo> list, List <CommandInfo> oracleCmdSqlList)
        {
            MySqlConnection connection = this.DbConn;
            int             result;

            using (MySqlCommand cmd = new MySqlCommand())
            {
                cmd.Connection = connection;
                MySqlTransaction tx = connection.BeginTransaction();
                cmd.Transaction = tx;
                try
                {
                    foreach (CommandInfo myDE in list)
                    {
                        string           cmdText  = myDE.CommandText;
                        MySqlParameter[] cmdParms = (MySqlParameter[])myDE.Parameters;
                        MyDbConnection2.PrepareCommand(cmd, connection, tx, cmdText, cmdParms);
                        if (myDE.EffentNextType == EffentNextType.SolicitationEvent)
                        {
                            if (myDE.CommandText.ToLower().IndexOf("count(") == -1)
                            {
                                tx.Rollback();
                                throw new Exception("违背要求" + myDE.CommandText + "必须符合select count(..的格式");
                            }
                            object obj = cmd.ExecuteScalar();
                            if (obj == null && obj == DBNull.Value)
                            {
                            }
                            bool isHave = Convert.ToInt32(obj) > 0;
                            if (isHave)
                            {
                                myDE.OnSolicitationEvent();
                            }
                        }
                        if (myDE.EffentNextType == EffentNextType.WhenHaveContine || myDE.EffentNextType == EffentNextType.WhenNoHaveContine)
                        {
                            if (myDE.CommandText.ToLower().IndexOf("count(") == -1)
                            {
                                tx.Rollback();
                                throw new Exception("SQL:违背要求" + myDE.CommandText + "必须符合select count(..的格式");
                            }
                            object obj = cmd.ExecuteScalar();
                            if (obj == null && obj == DBNull.Value)
                            {
                            }
                            bool isHave = Convert.ToInt32(obj) > 0;
                            if (myDE.EffentNextType == EffentNextType.WhenHaveContine && !isHave)
                            {
                                tx.Rollback();
                                throw new Exception("SQL:违背要求" + myDE.CommandText + "返回值必须大于0");
                            }
                            if (myDE.EffentNextType == EffentNextType.WhenNoHaveContine && isHave)
                            {
                                tx.Rollback();
                                throw new Exception("SQL:违背要求" + myDE.CommandText + "返回值必须等于0");
                            }
                        }
                        else
                        {
                            int val = cmd.ExecuteNonQuery();
                            if (myDE.EffentNextType == EffentNextType.ExcuteEffectRows && val == 0)
                            {
                                tx.Rollback();
                                throw new Exception("SQL:违背要求" + myDE.CommandText + "必须有影响行");
                            }
                            cmd.Parameters.Clear();
                        }
                    }
                    string oraConnectionString = PubConstant.GetConnectionString("ConnectionStringPPC");
                    if (!OracleHelper.ExecuteSqlTran(oraConnectionString, oracleCmdSqlList))
                    {
                        tx.Rollback();
                        throw new Exception("执行失败");
                    }
                    tx.Commit();
                    result = 1;
                }
                catch (MySqlException e)
                {
                    tx.Rollback();
                    throw e;
                }
            }
            return(result);
        }
示例#9
0
 public MyDataReader(MyDbConnection2 conn, MySqlDataReader dataReader)
 {
     this.MyConnection = conn;
     this.DataReader   = dataReader;
 }
示例#10
0
 public MyDataReader(MyDbConnection2 conn, MySqlDataReader dataReader)
 {
     MyConnection = conn;
     DataReader   = dataReader;
 }