Exemplo n.º 1
0
    private void ToggleStatus()
    {
        string errorMsg = string.Empty;
        string jobName = string.Empty;
        BCCJobsHelper sqlJobs = null;
        bool isEnabled = false;
        // Iterate through the Gridview Rows property
        foreach (GridViewRow row in gridSQLJobs.Rows)
        {
            HiddenField connectionString = row.FindControl("jobConnectionString") as HiddenField;
            Label lblIsJobEnabled = row.FindControl("lblIsJobEnabled") as Label;

            sqlJobs = new BCCJobsHelper(connectionString.Value);
            jobName = row.Cells[1].Text;
            isEnabled = ConvertStringToBool(lblIsJobEnabled.Text);

            // Access the CheckBox
            CheckBox cb = (CheckBox)row.FindControl("chkJobID");

            if (cb != null && cb.Checked)
            {
                try
                {
                    if (!isEnabled)
                    {
                        sqlJobs.EnableJob(jobName, true);
                        new ActivityHelper().RaiseAuditEvent(this, lblCaption.Text, "enabled job " + jobName, 302);
                    }
                    else
                    {
                        sqlJobs.EnableJob(jobName, false);
                        new ActivityHelper().RaiseAuditEvent(this, lblCaption.Text, "disabled job " + jobName, 302);
                    }
                }
                catch (Exception ex)
                {
                    DisplayError(ex.Message);
                    System.Diagnostics.Debug.Write(ex.Message + ex.StackTrace, SiteMap.CurrentNode.Description);
                }
            }
        }
    }
Exemplo n.º 2
0
    private void PopulateGrid(string searchKeyword)
    {
        try
        {
            StringCollection jobConnectionStringList = null;
            StringCollection jobsList = null;

            // Check whether the Profile is active and then proceed.
            if (Profile.ControlCenterProfile.IsProfileActive)
            {
                try
                {
                    BCCModuleProperty props = Profile.ControlCenterProfile.ModuleFilter[SiteMap.CurrentNode.Description];

                    if (props != null)
                    {
                        jobConnectionStringList = props.ModuleDictionary[BCCUIHelper.Constants.JOB_CONNECTION_STRING_LIST_KEY];
                        jobsList = props.ModuleDictionary[BCCUIHelper.Constants.JOB_LIST_KEY];
                    }
                }
                catch
                {
                    // Ignore errors from Profile system
                }
            }

            BCCJobsHelper sqlJobs = null;
            DataTable dt = null;

            if (jobConnectionStringList != null)
            {
                // The system should work even if one SQL job connection string goes bad.
                foreach (string jobConnectionString in jobConnectionStringList)
                {
                    DataTable dtTemp = null;
                    try
                    {
                        sqlJobs = new BCCJobsHelper(jobConnectionString);
                        // If SQL Jobs is NULL, an exception is thrown.
                        dtTemp = sqlJobs.EnumerateAllSQLJobs(jobsList);

                        // If the dataTable is empty you must clone the table to get the structure.
                        if (dt == null && dtTemp != null)
                        {
                            dt = dtTemp.Clone();
                        }

                        foreach (DataRow dr in dtTemp.Rows)
                        {
                            dt.ImportRow(dr);
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.Write(ex.Message + ex.StackTrace, SiteMap.CurrentNode.Description);
                        DisplayError(ex.Message);
                    }
                }
            }

            if (dt != null)
            {
                if (searchKeyword != null && searchKeyword.Length > 0)
                {
                    dt.DefaultView.RowFilter = "JobName LIKE '%" + searchKeyword + "%' OR JobExecutionStatus LIKE '%" + searchKeyword + "%' OR JobServer LIKE '%" + searchKeyword + "%'";
                }
            }
            else
            {
                if (searchKeyword != null && searchKeyword.Length > 0)
                {
                    DisplayError("There were no record(s) found, to start a search.");
                }
            }

            gridSQLJobs.DataSource = dt;
            gridSQLJobs.DataBind();
            gridSQLJobs.Visible = true;
            count = gridSQLJobs.Rows.Count;
            UpdateLabel();
        }
        catch (Exception ex)
        {
            DisplayError(ex.Message);
            System.Diagnostics.Debug.Write(ex.Message + ex.StackTrace, SiteMap.CurrentNode.Description);
            gridSQLJobs.Visible = false;
        }
    }