示例#1
0
        public static void RunVerify(string domainCode, string yearTermCode, TableLayoutPanel tablePanel, ProgressBar progressBar)
        {
            // Prep report factory for correct student totals.
            ReportFactory factory = new ReportFactory();
            factory.GetTotalStudentCount(yearTermCode, ref _sqlConn);

            // Delete current contents.
            tablePanel.Invoke(new MethodInvoker(delegate
            {
                tablePanel.Controls.Clear();
                tablePanel.RowStyles.Clear();
            }));

            // Grab reports listing.
            string sqlCmdStr = "SELECT * FROM [" + WorkingDB + "].[barobba].[" +
                ReportTable + "] WHERE [Domain] = '" + domainCode + "';";
            SqlCommand sqlCmd = new SqlCommand(sqlCmdStr);
            sqlCmd.Connection = _sqlConn;

            List<Dictionary<string, string>> reportItems = new List<Dictionary<string,string>>();

            SqlDataReader reader = sqlCmd.ExecuteReader();
            while (reader.Read())
            {
                Dictionary<string, string> report = new Dictionary<string, string>(6);

                if (report != null)
                {
                    report.Add("Type", reader["Type"].ToString());
                    report.Add("Command", reader["Command"].ToString());
                    report.Add("Title", reader["Title"].ToString());
                    report.Add("Library", reader["Library"].ToString());
                    report.Add("Item", reader["Item"].ToString());
                    report.Add("Other", reader["Other"].ToString());

                    reportItems.Add(report);
                }
                else
                {
                    MessageBox.Show("Failure executing query for " + domainCode + " item " + reader["Item"].ToString() + ". Please contact technical support.", "Failure Running Report", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }

            reader.Close();

            progressBar.Invoke(new MethodInvoker(delegate { progressBar.Value = 10; }));

            int row = 0;
            if (reportItems.Count > 0)
            {
                foreach (Dictionary<string, string> report in reportItems)
                {
                    ITableLayoutRowItem rowItem = factory.NewReport(yearTermCode, report, ref _sqlConn);

                    tablePanel.Invoke(new MethodInvoker(delegate
                    {
                        tablePanel.RowStyles.Add(new RowStyle(SizeType.Absolute, TableLayoutRowHeight));
                        tablePanel.Controls.Add(rowItem.ControlAt(0), 0, row);
                        tablePanel.Controls.Add(rowItem.ControlAt(1), 1, row);
                        tablePanel.Controls.Add(rowItem.ControlAt(2), 2, row);
                        tablePanel.Controls.Add(rowItem.ControlAt(3), 3, row);
                    }));
                    row++;

                    progressBar.Invoke(new MethodInvoker(delegate { progressBar.Value = 10 + ((90 / reportItems.Count) * row); }));
                }
            }
            else
            {
                MessageBox.Show("No " + domainCode + " verification reports were found or processed in database. Please contact technical support for more information.", "No Available Reports", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            // Add bottom spacer and set final layout.
            tablePanel.Invoke(new MethodInvoker(delegate
            {
                tablePanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                tablePanel.RowCount = ++row;
                tablePanel.PerformLayout();
                tablePanel.VerticalScroll.Enabled = true;
                tablePanel.VerticalScroll.Visible = true;
                tablePanel.HorizontalScroll.Enabled = false;
                tablePanel.HorizontalScroll.Visible = false;
                tablePanel.Refresh();
            }));
        }