| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369 |
- using BizCom;
- using Castle.ActiveRecord;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using Utils;
- using SiteCore;
- public partial class Ehr_Employee_Edit : BasePage
- {
- protected override void OnPreInit(EventArgs e)
- {
- PmTag = "employee_edit";
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- StringBuilder script = new StringBuilder();
- initBind(ref script);
- int oId = GetInt("oId");
- if (oId > 0)
- {
- hOrg.Value = oId.ToString();
- }
- if (UrlParmsCheck("pId"))
- {
- int pId = GetInt("pId");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from ce_erpuser where ID={0};", pId);
- sql.AppendFormat("select * from ce_erpuserinfo where ID=(select infoid from ce_erpuser where id={0});", pId);
- sql.AppendFormat("select id,OrgID as org,PostID as post,parentid from view_ErpUserPost where userid={0} ;", pId);
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- if (ds == null || ds.Tables[0].Rows.Count < 1)
- {
- ShowError("找不到该记录!");
- }
- DataTable dt = ds.Tables[0];
- DataTable infoDt = ds.Tables[1];
- DataRow dr = dt.Rows[0];
- DataRow infoDr = infoDt.Rows[0];
- //DataRow dr = ds.Tables[0].Rows[0];
- //if (Convert.ToBoolean(dr["isOpen"]))
- //{
- // //btnSaveExecute.Visible = false;
- // btnSaveExecute.Visible = false;
- // promptPanel.Visible = false;
- //}
- txtAcc.Text = dr["Account"].ToString();
- txtCode.Text = dr["Code"].ToString();
- txtName.Text = dr["Name"].ToString();
- hPemShop.Value = dr["pemShop"].ToString();
- hPemDesign.Value = dr["pemDesign"].ToString();
- hPemVend.Value = dr["pemVend"].ToString();
- hPemLogistics.Value = dr["pemLogistics"].ToString();
- hPemExpress.Value = dr["pemExpress"].ToString();
- hOrgIds.Value = dr["ManageOrgIds"].ToString();
- txtDing.Text = infoDr["Ding"].ToString();
- txtTb.Text = infoDr["Tb"].ToString();
- txtPdd.Text = infoDr["Pdd"].ToString();
- txtJd.Text = infoDr["Jd"].ToString();
- txtAli.Text = infoDr["Ali"].ToString();
- TextFinish.Text = infoDr["NoFinish"].ToString();
- TextTotal.Text = infoDr["Total"].ToString();
- TextFinalization.Text = infoDr["Finalization"].ToString();
- SelRadioItemSelected(selSex, infoDr["Sex"]);
- if (infoDr["Picture"].ToString() != "") userPic.Src = "../UserPic/" + infoDr["Picture"];
- txtMobile.Text = infoDr["Mobile"].ToString();
- txtIdentityCard.Text = infoDr["IdentityCard"].ToString();
- txtAddress.Text = infoDr["Address"].ToString();
- if (infoDr["BirthDay"].ToString() != "") txtBirthDay.Text = Convert.ToDateTime(infoDr["BirthDay"]).ToString("yyyy-MM-dd");
- if (infoDr["EnterTime"].ToString() != "") txtEnterTime.Text = Convert.ToDateTime(infoDr["EnterTime"]).ToString("yyyy-MM-dd");
- SelItemSelected(selParty, infoDr["Party"]);
- hId.Value = pId.ToString();
- script.AppendFormat("selPostData={0};", Utils.Serialization.JsonString.DataTable2Json(ds.Tables[2]));
- }
- AppendScript(script.ToString());
- }
- }
- private void initBind(ref StringBuilder str)
- {
- StringBuilder sql = new StringBuilder();
- if (CurrentUser.UserPost.Post.Code == "SysAdmin")
- {
- sql.AppendFormat("select * from CE_ErpOrganization ;");
- sql.AppendFormat("select id,name,orgId from CE_ErpPost order by sort asc ;");
- }
- else
- {
- sql.AppendFormat("select * from CE_ErpOrganization where id In ({0});", CurrentUser.User.ManageOrgIds.Length > 0 ? CurrentUser.User.ManageOrgIds : "0");
- sql.AppendFormat("select id,name,orgId from CE_ErpPost order by sort asc ;", CurrentUser.UserPost.OrgID);
- }
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- str.AppendFormat("orgData={0};", Utils.Serialization.JsonString.DataTable2Json(ds.Tables[0]));
- str.AppendFormat("postData={0};", Utils.Serialization.JsonString.DataTable2Json(ds.Tables[1]));
- }
- private string getOrgName(object name, object path)
- {
- if (path.ToString() == "") return name.ToString();
- int len = path.ToString().Split('|').Length - 2;
- return "".PadLeft(len, ' ') + name;
- }
- protected void btnSaveExecute_Click(object sender, EventArgs e)
- {
- savePerson(true);
- }
- protected void btnSave_Click(object sender, EventArgs e)
- {
- if (hSave.Value != "" && hSave.Value != "0")
- {
- savePerson(true);
- }
- else
- {
- savePerson(false);
- }
- }
- protected void savePerson(bool isExecute)
- {
- using (TransactionScope scope = new TransactionScope())
- {
- try
- {
- CeErpUser entity = null;
- CeErpUserInfo personEntity = null;
- bool isAdd = false;
- string oldContent = "";
- if (hId.Value != "")
- {
- //if (txtCode.Text != "" && CeErpUserInfo.Exists("Code=? and ID<>?", txtCode.Text, hId.Value))
- //{
- // ShowMsg("该工号已经存在,请更换!");
- // return;
- //}
- entity = CeErpUser.Get(hId.Value);
- if (entity.Account != txtAcc.Text)
- {
- if (txtAcc.Text != "" && CeErpUser.Exists("Account=? and Account<>?", txtAcc.Text, entity.Account))
- {
- ShowMsg("该账号已经存在,请更换!");
- return;
- }
- }
- personEntity = CeErpUserInfo.Get(entity.InfoID);
- isAdd = false;
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select Name,Account,OrgID,PostID from view_ErpUser where ID={0};", hId.Value);
- DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
- if (ds == null || ds.Tables[0].Rows.Count < 1)
- {
- ShowError("找不到该员工!");
- }
- DataTable dt = ds.Tables[0];
- DataRow dr = dt.Rows[0];
- oldContent = dr["Name"].ToString() + "/" + dr["Account"].ToString() + "/" + dr["OrgID"].ToString() + "/" + dr["PostID"].ToString();
- }
- else
- {
- if (txtAcc.Text != "" && CeErpUser.Exists("Account=?", txtAcc.Text))
- {
- ShowMsg("该账号已经存在,请更换!");
- return;
- }
- entity = new CeErpUser();
- entity.CreateTime = DateTime.Now;
- personEntity = new CeErpUserInfo();
- isAdd = true;
- }
- //图片上传
- if (txtFile.HasFile)
- {
- string errMsg = null;
- string picFile = ImageHelper.UpLoadUserPic(txtFile.PostedFile, txtCode.Text, out errMsg);
- if (picFile == "")
- {
- ShowMsg(errMsg);
- return;
- }
- else
- {
- personEntity.Picture = picFile;
- }
- }
- entity.Code = txtCode.Text;
- entity.Name = txtName.Text;
- entity.Account = txtAcc.Text;
- personEntity.Ding = txtDing.Text;
- personEntity.Tb = txtTb.Text;
- personEntity.Pdd = txtPdd.Text;
- personEntity.Jd = txtJd.Text;
- personEntity.Ali = txtAli.Text;
- personEntity.NoFinish = Convert.ToInt32(TextFinish.Text);
- personEntity.Total = Convert.ToInt32(TextTotal.Text);
- personEntity.Finalization = Convert.ToInt32(TextFinalization.Text);
- personEntity.Sex = selSex.SelectedItem.Value;
- personEntity.Mobile = txtMobile.Text;
- personEntity.IdentityCard = txtIdentityCard.Text;
- personEntity.Address = txtAddress.Text;
- if (txtBirthDay.Text != "") personEntity.BirthDay = Convert.ToDateTime(txtBirthDay.Text);
- if (txtEnterTime.Text != "") personEntity.EnterTime = Convert.ToDateTime(txtEnterTime.Text);
- personEntity.Party = selParty.SelectedItem.Value;
- if (hId.Value != "")
- {
- personEntity.Update();
- }
- else
- {
- personEntity.Create();
- }
- //if (isExecute)
- //{
- //}
- entity.InfoID = personEntity.ID;
- entity.Station = GetStation();
- entity.pemShop = hPemShop.Value;
- entity.pemDesign = hPemDesign.Value;
- entity.pemVend = hPemVend.Value;
- entity.pemLogistics = hPemLogistics.Value;
- entity.pemExpress = hPemExpress.Value;
- if (CurrentUser.UserPost.Post.Code == "SysAdmin")
- {
- entity.ManageOrgIds = hOrgIds.Value;
- }
- if (isAdd)
- {
- entity.PassWord = SecurityHelper.EncryptSymmetric("000000");
- entity.CreateTime = DateTime.Now;
- entity.isOpen = true;
- entity.Create();
- }
- else entity.Update();
- //归属部门职位信息
- if (hSite.Value != "")
- {
- string[] sArr = hSite.Value.Split(',');
- string[] dArr = hDep.Value.Split(',');
- string[] pArr = hPost.Value.Split(',');
- StringBuilder sql = new StringBuilder();
- if (hId.Value == "")//新增
- {
- for (var i = 0; i < sArr.Length; i++)
- {
- CeErpUserPost personPost = new CeErpUserPost();
- personPost.UserID = entity.ID;
- personPost.OrgID = Convert.ToInt32(dArr[i]);
- personPost.PostID = Convert.ToInt32(pArr[i]);
- personPost.Create();
- }
- }
- else//修改
- {
- string[] ppArr = hPP.Value.Split(',');
- if (ppArr.Length > sArr.Length)
- {
- bool ps = false;
- for (var pi = 0; pi < ppArr.Length; pi++)
- {
- ps = false;
- for (var si = 0; si < sArr.Length; si++)
- {
- if (ppArr[pi] == sArr[si]) { ps = false; break; }
- else ps = true;
- }
- if (ps)//被删除的
- {
- CeErpUserPost.Del(ppArr[pi], hId.Value);
- }
- }
- }
- for (var i = 0; i < sArr.Length; i++)
- {
- if (hPP.Value != "" && ppArr.Length > i)
- {
- CeErpUserPost personPost = CeErpUserPost.Get(entity.ID, ppArr[i]);
- bool isNew = false;
- if (personPost == null)
- {
- personPost = new CeErpUserPost();
- personPost.UserID = entity.ID;
- isNew = true;
- }
- personPost.OrgID = Convert.ToInt32(dArr[i]);
- personPost.PostID = Convert.ToInt32(pArr[i]);
- if (isNew) personPost.Create();
- else personPost.Update();
- }
- else
- {
- CeErpUserPost personPost = new CeErpUserPost();
- personPost.UserID = entity.ID;
- personPost.OrgID = Convert.ToInt32(dArr[i]);
- personPost.PostID = Convert.ToInt32(pArr[i]);
- personPost.Create();
- }
- }
- }
- //CeErpUserInfoPost.ExecuteNonQuery(sql.ToString());
- }
- SupplierLog supplierLog = new SupplierLog();
- supplierLog.UserID = CurrentUser.UserID;
- supplierLog.UserName = CurrentUser.UserName;
- supplierLog.OldContent = oldContent;
- supplierLog.NewContent = entity.Name + "/" + entity.Account + "/" + hDep.Value.Split(',')[0] + "/" + hPost.Value.Split(',')[0];
- supplierLog.ModifyTime = DateTime.Now;
- supplierLog.Create();
- scope.VoteCommit();
- ShowResult("保存成功", "closeFn(1);");
- }
- catch (Exception ex)
- {
- scope.VoteRollBack();
- ShowMsg("系统错误,无法添加员工!");
- //WebLog.SysLog(CurrentUser.UserID, "添加员工发生错误", ex);
- }
- }
- }
- private string GetStation()
- {
- if (hSite.Value != "")
- {
- var str = "";
- string[] sArr = hSite.Value.Split(',');
- str += sArr[0];
- for (int si = 1; si <= sArr.Length - 1; si++)
- {
- if (sArr[si] != sArr[si + 1])
- {
- str += "," + sArr[si + 1];
- }
- }
- return str;
- }
- return "";
- }
- }
|