我有一个带有历史数据的旧时间表应用程序,hr希望偶尔查看旧数据,因此我被赋予了构建c#应用程序的任务。首先用户选择一个支付组下拉菜单,选择一个支付组,根据支付组选择员工下拉菜单填充,然后我有两个文本框一个包含最小日期,另一个包含你猜对了最大日期,然后我有两个datetimepickers fromdate和迄今为止。 datetimepicker从mindate日期框和max date文本框中获取其值,在选择所有项目后,用户单击运行报告并生成报告。
视觉请点击此处 - > picture
我的问题是,如果没有可用的日期,我想将datetimepickers的可见性设置为false - > picture因为你可以看到日期不会改变,因为datetimepickers不能将自己设置为等于空字符串所以要解决这个问题我只想让用户甚至看不到datetimepickers
我试过的代码:
private void mindateset() // fill the listbox of values of mindate and maxdate
{
if (Employee.SelectedValue != null)
{
if (Employee.SelectedValue.ToString().Trim().Length > 0)
{
try
{
using (MSSQL.SqlConnection connection = new MSSQL.SqlConnection(constr))
{
timepunchnew = new EtimeHistoryDataSet();
connection.Open();
using (MSSQL.SqlCommand command = new MSSQL.SqlCommand("SELECT MIN(TransDate) AS mindate, MAX(TransDate) AS maxdate FROM dbo.EtimePunchDetail WHERE (EmpID = @empid)", connection))
{
MSSQL.SqlParameter myminparam = new MSSQL.SqlParameter();
myminparam.Direction = ParameterDirection.Input;
myminparam.ParameterName = "@empid";
myminparam.Value = Employee.SelectedValue;
command.Parameters.Add(myminparam);
MSSQL.SqlDataAdapter myadapter = new System.Data.SqlClient.SqlDataAdapter();
myadapter.SelectCommand = command;
myadapter.Fill(timepunchnew, "Mindate");
AvailableMin.DataSource = timepunchnew.Mindate;
AvailableMin.DisplayMember = "mindate";
AvailableMax.DataSource = timepunchnew.Mindate;
AvailableMax.DisplayMember = "maxdate";
FromDate.MinDate = DateTime.Parse(AvailableMin.Text);
FromDate.Value = FromDate.MinDate;
if (FromDate.Value != FromDate.MinDate)
{
if (DialogResult.OK == MessageBox.Show("The Selected User Does Not Have Any FromDate"))
{
FromDate.Visible = false;
}
else
{
FromDate.Value = FromDate.MinDate;
FromDate.Visible = true;
}
}
ToDate.MaxDate = DateTime.Parse(AvailableMax.Text);
ToDate.Value = ToDate.MaxDate;
if (ToDate.Value != ToDate.MaxDate)
if (DialogResult.OK == MessageBox.Show("The Selected User Does Not Have Any FromDate"))
{
ToDate.Visible = false;
}
else
{
ToDate.Value = ToDate.MinDate;
ToDate.Visible = true;
}
}
}
对此有任何帮助都会受到赞赏,这是我项目的最后一步
答案 0 :(得分:0)
我创建了两个文本框并将其放在datetimepicker值上,如果列表框中没有可用日期,则将其显示为:)
private void AvailableMin_SelectedIndexChanged(object sender, EventArgs e)
{
if (AvailableMin.Text == "")
{
textBox2.Visible = true;
textBox2.Text = "There are no to dates available for this particular user";
}
else
{
textBox2.Visible = false;
}
}
private void AvailableMax_SelectedIndexChanged(object sender, EventArgs e)
{
if (AvailableMax.Text == "")
{
textBox1.Visible = true;
textBox1.Text = "There are no to dates available for this particular user";
}
else
{
textBox1.Visible = false;
}
}