7644df57d0
2. 新增報名頁面加上取消鍵 3. 優化登入頁面:按下 enter 自動換格/送出 4. 修復新增報名頁面中,不同 search_dialog 中的 page 參數相互連動之異常 5. 修改報名頁面列印格式 6. 修復報名頁面匯出功能 7. 優化報到功能 8. 報名頁面中,無查詢資料時不可點選匯出/列印按鈕 9. 匯出/列印報名管理報表時,若無資料則顯示提示 10. 修復列印管理報表後父視窗 UI 不能點擊的問題 11. 新增報名管理表單匯出 excel 功能 12. 於新增信眾、新增活動頁面加上取消鍵 13. 優化報名管理匯出功能:若篩選條件包含特定活動,自動於「匯出條件」欄位標註活動名稱 14. 優化報名查詢匯出功能:匯出之文件中加上「匯出條件」欄位 15. 修復信眾資料頁面中,使用「生日」作為篩選基準時,後續執行「列印查詢資料」與「匯出查詢資料」會報錯 16. 修復「列印信眾查詢」功能中,電話搜尋欄位未正確帶入查詢條件之異常 17. 解決中文輸入法輸入電話號碼的跳字問題 18. 新增品項管理介面排序功能
391 lines
18 KiB
C#
391 lines
18 KiB
C#
using DocumentFormat.OpenXml;
|
|
using DocumentFormat.OpenXml.Packaging;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Interop;
|
|
using static TreeView;
|
|
|
|
|
|
public partial class admin_follower_index : MyWeb.config
|
|
{
|
|
public int page = 1;
|
|
private Model.ezEntities _db = new Model.ezEntities();
|
|
protected string lastAddedID;
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
if (!IsPostBack)
|
|
{
|
|
if (Session["LastAddedID"] != null)
|
|
{
|
|
lastAddedID = Session["LastAddedID"].ToString();
|
|
Session.Remove("LastAddedID");
|
|
}
|
|
BuildKind();
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#region 分類
|
|
|
|
|
|
|
|
public void BuildKind()
|
|
{
|
|
//國籍
|
|
s_country.Items.Clear();
|
|
s_country.Items.Add(new ListItem("請選擇", ""));
|
|
var qry = _db.countries.OrderBy(x => x.range).ThenBy(x => x.name_en).ToList();
|
|
if (qry.Count > 0)
|
|
{
|
|
foreach (var x in qry)
|
|
s_country.Items.Add(new ListItem(x.name_zh, x.ID));
|
|
}
|
|
|
|
//var qry1 = new TreeView().get_data2(_db.countries.AsEnumerable().Select(o => new TreeItem()
|
|
//{
|
|
// kind = o.name_zh,
|
|
// num = Convert.ToInt32( o.ID),
|
|
// root = 0,
|
|
// range = o.range,
|
|
//}).OrderBy(x => x.range).ThenBy(x => x.kind).ToList(), 0, 0);
|
|
//if (qry1.Count() > 0)
|
|
// foreach (var qq in qry1)
|
|
// s_country.Items.Add(new ListItem(new TreeView().RptDash(qq.Level) + qq.kind, qq.num.ToString()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region 匯出
|
|
|
|
protected void export_Click(object sender, EventArgs e)
|
|
{
|
|
var memoryStream = new MemoryStream();
|
|
|
|
LinkButton btn = sender as LinkButton;
|
|
if (btn == null) return;
|
|
bool isPrintMode = (btn.ID == "print_management");
|
|
bool isExcelMode = (btn.ID == "excel_management" || btn.ID == "excel");
|
|
bool isManagementMode = (btn.ID == "excel_management" || btn.ID == "print_management");
|
|
|
|
//查詢要匯出的資料
|
|
string _query = ""; // 紀錄匯出條件
|
|
var list = searchData(ref _query, isManagementMode);
|
|
|
|
if (isExcelMode)
|
|
{
|
|
if (list.Count > 0)
|
|
{
|
|
using (var doc = SpreadsheetDocument.Create(memoryStream, SpreadsheetDocumentType.Workbook))
|
|
{
|
|
var wb = doc.AddWorkbookPart();
|
|
wb.Workbook = new Workbook();
|
|
var sheets = wb.Workbook.AppendChild(new Sheets());
|
|
|
|
//建立第一個頁籤
|
|
var ws = wb.AddNewPart<WorksheetPart>();
|
|
ws.Worksheet = new Worksheet();
|
|
sheets.Append(new Sheet()
|
|
{
|
|
Id = wb.GetIdOfPart(ws),
|
|
SheetId = 1,
|
|
Name = "信眾資料"
|
|
});
|
|
|
|
//設定欄寬
|
|
var cu = new Columns();
|
|
cu.Append(
|
|
new Column { Min = 1, Max = 2, Width = 15, CustomWidth = true },
|
|
new Column { Min = 3, Max = 3, Width = 10, CustomWidth = true },
|
|
new Column { Min = 4, Max = 11, Width = 15, CustomWidth = true },
|
|
new Column { Min = 12, Max = 12, Width = 25, CustomWidth = true },
|
|
new Column { Min = 13, Max = 13, Width = 8, CustomWidth = true },
|
|
new Column { Min = 14, Max = 14, Width = 35, CustomWidth = true },
|
|
new Column { Min = 15, Max = 16, Width = 15, CustomWidth = true }
|
|
);
|
|
ws.Worksheet.Append(cu);
|
|
|
|
//建立資料頁
|
|
var sd = new SheetData();
|
|
ws.Worksheet.AppendChild(sd);
|
|
|
|
//第一列資料
|
|
var tr = new Row();
|
|
tr.Append(
|
|
new Cell() { CellValue = new CellValue("信眾編號"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("信眾姓名"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("性別"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("身分別"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("生日(國曆)"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("聯絡電話"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("手機號碼"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("皈依道場"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("皈依法名"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("皈依日期"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("加入日期"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("緊急連絡人"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("緊急連絡人電話"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("血型"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("國籍"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("收件地址"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("介紹人"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("LINE帳號"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("其它社群帳號"), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue("建檔日期"), DataType = CellValues.String }
|
|
, new Cell() { CellValue = new CellValue("身分證號"), DataType = CellValues.String }
|
|
//,new Cell() { CellValue = new CellValue("SHA"), DataType = CellValues.String }
|
|
);
|
|
sd.AppendChild(tr);
|
|
|
|
|
|
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
|
Model.country country = new Model.country();
|
|
var tdesc = publicFun.enum_desc<Model.follower.type>();
|
|
foreach (var item in list)
|
|
{
|
|
//新增資料列
|
|
tr = new Row();
|
|
string s1, s2, sha;
|
|
s1 = encrypt.DecryptAutoKey(item.phone);
|
|
s2 = encrypt.DecryptAutoKey(item.id_code);
|
|
sha = encrypt.followerHash(s1, s2);
|
|
tr.Append(
|
|
new Cell() { CellValue = new CellValue(item.f_number), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.u_name), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.sex), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(!isStrNull(item.identity_type) ? tdesc[item.identity_type ?? 1] : ""), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.birthday.HasValue ? ValDate(item.birthday.Value).ToString("yyyy/MM/dd") : ""), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.phone)), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.cellphone)), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.refuge_area), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.refuge_name), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.refugedate.HasValue ? ValDate(item.refugedate.Value).ToString("yyyy/MM/dd") : ""), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.join_date.HasValue ? ValDate(item.join_date.Value).ToString("yyyy/MM/dd") : ""), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.contactor), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.contactor_phone)), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.blood), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(!isStrNull(item.country) ? item.country1.name_zh : ""), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.address), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.introducer), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.socialid1), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.socialid2), DataType = CellValues.String },
|
|
new Cell() { CellValue = new CellValue(item.reg_time.HasValue ? ValDate(item.reg_time.Value).ToString("yyyy/MM/dd HH:mm:ss") : ""), DataType = CellValues.String }
|
|
, new Cell() { CellValue = new CellValue(encrypt.DecryptAutoKey(item.id_code)), DataType = CellValues.String }
|
|
//, new Cell() { CellValue = new CellValue(sha), DataType = CellValues.String }
|
|
);
|
|
sd.AppendChild(tr);
|
|
}
|
|
|
|
//空一列
|
|
tr = new Row();
|
|
sd.AppendChild(tr);
|
|
|
|
//匯出資訊
|
|
string _data = "匯出時間 : " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
_data += " " + admin.info.u_id;
|
|
tr = new Row();
|
|
tr.Append(
|
|
new Cell() { CellValue = new CellValue(_data), DataType = CellValues.String }
|
|
);
|
|
sd.AppendChild(tr);
|
|
|
|
_data = "匯出條件 : " + (!isStrNull(_query) ? _query : "-");
|
|
tr = new Row();
|
|
tr.Append(
|
|
new Cell() { CellValue = new CellValue(_data), DataType = CellValues.String }
|
|
);
|
|
sd.AppendChild(tr);
|
|
|
|
|
|
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.Excel, admin_log.LogViewBtn(list.Select(x => x.f_number + x.u_name).ToList()));
|
|
|
|
|
|
}
|
|
HttpContext.Current.Response.Clear();
|
|
HttpContext.Current.Response.AddHeader("content-disposition", "attachment; filename=信眾_data.xlsx");
|
|
HttpContext.Current.Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
HttpContext.Current.Response.BinaryWrite(memoryStream.ToArray());
|
|
HttpContext.Current.Response.End();
|
|
|
|
hid_err_msg.Value = "success";
|
|
}
|
|
else
|
|
{
|
|
//ScriptMsg2("查無資料");
|
|
hid_err_msg.Value = "nodata";
|
|
}
|
|
}
|
|
else if (isPrintMode)
|
|
{
|
|
string urlParams = "";
|
|
int selYear = !string.IsNullOrEmpty(hid_print_year.Value) ? int.Parse(hid_print_year.Value) : 0;
|
|
int selMonth = !string.IsNullOrEmpty(hid_print_month.Value) ? int.Parse(hid_print_month.Value) : 0;
|
|
int selSeason = !string.IsNullOrEmpty(hid_print_season.Value) ? int.Parse(hid_print_season.Value) : 0;
|
|
string selMode = !string.IsNullOrEmpty(hid_print_mode.Value) ? hid_print_mode.Value : "";
|
|
|
|
var qry = _db.followers.AsQueryable();
|
|
if (selYear > 0)
|
|
{
|
|
urlParams += "&year=" + selYear;
|
|
}
|
|
if (selMode == "mm" && selMonth > 0)
|
|
{
|
|
urlParams += "&month=" + selMonth;
|
|
}
|
|
else if (selMode == "ss" && selSeason > 0)
|
|
{
|
|
urlParams += "&season=" + selSeason;
|
|
}
|
|
|
|
if (list.Count > 0)
|
|
{
|
|
hid_err_msg.Value = "success";
|
|
hid_print_year.Value = selYear.ToString();
|
|
hid_print_month.Value = selMonth.ToString();
|
|
hid_print_season.Value = selSeason.ToString();
|
|
hid_print_mode.Value = selMode;
|
|
|
|
string script = $@"window.open('print.aspx?{urlParams}&mode={selMode}', '列印信眾資料', 'noopener,noreferrer');";
|
|
ScriptManager.RegisterStartupScript(this, GetType(), "ExecutePrint", script, true);
|
|
}
|
|
else
|
|
{
|
|
hid_err_msg.Value = "nodata";
|
|
}
|
|
}
|
|
}
|
|
protected List<Model.follower> searchData(ref string _query, bool isManagementMode = false)
|
|
{
|
|
|
|
//查詢要匯出的資料
|
|
var qry = _db.followers.AsQueryable();
|
|
|
|
// 管理報表
|
|
if (isManagementMode)
|
|
{
|
|
int selYear = !string.IsNullOrEmpty(hid_print_year.Value) ? int.Parse(hid_print_year.Value) : 0;
|
|
int selMonth = !string.IsNullOrEmpty(hid_print_month.Value) ? int.Parse(hid_print_month.Value) : 0;
|
|
int selSeason = !string.IsNullOrEmpty(hid_print_season.Value) ? int.Parse(hid_print_season.Value) : 0;
|
|
string selMode = !string.IsNullOrEmpty(hid_print_mode.Value) ? hid_print_mode.Value : "";
|
|
|
|
if (selYear > 0)
|
|
{
|
|
qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Year == selYear);
|
|
_query += "年份:" + selYear + "\n";
|
|
}
|
|
if (selMode == "mm" && selMonth > 0)
|
|
{
|
|
qry = qry.Where(o => o.join_date.HasValue && o.join_date.Value.Month == selMonth);
|
|
_query += "月份:" + selMonth + "\n";
|
|
}
|
|
else if (selMode == "ss" && selSeason > 0)
|
|
{
|
|
if (selSeason == 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 (selSeason == 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 (selSeason == 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 (selSeason == 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 += "季度:" + selSeason + "\n";
|
|
}
|
|
|
|
qry = qry.OrderByDescending(o => o.num);
|
|
return qry.ToList();
|
|
}
|
|
else
|
|
// 匯出查詢資料
|
|
{
|
|
//紀錄匯出條件
|
|
if (!isStrNull(s_f_number.Value))
|
|
{
|
|
qry = qry.Where(o => o.f_number.Contains(s_f_number.Value.Trim()));
|
|
|
|
_query += "信眾編號:" + s_f_number.Value.Trim() + "\n";
|
|
|
|
}
|
|
|
|
if (!isStrNull(s_u_name.Value))
|
|
{
|
|
qry = qry.Where(o => o.u_name.Contains(s_u_name.Value.Trim()));
|
|
|
|
_query += "信眾姓名:" + s_u_name.Value.Trim() + "\n";
|
|
|
|
}
|
|
if (!isStrNull(s_address.Value))
|
|
{
|
|
qry = qry.Where(o => o.address.Contains(s_address.Value.Trim()));
|
|
_query += "地址:" + s_address.Value.Trim() + "\n";
|
|
}
|
|
|
|
// 電話/證號搜尋 (使用 search_keywords HEX 編碼)
|
|
if (!isStrNull(s_phone_idcode.Value) && GlobalVariables.UseSearchKeywords)
|
|
{
|
|
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
|
string hexSearch = encrypt.ConvertToHex(s_phone_idcode.Value.Trim());
|
|
if (!string.IsNullOrEmpty(hexSearch))
|
|
{
|
|
qry = qry.Where(o => o.search_keywords != null && o.search_keywords.Contains(hexSearch));
|
|
_query += "電話/證號:" + s_phone_idcode.Value.Trim() + "\n";
|
|
}
|
|
}
|
|
|
|
if (!isStrNull(s_birthday.Value) && isDate(s_birthday.Value))
|
|
{
|
|
var tmp_s_birthday = ValDate(s_birthday.Value);
|
|
qry = qry.Where(o => o.birthday >= tmp_s_birthday);
|
|
_query += "生日(起):" + s_birthday.Value.Trim() + "\n";
|
|
}
|
|
if (!isStrNull(s_birthday2.Value) && isDate(s_birthday2.Value))
|
|
{
|
|
var tmp_s_birthday2 = Convert.ToDateTime(s_birthday2.Value).AddDays(1);
|
|
qry = qry.Where(o => o.birthday < tmp_s_birthday2);
|
|
_query += "生日(訖):" + s_birthday2.Value.Trim() + "\n";
|
|
}
|
|
qry = qry.OrderByDescending(o => o.num);
|
|
return qry.ToList();
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
} |