private void btnDelete_Click(object sender, EventArgs e) { try { ClassLibrary.Part part = new ClassLibrary.Part(); object id = dataGridView1.CurrentRow.Cells["PART_id"].Value; DataRow selectedRow = dtParts.Rows.Find(id); DialogResult dlgResult = MessageBox.Show ("this will delete the part and all the information related to the part", "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dlgResult == DialogResult.Yes) { part.Id = Convert.ToInt32(id); part.Delete(); DisplayAllParts(); } } catch (Exception ex) { DialogResult dlgResult = MessageBox.Show ("Cant delete the part! you are ordering this part from a supplier, please delete the supplier order first", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void DisplayAllParts() { ClassLibrary.Part part = new ClassLibrary.Part(); dtParts = part.GetAll().Tables[0]; bsSource.DataSource = dtParts; //set the parts id column as primary key so you can search the table later dtParts.PrimaryKey = new DataColumn[] { dtParts.Columns["PART_id"] }; dataGridView1.DataSource = dtParts; dataGridView1.Columns["PART_id"].HeaderText = "ID"; dataGridView1.Columns["PART_name"].HeaderText = "Name"; dataGridView1.Columns["PART_color"].HeaderText = "Color"; dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; }
//----------------------------------------------------------------------------------------------- private void frmAddSupplier_Load(object sender, EventArgs e) { //make parts list parts = new BindingList <PartList>(); //add parts to the combobox ClassLibrary.Part part = new ClassLibrary.Part(); dtPart = part.GetAll().Tables[0]; if (drSupllier == null) { } else { txtName.Text = drSupllier.ItemArray[1].ToString(); txtFailiureRate.Text = drSupllier.ItemArray[2].ToString(); txtPhone.Text = drSupllier.ItemArray[3].ToString(); txtEmail.Text = drSupllier.ItemArray[4].ToString(); txtAddress.Text = drSupllier.ItemArray[5].ToString(); txtPostalCode.Text = drSupllier.ItemArray[6].ToString(); txtProvince.Text = drSupllier.ItemArray[6].ToString(); ClassLibrary.SupplierPart supplierpart = new ClassLibrary.SupplierPart(); supplierpart.SupplierId = Convert.ToInt32(drSupllier.ItemArray[0]); DataTable thisTable = supplierpart.GetSupplierPartsBySupplierId().Tables[0]; foreach (DataRow row in thisTable.Rows) { //add to generic list parts.Add(new PartList { partID = Convert.ToInt32(row.ItemArray[0]), partName = row.ItemArray[1].ToString(), price = Convert.ToInt32(row.ItemArray[2]), }); } dataGridView1.DataSource = parts; } }
//------------------------------------------------------------------- private void frmAddProduct_Load(object sender, EventArgs e) { BOM = new BindingList <ProductBuildSheet>(); //add Parts to the combobox ClassLibrary.Part part = new ClassLibrary.Part(); dtParts = part.GetAll().Tables[0]; cmbParts.DataSource = dtParts; cmbParts.DisplayMember = "PART_name"; //ADDING MODE if (drCustomer == null) { } //EDITING MODE else { try { //System.Drawing.Image _image = System.Drawing.Image.FromStream // (new System.IO.MemoryStream((byte[])drCustomer[6])); //byte[] blob = (byte[])drCustomer[6]; //picProductImage.Image = _image; //picProductImage.SizeMode = PictureBoxSizeMode.StretchImage; //picProductImage.Refresh(); picProductImage.Image = Image.FromFile(picturesPath + drCustomer[6].ToString()); picProductImage.SizeMode = PictureBoxSizeMode.StretchImage; picProductImage.Refresh(); } catch (Exception ex) {} //display product information txtName.Text = drCustomer.ItemArray[1].ToString(); txtCost.Text = String.Format("{0:c}", drCustomer.ItemArray[2]); txtPrice.Text = String.Format("{0:c}", drCustomer.ItemArray[3]); txtColor.Text = drCustomer.ItemArray[4].ToString(); txtDescription.Text = drCustomer.ItemArray[5].ToString(); //display buildsheet ClassLibrary.BuildOfMaterial BuildOfMaterial = new ClassLibrary.BuildOfMaterial(); BuildOfMaterial.ProductId = Convert.ToInt32(drCustomer.ItemArray[0]); DataTable thisTable = BuildOfMaterial.GetAllPartsByProductId().Tables[0]; foreach (DataRow row in thisTable.Rows) { //add to generic list BOM.Add(new ProductBuildSheet { PartID = Convert.ToInt32(row.ItemArray[2]), PartName = row.ItemArray[0].ToString(), Quantity = Convert.ToInt32(row.ItemArray[1]), }); } dataGridView1.DataSource = BOM; } }
//------------------------------------------------------------------------------------------------- private void btnSaveToDatabase_Click(object sender, EventArgs e) { if ( (txtName.Text == "") ) { MessageBox.Show("please fill all the empty fields"); } else { try { //ADD MODE if (drRow == null) { ClassLibrary.Part part = new ClassLibrary.Part(); part.Name = txtName.Text; part.Color = txtColor.Text; int lastInsertedId = part.Add(); //add Suppliers ClassLibrary.SupplierPart supplierPart = new ClassLibrary.SupplierPart(); supplierPart.PartId = lastInsertedId; foreach (SupplierList s in supplerlist) { supplierPart.SupplierId = s.SupplierID; supplierPart.Price = Convert.ToDecimal(s.price.Replace("$", "")); supplierPart.Add(); } } //EDIT MODE else if (drRow != null) { ClassLibrary.Part part = new ClassLibrary.Part(); part.Id = Convert.ToInt32(drRow.ItemArray[0]); part.Name = txtName.Text; part.Color = txtColor.Text; part.Update(); //save supplier list to the database ClassLibrary.SupplierPart supplierPart = new ClassLibrary.SupplierPart(); supplierPart.PartId = part.Id; supplierPart.DeleteSupplierPartsByPartId(); foreach (SupplierList s in supplerlist) { supplierPart.SupplierId = s.SupplierID; supplierPart.Price = Convert.ToDecimal(s.price.Replace("$", "")); supplierPart.Add(); } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } if (formDisSupplierOrder != null) { //formDisSupplierOrder.DisplayOrderParts(); } else { frmDisParts.DisplayAllParts(); } Close(); } }