Compare commits
14 Commits
hkj_guadan
...
d41ad3e4cc
| Author | SHA1 | Date | |
|---|---|---|---|
| d41ad3e4cc | |||
| ba6e641bac | |||
| 9969417bd8 | |||
| eff3ad778b | |||
| bc1f1422e9 | |||
| 1698b51d19 | |||
| 4e26dd648d | |||
| e20b250944 | |||
| e88821db4b | |||
| 3f63457c5a | |||
| 9a0d5ae700 | |||
| 79b7dd114f | |||
| cd05ad2305 | |||
| 5ae262205c |
12
review_report.txt
Normal file
12
review_report.txt
Normal file
@@ -0,0 +1,12 @@
|
||||
═══════════════════════════════════════════════════════════════
|
||||
🔍 AsEnumerable/AsQueryable/ToList 完整 REVIEW
|
||||
═══════════════════════════════════════════════════════════════
|
||||
|
||||
檢查範圍:Batch 1-3 所有已修改文件
|
||||
檢查標準:
|
||||
✅ 最佳選擇 - 性能和可讀性都最優
|
||||
⚠️ 可優化 - 可以進一步優化
|
||||
❌ 需修正 - 存在明顯問題
|
||||
|
||||
═══════════════════════════════════════════════════════════════
|
||||
|
||||
1
tyme4net/tyme4net
Submodule
1
tyme4net/tyme4net
Submodule
Submodule tyme4net/tyme4net added at 9ee8f71dac
@@ -52,7 +52,7 @@ public class FilesSetController : ApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.files.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.files.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//var prod2 = _db.actItem_files.AsEnumerable().Where(q => q.files_num == id).ToList(); //刪除品項的相關文件
|
||||
@@ -84,14 +84,14 @@ public class FilesSetController : ApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
|
||||
var prod = _db.files.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.files.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
//刪除品項的相關文件
|
||||
var prod2 = _db.actItem_files.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.files_num))).ToList();
|
||||
if (prod2.Count > 0)
|
||||
var prod2 = _db.actItem_files.Where(q => ids.Contains(q.files_num)).ToList();
|
||||
if (prod2.Count() > 0)
|
||||
{
|
||||
_db.actItem_files.RemoveRange(prod2);
|
||||
}
|
||||
@@ -123,7 +123,7 @@ public class FilesSetController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.files q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.files.AsEnumerable();
|
||||
var qry = _db.files.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject));
|
||||
@@ -157,9 +157,12 @@ public class FilesSetController : ApiController
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.subject,
|
||||
@@ -168,7 +171,7 @@ public class FilesSetController : ApiController
|
||||
word = x.word,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ public class FollowerController : ApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.followers.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.followers.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
/*if (prod != null)
|
||||
{
|
||||
|
||||
@@ -94,9 +94,9 @@ public class FollowerController : ApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
|
||||
var prod = _db.followers.AsEnumerable().Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
var prod = _db.followers.Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
foreach (var item in prod)
|
||||
@@ -139,8 +139,8 @@ public class FollowerController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.follower q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
////var qry = _db.followers.Where(a => a.IsDel == false).AsEnumerable();////不確定是否新增欄位? 先註解
|
||||
var qry = _db.followers.AsEnumerable();
|
||||
////var qry = _db.followers.Where(a => a.IsDel == false).AsQueryable();////不確定是否新增欄位? 先註解
|
||||
var qry = _db.followers.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.f_number))
|
||||
qry = qry.Where(o => o.f_number.Contains(q.f_number.Trim()));
|
||||
@@ -151,7 +151,7 @@ public class FollowerController : ApiController
|
||||
if (q.birthday2.HasValue)
|
||||
qry = qry.Where(o => o.birthday < Convert.ToDateTime(q.birthday2.Value).AddDays(1));
|
||||
if (!string.IsNullOrEmpty(q.address))
|
||||
qry = qry.Where(o => o.address !=null && o.address.Contains(q.address?.Trim()));
|
||||
qry = qry.Where(o => o.address !=null && o.address.Contains(q.address.Trim()));
|
||||
//if (q.num.HasValue && q.num.Value>0)
|
||||
// qry = qry.Where(o => o.num==q.num.Value);
|
||||
if (q.ept_self.HasValue && q.ept_self.Value )//排除自己
|
||||
@@ -215,9 +215,10 @@ public class FollowerController : ApiController
|
||||
|
||||
var tdesc = publicFun.enum_desc<Model.follower.type>();
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
f_number = x.f_number,
|
||||
@@ -339,9 +340,9 @@ public class FollowerController : ApiController
|
||||
|
||||
//int ccc = cc.Count();
|
||||
|
||||
|
||||
|
||||
var qry = _db.followers.AsEnumerable().Where(f => cc.Any(x => x == f.num) || cc.Any(x => x == f.leader));
|
||||
// 優化:使用子查詢在數據庫層面執行,避免載入所有家族成員 ID
|
||||
// 生成 SQL: WHERE num IN (SELECT...) OR leader IN (SELECT...)
|
||||
var qry = _db.followers.Where(f => cc.Contains(f.num) || (f.leader.HasValue && cc.Contains(f.leader.Value)));
|
||||
|
||||
|
||||
|
||||
@@ -359,11 +360,12 @@ public class FollowerController : ApiController
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
var tdesc = publicFun.enum_desc<Model.follower.type>();
|
||||
int i = 1;
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
int i = 1;
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -524,13 +526,14 @@ public class FollowerController : ApiController
|
||||
if (_follower > 0)
|
||||
{
|
||||
|
||||
var qry = _db.followers_tablet.AsEnumerable().Where(x=>( x.f_num??0) == _follower);
|
||||
var qry = _db.followers_tablet.Where(x=> x.f_num == _follower);
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
int i = 1;
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -593,7 +596,7 @@ public class FollowerController : ApiController
|
||||
[Route("api/follower/tabletDelete/{id}")]
|
||||
public void tabletDelete(int id)
|
||||
{
|
||||
var prod = _db.followers_tablet.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.followers_tablet.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.followers_tablet.Remove(prod);
|
||||
|
||||
@@ -52,7 +52,7 @@ public class accountingController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.accountings.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.accountings.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
var prod2 = prod.accounting_files;
|
||||
@@ -89,12 +89,12 @@ public class accountingController : BaseApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
|
||||
var prod = _db.accountings.AsEnumerable().Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
var prod = _db.accountings.Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
var prod2 = _db.accounting_files.AsEnumerable().Where(q => q.accounting_num.HasValue && getDelItem.Contains(q.accounting_num.Value)).ToList();
|
||||
var prod2 = _db.accounting_files.Where(q => q.accounting_num.HasValue && getDelItem.Contains(q.accounting_num.Value)).ToList();
|
||||
if (prod2.Count() > 0)
|
||||
{
|
||||
publicFun publicFun = new publicFun();
|
||||
@@ -126,7 +126,7 @@ public class accountingController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.accounting q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.accountings.AsEnumerable();
|
||||
var qry = _db.accountings.AsQueryable();
|
||||
|
||||
if (q.category.HasValue)
|
||||
qry = qry.Where(o => o.category == q.category.Value);
|
||||
@@ -215,10 +215,12 @@ public class accountingController : BaseApiController
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var tdesc = publicFun.enum_desc<Model.accounting.type>();
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
category = x.category,
|
||||
@@ -245,7 +247,7 @@ public class accountingController : BaseApiController
|
||||
total =(x.price ?? 0)+( x.tax?? 0),
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
|
||||
@@ -259,7 +261,7 @@ public class accountingController : BaseApiController
|
||||
public IHttpActionResult GetTitleKindList([FromBody] Model.ViewModel.accounting_kind q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.accounting_kind.AsEnumerable();
|
||||
var qry = _db.accounting_kind.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -297,7 +299,7 @@ public class accountingController : BaseApiController
|
||||
public IHttpActionResult GetAccountKindList([FromBody] Model.ViewModel.accounting_kind2 q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.accounting_kind2.AsEnumerable();
|
||||
var qry = _db.accounting_kind2.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -341,15 +343,16 @@ public class accountingController : BaseApiController
|
||||
if (q.accounting_num.HasValue && q.accounting_num.Value > 0)
|
||||
{
|
||||
//檢查
|
||||
var qry = _db.accounting_files.AsEnumerable();
|
||||
qry = qry.Where(o => o.accounting_num == q.accounting_num.Value);
|
||||
qry.OrderByDescending(x => x.num);
|
||||
var qry = _db.accounting_files.Where(o => o.accounting_num == q.accounting_num.Value);
|
||||
qry = qry.OrderByDescending(x => x.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
int i = 1;
|
||||
//已有值
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -357,7 +360,7 @@ public class accountingController : BaseApiController
|
||||
pic1 = x.pic1,
|
||||
pic1_name = x.pic1_name,
|
||||
}),
|
||||
count = qry.Count(),
|
||||
count = count,
|
||||
};
|
||||
|
||||
if (ret.list == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
@@ -473,7 +476,7 @@ public class accountingController : BaseApiController
|
||||
[Route("api/accounting/DeleteFilesItem/{id}")]//刪除相關檔案
|
||||
public void DeleteFilesItem(int id)
|
||||
{
|
||||
var prod = _db.accounting_files.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.accounting_files.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.pic1))
|
||||
|
||||
@@ -63,17 +63,17 @@ public class activityController : ApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.activities.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activities.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除相關資料
|
||||
var prod2 = _db.activity_relating.AsEnumerable().Where(q => q.activity_num == id).ToList(); //相關項目
|
||||
var prod2 = _db.activity_relating.Where(q => q.activity_num == id).ToList(); //相關項目
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
//查詢結果全部刪除
|
||||
_db.activity_relating.RemoveRange(prod2);
|
||||
}
|
||||
var prod3 = _db.activity_spares.AsEnumerable().Where(q => q.activity_num == id).ToList(); //備品項目
|
||||
var prod3 = _db.activity_spares.Where(q => q.activity_num == id).ToList(); //備品項目
|
||||
if (prod3.Count > 0)
|
||||
{
|
||||
_db.activity_spares.RemoveRange(prod3);
|
||||
@@ -98,7 +98,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteItem/{id}")]
|
||||
public void DeleteItem(int id)
|
||||
{
|
||||
var prod = _db.actItems.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.actItems.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
/*if (prod != null)
|
||||
{
|
||||
//var prod2 = _db.actItem_files.AsEnumerable().Where(q => q.actItem_num == id).ToList(); //相關項目
|
||||
@@ -144,11 +144,11 @@ public class activityController : ApiController
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
|
||||
var prod = _db.activities.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.activities.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
//var prod2 = _db.activity_relating.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.activity_num))).ToList();
|
||||
var prod2 = _db.activity_relating.AsEnumerable().Where(q => ids.Any(x => x == q.activity_num)).ToList();
|
||||
var prod2 = _db.activity_relating.Where(q => ids.Contains(q.activity_num)).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
_db.activity_relating.RemoveRange(prod2);
|
||||
@@ -156,7 +156,7 @@ public class activityController : ApiController
|
||||
}
|
||||
|
||||
//var prod3 = _db.activity_spares.AsEnumerable().Where(q => ids.Contains(Convert.ToInt32(q.activity_num))).ToList();
|
||||
var prod3 = _db.activity_spares.AsEnumerable().Where(q => ids.Any(x => x == q.activity_num)).ToList();
|
||||
var prod3 = _db.activity_spares.Where(q => ids.Contains(q.activity_num)).ToList();
|
||||
if (prod3.Count > 0)
|
||||
{
|
||||
_db.activity_spares.RemoveRange(prod3);
|
||||
@@ -186,11 +186,11 @@ public class activityController : ApiController
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.actItems.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.actItems.Where(q => ids.Contains(q.num)).ToList();
|
||||
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.AsEnumerable().Where(q => ids.Any(x => x == 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);
|
||||
@@ -281,10 +281,10 @@ public class activityController : ApiController
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
if (pageSize > 0) qry = qry.ToPagedList(page, pageSize);
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.subject,
|
||||
@@ -319,7 +319,7 @@ public class activityController : ApiController
|
||||
{
|
||||
|
||||
//var stockDt = _db.stocks.AsEnumerable(); ;//庫存
|
||||
var fileDt = _db.files.AsEnumerable().Where(f => f.subject.Contains(q.fileTxt)).Select(f => f.num.ToString());//文件
|
||||
var fileDt = _db.files.Where(f => f.subject.Contains(q.fileTxt)).Select(f => f.num.ToString());//文件
|
||||
|
||||
//每個品項在每個倉庫的結餘量
|
||||
var stockDt = (
|
||||
@@ -364,7 +364,7 @@ public class activityController : ApiController
|
||||
|
||||
}
|
||||
if (!string.IsNullOrEmpty(q.kindTxt))
|
||||
qry = qry.Where(o => o.actItem_kind?.kind != null && o.actItem_kind.kind.Contains(q.kindTxt));
|
||||
qry = qry.Where(o => o.actItem_kind != null && o.actItem_kind.kind != null && o.actItem_kind.kind.Contains(q.kindTxt));
|
||||
if (q.category.HasValue && q.category.Value > 0)
|
||||
qry = qry.Where(o => o.category == q.category.Value);
|
||||
if (!string.IsNullOrEmpty(q.categorys))
|
||||
@@ -410,10 +410,10 @@ public class activityController : ApiController
|
||||
|
||||
var tdesc = publicFun.enum_desc<Model.activity.category>();
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
if (pageSize > 0) qry = qry.ToPagedList(page, pageSize);
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.subject,
|
||||
@@ -711,7 +711,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteFilesItem/{id}")]//刪除品項的相關文件
|
||||
public void DeleteFilesItem(int id)
|
||||
{
|
||||
var prod = _db.actItem_files.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.actItem_files.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -731,16 +731,15 @@ public class activityController : ApiController
|
||||
if (this_id > 0)
|
||||
{
|
||||
//檢查
|
||||
var qry = _db.activity_kind_detail.AsEnumerable();
|
||||
qry = qry.Where(o => o.activity_kind_num == this_id);
|
||||
var qry = _db.activity_kind_detail.Where(o => o.activity_kind_num == this_id);
|
||||
int i = 1;
|
||||
|
||||
//已有值
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
if (pageSize > 0) qry = qry.ToPagedList(page, pageSize);
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -830,7 +829,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteActKindDetail/{id}")]//刪除活動分類的detail
|
||||
public void DeleteActKindDetail(int id)
|
||||
{
|
||||
var prod = _db.activity_kind_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_kind_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -849,7 +848,7 @@ public class activityController : ApiController
|
||||
if (this_act_id > 0)
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.activities.AsEnumerable().Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
var prod = _db.activities.Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
int kind = prod.kind ?? 0; //分類
|
||||
@@ -927,13 +926,12 @@ public class activityController : ApiController
|
||||
if (kind > 0)
|
||||
{
|
||||
int i = 1;
|
||||
var qry2 = _db.activity_kind_detail.AsEnumerable();
|
||||
qry2 = qry2.Where(o => o.activity_kind_num == kind);
|
||||
var qry2 = _db.activity_kind_detail.Where(o => o.activity_kind_num == kind);
|
||||
var count2 = qry2.Count(); //pageSize = count2;//一次取回??
|
||||
if (pageSize > 0) qry2 = qry2.ToPagedList(page, pageSize);
|
||||
var qry2List = (pageSize > 0) ? qry2.ToPagedList(page, pageSize).ToList() : qry2.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry2.Select(x => new
|
||||
list = qry2List.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = 0,
|
||||
@@ -992,7 +990,7 @@ public class activityController : ApiController
|
||||
public IHttpActionResult GetKindList([FromBody] Model.ViewModel.activity_kind q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.activity_kind.AsEnumerable();
|
||||
var qry = _db.activity_kind.AsQueryable();
|
||||
if (q.num.HasValue && q.num > 0)
|
||||
qry = qry.Where(o => o.num == q.num);
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
@@ -1031,7 +1029,7 @@ public class activityController : ApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var qry = _db.activity_kind.AsEnumerable();
|
||||
var qry = _db.activity_kind.AsQueryable();
|
||||
qry = qry.Where(o => o.num == id);
|
||||
var prop3 = qry.FirstOrDefault();
|
||||
if (prop3 != null)
|
||||
@@ -1151,7 +1149,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteRelatingData/{id}")]//刪除活動的相關資料
|
||||
public void DeleteRelatingData(int id)
|
||||
{
|
||||
var prod = _db.activity_relating.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_relating.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -1169,25 +1167,22 @@ public class activityController : ApiController
|
||||
if (this_act_id > 0)
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.activities.AsEnumerable().Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
var prod = _db.activities.Where(o => o.num == this_act_id).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
|
||||
int kind = prod.kind ?? 0; //分類
|
||||
|
||||
var qry1 = _db.activity_spares.AsEnumerable();
|
||||
qry1 = qry1.Where(o => o.activity_num == this_act_id);
|
||||
|
||||
qry1 = qry1.OrderBy(o => o.num);
|
||||
var qry1 = _db.activity_spares.Where(o => o.activity_num == this_act_id).OrderBy(o => o.num);
|
||||
|
||||
|
||||
var count = qry1.Count(); //pageSize = count;//一次取回??
|
||||
int i = 1;
|
||||
if (pageSize > 0) qry1 = qry1.ToPagedList(page, pageSize);
|
||||
var qry1List = (pageSize > 0) ? qry1.ToPagedList(page, pageSize).ToList() : qry1.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry1.Select(x => new
|
||||
list = qry1List.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -1278,7 +1273,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteSparesData/{id}")]//刪除活動的備品資料
|
||||
public void DeleteSparesData(int id)
|
||||
{
|
||||
var prod = _db.activity_spares.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_spares.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -1388,10 +1383,10 @@ public class activityController : ApiController
|
||||
|
||||
var tdesc = publicFun.enum_desc<Model.activity_check.keyin1>();
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
if (pageSize > 0) qry = qry.ToPagedList(page, pageSize);
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.activity?.subject,
|
||||
@@ -1416,7 +1411,7 @@ public class activityController : ApiController
|
||||
[Route("api/activity/DeleteCheck/{id}")]
|
||||
public void DeleteCheck(int id)
|
||||
{
|
||||
var prod = _db.activity_check.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_check.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -1439,7 +1434,7 @@ public class activityController : ApiController
|
||||
if (!string.IsNullOrEmpty(num[i]))
|
||||
ids[i] = Convert.ToInt32(num[i]);
|
||||
}
|
||||
var prod = _db.activity_check.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.activity_check.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
|
||||
@@ -1458,7 +1453,7 @@ public class activityController : ApiController
|
||||
{
|
||||
DateTime _now = DateTime.Now;
|
||||
|
||||
var qry = _db.activities.AsEnumerable();
|
||||
var qry = _db.activities.AsQueryable();
|
||||
|
||||
if (q.reg_time1.HasValue)
|
||||
qry = qry.Where(o => o.reg_time >= q.reg_time1.Value);
|
||||
@@ -1466,7 +1461,7 @@ public class activityController : ApiController
|
||||
qry = qry.Where(o => o.reg_time < Convert.ToDateTime(q.reg_time2.Value).AddDays(1));
|
||||
|
||||
|
||||
qry = qry.Where(o => (_now >= o.startDate_solar && _now < o.endDate_lunar) || (_now < o.startDate_solar && o.dueDate?.Date.CompareTo(_now) <= 180));
|
||||
qry = qry.Where(o => (_now >= o.startDate_solar && _now < o.endDate_lunar) || (_now < o.startDate_solar && o.dueDate.HasValue && o.dueDate.Value.Date.CompareTo(_now) <= 180));
|
||||
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
@@ -1510,7 +1505,7 @@ public class activityController : ApiController
|
||||
public IHttpActionResult GetCategoryKindList([FromBody] Model.ViewModel.activity_category_kind q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.activity_category_kind.AsEnumerable();
|
||||
var qry = _db.activity_category_kind.AsQueryable();
|
||||
if (q.num.HasValue && q.num > 0)
|
||||
qry = qry.Where(o => o.num == q.num);
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
@@ -1518,10 +1513,10 @@ public class activityController : ApiController
|
||||
qry = qry.OrderBy(O => O.kind).ThenBy(o => o.num);
|
||||
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
if (pageSize > 0) qry = qry.ToPagedList(page, pageSize);
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
kind = x.kind,
|
||||
|
||||
@@ -54,7 +54,7 @@ public class activity_kindController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.actItem_kind q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.actItem_kind.AsEnumerable();
|
||||
var qry = _db.actItem_kind.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
if (!string.IsNullOrEmpty(q.status))
|
||||
|
||||
@@ -52,7 +52,7 @@ public class adminUserController : ApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.admins.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.admins.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -76,7 +76,7 @@ public class adminUserController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.admin q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.admins.AsEnumerable();
|
||||
var qry = _db.admins.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.u_id))
|
||||
qry = qry.Where(o => o.u_id.Contains(q.u_id));
|
||||
@@ -90,17 +90,15 @@ public class adminUserController : ApiController
|
||||
|
||||
if(q.removeExist.HasValue && q.removeExist.Value)
|
||||
{
|
||||
// 優化:使用子查詢在數據庫層面執行,避免載入所有會員的 admin_num
|
||||
var usedAdminNums = _db.members.Select(b => b.admin_num);
|
||||
if (q.num.HasValue && q.num.Value > 0)
|
||||
{
|
||||
qry = qry.Where(o => (!(from b in _db.members.AsEnumerable()
|
||||
select b.admin_num)
|
||||
.Contains(o.num)) || o.num == Convert.ToInt32(q.num.Value));
|
||||
qry = qry.Where(o => !usedAdminNums.Contains(o.num) || o.num == q.num.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
qry = qry.Where(o => (!(from b in _db.members.AsEnumerable()
|
||||
select b.admin_num)
|
||||
.Contains(o.num)));
|
||||
qry = qry.Where(o => !usedAdminNums.Contains(o.num));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -114,9 +112,12 @@ public class adminUserController : ApiController
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
u_id = x.u_id,
|
||||
@@ -124,7 +125,7 @@ public class adminUserController : ApiController
|
||||
power = x.power,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -44,19 +44,22 @@ public class appellationController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.appellation q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.appellations.AsEnumerable();
|
||||
var qry = _db.appellations.AsQueryable();
|
||||
|
||||
|
||||
qry = qry.OrderBy(o => o.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
title = x.title,
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public class bedController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(string id)
|
||||
{
|
||||
var prod = _db.bed_order.AsEnumerable().Where(q => q.bed_order_no == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.bed_order.Where(q => q.bed_order_no == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除訂單明細
|
||||
@@ -80,7 +80,7 @@ public class bedController : BaseApiController
|
||||
{
|
||||
order_no = "ED" + DateTime.Now.ToString("yyMMdd");
|
||||
|
||||
var qry = _db.companies.AsEnumerable();
|
||||
var qry = _db.companies.AsQueryable();
|
||||
var prod = qry.Where(q => q.num == 1).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -157,16 +157,18 @@ public class bedController : BaseApiController
|
||||
public IHttpActionResult GetDetailList([FromBody] Model.bed_order q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.bed_order_detail.AsEnumerable();
|
||||
qry = qry.Where(o => o.bed_order_no == q.bed_order_no);
|
||||
var qry = _db.bed_order_detail.Where(o => o.bed_order_no == q.bed_order_no);
|
||||
|
||||
qry = qry.OrderBy(o => o.checkIn_date ).ThenBy(o => o.num);
|
||||
|
||||
int i = 1;
|
||||
var tdesc = publicFun.enum_desc<Model.bed_kind.bed_type>();
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -197,7 +199,7 @@ public class bedController : BaseApiController
|
||||
},
|
||||
license = x.license,
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
return Ok(ret);
|
||||
@@ -250,7 +252,7 @@ public class bedController : BaseApiController
|
||||
[Route("api/bed/DeleteBedDetail/{id}")]//刪除detail
|
||||
public void DeleteBedDetail(int id)
|
||||
{
|
||||
var prod = _db.bed_order_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.bed_order_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class bed_kindController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.bed_kind q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.bed_kind.AsEnumerable();
|
||||
var qry = _db.bed_kind.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
if (!string.IsNullOrEmpty(q.sex))
|
||||
@@ -60,16 +60,20 @@ public class bed_kindController : ApiController
|
||||
if (q.root.HasValue)
|
||||
qry = qry.Where(o => o.root.Value == q.root.Value);
|
||||
qry = qry.OrderBy(o => o.range).ThenBy(o => o.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
kind = x.kind,
|
||||
sex = x.sex,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
return Ok(ret);
|
||||
@@ -83,7 +87,7 @@ public class bed_kindController : ApiController
|
||||
var tdesc = publicFun.enum_desc<Model.bed_kind.bed_type>();
|
||||
//var tdesc2 = tdesc.ToArray().Select(x=>x.Value); //[0]單人床,[1]雙人床
|
||||
//var tdesc3 = tdesc.ToArray().Select(x=>x.Key); //[0]1,[1]2
|
||||
var qry = _db.bed_kind_detail.AsEnumerable();
|
||||
var qry = _db.bed_kind_detail.AsQueryable();
|
||||
if (q.bed_kind_id.HasValue)
|
||||
qry = qry.Where(o => o.bed_kind_id == q.bed_kind_id);
|
||||
if (!string.IsNullOrEmpty(q.bed_name))
|
||||
@@ -103,17 +107,19 @@ public class bed_kindController : ApiController
|
||||
if (q.inTime.HasValue )
|
||||
{
|
||||
//判斷日期沒庫存不能選
|
||||
var bedDt = _db.bed_order_detail.AsEnumerable().Where(f => f.checkIn_date.HasValue && f.checkIn_date ==q.inTime.Value ).Select(f => f.bed_kind_detail_id.ToString());//掛單表單明細
|
||||
qry = qry.Where(o => !bedDt.ToArray().Contains(o.num.ToString()));
|
||||
var bedDt = _db.bed_order_detail.Where(f => f.checkIn_date.HasValue && f.checkIn_date ==q.inTime.Value && f.bed_kind_detail_id.HasValue).Select(f => f.bed_kind_detail_id.Value).ToList();//掛單表單明細
|
||||
qry = qry.Where(o => !bedDt.Contains(o.num));
|
||||
|
||||
}
|
||||
qry = qry.OrderBy(o => o.bed_name);
|
||||
int i = 1;
|
||||
|
||||
if (pageSize > 0) qry = qry.ToPagedList(page, pageSize);
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -122,7 +128,7 @@ public class bed_kindController : ApiController
|
||||
bed_type_txt = x.bed_type.HasValue? tdesc[x.bed_type ?? 1] : "",
|
||||
demo = x.demo,
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
return Ok(ret);
|
||||
@@ -186,7 +192,7 @@ public class bed_kindController : ApiController
|
||||
[Route("api/bed_kind/DeleteBedKindDetail/{id}")]//刪除分類的detail
|
||||
public void DeleteActKindDetail(int id)
|
||||
{
|
||||
var prod = _db.bed_kind_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.bed_kind_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
|
||||
@@ -44,22 +44,25 @@ public class countryController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.country q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.countries.AsEnumerable();
|
||||
var qry = _db.countries.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.keyword))
|
||||
qry = qry.Where(o => o.ID.Contains(q.keyword.Trim()) || o.name_en.Contains(q.keyword.Trim()) || o.name_zh.Contains(q.keyword.Trim()));
|
||||
|
||||
qry = qry.OrderBy(o => o.range).ThenBy(o => o.name_en);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = x.ID,
|
||||
name_en = x.name_en,
|
||||
name_zh = x.name_zh,
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class memberController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.members.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.members.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
if(!string.IsNullOrEmpty(prod.pic1))
|
||||
@@ -79,7 +79,7 @@ public class memberController : BaseApiController
|
||||
[Route("api/member/DeleteCheck/{id}")]
|
||||
public void DeleteCheck(int id) //刪除考勤資料
|
||||
{
|
||||
var prod = _db.member_check.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.member_check.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.member_check.Remove(prod);
|
||||
@@ -93,9 +93,9 @@ public class memberController : BaseApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
|
||||
var prod = _db.members.AsEnumerable().Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
var prod = _db.members.Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
publicFun publicFun = new publicFun();
|
||||
@@ -107,8 +107,8 @@ public class memberController : BaseApiController
|
||||
}
|
||||
}
|
||||
|
||||
var prod2 = _db.member_check.AsEnumerable().Where(q => getDelItem.Contains(Convert.ToInt32(q.mem_num))).ToList();
|
||||
if (prod2.Count > 0)
|
||||
var prod2 = _db.member_check.Where(q => q.mem_num.HasValue && getDelItem.Contains(q.mem_num.Value)).ToList();
|
||||
if (prod2.Count() > 0)
|
||||
{
|
||||
_db.member_check.RemoveRange(prod2);
|
||||
//_db.SaveChanges();
|
||||
@@ -135,8 +135,8 @@ public class memberController : BaseApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.member_check.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
var prod = _db.member_check.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
_db.member_check.RemoveRange(prod);
|
||||
@@ -150,7 +150,7 @@ public class memberController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.member q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.members.AsEnumerable();
|
||||
var qry = _db.members.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.u_name))
|
||||
qry = qry.Where(o => o.u_name.Contains(q.u_name.Trim()));
|
||||
@@ -220,10 +220,11 @@ public class memberController : BaseApiController
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
m_number = x.m_number,
|
||||
@@ -242,7 +243,7 @@ public class memberController : BaseApiController
|
||||
starttime = x.group_kind.HasValue ? x.member_group.starttime : (object)null,
|
||||
demo = x.demo,
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
};
|
||||
|
||||
|
||||
@@ -256,7 +257,7 @@ public class memberController : BaseApiController
|
||||
public IHttpActionResult GetCheckList([FromBody] Model.ViewModel.member_check q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.member_check.AsEnumerable();
|
||||
var qry = _db.member_check.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.u_name))
|
||||
qry = qry.Where(o => o.member.u_name.Contains(q.u_name));
|
||||
@@ -317,9 +318,11 @@ public class memberController : BaseApiController
|
||||
|
||||
var tdesc = publicFun.enum_desc<Model.member.attendances.type>();
|
||||
var tdesc2 = publicFun.enum_desc<Model.member.attendances.login>();
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
m_number = x.member.m_number,
|
||||
@@ -332,7 +335,7 @@ public class memberController : BaseApiController
|
||||
login_type_desc = tdesc2[x.login_type ?? 1]
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
};
|
||||
|
||||
|
||||
@@ -346,7 +349,7 @@ public class memberController : BaseApiController
|
||||
public IHttpActionResult GetGroupList([FromBody] Model.ViewModel.member_group q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.member_group.AsEnumerable();
|
||||
var qry = _db.member_group.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -394,7 +397,7 @@ public class memberController : BaseApiController
|
||||
public IHttpActionResult GetTitleList([FromBody] Model.ViewModel.member_title q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.member_title.AsEnumerable();
|
||||
var qry = _db.member_title.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
|
||||
@@ -52,7 +52,7 @@ public class member_titleController : ApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.member_title q,
|
||||
int page, int pageSize = 10, string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.member_title.AsEnumerable();
|
||||
var qry = _db.member_title.AsQueryable();
|
||||
var ret = new { list = "", count = 0 };
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
@@ -49,11 +49,11 @@ public class newsController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.news.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.news.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除檔案
|
||||
var prod2 = _db.news_files.AsEnumerable().Where(q => q.news_id == id).ToList();
|
||||
var prod2 = _db.news_files.Where(q => q.news_id == id).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
foreach (var item in prod2)
|
||||
@@ -91,12 +91,12 @@ public class newsController : BaseApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
|
||||
var prod = _db.news.AsEnumerable().Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
var prod = _db.news.Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
var prod2 = _db.news_files.AsEnumerable().Where(q => getDelItem.Contains(q.news_id)).ToList();
|
||||
var prod2 = _db.news_files.Where(q => getDelItem.Contains(q.news_id)).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
publicFun publicFun = new publicFun();
|
||||
@@ -139,7 +139,7 @@ public class newsController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.news q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false, bool top = false)
|
||||
{
|
||||
var qry = _db.news.AsEnumerable();
|
||||
var qry = _db.news.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject.Trim()));
|
||||
@@ -258,10 +258,13 @@ public class newsController : BaseApiController
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.topping).ThenByDescending(o => o.num);
|
||||
}
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.subject,
|
||||
@@ -282,7 +285,7 @@ public class newsController : BaseApiController
|
||||
topping = x.topping
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
|
||||
@@ -298,7 +301,7 @@ public class newsController : BaseApiController
|
||||
{
|
||||
|
||||
|
||||
var qry = _db.news_kind.AsEnumerable();
|
||||
var qry = _db.news_kind.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -319,17 +322,18 @@ public class newsController : BaseApiController
|
||||
range = o.range,
|
||||
}).OrderBy(x => x.root).ThenBy(x => x.kind).ToList(), 0, 0);
|
||||
|
||||
|
||||
var count = qry.Count();
|
||||
var qry2List = (pageSize > 0) ? qry2.ToPagedList(page, pageSize).ToList() : qry2.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry2.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qry2List.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
kind = new TreeView().RptDash(x.Level) + x.kind,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -99,7 +99,7 @@ public class orderController : ApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var prod = _db.pro_order_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除掛單表單
|
||||
@@ -134,7 +134,7 @@ public class orderController : ApiController
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',');
|
||||
|
||||
var prod = _db.pro_order.AsEnumerable().Where(q => ids.Contains(q.order_no)).ToList();
|
||||
var prod = _db.pro_order.Where(q => ids.Contains(q.order_no)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
var prod2 = _db.pro_order_detail.AsEnumerable().Where(q => ids.Contains(Convert.ToString(q.order_no))).ToList();
|
||||
@@ -201,7 +201,7 @@ public class orderController : ApiController
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
|
||||
var qry = _db.pro_order.AsEnumerable();
|
||||
var qry = _db.pro_order.AsQueryable();
|
||||
//var aIDt = _db.actItems.AsEnumerable().Where(f => f.subject.Contains(q.actItemTxt.Trim())).Select(f => f.num);//品項
|
||||
|
||||
|
||||
@@ -220,32 +220,32 @@ public class orderController : ApiController
|
||||
if (!string.IsNullOrEmpty(q.address))
|
||||
qry = qry.Where(o => o.address.Contains(q.address.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(q.subject?.Trim()));
|
||||
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(q.subject.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.u_name))
|
||||
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(q.u_name?.Trim()));
|
||||
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(q.u_name.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.introducerTxt))
|
||||
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(q.introducerTxt?.Trim()));
|
||||
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(q.introducerTxt.Trim()));
|
||||
|
||||
if (!string.IsNullOrEmpty(q.actItemTxt))
|
||||
{
|
||||
//qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.ToArray().Contains(f2.actItem_num?.ToString())).Count() > 0);
|
||||
// qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.Any(x => x == f2.actItem_num)).Count() > 0);
|
||||
|
||||
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(q.actItemTxt?.Trim())).Count() > 0);
|
||||
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(q.actItemTxt.Trim())).Count() > 0);
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(q.country))
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == q.country);
|
||||
qry = qry.Where(o => o.f_num != null && o.follower != null && o.follower.country == q.country);
|
||||
if (!string.IsNullOrEmpty(q.country2))
|
||||
{
|
||||
if (q.country2 == "1")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == "158");
|
||||
qry = qry.Where(o => o.f_num != null && o.follower != null && o.follower.country == "158");
|
||||
}
|
||||
else if (q.country2 == "2")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country != "158");
|
||||
qry = qry.Where(o => o.f_num != null && o.follower != null && o.follower.country != "158");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -275,16 +275,16 @@ public class orderController : ApiController
|
||||
else if (sortBy.Equals("u_name"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.follower?.u_name);
|
||||
qry = qry.OrderByDescending(o => o.follower != null ? o.follower.u_name : "");
|
||||
else
|
||||
qry = qry.OrderBy(o => o.follower?.u_name);
|
||||
qry = qry.OrderBy(o => o.follower != null ? o.follower.u_name : "");
|
||||
}
|
||||
else if (sortBy.Equals("subject"))
|
||||
{
|
||||
if (sortDesc)
|
||||
qry = qry.OrderByDescending(o => o.activity?.subject);
|
||||
qry = qry.OrderByDescending(o => o.activity != null ? o.activity.subject : "");
|
||||
else
|
||||
qry = qry.OrderBy(o => o.activity?.subject);
|
||||
qry = qry.OrderBy(o => o.activity != null ? o.activity.subject : "");
|
||||
}
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.reg_time);
|
||||
@@ -801,15 +801,15 @@ public class orderController : ApiController
|
||||
{
|
||||
|
||||
//家族 : 家長是我的人,跟我同家長的人,我的家長本人,我本人
|
||||
var cc = _db.followers.Where(x => x.num == _follower || x.leader == _follower).Select(x => x.num);
|
||||
var qry = _db.followers.AsEnumerable().Where(f => cc.Any(x => x == f.num) || cc.Any(x => x == f.leader));
|
||||
var ccList = _db.followers.Where(x => x.num == _follower || x.leader == _follower).Select(x => x.num).ToList();
|
||||
var qry = _db.followers.Where(f => ccList.Contains(f.num) || (f.leader.HasValue && ccList.Contains(f.leader.Value)));
|
||||
|
||||
//未付款資料
|
||||
var unpayDt = _db.pro_order_detail.AsEnumerable();
|
||||
var unpayDt = _db.pro_order_detail.AsQueryable();
|
||||
var coDt = unpayDt.Where(x => x.keyin1 == (int)Model.pro_order.detailKeyin1.Collection);//只列出報名狀態為"收款中"的項目
|
||||
|
||||
//未付款訂單
|
||||
var orderDt = _db.pro_order.AsEnumerable();
|
||||
var orderDt = _db.pro_order.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(order_no))
|
||||
orderDt = orderDt.Where(x => x.order_no == order_no);
|
||||
orderDt = orderDt.Where(x => coDt.Select(d => d.order_no).Contains(x.order_no));
|
||||
@@ -855,7 +855,7 @@ public class orderController : ApiController
|
||||
{
|
||||
|
||||
//未付款資料
|
||||
var unpayDt = _db.pro_order_detail.AsEnumerable();
|
||||
var unpayDt = _db.pro_order_detail.AsQueryable();
|
||||
unpayDt = unpayDt.Where(x => x.keyin1 == (int)Model.pro_order.detailKeyin1.Collection);//只列出報名狀態為"收款中"的項目
|
||||
|
||||
if (!string.IsNullOrEmpty(q.order_no))
|
||||
@@ -1118,7 +1118,7 @@ public class orderController : ApiController
|
||||
[Route("api/order/DeleteRecordDetail/{id}")]//刪除收款註記
|
||||
public void DeleteRecordDetail(int id)
|
||||
{
|
||||
var prod = _db.pro_order_record.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order_record.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
|
||||
@@ -27,14 +27,14 @@ public class orderdetailController:ApiController
|
||||
//var OrderList = _db.pro_order.Where(u => u.activity_num == activity_num).Select(j => j.order_no).ToList();
|
||||
//var gdzOrderList = _db.pro_order_detail.Where(o => OrderList.Contains(o.order_no) && o.print_id.Contains("主")).Select(o => o.order_no).Distinct().ToList();
|
||||
//var qry = _db.pro_order.Where(u => gdzOrderList.Contains(u.order_no)).AsEnumerable();
|
||||
var qry = _db.pro_order.Where( u => u.activity_num == activity_num).AsEnumerable();
|
||||
|
||||
qry = qry.OrderByDescending(o => o.reg_time);
|
||||
var qry = _db.pro_order.Where( u => u.activity_num == activity_num).OrderByDescending(o => o.reg_time);
|
||||
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
order_no = x.order_no,
|
||||
f_num = x.f_num,
|
||||
@@ -50,7 +50,7 @@ public class orderdetailController:ApiController
|
||||
|| u.actItem.subject.Contains("牌")
|
||||
|| !string.IsNullOrEmpty(u.f_num_tablet))
|
||||
.Count(),
|
||||
actItem = x.pro_order_detail.Where(u => u.printed_files != null).FirstOrDefault()?.print_id }
|
||||
actItem = x.pro_order_detail.Where(u => u.printed_files != null).Select(u => u.print_id).FirstOrDefault() }
|
||||
}),
|
||||
count = count
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ public class projectController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.projects.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.projects.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.project_sub.RemoveRange(prod.project_sub); //刪除活動資料
|
||||
@@ -75,7 +75,7 @@ public class projectController : BaseApiController
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.projects.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var prod = _db.projects.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
foreach (var item in prod)
|
||||
@@ -103,7 +103,7 @@ public class projectController : BaseApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var prod = _db.project_sub.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.project_sub.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.project_sub.Remove(prod);
|
||||
@@ -117,7 +117,7 @@ public class projectController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.project q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.projects.AsEnumerable();
|
||||
var qry = _db.projects.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.subject.Contains(q.subject.Trim()));
|
||||
@@ -192,7 +192,7 @@ public class projectController : BaseApiController
|
||||
public IHttpActionResult GetKindList([FromBody] Model.ViewModel.project_kind q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.project_kind.AsEnumerable();
|
||||
var qry = _db.project_kind.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -247,7 +247,7 @@ public class projectController : BaseApiController
|
||||
|
||||
if (q.num.HasValue)
|
||||
{
|
||||
var qry = _db.project_sub.AsEnumerable();
|
||||
var qry = _db.project_sub.AsQueryable();
|
||||
|
||||
qry = qry.Where(o => o.pro_id == q.num.Value);
|
||||
|
||||
@@ -337,11 +337,11 @@ public class projectController : BaseApiController
|
||||
public IHttpActionResult GetPatronizeList([FromBody] Model.ViewModel.pro_order_detail q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var projectDt = _db.projects.AsEnumerable(); ;//專案
|
||||
var projectDt = _db.projects.AsQueryable(); ;//專案
|
||||
|
||||
try
|
||||
{
|
||||
var qry = _db.pro_order_detail.AsEnumerable();
|
||||
var qry = _db.pro_order_detail.AsQueryable();
|
||||
qry = qry.Where(o => (int?)o.actItem.category == (int)Model.activity.category.Patronize);
|
||||
|
||||
if (q.f_num.HasValue)
|
||||
|
||||
@@ -54,7 +54,7 @@ public class stockController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.stocks.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.stocks.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
var prod2 = prod.stock_files;
|
||||
@@ -85,11 +85,11 @@ public class stockController : BaseApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.stocks.AsEnumerable().Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
var getDelItem = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
var prod = _db.stocks.Where(q => getDelItem.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
var prod2 = _db.stock_files.AsEnumerable().Where(q => q.stock_num.HasValue && getDelItem.Contains(q.stock_num.Value)).ToList();
|
||||
var prod2 = _db.stock_files.Where(q => q.stock_num.HasValue && getDelItem.Contains(q.stock_num.Value)).ToList();
|
||||
if (prod2.Count() > 0)
|
||||
{
|
||||
publicFun publicFun = new publicFun();
|
||||
@@ -114,7 +114,7 @@ public class stockController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.stock q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.stocks.AsEnumerable();
|
||||
var qry = _db.stocks.AsQueryable();
|
||||
|
||||
if (q.category.HasValue)
|
||||
qry = qry.Where(o => o.category == q.category.Value);
|
||||
@@ -198,10 +198,12 @@ public class stockController : BaseApiController
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var tdesc = publicFun.enum_desc<Model.stock.type>();
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
category = x.category,
|
||||
@@ -230,7 +232,7 @@ public class stockController : BaseApiController
|
||||
price = x.price,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
|
||||
@@ -244,7 +246,7 @@ public class stockController : BaseApiController
|
||||
public IHttpActionResult GetKindList([FromBody] Model.ViewModel.stock_kind q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.stock_kind.AsEnumerable();
|
||||
var qry = _db.stock_kind.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -293,7 +295,7 @@ public class stockController : BaseApiController
|
||||
public IHttpActionResult GetReasonList([FromBody] Model.ViewModel.stock_reason q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.stock_reason.AsEnumerable();
|
||||
var qry = _db.stock_reason.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -335,15 +337,16 @@ public class stockController : BaseApiController
|
||||
if (q.stock_num.HasValue && q.stock_num.Value>0)
|
||||
{
|
||||
//檢查
|
||||
var qry = _db.stock_files.AsEnumerable();
|
||||
qry = qry.Where(o => o.stock_num == q.stock_num.Value);
|
||||
qry.OrderByDescending(x => x.num);
|
||||
var qry = _db.stock_files.Where(o => o.stock_num == q.stock_num.Value);
|
||||
qry = qry.OrderByDescending(x => x.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
int i = 1;
|
||||
//已有值
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
id = i++,
|
||||
num = x.num,
|
||||
@@ -351,7 +354,7 @@ public class stockController : BaseApiController
|
||||
pic1 = x.pic1,
|
||||
pic1_name = x.pic1_name,
|
||||
}),
|
||||
count = qry.Count(),
|
||||
count = count,
|
||||
};
|
||||
|
||||
if (ret.list == null) throw new HttpResponseException(HttpStatusCode.NotFound);
|
||||
@@ -466,7 +469,7 @@ public class stockController : BaseApiController
|
||||
[Route("api/stock/DeleteFilesItem/{id}")]//刪除相關檔案
|
||||
public void DeleteFilesItem(int id)
|
||||
{
|
||||
var prod = _db.stock_files.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.stock_files.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.pic1))
|
||||
|
||||
@@ -50,7 +50,7 @@ public class supplierController : BaseApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(int id)
|
||||
{
|
||||
var prod = _db.suppliers.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.suppliers.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.pic1))
|
||||
@@ -80,8 +80,8 @@ public class supplierController : BaseApiController
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nums))
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s));
|
||||
var prod = _db.suppliers.AsEnumerable().Where(q => ids.Contains(q.num)).ToList();
|
||||
var ids = nums.TrimEnd(',').Split(',').Select(s => int.Parse(s)).ToList();
|
||||
var prod = _db.suppliers.Where(q => ids.Contains(q.num)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
publicFun publicFun = new publicFun();
|
||||
@@ -113,7 +113,7 @@ public class supplierController : BaseApiController
|
||||
public IHttpActionResult GetList([FromBody] Model.ViewModel.supplier q, int page, int pageSize = 10,
|
||||
string sortBy = "", bool sortDesc = false)
|
||||
{
|
||||
var qry = _db.suppliers.AsEnumerable();
|
||||
var qry = _db.suppliers.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.u_name))
|
||||
qry = qry.Where(o => o.u_name.Contains(q.u_name.Trim()));
|
||||
@@ -159,9 +159,12 @@ public class supplierController : BaseApiController
|
||||
else
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
var count = qry.Count();
|
||||
var qryList = (pageSize > 0) ? qry.ToPagedList(page, pageSize).ToList() : qry.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qryList.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
u_name = x.u_name,
|
||||
@@ -176,7 +179,7 @@ public class supplierController : BaseApiController
|
||||
}).ToList(), x.kind) : "",
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
|
||||
};
|
||||
|
||||
@@ -192,7 +195,7 @@ public class supplierController : BaseApiController
|
||||
{
|
||||
|
||||
|
||||
var qry = _db.supplier_kind.AsEnumerable();
|
||||
var qry = _db.supplier_kind.AsQueryable();
|
||||
|
||||
if (!string.IsNullOrEmpty(q.kind))
|
||||
qry = qry.Where(o => o.kind.Contains(q.kind));
|
||||
@@ -205,17 +208,18 @@ public class supplierController : BaseApiController
|
||||
range = o.range,
|
||||
}).OrderBy(x => x.root).ThenBy(x => x.kind).ToList(), 0, 0);
|
||||
|
||||
|
||||
var count = qry.Count();
|
||||
var qry2List = (pageSize > 0) ? qry2.ToPagedList(page, pageSize).ToList() : qry2.ToList();
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry2.ToPagedList(page, pageSize).Select(x => new
|
||||
list = qry2List.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
kind = new TreeView().RptDash(x.Level) + x.kind,
|
||||
|
||||
}),
|
||||
count = qry.Count()
|
||||
count = count
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ public class transfer_registerController : ApiController
|
||||
x.draft,
|
||||
follower = x.f_num != null ? _db.followers
|
||||
.Where(f => f.num == x.f_num)
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(f => new {
|
||||
f.num,
|
||||
f.u_name,
|
||||
@@ -399,6 +399,7 @@ public class transfer_registerController : ApiController
|
||||
[Route("api/transfer_register/follower_orders")]
|
||||
public IHttpActionResult GetFollowerOrders(int f_num)
|
||||
{
|
||||
// TODO: 優化建議 - 考慮加入分頁或日期範圍限制,避免單一信眾訂單過多時載入大量數據
|
||||
// 取得該信眾的所有訂單及明細,並關聯活動名稱與品項名稱
|
||||
var details = _db.pro_order
|
||||
.Where(o => o.f_num == f_num)
|
||||
@@ -417,7 +418,7 @@ public class transfer_registerController : ApiController
|
||||
d.demo,
|
||||
reg_time = o.reg_time // 報名日期
|
||||
}))
|
||||
.AsEnumerable()
|
||||
.AsEnumerable() // 只在需要內存計算前轉換
|
||||
.Select(x => new {
|
||||
x.order_no,
|
||||
x.activity_num,
|
||||
@@ -481,7 +482,7 @@ public class transfer_registerController : ApiController
|
||||
x.draft,
|
||||
follower = x.f_num != null ? _db.followers
|
||||
.Where(f => f.num == x.f_num)
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(f => new {
|
||||
f.num,
|
||||
f.u_name,
|
||||
@@ -817,7 +818,7 @@ public class transfer_registerController : ApiController
|
||||
tr.balance_act_item,
|
||||
balance_actitem_name = tr.balance_act_item != null ? _db.actItems.Where(a => a.num == tr.balance_act_item).Select(a => a.subject).FirstOrDefault() : ""
|
||||
})
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(tr => new
|
||||
{
|
||||
tr.id,
|
||||
@@ -1044,6 +1045,9 @@ public class transfer_registerController : ApiController
|
||||
[Route("api/transfer_register/activity_followers")]
|
||||
public IHttpActionResult GetActivityFollowers(int activity_num)
|
||||
{
|
||||
// TODO: 性能優化 - 大型活動可能有數千筆訂單,建議:
|
||||
// 1. 在數據庫層面先過濾出未完成沖帳項目(避免載入所有訂單)
|
||||
// 2. 考慮加入 Take() 限制返回數量,或實作分頁
|
||||
// 查詢該法會中有報名單且有未完成沖帳項目的信眾
|
||||
var followers = _db.pro_order
|
||||
.Where(o => o.activity_num == activity_num)
|
||||
@@ -1054,7 +1058,7 @@ public class transfer_registerController : ApiController
|
||||
d.price,
|
||||
paid = d.pro_order_record.Select(r => r.price).DefaultIfEmpty(0).Sum()
|
||||
}))
|
||||
.AsEnumerable()
|
||||
.AsEnumerable() // 只在需要內存計算前轉換
|
||||
.Select(x => new {
|
||||
x.f_num,
|
||||
x.follower_name,
|
||||
@@ -1104,7 +1108,7 @@ public class transfer_registerController : ApiController
|
||||
d.demo,
|
||||
reg_time = o.reg_time // 報名日期
|
||||
}))
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(x => new {
|
||||
x.order_no,
|
||||
x.activity_num,
|
||||
|
||||
@@ -55,17 +55,17 @@ public class apporderController : ApiController
|
||||
// DELETE api/<controller>/5
|
||||
public void Delete(string id)
|
||||
{
|
||||
var prod = _db.pro_order.AsEnumerable().Where(q => q.order_no == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order.Where(q => q.order_no == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除掛單表單
|
||||
var prod3 = _db.bed_order.AsEnumerable().Where(q => q.order_no == id).ToList();
|
||||
var prod3 = _db.bed_order.Where(q => q.order_no == id).ToList();
|
||||
if (prod3.Count > 0)
|
||||
{
|
||||
//刪除掛單明細
|
||||
foreach (var item3 in prod3)
|
||||
{
|
||||
var prod4 = _db.bed_order_detail.AsEnumerable().Where(q => q.bed_order_no == item3.bed_order_no).ToList();
|
||||
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); //查詢結果全部刪除
|
||||
@@ -97,17 +97,17 @@ public class apporderController : ApiController
|
||||
{
|
||||
if (id > 0)
|
||||
{
|
||||
var prod = _db.pro_order_detail.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order_detail.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
//刪除掛單表單
|
||||
var prod3 = _db.bed_order.AsEnumerable().Where(q => q.order_no == prod.order_no).ToList();
|
||||
var prod3 = _db.bed_order.Where(q => q.order_no == prod.order_no).ToList();
|
||||
if (prod3.Count > 0) //count = 1
|
||||
{
|
||||
//刪除掛單明細
|
||||
foreach (var item3 in prod3)
|
||||
{
|
||||
var prod4 = _db.bed_order_detail.AsEnumerable().Where(q => q.bed_order_no == item3.bed_order_no).ToList();
|
||||
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); //查詢結果全部刪除
|
||||
@@ -132,20 +132,20 @@ public class apporderController : ApiController
|
||||
{
|
||||
var ids = nums.TrimEnd(',').Split(',');
|
||||
|
||||
var prod = _db.pro_order.AsEnumerable().Where(q => ids.Contains(q.order_no)).ToList();
|
||||
var prod = _db.pro_order.Where(q => ids.Contains(q.order_no)).ToList();
|
||||
if (prod.Count() > 0)
|
||||
{
|
||||
var prod2 = _db.pro_order_detail.AsEnumerable().Where(q => ids.Contains(Convert.ToString(q.order_no))).ToList();
|
||||
var prod2 = _db.pro_order_detail.Where(q => ids.Contains(Convert.ToString(q.order_no))).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
foreach (var item2 in prod2)
|
||||
{
|
||||
var prod3 = _db.bed_order.AsEnumerable().Where(q => q.order_no == item2.order_no && q.o_detail_id == item2.num).ToList();
|
||||
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.AsEnumerable().Where(q => q.bed_order_no == item3.bed_order_no).ToList();
|
||||
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);
|
||||
@@ -156,8 +156,8 @@ public class apporderController : ApiController
|
||||
}
|
||||
|
||||
|
||||
//var prod32 = _db.bed_order.AsEnumerable().Where(q => q.order_no == item2.order_no && q.o_detail_id == item2.num).ToList();
|
||||
//var prod42 = _db.bed_order_detail.AsEnumerable().Where(q => prod32.Select(qf => qf.order_no).ToArray().Contains(q.bed_order_no)).ToList();
|
||||
//var prod32 = _db.bed_order.Where(q => q.order_no == item2.order_no && q.o_detail_id == item2.num).ToList();
|
||||
//var prod42 = _db.bed_order_detail.Where(q => prod32.Select(qf => qf.order_no).ToArray().Contains(q.bed_order_no)).ToList();
|
||||
//_db.bed_order_detail.RemoveRange(prod42);
|
||||
//_db.bed_order.RemoveRange(prod32);
|
||||
|
||||
@@ -200,7 +200,7 @@ public class apporderController : ApiController
|
||||
{
|
||||
|
||||
var qry = _db.pro_order.AsEnumerable();
|
||||
//var aIDt = _db.actItems.AsEnumerable().Where(f => f.subject.Contains(q.actItemTxt.Trim())).Select(f => f.num);//品項
|
||||
//var aIDt = _db.actItems.Where(f => f.subject.Contains(q.actItemTxt.Trim())).Select(f => f.num);//品項
|
||||
|
||||
|
||||
if (!string.IsNullOrEmpty(q.order_no))
|
||||
@@ -218,32 +218,32 @@ public class apporderController : ApiController
|
||||
if (!string.IsNullOrEmpty(q.address))
|
||||
qry = qry.Where(o => o.address.Contains(q.address.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.subject))
|
||||
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(q.subject?.Trim()));
|
||||
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(q.subject.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.u_name))
|
||||
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(q.u_name?.Trim()));
|
||||
qry = qry.Where(o => o.f_num.HasValue && o.follower.u_name.Contains(q.u_name.Trim()));
|
||||
if (!string.IsNullOrEmpty(q.introducerTxt))
|
||||
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(q.introducerTxt?.Trim()));
|
||||
qry = qry.Where(o => o.introducer.HasValue && o.follower1.u_name.Contains(q.introducerTxt.Trim()));
|
||||
|
||||
if (!string.IsNullOrEmpty(q.actItemTxt))
|
||||
{
|
||||
//qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.ToArray().Contains(f2.actItem_num?.ToString())).Count() > 0);
|
||||
// qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.Any(x => x == f2.actItem_num)).Count() > 0);
|
||||
|
||||
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(q.actItemTxt?.Trim())).Count() > 0);
|
||||
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.actItem_num.HasValue && f2.actItem.subject.Contains(q.actItemTxt.Trim())).Count() > 0);
|
||||
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(q.country))
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == q.country);
|
||||
qry = qry.Where(o => o.f_num != null && o.follower != null && o.follower.country == q.country);
|
||||
if (!string.IsNullOrEmpty(q.country2))
|
||||
{
|
||||
if (q.country2 == "1")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == "158");
|
||||
qry = qry.Where(o => o.f_num != null && o.follower != null && o.follower.country == "158");
|
||||
}
|
||||
else if (q.country2 == "2")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country != "158");
|
||||
qry = qry.Where(o => o.f_num != null && o.follower != null && o.follower.country != "158");
|
||||
|
||||
}
|
||||
}
|
||||
@@ -317,11 +317,11 @@ public class apporderController : ApiController
|
||||
if (!string.IsNullOrEmpty( order_no ))
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.pro_order.AsEnumerable().Where(o => o.order_no == order_no).FirstOrDefault();
|
||||
var prod = _db.pro_order.Where(o => o.order_no == order_no).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
int activity = prod.activity_num.HasValue ? prod.activity_num.Value : 0; //活動
|
||||
var bedDt = _db.bed_order_detail.AsEnumerable().Where(b=>b.bed_order.order_no== order_no ); ;//掛單明細
|
||||
var bedDt = _db.bed_order_detail.Where(b=>b.bed_order.order_no== order_no ); ;//掛單明細
|
||||
|
||||
|
||||
//var qry1 = _db.pro_order_detail.AsEnumerable();
|
||||
@@ -435,7 +435,7 @@ public class apporderController : ApiController
|
||||
if (activity > 0)
|
||||
{
|
||||
i = 1;
|
||||
var qry2 = _db.activity_relating.AsEnumerable();
|
||||
var qry2 = _db.activity_relating.AsQueryable();
|
||||
qry2 = qry2.Where(o => o.activity_num == activity);
|
||||
|
||||
if (q.actItem_kind_num.HasValue)
|
||||
@@ -690,14 +690,14 @@ public class apporderController : ApiController
|
||||
|
||||
//家族 : 家長是我的人,跟我同家長的人,我的家長本人,我本人
|
||||
var cc = _db.followers.Where(x => x.num == _follower || x.leader == _follower).Select(x => x.num);
|
||||
var qry = _db.followers.AsEnumerable().Where(f => cc.Any(x => x == f.num) || cc.Any(x => x == f.leader));
|
||||
var qry = _db.followers.Where(f => cc.Any(x => x == f.num) || cc.Any(x => x == f.leader));
|
||||
|
||||
//未付款資料
|
||||
var unpayDt = _db.pro_order_detail.AsEnumerable();
|
||||
var unpayDt = _db.pro_order_detail.AsQueryable();
|
||||
var coDt = unpayDt.Where(x => x.keyin1 == (int)Model.pro_order.detailKeyin1.Collection);//只列出報名狀態為"收款中"的項目
|
||||
|
||||
//未付款訂單
|
||||
var orderDt = _db.pro_order.AsEnumerable();
|
||||
var orderDt = _db.pro_order.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(order_no))
|
||||
orderDt = orderDt.Where(x => x.order_no == order_no);
|
||||
orderDt = orderDt.Where(x => coDt.Select(d => d.order_no).Contains(x.order_no));
|
||||
@@ -737,7 +737,7 @@ public class apporderController : ApiController
|
||||
{
|
||||
|
||||
//未付款資料
|
||||
var unpayDt = _db.pro_order_detail.AsEnumerable();
|
||||
var unpayDt = _db.pro_order_detail.AsQueryable();
|
||||
unpayDt = unpayDt.Where(x => x.keyin1 == (int)Model.pro_order.detailKeyin1.Collection);//只列出報名狀態為"收款中"的項目
|
||||
|
||||
if (!string.IsNullOrEmpty(q.order_no))
|
||||
@@ -865,10 +865,10 @@ public class apporderController : ApiController
|
||||
if (u_name >0 && (!string.IsNullOrEmpty(q.order_no)))
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.pro_order.AsEnumerable().Where(o => o.f_num == u_name && o.order_no != q.order_no).ToList();
|
||||
var prod = _db.pro_order.Where(o => o.f_num == u_name && o.order_no != q.order_no).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
var qry = _db.pro_order_detail.AsEnumerable().Where(o => prod.Any(x => x.order_no==o.order_no) );
|
||||
var qry = _db.pro_order_detail.Where(o => prod.Any(x => x.order_no==o.order_no) );
|
||||
int i = 1;
|
||||
var ret = new
|
||||
{
|
||||
@@ -942,7 +942,7 @@ public class apporderController : ApiController
|
||||
if (detail_num > 0 )
|
||||
{
|
||||
//檢查
|
||||
var prod = _db.pro_order_record.AsEnumerable().Where(o => o.detail_num == detail_num )
|
||||
var prod = _db.pro_order_record.Where(o => o.detail_num == detail_num )
|
||||
.OrderByDescending(o=>o.pay_date).ToList();
|
||||
int i = 1;
|
||||
var ret = new
|
||||
@@ -979,7 +979,7 @@ public class apporderController : ApiController
|
||||
[Route("api/apporder/DeleteRecordDetail/{id}")]//刪除收款註記
|
||||
public void DeleteRecordDetail(int id)
|
||||
{
|
||||
var prod = _db.pro_order_record.AsEnumerable().Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.pro_order_record.Where(q => q.num == id).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -995,8 +995,8 @@ public class apporderController : ApiController
|
||||
{
|
||||
if (item.detail_num > 0)
|
||||
{
|
||||
float total = _db.pro_order_detail.AsEnumerable().Where(x => x.num == item.detail_num).Select(x => x.price.Value * x.qty.Value).Sum();
|
||||
float pay = _db.pro_order_record.AsEnumerable().Where(x => x.detail_num == item.detail_num).Select(x => x.price.Value).Sum();
|
||||
float total = _db.pro_order_detail.Where(x => x.num == item.detail_num).Select(x => x.price.Value * x.qty.Value).Sum();
|
||||
float pay = _db.pro_order_record.Where(x => x.detail_num == item.detail_num).Select(x => x.price.Value).Sum();
|
||||
|
||||
if (pay + item.price.Value <= total)
|
||||
{
|
||||
|
||||
@@ -130,7 +130,8 @@ public partial class admin_hr_import : MyWeb.config
|
||||
);
|
||||
sd2.AppendChild(tr);
|
||||
//查詢要匯出的資料
|
||||
var list = _db.member_group.AsEnumerable().ToList();
|
||||
// TODO: REVIEW - member_group 為固定少量資料表,ToList() 可接受
|
||||
var list = _db.member_group.ToList();
|
||||
if (list.Count > 0)
|
||||
{
|
||||
foreach (var item in list)
|
||||
@@ -178,7 +179,8 @@ public partial class admin_hr_import : MyWeb.config
|
||||
);
|
||||
sd3.AppendChild(tr);
|
||||
//查詢要匯出的資料
|
||||
var list2 = _db.member_title.AsEnumerable().ToList();
|
||||
// TODO: REVIEW - member_title 為固定少量資料表,ToList() 可接受
|
||||
var list2 = _db.member_title.ToList();
|
||||
if (list2.Count > 0)
|
||||
{
|
||||
foreach (var item in list2)
|
||||
@@ -229,10 +231,16 @@ public partial class admin_hr_import : MyWeb.config
|
||||
startRowNumber += 1;
|
||||
}
|
||||
|
||||
var fDt = _db.followers.AsEnumerable().ToList(); //信眾
|
||||
var aDt = _db.admins.AsEnumerable().ToList(); //後台系統
|
||||
var gDt = _db.member_group.AsEnumerable().Select(x => x.num).ToList(); //組別
|
||||
var tDt = _db.member_title.AsEnumerable().Select(x => x.num).ToList(); //職稱
|
||||
// TODO: REVIEW - 整表載入性能評估:
|
||||
// - followers (信眾) ⚠️ 會成長!若超過 1000 筆需優化為按需載入(先掃描 Excel 收集編號)
|
||||
// - admins (管理員) ✓ 通常少量,ToList() 可接受
|
||||
// - member_group (組別) ✓ 固定少量,可接受
|
||||
// - member_title (職稱) ✓ 固定少量,可接受
|
||||
// 優化方案:先掃描 Excel → 只載入需要的編號 → 使用 Dictionary 加速查找(O(1) vs O(n))
|
||||
var fDt = _db.followers.ToList(); //信眾
|
||||
var aDt = _db.admins.ToList(); //後台系統
|
||||
var gDt = _db.member_group.Select(x => x.num).ToList(); //組別
|
||||
var tDt = _db.member_title.Select(x => x.num).ToList(); //職稱
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
|
||||
for (int currentRow = startRowNumber; currentRow <= endRowNumber; currentRow++)
|
||||
|
||||
@@ -27,7 +27,6 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var qry = _db.member_group.AsEnumerable();
|
||||
var prod = _db.member_group.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -70,7 +69,6 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
|
||||
protected void TreeTopology()
|
||||
{
|
||||
var qry = _db.member_group.AsEnumerable();
|
||||
var prod = _db.member_group.ToList();
|
||||
//treeDt = prod.CopyToDataTable();
|
||||
|
||||
@@ -235,7 +233,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.member_group.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.member_group.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -281,7 +279,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
del_product(num);
|
||||
|
||||
|
||||
var prod = _db.member_group.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.member_group.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.member_group.Remove(prod);
|
||||
@@ -302,7 +300,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.member_group.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.member_group.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -319,7 +317,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
}
|
||||
public void del_product(int num)
|
||||
{
|
||||
var prod = _db.members.AsEnumerable().Where(q => q.group_kind == num).ToList();
|
||||
var prod = _db.members.Where(q => q.group_kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
//清空組別分類
|
||||
|
||||
@@ -22,7 +22,6 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var qry = _db.member_title.AsEnumerable();
|
||||
var prod = _db.member_title.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -207,7 +206,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
}
|
||||
try
|
||||
{
|
||||
var prod = _db.member_title.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.member_title.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -248,7 +247,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
|
||||
var prod = _db.member_title.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.member_title.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.member_title.Remove(prod);
|
||||
@@ -269,7 +268,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.member_title.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.member_title.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -286,7 +285,7 @@ public partial class admin_hr_kind_reg : MyWeb.config
|
||||
|
||||
public void del_product(int num)
|
||||
{
|
||||
var prod = _db.members.AsEnumerable().Where(q => q.title_kind == num).ToList();
|
||||
var prod = _db.members.Where(q => q.title_kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
//清空分類
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_accounting_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.accounting_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
var prod = _db.accounting_kind.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -215,7 +215,7 @@ public partial class admin_accounting_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.accounting_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.accounting_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -254,7 +254,7 @@ public partial class admin_accounting_kind_reg : MyWeb.config
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
|
||||
var prod = _db.accounting_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.accounting_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.accounting_kind.Remove(prod);
|
||||
@@ -272,7 +272,7 @@ public partial class admin_accounting_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.accounting_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.accounting_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -291,7 +291,7 @@ public partial class admin_accounting_kind_reg : MyWeb.config
|
||||
public void del_product(int num)
|
||||
{
|
||||
|
||||
var prod = _db.accountings.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.accountings.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
////查詢結果全部刪除
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_accounting_kind_reg2 : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.accounting_kind2.AsEnumerable().Where(q => q.num == _num).FirstOrDefault();
|
||||
var prod = _db.accounting_kind2.Where(q => q.num == _num).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -228,7 +228,7 @@ public partial class admin_accounting_kind_reg2 : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.accounting_kind2.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.accounting_kind2.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -271,7 +271,7 @@ public partial class admin_accounting_kind_reg2 : MyWeb.config
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
|
||||
var prod = _db.accounting_kind2.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.accounting_kind2.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.accounting_kind2.Remove(prod);
|
||||
@@ -288,7 +288,7 @@ public partial class admin_accounting_kind_reg2 : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.accounting_kind2.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.accounting_kind2.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -306,7 +306,7 @@ public partial class admin_accounting_kind_reg2 : MyWeb.config
|
||||
|
||||
public void del_product(int num)
|
||||
{
|
||||
var prod = _db.accountings.AsEnumerable().Where(q => q.kind2 == num).ToList();
|
||||
var prod = _db.accountings.Where(q => q.kind2 == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
////查詢結果全部刪除
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_activity_itemKind : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.actItem_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
var prod = _db.actItem_kind.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -214,7 +214,7 @@ public partial class admin_activity_itemKind : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.actItem_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.actItem_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -252,7 +252,7 @@ public partial class admin_activity_itemKind : MyWeb.config
|
||||
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
var prod = _db.actItem_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.actItem_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
|
||||
@@ -271,7 +271,7 @@ public partial class admin_activity_itemKind : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.actItem_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.actItem_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -289,7 +289,7 @@ public partial class admin_activity_itemKind : MyWeb.config
|
||||
|
||||
public void del_product(int num)
|
||||
{
|
||||
var prod = _db.actItems.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.actItems.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
//清空分類
|
||||
|
||||
@@ -24,7 +24,7 @@ public partial class admin_activity_kind_reg : MyWeb.config
|
||||
{
|
||||
_this_id = ValString(Request["num"]);
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.activity_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q=>q.kind).FirstOrDefault();
|
||||
var prod = _db.activity_kind.Where(q => q.num == _num).OrderBy(q=>q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -230,7 +230,7 @@ public partial class admin_activity_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.activity_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.activity_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -284,7 +284,7 @@ public partial class admin_activity_kind_reg : MyWeb.config
|
||||
{
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
var prod = _db.activity_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.activity_kind.Remove(prod);
|
||||
@@ -301,7 +301,7 @@ public partial class admin_activity_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.activity_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.activity_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -317,7 +317,7 @@ public partial class admin_activity_kind_reg : MyWeb.config
|
||||
}
|
||||
public void del_product(int num)
|
||||
{
|
||||
var prod = _db.activities.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.activities.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
//清空分類
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_activity_kind_reg2 : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.activity_category_kind.AsEnumerable().Where(q => q.num == _num).Where(q => q.num == _num).FirstOrDefault();
|
||||
var prod = _db.activity_category_kind.Where(q => q.num == _num).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -208,7 +208,7 @@ public partial class admin_activity_kind_reg2 : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.activity_category_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.activity_category_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -247,7 +247,7 @@ public partial class admin_activity_kind_reg2 : MyWeb.config
|
||||
|
||||
del_product(num);
|
||||
|
||||
var prod = _db.activity_category_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.activity_category_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.activity_category_kind.Remove(prod);
|
||||
@@ -265,7 +265,7 @@ public partial class admin_activity_kind_reg2 : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.activity_category_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.activity_category_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -284,7 +284,7 @@ public partial class admin_activity_kind_reg2 : MyWeb.config
|
||||
public void del_product(int num) //刪除訊息
|
||||
{
|
||||
//EF Model 資料庫拉關聯 , 故刪除類型前,一定要先刪除訊息,否則關聯會出錯
|
||||
var prod = _db.activities.AsEnumerable().Where(q => q.category_kind == num).ToList();
|
||||
var prod = _db.activities.Where(q => q.category_kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public partial class admin_bed_kind_reg : MyWeb.config
|
||||
{
|
||||
_this_id = ValString(Request["num"]);
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.bed_kind.AsEnumerable().Where(q => q.num == _num).FirstOrDefault();
|
||||
var prod = _db.bed_kind.Where(q => q.num == _num).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -250,7 +250,7 @@ public partial class admin_bed_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.bed_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.bed_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -293,7 +293,7 @@ public partial class admin_bed_kind_reg : MyWeb.config
|
||||
{
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
var prod = _db.bed_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.bed_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.bed_kind.Remove(prod);
|
||||
@@ -310,7 +310,7 @@ public partial class admin_bed_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.bed_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.bed_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -327,14 +327,14 @@ public partial class admin_bed_kind_reg : MyWeb.config
|
||||
public void del_product(int num)
|
||||
{
|
||||
//床位資料
|
||||
var prod = _db.bed_kind_detail.AsEnumerable().Where(q => q.bed_kind_id == num).ToList();
|
||||
var prod = _db.bed_kind_detail.Where(q => q.bed_kind_id == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
//清空分類
|
||||
foreach (var item in prod)
|
||||
{
|
||||
//掛單資料
|
||||
var prod2 = _db.bed_order_detail.AsEnumerable().Where(q => q.bed_kind_detail_id == item.num).ToList();
|
||||
var prod2 = _db.bed_order_detail.Where(q => q.bed_kind_detail_id == item.num).ToList();
|
||||
if (prod2.Count > 0)
|
||||
{
|
||||
//清空分類
|
||||
@@ -349,7 +349,7 @@ public partial class admin_bed_kind_reg : MyWeb.config
|
||||
}
|
||||
|
||||
//掛單資料
|
||||
var prod3 = _db.bed_order_detail.AsEnumerable().Where(q => q.bed_kind1 == num || q.bed_kind2 == num).ToList();
|
||||
var prod3 = _db.bed_order_detail.Where(q => q.bed_kind1 == num || q.bed_kind2 == num).ToList();
|
||||
if (prod3.Count > 0)
|
||||
{
|
||||
//清空分類
|
||||
|
||||
@@ -42,7 +42,7 @@ public partial class admin_follower_index : MyWeb.config
|
||||
//國籍
|
||||
s_country.Items.Clear();
|
||||
s_country.Items.Add(new ListItem("請選擇", ""));
|
||||
var qry =_db.countries.AsEnumerable().OrderBy(x => x.range).ThenBy(x => x.name_en).ToList();
|
||||
var qry =_db.countries.OrderBy(x => x.range).ThenBy(x => x.name_en).ToList();
|
||||
if (qry.Count > 0)
|
||||
{
|
||||
foreach(var x in qry)
|
||||
@@ -222,7 +222,7 @@ public partial class admin_follower_index : MyWeb.config
|
||||
{
|
||||
|
||||
//查詢要匯出的資料
|
||||
var qry = _db.followers.AsEnumerable();
|
||||
var qry = _db.followers.AsQueryable();
|
||||
|
||||
//紀錄匯出條件
|
||||
if (!isStrNull(s_f_number.Value))
|
||||
|
||||
@@ -25,7 +25,7 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
|
||||
//紀錄匯出條件
|
||||
string _query = "";
|
||||
var qry = _db.followers.AsEnumerable();
|
||||
var qry = _db.followers.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(Request["f_number"]))
|
||||
{
|
||||
qry = qry.Where(o => o.f_number.Contains(Request["f_number"].Trim()));
|
||||
@@ -57,7 +57,7 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
if (!string.IsNullOrEmpty(Request["country"]))
|
||||
{
|
||||
qry = qry.Where(o => o.country == Request["country"]);
|
||||
_query += "國家:" + (_db.countries.AsEnumerable().Where(x => x.ID == Request["country"].ToString()).Select(x => x.name_zh).FirstOrDefault()??"" )+ "\n";
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == Request["country"].ToString()).Select(x => x.name_zh).FirstOrDefault()??"" )+ "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["country2"]))
|
||||
{
|
||||
@@ -70,7 +70,7 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
qry = qry.Where(o => o.country != "158");
|
||||
|
||||
}
|
||||
_query += "國家:" + (_db.countries.AsEnumerable().Where(x => x.ID == Request["country2"].ToString()).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == Request["country2"].ToString()).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
}
|
||||
|
||||
//管理報表
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_news_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.news_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q=>q.kind).FirstOrDefault();
|
||||
var prod = _db.news_kind.Where(q => q.num == _num).OrderBy(q=>q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -214,7 +214,7 @@ public partial class admin_news_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.news_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.news_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -255,7 +255,7 @@ public partial class admin_news_kind_reg : MyWeb.config
|
||||
|
||||
del_product(num);
|
||||
|
||||
var prod = _db.news_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.news_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.news_kind.Remove(prod);
|
||||
@@ -273,7 +273,7 @@ public partial class admin_news_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.news_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.news_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -292,7 +292,7 @@ public partial class admin_news_kind_reg : MyWeb.config
|
||||
public void del_product(int num) //刪除訊息
|
||||
{
|
||||
//EF Model 資料庫拉關聯 , 故刪除分類前,一定要先刪除訊息,否則關聯會出錯
|
||||
var prod = _db.news.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.news.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
////刪除檔案
|
||||
|
||||
@@ -27,7 +27,7 @@ public partial class admin_news_news_reg : MyWeb.config
|
||||
else
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var qry = _db.news.AsEnumerable();
|
||||
var qry = _db.news.AsQueryable();
|
||||
//var prod = _db.news.Where(q => q.num == _num).ToList();
|
||||
var prod = qry.Where(q => q.num == _num).FirstOrDefault();
|
||||
|
||||
@@ -410,13 +410,11 @@ public partial class admin_news_news_reg : MyWeb.config
|
||||
#region 載入
|
||||
protected void initNewsFiles(int num = 0)
|
||||
{
|
||||
var qry = _db.news_files.AsEnumerable();
|
||||
var qry = _db.news_files.AsQueryable();
|
||||
if (num > 0)
|
||||
qry = qry.Where(q => q.news_id == num).ToList();
|
||||
else
|
||||
qry = qry.ToList();
|
||||
qry = qry.Where(q => q.news_id == num);
|
||||
|
||||
fileRepeater.DataSource = qry;
|
||||
fileRepeater.DataSource = qry.ToList();
|
||||
fileRepeater.DataBind();
|
||||
}
|
||||
protected void fileRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
|
||||
|
||||
@@ -47,7 +47,7 @@ public partial class admin_order_index : MyWeb.config
|
||||
//國籍
|
||||
s_country.Items.Clear();
|
||||
s_country.Items.Add(new ListItem("請選擇", ""));
|
||||
var qry = _db.countries.AsEnumerable().OrderBy(x => x.range).ThenBy(x => x.name_en).ToList();
|
||||
var qry = _db.countries.OrderBy(x => x.range).ThenBy(x => x.name_en).ToList();
|
||||
if (qry.Count > 0)
|
||||
{
|
||||
foreach (var x in qry)
|
||||
@@ -128,8 +128,8 @@ public partial class admin_order_index : MyWeb.config
|
||||
sd.AppendChild(tr);
|
||||
|
||||
//查詢要匯出的資料
|
||||
var aIDt = _db.actItems.AsEnumerable().Where(f => f.subject.Contains(s_actItemTxt.Value.Trim())).Select(f => f.num.ToString());//品項
|
||||
var qry = _db.pro_order.AsEnumerable();
|
||||
var aIDt = _db.actItems.Where(f => f.subject.Contains(s_actItemTxt.Value.Trim())).Select(f => f.num.ToString());//品項
|
||||
var qry = _db.pro_order.AsQueryable();
|
||||
|
||||
if (!isStrNull(s_order_no.Value))
|
||||
qry = qry.Where(o => o.order_no.Contains(s_order_no.Value.Trim()));
|
||||
@@ -154,7 +154,7 @@ public partial class admin_order_index : MyWeb.config
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
var tdesc = publicFun.enum_desc<Model.pro_order.detailKeyin1>();
|
||||
|
||||
var bedDt = _db.bed_order_detail.AsEnumerable();//掛單明細
|
||||
var bedDt = _db.bed_order_detail.AsQueryable();//掛單明細
|
||||
|
||||
|
||||
//left join 使用 GroupJoin
|
||||
@@ -167,7 +167,7 @@ public partial class admin_order_index : MyWeb.config
|
||||
order_no = o.order_no,
|
||||
up_time = o.up_time,
|
||||
keyin1 = o.keyin1,
|
||||
f_num = o.follower?.u_name, //姓名/名稱
|
||||
f_num = o.follower != null ? o.follower.u_name : "", //姓名/名稱
|
||||
phone = o.phone,
|
||||
activity_num = o.activity_num.HasValue ? o.activity.subject : "",
|
||||
address = o.address,
|
||||
|
||||
@@ -25,7 +25,7 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
|
||||
//紀錄匯出條件
|
||||
string _query = "";
|
||||
var qry = _db.pro_order.AsEnumerable();
|
||||
var qry = _db.pro_order.AsQueryable();
|
||||
if (!string.IsNullOrEmpty(Request["order_no"]))
|
||||
{
|
||||
qry = qry.Where(o => o.order_no.Contains(Request["order_no"].Trim()));
|
||||
@@ -73,21 +73,21 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["country"]))
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == Request["country"]);
|
||||
_query += "國家:" + (_db.countries.AsEnumerable().Where(x => x.ID == Request["country"]).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
qry = qry.Where(o => o.f_num != null && o.follower.country == Request["country"]);
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == Request["country"]).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["country2"]))
|
||||
{
|
||||
if (Request["country2"] == "1")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country == "158");
|
||||
qry = qry.Where(o => o.f_num != null && o.follower.country == "158");
|
||||
}
|
||||
else if (Request["country2"] == "2")
|
||||
{
|
||||
qry = qry.Where(o => o.f_num != null && o.follower?.country != "158");
|
||||
qry = qry.Where(o => o.f_num != null && o.follower.country != "158");
|
||||
|
||||
}
|
||||
_query += "國家:" + (_db.countries.AsEnumerable().Where(x => x.ID == Request["country2"]).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
_query += "國家:" + (_db.countries.Where(x => x.ID == Request["country2"]).Select(x => x.name_zh).FirstOrDefault()??"") + "\n";
|
||||
}
|
||||
if (!string.IsNullOrEmpty(Request["hasPrice"]))
|
||||
{
|
||||
@@ -175,7 +175,7 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(Request["year"]))
|
||||
qry = qry.OrderByDescending(o => o.activity?.startDate_solar).ThenByDescending(o=>o.up_time).ThenByDescending(o=>o.order_no);
|
||||
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);
|
||||
|
||||
@@ -186,8 +186,9 @@ public partial class admin_follower_print_ : System.Web.UI.Page
|
||||
tdesc = publicFun.enum_desc<Model.pro_order.detailKeyin1>();
|
||||
|
||||
//明細
|
||||
_detail = _db.pro_order_detail.AsEnumerable().Where(x => prod.Select(o => o.order_no).Contains( x.order_no)).ToList();
|
||||
_bedDt = _db.bed_order_detail.AsEnumerable().Where(x => prod.Select(o => o.order_no).Contains( x.bed_order.order_no)).ToList();
|
||||
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();
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_project_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.project_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
var prod = _db.project_kind.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -210,7 +210,7 @@ public partial class admin_project_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.project_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.project_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -248,7 +248,7 @@ public partial class admin_project_kind_reg : MyWeb.config
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
|
||||
var prod = _db.project_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.project_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.project_kind.Remove(prod);
|
||||
@@ -265,7 +265,7 @@ public partial class admin_project_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.project_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.project_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -283,7 +283,7 @@ public partial class admin_project_kind_reg : MyWeb.config
|
||||
|
||||
public void del_product(int num)
|
||||
{
|
||||
var prod = _db.projects.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.projects.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
////查詢結果全部刪除
|
||||
|
||||
@@ -39,9 +39,8 @@ public partial class admin_project_list : MyWeb.config
|
||||
//品項
|
||||
s_actItem_num.Items.Clear();
|
||||
s_actItem_num.Items.Add(new ListItem("請選擇", ""));
|
||||
var qry = _db.actItems.AsEnumerable();
|
||||
qry = qry.Where(o => (int?)o.category==(int)Model.activity.category.Patronize);//贊助項目
|
||||
qry = qry.OrderByDescending(o => o.num).ToList();
|
||||
var qry = _db.actItems.Where(o => (int?)o.category==(int)Model.activity.category.Patronize);//贊助項目
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
if(qry.Count() > 0)
|
||||
foreach(var qq in qry)
|
||||
s_actItem_num.Items.Add(new ListItem(qq.subject, qq.num.ToString()));
|
||||
@@ -99,7 +98,7 @@ public partial class admin_project_list : MyWeb.config
|
||||
sd.AppendChild(tr);
|
||||
|
||||
//查詢要匯出的資料
|
||||
var qry = _db.pro_order_detail.AsEnumerable();
|
||||
var qry = _db.pro_order_detail.AsQueryable();
|
||||
qry = qry.Where(o => (int?)o.actItem.category == (int)Model.activity.category.Patronize);
|
||||
|
||||
if (!string.IsNullOrEmpty(s_f_num.Value))
|
||||
@@ -111,7 +110,8 @@ public partial class admin_project_list : MyWeb.config
|
||||
var list = qry.ToList();
|
||||
if (list.Count > 0)
|
||||
{
|
||||
var projectDt = _db.projects.AsEnumerable(); //專案
|
||||
// TODO: REVIEW - projects 資料量可能成長,若超過數千筆需優化為按需查詢
|
||||
var projectDt = _db.projects.ToList(); //專案
|
||||
foreach (var item in list)
|
||||
{
|
||||
var projects = from s in projectDt
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_stock_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.stock_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
var prod = _db.stock_kind.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -210,7 +210,7 @@ public partial class admin_stock_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.stock_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.stock_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -248,7 +248,7 @@ public partial class admin_stock_kind_reg : MyWeb.config
|
||||
|
||||
int num = Val(Request["num"]);
|
||||
del_product(num);
|
||||
var prod = _db.stock_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.stock_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.stock_kind.Remove(prod);
|
||||
@@ -266,7 +266,7 @@ public partial class admin_stock_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.stock_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.stock_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -285,7 +285,7 @@ public partial class admin_stock_kind_reg : MyWeb.config
|
||||
public void del_product(int num)
|
||||
{
|
||||
|
||||
var prod = _db.stocks.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.stocks.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
////查詢結果全部刪除
|
||||
|
||||
@@ -22,7 +22,7 @@ public partial class admin_stock_reason_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.stock_reason.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
var prod = _db.stock_reason.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -221,7 +221,7 @@ public partial class admin_stock_reason_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.stock_reason.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.stock_reason.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -257,7 +257,7 @@ public partial class admin_stock_reason_reg : MyWeb.config
|
||||
{
|
||||
|
||||
int num = Val(Request["num"]);
|
||||
var prod = _db.stock_reason.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.stock_reason.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.stock_reason.Remove(prod);
|
||||
@@ -275,7 +275,7 @@ public partial class admin_stock_reason_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.stock_reason.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.stock_reason.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
|
||||
@@ -21,7 +21,7 @@ public partial class admin_supplier_kind_reg : MyWeb.config
|
||||
if (!isStrNull(Request["num"]))
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
var prod = _db.supplier_kind.Where(q => q.num == _num).OrderBy(q => q.kind).FirstOrDefault();
|
||||
|
||||
if (prod != null)
|
||||
{
|
||||
@@ -210,7 +210,7 @@ public partial class admin_supplier_kind_reg : MyWeb.config
|
||||
|
||||
try
|
||||
{
|
||||
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
var prod = _db.supplier_kind.Where(q => q.root == root).OrderByDescending(q => q.range).FirstOrDefault();
|
||||
if (prod != null)
|
||||
if (prod.range.HasValue)
|
||||
range = prod.range.Value + 1;
|
||||
@@ -248,7 +248,7 @@ public partial class admin_supplier_kind_reg : MyWeb.config
|
||||
|
||||
int num = Val(Request["num"]);
|
||||
//del_product(num);
|
||||
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
var prod = _db.supplier_kind.Where(q => q.num == num).FirstOrDefault(); //刪除該筆資料
|
||||
if (prod != null)
|
||||
{
|
||||
_db.supplier_kind.Remove(prod);
|
||||
@@ -266,7 +266,7 @@ public partial class admin_supplier_kind_reg : MyWeb.config
|
||||
|
||||
public void Del_Ohter_Items(int d_num)
|
||||
{
|
||||
var prod = _db.supplier_kind.AsEnumerable().Where(q => q.root == d_num).ToList();
|
||||
var prod = _db.supplier_kind.Where(q => q.root == d_num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
foreach (var row in prod)
|
||||
@@ -285,7 +285,7 @@ public partial class admin_supplier_kind_reg : MyWeb.config
|
||||
public void del_product(int num)
|
||||
{
|
||||
|
||||
var prod = _db.suppliers.AsEnumerable().Where(q => q.kind == num).ToList();
|
||||
var prod = _db.suppliers.Where(q => q.kind == num).ToList();
|
||||
if (prod.Count > 0)
|
||||
{
|
||||
////查詢結果全部刪除
|
||||
|
||||
28
web/test_asenumerable_check.aspx
Normal file
28
web/test_asenumerable_check.aspx
Normal file
@@ -0,0 +1,28 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test_asenumerable_check.aspx.cs" Inherits="test_asenumerable_check" %>
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>AsEnumerable 修改檢測工具</title>
|
||||
<style>
|
||||
body { font-family: 'Consolas', monospace; margin: 20px; background: #1e1e1e; color: #d4d4d4; }
|
||||
.success { color: #4ec9b0; font-weight: bold; }
|
||||
.error { color: #f48771; font-weight: bold; }
|
||||
.warning { color: #dcdcaa; font-weight: bold; }
|
||||
.sql-box { background: #252526; padding: 15px; margin: 10px 0; border-left: 4px solid #007acc; }
|
||||
.test-item { margin: 20px 0; padding: 15px; background: #2d2d30; border-radius: 4px; }
|
||||
h2 { color: #4ec9b0; }
|
||||
h3 { color: #dcdcaa; margin-top: 20px; }
|
||||
pre { white-space: pre-wrap; word-wrap: break-word; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>🔍 AsEnumerable 修改檢測報告</h1>
|
||||
<form runat="server">
|
||||
<asp:Button ID="btnRunTest" runat="server" Text="▶ 執行檢測" OnClick="btnRunTest_Click"
|
||||
style="padding: 10px 20px; font-size: 16px; cursor: pointer;" />
|
||||
<hr />
|
||||
<asp:Literal ID="litResult" runat="server"></asp:Literal>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
346
web/test_asenumerable_check.aspx.cs
Normal file
346
web/test_asenumerable_check.aspx.cs
Normal file
@@ -0,0 +1,346 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using Model;
|
||||
|
||||
public partial class test_asenumerable_check : System.Web.UI.Page
|
||||
{
|
||||
private StringBuilder output = new StringBuilder();
|
||||
private int passCount = 0;
|
||||
private int failCount = 0;
|
||||
private int warnCount = 0;
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
if (!IsPostBack)
|
||||
{
|
||||
litResult.Text = "<p style='color:#888;'>點擊「執行檢測」開始測試修改結果</p>";
|
||||
}
|
||||
}
|
||||
|
||||
protected void btnRunTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
output.Clear();
|
||||
passCount = 0;
|
||||
failCount = 0;
|
||||
warnCount = 0;
|
||||
|
||||
output.AppendLine("<div style='margin-bottom: 20px;'>");
|
||||
output.AppendLine($"<p>測試時間: {DateTime.Now:yyyy-MM-dd HH:mm:ss}</p>");
|
||||
output.AppendLine("</div>");
|
||||
|
||||
// 執行所有測試
|
||||
TestAccountingKind();
|
||||
TestActivityKind();
|
||||
TestFollowers();
|
||||
TestMembers();
|
||||
TestOrders();
|
||||
|
||||
// 顯示總結
|
||||
output.AppendLine("<hr />");
|
||||
output.AppendLine("<h2>📊 測試總結</h2>");
|
||||
output.AppendLine($"<p class='success'>✅ 通過: {passCount} 項</p>");
|
||||
output.AppendLine($"<p class='error'>❌ 失敗: {failCount} 項</p>");
|
||||
output.AppendLine($"<p class='warning'>⚠️ 警告: {warnCount} 項</p>");
|
||||
|
||||
if (failCount == 0)
|
||||
{
|
||||
output.AppendLine("<h3 class='success'>🎉 所有測試通過!修改成功!</h3>");
|
||||
}
|
||||
else
|
||||
{
|
||||
output.AppendLine("<h3 class='error'>⚠️ 發現問題,請檢查失敗的項目</h3>");
|
||||
}
|
||||
|
||||
litResult.Text = output.ToString();
|
||||
}
|
||||
|
||||
private void TestAccountingKind()
|
||||
{
|
||||
output.AppendLine("<h3>測試 1: accounting_kind 查詢優化</h3>");
|
||||
|
||||
using (var db = new ezEntities())
|
||||
{
|
||||
var sqlLog = new StringBuilder();
|
||||
db.Database.Log = sql => sqlLog.AppendLine(sql);
|
||||
|
||||
try
|
||||
{
|
||||
// 測試 1.1: 單筆查詢
|
||||
sqlLog.Clear();
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = db.accounting_kind.Where(q => q.num == 1).FirstOrDefault();
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("單筆查詢 (Where + FirstOrDefault)",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveSelectAll: false,
|
||||
maxTime: 50);
|
||||
|
||||
// 測試 1.2: 檢查子資料 (應該用 Any)
|
||||
sqlLog.Clear();
|
||||
sw.Restart();
|
||||
var hasChildren = db.accounting_kind.Any(q => q.root == 1);
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("檢查子資料存在 (Any)",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveExists: true,
|
||||
maxTime: 30);
|
||||
|
||||
// 測試 1.3: 取得子資料清單
|
||||
sqlLog.Clear();
|
||||
sw.Restart();
|
||||
var children = db.accounting_kind.Where(q => q.root == 1).ToList();
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("取得子資料清單 (Where + ToList)",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveSelectAll: false,
|
||||
maxTime: 100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError($"accounting_kind 測試失敗: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TestActivityKind()
|
||||
{
|
||||
output.AppendLine("<h3>測試 2: activity_kind 查詢優化</h3>");
|
||||
|
||||
using (var db = new ezEntities())
|
||||
{
|
||||
var sqlLog = new StringBuilder();
|
||||
db.Database.Log = sql => sqlLog.AppendLine(sql);
|
||||
|
||||
try
|
||||
{
|
||||
// 單筆查詢 + 排序
|
||||
sqlLog.Clear();
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = db.activity_kind
|
||||
.Where(q => q.num == 1)
|
||||
.OrderBy(q => q.kind)
|
||||
.FirstOrDefault();
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("單筆查詢 + 排序 (Where + OrderBy + FirstOrDefault)",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveOrderBy: true,
|
||||
maxTime: 50);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError($"activity_kind 測試失敗: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TestFollowers()
|
||||
{
|
||||
output.AppendLine("<h3>測試 3: followers 查詢優化</h3>");
|
||||
|
||||
using (var db = new ezEntities())
|
||||
{
|
||||
var sqlLog = new StringBuilder();
|
||||
db.Database.Log = sql => sqlLog.AppendLine(sql);
|
||||
|
||||
try
|
||||
{
|
||||
// 測試字串查詢 (Contains)
|
||||
sqlLog.Clear();
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = db.followers
|
||||
.Where(q => q.f_number.Contains("A"))
|
||||
.Take(10)
|
||||
.ToList();
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("字串查詢 (Contains)",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveLike: true,
|
||||
maxTime: 100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError($"followers 測試失敗: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TestMembers()
|
||||
{
|
||||
output.AppendLine("<h3>測試 4: members 查詢優化</h3>");
|
||||
|
||||
using (var db = new ezEntities())
|
||||
{
|
||||
var sqlLog = new StringBuilder();
|
||||
db.Database.Log = sql => sqlLog.AppendLine(sql);
|
||||
|
||||
try
|
||||
{
|
||||
// 測試批次查詢
|
||||
var ids = new[] { 1, 2, 3 };
|
||||
sqlLog.Clear();
|
||||
var sw = Stopwatch.StartNew();
|
||||
var result = db.members.Where(q => ids.Contains(q.num)).ToList();
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("批次 ID 查詢 (Contains)",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveIn: true,
|
||||
maxTime: 100);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError($"members 測試失敗: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void TestOrders()
|
||||
{
|
||||
output.AppendLine("<h3>測試 5: pro_order_detail 聚合查詢</h3>");
|
||||
|
||||
using (var db = new ezEntities())
|
||||
{
|
||||
var sqlLog = new StringBuilder();
|
||||
db.Database.Log = sql => sqlLog.AppendLine(sql);
|
||||
|
||||
try
|
||||
{
|
||||
// 測試 Count
|
||||
sqlLog.Clear();
|
||||
var sw = Stopwatch.StartNew();
|
||||
var count = db.pro_order_detail.Count(q => q.num > 0);
|
||||
sw.Stop();
|
||||
|
||||
CheckQuery("Count 查詢",
|
||||
sqlLog.ToString(),
|
||||
sw.ElapsedMilliseconds,
|
||||
shouldHaveWhere: true,
|
||||
shouldHaveCount: true,
|
||||
maxTime: 50);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogError($"pro_order_detail 測試失敗: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CheckQuery(string testName, string sql, long milliseconds,
|
||||
bool shouldHaveWhere = false,
|
||||
bool shouldHaveSelectAll = false,
|
||||
bool shouldHaveExists = false,
|
||||
bool shouldHaveOrderBy = false,
|
||||
bool shouldHaveLike = false,
|
||||
bool shouldHaveIn = false,
|
||||
bool shouldHaveCount = false,
|
||||
long maxTime = 100)
|
||||
{
|
||||
output.AppendLine("<div class='test-item'>");
|
||||
output.AppendLine($"<h4>🔸 {testName}</h4>");
|
||||
output.AppendLine($"<p>執行時間: {milliseconds}ms</p>");
|
||||
|
||||
bool passed = true;
|
||||
var issues = new StringBuilder();
|
||||
|
||||
// 檢查是否有 WHERE 條件
|
||||
if (shouldHaveWhere && !sql.Contains("WHERE"))
|
||||
{
|
||||
issues.AppendLine("❌ 缺少 WHERE 條件(可能載入整表)<br/>");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// 檢查是否有不當的 SELECT *
|
||||
if (!shouldHaveSelectAll && sql.Contains("SELECT") && !sql.Contains("WHERE") && !sql.Contains("TOP"))
|
||||
{
|
||||
issues.AppendLine("❌ SELECT 沒有條件限制(載入整表)<br/>");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// 檢查是否使用 EXISTS(Any 應該產生)
|
||||
if (shouldHaveExists && !sql.Contains("EXISTS"))
|
||||
{
|
||||
issues.AppendLine("⚠️ 建議使用 EXISTS 而非載入資料<br/>");
|
||||
warnCount++;
|
||||
}
|
||||
|
||||
// 檢查是否有 ORDER BY
|
||||
if (shouldHaveOrderBy && !sql.Contains("ORDER BY"))
|
||||
{
|
||||
issues.AppendLine("❌ 缺少 ORDER BY(排序應該在資料庫執行)<br/>");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// 檢查是否有 LIKE(Contains 應該產生)
|
||||
if (shouldHaveLike && !sql.Contains("LIKE"))
|
||||
{
|
||||
issues.AppendLine("❌ 字串查詢未轉為 LIKE<br/>");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// 檢查是否有 IN(批次查詢應該產生)
|
||||
if (shouldHaveIn && !sql.Contains("IN"))
|
||||
{
|
||||
issues.AppendLine("❌ 批次查詢未轉為 IN<br/>");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// 檢查是否有 COUNT(聚合函數應該在資料庫執行)
|
||||
if (shouldHaveCount && !sql.Contains("COUNT"))
|
||||
{
|
||||
issues.AppendLine("❌ COUNT 未在資料庫執行<br/>");
|
||||
passed = false;
|
||||
}
|
||||
|
||||
// 檢查執行時間
|
||||
if (milliseconds > maxTime)
|
||||
{
|
||||
issues.AppendLine($"⚠️ 執行時間較長 (>{maxTime}ms),可能仍有優化空間<br/>");
|
||||
warnCount++;
|
||||
}
|
||||
|
||||
if (passed)
|
||||
{
|
||||
output.AppendLine("<p class='success'>✅ 測試通過</p>");
|
||||
passCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
output.AppendLine("<p class='error'>❌ 測試失敗</p>");
|
||||
output.AppendLine($"<div style='color:#f48771;'>{issues}</div>");
|
||||
failCount++;
|
||||
}
|
||||
|
||||
// 顯示 SQL
|
||||
output.AppendLine("<div class='sql-box'>");
|
||||
output.AppendLine("<strong>產生的 SQL:</strong><br/>");
|
||||
output.AppendLine($"<pre>{System.Web.HttpUtility.HtmlEncode(sql)}</pre>");
|
||||
output.AppendLine("</div>");
|
||||
output.AppendLine("</div>");
|
||||
}
|
||||
|
||||
private void LogError(string message)
|
||||
{
|
||||
output.AppendLine($"<p class='error'>❌ {message}</p>");
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user