Ejemplo n.º 1
0
    protected void Button3_Click(object sender, EventArgs e)
    {
        try
        {
            Response.Clear();
            Response.Buffer = true;
            string filename = "'" + ddl_PlantName.SelectedItem.Text + "' " + " '" + Label45.Text + "' " + " " + DateTime.Now.ToString() + ".xls";

            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
            // Response.AddHeader("content-disposition", "attachment;filename=GridViewExport.xls");
            Response.Charset     = "";
            Response.ContentType = "application/vnd.ms-excel";
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages
                GridView1.AllowPaging = false;
                // getgriddata();
                Get_IncreaseDecreaseAmountDetails();

                GridView1.HeaderRow.BackColor = Color.White;
                foreach (TableCell cell in GridView1.HeaderRow.Cells)
                {
                    cell.BackColor = GridView1.HeaderStyle.BackColor;
                }
                foreach (GridViewRow row in GridView1.Rows)
                {
                    row.BackColor = Color.White;
                    foreach (TableCell cell in row.Cells)
                    {
                        if (row.RowIndex % 2 == 0)
                        {
                            cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                        }
                        else
                        {
                            cell.BackColor = GridView1.RowStyle.BackColor;
                        }
                        cell.CssClass = "textmode";
                    }
                }

                GridView1.RenderControl(hw);

                //style to format numbers to string
                string style = @"<style> td { mso-number-format:""" + "\\@" + @"""; }</style>";
                // string style = @"<style> .textmode { } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
        }


        catch (Exception ex)
        {
            WebMsgBox.Show(ex.ToString());
        }
    }
        protected void ImageExport_Click(object sender, ImageClickEventArgs e)
        {
            string trteradataconnection = "Data Source='204.99.34.21';User ID='coebatch';Password='******';";

            Teradata.Client.Provider.TdConnection tereconnection = new Teradata.Client.Provider.TdConnection(trteradataconnection);
            //TdDataAdapter ID;
            // string defectid = TxtHistorySearch0.Text;

            // ID = dbObj.DefectHome();
            try
            {
                //  TdCommand Teracomd = new TdCommand("select * from coebatch.tbl_Defect", tereconnection);



                //TdDataAdapter AdvancedDefectSearch =
                //          new TdDataAdapter(@"Select DefectID,DefectName,Status,sDate,sCycle,Description,Project,Tester,TestcasesAssociated,Module,AssignedTo,Filenames,Filesize from  coebatch.tbl_Defect where  sDate between '" + fromdate + "' and '" + todate + "'", tereconnection);
                tereconnection.Open();
                TdDataAdapter AdvancedDefectSearch =
                    new TdDataAdapter(@"select Defectid,Defectname,sdate as OpenDate,Status,Scycle as Cycles,Project,Tester,Module,Assignedto,Closedate as LastUpdatedDate from coebatch.tbl_Defect order by Defectid asc ", tereconnection);

                // IDataSource dt1 = new IDataSource ;


                DataSet ds = new DataSet();

                AdvancedDefectSearch.Fill(ds);
                this.GridView1.DataSource = ds.Tables[0];
                GridView1.DataKeyNames    = new string[] { "Defectid" };
                this.GridView1.DataBind();
            }

            catch (Teradata.Client.Provider.TdException ex)
            {
                //Throw the exception to calling environment
                throw ex;
            }
            finally
            {
                //Close the Connection from the Database
                tereconnection.Close();;
            }

            string attachment = "attachment; filename=Export.xls";

            Response.ClearContent(); Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            StringWriter   sw  = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);

            // GridView1.HeaderRow.BackColor = Color.White;
            foreach (TableCell cell in GridView1.HeaderRow.Cells)
            {
                cell.BackColor = GridView1.HeaderStyle.BackColor;
                cell.Height    = 25;
            }


            foreach (GridViewRow row in GridView1.Rows)
            {
                foreach (TableCell cell in row.Cells)
                {
                    if (row.RowIndex % 1 == 0)
                    {
                        //cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                        cell.Height = 25;
                    }
                    else
                    {
                        cell.BackColor = GridView1.RowStyle.BackColor;
                    }
                    cell.CssClass = "textmode";
                }
            }

            GridView1.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();

            //int columns = this.GridView1.Columns.Count;
            //    //GridView1.AllowPaging = false;
            //   // GridView1.DataBind();

            //    int Count = dbObj.GetDefectcount();
            //    Microsoft.Office.Interop.Excel.Application ExcelApp =
            // new Microsoft.Office.Interop.Excel.Application();
            //    Microsoft.Office.Interop.Excel._Workbook ExcelBook;
            //    Microsoft.Office.Interop.Excel._Worksheet ExcelSheet;

            //    int i = 0;
            //    int j = 0;

            //    //create object of excel
            //    ExcelBook = (Microsoft.Office.Interop.Excel._Workbook)ExcelApp.Workbooks.Add(1);
            //    ExcelSheet = (Microsoft.Office.Interop.Excel._Worksheet)ExcelBook.ActiveSheet;
            //    //export header

            //    for (i = 1; i <= this.GridView1.Columns.Count; i++)
            //    {
            //        ExcelSheet.Cells[1, i] = this.GridView1.Columns[i - 1].HeaderText;
            //    }

            //    //export data
            //    for (i = 1; i <= Count; i++)
            //    {
            //        for (j = 1; j <= GridView1.Columns.Count; j++)
            //        {
            //            ExcelSheet.Cells[i + 1, j] = GridView1.Rows[i - 1].Cells[j - 1].Text;
            //        }
            //    }

            //    ExcelApp.Visible = true;
            //    //GridView1.AllowPaging = true;
        }
Ejemplo n.º 3
0
        protected void img_ExportToExcel1_Click(object sender, ImageClickEventArgs e)
        {
            Order = 1;
            int idostad = 0;

            if (txt_CodeOstad.Text != "")
            {
                idostad = int.Parse(txt_CodeOstad.Text);
            }
            DataTable dt = FRB.GetEvalutionProfDividedDid(ddl_Term.SelectedValue, idostad, int.Parse(ddl_CodeGroup.SelectedValue), int.Parse(ddl_CodeDras.SelectedValue), Order);

            if (dt.Rows.Count == 0)
            {
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment;filename=ReportEvalutionProf.xls");
                Response.Charset     = "";
                Response.ContentType = "application/vnd.ms-excel";
                using (StringWriter sw = new StringWriter())
                {
                    HtmlTextWriter hw = new HtmlTextWriter(sw);

                    //To Export all pages
                    ////gv_Show.AllowPaging = false;
                    ////this.BindGrid();

                    //gv_Show.HeaderRow.BackColor = Color.White;
                    foreach (TableCell cell in GridView1.HeaderRow.Cells)
                    {
                        cell.BackColor = GridView1.HeaderStyle.BackColor;
                    }
                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        //row.BackColor = Color.White;
                        foreach (TableCell cell in row.Cells)
                        {
                            if (row.RowIndex % 2 == 0)
                            {
                                cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                            }
                            else
                            {
                                cell.BackColor = GridView1.RowStyle.BackColor;
                            }
                            cell.CssClass = "textmode";
                        }
                    }

                    GridView1.RenderControl(hw);

                    //style to format numbers to string
                    string style = @"<style> .textmode { } </style>";
                    Response.Write(style);
                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
            }
        }
Ejemplo n.º 4
0
    // Export data to Excel from Gridview

    protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Clear();

        Response.Buffer = true;



        Response.AddHeader("content-disposition",

                           "attachment;filename=GridViewExport.xls");

        Response.Charset = "";

        Response.ContentType = "application/vnd.ms-excel";

        StringWriter sw = new StringWriter();

        HtmlTextWriter hw = new HtmlTextWriter(sw);



        GridView1.AllowPaging = false;

        GridView1.DataBind();



        //Change the Header Row back to white color

        GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");



        //Apply style to Individual Cells

        GridView1.HeaderRow.Cells[0].Style.Add("background-color", "green");

        GridView1.HeaderRow.Cells[1].Style.Add("background-color", "green");

        GridView1.HeaderRow.Cells[2].Style.Add("background-color", "green");

        GridView1.HeaderRow.Cells[3].Style.Add("background-color", "green");



        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];



            //Change Color back to white

            row.BackColor = System.Drawing.Color.White;



            //Apply text style to each Row

            row.Attributes.Add("class", "textmode");



            //Apply style to Individual Cells of Alternating Row

            if (i % 2 != 0)
            {
                row.Cells[0].Style.Add("background-color", "#C2D69B");

                row.Cells[1].Style.Add("background-color", "#C2D69B");

                row.Cells[2].Style.Add("background-color", "#C2D69B");

                row.Cells[3].Style.Add("background-color", "#C2D69B");
            }
        }

        GridView1.RenderControl(hw);



        //style to format numbers to string

        string style = @"<style> .textmode { mso-number-format:\@; } </style>";

        Response.Write(style);

        Response.Output.Write(sw.ToString());

        Response.Flush();

        Response.End();
    }
Ejemplo n.º 5
0
        protected void exportarPDF_Click(object sender, EventArgs e)
        {
            Response.ClearContent();
            Response.ContentType = "application/pdf";
            Response.AppendHeader("content-disposition", "attachment;filename=Plan_de_Pagos.pdf");
            Response.Cache.SetCacheability(HttpCacheability.NoCache);

            StringWriter   stringWriter   = new StringWriter();
            HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

            mainTitle.Style["font-family"]     = "Segoe UI";
            subTitle.Style["font-family"]      = "Segoe UI";
            subTitle.Style["display"]          = "block";
            headOne.Style["font-family"]       = "Segoe UI";
            headOne.Style["display"]           = "block";
            tituloReporte.Style["font-family"] = "Segoe UI";

            mainTitle.Style["text-align"]     = "center";
            subTitle.Style["text-align"]      = "center";
            headOne.Style["text-align"]       = "center";
            tituloReporte.Style["text-align"] = "center";


            subTitle.Style["font-size"]      = "18px";
            headOne.Style["font-size"]       = "18px";
            tituloReporte.Style["font-size"] = "22px";

            tituloReporte.Style["color"] = "#e43c5c";


            mainTitle.RenderControl(htmlTextWriter);
            subTitle.RenderControl(htmlTextWriter);
            headOne.RenderControl(htmlTextWriter);
            tituloReporte.RenderControl(htmlTextWriter);


            GridView1.Style["font-size"]    = "medium";
            GridView1.Style["table-layout"] = "auto";
            GridView1.Style["width"]        = "100%";

            foreach (TableCell tableCell in GridView1.HeaderRow.Cells)
            {
                tableCell.Style["background-color"] = "#e43c5c";
                tableCell.Style["color"]            = "#fff";
                tableCell.Style["border"]           = "1px solid #e43c5c";
            }
            foreach (GridViewRow gridViewRow in GridView1.Rows)
            {
                gridViewRow.BackColor = System.Drawing.Color.White;
                foreach (TableCell gridViewRowTableCell in gridViewRow.Cells)
                {
                    gridViewRowTableCell.Style["background-color"] = "#FFFFFF";
                    gridViewRowTableCell.Style["border"]           = "1px solid #e43c5c";
                    gridViewRowTableCell.Style["text-align"]       = "right";
                }
            }
            GridView1.AllowPaging = false;
            GridView1.DataBind();
            GridView1.RenderControl(htmlTextWriter);
            StringReader stringReader = new StringReader(stringWriter.ToString());

            // Document pdfDoc = new HTMLWorker(pdfDoc);



            GridView1.RenderControl(htmlTextWriter);
            Response.Write(stringWriter.ToString());
            Response.End();
        }
Ejemplo n.º 6
0
        protected void img_ExportToExcel1_Click(object sender, ImageClickEventArgs e)
        {
            if (txt_CodeOstad.Text == string.Empty || txt_CodeOstad.Text == "")
            {
                txt_CodeOstad.Text = "0";
                //Session["stcode"] = txt_CodeOstad.Text;
            }
            if (txt_did.Text == string.Empty)
            {
                txt_did.Text = "0";
            }
            System.Data.DataTable dt2 = FRB.GetAcceptMark(ddl_Term.SelectedValue, int.Parse(txt_did.Text), int.Parse(txt_CodeOstad.Text), Convert.ToInt32(ddlDanesh.SelectedValue));
            if (dt2.Rows.Count == 0)
            {
            }
            else
            {
                GridView1.DataSource = dt2;
                GridView1.DataBind();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment;filename=ReportConfirmScores.xls");
                Response.Charset     = "";
                Response.ContentType = "application/vnd.ms-excel";
                using (StringWriter sw = new StringWriter())
                {
                    HtmlTextWriter hw = new HtmlTextWriter(sw);

                    //To Export all pages
                    ////gv_Show.AllowPaging = false;
                    ////this.BindGrid();

                    //gv_Show.HeaderRow.BackColor = Color.White;
                    foreach (TableCell cell in GridView1.HeaderRow.Cells)
                    {
                        cell.BackColor = GridView1.HeaderStyle.BackColor;
                    }
                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        //row.BackColor = Color.White;
                        foreach (TableCell cell in row.Cells)
                        {
                            if (row.RowIndex % 2 == 0)
                            {
                                cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                            }
                            else
                            {
                                cell.BackColor = GridView1.RowStyle.BackColor;
                            }
                            cell.CssClass = "textmode";
                        }
                    }

                    GridView1.RenderControl(hw);

                    //style to format numbers to string
                    string style = @"<style> .textmode { } </style>";
                    Response.Write(style);
                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
            }
        }
Ejemplo n.º 7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var labelNameFormat = Request.QueryString["format"];
            int?qid             = Request.QueryString["id"].ToInt2();
            var r = Response;

            r.Clear();
            var useweb = Request.QueryString["web"];

            string header =
                @"<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">
<head>
	<meta http-equiv=Content-Type content=""text/html; charset=utf-8""> 
    <style>
    <!--table
    br {mso-data-placement:same-cell;}
    tr {vertical-align:top;}
    td.Text {mso-number-format:\@}
    -->
    </style>
</head>
<body>";

            r.Charset = "";

            if (!qid.HasValue && labelNameFormat != "Groups")
            {
                r.Write("no queryid");
                r.Flush();
                r.End();
            }
            if (useweb != "true")
            {
                r.ContentType = "application/vnd.ms-excel";
                r.AddHeader("Content-Disposition", "attachment;filename=CMSPeople.xls");
            }
            r.Write(header);
            var ctl       = new MailingController();
            var useTitles = Request.QueryString["titles"];

            ctl.UseTitles = useTitles == "true";
            var dg = new DataGrid();

            dg.EnableViewState = false;
            switch (labelNameFormat)
            {
            case "Individual":
                dg.DataSource = ExportPeople.FetchExcelList(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "IndividualPicture":
                GridView1.EnableViewState = false;
                GridView1.AllowPaging     = false;
                GridView1.DataSource      = ExportPeople.FetchExcelListPics(qid.Value, maxExcelRows);
                GridView1.DataBind();
                GridView1.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Library":
                dg.DataSource = ExportPeople.FetchExcelLibraryList(qid.Value);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Family":
                dg.DataSource = ctl.FetchExcelFamily(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "FamilyMembers":
                FamilyMembers.EnableViewState = false;
                FamilyMembers.AllowPaging     = false;
                FamilyMembers.DataSource      = ExportPeople.FetchExcelListFamilyMembers(qid.Value);
                FamilyMembers.DataBind();
                FamilyMembers.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "AllFamily":
                dg.DataSource = ExportPeople.FetchExcelListFamily(qid.Value);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "ParentsOf":
                dg.DataSource = ctl.FetchExcelParents(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "CouplesEither":
                dg.DataSource = ctl.FetchExcelCouplesEither(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "CouplesBoth":
                dg.DataSource = ctl.FetchExcelCouplesBoth(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Involvement":
                dg.DataSource = ExportInvolvements.InvolvementList(qid.Value);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Children":
                dg.DataSource = ExportInvolvements.ChildrenList(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Church":
                dg.DataSource = ExportInvolvements.ChurchList(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Attend":
                dg.DataSource = ExportInvolvements.AttendList(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Organization":
                dg.DataSource = ExportInvolvements.OrgMemberList(qid.Value);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Groups":
                dg.DataSource = ExportInvolvements.OrgMemberListGroups();
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;

            case "Promotion":
                dg.DataSource = ExportInvolvements.PromoList(qid.Value, maxExcelRows);
                dg.DataBind();
                dg.RenderControl(new HtmlTextWriter(r.Output));
                break;
            }
            r.Write("</body></HTML>");
            r.Flush();
            r.End();
        }
        protected MemoryStream CreatePDF()
        {
            // Create a Document object
            Document document = new Document(PageSize.A4, 70, 70, 70, 70);

            //MemoryStream
            MemoryStream PDFData = new MemoryStream();
            PdfWriter    writer  = PdfWriter.GetInstance(document, PDFData);

            // First, create our fonts
            var       titleFont     = FontFactory.GetFont("Arial", 14, Font.BOLD);
            var       boldTableFont = FontFactory.GetFont("Arial", 10, Font.BOLD);
            var       bodyFont      = FontFactory.GetFont("Arial", 10, Font.NORMAL);
            Rectangle pageSize      = writer.PageSize;

            // Open the Document for writing
            document.Open();
            //Add elements to the document here

            #region Top table
            // Create the header table
            PdfPTable headertable = new PdfPTable(3);
            headertable.HorizontalAlignment = 0;
            headertable.WidthPercentage     = 100;
            headertable.SetWidths(new float[] { 4, 2, 4 });  // then set the column's __relative__ widths
            headertable.DefaultCell.Border = Rectangle.NO_BORDER;
            //headertable.DefaultCell.Border = Rectangle.NO_BORDER; //à modifier
            headertable.SpacingAfter = 30;
            PdfPTable nested = new PdfPTable(1);
            //nested.DefaultCell.Border = Rectangle.NO_BORDER;//à modifier
            PdfPCell nextPostCell1 = new PdfPCell(new Phrase("GalaxySwissBourdin", bodyFont));
            nextPostCell1.Border = Rectangle.NO_BORDER | Rectangle.RIGHT_BORDER;
            nested.AddCell(nextPostCell1);
            PdfPCell nextPostCell2 = new PdfPCell(new Phrase("2, rue Albert Jacquard", bodyFont));
            nextPostCell2.Border = Rectangle.NO_BORDER | Rectangle.RIGHT_BORDER;
            nested.AddCell(nextPostCell2);
            PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Vénissieux 69200", bodyFont));
            nextPostCell3.Border = Rectangle.NO_BORDER | Rectangle.RIGHT_BORDER;
            nested.AddCell(nextPostCell3);
            PdfPCell nesthousing = new PdfPCell(nested);
            nesthousing.Rowspan = 4;
            nesthousing.Padding = 0f;
            headertable.AddCell(nesthousing);

            headertable.AddCell("");
            PdfPCell invoiceCell = new PdfPCell(new Phrase("GalaxySwissBourdin Labs", titleFont));
            invoiceCell.HorizontalAlignment = PdfPCell.ALIGN_CENTER;//à modifier
            invoiceCell.Border = Rectangle.NO_BORDER;
            headertable.AddCell(invoiceCell);
            PdfPCell noCell = new PdfPCell(new Phrase("N° Commande : ", bodyFont));
            noCell.HorizontalAlignment = 2;
            noCell.Border = Rectangle.NO_BORDER;
            headertable.AddCell(noCell);
            headertable.AddCell(new Phrase(tNumComm.Text, bodyFont));
            PdfPCell dateCell = new PdfPCell(new Phrase("Date : ", bodyFont));
            dateCell.HorizontalAlignment = 2;
            dateCell.Border = Rectangle.NO_BORDER;
            headertable.AddCell(dateCell);
            headertable.AddCell(new Phrase(datepicker.Value, bodyFont));
            PdfPCell billCell = new PdfPCell(new Phrase("Destinataire : ", bodyFont));
            billCell.HorizontalAlignment = 2;
            billCell.Border = Rectangle.NO_BORDER;
            headertable.AddCell(billCell);
            headertable.AddCell(new Phrase(ddPraticien.SelectedValue + "\n" + tbAdresse.Text + "\n" + tbCP.Text + "\n" + tbVille.Text + "\n" + ddTransporteur.Text, bodyFont));
            document.Add(headertable);
            #endregion

            #region Items Table
            StringWriter   sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            GridView1.RenderControl(hw);
            StringReader sr         = new StringReader(sw.ToString());
            HTMLWorker   htmlparser = new HTMLWorker(document);
            htmlparser.Parse(sr);
            Response.Write(document);
            GridView1.AllowPaging = true;
            GridView1.DataBind();
            #endregion

            writer.CloseStream = false; //set the closestream property
            // Close the Document without closing the underlying stream
            document.Close();
            PDFData.Position = 0;
            return(PDFData);
        }
Ejemplo n.º 9
0
    private void PDF()
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=exportar.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        //GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);


        StringReader sr     = new StringReader(sw.ToString());
        Document     pdcDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);

        HTMLWorker htmlparser = new HTMLWorker(pdcDoc);

        PdfWriter.GetInstance(pdcDoc, Response.OutputStream);

        PdfWriter writer = PdfWriter.GetInstance(pdcDoc, Response.OutputStream);

        pdcDoc.Open();

        iTextSharp.text.Font LineBreak = FontFactory.GetFont("Arial", size: 16);

        iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(@"C:\Users\hp\Desktop\SEXTO_CICLO\PUNTO_NET\seguno_parcial\EXCEL\potable.jpg");

        Paragraph parrafo = new Paragraph(string.Format("                PLANILLA DE COBRO"), new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16));

        parrafo.SpacingBefore = 200;
        parrafo.SpacingAfter  = 0;
        parrafo.Alignment     = 1;

        pdcDoc.Add(parrafo);
        pdcDoc.Add(Chunk.NEWLINE);
        img.SetAbsolutePosition(0, 750);
        pdcDoc.Add(img);

        img.ScaleToFit(115f, 50F);

        var numero = new Paragraph("N° " + lblRecibo.Text);

        numero.Alignment = 2;
        numero.Font.Size = 10;
        pdcDoc.Add(numero);
        pdcDoc.Add(new Paragraph("\n", LineBreak));


        pdcDoc.Add(new Paragraph("\n", LineBreak));

        PdfPTable table = new PdfPTable(2);

        table.DefaultCell.BackgroundColor = new iTextSharp.text.BaseColor(240, 240, 240);
        table.HorizontalAlignment         = Element.ALIGN_CENTER;


        table.AddCell("Cedula " + txtcedula.Text);
        table.AddCell("Dirección " + txtdireccion.Text);
        table.AddCell("Nombre  " + txtnombre.Text);
        table.AddCell("N° Medidor  " + txtmedidor.Text);

        table.AddCell("Apellido  " + txtapellido.Text);
        table.AddCell("Fecha Emisión  " + txtemision.Text);
        table.AddCell("Metros Consumidos " + txtmetros.Text);
        table.AddCell("Fecha Pago  " + txtpago.Text);
        table.AddCell("Total de Cancelar  " + txttotal.Text);

        pdcDoc.Add(table);
        htmlparser.Parse(sr);
        pdcDoc.Close();
        Response.Write(pdcDoc);
        Response.End();
    }
Ejemplo n.º 10
0
    protected void Page_LoadComplete(object sender, EventArgs e)
    {
        //send an email to user to confirm purchase
        //MembershipUser usr = Membership.GetUser(Session["userName"].ToString());
        //string strEmailTo = usr.Email.ToString();
        string strEmailTo      = User.Identity.Name + "@gmail.com"; //Be sure that username is the first part of your gmail account
        string strEmailFrom    = "*****@*****.**";          //put a valid gmail account here to represent the company's email.
        string strEmailSubject = "Purchase Confirmation";
        string strHTML         = "";                                //prepare a string variable to store rendered html
        string strEmailBody    = "";                                //prepare a string variable to store email body

        //calculate total purchase
        double total = 0;

        foreach (GridViewRow gvr in GridView1.Rows)
        {
            total = total + double.Parse(gvr.Cells[8].Text.ToString());
        }

        //convert GridView1 to HTML
        StringBuilder  sb     = new StringBuilder();
        StringWriter   sw     = new StringWriter(sb);
        HtmlTextWriter htmlTW = new HtmlTextWriter(sw);

        GridView1.RenderControl(htmlTW);
        strHTML = sb.ToString();

        strEmailBody = "<html><body>";
        strEmailBody =
            strEmailBody + "You have purchased the following song(s) from us:<br/><br/>";
        strEmailBody = strEmailBody + strHTML;
        strEmailBody = strEmailBody + "<br/><br/>Total Amount: $" + total + ".";
        strEmailBody = strEmailBody + "<br/><br/>We appreciate your business with us.";
        strEmailBody = strEmailBody + "</body></html>";

        MailMessage msg = new MailMessage();

        msg.From = new MailAddress(strEmailFrom);
        msg.To.Add(strEmailTo);
        msg.Subject    = strEmailSubject;
        msg.IsBodyHtml = true;
        msg.Body       = strEmailBody;
        System.Net.Mail.SmtpClient smtpClient =
            new System.Net.Mail.SmtpClient("smtp.gmail.com");
        smtpClient.EnableSsl = true;

        //change "*****@*****.**" with a valid Gmail account and "password" with
        //the password for that valid Gmail account.
        //Note: You might want to create a new, throw-away, Gmail account just for this project
        smtpClient.Credentials =
            new System.Net.NetworkCredential("*****@*****.**", "Poland@123");

        //send email
        smtpClient.Port = 587;
        smtpClient.Send(msg);

        //This transaction is done, clear session variables shopcartID and CC_No
        Session["shopCartID"] = null;
        Session["CC_No"]      = null;

        //redirect to download page from which user can download purchased song(s)
        Response.Redirect("download.aspx", true);
    } //end of Page_LoadComplete
Ejemplo n.º 11
0
    protected void download1_Click(object sender, EventArgs e)
    {
        //查询数据
        string SQL = "  SELECT  SEQ,USER_ID,CREAT_TIME,STATION,STAFF_NO,FLIGHT_NO,DEP_DT"
                     + "    ,SEAT_NUM,REASON,MEMBER,NATIONALITY,AGE,GENDER,CITY "
                     + "    ,VAL_01,VAL_02,VAL_03,VAL_04,VAL_05,VAL_06,VAL_07 "
                     + "    ,VAL_08,VAL_09,VAL_10,VAL_11,VAL_12,VAL_13,LCHAR01 "
                     + "    FROM BCSS_DATE "
                     + "   where STATUS='NEW' "
                     + "   and (CAST(DEP_DT AS date) between '" + from.Value + "' and '" + to.Value + "')";

        //存放数据的dt
        DataTable dt = new DataTable();

        dt.Columns.Add("SEQ", typeof(string));
        dt.Columns.Add("USER_ID", typeof(string));
        dt.Columns.Add("CREAT_TIME", typeof(string));
        dt.Columns.Add("STATION", typeof(string));
        dt.Columns.Add("STAFF_NO", typeof(string));
        dt.Columns.Add("FLIGHT_NO", typeof(string));
        dt.Columns.Add("DEP_DT", typeof(string));
        dt.Columns.Add("SEAT_NUM", typeof(string));
        dt.Columns.Add("REASON", typeof(string));
        dt.Columns.Add("MEMBER", typeof(string));
        dt.Columns.Add("NATIONALITY", typeof(string));
        dt.Columns.Add("AGE", typeof(string));
        dt.Columns.Add("GENDER", typeof(string));
        dt.Columns.Add("CITY", typeof(string));
        dt.Columns.Add("VAL_01", typeof(string));
        dt.Columns.Add("VAL_02", typeof(string));
        dt.Columns.Add("VAL_03", typeof(string));
        dt.Columns.Add("VAL_04", typeof(string));
        dt.Columns.Add("VAL_05", typeof(string));
        dt.Columns.Add("VAL_06", typeof(string));
        dt.Columns.Add("VAL_07", typeof(string));
        dt.Columns.Add("VAL_08", typeof(string));
        dt.Columns.Add("VAL_09", typeof(string));
        dt.Columns.Add("VAL_10", typeof(string));
        dt.Columns.Add("VAL_11", typeof(string));
        dt.Columns.Add("VAL_12", typeof(string));
        dt.Columns.Add("VAL_13", typeof(string));
        dt.Columns.Add("LCHAR01", typeof(string));
        using (SqlDataReader rdr = SqlHelper.ExecuteReader(SqlHelper.Conn, CommandType.Text, SQL))
        {
            while (rdr.Read())
            {
                DataRow row = dt.NewRow();
                row["SEQ"]         = Convert.ToString(rdr.GetSqlValue(0));
                row["USER_ID"]     = Convert.ToString(rdr.GetSqlValue(1));
                row["CREAT_TIME"]  = Convert.ToString(rdr.GetSqlValue(2));
                row["STATION"]     = Convert.ToString(rdr.GetSqlValue(3));
                row["STAFF_NO"]    = Convert.ToString(rdr.GetSqlValue(4));
                row["FLIGHT_NO"]   = Convert.ToString(rdr.GetSqlValue(5));
                row["DEP_DT"]      = Convert.ToString(rdr.GetSqlValue(6));
                row["SEAT_NUM"]    = Convert.ToString(rdr.GetSqlValue(7));
                row["REASON"]      = Convert.ToString(rdr.GetSqlValue(8));
                row["MEMBER"]      = Convert.ToString(rdr.GetSqlValue(9));
                row["NATIONALITY"] = Convert.ToString(rdr.GetSqlValue(10));
                row["AGE"]         = Convert.ToString(rdr.GetSqlValue(11));
                row["GENDER"]      = Convert.ToString(rdr.GetSqlValue(12));
                row["CITY"]        = Convert.ToString(rdr.GetSqlValue(13));
                row["VAL_01"]      = Convert.ToString(rdr.GetSqlValue(14));
                row["VAL_02"]      = Convert.ToString(rdr.GetSqlValue(15));
                row["VAL_03"]      = Convert.ToString(rdr.GetSqlValue(16));
                row["VAL_04"]      = Convert.ToString(rdr.GetSqlValue(17));
                row["VAL_05"]      = Convert.ToString(rdr.GetSqlValue(18));
                row["VAL_06"]      = Convert.ToString(rdr.GetSqlValue(19));
                row["VAL_07"]      = Convert.ToString(rdr.GetSqlValue(20));
                row["VAL_08"]      = Convert.ToString(rdr.GetSqlValue(21));
                row["VAL_09"]      = Convert.ToString(rdr.GetSqlValue(22));
                row["VAL_10"]      = Convert.ToString(rdr.GetSqlValue(23));
                row["VAL_11"]      = Convert.ToString(rdr.GetSqlValue(24));
                row["VAL_12"]      = Convert.ToString(rdr.GetSqlValue(25));
                row["VAL_13"]      = Convert.ToString(rdr.GetSqlValue(26));
                row["LCHAR01"]     = Convert.ToString(rdr.GetSqlValue(27));

                dt.Rows.Add(row);
            }
        }


        //插入 gridview
        GridView1.DataSource = dt;
        GridView1.DataBind();
        //下载
        Response.Charset         = "GB2312";
        Response.ContentEncoding = System.Text.Encoding.UTF8;
        Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("Input.xls", Encoding.UTF8).ToString());
        Response.ContentType = "application/ms-excel";
        this.EnableViewState = false;
        StringWriter   tw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);

        GridView1.RenderControl(hw);
        Response.Write(tw.ToString());
        Response.End();
    }
Ejemplo n.º 12
0
        void btnexcel_Click(object sender, EventArgs e)
        {
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages
                //Page_Load(sender, e);

                GridView1.AllowPaging  = false;
                GridView1.AllowSorting = false;
                GridView1.DataBind();
                //GridView1.Columns[1].Visible = false;
                foreach (GridViewRow row in GridView1.Rows)
                {
                    foreach (TableCell cell in row.Cells)
                    {
                        List <Control> controls = new List <Control>();
                        foreach (Control control in cell.Controls)
                        {
                            switch (control.GetType().Name)
                            {
                            case "HyperLink":
                                controls.Add(control);
                                break;

                            case "TextBox":
                                controls.Add(control);
                                break;

                            case "LinkButton":
                                controls.Add(control);
                                break;

                            case "CheckBox":
                                controls.Add(control);
                                break;

                            case "RadioButton":
                                controls.Add(control);
                                break;

                            case "Image":
                                controls.Add(control);
                                break;
                            }
                        }
                        foreach (Control control in controls)
                        {
                            switch (control.GetType().Name)
                            {
                            case "HyperLink":
                                cell.Controls.Add(new Literal {
                                    Text = (control as HyperLink).Text
                                });
                                break;

                            case "TextBox":
                                cell.Controls.Add(new Literal {
                                    Text = (control as TextBox).Text
                                });
                                break;

                            case "LinkButton":
                                cell.Controls.Add(new Literal {
                                    Text = (control as LinkButton).Text
                                });
                                break;

                            case "CheckBox":
                                cell.Controls.Add(new Literal {
                                    Text = (control as CheckBox).Text
                                });
                                break;

                            case "RadioButton":
                                cell.Controls.Add(new Literal {
                                    Text = (control as RadioButton).Text
                                });
                                break;

                            case "Image":
                                cell.Controls.Add(new Literal {
                                    Text = (control as System.Web.UI.WebControls.Image).AlternateText = ""
                                });
                                break;
                            }
                            cell.Controls.Remove(control);
                        }
                    }
                }
                GridView1.GridLines = GridLines.Both;
                Response.AddHeader("content-disposition", "attachment;filename=SchedulerDetails.xls");
                Response.Charset     = String.Empty;
                Response.ContentType = "application/vnd.xls";
                GridView1.RenderControl(hw);
                string style = @"<style> .textmode { mso-number-format:\@; } </style>";
                Response.Write(style);
                Response.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
        }
Ejemplo n.º 13
0
        protected void export_Click(object sender, EventArgs e)
        {
            string style = @"<style type=""text/css"">td{mso-number-format:'\@';text-align:center;}</style>";

            //从页面取到查询条件
            //发票类型代码:00所有/01专票/04普票
            string invoiceType = this.DropDownList1.SelectedValue.ToString();
            //起始日期
            string startDate = this.startDate.Text;
            //结束日期
            string endDate = this.endDate.Text;
            //填充数据源
            string operatorID = Request.LogonUserIdentity.Name;

            if (invoiceType != "" && startDate != "" && endDate != "" && operatorID != "")
            {
                DataSet ds = DataOperate.exportInvoiceInfo(invoiceType, startDate, endDate, operatorID);
                if (!(ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0))
                {
                    Response.Write("<script language=javascript>alert('该时间段内没有该类型发票!');</script>");
                }
                else
                {
                    Response.ClearContent();
                    //Response.Buffer = true;
                    //Response.Charset = "gb2312";
                    //Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");
                    Response.Charset         = "UTF-8";
                    Response.ContentEncoding = System.Text.Encoding.UTF8;
                    Response.AddHeader("content-disposition", "attachment; filename=export.xls");
                    Response.ContentType = "application/ms-excel";
                    StringWriter   sw   = new StringWriter();
                    HtmlTextWriter htw  = new HtmlTextWriter(sw);
                    StringWriter   sw2  = new StringWriter();
                    HtmlTextWriter htw2 = new HtmlTextWriter(sw2);
                    //导出前将GridView排序和分页都关闭
                    GridView1.AllowPaging  = false;
                    GridView1.AllowSorting = false;
                    GridView1.DataSource   = ds.Tables[0];
                    GridView2.DataSource   = ds.Tables[1];
                    //绑定数据源
                    GridView1.DataBind();
                    GridView2.DataBind();
                    // 清除GridView1中的所有控件,以便导出Excel
                    ClearControls(GridView1);
                    GridView1.RenderControl(htw);
                    GridView2.RenderControl(htw2);
                    //Style为导出Excel时的格式(有个五六种吧,去网上查一下)
                    Response.Write(style);
                    Response.Write(sw.ToString());
                    Response.Write(sw2.ToString());
                    Response.Flush();
                    Response.End();
                    //导出前将GridView分页打开
                    GridView1.AllowPaging  = true;
                    GridView1.AllowSorting = false;
                    //重新绑定数据源
                    //DataSet ds = DataOperate.queryInvoiceInfo("61106", "20170101", "20171231");
                    GridView1.DataSource   = ds.Tables[0];
                    GridView1.DataKeyNames = new string[] { "InvoiceCode", "InvoiceNumber" };//主键
                    GridView1.DataBind();
                }
            }
            else
            {
                Response.Write("<script language=javascript>alert('请完善查询起止日期!');</script>");
            }
        }
Ejemplo n.º 14
0
        protected void ExportToPDF_Click(object sender, EventArgs e)
        {
            using (StringWriter sw = new StringWriter())
            {
                using (HtmlTextWriter hw = new HtmlTextWriter(sw))
                {
                    //To Export all pages
                    GridView1.AllowPaging = false;
                    this.DataBind();

                    GridView1.RenderControl(hw);
                    StringReader sr         = new StringReader(sw.ToString());
                    Document     pdfDoc     = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                    HTMLWorker   htmlparser = new HTMLWorker(pdfDoc);
                    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
                    pdfDoc.Open();
                    htmlparser.Parse(sr);
                    pdfDoc.Close();

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=SecurityObligationReport.pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.Write(pdfDoc);
                    GridView1.AllowPaging = true;
                    Response.End();
                    GridView2.RenderControl(hw);
                    StringReader sr2         = new StringReader(sw.ToString());
                    Document     pdfDoc2     = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
                    HTMLWorker   htmlparser2 = new HTMLWorker(pdfDoc2);
                    PdfWriter.GetInstance(pdfDoc2, Response.OutputStream);
                    pdfDoc2.Open();
                    htmlparser2.Parse(sr2);
                    pdfDoc2.Close();

                    Response.ContentType = "application/pdf";
                    Response.AddHeader("content-disposition", "attachment;filename=FundsObligationReport.pdf");
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                    Response.Write(pdfDoc2);
                    Response.End();

                    GridView2.AllowPaging = true;
                }
            }

            //using (StringWriter sw = new StringWriter())
            //{
            //    using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            //    {
            //        //To Export all pages
            //        GridView2.AllowPaging = false;
            //        this.DataBind();

            //        GridView2.RenderControl(hw);
            //        StringReader sr = new StringReader(sw.ToString());
            //        Document pdfDoc = new Document(PageSize.A2, 10f, 10f, 10f, 0f);
            //        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
            //        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
            //        pdfDoc.Open();
            //        htmlparser.Parse(sr);
            //        pdfDoc.Close();

            //        Response.ContentType = "application/pdf";
            //        Response.AddHeader("content-disposition", "attachment;filename=FundsObligationReport.pdf");
            //        Response.Cache.SetCacheability(HttpCacheability.NoCache);
            //        Response.Write(pdfDoc);
            //        Response.End();

            //        GridView2.AllowPaging = true;
            //    }


            //}
        }
Ejemplo n.º 15
0
    private void SendPDFEmail(DataTable dt)
    {
        using (StringWriter sw = new StringWriter())
        {
            using (HtmlTextWriter hw = new HtmlTextWriter(sw))
            {
                //foreach (ListViewItem gg in GridView1.Items)
                //{

                //string companyName = ddlsection.SelectedItem.Text;
                //string orderNo = ddlclass.SelectedItem.Text;
                //StringBuilder sb = new StringBuilder();
                //sb.Append("<table width='100%' cellspacing='0' cellpadding='2'>");
                //sb.Append("<tr><td align='center' style='background-color: #18B5F0' colspan = '2'><b>" + ddlschool.SelectedItem.Text + "</b></td></tr>");
                //sb.Append("<tr><td colspan = '2'></td></tr>");
                //sb.Append("<tr><td><b>Class:</b>");
                //sb.Append(orderNo);
                //sb.Append("</td><td><b>Date: </b>");
                //sb.Append(txtdate.Text);
                //sb.Append(" </td></tr>");
                //sb.Append("<tr><td colspan = '2'><b>Section :</b> ");
                //sb.Append(companyName);
                //sb.Append("</td></tr>");
                //sb.Append("</table>");
                //sb.Append("<br />");
                //sb.Append("<table border = '1'>");
                //sb.Append("<tr>");
                //foreach (DataColumn column in dt.Columns)
                //{
                //    sb.Append("<th style = 'background-color: #D20B0C;color:#ffffff'>");
                //    sb.Append(column.ColumnName);
                //    sb.Append("</th>");
                //}
                //sb.Append("</tr>");
                //foreach (DataRow row in dt.Rows)
                //{
                //    sb.Append("<tr>");
                //    foreach (DataColumn column in dt.Columns)
                //    {
                //        sb.Append("<td>");
                //        sb.Append(row[column]);
                //        sb.Append("</td>");
                //    }
                //    sb.Append("</tr>");
                //}
                //sb.Append("</table>");
                //StringReader sr = new StringReader(sb.ToString());

                //Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
                //HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
                //using (MemoryStream memoryStream = new MemoryStream())
                //{
                //    PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream);
                //    pdfDoc.Open();
                //    htmlparser.Parse(sr);
                //    pdfDoc.Close();
                //    byte[] bytes = memoryStream.ToArray();
                //    memoryStream.Close();

                //    MailMessage mm = new MailMessage(email, email);

                //    mm.Subject = "Class Wise Report";
                //    mm.Body = "PDF Attachment";
                //    mm.Attachments.Add(new Attachment(new MemoryStream(bytes), "Report.pdf"));
                //    mm.IsBodyHtml = true;
                //    SmtpClient smtp = new SmtpClient();
                //    smtp.Host = "smtp.gmail.com";
                //    smtp.EnableSsl = true;
                //    NetworkCredential NetworkCred = new NetworkCredential("*****@*****.**", "passiong");
                //    smtp.UseDefaultCredentials = true;
                //    smtp.Credentials = NetworkCred;

                //    smtp.Port = 587;
                //    smtp.Send(mm);
                //}
                GridView1.RenderControl(hw);
                StringReader sr = new StringReader(sw.ToString());
                MailMessage  mm = new MailMessage("*****@*****.**", email);
                mm.Subject    = "Report";
                mm.Body       = "Daily Report:<hr />" + sw.ToString();;
                mm.IsBodyHtml = true;
                SmtpClient smtp = new SmtpClient();
                smtp.Host      = "smtp.gmail.com";
                smtp.EnableSsl = true;
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName       = "******";
                NetworkCred.Password       = "******";
                smtp.UseDefaultCredentials = true;
                smtp.Credentials           = NetworkCred;
                smtp.Port = 587;
                smtp.Send(mm);
            }
            // }
        }
    }
        protected void img_ExportToExcel1_Click(object sender, ImageClickEventArgs e)
        {
            if (txt_StCode.Text == string.Empty || txt_StCode.Text == "")
            {
                txt_StCode.Text   = "0";
                Session["stcode"] = txt_StCode.Text;
            }
            DataTable dt = ERB.GetLisAdamSabtenam(ddl_Term.SelectedValue, txt_StCode.Text, int.Parse(ddl_Degree.SelectedValue.ToString()), int.Parse(ddl_Education.SelectedValue.ToString()), int.Parse(ddl_Sex.SelectedValue.ToString()), txt_SalVorud.Text.ToString(), int.Parse(ddl_Field.SelectedValue));

            if (dt.Rows.Count == 0)
            {
            }
            else
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
                Response.Clear();
                Response.Buffer = true;
                Response.AddHeader("content-disposition", "attachment;filename=ReportNotRegistrationLicense.xls");
                Response.Charset     = "";
                Response.ContentType = "application/vnd.ms-excel";
                using (StringWriter sw = new StringWriter())
                {
                    HtmlTextWriter hw = new HtmlTextWriter(sw);

                    //To Export all pages
                    ////gv_Show.AllowPaging = false;
                    ////this.BindGrid();

                    //gv_Show.HeaderRow.BackColor = Color.White;
                    foreach (TableCell cell in GridView1.HeaderRow.Cells)
                    {
                        cell.BackColor = GridView1.HeaderStyle.BackColor;
                    }
                    foreach (GridViewRow row in GridView1.Rows)
                    {
                        //row.BackColor = Color.White;
                        foreach (TableCell cell in row.Cells)
                        {
                            if (row.RowIndex % 2 == 0)
                            {
                                cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                            }
                            else
                            {
                                cell.BackColor = GridView1.RowStyle.BackColor;
                            }
                            cell.CssClass = "textmode";
                        }
                    }

                    GridView1.RenderControl(hw);

                    //style to format numbers to string
                    string style = @"<style> .textmode { } </style>";
                    Response.Write(style);
                    Response.Output.Write(sw.ToString());
                    Response.Flush();
                    Response.End();
                }
            }
        }
Ejemplo n.º 17
0
    // Export data to Excel from Gridview

    protected void btnExport_Click(object sender, EventArgs e)
    {
        Response.Clear();
        Response.Buffer = true;

        Response.AddHeader("content-disposition",
                           "attachment;filename=Data Sources - Site Layers.xls");
        Response.Charset     = "";
        Response.ContentType = "application/vnd.ms-excel";
        StringWriter   sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);

        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.Caption = "Data Sources - Site Layers";

        //Change the Header Row back to white color
        GridView1.HeaderRow.Style.Add("background-color", "#FFFFFF");

        //Apply style to Individual Cells
        GridView1.HeaderRow.Cells[0].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[1].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[2].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[3].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[4].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[5].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[6].Style.Add("background-color", "green");
        GridView1.HeaderRow.Cells[7].Style.Add("background-color", "green");
        //GridView1.HeaderRow.Cells[8].Style.Add("background-color", "green");
        //GridView1.HeaderRow.Cells[9].Style.Add("background-color", "green");

        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            GridViewRow row = GridView1.Rows[i];

            //Change Color back to white
            row.BackColor = System.Drawing.Color.White;

            //Apply text style to each Row
            row.Attributes.Add("class", "textmode");

            //Apply style to Individual Cells of Alternating Row
            if (i % 2 != 0)
            {
                //    row.Cells[0].Style.Add("background-color", "#C2D69B");
                //    row.Cells[1].Style.Add("background-color", "#C2D69B");
                //    row.Cells[2].Style.Add("background-color", "#C2D69B");
                //    row.Cells[3].Style.Add("background-color", "#C2D69B");
            }
        }

        GridView1.RenderControl(hw);

        //style to format numbers to string
        string style = @"<style> .textmode { mso-number-format:\@; } </style>";

        // Eliminate the Hyperlinks from the exported columns
        Response.Write(Regex.Replace(sw.ToString(), @"(<a[^>]*>)|
                            (</a>)", " ", RegexOptions.IgnoreCase));
        // Response.Write(style);
        // Response.Output.Write(sw.ToString());
        Response.Flush();
        Response.End();
    }
Ejemplo n.º 18
0
        protected void img_ExportToExcel1_Click(object sender, ImageClickEventArgs e)
        {
            if (txt_CodeOstad.Text == null || txt_CodeOstad.Text == "")
            {
                txt_CodeOstad.Text = "0";
            }
            DataTable dt = new DataTable();

            if (rdb_Tuition.Checked == true)
            {
                dt = FRB.GetListTuition(ddl_Term.SelectedValue, int.Parse(ddl_Cooperation.SelectedValue), int.Parse(ddl_CodeGroup.SelectedValue), int.Parse(ddl_Daneshkade.SelectedValue), int.Parse(txt_CodeOstad.Text));
                if (dt.Rows.Count > 0)
                {
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                    Response.Clear();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", "attachment;filename=ReportConflictClassbyNumberClass.xls");
                    Response.Charset     = "";
                    Response.ContentType = "application/vnd.ms-excel";
                    using (StringWriter sw = new StringWriter())
                    {
                        HtmlTextWriter hw = new HtmlTextWriter(sw);

                        //To Export all pages
                        ////gv_Show.AllowPaging = false;
                        ////this.BindGrid();

                        //gv_Show.HeaderRow.BackColor = Color.White;
                        foreach (TableCell cell in GridView1.HeaderRow.Cells)
                        {
                            cell.BackColor = GridView1.HeaderStyle.BackColor;
                        }
                        foreach (GridViewRow row in GridView1.Rows)
                        {
                            //row.BackColor = Color.White;
                            foreach (TableCell cell in row.Cells)
                            {
                                if (row.RowIndex % 2 == 0)
                                {
                                    cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                                }
                                else
                                {
                                    cell.BackColor = GridView1.RowStyle.BackColor;
                                }
                                cell.CssClass = "textmode";
                            }
                        }

                        GridView1.RenderControl(hw);

                        //style to format numbers to string
                        string style = @"<style> .textmode { mso-number-format:\@; } </style>";
                        Response.Write(style);
                        Response.Output.Write(sw.ToString());
                        Response.Flush();
                        Response.End();
                    }
                }
            }
            else
            {
                dt = FRB.GetListTuition2(ddl_Term.SelectedValue, int.Parse(ddl_Cooperation.SelectedValue), int.Parse(ddl_CodeGroup.SelectedValue), int.Parse(ddl_Daneshkade.SelectedValue), int.Parse(txt_CodeOstad.Text));
                if (dt.Rows.Count > 0)
                {
                    GridView2.DataSource = dt;
                    GridView2.DataBind();
                    Response.Clear();
                    Response.Buffer = true;
                    Response.AddHeader("content-disposition", "attachment;filename=ReportConflictClassbyNumberClass.xls");
                    Response.Charset     = "";
                    Response.ContentType = "application/vnd.ms-excel";
                    using (StringWriter sw = new StringWriter())
                    {
                        HtmlTextWriter hw = new HtmlTextWriter(sw);

                        //To Export all pages
                        ////gv_Show.AllowPaging = false;
                        ////this.BindGrid();

                        //gv_Show.HeaderRow.BackColor = Color.White;
                        foreach (TableCell cell in GridView2.HeaderRow.Cells)
                        {
                            cell.BackColor = GridView1.HeaderStyle.BackColor;
                        }
                        foreach (GridViewRow row in GridView2.Rows)
                        {
                            int c = 0;
                            //row.BackColor = Color.White;
                            foreach (TableCell cell in row.Cells)
                            {
                                if (row.RowIndex % 2 == 0)
                                {
                                    cell.BackColor = GridView2.AlternatingRowStyle.BackColor;
                                }
                                else
                                {
                                    cell.BackColor = GridView2.RowStyle.BackColor;
                                }
                                if (c == 15)
                                {
                                    cell.CssClass = "textmode";
                                }
                                else
                                {
                                    cell.CssClass = "textmode";
                                }
                            }
                        }

                        GridView2.RenderControl(hw);

                        //style to format numbers to string
                        string style = @"<style> .textmode { }
.num {
  mso-number-format:\#\,\#\#0\.00;}</style>";
                        Response.Write(style);
                        Response.Output.Write(sw.ToString());
                        Response.Flush();
                        Response.End();
                    }
                }
            }
        }
Ejemplo n.º 19
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            String strfilename = "Breakdown Aging Report ";

            Response.ClearContent();

            Response.AddHeader("content-disposition", string.Format("attachment; filename=" + strfilename + DateTime.Now.ToString("yyyy-MM-dd HH::mm") + ".xls"));

            Response.ContentType = "application/vnd.ms-excel";

            // string space = "";

            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages
                GridView1.AllowPaging = false;

                string        connString = ConfigurationManager.ConnectionStrings["tomms_prodConnectionString"].ConnectionString;
                SqlConnection con        = null;
                con = new SqlConnection(connString);
                con.Open();


                SqlCommand cmd = new SqlCommand("exec SP_Ageing_Report_out '" + DropDownState.SelectedItem.Text + "','" +
                                                DropDownDistrict.SelectedItem.Text + "','" + DropDowncircle.SelectedItem.Text + "','" + DropDownCliniccat.SelectedItem.Text + "','" +
                                                DropDownBECate.SelectedItem.Value + "','" + DropDownOwner.SelectedItem.Text + "'", con);
                //SqlCommand cmd = new SqlCommand("exec SP_Ageing_Report_out '1','2','3','4','5'", con);
                cmd.CommandTimeout = 1000;

                SqlDataAdapter Adpt = new SqlDataAdapter(cmd);
                DataTable      dt1  = new DataTable();
                Adpt.Fill(dt1);
                GridView1.DataSource = dt1;
                GridView1.DataBind();

                GridView1.HeaderRow.BackColor = Color.White;
                foreach (TableCell cell in GridView1.HeaderRow.Cells)
                {
                    cell.BackColor = GridView1.HeaderStyle.BackColor;
                }
                foreach (GridViewRow row in GridView1.Rows)
                {
                    row.BackColor = Color.White;
                    foreach (TableCell cell in row.Cells)
                    {
                        if (row.RowIndex % 2 == 0)
                        {
                            cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                        }
                        else
                        {
                            cell.BackColor = GridView1.RowStyle.BackColor;
                        }
                        cell.CssClass = "textmode";
                    }
                }

                GridView1.RenderControl(hw);

                //style to format numbers to string
                string style = @"<style> .textmode { } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());
                Response.Flush();
                Response.End();
            }
        }
        protected void btnreport_Click(object sender, EventArgs e)
        {
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages
                //Page_Load(sender, e);
                GridView1.AllowPaging = false;
                //GridView1.Columns[0].Visible = false;
                GridView1.Columns[19].Visible = false;
                GridView1.AllowSorting        = false;
                GridView1.DataSourceID        = "SqlDataSource1";
                GridView1.DataBind();

                foreach (GridViewRow row in GridView1.Rows)
                {
                    foreach (TableCell cell in row.Cells)
                    {
                        List <Control> controls = new List <Control>();
                        foreach (Control control in cell.Controls)
                        {
                            switch (control.GetType().Name)
                            {
                            case "HyperLink":
                                controls.Add(control);
                                break;

                            case "TextBox":
                                controls.Add(control);
                                break;

                            case "LinkButton":
                                controls.Add(control);
                                break;

                            case "CheckBox":
                                controls.Add(control);
                                break;

                            case "RadioButton":
                                controls.Add(control);
                                break;

                            case "Image":
                                controls.Add(control);
                                break;
                            }
                        }
                        foreach (Control control in controls)
                        {
                            switch (control.GetType().Name)
                            {
                            case "HyperLink":
                                cell.Controls.Add(new Literal {
                                    Text = (control as HyperLink).Text
                                });
                                break;

                            case "TextBox":
                                cell.Controls.Add(new Literal {
                                    Text = (control as TextBox).Text
                                });
                                break;

                            case "LinkButton":
                                cell.Controls.Add(new Literal {
                                    Text = (control as LinkButton).Text
                                });
                                break;

                            case "CheckBox":
                                cell.Controls.Add(new Literal {
                                    Text = (control as CheckBox).Text
                                });
                                break;

                            case "RadioButton":
                                cell.Controls.Add(new Literal {
                                    Text = (control as RadioButton).Text
                                });
                                break;

                            case "Image":
                                cell.Controls.Add(new Literal {
                                    Text = (control as System.Web.UI.WebControls.Image).AlternateText = ""
                                });
                                break;
                            }
                            cell.Controls.Remove(control);
                        }
                    }
                }
                GridView1.GridLines = GridLines.Both;
                Response.AddHeader("content-disposition", "attachment;filename=IncidentMasterReport.xls");
                Response.Charset     = String.Empty;
                Response.ContentType = "application/vnd.xls";
                GridView1.RenderControl(hw);
                Response.Write(sw.ToString());
                Response.Flush();
                Response.End();
                Response.Redirect("Search.aspx");
            }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
            string SchoolID = Session["SchoolId"].ToString();


            exportdiv.Style.Remove("display");
            Response.Clear();
            Response.Buffer = true;
            Response.AddHeader("content-disposition", "attachment;filename=StudentDetails " + DateTime.Now.ToShortTimeString() + ".xls");
            Response.Charset     = "";
            Response.ContentType = "application/vnd.ms-excel";
            using (StringWriter sw = new StringWriter())
            {
                HtmlTextWriter hw = new HtmlTextWriter(sw);

                //To Export all pages
                GridView1.AllowPaging = false;
                this.BindGrid();

                GridView1.HeaderRow.BackColor = Color.White;
                foreach (TableCell cell in GridView1.HeaderRow.Cells)
                {
                    cell.BackColor = GridView1.HeaderStyle.BackColor;
                }
                foreach (GridViewRow row in GridView1.Rows)
                {
                    row.BackColor = Color.White;
                    foreach (TableCell cell in row.Cells)
                    {
                        if (row.RowIndex % 2 == 0)
                        {
                            cell.BackColor = GridView1.AlternatingRowStyle.BackColor;
                        }
                        else
                        {
                            cell.BackColor = GridView1.RowStyle.BackColor;
                        }
                        cell.CssClass = "textmode";
                    }
                }

                GridView1.RenderControl(hw);

                //style to format numbers to string
                string style = @"<style> .textmode { } </style>";
                Response.Write(style);
                Response.Output.Write(sw.ToString());


                //Retrieve the state of the CheckBox
                prStdDetail.SchoolUID = SchoolID;
                prStdDetail.ScholarNo = "0000";
                string retCode = clsStdDetail.DeleteStudetDetail(prStdDetail);
                if (retCode != "1")
                {
                    divsucrss.Style.Add("display", "none");
                    divUnsucrss.Style.Remove("display");
                    ltrNotSucess.Text = retCode + "There are some error contact to admin !!";
                }
                else
                {
                    divUnsucrss.Style.Add("display", "none");
                    divsucrss.Style.Remove("display");
                    ltrSucess.Text = "Data Deleted Sucess  ";
                }

                Response.Flush();
                Response.End();
                exportdiv.Style.Add("display", "none");
            }
        }