1. 新增法會活動品項:牌位陽上與超度人數限制功能

2. 信眾資料新增全年性選項以及開始參加活動日期,自動報名並代入前一次的報名資料(品項)
This commit is contained in:
2026-05-04 11:43:57 +08:00
parent 7644df57d0
commit 11a8c3e932
13 changed files with 995 additions and 104 deletions
+422 -5
View File
@@ -11,9 +11,11 @@ using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using static Model.activity_check;
public partial class admin_follower_reg : MyWeb.config
{
@@ -142,7 +144,7 @@ public partial class admin_follower_reg : MyWeb.config
country.Value = prod.country.ToString();
}
if (prod.reg_time.HasValue)
{
{
timePanel1.Visible = true;
reg_time.Text= prod.reg_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
}
@@ -153,6 +155,30 @@ public partial class admin_follower_reg : MyWeb.config
modify_time.Text = prod.admin_log;
}
if (!isStrNull(prod.is_auto_enroll))
{
hid_is_auto_enroll.Value = prod.is_auto_enroll.ToString();
}
if (prod.auto_enroll_start_date.HasValue)
{
hid_auto_enroll_start_date.Value = prod.auto_enroll_start_date.Value.ToString("yyyy-MM-dd");
}
if (prod.auto_enroll_is_receipt.HasValue)
{
hid_auto_enroll_is_receipt.Value = prod.auto_enroll_is_receipt.ToString();
}
if (!isStrNull(prod.auto_enroll_receipt_title))
{
hid_auto_enroll_receipt_title.Value = prod.auto_enroll_receipt_title.ToString();
}
if (!isStrNull(prod.auto_enroll_receipt_address))
{
hid_auto_enroll_receipt_address.Value = prod.auto_enroll_receipt_address.ToString();
}
edit.Visible = true;
goback.Visible = true;
@@ -178,10 +204,39 @@ public partial class admin_follower_reg : MyWeb.config
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
}
#region
protected string createOrderNumber()
{
Application.Lock();
string order_no = "AA" + DateTime.Now.ToString("yyMMdd");
var qry = _db.companies.AsQueryable();
//var prod = qry.Where(q => q.last_order_no.Contains(order_no)).FirstOrDefault();
var prod = qry.Where(q => q.num == 1).FirstOrDefault();
if (prod != null)
{
if (!isStrNull(prod.last_order_no) && prod.last_order_no.Contains(order_no))
{
int tmp = Convert.ToInt32(prod.last_order_no.Replace(order_no, "")) + 1;
order_no = order_no + tmp.ToString("0000");
}
else
{
order_no = order_no + "0001";
}
prod.last_order_no = order_no;
_db.SaveChanges();
}
else
order_no = "";
Application.UnLock();
return order_no;
}
protected void add_Click(object sender, EventArgs e)
{
if (Page.IsValid) {
@@ -237,12 +292,77 @@ public partial class admin_follower_reg : MyWeb.config
//tab
followers.tab = tab.Value.Trim(',');
if (!isStrNull(hid_is_auto_enroll.Value)) followers.is_auto_enroll = hid_is_auto_enroll.Value == "true";
if (!isStrNull(hid_auto_enroll_start_date.Value)) followers.auto_enroll_start_date = Convert.ToDateTime(hid_auto_enroll_start_date.Value);
if (!isStrNull(hid_auto_enroll_is_receipt.Value)) followers.auto_enroll_is_receipt = hid_auto_enroll_is_receipt.Value == "true";
if (!isStrNull(hid_auto_enroll_receipt_title.Value)) followers.auto_enroll_receipt_title = hid_auto_enroll_receipt_title.Value;
if (!isStrNull(hid_auto_enroll_receipt_address.Value)) followers.auto_enroll_receipt_address = hid_auto_enroll_receipt_address.Value;
string ChkNewMsg = Model.follower.ChkNewFollower(followers);
if(string.IsNullOrEmpty(ChkNewMsg))
{
_db.followers.Add(followers);
_db.SaveChanges();
if (hid_is_auto_enroll.Value == "true")
{
// 信眾自動報名
var qry = _db.activities.Where(a => a.startDate_solar >= followers.auto_enroll_start_date).AsQueryable();
var activities = qry.ToList();
if (activities != null)
{
try
{
foreach (var activity in activities)
{
Model.pro_order pro_order = new Model.pro_order(); //新增
bool isRegistered = _db.pro_order.Any(x => x.f_num == followers.num && x.activity_num == activity.num);
if (isRegistered) continue; // 重複報名
pro_order.order_no = createOrderNumber();
pro_order.up_time = DateTime.Now;
pro_order.reg_time = DateTime.Now;
pro_order.keyin1 = "A01";
pro_order.f_num = followers.num;
if (!isStrNull(followers.phone)) { pro_order.phone = followers.phone; }
if (!isStrNull(followers.cellphone)) { pro_order.phone = followers.cellphone; }
if (IsNumeric(activity.num)) { pro_order.activity_num = activity.num; }
pro_order.address = isStrNull(followers.auto_enroll_receipt_address) ? "" : followers.auto_enroll_receipt_address;
pro_order.receipt_title = isStrNull(followers.auto_enroll_receipt_title) ? "" : followers.auto_enroll_receipt_title;
pro_order.send_receipt = isStrNull(followers.auto_enroll_is_receipt) ? false : followers.auto_enroll_is_receipt;
pro_order.demo = "";
pro_order.customize_data = "";
try
{
if (!isStrNull(pro_order.order_no))
{
_db.pro_order.Add(pro_order);
_db.SaveChanges();
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.Insert, pro_order.order_no);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
//if (prod.Count > 0)
//{
// var orderNumbers = prod.Select(x => x.order_no).ToList();
// var qry = _db.pro_order_detail
// .Where(o => orderNumbers.Contains(o.order_no))
// }
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
}
int _id = followers.num;
@@ -301,6 +421,10 @@ public partial class admin_follower_reg : MyWeb.config
{
try
{
// 記錄修改前的舊值,供後續流程判斷
bool old_is_auto_enroll = followers.is_auto_enroll ?? false;
DateTime? old_auto_enroll_start_date = followers.auto_enroll_start_date;
foreach (Control obj in cardBodyPanel.Controls)
{
if (obj is TextBox)
@@ -318,10 +442,7 @@ public partial class admin_follower_reg : MyWeb.config
}
else
ObjValue.SetValue(followers, null);
}
}
followers.identity_type = Val(identity_type.SelectedValue);
@@ -333,6 +454,302 @@ public partial class admin_follower_reg : MyWeb.config
//followers.admin_log = admin.info.u_id + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
followers.follower_hash = encrypt.followerHash(followers.phone, followers.id_code);
if (!isStrNull(hid_is_auto_enroll.Value)) followers.is_auto_enroll = hid_is_auto_enroll.Value == "true";
if (!isStrNull(hid_auto_enroll_start_date.Value)) followers.auto_enroll_start_date = Convert.ToDateTime(hid_auto_enroll_start_date.Value);
if (!isStrNull(hid_auto_enroll_is_receipt.Value)) followers.auto_enroll_is_receipt = hid_auto_enroll_is_receipt.Value == "true";
if (!isStrNull(hid_auto_enroll_receipt_title.Value)) followers.auto_enroll_receipt_title = hid_auto_enroll_receipt_title.Value;
if (!isStrNull(hid_auto_enroll_receipt_address.Value)) followers.auto_enroll_receipt_address = hid_auto_enroll_receipt_address.Value;
// is_auto_enroll 從關 → 開,執行自動報名
bool new_is_auto_enroll = followers.is_auto_enroll ?? false;
bool isAutoEnrollTurnedOn = !old_is_auto_enroll && new_is_auto_enroll;
bool isAutoEnrollTurnedOff = old_is_auto_enroll && !new_is_auto_enroll;
// auto_enroll_start_date 有變更,確認是否刪除已有訂單
bool isStartDateChanged = followers.auto_enroll_start_date != old_auto_enroll_start_date;
// 關 → 開,執行自動報名
if (isAutoEnrollTurnedOn)
{
var qry = _db.activities.Where(a => a.startDate_solar >= followers.auto_enroll_start_date).AsQueryable();
var latestOrder = _db.pro_order.Where(o => o.f_num == followers.num).OrderByDescending(o => o.order_no).FirstOrDefault(); // 最近一次訂單
var activities = qry.ToList();
if (activities != null)
{
try
{
foreach (var activity in activities)
{
Model.pro_order pro_order = new Model.pro_order(); //新增
bool isRegistered = _db.pro_order.Any(x => x.f_num == followers.num && x.activity_num == activity.num);
if (isRegistered) continue; // 重複報名
pro_order.order_no = createOrderNumber();
pro_order.up_time = DateTime.Now;
pro_order.reg_time = DateTime.Now;
pro_order.keyin1 = "A01";
pro_order.f_num = followers.num;
if (!isStrNull(followers.phone)) { pro_order.phone = followers.phone; }
if (!isStrNull(followers.cellphone)) { pro_order.phone = followers.cellphone; }
if (IsNumeric(activity.num)) { pro_order.activity_num = activity.num; }
pro_order.address = isStrNull(followers.auto_enroll_receipt_address) ? "" : followers.auto_enroll_receipt_address;
pro_order.receipt_title = isStrNull(followers.auto_enroll_receipt_title) ? "" : followers.auto_enroll_receipt_title;
pro_order.send_receipt = isStrNull(followers.auto_enroll_is_receipt) ? false : followers.auto_enroll_is_receipt;
pro_order.demo = "";
pro_order.customize_data = "";
try
{
if (!isStrNull(pro_order.order_no))
{
Debug.WriteLine(pro_order.order_no);
_db.pro_order.Add(pro_order);
_db.SaveChanges();
// 報名品項(最近一次訂單內容)
if (latestOrder != null)
{
Debug.WriteLine("上次的單號 ", latestOrder.order_no);
var last_order_details = _db.pro_order_detail.Where(o => o.order_no == latestOrder.order_no).ToList();
foreach (var last_order_detail in last_order_details)
{
Model.pro_order_detail order_detail = new Model.pro_order_detail();
order_detail.order_no = pro_order.order_no;
order_detail.actItem = last_order_detail.actItem;
order_detail.parent_num = last_order_detail.parent_num;
order_detail.print_id = last_order_detail.print_id;
order_detail.f_num = last_order_detail.f_num;
order_detail.f_num_tablet = last_order_detail.f_num_tablet;
order_detail.address = last_order_detail.address;
order_detail.from_id = last_order_detail.from_id;
order_detail.from_id_tablet = last_order_detail.from_id_tablet;
order_detail.bed_type = last_order_detail.bed_type;
order_detail.qty = last_order_detail.qty;
order_detail.price = last_order_detail.price;
order_detail.start_date = DateTime.Today;
order_detail.pay = last_order_detail.pay;
order_detail.bed_type = last_order_detail.bed_type;
order_detail.keyin1 = last_order_detail.keyin1;
order_detail.demo = last_order_detail.demo;
order_detail.customize_data = last_order_detail.customize_data;
order_detail.printed_files = last_order_detail.printed_files;
order_detail.UpdateTime = DateTime.Now;
_db.pro_order_detail.Add(order_detail);
}
}
_db.SaveChanges();
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.Insert, pro_order.order_no);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
// 開 → 關,刪除自動報名訂單
if (isAutoEnrollTurnedOff && hid_is_delete_all_order.Value == "true")
{
if (!string.IsNullOrEmpty(hid_delete_order_list.Value))
{
var ids = hid_delete_order_list.Value.TrimEnd(',').Split(',');
Debug.WriteLine(ids);
var prod = _db.pro_order.Where(q => ids.Contains(q.order_no)).ToList();
if (prod.Count() > 0)
{
var prod2 = _db.pro_order_detail.Where(q => ids.Contains(q.order_no)).ToList();
if (prod2.Count > 0)
{
foreach (var item2 in prod2)
{
var prod3 = _db.bed_order.Where(q => q.order_no == item2.order_no && q.o_detail_id == item2.num).ToList();
if (prod3.Count > 0)
{
foreach (var item3 in prod3)
{
var prod4 = _db.bed_order_detail.Where(q => q.bed_order_no == item3.bed_order_no).ToList();
if (prod4.Count > 0)
{
_db.bed_order_detail.RemoveRange(prod4);
}
}
_db.bed_order.RemoveRange(prod3);
}
}
_db.pro_order_detail.RemoveRange(prod2);
_db.SaveChanges();
}
_db.pro_order.RemoveRange(prod);
_db.SaveChanges();
Model.admin_log admin_log = new Model.admin_log();
if (admin.isLoign())
{
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Order, (int)Model.admin_log.Status.Delete, admin_log.LogViewBtn(prod.Select(x => x.order_no).ToList()));
}
}
}
}
if (isStartDateChanged && old_auto_enroll_start_date.HasValue && !isAutoEnrollTurnedOff)
{
bool isDateMovedLater = followers.auto_enroll_start_date > old_auto_enroll_start_date; // 變晚
bool isDateMovedEarlier = followers.auto_enroll_start_date < old_auto_enroll_start_date; // 變早
// 日期變晚,刪除指定訂單
if (isDateMovedLater && hid_is_delete_all_order.Value == "true")
{
if (!string.IsNullOrEmpty(hid_delete_order_list.Value))
{
var ids = hid_delete_order_list.Value.TrimEnd(',').Split(',');
Debug.WriteLine(ids);
var prod = _db.pro_order.Where(q => ids.Contains(q.order_no)).ToList();
if (prod.Count() > 0)
{
//var prod2 = _db.pro_order_detail.ToList().Where(q => ids.Contains(Convert.ToString(q.order_no))).ToList();
var prod2 = _db.pro_order_detail.Where(q => ids.Contains(q.order_no)).ToList();
if (prod2.Count > 0)
{
foreach (var item2 in prod2)
{
var prod3 = _db.bed_order.Where(q => q.order_no == item2.order_no && q.o_detail_id == item2.num).ToList();
if (prod3.Count > 0)
{
foreach (var item3 in prod3)
{
var prod4 = _db.bed_order_detail.Where(q => q.bed_order_no == item3.bed_order_no).ToList();
if (prod4.Count > 0)
{
_db.bed_order_detail.RemoveRange(prod4);
}
}
_db.bed_order.RemoveRange(prod3);
}
}
_db.pro_order_detail.RemoveRange(prod2);
_db.SaveChanges();
}
_db.pro_order.RemoveRange(prod);
_db.SaveChanges();
Model.admin_log admin_log = new Model.admin_log();
if (admin.isLoign())
{
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Order, (int)Model.admin_log.Status.Delete, admin_log.LogViewBtn(prod.Select(x => x.order_no).ToList()));
}
}
}
}
// 日期變早,補報名
else if (isDateMovedEarlier && !isAutoEnrollTurnedOn)
{
var qry = _db.activities.Where(a =>
a.startDate_solar >= followers.auto_enroll_start_date &&
a.startDate_solar < old_auto_enroll_start_date);
var latestOrder = _db.pro_order.Where(o => o.f_num == followers.num).OrderByDescending(o => o.order_no).FirstOrDefault(); // 最近一次訂單
var activities = qry.ToList();
if (activities != null)
{
try
{
foreach (var activity in activities)
{
Model.pro_order pro_order = new Model.pro_order(); //新增
bool isRegistered = _db.pro_order.Any(x => x.f_num == followers.num && x.activity_num == activity.num);
if (isRegistered) continue; // 重複報名
pro_order.order_no = createOrderNumber();
pro_order.up_time = DateTime.Now;
pro_order.reg_time = DateTime.Now;
pro_order.keyin1 = "A01";
pro_order.f_num = followers.num;
if (!isStrNull(followers.phone)) { pro_order.phone = followers.phone; }
if (!isStrNull(followers.cellphone)) { pro_order.phone = followers.cellphone; }
if (IsNumeric(activity.num)) { pro_order.activity_num = activity.num; }
pro_order.address = isStrNull(followers.auto_enroll_receipt_address) ? "" : followers.auto_enroll_receipt_address;
pro_order.receipt_title = isStrNull(followers.auto_enroll_receipt_title) ? "" : followers.auto_enroll_receipt_title;
pro_order.send_receipt = isStrNull(followers.auto_enroll_is_receipt) ? false : followers.auto_enroll_is_receipt;
pro_order.demo = "";
pro_order.customize_data = "";
try
{
if (!isStrNull(pro_order.order_no))
{
Debug.WriteLine(pro_order.order_no);
_db.pro_order.Add(pro_order);
_db.SaveChanges();
// 報名品項(最近一次訂單內容)
if (latestOrder != null)
{
Debug.WriteLine("上次的單號 ", latestOrder.order_no);
var last_order_details = _db.pro_order_detail.Where(o => o.order_no == latestOrder.order_no).ToList();
foreach (var last_order_detail in last_order_details)
{
Model.pro_order_detail order_detail = new Model.pro_order_detail();
order_detail.order_no = pro_order.order_no;
order_detail.actItem = last_order_detail.actItem;
order_detail.parent_num = last_order_detail.parent_num;
order_detail.print_id = last_order_detail.print_id;
order_detail.f_num = last_order_detail.f_num;
order_detail.f_num_tablet = last_order_detail.f_num_tablet;
order_detail.address = last_order_detail.address;
order_detail.from_id = last_order_detail.from_id;
order_detail.from_id_tablet = last_order_detail.from_id_tablet;
order_detail.bed_type = last_order_detail.bed_type;
order_detail.qty = last_order_detail.qty;
order_detail.price = last_order_detail.price;
order_detail.start_date = DateTime.Today;
order_detail.pay = last_order_detail.pay;
order_detail.bed_type = last_order_detail.bed_type;
order_detail.keyin1 = last_order_detail.keyin1;
order_detail.demo = last_order_detail.demo;
order_detail.customize_data = last_order_detail.customize_data;
order_detail.printed_files = last_order_detail.printed_files;
order_detail.UpdateTime = DateTime.Now;
_db.pro_order_detail.Add(order_detail);
}
}
_db.SaveChanges();
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.Insert, pro_order.order_no);
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
}
}
// 如果啟用 search_keywords 功能,生成並更新 search_keywords
if (GlobalVariables.UseSearchKeywords)
{