Пример #1
0
        private async void CreateTransaction(object sender, RoutedEventArgs e)
        {
            Windows.UI.Popups.MessageDialog mD = new Windows.UI.Popups.MessageDialog("Please select an expense type");

            string      command     = String.Empty;
            int         expenseType = -1;
            string      date        = HelperMethods.GetDate();
            Transaction transaction = null;

            if (TypeCB.SelectedIndex.Equals(1)) // User selected type expense
            {
                if (ExpenseTypeCB.SelectedItem != null)
                {
                    expenseType = ExpenseTypeCB.SelectedIndex;
                }
                else
                {
                    await mD.ShowAsync();

                    return;
                }
            }
            double tax = 0;

            switch (TaxCB.SelectedIndex)
            {
            case 0:
                tax = Convert.ToDouble(AmountTB.Text) * 0.1;     // 10%
                break;

            case 1:
                tax = Convert.ToDouble(AmountTB.Text) * 0.13;     // 13%
                break;

            case 2:
                tax = Convert.ToDouble(AmountTB.Text) * 0.20;     // 20%
                break;
            }
            transaction = new Transaction(DescrTB.Text, Convert.ToDouble(AmountTB.Text), date, expenseType, tax);
            string jsonObject = JsonConvert.SerializeObject(transaction);

            SocketMethods.ConnectToServer();
            SocketMethods.SendMessage($"8;{jsonObject}");
            SocketMethods.ReceiveMessage();


            if (SocketMethods.response.Equals(1))
            {
                MessageDialog md = new MessageDialog("Transaction failed");
                await md.ShowAsync();
            }
            SocketMethods.client.Shutdown(System.Net.Sockets.SocketShutdown.Both);
            SocketMethods.Disconnect();
        }
Пример #2
0
        public async Task DeleteAccount()
        {
            if (SelectedAccount == null)
            {
                md.Content = "No account selected";
                await md.ShowAsync();

                return;
            }
            SocketMethods.client = new Socket(SocketMethods.ipAddress.AddressFamily,
                                              SocketType.Stream, ProtocolType.Tcp);
            SocketMethods.ConnectToServer();
            SocketMethods.SendMessage($"6;{SelectedAccount.AccID}");
            SocketMethods.ReceiveMessage();
            SocketMethods.client.Shutdown(System.Net.Sockets.SocketShutdown.Both);
            SocketMethods.Disconnect();
            accounts.Remove(selectedAccount);
        }