public void CrearDetall(factura_detall f) { using (var context = new dbempresaEntities()) { context.factura_detall.Add(f); context.SaveChanges(); } }
public void BorrarDetall(int id) { using (var context = new dbempresaEntities()) { try { factura_detall fac = context.factura_detall.First(i => i.id_factura_detall == id); context.factura_detall.Remove(fac); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException); } } }
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { try { DataGridViewTextBoxCell cellId = (DataGridViewTextBoxCell) dataGridView1.Rows[e.RowIndex].Cells[0]; DataGridViewTextBoxCell cellValue = (DataGridViewTextBoxCell) dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex]; this.parent.sendMessage(cellId.Value.ToString() + " " + cellValue.Value.ToString()); } catch (Exception ex) { } // if combobox cell is clicked change cell with combobox if (e.ColumnIndex == 1 && e.RowIndex >= 0) { parent.sendMessage("entra combo"); _Rectangle = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); // comboBoxFacturas.Size = new Size(_Rectangle.Width, _Rectangle.Height); // comboBoxFacturas.Location = new Point(_Rectangle.X, _Rectangle.Y); // comboBoxFacturas.Visible = true; } // if combobox cell is clicked change cell with combobox if (e.ColumnIndex == 2 && e.RowIndex >= 0) { parent.sendMessage("entra combo"); _Rectangle = dataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true); // comboBoxProductes.Size = new Size(_Rectangle.Width, _Rectangle.Height); // comboBoxProductes.Location = new Point(_Rectangle.X, _Rectangle.Y); // comboBoxProductes.Visible = true; } if (e.ColumnIndex == deleteColumn && e.RowIndex >= 0 && newrow != true) //delete icon button is clicked { int bid = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()); DialogResult result = MessageBox.Show("Quieres eliminar este registro?", "Confirmación", MessageBoxButtons.OKCancel); if (result == DialogResult.OK) { //deleteProdute(bid); //delete the record from the producte table new DAOFactory().getFacturaDetallDAO().BorrarFacturaDetall(bid); dataGridView1.Rows.RemoveAt(e.RowIndex); //delete the row from the DataGridView } } else if (e.ColumnIndex == deleteColumn && newrow) //save icon button is clicked { try { int n_factura = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString()); int id_producte = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());; int quantitat = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString());; DialogResult result = MessageBox.Show("Guardando siguiente registro:\n", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); if (result == DialogResult.OK) { // addProducto(producte, preu); //add the new row to the producte table var fac = new factura_detall { n_factura = n_factura, id_producte = id_producte, quantitat = quantitat }; new DAOFactory().getFacturaDetallDAO().CrearFacturaDetall(fac); newrow = false; dataGridView1.Rows[e.RowIndex].Cells[deleteColumn].Value = Image.FromFile(Environment.CurrentDirectory + "/images/del.jpg").GetThumbnailImage(15, 15, null, IntPtr.Zero); // dataGridView1.EndEdit(); // dataGridView1.Refresh(); dataGridView1.EndEdit(); this.context.SaveChanges(); this.loadData(); } } catch (Exception ex) { MessageBox.Show("Unable to save the record. The problem might come from the following:\n1. Blank fields\n2. Duplicate record", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Método que carga las entradas del XML en el context de la bd /// </summary> /// <returns></returns> public bool loadListFromXML() { if (xmlDoc == null) { return(false); } else { try { //Debug.WriteLine(xmlDoc.InnerXml); foreach (XmlNode client in xmlDoc.SelectNodes("empresa/clients/client")) { //< id_client > 123 </ id_client >< nom > David </ nom >< cognom1 > Ramírez </ cognom1 > //< cognom2 > Campoy </ cognom2 >< adreça > Mollet </ adreça >< codi_postal > 080100 </ codi_postal > //< poblacio > Mollet </ poblacio >< provincia > Barcelona </ provincia >< telefon > 696969696 </ telefon > //< fax > 686868686 </ fax >< email > [email protected] </ email > Debug.WriteLine(client.InnerXml); clients c = new clients(); c.id_client = Int32.Parse(client.SelectSingleNode("id_client").InnerText); c.nom = client.SelectSingleNode("nom").InnerText; c.cognom1 = client.SelectSingleNode("cognom1").InnerText; c.cognom2 = client.SelectSingleNode("cognom2").InnerText; c.adreça = client.SelectSingleNode("adreça").InnerText; c.codi_postal = Int32.Parse(client.SelectSingleNode("codi_postal").InnerText); c.poblacio = client.SelectSingleNode("poblacio").InnerText; c.provincia = client.SelectSingleNode("provincia").InnerText; c.telefon = Int32.Parse(client.SelectSingleNode("telefon").InnerText); c.fax = Int32.Parse(client.SelectSingleNode("fax").InnerText); c.email = client.SelectSingleNode("email").InnerText; clientList.Add(c); } foreach (XmlNode factura in xmlDoc.SelectNodes("empresa/factures/factura")) { /* * < factura > * < n_factura > 1111 </ factures > * < id_client > 123 </ client > * < data > 2017 - 12 - 05 00:10:00 < data > * < descompte > 5 </ descompte > * < iva > 21 </ iva > * </ factura >*/ Debug.WriteLine(factura.InnerXml); factura fc = new factura(); fc.n_factura = Int32.Parse(factura.SelectSingleNode("n_factura").InnerText); fc.id_client = Int32.Parse(factura.SelectSingleNode("id_client").InnerText); fc.data = DateTime.Parse(factura.SelectSingleNode("data").InnerText); fc.descompte = Int32.Parse(factura.SelectSingleNode("descompte").InnerText); fc.iva = Int32.Parse(factura.SelectSingleNode("iva").InnerText); facturaList.Add(fc); } foreach (XmlNode factura_detall in xmlDoc.SelectNodes("empresa/factures_detall/factura_detall")) { /* * <factures_detall> * <factura_detall> * <id_factura_detall>2222</id_factura_detall> * <n_factura>1111</n_factura> * <id_producte>333</id_producte> * <quantitat>5</quantitat> * </factura_detall> * </factures_detall>*/ Debug.WriteLine(factura_detall.InnerXml); factura_detall fcd = new factura_detall(); fcd.id_factura_detall = Int32.Parse(factura_detall.SelectSingleNode("id_factura_detall").InnerText); fcd.n_factura = Int32.Parse(factura_detall.SelectSingleNode("n_factura").InnerText); fcd.id_producte = Int32.Parse(factura_detall.SelectSingleNode("id_produte").InnerText); fcd.quantitat = Int32.Parse(factura_detall.SelectSingleNode("quantitat").InnerText); factura_detallList.Add(fcd); } foreach (XmlNode producte in xmlDoc.SelectNodes("empresa/productes/producte")) { /*<productes> * <producte> * <id_producte>333</id_producte> * <producte>Laser</producte> * <preu>190</preu> * </producte> * </productes>*/ Debug.WriteLine(producte.InnerXml); productes prod = new productes(); prod.id_produte = Int32.Parse(producte.SelectSingleNode("id_produte").InnerText); prod.producte = producte.SelectSingleNode("producte").InnerText; prod.preu = Int32.Parse(producte.SelectSingleNode("preu").InnerText); producteList.Add(prod); } return(true); } catch (Exception e) { return(false); } } }