微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Datagridview 中比较时间

如何解决在 Datagridview 中比较时间

我有一个 Datagridview,其中包含航空公司的几列。其中一栏是“出发”,另一栏是“实际出发”。 Departure 里面已经有时间了,但是Actual Departure 没有,因为用户需要填写。如果用户填写的实际出发时间在出发时间之前,如果是准确时间,则需要转为某个颜色,它会变成某种颜色,如果它在出发时间之后,再次变成另一种颜色。我遇到了这个问题,因为我正在尝试比较 2 列,但我认为它给了我一个错误,因为在实际出发中没有可比较的价值。实际离开直到运行时才会有值,当用户填写它时。也许有人可以对正在发生的事情或如何解决问题提供一些见解。

有多个航班起飞,因此一个航班实际上可能在另一个航班之前起飞,因此如果该特定航班的实际起飞仍然为空白,则需要能够跳到下一行。

我正在测试另一种这样做的方法,它在一定程度上起作用,但是如果之前的实际出发没有填写,那么该行不会改变颜色 Example of old method

当我运行当前代码时,出现错误:“字符串未被识别为有效”。

knex.schema
  .createTable('users_table',(table) => {
    table.increments('id');
    table.string('email').unique().notNullable();
    table.string('full_name').notNullable();
    table.timestamp('created_at').defaultTo(knex.fn.Now()).notNullable();

    table.index('email','email_unique','unique');
  })
  .createTable('users_credentials',(table) => {
    table.increments('id');
    table.string('password').notNullable();
    table.boolean('is_activated').defaultTo(false).notNullable();
    table.integer('user_id').unsigned().references('users_table.id').notNullable();

    table.index('user_id','user_id_unique','unique');
  });

解决方法

使用TimeSpan。将 time 转换为 TimeSpan 并进行比较。

for (int i = 0; i < dgvRampBoard.Rows.Count; i++)
{
    TimeSpan t1 = TimeSpan.Parse(dgvRampBoard.Rows[i].Cells[3].Value.ToString());
    TimeSpan t2 = TimeSpan.Parse(dgvRampBoard.Rows[i].Cells[4].Value.ToString());



    if (TimeSpan.Compare(t1,t2) == -1)
    {
       this.dgvRampBoard.Rows[i].Cells[5].Style.BackColor = Color.Red;
       this.dgvRampBoard.Rows[i].Cells[4].Style.BackColor = Color.FromArgb(247,13,26);
       this.dgvRampBoard.Rows[i].Cells[4].Style.ForeColor = Color.White;
    }
    else if (TimeSpan.Compare(t1,t2) == 0)
    {
       this.dgvRampBoard.Rows[i].Cells[4].Style.BackColor = Color.Black;
       this.dgvRampBoard.Rows[i].Cells[4].Style.ForeColor = Color.White;
    }
    else
    {
       this.dgvRampBoard.Rows[i].Cells[4].Style.BackColor = Color.FromArgb(0,204,0);
       this.dgvRampBoard.Rows[i].Cells[4].Style.ForeColor = Color.White;
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。