1

我正在尝试按 2 个日期列(startDate 和 endDate)过滤 datagridview 中的数据。

我想检查网格视图中的 arow 的结束日期是否已过期,但网格视图上的复选框的值 =“过期”,否则将其设置为“有效”

但我不知道如何使它成为现实请帮我这样做?!

这是我尝试过的代码:

        SqlConnection CN = new SqlConnection(mysql.CON.ConnectionString);
        SqlDataAdapter sda = new SqlDataAdapter();
        sda.SelectCommand.CommandText = "select TASDEED.ID ,ESALNO,DATTSADEED,NAME,EGARMONY,DATBEGIN,DATEND,AKARTYPE  from TASDEED ";
        try
        {
            foreach (DataGridView row in dataGridView1.Rows)
            {
                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {
                    if (myStatic.CalcExpire(dt.Rows[i]["DATEND"].ToString()))//
                    {
                        dataGridView1.Rows[i].Cells[8].Value = "Expired";
                    }
                    else
                    {
                        dataGridView1.Rows[i].Cells[8].Value = "Valid";
                    }

                }
            }
            BindingSource bsource = new BindingSource();
            bsource.DataSource = dt;
            dataGridView1.DataSource = bsource;
            sda.Update(dt);
           sda.Fill(dt);
        }
        catch(Exception ex) 
        {
            MessageBox.Show(ex.Message);
        }

那是我的 CalaExpire 函数:

    public static bool CalcExpire(string datee)
    {
        try
        {
            string[] Arr = datee.Split('/');
            long Day1 = Convert.ToInt64(Arr[2]);
            long Month1 = Convert.ToInt64(Arr[1]);
            long Year1 = Convert.ToInt64(Arr[0]);

            System.Globalization.UmAlQuraCalendar UmDate = new System.Globalization.UmAlQuraCalendar();
            long Day = Convert.ToInt64(UmDate.GetDayOfMonth(DateTime.Now));
            long Month = Convert.ToInt64(UmDate.GetMonth(DateTime.Now));
            long Year = Convert.ToInt64(UmDate.GetYear(DateTime.Now));

            if (Year > Year1)
                return true;
            else if (Year == Year1 && Month > Month1)
                return true;
            else if (Year == Year1 && Month == Month1 && Day >= Day1)
                return true;
            else
                return false;
        }
        catch { return false; }
    }
4

0 回答 0