public async Task <IActionResult> Edit(int id, [Bind("MaterialSuplyId,Provider,MaterialId,PriceOfMaterials,AmountOfMaterial,DeliveryDate")] MaterialSupply materialSupply) { if (id != materialSupply.MaterialSuplyId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(materialSupply); await _context.SaveChangesAsync(); _cachedService.RefreshMaterialSupplys(); } catch (DbUpdateConcurrencyException) { if (!MaterialSupplyExists(materialSupply.MaterialSuplyId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MaterialId"] = new SelectList(_context.Materials, "IdMaterial", "MaterialName", materialSupply.MaterialId); return(View(materialSupply)); }
public async Task <IActionResult> Create([Bind("MaterialSuplyId,Provider,MaterialId,PriceOfMaterials,AmountOfMaterial,DeliveryDate")] MaterialSupply materialSupply) { if (ModelState.IsValid) { _context.Add(materialSupply); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MaterialId"] = new SelectList(_context.Materials, "IdMaterial", "MaterialName", materialSupply.MaterialId); _cachedService.RefreshMaterialSupplys(); return(View(materialSupply)); }
private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) { if (e.ColumnIndex == 2 && e.RowIndex > -1) { var row = dataGridView1.Rows[e.RowIndex]; MaterialSupply supply = null; if (!ParseRow(row, out supply)) { return; } using (var context = new FactoryContext()) { var material = context.Materials.Single(m => m.MaterialId == supply.MaterialId); row.Cells[3].Value = material.Price * supply.Quantity; } } }
private bool ParseRow(DataGridViewRow row, out MaterialSupply supply) { supply = new MaterialSupply(); var id = row.Cells[0].Value; if (id == null || id.ToString().Length == 0) { return(false); } int count = 0; if (!Int32.TryParse(row.Cells[2].Value.ToString(), out count)) { return(false); } supply.MaterialId = id.ToString(); supply.Quantity = count; return(true); }
private void button3_Click(object sender, EventArgs e) { using (var context = new FactoryContext()) { foreach (DataGridViewRow row in dataGridView1.Rows) { MaterialSupply supply = null; if (!ParseRow(row, out supply)) { continue; } for (int i = 0; i < supply.Quantity; ++i) { var roll = new MaterialRoll(context.Materials.Single(m => m.MaterialId == supply.MaterialId)); context.MaterialRolls.Add(roll); } } context.SaveChanges(); MessageBox.Show("Данные успешно сохранены"); } }