110,538
社区成员
发帖
与我相关
我的任务
分享
public void freezeBatch()
{
try
{
deleteButtonColumn();
this.dateList.DataSource = null;
string sql = "select ID,FROMDATE,TODATE,BATCH_NAME,(case when freezeStatus=0 then '未冻结' when freezeStatus=1 then '已冻结' else '状态错误' end) as freezeStatus from DATEITEM where freezeStatus=0 order by FROMDATE";
DataTable dt = SqlLiteHelp.ExecuteDataSet(SqlLiteHelp.GetConnectings(), sql, CommandType.Text).Tables[0];
DataGridViewButtonColumn btnColumn1 = new DataGridViewButtonColumn();
btnColumn1.Name = "操作";
btnColumn1.UseColumnTextForButtonValue = false;
btnColumn1.DefaultCellStyle.NullValue = "冻结";
this.dateList.Columns.Add(btnColumn1);
this.dateList.DataSource = dt;
this.dateList.Columns["ID"].Visible = false;
dt.Columns["FROMDATE"].ColumnName = "开始日期";
dt.Columns["TODATE"].ColumnName = "结束日期";
dt.Columns["BATCH_NAME"].ColumnName = "所属期间";
dt.Columns["freezeStatus"].ColumnName = "冻结状态";
this.dateList.Columns["操作"].Width = 35;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
下面这个是点击添加button后的方法
private void dateList_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if(dateList.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.ColumnIndex != -1)
{
batch = dateList.Rows[e.RowIndex].Cells["所属期间"].Value.ToString();
DataGridViewButtonCell btnCell = (DataGridViewButtonCell)dateList.Rows[e.RowIndex].Cells[e.ColumnIndex];
if ("冻结".Equals(btnCell.FormattedValue.ToString()))
{
if ("期初".Equals(batch))
{
if (MessageBox.Show("冻结期初需要确定期初数据导入完毕,是否继续冻结期初?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
string sql = "update DATEITEM set freezeStatus=1 where BATCH_NAME='期初'";
int res = SqlLiteHelp.ExecuteNonQuery(SqlLiteHelp.GetConnectings(),sql,CommandType.Text);
if (res > 0)
{
MessageBox.Show("更新成功!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
freezeBatch();
}
else
{
MessageBox.Show("更新出错!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
else if(MessageBox.Show("确定要冻结期间:"+batch+"吗?", "冻结", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
Thread thread = new Thread(updateAllDataStatus);
thread.Start();
//updateAllDataStatus();
}
}
else if ("解冻".Equals(btnCell.FormattedValue.ToString()))
{
if (MessageBox.Show("确定要解冻期间:" + batch + "吗?", "解冻", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
{
}
}
}
}
在更新成功之后会再次刷新这个dgv
报错就出现在刷新dgv的过程 但是这个错误不是每次都会出现,而是偶然性的