private void btnUpdate_Click(object sender, EventArgs e) { try { double Value = 0; if (dgvContent.Rows.Count > 0) { //检查数据 for (int i = 0; i < dgvContent.Rows.Count; i++) { if (WUseToolClass.isObjectNull(dgvContent.Rows[i].Cells[1].Value, "第" + (i + 1).ToString() + "行的参数值")) { return; } try { Value = double.Parse(dgvContent.Rows[i].Cells[1].Value.ToString()); } catch (Exception) { MessageBox.Show("参数类型错误"); return; } } //更新数据 for (int i = 0; i < dgvContent.Rows.Count; i++) { //获取修改数据 double.TryParse(dgvContent.Rows[i].Cells[1].Value.ToString(), out Value); if (mWDataToolClass.UpdateParameter(false, dgvContent.Rows[i].Cells[0].Value.ToString(), "", "", Value, "", "") != 0) { MessageBox.Show("参数数据修改失败"); return; } } } else { MessageBox.Show("请先选中要修改的参数"); return; } UpdateData(); MessageBox.Show("参数数据修改成功"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnPataModifyOK_Click(object sender, EventArgs e) { try { if (WUseToolClass.isObjectNull(dgvPataModify.Rows[0].Cells[0].Value, "组名")) { return; } if (WUseToolClass.isObjectNull(dgvPataModify.Rows[0].Cells[1].Value, "参数名称")) { return; } if (WUseToolClass.isObjectNull(dgvPataModify.Rows[0].Cells[2].Value, "参数值")) { return; } string GroupName = dgvPataModify.Rows[0].Cells[0].Value.ToString(); string Name = dgvPataModify.Rows[0].Cells[1].Value.ToString(); double Value = 0.0; try { Value = double.Parse(dgvPataModify.Rows[0].Cells[2].Value.ToString()); } catch (Exception) { MessageBox.Show("参数的值输入类型错误,只能是数值"); return; } string CorrAxis = ""; if (dgvPataModify.Rows[0].Cells[3].Value != null) { CorrAxis = WUseToolClass.getCorrAxisID(dtCorrAxis, dgvPataModify.Rows[0].Cells[3].Value.ToString()); } string Remarks = ""; if (dgvPataModify.Rows[0].Cells[4].Value != null) { Remarks = dgvPataModify.Rows[0].Cells[4].Value.ToString(); } int mIndex = dgvParameter.CurrentRow.Index; string oldGroupName = dgvParameter.Rows[mIndex].Cells[0].Value.ToString(); string oldName = dgvParameter.Rows[mIndex].Cells[1].Value.ToString(); string oldCorrAxis = ""; if (dgvParameter.Rows[mIndex].Cells[3].Value != null) { oldCorrAxis = WUseToolClass.getCorrAxisID(dtCorrAxis, dgvParameter.Rows[mIndex].Cells[3].Value.ToString()); } string oldRemarks = ""; if (dgvParameter.Rows[mIndex].Cells[4].Value != null) { oldRemarks = dgvParameter.Rows[mIndex].Cells[4].Value.ToString(); } if (Name != oldName && mWDataToolClass.SelectShowParameterName(Name) == 1) { MessageBox.Show("参数名称:" + Name + ";已存在,请检查"); return; } bool isUpdateName = true;//是否更新组名和参数名称,true更新false不更新 if (oldGroupName == GroupName && oldName == Name && oldCorrAxis == CorrAxis && oldRemarks == Remarks) { isUpdateName = false; } if (mWDataToolClass.UpdateParameter(isUpdateName, oldName, GroupName, Name, Value, CorrAxis, Remarks) != 0) { MessageBox.Show("参数数据更改失败"); return; } closePanelUI(); //刷新参数数据 mWDataToolClass.SelectShowParameter(ref dgvParameter); dgvPataModify.Rows.Clear(); MessageBox.Show("参数数据更改成功"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }