private void AlterItemPopup_Load(object sender, EventArgs e) { BackColor = Properties.Settings.Default.BackGroundColor; // Set panels to center of the Form //CommonFunctions.SetPanelDimensions(PMain, ClientSize); CurrentItem = Global.AlterItem; // Sets the currently selected element CurrentSetter(); // Sets the combobox to have all afdelingen from the database GetBenamingen(); }
/// <summary> /// Returns a list of items, as returned from the database /// </summary> /// <param name="items"> The list in which the items should return </param> /// <param name="ConnString"> The connection string to the DataBase </param> /// <returns> Returns a list of MagazijnItems </returns> public static List <MagazijnItems> GetMagazijnItems(List <MagazijnItems> items, string ConnString) { items.Clear(); try { using (var conn = new NpgsqlConnection(ConnString)) { conn.Open(); using (var cmd = new NpgsqlCommand()) { cmd.Connection = conn; cmd.CommandText = string.Format("SELECT voorraad.id, afdelingnaam, nummer, omschrijving, voorraad, prijs " + "FROM voorraad INNER JOIN afdelingen ON (voorraad.afdeling = afdelingen.id) ORDER BY afdelingnaam, omschrijving;"); using (var reader = cmd.ExecuteReader()) { while (reader.Read()) { var res = new MagazijnItems() { Id = reader.GetInt32(0), Afdeling = reader.GetString(1), Nummer = reader.GetString(2), Omschrijving = reader.GetString(3), Voorraad = reader.GetInt32(4), Prijs = reader.GetDouble(5) }; items.Add(res); } } items = items.OrderBy(item => item.Afdeling).ToList(); return(items); } } } catch (Exception ex) { FlexibleMessageBox.Show(ex.Message); return(items); } }
/// <summary> /// When double clicked, opens the form to alter the data /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DgvVoorraad_DoubleClick(object sender, EventArgs e) { // Get the currently sellected row DataGridViewRow selectedRow = DgvVoorraad.CurrentRow; // Get the afdeling from the selected row string Afdeling = selectedRow.Cells["Afdeling"].Value.ToString(); // Get the nummer from the selected row string Nummer = selectedRow.Cells["Nummer"].Value.ToString(); // Get the omschrijing from teh selected row string Omschrijving = selectedRow.Cells["Omschrijving"].Value.ToString(); // Match the selected elements with the list of items var MatchingObject = from Result in ListMagazijnItems where (Result.Afdeling == Afdeling) && (Result.Omschrijving == Omschrijving) && (Result.Nummer == Nummer) select new MagazijnItems() { Id = Result.Id, Afdeling = Result.Afdeling, Nummer = Result.Nummer, Omschrijving = Result.Omschrijving, Voorraad = Result.Voorraad, Prijs = Result.Prijs }; // Get the first result of the linq query MagazijnItems items = MatchingObject.FirstOrDefault(); // Save the result in the global file Global.AlterItem = items; // Open the form mAlterArtikel.Show(ParentForm); }