Beispiel #1
0
 private static void preparedatadb()
 {
     if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL"))
     {
         DbCommand    dbCommand    = null;
         DbDataReader dbDataReader = null;
         DBConn       dBConn       = new DBConn();
         try
         {
             dBConn.con = new MySqlConnection(string.Concat(new object[]
             {
                 "Database=",
                 DBUrl.DB_CURRENT_NAME,
                 ";Data Source=",
                 DBUrl.CURRENT_HOST_PATH,
                 ";Port=",
                 DBUrl.CURRENT_PORT,
                 ";User Id=",
                 DBUrl.CURRENT_USER_NAME,
                 ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;"
             }));
             dBConn.con.Open();
             dBConn.setInUse();
             dbCommand             = dBConn.con.CreateCommand();
             dbCommand.CommandText = "SELECT table_name FROM INFORMATION_SCHEMA.TABLES where (table_name like '%_auto_info%' or table_name like '%_data_daily%' or table_name like '%_data_hourly%' or table_name like 'rackthermal_hourly20%' or table_name like 'rackthermal_daily20%') and table_schema = '" + DBUrl.DB_CURRENT_NAME + "' ";
             dbDataReader          = dbCommand.ExecuteReader();
             while (dbDataReader.Read())
             {
                 string text = Convert.ToString(dbDataReader.GetValue(0));
                 if (!DBTools.ht_tablename.ContainsKey(text))
                 {
                     DBTools.ht_tablename.Add(text, text);
                 }
             }
             dbDataReader.Close();
             dbCommand.Dispose();
             dBConn.Close();
         }
         catch (Exception ex)
         {
             DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + ex.Message + "\n" + ex.StackTrace);
             try
             {
                 dbDataReader.Close();
             }
             catch (Exception)
             {
             }
             try
             {
                 dbCommand.Dispose();
             }
             catch (Exception)
             {
             }
             try
             {
                 dBConn.Close();
             }
             catch (Exception)
             {
             }
         }
     }
 }
Beispiel #2
0
        public static DataTable GetAllPortPD()
        {
            DataTable     dataTable     = new DataTable();
            DBConn        dBConn        = null;
            DbCommand     dbCommand     = null;
            DbDataAdapter dbDataAdapter = null;
            string        commandText;

            if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL") || DBUrl.SERVERMODE)
            {
                commandText = "select * from port_data_daily" + DateTime.Now.ToString("yyyyMMdd");
                try
                {
                    dBConn = DBConnPool.getDynaConnection();
                    if (dBConn != null && dBConn.con != null)
                    {
                        dbDataAdapter               = DBConn.GetDataAdapter(dBConn.con);
                        dbCommand                   = dBConn.con.CreateCommand();
                        dbCommand.CommandText       = commandText;
                        dbDataAdapter.SelectCommand = dbCommand;
                        dbDataAdapter.Fill(dataTable);
                        dbDataAdapter.Dispose();
                        dbCommand.Dispose();
                        dBConn.Close();
                    }
                    return(dataTable);
                }
                catch (Exception)
                {
                    try
                    {
                        dbDataAdapter.Dispose();
                    }
                    catch
                    {
                    }
                    try
                    {
                        dbCommand.Dispose();
                    }
                    catch
                    {
                    }
                    try
                    {
                        dBConn.Close();
                    }
                    catch
                    {
                    }
                    return(dataTable);
                }
            }
            commandText = "select * from port_data_daily ";
            try
            {
                dBConn = DBConnPool.getDynaConnection(DateTime.Now);
                if (dBConn != null && dBConn.con != null)
                {
                    dbDataAdapter               = new OleDbDataAdapter();
                    dbCommand                   = dBConn.con.CreateCommand();
                    dbCommand.CommandText       = commandText;
                    dbDataAdapter.SelectCommand = dbCommand;
                    dbDataAdapter.Fill(dataTable);
                    dbDataAdapter.Dispose();
                    dbCommand.Dispose();
                    dBConn.Close();
                }
            }
            catch (Exception)
            {
                try
                {
                    dbDataAdapter.Dispose();
                }
                catch
                {
                }
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                try
                {
                    dBConn.Close();
                }
                catch
                {
                }
            }
            return(dataTable);
        }
Beispiel #3
0
        public int Save()
        {
            DbCommand dbCommand = null;
            DBConn    dBConn    = null;

            try
            {
                int result;
                if (this.gid == null || this.gid.Length < 1 || this.gid.Equals("0"))
                {
                    result = -1;
                    return(result);
                }
                if (this.bid == null || this.bid.Length < 1 || this.bid.Equals("0"))
                {
                    result = -1;
                    return(result);
                }
                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.DEFAULT_HOST_PATH + ";Jet OLEDB:Database Password="******"update gatewaytable set eleflag=",
                        current.ElectricityUsage,
                        ",capacity=",
                        current.Capacity,
                        " where slevel=2 and gid='",
                        this.gid,
                        "' and bid='",
                        this.bid,
                        "' and sid='",
                        current.SubmeterID,
                        "' "
                    });
                    dbCommand.ExecuteNonQuery();
                }
                dbCommand.CommandText = string.Concat(new string[]
                {
                    "update gatewaytable set disname = '",
                    this.bname,
                    "',location='",
                    this.location,
                    "' where slevel = 1 and gid = '",
                    this.gid,
                    "' and bid='",
                    this.bid,
                    "' "
                });
                int num = dbCommand.ExecuteNonQuery();
                dbCommand.Transaction.Commit();
                dbCommand.Dispose();
                dBConn.Close();
                result = num;
                return(result);
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                if (dbCommand != null)
                {
                    try
                    {
                        dbCommand.Transaction.Rollback();
                        dbCommand.Dispose();
                    }
                    catch (Exception)
                    {
                    }
                }
                if (dBConn.con != null)
                {
                    try
                    {
                        dBConn.Close();
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            return(-1);
        }