Beispiel #1
0
        private void btnSaveTransaction_Click(object sender, System.EventArgs e)
        {
            TransactionMgr tx = TransactionMgr.ThreadTransactionMgr();

            try
            {
                tx.BeginTransaction();

                this.emps.Save();
                this.prds.Save();

                tx.CommitTransaction();

                BindEmployeesGrid();
                BindProductsGrid();
            }
            catch (Exception)
            {
                tx.RollbackTransaction();
                TransactionMgr.ThreadTransactionMgrReset();
                MessageBox.Show("You need to generate the stored procedures for 'Employees' and 'Products' to be able to save. Use 'SQL_StoredProcs.vbgen' to generate them.");
            }
        }
Beispiel #2
0
        static bool SQLITE()
        {
            try
            {
                // LoadAll
                CSharp.SQLite.vwEmployees vemps = new CSharp.SQLite.vwEmployees();
                vemps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                vemps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.EmployeeID);
                vemps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.LastName);
                vemps.Query.AddOrderBy(CSharp.SQLite.Employees.ColumnNames.LastName, WhereParameter.Dir.ASC);
                vemps.Query.Top = 2;
                if (!vemps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                // LoadAll
                CSharp.SQLite.Employees emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                emps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.EmployeeID);
                emps.Query.AddResultColumn(CSharp.SQLite.Employees.ColumnNames.LastName);
                emps.Query.AddOrderBy(CSharp.SQLite.Employees.ColumnNames.LastName, WhereParameter.Dir.ASC);
                emps.Query.Top = 2;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                // LoadAll
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                long id = emps.EmployeeID;
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3;";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString         = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.SQLite.Employees emps1 = new CSharp.SQLite.Employees();
                emps1.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.SQLite.Employees emps2 = new CSharp.SQLite.Employees();
                emps2.ConnectionString = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.SQLite.Employees();
                emps.ConnectionString         = @"Data Source=C:\SQLite\employee.db;New=False;Compress=True;Synchronous=Off;Version=3";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
        private void btnChangeTo_Click(object sender, EventArgs e)
        {
            // Do validation
            if (dxErrorCorrectionValidator.Validate() && IsItemDetailValid())
            {
                if (
                    XtraMessageBox.Show("Are you sure you want to commit this change? You will not be able to undo this.",
                                        "Confirmation", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    return;
                }

                var      unitIdTo         = Convert.ToInt32(lkUnitTo.EditValue);
                var      manufacturerIdTo = Convert.ToInt32(lkManufacturerTo.EditValue);
                var      conversionFactor = Convert.ToDecimal(txtFactor.EditValue);
                var      changeExpiryDate = ckExpiryDate.Checked;
                var      changeBatchNo    = ckBatchNo.Checked;
                var      batchNo          = txtBatchNo.Text;
                var      expiryDate       = (DateTime?)dtExpiryDate.EditValue;
                DateTime dtCurrent;

                using (var dtDate = ConvertDate.GetCurrentEthiopianDateText())
                {
                    dtCurrent = ConvertDate.DateConverter(dtDate.Text);
                }
                TransactionMgr transactionMgr = TransactionMgr.ThreadTransactionMgr();

                int             userId          = CurrentContext.UserId;
                TransferService transferService = new TransferService();

                if (conversionFactor == 0 &&
                    XtraMessageBox.Show(
                        "This change is a factor of Zero make the Quantity Zero,Are you sure you want to commit this change? You will not be able to undo this.",
                        "Confirmation", MessageBoxButtons.YesNo) != DialogResult.Yes)
                {
                    return;
                }

                try
                {
                    transactionMgr.BeginTransaction();
                    var dataView  = (DataView)gridItemDetailView.DataSource;
                    int IDPRinted = transferService.CreateTransactionForErrorCorrection(dataView, ItemIDTo, unitIdTo,
                                                                                        manufacturerIdTo,
                                                                                        conversionFactor,
                                                                                        "Error Correction",
                                                                                        dtCurrent, userId,
                                                                                        changeExpiryDate, expiryDate,
                                                                                        changeBatchNo, batchNo);

                    transactionMgr.CommitTransaction();

                    var xtraReport = ReturnErrorCorrectionReport(unitIdTo, manufacturerIdTo, dataView, conversionFactor,
                                                                 IDPRinted, changeExpiryDate, expiryDate, changeBatchNo,
                                                                 batchNo);
                    xtraReport.PrintDialog();

                    XtraMessageBox.Show("Your changes have been applied, thanks.", "Confirmation");
                    // refresh
                    btnDisplay_Click(null, null);
                    lkWarehouse_EditValueChanged(null, null);
                    layoutWarehouse.ContentVisible = false;
                    lkWarehouse.Visible            = false;
                }
                catch (Exception exp)
                {
                    XtraMessageBox.Show("There was an error applying your changes", "Error");
                    transactionMgr.RollbackTransaction();
                    XtraMessageBox.Show(exp.Message.ToString());
                }
                finally
                {
                    TransactionMgr.ThreadTransactionMgrReset();
                }
            }
            else
            {
                XtraMessageBox.Show("Please correct the errors marked in red", "Error");
            }
        }
Beispiel #4
0
        static bool POSTGRESQL()
        {
            try
            {
                // LoadAll
                CSharp.POSTGRESQL.employees emps = new CSharp.POSTGRESQL.employees();
                emps.ConnectionString = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                int id = emps.EmployeeID;
                emps = new CSharp.POSTGRESQL.employees();
                emps.ConnectionString = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.POSTGRESQL.employees();
                emps.ConnectionString = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.POSTGRESQL.employees();
                emps.ConnectionString         = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.POSTGRESQL.employees emps1 = new CSharp.POSTGRESQL.employees();
                emps1.ConnectionString = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.POSTGRESQL.employees emps2 = new CSharp.POSTGRESQL.employees();
                emps2.ConnectionString = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.POSTGRESQL.employees();
                emps.ConnectionString         = @"Server=www.punktech.com;User Id=postgres;Password=password;Database=griffo;port=5432;";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
Beispiel #5
0
        static bool MYSQL4()
        {
            try
            {
                // LoadAll
                CSharp.MySQL4.employee emps = new CSharp.MySQL4.employee();
                emps.ConnectionString = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                emps.Query.AddResultColumn(CSharp.MySQL4.employee.ColumnNames.EmployeeID);
                emps.Query.AddResultColumn(CSharp.MySQL4.employee.ColumnNames.LastName);
                emps.Query.AddOrderBy(CSharp.MySQL4.employee.ColumnNames.LastName, WhereParameter.Dir.ASC);
                emps.Query.Top = 2;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }


                // LoadAll
                emps = new CSharp.MySQL4.employee();
                emps.ConnectionString = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                uint id = emps.EmployeeID;
                emps = new CSharp.MySQL4.employee();
                emps.ConnectionString = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.MySQL4.employee();
                emps.ConnectionString = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.MySQL4.employee();
                emps.ConnectionString         = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.MySQL4.employee emps1 = new CSharp.MySQL4.employee();
                emps1.ConnectionString = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.MySQL4.employee emps2 = new CSharp.MySQL4.employee();
                emps2.ConnectionString = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.MySQL4.employee();
                emps.ConnectionString         = @"Database=Test;Data Source=Griffo;User Id=anonymous;";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
Beispiel #6
0
        static bool SQL()
        {
            try
            {
                // LoadAll
                CSharp.SQL.Employees emps = new CSharp.SQL.Employees();
                emps.FlushData();
                emps.ConnectionString = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                int id = emps.EmployeeID;
                emps = new CSharp.SQL.Employees();
                emps.ConnectionString = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.SQL.Employees();
                emps.ConnectionString = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.SQL.Employees();
                emps.ConnectionString         = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.SQL.Employees emps1 = new CSharp.SQL.Employees();
                emps1.ConnectionString = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.SQL.Employees emps2 = new CSharp.SQL.Employees();
                emps2.ConnectionString = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.SQL.Employees();
                emps.ConnectionString         = "User ID=sa;Initial Catalog=Northwind;Data Source=griffo";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
Beispiel #7
0
        static bool FIREBIRD_3_TRUE()
        {
            try
            {
                // LoadAll
                CSharp.FIREBIRD.DIALECT3_TRUE.Employees emps = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps.ConnectionString = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                long id = emps.EmployeeID;
                emps = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps.ConnectionString = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps.ConnectionString = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps.ConnectionString         = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.FIREBIRD.DIALECT3_TRUE.Employees emps1 = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps1.ConnectionString = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.FIREBIRD.DIALECT3_TRUE.Employees emps2 = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps2.ConnectionString = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.FIREBIRD.DIALECT3_TRUE.Employees();
                emps.ConnectionString         = @"Database=C:\dOOdad_UnitTesting\EMPTRUE3.FDB;User=SYSDBA;Password=masterkey;Dialect=3;Server=griffo";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
Beispiel #8
0
        static bool ORACLE()
        {
            try
            {
                // LoadAll
                CSharp.ORACLE.EMPLOYEES emps = new CSharp.ORACLE.EMPLOYEES();
                emps.ConnectionString = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                decimal id = emps.EMPLOYEE_ID;
                emps = new CSharp.ORACLE.EMPLOYEES();
                emps.ConnectionString = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.ORACLE.EMPLOYEES();
                emps.ConnectionString = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                emps.AddNew();
                emps.FIRST_NAME = "trella1";
                emps.LAST_NAME  = "trella1";
                emps.AddNew();
                emps.FIRST_NAME = "trella2";
                emps.LAST_NAME  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.ORACLE.EMPLOYEES();
                emps.ConnectionString          = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                emps.Where.FIRST_NAME.Value    = "trella%";
                emps.Where.FIRST_NAME.Operator = WhereParameter.Operand.Like;
                emps.Where.LAST_NAME.Value     = "trella%";
                emps.Where.LAST_NAME.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LAST_NAME = emps.LAST_NAME + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.ORACLE.EMPLOYEES emps1 = new CSharp.ORACLE.EMPLOYEES();
                emps1.ConnectionString = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                emps1.AddNew();
                emps1.FIRST_NAME = "trella1_tx1";
                emps1.LAST_NAME  = "trella1_tx1";

                CSharp.ORACLE.EMPLOYEES emps2 = new CSharp.ORACLE.EMPLOYEES();
                emps2.ConnectionString = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                emps2.AddNew();
                emps2.FIRST_NAME = "trella1_tx2";
                emps2.LAST_NAME  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.ORACLE.EMPLOYEES();
                emps.ConnectionString          = @"Password=sa;Persist Security Info=True;User ID=GRIFFO;Data Source=dbMeta";
                emps.Where.FIRST_NAME.Value    = "trella%";
                emps.Where.FIRST_NAME.Operator = WhereParameter.Operand.Like;
                emps.Where.LAST_NAME.Value     = "trella%";
                emps.Where.LAST_NAME.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
Beispiel #9
0
        static bool ACCESS()
        {
            try
            {
                // LoadAll
                CSharp.ACCESS.Employees emps = new CSharp.ACCESS.Employees();
                emps.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                if (!emps.LoadAll())
                {
                    return(false);                    // ERROR
                }

                // LoadByPrimaryKey
                int id = emps.EmployeeID;
                emps = new CSharp.ACCESS.Employees();
                emps.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                if (!emps.LoadByPrimaryKey(id))
                {
                    return(false);                    // ERROR
                }

                // AddNew/Save
                emps = new CSharp.ACCESS.Employees();
                emps.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                emps.AddNew();
                emps.FirstName = "trella1";
                emps.LastName  = "trella1";
                emps.AddNew();
                emps.FirstName = "trella2";
                emps.LastName  = "trella2";
                emps.Save();

                // Query.Load/Update/Save
                emps = new CSharp.ACCESS.Employees();
                emps.ConnectionString         = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                do
                {
                    emps.LastName = emps.LastName + ":new";
                }while(emps.MoveNext());

                emps.Save();

                // Transaction
                CSharp.ACCESS.Employees emps1 = new CSharp.ACCESS.Employees();
                emps1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                emps1.AddNew();
                emps1.FirstName = "trella1_tx1";
                emps1.LastName  = "trella1_tx1";

                CSharp.ACCESS.Employees emps2 = new CSharp.ACCESS.Employees();
                emps2.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                emps2.AddNew();
                emps2.FirstName = "trella1_tx2";
                emps2.LastName  = "trella1_tx2";

                TransactionMgr.ThreadTransactionMgr().BeginTransaction();
                emps1.Save();
                emps2.Save();
                TransactionMgr.ThreadTransactionMgr().CommitTransaction();

                // Query.Load/MarkAsDeleted/Save
                emps = new CSharp.ACCESS.Employees();
                emps.ConnectionString         = @"Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=C:\Access\NewNorthwind.mdb;";
                emps.Where.FirstName.Value    = "trella%";
                emps.Where.FirstName.Operator = WhereParameter.Operand.Like;
                emps.Where.LastName.Value     = "trella%";
                emps.Where.LastName.Operator  = WhereParameter.Operand.Like;
                if (!emps.Query.Load())
                {
                    return(false);                    // ERROR
                }

                emps.DeleteAll();
                emps.Save();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return(false);
            }
            finally
            {
                TransactionMgr.ThreadTransactionMgrReset();
            }

            return(true);
        }
        public void Transactions()
        {
            TransactionMgr tx = TransactionMgr.ThreadTransactionMgr();

            try
            {
                Employees emps = new Employees();
                emps.AddNew();
                emps.FirstName = "Jimmy";
                emps.LastName  = "Lunch Box";

                Products prds = new Products();
                prds.AddNew();
                prds.ProductName  = "dOOdads";
                prds.Discontinued = false;

                tx.BeginTransaction();
                emps.Save();
                prds.Save();
                tx.CommitTransaction();
            }
            catch (Exception)
            {
                tx.RollbackTransaction();
                TransactionMgr.ThreadTransactionMgrReset();
            }

            //-----------------------------------------------------------
            // Moral:
            //-----------------------------------------------------------
            // Modeled after COM+ transactions, but still using ADO.NET
            // connection based transactions you have the best of both
            // worlds.
            //
            // 1) Your transactions paths do not have to be pre-planned.
            //    At any time you can begin a transaction
            //
            // 2) You can nest BeginTransaction/CommitTransaction any number of times as
            //    long as they are sandwiched appropriately
            //
            //    BeginTransaction
            //        BeginTransaction
            //            emps.Save
            //        CommitTransaction
            //    CommitTransaction
            //
            //    Only the final CommitTransaction will commit the transaction
            //
            // 3) Once RollbackTransaction is called the transaction is doomed,
            //    nothing can be committed even it is attempted.
            //
            // 4) Transactions are stored in the Thread Local Storage or
            //    TLS. This way the API isn't intrusive, ie, forcing you
            //    to pass a SqlConnection around everywhere.  There is one
            //    thing to remember, once you call RollbackTransaction you will
            //    be unable to commit anything on that thread until you
            //    call ThreadTransactionMgrReset().
            //
            //    In an ASP.NET application each page is handled by a thread
            //    that is pulled from a thread pool. Thus, you need to clear
            //    out the TLS (thread local storage) before your page begins
            //    execution. The best way to do this is to create a base page
            //    that inhertis from System.Web.UI.Page and clears the state
            //    like this
            //
            //    public class MyPage : System.Web.UI.Page
            //	  {
            //        private void Page_Init(System.Object sender, System.EventArgs e)
            //		  {
            //           TransactionMgr.ThreadTransactionMgrReset();
            //        }
            //    }
            //
            //    And then make sure all of your ASPX pages inherit from MyPage.
            //
            //-----------------------------------------------------------
        }