|
@@ -25,7 +25,6 @@ namespace FillingColumn
|
|
|
/// </summary>
|
|
|
public partial class RefuelingPage : Page
|
|
|
{
|
|
|
-
|
|
|
public RefuelingPage()
|
|
|
{
|
|
|
InitializeComponent();
|
|
@@ -47,7 +46,8 @@ namespace FillingColumn
|
|
|
HttpClient client = new HttpClient();
|
|
|
var response = await client.GetAsync("http://127.0.0.1:7070/getDataFromCamera/");
|
|
|
var Body = await response.Content.ReadAsStringAsync();
|
|
|
- DataFromCamera dataFromCamera = JsonConvert.DeserializeObject<DataFromCamera>(Body);
|
|
|
+ DataOfCamera dataFromCamera = JsonConvert.DeserializeObject<DataOfCamera>(Body);
|
|
|
+ Helper.DataFromCamera = dataFromCamera;
|
|
|
TxtDataOfCamera.Text = "Гос. номер распознан: " + dataFromCamera.CarNumber;
|
|
|
FindCar(Body);
|
|
|
}
|
|
@@ -57,7 +57,7 @@ namespace FillingColumn
|
|
|
Helper.FindCar = null;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public async void FindCar(string JsonDataOfCamera)
|
|
|
{
|
|
|
string IDGasStation = Helper.CurrentGasStation.GasStationID.ToString();
|
|
@@ -92,29 +92,32 @@ namespace FillingColumn
|
|
|
socket.Close();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ //Задание ограничений по типам запрвки
|
|
|
public void AddTypeOFRefueling()
|
|
|
{
|
|
|
|
|
|
List<string> TypeOfRefueling = new List<string>();
|
|
|
TypeOfRefueling.Add("Фиксированный объем");
|
|
|
TypeOfRefueling.Add("Фиксированная цена");
|
|
|
+ TypeOfRefueling.Add("До полного бака с ограничением по объему");
|
|
|
List<string> TypeOfPayment = new List<string>();
|
|
|
TypeOfPayment.Add("Банковской картой");
|
|
|
|
|
|
if (Helper.FindCar != null)
|
|
|
{
|
|
|
- if (Helper.FindCar.VolumeTank != null)
|
|
|
- {
|
|
|
- TypeOfRefueling.Add("До полного бака с ограничением по объему");
|
|
|
- }
|
|
|
- if (Helper.FindCar.CardOfCars.FirstOrDefault(x=>x.IDCardType == 3) != null)
|
|
|
+ if (Helper.FindCar.CardOfCars != null)
|
|
|
{
|
|
|
- TypeOfPayment.Add("Накопительной картой");
|
|
|
- }
|
|
|
- if (Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 2) != null)
|
|
|
- {
|
|
|
- TypeOfPayment.Add("Кредитной картой");
|
|
|
+ if (Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 3) != null)
|
|
|
+ {
|
|
|
+ TypeOfPayment.Add("Накопительной картой");
|
|
|
+ }
|
|
|
+ if (Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 1) != null)
|
|
|
+ {
|
|
|
+ TypeOfPayment.Add("Кредитной картой");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
CmbTypeOfPayment.ItemsSource = TypeOfPayment;
|
|
|
CmbTypeOfRefueling.ItemsSource = TypeOfRefueling;
|
|
@@ -130,10 +133,228 @@ namespace FillingColumn
|
|
|
|
|
|
private void BtnPayment_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
+ if (TbAmount.Text == string.Empty && CmbTypeOfRefueling.SelectedIndex == 0)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Не указан объём топлива", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TbCost.Text == string.Empty && CmbTypeOfRefueling.SelectedIndex == 1)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Не указана стоимость для заправки", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TxtErroreMessage.Visibility == Visibility.Visible)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Не корректные данные", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ decimal cost = string.IsNullOrEmpty(TbCost.Text) ? Convert.ToDecimal(TxtCost.Text.Split(' ')[0]) : Convert.ToDecimal(TbCost.Text);
|
|
|
+ int amount = string.IsNullOrEmpty(TbAmount.Text) ? Convert.ToInt32(TxtAmount.Text.Split(' ')[0]) : Convert.ToInt32(TbAmount.Text);
|
|
|
+ int FuelID = (CmbTypeOfFuel.SelectedItem as FuelInCurrentGasStation).IDFuelType;
|
|
|
+ switch (CmbTypeOfPayment.SelectedValue.ToString())
|
|
|
+ {
|
|
|
+ case "Банковской картой":
|
|
|
+ PaymentBankCard(cost, amount, FuelID); break;
|
|
|
+ case "Накопительной картой":
|
|
|
+ PaymentSavingCard(cost, amount, FuelID); break;
|
|
|
+ case "Кредитной картой":
|
|
|
+ PaymentCreditCard(cost,amount, FuelID); break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //Оплат банковской картой
|
|
|
+ public async void PaymentBankCard(decimal cost, int amount, int FuelID)
|
|
|
+ {
|
|
|
+ Helper.EnterPIN = string.Empty;
|
|
|
+ if (Helper.EnterBankCard == null && Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 2) == null)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Введите информацию о карте", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var CurrentFuel = Helper.CurrentGasStation.FuelInCurrentGasStation.FirstOrDefault(x => x.IDFuelType == FuelID);
|
|
|
+ if (CurrentFuel.AmountOfFuel < amount)
|
|
|
+ {
|
|
|
+ MessageBox.Show($"Не достаточно топлива в хранилище! Доступно {CurrentFuel.AmountOfFuel} л.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var BankCard = Helper.EnterBankCard is null ? Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 2) : Helper.EnterBankCard;
|
|
|
+ EnterPINWindow enterPINWindow = new EnterPINWindow();
|
|
|
+ enterPINWindow.ShowDialog();
|
|
|
+ if (Helper.EnterPIN == string.Empty)
|
|
|
+ {
|
|
|
+ MessageBox.Show("Введите ПИН", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ DataOfPayment dataOfPayment = new DataOfPayment()
|
|
|
+ {
|
|
|
+ PriceRefueling = cost,
|
|
|
+ NumberCard = BankCard.NumberCard,
|
|
|
+ CardExpDate = BankCard.CardExpDate,
|
|
|
+ Balance = BankCard.Balance,
|
|
|
+ CardHolder = BankCard.CardHolder,
|
|
|
+ KeySession = Helper.KeySession,
|
|
|
+ PIN = Helper.EnterPIN
|
|
|
+ };
|
|
|
+ HttpClient BankClient = new HttpClient();
|
|
|
+ string Json = JsonConvert.SerializeObject(dataOfPayment);
|
|
|
+ StringContent content = new StringContent(Json, Encoding.UTF8);
|
|
|
+ var response = await BankClient.PostAsync($"http://127.0.0.1:8081/pay", content);
|
|
|
+ var ResponseMessage = await response.Content.ReadAsStringAsync();
|
|
|
+ MessageBox.Show($"{ResponseMessage}", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
|
|
|
+ if (ResponseMessage.Contains("Отклонено")) return;
|
|
|
+ RootDataOfRefuling rootDataOfRefuling = new RootDataOfRefuling
|
|
|
+ {
|
|
|
+ Car = Helper.FindCar,
|
|
|
+ KeySession = Helper.KeySession,
|
|
|
+ DataOfCamera = Helper.DataFromCamera,
|
|
|
+ VolumeFuel = amount,
|
|
|
+ CurrentFuelID = CurrentFuel.IDFuelType,
|
|
|
+ GasStationID = Helper.CurrentGasStation.GasStationID
|
|
|
+ };
|
|
|
|
|
|
+ RootDataOfPayment rootDataOfPayment = new RootDataOfPayment()
|
|
|
+ {
|
|
|
+ RootDataOfCard = BankCard,
|
|
|
+ PriceRefueling = cost,
|
|
|
+ Status = true,
|
|
|
+ TransactionCode = DateTime.Now.ToString("ddMMyyyy-hhmmss"),
|
|
|
+ RootDataOfRefuling = rootDataOfRefuling
|
|
|
+ };
|
|
|
+ PostDataOfPayment(JsonConvert.SerializeObject(rootDataOfPayment));
|
|
|
}
|
|
|
|
|
|
+ //Оплата накопительной картой
|
|
|
+ public void PaymentSavingCard(decimal cost, int amount, int FuelID)
|
|
|
+ {
|
|
|
+ var CurrentFuel = Helper.CurrentGasStation.FuelInCurrentGasStation.FirstOrDefault(x => x.IDFuelType == FuelID);
|
|
|
+ if( CurrentFuel.AmountOfFuel < amount)
|
|
|
+ {
|
|
|
+ MessageBox.Show($"Не достаточно топлива в хранилище! Доступно {CurrentFuel.AmountOfFuel} л.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var SavingCard = Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 3);
|
|
|
+ if (SavingCard.Balance < cost)
|
|
|
+ {
|
|
|
+ double Amount = Convert.ToDouble(SavingCard.Balance) / CurrentFuel.Price;
|
|
|
+ double AvailableAmountFuel = Math.Truncate(Amount) * CurrentFuel.Price;
|
|
|
+ bool CreditCardIsEnable = Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 3) is null ? false : true;
|
|
|
+ decimal MissingAmount = cost - SavingCard.Balance;
|
|
|
+ if (Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 3).Balance < MissingAmount)
|
|
|
+ {
|
|
|
+ CreditCardIsEnable = false;
|
|
|
+ }
|
|
|
+ NoMoneyWindow noMoneyWindow = new NoMoneyWindow(MissingAmount, CreditCardIsEnable, Convert.ToInt32(Math.Truncate(Amount)));
|
|
|
+ noMoneyWindow.ShowDialog();
|
|
|
+ if (Helper.TypeOfNoMoney == 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ switch (Helper.TypeOfNoMoney)
|
|
|
+ {
|
|
|
+ //Оплата кредитной картой
|
|
|
+ case 1:
|
|
|
+ PaymentBankCard(cost, amount, FuelID);
|
|
|
+ break;
|
|
|
+ //Оплата на все накопленные бонусы
|
|
|
+ case 2: amount = Convert.ToInt32(Math.Truncate(Amount));
|
|
|
+ cost = (decimal)AvailableAmountFuel;
|
|
|
+ break;
|
|
|
+ //Оплата кредитной и накопительной картой
|
|
|
+ case 3: PaymentCreditCard(cost - (decimal)AvailableAmountFuel, amount - Convert.ToInt32(Math.Truncate(Amount)), FuelID);
|
|
|
+ amount = Convert.ToInt32(Math.Truncate(Amount));
|
|
|
+ cost = (decimal)AvailableAmountFuel;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ RootDataOfRefuling rootDataOfRefuling = new RootDataOfRefuling
|
|
|
+ {
|
|
|
+ Car = Helper.FindCar,
|
|
|
+ KeySession = Helper.KeySession,
|
|
|
+ DataOfCamera = Helper.DataFromCamera,
|
|
|
+ VolumeFuel = amount,
|
|
|
+ CurrentFuelID = CurrentFuel.IDFuelType,
|
|
|
+ GasStationID = Helper.CurrentGasStation.GasStationID
|
|
|
+ };
|
|
|
+
|
|
|
+ RootDataOfPayment rootDataOfPayment = new RootDataOfPayment()
|
|
|
+ {
|
|
|
+ RootDataOfCard = SavingCard,
|
|
|
+ PriceRefueling = cost,
|
|
|
+ Status = true,
|
|
|
+ TransactionCode = DateTime.Now.ToString("ddMMyyyy-hhmmss"),
|
|
|
+ RootDataOfRefuling = rootDataOfRefuling
|
|
|
+ };
|
|
|
+ PostDataOfPayment(JsonConvert.SerializeObject(rootDataOfPayment));
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //Оплата кредитной картой заправки
|
|
|
+ public void PaymentCreditCard(decimal cost, int amount, int FuelID)
|
|
|
+ {
|
|
|
+ var CurrentFuel = Helper.CurrentGasStation.FuelInCurrentGasStation.FirstOrDefault(x => x.IDFuelType == FuelID);
|
|
|
+ if (CurrentFuel.AmountOfFuel < amount)
|
|
|
+ {
|
|
|
+ MessageBox.Show($"Не достаточно топлива в хранилище! Доступно {CurrentFuel.AmountOfFuel} л.", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ var CreditCard = Helper.FindCar.CardOfCars.FirstOrDefault(x => x.IDCardType == 2);
|
|
|
+ if (CreditCard.Balance < cost)
|
|
|
+ {
|
|
|
+ MessageBox.Show($"Не достаточно средств на карте", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ RootDataOfRefuling rootDataOfRefuling = new RootDataOfRefuling
|
|
|
+ {
|
|
|
+ Car = Helper.FindCar,
|
|
|
+ KeySession = Helper.KeySession,
|
|
|
+ DataOfCamera = Helper.DataFromCamera,
|
|
|
+ VolumeFuel = amount,
|
|
|
+ CurrentFuelID= CurrentFuel.IDFuelType,
|
|
|
+ GasStationID = Helper.CurrentGasStation.GasStationID
|
|
|
+ };
|
|
|
+
|
|
|
+ RootDataOfPayment rootDataOfPayment = new RootDataOfPayment()
|
|
|
+ {
|
|
|
+ RootDataOfCard = CreditCard,
|
|
|
+ PriceRefueling = cost,
|
|
|
+ Status = true,
|
|
|
+ TransactionCode = DateTime.Now.ToString("ddMMyyyy-hhmmss"),
|
|
|
+ RootDataOfRefuling = rootDataOfRefuling
|
|
|
+ };
|
|
|
+ PostDataOfPayment(JsonConvert.SerializeObject(rootDataOfPayment));
|
|
|
+ }
|
|
|
|
|
|
+ //Отправка данных об покупке топлива
|
|
|
+ public async void PostDataOfPayment(string JsonDataOfPayment)
|
|
|
+ {
|
|
|
+ string IDGasStation = Helper.CurrentGasStation.GasStationID.ToString();
|
|
|
+ if (IDGasStation.Length == 1)
|
|
|
+ {
|
|
|
+ IDGasStation = IDGasStation.Insert(0, "0");
|
|
|
+ }
|
|
|
+ string port = "102" + IDGasStation;
|
|
|
+ IPEndPoint IpPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), Convert.ToInt32(port));
|
|
|
+ Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
|
|
+ socket.Connect(IpPoint);
|
|
|
+ string request = "POST data of payment=" + JsonDataOfPayment;
|
|
|
+ byte[] data = Encoding.UTF8.GetBytes(request);
|
|
|
+ socket.Send(data);
|
|
|
+ data = new byte[256]; // буфер для ответа
|
|
|
+ StringBuilder builder = new StringBuilder();
|
|
|
+ int bytes = 0; // количество полученных байт
|
|
|
+ do
|
|
|
+ {
|
|
|
+ bytes = socket.Receive(data, data.Length, 0);
|
|
|
+ builder.Append(Encoding.UTF8.GetString(data, 0, bytes));
|
|
|
+ }
|
|
|
+ while (socket.Available > 0);
|
|
|
+
|
|
|
+ MessageBox.Show(builder.ToString());
|
|
|
+ socket.Shutdown(SocketShutdown.Both);
|
|
|
+ socket.Close();
|
|
|
+ }
|
|
|
+
|
|
|
private void CmbTypeOfRefueling_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
{
|
|
|
if (CmbTypeOfRefueling.SelectedIndex == 0)
|
|
@@ -151,6 +372,14 @@ namespace FillingColumn
|
|
|
TbCost.Visibility = Visibility.Visible;
|
|
|
TxtCost.Visibility = Visibility.Hidden;
|
|
|
}
|
|
|
+ if (CmbTypeOfRefueling.SelectedIndex == 3)
|
|
|
+ {
|
|
|
+ TbAmount.Visibility = Visibility.Visible;
|
|
|
+ TxtAmount.Visibility = Visibility.Hidden;
|
|
|
+ TbCost.Visibility = Visibility.Hidden;
|
|
|
+ TxtCost.Visibility = Visibility.Visible;
|
|
|
+ TbAmount.Text = Helper.FindCar.VolumeTank.ToString();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void TbAmount_TextChanged(object sender, TextChangedEventArgs e)
|
|
@@ -184,12 +413,14 @@ namespace FillingColumn
|
|
|
TxtAmount.Text = string.Empty;
|
|
|
return;
|
|
|
}
|
|
|
- if (TbCost.Text.All(char.IsDigit) == true)
|
|
|
+ if (TbCost.Text.Any(char.IsLetter) == false)
|
|
|
{
|
|
|
TxtErroreMessage.Visibility = Visibility.Hidden;
|
|
|
var CurrentFuel = CmbTypeOfFuel.SelectedItem as FuelInCurrentGasStation;
|
|
|
double Amount = Convert.ToDouble(TbCost.Text) / CurrentFuel.Price;
|
|
|
- TxtAmount.Text = Amount.ToString("F2") + " л.";
|
|
|
+ double CorrectCost = Math.Truncate(Amount) * CurrentFuel.Price;
|
|
|
+ TbCost.Text = CorrectCost.ToString("F2");
|
|
|
+ TxtAmount.Text = Convert.ToInt32(Math.Truncate(Amount)).ToString() + " л.";
|
|
|
}
|
|
|
else
|
|
|
{
|