public Boolean DeleteWork(WeekyWork weekyWork) { Boolean result = false; string strConnection = DataProvider.DataProvider.getConnectionString(); string SQL = "delete Work where Id = @Id"; SqlConnection cnn = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand(SQL, cnn); cmd.Parameters.AddWithValue("@Id", weekyWork.Id); try { if (cnn.State == ConnectionState.Closed) { cnn.Open(); } result = cmd.ExecuteNonQuery() == 1; } catch (SqlException se) { result = false; } finally { cnn.Close(); } return(result); }
/// <summary> /// Update 1 WeekyWork /// </summary> /// <param name="weekyWork">Id, Description, StartTime, AlertTime, Deadline</param> /// <returns></returns> public Boolean UpdateWeekyWork(WeekyWork weekyWork) { Boolean result = false; string strConnection = DataProvider.DataProvider.getConnectionString(); //string SQL = "update Work set [Description] = @Description, StartTime = @StartTime, AlertTime = @AlertTime, Deadline = @Deadline where Id = @WorkId"; string SQL = "update Work set [Description] = @Description where Id = @WorkId"; SqlConnection cnn = new SqlConnection(strConnection); SqlCommand cmd = new SqlCommand(SQL, cnn); cmd.Parameters.AddWithValue("@Description", weekyWork.Description); cmd.Parameters.AddWithValue("@WorkId", weekyWork.Id); try { if (cnn.State == ConnectionState.Closed) { cnn.Open(); } result = cmd.ExecuteNonQuery() == 1; } catch (SqlException se) { result = false; } finally { cnn.Close(); } return(result); }
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { dynamic data = sender; if (data.SelectedItem == null) { return; } if (btnEdit.IsChecked == true) { workForm = new WorkForm(data.SelectedItem, data.DataContext.MorningTask); workForm.ShowDialog(); dynamic setTime = dpTime.SelectedDate; DateTime startTime = getDateTimeOfWeek(setTime, DayOfWeek.Monday); DateTime endTime = startTime.AddDays(7).Date; setProccess(startTime, endTime); } else if (btnMove.IsChecked == false) { WeekyTaskData weekyTaskData = new WeekyTaskData(); WeekyWork weekyWork = data.SelectedItem; if (weekyTaskData.ChangeWeekyWorkStatus(weekyWork.Id, 5)) { data.DataContext.MorningTask.Remove(weekyWork); dynamic setTime = dpTime.SelectedDate; DateTime startTime = getDateTimeOfWeek(setTime, DayOfWeek.Monday); DateTime endTime = startTime.AddDays(7).Date; setProccess(startTime, endTime); } } data.UnselectAll(); }
public WorkForm(WeekyWork weekyWork, ObservableCollection <WeekyWork> weekyWorkList) { InitializeComponent(); this.weekyWork = weekyWork; this.weekyWorkList = weekyWorkList; txtTitle.Text = weekyWork.Title; txtDescription.Text = weekyWork.Description; }
private void addWeekyWorkToDay(DayInWeek dayInWeek, WeekyWork weekyWork) { switch (weekyWork.StatusId) { case 2: case 3: case 4: case 1: dayInWeek.MorningTask.Add(weekyWork); break; case 5: dayInWeek.EverningTask.Add(weekyWork); break; } }
/// <summary> /// Lấy 1 list các DayInWeek để hiển thị /// </summary> /// <returns>List DayInWeek</returns> public List <DayInWeek> GetListDayInWeekForShow(DateTime startTime, DateTime endTime) { List <DayInWeek> result = new List <DayInWeek>(); DayInWeek monday = new DayInWeek(DayOfWeek.Monday); DayInWeek tuesday = new DayInWeek(DayOfWeek.Tuesday); DayInWeek wednesday = new DayInWeek(DayOfWeek.Wednesday); DayInWeek thursday = new DayInWeek(DayOfWeek.Thursday); DayInWeek friday = new DayInWeek(DayOfWeek.Friday); DayInWeek saturday = new DayInWeek(DayOfWeek.Saturday); DayInWeek sunday = new DayInWeek(DayOfWeek.Sunday); result.Add(monday); result.Add(tuesday); result.Add(wednesday); result.Add(thursday); result.Add(friday); result.Add(saturday); result.Add(sunday); foreach (DataRow row in GetWorkForShow(startTime, endTime).Rows) { WeekyWork weekyWork = new WeekyWork(); weekyWork.Id = int.Parse(row["Id"].ToString()); weekyWork.TaskId = int.Parse(row["TaskId"].ToString()); weekyWork.Title = row["Title"].ToString(); weekyWork.Description = row["Description"].ToString(); if (row["StartTime"].ToString().Length > 0) { weekyWork.StartTime = DateTime.Parse(row["StartTime"].ToString()); } if (row["AlertTime"].ToString().Length > 0) { weekyWork.AlertTime = DateTime.Parse(row["AlertTime"].ToString()); } if (row["Deadline"].ToString().Length > 0) { weekyWork.DeadLine = DateTime.Parse(row["Deadline"].ToString()); } weekyWork.StatusId = int.Parse(row["StatusId"].ToString()); switch (weekyWork.StartTime.DayOfWeek.ToString()) { case "Monday": addWeekyWorkToDay(monday, weekyWork); break; case "Tuesday": addWeekyWorkToDay(tuesday, weekyWork); break; case "Wednesday": addWeekyWorkToDay(wednesday, weekyWork); break; case "Thursday": addWeekyWorkToDay(thursday, weekyWork); break; case "Friday": addWeekyWorkToDay(friday, weekyWork); break; case "Saturday": addWeekyWorkToDay(saturday, weekyWork); break; case "Sunday": addWeekyWorkToDay(sunday, weekyWork); break; } } return(result); }