分配的小时标签是分配给每个部门的总小时数,剩余小时数是在单元格结束编辑结束时减去分配的小时数剩下的小时数。
在 Datagridview 中,一旦我从下拉列表中选择部门的值并输入 tmh 单元格的值,然后在 cellend 编辑行上,我必须更新左小时标签文本,但我没有得到这种情况的逻辑。
这是我的代码
#region THM CALCULATION.
int column = ProjectActivitiesGrid.CurrentCell.ColumnIndex;
string headerText = ProjectActivitiesGrid.Columns[column].HeaderText;
DataGridViewRow d = this.ProjectActivitiesGrid.Rows[e.RowIndex];
String department = d.Cells[0].Value.ToString();
if (department != null)
{
String chk = m_Project.projdepthrs.Where(c => c.DEPARTMENT == department).Select(c => c.DEPARTMENT).FirstOrDefault();
if (chk == null)
{
MessageBox.Show("Please fill up department alloted hrs first");
d.Cells[1].ReadOnly = true;
d.Cells[2].ReadOnly = true;
d.Cells[3].ReadOnly = true;
d.Cells[4].ReadOnly = true;
d.Cells[5].ReadOnly = true;
d.Cells[6].ReadOnly = true;
d.Cells[7].ReadOnly = true;
}
else
{
d.Cells[1].ReadOnly = false;
d.Cells[2].ReadOnly = false;
d.Cells[3].ReadOnly = false;
d.Cells[4].ReadOnly = false;
d.Cells[5].ReadOnly = false;
d.Cells[6].ReadOnly = false;
d.Cells[7].ReadOnly = false;
String tmh = m_Project.projdepthrs.Where(c => c.DEPARTMENT == department).Select(c => c.TMH).First();
LBLAllotedhrs.Text = tmh;
LBLLefthrs.Text = tmh;
}
if (d.Cells[5].Value != null)
{
foreach (DataGridViewRow rw in ProjectActivitiesGrid.Rows)
{
LBLLefthrs.Text = (Convert.ToInt32(LBLLefthrs.Text) - Convert.ToInt32(d.Cells[5].Value)).ToString();
}
}
else
{
LBLLefthrs.Text = "";
}
}
else
MessageBox.Show("please select department");
#endregion