424 lines
16 KiB
C#
424 lines
16 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;
|
|
using Model;
|
|
|
|
public partial class admin_follower_reg : MyWeb.config
|
|
{
|
|
private Model.ezEntities _db = new Model.ezEntities();
|
|
public ArrayList _tmp = new ArrayList();
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
CallAjax();
|
|
|
|
if (!IsPostBack)
|
|
{
|
|
|
|
InitEnumsOptions<Model.follower.type>(identity_type); //身分別
|
|
//var qry = _db.followers.AsEnumerable();
|
|
var qry = _db.followers.AsQueryable();
|
|
|
|
if (isStrNull(Request["num"]))
|
|
{
|
|
if (!isStrNull(Request["leader"]))
|
|
{
|
|
int _num = Val(Request["leader"]);
|
|
var prod = qry.Where(q => q.num == _num).FirstOrDefault(); //家長的資訊
|
|
if (prod != null)
|
|
{
|
|
leader_txt.Value = prod.u_name;
|
|
leader.Value = prod.num.ToString();
|
|
address.Text = prod.address;
|
|
contactor.Text = prod.u_name;
|
|
if (!isStrNull(prod.phone))
|
|
{
|
|
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
|
contactor_phone.Text = encrypt.DecryptAutoKey(prod.phone.ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
//預設國籍
|
|
country.Value = "158";
|
|
country_txt.Value = "中華民國(台灣)";
|
|
}
|
|
else
|
|
{
|
|
int _num = Val(Request["num"]);
|
|
var prod = qry.Where(q => q.num == _num).FirstOrDefault();
|
|
if (prod != null)
|
|
{
|
|
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
|
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 if (!isStrNull(textBox.Attributes["data-encrypt"]) &&
|
|
ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
|
|
{
|
|
textBox.Text = !isStrNull(ObjValue)?
|
|
encrypt.DecryptAutoKey(ObjValue.ToString()) :"";
|
|
}
|
|
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 ex)
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = ex.Message;
|
|
}
|
|
|
|
if (prod.birthday.HasValue)
|
|
{
|
|
Literal1.Text = publicFun.chagenDate(prod.birthday.Value);
|
|
Literal2.Text = Model.follower.chagenSign(prod.birthday.Value);
|
|
|
|
}
|
|
if (prod.leader.HasValue)
|
|
{
|
|
leader_txt.Value = prod.follower1.u_name.ToString();
|
|
leader.Value = prod.leader.ToString();
|
|
}
|
|
|
|
if (!isStrNull(prod.tab))
|
|
{
|
|
string[] k = prod.tab.Split(',');
|
|
for (int i = 0; i < k.Length; i++)
|
|
{
|
|
_tmp.Add(k[i].ToString());
|
|
}
|
|
tab.Value = prod.tab.ToString();
|
|
}
|
|
if (!isStrNull(prod.country))
|
|
{
|
|
country_txt.Value = prod.country1.name_zh.ToString();
|
|
country.Value = prod.country.ToString();
|
|
}
|
|
if (prod.reg_time.HasValue)
|
|
{
|
|
timePanel1.Visible = true;
|
|
reg_time.Text= prod.reg_time.Value.ToString("yyyy/MM/dd HH:mm:ss");
|
|
}
|
|
|
|
if ( !isStrNull( prod.admin_log))
|
|
{
|
|
timePanel2.Visible = true;
|
|
modify_time.Text = prod.admin_log;
|
|
}
|
|
|
|
|
|
edit.Visible = true;
|
|
goback.Visible = true;
|
|
add.Visible = false;
|
|
|
|
phoneReqStar.Visible = false;
|
|
cellphoneReqStar.Visible = false;
|
|
addrReqStar.Visible = false;
|
|
addressRFV.Visible = false;
|
|
f_numberReqStar.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 void add_Click(object sender, EventArgs e)
|
|
{
|
|
if (Page.IsValid) {
|
|
L_msg.Text = "";
|
|
|
|
if (chk_pro_num(f_number.Text))
|
|
{
|
|
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
|
Model.follower followers = new Model.follower();
|
|
try
|
|
{
|
|
foreach (Control obj in cardBodyPanel.Controls)
|
|
{
|
|
if (obj is TextBox)
|
|
{
|
|
var ObjValue = followers.GetType().GetProperty(obj.ID);
|
|
var textBox = (TextBox)obj;
|
|
if (!isStrNull(textBox.Text))
|
|
{
|
|
if (textBox.TextMode == TextBoxMode.Date)
|
|
{
|
|
ObjValue.SetValue(followers, selectDate(textBox));
|
|
}
|
|
else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"])
|
|
&& ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
|
|
{
|
|
ObjValue.SetValue(followers, encrypt.EncryptAutoKey(textBox.Text.Trim()));
|
|
}
|
|
else
|
|
{
|
|
ObjValue.SetValue(followers, ((TextBox)obj).Text.Trim());
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ObjValue.SetValue(followers, null);
|
|
}
|
|
}
|
|
}
|
|
// 使用新的 generate_f_number 方法,已內建重號檢查和重試機制
|
|
followers.f_number = follower.generate_f_number(sex.SelectedValue);
|
|
followers.identity_type = Val(identity_type.SelectedValue);
|
|
if(!isStrNull(leader.Value)) followers.leader = Val(leader.Value);
|
|
if (!isStrNull(country.Value)) followers.country = country.Value;
|
|
followers.sex = sex.SelectedValue;
|
|
|
|
followers.blood = blood.SelectedValue;
|
|
followers.reg_time = DateTime.Now;
|
|
|
|
//tab
|
|
followers.tab = tab.Value.Trim(',');
|
|
|
|
string ChkNewMsg = Model.follower.ChkNewFollower(followers);
|
|
|
|
if(string.IsNullOrEmpty(ChkNewMsg))
|
|
{
|
|
_db.followers.Add(followers);
|
|
_db.SaveChanges();
|
|
}
|
|
int _id = followers.num;
|
|
|
|
if (_id > 0)
|
|
{
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Follower, (int)Model.admin_log.Status.Insert, f_number.Text + u_name.Text);
|
|
|
|
Response.Redirect("index.aspx");
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "錯誤:" + ChkNewMsg;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "操作失敗";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
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 = "";
|
|
|
|
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
|
|
|
int _num = Val(Request["num"]);
|
|
Model.follower followers = _db.followers.Where(q => q.num == _num).FirstOrDefault();//修改
|
|
if (followers != null)
|
|
{
|
|
try
|
|
{
|
|
foreach (Control obj in cardBodyPanel.Controls)
|
|
{
|
|
if (obj is TextBox)
|
|
{
|
|
var ObjValue = followers.GetType().GetProperty(obj.ID);
|
|
var textBox = (TextBox)obj;
|
|
if (!isStrNull(textBox.Text))
|
|
{
|
|
if (textBox.TextMode == TextBoxMode.Date)
|
|
ObjValue.SetValue(followers, selectDate(textBox));
|
|
else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
|
|
ObjValue.SetValue(followers, encrypt.EncryptAutoKey(textBox.Text.Trim()));
|
|
else
|
|
ObjValue.SetValue(followers, ((TextBox)obj).Text.Trim());
|
|
}
|
|
else
|
|
ObjValue.SetValue(followers, null);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
followers.identity_type = Val(identity_type.SelectedValue);
|
|
if (!isStrNull(leader.Value)) followers.leader = Val(leader.Value);
|
|
if (!isStrNull(country.Value)) followers.country = country.Value;
|
|
followers.sex = sex.SelectedValue;
|
|
followers.blood = blood.SelectedValue;
|
|
followers.tab = tab.Value.Trim(',');
|
|
followers.admin_log = admin.info.u_id + " " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
|
|
followers.follower_hash = encrypt.followerHash(followers.phone, followers.id_code);
|
|
_db.SaveChanges();
|
|
|
|
Model.admin_log admin_log = new Model.admin_log();
|
|
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.Follower, (int)Model.admin_log.Status.Update, f_number.Text + u_name.Text);
|
|
|
|
Response.Redirect("index.aspx?page=" + Convert.ToString(Request["page"]));
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "操作失敗";
|
|
L_msg.Text = ex.Message;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "查無資料";
|
|
}
|
|
/*
|
|
if (chk_pro_num(f_number.Text, Val(Request["num"])))
|
|
{
|
|
}
|
|
else
|
|
{
|
|
L_msg.Type = alert_type.danger;
|
|
L_msg.Text = "信眾編號重複";
|
|
}
|
|
*/
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Ajax
|
|
protected void CallAjax()
|
|
{
|
|
if (!isStrNull(Request["type"]))
|
|
{
|
|
Response.Clear();
|
|
Response.ContentType = "application/json";
|
|
AjaxInfo info = new AjaxInfo();
|
|
info.isOk = false;
|
|
info.cDate = "";
|
|
info.sign = "";
|
|
info.msg = "";
|
|
|
|
if (ValString(Request["type"]) == "getTxt")
|
|
{
|
|
if (!isStrNull(Request["date"]) && isDate(Request["date"]))
|
|
{
|
|
DateTime date = ValDate(Request["date"]);
|
|
info.isOk = true;
|
|
|
|
info.cDate = publicFun.chagenDate(date);
|
|
info.sign = Model.follower.chagenSign(date);
|
|
}
|
|
else
|
|
info.msg = "參數不正確";
|
|
|
|
}
|
|
else if (ValString(Request["type"]) == "chkNo")
|
|
{
|
|
if (!isStrNull(Request["txt"]))
|
|
{
|
|
info.isOk = chk_pro_num(ValString(Request["txt"]), !isStrNull(Request["id"]) ? Val(Request["id"]) : 0);
|
|
if (!info.isOk)
|
|
info.msg = "信眾編號重複";
|
|
}
|
|
else
|
|
{
|
|
info.isOk = true;
|
|
info.msg = "";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
info.msg = "參數不正確";
|
|
}
|
|
|
|
Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(info));
|
|
Response.End();
|
|
}
|
|
}
|
|
public class AjaxInfo
|
|
{
|
|
public bool isOk { get; set; }
|
|
public string msg { get; set; }
|
|
public string cDate { get; set; }
|
|
public string cYear { get; set; }
|
|
public string sign { get; set; }
|
|
|
|
}
|
|
#endregion
|
|
|
|
#region 信眾編號
|
|
protected bool chk_pro_num(string txt, int num = 0)
|
|
{
|
|
bool success = false;
|
|
var qry = _db.followers.AsEnumerable();
|
|
qry = qry.Where(q => q.f_number == txt);
|
|
if (num > 0)
|
|
qry = qry.Where(q => q.num != num);
|
|
|
|
var prod = qry.FirstOrDefault();
|
|
|
|
success = (prod == null);
|
|
|
|
return success;
|
|
}
|
|
#endregion
|
|
|
|
|
|
|
|
} |