private void btn_stueckAktualisieren_Click(object sender, EventArgs e) { //foreach (DataGridViewRow row in dgv_stueckliste.Rows) for (int i = 0; i < dgv_stueckliste.RowCount - 1; i++) { var row = dgv_stueckliste.Rows[i]; double.TryParse(row.Cells[2].Value.ToString(), out double menge); if (row.Cells[2].Value != null) { Stueckliste stueckliste = new Stueckliste( Convert.ToInt32(tbx_fertigArtNr.Text), tbx_fertigBezeichnung.Text, Convert.ToInt32(row.Cells[0].Value), row.Cells[1].Value.ToString(), menge, row.Cells[3].Value.ToString() ); //foreach (DataGridViewCell cell in row.Cells) // Console.WriteLine(cell.ValueType); db.UpdateStueckliste(stueckliste); } } GetLists(); PopulateDgvStueckliste(); }
public void UpdateStueckliste(Stueckliste stueckliste) { try { OpenDB(); com = con.CreateCommand(); if (stueckliste.Menge > 0) { com.CommandText = String.Format("INSERT INTO tbl_stueckliste VALUES ({0}, {1}, {2}) ON DUPLICATE KEY UPDATE stueckliste_menge = {2};", stueckliste.FertigId.ToString(), stueckliste.RohId.ToString(), stueckliste.Menge.ToString().Replace(',', '.')); } else { com.CommandText = String.Format("DELETE FROM tbl_stueckliste WHERE fk_fertig_id = {0} AND fk_roh_id = {1}", stueckliste.FertigId.ToString(), stueckliste.RohId.ToString()); } //com.CommandText = String.Format("UPDATE tbl_stueckliste SET fk_fertig_id = {0}, fk_roh_id = {1}, stueckliste_menge = {2} WHERE fk_fertig_id = {0} AND fk_roh_id = {1};", stueckliste.FertigId.ToString(), stueckliste.RohId.ToString(), stueckliste.Menge.ToString().Replace(',', '.')); com.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("UR: " + ex.Message); } finally { CloseDB(); } }
public List <Stueckliste> GetStuecklisten() { var stuecklistenList = new List <Stueckliste>(); try { OpenDB(); com = con.CreateCommand(); com.CommandText = "SELECT * FROM v_stueckliste;"; var reader = com.ExecuteReader(); while (reader.Read()) { var stueckliste = new Stueckliste( !reader.IsDBNull(0) ? reader.GetInt32(0) : -1, // fk_fertig_id !reader.IsDBNull(1) ? reader.GetString(1) : "", // fertig_bezeichnung !reader.IsDBNull(2) ? reader.GetInt32(2) : -1, // fk_roh_id !reader.IsDBNull(3) ? reader.GetString(3) : "", // roh_bezeichnung !reader.IsDBNull(4) ? reader.GetDouble(4) : 0.0, // Menge !reader.IsDBNull(5) ? reader.GetString(5) : "" // Einheit ); stuecklistenList.Add(stueckliste); } } catch (Exception ex) { MessageBox.Show("GS: " + ex.Message); } finally { CloseDB(); } return(stuecklistenList); }
public void AddStueckliste(Stueckliste stueckliste) { try { OpenDB(); com = con.CreateCommand(); com.CommandText = String.Format("INSERT INTO tbl_stueckliste VALUES ({0}, {1}, {2});", stueckliste.FertigId.ToString(), stueckliste.RohId.ToString(), stueckliste.Menge.ToString().Replace(',', '.')); com.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show("AS: " + ex.Message); } finally { CloseDB(); } }