/// <summary> /// 计算材料定额 /// </summary> private void btnCalc_Click(object sender, EventArgs e) { if (dgvMaterialQuota.CurrentRow == null) { return; } //string quota = Calc(); //if (string.IsNullOrEmpty(quota)) // return; List <MaterialQuota> listOldMaterialQuota = new List <MaterialQuota>(); List <MaterialQuota> listNewMaterialQuota = new List <MaterialQuota>(); foreach (DataGridViewRow row in dgvMaterialQuota.Rows) { string id = row.Cells["Id"].Value.ToString(); bool isNew = false; if (string.IsNullOrEmpty(id)) { id = Guid.NewGuid().ToString(); isNew = true; } materialQuota = new MaterialQuota(); decimal meterWeight = decimal.Parse(row.Cells["colMeterWeight"].Value.ToString()); decimal quota = decimal.Parse(row.Cells["colChildCount"].Value.ToString()) * meterWeight; dgvMaterialQuota.CurrentRow.Cells["colMaterialQuota"].Value = quota; materialQuota.Quota = quota; materialQuota.Id = new Guid(id); if (isNew) { materialQuota.Code = row.Cells["colCode"].Value.ToString(); listNewMaterialQuota.Add(materialQuota); } else { listOldMaterialQuota.Add(materialQuota); } } foreach (MaterialQuota material in listOldMaterialQuota) { bool result = MaterialQuotaBLL.UpdateQuotaData(material); } foreach (MaterialQuota material in listNewMaterialQuota) { bool result = MaterialQuotaBLL.AddMaterialQuotaData(material); } LoadData(MaterialVerId); }
/// <summary> /// 修改 /// </summary> private void btnUpdate_Click(object sender, EventArgs e) { if (dgvMaterialQuota.CurrentRow == null || !CheckInput()) { return; } string id = dgvMaterialQuota.CurrentRow.Cells["Id"].Value.ToString(); int rowIndex = dgvMaterialQuota.CurrentRow.Index; materialQuota = new MaterialQuota(); materialQuota.Proportion = decimal.Parse(txtProportion.Text); materialQuota.ValidDigits = int.Parse(txtValidDigits.Text); materialQuota.Formula = txtFormula.Text; materialQuota.Id = new Guid(id); bool result = MaterialQuotaBLL.UpdateMaterialQuotaData(materialQuota); if (result) { _keyWords["Proportion"] = materialQuota.Proportion.ToString(); _keyWords["ValidDigits"] = materialQuota.ValidDigits.ToString(); _keyWords["Formula"] = materialQuota.Formula.ToString(); string quota = Calc(); if (string.IsNullOrEmpty(quota)) { return; } materialQuota.Quota = string.IsNullOrEmpty(quota) ? decimal.MinValue : decimal.Parse(quota); MaterialQuotaBLL.UpdateQuotaData(materialQuota); LoadData(MaterialVerId); dgvMaterialQuota.ClearSelection(); MessageBox.Show("材料定额修改成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } dgvMaterialQuota.Rows[rowIndex].Selected = true; }