Example #1
0
        private void btnSend_Click(object sender, EventArgs e)
        {
            using (SendDialog dialog = new SendDialog())
            {
                if (dialog.ShowDialog() == DialogResult.OK)
                {
                    string fromAddress = dialog.GetFromAddress();
                    string toAddress   = dialog.GetToAddress();
                    string strAmount   = dialog.GetAmount();
                    object AssetID     = dialog.GetAssetID();

                    SendCoinThread scthread = new SendCoinThread();
                    scthread.Amount   = strAmount;
                    scthread.FromAddr = fromAddress;
                    scthread.ToAddr   = toAddress;
                    scthread.Asset    = AssetID;

                    ThreadStart starter = new ThreadStart(scthread.DoWork);
                    starter += () => {
                        // Do what you want in the callback
                        Invoke(new Action(() =>
                        {
                            lbl_status.Text = lbl_status.Text.Substring(0, lbl_status.Text.Length - 12);
                        }));
                    };

                    Invoke(new Action(() =>
                    {
                        lbl_status.Text = lbl_status.Text + ";Sending Tx.";
                    }));

                    Thread thread = new Thread(starter)
                    {
                        IsBackground = true
                    };
                    thread.Start();

                    return;
                }
            }
        }
Example #2
0
        private void btnSend_Click(object sender, RoutedEventArgs e)
        {
            #region Check Fields
            string strCheckRet = CheckFieldFormat();

            if (strCheckRet != "STR_SP_SUCCESS")
            {
                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString(strCheckRet, iLang));
                return;
            }

            if (!isSendCoin)
            {
                StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_SEND_COIN_ERROR_WAITING", iLang));
                return;
            }

            bool ret = false;
            using (Quras_gui_wpf.Dialogs.AlertDialog dlg = new Quras_gui_wpf.Dialogs.AlertDialog(Application.Current.MainWindow, StringTable.GetInstance().GetString("STR_ALERT_DLG_TITLE", iLang), StringTable.GetInstance().GetString("STR_ALERT_SEND_TX", iLang)))
            {
                ret = (bool)dlg.ShowDialog();
            }

            if (ret == false)
            {
                return;
            }
            #endregion

            #region Sending Coin
            SendCoinThread scthread = new SendCoinThread();
            scthread.Amount            = txbAmount.Text;
            scthread.Fee               = txbFeeAmount.Text;
            scthread.FromAddr          = fromAddress;
            scthread.ToAddr            = txbReceiveAddress.Text;
            scthread.TaskChangedEvent += TaskChangedEvent;

            AssetState             state = Blockchain.Default.GetAssetState(AssetsManager.GetInstance().GetAssetID(cmbAssetType.Text));
            Global.AssetDescriptor asset = new Global.AssetDescriptor(state);

            scthread.Asset = asset;

            ThreadStart starter = new ThreadStart(scthread.DoWork);
            starter += () => {
                // Do what you want in the callback
                this.Dispatcher.Invoke(new Action(() =>
                {
                    // Show the status
                    StaticUtils.ShowMessageBox(StaticUtils.GreenBrush, StringTable.GetInstance().GetString("STR_SP_SENDING_SUCCESSFULLY", iLang));

                    SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_FINISHED", iLang));
                    Constant.TaskMessages.Add(taskMessage);
                    TaskChangedEventHandler?.Invoke(sender, taskMessage);
                    isSendCoin = true;
                }));
            };

            this.Dispatcher.Invoke(new Action(() =>
            {
                // show status
                StaticUtils.ShowMessageBox(StaticUtils.BlueBrush, StringTable.GetInstance().GetString("STR_SP_SENDING_TX", iLang));

                SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_START", iLang));
                Constant.TaskMessages.Add(taskMessage);
                TaskChangedEventHandler?.Invoke(sender, taskMessage);
                isSendCoin = false;
            }));

            Thread thread = new Thread(() => SafeExecute(() => starter()))
            {
                IsBackground = true
            };

            try
            {
                thread.Start();
            }
            catch (Exception)
            {
                this.Dispatcher.Invoke(new Action(() =>
                {
                    // show status
                    StaticUtils.ShowMessageBox(StaticUtils.ErrorBrush, StringTable.GetInstance().GetString("STR_SP_SEDDING_FAILED", iLang));

                    SendTaskMessage taskMessage = new SendTaskMessage(fromAddress, txbReceiveAddress.Text, txbAmount.Text, cmbAssetType.Text, DateTime.Now, StringTable.GetInstance().GetString("STR_TASK_MESSAGE_SEND_TX_FAILED", iLang), TaskColor.Red);
                    Constant.TaskMessages.Add(taskMessage);
                    TaskChangedEventHandler?.Invoke(sender, taskMessage);
                    isSendCoin = true;
                }));
            }
            #endregion

            #region Initialize fields
            txbReceiveAddress.Text = "";
            txbAmount.Text         = "";
            #endregion
        }