c# - C3 中的数据网格视图
问题描述
我正在做销售发票,我希望系统检查输入的数量是否是双值,如果是双值,则输入的数量必须小于数据库中的数量。
检查用户是否输入双精度的验证工作正常,但代码的另一部分工作不正常。代码在用户离开单元格并再次输入后工作,如果他编辑它,系统将继续保存旧值(错误值),但是对于第一部分,如果他输入字母,系统就会给他一个错误,当他更正它时,系统会采用新值并让他正常离开销售,问题出在第二个这里的一部分是我的代码:
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
if (e.ColumnIndex == 3 || e.ColumnIndex == 4 || e.ColumnIndex == 5 || e.ColumnIndex == 6 || e.ColumnIndex == 7) // 1 should be your column index
{
if (Convert.ToString(e.FormattedValue) != "")
{
double i;
if (!double.TryParse(Convert.ToString(e.FormattedValue), out i))
{
e.Cancel = true;
MessageBox.Show("Insert correct numbers");
}
else
{
if (e.ColumnIndex == 5)
{
qty3 = Convert.ToDouble(dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[5].Value);
string code = dataGridView1.Rows[dataGridView1.CurrentCell.RowIndex].Cells[0].Value.ToString();
sqlClass c = new sqlClass();
con = c.getcon();
con.Open();
c.command("select quantity from items where code='" + code + "'");
cmd = c.getcmd();
double qty2 = Convert.ToDouble(cmd.ExecuteScalar().ToString());
if (qty3 > qty2)
{
e.Cancel = true;
MessageBox.Show("You don't have enough quantity \n Quantity available is:" + qty2);
}
else
{
dataGridView1[e.ColumnIndex, e.RowIndex].ErrorText = null;
}
con.Close();
}
}
}
}
}
解决方案
推荐阅读
- testing - 在发出 fetch 请求后,编写 Testcafe 测试以断言加载微调器是可见的
- vba - 带有空指针的 Vba 图表循环
- .net-core - Visual Studio 2019 Debugger 只运行一次,需要重启才能再次运行
- java - 为什么在作为 JAR 执行时会收到 NoSuchMethodException?
- c# - 如何创建这样的 json 数据的 API
- rabbitmq - 如何在新的 RabbitMQ .conf 配置文件格式中设置 error_logger_hwm?
- vb.net - Visual Studio 在项目中找不到 .exe 文件
- oracle - Oracle Entity Framework Core 将表参数传递给存储过程
- sql - 有没有办法在 SQL Server 中查找和提取由 2 个字符后跟任何 8 位数字组成的字符串?
- python - 在 Jupyter 笔记本中的“小部件”和“内联”matplotlib 后端之间切换