示例#1
0
        private async void DashButtonsTable_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.ColumnIndex == DashButtonsTable.Columns["Test"].Index)
            {
                DataGridViewCellCollection rowCells = DashButtonsTable.Rows[e.RowIndex].Cells;
                string buttonDescription            = rowCells["Description"].Value?.ToString();
                string url = rowCells["ActionUrl"].Value?.ToString();
                if (!string.IsNullOrWhiteSpace(url))
                {
                    try
                    {
                        Log($"Testing action for {buttonDescription} button.");
                        await WebActionHelpers.SendGetRequestAsync(url);
                    }
                    catch (Exception ex)
                    {
                        _ = Task.Run(() => Log($"An error has occurred while running the action: '{url}' \n" + ex.Message));
                    }
                }
            }
            else if (DashButtonsTable.ReadOnly)
            {
                DialogResult dialogResult = MessageBox.Show("You need Administrative rights in order to modify values in this table. " +
                                                            "Would you like to restart the program with Administrative rights?",
                                                            "Missing Rights", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (dialogResult == DialogResult.Yes)
                {
                    try
                    {
                        Process.Start(new ProcessStartInfo()
                        {
                            FileName        = Assembly.GetExecutingAssembly().Location,
                            UseShellExecute = true,
                            Verb            = "runas"
                        });
                        Application.Exit();
                    }
                    catch (Win32Exception) { }
                }
            }
        }
 private async void DashButtonsTable_CellContentClick(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex >= 0 && e.ColumnIndex == DashButtonsTable.Columns["Test"].Index)
     {
         DataGridViewCellCollection rowCells = DashButtonsTable.Rows[e.RowIndex].Cells;
         string buttonDescription            = rowCells["Description"].Value?.ToString();
         string url = rowCells["ActionUrl"].Value?.ToString();
         if (!string.IsNullOrWhiteSpace(url))
         {
             try
             {
                 Log($"Testing action for {buttonDescription} button.");
                 await WebActionHelpers.SendGetRequestAsync(url);
             }
             catch (Exception ex)
             {
                 _ = Task.Run(() => Log($"An error has occurred while running the action: '{url}' \n" + ex.Message));
             }
         }
     }
 }