Beispiel #1
0
    protected void btnExport_Click(object sender, EventArgs e)
    {
        int    CountyID = 0;
        int    TownID   = 0;
        string BirthDateS;
        string BirthDateE;
        string CaseName;
        string CaseIdNo;
        string SearchReason;
        string SearchConditions = "";
        string ReportFields     = "";
        int    SearcResultCount = 0;
        int    IsSearch         = 0;
        int    SearchKind       = 3;

        BirthDateS = Request.Form["BirthDateS"] ?? "";
        BirthDateE = Request.Form["BirthDateE"] ?? "";
        if (BirthDateS != "")
        {
            try
            {
                BirthDateS = TaiwanYear.ToDateTime(BirthDateS).ToString("yyyyMMdd");
            }
            catch
            {
                BirthDateS = "";
            }
        }
        if (BirthDateE != "")
        {
            try
            {
                BirthDateE = TaiwanYear.ToDateTime(BirthDateE).ToString("yyyyMMdd");
            }
            catch
            {
                BirthDateE = "";
            }
        }

        CaseName = Request.Form["CaseName"] ?? "";
        CaseIdNo = Request.Form["CaseIdNo"] ?? "";
        int.TryParse(Request.Form["CountyID"], out CountyID);
        int.TryParse(Request.Form["TownID"], out TownID);
        int.TryParse(Request.Form["IsSearch"], out IsSearch);
        SearchReason = Request.Form["SearchReason"] ?? "";
        foreach (ListItem item in cblReportFields.Items)
        {
            if (item.Selected)
            {
                ReportFields += item.Value + ",";
            }
        }
        ReportFields = ReportFields.TrimEnd(',');

        // Response.Write(string.Format("exec dbo.usp_CaseUser_xGetUserListExport {0},{1},{2},{3},{4},{5},{6} ", CaseName, CaseIdNo, BirthDateS, BirthDateE, CountyID.ToString(), TownID.ToString(), ReportFields));
        //  Response.Write(ReportFields);
        DataTable dt = new DataTable();

        try
        {
            dt = (DataTable)DBUtil.DBOp("ConnDB", "exec dbo.usp_CaseUser_xGetUserListExport {0},{1},{2},{3},{4},{5},{6} ", new string[] { CaseName, CaseIdNo, BirthDateS, BirthDateE, CountyID.ToString(), TownID.ToString(), ReportFields }, NSDBUtil.CmdOpType.ExecuteReaderReturnDataTable);

            SearcResultCount = dt.Rows.Count;
        }
        catch
        {
        }
        finally {
            DBUtil.DBOp("ConnDB", " exec [dbo].[usp_CaseUser_xAddSearchLog] {0}, {1}, {2} ,{3} ,{4}", new string[] { AuthServer.GetLoginUser().ID.ToString(), SearchConditions, SearchReason, SearcResultCount.ToString(), SearchKind.ToString() }, NSDBUtil.CmdOpType.ExecuteNonQuery);
        }
        ExportToFile etf = new ExportToFile();

        etf.ExporttoExcel(dt, "批次資料勾稽");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        base.AllowHttpMethod("POST");
        base.DisableTop(true);
        int    pgNow;
        int    pgSize;
        int    CountyID = 0;
        int    TownID   = 0;
        string BirthDateS;
        string BirthDateE;
        string CaseName;
        string CaseIdNo;
        string SearchReason;
        string SearchConditions = "";
        int    SearcResultCount = 0;
        int    IsSearch         = 0;
        int    SearchKind       = 3;


        BirthDateS = Request.Form["BirthDateS"] ?? "";
        BirthDateE = Request.Form["BirthDateE"] ?? "";
        if (BirthDateS != "")
        {
            try
            {
                //BirthDateS = Convert.ToDateTime(BirthDateS).ToString("yyyyMMdd");
                BirthDateS = TaiwanYear.ToDateTime(BirthDateS).ToString("yyyyMMdd");
            }
            catch {
                BirthDateS = "";
            }
        }
        if (BirthDateE != "")
        {
            try
            {
                // BirthDateE = Convert.ToDateTime(BirthDateE).ToString("yyyyMMdd");
                BirthDateE = TaiwanYear.ToDateTime(BirthDateE).ToString("yyyyMMdd");
            }
            catch
            {
                BirthDateE = "";
            }
        }

        CaseName = Request.Form["CaseName"] ?? "";
        CaseIdNo = Request.Form["CaseIdNo"] ?? "";


        int.TryParse(Request.Form["pgNow"], out pgNow);
        int.TryParse(Request.Form["pgSize"], out pgSize);
        int.TryParse(Request.Form["CountyID"], out CountyID);
        int.TryParse(Request.Form["TownID"], out TownID);
        int.TryParse(Request.Form["IsSearch"], out IsSearch);
        SearchReason = Request.Form["SearchReason"] ?? "";


        List <UserProfileListVM> list = new List <UserProfileListVM>();
        PageVM  rtn = new PageVM();
        DataSet ds  = new DataSet();


        try
        {
            using (SqlConnection sc = new SqlConnection(WebConfigurationManager.ConnectionStrings["ConnDB"].ToString()))
            {
                using (SqlCommand cmd = new SqlCommand("dbo.usp_CaseUser_xGetUserList", sc))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@pgNow", pgNow == 0 ? 1 : pgNow);
                    cmd.Parameters.AddWithValue("@pgSize", pgSize == 0 ? 10 : pgSize);
                    cmd.Parameters.AddWithValue("@BirthDateS", BirthDateS);
                    cmd.Parameters.AddWithValue("@BirthDateE", BirthDateE);
                    cmd.Parameters.AddWithValue("@CaseName", CaseName);
                    cmd.Parameters.AddWithValue("@CaseIdNo", CaseIdNo);
                    cmd.Parameters.AddWithValue("@CountyID", CountyID);
                    cmd.Parameters.AddWithValue("@TownID", TownID);
                    //cmd.Parameters.AddWithValue("@IsSearch", IsSearch);
                    //cmd.Parameters.AddWithValue("@SearchReason", SearchReason);

                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        sc.Open();
                        da.Fill(ds);
                    }
                }
            }

            SearcResultCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);

            EntityS.FillModel(list, ds.Tables[0]);
            EntityS.FillModel(rtn, ds.Tables[1]);
        }
        catch
        {
        }
        finally {
            //記下查詢紀錄

            if (IsSearch == 1)
            {
                if (CaseName != "")
                {
                    SearchConditions += "姓名:" + CaseName;
                }
                if (CaseIdNo != "")
                {
                    SearchConditions += "身份證號:" + CaseIdNo;
                }
                if (BirthDateS != "")
                {
                    SearchConditions += "生日起日:" + BirthDateS;
                }
                if (BirthDateE != "")
                {
                    SearchConditions += "生日迄日:" + BirthDateE;
                }
                if (CountyID != 0)
                {
                    SearchConditions += "戶籍縣市:" + SystemAreaCode.GetName(CountyID);
                }
                if (TownID != 0)
                {
                    SearchConditions += "戶籍鄉鎮:" + SystemAreaCode.GetName(TownID);
                }

                Session["SearchID"] = Convert.ToInt32(DBUtil.DBOp("ConnDB", " exec [dbo].[usp_CaseUser_xAddSearchLog] {0}, {1}, {2} ,{3} ,{4}", new string[] { AuthServer.GetLoginUser().ID.ToString(), SearchConditions, SearchReason, SearcResultCount.ToString(), SearchKind.ToString() }, NSDBUtil.CmdOpType.ExecuteScalar));
            }
        }
        rtn.message = list;

        Response.ContentType = "application/json; charset=utf-8";
        Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(rtn));
        Response.End();
    }