using DocumentFormat.OpenXml.Drawing.Charts; using DocumentFormat.OpenXml.Vml.Office; using OfficeOpenXml.FormulaParsing.Excel.Functions.Information; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class admin_follower_print_ : System.Web.UI.Page { private Model.ezEntities _db = new Model.ezEntities(); public MyWeb.encrypt encrypt = new MyWeb.encrypt(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { MyWeb.admin admin = new MyWeb.admin(); if ( admin.isLoign()) { //var getDelItem = Request["num"].TrimEnd(',').Split(',').Select(s => int.Parse(s)); //var prod = _db.followers.AsEnumerable().Where(s => getDelItem.Contains(s.num)).ToList(); //紀錄匯出條件 string _query = ""; var qry = _db.followers.AsQueryable(); // ❌ 錯誤寫法: qry = qry.Where(o => o.f_number.Contains(Request["f_number"].Trim())); // LINQ to Entities 無法轉換 Request[] 方法,必須先轉換為變數再使用 string fNumberParam = Request["f_number"]?.Trim(); if (!string.IsNullOrEmpty(fNumberParam)) { qry = qry.Where(o => o.f_number.Contains(fNumberParam)); _query += "信眾編號:" + fNumberParam + "\n"; } string uNameParam = Request["u_name"]?.Trim(); if (!string.IsNullOrEmpty(uNameParam)) { qry = qry.Where(o => o.u_name.Contains(uNameParam)); _query += "信眾姓名:" + uNameParam + "\n"; } string addressParam = Request["address"]?.Trim(); if (!string.IsNullOrEmpty(addressParam)) { qry = qry.Where(o => o.address.Contains(addressParam)); _query += "地址:" + addressParam + "\n"; } if (!string.IsNullOrEmpty(Request["birthday"])) { DateTime birthdayParam = Convert.ToDateTime(Request["birthday"].Trim()); qry = qry.Where(o => o.birthday >= birthdayParam); _query += "生日(起):" + birthdayParam.ToString("yyyy/MM/dd") + "\n"; } if (!string.IsNullOrEmpty(Request["birthday2"])) { DateTime birthday2Param = Convert.ToDateTime(Request["birthday2"].Trim()); qry = qry.Where(o => o.birthday < birthday2Param.AddDays(1)); _query += "生日(訖):" + birthday2Param.ToString("yyyy/MM/dd") + "\n"; } // ❌ 錯誤寫法: _db.countries.Where(x => x.ID == Request["country"].ToString()) // LINQ to Entities 無法轉換 Request[].ToString(),必須先轉換為變數再使用 string countryId = Request["country"]?.ToString(); if (!string.IsNullOrEmpty(countryId)) { qry = qry.Where(o => o.country == countryId); _query += "國家:" + (_db.countries.Where(x => x.ID == countryId).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n"; } string country2Id = Request["country2"]?.ToString(); if (!string.IsNullOrEmpty(country2Id)) { if (country2Id == "1") { qry = qry.Where(o => o.country == "158"); } else if (country2Id == "2") { qry = qry.Where(o => o.country != "158"); } _query += "國家:" + (_db.countries.Where(x => x.ID == country2Id).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n"; } //管理報表 if (!string.IsNullOrEmpty(Request["year"])) { //title.Text = "信眾管理報表"; int yearParam = Convert.ToInt32(Request["year"]); qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Year == yearParam); _query += "年份:" + Request["year"] + "\n"; } if (!string.IsNullOrEmpty(Request["month"])) { int monthParam = Convert.ToInt32(Request["month"]); qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Month == monthParam); _query += "月份:" + Request["month"] + "\n"; } if (!string.IsNullOrEmpty(Request["season"]) ) { if (Request["season"] == "1") { qry = qry.Where(o => o.join_date.HasValue) .Where(o => o.join_date.Value.Month == 1 || o.join_date.Value.Month == 2 || o.join_date.Value.Month == 3); } else if (Request["season"] == "2") { qry = qry.Where(o => o.join_date.HasValue) .Where(o => o.join_date.Value.Month == 4 || o.join_date.Value.Month == 5 || o.join_date.Value.Month == 6); } else if (Request["season"] == "3") { qry = qry.Where(o => o.join_date.HasValue) .Where(o => o.join_date.Value.Month == 7 || o.join_date.Value.Month == 8 || o.join_date.Value.Month == 9); } else if (Request["season"] == "4") { qry = qry.Where(o => o.join_date.HasValue) .Where(o => o.join_date.Value.Month == 10 || o.join_date.Value.Month == 11 || o.join_date.Value.Month == 12); } _query += "季度:" + Request["season"] + "\n"; } qry = qry.OrderByDescending(o => o.num); //紀錄匯出條件 var prod= qry.ToList(); if (prod.Count > 0) { Repeater1.DataSource = prod; Repeater1.DataBind(); Model.admin_log admin_log = new Model.admin_log(); admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Follower, (int)Model.admin_log.Status.Print, admin_log.LogViewBtn(prod.Select(x => x.f_number + x.u_name).ToList())); } else { //PlaceHolder1.Visible = true; //Response.Clear(); //Response.StatusCode = 404; //Response.End(); } string _data = "列印時間 : " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); _data += "
列印帳號 : " + admin.info.u_id; _data += "
列印條件 : " + (!string.IsNullOrEmpty(_query) ? _query : "-"); footer.Text = _data; } else { Response.Clear(); Response.StatusCode = 404; Response.End(); } } } }