migrate to new git
This commit is contained in:
429
web/admin/HR/reg.aspx.cs
Normal file
429
web/admin/HR/reg.aspx.cs
Normal file
@@ -0,0 +1,429 @@
|
||||
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_hr_reg : MyWeb.config
|
||||
{
|
||||
private Model.ezEntities _db = new Model.ezEntities();
|
||||
public string _admin_id = "";
|
||||
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
CallAjax();
|
||||
if (!IsPostBack)
|
||||
{
|
||||
|
||||
if (isStrNull(Request["num"]))
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
int _num = Val(Request["num"]);
|
||||
var qry = _db.members.AsEnumerable();
|
||||
var prod = qry.Where(q => q.num == _num).FirstOrDefault();
|
||||
//var prod = _db.members.Where(q => q.num == _num).ToList();
|
||||
if (prod != null)
|
||||
//if (prod.Count>0)
|
||||
{
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
|
||||
|
||||
object[] ctrlist = { f_num, m_number, u_name, sex, id_code, birthday, blood, educational, refugedate, refuge_name,refuge_area, demo
|
||||
, takedate, leavedate, salary, group_kind, title_kind, phone, com_email, email, contact, address1, address2 };
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
foreach (Control obj in ctrlist)
|
||||
{
|
||||
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 = 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)
|
||||
{
|
||||
}
|
||||
for (int i = 1; i <= Model.member.picMax; i++)
|
||||
{
|
||||
if (prod.pic1 != "")
|
||||
{
|
||||
((CheckBox)Panel1.FindControl("CheckBox" + i.ToString())).Visible = true;
|
||||
ViewState["pic" + i.ToString()] = prod.pic1;
|
||||
Image img = (Image)Panel1.FindControl("Image" + i.ToString());
|
||||
img.Visible = true;
|
||||
img.ImageUrl = "../../App_Script/DisplayCut.ashx?file=" + Model.member.Dir.Replace("~/upload/","") + "/" + prod.pic1 + "&w=150&h=150";
|
||||
}
|
||||
}
|
||||
if (prod.f_num.HasValue)
|
||||
{
|
||||
f_num_txt.Value = prod.follower.f_number.ToString();
|
||||
f_num.Value = prod.f_num.ToString();
|
||||
}
|
||||
if (prod.admin_num.HasValue)
|
||||
{
|
||||
admin_num_txt.Value = prod.admin.u_id.ToString();
|
||||
admin_num.Value = prod.admin_num.ToString();
|
||||
_admin_id = prod.admin_num.ToString();
|
||||
}
|
||||
if (prod.group_kind.HasValue)
|
||||
{
|
||||
group_kind_txt.Value = prod.member_group.kind.ToString();
|
||||
group_kind.Value = prod.group_kind.ToString();
|
||||
}
|
||||
if (prod.title_kind.HasValue)
|
||||
{
|
||||
title_kind_txt.Value = prod.member_title.kind.ToString();
|
||||
title_kind.Value = prod.title_kind.ToString();
|
||||
}
|
||||
|
||||
|
||||
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 void add_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (Page.IsValid) {
|
||||
|
||||
L_msg.Text = "";
|
||||
|
||||
if (chk_pro_num(m_number.Text))
|
||||
{
|
||||
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
|
||||
string[] pic_name = fileSystem.UploadPhoto(Model.member.Dir, 800, admin.info.num); //縮圖的寬高不得超過800象素,如果不是圖片也會傳
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
|
||||
|
||||
Model.member member = new Model.member();//新增
|
||||
|
||||
object[] ctrlist = { f_num, m_number, u_name, sex, id_code, birthday, blood, educational, refugedate, refuge_name,refuge_area, demo
|
||||
, admin_num, takedate, leavedate, salary, group_kind, title_kind, phone, com_email, email, contact, address1, address2 };
|
||||
|
||||
member.pic1 = pic_name[0];
|
||||
try
|
||||
{
|
||||
foreach (Control obj in ctrlist)
|
||||
{
|
||||
if (obj is TextBox)
|
||||
{
|
||||
var ObjValue = member.GetType().GetProperty(obj.ID);
|
||||
var textBox = (TextBox)obj;
|
||||
if (!isStrNull(textBox.Text))
|
||||
{
|
||||
if (textBox.TextMode == TextBoxMode.Date)
|
||||
ObjValue.SetValue(member, selectDate(textBox));
|
||||
else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
|
||||
ObjValue.SetValue(member, encrypt.EncryptAutoKey(textBox.Text.Trim()));
|
||||
else
|
||||
ObjValue.SetValue(member, ((TextBox)obj).Text.Trim());
|
||||
}
|
||||
else
|
||||
ObjValue.SetValue(member, null);
|
||||
|
||||
}
|
||||
else if (obj is DropDownList)
|
||||
{
|
||||
var ObjValue = member.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(member, Val(dropDown.SelectedValue));
|
||||
else
|
||||
ObjValue.SetValue(member, dropDown.SelectedValue);
|
||||
}
|
||||
else
|
||||
ObjValue.SetValue(member, null);
|
||||
|
||||
}
|
||||
else if (obj is HiddenField)
|
||||
{
|
||||
var ObjValue = member.GetType().GetProperty(obj.ID);
|
||||
var dropDown = (HiddenField)obj;
|
||||
if (!isStrNull(dropDown.Value))
|
||||
{
|
||||
ObjValue.SetValue(member, Val(dropDown.Value));
|
||||
}
|
||||
else
|
||||
ObjValue.SetValue(member, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_db.members.Add(member);
|
||||
_db.SaveChanges();
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.HR, (int)Model.admin_log.Status.Insert, m_number.Text+ u_name.Text);
|
||||
|
||||
Response.Redirect("index.aspx");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//L_msg.Text = ex.Message;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
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 = "";
|
||||
int _num = Val(Request["num"]);
|
||||
if (chk_pro_num(m_number.Text, _num))
|
||||
{
|
||||
|
||||
MyWeb.fileSystem fileSystem = new MyWeb.fileSystem();
|
||||
string[] pic_name = fileSystem.UploadPhoto(Model.member.Dir, 800, admin.info.num); //縮圖的寬高不得超過800象素,如果不是圖片也會傳
|
||||
MyWeb.encrypt encrypt = new MyWeb.encrypt();
|
||||
|
||||
Model.member member = _db.members.Where(q => q.num == _num).FirstOrDefault();//修改
|
||||
if (member != null)
|
||||
{
|
||||
object[] ctrlist = { f_num, m_number, u_name, sex, id_code, birthday, blood, educational, refugedate, refuge_name,refuge_area, demo
|
||||
, admin_num, takedate, leavedate, salary, group_kind, title_kind, phone, com_email, email, contact, address1, address2 };
|
||||
|
||||
try
|
||||
{
|
||||
foreach (Control obj in ctrlist)
|
||||
{
|
||||
if (obj is TextBox)
|
||||
{
|
||||
var ObjValue = member.GetType().GetProperty(obj.ID);
|
||||
var textBox = (TextBox)obj;
|
||||
if (!isStrNull(textBox.Text))
|
||||
{
|
||||
if (textBox.TextMode == TextBoxMode.Date)
|
||||
ObjValue.SetValue(member, selectDate(textBox));
|
||||
else if (!isStrNull(((TextBox)obj).Attributes["data-encrypt"]) && ValString(textBox.Attributes["data-encrypt"]).Equals("Y"))
|
||||
ObjValue.SetValue(member, encrypt.EncryptAutoKey(textBox.Text.Trim()));
|
||||
else
|
||||
ObjValue.SetValue(member, ((TextBox)obj).Text.Trim());
|
||||
}
|
||||
else
|
||||
ObjValue.SetValue(member, null);
|
||||
|
||||
}
|
||||
else if (obj is DropDownList)
|
||||
{
|
||||
var ObjValue = member.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(member, Val(dropDown.SelectedValue));
|
||||
else
|
||||
ObjValue.SetValue(member, dropDown.SelectedValue);
|
||||
}
|
||||
else
|
||||
ObjValue.SetValue(member, null);
|
||||
|
||||
}
|
||||
else if (obj is HiddenField)
|
||||
{
|
||||
var ObjValue = member.GetType().GetProperty(obj.ID);
|
||||
var dropDown = (HiddenField)obj;
|
||||
if (!isStrNull(dropDown.Value))
|
||||
{
|
||||
ObjValue.SetValue(member, Val(dropDown.Value));
|
||||
}
|
||||
else
|
||||
ObjValue.SetValue(member, null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
L_msg.Text = ex.Message;
|
||||
}
|
||||
for (int i = 1; i <= fileSystem.Count(); i++)
|
||||
{
|
||||
CheckBox ck = (CheckBox)Panel1.FindControl("CheckBox" + i.ToString());
|
||||
if (pic_name[i - 1] != "" | ck.Checked)
|
||||
{
|
||||
member.pic1 = pic_name[i - 1].ToString();
|
||||
if (!isStrNull(ViewState["pic" + i.ToString()]))
|
||||
{
|
||||
fileSystem.Delete(Model.member.Dir + "/" + ViewState["pic" + i.ToString()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (isStrNull(L_msg.Text))
|
||||
{
|
||||
_db.SaveChanges();
|
||||
Model.admin_log admin_log = new Model.admin_log();
|
||||
admin_log.writeLog(admin.info.u_id, (int)Model.admin_log.Systems.HR, (int)Model.admin_log.Status.Update, m_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 = ex.InnerException.Message;
|
||||
L_msg.Text = "操作失敗";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
L_msg.Type = alert_type.danger;
|
||||
L_msg.Text = "查無資料";
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
L_msg.Type = alert_type.danger;
|
||||
L_msg.Text = "人員編號重複";
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
#region 人員編號
|
||||
protected bool chk_pro_num(string txt,int num=0)
|
||||
{
|
||||
bool success=false;
|
||||
var qry = _db.members.AsEnumerable();
|
||||
qry = qry.Where(q => q.m_number == txt);
|
||||
if (num > 0)
|
||||
qry = qry.Where(q => q.num != num);
|
||||
|
||||
var prod = qry.FirstOrDefault();
|
||||
|
||||
success = (prod == null);
|
||||
|
||||
return success;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region Ajax
|
||||
protected void CallAjax()
|
||||
{
|
||||
if (!isStrNull(Request["type"]))
|
||||
{
|
||||
Response.Clear();
|
||||
Response.ContentType = "application/json";
|
||||
AjaxInfo info = new AjaxInfo();
|
||||
info.isOk = false;
|
||||
|
||||
info.msg = "";
|
||||
|
||||
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; }
|
||||
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user