Exemple #1
0
        // Add PlugRTData to DataBase-PlugRTData Table
        public static bool AddPlugRTData(PlugRTData plugrtdata, string dbPath)
        {
            try
            {
                SQLiteConnection conn = new SQLiteConnection("Data Source=" + dbPath + ";");
                conn.Open();
                SQLiteCommand cmd = conn.CreateCommand();
                cmd.CommandText = @"INSERT INTO PlugRTData(PlugID, UpTime, V, I, P, Q1, S, S1, PF, PF1, SN, N, THDI, ECounter, PCounter, Freq, RelayState, TransmitInternal, DateTime)
                                     VALUES(@_PlugID, @_UpTime, @_V, @_I, @_P, @_Q1, @_S, @_S1, @_PF, @_PF1, @_SN, @_N, @_THDI, @_ECounter, @_PCounter, @_Freq, @_RelayState, @_TransmitInternal, @_DateTime)";

                cmd.Parameters.Add(new SQLiteParameter("_PlugID", plugrtdata.PlugID));
                cmd.Parameters.Add(new SQLiteParameter("_UpTime", plugrtdata.UpTime));
                cmd.Parameters.Add(new SQLiteParameter("_V", plugrtdata.V));
                cmd.Parameters.Add(new SQLiteParameter("_I", plugrtdata.I));
                cmd.Parameters.Add(new SQLiteParameter("_P", plugrtdata.P));
                cmd.Parameters.Add(new SQLiteParameter("_Q1", plugrtdata.Q1));
                cmd.Parameters.Add(new SQLiteParameter("_S", plugrtdata.S));
                cmd.Parameters.Add(new SQLiteParameter("_S1", plugrtdata.S1));
                cmd.Parameters.Add(new SQLiteParameter("_PF", plugrtdata.PF));
                cmd.Parameters.Add(new SQLiteParameter("_PF1", plugrtdata.PF1));
                cmd.Parameters.Add(new SQLiteParameter("_SN", plugrtdata.SN));
                cmd.Parameters.Add(new SQLiteParameter("_N", plugrtdata.N));
                cmd.Parameters.Add(new SQLiteParameter("_THDI", plugrtdata.THDI));
                cmd.Parameters.Add(new SQLiteParameter("_ECounter", plugrtdata.ECounter));
                cmd.Parameters.Add(new SQLiteParameter("_PCounter", plugrtdata.PCounter));
                cmd.Parameters.Add(new SQLiteParameter("_Freq", plugrtdata.Freq));
                cmd.Parameters.Add(new SQLiteParameter("_RelayState", plugrtdata.RelayState));
                cmd.Parameters.Add(new SQLiteParameter("_TransmitInternal", plugrtdata.TransmitInterval));
                cmd.Parameters.Add(new SQLiteParameter("_DateTime", plugrtdata.AddDateTime));

                int i = cmd.ExecuteNonQuery();
                return(i == 1);
            }
            catch (SQLiteException se)
            {
                MessageBox.Show(se.Message + " \n\n" + se.Source + "\n\n" + se.StackTrace + "\n\n" + se.Data);
                return(false);
            }
            catch (ArgumentException ae)
            {
                MessageBox.Show(ae.Message + " \n\n" + ae.Source + "\n\n" + ae.StackTrace + "\n\n" + ae.Data);
                return(false);
            }
            catch (Exception ex)
            {
                //Do any logging operation here if necessary
                MessageBox.Show(ex.Message + "\n\n" + ex.Source + "\n\n" + ex.StackTrace + "\n\n" + ex.Data);
                return(false);
            }
        }
Exemple #2
0
        private void SimulateDataTimer_Tick(object sender, EventArgs e)
        {
            Random _rand = new Random(DateTime.Now.Millisecond);

            PlugRTData plugrtdata = new PlugRTData();

            uptime += 2;

            plugrtdata.PlugID           = 3813057585;
            plugrtdata.UpTime           = uptime;
            plugrtdata.V                = _rand.Next(210, 230);
            plugrtdata.I                = _rand.Next(0, 10);
            plugrtdata.P                = _rand.Next(0, 2300);
            plugrtdata.Q1               = _rand.Next(0, 100);
            plugrtdata.S                = _rand.Next(0, 2400);
            plugrtdata.S1               = _rand.Next(0, 2350);
            plugrtdata.PF               = _rand.Next(0, 1);
            plugrtdata.PF1              = _rand.Next(0, 1);
            plugrtdata.SN               = _rand.Next(0, 100);
            plugrtdata.N                = _rand.Next(0, 100);
            plugrtdata.THDI             = _rand.Next(0, 100);
            plugrtdata.ECounter         = _rand.Next(0, 10);
            plugrtdata.PCounter         = _rand.Next(0, 10);
            plugrtdata.Freq             = 50;
            plugrtdata.RelayState       = true;
            plugrtdata.TransmitInterval = 2;
            plugrtdata.AddDateTime      = DateTime.Now;

            try
            {
                SmartPlugDAL.AddPlugRTData(plugrtdata, SqliteDBPath);
            }
            catch
            {
            }
        }