protected void btnAdd_Click(object sender, EventArgs e) { IScheduleManager scheduleManager = (IScheduleManager)AirTravelManagerFactory.Create("Schedule"); Schedule schedule = new Schedule(); Route route = new Route(); 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 (dpAirlineName.Text.Equals("None") == true) { lblError.Text = "Select Airline Name"; dpAirlineName.Focus(); } else if (dpFlightName.Text.Equals("None") == true) { lblError.Text = "Select Flight Name"; dpFlightName.Focus(); } else if (DropDownList1.Text.Equals("None") == true) { lblError.Text = "Select Departure Hours"; DropDownList1.Focus(); } else if (DropDownList2.Text.Equals("None") == true) { lblError.Text = "Select Departure Minutes"; DropDownList2.Focus(); } else if (DropDownList4.Text.Equals("None") == true) { lblError.Text = "Select Arrival Hours"; DropDownList4.Focus(); } else if (DropDownList5.Text.Equals("None") == true) { lblError.Text = "Select Arrival Minutes"; DropDownList5.Focus(); } else { 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; schedule.RouteInfo = route; int routeID = scheduleManager.GetRouteID(schedule); schedule.RouteInfo.ID = routeID; if (routeID == 0) { lblError.Text = "Select the Existing Route"; dpFromCity.Focus(); } else { TimeSpan t1 = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.SelectedItem.ToString()); TimeSpan t2 = TimeSpan.Parse(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString()); total = int.Parse((t1 - t2).TotalMinutes.ToString()); 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(DropDownList1.SelectedItem.ToString() + ":" + DropDownList2.SelectedItem.ToString()); schedule.ArrivalTime = TimeSpan.Parse(DropDownList4.SelectedItem.ToString() + ":" + DropDownList5.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"); if (txtcost.Text.Length == 0) { lblError.Text = "Flight Cost Can't be Empty"; txtcost.Focus(); break; } 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); } } } try { scheduleManager.AddSchedule(schedule); lblError.Text = "Schedule Added Successfully"; } catch (ScheduleManagerException ex) { lblError.Text = ex.Message; } } } }
protected void ButtonAdd_Click(object sender, EventArgs e) { loggedInUserIdString = Request.QueryString["loggedInUserId"].Trim(); loggedInUserId = new Guid(loggedInUserIdString); //loggedInUserId = new Guid("282DD55C-5BD0-E711-A94A-000D3A2CD91F"); var owner = DropDownList5.SelectedItem.Value; if (owner != "") { ownerId = new Guid(owner); } if (DropDownList4.SelectedItem.Value == "") { Label7.Text = "Please Insert Customer or Lead"; DropDownList4.Focus(); } else if (DropDownList3.SelectedItem.Value == "") { Label7.Text = "Please Insert a Unit"; DropDownList3.Focus(); } else if (DropDownList5.SelectedItem.Value == "") { Label7.Text = "Please Insert an Owner"; DropDownList5.Focus(); } try { if (DropDownList4.SelectedItem.Value != "" && DropDownList2.SelectedItem.Value != "" && DropDownList3.SelectedItem.Value != "" && DropDownList5.SelectedItem.Value != "") { Entity launchRequestEntity = new Entity("ldv_launchrequest"); launchRequestEntity["ldv_requestcreator"] = new EntityReference("systemuser", loggedInUserId); var customerOrLeadValue = DropDownList4.SelectedItem.Value; Guid customerOrLeadId = new Guid(customerOrLeadValue); service_proxy.CallerId = loggedInUserId; string fetch = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='contact'> <attribute name='fullname' /> <attribute name='telephone1' /> <attribute name='contactid' /> <order attribute='fullname' descending='false' /> <filter type='and'> <condition attribute='contactid' operator='eq' uitype='contact' value='" + customerOrLeadId + @"' /> </filter> </entity> </fetch>"; EntityCollection CustomerColl = service_proxy.RetrieveMultiple(new FetchExpression(fetch)); if (CustomerColl.Entities.Any()) // customer { launchRequestEntity["ldv_customerid"] = CustomerColl.Entities[0].ToEntityReference(); } else // lead { string fetchLeads = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'> <entity name='lead'> <attribute name='fullname' /> <attribute name='leadid' /> <attribute name='mobilephone' /> <order attribute='fullname' descending='false' /> <filter type='and'> <condition attribute='leadid' operator='eq' uitype='lead' value='" + customerOrLeadId + @"' /> </filter> </entity> </fetch>"; EntityCollection LeadsColl = service_proxy.RetrieveMultiple(new FetchExpression(fetchLeads)); if (LeadsColl.Entities.Any())//lead { launchRequestEntity["ldv_leadid"] = LeadsColl.Entities[0].ToEntityReference(); } } // choices var choicesValue = DropDownList2.SelectedItem.Value; launchRequestEntity["ldv_prioritycode"] = new OptionSetValue(Convert.ToInt32(choicesValue)); //Unit var unitValue = DropDownList3.SelectedItem.Value; Guid unitId = new Guid(unitValue); Entity unitEntity = service_proxy.Retrieve("new_unit", unitId, new ColumnSet("new_unitid")); if (unitEntity.Id != Guid.Empty) { launchRequestEntity["ldv_unitid"] = unitEntity.ToEntityReference(); } service_proxy.CallerId = ownerId; Guid luanchRequestCreatedRecord = service_proxy.Create(launchRequestEntity); if (luanchRequestCreatedRecord != Guid.Empty) { Label7.Text = "Request Added Successfuly"; Label7.ForeColor = System.Drawing.Color.Green; FillRequestsGridOnLoad(); } } } catch (Exception ex) { Label7.Text = ex.Message; Label7.ForeColor = System.Drawing.Color.Red; } }