Example #1
0
        private async void ThreadProcesses(object obj)
        {
            if (token2 == "")
            {
                DialogResult d;
                d = System.Windows.Forms.MessageBox.Show("Please login your account ", "Login required", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (d == System.Windows.Forms.DialogResult.Yes)
                {
                    Thread.Sleep(50);
                    FourPage fo = new FourPage();
                    fo.Show();
                    this.Hide();
                }
                if (d == System.Windows.Forms.DialogResult.No)
                {
                    Close();
                    Environment.Exit(0);
                }
            }
            else
            {
                FunctionStep1 step4 = new FunctionStep1();
                list2 = step4.GetMeJoinedTeamTo(token2);
                for (int i = 0; i < list2.Count; i++)
                {
                    await testFuction(token2, list2[i].id, 2);

                    int c = i + 1;
                    SetprogressBar2(c, list2.Count);
                    Thread.Sleep(5);
                }
            }
        }
Example #2
0
        private void btn1_Click_1(object sender, RoutedEventArgs e)
        {
            FourPage fo = new FourPage();

            fo.Show();
            this.Hide();
        }
Example #3
0
        public FivePage()
        {
            InitializeComponent();
            con.Open();
            SqlCommand cmd1 = new SqlCommand("select_atoken", con);

            cmd1.CommandType = CommandType.StoredProcedure;
            using (SqlDataReader reader = cmd1.ExecuteReader())
            {
                if (reader.Read())
                {
                    token1 = reader["access_token"].ToString();
                }
            }
            con.Close();

            if (token1 == "")
            {
                DialogResult d;
                d = System.Windows.Forms.MessageBox.Show("Please login your account ", "Login required", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (d == System.Windows.Forms.DialogResult.Yes)
                {
                    FourPage fo = new FourPage();
                    fo.Show();
                    this.Hide();
                }
                if (d == System.Windows.Forms.DialogResult.No)
                {
                    Close();
                    Environment.Exit(0);
                }
            }
            else
            {
                FunctionStep1 step1 = new FunctionStep1();
                list1 = step1.GetMeJoinedTeam(token1);
            }

            worker                            = new BackgroundWorker();
            worker.DoWork                    += worker_DoWork;
            worker.ProgressChanged           += worker_ProgressChanged;
            worker.RunWorkerCompleted        += worker_RunWorkerCompleted;
            worker.WorkerReportsProgress      = true;
            worker.WorkerSupportsCancellation = false;

            int maxItems = list1.Count;

            pbar.Minimum = 1;
            pbar.Maximum = 100;

            StatusTextBox.Text = "Starting...";
            worker.RunWorkerAsync(maxItems);
        }
Example #4
0
 private void btn1_Click_1(object sender, RoutedEventArgs e)
 {
     try
     {
         con.Open();
         SqlCommand cmd1 = new SqlCommand("delteamcha", con);
         cmd1.CommandType = CommandType.StoredProcedure;
         cmd1.ExecuteNonQuery();
         con.Close();
         FourPage th = new FourPage();
         th.Show();
         this.Hide();
     }
     catch (Exception em)
     {
         System.Windows.Forms.MessageBox.Show(em.Message);
     }
 }
Example #5
0
        private async void btn2_Click(object sender, RoutedEventArgs e)
        {
            AuthenticationResult authResult = null;
            var app = App.PublicClientApp;


            var accounts = await app.GetAccountsAsync();

            var firstAccount = accounts.FirstOrDefault();

            try
            {
                authResult = await app.AcquireTokenSilent(scopes, firstAccount)
                             .ExecuteAsync();
            }
            catch (MsalUiRequiredException ex)
            {
                // A MsalUiRequiredException happened on AcquireTokenSilent.
                // This indicates you need to call AcquireTokenInteractive to acquire a token
                System.Diagnostics.Debug.WriteLine($"MsalUiRequiredException: {ex.Message}");

                try
                {
                    authResult = await app.AcquireTokenInteractive(scopes)
                                 .WithAccount(accounts.FirstOrDefault())
                                 .WithParentActivityOrWindow(new WindowInteropHelper(this).Handle) // optional, used to center the browser on the window
                                 .WithPrompt(Prompt.SelectAccount)
                                 .ExecuteAsync();
                }
                catch (MsalException msalex)
                {
                    System.Windows.Forms.MessageBox.Show($"Error Acquiring Token:{System.Environment.NewLine}{msalex}");
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show($"Error Acquiring Token Silently:{System.Environment.NewLine}{ex}");
                return;
            }

            if (authResult != null)
            {
                string aten = "4dd770a9-6973-4a56-b6a1-89897496fa2d";
                if (authResult.TenantId != aten)
                {
                    System.Windows.Forms.DialogResult dl;
                    dl = System.Windows.Forms.MessageBox.Show("Account don't have permission to do migration, please check account and try again.", "Permission required", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    if (dl == System.Windows.Forms.DialogResult.OK)
                    {
                        var account = await App.PublicClientApp.GetAccountsAsync();

                        if (account.Any())
                        {
                            try
                            {
                                await App.PublicClientApp.RemoveAsync(account.FirstOrDefault());

                                con.Open();
                                SqlCommand cmd1 = new SqlCommand("user_del", con);
                                cmd1.CommandType = CommandType.StoredProcedure;
                                cmd1.ExecuteNonQuery();
                                con.Close();
                                usr_nm.Visibility    = Visibility.Collapsed;
                                unmlab.Visibility    = Visibility.Collapsed;
                                this.btn4.Visibility = Visibility.Collapsed;
                                c_idlab.Visibility   = Visibility.Visible;
                                cl_id.Visibility     = Visibility.Visible;
                                cs_lab.Visibility    = Visibility.Visible;
                                cl_sect.Visibility   = Visibility.Visible;
                                pass_lab.Visibility  = Visibility.Visible;
                                cl_pass.Visibility   = Visibility.Visible;
                            }
                            catch (MsalException ex)
                            {
                                System.Windows.Forms.MessageBox.Show(ex.Message);
                            }
                        }
                    }
                }
                else
                {
                    string ppwd           = cl_pass.Password.ToString();
                    string CLIENT_ID      = cl_id.Text;
                    string CLIENT_SECERET = cl_sect.Text;
                    string sta_cd         = "1";
                    try
                    {
                        con.Open();
                        SqlCommand cmd = new SqlCommand("addUser", con);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@email", authResult.Account.Username);
                        cmd.Parameters.AddWithValue("@p_pwd", ppwd);
                        cmd.Parameters.AddWithValue("@c_id", CLIENT_ID);
                        cmd.Parameters.AddWithValue("@c_cs", CLIENT_SECERET);
                        cmd.Parameters.AddWithValue("@t_id", authResult.TenantId);
                        cmd.Parameters.AddWithValue("@access_token", authResult.AccessToken);
                        cmd.Parameters.AddWithValue("@sta_cd", sta_cd);
                        cmd.ExecuteNonQuery();
                        con.Close();
                        FourPage fg = new FourPage();
                        fg.Show();
                        this.Hide();
                    }
                    catch (Exception ex)
                    {
                        System.Windows.Forms.MessageBox.Show(ex.Message);
                    }
                }
            }
        }