protected void btn_ImportaListino_Click(object sender, EventArgs e)
        {
            DBTransaction tr = new DBTransaction();

            tr.Begin();
            try
            {
                //// Elimino il listino
                //Mamg0DAO.EliminaListino(tr);

                //// Reinserisco tutto il listino Mamg0, recuperando i dati da un file excel nominato Mamg0.xlsx
                //Mamg0DAO.GetDataFromExcelAndInsertBulkCopy(filePath, tr);

                // Nuovo metodo, con txt
                // Elimino il listino
                List <Mamg0> items = ReadDataFromTextFile();
                Mamg0DAO.DeleteListino(tr);
                Mamg0DAO.InsertListino(items, tr);

                tr.Commit();
                lblImportMsg.Text      = "Importazione del listino avvenuta con successo";
                lblImportMsg.ForeColor = Color.Blue;
            }
            catch (Exception ex)
            {
                tr.Rollback();
                lblImportMsg.Text      = "Errore durante l'importazione del listino. <br />" + ex;
                lblImportMsg.ForeColor = Color.Red;
            }

            // Aggiorno la tabella di visualizzazione risultati
            BindGrid();
        }
        protected void btnEliminaListino_Click(object sender, EventArgs e)
        {
            DBTransaction tr = new DBTransaction();

            tr.Begin();
            try
            {
                Mamg0DAO.DeleteListino(tr);
                tr.Commit();
            }
            catch (Exception ex)
            {
                tr.Rollback();
                throw new Exception("Errore durante l'eliminazione del listino MEF", ex);
            }
            Response.Redirect("~/Listino.aspx");
        }
Example #3
0
        protected void btnClonaGruppo_Click(object sender, EventArgs e)
        {
            DBTransaction tr = new DBTransaction();

            tr.Begin();
            try
            {
                int                   idGruppo      = Convert.ToInt32(ddlScegliGruppo.SelectedItem.Value);
                GruppiFrutti          gf            = GruppiFruttiDAO.GetSingle(idGruppo, tr);
                int                   idGruppoCopia = GruppiFruttiDAO.InserisciGruppo("Copia" + gf.NomeGruppo, gf.Descrizione, tr);
                List <CompGruppoFrut> components    = CompGruppoFrutDAO.GetCompGruppo(idGruppo, tr);
                components.ForEach(f => f.IdTblGruppo = idGruppoCopia);
                CompGruppoFrutDAO.InsertList(components, tr);
                tr.Commit();
            }
            catch (Exception ex)
            {
                tr.Rollback();
                (Master as layout).SetAlert("alert-danger", $"Errore durante la clonazione del gruppo selezionato - {ex.Message}");
            }

            (Master as layout).SetAlert("alert-success", "Gruppo clonato con successo");
            BindGrid();
        }
Example #4
0
        private void TestTransactions(DBRunner runner, ISQLExecuter executer, DBDatabase db, DBTable table, IConnectionInfo connInfo)
        {
            Output("TestTransactions:");
            Output("");

            try
            {
                DBConnection conn = runner.OpenConnection(executer, db, connInfo);

                try
                {
                    Stmt_Insert stmtInsert;
                    Stmt_Select stmtSelect;
                    long        result;

                    Output("Begin transaction");
                    DBTransaction trans = runner.CreateTransaction(executer);
                    trans.Begin(conn);

                    try
                    {
                        Output("Insert row");
                        stmtInsert = new Stmt_Insert(table);
                        stmtInsert.AddColumns("uiNoegle", "iTal", "lStortTal", "dtDato", "bValg");
                        stmtInsert.AddValues(Guid.NewGuid(), 87, (long)2394287487, DateTime.Now, false);
                        runner.Insert(executer, conn, stmtInsert);

                        stmtSelect = new Stmt_Select();
                        stmtSelect.AddTable(table);
                        stmtSelect.AddAggregate(new Aggre_Count());
                        result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect);
                        Output("Count: " + result + " / 1");

                        Output("Rollback");
                        trans.RollbackAll();
                    }
                    catch (Exception)
                    {
                        trans.RollbackAll();
                        throw;
                    }

                    stmtSelect = new Stmt_Select();
                    stmtSelect.AddTable(table);
                    stmtSelect.AddAggregate(new Aggre_Count());
                    result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect);
                    Output("Count: " + result + " / 0");
                    Output("");

                    Output("Begin new transaction");
                    trans = runner.CreateTransaction(executer);
                    trans.Begin(conn);

                    try
                    {
                        Output("Insert row");
                        stmtInsert = new Stmt_Insert(table);
                        stmtInsert.AddColumns("uiNoegle", "iTal", "lStortTal", "dtDato", "bValg");
                        stmtInsert.AddValues(Guid.NewGuid(), 87, (long)2394287487, DateTime.Now, false);
                        runner.Insert(executer, conn, stmtInsert);

                        stmtSelect = new Stmt_Select();
                        stmtSelect.AddTable(table);
                        stmtSelect.AddAggregate(new Aggre_Count());
                        result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect);
                        Output("Count: " + result + " / 1");

                        Output("Commit");
                        trans.CommitAll();
                    }
                    catch (Exception)
                    {
                        trans.RollbackAll();
                        throw;
                    }

                    stmtSelect = new Stmt_Select();
                    stmtSelect.AddTable(table);
                    stmtSelect.AddAggregate(new Aggre_Count());
                    result = runner.SelectWithSingleAggregate(executer, conn, stmtSelect);
                    Output("Count: " + result + " / 1");
                }
                finally
                {
                    conn.Close();
                }
            }
            catch (Exception ex)
            {
                Output("TestTransactions failed with an exception:");
                Output(ex);
            }
            finally
            {
                Output("");
                Output("");
            }
        }