private void Btn_AddAct_Click(object sender, EventArgs e) { List <Activity> activities = activityService.GetActivities(); if (txt_ActDate.Text == "" || txt_ActID.Text == "" || txt_description.Text == "" || txt_NumGuides.Text == "" || txt_NumPart.Text == "") { MessageBox.Show("Please fill in ALL the fields to succesfully add an activity"); return; } foreach (Activity act in activities) { if (txt_description.Text.ToLower() == act.Description.ToLower() || txt_ActID.Text == act.ActivityID.ToString()) { MessageBox.Show("The description or ID of an activity can not be the same as another activity"); txt_ActDate.Clear(); txt_ActID.Clear(); txt_description.Clear(); txt_NumGuides.Clear(); txt_NumPart.Clear(); return; } } string query = "INSERT INTO activities VALUES (" + txt_ActID.Text + ", '" + @txt_description.Text + "', " + @txt_NumGuides.Text + ", " + @txt_NumPart.Text + ", '" + @txt_ActDate.Text + "')"; activityService.UpdateActivity(query); this.Close(); }
private void Btn_EditAct_Click(object sender, EventArgs e) { string newDescription; Int16 newNumGuides; Int16 newNumPart; DateTime newDate; List <Activity> activities = activityService.GetActivities(); if (txt_description.Text == "") { newDescription = selectedAct.Description; } else { foreach (Activity act in activities) { if (txt_description.Text == act.Description) { MessageBox.Show("There already is an activity like this, please choose something else"); txt_description.Clear(); txt_ActDate.Clear(); txt_NumGuides.Clear(); txt_NumPart.Clear(); return; } } newDescription = txt_description.Text; } if (txt_NumGuides.Text == "") { newNumGuides = selectedAct.NumberOfGuides; } else { newNumGuides = Int16.Parse(txt_NumGuides.Text); } if (txt_NumPart.Text == "") { newNumPart = selectedAct.NumberOfParticipants; } else { newNumPart = Int16.Parse(txt_NumPart.Text); } if (txt_ActDate.Text == "") { newDate = selectedAct.ActivityDate; } else { newDate = DateTime.Parse(txt_ActDate.Text); } string query = "UPDATE activities SET [description]='" + newDescription + "', numberOfGuides=" + newNumGuides + ", numberOfParticipants=" + newNumPart + ", [date]='" + newDate.ToString("yyyy/MM/dd") + "' WHERE activityID=" + selectedAct.ActivityID; activityService.UpdateActivity(query); this.Close(); }