codice:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;
namespace SmsMobilev1
{
public partial class Interface : Form
{
// Importazione della libreria per l'esecuzione del file audio
[DllImport("coredll.dll")]
private static extern int PlaySound(string szSound, IntPtr hModule, int flags);
/// <summary>
/// Flags per l'esecuzione del suono
/// </summary>
[Flags]
private enum PlaySoundFlags
{
SndSync = 0x0,
SndFilename = 0x20000,
}
// Costanti
public const string splitFault = "/";
public const int nSensors = 10;
public const string pathSounds = @"\sounds";
public const string nameSoundAllarm = @"\Allarm.wav";
public Interface()
{
InitializeComponent();
******************************************************************************************************************************
Se quì ci metto una this.Show(), o una this.ShowDialog(), riesco a visualizzare l'interfaccia aggiornata, ma su
una nuova finestra! Non è ciò che vorrei.
*****************************************************************************************************************************
}
private void FrmStartAudio_Load(object sender, EventArgs e)
{
// Path del File Audio
string path;
path = Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
// Esecuzione del file
PlaySound(path + pathSounds + nameSoundAllarm,
IntPtr.Zero, (int)(PlaySoundFlags.SndFilename)
| (int)(PlaySoundFlags.SndSync));
}
private void menuItem1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void menuItem2_Click(object sender, EventArgs e)
{
new viewHistory().ShowDialog();
}
public void setValueText(string text) {
this.ValueValue.Text = text;
*****************************************************************************************************************************
Secondo me, per ogni set, ci vorrebbe un istruzione, che però ne conosco, ne ho trovato, per dire di aggiornare
l'elemento.
********************************************************************************************************************************
}
public void setTimeText(string text)
{
this.TimeValue.Text = text;
}
public void setUnitText(string text)
{
this.UnitValue.Text = text;
}
public void setFaultText(string fault,string nSensors)
{
this.FaultValue.Text = fault + "/" + nSensors;
}
public void setInterpretation(bool interpretation) {
this.Interpretation = interpretation;
if (this.Interpretation)
{
//
// FaultValue
//
this.FaultValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.FaultValue.ForeColor = System.Drawing.Color.Red;
this.FaultValue.Location = new System.Drawing.Point(192, 150);
this.FaultValue.Name = "FaultValue";
this.FaultValue.Size = new System.Drawing.Size(48, 20);
//
// UnitValue
//
this.UnitValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.UnitValue.ForeColor = System.Drawing.Color.Red;
this.UnitValue.Location = new System.Drawing.Point(150, 150);
this.UnitValue.Name = "UnitValue";
this.UnitValue.Size = new System.Drawing.Size(43, 20);
//
// ValueValue
//
this.ValueValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.ValueValue.ForeColor = System.Drawing.Color.Red;
this.ValueValue.Location = new System.Drawing.Point(98, 150);
this.ValueValue.Name = "ValueValue";
this.ValueValue.Size = new System.Drawing.Size(34, 20);
//
// TimeValue
//
this.TimeValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.TimeValue.ForeColor = System.Drawing.Color.Red;
this.TimeValue.Location = new System.Drawing.Point(42, 150);
this.TimeValue.Name = "TimeValue";
this.TimeValue.Size = new System.Drawing.Size(50, 20);
//
// flagAllarm
//
this.flagAllarm.Location = new System.Drawing.Point(4, 138);
this.flagAllarm.Name = "flagAllarm";
this.flagAllarm.Size = new System.Drawing.Size(32, 32);
this.flagAllarm.Visible = true;
//
// flagNoAllarm
//
this.flagNoAllarm.Location = new System.Drawing.Point(0, 0);
this.flagNoAllarm.Name = "flagNoAllarm";
this.flagNoAllarm.Size = new System.Drawing.Size(0, 0);
this.flagNoAllarm.Visible = false;
}
else {
//
// FaultValue
//
this.FaultValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.FaultValue.ForeColor = System.Drawing.Color.Lime;
this.FaultValue.Location = new System.Drawing.Point(192, 150);
this.FaultValue.Name = "FaultValue";
this.FaultValue.Size = new System.Drawing.Size(48, 20);
//
// UnitValue
//
this.UnitValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.UnitValue.ForeColor = System.Drawing.Color.Lime;
this.UnitValue.Location = new System.Drawing.Point(150, 150);
this.UnitValue.Name = "UnitValue";
this.UnitValue.Size = new System.Drawing.Size(43, 20);
//
// ValueValue
//
this.ValueValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.ValueValue.ForeColor = System.Drawing.Color.Lime;
this.ValueValue.Location = new System.Drawing.Point(98, 150);
this.ValueValue.Name = "ValueValue";
this.ValueValue.Size = new System.Drawing.Size(34, 20);
//
// TimeValue
//
this.TimeValue.Font = new System.Drawing.Font("Courier New", 10F, System.Drawing.FontStyle.Regular);
this.TimeValue.ForeColor = System.Drawing.Color.Lime;
this.TimeValue.Location = new System.Drawing.Point(42, 150);
this.TimeValue.Name = "TimeValue";
this.TimeValue.Size = new System.Drawing.Size(50, 20);
//
// flagAllarm
//
this.flagAllarm.Location = new System.Drawing.Point(0, 0);
this.flagAllarm.Name = "flagAllarm";
this.flagAllarm.Size = new System.Drawing.Size(0, 0);
this.flagAllarm.Visible = false;
//
// flagNoAllarm
//
this.flagNoAllarm.Location = new System.Drawing.Point(4, 138);
this.flagNoAllarm.Name = "flagNoAllarm";
this.flagNoAllarm.Size = new System.Drawing.Size(33, 32);
this.flagNoAllarm.Visible = true;
}
}
}
}
Ora ti posto la program e ti faccio vedere, come, con il tuo aiuto ho semi-risolto il problema.
codice:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace SmsMobilev1
{
static class SmsMobileEcecute
{
// Timer, per la temporizzazione della ricezione delle stringhe
***********************************************************************************************************************************
I membri statici che servono nel mio caso, sono solo questi due. smsMobile, è la classe nella quale è presente
il metodo per la ricezione delle stringhe. Il perchè te lo spiego tra un pò.
************************************************************************************************************************************
static Timer timer;
static SmsMobile smsMobile;
// Costanti
public const string subPathSurvey = @"\textFile";
public const string nameSurveyFile = @"\rilevazioni.txt";
[MTAThread]
static void Main()
{
timer = new Timer();
timer.Interval = 10000;
timer.Tick += new EventHandler(timer_Tick);
smsMobile = new SmsMobile();
timer.Enabled = true;
Application.Run(smsMobile.currentInterface);
*********************************************************************************************************************************
La form non è un membro statico, perchè è già un membro della classe SmsMobile
*********************************************************************************************************************************
}
static void timer_Tick(object sender, EventArgs e)
{
string pathSurevy = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase)
+ subPathSurvey + nameSurveyFile;
string relativePath = subPathSurvey + nameSurveyFile;
if (countLines(pathSurevy) > 0)
{
**************************************************************************************************************************************
in questo caso, l'evento della scadenza del timer, non fa altro che "ricevere la stringa".
la ricezione della stringa, nella classe SmsMobile, si occupa di far partire le set per la form, dove la currentInterface
è un membro della classe stessa.
***************************************************************************************************************************************
string survey = extractLine(relativePath, new object(), new EventArgs());
smsMobile.receiveSurvey(survey);
}
else timer.Enabled = false;
}
//Altra roba che non serve!
}
}
Ora secondo me dovremmo arrivare al problema di fondo!