客堂登記報名
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
namespace Model.ViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// preOrder 的摘要描述
|
||||
/// </summary>
|
||||
public class preOrder
|
||||
{
|
||||
public preOrder()
|
||||
{
|
||||
//
|
||||
// TODO: 在這裡新增建構函式邏輯
|
||||
//
|
||||
}
|
||||
|
||||
public int? num { get; set; }
|
||||
public Nullable<int> f_num { get; set; }
|
||||
public string order_no { get; set; }
|
||||
public Nullable<int> item_count { get; set; }
|
||||
public Nullable<int> total_amt { get; set; }
|
||||
public Nullable<int> act_num { get; set; }
|
||||
public Nullable<int> admin_num { get; set; }
|
||||
public Nullable<System.DateTime> reg_time { get; set; }
|
||||
public Nullable<int> receipt_num { get; set; }
|
||||
public string f_name { get; set; }
|
||||
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,8 @@ using System.Linq;
|
||||
using System.Net;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
|
||||
using MyWeb;
|
||||
using MINOM.COM.Utility;
|
||||
// api/pre_order
|
||||
//[ezAuthorize(Roles = "admin")]//群組:*
|
||||
//[ezAuthorize]
|
||||
@@ -30,7 +31,8 @@ public class preOrderController: ApiController
|
||||
{
|
||||
qry = qry.Where(x => _db.followers.Where(y => y.u_name == pre.f_name).Select(y => y.num).ToList().Contains((int)x.f_num));
|
||||
}
|
||||
sortBy = sortBy ?? string.Empty;
|
||||
//sortBy = sortBy ?? string.Empty;
|
||||
qry=qry.OrderByDescending(x => x.num);
|
||||
var count = qry.Count(); //pageSize = count;//一次取回??
|
||||
if (pageSize == -1)
|
||||
{
|
||||
@@ -52,4 +54,99 @@ public class preOrderController: ApiController
|
||||
return Ok(ret);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/preOrder/SavePreOrder")]
|
||||
public IHttpActionResult SavePreOrder([FromBody] Model.ViewModel.preOrder pre)
|
||||
{
|
||||
try
|
||||
{
|
||||
//要檢查有無報過名
|
||||
var qry1 = _db.pro_order.AsQueryable();
|
||||
qry1 = qry1.Where(y=>y.f_num==pre.f_num&&y.activity_num==pre.act_num);
|
||||
var o=qry1.FirstOrDefault();
|
||||
if (o != null && !string.IsNullOrEmpty(o.order_no))
|
||||
{
|
||||
throw new Exception("已經報過名,請勿重複報名");
|
||||
}
|
||||
|
||||
var qry = _db.followers.AsQueryable();
|
||||
qry = qry.Where(x => x.num == pre.f_num);
|
||||
var f = qry.FirstOrDefault();
|
||||
//寫入pre_order,同時寫入pro_order
|
||||
pre.order_no = new MyWeb.autoNum().createOrderNumber();
|
||||
Model.pre_order preO = new Model.pre_order();
|
||||
Model.pro_order proO = new Model.pro_order();
|
||||
preO.order_no = pre.order_no;
|
||||
preO.act_num = pre.act_num;
|
||||
preO.f_num = pre.f_num;
|
||||
preO.item_count = pre.item_count;
|
||||
|
||||
preO.total_amt = pre.total_amt;
|
||||
preO.reg_time = DateTime.Now;
|
||||
|
||||
proO.up_time= DateTime.Now;
|
||||
proO.reg_time = DateTime.Now;
|
||||
proO.order_no = preO.order_no;
|
||||
proO.activity_num = pre.act_num;
|
||||
proO.f_num = pre.f_num;
|
||||
proO.keyin1 = "A01";
|
||||
proO.phone = f.phone;
|
||||
proO.address = f.address??"";
|
||||
proO.demo = "";
|
||||
|
||||
_db.pre_order.Add(preO);
|
||||
_db.pro_order.Add(proO);
|
||||
_db.SaveChanges();
|
||||
return Ok(new {result="Y",message="新增成功"});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogUtility log = new LogUtility();
|
||||
log.writeErrorPath(ex.Message+ex.StackTrace);
|
||||
return Ok(new { result = "N", message = $"新增失敗 {ex.Message}" });
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Route("api/preOrder/GetPreOrderByNum")]
|
||||
|
||||
public IHttpActionResult GetPreOrderByNum([FromBody] Model.ViewModel.preOrder pre)
|
||||
{
|
||||
var qry = _db.pre_order.AsQueryable();
|
||||
|
||||
qry = qry.Where(x => x.order_no==pre.order_no);
|
||||
//sortBy = sortBy ?? string.Empty;
|
||||
qry = qry.OrderByDescending(x => x.num);
|
||||
|
||||
var ret = new
|
||||
{
|
||||
data=qry.Select(x => new
|
||||
{
|
||||
x.num,
|
||||
x.f_num,
|
||||
x.admin_num,
|
||||
x.order_no,
|
||||
x.item_count,
|
||||
x.total_amt,
|
||||
x.reg_time,
|
||||
x.receipt_num,
|
||||
x.act_num,
|
||||
f_name = _db.followers.Where(z => z.num == x.f_num).Select(z => z.u_name).FirstOrDefault(),
|
||||
act_name = _db.activities.Where(w => w.num == x.act_num).Select(w => w.subject).FirstOrDefault(),
|
||||
}).FirstOrDefault()
|
||||
};
|
||||
if (ret.data == null) {
|
||||
return Ok(new {result="N",message=""});
|
||||
}
|
||||
;
|
||||
return Ok(new
|
||||
{
|
||||
result = "Y",
|
||||
ret
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace MyWeb
|
||||
{
|
||||
/// <summary>
|
||||
/// autoNum 的摘要描述
|
||||
/// </summary>
|
||||
public class autoNum
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
public autoNum()
|
||||
{
|
||||
//
|
||||
// TODO: 在這裡新增建構函式邏輯
|
||||
//
|
||||
}
|
||||
public string createOrderNumber()
|
||||
{
|
||||
//Application.Lock();
|
||||
string order_no = "AA" + DateTime.Now.ToString("yyMMdd");
|
||||
|
||||
var qry = _db.companies.AsQueryable();
|
||||
//var prod = qry.Where(q => q.last_order_no.Contains(order_no)).FirstOrDefault();
|
||||
var prod = qry.Where(q => q.num == 1).FirstOrDefault();
|
||||
if (prod != null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(prod.last_order_no) && prod.last_order_no.Contains(order_no))
|
||||
{
|
||||
int tmp = Convert.ToInt32(prod.last_order_no.Replace(order_no, "")) + 1;
|
||||
order_no = order_no + tmp.ToString("0000");
|
||||
}
|
||||
else
|
||||
{
|
||||
order_no = order_no + "0001";
|
||||
}
|
||||
|
||||
prod.last_order_no = order_no;
|
||||
_db.SaveChanges();
|
||||
}
|
||||
else
|
||||
order_no = "";
|
||||
|
||||
//Application.UnLock();
|
||||
|
||||
return order_no;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user