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);
                }
            }
        }
示例#2
0
        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);
                }
            }
        }