Beispiel #1
0
        public IDictionary <string, Warehouse> GetWarehouses(string stock)
        {
            Dictionary <string, Warehouse> res = new Dictionary <string, Warehouse>();

            try
            {
                var materialName = StockHelper.GetMaterialName(stock);
                var materialId   = StockHelper.GetMaterialID(stock);
                var warehouses   = StockHelper.GetWarehouses(stock);

                foreach (var item in warehouses)
                {
                    Material tmpMaterial = new Material();
                    tmpMaterial.Name       = materialName;
                    tmpMaterial.MaterialId = materialId;

                    var warehouseName  = StockHelper.GetWarehouseName(item);
                    var materialAmount = StockHelper.GetMaterialAmount(item);

                    Warehouse tmpWarehouse = new Warehouse();
                    tmpWarehouse.Name = warehouseName;

                    int  amount;
                    bool success = int.TryParse(materialAmount, out amount);
                    if (success)
                    {
                        tmpMaterial.Amount = amount;
                    }
                    else
                    {
                        throw new Exception();
                    }

                    tmpWarehouse.Materials = new List <Material>()
                    {
                        tmpMaterial
                    };

                    res.Add(tmpWarehouse.Name, tmpWarehouse);
                }
            }
            catch (Exception ex)
            {
                Console.Write(ex);
            }
            return(res);
        }
Beispiel #2
0
 public bool ValidateRawStock(string stock)
 {
     if (!stock.StartsWith("#") &&
         StockHelper.GetPropertyCount(stock) == 3 &&
         !string.IsNullOrEmpty(StockHelper.GetMaterialName(stock)) &&
         !string.IsNullOrEmpty(StockHelper.GetMaterialID(stock)))
     {
         var warehouses = StockHelper.GetWarehouses(stock);
         if (warehouses.Length != 0)
         {
             foreach (var item in warehouses)
             {
                 if (string.IsNullOrEmpty(StockHelper.GetWarehouseName(item)) || string.IsNullOrEmpty(StockHelper.GetMaterialAmount(item)))
                 {
                     return(false);
                 }
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
     else
     {
         if (!stock.StartsWith("#"))
         {
             //w zadaniu nie bylo sprecyzowane co robic z blednymi liniami czy je poprawiac czy gdzies logowac
             using (StreamWriter w = File.AppendText("importError.txt"))
             {
                 w.WriteLine("Błąd importu w lini - {0}", stock);
             }
         }
         return(false);
     }
 }