其实,我有我的形式2 dateTimePicker在C尖锐净2008年。他们都执行相同的事件。但其中一个是不正常工作,直到我使用另一个one.Please帮我出去! !DateTimePicker不能正常工作
private void dtpStart_ValueChanged(object sender, EventArgs e)
{
if (cmbDay.SelectedIndex == -1 || cmbLeaveName.SelectedIndex == -1)
{
MessageBox.Show("Please select Day and Leave Name", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
dtpStart.ValueChanged -= new EventHandler(dtpStart_ValueChanged);
}
if (dtpStart.Value > dtpEnd.Value)
{
MessageBox.Show("The End date of leave cannot be occur before date of leave ", "Invalid Entry", MessageBoxButtons.OK);
dtpStart.Value = dtpEnd.Value;
}
getdays();
check = validate();
if (check == "Incorrect")
{
check = "Correct";
return;
}
LoadDataGridView();
}
private void dtpEnd_ValueChanged(object sender, EventArgs e)
{
if (cmbDay.SelectedIndex == -1 || cmbLeaveName.SelectedIndex == -1)
{
MessageBox.Show("Please select Day and Leave Name","Error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
dtpEnd.ValueChanged -= new EventHandler(dtpEnd_ValueChanged);
return;
}
if (dtpEnd.Value < dtpStart.Value)
{
MessageBox.Show("The End date of leave cannot be occur before date of leave ", "Invalid Entry", MessageBoxButtons.OK);
dtpEnd.Value = dtpStart.Value;
}
getdays();
check = validate();
if (check == "Incorrect")
{
check = "Correct";
return;
}
LoadDataGridView();
}
private void getdays()
{
double ts = GetDateDifference();
if (cmbDay.Text.ToString() == "Full Day")
{
txtLeaveApplied.Text = ts.ToString();
}
else if (cmbDay.Text.ToString() == "Half Day")
{
txtLeaveApplied.Text = ((float.Parse(ts.ToString()))/2).ToString();
}
}
private string validate()
{
string Name = cmbApplicantName.Text.ToString();
string EMP_ID = GetEmpId(Name);
DataTable dtvalidate = new DataTable();
dtvalidate = LI.ValidateLeaveInfo(EMP_ID,
DateTime.Parse(dtpStart.Value.ToShortDateString()),
DateTime.Parse(dtpEnd.Value.ToShortDateString()));
if (dtvalidate.Rows.Count > 0)
{
StringBuilder date = new StringBuilder();
foreach (DataRow row in dtvalidate.Rows)
{
date.Append(row["Leave_Date"].ToString() + Environment.NewLine);
}
MessageBox.Show("Leave Already applied in following Date(s)" +
Environment.NewLine + date, "Select valid date", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
check = "Incorrect";
dgvLeaveApplication.Rows.Clear();
}
dtvalidate.Rows.Clear();
dtvalidate.Dispose();
return check;
}
private void LoadDataGridView()
{
double ts = GetDateDifference();
dgvLeaveApplication.Rows.Clear();
DateTime dt = DateTime.Parse(dtpStart.Value.ToShortDateString());
for (int i = 0; i < Convert.ToInt32(ts.ToString()); i++)
{
dgvLeaveApplication.Rows.Add(dgvLeaveApplication.Rows.Count,
dt.ToShortDateString(), cmbLeaveName.SelectedValue.ToString());
dt = dt.AddDays(1);
}
dgvLeaveApplication.Refresh();
}
winform,wpf或web? – 2011-03-27 11:32:30
删除处理程序的目的是什么? – Anuraj 2011-03-29 05:52:04
,因为当我改变月,它会自动增加一个月,如03/03/2011 ... 04/03/2011 05/03/2011 ..这就是为什么我使用。 – 2011-03-29 06:01:55