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(); }
public void ExportDataPDF(string filePath) { FileStream fs = new FileStream(filePath, FileMode.Create); // Create an instance of the document class which represents the PDF document itself. Document doc = new Document(PageSize.A4, 25, 25, 30, 30); // Create an instance to the PDF file by creating an instance of the PDF // Writer class using the document and the filestream in the constructor. PdfWriter writer = PdfWriter.GetInstance(doc, fs); // Open the document to enable you to write to the document doc.Open(); // Add a simple and wellknown phrase to the document in a flow layout manner doc.Add(new Paragraph("Rapport de données relatives à un capteur")); doc.Add(new Paragraph("" + Environment.NewLine)); Form form = this.ParentForm; MainForm main = (MainForm)form; SynthesisForm synthesis = main.getSynthesis(); doc.Add(new Paragraph("Nom du capteur : " + main.getSynthesis().tfLabel.Text)); doc.Add(new Paragraph("UID du capteur : " + main.getSynthesis().tfUID.Text)); doc.Add(new Paragraph("Date et heure du premier relevé : " + main.getSynthesis().tfdtStart.Text)); doc.Add(new Paragraph("Date et heure du dernier relevé : " + main.getSynthesis().tfdtEnd.Text)); doc.Add(new Paragraph("Nombre de relevés : " + main.getSynthesis().tfNbr.Text)); doc.Add(new Paragraph("Amplitude temporelle des relevés : " + main.getSynthesis().tfAmplitude.Text)); doc.Add(new Paragraph("Température Minimum / Moyenne / Maximum : " + main.getSynthesis().mlMinTempData.Text + " / " + main.getSynthesis().mlMedTempData.Text + " / " + main.getSynthesis().mlMaxTempData.Text)); doc.Add(new Paragraph("Humidité Minimum / Moyenne / Maximum : " + main.getSynthesis().mlMinHumidData.Text + " / " + main.getSynthesis().mlMedHumidData.Text + " / " + main.getSynthesis().mlMaxHumidData.Text)); MemoryStream chTempHumidImageBuffer = synthesis.getCHTempHumidImageBuffer(); iTextSharp.text.Image iImage = iTextSharp.text.Image.GetInstance(chTempHumidImageBuffer.ToArray()); iImage.ScaleToFit(doc.PageSize); iImage.SetAbsolutePosition(0, 250); doc.Add(iImage); doc.NewPage(); PdfPTable table = new PdfPTable(5); table.HorizontalAlignment = 0; //leave a gap before and after the table table.SpacingBefore = 20f; table.SpacingAfter = 30f; PdfPCell cell0 = new PdfPCell(new Phrase("Rapport")); cell0.Colspan = 5; cell0.Border = 0; cell0.HorizontalAlignment = 1; table.AddCell(cell0); table.AddCell("Nom du capteur"); table.AddCell("UID du capteur"); table.AddCell("Date-heure du relevé"); table.AddCell("Température"); table.AddCell("Humidité"); DateTime start = main.GetStartDate(); DateTime end = main.GetEndDate(); String startString = start.ToString("yyyy-MM-dd HH:mm:ss"); String endString = end.ToString("yyyy-MM-dd HH:mm:ss"); String idSensor = main.getSensor(); String query; String optionalClause = "WHERE 1 "; if (idSensor != "") { optionalClause = "WHERE sensor.id = " + idSensor + " "; } query = "SELECT sensor.*, data.*" + "FROM sensor INNER JOIN data " + "ON data.sensor = sensor.id " + optionalClause + " " + "AND (data_date BETWEEN '" + startString + "' AND '" + endString + "') " + "ORDER BY sensor ASC, data_date ASC"; List <Dictionary <String, String> > resultset = new List <Dictionary <string, string> >(); try { resultset = DBInteractor.QuickSelect(query); } 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); } foreach (Dictionary <String, String> line in resultset) { table.AddCell(line["label"].ToString()); table.AddCell(line["uid"].ToString()); table.AddCell(line["data_date"].ToString()); table.AddCell(line["temperature"].ToString()); table.AddCell(line["humidity"].ToString()); } doc.Add(table); // Close the document doc.Close(); try { // Close the writer instance writer.Close(); // Always close open filehandles explicity fs.Close(); Thread.Sleep(1000); } catch (Exception ex) { MessageBox.Show("Erreur à l'enregistrement: " + ex.Message, "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error); } }