Example #1
0
        }//ctor

        public DataStorage(MyDictionary <Customer> CustomerMap, MyDictionary <Product> ProductMap, MyDictionary <MyDictionary <List <Sale> > > customerActivity,
                           MyDictionary <MyDictionary <double> > priceListActivity)
        {
            this.CustomerMap       = CustomerMap;
            this.ProductMap        = ProductMap;
            this.CustomerActivity  = customerActivity;
            this.PriceListActivity = priceListActivity;
        }//ctor
Example #2
0
      //private object baton = new object();

      #endregion

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

      public SDOPriceListReader(MyDictionary<Models.Customer> customerMap, MyDictionary<Models.Product> productMap)
      {
         this.customerMap = customerMap;
         this.productMap = productMap;
      }//CTOR
Example #3
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
Example #4
0
      }//CTOR

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

      /// <summary>
      /// Reads all invoices and stores it's values in a List.
      /// </summary>
      /// <param name="customersFileName"></param>
      public MyDictionary<MyDictionary<List<Sale>>> ReadInvoiceData()
      {
         MyDictionary<MyDictionary<List<Sale>>> customerActivity = new MyDictionary<MyDictionary<List<Sale>>>(StringComparer.InvariantCultureIgnoreCase);

         ///Start date is lookBackYrs year ago.
         int lookBackYrs = (int)Settings.Default.invoiceLookBackYrs;
         DateTime startDate = DateTime.Now.AddYears(-lookBackYrs);
         int invNum = -1;
         string cusCode = String.Empty;
         string stockCode = String.Empty;
         double salePrice = -1;
         int currCode = -1;
         double xRate = -1;
         DateTime invDate = new DateTime();
         MyDictionary<List<Sale>> productActivity;

         try
         {
            sdo = new SDOEngine();
            //Try a connection, will throw an exception if it fails
            ws = (WorkSpace)sdo.Workspaces.Add("App Server Update");
            ws.Connect(sageUsrSet.sageDBDir, sageUsrSet.sageUsername, sageUsrSet.sagePassword, "UniqueUpdater");

            //Create instances of the objects
            invoiceRecord = (InvoiceRecord)ws.CreateObject("InvoiceRecord");
            invoiceItem = (InvoiceItem)ws.CreateObject("InvoiceItem");


            //Start at last Invoice
            invoiceRecord.MoveLast();
            do
            {
               //Invoice info
               invDate = (DateTime)SDOHelper.Read(invoiceRecord, "INVOICE_DATE");

               //Only read invoice details if it is recent enough.
               if (invDate >= startDate)
               {
                  invNum = (Int32)SDOHelper.Read(invoiceRecord, "INVOICE_NUMBER");
                  cusCode = (String)SDOHelper.Read(invoiceRecord, "ACCOUNT_REF");
                  currCode = (SByte)SDOHelper.Read(invoiceRecord, "CURRENCY");
                  xRate = (Double)SDOHelper.Read(invoiceRecord, "FOREIGN_RATE");


                  //Check for cusCode entry in customerActivity.
                  if (!customerActivity.ContainsKey(cusCode))
                  {
                     productActivity = new MyDictionary<List<Sale>>();
                     customerActivity[cusCode] = productActivity;
                  }
                  else
                  {
                     productActivity = customerActivity[cusCode];
                  }//Else


                  //Link Items to Record
                  invoiceItem = invoiceRecord.Link;

                  //Invoice Item info.
                  invoiceItem.MoveFirst();
                  do
                  {
                     stockCode = (String)SDOHelper.Read(invoiceItem, "STOCK_CODE");
                     double netAmount = (Double)SDOHelper.Read(invoiceItem, "NET_AMOUNT");
                     double qty = (Double)SDOHelper.Read(invoiceItem, "QTY_ORDER");

                     //if (currCode != baseCurrCode)
                     //{
                     //    salePrice = (netAmount * xRate) / qty;
                     //}
                     //else
                     //{
                     //    salePrice = netAmount / qty;
                     //}//Else

                     salePrice = netAmount / qty;


                     //If Customer or Product were not on lists then skip row.
                     if (!productMap.ContainsKey(stockCode) || !customerMap.ContainsKey(cusCode))
                        continue;


                     List<Sale> salesList;

                     //Check for stockCode entry in productActivity.
                     if (!productActivity.ContainsKey(stockCode))
                     {
                        salesList = new List<Sale>();
                        productActivity[stockCode] = salesList;
                     }
                     else
                     {
                        salesList = productActivity[stockCode];
                     }//Else


                     //Retrieve sale and add it to salesList.
                     Sale sale = new Sale(invDate, salePrice, stockCode);
                     salesList.Add(sale);
                     salesList.Sort();

                  } while (invoiceItem.MoveNext());

               }//If date

            } while (invoiceRecord.MovePrev());

         }
         catch (Exception e)
         {
            string eString = "Problem reading Invoice Data"
                              + "\r\n    -----------------     \r\n"
                              + e.GetType() + "\r\n" + e.Message
                              + "\r\n    -----------------     \r\n"
                              + "\r\nInvoice No.: " + invNum + ", Product: " + stockCode + ", Customer : " + cusCode
                              + "\r\nSale Price : " + salePrice + "\r\n";
            throw new Exception(eString);
         }
         finally
         {
            DestroyAllObjects();
         }//Finally

         return customerActivity;

      }//readInvoiceData