导出GridView时如何屏蔽信用卡中的数字? [英] How can I mask digits from a credit card when exporting a GridView?

查看:58
本文介绍了导出GridView时如何屏蔽信用卡中的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是我要屏蔽一些16位数的信用卡号码。我想屏蔽的号码位置是前6位数字的第7位到第12位,最后4位数字没有被屏蔽。信用卡号码存储在boundfield中,并且是字符串类型。然后我将网页数据导出到excel表格。我想要执行的屏蔽过程是在文件导出后意味着卡号应该显示原创在网页上,但当我下载excel表时,应该屏蔽卡号。我使用的是Oracle数据库,Microsoft Visual Studio 2008作为IDE和C#ASP.NET框架3.5。提前致谢,对不起这个问题的长度。







My question is that i want to mask some numbers of credit card number which is of 16 digits.The positions of the numbers which i want to mask are from 7th to 12th the first six numbers and the last four numbers are not masked.The credit card numbers are being stored in boundfield and are of string type.Then i am exporting the web page data into an excel sheet.The process of masking which i want to perform is after the file is exported meaning the card number should show original on web page but when i will download it excel sheet the card number should be masked.I am using Oracle database, Microsoft Visual Studio 2008 as IDE and C# ASP.NET framework 3.5. Thanks in advance and sorry for the question's length.



using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.IO;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
    
 protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridview();
}
}
protected void BindGridview()
{
DataSet ds = new DataSet();
{
con.Open();
OracleCommand cmd = new OracleCommand("select * from CAPTURED_CARD_REPORTING where CARD_NO is not null", con);
OracleDataAdapter da = new OracleDataAdapter(cmd);
da.Fill(ds);
con.Close();
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
}
protected void gvDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && gvDetails.EditIndex == e.Row.RowIndex)
{
{
con.Open();
DropDownList ddlcard = (DropDownList)e.Row.FindControl("ddlreturn_to_customer");
con.Close();
ddlcard.Items.Insert(0, new ListItem("--Select--","-1"));
ddlcard.Items.Insert(1, new ListItem("Yes","Y"));
ddlcard.Items.Insert(2, new ListItem("No","N"));
}
}
}
protected void gvDetails_RowEditing(object sender, GridViewEditEventArgs e)
{
gvDetails.EditIndex = e.NewEditIndex;
BindGridview();
}
protected void gvDetails_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvDetails.EditIndex = -1;
BindGridview();
}
protected void gvDetails_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvDetails.PageIndex = e.NewPageIndex;
BindGridview();
}
protected void gvDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    
{
string card_no = Convert.ToString(gvDetails.DataKeys[e.RowIndex].Value.ToString());
string branch_code = Convert.ToString(gvDetails.Rows[e.RowIndex].Cells[1].Text);
DropDownList ddlreturn_to_customer = (DropDownList)gvDetails.Rows[e.RowIndex].FindControl("ddlreturn_to_customer");
con.Open();
OracleCommand cmd = new OracleCommand("update CAPTURED_CARD_REPORTING set RETURN_TO_CUSTOMER='" + ddlreturn_to_customer.SelectedValue + "' where CARD_NO='" + card_no + "'  and BRANCH_CODE='" + branch_code + "' ", con);
cmd.ExecuteNonQuery();
lblresult.ForeColor = Color.Green;
lblresult.Text = " Details Updated successfully";
gvDetails.EditIndex = -1;
BindGridview();
con.Close();
}
}
protected DataSet BindDatatable()
{
    OracleDataAdapter adapter = new OracleDataAdapter();
    DataSet ds = new DataSet();
    string oracle = null;
    oracle = "select CARD_NO , BRANCH_CODE , BANK_NAME , RETURN_TO_CUSTOMER from CAPTURED_CARD_REPORTING where CARD_NO is not null";
    OracleConnection connection = new OracleConnection(connetionString);
    connection.Open();
    OracleCommand command = new OracleCommand(oracle, connection);
    adapter.SelectCommand = command;
    adapter.Fill(ds);
    connection.Close();
    gvDetails.DataSource = ds.Tables[0];
    gvDetails.DataBind();
    return ds;
}
public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}
protected void ExportFile(string fileName, string contentType)
{
    //disable paging to export all data and make sure to bind griddata before begin
    Response.ClearContent();
    Response.Buffer = true;
    Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", fileName));
    Response.ContentType = contentType;
    StringWriter objSW = new StringWriter();
    HtmlTextWriter objTW = new HtmlTextWriter(objSW);
    gvDetails.AllowPaging = false;
    BindDatatable();
    gvDetails.Columns[4].Visible = false;
    gvDetails.RenderControl(objTW);
    Response.Write(objSW);
    Response.End();
}
protected void btnExport_Click(object sender, EventArgs e)
{
    string fileName = "ExportToExcel_" + DateTime.Now.ToShortDateString() + ".xls",
    contentType = "application/vnd.ms-excel";

    //call 1st export method with fileName and contentType
    ExportFile(fileName, contentType);

}

protected void gvDetails_SelectedIndexChanged(object sender, EventArgs e)
{

}
}

推荐答案

您好,



在您的代码中,在创建流式编写器时,

Hi,

In your code, while creating the stream writer,
StringWriter objSW = new StringWriter();
   HtmlTextWriter objTW = new HtmlTextWriter(objSW);





可修改为





That can be modified as

 using (StringWriter sw = new StringWriter())
    {
        HtmlTextWriter hw = new HtmlTextWriter(sw);
 
        //To Export all pages
        GridView1.AllowPaging = false;
        this.BindGrid();
 foreach (GridViewRow row in GridView1.Rows)
        {
//here go by the row index you want to modify the text.
}
//your remaining code
gvDetails.AllowPaging = false;
    BindDatatable();
    gvDetails.Columns[4].Visible = false;
    gvDetails.RenderControl(objTW);
    Response.Write(objSW);
    Response.End();
}





或者如果循环很多并且你可以使用excel模板,那么你可以参考这篇文章,



http://www.c-sharpcorner.com/UploadFile/pandeypradip/export-data-into-excel-in-a-pre-defined-template-using-strea/ [ ^ ]



这未经过测试。只是为了给你一个想法。

希望这会有所帮助。



快乐编码!



Or if looping through is much and you can make use of a excel template, then you can refer this article,

http://www.c-sharpcorner.com/UploadFile/pandeypradip/export-data-into-excel-in-a-pre-defined-template-using-strea/[^]

This is not tested.Its just to give you an idea.
Hope this helps.

Happy coding!


这篇关于导出GridView时如何屏蔽信用卡中的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆