/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void InsertSkiRun(SkiRun skiRun) { string connString = GetConnectionString(); // build out SQL command var sb = new StringBuilder("INSERT INTO SkiRuns"); sb.Append(" ([ID],[Name],[Vertical])"); sb.Append(" Values ("); sb.Append("'").Append(skiRun.ID).Append("',"); sb.Append("'").Append(skiRun.Name).Append("',"); sb.Append("'").Append(skiRun.Vertical).Append("')"); string sqlCommandString = sb.ToString(); SqlConnection sqlConn = new SqlConnection(connString); SqlDataAdapter sqlAdapter = new SqlDataAdapter(); using (sqlConn) { try { sqlConn.Open(); sqlAdapter.InsertCommand = new SqlCommand(sqlCommandString, sqlConn); sqlAdapter.InsertCommand.ExecuteNonQuery(); } catch (SqlException sqlEx) { Console.WriteLine("SQL Exception: {0}", sqlEx.Message); Console.WriteLine(sqlCommandString); } } }
private static void DeleteSkiRun() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); List <SkiRun> skiRuns; SkiRun skiRun = new SkiRun(); int skiRunID; string message; using (skiRunRepository) { skiRuns = skiRunRepository.SelectAllRuns(); } skiRunID = ConsoleView.GetSkiRunID(skiRuns); using (skiRunRepository) { skiRunRepository.DeleteSkiRun(skiRunID); } ConsoleView.DisplayReset(); // TODO refactor message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID); ConsoleView.DisplayMessage(message); ConsoleView.DisplayContinuePrompt(); }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun SelectById(int ID) { //Variable Declarations. SkiRun skiRunDetail = null; if (IsSkiRunIDTaken(ID) == true) { //If the ID value entered exists... //Get the ski run information for the ID entered by the user. foreach (SkiRun skiRun in _skiRuns) { if (skiRun.ID == ID) { skiRunDetail = skiRun; break; } } } else { //If the ID value entered does not exist... //Throw a new exception. throw new ArgumentException($"The ID value of {ID} does not exist. Please re-enter a new ID."); } return(skiRunDetail); }
/// <summary> /// Adds a record to the data source with information provided by the user /// </summary> /// <param name="skiRunRepository"></param> private static void AddSkiRun() { SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository); //Variable Declarations. SkiRun aSkiRun = new SkiRun(); ConsoleView.DisplayReset(); //Get the ID, Name, and Vertical feet from the user. aSkiRun.ID = ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: "); aSkiRun.Name = ConsoleView.GetUserResponse("Enter the name for the Ski Run: "); aSkiRun.Vertical = ConsoleView.GetIntegerFromUser("Enter the vertical (in feet) for the Ski Run: "); using (skiRunBusiness) { //Insert the new ski run. try { //Insert the new record. skiRunRepository.Insert(aSkiRun); //Display a message to the user that the record was inserted. ConsoleView.DisplayReset(); ConsoleView.DisplayMessage($"The information for the {aSkiRun.Name} ski run has been saved."); ConsoleView.DisplayContinuePrompt(); } catch (Exception ex) { //Display the error message for the error that occurred. CatchIOExceptions(ex); } } }
public static SkiRun UpdateSkiRun(SkiRun skiRun) { string userResponse = ""; DisplayReset(); DisplayMessage(""); Console.WriteLine(ConsoleUtil.Center("Edit A Ski Run", WINDOW_WIDTH)); DisplayMessage(""); DisplayMessage(String.Format("Current Name: {0}", skiRun.Name)); DisplayPromptMessage("Enter a new name or just press Enter to keep the current name: "); userResponse = Console.ReadLine(); if (userResponse != "") { skiRun.Name = userResponse; } DisplayMessage(""); DisplayMessage(String.Format("Current Vertical in Feet: {0}", skiRun.Vertical.ToString())); DisplayPromptMessage("Enter the new vertical in feet or just press Enter to keep the current vertical: "); userResponse = Console.ReadLine(); if (userResponse != "") { skiRun.Vertical = ConsoleUtil.ValidateIntegerResponse("Please enter the vertical in feet.", userResponse); } DisplayContinuePrompt(); return(skiRun); }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void UpdateSkiRun(SkiRun skiRun) { DeleteSkiRun(skiRun.ID); InsertSkiRun(skiRun); WriteSkiRunsData(); }
public static string GetAddSkiRun(SkiRun skiRun) { //string newSkiRun = skiRun.ID + "," + skiRun.Name + "," + skiRun.Vertical; DisplayMessage(""); DisplayPromptMessage("Enter a ski run ID: "); skiRun.ID = ConsoleUtil.ValidateIntegerResponse("Please enter the ski run ID: ", Console.ReadLine()); DisplayMessage(""); DisplayPromptMessage("Enter the Ski Run name: "); skiRun.Name = Console.ReadLine(); DisplayMessage(""); DisplayPromptMessage("Enter the ski run vertical: "); skiRun.Vertical = ConsoleUtil.ValidateIntegerResponse("Please enter the ski run vertical: ", Console.ReadLine()); StringBuilder newSkiRun = new StringBuilder(); return(newSkiRun.ToString()); }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void Update(SkiRun skiRun) { Delete(skiRun.ID); Insert(skiRun); Save(); }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void UpdateSkiRun(SkiRun skiRun) { DataRow[] skiRuns; int ID = skiRun.ID; // get an array of ski runs with the matching ID skiRuns = _skiRuns_dt.Select("ID = " + ID.ToString()); // no ski runs with the matching ID if (skiRuns.Count() < 1) { throw new Exception("Ski run now found."); } // multiple ski runs with the matching ID else if (skiRuns.Count() > 1) { throw new Exception("More than one ski run with the id: " + ID); } // a unique ski run with the matching ID else { skiRuns[0]["ID"] = skiRun.ID; skiRuns[0]["Name"] = skiRun.Name; skiRuns[0]["Vertical"] = skiRun.Vertical; } }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun SelectByID(int ID) { SkiRun skiRun = new SkiRun(); DataRow[] skiRuns; // get an array of ski runs with the matching ID skiRuns = _skiRuns_dt.Select("ID = " + ID.ToString()); // no ski runs with the matching ID if (skiRuns.Count() < 1) { throw new Exception("Ski run now found."); } // multiple ski runs with the matching ID else if (skiRuns.Count() > 1) { throw new Exception("More than one ski run with the id: " + ID); } // a unique ski run with the matching ID else { skiRun.ID = int.Parse(skiRuns[0]["ID"].ToString()); skiRun.Name = skiRuns[0]["Name"].ToString(); skiRun.Vertical = int.Parse(skiRuns[0]["Vertical"].ToString()); } return(skiRun); }
private static void UpdateSkiRun() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); List <SkiRun> skiRuns = skiRunRepository.SelectAllRuns(); SkiRun skiRun = new SkiRun(); int skiRunID; using (skiRunRepository) { skiRuns = skiRunRepository.SelectAllRuns(); } skiRunID = ConsoleView.GetSkiRunID(skiRuns); using (skiRunRepository) { skiRun = skiRunRepository.SelectByID(skiRunID); } skiRun = ConsoleView.UpdateSkiRun(skiRun); using (skiRunRepository) { skiRunRepository.UpdateSkiRun(skiRun); } }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun GetSkiRunByID(int ID) { SkiRun skiRun = null; skiRun = _skiRuns[GetSkiRunIndex(ID)]; return(skiRun); }
/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void InsertSkiRun(SkiRun skiRun) { string skiRunString; skiRunString = skiRun.ID + "," + skiRun.Name + "," + skiRun.Vertical; WriteSkiRunsData(); }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun SelectById(int ID) { SkiRun skiRun = null; skiRun = _skiRuns.FirstOrDefault(sr => sr.ID == ID); return(skiRun); }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun GetSkiRunByID(int ID) { SkiRun skiRun = null; skiRun = _skiRuns.FirstOrDefault(sr => sr.ID == ID); return(skiRun); }
/// <summary> /// Updates a specific ski run's information in the data source with data entered by the user /// </summary> /// <param name="skiRunRepository"></param> /// <param name="skiRuns"></param> private static void UpdateSkiRun() { SkiRunBusiness skiRunBusiness = new SkiRunBusiness(skiRunRepository); SkiRun aSkiRun = new SkiRun(); using (skiRunBusiness) { List <SkiRun> skiRuns = skiRunRepository.SelectAll(); //Variable Declarations. ConsoleView.DisplayReset(); //Display all ski runs. ConsoleView.DisplayAllSkiRuns(skiRuns, false); Console.WriteLine(); Console.WriteLine(); //Get the information for the ski run to be updated and display it on the screen. try { //Display the ski run information on the screen. //ConsoleView.DisplaySkiRunDetail(skiRunRepository.GetSkiRunByID(ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: "))); aSkiRun = skiRunRepository.SelectById(ConsoleView.GetIntegerFromUser("Enter the ID for the Ski Run: ")); ConsoleView.DisplaySkiRunDetail(aSkiRun); } catch (Exception ex) { //Display the error message for the error that occurred. CatchIOExceptions(ex); return; } //Get the new Name and Vertical feet from the user. Console.WriteLine(); Console.WriteLine(); aSkiRun.Name = ConsoleView.GetUserResponse("Enter the new name for the Ski Run: "); aSkiRun.Vertical = ConsoleView.GetIntegerFromUser("Enter the new vertical (in feet) for the Ski Run: "); //Update the ski run. try { //Update the ski run information. skiRunRepository.Update(aSkiRun); //Display a message to the user that the record was updated. ConsoleView.DisplayReset(); ConsoleView.DisplayMessage($"The information for the {aSkiRun.Name} ski run has been updated."); ConsoleView.DisplayContinuePrompt(); } catch (Exception ex) { //Display the error message for the error that occurred. CatchIOExceptions(ex); return; } } }
private void ApplicationControl() { //Variable Declarations. ConsoleView.DisplayWelcomeScreen(); while (active) { AppEnum.ManagerAction userActionChoice; SkiRun aSkiRun = new SkiRun(); userActionChoice = ConsoleView.GetUserActionChoice(); switch (userActionChoice) { case AppEnum.ManagerAction.None: break; case AppEnum.ManagerAction.ListAllSkiRuns: //Display all ski runs. ListAllSkiRuns(); break; case AppEnum.ManagerAction.DisplaySkiRunDetail: DisplaySkiRunDetail(); break; case AppEnum.ManagerAction.DeleteSkiRun: DeleteSkiRun(); break; case AppEnum.ManagerAction.AddSkiRun: AddSkiRun(); break; case AppEnum.ManagerAction.UpdateSkiRun: UpdateSkiRun(); break; case AppEnum.ManagerAction.QuerySkiRunsByVertical: QuerySkiRunsByVertical(); break; case AppEnum.ManagerAction.Quit: active = false; break; default: break; } } ConsoleView.DisplayExitPrompt(); }
private static void AddSkiRun() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); SkiRun skiRun = new SkiRun(); skiRun = ConsoleView.AddSkiRun(); using (skiRunRepository) { skiRunRepository.InsertSkiRun(skiRun); } ConsoleView.DisplayContinuePrompt(); }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun GetSkiRunByID(int ID) { SkiRun skiRun = null; for (int index = 0; index < _skiRuns.Count(); index++) { if (_skiRuns[index].ID == ID) { return(skiRun); } } return(skiRun); }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void Update(SkiRun skiRun) { foreach (SkiRun skiRunToUpdate in _skiRuns) { if (skiRunToUpdate.ID == skiRun.ID) { skiRunToUpdate.Name = skiRun.Name; skiRunToUpdate.Vertical = skiRun.Vertical; break; } Save(); } }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void UpdateSkiRun(SkiRun skiRun) { string tabLeft = ConsoleUtil.FillStringWithSpaces(ViewSettings.DISPLAY_HORIZONTAL_MARGIN); //Finds the ID of the skirun you wish to change for (int index = 0; index < _skiRuns.Count(); index++) { if (_skiRuns[index].ID == skiRun.ID) { skiRun.Name = _skiRuns[index].Name; skiRun.Vertical = _skiRuns[index].Vertical; //The remove is here because it's going to add the skirun back at the //end of the update. _skiRuns.RemoveAt(index); } } //Gets a new name. If the user does not input anything, it keeps the old one. Console.WriteLine(tabLeft + "Changing Name. If you wish to keep the same name, just hit enter."); Console.Write(tabLeft); string nameChange = Console.ReadLine(); if (nameChange != "") { skiRun.Name = nameChange; } //Gets a new vertical. If the user does not input anything, it keeps the old one. Console.WriteLine(tabLeft + "Changeing Vertical. If you wish to keep the same vertical, just hit enter."); Console.Write(tabLeft); string verticalChangeCheck = Console.ReadLine(); int verticalChange; if (verticalChangeCheck != "") { while (!int.TryParse(verticalChangeCheck, out verticalChange)) { ConsoleView.DisplayPromptMessage("Sorry, but the ID needs to be a number. Please try again."); } ; skiRun.Vertical = verticalChange; } //Adds the skirun to the list and writes the list. _skiRuns.Add(skiRun); WriteSkiRunsData(); }
/// <summary> /// method to display a ski run info /// </summary> public static void DisplaySkiRun(SkiRun skiRun) { DisplayReset(); DisplayMessage(""); Console.WriteLine(ConsoleUtil.Center("Ski Run Detail", WINDOW_WIDTH)); DisplayMessage(""); DisplayMessage(String.Format("Ski Run: {0}", skiRun.Name)); DisplayMessage(""); DisplayMessage(String.Format("ID: {0}", skiRun.ID.ToString())); DisplayMessage(String.Format("Vertical in Feet: {0}", skiRun.Vertical.ToString())); DisplayMessage(""); }
private static void DisplaySkiRunDetail() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); List <SkiRun> skiRuns; SkiRun skiRun = new SkiRun(); int skiRunID; using (skiRunRepository) { skiRuns = skiRunRepository.SelectAllRuns(); } skiRunID = ConsoleView.GetSkiRunID(skiRuns); using (skiRunRepository) { skiRun = skiRunRepository.SelectByID(skiRunID); } ConsoleView.DisplaySkiRun(skiRun); ConsoleView.DisplayContinuePrompt(); }
private static void DisplaySkiRunDetail() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); List<SkiRun> skiRuns = skiRunRepository.SelectAllRuns(); SkiRun skiRun = new SkiRun(); int skiRunID; using (skiRunRepository) { skiRuns = skiRunRepository.SelectAllRuns(); } skiRunID = ConsoleView.GetSkiRunID(skiRuns); using (skiRunRepository) { skiRun = skiRunRepository.SelectByID(skiRunID); } ConsoleView.DisplaySkiRun(skiRun); ConsoleView.DisplayContinuePrompt(); }
/// <summary> /// method to add a ski run info /// </summary> public static SkiRun AddSkiRun() { SkiRun skiRun = new SkiRun(); DisplayReset(); DisplayMessage(""); Console.WriteLine(ConsoleUtil.Center("Add A Ski Run", WINDOW_WIDTH)); DisplayMessage(""); DisplayPromptMessage("Enter the ski run ID: "); skiRun.ID = ConsoleUtil.ValidateIntegerResponse("Please enter the ski run ID: ", Console.ReadLine()); DisplayMessage(""); DisplayPromptMessage("Enter the ski run name: "); skiRun.Name = Console.ReadLine(); DisplayMessage(""); DisplayPromptMessage("Enter the ski run vertical in feet: "); skiRun.Vertical = ConsoleUtil.ValidateIntegerResponse("Please the ski run vertical in feet: ", Console.ReadLine()); return skiRun; }
/// <summary> /// Displays the detail information for a single ski run. /// </summary> /// <param name="skiRun"></param> public static void DisplaySkiRunDetail(SkiRun skiRun) { DisplayReset(); DisplayMessage($"The details for ski run {skiRun.Name} are listed below: "); DisplayMessage(""); StringBuilder columnHeader = new StringBuilder(); columnHeader.Append("ID".PadRight(8)); columnHeader.Append("Ski Run".PadRight(25)); columnHeader.Append("Vertical in Feet".PadRight(5)); DisplayMessage(columnHeader.ToString()); StringBuilder skiRunInfo = new StringBuilder(); skiRunInfo.Append(skiRun.ID.ToString().PadRight(8)); skiRunInfo.Append(skiRun.Name.PadRight(25)); skiRunInfo.Append(skiRun.Vertical.ToString().PadRight(5)); DisplayMessage(skiRunInfo.ToString()); }
/// <summary> /// method to add a ski run info /// </summary> public static SkiRun AddSkiRun() { SkiRun skiRun = new SkiRun(); DisplayReset(); DisplayMessage(""); Console.WriteLine(ConsoleUtil.Center("Add A Ski Run", WINDOW_WIDTH)); DisplayMessage(""); DisplayPromptMessage("Enter the ski run ID: "); skiRun.ID = ConsoleUtil.ValidateIntegerResponse("Please enter the ski run ID: ", Console.ReadLine()); DisplayMessage(""); DisplayPromptMessage("Enter the ski run name: "); skiRun.Name = Console.ReadLine(); DisplayMessage(""); DisplayPromptMessage("Enter the ski run vertical in feet: "); skiRun.Vertical = ConsoleUtil.ValidateIntegerResponse("Please the ski run vertical in feet: ", Console.ReadLine()); return(skiRun); }
private static void DeleteSkiRun() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); List<SkiRun> skiRuns = skiRunRepository.SelectAllRuns(); SkiRun skiRun = new SkiRun(); int skiRunID; string message; skiRunID = ConsoleView.GetSkiRunID(skiRuns); using (skiRunRepository) { skiRunRepository.DeleteSkiRun(skiRunID); } ConsoleView.DisplayReset(); // TODO refactor message = String.Format("Ski Run ID: {0} had been deleted.", skiRunID); ConsoleView.DisplayMessage(message); ConsoleView.DisplayContinuePrompt(); }
/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void Insert(SkiRun skiRun) { //Variale Declarations. string skiRunString; skiRunString = skiRun.ID + "," + skiRun.Name + "," + skiRun.Vertical; //Check to make sure the ID and Name values have not been taken. if (IsSkiRunIDTaken(skiRun.ID) == true) { throw new ArgumentException($"The ID value of {skiRun.ID} has already been used for another ski run. Please re-enter the ski run information with a different ID value."); //return; } if (IsSkiRunNameTaken(skiRun.Name) == true) { throw new ArgumentException($"The name {skiRun.Name} has already been used for another ski run. Please re-enter the ski run information with a different Name."); } _skiRuns.Add(skiRun); Save(); }
/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void InsertSkiRun(SkiRun skiRun) { _skiRuns.Add(skiRun); WriteSkiRunsData(); }
public static SkiRun UpdateSkiRun(SkiRun skiRun) { string userResponse = ""; DisplayReset(); DisplayMessage(""); Console.WriteLine(ConsoleUtil.Center("Edit A Ski Run", WINDOW_WIDTH)); DisplayMessage(""); DisplayMessage(String.Format("Current Name: {0}", skiRun.Name)); DisplayPromptMessage("Enter a new name or just press Enter to keep the current name: "); userResponse = Console.ReadLine(); if (userResponse != "") { skiRun.Name = userResponse; } DisplayMessage(""); DisplayMessage(String.Format("Current Vertical in Feet: {0}", skiRun.Vertical.ToString())); DisplayPromptMessage("Enter the new vertical in feet or just press Enter to keep the current vertical: "); userResponse = Console.ReadLine(); if (userResponse != "") { skiRun.Vertical = ConsoleUtil.ValidateIntegerResponse("Please enter the vertical in feet.", userResponse); } DisplayContinuePrompt(); return skiRun; }
/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void InsertSkiRun(SkiRun skiRun) { fillRow(_skiRuns_dt, skiRun.ID, skiRun.Name, skiRun.Vertical); }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun SelectByID(int ID) { SkiRun skiRun = new SkiRun(); DataRow[] skiRuns; // get an array of ski runs with the matching ID skiRuns = _skiRuns_dt.Select("ID = " + ID.ToString()); // no ski runs with the matching ID if (skiRuns.Count() < 1) { throw new Exception("Ski run now found."); } // multiple ski runs with the matching ID else if (skiRuns.Count() > 1) { throw new Exception("More than one ski run with the id: " + ID); } // a unique ski run with the matching ID else { skiRun.ID = int.Parse(skiRuns[0]["ID"].ToString()); skiRun.Name = skiRuns[0]["Name"].ToString(); skiRun.Vertical = int.Parse(skiRuns[0]["Vertical"].ToString()); } return skiRun; }
/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void Insert(SkiRun skiRun) { _skiRuns.Add(skiRun); Save(); }
private static void UpdateSkiRun() { SkiRunRepositoryXML_DS skiRunRepository = new SkiRunRepositoryXML_DS(); List<SkiRun> skiRuns = skiRunRepository.SelectAllRuns(); SkiRun skiRun = new SkiRun(); int skiRunID; using (skiRunRepository) { skiRuns = skiRunRepository.SelectAllRuns(); } skiRunID = ConsoleView.GetSkiRunID(skiRuns); using (skiRunRepository) { skiRun = skiRunRepository.SelectByID(skiRunID); } skiRun = ConsoleView.UpdateSkiRun(skiRun); using (skiRunRepository) { skiRunRepository.UpdateSkiRun(skiRun); } }
/// <summary> /// method to return a ski run object given the ID /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun GetSkiRunByID(int ID) { SkiRun skiRun = null; return(skiRun); }
/// <summary> /// method to return a ski run given the name /// uses a DataSet to hold ski run info /// NOTE: not implemented or tested /// </summary> /// <param name="ID">int ID</param> /// <returns>ski run object</returns> public SkiRun SelectSkiRun(string name) { DataSet skiRuns_ds = new DataSet(); DataTable skiRuns_dt = new DataTable(); DataRow[] skiRunRows; SkiRun skiRun = new SkiRun(); string selectExpression; // read all ski run info into a DataSet skiRuns_ds = GetDataSet(); // build select expression selectExpression = "ID = " + name; // add all matching ski runs to an array of DataRow skiRunRows = skiRuns_ds.Tables["SkiRuns"].Select(selectExpression); // check for unique ID value if (skiRunRows.Count() == 1) { skiRun.ID = int.Parse(skiRunRows[0]["ID"].ToString()); skiRun.Name = skiRunRows[0]["Name"].ToString(); skiRun.Vertical = int.Parse(skiRunRows[0]["Vertical"].ToString()); } else { // ski run ID not unique } return skiRun; }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void UpdateSkiRun(SkiRun skiRun) { }
/// <summary> /// method to update an existing ski run /// </summary> /// <param name="skiRun">ski run object</param> public void UpdateSkiRun(SkiRun skiRun) { string connString = GetConnectionString(); // build out SQL command var sb = new StringBuilder("UPDATE SkiRuns SET "); sb.Append("Name = '").Append(skiRun.Name).Append("', "); sb.Append("Vertical = ").Append(skiRun.Vertical).Append(" "); sb.Append("WHERE "); sb.Append("ID = ").Append(skiRun.ID); string sqlCommandString = sb.ToString(); SqlConnection sqlConn = new SqlConnection(connString); SqlDataAdapter sqlAdapter = new SqlDataAdapter(); using (sqlConn) { try { sqlConn.Open(); sqlAdapter.UpdateCommand = new SqlCommand(sqlCommandString, sqlConn); sqlAdapter.UpdateCommand.ExecuteNonQuery(); } catch (SqlException sqlEx) { Console.WriteLine("SQL Exception: {0}", sqlEx.Message); Console.WriteLine(sqlCommandString); } } }
/// <summary> /// method to add a new ski run /// </summary> /// <param name="skiRun"></param> public void InsertSkiRun(SkiRun skiRun) { string skiRunString; skiRunString = skiRun.ID + "," + skiRun.Name + "," + skiRun.Vertical; }
private void ApplicationControl() { SkiRunRepository skiRunRepository = new SkiRunRepository(); ConsoleView.DisplayWelcomeScreen(); using (skiRunRepository) { List <SkiRun> skiRuns = skiRunRepository.GetSkiAllRuns(); while (active) { AppEnum.ManagerAction userActionChoice; int vertical; int skiRunID; SkiRun skiRun; string skiRunString; List <SkiRun> ski2 = new List <SkiRun>(); userActionChoice = ConsoleView.GetUserActionChoice(); switch (userActionChoice) { case AppEnum.ManagerAction.None: break; case AppEnum.ManagerAction.ListAllSkiRuns: ConsoleView.DisplayAllSkiRuns(skiRuns); ConsoleView.DisplayContinuePrompt(); break; case AppEnum.ManagerAction.DisplaySkiRunDetail: ConsoleView.DisplayAllSkiRuns(skiRuns); ski2 = skiRunRepository.GetSkiRunByID(ConsoleView.DisplayGetSkiRunIDChoice(skiRuns)); ConsoleView.DisplaySkiRunDetails(ski2); ConsoleView.DisplayContinuePrompt(); break; case AppEnum.ManagerAction.DeleteSkiRun: skiRunRepository.DeleteSkiRun(ConsoleView.DisplayGetSkiRunIDChoice(skiRuns)); ConsoleView.DisplayReset(); ConsoleView.DisplayMessage("Ski Run has been deleted."); ConsoleView.DisplayContinuePrompt(); break; case AppEnum.ManagerAction.AddSkiRun: skiRun = new SkiRun(); skiRun.ID = ConsoleView.DisplayGetSkiRunID(); skiRun.Name = ConsoleView.DisplayGetSkiRunName(); skiRun.Vertical = ConsoleView.DisplayGetSkiRunVertical(); skiRunRepository.InsertSkiRun(skiRun); ConsoleView.DisplayAllSkiRuns(skiRuns); ConsoleView.DisplayNewSkiRunMessage(); break; case AppEnum.ManagerAction.UpdateSkiRun: skiRun = new SkiRun(); skiRun.ID = ConsoleView.DisplayGetSkiRunIDChoice(skiRuns); skiRunRepository.UpdateSkiRun(skiRun); Console.WriteLine(); break; case AppEnum.ManagerAction.QuerySkiRunsByVertical: int minimumVertical = skiRunRepository.GetMinimumVertical(); int maximumVertical = skiRunRepository.GetMaximumVertical(); //Sorts all the available entries and pushes out those that match into a new list. List <SkiRun> matchingSkiRuns = skiRunRepository.QueryByVertical(minimumVertical, maximumVertical); ConsoleView.DisplayReset(); //Displays the new list. Console.WriteLine("Ski Runs with a vertical between " + minimumVertical + " and " + maximumVertical + "."); skiRunRepository.DisplayQueriedVertical(matchingSkiRuns); ConsoleView.DisplayContinuePrompt(); break; case AppEnum.ManagerAction.Quit: active = false; break; default: break; } } } ConsoleView.DisplayExitPrompt(); }