protected void btnAdd_Click(object sender, EventArgs e) { try { HotelManager hm = new HotelManager(); Hotel hotel = new Hotel(); ICityManager cm = (ICityManager)BusinessObjectManager.GetCityManager(); hotel.HotelName = txtHotelName.Text; hotel.Address = txtAddress.Text; hotel.City = cm.GetCityById(Convert.ToInt64(dpCity.SelectedValue)); hotel.CityID = Convert.ToInt32(dpCity.SelectedValue); hotel.BriefNote = txtBrief.Text; hotel.Email = txtEMail.Text; hotel.ContactNo = txtContact.Text; hotel.Pincode = txtPincode.Text; hotel.StarRanking = Convert.ToInt32(dpStarRanking.SelectedValue); hotel.PhotoUrl = txtPhoto.Text; hotel.WebsiteURL = txtWebsite.Text; hm.SaveHotel(hotel); //Resetting the session to invalidate the hotels Session["HOTELDS"] = null; Response.Redirect("~/Admin/ViewHotel.aspx"); } catch (Exception ex) { lblError.Text = ex.Message; } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; if (((TextBox)(row.Cells[3].Controls[0])).Text.Length == 0) { lblError.Text = "Distance in Kms Can't be Empty"; ((TextBox)(row.Cells[3].Controls[0])).Focus(); } else { try { IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); Route route = new Route(); route.ID = long.Parse((row.Cells[0].Text)); route.DistanceInKms = long.Parse(((TextBox)(row.Cells[3].Controls[0])).Text); route.IsActive = ((CheckBox)(row.Cells[4].Controls[0])).Checked; routeManager.UpdateRoute(route); e.Cancel = true; GridView1.EditIndex = -1; BindData(); lblError.Text = "Route Updated"; } catch (RouteManagerException ex) { throw ex; } } }
private void BindData() { try { IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); DataTable dt = new DataTable(); List <Route> routes = routeManager.GetRoutes(); dt.Columns.Add("RouteId", typeof(long)); dt.Columns.Add("FromCityName", typeof(string)); dt.Columns.Add("ToCityName", typeof(string)); dt.Columns.Add("DistanceInKms", typeof(decimal)); dt.Columns.Add("status", typeof(bool)); foreach (Route r in routes) { DataRow rw = dt.NewRow(); rw["RouteId"] = r.ID; rw["FromCityName"] = r.FromCity.Name + " (" + r.FromCity.StateInfo.Name + ")"; rw["ToCityName"] = r.ToCity.Name + " (" + r.ToCity.StateInfo.Name + ")"; rw["DistanceInKms"] = r.DistanceInKms; rw["status"] = r.IsActive; dt.Rows.Add(rw); } GridView1.DataSource = dt; ctlAdminMaster.BuildPager(GridView1); } catch (RouteManagerException ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { ctlAdminMaster.ErrorMessage = ""; if (!IsPostBack) { try { ICityManager cityManager = (ICityManager)BusinessObjectManager.GetCityManager(); List <City> cities = cityManager.GetCities(); dpFromCity.Items.Add("None"); foreach (City c in cities) { ListItem item = new ListItem(c.Name + " (" + c.StateInfo.Name + ")", c.CityId.ToString()); dpFromCity.Items.Add(item); } dpFromCity.DataBind(); dpToCity.Items.Add("None"); foreach (City c in cities) { ListItem item = new ListItem(c.Name + " (" + c.StateInfo.Name + ")", c.CityId.ToString()); dpToCity.Items.Add(item); } dpToCity.DataBind(); } catch (CityManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } }
protected void btnUpdate_Click(object sender, EventArgs e) { HotelManager hm = new HotelManager(); Hotel hotel = new Hotel(); ICityManager cm = (ICityManager)BusinessObjectManager.GetCityManager(); hotel.HotelId = Convert.ToInt64(txtHotelId.Text); hotel.HotelName = txtHotelName.Text; hotel.Address = txtAddress.Text; hotel.City = cm.GetCityById(Convert.ToInt64(dpCity.SelectedValue)); hotel.CityID = Convert.ToInt32(dpCity.SelectedValue); hotel.BriefNote = txtBrief.Text; hotel.Email = txtEMail.Text; hotel.ContactNo = txtContact.Text; hotel.Pincode = txtPincode.Text; hotel.StarRanking = Convert.ToInt32(dpStarRanking.SelectedValue); hotel.PhotoUrl = txtPhoto.Text; hotel.WebsiteURL = txtWebsite.Text; hm.UpdateHotel(hotel); ResetHotelDataSet(); Response.Redirect("~/Admin/ViewHotel.aspx"); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { ICityManager cityManager = BusinessObjectManager.GetCityManager(); List <City> cities = cityManager.GetCities(); dpFromCity.Items.Add("None"); foreach (City c in cities) { ListItem item = new ListItem(c.Name, c.CityId.ToString()); dpFromCity.Items.Add(item); } dpFromCity.DataBind(); dpToCity.Items.Add("None"); foreach (City c in cities) { ListItem item = new ListItem(c.Name, c.CityId.ToString()); dpToCity.Items.Add(item); } dpToCity.DataBind(); } catch (CityManagerException ex) { throw ex; } } }
protected void btnSave_Click(object sender, EventArgs e) { if (dpFromCity.Text.Equals("None") == true) { lblError.Text = "Select From City"; dpFromCity.Focus(); } else if (dpToCity.Text.Equals("None") == true) { lblError.Text = "Select To City"; dpToCity.Focus(); } else if (dpFromCity.SelectedItem.Text.Equals(dpToCity.SelectedItem.Text)) { lblError.Text = "From City & To City Cannot be Same"; dpFromCity.Focus(); } else if (txtDistance.Text.Length == 0) { lblError.Text = "Enter the Distance between Routes"; txtDistance.Focus(); } else { try { Route route = new Route(); IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); City fromcity = new City(); fromcity.CityId = long.Parse(dpFromCity.SelectedItem.Value); fromcity.Name = dpFromCity.SelectedItem.Text; route.FromCity = fromcity; City tocity = new City(); tocity.CityId = long.Parse(dpToCity.SelectedItem.Value); tocity.Name = dpToCity.SelectedItem.Text; route.ToCity = tocity; if (routeManager.GetRouteID(route) > 0) { lblError.Text = "Already route exists"; dpFromCity.Focus(); } else { route.DistanceInKms = double.Parse(txtDistance.Text); route.IsActive = chkActive.Checked; routeManager.AddRoute(route); lblError.Text = "Route Added Successfully"; } } catch (RouteManagerException ex) { throw ex; } } }
protected void grdCity_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (IsValid) { GridViewRow row = grdCity.Rows[e.RowIndex]; HiddenField hdnStateId = (HiddenField)row.FindControl("hdnStateId"); TextBox txtState = (TextBox)row.FindControl("txtState"); TextBox txtCityName = (TextBox)row.FindControl("txtCityName"); if (string.IsNullOrWhiteSpace(txtCityName.Text)) { ctlAdminMaster.ErrorMessage = "City Name Can't be Empty"; txtCityName.Focus(); } else { int cityId = Int32.Parse(grdCity.DataKeys[e.RowIndex].Value.ToString()); string CityName = txtCityName.Text; string StateName = txtState.Text; City _city = new City() { CityId = cityId, Name = CityName, StateInfo = new State() { StateId = long.Parse(hdnStateId.Value), Name = StateName } }; try { ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); if (cityManger.UpdateCity(_city)) { ctlAdminMaster.ErrorMessage = "City Updated Successfully"; } else { ctlAdminMaster.ErrorMessage = "City already exists"; } grdCity.EditIndex = -1; BindData(); } catch (CityManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } } }
public void BindData() { try { ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); List <City> cities = cityManger.GetCities(); grdCity.DataSource = cities; grdCity.DataBind(); } catch (CityManagerException ex) { throw ex; } }
protected void Page_Load(object sender, EventArgs e) { hotelManager = new HotelManager(); cityManager = (ICityManager)BusinessObjectManager.GetCityManager(); if (!Page.IsPostBack) { dpCity.DataSource = cityManager.GetCities(); dpCity.DataTextField = "Name"; dpCity.DataValueField = "CityId"; dpCity.DataBind(); dpCity.Items.Insert(0, "--- Select City ---"); } }
protected void grdCity_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = grdCity.Rows[e.RowIndex]; TextBox txtState = (TextBox)row.FindControl("txtState"); TextBox txtCityName = (TextBox)row.FindControl("txtCityName"); if (txtCityName.Text.Length == 0) { lblError.Text = "City Name Can't be Empty"; txtCityName.Focus(); } else { int cityId = Int32.Parse(grdCity.DataKeys[e.RowIndex].Value.ToString()); string CityName = txtCityName.Text; string StateName = txtState.Text; City _city = new City() { CityId = cityId, Name = CityName, StateInfo = new State() { Name = StateName } }; try { ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); if (cityManger.UpdateCity(_city)) { lblError.Text = "City Updated Successfully"; } else { lblError.Text = "City already exists"; } grdCity.EditIndex = -1; BindData(); } catch (CityManagerException ex) { throw ex; } } }
protected void btnSave_Click(object sender, EventArgs e) { ctlAdminMaster.ErrorMessage = ""; if (cityNameValidator.IsValid) { if (txtCrCity.Text.Trim().Length == 0) { ctlAdminMaster.ErrorMessage = "City Name Can't be Empty"; txtCrCity.Focus(); } else if (dpStateCity.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select the State"; dpStateCity.Focus(); } else { string CityName = txtCrCity.Text; State _state = new State(); _state.StateId = long.Parse(dpStateCity.SelectedItem.Value); City _city = new City(); _city.Name = CityName; _city.StateInfo = _state; ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); try { if (cityManger.AddCity(_city)) { ctlAdminMaster.ErrorMessage = "City Added Successfully"; } else { ctlAdminMaster.ErrorMessage = "City already exists"; } } catch (CityManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } } }
public void clear() { txtCrCity.Text = ""; ctlAdminMaster.ErrorMessage = ""; dpStateCity.Items.Clear(); ICityManager cityManager = (ICityManager)BusinessObjectManager.GetCityManager(); List <State> stateList = cityManager.GetStates(); dpStateCity.Items.Add("None"); foreach (State s in stateList) { ListItem item = new ListItem(s.Name, s.StateId.ToString()); dpStateCity.Items.Add(item); } dpStateCity.DataBind(); }
public void BindData() { try { ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); List <City> cities = cityManger.GetCities(); if (cities.Count > 0) { grdCity.DataSource = cities; ctlAdminMaster.BuildPager(grdCity); } else { grdCity.Visible = false; } } catch (CityManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } }
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox txtDist = (TextBox)row.Cells[3].Controls[1]; if (txtDist != null) { long lngDistance = 0; if ((!long.TryParse(txtDist.Text, out lngDistance)) || (lngDistance <= 0)) { ctlAdminMaster.ErrorMessage = "Distance should be a positive number"; txtDist.Focus(); } else { try { IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); Route route = new Route(); route.ID = long.Parse(((Label)row.Cells[0].Controls.OfType <Label>().First()).Text); route.DistanceInKms = lngDistance; //route.IsActive = ((CheckBox)(row.Cells[4].Controls[0])).Checked; route.IsActive = true; routeManager.UpdateRoute(route); e.Cancel = true; GridView1.EditIndex = -1; BindData(); ctlAdminMaster.ErrorMessage = "Route Updated"; } catch (RouteManagerException ex) { throw ex; } } } }
private void clear() { dpFromCity.Items.Clear(); dpToCity.Items.Clear(); dpAirlineName.Items.Clear(); dpFlightName.Items.Clear(); DropDownList1.Items.Clear(); DropDownList2.Items.Clear(); DropDownList4.Items.Clear(); DropDownList5.Items.Clear(); DropDownList1.Items.Add("None"); DropDownList4.Items.Add("None"); for (int i = 1; i <= 24; i++) { DropDownList1.Items.Add(i.ToString()); DropDownList4.Items.Add(i.ToString()); } DropDownList1.DataBind(); DropDownList4.DataBind(); DropDownList2.Items.Add("None"); DropDownList5.Items.Add("None"); for (int i = 0; i <= 59; i++) { DropDownList2.Items.Add(i.ToString()); DropDownList5.Items.Add(i.ToString()); } DropDownList2.DataBind(); DropDownList5.DataBind(); txtDuration.Enabled = false; txtDuration.Text = ""; chkStatus.Checked = false; ICityManager cityManager = (ICityManager)BusinessObjectManager.GetCityManager(); try { List <City> cities = cityManager.GetCities(); dpFromCity.Items.Add("None"); foreach (City c in cities) { ListItem item = new ListItem(c.Name, c.CityId.ToString()); dpFromCity.Items.Add(item); } dpFromCity.DataBind(); dpToCity.Items.Add("None"); foreach (City c in cities) { ListItem item = new ListItem(c.Name, c.CityId.ToString()); dpToCity.Items.Add(item); } dpToCity.DataBind(); } catch (CityManagerException e) { lblError.Text = e.Message; } IAirLineManager airlineManager = (IAirLineManager)AirTravelManagerFactory.Create("AirlineManager"); try { List <Airline> airlines = airlineManager.GetAirLines(); dpAirlineName.Items.Add("None"); foreach (Airline c in airlines) { ListItem item = new ListItem(c.Name, c.Id.ToString()); dpAirlineName.Items.Add(item); } dpAirlineName.DataBind(); } catch (AirlineManagerException e) { lblError.Text = e.Message; } var travelClassvalues = Enum.GetValues(typeof(TravelClass)).Cast <TravelClass>(); Repeater1.DataSource = travelClassvalues; Repeater1.DataBind(); }
protected void btnSave_Click(object sender, EventArgs e) { int intDistance = 0; if (dpFromCity.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select From City"; dpFromCity.Focus(); } else if (dpToCity.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select To City"; dpToCity.Focus(); } else if (dpFromCity.SelectedItem.Text.Equals(dpToCity.SelectedItem.Text)) { ctlAdminMaster.ErrorMessage = "From City & To City Cannot be Same"; dpFromCity.Focus(); } else if (txtDistance.Text.Length == 0) { ctlAdminMaster.ErrorMessage = "Enter the Distance between Routes"; txtDistance.Focus(); } else if (!int.TryParse(txtDistance.Text, out intDistance) || (intDistance <= 0)) { ctlAdminMaster.ErrorMessage = "Distance should be a valid positive number"; txtDistance.Focus(); } else { try { Route route = new Route(); IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); City fromcity = new City(); fromcity.CityId = long.Parse(dpFromCity.SelectedItem.Value); fromcity.Name = dpFromCity.SelectedItem.Text; route.FromCity = fromcity; City tocity = new City(); tocity.CityId = long.Parse(dpToCity.SelectedItem.Value); tocity.Name = dpToCity.SelectedItem.Text; route.ToCity = tocity; if (routeManager.GetRouteID(route) > 0) { ctlAdminMaster.ErrorMessage = "Already route exists"; dpFromCity.Focus(); } else { route.DistanceInKms = double.Parse(txtDistance.Text); route.IsActive = chkActive.Checked; routeManager.AddRoute(route); ctlAdminMaster.ErrorMessage = "Route Added Successfully"; //Response.Redirect("~/Admin/Home.aspx"); } } catch (RouteManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } }
private void clear() { dpFromCity.Items.Clear(); dpToCity.Items.Clear(); dpAirlineName.Items.Clear(); dpFlightName.Items.Clear(); DropDownList1.Items.Clear(); DropDownList2.Items.Clear(); DropDownList4.Items.Clear(); DropDownList5.Items.Clear(); for (int i = 1; i <= 24; i++) { DropDownList1.Items.Add(i.ToString()); DropDownList4.Items.Add(i.ToString()); } DropDownList1.DataBind(); DropDownList4.DataBind(); for (int i = 0; i <= 59; i++) { DropDownList2.Items.Add(i.ToString()); DropDownList5.Items.Add(i.ToString()); } DropDownList2.DataBind(); DropDownList5.DataBind(); txtDuration.Enabled = false; txtDuration.Text = ""; chkStatus.Checked = false; try { ICityManager cityManager = (ICityManager)BusinessObjectManager.GetCityManager(); List <City> cities = cityManager.GetCities(); foreach (City c in cities) { ListItem item = new ListItem(c.Name.Trim(), c.CityId.ToString()); dpFromCity.Items.Add(item); } dpFromCity.DataBind(); foreach (City c in cities) { ListItem item = new ListItem(c.Name, c.CityId.ToString()); dpToCity.Items.Add(item); } dpToCity.DataBind(); AirLineManager objairline = new AirLineManager(); List <Airline> airlines = objairline.GetAirLines(); foreach (Airline c in airlines) { ListItem item = new ListItem(c.Name, c.Id.ToString()); dpAirlineName.Items.Add(item); } dpAirlineName.DataBind(); } catch (CityManagerException ex) { throw ex; } catch (AirlineManagerException exc) { throw exc; } }
private void clear() { dpAirlineName.Items.Clear(); dpFlightName.Items.Clear(); dpDepartHours.Items.Clear(); dpDepartMins.Items.Clear(); dpArrivalHours.Items.Clear(); dpArrivalMins.Items.Clear(); for (int i = 0; i < 24; i++) { dpDepartHours.Items.Add(i.ToString()); dpArrivalHours.Items.Add(i.ToString()); } for (int i = 0; i <= 59; i += 10) { dpDepartMins.Items.Add(i.ToString()); dpArrivalMins.Items.Add(i.ToString()); } txtDuration.Enabled = false; txtDuration.Text = ""; chkStatus.Checked = false; try { IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); try { List <Route> routes = routeManager.GetRoutes(); //dpRoute.Items.Add(new ListItem("Select Route...", "-1")); foreach (Route route in routes) { string r = route.FromCity.Name + " ==> " + route.ToCity.Name; string v = route.ID.ToString(); dpRoute.Items.Add(new ListItem(r, v)); } } catch (RouteManagerException e) { ctlAdminMaster.ErrorMessage = e.Message; } AirLineManager objairline = new AirLineManager(); List <Airline> airlines = objairline.GetAirLines(); foreach (Airline a in airlines) { ListItem item = new ListItem(a.Name, a.Id.ToString()); dpAirlineName.Items.Add(item); } dpAirlineName.DataBind(); } catch (CityManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } catch (AirlineManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } }
private void clear() { dpAirlineName.Items.Clear(); dpFlightName.Items.Clear(); dpDepartHours.Items.Clear(); dpDepartMins.Items.Clear(); dpArrivalHours.Items.Clear(); dpArrivalMins.Items.Clear(); dpDepartHours.Items.Add("None"); dpArrivalHours.Items.Add("None"); for (int i = 0; i < 24; i++) { dpDepartHours.Items.Add(i.ToString()); dpArrivalHours.Items.Add(i.ToString()); } //dpDepartMins.Items.Add("None"); //dpArrivalMins.Items.Add("None"); for (int i = 0; i <= 59; i += 10) { dpDepartMins.Items.Add(i.ToString()); dpArrivalMins.Items.Add(i.ToString()); } txtDuration.Enabled = false; txtDuration.Text = ""; chkStatus.Checked = false; IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); try { List <Route> routes = routeManager.GetRoutes(); dpRoute.Items.Add(new ListItem("Select Route...", "-1")); foreach (Route route in routes) { string r = route.FromCity.Name + " (" + route.FromCity.StateInfo.Name + ")" + " ==> " + route.ToCity.Name + " (" + route.ToCity.StateInfo.Name + ")"; string v = route.ID.ToString(); dpRoute.Items.Add(new ListItem(r, v)); } } catch (RouteManagerException e) { ctlAdminMaster.ErrorMessage = e.Message; } IAirLineManager airlineManager = (IAirLineManager)AirTravelManagerFactory.Create("AirlineManager"); try { List <Airline> airlines = airlineManager.GetAirLines(); dpAirlineName.Items.Add("None"); foreach (Airline c in airlines) { ListItem item = new ListItem(c.Name, c.Id.ToString()); dpAirlineName.Items.Add(item); } dpAirlineName.DataBind(); } catch (AirlineManagerException e) { ctlAdminMaster.ErrorMessage = e.Message; } ShowDefaultClasses(); }
protected void btnUpdate_Click(object sender, EventArgs e) { try { Route route = null; IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("ScheduleManager"); Schedule schedule = new Schedule(); string rid = dpRoute.SelectedValue; IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); try { List <Route> routes = routeManager.GetRoutes(); foreach (Route r in routes) { if (r.ID == Convert.ToInt32(rid)) { route = r; break; } } } catch (RouteManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } schedule.RouteInfo = route; if (scheduleManager.GetRouteID(schedule) == 0) { ctlAdminMaster.ErrorMessage = "Select the Existing Route"; } else if (dpFlightName.SelectedItem == null) { ctlAdminMaster.ErrorMessage = "Please select a Flight name"; } else { TimeSpan t1 = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString()); TimeSpan t2 = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString()); total = int.Parse((t1 - t2).TotalMinutes.ToString()); if (total == 0) { ctlAdminMaster.ErrorMessage = "The departure time and the arrival time cannot be same"; return; } if (total < 0) { total = (24 * 60) + total; } txtDuration.Text = total.ToString(); Flight flight = new Flight(); flight.ID = long.Parse(dpFlightName.SelectedItem.Value); flight.Name = dpFlightName.SelectedItem.Text; scheduleid = Request.QueryString["scheduleid"].ToString(); schedule.ID = long.Parse(scheduleid); schedule.RouteInfo = route; schedule.FlightInfo = flight; schedule.DepartureTime = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString()); schedule.ArrivalTime = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString()); schedule.DurationInMins = total; schedule.IsActive = chkStatus.Checked; scheduleManager.UpdateSchedule(schedule); Response.Redirect("~/Admin/Schedule_Flight.aspx"); } } catch (ScheduleManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } }
protected void btnAdd_Click(object sender, EventArgs e) { IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("ScheduleManager"); Schedule schedule = new Schedule(); Route route = null; if (dpAirlineName.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Airline Name"; dpAirlineName.Focus(); } else if (dpFlightName.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Flight Name"; dpFlightName.Focus(); } else if (dpDepartHours.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Departure Hours"; dpDepartHours.Focus(); } else if (dpDepartMins.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Departure Minutes"; dpDepartMins.Focus(); } else if (dpArrivalHours.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Arrival Hours"; dpArrivalHours.Focus(); } else if (dpArrivalMins.Text.Equals("None") == true) { ctlAdminMaster.ErrorMessage = "Select Arrival Minutes"; dpArrivalMins.Focus(); } else { string rid = dpRoute.SelectedValue; if (rid.Equals("-1")) { ctlAdminMaster.ErrorMessage = "Select a route"; return; } IRouteManager routeManager = (IRouteManager)BusinessObjectManager.GetRouteManager(); try { List <Route> routes = routeManager.GetRoutes(); foreach (Route r in routes) { if (r.ID == Convert.ToInt32(rid)) { route = r; break; } } } catch (RouteManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } schedule.RouteInfo = route; if (scheduleManager.GetRouteID(schedule) == 0) { ctlAdminMaster.ErrorMessage = "Select the Existing Route"; //dpFromCity.Focus(); } else { TimeSpan t1 = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString()); TimeSpan t2 = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString()); total = int.Parse((t1 - t2).TotalMinutes.ToString()); if (total == 0) { ctlAdminMaster.ErrorMessage = "The departure time and the arrival time cannot be same"; return; } if (total < 0) { total = (24 * 60) + total; } txtDuration.Text = total.ToString(); Flight flight = new Flight(); flight.ID = long.Parse(dpFlightName.SelectedItem.Value); flight.Name = dpFlightName.SelectedItem.Text; schedule.RouteInfo = route; schedule.FlightInfo = flight; schedule.DepartureTime = TimeSpan.Parse(dpDepartHours.SelectedItem.ToString() + ":" + dpDepartMins.SelectedItem.ToString()); schedule.ArrivalTime = TimeSpan.Parse(dpArrivalHours.SelectedItem.ToString() + ":" + dpArrivalMins.SelectedItem.ToString()); schedule.DurationInMins = total; schedule.IsActive = chkStatus.Checked; foreach (RepeaterItem item in Repeater1.Items) { Label lblclassname = (Label)item.FindControl("ClassName"); TextBox txtcost = (TextBox)item.FindControl("txtCostPerTicket"); decimal cost = 0; try { cost = Convert.ToDecimal(txtcost.Text); } catch (FormatException) { ctlAdminMaster.ErrorMessage = "Cost should be a positive currency value"; txtcost.Focus(); return; } if (cost <= 0) { ctlAdminMaster.ErrorMessage = "Cost should be a positive currency value"; txtcost.Focus(); return; } else { if (txtcost != null || lblclassname != null) { string classname = lblclassname.Text; string val = txtcost.Text; FlightCost fc = new FlightCost(); fc.Class = (TravelClass)Enum.Parse(typeof(TravelClass), classname); fc.CostPerTicket = decimal.Parse(txtcost.Text); schedule.AddFlightCost(fc); } } } //Extracted from the loop preventing a potential exception try { scheduleManager.AddSchedule(schedule); ctlAdminMaster.ErrorMessage = "Schedule Added Successfully"; //Response.Redirect("~/Admin/Home.aspx"); } catch (ScheduleManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } } }