diff --git a/web/App_Code/Model/Model.Context.cs b/web/App_Code/Model/Model.Context.cs index d4d20be..5362fde 100644 --- a/web/App_Code/Model/Model.Context.cs +++ b/web/App_Code/Model/Model.Context.cs @@ -94,6 +94,7 @@ namespace Model public virtual DbSet AncestralTabletRegistrant { get; set; } public virtual DbSet AncestralTabletStatus { get; set; } public virtual DbSet GuaDanOrderGuest { get; set; } + public virtual DbSet auto_enroll { get; set; } public virtual int pager_eztrust(Nullable startRowIndex, Nullable pageSize, string tableName, string columnName, string sqlWhere, string orderBy, ObjectParameter rowCount) { diff --git a/web/App_Code/Model/Model.Designer.cs b/web/App_Code/Model/Model.Designer.cs index dc691dc..b78332d 100644 --- a/web/App_Code/Model/Model.Designer.cs +++ b/web/App_Code/Model/Model.Designer.cs @@ -1,4 +1,4 @@ -// 已啟用模型 'D:\17168ERP\web\App_Code\Model\Model.edmx' 的 T4 程式碼產生。 +// 已啟用模型 'E:\17168ERP\web\App_Code\Model\Model.edmx' 的 T4 程式碼產生。 // 若要啟用舊版程式碼產生,請將 [程式碼產生策略] 設計工具屬性的值 //變更為 [舊版 ObjectContext]。當模型在設計工具中開啟時,這個屬性便可 //以在 [屬性] 視窗中使用。 diff --git a/web/App_Code/Model/Model.cs b/web/App_Code/Model/Model.cs index 1ca239e..a992412 100644 --- a/web/App_Code/Model/Model.cs +++ b/web/App_Code/Model/Model.cs @@ -184,6 +184,7 @@ namespace Model public string partno { get; set; } public string print_init { get; set; } public string is_reconcile { get; set; } + public Nullable sort_order { get; set; } public virtual actItem_kind actItem_kind { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] @@ -405,6 +406,10 @@ namespace Model public Nullable price { get; set; } public Nullable qty { get; set; } public Nullable reg_time { get; set; } + public Nullable has_yang_limit { get; set; } + public Nullable has_chao_limit { get; set; } + public Nullable yang_limit_count { get; set; } + public Nullable chao_limit_count { get; set; } public virtual actItem actItem { get; set; } public virtual activity activity { get; set; } @@ -676,6 +681,31 @@ namespace Model using System; using System.Collections.Generic; + public partial class auto_enroll + { + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] + public auto_enroll() + { + this.pro_order = new HashSet(); + } + + public int num { get; set; } + public int f_num { get; set; } + public System.DateTime start_date { get; set; } + public System.DateTime end_date { get; set; } + public string receipt_title { get; set; } + public string receipt_address { get; set; } + + public virtual follower followers { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection pro_order { get; set; } + } +} +namespace Model +{ + using System; + using System.Collections.Generic; + public partial class bed_kind { [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")] @@ -802,6 +832,7 @@ namespace Model public string smtp_def { get; set; } public string use_sender { get; set; } public string bed_order_no { get; set; } + public string last_auto_order_no { get; set; } } } namespace Model @@ -903,6 +934,7 @@ namespace Model this.transfer_register1 = new HashSet(); this.GuaDanOrder = new HashSet(); this.GuaDanOrderGuest = new HashSet(); + this.auto_enroll = new HashSet(); } public int num { get; set; } @@ -967,6 +999,8 @@ namespace Model public virtual ICollection GuaDanOrder { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection GuaDanOrderGuest { get; set; } + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] + public virtual ICollection auto_enroll { get; set; } } } namespace Model @@ -1340,6 +1374,7 @@ namespace Model public Nullable introducer { get; set; } public Nullable send_receipt { get; set; } public string receipt_title { get; set; } + public Nullable au_num { get; set; } public virtual activity activity { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] @@ -1348,6 +1383,7 @@ namespace Model public virtual follower follower1 { get; set; } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")] public virtual ICollection pro_order_detail { get; set; } + public virtual auto_enroll auto_enroll { get; set; } } } namespace Model diff --git a/web/App_Code/Model/Model.edmx b/web/App_Code/Model/Model.edmx index 9bd2192..5d13da6 100644 --- a/web/App_Code/Model/Model.edmx +++ b/web/App_Code/Model/Model.edmx @@ -91,6 +91,7 @@ + @@ -189,6 +190,10 @@ + + + + @@ -329,6 +334,17 @@ + + + + + + + + + + + @@ -400,6 +416,7 @@ + @@ -480,7 +497,7 @@ - + @@ -604,8 +621,8 @@ - - + + @@ -696,6 +713,7 @@ + @@ -980,7 +998,7 @@ - + @@ -1079,7 +1097,9 @@ - + + + @@ -1128,18 +1148,6 @@ - - - - - - - - - - - - @@ -1211,7 +1219,9 @@ - + + + @@ -1272,6 +1282,18 @@ + + + + + + + + + + + + @@ -1637,7 +1659,9 @@ - + + + @@ -1648,6 +1672,18 @@ + + + + + + + + + + + + @@ -1687,7 +1723,9 @@ - + + + @@ -1699,7 +1737,9 @@ - + + + @@ -2114,6 +2154,7 @@ + @@ -2157,7 +2198,7 @@ - + @@ -2205,10 +2246,6 @@ - - - - @@ -2249,6 +2286,10 @@ + + + + @@ -2373,6 +2414,10 @@ + + + + @@ -2613,6 +2658,7 @@ + @@ -2733,6 +2779,10 @@ + + + + @@ -2896,6 +2946,7 @@ + @@ -2972,8 +3023,9 @@ - + + @@ -3062,8 +3114,8 @@ - - + + @@ -3152,6 +3204,8 @@ + + @@ -4549,6 +4603,15 @@ + + + + + + + + + @@ -5266,6 +5329,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -5334,6 +5436,7 @@ + @@ -5448,6 +5551,10 @@ + + + + @@ -5587,6 +5694,7 @@ + @@ -5821,6 +5929,7 @@ + @@ -6314,6 +6423,18 @@ + + + + + + + + + + + + diff --git a/web/App_Code/Model/Model.edmx.diagram b/web/App_Code/Model/Model.edmx.diagram index 4147bfb..29df88e 100644 --- a/web/App_Code/Model/Model.edmx.diagram +++ b/web/App_Code/Model/Model.edmx.diagram @@ -9,7 +9,7 @@ - + @@ -162,6 +162,9 @@ + + + diff --git a/web/App_Code/admin.cs b/web/App_Code/admin.cs index b970cc4..4de3c17 100644 --- a/web/App_Code/admin.cs +++ b/web/App_Code/admin.cs @@ -28,7 +28,7 @@ namespace MyWeb public AdmItem info { get; set; } //定義欄位cookie==================start - public class AdmItem + public class AdmItem { public int num { get; set; } public string u_id { get; set; } diff --git a/web/App_Code/api/FollowerController.cs b/web/App_Code/api/FollowerController.cs index eb581d9..6df03f9 100644 --- a/web/App_Code/api/FollowerController.cs +++ b/web/App_Code/api/FollowerController.cs @@ -1,15 +1,20 @@ -using System; +using DocumentFormat.OpenXml.Drawing.Charts; +using DocumentFormat.OpenXml.Office2010.Excel; +using Model; +using MyWeb; +using Newtonsoft.Json; +using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; +using PagedList; +using System; +using System.Collections; using System.Collections.Generic; +using System.Data.Entity; +using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; -using PagedList; -using Newtonsoft.Json; -using System.Collections; -using DocumentFormat.OpenXml.Office2010.Excel; -using MyWeb; -using System.Data.Entity; +using System.Web.Razor.Tokenizer; // api/Follower //[ezAuthorize(Roles = "admin")]//群組:* @@ -103,17 +108,18 @@ public class FollowerController : ApiController { foreach (var item in prod) { - foreach (var item2 in item.pro_order_detail1) - item2.from_id = null; //清空訂單明細的陽上報恩者from_id //f_num設定串聯刪除 + //foreach (var item2 in item.pro_order_detail1) + // item2.from_id = null; //清空訂單明細的陽上報恩者from_id //f_num設定串聯刪除 - foreach (var item2 in item.pro_order) - item2.introducer = null; + //foreach (var item2 in item.pro_order) + // item2.introducer = null; - item.leader = null;//清空leader + //item.leader = null;//清空leader + _db.followers.RemoveRange(prod); } - _db.followers.RemoveRange(prod); + //_db.followers.RemoveRange(prod); _db.SaveChanges(); Model.admin_log admin_log = new Model.admin_log(); @@ -150,8 +156,10 @@ public class FollowerController : ApiController qry = qry.Where(o => o.u_name.Contains(q.u_name.Trim())); if (q.birthday.HasValue) qry = qry.Where(o => o.birthday >= q.birthday.Value); - if (q.birthday2.HasValue) - qry = qry.Where(o => o.birthday < Convert.ToDateTime(q.birthday2.Value).AddDays(1)); + if (q.birthday2.HasValue) { + var tmpBirthday2 = Convert.ToDateTime(q.birthday2.Value).AddDays(1); + qry = qry.Where(o => o.birthday < tmpBirthday2); + } if (!string.IsNullOrEmpty(q.address)) qry = qry.Where(o => o.address !=null && o.address.Contains(q.address.Trim())); //if (q.num.HasValue && q.num.Value>0) @@ -173,7 +181,7 @@ public class FollowerController : ApiController } } - + // 電話/證號搜尋 (使用 search_keywords HEX 編碼) if (!string.IsNullOrEmpty(q.phone_idcode) && GlobalVariables.UseSearchKeywords) { @@ -528,6 +536,203 @@ public class FollowerController : ApiController } + [HttpGet] + [Route("api/follower/GetAutoEnrollList/{id}")] + public IHttpActionResult GetAutoEnrollList(int id) + { + var prod = _db.auto_enroll.Where(q => q.f_num == id).ToList(); + var ret = new + { + list = prod.Select(x => new + { + num = x.num, + auto_enroll_start_date = x.start_date.ToString("yyyy-MM-dd"), + auto_enroll_end_date = x.end_date.ToString("yyyy-MM-dd"), + auto_enroll_receipt_title = x.receipt_title?? "", + auto_enroll_receipt_address = x.receipt_address?? "", + }), + + }; + return Ok(ret); + } + + [HttpPost] + [Route("api/follower/SaveAutoEnrollList")] + public IHttpActionResult SaveAutoEnrollList([FromBody] Model.auto_enroll item) + { + Model.auto_enroll autoEnroll; + if (item.num == 0) + { + // ===== 新增 ===== + autoEnroll = new Model.auto_enroll() + { + f_num = item.f_num, + start_date = item.start_date, + end_date = item.end_date, + receipt_title = string.IsNullOrEmpty(item.receipt_title) ? null : item.receipt_title.Trim(), + receipt_address = string.IsNullOrEmpty(item.receipt_address) ? null : item.receipt_address.Trim(), + } + ; + _db.auto_enroll.Add(autoEnroll); + _db.SaveChanges(); + CreateOrdersForActivities(item.f_num, autoEnroll.num, item.start_date, item.end_date, item.receipt_title, item.receipt_address); + } + else + { + // ===== 更新 ===== + autoEnroll = _db.auto_enroll.Where(q => q.num == item.num).FirstOrDefault(); + if (autoEnroll == null) return NotFound(); + + autoEnroll.start_date = item.start_date; + autoEnroll.end_date = item.end_date; + autoEnroll.receipt_title = item.receipt_title?.Trim() ?? null; + autoEnroll.receipt_address = item.receipt_address?.Trim() ?? null; + _db.SaveChanges(); + CreateOrdersForActivities(item.f_num, autoEnroll.num, item.start_date, item.end_date, item.receipt_title, item.receipt_address); + } + + try + { + var ret = new + { + num = autoEnroll.num, + start_date = autoEnroll.start_date.ToString("yyyy-MM-dd"), + end_date = autoEnroll.end_date.ToString("yyyy-MM-dd"), + receipt_title = autoEnroll.receipt_title, + receipt_address = autoEnroll.receipt_address, + }; + return Ok(ret); + } + catch(Exception ex) + { + return InternalServerError(ex); + } + } + + [HttpPost] + [Route("api/follower/GetAffectedOrders")] + public IHttpActionResult GetAffectedOrders([FromBody] Model.auto_enroll item, bool is_delete = false) + { + if (item == null) return BadRequest(); + try + { + IQueryable query = _db.pro_order + .Where(o => o.f_num == item.f_num + && o.order_no.StartsWith("AU") + && o.au_num == item.num); + + if (is_delete) + { + // 刪除:查期間內所有自動報名訂單 + query = query.Where(o => + o.activity.startDate_solar >= item.start_date && + o.activity.startDate_solar <= item.end_date + ); + } + else + { + // 修改:查不在新範圍內的訂單 + query = query.Where(o => + o.activity.startDate_solar < item.start_date || + o.activity.startDate_solar > item.end_date + ); + } + + var rawOrders = query.Select(o => new + { + o.order_no, + o.activity.subject, + o.activity.startDate_solar + }).ToList(); + + var affectedOrders = rawOrders.Select(o => new + { + order_no = o.order_no, + activityname = o.subject, + activitydate = o.startDate_solar?.ToString("yyyy/MM/dd") ?? "" + }).ToList(); + + return Ok(new + { + count = affectedOrders.Count, + list = affectedOrders + }); + } + catch (Exception ex) + { + return InternalServerError(ex.GetBaseException()); + } + } + + + [HttpDelete] + [Route("api/follower/DeleteAutoEnroll/{id}")] + public IHttpActionResult DeleteAutoEnroll(int id) + { + try + { + var prod = _db.auto_enroll.Where(q => q.num == id).FirstOrDefault(); + if (prod != null) + { + _db.auto_enroll.Remove(prod); + _db.SaveChanges(); + return Ok(); + } + else return NotFound(); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + + + [HttpGet] + [Route("api/follower/GetUnfilledActivityOrders/{id}")] + public IHttpActionResult GetUnfilledActivityOrders(int id, int page, int pageSize = 10, string sortBy = "", bool sortDesc = false) + { + try + { + var config = _db.auto_enroll.FirstOrDefault(x => x.num == id); + if (config == null) return NotFound(); + + var query = from o in _db.pro_order + join a in _db.activities on o.activity_num equals a.num + where o.f_num == config.f_num + && a.startDate_solar >= config.start_date + && a.startDate_solar <= config.end_date + && !_db.pro_order_detail.Any(d => d.order_no == o.order_no) + select new { o, a }; + + int totalCount = query.Count(); + + var pagedData = query + .OrderByDescending(x => x.o.order_no) + .Skip((page - 1) * pageSize) + .Take(pageSize) + .ToList() + .Select(x => new { + order_no = x.o.order_no, + startdate = x.a.startDate_solar?.ToString("yyyy/MM/dd") ?? "", + enddate = x.a.endDate_solar?.ToString("yyyy/MM/dd") ?? "", + activityname = x.a.subject, + category = x.a.activity_category_kind?.kind ?? "" + }); + + return Ok(new + { + list = pagedData, + count = totalCount, + page = page, + pageSize = pageSize + }); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } + } + [HttpPost] [Route("api/follower/GetTabletList")] @@ -655,8 +860,10 @@ public class FollowerController : ApiController list = orderrecord.Select(x => new { orderno = x.order_no, - startdate = x.reg_time, - endtime = x.up_time, + //startdate = x.reg_time, + //endtime = x.up_time, + startdate = x.activity.startDate_solar, + enddate = x.activity.endDate_solar, pwcount = x.pro_order_detail.Where(a => a.actItem.act_bom.Where(b => b.item_num == a.actItem_num && b.package_num == null).Count() == 0).Count(), amount = x.pro_order_detail.Select(o => (float?)o.price).Sum(), activityname = x.activity.subject, @@ -667,6 +874,31 @@ public class FollowerController : ApiController return Ok(data); } [HttpPost] + [Route("api/follower/pending_orders")] + public IHttpActionResult GetPendingOrders(int id, string targetDate) + { + + DateTime today = DateTime.Today; + if (!DateTime.TryParse(targetDate, out DateTime limitDate)) + { + limitDate = new DateTime(2099, 12, 31); + } + var orderrecord = _db.pro_order + .Where(x => x.f_num == id && x.activity.startDate_solar >= today && x.activity.startDate_solar < limitDate) + .Include(x => x.activity) + .ToList(); + var data = new + { + list = orderrecord.Select(x => new + { + orderno = x.order_no, + activitydate = x.activity.startDate_solar.Value.ToString("yyyy/MM/dd"), + activityname = x.activity.subject, + }) + }; + return Ok(data); + } + [HttpPost] [Route("api/follower/totalorderamount")] public IHttpActionResult GetTotalOrderCount(int id) { @@ -702,5 +934,132 @@ public class FollowerController : ApiController }; return Ok(data); } + + private void CreateOrdersForActivities(int f_num, int au_num, DateTime start_date, DateTime end_date, string receipt_title, string receipt_address) + { + var follower = _db.followers.Where(x => x.num == f_num).FirstOrDefault(); + var activities = _db.activities + .Where(x => + x.startDate_solar >= start_date && + x.startDate_solar <= end_date + ) + .ToList(); + + foreach (var activity in activities) + { + var existOrder = _db.pro_order + .Where(o => o.activity_num == activity.num && o.f_num == f_num) + .FirstOrDefault(); + + if (existOrder != null) { + existOrder.au_num = au_num; + _db.SaveChanges(); + continue; + } + + string newOrderNo = AutoOrderService.CreateAutoOrderNumber(_db); + string finalPhone = follower?.cellphone ?? follower?.phone ?? ""; + + var newOrder = new pro_order + { + order_no = newOrderNo, + up_time = DateTime.Now, + reg_time = DateTime.Now, + keyin1 = "A01", + f_num = f_num, + au_num = au_num, + phone = finalPhone, + address = string.IsNullOrEmpty(receipt_address) ? "" : receipt_address, + activity_num = activity.num, + receipt_title = receipt_title ?? "", + demo = "", + customize_data = "", + }; + _db.pro_order.Add(newOrder); + + // 抓取同活動分類的上一筆訂單,複製品項 + var latestOrder = _db.pro_order + .Where(o => + o.f_num == f_num && + o.activity.kind == activity.kind && + o.order_no != newOrderNo && + _db.pro_order_detail.Any(d => d.order_no == o.order_no) + ) + .OrderByDescending(o => o.order_no) + .FirstOrDefault(); + + if (latestOrder != null) + { + var prevDetails = _db.pro_order_detail + .Where(d => d.order_no == latestOrder.order_no) + .ToList(); + + foreach (var detail in prevDetails) + { + var newDetail = new pro_order_detail + { + order_no = newOrderNo, + actItem_num = detail.actItem_num, + parent_num = detail.parent_num, + print_id = detail.print_id, + f_num = detail.f_num, + f_num_tablet = detail.f_num_tablet, + address = detail.address, + from_id = detail.from_id, + from_id_tablet = detail.from_id_tablet, + bed_type = detail.bed_type, + qty = detail.qty, + price = detail.price, + start_date = DateTime.Today, + pay = detail.pay, + keyin1 = detail.keyin1, + demo = detail.demo, + customize_data = detail.customize_data, + printed_files = detail.printed_files, + UpdateTime = DateTime.Now, + }; + _db.pro_order_detail.Add(newDetail); + } + + } + } + + _db.SaveChanges(); + + + } + } +public static class AutoOrderService +{ + private static readonly object _lock = new object(); + + public static string CreateAutoOrderNumber(Model.ezEntities _db) + { + lock (_lock) + { + string prefix = "AU" + DateTime.Now.ToString("yyMMdd"); + + var company = _db.companies.FirstOrDefault(q => q.num == 1); + if (company == null) return ""; + + string order_no; + if (!string.IsNullOrEmpty(company.last_auto_order_no) && company.last_auto_order_no.StartsWith(prefix)) + { + string serialStr = company.last_auto_order_no.Replace(prefix, ""); + int nextSerial = int.Parse(serialStr) + 1; + order_no = prefix + nextSerial.ToString("0000"); + } + else + { + order_no = prefix + "0001"; + } + + company.last_auto_order_no = order_no; + _db.SaveChanges(); + + return order_no; + } + } +} diff --git a/web/App_Code/api/activityController.cs b/web/App_Code/api/activityController.cs index 2b40226..feaf43c 100644 --- a/web/App_Code/api/activityController.cs +++ b/web/App_Code/api/activityController.cs @@ -1,14 +1,19 @@ -using System; +using DocumentFormat.OpenXml.Drawing.Spreadsheet; +using Model; +using Newtonsoft.Json; +using Org.BouncyCastle.Crypto; +using PagedList; +using System; +using System.Collections; using System.Collections.Generic; +using System.Data.Entity; +using System.Diagnostics; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; -using PagedList; -using Newtonsoft.Json; -using System.Collections; +using System.Web.Services; using static TreeView; -using System.Data.Entity; // api/activity //[ezAuthorize(Roles = "admin")]//群組:* @@ -126,6 +131,12 @@ public class activityController : ApiController if (prod != null) { ////prod.IsDel = true; ////不確定是否新增欄位? 先註解 + + // 先刪除子項目 + var prod2 = _db.act_bom.Where(q => q.package_num == prod.num).ToList(); + _db.act_bom.RemoveRange(prod2); + + _db.actItems.Remove(prod); _db.SaveChanges(); Model.admin_log admin_log = new Model.admin_log(); MyWeb.admin admin = new MyWeb.admin();//api裡不可以用MyWeb @@ -190,12 +201,18 @@ public class activityController : ApiController if (prod.Count() > 0) { //var prod2 = _db.actItem_files.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.actItem_num))).ToList(); - var prod2 = _db.actItem_files.Where(q => ids.Contains(q.actItem_num)).ToList(); - if (prod2.Count > 0) - { - _db.actItem_files.RemoveRange(prod2); - //_db.SaveChanges(); - } + //var prod2 = _db.actItem_files.Where(q => ids.Contains(q.actItem_num)).ToList(); + //if (prod2.Count > 0) + //{ + // _db.actItem_files.RemoveRange(prod2); + // //_db.SaveChanges(); + //} + + // 先刪除子項目 + var parentBoms = _db.act_bom.Where(q => q.item_num.HasValue && ids.Contains(q.item_num.Value)).ToList(); + var parentIds = parentBoms.Select(x => x.num).ToList(); // 取得母件 id + var childBoms = _db.act_bom.Where(q => q.package_num.HasValue && parentIds.Contains(q.package_num.Value)).ToList(); + _db.act_bom.RemoveRange(childBoms); _db.actItems.RemoveRange(prod); _db.SaveChanges(); @@ -312,6 +329,36 @@ public class activityController : ApiController return Ok(ret); } + public class SortOrderRequest + { + public List ids { get; set; } + } + + [HttpPost] + [Route("api/activity/SaveItemList")] + public IHttpActionResult UpdateSortOrder([FromBody] SortOrderRequest request) + { + if (request == null || request.ids == null) return BadRequest(); + + using (Model.ezEntities _db = new Model.ezEntities()) + { + int totalCount = request.ids.Count; + + for (int i = 0; i < totalCount; i++) + { + int id = request.ids[i]; + var item = _db.actItems.FirstOrDefault(x => x.num == id); + if (item != null) + { + // 改成總數減去索引,這樣第一筆 (i=0) 會拿到最大的數字 + item.sort_order = totalCount - i; + } + } + _db.SaveChanges(); + } + return Ok(); + } + [HttpPost] [Route("api/activity/GetItemList")] public IHttpActionResult GetItemList([FromBody] Model.ViewModel.actItem q, int page, int pageSize = 10, @@ -416,8 +463,14 @@ public class activityController : ApiController else qry = qry.OrderBy(o => o.status); } - else + else if (sortBy.Equals("num")) + { qry = qry.OrderByDescending(o => o.num); + } + else + { + qry = qry.OrderByDescending(o => o.sort_order); + } var tdesc = publicFun.enum_desc(); var count = qry.Count(); //pageSize = count;//一次取回?? @@ -750,7 +803,7 @@ public class activityController : ApiController //已有值 var count = qry.Count(); //pageSize = count;//一次取回?? - var qryList = (pageSize > 0) ? qry.OrderBy(a=>a.num).ToPagedList(page, pageSize).ToList() : qry.ToList(); + var qryList = (pageSize > 0) ? qry.OrderBy(a => a.num).ToPagedList(page, pageSize).ToList() : qry.ToList(); var ret = new { list = qryList.Select(x => new @@ -906,6 +959,10 @@ public class activityController : ApiController }, price = x.price ?? 0, qty = x.qty ?? 0, + has_yang_limit = x.has_yang_limit ?? false, + has_chao_limit = x.has_yang_limit ?? false, + yang_limit_count = x.yang_limit_count ?? 0, + chao_limit_count = x.chao_limit_count ?? 0, files = x.actItem?.actItem_files.Select(f => new { num = f.file.num, @@ -1123,6 +1180,10 @@ public class activityController : ApiController if (item.qty.HasValue) { _data.qty = item.qty.Value; } else { _data.qty = null; } _data.reg_time = DateTime.Now; + if (item.has_yang_limit.HasValue) { _data.has_yang_limit = item.has_yang_limit; } + if (item.yang_limit_count >= 0) { _data.yang_limit_count = item.yang_limit_count.Value; } + if (item.has_chao_limit.HasValue) { _data.has_chao_limit = item.has_chao_limit; } + if (item.chao_limit_count >= 0) { _data.chao_limit_count = item.chao_limit_count.Value; } _db.SaveChanges(); var ret = _data.num; @@ -1143,6 +1204,10 @@ public class activityController : ApiController if (item.qty.HasValue) { _data.qty = item.qty.Value; } else { _data.qty = null; } _data.reg_time = DateTime.Now; + if (item.has_yang_limit.HasValue) { _data.has_yang_limit = item.has_yang_limit; } + if (item.yang_limit_count >= 0) { _data.yang_limit_count = item.yang_limit_count.Value; } + if (item.has_chao_limit.HasValue) { _data.has_chao_limit = item.has_chao_limit; } + if (item.chao_limit_count >= 0) { _data.chao_limit_count = item.chao_limit_count.Value; } _db.activity_relating.Add(_data); _db.SaveChanges(); @@ -1301,7 +1366,7 @@ public class activityController : ApiController [Route("api/activity/OrderCheckIn")] public IHttpActionResult OrderCheckIn([FromBody] Model.activity_check item) { - if (item.f_num.HasValue && item.activity_num.HasValue && item.qty.HasValue && item.status.HasValue) + if (item.f_num.HasValue && item.activity_num.HasValue && item.status.HasValue) { //同一天不能簽到兩次以上 Model.activity_check check = _db.activity_check @@ -1495,13 +1560,13 @@ public class activityController : ApiController var r1 = qry.ToList(); var r2 = r1.Select(x => new { num = x.num, subject = x.subject }); var count = qry.Count(); - + // 計算昨天和今天的日期範圍 var yesterdayStart = _now.Date.AddDays(-1); var yesterdayEnd = _now.Date; var todayStart = _now.Date; var todayEnd = _now.Date.AddDays(1); - + var ret = new { list = r1.Select(x => new @@ -1555,4 +1620,136 @@ public class activityController : ApiController return Ok(ret); } + [HttpGet] + [Route("api/activity/GetUnfilledOrdersByActivity/{num}")] + public IHttpActionResult GetUnfilledOrdersByActivity(int num) + { + try + { + var activityExists = _db.activities.Any(a => a.num == num); + if (!activityExists) return NotFound(); + + var query = from o in _db.pro_order + join f in _db.followers on o.f_num equals f.num into fg + from f in fg.DefaultIfEmpty() + where o.activity_num == num + && !_db.pro_order_detail.Any(d => d.order_no == o.order_no) + select new { o, f }; + + MyWeb.encrypt encrypt = new MyWeb.encrypt(); + + var unfilledOrders = query.ToList().Select(x => new + { + order_no = x.o.order_no, + f_number = x.f.f_number, + u_name = x.f != null ? x.f.u_name : "未知", + phone = !string.IsNullOrEmpty(x.f.cellphone) ? encrypt.DecryptAutoKey(x.f.cellphone) : (encrypt.DecryptAutoKey(x.f.phone) ?? ""), + order_date = x.o.reg_time.HasValue ? x.o.reg_time.Value.ToString("yyyy/MM/dd") : "", + }).ToList(); + + return Ok(new + { + list = unfilledOrders, + count = unfilledOrders.Count + }); + } + catch (Exception ex) + { + return InternalServerError(ex.GetBaseException()); + } + } + + [HttpPost] + [Route("api/activity/TriggerAutoEnroll/{activity_num}")] + public IHttpActionResult TriggerAutoEnroll(int activity_num) + { + try + { + var activity = _db.activities.FirstOrDefault(a => a.num == activity_num); + if (activity == null) return NotFound(); + if (!activity.startDate_solar.HasValue) return BadRequest("該活動沒有設定開始日期,無法執行自動報名。"); + + DateTime actDate = activity.startDate_solar.Value; + + var validConfigs = _db.auto_enroll + .Where(ae => actDate >= ae.start_date && actDate <= ae.end_date) + .ToList(); + + int successCount = 0; + + foreach (var config in validConfigs) + { + if (_db.pro_order.Any(o => o.activity_num == activity_num && o.f_num == config.f_num)) + continue; + + var follower = _db.followers.FirstOrDefault(f => f.num == config.f_num); + string newOrderNo = AutoOrderService.CreateAutoOrderNumber(_db); + + var newOrder = new pro_order + { + order_no = newOrderNo, + up_time = DateTime.Now, + reg_time = DateTime.Now, + keyin1 = "A01", + f_num = config.f_num, + au_num = config.num, + phone = follower?.cellphone ?? follower?.phone ?? "", + address = config.receipt_address ?? "", + activity_num = activity_num, + receipt_title = config.receipt_title ?? "", + demo = "系統於新增活動時自動報名", + }; + _db.pro_order.Add(newOrder); + + CopyLatestOrderDetails(newOrderNo, config.f_num, (int)activity.kind); + + successCount++; + } + + _db.SaveChanges(); + + return Ok(new + { + message = $"自動報名執行完畢,共為 {successCount} 位信眾完成報名。", + count = successCount + }); + } + catch (Exception ex) + { + return InternalServerError(ex.GetBaseException()); + } + } + private void CopyLatestOrderDetails(string newOrderNo, int f_num, int activityKind) + { + var latestOrder = _db.pro_order + .Where(o => o.f_num == f_num && o.activity.kind == activityKind && _db.pro_order_detail.Any(d => d.order_no == o.order_no)) + .OrderByDescending(o => o.order_no) + .FirstOrDefault(); + + if (latestOrder != null) + { + var prevDetails = _db.pro_order_detail.Where(d => d.order_no == latestOrder.order_no).ToList(); + foreach (var detail in prevDetails) + { + _db.pro_order_detail.Add(new pro_order_detail + { + order_no = newOrderNo, + actItem_num = detail.actItem_num, + parent_num = detail.parent_num, + print_id = detail.print_id, + f_num = detail.f_num, + f_num_tablet = detail.f_num_tablet, + address = detail.address, + from_id = detail.from_id, + from_id_tablet = detail.from_id_tablet, + qty = detail.qty, + price = detail.price, + start_date = DateTime.Today, + pay = 0, + UpdateTime = DateTime.Now + }); + } + } + } + } diff --git a/web/App_Code/api/orderController.cs b/web/App_Code/api/orderController.cs index 6260df2..d5d0c9a 100644 --- a/web/App_Code/api/orderController.cs +++ b/web/App_Code/api/orderController.cs @@ -1,17 +1,21 @@ -using System; +using DocumentFormat.OpenXml.Drawing.Charts; +using Model; +using MyWeb; +using Newtonsoft.Json; +using PagedList; +using System; +using System.Activities.Expressions; +using System.Collections; using System.Collections.Generic; +using System.Data.Entity; +using System.Data.Entity.Core.Objects; +using System.Diagnostics; +using System.IdentityModel.Metadata; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; -using PagedList; -using Newtonsoft.Json; -using System.Collections; using static TreeView; -using Model; -using System.IdentityModel.Metadata; -using MyWeb; -using DocumentFormat.OpenXml.Drawing.Charts; // api/order @@ -206,7 +210,7 @@ public class orderController : ApiController string sortBy = "", bool sortDesc = false) { - var qry = _db.pro_order.AsQueryable(); + var qry = _db.pro_order.Include("activity").Include("activity.activity_check").AsQueryable(); //var aIDt = _db.actItems.AsEnumerable().Where(f => f.subject.Contains(q.actItemTxt.Trim())).Select(f => f.num);//品項 @@ -221,7 +225,10 @@ public class orderController : ApiController if (q.up_time1.HasValue) qry = qry.Where(o => o.up_time >= q.up_time1.Value); if (q.up_time2.HasValue) - qry = qry.Where(o => o.up_time < Convert.ToDateTime(q.up_time2.Value).AddDays(1)); + { + var tmp_up_time2 = Convert.ToDateTime(q.up_time2.Value).AddDays(1); + qry = qry.Where(o => o.up_time < tmp_up_time2); + } if (!string.IsNullOrEmpty(q.address)) qry = qry.Where(o => o.address.Contains(q.address.Trim())); if (!string.IsNullOrEmpty(q.subject)) @@ -291,6 +298,13 @@ public class orderController : ApiController else qry = qry.OrderBy(o => o.activity != null ? o.activity.subject : ""); } + else if(sortBy.Equals("status")) + { + if (sortDesc) + qry = qry.OrderByDescending(o => o.activity.activity_check.FirstOrDefault(a => o.activity_num == a.activity_num && o.f_num == a.f_num).status ?? 0); + else + qry = qry.OrderBy(o => o.activity.activity_check.FirstOrDefault(a => o.activity_num == a.activity_num && o.f_num == a.f_num).status ?? 0); + } else qry = qry.OrderByDescending(o => o.reg_time); @@ -307,6 +321,7 @@ public class orderController : ApiController keyin1 = x.keyin1, up_time = x.up_time, keyin1_txt = Model.pro_order.keyin1_value_to_text(x.keyin1), + status = x.activity.activity_check.FirstOrDefault(a => x.activity_num == a.activity_num && x.f_num == a.f_num)?.status ?? 0, }), count = count }; @@ -338,7 +353,7 @@ public class orderController : ApiController //var qry1 = _db.pro_order_detail.AsEnumerable(); //qry1 = qry1.Where(o => o.order_no == order_no); //var qry1 = prod.pro_order_detail.AsEnumerable(); - var qry1 = prod.pro_order_detail.AsQueryable(); + var qry1 = prod.pro_order_detail.AsQueryable().Include(o => o.pro_order.activity.activity_relating); //if (!string.IsNullOrEmpty(q.subject)) // qry = qry.Where(o => o.subject.Contains(q.subject)); @@ -367,7 +382,7 @@ public class orderController : ApiController qry1 = qry1.OrderByDescending(o => o.num); } - + var tdesc = publicFun.enum_desc(); int i = 1; @@ -377,82 +392,91 @@ public class orderController : ApiController (List)qry1_list.ToPagedList(page, pageSize); var count = qry1_list.Count(); + + var ret = new { - list = qry1_list.Select(x => new - { - id = i++, - num = x.num, - order_no = x.order_no, - actitem_num_selected = new + list = qry1_list.Select(x => { + var tmpActivityRelating = x.pro_order?.activity?.activity_relating?.Where(a => a.actItem_num == x.actItem_num).FirstOrDefault(); + return new { - text = x.actItem_num.HasValue ? x.actItem.subject : "", - val = x.actItem_num.HasValue ? x.actItem_num.Value : 0, - }, - parent_num = x.parent_num, - f_num_selected = new - { - text = x.f_num.HasValue ? x.follower.u_name : "", - val = x.f_num.HasValue ? x.f_num.Value : 0, - }, - f_num_tablet = x.f_num_tablet, - print_id = x.print_id, - address = x.address, - due_date = x.due_date, - start_date = x.start_date, - extend_date = x.extend_date, - from_id_selected = new - { - text = x.from_id.HasValue ? x.follower1.u_name : "", - val = x.from_id.HasValue ? x.from_id : 0, - }, - from_id_tablet = x.from_id_tablet, - price = x.price ?? 0, - qty = x.qty ?? 0, - writeBedQty = bedDt.Where(b => b.bed_order.o_detail_id.Value == x.num && b.checkIn_date.HasValue && b.bed_kind_detail_id.HasValue).Count(), //已劃數量 - notBedQty = bedDt.Where(b => b.bed_order.o_detail_id.Value == x.num && (!b.checkIn_date.HasValue || !b.bed_kind_detail_id.HasValue)).Count(), //未劃數量 - //total = x.total.HasValue ? x.total.Value : 0, - category = x.actItem?.category, - //pay = x.pay ?? 0, - pay = x.pro_order_record.Select(c => c.price).Sum(), - pay_date = x.pay_date, - keyin1_selected = new - { - text = tdesc[x.keyin1.HasValue && x.keyin1.Value > 0 ? x.keyin1.Value : 1], - val = x.keyin1, - }, - demo = x.demo, - files = x.actItem?.actItem_files.Select(f => new - { - num = f.file.num, - subject = f.file.subject, - word = f.file.word, - cuz_column = f.file.customize_data ?? "", //?? - paperset = f.file.paperset ?? "", - }), - customize_data = x.customize_data ?? "", - customize_data_comb = new - { - from_id_cuz_data = "", - activity_cuz_data = "", - actitem_cuz_data = "", - order_cuz_data = "", - }, - printed_files = x.printed_files ?? "", - isPackage = (x.actItem.act_bom - .Any(ab => ab.package_num == null && ab.item_num != null) - ? 1 : 0), - bom_order = (x.actItem.act_bom - .Any(ab => ab.package_num == null && ab.item_num != null) - ? x.num.ToString() - : (x.parent_num.ToString() + x.num.ToString()) - ), - //cash_record = x.pro_order_record.Select( c => new { - // c, - // //pay_kind = tdesc2[c.payment.HasValue && x.keyin1.Value > 0 ? x.keyin1.Value : 1], - //}), + has_yang_limit = tmpActivityRelating?.has_yang_limit ?? false, + has_chao_limit = tmpActivityRelating?.has_chao_limit ?? false, + yang_limit_count = tmpActivityRelating?.yang_limit_count ?? 0, + chao_limit_count = tmpActivityRelating?.chao_limit_count ?? 0, + id = i++, + num = x.num, + order_no = x.order_no, + actitem_num_selected = new + { + text = x.actItem_num.HasValue ? x.actItem.subject : "", + val = x.actItem_num.HasValue ? x.actItem_num.Value : 0, + }, + parent_num = x.parent_num, + f_num_selected = new + { + text = x.f_num.HasValue ? x.follower.u_name : "", + val = x.f_num.HasValue ? x.f_num.Value : 0, + }, + f_num_tablet = x.f_num_tablet, + print_id = x.print_id, + address = x.address, + due_date = x.due_date, + start_date = x.start_date, + extend_date = x.extend_date, + from_id_selected = new + { + text = x.from_id.HasValue ? x.follower1.u_name : "", + val = x.from_id.HasValue ? x.from_id : 0, + }, + from_id_tablet = x.from_id_tablet, + price = x.price ?? 0, + qty = x.qty ?? 0, + writeBedQty = bedDt.Where(b => b.bed_order.o_detail_id.Value == x.num && b.checkIn_date.HasValue && b.bed_kind_detail_id.HasValue).Count(), //已劃數量 + notBedQty = bedDt.Where(b => b.bed_order.o_detail_id.Value == x.num && (!b.checkIn_date.HasValue || !b.bed_kind_detail_id.HasValue)).Count(), //未劃數量 + //total = x.total.HasValue ? x.total.Value : 0, + category = x.actItem?.category, + //pay = x.pay ?? 0, + pay = x.pro_order_record.Select(c => c.price).Sum(), + pay_date = x.pay_date, + keyin1_selected = new + { + text = tdesc[x.keyin1.HasValue && x.keyin1.Value > 0 ? x.keyin1.Value : 1], + val = x.keyin1, + }, + demo = x.demo, + files = x.actItem?.actItem_files.Select(f => new + { + num = f.file.num, + subject = f.file.subject, + word = f.file.word, + cuz_column = f.file.customize_data ?? "", //?? + paperset = f.file.paperset ?? "", + }), + customize_data = x.customize_data ?? "", + customize_data_comb = new + { + from_id_cuz_data = "", + activity_cuz_data = "", + actitem_cuz_data = "", + order_cuz_data = "", + }, + printed_files = x.printed_files ?? "", + isPackage = (x.actItem.act_bom + .Any(ab => ab.package_num == null && ab.item_num != null) + ? 1 : 0), + bom_order = (x.actItem.act_bom + .Any(ab => ab.package_num == null && ab.item_num != null) + ? x.num.ToString() + : (x.parent_num.ToString() + x.num.ToString()) + ), + //cash_record = x.pro_order_record.Select( c => new { + // c, + // //pay_kind = tdesc2[c.payment.HasValue && x.keyin1.Value > 0 ? x.keyin1.Value : 1], + //}), - }) + }; + }) .ToList() .OrderByDescending(x => (x.isPackage + (x.parent_num == null ? 0 : 1))) //.ThenBy(x => (x.parent_num == null ? 1 : 2)) // Top-level items first @@ -498,6 +522,10 @@ public class orderController : ApiController text = ar.actItem.subject, val = ar.actItem_num, }, + has_yang_limit = ar.has_yang_limit ?? false, + has_chao_limit = ar.has_chao_limit ?? false, + yang_limit_count = ar.yang_limit_count ?? 0, + chao_limit_count = ar.chao_limit_count ?? 0, parent_num = q.num, f_num_selected = new { @@ -578,6 +606,10 @@ public class orderController : ApiController text = x.actItem.subject, val = x.actItem.num, }, + has_yang_limit = x.has_yang_limit, + has_chao_limit = x.has_chao_limit, + yang_limit_count = x.yang_limit_count, + chao_limit_count = x.chao_limit_count, f_num_selected = new { text = "", @@ -683,7 +715,7 @@ public class orderController : ApiController .Where(q => q.num == item.num) .FirstOrDefault();//修改 if (order != null) - { + { order.actItem_num = (item.actItem_num.HasValue && item.actItem_num.Value > 0) ? item.actItem_num : null; order.f_num = (item.f_num.HasValue && item.f_num.Value > 0) diff --git a/web/admin/Templates/TBS5ADM001/uc/menu.ascx b/web/admin/Templates/TBS5ADM001/uc/menu.ascx index cd408e4..153319a 100644 --- a/web/admin/Templates/TBS5ADM001/uc/menu.ascx +++ b/web/admin/Templates/TBS5ADM001/uc/menu.ascx @@ -16,6 +16,8 @@ " + onclick="sessionStorage.removeItem('member_list_cache'); sessionStorage.removeItem('member_query_params'); + sessionStorage.removeItem('order_list_cache'); sessionStorage.removeItem('order_query_params');" target="<%#(ValString(Eval("target"))=="B"?"_blank":"_self") %>"> <%#Eval("title") %> diff --git a/web/admin/activity/index2.aspx b/web/admin/activity/index2.aspx index 524c8dc..973af5b 100644 --- a/web/admin/activity/index2.aspx +++ b/web/admin/activity/index2.aspx @@ -7,19 +7,20 @@
<%--
--%> -
+ +
-
- 匯出Excel + 編輯排列順序 + 完成編輯 +
+ + 匯出Excel -
+
- +
- + + + @@ -352,12 +453,12 @@ - + + + + + + + + + {{ confirm_dialog.title }} + mdi-close + + + +

{{ confirm_dialog.desc }}

+ + + + + + +
+ + + + {{ confirm_dialog.btn_keep_text }} + + + + {{ confirm_dialog.btn_cancel_text }} + + +
+
+
+
\ No newline at end of file diff --git a/web/admin/follower/reg.aspx.cs b/web/admin/follower/reg.aspx.cs index a3be434..5b03916 100644 --- a/web/admin/follower/reg.aspx.cs +++ b/web/admin/follower/reg.aspx.cs @@ -1,34 +1,46 @@ -using System; +using Model; +using Newtonsoft.Json; +using System; using System.Collections; using System.Collections.Generic; +using System.Configuration; using System.Data; +using System.Data.Entity; using System.Data.OleDb; +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 System.Configuration; -using System.IO; -using System.Linq; -using System.Globalization; -using Model; +using static Model.activity_check; public partial class admin_follower_reg : MyWeb.config { private Model.ezEntities _db = new Model.ezEntities(); public ArrayList _tmp = new ArrayList(); + public bool isDataChanged = false; + public bool isAutoNumbering = ConfigurationManager.AppSettings["IsAutoNumbering"].ToString() == "true" ? true : false; protected void Page_Load(object sender, EventArgs e) { CallAjax(); if (!IsPostBack) - { + { InitEnumsOptions(identity_type); //身分別 //var qry = _db.followers.AsEnumerable(); - var qry = _db.followers.AsQueryable(); - + var qry = _db.followers.AsQueryable(); + if (isStrNull(Request["num"])) { + if (!isAutoNumbering) + { + f_number.ReadOnly = false; + } + if (!isStrNull(Request["leader"])) { int _num = Val(Request["leader"]); @@ -50,9 +62,14 @@ public partial class admin_follower_reg : MyWeb.config //預設國籍 country.Value = "158"; country_txt.Value = "中華民國(台灣)"; + + // 預設加入日期 + join_date.Text = DateTime.Now.ToString("yyyy-MM-dd"); } else { + f_number.ReadOnly = true; + int _num = Val(Request["num"]); var prod = qry.Where(q => q.num == _num).FirstOrDefault(); if (prod != null) @@ -127,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"); } @@ -138,7 +155,6 @@ public partial class admin_follower_reg : MyWeb.config modify_time.Text = prod.admin_log; } - edit.Visible = true; goback.Visible = true; add.Visible = false; @@ -163,10 +179,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) { @@ -190,7 +235,7 @@ public partial class admin_follower_reg : MyWeb.config { ObjValue.SetValue(followers, selectDate(textBox)); } - else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) + else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y")) { ObjValue.SetValue(followers, encrypt.EncryptAutoKey(textBox.Text.Trim())); @@ -206,8 +251,11 @@ public partial class admin_follower_reg : MyWeb.config } } } - // 使用新的 generate_f_number 方法,已內建重號檢查和重試機制 - followers.f_number = follower.generate_f_number(sex.SelectedValue); + if (isAutoNumbering) + { + // 使用新的 generate_f_number 方法,已內建重號檢查和重試機制 + followers.f_number = follower.generate_f_number(sex.SelectedValue); + } followers.identity_type = Val(identity_type.SelectedValue); if(!isStrNull(leader.Value)) followers.leader = Val(leader.Value); if (!isStrNull(country.Value)) followers.country = country.Value; @@ -240,6 +288,8 @@ public partial class admin_follower_reg : MyWeb.config 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.Insert, f_number.Text + u_name.Text); + Session["LastAddedID"] = followers.f_number; + Response.Redirect("index.aspx"); } else @@ -259,8 +309,8 @@ public partial class admin_follower_reg : MyWeb.config L_msg.Type = alert_type.danger; L_msg.Text = "信眾編號重複"; } - - } + + } } #endregion @@ -282,7 +332,7 @@ public partial class admin_follower_reg : MyWeb.config try { foreach (Control obj in cardBodyPanel.Controls) - { + { if (obj is TextBox) { var ObjValue = followers.GetType().GetProperty(obj.ID); @@ -298,10 +348,7 @@ public partial class admin_follower_reg : MyWeb.config } else ObjValue.SetValue(followers, null); - } - - } followers.identity_type = Val(identity_type.SelectedValue); @@ -310,22 +357,60 @@ public partial class admin_follower_reg : MyWeb.config followers.sex = sex.SelectedValue; followers.blood = blood.SelectedValue; followers.tab = tab.Value.Trim(','); - followers.admin_log = admin.info.u_id + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + //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); - + // 如果啟用 search_keywords 功能,生成並更新 search_keywords if (GlobalVariables.UseSearchKeywords) { followers.search_keywords = encrypt.GenerateSearchKeywords(followers); } - - _db.SaveChanges(); - 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.Update, f_number.Text + u_name.Text); + // 檢查是否有修改資料 + var entry = _db.Entry(followers); + this.isDataChanged = entry.CurrentValues.PropertyNames.Any(name => + { + if (name == "admin_log" || name == "follower_hash") + return false; - Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"])); + var originalVal = entry.OriginalValues[name]?.ToString(); + var currentVal = entry.CurrentValues[name]?.ToString(); + // 針對加密欄位進行特殊處理 + bool isEncryptedField = (name == "phone" || name == "id_code"); + + if (isEncryptedField) + { + string originalPlain = !string.IsNullOrEmpty(originalVal) ? encrypt.DecryptAutoKey(originalVal) : ""; + string currentPlain = !string.IsNullOrEmpty(currentVal) ? encrypt.DecryptAutoKey(currentVal) : ""; + return originalPlain.Trim() != currentPlain.Trim(); + } + + return !object.Equals(originalVal, currentVal); + }); + + if (this.isDataChanged) + { + followers.admin_log = admin.info.u_id + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"); + } + else + { + entry.State = EntityState.Unchanged; + } + + int isDataSaved = _db.SaveChanges(); + if (isDataSaved > 0) + { + //L_msg.Type = alert_type.success; + //L_msg.Text = "修改成功"; + 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.Update, f_number.Text + u_name.Text); + Response.Redirect("index.aspx?dirty=1&page=" + Convert.ToString(Request["page"])); + } + else + { + Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"])); + } } catch (Exception ex) { @@ -340,16 +425,16 @@ public partial class admin_follower_reg : MyWeb.config L_msg.Text = "查無資料"; } /* - if (chk_pro_num(f_number.Text, Val(Request["num"]))) - { - } - else - { - L_msg.Type = alert_type.danger; - L_msg.Text = "信眾編號重複"; - } - */ - } + if (chk_pro_num(f_number.Text, Val(Request["num"]))) + { + } + else + { + L_msg.Type = alert_type.danger; + L_msg.Text = "信眾編號重複"; + } + */ + } } #endregion diff --git a/web/admin/index.aspx b/web/admin/index.aspx index 54ae257..95fede5 100644 --- a/web/admin/index.aspx +++ b/web/admin/index.aspx @@ -85,7 +85,7 @@
- 登入
+ diff --git a/web/admin/menu.ascx b/web/admin/menu.ascx index b379ba8..8647bdc 100644 --- a/web/admin/menu.ascx +++ b/web/admin/menu.ascx @@ -8,7 +8,7 @@
    -
  • " +
  • " target="<%#(ValString(Eval("target"))=="B"?"_blank":"_self") %>"><%#Eval("title") %>
  • diff --git a/web/admin/order/index.aspx b/web/admin/order/index.aspx index f4e13da..974a16e 100644 --- a/web/admin/order/index.aspx +++ b/web/admin/order/index.aspx @@ -14,17 +14,18 @@ 列印管理報表 - - @@ -39,6 +40,8 @@ vuetify: new Vuetify(vuetify_options), data() { return { + print_error_msg: "", + isSearched: false, this_act : '<%= Request["act_id"]%>', options: { multiSort: false }, search_options: { multiSort: false }, @@ -56,6 +59,7 @@ { text: '報名日期', value: 'up_time' }, { text: '報名活動', value: 'subject', align: 'start' }, { text: '單據狀態', value: 'keyin1_txt' }, + { text: '報到狀態', value: 'status' }, { text: '', value: 'slot_btn', sortable: false, align: 'end' } ], footer:{ @@ -203,6 +207,10 @@ } }, mounted() { + const printResult = document.getElementById('<%= hid_err_msg.ClientID %>').value; + document.getElementById('<%= hid_err_msg.ClientID %>').value = ''; + window._printResult = printResult + this.detalKeyinArray(); this.search_dialog.current = this.search_dialog.controls.search1 ///default if (this.this_act != '') @@ -211,20 +219,63 @@ this.initActivity(); const navEntries = performance.getEntriesByType("navigation"); const isReload = navEntries.length > 0 && navEntries[0].type === "reload"; + if (isReload) { sessionStorage.removeItem("orderpage"); + sessionStorage.removeItem("order_list_cache"); + sessionStorage.removeItem("order_query_params"); + } + else if ("<%=lastAddedNo%>" !== "") { + const newQuery = { order_no: '<%=lastAddedNo%>' }; + sessionStorage.setItem('order_query_params', JSON.stringify(newQuery)); + this.search = newQuery; + this.isSearched = true; } else { const savedPage = parseInt(sessionStorage.getItem('orderpage')); + const savedData = sessionStorage.getItem("order_list_cache"); + const savedQuery = JSON.parse(sessionStorage.getItem("order_query_params")); + if (savedQuery) { + this.search = savedQuery; + this.isSearched = true; + } if (savedPage) { this.options.page = savedPage; } - } + if (savedData && savedData !== "undefined") { + this.data_table = JSON.parse(savedData); + this.isSearched = true; + } + } + + if (printResult === 'nodata' || printResult === 'success') { + + + this.$nextTick(() => { + this.print_dialog.show = true; + if (printResult === 'nodata') { + this.print_error_msg = "查無資料,請重新選擇區間"; + } + }); + } + + this.$nextTick(() => { + setTimeout(() => { + // 清空 URL + const cleanUrl = window.location.protocol + "//" + window.location.host + window.location.pathname; + window.history.replaceState({}, '', cleanUrl); + }, 100); + }); }, watch: { options: { handler() { - this.getDefault() + if (this.isSearched) { + this.getDefault() + } + else { + this.data_table.loading = false; + } }, deep: true, }, @@ -236,6 +287,57 @@ }, }, methods: { + triggerManagementExport(mode) { + this.print_error_msg = ""; + if (this.print_search.year == '') { + msgbox('請輸入年份'); + return; + } + if (!this.print_search.chk_noact && !this.print_search.chk_hasact) { + msgbox('活動/非活動至少勾選一項'); + return; + } + + // 將 Vue 狀態同步至 ASP.NET HiddenField,供後端 PostBack 讀取參數 + document.getElementById('<%= hid_print_mode.ClientID %>').value = this.print_conditions; + document.getElementById('<%= hid_print_year.ClientID %>').value = this.print_search.year; + if (this.print_conditions == 'mm') + document.getElementById('<%= hid_print_month.ClientID %>').value = this.print_search.month; + else if (this.print_conditions == 'ss') + document.getElementById('<%= hid_print_season.ClientID %>').value = this.print_search.season; + document.getElementById('<%= hid_select_act.ClientID %>').value = this.print_search.select_act; + document.getElementById('<%= hid_select_actitem.ClientID %>').value = this.print_search.select_actitem; + document.getElementById('<%= hid_chk_hasact.ClientID %>').value = this.print_search.chk_hasact; + document.getElementById('<%= hid_chk_noact.ClientID %>').value = this.print_search.chk_noact; + + let qry = ""; + Object.keys(this.print_search).forEach(key => { + if (this.print_search[key] != undefined && this.print_search[key] != null && this.print_search[key] != '') { + if (key == 'month' ) { + if (this.print_conditions == 'mm') { + qry += "&month=" + this.print_search.month; + } + } else if ( key == 'season') + { + if (this.print_conditions == 'ss') { + qry += "&season=" + this.print_search.season; + } + } + else { + qry += (qry != '' ? '&' : '?') + (key + '=' + this.print_search[key]); + } + + } + }); + document.getElementById('<%= hid_qry.ClientID %>').value = qry; + + if (mode === 'print') { + document.getElementById('<%= print_management.ClientID %>').click(); + } + else if (mode === "excel") { + document.getElementById('<%= excel_management.ClientID %>').click(); + } + }, search_show(curr) { //console.log("btn_click:", curr, curr.api_url); this.search_dialog.current = curr; @@ -321,19 +423,24 @@ this.data_table.list = response.data.list this.data_table.count = response.data.count; this.data_table.loading = false + + const dataToStore = JSON.stringify(this.data_table); + sessionStorage.setItem("order_list_cache", dataToStore); }) .catch(error => console.log(error)) }, detalKeyinArray() { var getArray = <%=Newtonsoft.Json.JsonConvert.SerializeObject(_keyin1Item, Newtonsoft.Json.Formatting.Indented) %>; - var keys = Object.keys(getArray); - for (let i = 0; i < keys.length; i++) { - //console.log(`${keys[i]}:${getArray[keys[i]]}`); //value : text - var _tmp = { - text: getArray[keys[i]], - val: parseInt(keys[i]), + if (getArray !== null) { + var keys = Object.keys(getArray); + for (let i = 0; i < keys.length; i++) { + //console.log(`${keys[i]}:${getArray[keys[i]]}`); //value : text + var _tmp = { + text: getArray[keys[i]], + val: parseInt(keys[i]), + } + this.keyin1_items.push(_tmp); } - this.keyin1_items.push(_tmp); } }, @@ -368,22 +475,28 @@ //} //this.data_table.selected = []; //this.data_table.count = this.data_table.list.length - location.reload(); + //location.reload(); + this.getDefault(); }) .catch(error => console.log(error)) } }, btn_search() { + this.isSearched = true; + sessionStorage.setItem("order_query_params", JSON.stringify(this.search)); this.this_act = ''; this.search.activity_num = ''; this.getDefault(true) + bootstrap.Offcanvas.getInstance(document.getElementById("offcanvasRight")).hide() }, btn_all() { + this.isSearched = false; this.this_act = ''; this.search.activity_num = ''; clearObjProps(this.search); - this.btn_search() + sessionStorage.setItem("order_query_params", JSON.stringify(this.search)); + //this.btn_search() }, checkInMsg(item) { this.check_data.f_num = item.f_num; @@ -392,39 +505,59 @@ this.check_data.activity_name = item.subject; this.check_dialog.show = true; }, - checkIn() { - if (this.check_data.qty > 0 && this.check_data.status.val > 0) { - var chechdata = - { - f_num: this.check_data.f_num, - activity_num: this.check_data.activity_num, - status: this.check_data.status.val, - qty: this.check_data.qty, - } - axios - .post(HTTP_HOST + 'api/activity/OrderCheckIn', chechdata) - .then(response => { - //清空 - this.check_data.f_num = 0; - this.check_data.u_name = ''; - this.check_data.activity_num = 0; - this.check_data.activity_name = ''; - this.check_data.qty = 1; - this.check_data.status.text = ''; - this.check_data.status.val = 1; - - this.check_dialog.show = false; - msgtop('簽到成功') - }) - .catch( - error => { - console.log(error) - msgtop('簽到失敗', 'error') - } - ) - } else { - msgbox('報到資訊請填寫完整'); + checkIn(item) { + var checkdata = + { + f_num: item.f_num, + activity_num: item.activity_num, + status: 1, + qty: 1, } + console.log(checkdata) + axios + .post(HTTP_HOST + 'api/activity/OrderCheckIn', checkdata) + .then(response => { + msgtop('簽到成功'); + this.getDefault(); + }) + .catch( + error => { + console.log(error) + msgtop('簽到失敗', 'error') + } + ) + //if (this.check_data.qty > 0 && this.check_data.status.val > 0) { + // var chechdata = + // { + // f_num: this.check_data.f_num, + // activity_num: this.check_data.activity_num, + // status: this.check_data.status.val, + // qty: this.check_data.qty, + // } + // axios + // .post(HTTP_HOST + 'api/activity/OrderCheckIn', chechdata) + // .then(response => { + // //清空 + // this.check_data.f_num = 0; + // this.check_data.u_name = ''; + // this.check_data.activity_num = 0; + // this.check_data.activity_name = ''; + // this.check_data.qty = 1; + // this.check_data.status.text = ''; + // this.check_data.status.val = 1; + + // this.check_dialog.show = false; + // msgtop('簽到成功') + // }) + // .catch( + // error => { + // console.log(error) + // msgtop('簽到失敗', 'error') + // } + // ) + //} else { + // msgbox('報到資訊請填寫完整'); + //} }, goPrint() { let _qry = ""; Object.keys(this.search).forEach(key => { @@ -442,6 +575,7 @@ //列印管理報表 print_close() { this.print_dialog.show = false; + this.print_error_msg = ""; } , initPrintSearch() { @@ -504,9 +638,9 @@ } } }); - + console.log(_qry); this.print_dialog.show = false; - window.open("print.aspx" + _qry, '_blank'); + //window.open("print.aspx" + _qry, '_blank'); } else { msgbox('活動/非活動至少勾選一項'); } @@ -537,7 +671,7 @@ initActivity() { axios.get(HTTP_HOST + 'api/activity') .then(response => { - this.select_act_list = response.data + this.select_act_list = response.data }) .catch(error => { console.log(error) @@ -556,10 +690,35 @@ $('#country2').val(''); VueApp.search.country2 = ''; }); + + $(document).ready(function () { + // 判斷是否彈出 search dialog + let hasSearchResult = sessionStorage.getItem("order_list_cache") !== null; + + if (!hasSearchResult && window._printResult === '') { + let $btn = $("a[data-bs-target='#offcanvasRight'][href='#search_panel']"); + $btn.click(); + let el = document.getElementById('offcanvasRight'); + let offcanvas = bootstrap.Offcanvas.getOrCreateInstance(el); + offcanvas.show(); + } + }); + + + + + + + + + + +