public BoatBLL GetBoat(BoatBLL boat) { using (SqlConnection conn = CreateConnection()) { try { SqlCommand cmd = new SqlCommand("appSchema.uspGetBoat", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@BoatId", SqlDbType.Int, 4).Value = boat.BoatId; conn.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { int SSNIndex = reader.GetOrdinal("SSN"); int BoatTypeIndex = reader.GetOrdinal("BoatType"); int BoatLengthIndex = reader.GetOrdinal("BoatLength"); boat.SSN = reader.GetString(SSNIndex); boat.BoatType = (BoatType)reader.GetInt32(BoatTypeIndex); boat.BoatLength = reader.GetInt32(BoatLengthIndex); return boat; } } return null; } catch { throw new ApplicationException("An error occured while getting a member from the database."); } } }
public BoatBLL CreateBoatMenu(string SSN, BoatBLL boat) { BoatType boatType = CreateBoatTypeMenu(); int length = (int)Menu.ReadInt("Boat length: "); boat.SSN = SSN; boat.BoatType = boatType; boat.BoatLength = length; return boat; }
//**************** public void BoatCreatedMenu(BoatBLL boat, bool succeeded = true) { if (succeeded) { Console.WriteLine("**** You registered a boat ****\n"); ShowBoat(boat); } else { Console.WriteLine("**** Boat could not be registered ****\n"); } Menu.PressKeyToContinue(); }
public void BoatUpdatedMenu(BoatBLL boat, bool succeeded = true) { if (succeeded) { Console.WriteLine("**** You updated a boat ****\n"); ShowBoat(boat); } else { Console.WriteLine("**** Boat update failed ****\n"); Console.WriteLine("Owner SSN: " + boat.SSN + " BoatId: " + boat.BoatId); } Menu.PressKeyToContinue(); }
public void BoatDeletedMenu(BoatBLL boat, bool succeeded = true) { if (succeeded) { Console.WriteLine("**** You deleted a boat ****\n"); Console.WriteLine("For Owner SSN: " + boat.SSN); } else { Console.WriteLine("**** Boat delete failed ****\n"); if (boat.BoatId == 0) { Console.WriteLine("Owner SSN: " + boat.SSN + " doesn't have a boat registered "); } else { Console.WriteLine("Owner SSN: " + boat.SSN + " BoatId: " + boat.BoatId); } } Menu.PressKeyToContinue(); }
// Boat part public BoatBLL GetBoat(BoatBLL boat) { return BoatDAL.GetBoat(boat); }
public void start() { _1DV607_WS2.View.Menu.UserAction menuChoice; do { menuChoice = this.menu.mainMenu(); switch (menuChoice) { case _1DV607_WS2.View.Menu.UserAction.EndSession : { return; } case _1DV607_WS2.View.Menu.UserAction.CreateMember: { MemberBLL member = new MemberBLL(); member = this.menu.CreateMemberMenu(member); SaveMember(member); this.menu.MemberCreatedMenu(member); break; } case _1DV607_WS2.View.Menu.UserAction.UpdateMember: { string SSN = this.menu.GetMemberMenu(); MemberBLL member = new MemberBLL(); member.SSN = SSN; member = GetMember(member); if (member != null) { member = this.menu.UpdateMemberMenu(member); SaveMember(member); member = GetMember(member); this.menu.MemberUpdatedMenu(member); } else { MemberBLL voidMember = new MemberBLL(); voidMember.SSN = SSN; this.menu.MemberUpdatedMenu(voidMember, false); } break; } case _1DV607_WS2.View.Menu.UserAction.ViewMember: { string SSN = this.menu.GetMemberMenu(); MemberBLL member = new MemberBLL(); member.SSN = SSN; member = GetMember(member); if (member != null) { this.menu.ShowMemberMenu(member); } else { MemberBLL voidMember = new MemberBLL(); voidMember.SSN = SSN; this.menu.ShowMemberMenu(voidMember, false); } break; } case _1DV607_WS2.View.Menu.UserAction.DeleteMember: { string SSN = this.menu.GetMemberMenu(); MemberBLL member = new MemberBLL(); member.SSN = SSN; member = GetMember(member); if (member != null) { DeleteMember(SSN); member = GetMember(member); if (member != null) this.menu.MemberDeletedMenu(SSN, false); else this.menu.MemberDeletedMenu(SSN); } else { MemberBLL voidMember = new MemberBLL(); voidMember.SSN = SSN; this.menu.ShowMemberMenu(voidMember, false); } break; } case _1DV607_WS2.View.Menu.UserAction.RegisterBoat: { string SSN = this.menu.GetMemberMenu(); BoatBLL boat = new BoatBLL(); MemberBLL member = new MemberBLL(); member.SSN = SSN; member = GetMember(member); if (member != null) { boat = this.menu.CreateBoatMenu(member.SSN, boat); SaveBoat(boat); this.menu.BoatCreatedMenu(boat); } else { this.menu.BoatCreatedMenu(null, false); } break; } case _1DV607_WS2.View.Menu.UserAction.UpdateBoat: { string SSN = this.menu.GetMemberMenu(); MemberBLL member = new MemberBLL(); member.SSN = SSN; member = GetMember(member); if (member != null) { IEnumerable<BoatBLL> boats; boats = GetBoats(member.SSN); BoatBLL boat = this.menu.SelectBoatMenu(boats); if (boat != null) { boat = this.menu.UpdateBoatMenu(boat); SaveBoat(boat); boat = GetBoat(boat); this.menu.BoatUpdatedMenu(boat); } else { BoatBLL voidBoat = new BoatBLL(); voidBoat.SSN = member.SSN; this.menu.BoatUpdatedMenu(voidBoat, false); } } else { MemberBLL voidMember = new MemberBLL(); voidMember.SSN = SSN; this.menu.ShowMemberMenu(voidMember, false); } break; } case _1DV607_WS2.View.Menu.UserAction.DeleteBoat: { string SSN = this.menu.GetMemberMenu(); MemberBLL member = new MemberBLL(); member.SSN = SSN; member = GetMember(member); if (member != null) { IEnumerable<BoatBLL> boats; BoatBLL boat = null; boats = GetBoats(member.SSN); if (boats.Count() != 0) { boat = this.menu.SelectBoatMenu(boats); } if (boat != null) { BoatBLL tempBoat = boat; DeleteBoat(boat.BoatId); boat = GetBoat(boat); if (boat != null) this.menu.BoatDeletedMenu(boat, false); else this.menu.BoatDeletedMenu(tempBoat); } else { BoatBLL voidBoat = new BoatBLL(); voidBoat.SSN = member.SSN; this.menu.BoatDeletedMenu(voidBoat, false); } } else { MemberBLL voidMember = new MemberBLL(); voidMember.SSN = SSN; this.menu.ShowMemberMenu(voidMember, false); } break; } case _1DV607_WS2.View.Menu.UserAction.ListMembers: { // IEnumerable<MemberBLL> members = GetMembers(); // IEnumerable<BoatBLL> boats = GetAllBoats(); IEnumerable<MemberDetailsBLL> memberDetails = GetMembersDetails(); this.menu.ShowMemberList(memberDetails); break; } case _1DV607_WS2.View.Menu.UserAction.ListMembersVerbose: { IEnumerable<MemberDetailsBLL> memberDetails = GetMembersDetails(); this.menu.ShowMemberListVerbose(memberDetails); break; } default: { Debug.Assert(true, "start(): forgot to extend switch case entries?"); break; }; } } while (true); }
public void SaveBoat(BoatBLL boat) { if (boat == null) { throw new Exception("boat didn't validate correctly"); } BoatBLL oldBoat = new BoatBLL(); oldBoat.BoatId = boat.BoatId; if (GetBoat(oldBoat) != null) { BoatDAL.UpdateBoat(boat); } else { BoatDAL.InsertBoat(boat); } }
public BoatBLL UpdateBoatMenu(BoatBLL boat) { Console.WriteLine("Just press ENTER for fields you don't want to change"); string SSN = Menu.ReadLine("Owner SSN: ", false); int? boatType; bool done = false; do { Console.WriteLine("press 1 for " + TranslateBoatType(BoatType.Sailboat)); Console.WriteLine("press 2 for " + TranslateBoatType(BoatType.Motorsailer)); Console.WriteLine("press 3 for " + TranslateBoatType(BoatType.kayak_Canoe)); Console.WriteLine("press 4 for " + TranslateBoatType(BoatType.Other)); Console.WriteLine("or ENTER to leave it unchanged "); boatType = Menu.ReadInt("Boat Type: ", false); if (boatType > 0 && boatType < 5 || boatType == null) { done = true; } else { Console.WriteLine("You have to select a menualternative <1-4>"); Menu.PressKeyToContinue(); } } while (!done); int? boatLength = Menu.ReadInt("Boat length: ", false); if (SSN != null && SSN != "") boat.SSN = SSN; if (boatType != null) boat.BoatType = (BoatType)boatType; if (boatLength != null) boat.BoatLength = (int)boatLength; return boat; }
public void ShowBoatRow(BoatBLL boat, int index) { Console.WriteLine(" " + index + " - " + "BoatId: " + boat.BoatId + " Owner: " + boat.SSN + " BoatType: " + TranslateBoatType(boat.BoatType) + " Boat length: " + boat.BoatLength); }
public void ShowBoatMenu(BoatBLL boat, bool succeeded = true) { if (succeeded) { Console.WriteLine("**** boat ****\n"); ShowBoat(boat); } else { Console.WriteLine("**** Boat info not found ****\n"); Console.WriteLine("Owner SSN: " + boat.SSN + "Boat Id:" + boat.BoatId); } Menu.PressKeyToContinue(); }
public void ShowBoat(BoatBLL boat) { Console.WriteLine("Boat Id: " + boat.BoatId); Console.WriteLine("Owner: " + boat.SSN); Console.WriteLine("BoatType: " + TranslateBoatType(boat.BoatType)); Console.WriteLine("BoatLength: " + boat.BoatLength); }
public void UpdateBoat(BoatBLL boat) { using (SqlConnection conn = CreateConnection()) { try { SqlCommand cmd = new SqlCommand("appSchema.uspUpdateBoat", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@BoatId", SqlDbType.Int, 4).Value = boat.BoatId; cmd.Parameters.Add("@SSN", SqlDbType.VarChar, 12).Value = boat.SSN; cmd.Parameters.Add("@BoatType", SqlDbType.Int, 4).Value = boat.BoatType; cmd.Parameters.Add("@BoatLength", SqlDbType.Int, 4).Value = boat.BoatLength; conn.Open(); cmd.ExecuteNonQuery(); } catch { throw new ApplicationException("An error occured while updating boat at the database"); } } }
public void InsertBoat(BoatBLL boat) { using (SqlConnection conn = CreateConnection()) { try { SqlCommand cmd = new SqlCommand("appSchema.uspInsertBoat", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@BoatType", SqlDbType.Int, 4).Value = boat.BoatType; cmd.Parameters.Add("@BoatLength", SqlDbType.Int, 4).Value = boat.BoatLength; cmd.Parameters.Add("@SSN", SqlDbType.VarChar, 12).Value = boat.SSN; cmd.Parameters.Add("@BoatId", SqlDbType.Int).Direction = ParameterDirection.Output; conn.Open(); cmd.ExecuteNonQuery(); boat.BoatId = Convert.ToInt32(cmd.Parameters["@BoatId"].Value); } catch { throw new ApplicationException("An error occured while inserting a a boat into the database."); } } }