Пример #1
0
        /// <summary>
        /// Exports the report in CSV format in which can be imported back
        /// into REDCap for RMATRIX's records (Point person: Ms. Grace Matsuura, GDO Data Coordinator).
        /// </summary>
        private void ExportCsv()
        {
            DateTime fromDate, toDate;

            if (DateTime.TryParse(txtFromDate.Text, out fromDate) && DateTime.TryParse(txtToDate.Text, out toDate))
            {
                string        constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                SqlConnection con    = new SqlConnection(constr);

                string reportGrant = ddlGrantType.SelectedItem.Text;

                var cmdText = reportGrant == "RMATRIX" ? "Rpt_RMATRIX_Monthly" : "Rpt_Ola_HAWAII_Monthly";

                try
                {
                    DataTable dt = ddlGrantType.SelectedItem.Text == "RMATRIX" ? new DataTable("tblRmatrix") : new DataTable("tblOlaHawaii");
                    using (SqlConnection sqlcon = new SqlConnection(constr))
                    {
                        using (SqlCommand cmd = new SqlCommand(cmdText, sqlcon))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@StartDate", fromDate);
                            cmd.Parameters.AddWithValue("@EndDate", toDate);

                            using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                            {
                                da.Fill(dt);
                            }
                        }
                    }

                    FileExport fileExport = new FileExport(this.Response);
                    fileExport.CsvExport(dt, fromDate, download_token.Value, reportGrant);
                }
                catch (Exception ex)
                {
                    //Response.Write(ex.ToString());
                    throw ex;
                }
                finally
                {
                    if (con.State != ConnectionState.Closed)
                    {
                        con.Close();
                    }
                }
            }
        }
Пример #2
0
        /// <summary>
        /// NOT BEING USED. (Pulls separate report for RMATRIX Montly Reports; now uses independent report.)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnRmatrixMonthly_Click(object sender, EventArgs e)
        {
            //create csv file for download
            if (Page.User.IsInRole("Admin"))
            {
                DateTime dtFrom, dtTo;

                if (DateTime.TryParse(TextBoxInitialDate.Text, out dtFrom) && DateTime.TryParse(TextBoxCompleteDate.Text, out dtTo))
                {
                    string        constr = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                    SqlConnection con    = new SqlConnection(constr);

                    var cmdText = ddlRmatrix.Value == "Monthly" ? "Rpt_RMATRIX_Monthly" : "Rpt_RMATRIX_Summary";

                    try
                    {
                        DataTable dt = new DataTable("tblRmatrix");
                        using (SqlConnection sqlcon = new SqlConnection(constr))
                        {
                            using (SqlCommand cmd = new SqlCommand(cmdText, sqlcon))
                            {
                                cmd.CommandType = CommandType.StoredProcedure;
                                cmd.Parameters.AddWithValue("@StartDate", dtFrom);
                                cmd.Parameters.AddWithValue("@EndDate", dtTo);

                                if (ddlRmatrix.Value == "Summary")
                                {
                                    var affiliation = txtPIAffil.Text;
                                    cmd.Parameters.AddWithValue("@Affiliation", affiliation);
                                }

                                using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                                {
                                    da.Fill(dt);
                                }
                            }
                        }

                        FileExport fileExport = new FileExport(this.Response);
                        if (ddlRmatrix.Value == "Summary")
                        {
                            fileExport.ExcelExport(dt, cmdText);
                        }
                        else
                        {
                            fileExport.CsvExport(dt, dtFrom, download_token.Value);
                        }
                    }
                    catch (Exception ex)
                    {
                        //Response.Write(ex.ToString());
                        throw ex;
                    }
                    finally
                    {
                        if (con.State != ConnectionState.Closed)
                        {
                            con.Close();
                        }

                        GetProjectReport();
                    }
                }
            }
        }