如何设置日期限制?

时间:2014-06-30 02:49:52

标签: asp.net

我正在建立一个网站,其中将会有一个不同的用户登录.DIN ADMIN,SUPERVISOR和SUPERVISEE。现在我正在为主管做屏幕。当主管登录时,他/她将被重定向到一个页面,其中所有他/她的受监管者的数据都显示在网格视图中。他/她的数据也包含在gridview中。但问题是,主管有一个日期限制,成为每个受监管者的主管。 例如,主管A将监督受监管者B,C和D.主管A监督B和C的日期限制是从2012年1月至2014年12月,而主管A监督D的日期限制是从2011年1月到2013年12月。 因此,gridview应该只显示受监管者B和C的记录,因为日期限制仍然有效。但是怎么做呢?目前,gridview正在显示所有记录..

以下是我的服务器端代码。请帮忙

protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
string emnum_supervisor = null;
string svname = null;

if (Session["username"] != null)
{
svname = Session["username"].ToString();
}

OdbcConnection connection = null; //declaration for connection variable for odbcconnection
OdbcCommand com = null;
OdbcDataReader reader = null; // declaration to read the data

string queryString = "SELECT EMNUM FROM QMBSTEST.TBLEMP WHERE EMUSID = '" + svname.ToString() + "'";
connection = new OdbcConnection(@"Dsn=as400;Uid=FATIN;Pwd=FATIN;");

com = new OdbcCommand(queryString, connection); // execute the command (queryString) and the connection (connection)

connection.Open();

reader = com.ExecuteReader(); //Execute odbc data reader (reader)

while (reader.Read()) //reading data from database
{
emnum_supervisor = reader.GetValue(0).ToString(); //get sv number from gridview
tb_emnum_supervisor.Text = emnum_supervisor;
}

connection.Close();

// TO BIND DATA TO GRIDVIEW
string queryBindGrid = "SELECT QMBSTEST.SCEMLV.LVDTST, QMBSTEST.SCEMLV.LVEMID, QMBSTEST.TBLEMP.EMNAME, QMBSTEST.SCEMLV.LVDAYS, QMBSTEST.SCEMLV.LVTYPE, QMBSTEST.SCEMLV.LVAPPV " + 
"FROM QMBSTEST.TBLMTX INNER JOIN QMBSTEST.TBLEMP ON QMBSTEST.TBLMTX.EMNUM = QMBSTEST.TBLEMP.EMNUM INNER JOIN " +
"QMBSTEST.SCEMLV ON QMBSTEST.TBLEMP.EMNUM = QMBSTEST.SCEMLV.LVEMID " +
"WHERE QMBSTEST.TBLMTX.EMSPVR = '" + emnum_supervisor + "'" + " UNION " +
"SELECT QMBSTEST.SCEMLV.LVDTST, QMBSTEST.SCEMLV.LVEMID, QMBSTEST.TBLEMP.EMNAME, QMBSTEST.SCEMLV.LVDAYS, QMBSTEST.SCEMLV.LVTYPE, QMBSTEST.SCEMLV.LVAPPV " +
"FROM QMBSTEST.SCEMLV INNER JOIN QMBSTEST.TBLEMP ON QMBSTEST.TBLEMP.EMNUM = QMBSTEST.SCEMLV.LVEMID " +
"WHERE QMBSTEST.SCEMLV.LVEMID = '" + emnum_supervisor + "'";


connection = new OdbcConnection(@"Dsn=as400;Uid=FATIN;Pwd=FATIN;");

DataTable dt = new DataTable();
OdbcDataAdapter adapter = new OdbcDataAdapter(queryBindGrid, connection);
DataSet ds = new DataSet();
try
{
connection.Open(); adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}

// FOR DDL
string queryddl = "SELECT DISTINCT QMBSTEST.TBLEMP.EMNUM, QMBSTEST.TBLEMP.EMNAME " + 
"FROM QMBSTEST.TBLMTX INNER JOIN QMBSTEST.TBLEMP ON QMBSTEST.TBLMTX.EMNUM = QMBSTEST.TBLEMP.EMNUM INNER JOIN " +
"QMBSTEST.SCEMLV ON QMBSTEST.TBLEMP.EMNUM = QMBSTEST.SCEMLV.LVEMID " +
"WHERE QMBSTEST.TBLMTX.EMSPVR = '" + emnum_supervisor + "'" + " UNION " +
"SELECT QMBSTEST.TBLEMP.EMNUM, QMBSTEST.TBLEMP.EMNAME FROM QMBSTEST.TBLEMP " +
"WHERE QMBSTEST.TBLEMP.EMNUM = '" + emnum_supervisor + "'";

connection = new OdbcConnection(@"Dsn=as400;Uid=FATIN;Pwd=FATIN;");

OdbcDataAdapter oda = new OdbcDataAdapter(queryddl, connection);
DataSet dset = new DataSet();
oda.Fill(dset);
ddl1.Items.Clear();

ddl1.DataSource = dset;
ddl1.DataValueField = "EMNUM";
ddl1.DataTextField = "EMNAME";
ddl1.DataBind();
ddl1.Items.Insert(0, new ListItem("ALL EMPLOYEES", "ALL"));

}
}

protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
OdbcConnection connection = null;
string query = "";

if (ddl1.SelectedValue != "ALL")
{ 
query = "SELECT QMBSTEST.SCEMLV.LVDTST, QMBSTEST.SCEMLV.LVEMID, QMBSTEST.TBLEMP.EMNAME, QMBSTEST.SCEMLV.LVDAYS, QMBSTEST.SCEMLV.LVTYPE, QMBSTEST.SCEMLV.LVAPPV " +
"FROM QMBSTEST.SCEMLV INNER JOIN QMBSTEST.TBLEMP ON QMBSTEST.TBLEMP.EMNUM = QMBSTEST.SCEMLV.LVEMID " +
"WHERE QMBSTEST.SCEMLV.LVEMID = '" + ddl1.SelectedValue + "'";
}
else
{
query = "SELECT QMBSTEST.SCEMLV.LVDTST, QMBSTEST.SCEMLV.LVEMID, QMBSTEST.TBLEMP.EMNAME, QMBSTEST.SCEMLV.LVDAYS, QMBSTEST.SCEMLV.LVTYPE, QMBSTEST.SCEMLV.LVAPPV " +
"FROM QMBSTEST.TBLMTX INNER JOIN QMBSTEST.TBLEMP ON QMBSTEST.TBLMTX.EMNUM = QMBSTEST.TBLEMP.EMNUM INNER JOIN " +
"QMBSTEST.SCEMLV ON QMBSTEST.TBLEMP.EMNUM = QMBSTEST.SCEMLV.LVEMID " +
"WHERE QMBSTEST.TBLMTX.EMSPVR = '" + tb_emnum_supervisor.Text.Trim() + "'" + " UNION " +
"SELECT QMBSTEST.SCEMLV.LVDTST, QMBSTEST.SCEMLV.LVEMID, QMBSTEST.TBLEMP.EMNAME, QMBSTEST.SCEMLV.LVDAYS, QMBSTEST.SCEMLV.LVTYPE, QMBSTEST.SCEMLV.LVAPPV " +
"FROM QMBSTEST.SCEMLV INNER JOIN QMBSTEST.TBLEMP ON QMBSTEST.TBLEMP.EMNUM = QMBSTEST.SCEMLV.LVEMID " +
"WHERE QMBSTEST.SCEMLV.LVEMID = '" + tb_emnum_supervisor.Text.Trim() + "'";
}


connection = new OdbcConnection(@"Dsn=as400;Uid=FATIN;Pwd=FATIN;");

DataTable dt = new DataTable();
OdbcDataAdapter adapter = new OdbcDataAdapter(query, connection);
DataSet ds = new DataSet();
try
{
connection.Open();
adapter.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
catch (Exception ex)
{
throw ex;
}
}

0 个答案:

没有答案