关于DataGridView控件部分的使用
if (e.ColumnIndex == 1)
{
m = e.RowIndex;
txt_startTime.Text = dgv_reserve.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
tc();
txt_endTime.Text = “”;
dgv_reserve.Rows[e.RowIndex].Cells[1].Style.BackColor = Color.MediumOrchid;
//dgv_reserve.Rows[e.RowIndex].Cells[1].Style.SelectionBackColor = Color.Green;
for (int i = e.RowIndex; i >= 0; i–) //涂抹小于此开始时间的结束时间部分
{
if (DateTime.Parse(txt_startTime.Text) >= (DateTime)dgv_reserve.Rows[i].Cells[2].Value && dgv_reserve.Rows[i].Cells[2].Style.BackColor != Color.Red && dgv_reserve.Rows[i].Cells[1].Style.BackColor != Color.Red)
{
dgv_reserve.Rows[i].Cells[2].Style.BackColor = Color.Gray;
}
}
for (int i = e.RowIndex; i < dgv_reserve.RowCount; i++) //大于此开始时间的结束时间部分
{
if (dgv_reserve.Rows[i].Cells[2].Style.BackColor == Color.Red && dgv_reserve.Rows[i].Cells[1].Style.BackColor == Color.Red) //寻找被预约的标
{
DateTime tm = (DateTime)dgv_reserve.Rows[i].Cells[2].Value;
for (int j = e.RowIndex; j < dgv_reserve.RowCount; j++) //涂抹大于此开始时间的下一个区间的结束时间部分
{
if (tm < (DateTime)dgv_reserve.Rows[j].Cells[2].Value)
{
if (dgv_reserve.Rows[j].Cells[2].Style.BackColor != Color.Red)
{
dgv_reserve.Rows[j].Cells[2].Style.BackColor = Color.Gray;
}
}
}
break; //只找开始时间最近的预约标
}
}
//if (rowindex >= 0)
//{
// dgv_reserve.Rows[rowindex].Cells[2].Style.BackColor = Color.Green;
//}
//rowindex = e.RowIndex;
return;
}
tc();
if (e.ColumnIndex == 2)
{
n = e.RowIndex;
if (txt_startTime.Text == “”)
{
MessageBox.Show(“请先选择开始时间”);
return;
}
if (txt_startTime.Text != “”)
{
txt_endTime.Text = dgv_reserve.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
//dgv_reserve.Rows[e.RowIndex].Cells[2].Style.BackColor = Color.Green;
//dgv_reserve.Rows[e.RowIndex].Cells[2].Style.SelectionBackColor = Color.Green;
for (int i = e.RowIndex; i >= 0; i–) //涂抹小于此开始时间的结束时间部分
{
if (DateTime.Parse(txt_startTime.Text) >= (DateTime)dgv_reserve.Rows[i].Cells[2].Value && dgv_reserve.Rows[i].Cells[2].Style.BackColor != Color.Red && dgv_reserve.Rows[i].Cells[1].Style.BackColor != Color.Red)
{
dgv_reserve.Rows[i].Cells[2].Style.BackColor = Color.Gray;
}
}
}
for (int i = m; i <= n; i++)
{
dgv_reserve.Rows[i].Cells[2].Style.BackColor = Color.MediumOrchid;
dgv_reserve.Rows[i].Cells[1].Style.BackColor = Color.MediumOrchid;
}
for (int i = e.RowIndex; i < dgv_reserve.RowCount; i++) //大于此开始时间的结束时间部分
{
if (dgv_reserve.Rows[i].Cells[2].Style.BackColor == Color.Red && dgv_reserve.Rows[i].Cells[1].Style.BackColor == Color.Red) //寻找被预约的标记
{
DateTime tm = (DateTime)dgv_reserve.Rows[i].Cells[2].Value;
for (int j = e.RowIndex; j < dgv_reserve.RowCount; j++) //涂抹大于此开始时间的下一个区间的结束时间部分
{
if (tm < (DateTime)dgv_reserve.Rows[j].Cells[2].Value)
{
if (dgv_reserve.Rows[j].Cells[2].Style.BackColor != Color.Red)
{
dgv_reserve.Rows[j].Cells[2].Style.BackColor = Color.Gray;
}
}
}
break; //只找开始时间最近的预约标记
}
}