Hello everyone,
I have tried the code for start and stop time and been successful in doing so.Now I am trying to compare values of start and stop time as shown below in the code. I have used two masked txtbox.
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.Globalization;
namespace LoginPage
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string start,stop,check;
CultureInfo info = new CultureInfo("en-US");
start = maskedTextBox1.Text;
DateTime start1 = DateTime.ParseExact(start,"HH:mm",info);
stop = maskedTextBox2.Text;
DateTime stop1 = DateTime.ParseExact(stop, "HH:mm", info);
check = maskedTextBox2.Mask;
DateTime check1 = DateTime.ParseExact(check,"HH:mm",info);
if (start1 >= stop1)
{
MessageBox.Show("Invalid entry","Warning");
}
MessageBox.Show("The start time is: " + maskedTextBox1.Text + "\n" + "The stop time is: " + maskedTextBox2.Text);
MessageBox.Show("System time-" + DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString());
}
public void Form3_Load(object sender, EventArgs e)
{
// Other initialization code
maskedTextBox1.Mask = "00:00";
maskedTextBox1.ValidatingType = typeof(System.DateTime);
maskedTextBox1.TypeValidationCompleted += new TypeValidationEventHandler(maskedTextBox1_TypeValidationCompleted);
maskedTextBox1.MaskInputRejected += new MaskInputRejectedEventHandler(maskedTextBox1_MaskInputRejected);
maskedTextBox2.Mask = "00:00";
maskedTextBox2.ValidatingType = typeof(System.DateTime);
maskedTextBox2.TypeValidationCompleted += new TypeValidationEventHandler(maskedTextBox2_TypeValidationCompleted);
maskedTextBox2.MaskInputRejected += new MaskInputRejectedEventHandler(maskedTextBox2_MaskInputRejected);
}
}
}
I have used the handlers that I've defined above.Alz working well. But, the problem is wid the If condition used in ButtonClick Event above. The check has value of "00:00" strored in it.Now I want to enter the start time as today' timei.e. after "22:00" and the end time should be of next day's early morning i.e. between "03:00" to "07:00". So, i am having trouble with comparing the values of start1 and stop1 along with check1.As d value of stop1 is after "00:00" it is not giiving proper validation. Plz see if someone can help.