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 void saveToDB(CarData carData) { try { SQLiteConnection = new SQLiteConnection(Globals.DBsource); SQLiteConnection.Open(); SQLiteCommand = SQLiteConnection.CreateCommand(); SQLiteCommand.CommandText = "INSERT INTO FinishedCarRepairRecords(CustName, CustSurname, CustPhone, AddmitionTime, CarMake, " + "CarModel, CarNR, CarEngineID, EngineVolume, EnginePower, FuelType, WorkDescription, WorkPrice) " + "VALUES(@name, @surname, @phone, @time, @make, @model, @carNr, @carID, @volume, @power, @fuelType, @workDescription, @workPrice)"; SQLiteCommand.Parameters.AddWithValue("@name", carData.ClientName); SQLiteCommand.Parameters.AddWithValue("@surname", carData.ClientSurname); SQLiteCommand.Parameters.AddWithValue("@phone", carData.ClientPhone); SQLiteCommand.Parameters.AddWithValue("@time", carData.TimeAdded); SQLiteCommand.Parameters.AddWithValue("@make", carData.CarMake); SQLiteCommand.Parameters.AddWithValue("@model", carData.CarModel); SQLiteCommand.Parameters.AddWithValue("@carNr", carData.CarNR); SQLiteCommand.Parameters.AddWithValue("@carID", carData.CarID); SQLiteCommand.Parameters.AddWithValue("@volume", carData.EngineVol); SQLiteCommand.Parameters.AddWithValue("@power", carData.EnginePower); SQLiteCommand.Parameters.AddWithValue("@fuelType", carData.FuelType); SQLiteCommand.Parameters.AddWithValue("@workDescription", carData.WorkDescription); SQLiteCommand.Parameters.AddWithValue("@workPrice", carData.WorkPrice); SQLiteCommand.Prepare(); SQLiteCommand.ExecuteNonQuery(); SQLiteConnection.Close(); } catch (Exception ex) { throw new Exception(ex.Message); } }
private void save_Click(object sender, RoutedEventArgs e) { //TODO: save button cant be clicked if form isnt filled CarData carData = new CarData(); carData.ClientName = nameTB.Text; carData.ClientSurname = surnameTB.Text; carData.ClientPhone = phoneTB.Text; carData.CarModel = modelTB.Text; carData.CarNR = carNRTB.Text; carData.CarID = carIDTB.Text; carData.EnginePower = Int32.Parse(enginePowerTB.Text); carData.CarMake = makeCB.SelectedIndex + 1; carData.FuelType = fuelTypeCB.SelectedIndex + 1; //converting date to unix time stap + seconds long unixTime = ((DateTimeOffset)acceptanceDateCB.SelectedDate).ToUnixTimeSeconds(); TimeSpan t = (DateTime.Now - DateTime.Today); unixTime += (long)t.TotalSeconds; //Console.WriteLine(unixTime); carData.TimeAdded = unixTime; //dealing with volume carData.EngineVol = Int32.Parse(engineVolumeCB.Text); //sending to database SaveUnfinishedCar saveUnfinishedCar = new SaveUnfinishedCar(); Saving(saveUnfinishedCar, carData); this.Close(); }
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; } }
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; }
public void Saving(ISaveDB saver, CarData carData) { saver.saveToDB(carData); }