Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions SecondLesson/CarRent.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2041
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRent", "CarRent\CarRent.csproj", "{DAE9ABAA-B382-41C0-B0EE-49C67F29B0DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarRentTest", "CarRentTest\CarRentTest.csproj", "{23CE3592-96D4-4DA6-BFAD-9E86216EAC72}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DAE9ABAA-B382-41C0-B0EE-49C67F29B0DB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAE9ABAA-B382-41C0-B0EE-49C67F29B0DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAE9ABAA-B382-41C0-B0EE-49C67F29B0DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DAE9ABAA-B382-41C0-B0EE-49C67F29B0DB}.Release|Any CPU.Build.0 = Release|Any CPU
{23CE3592-96D4-4DA6-BFAD-9E86216EAC72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23CE3592-96D4-4DA6-BFAD-9E86216EAC72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23CE3592-96D4-4DA6-BFAD-9E86216EAC72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23CE3592-96D4-4DA6-BFAD-9E86216EAC72}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5920830F-E254-4561-9061-714535965A46}
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions SecondLesson/CarRent/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
93 changes: 93 additions & 0 deletions SecondLesson/CarRent/AutoPark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRent
{
public class AutoPark
{
private List<Car> _cars = new List<Car>();
private List<User> _users = new List<User>();
private List<Rent> _rents = new List<Rent>();
private User _TO;
public void AddCar(string mark)
{
Car adding = new Car(new Guid(), mark);
_cars.Add(adding);
}

public void AddUser(string name)
{
User adding = new User(new Guid(), name);
_users.Add(adding);
}

public bool RentCar(User user, Car car, DateTime start, DateTime finish)
{
var index1 = _cars.IndexOf(car);
var index2 = _users.IndexOf(user);

if ((index1== -1)||(index2 == -1)) return false;

foreach (var rent in _rents)
{
if ((rent.Tenant == user) && ((!(((start > rent.Start) && (finish > rent.Finish)) || ((start < rent.Start) && (finish < rent.Finish)))))) return false;
}

Rent adding = new Rent(start, finish, user, car);
_rents.Add(adding);

if (car.WantToRest())
{
SendToTO(car);
}

return true;
}

private void SendToTO(Car car)
{
DateTimeOffset last = new DateTimeOffset(0, 0, 0, 0, 0, 0, new TimeSpan(0));
foreach (var rent in _rents)
{
if ((rent.CarMark == car) && (rent.Finish > last)) last = rent.Finish;
}
Rent adding = new Rent(new DateTimeOffset(0, 0, 0, 0, 0, 0, new TimeSpan(0)), last, _TO, car);
_rents.Add(adding);
}

public List<Rent> ShowUserRents(User user)
{
List<Rent> UserRents = new List<Rent>();
foreach (var rent in _rents)
{
if (rent.Tenant == user) UserRents.Add(rent);
}
return UserRents;
}

public List<Car> ShowAviableCars(DateTimeOffset start, DateTimeOffset finish)
{
List<Car> AviableCars = _cars;
foreach (var rent in _rents)
{
if (!(((start > rent.Start) && (finish > rent.Finish)) || ((start < rent.Start) && (finish < rent.Finish))))
AviableCars.Remove(rent.CarMark);
}
return AviableCars;
}

public AutoPark (List<Car> cars, List<User> users, List<Rent> rents)
{
_cars = cars;
_users = users;
_rents = rents;
User TO = new User(new Guid(), "checkup");
_TO = TO;
_users.Add(_TO);
}

}
}
47 changes: 47 additions & 0 deletions SecondLesson/CarRent/Car.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRent
{
public class Car
{
public Guid Id { get; }
public string Model { get; }
public int RentCount { get; private set; }


public bool WantToRest()
{
if (RentCount >= 10)
{
RentCount = 0;
return true;
}
else return false;
}

public void TakeRent()
{
RentCount++;
}

public Car(Guid id, string model)
{
Id = id;
Model = model;
RentCount = 0;
}

public Car(Guid id, string model, int rentCount)
{
Id = id;
Model = model;
RentCount = rentCount;
}


}
}
59 changes: 59 additions & 0 deletions SecondLesson/CarRent/CarRent.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DAE9ABAA-B382-41C0-B0EE-49C67F29B0DB}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>CarRent</RootNamespace>
<AssemblyName>CarRent</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Car.cs" />
<Compile Include="Rent.cs" />
<Compile Include="AutoPark.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="User.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
36 changes: 36 additions & 0 deletions SecondLesson/CarRent/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// Общие сведения об этой сборке предоставляются следующим набором
// набора атрибутов. Измените значения этих атрибутов, чтобы изменить сведения,
// связанные со сборкой.
[assembly: AssemblyTitle("CarRent")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CarRent")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми
// для компонентов COM. Если необходимо обратиться к типу в этой сборке через
// COM, задайте атрибуту ComVisible значение TRUE для этого типа.
[assembly: ComVisible(false)]

// Следующий GUID служит для идентификации библиотеки типов, если этот проект будет видимым для COM
[assembly: Guid("dae9abaa-b382-41c0-b0ee-49c67f29b0db")]

// Сведения о версии сборки состоят из следующих четырех значений:
//
// Основной номер версии
// Дополнительный номер версии
// Номер сборки
// Редакция
//
// Можно задать все значения или принять номер сборки и номер редакции по умолчанию.
// используя "*", как показано ниже:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
63 changes: 63 additions & 0 deletions SecondLesson/CarRent/Rent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRent
{
public class Rent
{
public DateTimeOffset Start { get; }
public DateTimeOffset Finish { get; }
public User Tenant { get; }
public Car CarMark { get; }

public Rent(DateTimeOffset start, DateTimeOffset finish, User tenant, Car carmark)
{
Start = start;
Finish = finish;

if (Start > Finish)
{
DateTimeOffset Buf = Start;
Start = Finish;
Finish = Buf;
}

Tenant = tenant;
CarMark = carmark;
}

public Rent(string start, string finish, User tenant, Car carmark)
{
Start = ChangeToDate(start);
Finish = ChangeToDate(finish);

if (Start > Finish)
{
DateTimeOffset Buf = Start;
Start = Finish;
Finish = Buf;
}

Tenant = tenant;
CarMark = carmark;
}

private DateTimeOffset ChangeToDate(string date)
{
string[] dateStr = date.Split('.');
int[] dateInt = new int[3];

for (int i = 0; i < 3; i++)
{
dateInt[i] = int.Parse(dateStr[i]);
}

DateTimeOffset Changed = new DateTimeOffset(dateInt[2], dateInt[1], dateInt[0], 0, 0, 0, new TimeSpan(0));

return Changed;
}
}
}
20 changes: 20 additions & 0 deletions SecondLesson/CarRent/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CarRent
{
public class User
{
public Guid Id { get; }
public string Name { get; }

public User (Guid id, string name)
{
Name = name;
Id = id;
}
}
}
Binary file added SecondLesson/CarRent/bin/Debug/CarRent.dll
Binary file not shown.
6 changes: 6 additions & 0 deletions SecondLesson/CarRent/bin/Debug/CarRent.dll.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Binary file added SecondLesson/CarRent/bin/Debug/CarRent.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
79c3cf20854c8c78eb410eff414767d93a1adcbb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\obj\Debug\CarRent.csprojAssemblyReference.cache
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\obj\Debug\CarRent.csproj.CoreCompileInputs.cache
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\bin\Debug\CarRent.dll.config
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\bin\Debug\CarRent.dll
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\bin\Debug\CarRent.pdb
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\obj\Debug\CarRent.dll
C:\Users\markp\Desktop\Programming\C#\League\CarRent\CarRent\obj\Debug\CarRent.pdb
Binary file not shown.
Binary file added SecondLesson/CarRent/obj/Debug/CarRent.dll
Binary file not shown.
Binary file added SecondLesson/CarRent/obj/Debug/CarRent.pdb
Binary file not shown.
Binary file not shown.
Loading