private void afegirProductesBBDD() { int Id = Int32.Parse(bd.resultatComanda("SELECT max(id_venda) FROM vendes")); Boolean VendaCorrecte = true; //Per cada Producte en el ticket l'afageix a linia_venda a la bbdd foreach (ListViewItem itemRow in this.listViewCompra.Items) { string producte = itemRow.SubItems[0].Text; int IdProd = Int32.Parse(bd.resultatComanda("SELECT id_medicament FROM medicaments where nom_comercial = '" + producte + "'")); int cantidad = Int32.Parse(itemRow.SubItems[3].Text); string preu = itemRow.SubItems[1].Text; preu = preu.Replace(@",", "."); string iva = itemRow.SubItems[2].Text; iva = iva.Replace(@",", "."); var correcte = bd.executaComanda("insert into linia_venda (id_venda,id_medicament,quantitat,pvp,IVA) values (" + Id + "," + IdProd + "," + cantidad + "," + preu + "," + iva + ")"); //si s'ha afegit correctament baixara el stock dels medicaments comprats a la bbdd if (!correcte.Equals(0)) { int stockNumber = Int32.Parse(bd.resultatComanda("SELECT stock FROM medicaments where id_medicament = " + IdProd)); stockNumber -= cantidad; correcte = bd.executaComanda("update medicaments set stock= " + stockNumber + " where id_medicament = " + IdProd); if (correcte.Equals(0)) { VendaCorrecte = false; } } else { VendaCorrecte = false; } } if (VendaCorrecte) { MessageBox.Show("Venda Tramitada"); //actualitza la dataGridView medicaments = bd.portarPerConsulta("select v.registre_nacional, v.nom_comercial as 'Producte',v.contingut, e.nom as 'Principi_Actiu',v.PVP,v.IVA,v.stock,v.substituible,v.generic from medicaments v , principis_actius e where v.id_PrincipiActiu = e.id_PrincipiActiu", "medicaments"); CcQuant.SelectedIndex = 0; BindingDades("medicaments"); } else { MessageBox.Show("Error al tramitar la venda"); } }
public void PortarDadesMySQL(string table) { ConexioBBDD.Conexio bd = new ConexioBBDD.Conexio(); query = "Select * from " + table; dataSet = bd.portarPerConsulta(query, table); BindingDades(table); }
private void Clients_Load(object sender, EventArgs e) { query = "Select * from " + table; dataSet = bd.portarPerConsulta(query, table); //ComboBox table options comboBoxQuery = "Select id_carnet, nom_carnet from " + CcomboBox.Reference; DataTable t = bd.searchTableFromQuery(comboBoxQuery); addComboBoxData(t, CcomboBox); BindingDades(table); clientsDataGridView.Columns[0].Visible = false; clientsDataGridView.Columns[7].Visible = false; }
public void ActualitzarMySQL(string table) { Boolean correcte = false; correcte = ComprovarCamps(); if (correcte) { ConexioBBDD.Conexio bd = new ConexioBBDD.Conexio(); correcte = bd.Actualitzar(query, table, dataSet); if (correcte) { MessageBox.Show("Dades actualitzades"); bd.portarPerConsulta(query, table); } else { MessageBox.Show("Error al actualitzar les dades"); } } else { MessageBox.Show("Camps buits"); } }