.NET 时间判断

//在Gridview1  做的一个查看

//配货数量大于0  显示  已配货

//处理时间等于今天说明  已处理

 private void GetBind()
    {
        DataTable ds = GetInfo();
        GridView1.DataSource = ds;
        GridView1.DataBind(); //绑定数据
        if (ds != null)//判断信息
        {
            string oldstr = "";
            DateTime oldtime;
            DateTime date = new DateTime(); //定义变量
            DateTime newtime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
            for (int j = 0; j < ds.Rows.Count; j++)
            {
                int bh = Convert.ToInt32(ds.Rows[j]["补货数量"].ToString());
                if (bh == 0)
                {
                    ((Label)GridView1.Rows[j].Cells[6].FindControl("sp1")).Attributes.Add("style", "display:none");//查找控件 sp1  使之隐藏
                    oldstr = ds.Rows[j]["处理时间"].ToString();
                    if (DateTime.TryParse(oldstr, out date))//判断时间是否匹配
                    {
                        oldtime = Convert.ToDateTime(oldstr);
                    }
                    else
                    {
                        oldtime = Convert.ToDateTime("2012-1-1");//不匹配 赋值  (让下面不出错)
                    }
                    if (oldtime == newtime)//两个时间比较
                    {
                        ((Label)GridView1.Rows[j].Cells[7].FindControl("cl_id1")).Text = "已处理";
                    }
                    else
                    {
                        ((Label)GridView1.Rows[j].Cells[7].FindControl("cl_id1")).Text = "";
                    }
                }
                else
                {
                    ((Label)GridView1.Rows[j].Cells[6].FindControl("sp2")).Attributes.Add("style", "display:none");
                    ((Label)GridView1.Rows[j].Cells[7].FindControl("cl_id1")).Text = "已配货";
                }
            }
        }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值