Files
17168ERP/web/admin/order/print.aspx.cs

454 lines
19 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>();
// Request 參數變數
private string _orderNo;
private string _subject;
private string _uName;
private string _introducer;
private string _actItem;
private string _keyin1;
private string _address;
private string _upTime1;
private string _upTime2;
private string _country;
private string _country2;
private string _hasPrice;
private string _year;
private string _month;
private string _season;
private string _chkHasAct;
private string _chkNoAct;
private string _selectAct;
private string _selectActItem;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// 初始化所有 Request 參數
InitializeRequestParameters();
MyWeb.admin admin = new MyWeb.admin();
if (admin.isLoign())
{
//紀錄匯出條件
string _query = "";
var qry = _db.pro_order.AsQueryable();
if (!string.IsNullOrEmpty(_orderNo))
{
qry = qry.Where(o => o.order_no.Contains(_orderNo));
_query += "單號:" + _orderNo + "\n";
}
if (!string.IsNullOrEmpty(_subject))
{
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(_subject));
_query += "報名活動:" + _subject + "\n";
}
if (!string.IsNullOrEmpty(_uName))
{
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(_uName));
_query += "姓名/名稱:" + _uName + "\n";
}
if (!string.IsNullOrEmpty(_introducer))
{
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(_introducer));
_query += "介紹人:" + _introducer + "\n";
}
if (!string.IsNullOrEmpty(_actItem))
{
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(_actItem)).Count() > 0);
_query += "品項:" + _actItem + "\n";
}
if (!string.IsNullOrEmpty(_keyin1))
{
qry = qry.Where(o => o.keyin1 == _keyin1);
_query += "單據狀態:" + Model.pro_order.keyin1_value_to_text(_keyin1) + "\n";
}
if (!string.IsNullOrEmpty(_address))
{
qry = qry.Where(o => o.address.Contains(_address));
_query += "地址:" + _address + "\n";
}
if (!string.IsNullOrEmpty(_upTime1))
{
DateTime upTime1 = Convert.ToDateTime(_upTime1);
qry = qry.Where(o => o.up_time >= upTime1);
_query += "報名日期(起):" + upTime1.ToString("yyyy/MM/dd") + "\n";
}
if (!string.IsNullOrEmpty(_upTime2))
{
DateTime upTime2 = Convert.ToDateTime(_upTime2);
qry = qry.Where(o => o.up_time < upTime2.AddDays(1));
_query += "報名日期(訖):" + upTime2.ToString("yyyy/MM/dd") + "\n";
}
if (!string.IsNullOrEmpty(_country))
{
qry = qry.Where(o => o.f_num != null && o.follower.country == _country);
_query += "國家:" + (_db.countries.Where(x => x.ID == _country).Select(x => x.name_zh).FirstOrDefault() ?? "") + "\n";
}
if (!string.IsNullOrEmpty(_country2))
{
if (_country2 == "1")
{
qry = qry.Where(o => o.f_num != null && o.follower.country == "158");
}
else if (_country2 == "2")
{
qry = qry.Where(o => o.f_num != null && o.follower.country != "158");
}
_query += "國家:" + (_country2 == "1" ? "台灣" : _country2 == "2" ? "非台灣" : "") + "\n";
}
if (!string.IsNullOrEmpty(_hasPrice))
{
if (_hasPrice == "Y")
{
_query += "有金額\n";
}
else if (_hasPrice == "N")
{
_query += "無金額\n";
}
}
//管理報表
if (!string.IsNullOrEmpty(_year))
{
title.Text = "報名管理報表";
int year = Convert.ToInt32(_year);
qry = qry.Where(o => o.up_time.HasValue && o.up_time.Value.Year == year);
_query += "年份:" + _year + "\n";
}
if (!string.IsNullOrEmpty(_month))
{
int month = Convert.ToInt32(_month);
qry = qry.Where(o => o.up_time.HasValue && o.up_time.Value.Month == month);
_query += "月份:" + _month + "\n";
}
if (!string.IsNullOrEmpty(_season))
{
if (_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 (_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 (_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 (_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 += "季度:" + _season + "\n";
}
if (!string.IsNullOrEmpty(_chkHasAct) && Convert.ToBoolean(_chkHasAct))
{
_query += "活動報名\n";
if (!string.IsNullOrEmpty(_chkNoAct) && Convert.ToBoolean(_chkNoAct))
{
_query += "非活動報名\n";
if (!string.IsNullOrEmpty(_selectAct))
{
int selectAct = Convert.ToInt32(_selectAct);
if (selectAct > 0)
{
qry = qry.Where(o => o.activity_num.HasValue && o.activity_num.Value == selectAct);
}
}
}
else
{
qry = qry.Where(o => o.activity_num.HasValue);
if (!string.IsNullOrEmpty(_selectAct))
{
int selectAct = Convert.ToInt32(_selectAct);
if (selectAct > 0)
{
qry = qry.Where(o => o.activity_num.Value == selectAct);
}
}
}
}
else
{
if (!string.IsNullOrEmpty(_chkNoAct) && Convert.ToBoolean(_chkNoAct))
{
qry = qry.Where(o => o.activity_num == null);
_query += "非活動報名\n";
}
}
if (!string.IsNullOrEmpty(_selectActItem))
{
int selectActItem = Convert.ToInt32(_selectActItem);
if (selectActItem > 0)
{
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem_num.Value == selectActItem).Count() > 0);
}
}
if (!string.IsNullOrEmpty(_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;
}
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 (!string.IsNullOrEmpty(_hasPrice) && _hasPrice == "Y" && Repeater1.Items.Count > 0)
{
Panel hrPanel = (Panel)Repeater1.Items[Repeater1.Items.Count - 1].FindControl("hr");
if (hrPanel != null)
{
hrPanel.Visible = false;
}
int _total = 0;
int _item_qty = 0;
foreach (RepeaterItem gItem in Repeater1.Items)
{
Repeater rpt = (Repeater)gItem.FindControl("Repeater2");
if (rpt != null)
{
foreach (RepeaterItem rItem in rpt.Items)
{
Literal item_price = (Literal)rItem.FindControl("item_price");
Literal item_qty = (Literal)rItem.FindControl("item_qty");
int price = 0;
int qty = 0;
if (item_price != null && !string.IsNullOrEmpty(item_price.Text))
{
int.TryParse(item_price.Text, out price);
}
if (item_qty != null && !string.IsNullOrEmpty(item_qty.Text))
{
int.TryParse(item_qty.Text, out qty);
}
_total += price * qty;
_item_qty += qty;
}
}
}
_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();
}
}
}
/// <summary>
/// 初始化所有 Request 參數
/// </summary>
private void InitializeRequestParameters()
{
_orderNo = Request["order_no"]?.Trim();
_subject = Request["subject"]?.Trim();
_uName = Request["u_name"]?.Trim();
_introducer = Request["introducerTxt"]?.Trim();
_actItem = Request["actItemTxt"]?.Trim();
_keyin1 = Request["keyin1"]?.Trim();
_address = Request["address"]?.Trim();
_upTime1 = Request["up_time1"]?.Trim();
_upTime2 = Request["up_time2"]?.Trim();
_country = Request["country"]?.Trim();
_country2 = Request["country2"]?.Trim();
_hasPrice = Request["hasPrice"]?.Trim();
_year = Request["year"]?.Trim();
_month = Request["month"]?.Trim();
_season = Request["season"]?.Trim();
_chkHasAct = Request["chk_hasact"]?.Trim();
_chkNoAct = Request["chk_noact"]?.Trim();
_selectAct = Request["select_act"]?.Trim();
_selectActItem = Request["select_actitem"]?.Trim();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Model.pro_order row = (Model.pro_order)e.Item.DataItem;
Literal keyin1Lit = (Literal)e.Item.FindControl("keyin1");
if (keyin1Lit != null)
{
keyin1Lit.Text = Model.pro_order.keyin1_value_to_text(row.keyin1);
}
Literal fNumTxtLit = (Literal)e.Item.FindControl("f_numTxt");
if (fNumTxtLit != null)
{
fNumTxtLit.Text = row.f_num.HasValue && row.follower != null ? row.follower.u_name : "";
}
Literal activityTxtLit = (Literal)e.Item.FindControl("activityTxt");
if (activityTxtLit != null)
{
activityTxtLit.Text = row.activity_num.HasValue && row.activity != null ? row.activity.subject : "";
}
Repeater Repeater2 = (Repeater)e.Item.FindControl("Repeater2");
if (Repeater2 != null)
{
var _ds = _detail.Where(x => x.order_no == row.order_no).ToList();
if (_ds.Count > 0)
{
PlaceHolder detailTable = (PlaceHolder)e.Item.FindControl("detailTable");
if (detailTable != null)
{
detailTable.Visible = true;
}
Repeater2.DataSource = _ds;
Repeater2.DataBind();
PlaceHolder ph2 = (PlaceHolder)e.Item.FindControl("PlaceHolder2");
if (ph2 != null)
{
ph2.Visible = !string.IsNullOrEmpty(_hasPrice) && _hasPrice == "Y";
}
}
}
}
}
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Model.pro_order_detail row = (Model.pro_order_detail)e.Item.DataItem;
Literal actitem_numTxt = (Literal)e.Item.FindControl("actitem_numTxt");
if (actitem_numTxt != null)
{
actitem_numTxt.Text = row.actItem_num.HasValue && row.actItem != null ? row.actItem.subject : "";
}
Literal fNumTxtLit = (Literal)e.Item.FindControl("f_numTxt");
if (fNumTxtLit != null)
{
fNumTxtLit.Text = row.f_num.HasValue && row.follower != null ? row.follower.u_name : "";
}
Literal fromIdTxtLit = (Literal)e.Item.FindControl("from_idTxt");
if (fromIdTxtLit != null)
{
fromIdTxtLit.Text = row.from_id.HasValue && row.follower1 != null ? row.follower1.u_name : "";
}
Literal dueDateLit = (Literal)e.Item.FindControl("due_date");
if (dueDateLit != null)
{
dueDateLit.Text = row.due_date.HasValue ? row.due_date.Value.ToString("yyyy-MM-dd") : "";
}
Literal extendDateLit = (Literal)e.Item.FindControl("extend_date");
if (extendDateLit != null)
{
extendDateLit.Text = row.extend_date.HasValue ? row.extend_date.Value.ToString("yyyy-MM-dd") : "";
}
//劃位狀態
int writeBedQty = _bedDt.Where(b => b.bed_order != null && 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 != null && b.bed_order.o_detail_id == row.num && (!b.checkIn_date.HasValue || !b.bed_kind_detail_id.HasValue)).Count();
Literal bedQtyLit = (Literal)e.Item.FindControl("BedQty");
if (bedQtyLit != null)
{
bedQtyLit.Text = (row.actItem != null && row.actItem.category.HasValue && Convert.ToInt32(row.actItem.category.Value) == (int)Model.activity.category.Order) ? (notBedQty + "/" + writeBedQty) : "";
}
Literal keyin1Lit = (Literal)e.Item.FindControl("keyin1");
if (keyin1Lit != null)
{
keyin1Lit.Text = row.keyin1.HasValue && row.keyin1.Value > 0 && tdesc.ContainsKey(row.keyin1.Value) ? tdesc[row.keyin1.Value] : "";
}
PlaceHolder ph2 = (PlaceHolder)e.Item.FindControl("PlaceHolder2");
if (ph2 != null)
{
ph2.Visible = !string.IsNullOrEmpty(_hasPrice) && _hasPrice == "Y";
}
}
}
}