private Prodotto CercaById(int codice)
        {
            DataBases db = new DataBases();

            foreach (Prodotto p in db.products)
            {
                if (p.Codice == codice)
                {
                    return(p);
                }
            }
            return(null);
        }
        private List <Prodotto> CercaProducts(string wordSearch)
        {
            DataBases       db       = new DataBases();
            List <Prodotto> products = db.products;
            List <Prodotto> result   = new List <Prodotto>();

            foreach (Prodotto p in products)
            {
                if (p.Descrizione.Contains(wordSearch))
                {
                    result.Add(p);
                }
            }
            return(result);
        }
 protected void Cerca(object sender, EventArgs e)
 {
     if (!String.IsNullOrEmpty(id.Text))
     {
         Response.Redirect($"~/Detail.aspx?codice={id.Text}");
     }
     else if (!String.IsNullOrEmpty(descr.Text))
     {
         DataBases db = new DataBases();
         foreach (var p in CercaProducts(descr.Text))
         {
             TableRow  tr     = new TableRow();
             TableCell codice = new TableCell();
             codice.Controls.Add(new Label()
             {
                 Text = p.Codice.ToString(), CssClass = "col-xs-2"
             });
             tr.Cells.Add(codice);
             TableCell descri = new TableCell();
             descri.Controls.Add(new Label()
             {
                 Text = p.Descrizione, CssClass = "col-xs-6"
             });
             tr.Cells.Add(descri);
             TableCell qnt = new TableCell();
             qnt.Controls.Add(new Label()
             {
                 Text = p.Quantita.ToString(), CssClass = "col-xs-2"
             });
             tr.Cells.Add(qnt);
             TableCell but = new TableCell();
             but.Controls.Add(new Button()
             {
                 Text = "Dettaglio", PostBackUrl = $"Detail?codice={p.Codice}", CssClass = "col-xs-2"
             });
             tr.Cells.Add(but);
             Table1.Rows.Add(tr);
         }
     }
 }
Example #4
0
        protected void AddRequest(object sender, EventArgs e)
        {
            DataBases     db         = new DataBases();
            SqlConnection connection = db.InitConnection();

            try {
                connection.Open();
                foreach (Prodotto p in Session["prodotti"] as List <Prodotto> )
                {
                    SqlCommand command = new SqlCommand("dbo.AddRequest", connection);
                    command.CommandType = System.Data.CommandType.StoredProcedure;
                    command.Parameters.Add("@id", System.Data.SqlDbType.Int).Value       = p.Codice;
                    command.Parameters.Add("@quantita", System.Data.SqlDbType.Int).Value = p.Quantita;
                    command.Dispose();
                    Session["prodotti"] = null;
                }
            }catch (Exception p) {
                throw p;
            } finally {
                connection.Dispose();
            }
        }