Browse Source

5 mlab

pull/3/head
Your Name 3 years ago
parent
commit
03019b3900
  1. 22
      20230415.3/w230415/CinemaHall.cs
  2. 104
      20230415.3/w230415/Hall.cs
  3. 15
      20230415.3/w230415/HallPlace.cs
  4. 25
      20230415.3/w230415/w230415.sln
  5. 13
      20230415.3/w230415/w230415_classes.csproj
  6. 21
      20230415.3/w230415_console/Program.cs
  7. 14
      20230415.3/w230415_console/w230415_console.csproj

22
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
});
}
}
}
}
}

104
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<HallPlace> HallPlaceList { get; set; } = new List<HallPlace>();
/// <summary>
/// Read [R]
/// </summary>
/// <returns></returns>
public List<HallPlace> GetNotBookedPlaceList()
{
List<HallPlace> hpl = new List<HallPlace>();
foreach (var item in HallPlaceList)
{
if (item.FlagBooked) continue;
hpl.Add(item);
}
return hpl;
}
/// <summary>
/// Read [R]
/// </summary>
/// <param name="iRow"></param>
/// <param name="iPosition"></param>
/// <returns></returns>
public HallPlace? ReadPlace(int iRow, int iPosition)
{
var el = HallPlaceList.FirstOrDefault(hp => hp.SeatPosition == iPosition && hp.SeatRow == iRow);
return el;
}
/// <summary>
/// Update [U]
/// </summary>
/// <param name="iRow"></param>
/// <param name="iPosition"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Create [C]
/// </summary>
/// <param name="iRow"></param>
/// <param name="iPosition"></param>
/// <returns></returns>
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;
}
/// <summary>
/// Delete [D]
/// </summary>
/// <param name="iRow"></param>
/// <param name="iPosition"></param>
/// <returns></returns>
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);
}
}
}

15
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; }
}
}

25
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

13
20230415.3/w230415/w230415_classes.csproj

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Intf\" />
</ItemGroup>
</Project>

21
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}");
}
}
}
}

14
20230415.3/w230415_console/w230415_console.csproj

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\w230415\w230415_classes.csproj" />
</ItemGroup>
</Project>
Loading…
Cancel
Save