From 03019b3900cba63f247dce18c2aa075b74ede0e1 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sat, 15 Apr 2023 13:17:27 +0700 Subject: [PATCH] 5 mlab --- 20230415.3/w230415/CinemaHall.cs | 22 ++++ 20230415.3/w230415/Hall.cs | 104 ++++++++++++++++++ 20230415.3/w230415/HallPlace.cs | 15 +++ 20230415.3/w230415/w230415.sln | 25 +++++ 20230415.3/w230415/w230415_classes.csproj | 13 +++ 20230415.3/w230415_console/Program.cs | 21 ++++ .../w230415_console/w230415_console.csproj | 14 +++ 7 files changed, 214 insertions(+) create mode 100644 20230415.3/w230415/CinemaHall.cs create mode 100644 20230415.3/w230415/Hall.cs create mode 100644 20230415.3/w230415/HallPlace.cs create mode 100644 20230415.3/w230415/w230415.sln create mode 100644 20230415.3/w230415/w230415_classes.csproj create mode 100644 20230415.3/w230415_console/Program.cs create mode 100644 20230415.3/w230415_console/w230415_console.csproj diff --git a/20230415.3/w230415/CinemaHall.cs b/20230415.3/w230415/CinemaHall.cs new file mode 100644 index 0000000..065f042 --- /dev/null +++ b/20230415.3/w230415/CinemaHall.cs @@ -0,0 +1,22 @@ +namespace w230415_classes +{ + public class CinemaHall : Hall + { + public CinemaHall() + { + int iW = 10; + int iH = 3; + for (int iX = 0; iX < iW; iX++) + { + for (int iY = 0; iY < iH; iY++) + { + HallPlaceList.Add(new HallPlace() + { + SeatPosition = iX, + SeatRow = iY + }); + } + } + } + } +} diff --git a/20230415.3/w230415/Hall.cs b/20230415.3/w230415/Hall.cs new file mode 100644 index 0000000..a36051f --- /dev/null +++ b/20230415.3/w230415/Hall.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace w230415_classes +{ + public class Hall + { + public string Name { get; set; } + + protected List HallPlaceList { get; set; } = new List(); + + + /// + /// Read [R] + /// + /// + public List GetNotBookedPlaceList() + { + List hpl = new List(); + foreach (var item in HallPlaceList) + { + if (item.FlagBooked) continue; + hpl.Add(item); + } + return hpl; + } + + /// + /// Read [R] + /// + /// + /// + /// + public HallPlace? ReadPlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + return el; + } + + + + /// + /// Update [U] + /// + /// + /// + /// + public bool BookPlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + if (el == null) + { + return false; + } + if (el.FlagBooked) + { + return false; + } + el.FlagBooked = true; + return true; + } + + /// + /// Create [C] + /// + /// + /// + /// + public bool AddPlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + if (el != null) + { + return false; + } + HallPlaceList.Add(new HallPlace() + { + SeatPosition = iPosition, + SeatRow = iRow, + }); + return true; + } + + /// + /// Delete [D] + /// + /// + /// + /// + public bool DeletePlace(int iRow, int iPosition) + { + var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow); + if (el == null) + { + return false; + } + return HallPlaceList.Remove(el); + } + + } +} diff --git a/20230415.3/w230415/HallPlace.cs b/20230415.3/w230415/HallPlace.cs new file mode 100644 index 0000000..1005181 --- /dev/null +++ b/20230415.3/w230415/HallPlace.cs @@ -0,0 +1,15 @@ +namespace w230415_classes +{ + public class HallPlace + { + public HallPlace() + { + Uid = Guid.NewGuid().ToString("N"); + } + + public string Uid { get; set; } + public int SeatPosition { get; set; } + public int SeatRow { get; set; } + public bool FlagBooked { get; set; } + } +} \ No newline at end of file diff --git a/20230415.3/w230415/w230415.sln b/20230415.3/w230415/w230415.sln new file mode 100644 index 0000000..3810909 --- /dev/null +++ b/20230415.3/w230415/w230415.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32616.157 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "w230415_classes", "w230415_classes.csproj", "{3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B2A3797-78B5-42F6-9C7E-5F9F20838C3F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {819D4FAE-A124-443D-B564-39D533244A18} + EndGlobalSection +EndGlobal diff --git a/20230415.3/w230415/w230415_classes.csproj b/20230415.3/w230415/w230415_classes.csproj new file mode 100644 index 0000000..30d4703 --- /dev/null +++ b/20230415.3/w230415/w230415_classes.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/20230415.3/w230415_console/Program.cs b/20230415.3/w230415_console/Program.cs new file mode 100644 index 0000000..ae28b44 --- /dev/null +++ b/20230415.3/w230415_console/Program.cs @@ -0,0 +1,21 @@ +using w230415_classes; + +namespace w230415_console +{ + internal class Program + { + static void Main(string[] args) + { + CinemaHall ch = new CinemaHall(); + h_Process(ch); + } + + private static void h_Process(CinemaHall ch) + { + foreach (var item in ch.GetNotBookedPlaceList()) + { + Console.WriteLine($"{item.SeatRow}/{item.SeatPosition}: {item.Uid}"); + } + } + } +} \ No newline at end of file diff --git a/20230415.3/w230415_console/w230415_console.csproj b/20230415.3/w230415_console/w230415_console.csproj new file mode 100644 index 0000000..cea817f --- /dev/null +++ b/20230415.3/w230415_console/w230415_console.csproj @@ -0,0 +1,14 @@ + + + + Exe + net6.0 + enable + enable + + + + + + +