503 lines
19 KiB
C#
503 lines
19 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.OleDb;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
using System.Configuration;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Globalization;
|
|
|
|
public partial class admin_activity_reg : MyWeb.config
|
|
{
|
|
private Model.ezEntities _db = new Model.ezEntities();
|
|
public string _category_kindTxt = "相關";
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
if (isStrNull(Request["num"]))
|
|
{
|
|
BuildKind();
|
|
}
|
|
else
|
|
{
|
|
int _num = Val(Request["num"]);
|
|
//var qry = _db.activities.AsEnumerable();
|
|
var prod = _db.activities.Where(q => q.num == _num).FirstOrDefault();
|
|
|
|
if (prod != null)
|
|
{
|
|
|
|
BuildKind();
|
|
try
|
|
{
|
|
foreach (Control obj in cardBodyPanel.Controls)
|
|
{
|
|
if (obj is TextBox)
|
|
{
|
|
var ObjValue = prod.GetType().GetProperty(obj.ID).GetValue(prod, null);
|
|
if (!isStrNull(ObjValue))
|
|
{
|
|
var textBox = (TextBox)obj;
|
|
if (textBox.TextMode == TextBoxMode.Date)
|
|
{
|
|
textBox.Text = Convert.ToDateTime(ObjValue).ToString("yyyy-MM-dd");
|
|
}
|
|
else
|
|
{
|
|
textBox.Text = ObjValue.ToString();
|
|
}
|
|
}
|
|
}
|
|
else if (obj is DropDownList && ((DropDownList)obj).SelectedIndex == 0)
|
|
{
|
|
var ObjValue = prod.GetType().GetProperty(obj.ID).GetValue(prod, null);
|
|
if (!isStrNull(ObjValue))
|
|
{
|
|
var dropDown = (DropDownList)obj;
|
|
dropDown.SelectedValue = ObjValue.ToString();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
}
|
|
|
|
if (prod.kind.HasValue)
|
|
{
|
|
kind_txt.Value = prod.activity_kind.kind;
|
|
kind.Value = prod.kind.Value.ToString();
|
|
kind_txt2.Text = "<div class='pt-2'>" + prod.activity_kind.kind + "</div>";
|
|
}
|
|
if (prod.category_kind.HasValue)
|
|
{
|
|
_category_kindTxt = prod.activity_category_kind.kind;
|
|
category_kind_txt.Value = prod.activity_category_kind.kind;
|
|
category_kind.Value = prod.category_kind.Value.ToString();
|
|
}
|
|
if (prod.startDate_solar.HasValue)
|
|
{
|
|
startDate_lunar.Text= publicFun.chagenDate(prod.startDate_solar);
|
|
}
|
|
if (prod.endDate_solar.HasValue)
|
|
{
|
|
endDate_lunar.Text = publicFun.chagenDate(prod.endDate_solar);
|
|
}
|
|
|
|
if (prod.reg_time.HasValue)
|
|
{
|
|
timePanel1.Visible = true;
|
|
reg_time.Text = prod.reg_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
|
|
}
|
|
kindPH.Visible = false;
|
|
|
|
|
|
edit.Visible = true;
|
|
goback.Visible = true;
|
|
add.Visible = false;
|
|
|
|
}
|
|
else
|
|
{
|
|
Response.Redirect("index.aspx");
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
protected void goback_Click(object sender, EventArgs e)
|
|
{
|
|
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
|
}
|
|
|
|
#region 分類
|
|
|
|
|
|
|
|
public void BuildKind()
|
|
{
|
|
|
|
}
|
|
protected void kind_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
//if (isStrNull(Request["num"])) // 只有新增時帶入預設
|
|
//{
|
|
// if (!isStrNull(kind.SelectedValue))
|
|
// {
|
|
// int _kind = Val(kind.SelectedValue);
|
|
// //日期
|
|
// var prop3 = _db.activity_kind.Where(q => q.num == _kind).FirstOrDefault();
|
|
// if (prop3 != null)
|
|
// {
|
|
// ChineseLunisolarCalendar chineseDate = new ChineseLunisolarCalendar();
|
|
|
|
// string _calendar = prop3.calendar;
|
|
// DateTime _today = DateTime.Now;
|
|
// if (_calendar == "國曆")
|
|
// {
|
|
// DateTime _newDay = Convert.ToDateTime(DateTime.Now.Year + "/" + prop3.month + "/" + prop3.day);
|
|
// if (_today.Month >= prop3.month && _today.Day >= prop3.day)
|
|
// {
|
|
// //過期->預設明年
|
|
// _newDay = Convert.ToDateTime(DateTime.Now.AddYears(1).Year + "/" + prop3.month + "/" + prop3.day);
|
|
// }
|
|
// else
|
|
// {
|
|
// //未過期->預設今年
|
|
// }
|
|
|
|
// startDate_solar.Text = _newDay.ToString("yyyy-MM-dd");
|
|
// endDate_solar.Text = _newDay.ToString("yyyy-MM-dd");
|
|
|
|
// DateTime _newDay2 = Convert.ToDateTime(chineseDate.GetYear(_newDay) + "/" + chineseDate.GetMonth(_newDay) + "/" + chineseDate.GetDayOfMonth(_newDay));
|
|
// startDate_lunar.Text = _newDay2.ToString("yyyy-MM-dd");
|
|
// endDate_lunar.Text = _newDay2.ToString("yyyy-MM-dd");
|
|
|
|
// //TaiwanLunisolarCalendar tlc = new TaiwanLunisolarCalendar();
|
|
// //DateTime _newDay3 = Convert.ToDateTime(tlc.GetYear(_newDay) + "/" + tlc.GetMonth(_newDay) + "/" + tlc.GetDayOfMonth(_newDay));
|
|
// // -> TaiwanLunisolarCalendar 民國年農曆
|
|
|
|
|
|
// }
|
|
// else if (_calendar == "農曆")
|
|
// {
|
|
|
|
|
|
// }
|
|
|
|
|
|
// }
|
|
|
|
// //項目
|
|
// DataTable dt = createNewDt();
|
|
// var qry = _db.activity_kind_detail.AsEnumerable().Where(q => q.activity_kind_num == _kind && q.actItem.status == "Y");
|
|
// var prop = qry.OrderBy(q => q.reg_time).ToList();
|
|
// if (prop.Count > 0)
|
|
// {
|
|
// foreach (var item in prop)
|
|
// {
|
|
// DataRow dr = dt.NewRow();
|
|
// //dr["num"] = item.actItem_num;
|
|
// dr["num"] = ""; //新增時為空
|
|
// dr["actItem_num"] = item.actItem_num;
|
|
// dr["price"] = item.price.HasValue ? item.price.Value.ToString() : "";
|
|
// dr["qty"] = item.qty.HasValue ? item.qty.Value.ToString() : "";
|
|
// dt.Rows.Add(dr);
|
|
// }
|
|
// }
|
|
// Repeater1.DataSource = dt;
|
|
// Repeater1.DataBind();
|
|
// //var query =
|
|
// //from c in _db.actItems.AsEnumerable()
|
|
// //where ((from o in _db.activity_kind_detail.AsEnumerable()
|
|
// // where o.activity_kind_num == _kind
|
|
// // select o.actItem_num)
|
|
// // .Contains(c.num) && c.status=="Y")
|
|
// //select c;
|
|
|
|
// dt = createNewDt2();
|
|
// var prop2 = qry.Where(q=>q.actItem.spares=="Y").OrderBy(q => q.reg_time).ToList();
|
|
// if (prop2.Count > 0)
|
|
// {
|
|
// foreach (var item in prop2)
|
|
// {
|
|
// DataRow dr = dt.NewRow();
|
|
// dr["num"] = "";
|
|
// dr["actItem_num"] = item.actItem_num;
|
|
// dr["qty1"] = item.qty.HasValue ? item.qty.Value.ToString() : "";
|
|
// dr["qty2"] = "";
|
|
// dr["demo"] = "";
|
|
// dt.Rows.Add(dr);
|
|
// }
|
|
// }
|
|
// Repeater2.DataSource = dt;
|
|
// Repeater2.DataBind();
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// Repeater1.DataSource = null;
|
|
// Repeater1.DataBind();
|
|
// Repeater2.DataSource = null;
|
|
// Repeater2.DataBind();
|
|
// }
|
|
//}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 資料新增
|
|
protected string createOrderNumber()
|
|
{
|
|
Application.Lock();
|
|
string order_no = "AA" + DateTime.Now.ToString("yyMMdd");
|
|
|
|
var qry = _db.companies.AsQueryable();
|
|
//var prod = qry.Where(q => q.last_order_no.Contains(order_no)).FirstOrDefault();
|
|
var prod = qry.Where(q => q.num == 1).FirstOrDefault();
|
|
if (prod != null)
|
|
{
|
|
if (!isStrNull(prod.last_order_no) && prod.last_order_no.Contains(order_no))
|
|
{
|
|
int tmp = Convert.ToInt32(prod.last_order_no.Replace(order_no, "")) + 1;
|
|
order_no = order_no + tmp.ToString("0000");
|
|
}
|
|
else
|
|
{
|
|
order_no = order_no + "0001";
|
|
}
|
|
|
|
prod.last_order_no = order_no;
|
|
_db.SaveChanges();
|
|
}
|
|
else
|
|
order_no = "";
|
|
|
|
Application.UnLock();
|
|
|
|
return order_no;
|
|
}
|
|
|
|
protected void add_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid) {
|
|
L_msg.Text = "";
|
|
|
|
Model.activity activity = new Model.activity();
|
|
try
|
|
{
|
|
foreach (Control obj in cardBodyPanel.Controls)
|
|
{
|
|
if (obj is TextBox)
|
|
{
|
|
var ObjValue = activity.GetType().GetProperty(obj.ID);
|
|
var textBox = (TextBox)obj;
|
|
if (!isStrNull(textBox.Text))
|
|
{
|
|
if (textBox.TextMode == TextBoxMode.Date)
|
|
ObjValue.SetValue(activity, selectDate(textBox));
|
|
|
|
else
|
|
ObjValue.SetValue(activity, ((TextBox)obj).Text.Trim());
|
|
}
|
|
else
|
|
ObjValue.SetValue(activity, null);
|
|
|
|
}
|
|
else if (obj is DropDownList)
|
|
{
|
|
var ObjValue = activity.GetType().GetProperty(obj.ID);
|
|
var dropDown = (DropDownList)obj;
|
|
if (!isStrNull(dropDown.SelectedValue))
|
|
{
|
|
if (!isStrNull(dropDown.Attributes["data-int"]) && ValString(dropDown.Attributes["data-int"]).Equals("Y"))
|
|
ObjValue.SetValue(activity, Val(dropDown.SelectedValue));
|
|
else
|
|
ObjValue.SetValue(activity, dropDown.SelectedValue);
|
|
}
|
|
else
|
|
ObjValue.SetValue(activity, null);
|
|
}
|
|
}
|
|
|
|
// printInit 欄位
|
|
//var printInitValue = printInit.Text.Trim();
|
|
//activity.print_init = !string.IsNullOrEmpty(printInitValue) ? printInitValue : null;
|
|
|
|
activity.kind = Val(kind.Value);
|
|
activity.category_kind = Val(category_kind.Value);
|
|
activity.reg_time = DateTime.Now;
|
|
_db.activities.Add(activity);
|
|
_db.SaveChanges();
|
|
int _id = activity.num;
|
|
if (_id > 0)
|
|
{
|
|
RunAutoEnroll(_id);
|
|
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Activity, (int)Model.admin_log.Status.Insert, subject.Text);
|
|
Response.Redirect("index.aspx");
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "Error";
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "操作失敗";
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 資料修改
|
|
|
|
protected void edit_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid)
|
|
{
|
|
L_msg.Text = "";
|
|
|
|
int _num = Val(Request["num"]);
|
|
Model.activity activity = _db.activities.Where(q => q.num == _num).FirstOrDefault(); // 修改
|
|
if (activity != null)
|
|
{
|
|
try
|
|
{
|
|
foreach (Control obj in cardBodyPanel.Controls)
|
|
{
|
|
if (obj is TextBox)
|
|
{
|
|
var ObjValue = activity.GetType().GetProperty(obj.ID);
|
|
var textBox = (TextBox)obj;
|
|
if (!isStrNull(textBox.Text))
|
|
{
|
|
if (textBox.TextMode == TextBoxMode.Date)
|
|
ObjValue.SetValue(activity, selectDate(textBox));
|
|
else
|
|
ObjValue.SetValue(activity, ((TextBox)obj).Text.Trim());
|
|
}
|
|
else
|
|
ObjValue.SetValue(activity, null);
|
|
}
|
|
else if (obj is DropDownList)
|
|
{
|
|
var ObjValue = activity.GetType().GetProperty(obj.ID);
|
|
var dropDown = (DropDownList)obj;
|
|
if (!isStrNull(dropDown.SelectedValue))
|
|
{
|
|
if (!isStrNull(dropDown.Attributes["data-int"]) && ValString(dropDown.Attributes["data-int"]).Equals("Y"))
|
|
ObjValue.SetValue(activity, Val(dropDown.SelectedValue));
|
|
else
|
|
ObjValue.SetValue(activity, dropDown.SelectedValue);
|
|
}
|
|
else
|
|
ObjValue.SetValue(activity, null);
|
|
}
|
|
}
|
|
|
|
// printInit 欄位
|
|
//var printInitValue = printInit.Text.Trim();
|
|
//activity.print_init = !string.IsNullOrEmpty(printInitValue) ? printInitValue : null;
|
|
|
|
activity.category_kind = Val(category_kind.Value);
|
|
_db.SaveChanges();
|
|
|
|
RunAutoEnroll(activity.num);
|
|
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Activity, (int)Model.admin_log.Status.Update, subject.Text);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "操作失敗";
|
|
}
|
|
|
|
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "查無資料";
|
|
}
|
|
}
|
|
}
|
|
|
|
private void RunAutoEnroll(int activityNum)
|
|
{
|
|
var activity = _db.activities.FirstOrDefault(a => a.num == activityNum);
|
|
if (activity == null || !activity.startDate_solar.HasValue) return;
|
|
|
|
DateTime actDate = activity.startDate_solar.Value;
|
|
|
|
var validConfigs = _db.auto_enroll
|
|
.Where(ae => actDate >= ae.start_date && actDate <= ae.end_date)
|
|
.ToList();
|
|
|
|
foreach (var config in validConfigs)
|
|
{
|
|
if (_db.pro_order.Any(o => o.activity_num == activity.num && o.f_num == config.f_num))
|
|
continue;
|
|
|
|
var follower = _db.followers.FirstOrDefault(f => f.num == config.f_num);
|
|
if (follower == null) continue;
|
|
|
|
string newOrderNo = AutoOrderService.CreateAutoOrderNumber(_db);
|
|
|
|
Model.pro_order proOrder = new Model.pro_order
|
|
{
|
|
order_no = newOrderNo,
|
|
up_time = DateTime.Now,
|
|
reg_time = DateTime.Now,
|
|
keyin1 = "A01",
|
|
f_num = follower.num,
|
|
au_num = config.num,
|
|
phone = !string.IsNullOrEmpty(follower.cellphone) ? follower.cellphone : (follower.phone ?? ""),
|
|
activity_num = activity.num,
|
|
address = config.receipt_address ?? "",
|
|
receipt_title = config.receipt_title ?? "",
|
|
demo = "",
|
|
customize_data = ""
|
|
};
|
|
|
|
_db.pro_order.Add(proOrder);
|
|
|
|
CopyLatestOrderDetails(newOrderNo, config.f_num, (int)activity.kind);
|
|
}
|
|
|
|
_db.SaveChanges();
|
|
}
|
|
|
|
private void CopyLatestOrderDetails(string newOrderNo, int f_num, int activityKind)
|
|
{
|
|
var latestOrder = _db.pro_order
|
|
.Where(o => o.f_num == f_num && o.activity.kind == activityKind && _db.pro_order_detail.Any(d => d.order_no == o.order_no))
|
|
.OrderByDescending(o => o.order_no)
|
|
.FirstOrDefault();
|
|
|
|
if (latestOrder != null)
|
|
{
|
|
var prevDetails = _db.pro_order_detail.Where(d => d.order_no == latestOrder.order_no).ToList();
|
|
foreach (var detail in prevDetails)
|
|
{
|
|
Model.pro_order_detail newDetail = new Model.pro_order_detail
|
|
{
|
|
order_no = newOrderNo,
|
|
actItem_num = detail.actItem_num,
|
|
parent_num = detail.parent_num,
|
|
print_id = detail.print_id,
|
|
f_num = detail.f_num,
|
|
f_num_tablet = detail.f_num_tablet,
|
|
address = detail.address,
|
|
from_id = detail.from_id,
|
|
from_id_tablet = detail.from_id_tablet,
|
|
qty = detail.qty,
|
|
price = detail.price,
|
|
start_date = DateTime.Today,
|
|
pay = 0,
|
|
UpdateTime = DateTime.Now
|
|
};
|
|
_db.pro_order_detail.Add(newDetail);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
} |