Employee_Edit.aspx.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. using BizCom;
  2. using Castle.ActiveRecord;
  3. using SQLData;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Text;
  8. using System.Web;
  9. using System.Web.UI;
  10. using System.Web.UI.WebControls;
  11. using Utils;
  12. using SiteCore;
  13. public partial class Ehr_Employee_Edit : BasePage
  14. {
  15. protected override void OnPreInit(EventArgs e)
  16. {
  17. PmTag = "employee_edit";
  18. }
  19. protected void Page_Load(object sender, EventArgs e)
  20. {
  21. if (!IsPostBack)
  22. {
  23. StringBuilder script = new StringBuilder();
  24. initBind(ref script);
  25. int oId = GetInt("oId");
  26. if (oId > 0)
  27. {
  28. hOrg.Value = oId.ToString();
  29. }
  30. if (UrlParmsCheck("pId"))
  31. {
  32. int pId = GetInt("pId");
  33. StringBuilder sql = new StringBuilder();
  34. sql.AppendFormat("select * from ce_erpuser where ID={0};", pId);
  35. sql.AppendFormat("select * from ce_erpuserinfo where ID=(select infoid from ce_erpuser where id={0});", pId);
  36. sql.AppendFormat("select id,OrgID as org,PostID as post,parentid from view_ErpUserPost where userid={0} ;", pId);
  37. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  38. if (ds == null || ds.Tables[0].Rows.Count < 1)
  39. {
  40. ShowError("找不到该记录!");
  41. }
  42. DataTable dt = ds.Tables[0];
  43. DataTable infoDt = ds.Tables[1];
  44. DataRow dr = dt.Rows[0];
  45. DataRow infoDr = infoDt.Rows[0];
  46. //DataRow dr = ds.Tables[0].Rows[0];
  47. //if (Convert.ToBoolean(dr["isOpen"]))
  48. //{
  49. // //btnSaveExecute.Visible = false;
  50. // btnSaveExecute.Visible = false;
  51. // promptPanel.Visible = false;
  52. //}
  53. txtAcc.Text = dr["Account"].ToString();
  54. txtCode.Text = dr["Code"].ToString();
  55. txtName.Text = dr["Name"].ToString();
  56. hPemShop.Value = dr["pemShop"].ToString();
  57. hPemDesign.Value = dr["pemDesign"].ToString();
  58. hPemVend.Value = dr["pemVend"].ToString();
  59. hPemLogistics.Value = dr["pemLogistics"].ToString();
  60. hPemExpress.Value = dr["pemExpress"].ToString();
  61. hOrgIds.Value = dr["ManageOrgIds"].ToString();
  62. txtDing.Text = infoDr["Ding"].ToString();
  63. txtTb.Text = infoDr["Tb"].ToString();
  64. txtPdd.Text = infoDr["Pdd"].ToString();
  65. txtJd.Text = infoDr["Jd"].ToString();
  66. txtAli.Text = infoDr["Ali"].ToString();
  67. TextFinish.Text = infoDr["NoFinish"].ToString();
  68. TextTotal.Text = infoDr["Total"].ToString();
  69. TextFinalization.Text = infoDr["Finalization"].ToString();
  70. SelRadioItemSelected(selSex, infoDr["Sex"]);
  71. if (infoDr["Picture"].ToString() != "") userPic.Src = "../UserPic/" + infoDr["Picture"];
  72. txtMobile.Text = infoDr["Mobile"].ToString();
  73. txtIdentityCard.Text = infoDr["IdentityCard"].ToString();
  74. txtAddress.Text = infoDr["Address"].ToString();
  75. if (infoDr["BirthDay"].ToString() != "") txtBirthDay.Text = Convert.ToDateTime(infoDr["BirthDay"]).ToString("yyyy-MM-dd");
  76. if (infoDr["EnterTime"].ToString() != "") txtEnterTime.Text = Convert.ToDateTime(infoDr["EnterTime"]).ToString("yyyy-MM-dd");
  77. SelItemSelected(selParty, infoDr["Party"]);
  78. hId.Value = pId.ToString();
  79. script.AppendFormat("selPostData={0};", Utils.Serialization.JsonString.DataTable2Json(ds.Tables[2]));
  80. }
  81. AppendScript(script.ToString());
  82. }
  83. }
  84. private void initBind(ref StringBuilder str)
  85. {
  86. StringBuilder sql = new StringBuilder();
  87. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  88. {
  89. sql.AppendFormat("select * from CE_ErpOrganization ;");
  90. sql.AppendFormat("select id,name,orgId from CE_ErpPost order by sort asc ;");
  91. }
  92. else
  93. {
  94. sql.AppendFormat("select * from CE_ErpOrganization where id In ({0});", CurrentUser.User.ManageOrgIds.Length > 0 ? CurrentUser.User.ManageOrgIds : "0");
  95. sql.AppendFormat("select id,name,orgId from CE_ErpPost order by sort asc ;", CurrentUser.UserPost.OrgID);
  96. }
  97. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  98. str.AppendFormat("orgData={0};", Utils.Serialization.JsonString.DataTable2Json(ds.Tables[0]));
  99. str.AppendFormat("postData={0};", Utils.Serialization.JsonString.DataTable2Json(ds.Tables[1]));
  100. }
  101. private string getOrgName(object name, object path)
  102. {
  103. if (path.ToString() == "") return name.ToString();
  104. int len = path.ToString().Split('|').Length - 2;
  105. return "".PadLeft(len, ' ') + name;
  106. }
  107. protected void btnSaveExecute_Click(object sender, EventArgs e)
  108. {
  109. savePerson(true);
  110. }
  111. protected void btnSave_Click(object sender, EventArgs e)
  112. {
  113. if (hSave.Value != "" && hSave.Value != "0")
  114. {
  115. savePerson(true);
  116. }
  117. else
  118. {
  119. savePerson(false);
  120. }
  121. }
  122. protected void savePerson(bool isExecute)
  123. {
  124. using (TransactionScope scope = new TransactionScope())
  125. {
  126. try
  127. {
  128. CeErpUser entity = null;
  129. CeErpUserInfo personEntity = null;
  130. bool isAdd = false;
  131. string oldContent = "";
  132. if (hId.Value != "")
  133. {
  134. //if (txtCode.Text != "" && CeErpUserInfo.Exists("Code=? and ID<>?", txtCode.Text, hId.Value))
  135. //{
  136. // ShowMsg("该工号已经存在,请更换!");
  137. // return;
  138. //}
  139. entity = CeErpUser.Get(hId.Value);
  140. if (entity.Account != txtAcc.Text)
  141. {
  142. if (txtAcc.Text != "" && CeErpUser.Exists("Account=? and Account<>?", txtAcc.Text, entity.Account))
  143. {
  144. ShowMsg("该账号已经存在,请更换!");
  145. return;
  146. }
  147. }
  148. personEntity = CeErpUserInfo.Get(entity.InfoID);
  149. isAdd = false;
  150. StringBuilder sql = new StringBuilder();
  151. sql.AppendFormat("select Name,Account,OrgID,PostID from view_ErpUser where ID={0};", hId.Value);
  152. DataSet ds = DbHelper.DbConn.ExecuteDataset(sql.ToString());
  153. if (ds == null || ds.Tables[0].Rows.Count < 1)
  154. {
  155. ShowError("找不到该员工!");
  156. }
  157. DataTable dt = ds.Tables[0];
  158. DataRow dr = dt.Rows[0];
  159. oldContent = dr["Name"].ToString() + "/" + dr["Account"].ToString() + "/" + dr["OrgID"].ToString() + "/" + dr["PostID"].ToString();
  160. }
  161. else
  162. {
  163. if (txtAcc.Text != "" && CeErpUser.Exists("Account=?", txtAcc.Text))
  164. {
  165. ShowMsg("该账号已经存在,请更换!");
  166. return;
  167. }
  168. entity = new CeErpUser();
  169. entity.CreateTime = DateTime.Now;
  170. personEntity = new CeErpUserInfo();
  171. isAdd = true;
  172. }
  173. //图片上传
  174. if (txtFile.HasFile)
  175. {
  176. string errMsg = null;
  177. string picFile = ImageHelper.UpLoadUserPic(txtFile.PostedFile, txtCode.Text, out errMsg);
  178. if (picFile == "")
  179. {
  180. ShowMsg(errMsg);
  181. return;
  182. }
  183. else
  184. {
  185. personEntity.Picture = picFile;
  186. }
  187. }
  188. entity.Code = txtCode.Text;
  189. entity.Name = txtName.Text;
  190. entity.Account = txtAcc.Text;
  191. personEntity.Ding = txtDing.Text;
  192. personEntity.Tb = txtTb.Text;
  193. personEntity.Pdd = txtPdd.Text;
  194. personEntity.Jd = txtJd.Text;
  195. personEntity.Ali = txtAli.Text;
  196. personEntity.NoFinish = Convert.ToInt32(TextFinish.Text);
  197. personEntity.Total = Convert.ToInt32(TextTotal.Text);
  198. personEntity.Finalization = Convert.ToInt32(TextFinalization.Text);
  199. personEntity.Sex = selSex.SelectedItem.Value;
  200. personEntity.Mobile = txtMobile.Text;
  201. personEntity.IdentityCard = txtIdentityCard.Text;
  202. personEntity.Address = txtAddress.Text;
  203. if (txtBirthDay.Text != "") personEntity.BirthDay = Convert.ToDateTime(txtBirthDay.Text);
  204. if (txtEnterTime.Text != "") personEntity.EnterTime = Convert.ToDateTime(txtEnterTime.Text);
  205. personEntity.Party = selParty.SelectedItem.Value;
  206. if (hId.Value != "")
  207. {
  208. personEntity.Update();
  209. }
  210. else
  211. {
  212. personEntity.Create();
  213. }
  214. //if (isExecute)
  215. //{
  216. //}
  217. entity.InfoID = personEntity.ID;
  218. entity.Station = GetStation();
  219. entity.pemShop = hPemShop.Value;
  220. entity.pemDesign = hPemDesign.Value;
  221. entity.pemVend = hPemVend.Value;
  222. entity.pemLogistics = hPemLogistics.Value;
  223. entity.pemExpress = hPemExpress.Value;
  224. if (CurrentUser.UserPost.Post.Code == "SysAdmin")
  225. {
  226. entity.ManageOrgIds = hOrgIds.Value;
  227. }
  228. if (isAdd)
  229. {
  230. entity.PassWord = SecurityHelper.EncryptSymmetric("000000");
  231. entity.CreateTime = DateTime.Now;
  232. entity.isOpen = true;
  233. entity.Create();
  234. }
  235. else entity.Update();
  236. //归属部门职位信息
  237. if (hSite.Value != "")
  238. {
  239. string[] sArr = hSite.Value.Split(',');
  240. string[] dArr = hDep.Value.Split(',');
  241. string[] pArr = hPost.Value.Split(',');
  242. StringBuilder sql = new StringBuilder();
  243. if (hId.Value == "")//新增
  244. {
  245. for (var i = 0; i < sArr.Length; i++)
  246. {
  247. CeErpUserPost personPost = new CeErpUserPost();
  248. personPost.UserID = entity.ID;
  249. personPost.OrgID = Convert.ToInt32(dArr[i]);
  250. personPost.PostID = Convert.ToInt32(pArr[i]);
  251. personPost.Create();
  252. }
  253. }
  254. else//修改
  255. {
  256. string[] ppArr = hPP.Value.Split(',');
  257. if (ppArr.Length > sArr.Length)
  258. {
  259. bool ps = false;
  260. for (var pi = 0; pi < ppArr.Length; pi++)
  261. {
  262. ps = false;
  263. for (var si = 0; si < sArr.Length; si++)
  264. {
  265. if (ppArr[pi] == sArr[si]) { ps = false; break; }
  266. else ps = true;
  267. }
  268. if (ps)//被删除的
  269. {
  270. CeErpUserPost.Del(ppArr[pi], hId.Value);
  271. }
  272. }
  273. }
  274. for (var i = 0; i < sArr.Length; i++)
  275. {
  276. if (hPP.Value != "" && ppArr.Length > i)
  277. {
  278. CeErpUserPost personPost = CeErpUserPost.Get(entity.ID, ppArr[i]);
  279. bool isNew = false;
  280. if (personPost == null)
  281. {
  282. personPost = new CeErpUserPost();
  283. personPost.UserID = entity.ID;
  284. isNew = true;
  285. }
  286. personPost.OrgID = Convert.ToInt32(dArr[i]);
  287. personPost.PostID = Convert.ToInt32(pArr[i]);
  288. if (isNew) personPost.Create();
  289. else personPost.Update();
  290. }
  291. else
  292. {
  293. CeErpUserPost personPost = new CeErpUserPost();
  294. personPost.UserID = entity.ID;
  295. personPost.OrgID = Convert.ToInt32(dArr[i]);
  296. personPost.PostID = Convert.ToInt32(pArr[i]);
  297. personPost.Create();
  298. }
  299. }
  300. }
  301. //CeErpUserInfoPost.ExecuteNonQuery(sql.ToString());
  302. }
  303. SupplierLog supplierLog = new SupplierLog();
  304. supplierLog.UserID = CurrentUser.UserID;
  305. supplierLog.UserName = CurrentUser.UserName;
  306. supplierLog.OldContent = oldContent;
  307. supplierLog.NewContent = entity.Name + "/" + entity.Account + "/" + hDep.Value.Split(',')[0] + "/" + hPost.Value.Split(',')[0];
  308. supplierLog.ModifyTime = DateTime.Now;
  309. supplierLog.Create();
  310. scope.VoteCommit();
  311. ShowResult("保存成功", "closeFn(1);");
  312. }
  313. catch (Exception ex)
  314. {
  315. scope.VoteRollBack();
  316. ShowMsg("系统错误,无法添加员工!");
  317. //WebLog.SysLog(CurrentUser.UserID, "添加员工发生错误", ex);
  318. }
  319. }
  320. }
  321. private string GetStation()
  322. {
  323. if (hSite.Value != "")
  324. {
  325. var str = "";
  326. string[] sArr = hSite.Value.Split(',');
  327. str += sArr[0];
  328. for (int si = 1; si <= sArr.Length - 1; si++)
  329. {
  330. if (sArr[si] != sArr[si + 1])
  331. {
  332. str += "," + sArr[si + 1];
  333. }
  334. }
  335. return str;
  336. }
  337. return "";
  338. }
  339. }