API 查詢同步改寫 .Contains()、.OrderBy()、複雜 GroupBy/Math.Round,必要時 materialize 或加 HasValue。 Participation rate / kind breakdown 改在記憶體計算,同時檢查整數陣列 .Contains() 的型別安全性。
339 lines
16 KiB
C#
339 lines
16 KiB
C#
using DocumentFormat.OpenXml.Drawing.Charts;
|
|
using DocumentFormat.OpenXml.Vml.Office;
|
|
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();
|
|
List<Model.pro_order_detail> _detail = new List<Model.pro_order_detail>();
|
|
List<Model.bed_order_detail> _bedDt = new List<Model.bed_order_detail>();
|
|
Dictionary<int, string> tdesc = new Dictionary<int, string>();
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
MyWeb.admin admin = new MyWeb.admin();
|
|
|
|
if ( admin.isLoign())
|
|
{
|
|
|
|
//紀錄匯出條件
|
|
string _query = "";
|
|
var qry = _db.pro_order.AsQueryable();
|
|
|
|
// ❌ 錯誤寫法: qry = qry.Where(o => o.order_no.Contains(Request["order_no"].Trim()));
|
|
// LINQ to Entities 無法轉換 Request[] 方法,必須先轉換為變數再使用
|
|
string orderNoParam = Request["order_no"]?.Trim();
|
|
if (!string.IsNullOrEmpty(orderNoParam))
|
|
{
|
|
qry = qry.Where(o => o.order_no.Contains(orderNoParam));
|
|
_query += "單號:" + orderNoParam + "\n";
|
|
}
|
|
|
|
string subjectParam = Request["subject"]?.Trim();
|
|
if (!string.IsNullOrEmpty(subjectParam))
|
|
{
|
|
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(subjectParam));
|
|
_query += "報名活動:" + subjectParam + "\n";
|
|
}
|
|
|
|
string uNameParam = Request["u_name"]?.Trim();
|
|
if (!string.IsNullOrEmpty(uNameParam))
|
|
{
|
|
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(uNameParam));
|
|
_query += "姓名/名稱:" + uNameParam + "\n";
|
|
}
|
|
|
|
string introducerParam = Request["introducerTxt"]?.Trim();
|
|
if (!string.IsNullOrEmpty(introducerParam))
|
|
{
|
|
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(introducerParam));
|
|
_query += "介紹人:" + introducerParam + "\n";
|
|
}
|
|
|
|
string actItemParam = Request["actItemTxt"]?.Trim();
|
|
if (!string.IsNullOrEmpty(actItemParam))
|
|
{
|
|
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(actItemParam)).Count() > 0);
|
|
_query += "品項:" + actItemParam + "\n";
|
|
}
|
|
if (!string.IsNullOrEmpty(Request["keyin1"]))
|
|
{
|
|
// ❌ 錯誤寫法: qry = qry.Where(o => o.keyin1==Request["keyin1"].ToString());
|
|
// LINQ to Entities 無法轉換 Request[].ToString(),必須先轉換為變數再使用
|
|
string keyin1Value = Request["keyin1"]?.ToString();
|
|
qry = qry.Where(o => o.keyin1 == keyin1Value);
|
|
_query += "單據狀態:" + Model.pro_order.keyin1_value_to_text( Request["keyin1"].Trim()) + "\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["up_time1"]))
|
|
{
|
|
DateTime upTime1Param = Convert.ToDateTime(Request["up_time1"].Trim());
|
|
qry = qry.Where(o => o.up_time >= upTime1Param);
|
|
_query += "報名日期(起):" + upTime1Param.ToString("yyyy/MM/dd") + "\n";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Request["up_time2"]))
|
|
{
|
|
DateTime upTime2Param = Convert.ToDateTime(Request["up_time2"].Trim());
|
|
qry = qry.Where(o => o.up_time < upTime2Param.AddDays(1));
|
|
_query += "報名日期(訖):" + upTime2Param.ToString("yyyy/MM/dd") + "\n";
|
|
}
|
|
|
|
string countryParam = Request["country"]?.ToString();
|
|
if (!string.IsNullOrEmpty(countryParam))
|
|
{
|
|
qry = qry.Where(o => o.f_num != null && o.follower.country == countryParam);
|
|
_query += "國家:" + (_db.countries.Where(x => x.ID == countryParam).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n";
|
|
}
|
|
|
|
string country2Param = Request["country2"]?.ToString();
|
|
if (!string.IsNullOrEmpty(country2Param))
|
|
{
|
|
if (country2Param == "1")
|
|
{
|
|
qry = qry.Where(o => o.f_num != null && o.follower.country == "158");
|
|
}
|
|
else if (country2Param == "2")
|
|
{
|
|
qry = qry.Where(o => o.f_num != null && o.follower.country != "158");
|
|
}
|
|
_query += "國家:" + (_db.countries.Where(x => x.ID == country2Param).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n";
|
|
}
|
|
if (!string.IsNullOrEmpty(Request["hasPrice"]))
|
|
{
|
|
if (Request["hasPrice"].ToString() == "Y")
|
|
{
|
|
_query += "有金額\n";
|
|
}
|
|
else if (Request["hasPrice"].ToString() == "N")
|
|
{
|
|
_query += "無金額\n";
|
|
}
|
|
}
|
|
|
|
//管理報表
|
|
if (!string.IsNullOrEmpty(Request["year"]))
|
|
{
|
|
title.Text = "報名管理報表";
|
|
int yearParam = Convert.ToInt32(Request["year"]);
|
|
qry = qry.Where(o => o.up_time.HasValue && o.up_time.Value.Year == yearParam);
|
|
_query += "年份:" + Request["year"] + "\n";
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Request["month"]))
|
|
{
|
|
int monthParam = Convert.ToInt32(Request["month"]);
|
|
qry = qry.Where(o => o.up_time.HasValue && o.up_time.Value.Month == monthParam);
|
|
_query += "月份:" + Request["month"] + "\n";
|
|
}
|
|
if (!string.IsNullOrEmpty(Request["season"]))
|
|
{
|
|
|
|
if (Request["season"] == "1")
|
|
{
|
|
qry = qry.Where(o => o.up_time.HasValue)
|
|
.Where(o => o.up_time.Value.Month == 1 || o.up_time.Value.Month == 2 || o.up_time.Value.Month == 3);
|
|
}
|
|
else if (Request["season"] == "2")
|
|
{
|
|
qry = qry.Where(o => o.up_time.HasValue)
|
|
.Where(o => o.up_time.Value.Month == 4 || o.up_time.Value.Month == 5 || o.up_time.Value.Month == 6);
|
|
}
|
|
else if (Request["season"] == "3")
|
|
{
|
|
qry = qry.Where(o => o.up_time.HasValue)
|
|
.Where(o => o.up_time.Value.Month == 7 || o.up_time.Value.Month == 8 || o.up_time.Value.Month == 9);
|
|
}
|
|
else if (Request["season"] == "4")
|
|
{
|
|
qry = qry.Where(o => o.up_time.HasValue)
|
|
.Where(o => o.up_time.Value.Month == 10 || o.up_time.Value.Month == 11 || o.up_time.Value.Month == 12);
|
|
}
|
|
|
|
_query += "季度:" + Request["season"] + "\n";
|
|
}
|
|
if (!string.IsNullOrEmpty(Request["chk_hasact"]) && Convert.ToBoolean(Request["chk_hasact"]))
|
|
{
|
|
_query += "活動報名\n";
|
|
if (!string.IsNullOrEmpty(Request["chk_noact"]) && Convert.ToBoolean(Request["chk_noact"]))
|
|
{
|
|
_query += "非活動報名\n";
|
|
|
|
if (!string.IsNullOrEmpty(Request["select_act"]))
|
|
{
|
|
int selectActParam = Convert.ToInt32(Request["select_act"]);
|
|
if (selectActParam > 0)
|
|
{
|
|
qry = qry.Where(o => o.activity_num.HasValue && o.activity_num.Value == selectActParam);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
qry = qry.Where(o => o.activity_num.HasValue);
|
|
if (!string.IsNullOrEmpty(Request["select_act"]))
|
|
{
|
|
int selectActParam = Convert.ToInt32(Request["select_act"]);
|
|
if (selectActParam > 0)
|
|
{
|
|
qry = qry.Where(o => o.activity_num.Value == selectActParam);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(Request["chk_noact"]) && Convert.ToBoolean(Request["chk_noact"]))
|
|
{
|
|
qry = qry.Where(o => o.activity_num == null);
|
|
_query += "非活動報名\n";
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Request["select_actitem"]))
|
|
{
|
|
int selectActItemParam = Convert.ToInt32(Request["select_actitem"]);
|
|
if (selectActItemParam > 0)
|
|
{
|
|
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem_num.Value == selectActItemParam).Count() > 0);
|
|
}
|
|
}
|
|
|
|
if (!string.IsNullOrEmpty(Request["year"]))
|
|
qry = qry.OrderByDescending(o => o.activity != null ? o.activity.startDate_solar : null).ThenByDescending(o=>o.up_time).ThenByDescending(o=>o.order_no);
|
|
else
|
|
qry = qry.OrderByDescending(o => o.order_no);
|
|
|
|
//紀錄匯出條件
|
|
var prod= qry.ToList();
|
|
if (prod.Count > 0)
|
|
{
|
|
tdesc = publicFun.enum_desc<Model.pro_order.detailKeyin1>();
|
|
|
|
//明細
|
|
var orderNos = prod.Select(o => o.order_no).ToList();
|
|
_detail = _db.pro_order_detail.Where(x => orderNos.Contains(x.order_no)).ToList();
|
|
_bedDt = _db.bed_order_detail.Where(x => orderNos.Contains(x.bed_order.order_no)).ToList();
|
|
|
|
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.Order, (int)Model.admin_log.Status.Print, admin_log.LogViewBtn(prod.Select(x => x.order_no).ToList()));
|
|
|
|
}
|
|
else
|
|
{
|
|
PlaceHolder1.Visible = true;
|
|
//Response.Clear();
|
|
//Response.StatusCode = 404;
|
|
//Response.End();
|
|
}
|
|
|
|
string _data = "列印時間 : " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
_data += "<br>列印帳號 : " + admin.info.u_id;
|
|
_data += "<br>列印條件 : " + (!string.IsNullOrEmpty(_query) ? _query : "-");
|
|
footer.Text = _data;
|
|
|
|
if (Request["hasPrice"].ToString() == "Y")
|
|
{
|
|
((Panel)Repeater1.Items[Repeater1.Items.Count - 1].FindControl("hr")).Visible = false;
|
|
|
|
int _total = 0;
|
|
int _item_qty = 0;
|
|
foreach (RepeaterItem gItem in Repeater1.Items)
|
|
{
|
|
Repeater rpt = (Repeater)gItem.FindControl("Repeater2");
|
|
foreach (RepeaterItem rItem in rpt.Items)
|
|
{
|
|
Literal item_price = (Literal)rItem.FindControl("item_price");
|
|
Literal item_qty = (Literal)rItem.FindControl("item_qty");
|
|
|
|
_total += Convert.ToInt32(item_price.Text) * Convert.ToInt32(item_qty.Text);
|
|
_item_qty += Convert.ToInt32(item_qty.Text);
|
|
}
|
|
|
|
}
|
|
|
|
_data = "報名單筆數 : " + Repeater1.Items.Count;
|
|
_data += "</td><td>項目數量合計 : " + _item_qty;
|
|
_data += "</td><td>金額合計 : $" + _total;
|
|
|
|
count_data.Text = _data;
|
|
count_data2.Text = _data;
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
Response.Clear();
|
|
Response.StatusCode = 404;
|
|
Response.End();
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
|
|
{
|
|
Model.pro_order row = (Model.pro_order)e.Item.DataItem;
|
|
|
|
((Literal)e.Item.FindControl("keyin1")).Text = Model.pro_order.keyin1_value_to_text(row.keyin1);
|
|
((Literal)e.Item.FindControl("f_numTxt")).Text = row.f_num.HasValue ? row.follower.u_name : "";
|
|
((Literal)e.Item.FindControl("activityTxt")).Text = row.activity_num.HasValue ? row.activity.subject : "";
|
|
|
|
Repeater Repeater2 = (Repeater)e.Item.FindControl("Repeater2");
|
|
var _ds = _detail.Where(x => x.order_no == row.order_no).ToList();
|
|
if (_ds .Count>0) {
|
|
((PlaceHolder)e.Item.FindControl("detailTable")).Visible = true;
|
|
Repeater2.DataSource = _ds;
|
|
Repeater2.DataBind();
|
|
|
|
((PlaceHolder)e.Item.FindControl("PlaceHolder2")).Visible = Request["hasPrice"].ToString() == "Y";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
|
|
{
|
|
Model.pro_order_detail row = (Model.pro_order_detail)e.Item.DataItem;
|
|
|
|
Literal actitem_numTxt = (Literal)e.Item.FindControl("actitem_numTxt");
|
|
actitem_numTxt.Text = row.actItem_num.HasValue ? row.actItem.subject : "";
|
|
|
|
((Literal)e.Item.FindControl("f_numTxt")).Text = row.f_num.HasValue ? row.follower.u_name : "";
|
|
((Literal)e.Item.FindControl("from_idTxt")).Text = row.from_id.HasValue ? row.follower1.u_name : "";
|
|
|
|
((Literal)e.Item.FindControl("due_date")).Text = row.due_date.HasValue? row.due_date.Value.ToString("yyyy-MM-dd"):"";
|
|
// ((Literal)e.Item.FindControl("start_date")).Text = row.start_date.HasValue? row.start_date.Value.ToString("yyyy-MM-dd"):"";
|
|
((Literal)e.Item.FindControl("extend_date")).Text = row.extend_date.HasValue? row.extend_date.Value.ToString("yyyy-MM-dd"):"";
|
|
|
|
//劃位狀態
|
|
int writeBedQty = _bedDt.Where(b => b.bed_order.o_detail_id == row.num && b.checkIn_date.HasValue && b.bed_kind_detail_id.HasValue).Count(); //已劃數量
|
|
int notBedQty = _bedDt.Where(b => b.bed_order.o_detail_id == row.num && (!b.checkIn_date.HasValue || !b.bed_kind_detail_id.HasValue)).Count(); //未劃數量
|
|
((Literal)e.Item.FindControl("BedQty")).Text = (Convert.ToInt32(row.actItem?.category) == (int)Model.activity.category.Order) ? (notBedQty + "/" + writeBedQty) : "";
|
|
|
|
((Literal)e.Item.FindControl("keyin1")).Text = row.keyin1.HasValue && row.keyin1.Value > 0 ? tdesc[row.keyin1 ?? 1] : "";
|
|
|
|
((PlaceHolder)e.Item.FindControl("PlaceHolder2")).Visible = Request["hasPrice"].ToString() == "Y";
|
|
|
|
|
|
}
|
|
} |