Esempio n. 1
0
  /// <summary>Main</summary>
  public static void Main
  ( 
   string[] argv
  )
  {
   Boolean                                 booleanParseCommandLineArguments  =  false;
   string                                  exceptionMessage                  =  null;     
   string                                  filenameApplication               =  System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
   UtilityThoughtWorksSalesTaxArgument     utilityThoughtWorksSalesTaxArgument         =  null;
   
   utilityThoughtWorksSalesTaxArgument = new UtilityThoughtWorksSalesTaxArgument();
   
   booleanParseCommandLineArguments =  UtilityParseCommandLineArgument.ParseCommandLineArguments
   ( 
    argv, 
    utilityThoughtWorksSalesTaxArgument
   );

   if ( booleanParseCommandLineArguments == false )
   {
    // error encountered in arguments. Display usage message
    System.Console.Write
    (
     UtilityParseCommandLineArgument.CommandLineArgumentsUsage( typeof ( UtilityThoughtWorksSalesTaxArgument ) )
    );
    return;
   }//if ( booleanParseCommandLineArguments  == false )

   /*
   #if (DEBUG)
    System.Console.WriteLine
    (
     "Filename Application: {0}",
     filenameApplication
    );
   #endif

   #if (DEBUG)
    foreach( string  shoppingBasketCurrent in  utilityThoughtWorksSalesTaxArgument.shoppingBasket )
    {
     System.Console.WriteLine
     (
      "Argument ShoppingBasket: {0}",
      shoppingBasketCurrent
     );
    }//foreach( string  shoppingBasketCurrent in  utilityThoughtWorksSalesTaxArgument.shoppingBasket ) 
   #endif
   */
   
   ReceiptDetail
   (
    ref  utilityThoughtWorksSalesTaxArgument,
    ref  exceptionMessage
   );

  }//Main  
Esempio n. 2
0
  }//Main  

  /// <summary>ReceiptDetail</summary>
  public static void ReceiptDetail
  (
   ref UtilityThoughtWorksSalesTaxArgument  utilityThoughtWorksSalesTaxArgument,
   ref string                               exceptionMessage
  )
  {
   HttpContext       httpContext  =  HttpContext.Current;
   
   double            itemImportDuty                                    =  0.0;
   double            itemImportDutyRound5Cents                         =  0.0;
   double            itemMarkPrice                                     =  0.0;
   double            itemShelfPrice                                    =  0.0;
   double            itemSalesTax                                      =  0.0;
   double            itemSalesTaxRound5Cents                           =  0.0;
   double            itemSalesTaxRate                                  =  0.0;
   
   double            totalCost                                         =  0.0;
   double            totalSalesTax                                     =  0.0;   

   int               indexOfItemImport                                 =  0;
   int               indexOfItemTitle                                  =  0;
   int               indexOfSeparatorItemPriceAt                       =  0;
   
   string            itemCategory                                      =  null;
   string            itemDescription                                   =  null;
   string            itemPrice                                         =  null;

   // Creates CompareInfo for the InvariantCulture.
   CompareInfo       compareInfo                                       = CultureInfo.InvariantCulture.CompareInfo;

   UtilityThoughtWorksItem[]          utilityThoughtWorksItem          =  null;
   UtilityThoughtWorksItemCategory[]  utilityThoughtWorksItemCategory  =  null;   
   
   try
   {

    utilityThoughtWorksItem = ( UtilityThoughtWorksItem[] ) UtilityThoughtWorksItem.arrayListUtilityThoughtWorksItem.ToArray( typeof( UtilityThoughtWorksItem ) );

    utilityThoughtWorksItemCategory = ( UtilityThoughtWorksItemCategory[] ) UtilityThoughtWorksItemCategory.arrayListUtilityThoughtWorksItemCategory.ToArray( typeof( UtilityThoughtWorksItemCategory ) );

    foreach( string  shoppingBasketCurrent in  utilityThoughtWorksSalesTaxArgument.shoppingBasket )
    {
     itemImportDuty               =  0;
     itemImportDutyRound5Cents    =  0;
     itemSalesTax                 =  0;
     itemSalesTaxRate             =  ItemSalesTaxRate;
     itemSalesTaxRound5Cents      =  0;
     
     indexOfSeparatorItemPriceAt  =  compareInfo.IndexOf
                                     ( 
                                      shoppingBasketCurrent,
                                      SeparatorItemPriceAt,
                                      CompareOptions.IgnoreCase
                                     );

     itemDescription              =  shoppingBasketCurrent.Substring( 0, indexOfSeparatorItemPriceAt ).Trim();
     itemPrice                    =  shoppingBasketCurrent.Substring( indexOfSeparatorItemPriceAt + 4  ).Trim();
     itemMarkPrice                =  double.Parse( itemPrice );
     itemMarkPrice                =  Convert.ToDouble( itemPrice );

     foreach( UtilityThoughtWorksItem utilityThoughtWorksItemCurrent in utilityThoughtWorksItem )
     {
      indexOfItemTitle =  compareInfo.IndexOf
                          ( 
                           itemDescription,
                           utilityThoughtWorksItemCurrent.itemTitle,
                           CompareOptions.IgnoreCase
                          );

      if ( indexOfItemTitle >= 0 )
      {
       itemCategory = utilityThoughtWorksItemCurrent.itemCategory;

       if ( utilityThoughtWorksItemCurrent.itemCategory != null )
       {
        foreach( UtilityThoughtWorksItemCategory utilityThoughtWorksItemCategoryCurrent in utilityThoughtWorksItemCategory )
        {
         if ( string.Compare( utilityThoughtWorksItemCategoryCurrent.itemCategory, itemCategory, true ) == 0 )
         {
          itemSalesTaxRate = utilityThoughtWorksItemCategoryCurrent.itemSalesTaxRate;
          break;
         }//if ( string.Compare( utilityThoughtWorksItemCategoryCurrent.itemCategory, itemCategory ) == 0 )
        }//foreach( UtilityThoughtWorksItemCategory utilityThoughtWorksItemCategoryCurrent in utilityThoughtWorksItemCategory )
       }//if ( utilityThoughtWorksItemCurrent.itemCategory != null ) 
       
       break;
       
      }//if ( indexOfItemTitle >= 0 )

     }//foreach( UtilityThoughtWorksItem utilityThoughtWorksItemCurrent in utilityThoughtWorksItem )
     
     if ( itemSalesTaxRate != 0 )
     {
      itemSalesTax = itemMarkPrice * itemSalesTaxRate;
      itemSalesTaxRound5Cents = MonetaryRound( itemSalesTax );
     }//if ( itemSalesTaxRate != 0 ) 

     indexOfItemImport = shoppingBasketCurrent.IndexOf( Imported );
     if ( indexOfItemImport >= 0 )
     {
      itemImportDuty = itemMarkPrice * ImportDutyRate;
      itemImportDutyRound5Cents = MonetaryRound( itemImportDuty );
     }//if ( indexOfItemImport >= 0 )
      
     itemShelfPrice = itemMarkPrice + itemSalesTaxRound5Cents + itemImportDutyRound5Cents;
     	
     totalSalesTax  += itemSalesTax + itemImportDutyRound5Cents;
     totalCost      += itemShelfPrice;
     
     System.Console.WriteLine
     (
      "{0}: {1}",
      itemDescription,
      itemShelfPrice.ToString("#,##0.00;(#,##0.00);Zero")
     );
     
     /*
     #if (DEBUG)
      System.Console.WriteLine
      (
       "itemMarkPrice: {0} | itemSalesTax: {1} | itemSalesTaxRound5Cents: {2} | itemImportDuty: {3}",
       itemMarkPrice,
       itemSalesTax,
       itemSalesTaxRound5Cents,
       itemImportDuty
      );
     #endif
     */

    }//foreach( string  shoppingBasketCurrent in  utilityThoughtWorksSalesTaxArgument.shoppingBasket ) 

    System.Console.WriteLine("Sales Taxes: {0}", totalSalesTax.ToString("#,##0.00;(#,##0.00);Zero"));
    System.Console.WriteLine("Total: {0}", totalCost.ToString("#,##0.00;(#,##0.00);Zero"));

   }//try
   catch ( Exception exception )
   {
    exceptionMessage = "Exception: " + exception.Message;
   }//catch ( Exception exception )

   if ( exceptionMessage != null )
   {
    if ( httpContext == null )
    {
     System.Console.WriteLine( exceptionMessage );
    }//if ( httpContext == null )
    else
    {
     //httpContext.Response.Write( exceptionMessage );
    }//else 
   }//if ( exceptionMessage != null )
     
  }//public static void ReceiptDetail()