private void UpdateButton_Click(object sender, EventArgs e) { string OldType = FacilityDataGrid.SelectedCells[0].Value.ToString(); FacilityType f1 = ctx.FacilityTypes.Where(x => x.Name == OldType).FirstOrDefault(); // f1.Name = InputTypeNameTextBox.Text; ctx.SaveChanges(); refresh(); MessageBox.Show("Facility Type successfully updated."); }
private void DeleteButton_Click(object sender, EventArgs e) //delete means Deactive { //check whether related type has related record string OldType = FacilityDataGrid.SelectedCells[0].Value.ToString(); //selected typename FacilityType ft = ctx.FacilityTypes.Where(x => x.Name == OldType).First(); //selected facilityType List <int> fi = new List <int>(); //typeid related facilityid Array foreach (Facility f in ctx.Facilities) { if (f.TypeID == ft.TypeID) { fi.Add(f.FacilityID); } } int flag = 0; foreach (Booking b in ctx.Bookings) { for (int i = 0; i < fi.Count(); i++) { if (b.FacilityID == fi[i]) { flag++; } } } if (flag != 0) { MessageBox.Show("Unable to delete due to existing Booking Records."); flag = 0; } else { ElevenAlphaEntities ctx = new ElevenAlphaEntities(); OldType = FacilityDataGrid.SelectedCells[0].Value.ToString(); FacilityType f = ctx.FacilityTypes.Where(x => x.Name == OldType).First(); f.Active = 0; ctx.SaveChanges(); refresh(); } }
private void AddButton_Click(object sender, EventArgs e) { string inputname = InputTypeNameTextBox.Text; // check if the inputname already exist but deactive int flag = 0; foreach (FacilityType f1 in ctx.FacilityTypes) { if (f1.Name.ToLower() == inputname.ToLower()) { ElevenAlphaEntities ctx = new ElevenAlphaEntities(); FacilityType f = ctx.FacilityTypes.Where(x => x.Name == inputname).First(); //f.Active = 1; flag = 1; if (f.Active == 0) { f.Active = 1; MessageBox.Show("Facility Type successfully reactivated."); } else { MessageBox.Show("Facility Type already exists!"); } ctx.SaveChanges(); refresh(); break; } } if (flag == 0) { ElevenAlphaEntities ctx = new ElevenAlphaEntities(); FacilityType fnew = new FacilityType(); fnew.Active = 1; fnew.Name = inputname; ctx.FacilityTypes.Add(fnew); ctx.SaveChanges(); refresh(); MessageBox.Show("Facility Type successfully added."); } }
private void AddFacilityButton_Click(object sender, EventArgs e) { Facility f = new Facility(); int flag = 0; DateTime opentime; DateTime closetime; string inputname = FacilityNameTxtB.Text; if (inputname == "") { MessageBox.Show("Please input the Facility Name."); } else { foreach (Facility f1 in ctx.Facilities) { if (f1.Name.ToLower() == inputname.ToLower()) { flag++; break; } } if (flag > 0) { MessageBox.Show("This Facility Name already exists. Please input a different one."); flag = 0; } else { f.Name = inputname; if (typename == "") { MessageBox.Show("Please choose a Facility Type."); } else { FacilityType ft = ctx.FacilityTypes.Where(x => x.Name == typename).FirstOrDefault(); //found selected facilitytype f.TypeID = ft.TypeID; // set facility typeid if (OpenHrsMskTxB.MaskedTextProvider.AssignedEditPositionCount == 0) { MessageBox.Show("Please input the Opening Time."); } else if (Convert.ToDateTime(OpenHrsMskTxB.Text.ToString()) >= Convert.ToDateTime(CloseHrsMskTxB.Text.ToString())) { MessageBox.Show("Please input a closing time later than opening time!"); } else { DateTime d1 = Convert.ToDateTime(OpenHrsMskTxB.Text.ToString()); //OpenHrsMskTxB.value.hour opentime = new DateTime(1900, 1, 1, d1.Hour, d1.Minute, d1.Second);// if (CloseHrsMskTxB.MaskedTextProvider.AssignedEditPositionCount == 0) { MessageBox.Show("Please input the Closing Time."); } else { DateTime d2 = Convert.ToDateTime(CloseHrsMskTxB.Text.ToString()); closetime = new DateTime(1900, 01, 01, d2.Hour, d2.Minute, d2.Second);// f.Location = LocationTexB.Text; f.Description = DescriptionTexB.Text; f.Active = 1; f.OpeningTime = opentime; f.ClosingTime = closetime; ctx.Facilities.Add(f); ctx.SaveChanges(); MessageBox.Show("Successfully added Facility."); } } } } } }