private OrderedDictionary GetItems() { OrderedDictionary coll = new OrderedDictionary(System.StringComparer.OrdinalIgnoreCase); // Read info from grid int tempForEndVar = fgItems.RowsCount - 1; double qty = 0; decimal price = 0; int Code = 0; string Desc = ""; TicketItem item = null; for (int i = 1; i <= tempForEndVar; i++) { // Quantity qty = Convert.ToInt32(Double.Parse(Convert.ToString(fgItems[i, 0].Value))); // Price price = Decimal.Parse(Convert.ToString(fgItems[i, 3].Value), NumberStyles.Currency | NumberStyles.AllowExponent); // Code Code = Convert.ToInt32(Decimal.Parse(Convert.ToString(fgItems[i, 1].Value), NumberStyles.Currency | NumberStyles.AllowExponent)); // Description Desc = Convert.ToString(this.fgItems[i, 2].Value); // Create item info // and insert it into collection item = new TicketItem(); item.Code = Code; item.Line = i; item.price = price; item.Units = Convert.ToInt32(qty); item.Description = Desc; coll.Add(Guid.NewGuid().ToString(), item); } return(coll); }
// Stores the sale in the database internal static bool SaveSale(decimal m_SubTotal, decimal taxes, decimal Total, OrderedDictionary payments, OrderedDictionary items, int currentCustomer, int POSID, int UserID) { bool result = false; DbConnection conn = default(DbConnection); try { conn = UpgradeHelpers.DB.AdoFactoryManager.GetFactory().CreateConnection(); conn = OpenConnection(); // Start Transaction UpgradeHelpers.DB.TransactionManager.Enlist(conn.BeginTransaction()); // Register payment Payment currentPayment = null; foreach (Payment pay in payments.Values) { currentPayment = pay; SavePayment(conn, CurrentTicketID, POSID, currentPayment); } // Register items TicketItem currentItem = null; foreach (TicketItem item in items.Values) { currentItem = item; SaveItem(conn, CurrentTicketID, POSID, currentItem); } CompleteTicket(conn, Total, taxes, POSID, UserID); UpgradeHelpers.DB.TransactionManager.Commit(conn); UpgradeHelpers.DB.TransactionManager.DeEnlist(conn); conn.Close(); return(true); } catch { UpgradeHelpers.DB.TransactionManager.Rollback(conn); UpgradeHelpers.DB.TransactionManager.DeEnlist(conn); conn.Close(); result = false; } return(result); }
internal static void SaveItem(DbConnection conn, int ticketID, int POSID, TicketItem item) { DbCommand command = UpgradeHelpers.DB.AdoFactoryManager.GetFactory().CreateCommand(); command.Connection = conn; UpgradeHelpers.DB.DbConnectionHelper.ResetCommandTimeOut(command); command.CommandText = "Insert into TicketLines(POSID, TicketID, Line, Price, Units, Code) Values (@POSID, @TicketID, @Line, @Price, @Units, @Code)"; DbParameter TempParameter = null; TempParameter = command.CreateParameter(); TempParameter.ParameterName = "@POSID"; TempParameter.DbType = DbType.Decimal; TempParameter.Direction = ParameterDirection.Input; TempParameter.Size = 0; TempParameter.Value = POSID; command.Parameters.Add(TempParameter); DbParameter TempParameter_2 = null; TempParameter_2 = command.CreateParameter(); TempParameter_2.ParameterName = "@TicketID"; TempParameter_2.DbType = DbType.Decimal; TempParameter_2.Direction = ParameterDirection.Input; TempParameter_2.Size = 0; TempParameter_2.Value = ticketID; command.Parameters.Add(TempParameter_2); DbParameter TempParameter_3 = null; TempParameter_3 = command.CreateParameter(); TempParameter_3.ParameterName = "@Line"; TempParameter_3.DbType = DbType.Decimal; TempParameter_3.Direction = ParameterDirection.Input; TempParameter_3.Size = 0; TempParameter_3.Value = item.Line; command.Parameters.Add(TempParameter_3); DbParameter TempParameter_4 = null; TempParameter_4 = command.CreateParameter(); TempParameter_4.ParameterName = "@Price"; TempParameter_4.DbType = DbType.Decimal; TempParameter_4.Direction = ParameterDirection.Input; TempParameter_4.Size = 0; TempParameter_4.Value = item.price; command.Parameters.Add(TempParameter_4); DbParameter TempParameter_5 = null; TempParameter_5 = command.CreateParameter(); TempParameter_5.ParameterName = "@Units"; TempParameter_5.DbType = DbType.Decimal; TempParameter_5.Direction = ParameterDirection.Input; TempParameter_5.Size = 0; TempParameter_5.Value = item.Units; command.Parameters.Add(TempParameter_5); DbParameter TempParameter_6 = null; TempParameter_6 = command.CreateParameter(); TempParameter_6.ParameterName = "@Code"; TempParameter_6.DbType = DbType.Decimal; TempParameter_6.Direction = ParameterDirection.Input; TempParameter_6.Size = 0; TempParameter_6.Value = item.Code; command.Parameters.Add(TempParameter_6); UpgradeHelpers.DB.TransactionManager.SetCommandTransaction(command); command.ExecuteNonQuery(); }