Exemple #1
0
        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.currentProducto = int.Parse(cellId.Value.ToString());
                this.parent.sendMessage(cellId.Value.ToString() + " " + cellValue.Value.ToString());
            }
            catch (Exception ex)
            {
            }


            if (e.ColumnIndex == 3 && 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().getProductoDAO().BorrarProducto(bid);
                    dataGridView1.Rows.RemoveAt(e.RowIndex); //delete the row from the DataGridView
                }
            }
            else if (e.ColumnIndex == 3 && newrow) //save icon button is clicked
            {
                try
                {
                    String producte = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
                    int    preu     = int.Parse(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());

                    DialogResult result = MessageBox.Show("Guardando siguiente registro:\n" + producte.ToString() + "\n" + preu.ToString(), "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (result == DialogResult.OK)
                    {
                        // addProducto(producte, preu); //add the new row to the producte table
                        var prod = new productes {
                            producte = producte, preu = preu
                        };
                        new DAOFactory().getProductoDAO().CrearProducto(prod);
                        newrow = false;
                        dataGridView1.Rows[e.RowIndex].Cells[3].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);
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Crea un nuevo objeto producto
 /// </summary>
 /// <param name="p">objeto producto que se quiere guadar</param>
 public void CrearProducto(productes p)
 {
     //Querying with LINQ to Entities
     using (var context = new dbempresaEntities())
     {
         context.productes.Add(p);
         context.SaveChanges();
     }
 }
Exemple #3
0
 /// <summary>
 /// Método que elimina un registro de la base de datos
 /// </summary>
 /// <param name="id">id del producto que se quiere borrar</param>
 public void BorrarProducto(int id)
 {
     using (var context = new dbempresaEntities())
     {
         try
         {
             productes prod = context.productes.First(i => i.id_produte == id);
             context.productes.Remove(prod);
             context.SaveChanges();
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.InnerException);
         }
     }
 }
Exemple #4
0
        /// <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);
                }
            }
        }