Exemplo n.º 1
0
        private void mrbSensorRegister_Click(object sender, EventArgs e)
        {
            try
            {
                Form     form = this.ParentForm;
                MainForm main = (MainForm)form;

                Dictionary <String, String> parameters = new Dictionary <String, String>();
                parameters["@label"]      = msltfLabelSensor.Text;
                parameters["@webservice"] = msltfWebServiceSensor.Text;
                parameters["@uid"]        = msltfUIDSensor.Text;
                if (idSensor != null)
                {
                    DBInteractor.QuickExecute("UPDATE sensor SET label = '" + msltfLabelSensor.Text + "', webservice = '"
                                              + msltfWebServiceSensor.Text + "', uid = '" + msltfUIDSensor.Text + "' WHERE id = " + idSensor);
                    idSensor = null;
                }
                else
                {
                    DBInteractor.QuickExecute("INSERT INTO sensor (label,webservice,uid) VALUE(@label,@webservice,@uid)", parameters);
                }
                main.refreshSensorMain();
                msltfLabelSensor.Text      = "";
                msltfWebServiceSensor.Text = "";
                msltfUIDSensor.Text        = "";
                refreshSensor();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Erreur lors de l'ajout " + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
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();
        }
Exemplo n.º 3
0
        private void dgBase_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 5)

            {
                int    row       = e.RowIndex;
                object object_id = dgBase.Rows[row].Tag;
                String id        = (String)object_id;

                DialogResult result = MessageBox.Show("Etes vous sur de vouloir supprimer les entrees", "Confirmation de suppresion", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }

                String query = "DELETE FROM data WHERE id = " + id;
                DBInteractor.QuickExecute(query);

                DisplayData();
            }
        }
Exemplo n.º 4
0
        private void dgvSensor_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 4)
            {
                Form     form = this.ParentForm;
                MainForm main = (MainForm)form;

                int    row       = e.RowIndex;
                object object_id = dgvSensor.Rows[row].Tag;
                String id        = (String)object_id;

                DialogResult result = MessageBox.Show("Etes vous sur de vouloir supprimer ce capteur ? Toutes les données y étant attaché vont être aussi supprimé ! "
                                                      , "Confirmation de suppresion", MessageBoxButtons.YesNo);
                if (result == DialogResult.No)
                {
                    return;
                }
                String queryData   = "DELETE FROM data WHERE sensor = " + id;
                String querySensor = "DELETE FROM sensor WHERE id = " + id;
                DBInteractor.QuickExecute(queryData);
                DBInteractor.QuickExecute(querySensor);
                refreshSensor();
                main.refreshSensorMain();
                DisplaySensor();
            }
            if (e.ColumnIndex == 3)
            {
                int    row       = e.RowIndex;
                object object_id = dgvSensor.Rows[row].Tag;
                String id        = (String)object_id;

                List <Dictionary <String, String> > resultSensor = DBInteractor.QuickSelect("SELECT * FROM sensor WHERE id = " + id);
                msltfLabelSensor.Text      = resultSensor[0]["label"];
                msltfWebServiceSensor.Text = resultSensor[0]["webservice"];
                msltfUIDSensor.Text        = resultSensor[0]["uid"];
                idSensor = resultSensor[0]["id"];
            }
        }
Exemplo n.º 5
0
 private void dgBase_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
 {
     try
     {
         object object_id = e.Row.Tag;
         String id        = (String)object_id;
         String query     = "DELETE FROM data WHERE id = " + id;
         //Dictionary<String, String> parameters = new Dictionary<string, string>();
         //DBInteractor db = new DBInteractor();
         DBInteractor.QuickExecute(query);
     }
     catch (Exception)
     {
         DataGridViewCellStyle style = new DataGridViewCellStyle();
         style.BackColor      = Color.Red;
         e.Row.Cells[0].Style = style;
         //MessageBox.Show("Erreur lors de la suppression :" + ex.Message, "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         //errorSupp.Add(ex.Message);
         //int sizeOfList = errorSupp.Count;
         errorCpt++;
         lblDatas.Text = "Le nombre d'erreur est : " + errorCpt;
         e.Cancel      = true;
     }
 }
Exemplo n.º 6
0
        private void btnClick_Import(object sender, EventArgs e)
        {
            try {
                OpenFileDialog pickedfile = new OpenFileDialog();
                //on récupère le formulaire parent de l'import form, il ns renvoie que le type du dessus
                //le parent c'est en fait le MainForm
                //Form.cb ne nous donne pas accès au sensor, c'est le MainForm qui contient la combobox
                //on cast le form parent en MainForm pour avoir le bon type
                //la cb ne peut tjs pas être récupérée car elle est en privé, dc on va faire un get ds MainForm

                if (pickedfile.ShowDialog() == DialogResult.OK)
                {
                    Form     form   = this.ParentForm;
                    MainForm main   = (MainForm)form;
                    String   sensor = main.getSensor();
                    if (sensor == "")
                    {
                        throw new Exception("Merci de sélectionner un capteur");
                    }
                    if (!File.Exists(pickedfile.FileName))
                    {
                        throw new Exception("Fichier Inexistant");
                    }

                    long finfo = new FileInfo(pickedfile.FileName).Length;
                    if (finfo == 0)
                    {
                        throw new Exception("Fichier vide");
                    }

                    String[]   content         = File.ReadAllLines(pickedfile.FileName);
                    List <int> unformatedLines = new List <int>();

                    for (int lineNumber = 1; lineNumber < content.Length; lineNumber++)
                    {
                        String[] columns = content[lineNumber].Split(' ');
                        if (columns.Length != 5)
                        {
                            unformatedLines.Add(lineNumber + 1);
                        }
                    }

                    if (unformatedLines.Count > 0)
                    {
                        throw new Exception("Certaines lignes sont mal formatées : \n\r" + String.Join(", ", unformatedLines.ToArray())
                                            + "\n\rVeuillez reformater votre fichier");
                    }

                    List <int> nonExecutedQueries = new List <int>();

                    //On itère sur chaque ligne du fichier sélectionné
                    for (int i = 0; i < content.Length; i++)
                    {
                        //on split sur les espace, on a autant d'éléments ds le tableau que de colonnes ds le fichier
                        String[] columns = content[i].Split(' ');

                        String humidity    = Regex.Replace(columns[4], "%", "");
                        String temperature = columns[3];
                        String dataDate    = columns[1] + " " + columns[2];
                        try
                        {
                            DBInteractor.QuickExecute("INSERT INTO data(data_date,temperature,humidity,import_date,sensor) " +
                                                      "VALUES(@data_date, @temperature, @humidity, @import_date, @sensor)",
                                                      new Dictionary <String, String>()
                            {
                                { "@data_date", dataDate },
                                { "@temperature", temperature },
                                { "@humidity", humidity },
                                { "@import_date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") },
                                { "@sensor", sensor },
                            });
                        }
                        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");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("ERREUR : " + ex.Message);
            }
        }