0
Form1.cs
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.Text.RegularExpressions;



namespace Temporizador
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            /*if (escolherHoraTxt.InvokeRequired == true)
                escolherHoraTxt.Invoke((MethodInvoker)delegate { escolherHoraTxt.Text = "Invoke was needed"; });*/
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void escolherFicheiroBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.ShowDialog();

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                string fileName;
                fileName = dlg.FileName;
                link.Text = fileName;
                //MessageBox.Show(fileName);
            }
        }

        private void escolherHoraTxt_MouseClick(object sender, EventArgs e)
        {
            if (escolherHoraTxt.Text == "--:--:--")
                escolherHoraTxt.Text = " ";
        }

        private void escolherHoraTxt_TextChanged(object sender, EventArgs e)
        {
            if (escolherHoraTxt.Text == "--:--:--")
                escolherHoraTxt.Text = " ";
        }

        private void gravarBtn_Click(object sender, EventArgs e)
        {
        }

        private void gravarBtn_Click_1(object sender, EventArgs e)
        {
            String s = escolherHoraTxt.Text;

            Horas hora = new Horas();

            hora.IsValidTime(s);
            hora.compareTime(s);  
        }
    }
}


Horas.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Temporizador
{
    class Horas
    {
        private String m_timeNow;

        public String timeNow 
        {
            get
            {
                return m_timeNow;
            }
            set
            {
                m_timeNow = value;
            }
        }

        public Horas()
        { 
        }

        public string getCurrentTime()
        {
            m_timeNow=DateTime.Now.ToString("HH:mm:ss");
            return m_timeNow;
        }

        public void IsValidTime(String theTime)
        {
            string[] timeArray = theTime.Split(new[] { ":" }, StringSplitOptions.None);

            try{
                Convert.ToDateTime(theTime);
            }
            catch (FormatException e)
            {     
                MessageBox.Show(e.Message);
            }
        }

        public void compareTime(String theTime)
        {
            string currentTime=getCurrentTime();
            if (currentTime == theTime)
                MessageBox.Show("SIM");
            else
                MessageBox.Show("NAO");
        }
    }
}

/I´m trying to make an application that it is always running and that will close and then open a file in a certain hour choosen by the user. I intend to use something like while(1){...} but I don´t know in what part of the program should I put this. Could someone help me please?/

Cristina
  • 15
  • 4

0 Answers0