/// <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 btnAdd_Click(object sender, EventArgs e) { if (dgvMaterialQuota.CurrentRow == null || !CheckInput()) { return; } materialQuota = new MaterialQuota(); materialQuota.Proportion = decimal.Parse(txtProportion.Text); materialQuota.ValidDigits = int.Parse(txtValidDigits.Text); materialQuota.Formula = txtFormula.Text; materialQuota.Id = Guid.NewGuid(); materialQuota.Code = dgvMaterialQuota.CurrentRow.Cells["colCode"].Value.ToString(); bool result = MaterialQuotaBLL.AddMaterialQuotaData(materialQuota); if (result) { LoadData(MaterialVerId); dgvMaterialQuota.ClearSelection(); MessageBox.Show("材料定额信息新增成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); dgvMaterialQuota.Rows[dgvMaterialQuota.Rows.Count - 1].Selected = true; } }