private void CreateNewSQLReport_Click(object sender, EventArgs e)
        {
            FormSQLReport form = new FormSQLReport();

            if ((form.ShowDialog() == DialogResult.OK) && (form.SQLString != null))
            {
                ReportsWorkItemController wiController = (ReportsWorkItemController)workItem.Controller;
                wiController.RunSQLReport(form.ReportName, form.SQLString);
                RefreshView();
            }
        }
        private void bnEditSQLReport_Click(object sender, EventArgs e)
        {
            if (cmbSQLReports.SelectedValue == null)
            {
                return;
            }

            FormSQLReport form = new FormSQLReport(Convert.ToInt32(cmbSQLReports.SelectedValue));

            if (form.ShowDialog() == DialogResult.OK)
            {
                ReportsWorkItemController wiController = (ReportsWorkItemController)workItem.Controller;
                wiController.RunSQLReport(form.ReportName, form.SQLString);
            }
        }
        private void bnRunSQLReport_Click(object sender, EventArgs e)
        {
            if (cmbSQLReports.SelectedValue == null)
            {
                return;
            }

            DataTable reportsDataTable = new ReportsDAO().GetReportById(Convert.ToInt32(cmbSQLReports.SelectedValue));
            string    lReportData      = reportsDataTable.Rows[0][2].ToString();
            string    reportName       = ((DataRowView)(cmbSQLReports.SelectedItem)).Row.ItemArray[1].ToString();

            BinaryFormatter bf              = new BinaryFormatter();
            MemoryStream    mem             = new MemoryStream(Convert.FromBase64String(lReportData));
            List <string>   lReportDataList = (List <string>)bf.Deserialize(mem);

            ReportsWorkItemController wiController = (ReportsWorkItemController)workItem.Controller;

            wiController.RunSQLReport(reportName, lReportDataList[0]);
        }
        private void RunApplicationByLocationOption(string reportName)
        {
            //MessageBox.Show("Assets By Location Selected");
            //Hide the tab first
            //Display the asset selection dialog..
            FormAppByLocation AppByLocation = new FormAppByLocation();

            if (AppByLocation.ShowDialog() == DialogResult.OK)
            {
                //run the query based on for the recordset..

                string strQuery = "SELECT APP._PUBLISHER, APP._NAME + ' (' + APP._VERSION + ')' AS [Application & Version], A._NAME AS Asset, L._NAME AS Location " +
                                  "FROM APPLICATIONS APP " +
                                  "INNER JOIN APPLICATION_INSTANCES APPI ON (APP._APPLICATIONID = APPI._APPLICATIONID) " +
                                  "INNER JOIN ASSETS A ON (A._ASSETID = APPI._ASSETID) " +
                                  "INNER JOIN LOCATIONS L ON (A._LOCATIONID = L._LOCATIONID) " +
                                  "WHERE APP._IGNORED = 0 ";

                string strSelectedApplicationSQL = "";
                string strSelectedLocationSQL    = "";

                if (AppByLocation.LastSavedSelectionItem.ApplicationItemList.Count > 0)
                {
                    strSelectedApplicationSQL = "AND (";

                    for (int i = 0; i < AppByLocation.LastSavedSelectionItem.ApplicationItemList.Count - 1; i++)
                    {
                        strSelectedApplicationSQL += "APP._NAME ='";
                        strSelectedApplicationSQL += AppByLocation.LastSavedSelectionItem.ApplicationItemList[i].ApplicationName;
                        strSelectedApplicationSQL += "' OR ";
                    }
                    strSelectedApplicationSQL += "APP._NAME =";
                    strSelectedApplicationSQL += AuditWizardDataAccess.PrepareSqlString(AppByLocation.LastSavedSelectionItem.ApplicationItemList[AppByLocation.LastSavedSelectionItem.ApplicationItemList.Count - 1].ApplicationName);
                    //strSelectedApplicationSQL += "";
                    strSelectedApplicationSQL += " )";

                    strQuery += strSelectedApplicationSQL;
                }
                if (AppByLocation.LastSavedSelectionItem.LocationNames.Count > 0)
                {
                    strSelectedLocationSQL = "AND (";

                    for (int i = 0; i < AppByLocation.LastSavedSelectionItem.LocationNames.Count - 1; i++)
                    {
                        strSelectedLocationSQL += "L._NAME ='";
                        strSelectedLocationSQL += AppByLocation.LastSavedSelectionItem.LocationNames[i];
                        strSelectedLocationSQL += "' OR ";
                    }
                    strSelectedLocationSQL += "L._NAME ='";
                    strSelectedLocationSQL += AppByLocation.LastSavedSelectionItem.LocationNames[AppByLocation.LastSavedSelectionItem.LocationNames.Count - 1];
                    strSelectedLocationSQL += "'";
                    strSelectedLocationSQL += " )";

                    strQuery += strSelectedLocationSQL;
                }
                strQuery += "ORDER BY L._NAME";

                ReportsWorkItemController wiController = (ReportsWorkItemController)workItem.Controller;
                wiController.RunSQLReport(reportName, strQuery);

                //Filter the recodset based on the dialog settings
                if (AppByLocation.SaveAsUserDefinedReport)
                {
                    List <string> _filterConditions = new List <string>();
                    _filterConditions.Add(strQuery);

                    BinaryFormatter bf  = new BinaryFormatter();
                    MemoryStream    mem = new MemoryStream();
                    bf.Serialize(mem, _filterConditions);
                    string lReportData = Convert.ToBase64String(mem.ToArray());
                    new ReportsDAO().Insert(AppByLocation.UserDefinedReportName, ReportsDAO.ReportType.SqlReport, lReportData);

                    RefreshView();
                    AppByLocation.SaveAllSQLProfilesFromTheList();
                }
                AppByLocation.SaveItemSelection();

                //Fill the Report grid
                //Show the grid to the user
            }
            else
            {
            }
        }