public static void RemovePart(int index) { using (var con = new InventoryMgmtEntities()) { partsdb partTemp = con.partsdbs.Find(index); con.partsdbs.Remove(partTemp); con.SaveChanges(); } }
//Parts public static int AddPart(partsdb part) { using (var con = new InventoryMgmtEntities()) { con.partsdbs.Add(part); con.SaveChanges(); return(part.partid); } }
private void btAddPartSave_Click(object sender, EventArgs e) { if (l_Modify_PartName.Visible == true || l_Modify_Price.Visible == true || l_Modify_PartInventory.Visible == true || l_Modify_Max.Visible == true || l_Modify_Min.Visible == true || l_Modify_MachineIDName.Visible == true) { MessageBox.Show("You must fix the red boxes before you can save."); return; } if (Int32.Parse(tbModifyPartMax.Text) <= Int32.Parse(tbModifyPartMin.Text)) { MessageBox.Show("Max must be greater than Min."); return; } if ((Int32.Parse(tbModifyPartInventory.Text) <= Int32.Parse(tbModifyPartMin.Text)) || (Int32.Parse(tbModifyPartInventory.Text) >= Int32.Parse(tbModifyPartMax.Text))) { MessageBox.Show("Inventory must be greater than min and less than max."); return; } if (isPart) { partsdb tempPart = new partsdb(); tempPart.createdby = dbHelper.currentUser.userid; tempPart.name = tbModifyPartName.Text; tempPart.price = Decimal.Parse(tbModifyPartPrice.Text); tempPart.instock = Int32.Parse(tbModifyPartInventory.Text); tempPart.min = Int32.Parse(tbModifyPartMin.Text); tempPart.max = Int32.Parse(tbModifyPartMax.Text); tempPart.details = tbModifyPartMachineIdCompanyName.Text; tempPart.lastmodified = DateTime.Now; tempPart.type = rdbModifyPartInHouse.Checked ? "i" : "o"; dbHelper.AddPart(tempPart); } else { BuildPart(); if (IsSame()) { MessageBox.Show("You haven't modified any part details", "Warning"); return; } dbHelper.UpdatePart(newPart); } test.Show(); this.Close();; }
private static int TestPart() { DateTime dateTimenow = DateTime.Now; int testsPassed = 0; partsdb part1 = new partsdb(); part1.name = "PartTest"; part1.price = 12.34M; part1.instock = 666; part1.min = 5; part1.max = 999; part1.type = "i"; part1.details = "ABC100"; part1.lastmodified = dateTimenow; cl(""); cl("---Running part creation test."); int idIndex = dbHelper.AddPart(part1); if (dbHelper.PartExists(idIndex)) { cl("Part creation test PASSED"); testsPassed++; cl("---Running part retrieval test."); partsdb testpart = dbHelper.GetPart(idIndex); if ((testpart.partid == idIndex) && (testpart.instock == part1.instock)) { testsPassed++; cl("Part retrieval test PASSED."); cl("---Running part deletion test."); dbHelper.RemovePart(idIndex); if (!dbHelper.PartExists(idIndex)) { testsPassed++; cl("Part deletion test has PASSED."); } else { cl("Part deletion test has FAILED."); } } else { cl("Part retrieval test FAILED."); } } else { cl("Part creation test FAILED."); } return(testsPassed); }
public static void UpdatePart(partsdb part) { partsdb updatedPart = part; using (var con = new InventoryMgmtEntities()) { partsdb tempPart = con.partsdbs.Find(updatedPart.partid); tempPart.name = updatedPart.name; tempPart.instock = updatedPart.instock; tempPart.min = updatedPart.min; tempPart.max = updatedPart.max; tempPart.type = updatedPart.type; tempPart.details = updatedPart.details; tempPart.price = updatedPart.price; tempPart.lastmodified = DateTime.Now; if (updatedPart.createdby != null) { tempPart.createdby = updatedPart.createdby; } con.SaveChanges(); } }
public static List <partsdb> GetDerivedParts(int productIndex) { using (var con = new InventoryMgmtEntities()) { List <productspart> productPartList = con.productsparts.Where(n => n.productid == productIndex).ToList(); List <partsdb> tempList = new List <partsdb>(); for (int i = 0; i < productPartList.Count(); i++) { //Get part based on productPartLists.partID partsdb partTemp = con.partsdbs.Find(productPartList[i].partid); partDerived tempDerivedPart = new partDerived(); tempDerivedPart.zproductpartid = productPartList[i].productpartid; tempDerivedPart.name = partTemp.name; tempDerivedPart.instock = partTemp.instock; tempDerivedPart.max = partTemp.max; tempDerivedPart.min = partTemp.min; tempDerivedPart.partid = partTemp.partid; tempDerivedPart.price = partTemp.price; tempDerivedPart.type = partTemp.type; tempDerivedPart.createdby = partTemp.createdby; tempDerivedPart.details = partTemp.details; tempDerivedPart.lastmodified = partTemp.lastmodified; //partDerived tempDerived = (partDerived)partTemp; //cast operation instead? tempList.Add(tempDerivedPart); } return(tempList); } }
private void ModifyPartForm_Load(object sender, EventArgs e) { if (isPart) { label1.Text = "Add Part"; this.Text = "Add Part Form"; setColors(); return; } label1.Text = "Modify Part"; this.Text = "Modify Part Form"; modify = dbHelper.GetPart(partId); if (modify != null) { newPart.type = modify.type; if (modify.createdby != null) { newPart.createdby = modify.createdby; } tbModifyPartID.Text = Convert.ToString(modify.partid); tbModifyPartName.Text = modify.name; tbModifyPartPrice.Text = modify.price.ToString("#,0.00"); tbModifyPartInventory.Text = Convert.ToString(modify.instock); tbModifyPartMax.Text = Convert.ToString(modify.max); tbModifyPartMin.Text = Convert.ToString(modify.min); if (modify.type == "i") { rdbModifyPartInHouse.Checked = true; tbModifyPartMachineIdCompanyName.Text = Convert.ToString(modify.details); } if (modify.type == "o") { rdbModifyPartOutsourced.Checked = true; tbModifyPartMachineIdCompanyName.Text = Convert.ToString(modify.details); } } }
private void dgvModifyProductAddParts_CellClick(object sender, DataGridViewCellEventArgs e) { modifyProductRemovePartsIndex = dgvModifyProductAddParts.CurrentCell.RowIndex; partToRemove = addedParts[modifyProductRemovePartsIndex]; }
private void dgvModifyProductAllParts_CellClick(object sender, DataGridViewCellEventArgs e) { modifyProductAllPartsIndex = dgvModifyProductAllParts.CurrentCell.RowIndex; chosenPart = allParts[modifyProductAllPartsIndex]; }