private void btnModify_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtMeterWeight.Text)) { MessageBox.Show("米重量不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } decimal meterWeight = 0; if (!decimal.TryParse(txtMeterWeight.Text, out meterWeight)) { MessageBox.Show("米重量格式不正确,只能为整数或小数", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (dgvMaterialQuota.CurrentRow != null) { if (dgvMaterialQuota.CurrentRow.Cells["Id"] != null && dgvMaterialQuota.CurrentRow.Cells["Id"].Value != null && !string.IsNullOrEmpty(dgvMaterialQuota.CurrentRow.Cells["Id"].Value.ToString())) { bool result = MaterialQuotaBLL.UpdateMeterWeight(dgvMaterialQuota.CurrentRow.Cells["Id"].Value.ToString(), comboType.SelectedIndex, meterWeight); if (result) { BindData(comboType.SelectedIndex); } } } }
/// <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); }
private void BindData(int type) { DataTable dt = MaterialQuotaBLL.GetMeterWeight(type); dgvMaterialQuota.DataSource = dt; if (dt.Columns.Contains("CategoryName")) { dgvMaterialQuota.Columns[4].Visible = type == 1; dgvMaterialQuota.Columns[4].HeaderText = "业务类型"; } }
/// <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; }
/// <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; } }
/// <summary> /// 加载材料定额数据 /// </summary> /// <param name="materiaVerId"></param> private void LoadData(string materiaVerId) { DataTable dt = MaterialQuotaBLL.GetMaterialVersionData(materiaVerId); dgvMaterialQuota.DataSource = dt; }
/// <summary> /// 获取米重量 /// </summary> private void GetProportionData(string codes) { dtMaterialQuota = MaterialQuotaBLL.GetMaterialQuotaData(codes, txtProperty.Text); }