BizComponent_PMU.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
  1. using System;
  2. using System.Data;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. //using MediII.Adapter.BaseBiz;
  7. using System.Data.Common;
  8. using System.Transactions;
  9. using Microsoft.Practices.EnterpriseLibrary.Data;
  10. //using MediII.Adapter.Model.UE;
  11. using System.Globalization;
  12. using MediII.Adapter.BizComponent.Base;
  13. using IL.Common;
  14. using System.Xml;
  15. namespace MediII.Adapter.BizComponent.PMU
  16. {
  17. public class BizComponent_PMU : BaseBizComponent, IBizComponent
  18. {
  19. const string Insert = "B01"; //增加个人纪录
  20. //const string Update = "B02"; //更新个人记录
  21. //const string Delete = "B03"; //删除个人记录
  22. //数据库连接
  23. protected Database ctx
  24. {
  25. get { return base.HealthCarectx; }
  26. }
  27. public BizComponent_PMU()
  28. {
  29. }
  30. ////HealthCareContainer HealthCareContainer = new HealthCareContainer();
  31. //private Database ctx = null;
  32. //public BizComponent_PMU(Database dbCtx)
  33. //{
  34. // ctx = dbCtx;
  35. //}
  36. public override string DoProcess(string m, string msgType)
  37. {
  38. string strMsgType = null;
  39. //try
  40. //{
  41. //try
  42. // {
  43. //取得消息类型 MAD新增 MUP更新 MDL删除 "MDC"作废 "MAC"恢复
  44. OperateXmlUtil helper = new OperateXmlUtil();
  45. string qurysql = "select count(*) from dbo.his_doct where DOCT_CODE=@DOCT_CODE";
  46. DbCommand command = ctx.GetSqlStringCommand(qurysql.ToString());
  47. //string pkid = helper.XpathRead(m, "//*[@root='2.16.156.10011.1.4']", "extension");
  48. //ctx.AddInParameter(command, "DOCT_CODE", System.Data.DbType.String, pkid);
  49. //int counts = Convert.ToInt32(ctx.ExecuteScalar(command));
  50. var valueNode = helper.XpathRead(m, "//*[name()='healthCarePrincipalPerson']").Item(0);
  51. string idCode = string.Empty;
  52. foreach (XmlNode xe in valueNode.ChildNodes)
  53. {
  54. if (xe.Name == "name")
  55. {
  56. idCode = xe.LastChild.LastChild.Attributes["value"].Value;
  57. break;
  58. }
  59. }
  60. int index = idCode.IndexOf('/');
  61. string pkid = idCode.Substring(index, idCode.Length - index);
  62. //ctx.AddInParameter(command, "DOCT_NAME", System.Data.DbType.String, pkid.Substring(0,index));
  63. ctx.AddInParameter(command, "DOCT_CODE", System.Data.DbType.String, idCode.Substring(index, idCode.Length - index));
  64. int counts = Convert.ToInt32(ctx.ExecuteScalar(command));
  65. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  66. {
  67. //for (int i = 0; i < pmuB01.EDURepetitionsUsed; i++)
  68. //{
  69. if (counts == 0)
  70. {
  71. //没有查询到记录则新增,否则修改
  72. AddData(m, idCode);
  73. }
  74. else
  75. {
  76. UpDateData(m, idCode);
  77. }
  78. scope.Complete();
  79. }
  80. return string.Empty;
  81. }
  82. public void AddData(string message, string id)
  83. {
  84. #region 新增
  85. // string sql = @"INSERT INTO dbo.his_doct
  86. // ( DOCT_CODE ,
  87. // DOCT_NAME ,
  88. // HIS_DEPT_CODE ,
  89. // HIS_DEPT_NAME ,
  90. // status
  91. // )
  92. // VALUES ( @DOCT_CODE,
  93. // @DOCT_NAME ,
  94. // @HIS_DEPT_CODE ,
  95. // @HIS_DEPT_NAME ,
  96. // @status)";
  97. string sql = @"INSERT INTO dbo.his_doct
  98. ( DOCT_CODE ,
  99. DOCT_NAME
  100. )
  101. VALUES ( @DOCT_CODE,
  102. @DOCT_NAME )";
  103. DbCommand command = ctx.GetSqlStringCommand(sql.ToString());
  104. SetEntity(message, command, id);
  105. SqlDataAccess.ExecuteNonQuery(ctx, command);
  106. #endregion
  107. }
  108. public void UpDateData(string message, string id)
  109. {
  110. #region 修改
  111. string sql1 = @"update dbo.his_doct set
  112. DOCT_NAME =@DOCT_NAME
  113. where DOCT_CODE=@DOCT_CODE";
  114. DbCommand command1 = ctx.GetSqlStringCommand(sql1.ToString());
  115. SetEntity(message, command1, id);
  116. SqlDataAccess.ExecuteNonQuery(ctx, command1);
  117. #endregion
  118. }
  119. public void SetEntity(string message, DbCommand command, string id)
  120. {
  121. string value = string.Empty;
  122. OperateXmlUtil xmlHelper = new OperateXmlUtil();
  123. int index = id.IndexOf('/');
  124. ctx.AddInParameter(command, "DOCT_CODE", System.Data.DbType.String, id.Substring(index+1, id.Length - index-1));
  125. ctx.AddInParameter(command, "DOCT_NAME", System.Data.DbType.String, id.Substring(0,index));
  126. //var valueNode = xmlHelper.XpathRead(message, "//*[name()='healthCarePrincipalPerson']").Item(0);
  127. //foreach (XmlNode xe in valueNode.ChildNodes)
  128. //{
  129. // if (xe.Name == "name")
  130. // {
  131. // value = xe.LastChild.LastChild.Attributes["value"].Value;
  132. // ctx.AddInParameter(command, "DOCT_NAME", System.Data.DbType.String, value);
  133. // break;
  134. // }
  135. //}
  136. //value = xmlHelper.XpathRead(message, "//*[@root='2.16.156.10011.1.26']", "extension");
  137. //ctx.AddInParameter(command, "HIS_DEPT_CODE", System.Data.DbType.AnsiString, value);
  138. //valueNode = xmlHelper.XpathRead(message, "//*[name()='affiliatedPrincipalOrganization']").Item(0);
  139. //foreach (XmlNode xe in valueNode.ChildNodes)
  140. //{
  141. // if (xe.Name == "name")
  142. // {
  143. // value = xe.LastChild.LastChild.Attributes["value"].Value;
  144. // ctx.AddInParameter(command, "HIS_DEPT_NAME", System.Data.DbType.String, value);
  145. // break;
  146. // }
  147. //}
  148. //ctx.AddInParameter(command, "status", System.Data.DbType.String, "在用");
  149. //ctx.ExecuteNonQuery(command);
  150. }
  151. public void AddEmpLicense(string type, string pkid, string bm, string updateuser)
  152. {
  153. #region 新增资格编码
  154. var sql = @"INSERT INTO HealthCare.dbo.EmpLicense
  155. ( EmpLicenseID ,
  156. EmpNo ,
  157. LicenseType ,
  158. LicenseClass ,
  159. LicenseNo ,
  160. IsMajor ,
  161. IssueDate ,
  162. StartDate ,
  163. EndDate ,
  164. UpdateUser ,
  165. UpdateTime ,
  166. IsDel
  167. )
  168. VALUES ( NEXT VALUE FOR HealthCare.dbo.Seq_EmpLicense_EmpLicenseID ,
  169. @EmpNo ,
  170. @LicenseType ,
  171. 1 ,
  172. @LicenseNo ,
  173. 0 ,
  174. GETDATE() ,
  175. GETDATE() ,
  176. '2999-12-31 00:00:00.000',
  177. @UpdateUser ,
  178. GETDATE() ,
  179. 0
  180. )";
  181. #endregion
  182. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  183. SqlDataAccess.AddInParameter(ctx, cmd, "EmpNo", DbType.AnsiString, pkid);
  184. SqlDataAccess.AddInParameter(ctx, cmd, "LicenseType", DbType.AnsiString, type);
  185. SqlDataAccess.AddInParameter(ctx, cmd, "LicenseNo", DbType.AnsiString, bm);
  186. SqlDataAccess.AddInParameter(ctx, cmd, "UpdateUser", DbType.AnsiString, updateuser);
  187. SqlDataAccess.DBExecuteNonQuery(ctx, cmd);
  188. }
  189. public void UpdateEmpLicense(string type, string pkid, string bm)
  190. {
  191. var sql = @"UPDATE HealthCare.dbo.EmpLicense SET LicenseNo=@LicenseNo WHERE EmpNo=@EmpNo AND LicenseType=@LicenseType ";
  192. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  193. SqlDataAccess.AddInParameter(ctx, cmd, "EmpNo", DbType.AnsiString, pkid);
  194. SqlDataAccess.AddInParameter(ctx, cmd, "LicenseType", DbType.AnsiString, type);
  195. SqlDataAccess.AddInParameter(ctx, cmd, "LicenseNo", DbType.AnsiString, bm);
  196. SqlDataAccess.DBExecuteNonQuery(ctx, cmd);
  197. }
  198. public void DeleteEmpLicense(string type, string pkid)
  199. {
  200. var sql = "DELETE FROM HealthCare.dbo.EmpLicense WHERE EmpNo=@EmpNo AND LicenseType=@LicenseType";
  201. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  202. SqlDataAccess.AddInParameter(ctx, cmd, "EmpNo", DbType.AnsiString, pkid);
  203. SqlDataAccess.AddInParameter(ctx, cmd, "LicenseType", DbType.AnsiString, type);
  204. SqlDataAccess.DBExecuteNonQuery(ctx, cmd);
  205. }
  206. ///// <summary>
  207. ///// 获取当前时间
  208. ///// </summary>
  209. //internal DateTime GetNow(Database ctx)
  210. //{
  211. // object obj = (DateTime)SqlDataAccess.ExecuteScalar(ctx, CommandType.Text, "select GETDATE()");
  212. // if (obj != null)
  213. // return Convert.ToDateTime(obj.ToString());
  214. // else
  215. // return DateTime.Now;
  216. //}
  217. //获取性别,转化
  218. public string GetSex(string value)
  219. {
  220. string sex = "0";
  221. switch (value)
  222. {
  223. case "F":
  224. sex = "1";//男
  225. break;
  226. case "男":
  227. sex = "1";//男
  228. break;
  229. case "M":
  230. sex = "2";//女
  231. break;
  232. case "女":
  233. sex = "2";//女
  234. break;
  235. default:
  236. sex = "9";//不定
  237. break;
  238. }
  239. return sex;
  240. }
  241. public string GetYsdj(string hiscodeid)
  242. {
  243. var sql = "SELECT CodeID FROM HealthCare.dbo.V_UserLevel WHERE HisCodeID=@HisCodeID";
  244. var cmd = SqlDataAccess.GetSqlStringCommand(ctx, sql);
  245. SqlDataAccess.AddInParameter(ctx, cmd, "HisCodeID", DbType.AnsiString, hiscodeid);
  246. string codeid = StrHelepr.Obj2StrTrim(SqlDataAccess.DBExecuteScalar(ctx, cmd));
  247. if (codeid != null)
  248. {
  249. return codeid;
  250. }
  251. else
  252. {
  253. throw new Exception("V_UserLevel没有找到对应的医生等级");
  254. }
  255. }
  256. public string GetEmpType(string value)
  257. {
  258. string emptype = "";
  259. switch (value) // 员工分类
  260. {
  261. case "1"://1 医生
  262. emptype = "1";
  263. break;
  264. case "2"://2 护士
  265. emptype = "2";
  266. break;
  267. case "3"://3 财务人员
  268. emptype = "3";
  269. break;
  270. case "4"://4 药剂人员
  271. emptype = "4";
  272. break;
  273. case "5"://5 技师(检验)
  274. emptype = "5";
  275. break;
  276. case "6"://6 技师(影像)
  277. emptype = "6";
  278. break;
  279. case "7"://7 管理人员
  280. emptype = "7";
  281. break;
  282. case "8"://8 其他卫生技术人员
  283. emptype = "8";
  284. break;
  285. case "9"://9 其他人员
  286. emptype = "9";
  287. break;
  288. }
  289. return emptype;
  290. }
  291. }
  292. }
  293. #region 此为老版本代码
  294. /*
  295. Employee Module_Employee = new Employee();
  296. strMsgType = pmuB01.EVN.EventTypeCode.Value;
  297. #region STG
  298. STF stf = pmuB01.STF;
  299. Module_Employee.EmpNo = Convert.ToInt16(stf.PrimaryKeyValueSTF.Identifier.Value);// 员工代号
  300. Module_Employee.EmpCode = stf.GetStaffIDCode(0).ID.Value;// 员工代码
  301. Module_Employee.EmpName = stf.GetStaffName(0).GivenName.Value;// 姓名
  302. Module_Employee.EngName = stf.GetStaffName(0).GivenName.Value;// 英文姓名
  303. Module_Employee.IdNo = stf.DriverSLicenseNumberStaff.DriverSLicenseNumber.Value.Trim() ;// 身份证号 <<<<<<<<<<<<<<<<<<<<<< 目前ISNULL
  304. #region 性别转换
  305. // 1:男 2:女
  306. Module_Employee.Sex = His.MediIITransfer.MediII2Ue.GetSex(stf.AdministrativeSex.Value);
  307. #endregion
  308. Module_Employee.Birthday = His.Time.TryParseExact(stf.DateTimeOfBirth.TimeOfAnEvent.Value, "yyyyMMddhhmmss");
  309. #region 婚姻状况
  310. // 婚姻状况 (0:未婚,1:已婚,2:离婚)
  311. switch (stf.MaritalStatus.Text.Value)
  312. {
  313. case "S"://S 独身
  314. case "P"://P 同性恋
  315. case "G"://G 同居
  316. case "B"://B 未婚
  317. case "U"://U 未知
  318. case "O"://O 其他
  319. case "T"://T 未报告
  320. Module_Employee.MaritalStatus = "0";
  321. break;
  322. case "M"://M 结婚
  323. case "A": //A 分居
  324. case "W"://W 丧偶
  325. case "R"://R 已登记同性恋
  326. case "E"://E 合法分居
  327. // case "C"://C 普通法律
  328. case "I"://I 诉讼中
  329. Module_Employee.MaritalStatus = "1";
  330. break;
  331. case "D"://D 离婚
  332. Module_Employee.MaritalStatus = "2";
  333. break;
  334. default:
  335. Module_Employee.MaritalStatus = "0";
  336. break;
  337. }
  338. #endregion
  339. Module_Employee.HomeAdrArea = 0;// 住处区域代码 <<<<<<<<<<<<<<<<<<<<<<<<<<<
  340. Module_Employee.HomeAdrDesc = stf.GetOfficeHomeAddress(0).StreetAddress.StreetOrMailingAddress.Value;// 住处地址
  341. Module_Employee.HomeTel1 = stf.GetPhone(0).PhoneNumber.Value;// 住处电话1
  342. Module_Employee.HomeTel2 = "0"; // 住处电话2(不同步)
  343. Module_Employee.MobilePhone = stf.GetPhone(0).PhoneNumber.Value; // 移动电话
  344. Module_Employee.NativeAdrArea = 0;// 户籍区域代码(不同步)
  345. Module_Employee.NativeAdrDesc = "";// 户籍地址(不同步)
  346. Module_Employee.NativeTel = "";// 户籍电话(不同步)
  347. Module_Employee.ConName = "";// 联系人姓名(不同步)
  348. Module_Employee.ConTel1 = "";// 络人电话(不同步)
  349. Module_Employee.ConTel2 = "";// 络人电话(不同步)
  350. Module_Employee.ConAdrArea = 0;// 联系人区域代码(不同步)
  351. Module_Employee.ConAdrDesc = "";// 联系人地址(不同步)
  352. Module_Employee.Affiliation = "";// 与联系人关系(不同步)
  353. try
  354. {
  355. string sHireDate =stf.GetInstitutionActivationDate(0).Date.TimeOfAnEvent.Value;
  356. DateTime dtHireDate = His.Time.TryParseExact(sHireDate, "yyyyMMddhhmmss");
  357. Module_Employee.HireDate = dtHireDate == His.Time.MaxDateTime ? Convert.ToDateTime("1911-01-01 00:00:00") : dtHireDate; // 到职日期
  358. }
  359. catch
  360. {
  361. Module_Employee.HireDate = Convert.ToDateTime("1911-01-01 00:00:00");
  362. }
  363. Module_Employee.Zone = "A";// 归属院区(联众会开栏位**********)<<<<<<<<<<<<<<<<<<<<<<
  364. string tmp = stf.GetDepartment(0).Identifier.Value;
  365. try
  366. {
  367. string sDepartNo = His.MediIITransfer.MediII2Ue.GetDepartNo(stf.GetDepartment(0).Identifier.Value);
  368. Module_Employee.DepartNo = Convert.ToInt16(sDepartNo);// 部门代码
  369. }
  370. catch (Exception ex)
  371. {
  372. Module_Employee.DepartNo = -1;
  373. }
  374. Module_Employee.EmpType = stf.GetStaffType(0).Value;
  375. #region 员工分类
  376. switch (stf.GetStaffType(0).Value) // 员工分类
  377. {
  378. case "1"://1 医生
  379. Module_Employee.EmpType = "1";
  380. break;
  381. case "2"://2 护士
  382. Module_Employee.EmpType = "2";
  383. break;
  384. case "3"://3 财务人员
  385. Module_Employee.EmpType = "3";
  386. break;
  387. case "4"://4 药剂人员
  388. Module_Employee.EmpType = "4";
  389. break;
  390. case "5"://5 技师(检验)
  391. case "6"://6 技师(影像)
  392. case "7"://7 管理人员
  393. case "8"://8 其他卫生技术人员
  394. case "9"://9 其他人员
  395. Module_Employee.EmpType = "0";
  396. break;
  397. }
  398. #endregion
  399. string tmp2 = stf.JobCodeClass.JobCode.Value;
  400. try
  401. {
  402. Module_Employee.Title = Convert.ToInt16(stf.JobCodeClass.JobCode.Value);// 职称
  403. }
  404. catch (Exception ex)
  405. {
  406. Module_Employee.Title = -1;
  407. }
  408. Module_Employee.ChiefNo = Convert.ToInt16(stf.GetHospitalService(0).Identifier.Value);// 职位
  409. string tmp3 = stf.GetDepartment(0).Identifier.Value;
  410. try
  411. {
  412. string sWorkDepartNo = His.MediIITransfer.MediII2Ue.GetDepartNo(stf.GetDepartment(0).Identifier.Value);
  413. Module_Employee.WorkDepartNo = Convert.ToInt16(sWorkDepartNo);// 工作单位代号 <<<<<<<<<<<<<
  414. }
  415. catch
  416. {
  417. Module_Employee.WorkDepartNo = -1;
  418. }
  419. Module_Employee.SimpleTel = stf.GetPhone(0).PhoneNumber.Value;// 速拨码
  420. Module_Employee.SubTel = stf.GetPhone(0).PhoneNumber.Value;// 分机
  421. string sPassword = stf.GetBackupPersonID(0).Identifier.Value;
  422. Module_Employee.Password = sPassword == null ? "" : sPassword;
  423. Module_Employee.PasswordTime = DateTime.Now; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  424. Module_Employee.PressCard = 0;// 工作卡号(暫時不填)
  425. string sActiveInactiveFlag = stf.ActiveInactiveFlag.Value; // A,在职;I,离职
  426. Module_Employee.ResignDate = sActiveInactiveFlag == "A" ? His.Time.MaxDateTime : His.Time.MaxDateTime;
  427. int iIntParse;
  428. int.TryParse(stf.PreferredMethodOfContact.Identifier.Value, out iIntParse);
  429. if (iIntParse != 0)
  430. {
  431. Module_Employee.UpdateUser = Convert.ToInt16(iIntParse);// 最后修改人
  432. }
  433. Module_Employee.UpdateTime = DateTime.Now;
  434. Module_Employee.EMail = "";// 电子信箱(不同步)
  435. Module_Employee.Remark = "";// 备注说明(不同步)
  436. Module_Employee.Team = 0;// 组别
  437. #endregion
  438. #region 測試
  439. string sErrMsg;
  440. if (string.IsNullOrEmpty(Module_Employee.IdNo))
  441. {
  442. sErrMsg = "【身份证】无法为空";
  443. SetACK(m, "ACK", strMsgType, "ACK", sErrMsg);
  444. }
  445. if (string.IsNullOrEmpty(Module_Employee.HomeAdrDesc))
  446. {
  447. Module_Employee.HomeAdrDesc = "";
  448. }
  449. if (string.IsNullOrEmpty(Module_Employee.HomeTel1))
  450. {
  451. Module_Employee.HomeTel1 = "";
  452. }
  453. if (string.IsNullOrEmpty(Module_Employee.HomeTel1))
  454. {
  455. Module_Employee.HomeTel1 = ""; // 住处电话1
  456. }
  457. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  458. {
  459. Module_Employee.MobilePhone = ""; // 移动电话1
  460. }
  461. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  462. {
  463. Module_Employee.MobilePhone = ""; // 移动电话1
  464. }
  465. //Module_Employee.HireDate = His.Time.TryParseExact(sHireDate, "yyyyMMdd"); // 到职日期
  466. //Module_Employee.Title = Convert.ToInt16(stf.JobCodeClass.JobCode.Value);// 职称
  467. //Module_Employee.ChiefNo = Convert.ToInt16(stf.GetHospitalService(0).Identifier.Value);// 职位
  468. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  469. {
  470. Module_Employee.SimpleTel = "";// 速拨码
  471. }
  472. if (string.IsNullOrEmpty(Module_Employee.MobilePhone))
  473. {
  474. Module_Employee.SubTel = "";// 分机
  475. }
  476. if (string.IsNullOrEmpty(Module_Employee.Password))
  477. {
  478. sErrMsg = "【密碼】无法为空";
  479. SetACK(m, "ACK", strMsgType, "ACK", sErrMsg);
  480. }
  481. //if (Module_Employee.HireDate == DateTime.MinValue)
  482. //{
  483. // Module_Employee.HireDate = His.Time.MaxDateTime;
  484. //}
  485. if (Module_Employee.PasswordTime == DateTime.MinValue)
  486. {
  487. Module_Employee.PasswordTime = His.Time.MaxDateTime;
  488. }
  489. if (Module_Employee.UpdateTime == DateTime.MinValue)
  490. {
  491. Module_Employee.UpdateTime = His.Time.MaxDateTime;
  492. }
  493. if (Module_Employee.ResignDate == DateTime.MinValue)
  494. {
  495. Module_Employee.ResignDate = His.Time.MaxDateTime;
  496. }
  497. //Module_Employee.ResignDate = His.Time.TryParseExact(sResignDate, "yyyyMMdd"); // 离职日期
  498. #endregion
  499. // 開始存入資料庫
  500. int iEmpNo = Convert.ToInt16(stf.PrimaryKeyValueSTF.Identifier.Value);// 员工代号
  501. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
  502. {
  503. switch (strMsgType)
  504. {
  505. case Insert:
  506. case Update:
  507. EmployeeDelete(iEmpNo, ref HealthCareContainer, scope, ref Module_Employee);
  508. EmployeeInsert(iEmpNo, ref HealthCareContainer, scope, ref Module_Employee);
  509. break;
  510. case Delete:
  511. EmployeeDelete(iEmpNo, ref HealthCareContainer, scope, ref Module_Employee);
  512. break;
  513. }
  514. #region 存入資料庫
  515. try
  516. {
  517. HealthCareContainer.SaveChanges();
  518. }
  519. catch (System.Data.Entity.Validation.DbEntityValidationException ex)
  520. {
  521. scope.Dispose();
  522. throw ex;
  523. }
  524. #endregion
  525. scope.Complete();
  526. }
  527. */
  528. // return string.Empty;
  529. // }
  530. // catch (Exception ex)
  531. // {
  532. // string errMsg = string.Empty;
  533. // if (ex.InnerException == null)
  534. // {
  535. // errMsg = ex.Message + "\r\n" + ex.StackTrace;
  536. // }
  537. // else
  538. // {
  539. // errMsg = ex.Message + "\r\n" + ex.InnerException.Message + "\r\n" + ex.InnerException.StackTrace;
  540. // }
  541. // return errMsg;
  542. // }
  543. //}
  544. // catch (System.Data.Entity.Validation.DbEntityValidationException ex)
  545. //{
  546. //var tmp = ex.EntityValidationErrors.FirstOrDefault().ValidationErrors;
  547. //string errString = "";
  548. //foreach (var item in tmp)
  549. //{
  550. // errString += item.ErrorMessage;
  551. //}
  552. //string ack = SetACK(m, "ACK", mType, "ACK", ex.EntityValidationErrors.ToString());
  553. //throw new Exception(string.Format("{0}\r\n{1}", ex.EntityValidationErrors.ToString()));
  554. //return ex.Message;
  555. //}
  556. //}
  557. /*
  558. public void EmployeeInsert(int iEmpNo, ref HealthCareContainer HealthCareContainer, TransactionScope scope, ref Employee Module_Employee)
  559. {
  560. try
  561. {
  562. HealthCareContainer.Employee.Add(Module_Employee);
  563. }
  564. catch (Exception ex)
  565. {
  566. scope.Dispose();
  567. throw ex;
  568. }
  569. }
  570. public void EmployeeDelete(int iEmpNo, ref HealthCareContainer HealthCareContainer, TransactionScope scope, ref Employee Module_Employee)
  571. {
  572. try
  573. {
  574. IEnumerable<Employee> EmployeeList = HealthCareContainer.Employee.Where(x => x.EmpNo == iEmpNo);
  575. if (EmployeeList.Count() != 0)
  576. {
  577. Employee Module_Employee_Del = EmployeeList.FirstOrDefault();
  578. HealthCareContainer.Employee.Remove(Module_Employee_Del);
  579. HealthCareContainer.SaveChanges();
  580. }
  581. }
  582. catch (Exception ex)
  583. {
  584. scope.Dispose();
  585. throw ex;
  586. }
  587. }
  588. */
  589. // }
  590. //}
  591. #endregion