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.Data.Entity.Infrastructure; public partial class admin_order_reg : MyWeb.config { private Model.ezEntities _db = new Model.ezEntities(); public string _activity_id = ""; public string _follower_id = ""; public string _org_from_id_cuz_data = ""; public string _org_activity_cuz_data = ""; public Dictionary _keyin1Item = null; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Model.pro_order order = new Model.pro_order(); ArrayList options = order.keyin1_list(); foreach (Model.pro_order.keyin optionKey in options) { ListItem item = new ListItem(optionKey.Text, optionKey.Value); item.Attributes.Add("style", "color:" + optionKey.Color); keyin1.Items.Add(item); } _keyin1Item = publicFun.enum_desc(); //報名狀態 if (isStrNull(Request["order_no"])) { up_time.Text =DateTime.Now.ToString("yyyy-MM-dd"); } else { var qry = _db.pro_order.AsEnumerable(); var prod = qry.Where(q => q.order_no == Convert.ToString(Request["order_no"])).FirstOrDefault(); if (prod != null) { MyWeb.encrypt encrypt = new MyWeb.encrypt(); order_no.Text = prod.order_no.ToString(); if (prod.up_time.HasValue) { up_time.Text = prod.up_time.Value.ToString("yyyy-MM-dd"); up_time2.Text = "
" + prod.up_time.Value.ToString("yyyy-MM-dd") + "
"; } keyin1.SelectedValue = prod.keyin1.ToString(); if (prod.f_num.HasValue) { f_num_txt.Value = prod.follower.u_name.ToString(); f_num_txt_link.Text = prod.follower.u_name.ToString(); f_num_txt_link.NavigateUrl = "../follower/reg.aspx?num="+ prod.f_num.ToString(); f_num.Value = prod.f_num.ToString(); _follower_id= prod.f_num.ToString(); } if (prod.introducer.HasValue) { introducer_txt.Value = prod.follower1.u_name.ToString(); introducer.Value = prod.introducer.ToString(); } if (!isStrNull(prod.phone)) { phone.Text = encrypt.DecryptAutoKey(prod.phone); } if (prod.activity_num.HasValue) { activity_num_txt.Value = prod.activity.subject.ToString(); activity_num_txt2.Text = "
" + prod.activity.subject.ToString() + "
"; activity_num.Value = prod.activity_num.ToString(); _activity_id = prod.activity_num.ToString(); } address.Text = prod.address.ToString(); if (prod.receipt_title != null) { receipt_title.Text = prod.receipt_title?.ToString(); } send_receipt.Checked = prod.send_receipt.HasValue ? prod.send_receipt.Value : false; demo.Text = prod.demo.ToString(); customize_data.Text = prod.customize_data; _org_from_id_cuz_data = prod.f_num.HasValue ? prod.follower.customize_data?.Replace(Convert.ToString((char)10), "").Replace(Convert.ToString((char)13), "") ?? "" : ""; _org_activity_cuz_data = prod.activity_num.HasValue ? prod.activity.customize_data?.Replace(Convert.ToString((char)10), "").Replace(Convert.ToString((char)13), "") ?? "" : ""; if (prod.reg_time.HasValue) { timePanel1.Visible = true; reg_time.Text = prod.reg_time.Value.ToString("yyyy/MM/dd HH:mm:ss"); } activity_numPH.Visible = false; f_numPH.Visible = false; up_timePH.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 資料新增 protected string createOrderNumber() { Application.Lock(); string order_no = "AA" + DateTime.Now.ToString("yyMMdd"); var qry = _db.companies.AsEnumerable(); //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 = ""; MyWeb.encrypt encrypt = new MyWeb.encrypt(); Model.pro_order pro_order = new Model.pro_order();//新增 pro_order.order_no = createOrderNumber(); if (isDate(up_time.Text)) { pro_order.up_time = ValDate(up_time.Text); } pro_order.reg_time = DateTime.Now; pro_order.keyin1 = keyin1.SelectedValue; if (IsNumeric(f_num.Value)) { pro_order.f_num = Val(f_num.Value); } if (!isStrNull(phone.Text)) { pro_order.phone = encrypt.EncryptAutoKey(phone.Text); } if (IsNumeric(activity_num.Value)) { pro_order.activity_num = Val(activity_num.Value); } pro_order.address = address.Text; pro_order.receipt_title = receipt_title.Text; pro_order.send_receipt = send_receipt.Checked; pro_order.demo = demo.Text; pro_order.customize_data = customize_data.Text; if (IsNumeric(introducer.Value)) { pro_order.introducer = Val(introducer.Value); } try { if (!isStrNull(pro_order.order_no)) { _db.pro_order.Add(pro_order); _db.SaveChanges(); Model.admin_log admin_log = new Model.admin_log(); admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Order, (int)Model.admin_log.Status.Insert, pro_order.order_no); string url = "index.aspx"; url = "reg.aspx?order_no=" + pro_order.order_no; Response.Redirect(url); } else { L_msg.Type = alert_type.danger; L_msg.Text = "報名單號錯誤"; } } catch (Exception ex) { L_msg.Type = alert_type.danger; //L_msg.Text = ex.InnerException.Message; L_msg.Text = "操作失敗"; } } } #endregion #region 資料修改 protected void edit_Click(object sender, EventArgs e) { if (Page.IsValid) { L_msg.Text = ""; string _orderNo = Request["order_no"].ToString(); MyWeb.encrypt encrypt = new MyWeb.encrypt(); Model.pro_order pro_order = _db.pro_order.Where(q => q.order_no == _orderNo).FirstOrDefault();//修改 if (pro_order != null) { //if (isDate(up_time.Text)) { pro_order.up_time = ValDate(up_time.Text); } pro_order.keyin1 = keyin1.SelectedValue; if (!isStrNull(phone.Text)) { pro_order.phone = encrypt.EncryptAutoKey(phone.Text); } pro_order.address = address.Text; pro_order.receipt_title = receipt_title.Text; pro_order.send_receipt = send_receipt.Checked; pro_order.demo = demo.Text; pro_order.customize_data = customize_data.Text; if (IsNumeric(introducer.Value)) { pro_order.introducer = Val(introducer.Value); } try { _db.SaveChanges(); Model.admin_log admin_log = new Model.admin_log(); admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Order, (int)Model.admin_log.Status.Update, pro_order.order_no); //Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"])); } catch (Exception ex) { L_msg.Type = alert_type.danger; //L_msg.Text = ex.Message; L_msg.Text = "操作失敗"; } } else { L_msg.Type = alert_type.danger; L_msg.Text = "查無資料"; } } } #endregion }