Ejemplo n.º 1
0
        private void WebserviceTimer_Tick(object sender, EventArgs e)
        {
            MenuItem       item       = (MenuItem)cbSensor.SelectedItem;
            String         webservice = (String)item.Tag;
            HttpWebRequest request    = (HttpWebRequest)WebRequest.Create(webservice);

            //onglet network F12 qui permet de voir ce qu'on envoie en header
            request.UserAgent = "Mozilla(Gecko 1.2.13)";
            request.Method    = "GET";
            WebResponse  response      = request.GetResponse();
            Stream       receiveStream = response.GetResponseStream();
            StreamReader readStream    = new StreamReader(receiveStream, Encoding.UTF8);

            Console.WriteLine("Response stream received.");



            JObject obj = JObject.Parse(readStream.ReadToEnd());

            String dataDate    = (String)obj["date"];
            String humidity    = (String)obj["humidity"];
            String temperature = (String)obj["temperature"];

            String query = "INSERT INTO data(data_date,temperature,humidity,import_date,sensor) " +
                           "VALUES(@data_date, @temperature, @humidity, @import_date, @sensor)";
            Dictionary <String, String> parameters = new Dictionary <String, String>()
            {
                { "@data_date", dataDate },
                { "@temperature", temperature },
                { "@humidity", humidity },
                { "@import_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
                { "@sensor", item.Name },
            };

            try
            {
                DBInteractor.QuickExecute(query, parameters);
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERREUR : Impossible de se connecter à la base de données...\n\r\n\r" +
                                ex.Message + "\n\r" + ex.StackTrace);
            }

            //MessageBox.Show("L'insertion de vos données a été effectuée avec succès");

            response.Close();
            readStream.Close();
            synthesis.DisplaySynthesis();
        }
Ejemplo n.º 2
0
        public MainForm()
        {
            InitializeComponent();

            webserviceTimer          = new Timer();
            webserviceTimer.Interval = 5000;
            webserviceTimer.Tick    += WebserviceTimer_Tick;


            //Instantiation du formulaire enfant
            import = new ImportForm();
            //Définition en formulaire inclus
            import.TopLevel = false;
            //Agrandissement à la taille du panel conteneur
            import.Dock = DockStyle.Fill;
            //Ajout du formulaire au panel principal
            pnlMain.Controls.Add(import);

            synthesis          = new SynthesisForm();
            synthesis.TopLevel = false;
            synthesis.Dock     = DockStyle.Fill;
            pnlMain.Controls.Add(synthesis);

            data          = new DataForm();
            data.TopLevel = false;
            data.Dock     = DockStyle.Fill;
            pnlMain.Controls.Add(data);

            sensor          = new SensorForm();
            sensor.TopLevel = false;
            sensor.Dock     = DockStyle.Fill;
            pnlMain.Controls.Add(sensor);

            refreshSensorMain();

            dtpStart.Value = new DateTime(DateTime.Now.Year, 1, 1);
            dtpEnd.Value   = DateTime.Now.AddDays(1);

            HideForms();
            synthesis.Show();
            synthesis.DisplaySynthesis();
            synthesis.chTemp_Load();
        }