private void refreshDataGrid()
        {
            dataGrid.ItemsSource = null;
            carDatas.Clear();

            DataBaseReader DBreader = new DataBaseReader();

            DBreader.CommandText = "SELECT * FROM StartedCarRepairRecords";
            DBreader.execCommand();

            while (DBreader.SQLiteDataReader.Read())
            {
                CarData carData = new CarData();

                carData.DBId          = DBreader.SQLiteDataReader.GetInt32(0);
                carData.ClientName    = DBreader.SQLiteDataReader.GetString(1);
                carData.ClientSurname = DBreader.SQLiteDataReader.GetString(2);
                carData.ClientPhone   = DBreader.SQLiteDataReader.GetString(3);
                carData.TimeAdded     = DBreader.SQLiteDataReader.GetInt32(4);
                carData.CarMake       = DBreader.SQLiteDataReader.GetInt32(5);
                carData.CarModel      = DBreader.SQLiteDataReader.GetString(6);
                carData.CarNR         = DBreader.SQLiteDataReader.GetString(7);
                carData.CarID         = DBreader.SQLiteDataReader.GetString(8);
                carData.EngineVol     = DBreader.SQLiteDataReader.GetInt32(9);
                carData.EnginePower   = DBreader.SQLiteDataReader.GetInt32(10);
                carData.FuelType      = DBreader.SQLiteDataReader.GetInt32(11);

                carData.formatData();

                carDatas.Add(carData);
            }

            DBreader.closeConnection();
            dataGrid.ItemsSource = carDatas;
        }
        public AddCarWindow()
        {
            InitializeComponent();

            //sett todays date in datapicker
            acceptanceDateCB.SelectedDate = DateTime.Today;

            //populate car brand combobox
            DataBaseReader DBreader = new DataBaseReader {
                CommandText = "SELECT Brand FROM CarBrands"
            };

            DBreader.execCommand();

            while (DBreader.SQLiteDataReader.Read())
            {
                makeCB.Items.Add(DBreader.SQLiteDataReader.GetString(0));
            }

            DBreader.closeConnection();


            //populate fuel type combo box
            DBreader = new DataBaseReader {
                CommandText = "SELECT FuelType FROM FuelType"
            };
            DBreader.execCommand();

            while (DBreader.SQLiteDataReader.Read())
            {
                fuelTypeCB.Items.Add(DBreader.SQLiteDataReader.GetString(0));
            }

            DBreader.closeConnection();
        }
        public FinishCarWindow(CarData carData)
        {
            InitializeComponent();

            localCarData = carData;

            //populate car brand combobox
            DataBaseReader DBreader = new DataBaseReader {
                CommandText = "SELECT Brand FROM CarBrands"
            };

            DBreader.execCommand();

            while (DBreader.SQLiteDataReader.Read())
            {
                makeCB.Items.Add(DBreader.SQLiteDataReader.GetString(0));
            }

            DBreader.closeConnection();

            //populate fuel type combo box
            DBreader = new DataBaseReader {
                CommandText = "SELECT FuelType FROM FuelType"
            };
            DBreader.execCommand();

            while (DBreader.SQLiteDataReader.Read())
            {
                fuelTypeCB.Items.Add(DBreader.SQLiteDataReader.GetString(0));
            }

            DBreader.closeConnection();


            nameTB.Text              = localCarData.ClientName;
            surnameTB.Text           = localCarData.ClientSurname;
            phoneTB.Text             = localCarData.ClientPhone;
            modelTB.Text             = localCarData.CarModel;
            carNRTB.Text             = localCarData.CarNR;
            carIDTB.Text             = localCarData.CarID;
            enginePowerTB.Text       = localCarData.EnginePower.ToString(); //fix this not showing properly
            makeCB.SelectedIndex     = localCarData.CarMake - 1;
            fuelTypeCB.SelectedIndex = localCarData.FuelType - 1;
            enginePowerTB.Text       = localCarData.EnginePower.ToString();
            engineVolumeCB.Text      = localCarData.EngineVol.ToString();


            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            acceptanceDateCB.SelectedDate = dtDateTime.AddSeconds(localCarData.TimeAdded).ToLocalTime();
        }
        private void deleteOrder(CarData carData)
        {
            try {
                DataBaseReader DBreader = new DataBaseReader();
                DBreader.SQLiteCommand             = DBreader.SQLiteConnection.CreateCommand();
                DBreader.SQLiteCommand.CommandText = "DELETE FROM StartedCarRepairRecords where id=@id";
                DBreader.SQLiteCommand.Parameters.AddWithValue("@id", carData.DBId);
                DBreader.SQLiteCommand.Prepare();
                DBreader.SQLiteCommand.ExecuteNonQuery();

                DBreader.closeConnection();
            }
            catch (Exception) {
                throw;
            }
        }
Exemplo n.º 5
0
        //TODO: finish vars to make universal

        public void formatData()
        {
            //carmakestring
            try {
                DataBaseReader DBreader = new DataBaseReader();
                DBreader.SQLiteCommand             = DBreader.SQLiteConnection.CreateCommand();
                DBreader.SQLiteCommand.CommandText = "SELECT Brand from CarBrands WHERE ID=@id";
                DBreader.SQLiteCommand.Parameters.AddWithValue("@id", this.CarMake);
                DBreader.SQLiteCommand.Prepare();
                DBreader.SQLiteDataReader = DBreader.SQLiteCommand.ExecuteReader();

                DBreader.SQLiteDataReader.Read();
                this.CarMakeString = DBreader.SQLiteDataReader.GetString(0);
                DBreader.closeConnection();
                int i = 0;
                Console.WriteLine(i++);
            }
            catch (Exception ex) {
                throw new Exception(ex.Message);
            }

            //Fueltypestring
            try {
                DataBaseReader DBreader = new DataBaseReader();
                DBreader.SQLiteCommand             = DBreader.SQLiteConnection.CreateCommand();
                DBreader.SQLiteCommand.CommandText = "SELECT FuelType from FuelType WHERE ID=@id";
                DBreader.SQLiteCommand.Parameters.AddWithValue("@id", this.FuelType);
                DBreader.SQLiteCommand.Prepare();
                DBreader.SQLiteDataReader = DBreader.SQLiteCommand.ExecuteReader();

                DBreader.SQLiteDataReader.Read();
                this.FuelTypeString = DBreader.SQLiteDataReader.GetString(0);
            }
            catch (Exception ex) {
                throw new Exception(ex.Message);
            }

            //format date time
            DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);

            this.TimeAddedFormatted = dtDateTime.AddSeconds(this.TimeAdded).ToLocalTime();
        }
        public FinishedCarBrowser()
        {
            InitializeComponent();

            finishedCarDatas.Clear();

            DataBaseReader DBreader = new DataBaseReader();

            DBreader.CommandText = "SELECT * FROM FinishedCarRepairRecords";
            DBreader.execCommand();

            while (DBreader.SQLiteDataReader.Read())
            {
                CarData carData = new CarData();

                carData.DBId            = DBreader.SQLiteDataReader.GetInt32(0);
                carData.ClientName      = DBreader.SQLiteDataReader.GetString(1);
                carData.ClientSurname   = DBreader.SQLiteDataReader.GetString(2);
                carData.ClientPhone     = DBreader.SQLiteDataReader.GetString(3);
                carData.TimeAdded       = DBreader.SQLiteDataReader.GetInt32(4); //change formatting
                carData.CarMake         = DBreader.SQLiteDataReader.GetInt32(5); //change formatting
                carData.CarModel        = DBreader.SQLiteDataReader.GetString(6);
                carData.CarNR           = DBreader.SQLiteDataReader.GetString(7);
                carData.CarID           = DBreader.SQLiteDataReader.GetString(8);
                carData.EngineVol       = DBreader.SQLiteDataReader.GetInt32(9);
                carData.EnginePower     = DBreader.SQLiteDataReader.GetInt32(10);
                carData.FuelType        = DBreader.SQLiteDataReader.GetInt32(11); //chage formatting
                carData.WorkDescription = DBreader.SQLiteDataReader.GetString(12);
                carData.WorkPrice       = DBreader.SQLiteDataReader.GetFloat(13);

                carData.formatData();

                finishedCarDatas.Add(carData);
            }

            DBreader.closeConnection();
            dataGrid.ItemsSource = finishedCarDatas;
        }