private void DelIngredient() { //删除记录 if (MessageBox.Show("确认删除这(条/些)记录吗?", "询问", MessageBoxButtons.YesNo) == DialogResult.Yes) { try { BaseInfoMaterial bim = BaseInfoMaterial.FindById(long.Parse(BaseParentId)); if (dgvDest.Rows.Count > 0) { int count = 0; foreach (DataGridViewRow row in dgvDest.SelectedRows) { string delId = row.Cells["Id"].Value.ToString(); bim.ConvPrice -= (Decimal)row.Cells["单价"].Value * (Decimal)row.Cells["数量"].Value; BaseInfoMaterialIngredient.DeleteAll(CK.K["Id"] == delId); count++; } MessageBox.Show("已删除" + count + "条记录!"); } else { MessageBox.Show("没有可删除的数据", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (bim.BaseInfoMaterialIngredients.Count == 0) { bim.IsAddToInventory = true; bim.Save(); } else { bim.Save(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Error); } } bsDest.DataSource = null; bsDest.DataSource = BllBaseInfoMaterialIngredients.GetDestTable(UserStatics.OptrType, BaseParentId); dgvDest.DataSource = bsDest; }
private void AddIngredients() { //1.判断右边有无该编码 if ( BaseInfoMaterialIngredient.GetCount(CK.K["BaseInfoMaterial_Id"] == BaseParentId && CK.K["IngredientId"] == _itemId) != 0) { MessageBox.Show("该物料已经添加"); } //2.在右边加入该成品 else { BaseInfoMaterial bim = BaseInfoMaterial.FindById(long.Parse(BaseParentId)); BaseInfoMaterial bimChild = BaseInfoMaterial.FindById(long.Parse(_itemId)); BaseInfoMaterialIngredient baseInfoMaterialIngredient = BaseInfoMaterialIngredient.New; baseInfoMaterialIngredient.IngredientId = long.Parse(_itemId); baseInfoMaterialIngredient.MaterialName = bimChild.Name; baseInfoMaterialIngredient.Price = bimChild.ConvPrice; if (tbAmount.Text == "") { baseInfoMaterialIngredient.Quantity = 1; } else { baseInfoMaterialIngredient.Quantity = Decimal.Parse(tbAmount.Text); } baseInfoMaterialIngredient.Cost = baseInfoMaterialIngredient.Price * baseInfoMaterialIngredient.Quantity; baseInfoMaterialIngredient.OptrType = UserStatics.OptrType; baseInfoMaterialIngredient.Save(); bim.BaseInfoMaterialIngredients.Add(baseInfoMaterialIngredient); bim.ConvPrice += baseInfoMaterialIngredient.Price * baseInfoMaterialIngredient.Quantity; bim.IsAddToInventory = false; bim.Save(); } //3.刷新右边的dgv bsDest.DataSource = null; bsDest.DataSource = BllBaseInfoMaterialIngredients.GetDestTable(UserStatics.OptrType, BaseParentId); dgvDest.DataSource = bsDest; //4.更新主物料的成本 }