Esempio n. 1
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 port_data_daily",
                        text,
                        " set power_consumption = power_consumption + ",
                        CultureTransfer.ToString((float)num),
                        " where port_id = ",
                        this.port_id,
                        " and insert_time = #",
                        this.insert_time.ToString("yyyy-MM-dd"),
                        "#"
                    });
                    string item2 = string.Concat(new object[]
                    {
                        "update port_data_hourly",
                        text,
                        " set power_consumption = power_consumption + ",
                        CultureTransfer.ToString((float)num),
                        " where port_id = ",
                        this.port_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 port_data_daily",
                            text,
                            " set power_consumption = power_consumption + ",
                            CultureTransfer.ToString((float)num),
                            " where port_id = ",
                            this.port_id,
                            " and insert_time = #",
                            this.insert_time.ToString("yyyy-MM-dd"),
                            "#"
                        });
                        string item4 = string.Concat(new object[]
                        {
                            "update port_data_hourly",
                            text,
                            " set power_consumption = power_consumption + ",
                            CultureTransfer.ToString((float)num),
                            " where port_id = ",
                            this.port_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.port_id));
                        list.Add(this.insert_time.ToString("yyyy-MM-dd HH:mm:ss"));
                        list.Add("port_data_daily");
                        list.Add(CultureTransfer.ToString((float)num));
                        MinuteDataProcess.GetInstance().PutItem(list);
                        List <string> list2 = new List <string>();
                        list2.Add(string.Concat(this.port_id));
                        list2.Add(this.insert_time.ToString("yyyy-MM-dd HH:mm:ss"));
                        list2.Add("port_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);
        }
Esempio n. 2
0
        private void CompactThread()
        {
            Interlocked.Exchange(ref this._threadDone, 0);
            int arg_12_0 = Environment.TickCount;

            try
            {
                File.Delete(this._dstDatabasePath);
                this._result = this.CompactDB(this._srcDatabasePath, this._dstDatabasePath, this._password);
                string text = "";
                if (this._result)
                {
                    text = this._dstDatabasePath;
                }
                else
                {
                    text = this._srcDatabasePath;
                }
                int num = DBTools.ShudownAccess();
                if (num > 0)
                {
                    try
                    {
                        if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "datadb.mdb") && File.Exists(text))
                        {
                            string text2 = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("yyyyMMddHHmmss") + "_tmpdatadb.mdb";
                            bool   flag  = true;
                            int    num2  = 0;
                            while (flag && num2 < 5)
                            {
                                try
                                {
                                    FileInfo fileInfo = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "datadb.mdb");
                                    fileInfo.MoveTo(text2);
                                    FileInfo fileInfo2 = new FileInfo(text);
                                    fileInfo2.MoveTo(AppDomain.CurrentDomain.BaseDirectory + "datadb.mdb");
                                    flag = false;
                                    TaskStatus.TMPDB_path = text2;
                                    try
                                    {
                                        File.Delete(TaskStatus.DB_compact_tmp);
                                        TaskStatus.DB_compact_tmp = "";
                                    }
                                    catch
                                    {
                                    }
                                    TaskStatus.SetDBStatus(1);
                                }
                                catch (Exception)
                                {
                                }
                                num2++;
                            }
                            if (flag)
                            {
                                TaskStatus.SetDBStatus(1);
                            }
                            else
                            {
                                OleDbConnection oleDbConnection = null;
                                OleDbCommand    oleDbCommand    = new OleDbCommand();
                                try
                                {
                                    string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + TaskStatus.TMPDB_path + ";Jet OLEDB:Database Password=root";
                                    oleDbConnection = new OleDbConnection(connectionString);
                                    oleDbConnection.Open();
                                    oleDbCommand = oleDbConnection.CreateCommand();
                                    try
                                    {
                                        oleDbCommand.CommandText = "select device_id,power_consumption,insert_time from device_data_daily ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item = string.Concat(new string[]
                                            {
                                                "update device_data_daily set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where device_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select device_id,power_consumption,insert_time from device_data_hourly ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item2 = string.Concat(new string[]
                                            {
                                                "update device_data_hourly set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where device_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item2);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select bank_id,power_consumption,insert_time from bank_data_hourly ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item3 = string.Concat(new string[]
                                            {
                                                "update bank_data_hourly set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where bank_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item3);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select bank_id,power_consumption,insert_time from bank_data_daily ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item4 = string.Concat(new string[]
                                            {
                                                "update bank_data_daily set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where bank_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item4);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select port_id,power_consumption,insert_time from port_data_daily ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item5 = string.Concat(new string[]
                                            {
                                                "update port_data_daily set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where port_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item5);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select port_id,power_consumption,insert_time from port_data_hourly ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item6 = string.Concat(new string[]
                                            {
                                                "update port_data_hourly set power_consumption = power_consumption + ",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                " where port_id = ",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                " and insert_time = #",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#"
                                            });
                                            WorkQueue <string> .getInstance_pd().WorkSequential = true;

                                            WorkQueue <string> .getInstance_pd().EnqueueItem(item6);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select device_id,power,insert_time from device_auto_info ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item7 = string.Concat(new string[]
                                            {
                                                "insert into device_auto_info (device_id,power,insert_time ) values(",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                ",",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                ",#",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#)"
                                            });
                                            WorkQueue <string> .getInstance().WorkSequential = true;

                                            WorkQueue <string> .getInstance().EnqueueItem(item7);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select bank_id,power,insert_time from bank_auto_info ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item8 = string.Concat(new string[]
                                            {
                                                "insert into bank_auto_info (bank_id,power,insert_time ) values(",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                ",",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                ",#",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#)"
                                            });
                                            WorkQueue <string> .getInstance().WorkSequential = true;

                                            WorkQueue <string> .getInstance().EnqueueItem(item8);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    try
                                    {
                                        oleDbCommand.CommandText = "select port_id,power,insert_time from port_auto_info ";
                                        OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
                                        while (oleDbDataReader.Read())
                                        {
                                            string item9 = string.Concat(new string[]
                                            {
                                                "insert into port_auto_info (port_id,power,insert_time ) values(",
                                                Convert.ToString(oleDbDataReader.GetValue(0)),
                                                ",",
                                                Convert.ToString(oleDbDataReader.GetValue(1)),
                                                ",#",
                                                Convert.ToDateTime(oleDbDataReader.GetValue(2)).ToString("yyyy-MM-dd HH:mm:ss"),
                                                "#)"
                                            });
                                            WorkQueue <string> .getInstance().WorkSequential = true;

                                            WorkQueue <string> .getInstance().EnqueueItem(item9);
                                        }
                                        oleDbDataReader.Close();
                                    }
                                    catch
                                    {
                                    }
                                    oleDbCommand.Dispose();
                                    oleDbConnection.Close();
                                    try
                                    {
                                        TaskStatus.DB_compact_final = "";
                                        File.Delete(TaskStatus.TMPDB_path);
                                    }
                                    catch
                                    {
                                    }
                                    DebugCenter.GetInstance().appendToFile("Finish compact Access Database ");
                                }
                                catch (Exception)
                                {
                                    oleDbCommand.Dispose();
                                    if (oleDbConnection != null)
                                    {
                                        oleDbConnection.Close();
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
            catch (Exception)
            {
            }
            Interlocked.Exchange(ref this._threadDone, 1);
        }