Esempio n. 1
0
        ////private void DeserializeXMLDatabase()
        ////{
        ////    if (!File.Exists("data.xml"))
        ////    {
        ////        XmlSerializer xSerializer = new XmlSerializer(typeof(Car));
        ////        using (FileStream read = new FileStream("data.xml", FileMode.Open, FileAccess.Read, FileShare.Read))
        ////        {
        ////            Car xmlCar = (Car)xSerializer.Deserialize(read);
        ////            dieler.CarsList.Add(xmlCar);
        ////        }
        ////    }
        //
        ////}

        private void soldButton_Click(object sender, EventArgs e)
        {
            // find selected item
            // copy item to soldCarsList
            // erase from carsList
            if (carsListBox.SelectedItem != null)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure ?", "Check", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    Car selectedCar      = (Car)carsListBox.SelectedItem;
                    var selectedCarPrice = int.Parse(selectedCar.Price);
                    Settings.Default.MonthlyProfit += selectedCarPrice;
                    Settings.Default.Save();

                    XMLDatabase.Remove(carsListBox.SelectedItem);
                    this.soldCarsList.Add(selectedCar);
                    this.soldCarsBinding.ResetBindings(false);

                    this.carsBinding.DataSource = XMLDatabase.Load().Where(x => x.IsSold == false).ToList();

                    carsListBox.ClearSelected();
                    soldCarsListBox.ClearSelected();

                    ProfitLabel.Text = Settings.Default.MonthlyProfit.ToString() + "$";
                }
                else
                {
                    return;
                }
            }
        }
Esempio n. 2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            if (brandTextBox.ReadOnly == true)
            {
                this.TextboxesReadOnlyOrNot(false);
                this.ClearTextboxes();
                carsListBox.ClearSelected();
                return;
            }

            if (string.IsNullOrEmpty(brandTextBox.Text) && string.IsNullOrEmpty(modelTextBox.Text))
            {
                MessageBox.Show("Brand and model are mandatory !");
                soldCarsListBox.ClearSelected();
                return;
            }

            var id     = this.NextContractNumber();
            Car newCar = new Car(id);

            newCar.Brand          = brandTextBox.Text;
            newCar.Model          = modelTextBox.Text;
            newCar.BodyworkType   = typeTextBox.Text;
            newCar.EngineVolumeCc = EngineVolumeCCTextBox.Text;
            newCar.HorsePower     = horsePowerTextBox.Text;
            newCar.FuelType       = fuelTypeTextBox.Text;
            newCar.Color          = colorTextBox.Text;
            newCar.ProductionDate = productionDateTextBox.Text;
            newCar.Mileage        = mileageTextBox.Text;
            newCar.Price          = priceTextBox.Text;
            newCar.AdditionalInfo = additionalCarInfoTextBox.Text;
            newCar.Win            = WinTextBox.Text;
            this.AddExtrasToCarExtrasFieldIfChecked(newCar);

            this.ClearTextboxes();
            this.carsBinding.ResetBindings(false);
            soldCarsListBox.ClearSelected();

            XMLDatabase.AppendDataToXML(newCar); // works fine

            this.carsBinding.DataSource = XMLDatabase.Load().Where(x => x.IsSold == false).ToList();
            this.UncheckCheckboxes();
        }
Esempio n. 3
0
        public DielershipUI()
        {
            this.InitializeComponent();
            this.SetupData();

            ////carsBinding.DataSource = dieler.CarsList.Where(x => x.IsSold == false).ToList();
            this.carsBinding.DataSource = XMLDatabase.Load().Where(x => x.IsSold == false).ToList();

            carsListBox.DataSource = this.carsBinding;

            carsListBox.DisplayMember = "Display";
            carsListBox.ValueMember   = "Display";

            this.soldCarsBinding.DataSource = this.soldCarsList;
            this.soldCarsListBox.DataSource = this.soldCarsBinding;

            soldCarsListBox.DisplayMember = "Display";
            soldCarsListBox.ValueMember   = "Display";

            MenuStrip menuStrip = new MenuStrip();
        }