Example #1
0
 public void AddTask(Task taskToAdd)
 {
     task.Add(taskToAdd);
 }
        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;
        }