示例#1
0
        public int GetCurrentSid(string tableName)
        {
            try
            {
                string connectionString = new DBConnectionString().ToString();
                this.conn = new MySqlConnection(connectionString);
                this.conn.Open();
                this.cmd = this.conn.CreateCommand();

                string query = string.Format("select max(Sid) from {0} ", tableName);
                this.cmd.CommandText = query;

                using (var reader = this.cmd.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        int sid = reader.GetInt32(0);
                        return sid;
                    }
                }

                conn.Close();
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
            return 1;
        }
示例#2
0
文件: DataSource.cs 项目: oisy/scada
 internal MySqlConnection GetDBConnection()
 {
     string connectionString = new DBConnectionString().ToString();
     var conn = new MySqlConnection(connectionString);
     conn.Open();
     return conn;
 }
示例#3
0
 private void Initialize()
 {
     string connectionString = new DBConnectionString().ToString();
     this.conn = new MySqlConnection(connectionString);
     this.conn.Open();
     this.cmd = this.conn.CreateCommand();
 }
示例#4
0
        /// <summary>
        /// 
        /// </summary>
        public DBDataProvider()
        {
            this.allDeviceKeys.Add(DeviceKey_Hpic);
            this.allDeviceKeys.Add(DeviceKey_Dwd);
            this.allDeviceKeys.Add(DeviceKey_HvSampler);
            this.allDeviceKeys.Add(DeviceKey_ISampler);
            this.allDeviceKeys.Add(DeviceKey_NaI);
            this.allDeviceKeys.Add(DeviceKey_Shelter);
            this.allDeviceKeys.Add(DeviceKey_Weather);

            this.FetchCount = 26;

            this.dataListeners = new Dictionary<string, DBDataCommonListerner>(30);

            // 192.168.1.24
            string installPath = Assembly.GetExecutingAssembly().Location;
            string fileName = string.Format("{0}\\..\\local.ip", installPath);
            var s = new DBConnectionString();
            s.Address = "127.0.0.1";
            if (File.Exists(fileName))
            {
                using (StreamReader sr = new StreamReader(fileName))
                {
                    string ip = sr.ReadLine();
                    if (ip != null && ip.Length > 0)
                    {
                        s.Address = ip;
                    }
                }
            }

            this.ConnectionString = s.ToString();
            this.conn = new MySqlConnection(this.ConnectionString);

            if (this.conn != null)
            {
                try
                {
                    this.conn.Open();
                    this.cmd = this.conn.CreateCommand();
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                }
            }

            // 192.168.1.24

            this.timelineSource = new List<Dictionary<string, object>>();
        }
示例#5
0
 /// <summary>
 /// 
 /// </summary>
 private DBDataSource()
 {
     try
     {
         string connectionString = new DBConnectionString().ToString();
         this.conn = new MySqlConnection(connectionString);
         this.conn.Open();
         this.cmd = this.conn.CreateCommand();
     }
     catch (Exception e)
     {
         string msg = e.Message;
     }
 }
示例#6
0
        internal void Import()
        {
            var connectionString = new DBConnectionString().ToString();
            using (var connToMySql = new MySqlConnection(connectionString))
            {
                connToMySql.Open();

                MySqlCommand cmd = connToMySql.CreateCommand();

                string sql = string.Format("LOAD DATA INFILE '{0}' IGNORE INTO TABLE scada.hpic_rec FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' lines terminated by '\n' (time,Doserate,Highvoltage,Battery,Temperature);", this.csvFile);
                cmd.CommandText = sql;

                cmd.ExecuteNonQuery();
            }
        }
示例#7
0
        internal void CreateDAQDB()
        {
            var s = new DBConnectionString();
            s.Database = "mysql";
            this.connectionString = new DBConnectionString().ToString();
            using (var connToMySql = new MySqlConnection(this.connectionString))
            {
                connToMySql.Open();

                MySqlCommand cmd = connToMySql.CreateCommand();
                cmd.CommandText = "CREATE DATABASE if NOT EXISTS scada";
                cmd.ExecuteNonQuery();
                cmd.Dispose();
            }
        }
示例#8
0
 public void Connect()
 {
     try
     {
         string connectionString = new DBConnectionString().ToString();
         this.conn = new MySqlConnection(connectionString);
         this.conn.Open();
         this.cmd = this.conn.CreateCommand();
     }
     catch (Exception e)
     {
         RecordManager.DoSystemEventRecord(Device.Main, e.Message, RecordType.Error);
         
         // disable RetryConnection      by Kaikai
         //this.RetryConnection(e);
     }
 }
示例#9
0
 public MySqlConnection CreateMySqlConnection()
 {
     string connectionString = new DBConnectionString().ToString();
     return new MySqlConnection(connectionString);
 }
示例#10
0
        public void Connect()
        {
            try
            {
                string connectionString = new DBConnectionString().ToString();
                this.conn = new MySqlConnection(connectionString);
                this.conn.Open();
                this.cmd = this.conn.CreateCommand();

                // AddHPICRecordData("243.5", "2.3", "5.88", "24.0000", 2);
                // AddHPICRecordData("243.5", "2.3", "5.88", "24.0000", 2);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.Message);
            }
        }
示例#11
0
        public MySqlConnection GetMySqlConnection()
        {
            string installPath = Assembly.GetExecutingAssembly().Location;
            string fileName = string.Format("{0}\\..\\local.ip", installPath);

            var s = new DBConnectionString();
            s.Address = "127.0.0.1";
            if (File.Exists(fileName))
            {
                using (StreamReader sr = new StreamReader(fileName))
                {
                    string ip = sr.ReadLine();
                    if (ip != null && ip.Length > 0)
                    {
                        s.Address = ip;
                    }
                }
            }
            this.ConnectionString = s.ToString();
            var conn = new MySqlConnection(this.ConnectionString);

            if (conn != null)
            {
                try
                {
                    conn.Open();
                    return conn;
                }
                catch (Exception e)
                {
                    string msg = e.Message;
                }
            }
            return null;
        }