Exemplo n.º 1
0
        public static int GetRowCount(int i_range_type, DateTime dt_start, DateTime dt_end)
        {
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();
            long      arg_0F_0  = dt_start.Ticks;
            long      arg_17_0  = dt_end.Ticks;

            try
            {
                dBConn = DBConnPool.getLogConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    switch (i_range_type)
                    {
                    case 0:
                        dbCommand.CommandText = "select count(id) from logrecords";
                        break;

                    case 1:
                        dbCommand.CommandText = string.Concat(new string[]
                        {
                            "select count(id) from logrecords where ticks >= #",
                            dt_start.ToString("yyyy-MM-dd HH:mm:ss"),
                            "# and ticks <= #",
                            dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                            "# "
                        });
                        break;

                    case 2:
                        dbCommand.CommandText = string.Concat(new string[]
                        {
                            "select count(id) from logrecords where ticks <= #",
                            dt_start.ToString("yyyy-MM-dd HH:mm:ss"),
                            "# or ticks >= #",
                            dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                            "# "
                        });
                        break;
                    }
                    if (DBUrl.SERVERMODE)
                    {
                        dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                    }
                    object obj = dbCommand.ExecuteScalar();
                    dbCommand.Dispose();
                    int result;
                    if (obj == null || obj is DBNull || Convert.ToInt32(obj) < 1)
                    {
                        result = -1;
                        return(result);
                    }
                    result = Convert.ToInt32(obj);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 2
0
        public static DataTable GetSearchResult(int i_range_type, DateTime dt_start, DateTime dt_end, int i_pagenum, int i_pagesize, int i_total)
        {
            DateTime   now        = DateTime.Now;
            DataTable  dataTable  = new DataTable();
            DataColumn dataColumn = new DataColumn("insert_time");

            dataColumn.DataType = Type.GetType("System.String");
            dataTable.Columns.Add(dataColumn);
            DataColumn dataColumn2 = new DataColumn("eventid");

            dataColumn2.DataType = Type.GetType("System.String");
            dataTable.Columns.Add(dataColumn2);
            DataColumn dataColumn3 = new DataColumn("parametervalue");

            dataColumn3.DataType = Type.GetType("System.String");
            dataTable.Columns.Add(dataColumn3);
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();
            long      arg_95_0  = dt_start.Ticks;
            long      arg_9D_0  = dt_end.Ticks;
            string    text      = "";

            switch (i_range_type)
            {
            case 0:
                text = " 2=2 ";
                break;

            case 1:
                text = string.Concat(new string[]
                {
                    " 2=2 and ticks >= #",
                    dt_start.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# and ticks <= #",
                    dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# "
                });
                break;

            case 2:
                text = string.Concat(new string[]
                {
                    " 2=2 and (ticks <= #",
                    dt_start.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# or ticks >= #",
                    dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# )"
                });
                break;
            }
            try
            {
                dBConn = DBConnPool.getLogConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    if (i_pagenum == 0 && i_pagesize == 0)
                    {
                        dbCommand.CommandText = "select ticks,eventid,logpara from logrecords where " + text + " order by id desc";
                        if (DBUrl.SERVERMODE)
                        {
                            dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                        }
                        DbDataReader dbDataReader = dbCommand.ExecuteReader();
                        while (dbDataReader.Read())
                        {
                            string  value   = Convert.ToDateTime(dbDataReader.GetValue(0)).ToString("yyyy-MM-dd HH:mm:ss");
                            string  @string = dbDataReader.GetString(1);
                            string  string2 = dbDataReader.GetString(2);
                            DataRow dataRow = dataTable.NewRow();
                            dataRow["insert_time"]    = value;
                            dataRow["eventid"]        = @string;
                            dataRow["parametervalue"] = string2;
                            dataTable.Rows.Add(dataRow);
                        }
                        dbDataReader.Close();
                    }
                    else
                    {
                        if (LogInfo.m_type == i_range_type && DateTime.Compare(LogInfo.mdt_start, dt_start) == 0 && DateTime.Compare(LogInfo.mdt_end, dt_end) == 0)
                        {
                            long num;
                            long num2;
                            if (i_pagenum * i_pagesize > i_total)
                            {
                                num  = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]);
                                num2 = Convert.ToInt64(LogInfo.ht_cache[i_total]);
                            }
                            else
                            {
                                num  = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]);
                                num2 = Convert.ToInt64(LogInfo.ht_cache[i_pagenum * i_pagesize]);
                            }
                            dbCommand.CommandText = string.Concat(new object[]
                            {
                                "select * from logrecords where id >= ",
                                num2,
                                " and id <= ",
                                num,
                                " order by id desc"
                            });
                            if (DBUrl.SERVERMODE)
                            {
                                dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                            }
                            DbDataReader dbDataReader2 = dbCommand.ExecuteReader();
                            while (dbDataReader2.Read())
                            {
                                string  value2   = Convert.ToDateTime(dbDataReader2.GetValue(1)).ToString("yyyy-MM-dd HH:mm:ss");
                                string  string3  = dbDataReader2.GetString(2);
                                string  string4  = dbDataReader2.GetString(3);
                                DataRow dataRow2 = dataTable.NewRow();
                                dataRow2["insert_time"]    = value2;
                                dataRow2["eventid"]        = string3;
                                dataRow2["parametervalue"] = string4;
                                dataTable.Rows.Add(dataRow2);
                            }
                            dbDataReader2.Close();
                        }
                        else
                        {
                            LogInfo.m_type        = i_range_type;
                            LogInfo.mdt_start     = dt_start;
                            LogInfo.mdt_end       = dt_end;
                            LogInfo.ht_cache      = new Hashtable();
                            dbCommand.CommandText = "select id from logrecords where " + text + " order by id desc";
                            if (DBUrl.SERVERMODE)
                            {
                                dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                            }
                            DbDataReader dbDataReader3 = dbCommand.ExecuteReader();
                            int          num3          = 1;
                            while (dbDataReader3.Read())
                            {
                                LogInfo.ht_cache.Add(num3, dbDataReader3.GetValue(0));
                                num3++;
                            }
                            dbDataReader3.Close();
                            new DataTable();
                            long num5;
                            long num6;
                            if (i_pagenum * i_pagesize > i_total)
                            {
                                int num4 = i_pagenum * i_pagesize - i_total;
                                string.Concat(new object[]
                                {
                                    "select top ",
                                    i_pagesize - num4,
                                    " id  from (select top ",
                                    i_pagesize - num4,
                                    " id from logrecords where ",
                                    text,
                                    " order by id asc) order by id desc"
                                });
                                num5 = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]);
                                num6 = Convert.ToInt64(LogInfo.ht_cache[i_total]);
                            }
                            else
                            {
                                num5 = Convert.ToInt64(LogInfo.ht_cache[(i_pagenum - 1) * i_pagesize + 1]);
                                num6 = Convert.ToInt64(LogInfo.ht_cache[i_pagenum * i_pagesize]);
                                if (i_pagenum * i_pagesize > i_total / 2)
                                {
                                    string.Concat(new object[]
                                    {
                                        "select top ",
                                        i_pagesize,
                                        " id  from (select top ",
                                        i_total - i_pagenum * i_pagesize + i_pagesize,
                                        " id from logrecords where ",
                                        text,
                                        " order by id asc) order by id desc"
                                    });
                                }
                                else
                                {
                                    string.Concat(new object[]
                                    {
                                        "select id from (select top ",
                                        i_pagesize,
                                        " id  from (select top ",
                                        i_pagenum * i_pagesize,
                                        " id from logrecords where ",
                                        text,
                                        " order by id desc) order by id asc) order by id desc"
                                    });
                                }
                            }
                            dbCommand.CommandText = string.Concat(new object[]
                            {
                                "select * from logrecords where id >= ",
                                num6,
                                " and id <= ",
                                num5,
                                " order by id desc"
                            });
                            if (DBUrl.SERVERMODE)
                            {
                                dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                            }
                            DbDataReader dbDataReader4 = dbCommand.ExecuteReader();
                            while (dbDataReader4.Read())
                            {
                                string  value3   = Convert.ToDateTime(dbDataReader4.GetValue(1)).ToString("yyyy-MM-dd HH:mm:ss");
                                string  string5  = dbDataReader4.GetString(2);
                                string  string6  = dbDataReader4.GetString(3);
                                DataRow dataRow3 = dataTable.NewRow();
                                dataRow3["insert_time"]    = value3;
                                dataRow3["eventid"]        = string5;
                                dataRow3["parametervalue"] = string6;
                                dataTable.Rows.Add(dataRow3);
                            }
                            dbDataReader4.Close();
                        }
                    }
                    dbCommand.Dispose();
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            Console.WriteLine("million sencods is : " + (DateTime.Now - now).TotalMilliseconds.ToString());
            return(dataTable);
        }
Exemplo n.º 3
0
        public static DataTable GetPrePage(int i_key, int i_range_type, DateTime dt_start, DateTime dt_end, int i_pagenum, int i_pagesize, int i_total)
        {
            DateTime   now        = DateTime.Now;
            DataTable  dataTable  = new DataTable();
            DataColumn dataColumn = new DataColumn("insert_time");

            dataColumn.DataType = Type.GetType("System.String");
            dataTable.Columns.Add(dataColumn);
            DataColumn dataColumn2 = new DataColumn("eventid");

            dataColumn2.DataType = Type.GetType("System.String");
            dataTable.Columns.Add(dataColumn2);
            DataColumn dataColumn3 = new DataColumn("parametervalue");

            dataColumn3.DataType = Type.GetType("System.String");
            dataTable.Columns.Add(dataColumn3);
            DataColumn dataColumn4 = new DataColumn("id");

            dataColumn4.DataType = Type.GetType("System.Int32");
            dataTable.Columns.Add(dataColumn4);
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();
            long      arg_BF_0  = dt_start.Ticks;
            long      arg_C7_0  = dt_end.Ticks;
            string    text      = "";

            switch (i_range_type)
            {
            case 0:
                text = string.Concat(new object[]
                {
                    " 2=2 id > ",
                    i_key,
                    " and ticks <= #",
                    dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# "
                });
                break;

            case 1:
                text = string.Concat(new object[]
                {
                    " 2=2 id > ",
                    i_key,
                    " and ticks >= #",
                    dt_start.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# and ticks <= #",
                    dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# "
                });
                break;

            case 2:
                text = string.Concat(new object[]
                {
                    " 2=2 id > ",
                    i_key,
                    " and (ticks <= #",
                    dt_start.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# or ticks >= #",
                    dt_end.ToString("yyyy-MM-dd HH:mm:ss"),
                    "# )"
                });
                break;
            }
            try
            {
                dBConn = DBConnPool.getLogConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    long      num        = 0L;
                    long      num2       = 0L;
                    DataTable dataTable2 = new DataTable();
                    string    commandText;
                    if (i_pagenum * i_pagesize > i_total)
                    {
                        int num3 = i_pagenum * i_pagesize - i_total;
                        commandText = string.Concat(new object[]
                        {
                            "select top ",
                            i_pagesize - num3,
                            " id  from (select top ",
                            i_pagesize - num3,
                            " id from logrecords where ",
                            text,
                            " order by id asc) order by id desc"
                        });
                    }
                    else
                    {
                        commandText = string.Concat(new object[]
                        {
                            "select id from ( select top ",
                            i_pagesize,
                            " id from logrecords where ",
                            text,
                            " order by id asc ) order by id desc"
                        });
                    }
                    dbCommand.CommandText = commandText;
                    if (DBUrl.SERVERMODE)
                    {
                        dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                    }
                    DbDataReader dbDataReader = dbCommand.ExecuteReader();
                    if (dbDataReader.HasRows)
                    {
                        dataTable2 = DBConn.ConvertOleDbReaderToDataTable(dbDataReader);
                    }
                    dbDataReader.Close();
                    DataRow[] array = dataTable2.Select("", "id DESC");
                    if (array.Length > 0)
                    {
                        num2 = Convert.ToInt64(array[0]["id"]);
                        num  = Convert.ToInt64(array[array.Length - 1]["id"]);
                    }
                    dbCommand.CommandText = string.Concat(new object[]
                    {
                        "select * from logrecords where id >= ",
                        num,
                        " and id <= ",
                        num2,
                        " order by id desc"
                    });
                    if (DBUrl.SERVERMODE)
                    {
                        dbCommand.CommandText = dbCommand.CommandText.Replace("#", "'");
                    }
                    DbDataReader dbDataReader2 = dbCommand.ExecuteReader();
                    while (dbDataReader2.Read())
                    {
                        string  value   = Convert.ToDateTime(dbDataReader2.GetValue(1)).ToString("yyyy-MM-dd HH:mm:ss");
                        string  @string = dbDataReader2.GetString(2);
                        string  string2 = dbDataReader2.GetString(3);
                        int     num4    = Convert.ToInt32(dbDataReader2.GetValue(0));
                        DataRow dataRow = dataTable.NewRow();
                        dataRow["insert_time"]    = value;
                        dataRow["eventid"]        = @string;
                        dataRow["parametervalue"] = string2;
                        dataRow["id"]             = num4;
                        dataTable.Rows.Add(dataRow);
                    }
                    dbDataReader2.Close();
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            Console.WriteLine("million sencods is : " + (DateTime.Now - now).TotalMilliseconds.ToString());
            return(dataTable);
        }
Exemplo n.º 4
0
        public int Update()
        {
            if (this.id < 1)
            {
                return(-1);
            }
            if (this.device_id < 1)
            {
                return(-1);
            }
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();

            try
            {
                dBConn = DBConnPool.getConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    if (DBUrl.SERVERMODE)
                    {
                        string commandText = "update device_sensor_info set sensor_nm=?sensor_nm,max_humidity=?max_humidity,min_humidity=?min_humidity,max_temperature=?max_temperature,min_temperature=?min_temperature,max_press=?max_press,min_press=?min_press,sensor_type=?sensor_type,location_type=?location_type  where id=" + this.id;
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("?sensor_nm", this.sensor_nm, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_humidity", this.max_humidity, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_humidity", this.min_humidity, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_temperature", this.max_temperature, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_temperature", this.min_temperature, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_press", this.max_press, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_press", this.min_press, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?sensor_type", this.sensor_type, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?location_type", this.sensor_locationtype, dbCommand));
                    }
                    else
                    {
                        string commandText = "update device_sensor_info set sensor_nm=?,max_humidity=?,min_humidity=?,max_temperature=?,min_temperature=?,max_press=?,min_press=?,sensor_type=?,location_type=?  where id=" + this.id;
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("@sensor_nm", this.sensor_nm, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_humidity", this.max_humidity, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_humidity", this.min_humidity, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_temperature", this.max_temperature, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_temperature", this.min_temperature, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_press", this.max_press, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_press", this.min_press, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@sensor_type", this.sensor_type, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@location_type", this.sensor_locationtype, dbCommand));
                    }
                    int result = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    DBCacheStatus.Device = true;
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_Device"
                    });
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 5
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)
             {
             }
         }
     }
 }
Exemplo n.º 6
0
        public DBWorkThread(int i_type)
        {
            if (DBUrl.SERVERMODE)
            {
                string   cONNECT_STRING = DBUrl.CONNECT_STRING;
                string[] array          = cONNECT_STRING.Split(new string[]
                {
                    ","
                }, StringSplitOptions.RemoveEmptyEntries);
                this.con = new MySqlConnection(string.Concat(new string[]
                {
                    "Database=eco",
                    DBUrl.SERVERID,
                    ";Data Source=",
                    array[0],
                    ";Port=",
                    array[1],
                    ";User Id=",
                    array[2],
                    ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=50;Default Command Timeout=0;charset=utf8;"
                }));
                this.con.Open();
            }
            else
            {
                this.DBTYPE = i_type;
                switch (this.DBTYPE)
                {
                case 0:
                    break;

                case 1:
                    try
                    {
                        this.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;"
                        }));
                        this.con.Open();
                        DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        goto IL_25B;
                    }
                    catch (Exception e)
                    {
                        DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e, false, "    "));
                        goto IL_25B;
                    }
                    break;

                default:
                    goto IL_25B;
                }
                try
                {
                    int num = 0;
                    while (TaskStatus.GetDBStatus() == -1 && num < 600)
                    {
                        Thread.Sleep(50);
                        DebugCenter.GetInstance().appendToFile(this.ToString() + "Waiting DBConnection : " + num);
                        num++;
                    }
                    DBConn dynaConnection = DBConnPool.getDynaConnection();
                    if (dynaConnection != null)
                    {
                        this.con = dynaConnection.con;
                    }
                    else
                    {
                        this.con = null;
                    }
                }
                catch (Exception ex)
                {
                    DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                }
            }
IL_25B:
            this.debug = DebugCenter.GetInstance();
        }
Exemplo n.º 7
0
        public int update()
        {
            int       num       = -1;
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();

            try
            {
                dBConn = DBConnPool.getConnection();
                string commandText  = "update sys_para set para_value = '" + this.maintenance + "' where para_name = 'LIMITTYPE' and para_type = 'int' ";
                string commandText2 = "update sys_para set para_value = '" + this.days + "' where para_name = 'DAYLIMIT' and para_type = 'int' ";
                string commandText3 = "update sys_para set para_value = '" + this.recordNum + "' where para_name = 'RECORDSLIMIT' and para_type = 'int' ";
                string commandText4 = "update sys_para set para_value = '" + this.pageSize + "' where para_name = 'PAGESIZE' and para_type = 'int' ";
                string commandText5 = "update sys_para set para_value = '" + this.saveRange + "' where para_name = 'SAVERANGE' and para_type = 'int' ";
                dbCommand             = DBConn.GetCommandObject(dBConn.con);
                dbCommand.CommandType = CommandType.Text;
                dbCommand.CommandText = commandText;
                num = dbCommand.ExecuteNonQuery();
                if (num < 1)
                {
                    int result = num;
                    return(result);
                }
                dbCommand.CommandText = commandText2;
                num = dbCommand.ExecuteNonQuery();
                if (num < 1)
                {
                    int result = num;
                    return(result);
                }
                dbCommand.CommandText = commandText3;
                num = dbCommand.ExecuteNonQuery();
                if (num < 1)
                {
                    int result = num;
                    return(result);
                }
                dbCommand.CommandText = commandText4;
                num = dbCommand.ExecuteNonQuery();
                if (num < 1)
                {
                    int result = num;
                    return(result);
                }
                dbCommand.CommandText = commandText5;
                num = dbCommand.ExecuteNonQuery();
                dbCommand.Dispose();
                DBCacheStatus.SystemParameter = true;
                DBCacheStatus.DBSyncEventSet(true, new string[]
                {
                    "DBSyncEventName_Service_SystemParameter"
                });
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(num);
        }
Exemplo n.º 8
0
        public static DBConn getLogConnection()
        {
            string str = "";
            DBConn result;

            if (DBUrl.SERVERMODE)
            {
                try
                {
                    DBConn   dBConn         = new DBConn();
                    string   cONNECT_STRING = DBUrl.CONNECT_STRING;
                    string[] array          = cONNECT_STRING.Split(new string[]
                    {
                        ","
                    }, StringSplitOptions.RemoveEmptyEntries);
                    dBConn.con = new MySqlConnection(string.Concat(new string[]
                    {
                        "Database=eco",
                        DBUrl.SERVERID,
                        ";Data Source=",
                        array[0],
                        ";Port=",
                        array[1],
                        ";User Id=",
                        array[2],
                        ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;"
                    }));
                    dBConn.con.Open();
                    dBConn.setInUse();
                    result = dBConn;
                    return(result);
                }
                catch (Exception ex)
                {
                    DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get LogDB Connection Error : " + ex.Message + "\n" + ex.StackTrace);
                    result = null;
                    return(result);
                }
            }
            bool   flag    = false;
            DBConn dBConn2 = new DBConn();

            try
            {
                try
                {
                    dBConn2.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "logdb.mdb;Jet OLEDB:Database Password=ecoSensorlog");
                    dBConn2.con.Open();
                    flag = true;
                }
                catch (Exception ex2)
                {
                    str = ex2.Message + "\r\n" + ex2.StackTrace;
                    int i = 0;
                    while (i < 4)
                    {
                        Thread.Sleep(10);
                        i++;
                        try
                        {
                            dBConn2.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "logdb.mdb;Jet OLEDB:Database Password=ecoSensorlog");
                            dBConn2.con.Open();
                            flag = true;
                            break;
                        }
                        catch (Exception ex3)
                        {
                            str = ex3.Message + "\r\n" + ex3.StackTrace;
                        }
                    }
                }
                if (flag)
                {
                    dBConn2.setInUse();
                    result = dBConn2;
                }
                else
                {
                    DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get LogDB Connection Error : " + str);
                    result = null;
                }
            }
            catch (Exception ex4)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get LogDB Connection Error : " + ex4.Message + "\n" + ex4.StackTrace);
                result = null;
            }
            return(result);
        }
Exemplo n.º 9
0
        public static DBConn getDynaConnection(DateTime dt_inserttime, bool b_create)
        {
            DBConn result;

            lock (DBConnPool._lockdatadb)
            {
                string str = "";
                if (DBUrl.SERVERMODE)
                {
                    try
                    {
                        DBConn   dBConn         = new DBConn();
                        string   cONNECT_STRING = DBUrl.CONNECT_STRING;
                        string[] array          = cONNECT_STRING.Split(new string[]
                        {
                            ","
                        }, StringSplitOptions.RemoveEmptyEntries);
                        dBConn.con = new MySqlConnection(string.Concat(new string[]
                        {
                            "Database=eco",
                            DBUrl.SERVERID,
                            ";Data Source=",
                            array[0],
                            ";Port=",
                            array[1],
                            ";User Id=",
                            array[2],
                            ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=150;Default Command Timeout=0;charset=utf8;"
                        }));
                        dBConn.con.Open();
                        dBConn.setInUse();
                        DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        result = dBConn;
                        return(result);
                    }
                    catch (Exception e)
                    {
                        DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e, false, "    "));
                        result = null;
                        return(result);
                    }
                }
                if (DBUrl.DB_CURRENT_TYPE.ToUpperInvariant().Equals("MYSQL"))
                {
                    try
                    {
                        DBConn dBConn2 = new DBConn();
                        dBConn2.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;"
                        }));
                        dBConn2.con.Open();
                        dBConn2.setInUse();
                        DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_Success, false);
                        result = dBConn2;
                        return(result);
                    }
                    catch (Exception e2)
                    {
                        DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                        DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e2, false, "    "));
                        result = null;
                        return(result);
                    }
                }
                try
                {
                    string text = AppDomain.CurrentDomain.BaseDirectory + "datadb";
                    if (text[text.Length - 1] != Path.DirectorySeparatorChar)
                    {
                        text += Path.DirectorySeparatorChar;
                    }
                    if (!Directory.Exists(text))
                    {
                        Directory.CreateDirectory(text);
                    }
                    DateTime.Now.ToString("yyyyMMdd");
                    dt_inserttime.ToString("yyyyMMdd");
                    string text2 = text + "datadb_" + dt_inserttime.ToString("yyyyMMdd") + ".mdb";
                    if (!File.Exists(text2) && b_create)
                    {
                        string sourceFileName = text + "datadb.org";
                        File.Copy(sourceFileName, text2, true);
                    }
                    bool flag2 = false;
                    try
                    {
                        DBConn dBConn3 = new DBConn();
                        try
                        {
                            dBConn3.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text2 + ";Jet OLEDB:Database Password=root");
                            dBConn3.con.Open();
                            flag2 = true;
                        }
                        catch (Exception ex)
                        {
                            str = ex.Message + "\r\n" + ex.StackTrace;
                            int i = 0;
                            while (i < 4)
                            {
                                Thread.Sleep(10);
                                i++;
                                try
                                {
                                    dBConn3.con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + text2 + ";Jet OLEDB:Database Password=root");
                                    dBConn3.con.Open();
                                    flag2 = true;
                                    break;
                                }
                                catch (Exception ex2)
                                {
                                    str = ex2.Message + "\r\n" + ex2.StackTrace;
                                }
                            }
                        }
                        if (flag2)
                        {
                            dBConn3.setInUse();
                            dBConn3.DBSource_Type = 2;
                            try
                            {
                                StackTrace stackTrace = new StackTrace();
                                MethodBase method     = stackTrace.GetFrame(1).GetMethod();
                                DBCache.OpenDataDB(dBConn3.GetHashCode(), method.Name);
                                DBCache.PrintDataDB();
                            }
                            catch
                            {
                            }
                            result = dBConn3;
                        }
                        else
                        {
                            DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + str);
                            result = null;
                        }
                    }
                    catch (Exception ex3)
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + ex3.Message + "\n" + ex3.StackTrace);
                        result = null;
                    }
                }
                catch (Exception ex4)
                {
                    DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~Get DynaDB Connection Error : " + ex4.Message + "\n" + ex4.StackTrace);
                    result = null;
                }
            }
            return(result);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
 public static int CloseAllConnection()
 {
     if (DBUrl.RUNMODE == 2)
     {
         DBConn[] array = DBConnPool.dynaConns;
         for (int i = 0; i < array.Length; i++)
         {
             DBConn dBConn = array[i];
             if (dBConn.con != null)
             {
                 try
                 {
                     dBConn.close();
                     dBConn.con.Close();
                     dBConn.con = null;
                 }
                 catch (Exception ex)
                 {
                     DebugCenter.GetInstance().appendToFile("Close DBConnection exception : " + ex.Message + "\n" + ex.StackTrace);
                 }
             }
         }
         DBConn[] array2 = DBConnPool.dbConns;
         for (int j = 0; j < array2.Length; j++)
         {
             DBConn dBConn2 = array2[j];
             if (dBConn2.con != null)
             {
                 try
                 {
                     dBConn2.close();
                     dBConn2.con.Close();
                     dBConn2.con = null;
                 }
                 catch (Exception ex2)
                 {
                     DebugCenter.GetInstance().appendToFile("Close DBConnection exception : " + ex2.Message + "\n" + ex2.StackTrace);
                 }
             }
         }
         return(1);
     }
     if (DBUrl.DB_CURRENT_TYPE.ToUpper().Equals("MYSQL"))
     {
         return(1);
     }
     DBConn[] array3 = DBConnPool.dynaConns;
     for (int k = 0; k < array3.Length; k++)
     {
         DBConn dBConn3 = array3[k];
         if (dBConn3.con != null)
         {
             try
             {
                 dBConn3.close();
                 dBConn3.con.Close();
                 dBConn3.con = null;
             }
             catch (Exception ex3)
             {
                 DebugCenter.GetInstance().appendToFile("Close DBConnection exception : " + ex3.Message + "\n" + ex3.StackTrace);
             }
         }
     }
     return(1);
 }
Exemplo n.º 12
0
        public int Update()
        {
            if (this.id < 1)
            {
                return(-1);
            }
            if (this.device_id < 1)
            {
                return(-1);
            }
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();

            try
            {
                dBConn = DBConnPool.getConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    if (DBUrl.SERVERMODE)
                    {
                        string commandText = "update port_info set port_nm=?port_nm,port_confirmation=?port_confirmation,port_ondelay_time=?port_ondelay_time,port_offdelay_time=?port_offdelay_time,max_voltage=?max_voltage,min_voltage=?min_voltage,max_power_diss=?max_power_diss,min_power_diss=?min_power_diss,max_power=?max_power,min_power=?min_power,max_current=?max_current,min_current=?min_current,shutdown_method=?shutdown_method ,mac=?mac where id=" + this.id;
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("?port_nm", this.port_nm, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?port_confirmation", this.port_confirmation, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?port_ondelay_time", this.port_ondelay_time, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?port_offdelay_time", this.port_offdelay_time, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_voltage", this.max_voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_voltage", this.min_voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_power_diss", this.max_power_diss, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_power_diss", this.min_power_diss, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_power", this.max_power, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_power", this.min_power, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_current", this.max_current, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_current", this.min_current, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?shutdown_method", this.shutdown_method, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?mac", this.port_mac, dbCommand));
                    }
                    else
                    {
                        string commandText = "update port_info set port_nm=?,port_confirmation=?,port_ondelay_time=?,port_offdelay_time=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=?,shutdown_method=? ,mac=? where id=" + this.id;
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("@port_nm", this.port_nm, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@port_confirmation", this.port_confirmation, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@port_ondelay_time", this.port_ondelay_time, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@port_offdelay_time", this.port_offdelay_time, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_power_diss", this.max_power_diss, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_power_diss", this.min_power_diss, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@shutdown_method", this.shutdown_method, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@mac", this.port_mac, dbCommand));
                    }
                    int result = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    DBCacheStatus.Device = true;
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_Device"
                    });
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                dbCommand.Dispose();
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 13
0
        public int Update()
        {
            if (this.id < 1)
            {
                return(-1);
            }
            if (this.device_id < 1)
            {
                return(-1);
            }
            DBConn    dBConn    = null;
            DbCommand dbCommand = null;

            try
            {
                dBConn = DBConnPool.getConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    if (DBUrl.SERVERMODE)
                    {
                        string commandText = "update bank_info set port_nums=?port_nums,bank_nm=?bank_nm,voltage=?voltage,max_voltage=?max_voltage,min_voltage=?min_voltage,max_power_diss=?max_power_diss,min_power_diss=?min_power_diss,max_power=?max_power,min_power=?min_power,max_current=?max_current,min_current=?min_current  where id=" + this.id;
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("?port_nums", this.portlists, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?bank_nm", this.bank_nm, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?voltage", this.voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_voltage", this.max_voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_voltage", this.min_voltage, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_power_diss", this.max_power_diss, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_power_diss", this.min_power_diss, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_power", this.max_power, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_power", this.min_power, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?max_current", this.max_current, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?min_current", this.min_current, dbCommand));
                    }
                    else
                    {
                        if (this.bank_nm != null && this.bank_nm.Equals("\r\n"))
                        {
                            string commandText = "update bank_info set port_nums=?,voltage=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=?  where id=" + this.id;
                            dbCommand.CommandText = commandText;
                            dbCommand.Parameters.Add(DBTools.GetParameter("@port_nums", this.portlists, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@voltage", this.voltage, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_power_diss", this.max_power_diss, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_power_diss", this.min_power_diss, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand));
                        }
                        else
                        {
                            string commandText = "update bank_info set port_nums=?,bank_nm=?,voltage=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=?  where id=" + this.id;
                            dbCommand.CommandText = commandText;
                            dbCommand.Parameters.Add(DBTools.GetParameter("@port_nums", this.portlists, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@bank_nm", this.bank_nm, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@voltage", this.voltage, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_voltage", this.max_voltage, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_voltage", this.min_voltage, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_power_diss", this.max_power_diss, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_power_diss", this.min_power_diss, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_power", this.max_power, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_power", this.min_power, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@max_current", this.max_current, dbCommand));
                            dbCommand.Parameters.Add(DBTools.GetParameter("@min_current", this.min_current, dbCommand));
                        }
                    }
                    int result = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    DBCacheStatus.Device = true;
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_Device"
                    });
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 14
0
        public int UpdateBankThreshold(DBConn conn)
        {
            if (this.id < 1)
            {
                return(-1);
            }
            if (this.device_id < 1)
            {
                return(-1);
            }
            DbCommand dbCommand = null;

            try
            {
                if (conn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(conn.con);
                    dbCommand.Connection  = conn.con;
                    dbCommand.CommandType = CommandType.Text;
                    string text = "update bank_info set bank_nm=?,voltage=?,max_voltage=?,min_voltage=?,max_power_diss=?,min_power_diss=?,max_power=?,min_power=?,max_current=?,min_current=?  where id=" + this.id;
                    text = "update bank_info set ";
                    if (!this.bank_nm.Equals("\r\n"))
                    {
                        text = text + "bank_nm='" + this.bank_nm + "',";
                    }
                    text = text + "voltage=" + CultureTransfer.ToString(this.voltage);
                    text = text + ",max_voltage=" + CultureTransfer.ToString(this.max_voltage);
                    text = text + ",min_voltage=" + CultureTransfer.ToString(this.min_voltage);
                    text = text + ",max_power_diss=" + CultureTransfer.ToString(this.max_power_diss);
                    text = text + ",min_power_diss=" + CultureTransfer.ToString(this.min_power_diss);
                    text = text + ",max_power=" + CultureTransfer.ToString(this.max_power);
                    text = text + ",min_power=" + CultureTransfer.ToString(this.min_power);
                    text = text + ",max_current=" + CultureTransfer.ToString(this.max_current);
                    text = text + ",min_current=" + CultureTransfer.ToString(this.min_current);
                    text = text + "  where id= " + this.id;
                    dbCommand.CommandText = text;
                    int result = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    dbCommand.Dispose();
                    return(result);
                }
            }
            catch (Exception ex)
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
            }
            return(-1);
        }
Exemplo n.º 15
0
        public int Update()
        {
            DBConn       dBConn       = null;
            OleDbCommand oleDbCommand = new OleDbCommand();

            try
            {
                dBConn = DBConnPool.getConnection();
                if (dBConn.con != null)
                {
                    OleDbTransaction transaction = (OleDbTransaction)dBConn.con.BeginTransaction();
                    oleDbCommand             = (OleDbCommand)dBConn.con.CreateCommand();
                    oleDbCommand.CommandType = CommandType.Text;
                    oleDbCommand.Transaction = transaction;
                    oleDbCommand.Parameters.Clear();
                    oleDbCommand.CommandText = "delete from group_detail where group_id = ? ";
                    oleDbCommand.Parameters.Add("?", OleDbType.Integer);
                    oleDbCommand.Prepare();
                    oleDbCommand.Parameters[0].Value = this.id;
                    int result;
                    try
                    {
                        oleDbCommand.ExecuteNonQuery();
                    }
                    catch
                    {
                        oleDbCommand.Transaction.Rollback();
                        result = -1;
                        return(result);
                    }
                    oleDbCommand.Parameters.Clear();
                    oleDbCommand.CommandText = string.Concat(new object[]
                    {
                        "insert into group_detail (group_id,grouptype,dest_id) values (",
                        this.id,
                        ",'",
                        this.group_type,
                        "',?)"
                    });
                    oleDbCommand.Parameters.Add("?", OleDbType.Integer);
                    oleDbCommand.Prepare();
                    string[] array = this.members.Split(new string[]
                    {
                        ","
                    }, StringSplitOptions.RemoveEmptyEntries);
                    string[] array2 = array;
                    for (int i = 0; i < array2.Length; i++)
                    {
                        string value = array2[i];
                        oleDbCommand.Parameters[0].Value = Convert.ToInt64(value);
                        int num = oleDbCommand.ExecuteNonQuery();
                        if (num < 0)
                        {
                            oleDbCommand.Transaction.Rollback();
                            result = num;
                            return(result);
                        }
                    }
                    oleDbCommand.Parameters.Clear();
                    oleDbCommand.CommandText = "update data_group set groupname= ?, grouptype = ?, linecolor = ?, isselect = ?, thermalflag = ?, billflag = ? where id = " + this.id;
                    oleDbCommand.Parameters.Add("?", OleDbType.VarChar);
                    oleDbCommand.Parameters.Add("?", OleDbType.VarChar);
                    oleDbCommand.Parameters.Add("?", OleDbType.VarChar);
                    oleDbCommand.Parameters.Add("?", OleDbType.Integer);
                    oleDbCommand.Parameters.Add("?", OleDbType.Integer);
                    oleDbCommand.Parameters.Add("?", OleDbType.Integer);
                    oleDbCommand.Parameters[0].Value = this.group_name;
                    oleDbCommand.Parameters[1].Value = this.group_type;
                    oleDbCommand.Parameters[2].Value = this.color;
                    oleDbCommand.Parameters[3].Value = Convert.ToInt32(this.isselected);
                    oleDbCommand.Parameters[4].Value = Convert.ToInt64(this.thermalflag);
                    oleDbCommand.Parameters[5].Value = Convert.ToInt64(this.billflag);
                    try
                    {
                        oleDbCommand.ExecuteNonQuery();
                    }
                    catch
                    {
                        oleDbCommand.Transaction.Rollback();
                        result = -1;
                        return(result);
                    }
                    oleDbCommand.Parameters.Clear();
                    oleDbCommand.Transaction.Commit();
                    DBCacheStatus.Group = true;
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_Group"
                    });
                    result = 1;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                oleDbCommand.Transaction.Rollback();
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                if (ex.Message.IndexOf(" duplicate values ") > 0)
                {
                    int result = -2;
                    return(result);
                }
            }
            finally
            {
                oleDbCommand.Dispose();
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 16
0
        public int UpdateSetting()
        {
            DBConn    dBConn    = null;
            DbCommand dbCommand = new OleDbCommand();

            try
            {
                dBConn = DBConnPool.getConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    if (DBUrl.SERVERMODE)
                    {
                        string commandText = "update smtpsetting set EnableSMTP=?EnableSMTP , ServerAddress=?ServerAddress , PortId=?PortId , EmailFrom=?EmailFrom , EmailTo=?EmailTo , SendEvent=?SendEvent , EnableAuth=?EnableAuth, Account=?Account, UserPwd=?UserPwd ";
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("?EnableSMTP", this.smtp_enable, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?ServerAddress", this.smtp_server, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?PortId", this.smtp_port, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?EmailFrom", this.smtp_from, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?EmailTo", this.smtp_to, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?SendEvent", this.smtp_event, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?EnableAuth", this.smtp_auth, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?Account", this.smtp_account, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("?UserPwd", this.smtp_pwd, dbCommand));
                    }
                    else
                    {
                        string commandText = "update smtpsetting set EnableSMTP=? , ServerAddress=? , PortId=? , EmailFrom=? , EmailTo=? , SendEvent=? , EnableAuth=?, Account=?, UserPwd=? ";
                        dbCommand.CommandText = commandText;
                        dbCommand.Parameters.Add(DBTools.GetParameter("@EnableSMTP", this.smtp_enable, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@ServerAddress", this.smtp_server, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@PortId", this.smtp_port, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@EmailFrom", this.smtp_from, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@EmailTo", this.smtp_to, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@SendEvent", this.smtp_event, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@EnableAuth", this.smtp_auth, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@Account", this.smtp_account, dbCommand));
                        dbCommand.Parameters.Add(DBTools.GetParameter("@UserPwd", this.smtp_pwd, dbCommand));
                    }
                    int num = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    DBCacheStatus.Smtp = true;
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_Smtp"
                    });
                    int result = num;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                if (ex.Message.IndexOf(" duplicate values ") > 0)
                {
                    int result = -2;
                    return(result);
                }
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 17
0
        public static int DeleteGroupByID(long l_id)
        {
            DBConn    dBConn    = null;
            DbCommand dbCommand = null;

            try
            {
                dBConn = DBConnPool.getConnection();
                if (dBConn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(dBConn.con);
                    dbCommand.CommandType = CommandType.Text;
                    string commandText = "delete from group_detail where group_id = " + l_id;
                    dbCommand.CommandText = commandText;
                    int result = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    dbCommand.CommandText = "delete from groupcontroltask where groupid = " + l_id;
                    result = dbCommand.ExecuteNonQuery();
                    dbCommand.CommandText = "delete from taskschedule where groupid = " + l_id;
                    result = dbCommand.ExecuteNonQuery();
                    dbCommand.CommandText = "delete from data_group where id = " + l_id;
                    result = dbCommand.ExecuteNonQuery();
                    dbCommand.CommandText = "delete from ugp where gid =" + l_id;
                    dbCommand.ExecuteNonQuery();
                    DBCacheStatus.Group     = true;
                    DBCacheStatus.GroupTask = true;
                    DBCacheStatus.User      = true;
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_Group"
                    });
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_GroupTask"
                    });
                    DBCacheStatus.DBSyncEventSet(true, new string[]
                    {
                        "DBSyncEventName_Service_User"
                    });
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
                if (dBConn != null)
                {
                    dBConn.close();
                }
            }
            return(-1);
        }
Exemplo n.º 18
0
        public static DataTable GetAllBankPD()
        {
            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 bank_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 bank_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);
        }
Exemplo n.º 19
0
        public void workQueue_DBWork(object sender, WorkQueue <string> .EnqueueEventArgs e)
        {
            try
            {
                if (!DBWorkThread.STOP_THREAD)
                {
                    string text = "";
                    if (TaskStatus.GetDBStatus() == -1)
                    {
                        try
                        {
                            this.con.Close();
                            this.con.Dispose();
                            this.con = null;
                        }
                        catch
                        {
                        }
                    }
                    if (this.con == null)
                    {
                        if (DBUrl.SERVERMODE)
                        {
                            string   cONNECT_STRING = DBUrl.CONNECT_STRING;
                            string[] array          = cONNECT_STRING.Split(new string[]
                            {
                                ","
                            }, StringSplitOptions.RemoveEmptyEntries);
                            this.con = new MySqlConnection(string.Concat(new string[]
                            {
                                "Database=eco",
                                DBUrl.SERVERID,
                                ";Data Source=",
                                array[0],
                                ";Port=",
                                array[1],
                                ";User Id=",
                                array[2],
                                ";Password="******";Pooling=true;Min Pool Size=0;Max Pool Size=50;Default Command Timeout=0;charset=utf8;"
                            }));
                            this.con.Open();
                        }
                        else
                        {
                            if (DBWorkThread.STOP_THREAD)
                            {
                                return;
                            }
                            switch (this.DBTYPE)
                            {
                            case 0:
                                break;

                            case 1:
                                try
                                {
                                    this.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;"
                                    }));
                                    this.con.Open();
                                    DebugCenter.GetInstance().clearStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                                    goto IL_2A6;
                                }
                                catch (Exception e2)
                                {
                                    DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                                    DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e2, false, "    "));
                                    goto IL_2A6;
                                }
                                break;

                            default:
                                goto IL_2A6;
                            }
                            try
                            {
                                "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBUrl.CURRENT_HOST_PATH + ";Jet OLEDB:Database Password="******"Waiting DBConnection : " + num);
                                    num++;
                                }
                                DBConn dynaConnection = DBConnPool.getDynaConnection();
                                if (dynaConnection != null)
                                {
                                    this.con = dynaConnection.con;
                                }
                                else
                                {
                                    this.con = null;
                                }
                            }
                            catch (Exception ex)
                            {
                                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                            }
                        }
                    }
                    try
                    {
IL_2A6:
                        if (this.con.State != ConnectionState.Open)
                        {
                            try
                            {
                                this.con.Close();
                                this.con.Open();
                            }
                            catch (Exception e3)
                            {
                                this.con = null;
                                DebugCenter.GetInstance().setLastStatusCode(DebugCenter.ST_MYSQLCONNECT_LOST, true);
                                DebugCenter.GetInstance().appendToFile("Could not create MySQL connection : \r\n" + CommonAPI.ReportException(0, e3, false, "    "));
                            }
                        }
                    }
                    catch
                    {
                    }
                    try
                    {
                        if (this.cmd != null)
                        {
                            this.cmd.Dispose();
                        }
                    }
                    catch (Exception ex2)
                    {
                        DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex2.Message + "\n" + ex2.StackTrace);
                    }
                    try
                    {
                        string item = e.Item;
                        if (item.StartsWith("PDEND"))
                        {
                            InSnergyGateway.Need_Calculate_PUE = true;
                            DBWorkThread.NEEDLOG = true;
                        }
                        else
                        {
                            if (item.IndexOf("END") > -1)
                            {
                                DBCacheStatus.LastInsertTime = DateTime.Now;
                                DBWorkThread.NEEDLOG         = true;
                            }
                            else
                            {
                                this.cmd = this.con.CreateCommand();
                                int num2 = this.NeedU2I(item);
                                if (this.DBTYPE == 1 || DBUrl.SERVERMODE)
                                {
                                    string commandText = item.Replace("#", "'");
                                    this.cmd.CommandText = commandText;
                                }
                                else
                                {
                                    this.cmd.CommandText = item;
                                }
                                text = this.cmd.CommandText;
                                if (!DBWorkThread.STOP_THREAD)
                                {
                                    int num3 = this.cmd.ExecuteNonQuery();
                                    if (num3 < 1 && num2 > 0)
                                    {
                                        if (this.DBTYPE == 1 || DBUrl.SERVERMODE)
                                        {
                                            string text2 = this.ChgU2I(item, num2);
                                            text2 = text2.Replace("#", "'");
                                            this.cmd.CommandText = text2;
                                        }
                                        else
                                        {
                                            this.cmd.CommandText = this.ChgU2I(item, num2);
                                        }
                                        text = this.cmd.CommandText;
                                        if (DBWorkThread.STOP_THREAD)
                                        {
                                            return;
                                        }
                                        this.cmd.ExecuteNonQuery();
                                    }
                                    this.cmd.Dispose();
                                    if (TaskStatus.GetDBStatus() == -1)
                                    {
                                        try
                                        {
                                            this.con.Close();
                                        }
                                        catch
                                        {
                                        }
                                        try
                                        {
                                            this.con.Dispose();
                                        }
                                        catch
                                        {
                                        }
                                        this.con = null;
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex3)
                    {
                        if (ex3.GetType().FullName.Equals("MySql.Data.MySqlClient.MySqlException"))
                        {
                            string tableName = DBUtil.GetTableName(text);
                            if (tableName != null && tableName.Length > 0)
                            {
                                DBUtil.SetMySQLInfo(tableName);
                                DebugCenter.GetInstance().appendToFile("MySQL database is marked as crashed, EcoSensor Monitor Service will be shutdown ");
                                DBUtil.StopService();
                            }
                        }
                        if (ex3.Message.ToLower().IndexOf("fatal error encountered during command execution") < 0)
                        {
                            if (text.IndexOf("rack_effect") > 0)
                            {
                                try
                                {
                                    DBTools.Write_DBERROR_Log();
                                    goto IL_56F;
                                }
                                catch
                                {
                                    goto IL_56F;
                                }
                            }
                            if (DBWorkThread.NEEDLOG)
                            {
                                try
                                {
                                    DBTools.Write_DBERROR_Log();
                                }
                                catch
                                {
                                }
                                DBWorkThread.NEEDLOG = false;
                            }
IL_56F:
                            DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex3.Message + "\n" + ex3.StackTrace);
                        }
                        try
                        {
                            this.cmd.Dispose();
                            this.con.Close();
                        }
                        catch (Exception)
                        {
                        }
                        this.con = null;
                    }
                }
            }
            finally
            {
                try
                {
                    if (this.con != null)
                    {
                        this.con.Close();
                    }
                    this.con = null;
                }
                catch
                {
                }
            }
        }
Exemplo n.º 20
0
        public int Update(DBConn conn)
        {
            string text = this.insert_time.ToString("yyyyMMdd");

            try
            {
                long num = Convert.ToInt64(this.power_consumption * 10000.0);
                if (DBUrl.SERVERMODE)
                {
                    string item = string.Concat(new object[]
                    {
                        "update bank_data_daily",
                        text,
                        " set power_consumption = power_consumption + ",
                        CultureTransfer.ToString((float)num),
                        " where bank_id = ",
                        this.bank_id,
                        " and insert_time = #",
                        this.insert_time.ToString("yyyy-MM-dd"),
                        "#"
                    });
                    string item2 = string.Concat(new object[]
                    {
                        "update bank_data_hourly",
                        text,
                        " set power_consumption = power_consumption + ",
                        CultureTransfer.ToString((float)num),
                        " where bank_id = ",
                        this.bank_id,
                        " and insert_time = #",
                        new DateTime(this.insert_time.Year, this.insert_time.Month, this.insert_time.Day, DateTime.Now.Hour, 30, 0).ToString("yyyy-MM-dd HH:mm:ss"),
                        "#"
                    });
                    WorkQueue <string> .getInstance_pd().WorkSequential = true;

                    WorkQueue <string> .getInstance_pd().EnqueueItem(item);

                    WorkQueue <string> .getInstance_pd().EnqueueItem(item2);
                }
                else
                {
                    if (DBUrl.DB_CURRENT_TYPE.Equals("MYSQL"))
                    {
                        string item3 = string.Concat(new object[]
                        {
                            "update bank_data_daily",
                            text,
                            " set power_consumption = power_consumption + ",
                            CultureTransfer.ToString((float)num),
                            " where bank_id = ",
                            this.bank_id,
                            " and insert_time = #",
                            this.insert_time.ToString("yyyy-MM-dd"),
                            "#"
                        });
                        string item4 = string.Concat(new object[]
                        {
                            "update bank_data_hourly",
                            text,
                            " set power_consumption = power_consumption + ",
                            CultureTransfer.ToString((float)num),
                            " where bank_id = ",
                            this.bank_id,
                            " and insert_time = #",
                            new DateTime(this.insert_time.Year, this.insert_time.Month, this.insert_time.Day, DateTime.Now.Hour, 30, 0).ToString("yyyy-MM-dd HH:mm:ss"),
                            "#"
                        });
                        WorkQueue <string> .getInstance_pd().WorkSequential = true;

                        WorkQueue <string> .getInstance_pd().EnqueueItem(item3);

                        WorkQueue <string> .getInstance_pd().EnqueueItem(item4);
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        list.Add(string.Concat(this.bank_id));
                        list.Add(this.insert_time.ToString("yyyy-MM-dd HH:mm:ss"));
                        list.Add("bank_data_daily");
                        list.Add(CultureTransfer.ToString((float)num));
                        MinuteDataProcess.GetInstance().PutItem(list);
                        List <string> list2 = new List <string>();
                        list2.Add(string.Concat(this.bank_id));
                        list2.Add(this.insert_time.ToString("yyyy-MM-dd HH:mm:ss"));
                        list2.Add("bank_data_hourly");
                        list2.Add(CultureTransfer.ToString((float)num));
                        MinuteDataProcess.GetInstance().PutItem(list2);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
            return(0);
        }
Exemplo n.º 21
0
        public static void InsertDevicePower(int i_deviceid, double f_power, DateTime dt_inserttime, DBConn conn)
        {
            try
            {
                long num = Convert.ToInt64(f_power * 10000.0);
                if (DBUrl.SERVERMODE)
                {
                    string item = string.Concat(new object[]
                    {
                        "insert into device_auto_info",
                        dt_inserttime.ToString("yyyyMMdd"),
                        " (device_id,power,insert_time ) values(",
                        i_deviceid,
                        ",",
                        num,
                        ",#",
                        dt_inserttime.ToString("yyyy-MM-dd HH:mm:ss"),
                        "#)"
                    });
                    WorkQueue <string> .getInstance().WorkSequential = true;

                    WorkQueue <string> .getInstance().EnqueueItem(item);
                }
                else
                {
                    if (DBUrl.DB_CURRENT_TYPE.Equals("MYSQL"))
                    {
                        string item2 = string.Concat(new object[]
                        {
                            "insert into device_auto_info",
                            dt_inserttime.ToString("yyyyMMdd"),
                            " (device_id,power,insert_time ) values(",
                            i_deviceid,
                            ",",
                            num,
                            ",#",
                            dt_inserttime.ToString("yyyy-MM-dd HH:mm:ss"),
                            "#)"
                        });
                        WorkQueue <string> .getInstance().WorkSequential = true;

                        WorkQueue <string> .getInstance().EnqueueItem(item2);
                    }
                    else
                    {
                        List <string> list = new List <string>();
                        list.Add(string.Concat(i_deviceid));
                        list.Add(dt_inserttime.ToString("yyyy-MM-dd HH:mm:ss"));
                        list.Add("device_auto_info");
                        list.Add(string.Concat(num));
                        PDDataProcess.GetInstance().PutItem(list);
                    }
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
            }
        }
Exemplo n.º 22
0
        public int UpdateSensorThreshold(DBConn conn)
        {
            if (this.id < 1)
            {
                return(-1);
            }
            if (this.device_id < 1)
            {
                return(-1);
            }
            DbCommand dbCommand = new OleDbCommand();

            try
            {
                if (conn.con != null)
                {
                    dbCommand             = DBConn.GetCommandObject(conn.con);
                    dbCommand.CommandType = CommandType.Text;
                    string text = "update device_sensor_info set max_humidity=?,min_humidity=?,max_temperature=?,min_temperature=?,max_press=?,min_press=?  where id=" + this.id;
                    text = "update device_sensor_info set ";
                    text = text + "max_humidity=" + CultureTransfer.ToString(this.max_humidity);
                    text = text + ",min_humidity=" + CultureTransfer.ToString(this.min_humidity);
                    text = text + ",max_temperature=" + CultureTransfer.ToString(this.max_temperature);
                    text = text + ",min_temperature=" + CultureTransfer.ToString(this.min_temperature);
                    text = text + ",max_press=" + CultureTransfer.ToString(this.max_press);
                    text = text + ",min_press=" + CultureTransfer.ToString(this.min_press);
                    text = text + "  where id= " + this.id;
                    dbCommand.CommandText = text;
                    int result = dbCommand.ExecuteNonQuery();
                    dbCommand.Parameters.Clear();
                    try
                    {
                        dbCommand.Dispose();
                    }
                    catch
                    {
                    }
                    return(result);
                }
            }
            catch (Exception ex)
            {
                DebugCenter.GetInstance().appendToFile("DBERROR~~~~~~~~~~~DBERROR : " + ex.Message + "\n" + ex.StackTrace);
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
            }
            finally
            {
                try
                {
                    dbCommand.Dispose();
                }
                catch
                {
                }
            }
            return(-1);
        }