Beispiel #1
0
        public virtual CrystalDecisions.CrystalReports.Engine.ReportDocument CreateReport()
        {
            FullRequestReport rpt = new FullRequestReport();

            rpt.Site = this.Site;
            return(rpt);
        }
        private void generateReport(string qry, bool from)
        {
            MySqlDataReader reqReader  = null;
            MySqlDataReader permReader = null;

            DataTable reqTable = new DataTable();

            reqTable.Columns.Add("Project", typeof(string));
            reqTable.Columns.Add("Client", typeof(string));
            reqTable.Columns.Add("Request", typeof(string));
            reqTable.Columns.Add("Added", typeof(DateTime));
            reqTable.Columns.Add("Started", typeof(DateTime));
            reqTable.Columns.Add("Ended", typeof(DateTime));
            reqTable.Columns.Add("Developer", typeof(string));
            reqTable.Columns.Add("Dev_Time", typeof(TimeSpan));
            reqTable.Columns.Add("Perm_Granted_By", typeof(string));

            try
            {
                reqReader = DBConnection.getData(qry);

                if (reqReader.HasRows)
                {
                    while (reqReader.Read())
                    {
                        permReader = DBConnection.getDataViaTmpConnection("select IFNULL(concat(first_name, ' ', last_name), ' ') as permName from staff where staff_id=" + reqReader.GetInt32("perm_by_id"));
                        string permName = "";

                        if (permReader.HasRows)
                        {
                            while (permReader.Read())
                            {
                                permName = permReader.GetString(0);
                            }
                        }

                        permReader.Close();
                        DBConnection.closeTmpConnection();

                        Object obj;

                        try
                        {
                            obj = reqReader.GetString(3);
                        }
                        catch (Exception)
                        {
                            obj = null;
                        }

                        if (obj == null)
                        {
                            Object obj2;

                            try
                            {
                                obj2 = reqReader.GetString(2);
                            }
                            catch (Exception)
                            {
                                obj2 = null;
                            }

                            if (obj2 == null)
                            {
                                reqTable.Rows.Add(reqReader.GetString(4), reqReader.GetString(5), reqReader.GetString(0), reqReader.GetDateTime(1), null, null, null, null, permName);
                            }
                            else
                            {
                                reqTable.Rows.Add(reqReader.GetString(4), reqReader.GetString(5), reqReader.GetString(0), reqReader.GetDateTime(1), reqReader.GetDateTime(2), null, reqReader.GetString(6), null, permName);
                            }
                        }
                        else
                        {
                            reqTable.Rows.Add(reqReader.GetString(4), reqReader.GetString(5), reqReader.GetString(0), reqReader.GetDateTime(1), reqReader.GetDateTime(2), reqReader.GetDateTime(3), reqReader.GetString(6), (reqReader.GetDateTime(3) - reqReader.GetDateTime(2)), permName);
                        }
                    }

                    if (reqReader != null)
                    {
                        if (!reqReader.IsClosed)
                        {
                            reqReader.Close();
                        }
                    }

                    if (permReader != null)
                    {
                        if (!permReader.IsClosed)
                        {
                            permReader.Close();
                        }
                    }

                    if (from)
                    {
                        ChangeRequestReport rpt = new ChangeRequestReport();

                        rpt.Database.Tables["ChangeReqTable"].SetDataSource(reqTable);

                        requestReportViewer.ReportSource = null;
                        requestReportViewer.ReportSource = rpt;
                    }
                    else
                    {
                        FullRequestReport rpt = new FullRequestReport();

                        rpt.Database.Tables["ChangeReqTable"].SetDataSource(reqTable);

                        requestReportViewer.ReportSource = null;
                        requestReportViewer.ReportSource = rpt;
                    }
                }
                else
                {
                    if (reqReader != null)
                    {
                        if (!reqReader.IsClosed)
                        {
                            reqReader.Close();
                        }
                    }

                    if (permReader != null)
                    {
                        if (!permReader.IsClosed)
                        {
                            permReader.Close();
                        }
                    }

                    MessageBox.Show("No Records for this Developer!", "Change Request Report", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                    devCmbBox.SelectedItem = null;
                    requestReportViewer.Focus();
                    requestReportViewer.ReportSource = null;
                }
            }
            catch (Exception exc)
            {
                if (reqReader != null)
                {
                    if (!reqReader.IsClosed)
                    {
                        reqReader.Close();
                    }
                }

                if (permReader != null)
                {
                    if (!permReader.IsClosed)
                    {
                        permReader.Close();
                    }
                }

                MessageBox.Show("Something went wrong!\n" + exc, "Change Request Report", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                devCmbBox.SelectedItem = null;
                requestReportViewer.Focus();
                requestReportViewer.ReportSource = null;
            }
        }