public MainWindow() { InitializeComponent(); taskList = new TaskList(); taskList = DataBaseHandler.LoadData(); rightFrameMainWindow.Content = new MainPage(taskList); //leftFrameMainWindow.Source = new Uri("MainPage.xml", UriKind.RelativeOrAbsolute); }
public static TaskList LoadData() { TaskList task = new TaskList(); Task tempTask; //Connect to database using (SqlConnection con = new SqlConnection(masterConnectionString)) { con.Open(); try { using (SqlCommand command = new SqlCommand("SELECT * FROM [dbo].[Table]", con)) { SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { try { int first = reader.GetInt32(0); string second = reader.GetString(1); int third = reader.GetInt32(2); DateTime dT = reader.GetDateTime(3); decimal fifeth = reader.GetDecimal(4); tempTask = new Task(first, second, TypeOfTask.Daily, third, dT , fifeth); task.AddTask(tempTask); Debug.WriteLine(tempTask.ToString()); } catch (Exception) { Debug.WriteLine("Null przy odczycie"); } } } } catch { Debug.WriteLine("Odczyt się posypał"); } } return task; }
public static void SaveData(TaskList taskList) { Task tempTask; using (SqlConnection con = new SqlConnection(masterConnectionString)) { con.Open(); try { for (int i = 0; i < taskList.CountOfTaskList(); i++) { using (SqlCommand command = new SqlCommand("INSERT INTO [dbo].[Table] VALUES(@Id, @Title, @Prior, @Time, @Multiplier)", con)) { try { tempTask = taskList.ReadTask(i); command.Parameters.Add(new SqlParameter("Id", tempTask.Id)); command.Parameters.Add(new SqlParameter("Title", tempTask.Title)); command.Parameters.Add(new SqlParameter("Prior", tempTask.Prior)); command.Parameters.Add(new SqlParameter("Time", tempTask.Date)); command.Parameters.Add(new SqlParameter("Multiplier", tempTask.Multiplier)); command.ExecuteNonQuery(); } catch (Exception e) { Debug.WriteLine("Message: "+ e.Message); } } } } catch { Debug.WriteLine("Zapis się posypał"); } } }
public MainPage(TaskList taskList) { InitializeComponent(); this.taskList = taskList; FillListBox(); }