Beispiel #1
0
        void bw_DoAsyncWork(object sender, DoWorkEventArgs e)
        {
            string method = (string)e.Argument; //Read the method name that was passed as a parameter

            rowcount = 0;
            foreach (DataGridViewRow item in dataGridView1.Rows)
            {
                DataGridViewCheckBoxCell cell = (DataGridViewCheckBoxCell)item.Cells[5];
                if (cell.Value is true)
                {
                    rowcount += 1;
                    string        serverName   = item.Cells[0].Value.ToString();
                    DatabaseLayer objDataLayer = new DatabaseLayer();
                    MethodInfo    methodInfo   = typeof(DatabaseLayer).GetMethod(method);
                    objDataLayer.ServerName = serverName;
                    objDataLayer.ConnString = objDataLayer.CreateConnectionString(serverName);
                    var thisParameter               = Expression.Constant(objDataLayer);
                    ParameterExpression  param      = Expression.Parameter(typeof(string), item.Cells[1].Value.ToString());
                    MethodCallExpression methodCall = Expression.Call(thisParameter, methodInfo, param);

                    //This was tough! You made it! :)
                    Expression.Lambda(methodCall, param).Compile().DynamicInvoke(item.Cells[1].Value.ToString());
                }
            }
            if (rowcount == 0)
            {
                MessageBox.Show("Now rows were selected");
            }
            else
            {
                if (method == "TakeBackup")
                {
                    MessageBox.Show("Backup operation completed\n\nBackup Location: " + ConfigurationManager.AppSettings["BackupLocation"]);
                }
                dataTable1 = Utility.RefreshDataGrid(dataTable1);
            }
        }
        public static DataTable RefreshDataGrid(DataTable dt)
        {
            //loading to a dataview so we can filter and get distinct server values
            DataView  view           = new DataView(dt);
            DataTable distinctValues = view.ToTable(true, "ServerName");

            //Create a new data table to load results from each server connection
            DataTable results = new DataTable();


            foreach (DataRow row in distinctValues.Rows)
            {
                string serverName = row[0].ToString();
                //Get Database Names
                DataRow[] result = dt.Select("[ServerName] = '" + serverName + "'");

                DatabaseLayer objDataLayer = new DatabaseLayer();
                objDataLayer.ServerName = serverName;
                objDataLayer.ConnString = objDataLayer.CreateConnectionString(serverName);

                if (objDataLayer.IsServerConnected(objDataLayer.ConnString) == true)
                {
                    foreach (DatabaseStatus DS in objDataLayer.GetDatabaseStatus(result))
                    {
                        results.Merge(Utility.ObjectToData(DS));
                    }
                }
                else
                {
                    string message = "Could not connect to Instance: " + serverName;
                    MessageBox.Show(message);
                }
            }

            return(results);
        }
Beispiel #3
0
 public void SetConnString(string InstanceName)
 {
     objDataLayer.ConnString = objDataLayer.CreateConnectionString(InstanceName);
 }