private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
DataTable dtList=new DataTable();
dtList=GetQuery(DropDownList1.SelectedIndex);
this.DataGrid1.DataSource=dtList.DefaultView;
this.DataGrid1.DataBind();
}
}
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataTable dtList=new DataTable();
dtList=GetQuery(DropDownList1.SelectedIndex);
this.DataGrid1.DataSource=dtList.DefaultView;
this.DataGrid1.DataBind();
}
private DataTable GetQuery(int SelectIndex)
{
string strCmdText="";
SqlConnection conn =new SqlConnection();
DataSet ds = new DataSet();
DataTable dtResult = new DataTable("QueryDateTime");
ds.Tables.Add("QueryDateTime");
switch(SelectIndex)
{
case 0:
strCmdText="select staff_name as 姓名,staff_sex as 性別,staff_native as 籍貫,staff_diploma as 學歷,staff_ismarry as 婚否 ,staff_birthday as 出生年月 ,staff_identitycard as 證件號碼,staff_skill as 特長,staff_old_dept as 原單位,staff_old_leavedate as 離職時間,staff_rapport as 關係,introducer_dept as 介紹人部門,introducer_name as 介紹人姓名,introducer_indate as 入廠時間 from Staff_Register ";
conn=DBC.CreateDB();
break;
case 1:
strCmdText="select staff_name as 姓名,staff_sex as 性別,staff_native as 籍貫,staff_diploma as 學歷,staff_ismarry as 婚否 ,staff_birthday as 出生年月 ,staff_identitycard as 證件號碼,staff_skill as 特長,staff_old_dept as 原單位,staff_old_leavedate as 離職時間,staff_rapport as 關係,introducer_dept as 介紹人部門,introducer_name as 介紹人姓名,introducer_indate as 入廠時間 from Staff_Register where staff_identitycard not in (select staff_identitycard from Staff_Register where staff_identitycard in (select id_no from [it-srv-db1].fc_person_data.dbo.trans_staff where status>0)) and staff_identitycard not in (select staff_identitycard from [it-srv-db1].fc_person_data.dbo.trans_staff Where out_date Is Not Null And out_date<>'' Or datediff(dd,in_date,getdate())<30) and staff_identitycard not in (select staff_identitycard from Staff_Register A, (select department_no,staff_name,introducer_remark,in_date from [it-srv-db1].fc_person_data.dbo.trans_staff where datediff(dd,in_date,getdate())<30 ) B Where A.introducer_name=B.staff_name) and staff_identitycard not in (select staff_identitycard from Staff_Register where datediff(yy,staff_birthday,getdate())<18 Or datediff(yy,staff_birthday,getdate())>35)";
conn=DBC.CreateDB();
break;
case 2:
strCmdText="select staff_name as 姓名,staff_identitycard as 身份證號碼 from Staff_Register where staff_identitycard in (select id_no from [it-srv-db1].fc_person_data.dbo.trans_staff where status>0) ";
conn=DBC.CreateDB();
break;
case 3:
strCmdText="select A.staff_name as 姓名,staff_sex as 性別,staff_native as 籍貫,B.out_date as 出廠日期 from Staff_Register A Inner Join [it-srv-db1].fc_person_data.dbo.trans_staff B On A.staff_identitycard=B.id_no And (B.id_no is null Or datediff(dd,B.out_date,getdate())<30)";
conn=DBC.CreateDB();
break;
case 4:
strCmdText="select A.staff_name as 姓名 ,B.staff_name as 介紹人姓名 ,B.department_no as 介紹人部門,B.introducer_remark as 介紹人關係,B.in_date as 入敞時間 from Staff_Register A, (select department_no,staff_name,introducer_remark,in_date from [it-srv-db1].fc_person_data.dbo.trans_staff where datediff(dd,in_date,getdate())<30 ) B Where A.introducer_name=B.staff_name ";
conn=DBC.CreateDB();
break;
case 5:
strCmdText="select staff_name as 姓名,staff_birthday as 出生年月 from Staff_Register where datediff(yy,staff_birthday,getdate())<18 Or datediff(yy,staff_birthday,getdate())>35 order by staff_birthday desc";
conn=DBC.CreateDB();
break;
}
SqlDataAdapter sqlDA = new SqlDataAdapter(strCmdText,conn);
sqlDA.Fill(ds,"QueryDateTime");
dtResult=ds.Tables[0];
return dtResult;
}
private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex=e.NewPageIndex;
}