Files
17168ERP/web/admin/order/print.aspx.cs
2025-08-29 01:27:25 +08:00

299 lines
14 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.AsEnumerable();
if (!string.IsNullOrEmpty(Request["order_no"]))
{
qry = qry.Where(o => o.order_no.Contains(Request["order_no"].Trim()));
_query += "單號:" + Request["order_no"].Trim() + "\n";
}
if (!string.IsNullOrEmpty(Request["subject"]))
{
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(Request["subject"].Trim()));
_query += "報名活動:" + Request["subject"].Trim() + "\n";
}
if (!string.IsNullOrEmpty(Request["u_name"]))
{
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(Request["u_name"].Trim()));
_query += "姓名/名稱:" + Request["u_name"].Trim() + "\n";
}
if (!string.IsNullOrEmpty(Request["introducerTxt"]))
{
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(Request["introducerTxt"].Trim()));
_query += "介紹人:" + Request["introducerTxt"].Trim() + "\n";
}
if (!string.IsNullOrEmpty(Request["actItemTxt"]))
{
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(Request["actItemTxt"].Trim()) ).Count() > 0);
_query += "品項:" + Request["actItemTxt"].Trim() + "\n";
}
if (!string.IsNullOrEmpty(Request["keyin1"]))
{
qry = qry.Where(o => o.keyin1==Request["keyin1"].ToString());
_query += "單據狀態:" + Model.pro_order.keyin1_value_to_text( Request["keyin1"].Trim()) + "\n";
}
if (!string.IsNullOrEmpty(Request["address"]))
{
qry = qry.Where(o => o.address.Contains(Request["address"].Trim()));
_query += "地址:" + Request["address"].Trim() + "\n";
}
if (!string.IsNullOrEmpty(Request["up_time1"]))
{
qry = qry.Where(o => o.up_time >= Convert.ToDateTime(Request["up_time1"].Trim()));
_query += "報名日期(起):" + Convert.ToDateTime(Request["up_time1"].Trim()).ToString("yyyy/MM/dd") + "\n";
}
if (!string.IsNullOrEmpty(Request["up_time2"]) )
{
qry = qry.Where(o => o.up_time < Convert.ToDateTime(Request["up_time2"]).AddDays(1));
_query += "報名日期(訖):" + Convert.ToDateTime(Request["up_time2"].Trim()).ToString("yyyy/MM/dd") + "\n";
}
if (!string.IsNullOrEmpty(Request["country"]))
{
qry = qry.Where(o => o.f_num != null && o.follower?.country == Request["country"]);
_query += "國家:" + (_db.countries.AsEnumerable().Where(x => x.ID == Request["country"]).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
}
if (!string.IsNullOrEmpty(Request["country2"]))
{
if (Request["country2"] == "1")
{
qry = qry.Where(o => o.f_num != null && o.follower?.country == "158");
}
else if (Request["country2"] == "2")
{
qry = qry.Where(o => o.f_num != null && o.follower?.country != "158");
}
_query += "國家:" + (_db.countries.AsEnumerable().Where(x => x.ID == Request["country2"]).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 = "報名管理報表";
qry = qry.Where(o => o.up_time.HasValue && o.up_time.Value.Year == Convert.ToInt32(Request["year"]));
_query += "年份:" + Request["year"] + "\n";
}
if (!string.IsNullOrEmpty(Request["month"]))
{
qry = qry.Where(o => o.up_time.HasValue && o.up_time.Value.Month == Convert.ToInt32(Request["month"]));
_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"]) && Convert.ToInt32(Request["select_act"]) > 0)
{
qry = qry.Where(o => o.activity_num.HasValue && o.activity_num.Value == Convert.ToInt32(Request["select_act"]));
}
}
else
{
qry = qry.Where(o => o.activity_num.HasValue);
if (!string.IsNullOrEmpty(Request["select_act"]) && Convert.ToInt32(Request["select_act"]) > 0)
{
qry = qry.Where(o => o.activity_num.Value == Convert.ToInt32(Request["select_act"]));
}
}
}
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"]) && Convert.ToInt32(Request["select_actitem"]) > 0)
{
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem_num.Value == Convert.ToInt32(Request["select_actitem"])).Count() > 0);
}
if (!string.IsNullOrEmpty(Request["year"]))
qry = qry.OrderByDescending(o => o.activity?.startDate_solar).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>();
//明細
_detail = _db.pro_order_detail.AsEnumerable().Where(x => prod.Select(o => o.order_no).Contains( x.order_no)).ToList();
_bedDt = _db.bed_order_detail.AsEnumerable().Where(x => prod.Select(o => o.order_no).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";
}
}