加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何禁用按钮

发布时间:2020-12-15 21:54:21 所属栏目:百科 来源:网络整理
导读:如果检索的日期小于当前日期,我想停用button6,我已使用下面的代码,但它不起作用.请帮我找错. protected void Button6_Click1(object sender,EventArgs e){ MySqlConnection connection = new MySqlConnection("server=localhost; database=e-learningsystem;
如果检索的日期小于当前日期,我想停用button6,我已使用下面的代码,但它不起作用.请帮我找错.

protected void Button6_Click1(object sender,EventArgs e)
{
    MySqlConnection connection = new MySqlConnection("server=localhost; database=e-learningsystem; uid=root; password=123;port=3307;");
    connection.Open();
    try
    {
        MySqlCommand cmd = new MySqlCommand("SELECT Date FROM fundamentals of is WHERE ChapNo=Chapter 1",connection);
        string date = Convert.ToString(cmd.ExecuteScalar());
        //date = cmd;
        if (Convert.ToDateTime(cmd).CompareTo(System.DateTime.Now) < 0)
        {
            DownLoadFileFromServer("~/NewFolder1/" + "Fundamentals of IS.pdf");
        }
        else
        {
            Button6.Enabled = false;
        }
    }  
    catch (Exception ex)
    {
        // file IO errors

    }
}

这是serverMapPath代码

public static string ServerMapPath(string path)
{
    return HttpContext.Current.Server.MapPath(path);
}

public static HttpResponse GetHttpResponse()
{
    return HttpContext.Current.Response;
}
public static void DownLoadFileFromServer(string fileName)
{
    //This is used to get Project Location.
    try
    {
        string filePath = ServerMapPath(fileName);
        //This is used to get the current response.
        HttpResponse res = GetHttpResponse();
        res.Clear();
        res.AppendHeader("content-disposition","attachment; filename=" + filePath);
        res.ContentType = "application/octet-stream";
        res.WriteFile(filePath);
        res.Flush();
        res.End();
    }
    catch (Exception ex)
    {

    }
}

解决方法

MSDN答案:

我认为这会对你有所帮助

int result = DateTime.Compare(date1,date2);

string relationship;
if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";         
else
   relationship = "is later than";

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读