public static List <CarPart> CreateCarParts(CarPart car, List <Tuple <string, string, int, decimal, CurrencyTypeEnum> > parts) { var list = new List <CarPart>(); foreach (var part in parts) { var partialVin = car.Vin.Substring(car.Vin.Length - 5); var description = partialVin + " " + car.Model + " " + part.Item1; var category = part.Item2; var quantity = part.Item3; var price = part.Item4; var currency = part.Item5; var index = parts.IndexOf(part) + 1; var newPart = new CarPart() { Code = partialVin + index, AlternativeCode = "NA", ProviderProductId = "NA", Description = description, Vin = car.Vin, Make = car.Make, Model = car.Model, Year = car.Year, Transmission = car.Transmission, Motor = car.Motor, Color = car.Color, Provider = car.Provider, Category = category, LastPurchaseDate = car.LastPurchaseDate, Cost = 0M, CostCurrency = CurrencyTypeEnum.USD, ImportCost = 0M, ImportCostCurrency = CurrencyTypeEnum.USD, Price = price, PriceCurrency = currency, Location = car.Location, SpecificLocation = car.SpecificLocation, InternalQuantity = 0, QuantitySold = 0, AmountSold = 0, LocalQuantityAvailable = quantity, TotalQuantityAvailable = quantity, MinimumStockQuantity = 0, LastSaleDate = car.LastPurchaseDate, ImageName = car.ImageName, Valid = true }; list.Add(newPart); } return(list); }
public CarRegistrationViewModel() { Thread.CurrentThread.CurrentCulture = new CultureInfo("es-MX"); _carPartsSearchedEntries = new ObservableCollection <CarPart>(); //_carPartsSearchedEntries.Add(new CarPart() //{ // Id = 1, // Category = "interior", // Code = "123x", // Description = "Puerta", // Model = "Honda 1998", // Vin = "FDG43BDBSG1435", // Price = 100M, // PriceCurrency = CurrencyTypeEnum.USD, // Enabled = true, // TotalQuantityAvailable = 4 //}); //_carPartsSearchedEntries.Add(new CarPart() //{ // Id = 1, // Category = "interior", // Code = "12343x", // Description = "Cofre", // Model = "Honda 1998", // Vin = "FDG43BDBSG1435", // Price = 150M, // PriceCurrency = CurrencyTypeEnum.USD, // Enabled = true, // TotalQuantityAvailable = 1 //}); var carList = FileIO.GetListFromFile(Constants.DataFolderPath + Constants.CarBrandListFileName); var transList = FileIO.GetListFromFile(Constants.DataFolderPath + Constants.TransmissiondListFileName); var locationList = FileIO.GetListFromFile(Constants.DataFolderPath + Constants.LocationListFileName); CarBrandsList = new ObservableCollection <string>(carList); TransmissionsList = new ObservableCollection <string>(transList); LocationsList = new ObservableCollection <string>(locationList); //Set default states Car = new CarPart() { CostCurrency = CurrencyTypeEnum.USD, ImportCostCurrency = CurrencyTypeEnum.USD, LastPurchaseDate = DateTime.Now, Make = carList[0], Transmission = transList[1], Location = locationList[0], }; CurrentPage = Constants.CarRegistrationMainPage; //"\\View\\CarRegistrationInfoPage.xaml"; }
internal void Execute_ImportExportCarCommand(object parameter) { if ((string)parameter == "import") { var openFileDialog = new OpenFileDialog() { Filter = ".csv files (*.csv)|*.csv", Title = "Selecciona archivo de partes de carros", InitialDirectory = @"C:\Projects\" }; if (openFileDialog.ShowDialog() == true) { var fileName = openFileDialog.FileName; var parts = CarPart.ReadPartsFile(fileName); //var car = new CarPart() //{ // Vin = "10000", // Make = "Honda", // Model = "Civic", // Year = 2010, // Color = "Azul", // Transmission = "Std", // Motor = "1.8T" //}; CarPartsSearchedEntries = new ObservableCollection <CarPart>(CarPart.CreateCarParts(Car, parts)); CarParts = new ObservableCollection <CarPart>(CarPart.CreateCarParts(Car, parts)); } } else if ((string)parameter == "export") { var saveFileDialog = new SaveFileDialog() { Filter = ".csv files (*.csv)|*.csv", Title = "Guarda archivo de partes de carro", InitialDirectory = @"C:\Projects\" }; if (saveFileDialog.ShowDialog() == true) { var carParts = new List <Tuple <string, string, int, decimal, CurrencyTypeEnum> >(); foreach (var carPart in CarParts) { carParts.Add(new Tuple <string, string, int, decimal, CurrencyTypeEnum>(carPart.Description, carPart.Category, carPart.TotalQuantityAvailable, carPart.Price, carPart.PriceCurrency)); } CarPart.WritePartsFile(saveFileDialog.FileName, carParts); } } }
internal void Execute_StartCarRegistrationCommand(object parameter) { var parts = CarPart.ReadPartsFile(Constants.DataFolderPath + Constants.DefaultPartsListFileName); //var car = new CarPart() //{ // Vin = "10000", // Make = "Honda", // Model = "Civic", // Year = 2010, // Color = "Azul", // Transmission = "Std", // Motor = "1.8T" //}; CarParts = new ObservableCollection <CarPart>(CarPart.CreateCarParts(Car, parts)); CarPartsSearchedEntries = CarParts; MainWindowViewModel.GetInstance(null, null).CurrentPage = "\\View\\CarRegistrationListPage.xaml"; }
public List <IProduct> Search(string input) { var products = new List <IProduct>(); //Return empty list if invalid inputs are entered for the search if (string.IsNullOrWhiteSpace(input) || input == "x") { return(products); } if (input == "*") { var allProducts = DictOfData.AsEnumerable(); foreach (var row in allProducts) { var product = new CarPart() { Id = Int32.Parse(row["NumeroProducto"].ToString()), Code = row["Codigo"].ToString(), AlternativeCode = row["CodigoAlterno"].ToString(), ProviderProductId = row["ProveedorProductoId"].ToString(), Description = row["Descripcion"].ToString(), Provider = row["Proveedor"].ToString(), Category = row["Categoria"].ToString(), LastPurchaseDate = Convert.ToDateTime(row["UltimoPedidoFecha"].ToString()), Cost = Decimal.Parse(row["Costo"].ToString()), Price = decimal.Parse(row["Precio"].ToString()), InternalQuantity = Int32.Parse(row["CantidadInternoHistorial"].ToString()), QuantitySold = Int32.Parse(row["CantidadVendidoHistorial"].ToString()), AmountSold = decimal.Parse(row["VendidoHistorial"].ToString()), LocalQuantityAvailable = Int32.Parse(row["CantidadLocal"].ToString()), TotalQuantityAvailable = Int32.Parse(row["CantidadDisponibleTotal"].ToString()), MinimumStockQuantity = Int32.Parse(row["CantidadMinima"].ToString()), LastSaleDate = Convert.ToDateTime(row["UltimaTransaccionFecha"].ToString()), ImageName = row["Imagen"].ToString(), Vin = row["VIN"].ToString(), Make = row["Marca"].ToString(), Model = row["Modelo"].ToString(), Year = Int32.Parse(row["Anho"].ToString()), Transmission = row["Transmision"].ToString(), Motor = row["Motor"].ToString(), Color = row["Color"].ToString(), ImportCost = decimal.Parse(row["CostoImportacion"].ToString()), Location = row["Ubicacion"].ToString(), SpecificLocation = row["Pasillo"].ToString() }; product.CostCurrency = row["CostoMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; product.PriceCurrency = row["PrecioMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; product.ImportCostCurrency = row["CostoImportacionMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; products.Add(product); } return(products); } var descriptionFilter = DictOfData.AsEnumerable().Where(r => r.Field <string>("Descripcion").ToLower().Contains(input)); var codeFilter = DictOfData.AsEnumerable().Where(r => r.Field <string>("Codigo").ToLower().Contains(input)); foreach (var row in codeFilter) { var product = new CarPart() { Id = Int32.Parse(row["NumeroProducto"].ToString()), Code = row["Codigo"].ToString(), AlternativeCode = row["CodigoAlterno"].ToString(), ProviderProductId = row["ProveedorProductoId"].ToString(), Description = row["Descripcion"].ToString(), Provider = row["Proveedor"].ToString(), Category = row["Categoria"].ToString(), LastPurchaseDate = Convert.ToDateTime(row["UltimoPedidoFecha"].ToString()), Cost = Decimal.Parse(row["Costo"].ToString()), Price = decimal.Parse(row["Precio"].ToString()), InternalQuantity = Int32.Parse(row["CantidadInternoHistorial"].ToString()), QuantitySold = Int32.Parse(row["CantidadVendidoHistorial"].ToString()), AmountSold = decimal.Parse(row["VendidoHistorial"].ToString()), LocalQuantityAvailable = Int32.Parse(row["CantidadLocal"].ToString()), TotalQuantityAvailable = Int32.Parse(row["CantidadDisponibleTotal"].ToString()), MinimumStockQuantity = Int32.Parse(row["CantidadMinima"].ToString()), LastSaleDate = Convert.ToDateTime(row["UltimaTransaccionFecha"].ToString()), ImageName = row["Imagen"].ToString(), Vin = row["VIN"].ToString(), Make = row["Marca"].ToString(), Model = row["Modelo"].ToString(), Year = Int32.Parse(row["Anho"].ToString()), Transmission = row["Transmision"].ToString(), Motor = row["Motor"].ToString(), Color = row["Color"].ToString(), ImportCost = decimal.Parse(row["CostoImportacion"].ToString()), Location = row["Ubicacion"].ToString(), SpecificLocation = row["Pasillo"].ToString() }; product.CostCurrency = row["CostoMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; product.PriceCurrency = row["PrecioMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; product.ImportCostCurrency = row["CostoImportacionMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; products.Add(product); } foreach (var row in descriptionFilter) { var product = new CarPart() { Id = Int32.Parse(row["NumeroProducto"].ToString()), Code = row["Codigo"].ToString(), AlternativeCode = row["CodigoAlterno"].ToString(), ProviderProductId = row["ProveedorProductoId"].ToString(), Description = row["Descripcion"].ToString(), Provider = row["Proveedor"].ToString(), Category = row["Categoria"].ToString(), LastPurchaseDate = Convert.ToDateTime(row["UltimoPedidoFecha"].ToString()), Cost = Decimal.Parse(row["Costo"].ToString()), Price = decimal.Parse(row["Precio"].ToString()), InternalQuantity = Int32.Parse(row["CantidadInternoHistorial"].ToString()), QuantitySold = Int32.Parse(row["CantidadVendidoHistorial"].ToString()), AmountSold = decimal.Parse(row["VendidoHistorial"].ToString()), LocalQuantityAvailable = Int32.Parse(row["CantidadLocal"].ToString()), TotalQuantityAvailable = Int32.Parse(row["CantidadDisponibleTotal"].ToString()), MinimumStockQuantity = Int32.Parse(row["CantidadMinima"].ToString()), LastSaleDate = Convert.ToDateTime(row["UltimaTransaccionFecha"].ToString()), ImageName = row["Imagen"].ToString(), Vin = row["VIN"].ToString(), Make = row["Marca"].ToString(), Model = row["Modelo"].ToString(), Year = Int32.Parse(row["Anho"].ToString()), Transmission = row["Transmision"].ToString(), Motor = row["Motor"].ToString(), Color = row["Color"].ToString(), ImportCost = decimal.Parse(row["CostoImportacion"].ToString()), Location = row["Ubicacion"].ToString(), SpecificLocation = row["Pasillo"].ToString() }; product.CostCurrency = row["CostoMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; product.PriceCurrency = row["PrecioMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; product.ImportCostCurrency = row["CostoImportacionMoneda"].ToString().ToUpper() == "USD" ? CurrencyTypeEnum.USD : CurrencyTypeEnum.MXN; //Add if it does not exist already if (!products.Exists(x => x.Code == product.Code)) { products.Add(product); } } return(products); }
internal void Execute_ImportExportCarCommand(object parameter) { if ((string)parameter == "import") { var openFileDialog = new OpenFileDialog() { Filter = ".csv files (*.csv)|*.csv", Title = "Selecciona archivo de partes de carros", InitialDirectory = @"C:\" }; if (openFileDialog.ShowDialog() == true) { var fileName = openFileDialog.FileName; var parts = CarPart.ReadPartsFile(fileName); //var car = new CarPart() //{ // Vin = "10000", // Make = "Honda", // Model = "Civic", // Year = 2010, // Color = "Azul", // Transmission = "Std", // Motor = "1.8T" //}; CarPartsSearchedEntries = new ObservableCollection <CarPart>(CarPart.CreateCarParts(Car, parts)); CarParts = new ObservableCollection <CarPart>(CarPart.CreateCarParts(Car, parts)); } } else if ((string)parameter == "export") { var saveFileDialog = new SaveFileDialog() { Filter = ".csv files (*.csv)|*.csv", Title = "Guarda archivo de partes de carro", InitialDirectory = @"C:\" }; if (saveFileDialog.ShowDialog() == true) { var carParts = new List <Tuple <string, string, int, decimal, CurrencyTypeEnum, bool> >(); foreach (var carPart in CarParts) { //remove detailed information to create default list //remove model var desc = carPart.Description.Replace(Car.Model, ""); //remove year desc = desc.Replace(Car.Year.ToString(), ""); //remove vin var firstSpaceIndex = desc.IndexOf(" ", StringComparison.Ordinal); desc = desc.Remove(0, firstSpaceIndex + 1); //remove spaces desc = desc.TrimStart(' '); carParts.Add(new Tuple <string, string, int, decimal, CurrencyTypeEnum, bool>(desc, carPart.Category, carPart.TotalQuantityAvailable, carPart.Price, carPart.PriceCurrency, carPart.Valid)); } CarPart.WritePartsFile(saveFileDialog.FileName, carParts); } } }