alexandrheathen

Untitled

May 28th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.85 KB | None | 0 0
  1. amountForUser = decimal.Parse(sendingAmount.Text);
  2.             amountForRecipient = amountForUser;
  3.             amountForUser = calculateMoney(amountForUser, percent);
  4.             LoadingForm loading = new LoadingForm();
  5.             loading.ShowDialog();
  6.             this.Visible = false;
  7.             if (userBalance >= amountForUser)
  8.             {
  9.                 this.Visible = true;
  10.                 try
  11.                 {
  12.                     int operationSuccsessful = 0;
  13.                     recipientCard = long.Parse(recipient_textBox.Text);
  14.                     string query = "Select [UserName], [UserSurname], [UserPatronymic], [Balance] from UsersInfo where CardNumber = '" + recipientCard + "'";
  15.                     using (SqlConnection Connection = new SqlConnection(connectionString))
  16.                     {
  17.                         SqlCommand Command = new SqlCommand(query, Connection);
  18.                         SqlDataReader Reader;
  19.                         Connection.Open();
  20.                         Reader = Command.ExecuteReader();
  21.                         while (Reader.Read())
  22.                         {
  23.                             operationSuccsessful++;
  24.                             recipientName = Reader["UserName"].ToString();
  25.                             recipientSurname = Reader["UserSurname"].ToString();
  26.                             recipientPatronymic = Reader["UserPatronymic"].ToString();
  27.                             recipientBalance = Convert.ToDecimal(Reader["Balance"]);
  28.                         }
  29.                     }
  30.                     if (operationSuccsessful == 0 || recipientCard == userCard)
  31.                     {
  32.                         recipient_textBox.Focus();
  33.                         MessageBox.Show("Вы не можете перевести деньги на этот счет.\nПроверьте введенные данные", "Ошибка перевеода", MessageBoxButtons.OK, MessageBoxIcon.Error);
  34.                         return;
  35.                     }
  36.                     else if (operationSuccsessful != 0 && recipientCard != userCard)
  37.                     {
  38.                         userBalance -= amountForUser;
  39.                         recipientBalance += amountForRecipient;
  40.                         this.Opacity = 0.2;
  41.                         ConfirmationForm confirmation = new ConfirmationForm();
  42.                         confirmation.userName = userName;
  43.                         confirmation.userPassword = userPassword;
  44.                         confirmation.amount = amountForUser;
  45.                         confirmation.ShowDialog();
  46.                         bool succsess = confirmation.ok;
  47.                         if (succsess != true)
  48.                         {
  49.                             this.Opacity = 1;
  50.                             try
  51.                             {
  52.                                  using(SqlConnection connection = new SqlConnection(connectionString))
  53.                                 {
  54.                                     string recipQuery = "Update UsersInfo set Balance = '" + recipientBalance + "' where CardNumber = '" + recipientCard + "'";
  55.                                     string userQuery = "Update UsersInfo set Balance = '" + userBalance + "' where Phone = '" + login + "'";
  56.                                     connection.Open();
  57.                                     SqlCommand recipCommand = new SqlCommand(recipQuery, connection);
  58.                                     SqlCommand userCommand = new SqlCommand(userQuery, connection);
  59.                                     recipCommand.ExecuteNonQuery();
  60.                                     userCommand.ExecuteNonQuery();
  61.                                 }
  62.                                 this.Close();
  63.                                 LoadingForm loadingForm = new LoadingForm();
  64.                                 loadingForm.Show();
  65.                                 notifyIconConfirmed.Icon = SystemIcons.Application;
  66.                                 notifyIconConfirmed.Visible = true;
  67.                                 notifyIconConfirmed.ShowBalloonTip(3000, "Перевод средств", $"Сумма в размере {amountForRecipient} были успешно переведены {recipientSurname} {recipientName} {recipientPatronymic}\nВаш поточный баланс: {userBalance}", ToolTipIcon.Info);
  68.                                 mainMenu.login = login;
  69.                                 mainMenu.Show();
  70.                             }
  71.  
  72.                             catch (Exception ex)
  73.                             {
  74.                                 MessageBox.Show(ex.Message);
  75.                                 return;
  76.                             }
  77.                         }
  78.                         else if(confirmation.ok != true)
  79.                         {
  80.                             this.Opacity = 1;
  81.                             MessageBox.Show($"Извините, {userName}, Вы не можете отправить деньги без подтверждения.", "Ошибка перевода", MessageBoxButtons.OK, MessageBoxIcon.Error);
  82.                             sendMoney.Focus();
  83.                             return;
  84.                         }
  85.                         else
  86.                         {
  87.                             this.Opacity = 1;
  88.                         }
  89.                     }
  90.                 }
  91.  
  92.                 catch (FormatException fe)
  93.                 {
  94.                     MessageBox.Show(fe.Message);
  95.                 }
  96.  
  97.             }
  98.             else
  99.             {
  100.                 this.Visible = true;
  101.                 MessageBox.Show($"У вас не достаточно сресдтв для перевода\nВведите сумму меньше или равную {amountForUser}", "Ошибка перевеода", MessageBoxButtons.OK, MessageBoxIcon.Error);
  102.                 return;
  103.             }
Advertisement
Add Comment
Please, Sign In to add comment