Ejemplo n.º 1
0
      //-------------------------------------------------------------------------------------------------------//

      /// <summary>
      /// Reads all customers and stores it's values in a List.
      /// </summary>
      /// <param name="customersFileName"></param>
      public MyDictionary<Models.Customer> ReadCustomerData()
      {
         MyDictionary<Models.Customer> customerMap = new MyDictionary<Models.Customer>();

         try
         {
            sdo = new SDOEngine();
            ws = (WorkSpace)sdo.Workspaces.Add("App Server Update");
            ws.Connect(sageUsrSet.sageDBDir, sageUsrSet.sageUsername, sageUsrSet.sagePassword, "UniqueUpdater");
            salesRecord = (SalesRecord)ws.CreateObject("SalesRecord");
            currencyData = (CurrencyData)ws.CreateObject("CurrencyData");

            string code = string.Empty;
            string desc = string.Empty;

            salesRecord.MoveFirst();
            do
            {
               code = CutQuotes((string)SDOHelper.Read(salesRecord, "ACCOUNT_REF"));
               desc = CutQuotes((string)SDOHelper.Read(salesRecord, "NAME"));

               //Create customer
               Models.Customer customer = new Models.Customer(code, desc);

               //Check if it's a foreign customer. 
               //If it is add XRate to customer.
               //Add 1 to salesrecord.CURRENCY to get the equivilant currencyData record.
               int currCode = (sbyte)SDOHelper.Read(salesRecord, "CURRENCY") + 1;

               if (currCode != baseCurrencyCode)
               {
                  currencyData.Read(currCode);
                  customer.XRate = (double)SDOHelper.Read(currencyData, "EXCHANGE_RATE");
               }//If

               customerMap.Add(code, customer);

            } while (salesRecord.MoveNext());
         }
         finally
         {
            DestroyAllObjects();
         }//finally

         return customerMap;

      }//readCustomerData
Ejemplo n.º 2
0
      }//CTOR

      //-------------------------------------------------------------------------------------------------------//

      /// <summary>
      /// Reads all invoices and stores it's values in a List.
      /// </summary>
      /// <param name="customersFileName"></param>
      public MyDictionary<MyDictionary<double>> ReadPriceListData()
      {
         //PriceListActivity set to new() so null is not returned.
         MyDictionary<MyDictionary<double>> PriceListActivity = new MyDictionary<MyDictionary<double>>();
         try
         {
            sdo = new SDOEngine();
            //Try a connection, will throw an exception if it fails
            ws = (WorkSpace)sdo.Workspaces.Add("App Server Update");
            ws.Connect(sageUserSet.sageDBDir, sageUserSet.sageUsername, sageUserSet.sagePassword, "UniqueUpdater");

            //Dictionary of PriceList Name vs PriceList Data.
            MyDictionary<MyDictionary<double>> miniPLActivity = new MyDictionary<MyDictionary<double>>();
            //Dictionary of PriceList Name vs PriceListUserList.
            MyDictionary<List<string>> plUsers = new MyDictionary<List<string>>();

            //Create instances of the objects
            priceRecord = (PriceRecord)ws.CreateObject("PriceRecord");
            salesRecord = (SalesRecord)ws.CreateObject("SalesRecord");
            stockRecord = (StockRecord)ws.CreateObject("StockRecord");


            //Create a dictionary of PL's that are acually being referenced v's Empty ProductActivities.
            //Single Price Lists can be used for multiple Customers
            salesRecord.MoveFirst();
            do
            {
               string cusCode;
               string cusPriceListRef = ((String)SDOHelper.Read(salesRecord, "PRICE_LIST_REF")).Trim();

               //If pLists already contains PL then add customer to it's entry. Else make new entry if not empty string.
               if (plUsers.ContainsKey(cusPriceListRef))
               {
                  cusCode = (String)SDOHelper.Read(salesRecord, "ACCOUNT_REF");
                  plUsers[cusPriceListRef].Add(cusCode);
               }
               else if (!cusPriceListRef.Equals(String.Empty))
               {
                  plUsers[cusPriceListRef] = new List<string>();
                  cusCode = (String)SDOHelper.Read(salesRecord, "ACCOUNT_REF");
                  plUsers[cusPriceListRef].Add(cusCode);

                  //Add new entry for each priceList.
                  miniPLActivity[cusPriceListRef] = new MyDictionary<double>();
               }//Else

            } while (salesRecord.MoveNext());

            Dictionary<string, double> productActivity = null;
            string plName = String.Empty;
            string plNamePrev = String.Empty;
            double calcValue;
            int calcMeth;
            double xRate = 1;
            double costPrice;
            double salePrice;
            double listPrice;
            string stockCode;

            //Start at first pricerecord
            priceRecord.MoveFirst();
            do
            {
               //Get first stock code in Price List.
               stockCode = (String)SDOHelper.Read(priceRecord, "STOCK_CODE");
               //Create SDO stockRecord with this stockCode to use for searching later.
               SDOHelper.Write(stockRecord, "STOCK_CODE", stockCode);

               plName = ((string)SDOHelper.Read(priceRecord, "EXT_REF")).Trim();
               calcValue = (double)SDOHelper.Read(priceRecord, "VALUE");
               calcMeth = (sbyte)SDOHelper.Read(priceRecord, "DISCOUNT_TYPE");
               salePrice = (double)SDOHelper.Read(stockRecord, "SALES_PRICE");
               costPrice = CheckProduct(stockCode).CostPrice;

               if (plName.Equals(plNamePrev))
               {
                  //Old plName: Check stock, if found get it's list price & add to productActivity from PLACtivity.
                  if (stockRecord.Find(false))
                  {
                     listPrice = CalculateListPrice(calcValue, calcMeth, costPrice, salePrice, xRate);
                     productActivity[stockCode] = listPrice;
                  }//If
               }
               else if (miniPLActivity.ContainsKey(plName))
               {
                  //New name: Check stock, if found get it's list price & add to productActivity from PLACtivity. 
                  //Change plNamePrev
                  //Get new currency, keep till next Price List.
                  if (stockRecord.Find(false))
                  {
                     xRate = GetCurrency(priceRecord);
                     listPrice = CalculateListPrice(calcValue, calcMeth, costPrice, salePrice, xRate);
                     productActivity = miniPLActivity[plName];
                     productActivity[stockCode] = listPrice;
                     plNamePrev = plName;
                  }//If
               }//Else

            } while (priceRecord.MoveNext());


            //Give each customer their own PriceList.
            foreach (string key in plUsers.Keys)
            {
               foreach (string cusCode in plUsers[key])
               {
                  PriceListActivity[cusCode] = miniPLActivity[key];
               }//ForEach
            }//ForEach   
         }
         finally
         {
            DestroyAllObjects();
         }//Finally


         return PriceListActivity;

      }//ReadPriceListData