gr672_pgv 4 vuotta sitten
vanhempi
commit
b9ed057e49

BIN
.vs/Server/v15/.suo


+ 0 - 0
.vs/Server/v15/Server/sqlite3/db.lock


BIN
.vs/Server/v15/Server/sqlite3/storage.ide


BIN
.vs/Server/v15/Server/sqlite3/storage.ide-shm


BIN
.vs/Server/v15/Server/sqlite3/storage.ide-wal


BIN
.vs/Server/v16/.suo


+ 0 - 0
.vs/Server/v16/Server/sqlite3/db.lock


BIN
.vs/Server/v16/Server/sqlite3/storage.ide


BIN
.vs/Server/v16/TestStore/0/000.testlog


BIN
.vs/Server/v16/TestStore/0/testlog.manifest


+ 4 - 4
Server/GasStationModel.edmx

@@ -86,7 +86,7 @@
           <Key>
             <PropertyRef Name="PaymentID" />
           </Key>
-          <Property Name="PaymentID" Type="int" Nullable="false" />
+          <Property Name="PaymentID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
           <Property Name="IDRefueling" Type="int" Nullable="false" />
           <Property Name="PriceRefueling" Type="money" Nullable="false" />
           <Property Name="Status" Type="bit" Nullable="false" />
@@ -115,7 +115,7 @@
           <Key>
             <PropertyRef Name="RefuelingGunID" />
           </Key>
-          <Property Name="RefuelingGunID" Type="int" Nullable="false" />
+          <Property Name="RefuelingGunID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
           <Property Name="IDRefuelingColumn" Type="int" Nullable="false" />
           <Property Name="IDFuelType" Type="int" Nullable="false" />
         </EntityType>
@@ -531,7 +531,7 @@
           <Key>
             <PropertyRef Name="PaymentID" />
           </Key>
-          <Property Name="PaymentID" Type="Int32" Nullable="false" />
+          <Property Name="PaymentID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
           <Property Name="IDRefueling" Type="Int32" Nullable="false" />
           <Property Name="PriceRefueling" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
           <Property Name="Status" Type="Boolean" Nullable="false" />
@@ -568,7 +568,7 @@
           <Key>
             <PropertyRef Name="RefuelingGunID" />
           </Key>
-          <Property Name="RefuelingGunID" Type="Int32" Nullable="false" />
+          <Property Name="RefuelingGunID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
           <Property Name="IDRefuelingColumn" Type="Int32" Nullable="false" />
           <Property Name="IDFuelType" Type="Int32" Nullable="false" />
           <NavigationProperty Name="FuelType" Relationship="gr672_pgvModel.FK_RefuelingGun_FuelType" FromRole="RefuelingGun" ToRole="FuelType" />

+ 2 - 2
Server/GasStationModel.edmx.diagram

@@ -7,8 +7,8 @@
       <Diagram DiagramId="f4e9d5c7c118418dbeec7f2029dd3ae0" Name="Diagram1">
         <EntityTypeShape EntityType="gr672_pgvModel.Car" Width="1.5" PointX="5.25" PointY="10" />
         <EntityTypeShape EntityType="gr672_pgvModel.Card" Width="1.5" PointX="7.5" PointY="14" />
-        <EntityTypeShape EntityType="gr672_pgvModel.CardIssuer" Width="1.5" PointX="5.25" PointY="16" />
-        <EntityTypeShape EntityType="gr672_pgvModel.CardType" Width="1.5" PointX="5.25" PointY="13.625" />
+        <EntityTypeShape EntityType="gr672_pgvModel.CardIssuer" Width="1.5" PointX="5.25" PointY="13.625" />
+        <EntityTypeShape EntityType="gr672_pgvModel.CardType" Width="1.5" PointX="5.25" PointY="16" />
         <EntityTypeShape EntityType="gr672_pgvModel.Client" Width="1.5" PointX="3" PointY="10" />
         <EntityTypeShape EntityType="gr672_pgvModel.DataOfCamera" Width="1.5" PointX="5.25" PointY="3" />
         <EntityTypeShape EntityType="gr672_pgvModel.FuelType" Width="1.5" PointX="0.75" PointY="0.75" />

+ 118 - 18
Server/Program.cs

@@ -14,7 +14,6 @@ namespace Server
        public static gr672_pgvEntities db = new gr672_pgvEntities();
         static void Main(string[] args)
         {
-
            Listen();
            Console.Read();
         }
@@ -41,7 +40,7 @@ namespace Server
                         rootFuelInStations.Add(new RootFuelInStation() { GasStationID = item.IDGasStation, Address = item.GasStation.Address, Price = item.Price });
                     }
                     var Json = JsonConvert.SerializeObject(rootFuelInStations);
-                    byte[] buffer = System.Text.Encoding.UTF8.GetBytes(Json);
+                    byte[] buffer = Encoding.UTF8.GetBytes(Json);
                     response.ContentLength64 = buffer.Length;
                     Stream output = response.OutputStream;
                     output.Write(buffer, 0, buffer.Length);
@@ -156,14 +155,13 @@ namespace Server
                     output.Close();
                     Console.WriteLine("Выполненно");
                 }
-
+                //Получение данных с камеры, поиск машины в БД и при её отсутствии создаём новую запись о машине
                 if (request.RawUrl.Contains("/FindOrAddCar") && request.HttpMethod == "POST")
                 {
                     StreamReader reader = new StreamReader(request.InputStream, Encoding.UTF8);
                     string Json = await reader.ReadToEndAsync();
                     DataOfCamera dataOfCamera = JsonConvert.DeserializeObject<DataOfCamera>(Json);
-                    db.DataOfCamera.Add(dataOfCamera);
-                    Car FindCar = db.Car.FirstOrDefault(x => x.CarNumber == dataOfCamera.CarNumber);
+                   Car FindCar = db.Car.FirstOrDefault(x => x.CarNumber == dataOfCamera.CarNumber);
                     RootDataOfCar rootDataOfCar = new RootDataOfCar();
                     if (FindCar == null)
                     {
@@ -175,26 +173,29 @@ namespace Server
                         {
                             CarID = ResponseCar.CarID,
                             CarNumber = ResponseCar.CarNumber,
-                            VolumeTank = FindCar.VolumeTank,
+                            VolumeTank = ResponseCar.VolumeTank,
                             CardOfCars = null
                         };
                     }
                     else
                     {
-                        List<RootDataOfCard> CardOfCars = FindCar.IDClient is null ? null : new List<RootDataOfCard>();
-                        foreach (var item in FindCar.Client.Card.ToList())
+                        List<RootDataOfCard> CardOfCars = new List<RootDataOfCard>();
+                        if (FindCar.IDClient != null)
                         {
-                            CardOfCars.Add(new RootDataOfCard {
-                                CardID = item.CardID,
-                                CardExpDate = item.CardExpDate,
-                                Balance = item.Balance,
-                                CardHolder = item.Client.LastName + " " + item.Client.Name,
-                                IDCardIssuer = item.IDCardIssuer,
-                                IDCardType = item.IDCardType,
-                                NumberCard = item.NumberCard
-                            });
+                            foreach (var item in FindCar.Client.Card.ToList())
+                            {
+                                CardOfCars.Add(new RootDataOfCard
+                                {
+                                    CardID = item.CardID,
+                                    CardExpDate = item.CardExpDate,
+                                    Balance = item.Balance,
+                                    CardHolder = item.Client.LastName + " " + item.Client.Name,
+                                    IDCardIssuer = item.IDCardIssuer,
+                                    IDCardType = item.IDCardType,
+                                    NumberCard = item.NumberCard
+                                });
+                            }
                         }
-
                         rootDataOfCar = new RootDataOfCar
                         {
                             CarID = FindCar.CarID,
@@ -214,6 +215,105 @@ namespace Server
                     Console.WriteLine(Json);
 
                 }
+                //Получение данных о об оплате заправке автомобиля
+                if (request.RawUrl.Contains("PostDataOfPayment") && request.HttpMethod == "POST")
+                {
+                    StreamReader streamReader = new StreamReader(request.InputStream, Encoding.UTF8);
+                    string Json = await streamReader.ReadToEndAsync();
+                    RootDataOfPayment dataOfPayment = JsonConvert.DeserializeObject<RootDataOfPayment>(Json);
+                    //Запись о заправке
+                    var RefuelingColumn = db.RefuelingColumn.FirstOrDefault(x=> x.IDGasStation == dataOfPayment.RootDataOfRefuling.GasStationID);
+                    var RefuelingGun = db.RefuelingGun.FirstOrDefault(x => x.IDFuelType == dataOfPayment.RootDataOfRefuling.CurrentFuelID && x.IDRefuelingColumn == RefuelingColumn.RefuelingColumnID);
+                    Refueling NewRefuling = new Refueling
+                    {
+                        IDCar = dataOfPayment.RootDataOfRefuling.Car.CarID,
+                        VolumeFuel = dataOfPayment.RootDataOfRefuling.VolumeFuel,
+                        DataOfCamera = dataOfPayment.RootDataOfRefuling.DataOfCamera,
+                        KeySession = dataOfPayment.RootDataOfRefuling.KeySession,
+                        IDRefulingGun = RefuelingGun.RefuelingGunID
+                    };
+                    db.Refueling.Add(NewRefuling);
+                    var FindCard = db.Card.FirstOrDefault(x => x.CardID == dataOfPayment.RootDataOfCard.CardID);
+                    string LastName = dataOfPayment.RootDataOfCard.CardHolder.Split(' ')[0];
+                    string Name = dataOfPayment.RootDataOfCard.CardHolder.Split(' ')[1];
+                    var FindClient = db.Client.FirstOrDefault(x => x.LastName == LastName && x.Name == Name);
+                    //Запись об оплате
+                    Payment NewPayment = new Payment()
+                    {
+                        IDRefueling = NewRefuling.RefuelingID,
+                        PriceRefueling = dataOfPayment.PriceRefueling,
+                        Status = dataOfPayment.Status,
+                        TransactionCode = dataOfPayment.TransactionCode,
+                        //Создание новой карты, если с неё раньше не производилось оплаты
+                        Card = FindCard is null ? new Card
+                        {
+                            NumberCard = dataOfPayment.RootDataOfCard.NumberCard,
+                            CardExpDate = dataOfPayment.RootDataOfCard.CardExpDate,
+                            Balance = dataOfPayment.RootDataOfCard.Balance - dataOfPayment.PriceRefueling,
+                            IDCardType = dataOfPayment.RootDataOfCard.IDCardType,
+                            IDCardIssuer = dataOfPayment.RootDataOfCard.IDCardIssuer,
+                            //Добавление нового клиента, если у него раньше не было карт
+                            Client = FindClient is null ? new Client { LastName = LastName, Name = Name } : FindClient
+                        } : FindCard
+                    };
+                    db.Payment.Add(NewPayment);
+                    //Списание топлива
+                    var CurrentFuelInGasStation = db.FuelTypeOnGasStation
+                        .FirstOrDefault(x => x.IDGasStation == dataOfPayment.RootDataOfRefuling.GasStationID && 
+                        x.IDFuelType == dataOfPayment.RootDataOfRefuling.CurrentFuelID);
+                    CurrentFuelInGasStation.AmountOfFuel = CurrentFuelInGasStation.AmountOfFuel - dataOfPayment.RootDataOfRefuling.VolumeFuel;
+                    //Списание средств с карты
+                    if (FindCard != null)
+                    {
+                        FindCard.Balance = FindCard.Balance - dataOfPayment.PriceRefueling;
+                    }
+                    db.SaveChanges();
+                    FindClient = db.Client.FirstOrDefault(x => x.LastName == LastName && x.Name == Name);
+                    //Запись о владельце автомобиля исходя из данных карты (Если это превая оплата с банковской карты)
+                    var FindCar = db.Car.Find(dataOfPayment.RootDataOfRefuling.Car.CarID);
+                    if (FindCar.IDClient is null)
+                    {
+                        FindCar.IDClient = FindClient.ClientID;
+                    }
+                    
+                    //if (dataOfPayment.RootDataOfCard.IDCardType == 2)
+                    //{
+                    //    var FindSavingCard = db.Card.FirstOrDefault(x => x.IDHolder == FindClient.ClientID && x.IDCardType == 3);
+                    //    if (FindSavingCard == null)
+                    //    {
+                    //        Random random = new Random();
+                    //        string NumberCard = "";
+                    //        for (int i = 0; i < 7; i++)
+                    //        {
+                    //            NumberCard += random.Next(0, 9).ToString();
+                    //        }
+
+
+                    //        Card NewCard = new Card
+                    //        {
+                    //            NumberCard = NumberCard,
+                    //            CardExpDate = null,
+                    //            Balance = 10,
+                    //            IDCardType = 2,
+                    //            IDCardIssuer = null,
+                    //            IDHolder = FindClient.ClientID
+                    //        };
+                    //        db.Card.Add(NewCard);
+                    //    }
+                    //    else
+                    //    {
+                    //        FindSavingCard.Balance = FindSavingCard.Balance + FindCard.Balance * 3 / 100;
+                    //    }
+                    //}
+                    //db.SaveChanges();
+                    HttpListenerResponse response = context.Response;
+                    byte[] buffer = Encoding.UTF8.GetBytes("Оплата прошла успешно");
+                    response.ContentLength64 = buffer.Length;
+                    Stream output = response.OutputStream;
+                    output.Write(buffer, 0, buffer.Length);
+                    output.Close();
+                    Console.WriteLine("Оплата прошла успешно");
+                }
 
             }
 

+ 18 - 0
Server/RootDataOfPayment.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Server
+{
+   public class RootDataOfPayment
+    {
+        public int PaymentID { get; set; }
+        public decimal PriceRefueling { get; set; }
+        public bool Status { get; set; }
+        public string TransactionCode { get; set; }
+        public RootDataOfCard RootDataOfCard { get; set; }
+        public RootDataOfRefuling RootDataOfRefuling { get; set; }
+    }
+}

+ 19 - 0
Server/RootDataOfRefuling.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Server
+{
+    public class RootDataOfRefuling
+    {
+        public int RefuelingID { get; set; }
+        public RootDataOfCar Car { get; set; }
+        public int CurrentFuelID { get; set; }
+        public int GasStationID { get; set; }
+        public int VolumeFuel { get; set; }
+        public DataOfCamera DataOfCamera { get; set; }
+        public string KeySession { get; set; }
+    }
+}

+ 2 - 0
Server/Server.csproj

@@ -115,6 +115,8 @@
     <Compile Include="RootDataOfCar.cs" />
     <Compile Include="RootDataOfCard.cs" />
     <Compile Include="RootDataOfGasStation.cs" />
+    <Compile Include="RootDataOfPayment.cs" />
+    <Compile Include="RootDataOfRefuling.cs" />
     <Compile Include="RootFuelInStation.cs" />
   </ItemGroup>
   <ItemGroup>

BIN
Server/bin/Debug/Server.exe


BIN
Server/bin/Debug/Server.pdb


+ 1 - 1
Server/obj/Debug/Server.csproj.CoreCompileInputs.cache

@@ -1 +1 @@
-5852a6fd78a0306b4829398c7ebe85e94f1f52ec
+c153b29f2bc471e1100ca21d293a443a73f4eefe

BIN
Server/obj/Debug/Server.csprojAssemblyReference.cache


BIN
Server/obj/Debug/Server.exe


BIN
Server/obj/Debug/Server.pdb


BIN
Server/obj/Debug/TempPE/GasStationModel.Designer.cs.dll


BIN
Server/obj/Debug/TempPE/GasStationModel.cs.dll


+ 2 - 2
Server/obj/Debug/edmxResourcesToEmbed/GasStationModel.csdl

@@ -169,7 +169,7 @@
     <Key>
       <PropertyRef Name="PaymentID" />
     </Key>
-    <Property Name="PaymentID" Type="Int32" Nullable="false" />
+    <Property Name="PaymentID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
     <Property Name="IDRefueling" Type="Int32" Nullable="false" />
     <Property Name="PriceRefueling" Type="Decimal" Nullable="false" Precision="19" Scale="4" />
     <Property Name="Status" Type="Boolean" Nullable="false" />
@@ -206,7 +206,7 @@
     <Key>
       <PropertyRef Name="RefuelingGunID" />
     </Key>
-    <Property Name="RefuelingGunID" Type="Int32" Nullable="false" />
+    <Property Name="RefuelingGunID" Type="Int32" Nullable="false" annotation:StoreGeneratedPattern="Identity" />
     <Property Name="IDRefuelingColumn" Type="Int32" Nullable="false" />
     <Property Name="IDFuelType" Type="Int32" Nullable="false" />
     <NavigationProperty Name="FuelType" Relationship="gr672_pgvModel.FK_RefuelingGun_FuelType" FromRole="RefuelingGun" ToRole="FuelType" />

+ 2 - 2
Server/obj/Debug/edmxResourcesToEmbed/GasStationModel.ssdl

@@ -81,7 +81,7 @@
     <Key>
       <PropertyRef Name="PaymentID" />
     </Key>
-    <Property Name="PaymentID" Type="int" Nullable="false" />
+    <Property Name="PaymentID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
     <Property Name="IDRefueling" Type="int" Nullable="false" />
     <Property Name="PriceRefueling" Type="money" Nullable="false" />
     <Property Name="Status" Type="bit" Nullable="false" />
@@ -110,7 +110,7 @@
     <Key>
       <PropertyRef Name="RefuelingGunID" />
     </Key>
-    <Property Name="RefuelingGunID" Type="int" Nullable="false" />
+    <Property Name="RefuelingGunID" Type="int" StoreGeneratedPattern="Identity" Nullable="false" />
     <Property Name="IDRefuelingColumn" Type="int" Nullable="false" />
     <Property Name="IDFuelType" Type="int" Nullable="false" />
   </EntityType>