private void ReturnToStoreForQuantityEdit() { //TODO: finish updating the changed locations TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr(); transaction.BeginTransaction(); try { var pl = new PalletLocation(); String reference = gridReceiveView.GetFocusedDataRow()["RefNo"].ToString(); // pl.ConfirmAllReceived(reference); if (gridDetailView.DataSource == null) { return; } foreach (DataRowView drv in gridDetailView.DataSource as DataView) { int PalletLocationID = Convert.ToInt32(drv["PalletLocationID"]); int ProposedPalletLocationID = Convert.ToInt32(drv["ProposedPalletLocationID"]); if (PalletLocationID != ProposedPalletLocationID) { pl.LoadByPrimaryKey(PalletLocationID); if (pl.IsColumnNull("PalletID")) { pl.Confirmed = false; pl.Save(); } } else { pl.LoadByPrimaryKey(PalletLocationID); pl.Confirmed = false; pl.Save(); } } var recDoc = new ReceiveDoc(); recDoc.LoadByReferenceNo(reference); recDoc.SetStatusAsReceived(null); transaction.CommitTransaction(); XtraMessageBox.Show("Receipt Returned!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); BindFormContents(); } catch (Exception exp) { transaction.RollbackTransaction(); XtraMessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void OnConfirmClicked(object sender, EventArgs e) { if (BLL.Settings.IsCenter) { GRV = new CenterCostCalculator(); GRV.LoadGRV(ReceiptID); GRV.CalculateFinalCost(); } else { GRV = new CostCalculator(); GRV.LoadGRV(ReceiptID); (GRV as CostCalculator).LoadGRVPreviousStock(); GRV.CalculateFinalCost(); } if (!SetSellingPrice(GRV)) { return; } TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr(); try { transaction.BeginTransaction(); // This is where we set the Price for the previous Stock foreach (CostElement costElement in GRV.CostElements) { costElement.PreviousCostDetials.Confirm(CurrentContext.UserId); } PrintConfirmation(null); try { CostingService.ConfirmPriceChange(GRV.CostElements, CurrentContext.UserId, ChangeMode.Recieve, ReceiptID.ToString()); } catch (Exception exception) { XtraMessageBox.Show(exception.Message); throw exception; } transaction.CommitTransaction(); this.LogActivity("Print-SRM", ReceiptID); } catch (Exception ex) { transaction.RollbackTransaction(); XtraMessageBox.Show(ex.Message); } }
private void btnReprintGRV_Click(object sender, EventArgs e) { TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr(); try { transaction.BeginTransaction(); DataRow dr = gridReceiveView.GetFocusedDataRow(); int? receiptConfirmationPrintoutID = Convert.ToInt32(dr["ID"]); PrintConfirmation(receiptConfirmationPrintoutID); transaction.CommitTransaction(); this.LogActivity("Reprint", ReceiptID); } catch (Exception ex) { transaction.RollbackTransaction(); XtraMessageBox.Show(ex.Message); } }
public void InitializeCommit(int userId, int warehouseID) { var user = new User(); user.LoadByPrimaryKey(userId); InventoryCommitMemberInstance.User = user; // open transaction InventoryCommitMemberInstance.Transaction = TransactionMgr.ThreadTransactionMgr(); // create the order here InventoryCommitMemberInstance.Order = Order.GenerateOrder(null, OrderType.CONSTANTS.INVENTORY, OrderStatus.Constant.ISSUED, ActivityID, PaymentType.Constants.INVENTORY, user.FullName, GeneralInfo.Current.InstitutionID, user.ID, 0); // create the picklist here InventoryCommitMemberInstance.PickList = PickList.GeneratePickList(InventoryCommitMemberInstance.Order.ID); // create the issue header IssueService issueService = new IssueService(); InventoryCommitMemberInstance.Issue = issueService.CreateSTVLog(null, false , InventoryCommitMemberInstance.PickList , InventoryCommitMemberInstance.Order , null, ActivityID, false, user.ID); // create the reciept header ReceiveService receiveService = new ReceiveService(); InventoryCommitMemberInstance.Receipt = receiveService.CreateFakeReceiptWithInvoicePO(OrderType.CONSTANTS.INVENTORY , ActivityID, GeneralInfo.Current.SupplierID, "Inventory" , InventoryCommitMemberInstance.Issue.IDPrinted , ReceiptType.CONSTANTS.BEGINNING_BALANCE, user.ID, ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED, warehouseID); }
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."); } }
/// <summary> /// Moves the balance. /// </summary> /// <param name="rpSource">The rp source.</param> /// <param name="rpDestination">The rp destination.</param> /// <param name="quantityToBeMoved">The quantity to be moved.</param> /// <exception cref="System.Exception"></exception> public static void MoveBalance(ReceivePallet rpSource, ReceivePallet rpDestination, long quantityToBeMoved) { TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr(); transaction.BeginTransaction(); try { //DropProcedureReceiveDocReceivePallet(); if (rpSource.Balance < quantityToBeMoved) { throw new Exception("Quantity to be moved must be less than or equal to the balance!"); } if (rpDestination.IsColumnNull("Balance")) { rpDestination.Balance = 0; } rpDestination.Balance += quantityToBeMoved; rpDestination.BoxSize = 0; rpDestination.IsOriginalReceive = rpSource.IsOriginalReceive; rpDestination.Save(); rpSource.BoxSize = 0; rpSource.Balance -= quantityToBeMoved; rpSource.Save(); //CreateProcedureReceiveDocReceivePallet(); transaction.CommitTransaction(); } catch { transaction.RollbackTransaction(); CreateProcedureReceiveDocReceivePallet(); } }
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"); } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
private void btnPrint_Click(object sender, EventArgs e) { DataRow dataRow = gridReceiveView.GetFocusedDataRow(); if (dataRow != null) { if (Convert.ToInt32(dataRow["ReceiptConfirmationStatusID"]) == ReceiptConfirmationStatus.Constants.RECEIVE_QUANTITY_CONFIRMED) { ReceiptID = Convert.ToInt32(dataRow["ReceiptID"]); PrintDialog printDialog = new PrintDialog(); printDialog.PrinterSettings.Copies = BLL.Settings.GRNFCopies; DialogResult dialogResult = printDialog.ShowDialog(); if (dialogResult != DialogResult.OK) { MessageBox.Show("Printing Canceled by user", "Cancel Printint...", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return; } TransactionMgr transaction = TransactionMgr.ThreadTransactionMgr(); XtraReport printout; try { transaction.BeginTransaction(); printout = WorkflowReportFactory.CreateGRNFPrintout(ReceiptID, null, false, FiscalYear.Current); var receipt = new BLL.Receipt(ReceiptID); var recDoc = new ReceiveDoc(); recDoc.LoadByReceiptID(ReceiptID); if (receipt.ReceiptInvoice.PO.PurchaseType == BLL.POType.STORE_TO_STORE_TRANSFER || !BLL.Settings.HandleGRV) { recDoc.ConfirmGRVPrinted(CurrentContext.UserId); BLL.Receipt receiptStatus = new BLL.Receipt(); receiptStatus.LoadByPrimaryKey(ReceiptID); receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.GRV_PRINTED, null, this.GetFormIdentifier(), CurrentContext.UserId, "Transfer Confirmed"); } else { recDoc.ConfirmGRNFPrinted(CurrentContext.UserId); BLL.Receipt receiptStatus = new BLL.Receipt(); receiptStatus.LoadByPrimaryKey(ReceiptID); receiptStatus.ChangeStatus(ReceiptConfirmationStatus.Constants.GRNF_PRINTED, null, this.GetFormIdentifier(), CurrentContext.UserId, "GRNF Printed"); } transaction.CommitTransaction(); } catch (Exception exception) { transaction.RollbackTransaction(); XtraMessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); throw; } for (int i = 0; i < printDialog.PrinterSettings.Copies; i++) { printout.Print(printDialog.PrinterSettings.PrinterName); } ReceiptConfirmation_Load(null, null); } else { XtraMessageBox.Show("The selected receipt has to be confirmed before GRNF is printed!", "ERROR", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); } } }
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. // //----------------------------------------------------------- }