Ouverture Pop up avec timer

Fermé
bart8686 Messages postés 81 Date d'inscription vendredi 26 avril 2013 Statut Membre Dernière intervention 1 juillet 2014 - 26 avril 2013 à 13:52
bart8686 Messages postés 81 Date d'inscription vendredi 26 avril 2013 Statut Membre Dernière intervention 1 juillet 2014 - 29 avril 2013 à 08:16
Bonjour,
Je dois faire une application qui toutes les 20 secondes consulte une base de données pour récupérer des alarmes. Je dois ensuite afficher ces alarmes une par une dans un pop up (exemple : alarme1 pendant 2sec, ca disparait, alarme2 pendant 2sec etc...).

J'arrive à afficher les alarmes et à faire le "check" dans la base de données.
Mais je n'ai aucune idée de comment faire pour afficher une pop up un certain temps puis la cacher et la réafficher avec autre chose dedans etc...

Merci de votre aide.
A voir également:

2 réponses

tsri_badr_esgi Messages postés 524 Date d'inscription samedi 21 mars 2009 Statut Membre Dernière intervention 26 mai 2014 9
27 avril 2013 à 00:21
Combien de classe ton programme utilise?.
montrer nous le code pour bien comprendre ce que tu veut faire
0
bart8686 Messages postés 81 Date d'inscription vendredi 26 avril 2013 Statut Membre Dernière intervention 1 juillet 2014 84
29 avril 2013 à 08:16
J'utilise 2 classes avec plusieurs Forms :

Voici la pop up :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

namespace Itron.Local.Security.GTC
{
public partial class MainForm : Form
{
/***** Properties *****/
#region Properties
private CSqlServer m_oSQLServer = new CSqlServer();
private Rectangle m_oScreenResolution;
private CManageXML m_oManageXML;
private int iNbAlarms = 0;
private Timer m_oCloseTimer = new Timer();
private int m_iId = 0;
private List<String> m_oid;


#endregion




public MainForm()
{
InitializeComponent();
}

private void MainForm_Load(object sender, EventArgs e)
{
m_oCloseTimer.Tick += new EventHandler(CloseTimer);
m_oCloseTimer.Interval = Properties.Settings.Default.Popup_Time;
m_oCloseTimer.Start();

// DB Connect
m_oSQLServer.Server = Properties.Settings.Default.DB_Server;
m_oSQLServer.Username = Properties.Settings.Default.DB_User;
m_oSQLServer.Password = Properties.Settings.Default.DB_Pass;
m_oSQLServer.Database = Properties.Settings.Default.DB_Log;
m_oSQLServer.Connect();

m_oManageXML = new CManageXML("Log.xml");
List<String> m_oid = new List<String>();
List<List<Object>> oResults = m_oSQLServer.ExeSelectResult("SELECT AlarmEntryId,SiteId,DeviceId,ObjectId,SystemDesignation,TechnicalDesignation,SystemDescription,TechnicalDescription,ObjectDescription,State,StateText,AlarmCondition,AlarmConditionText,Type,TypeText,PriorityNumber,PriorityText,ToAlarmMessageText,CategoryText,ReadLevel,LastChangeTime,ToAlarmTime,ToNormalTime,LastValueType,LastValueReal,LastValuePrecision,LastValueMultistateText,LimitValueType,LimitValueReal,LimitValuePrecision,LimitValueMultistateText,ToAlarmValueType,ToAlarmValueReal,ToAlarmValuePrecision,ToAlarmValueMultistateText,AlarmCount,ToAlarmTimeDI,LastChangeTimeDI FROM Alarm");
for (int i = 0; i < m_oSQLServer.Count_Row; i++)
{

if (m_oManageXML.GenerateMemory("alarm", oResults, i))
{
// If alarm not exist in XML
LinkLabel oAlarm = new LinkLabel();
m_iId = int.Parse(oResults[i][0].ToString());
oAlarm.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(oAlarmClicked);
oAlarm.Size = new System.Drawing.Size(500, 20);
oAlarm.Location = new System.Drawing.Point(30, 30 + (iNbAlarms * 30));
oAlarm.Text = ("Attention alarme numéro : '" + oResults[i][0].ToString() + "'");
this.Controls.Add(oAlarm);
m_oManageXML.CreateAlert(oResults[i][0].ToString(), DateTime.Now.ToString());
/* Number of alarms for the size of pop up */
iNbAlarms = iNbAlarms + 1;
/* List of id in DB*/
m_oid.Add(oResults[i][0].ToString());

}
else
{
/* List of id in DB*/
m_oid.Add(oResults[i][0].ToString());

// Compare alert and current time
DateTime dToday = DateTime.Parse(DateTime.Now.ToString());
DateTime dAlert = DateTime.Parse(m_oManageXML.LastAlert(oResults[i][0].ToString()));
if (dAlert.AddMinutes(10) < dToday)
{
// Alert for an old alarm
LinkLabel oAlarm = new LinkLabel();
oAlarm.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(oAlarmClicked);
m_oManageXML.CreateAlert(oResults[i][0].ToString(), DateTime.Now.ToString());
oAlarm.Size = new System.Drawing.Size(500, 20);
oAlarm.Location = new System.Drawing.Point(30, 30 + (iNbAlarms * 30));
oAlarm.Text = ("Attention alarme numéro : '" + oResults[i][0].ToString() + "'");
this.Controls.Add(oAlarm);
/* Number of alarms for the size of pop up */
iNbAlarms = iNbAlarms + 1;
}

}

}
this.Size = new System.Drawing.Size(220, 60 + (iNbAlarms * 30));


// Position
m_oScreenResolution = Screen.PrimaryScreen.Bounds;
Point oLocation = new Point(m_oScreenResolution.Width - this.Width, m_oScreenResolution.Height - this.Height - 30);
this.Location = oLocation;

if (iNbAlarms == 20) //A modifier par 0
{
this.Opacity = 0;
}
else
{
this.Activate();
}
iNbAlarms = 0;

List<String> o_idAlarms = new List<String>();
for (int i = 0; i < m_oSQLServer.Count_Row; i++)
{
o_idAlarms.Add(oResults[i][0].ToString());
}

//Delete an alarm in XML if it is not is DB and copy it in Archive.XML
List<String> oXMLAlerts = m_oManageXML.getAlarms();
for (int i = 0; i < oXMLAlerts.Count; i++)
{
if (m_oManageXML.IfExistAlarmBD(oXMLAlerts[i], m_oid))
{
}
else
{
m_oManageXML.CopyAlarm(oXMLAlerts[i]);
m_oManageXML.DeleteElement(oXMLAlerts[i]);
}
}
}


//Show details of alarms
private void oAlarmClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();
frm_details oForm = new frm_details();
oForm.Show();
}

private void CloseTimer(object sender, EventArgs e)
{
this.Close();
}

}
}











Et voici la form principale qui appel l'alarme et fait le check toutes les 20 secondes :

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Mail;
using System.Net;


namespace Itron.Local.Security.GTC
{
public partial class frm_icon : Form
{

private System.Windows.Forms.NotifyIcon notifyIcon1;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem menuItem0;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.ComponentModel.IContainer componentis;
public Timer m_oCloseTimer = new Timer();
private static frm_icon instance = null;
private static readonly object mylock = new object();

public void initTimer()
{
m_oCloseTimer.Interval = Properties.Settings.Default.Popup_Time;
}

private frm_icon()
{
InitializeComponent();
this.componentis = new System.ComponentModel.Container();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.menuItem0 = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();

m_oCloseTimer.Tick += new EventHandler(CloseTimer);

// Initialize contextMenu1
this.contextMenu1.MenuItems.AddRange(
new System.Windows.Forms.MenuItem[] {this.menuItem0, this.menuItem1, this.menuItem2 });

// Initialize menuItem0
this.menuItem0.Index = 0;
this.menuItem0.Text = "Update";
this.menuItem0.Click += new System.EventHandler(this.menuItem0_Click);

// Initialize menuItem1
this.menuItem1.Index = 1;
this.menuItem1.Text = "Parameters";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);

// Initialize menuItem2
this.menuItem2.Index = 2;
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);

// Create the NotifyIcon.
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.componentis);

// The Icon property sets the icon that will appear
// in the systray for this application.
notifyIcon1.Icon = new Icon("appicon.ico");

// The ContextMenu property sets the menu that will
// appear when the systray icon is right clicked.
notifyIcon1.ContextMenu = this.contextMenu1;

// The Text property sets the text that will be displayed,
// in a tooltip, when the mouse hovers over the systray icon.
notifyIcon1.Text = "GTC Alarms";
notifyIcon1.Visible = true;

// Handle the DoubleClick event to activate the form.
notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
this.Opacity = 0;
}

public static frm_icon GetInstance()
{

lock ((mylock))
{
// If instance not exist, we create it
if (instance == null)
{
instance = new frm_icon();
}
else
{
instance.Activate();
}
// return the instance
return instance;
}
}

private void CloseTimer(object sender, EventArgs e)
{
MainForm oForm = new MainForm();
oForm.Show();
System.Threading.Thread.Sleep(10000);
m_oCloseTimer.Interval = Properties.Settings.Default.Check_time;
m_oCloseTimer.Enabled = true;
}

protected override void Dispose(bool disposing)
{
// Clean up any components being used.
if (disposing)
if (componentis != null)
componentis.Dispose();

base.Dispose(disposing);
}

private void notifyIcon1_DoubleClick(object Sender, EventArgs e)
{
frm_parameters oForm = null;
oForm.Show();
m_oCloseTimer.Stop();
}

private void menuItem0_Click(object Sender, EventArgs e)
{
MainForm oForm = new MainForm();
oForm.Show();
}

private void menuItem1_Click(object Sender, EventArgs e)
{
// Parameters when click
frm_parameters oForm = null;
oForm = frm_parameters.GetInstance();
oForm.Show();
m_oCloseTimer.Stop();
}

private void menuItem2_Click(object Sender, EventArgs e)
{
// Close the form, which closes the application.
Application.Exit();
}
}
}
0