private void createButton_Click(object sender, EventArgs e) { if (courtNameTextBox2.Text == "" || sportTextBox4.Text == "" || remarksTextBox.Text == "") { MessageBox.Show("Please fill in all fields!"); } else { SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities(); CourtTable ct = new CourtTable(); try { ct.CourtType = courtNameTextBox2.Text; ct.SportsType = sportTextBox4.Text; ct.MaintDate = lastDOM.Value; ct.Remarks = remarksTextBox.Text; ct.Flag = "active"; ctx.CourtTables.Add(ct); ctx.SaveChanges(); MessageBox.Show("New Court " + ct.CourtID + " successfully created!"); ClearContent(); } catch (System.FormatException) { MessageBox.Show("Please fill in the correct values for the fields!"); } } }
private void button1_Click_1(object sender, EventArgs e) { SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities(); TransactionTable tt = new TransactionTable(); try { tt.CustomerID = Convert.ToInt32(CIDTextBox.Text); CourtTable ct = ctx.CourtTables.Where(x => x.CourtType == comboBox1.Text).First(); tt.CourtTable = ct; tt.DateBook = dateTimePicker1.Value.Date; SlotTable st = ctx.SlotTables.Where(x => x.Time == timeSlotListBox1.Text).First(); tt.SlotTable = st; tt.Status = "Booked"; ctx.TransactionTables.Add(tt); ctx.SaveChanges(); MessageBox.Show("Booking for " + comboBox1.Text + " on " + dateTimePicker1.Value.ToString("dd/MM/yyyy") + " at " + timeSlotListBox1.Text + " is completed."); ClearContent(); } catch (System.FormatException) { MessageBox.Show("Please ensure all fields are manually selected"); } }
public void PopulateTimeSlot() { SA46Team10BsportsEntities Content = new SA46Team10BsportsEntities(); var qry2 = Content.TransactionTables.Where(x => x.CourtTable.CourtType == comboBox1.Text && x.DateBook == dateTimePicker1.Value.Date && x.Status == "Booked").Select(x => x.SlotTable.Time); var qry1 = Content.SlotTables.Select(x => x.Time).Except(qry2); timeSlotListBox1.DataSource = qry1.ToList(); }
private void deleteButtom_Click(object sender, EventArgs e) { SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities(); int CID = Convert.ToInt32(courtIDTextBox.Text); CourtTable c = ctx.CourtTables.Where(x => x.CourtID == CID && x.Flag == "active").First(); c.Flag = "inactive"; ctx.SaveChanges(); MessageBox.Show(c.CourtType + " record has been deleted"); ClearContent(); }
private void searchButton_Click(object sender, EventArgs e) { try { if (!(string.IsNullOrWhiteSpace(courtIDTextBox.Text))) { SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities(); int CID = Convert.ToInt32(courtIDTextBox.Text); CourtTable c = ctx.CourtTables.Where(x => x.CourtID == CID && x.Flag == "active").First(); LockCourtIDTextBox(); courtNameTextBox2.Text = c.CourtType; sportTextBox4.Text = c.SportsType; lastDOM.Text = c.MaintDate.Value.ToString("dd-MM-yyyy"); remarksTextBox.Text = c.Remarks; } else { CourtLookOutFormcs clof = new CourtLookOutFormcs(); clof.ShowDialog(); this.courtIDTextBox.Text = clof.CIDFromGrid; LockCourtIDTextBox(); this.courtNameTextBox2.Text = clof.CTFromGrid; this.sportTextBox4.Text = clof.STFromGrid; this.lastDOM.Text = clof.MDFromGrid; this.remarksTextBox.Text = clof.RFromGrid; } } catch (System.ArgumentOutOfRangeException) { MessageBox.Show("Please ensure all fields have relevant data before updating."); } catch (System.FormatException) { MessageBox.Show("Please enter the correct ID"); } catch (System.InvalidOperationException) { MessageBox.Show("This ID does not exist"); } }
private void button1_Click(object sender, EventArgs e) { try { int TransID = Convert.ToInt32(dataGridView1.SelectedCells[0].FormattedValue.ToString()); SA46Team10BsportsEntities context = new SA46Team10BsportsEntities(); TransactionTable t = context.TransactionTables.Where(x => x.TransactionID == TransID).First(); t.Status = "Cancelled"; context.SaveChanges(); MessageBox.Show("Transaction " + dataGridView1.SelectedCells[0].FormattedValue.ToString() + " has been cancelled."); ClearContent(); } catch (System.IndexOutOfRangeException ex) { MessageBox.Show(ex.Message + "\nPlease select a row"); } catch (System.ArgumentOutOfRangeException ex) { MessageBox.Show("\nPlease select a row before click on cancel"); } }
private void SearchButton_Click(object sender, EventArgs e) { SA46Team10BsportsEntities context = new SA46Team10BsportsEntities(); try { if (radioButton1.Checked == true) { int CID = Convert.ToInt32(CIDTextBox.Text); dataGridView1.DataSource = context.TransactionTables.Where(x => x.CustomerID == CID && x.Status == "Booked").Select(x => new { x.TransactionID, x.CustomerTable.FirstName, x.CustomerTable.LastName, x.CourtTable.CourtType, x.DateBook, x.SlotTable.Time }).ToList(); } else if (radioButton2.Checked == true) { int TransID = Convert.ToInt32(TransTextBox.Text); dataGridView1.DataSource = context.TransactionTables.Where(x => x.TransactionID == TransID && x.Status == "Booked").Select(x => new { x.TransactionID, x.CustomerTable.FirstName, x.CustomerTable.LastName, x.CourtTable.CourtType, x.DateBook, x.SlotTable.Time }).ToList(); } } catch (System.FormatException ex) { MessageBox.Show(ex.Message + "\nPlease provide a valid entry in the search.\nCustomerID and Transaction ID can only contain numbers.\n"); } }
private void updateButton_Click(object sender, EventArgs e) { try { if (courtNameTextBox2.Text == "" || sportTextBox4.Text == "" || remarksTextBox.Text == "") { MessageBox.Show("Please leave no field blank"); } else { SA46Team10BsportsEntities ctx = new SA46Team10BsportsEntities(); int CID = Convert.ToInt32(courtIDTextBox.Text); CourtTable c = ctx.CourtTables.Where(x => x.CourtID == CID && x.Flag == "active").First(); c.CourtType = courtNameTextBox2.Text; c.SportsType = sportTextBox4.Text; c.MaintDate = lastDOM.Value; c.Remarks = remarksTextBox.Text; ctx.SaveChanges(); MessageBox.Show("Update Successful"); ClearContent(); } } catch (System.ArgumentOutOfRangeException) { MessageBox.Show("Please ensure all fields are filled before updating"); } catch (System.FormatException) { MessageBox.Show("Please ensure all fields are filled before updating"); } }