Beispiel #1
0
        public void DownloadTasks()
        {
            string query = "SELECT * FROM Task";

            using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
            {
                SqlCommand cmd = new SqlCommand(query, sqlConnection);
                sqlConnection.Open();
                using (SqlDataReader dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        int    id          = int.Parse(dataReader["Id"].ToString());
                        string name        = dataReader["Name"].ToString();
                        string description = dataReader["Description"].ToString();
                        string priority    = dataReader["Priority"].ToString();
                        DateTime.TryParse(dataReader["Date"].ToString(), out DateTime posDate);
                        DateTime?date = posDate;
                        if (posDate < DateTime.Parse("1/1/1800 12:00:00 PM"))
                        {
                            date = null;
                        }
                        string status = dataReader["Status"].ToString();

                        TaskCreator task = new TaskCreator(id, name, description, priority, date, status);
                    }
                }
            }
        }
Beispiel #2
0
        public void UpdateTask(TaskCreator task)
        {
            string query = $"UPDATE Task SET Name = @Name, Description = @Description, Priority = @Priority, Date = @Date, Status = @Status WHERE Id = @Id";

            using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                using (SqlCommand cmd = new SqlCommand(query, sqlConnection))
                {
                    cmd.Parameters.AddWithValue("@Id", task.Id);
                    cmd.Parameters.AddWithValue("@Name", task.Name);
                    cmd.Parameters.AddWithValue("@Description", task.Description);
                    cmd.Parameters.AddWithValue("@Priority", task.Priority);
                    if (task.Date != null)
                    {
                        cmd.Parameters.AddWithValue("@Date", task.Date);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@Date", DBNull.Value);
                    }
                    cmd.Parameters.AddWithValue("@Status", task.Status);

                    cmd.ExecuteNonQuery();
                }
                sqlConnection.Close();
            }
        }
Beispiel #3
0
        public void SendTask(TaskCreator task)
        {
            string query = "INSERT INTO Task (Name, Description, Priority, Date, Status) VALUES (@Name, @Description, @Priority, @Date, @Status)";

            using (SqlConnection sqlConnection = new SqlConnection(ConnectionString))
            {
                sqlConnection.Open();
                using (SqlCommand cmd = new SqlCommand(query, sqlConnection))
                {
                    //cmd.Parameters.AddWithValue("@Id", task.Id);
                    cmd.Parameters.AddWithValue("@Name", task.Name);
                    cmd.Parameters.AddWithValue("@Description", task.Description);
                    cmd.Parameters.AddWithValue("@Priority", task.Priority);
                    if (task.Date != null)
                    {
                        cmd.Parameters.AddWithValue("@Date", task.Date);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@Date", DBNull.Value);
                    }
                    cmd.Parameters.AddWithValue("@Status", task.Status);

                    cmd.ExecuteNonQuery();
                }
                sqlConnection.Close();
            }
        }
        public static void EditTask(int id, string name, string description, string priority, DateTime date, string status)
        {
            TaskCreator taskToEdit = FindTask(id);

            taskToEdit.Name        = name;
            taskToEdit.Description = description;
            taskToEdit.Priority    = priority;
            taskToEdit.Date        = date;
            taskToEdit.Status      = status;
        }