コード例 #1
0
        private void btnSaveToDB_Click(object sender, EventArgs e)
        {
            string        notebookQuery      = null;
            string        keyboardQuery      = null;
            List <string> thinkpadProperties = null;
            List <string> keyboardProperties = null;
            string        connectionString   = "Data Source=.;Initial Catalog=Products;Integrated Security=True";

            if (Factory.listaProductos.Count > 0)
            {
                if (Factory.listaProductos.ContainsType("Thinkpad")) // metodo de extension
                {
                    thinkpadProperties = Factory.GetProperties(Factory.listaProductos, "Thinkpad");
                    notebookQuery      = SQL <Thinkpad> .BuildInsertQuery(thinkpadProperties, "Notebooks");
                }
                if (Factory.listaProductos.ContainsType("MechanicalKeyboard")) // metodo de extension
                {
                    keyboardProperties = Factory.GetProperties(Factory.listaProductos, "MechanicalKeyboard");
                    keyboardQuery      = SQL <MechanicalKeyboard> .BuildInsertQuery(keyboardProperties, "Keyboards");
                }
                try
                {
                    List <Product> temp = new List <Product>(Factory.listaProductos);
                    foreach (Product item in temp)
                    {
                        if (item is Thinkpad)
                        {
                            SQL <Thinkpad> .Insert(connectionString, notebookQuery, thinkpadProperties, (Thinkpad)item);
                        }
                        if (item is MechanicalKeyboard)
                        {
                            SQL <MechanicalKeyboard> .Insert(connectionString, keyboardQuery, keyboardProperties, (MechanicalKeyboard)item);
                        }
                        //this.UpdateView(item);
                        DataBaseModified?.Invoke(item);
                        pFinal = item;
                        pCount++;
                        Factory.listaProductos.Remove(item);
                    }
                    MessageBox.Show("Product/s successfully save to DB. Stock emptied");
                }
                catch (InvalidQueryException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("Stock is empty, nothing to save on DB\nGo build some");
            }
        }
コード例 #2
0
ファイル: ReportsFrm.cs プロジェクト: toty88/tp_laboratorio_2
        private void btnGuardarEnBase_Click(object sender, EventArgs e)
        {
            string        notebookQuery      = null;
            string        keyboardQuery      = null;
            List <string> thinkpadProperties = null;
            List <string> keyboardProperties = null;

            if (Factory.listaProductos.Count > 0)
            {
                try
                {
                    if (Factory.listaProductos.ContainsType("Thinkpad")) // metodo de extension
                    {
                        thinkpadProperties = Factory.GetProperties(Factory.listaProductos, "Thinkpad");
                        notebookQuery      = SQL <Thinkpad> .BuildInsertQuery(thinkpadProperties, "Notebooks");
                    }
                    if (Factory.listaProductos.ContainsType("MechanicalKeyboard")) // metodo de extension
                    {
                        keyboardProperties = Factory.GetProperties(Factory.listaProductos, "MechanicalKeyboard");
                        keyboardQuery      = SQL <MechanicalKeyboard> .BuildInsertQuery(keyboardProperties, "Keyboards");
                    }
                    foreach (Product item in Factory.listaProductos)
                    {
                        if (item is Thinkpad)
                        {
                            SQL <Thinkpad> .Insert(notebookQuery, thinkpadProperties, (Thinkpad)item);
                        }
                        if (item is MechanicalKeyboard)
                        {
                            SQL <MechanicalKeyboard> .Insert(keyboardQuery, keyboardProperties, (MechanicalKeyboard)item);
                        }
                    }
                    List <Product> temp = new List <Product>(Factory.listaProductos);
                    DataBaseModified?.Invoke(temp);
                    MessageBox.Show("Producto/s Enviados a BD con EXITO. Se vacia Stock!");
                }
                catch (InvalidQueryException ex)
                {
                    MessageBox.Show(ex.Message);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                MessageBox.Show("ATENCION: No existen Productos en Stock\nCONSTRUI Algunos!!!!");
            }
        }