VmInsurancePolicyEditor.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. 
  2. ///////////////////////////////////////////////////////////////////////////////
  3. //文件名称: VmInsurancePolicyEditor.cs
  4. //文件描述: 保险单编辑
  5. //创 建 者: xls
  6. //创建日期: 2018/5/24 22:01:48
  7. //版 本 号:1.0.0.0
  8. ////////////////////////////////////////////////////////////////////////////////
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Collections.ObjectModel;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Windows;
  15. using CEFSharpWpf;
  16. using Com.FirmLib.Bll;
  17. using Com.FirmLib.Entity;
  18. using Com.FirmLib.UI.BllCommon;
  19. using Com.FirmLib.UI.Common.Model;
  20. using Com.FirmLib.UI.Insuer.Model;
  21. using FirmHttpDao;
  22. using FWindSoft.Data;
  23. using FWindSoft.DataFramework;
  24. using FWindSoft.MVVM;
  25. using FWindSoft.Wpf;
  26. using FWindSoft.Wpf.Common;
  27. using FWindSoft.Wpf.Controls;
  28. using Microsoft.Win32;
  29. namespace Com.FirmLib.UI.Insuer
  30. {
  31. /*
  32. * 两种入口
  33. * 1、没有项目信息的,直接创建
  34. * 2、带有项目信息的,项目信息不能改变
  35. */
  36. public class VmInsurancePolicyEditor : BaseViewModel
  37. {
  38. #region 初始化
  39. public VmInsurancePolicyEditor()
  40. {
  41. Init();
  42. }
  43. private void Init()
  44. {
  45. AssetItems = new ObservableCollection<AssetShowItem>();
  46. PolicyFile = new FileItem();
  47. ContactItem = new ContactInformationItem();
  48. PolicyEndDate = DateTimeManager.ConvertDateTime(DateTime.Now);
  49. }
  50. public void Init(LoadParameter parameter)
  51. {
  52. var param = parameter.Parameter as InsuerParameter;
  53. if (param == null)
  54. return;
  55. InsuerId = param.Insuer.Id;
  56. #region 控制条件初始化
  57. ProjectFixed = !string.IsNullOrEmpty(param.Project.Id);
  58. if (ProjectFixed)
  59. {
  60. ProjectNo =ProjectIdManager.GetForeSystemProjectId(param.Project.Id); ;
  61. }
  62. PolicyFixed = !string.IsNullOrEmpty(param.Policy.Id);
  63. if (PolicyFixed)
  64. {
  65. PolicyNo = param.Policy.Id;
  66. if (!string.IsNullOrEmpty(PolicyEndDate))
  67. {
  68. var now=DateTimeManager.ConvertDateTime(DateTime.Now);
  69. if (now.CompareTo(PolicyEndDate)>0)
  70. {
  71. IsEpire = true;
  72. }
  73. }
  74. }
  75. #endregion
  76. //如果上面的值有自然会加载资产信息
  77. //LoadAssetItems();
  78. }
  79. #endregion
  80. #region 属性相关
  81. /// <summary>
  82. /// 保险商Id
  83. /// </summary>
  84. public string InsuerId { get; private set; }
  85. #region 入口控制信息
  86. private bool m_ProjectFixed;
  87. /// <summary>
  88. /// 项目是否固定【编辑进入入口】
  89. /// </summary>
  90. public bool ProjectFixed
  91. {
  92. get { return this.m_ProjectFixed; }
  93. set
  94. {
  95. this.m_ProjectFixed = value;
  96. RaisePropertyChanged(nameof(this.ProjectFixed));
  97. }
  98. }
  99. private bool m_PolicyFixed;
  100. /// <summary>
  101. /// 保单是否固定
  102. /// </summary>
  103. public bool PolicyFixed
  104. {
  105. get { return this.m_PolicyFixed; }
  106. set
  107. {
  108. this.m_PolicyFixed = value;
  109. RaisePropertyChanged(nameof(this.PolicyFixed));
  110. }
  111. }
  112. private bool m_IsEpire;
  113. /// <summary>
  114. /// 保单是否过期
  115. /// </summary>
  116. public bool IsEpire
  117. {
  118. get { return this.m_IsEpire; }
  119. set
  120. {
  121. this.m_IsEpire = value;
  122. RaisePropertyChanged(() => this.IsEpire);
  123. }
  124. }
  125. #endregion
  126. #region 保单信息
  127. /// <summary>
  128. /// 是否是可用的ValidatePolicy
  129. /// </summary>
  130. public bool ValidatePolicy { get; set; }
  131. private string m_PolicyNo;
  132. /// <summary>
  133. /// 保单编号
  134. /// </summary>
  135. public string PolicyNo
  136. {
  137. get { return this.m_PolicyNo; }
  138. set
  139. {
  140. this.m_PolicyNo = value;
  141. if (!IsInEditing)
  142. {
  143. LoadPolicyByNo(SystemProjectId, value);
  144. LoadAssetItems();
  145. }
  146. RaisePropertyChanged(() => this.PolicyNo);
  147. }
  148. }
  149. private string m_PolicyEndDate;
  150. /// <summary>
  151. /// 保单截止日期
  152. /// </summary>
  153. public string PolicyEndDate
  154. {
  155. get { return this.m_PolicyEndDate; }
  156. set
  157. {
  158. this.m_PolicyEndDate = value;
  159. RaisePropertyChanged(() => this.PolicyEndDate);
  160. }
  161. }
  162. private FileItem m_PolicyFile;
  163. /// <summary>
  164. /// 保险文件
  165. /// </summary>
  166. public FileItem PolicyFile
  167. {
  168. get { return this.m_PolicyFile; }
  169. set
  170. {
  171. this.m_PolicyFile = value;
  172. RaisePropertyChanged(() => this.PolicyFile);
  173. }
  174. }
  175. /// <summary>
  176. /// 有效的项目编号
  177. /// </summary>
  178. public bool ValidateProject { get; set; }
  179. #endregion
  180. #region 项目相关信息
  181. private string m_ProjectNo;
  182. /// <summary>
  183. /// 项目编号
  184. /// </summary>
  185. public string ProjectNo
  186. {
  187. get { return this.m_ProjectNo; }
  188. set
  189. {
  190. this.m_ProjectNo = value;
  191. if (!IsInEditing)
  192. {
  193. LoadProjectById(SystemProjectId);
  194. LoadPolicyByNo(SystemProjectId, PolicyNo);
  195. LoadAssetItems();
  196. }
  197. RaisePropertyChanged(() => this.ProjectNo);
  198. }
  199. }
  200. /// <summary>
  201. /// 系统项目Id
  202. /// </summary>
  203. public string SystemProjectId
  204. {
  205. get { return ProjectIdManager.GetSystemProjectId(ProjectNo); }
  206. }
  207. private string m_LocalProjectName;
  208. /// <summary>
  209. /// 本地项目名称
  210. /// </summary>
  211. public string LocalProjectName
  212. {
  213. get { return this.m_LocalProjectName; }
  214. set
  215. {
  216. this.m_LocalProjectName = value;
  217. RaisePropertyChanged(() => this.LocalProjectName);
  218. }
  219. }
  220. #endregion
  221. #region 联系人信息
  222. private ContactInformationItem m_ContactItem;
  223. /// <summary>
  224. /// 联系人信息
  225. /// </summary>
  226. public ContactInformationItem ContactItem
  227. {
  228. get { return this.m_ContactItem; }
  229. set
  230. {
  231. this.m_ContactItem = value;
  232. RaisePropertyChanged(() => this.m_ContactItem);
  233. }
  234. }
  235. #endregion
  236. #region 资产信息
  237. private ObservableCollection<AssetShowItem> m_AssetItems;
  238. /// <summary>
  239. /// 保单资产信息
  240. /// </summary>
  241. public ObservableCollection<AssetShowItem> AssetItems
  242. {
  243. get { return this.m_AssetItems; }
  244. set
  245. {
  246. this.m_AssetItems = value;
  247. RaisePropertyChanged(() => this.AssetItems);
  248. }
  249. }
  250. #endregion
  251. #endregion
  252. #region 命令相关
  253. /// <summary>
  254. /// 上传文件
  255. /// </summary>
  256. /// <param name="parameter"></param>
  257. [Command]
  258. public void UploadCommand(object parameter)
  259. {
  260. try
  261. {
  262. OpenFileDialog ofd = new OpenFileDialog();
  263. ofd.Filter = "pdf文件|*.pdf";
  264. if (ofd.ShowDialog() == true)
  265. {
  266. string fileName = ofd.FileName;
  267. PolicyFile.Name = Path.GetFileName(fileName);
  268. PolicyFile.Path = fileName;
  269. }
  270. }
  271. catch (Exception e)
  272. {
  273. MessageTipEx.Show(this.GetWindow(), e);
  274. }
  275. }
  276. public bool CanUploadCommand(object parameter)
  277. {
  278. return true;
  279. }
  280. /// <summary>
  281. /// 查看资产详情
  282. /// </summary>
  283. /// <param name="parameter"></param>
  284. [Command]
  285. public void ScanAsset(object parameter)
  286. {
  287. try
  288. {
  289. AssetShowItem item = parameter as AssetShowItem;
  290. if (item == null)
  291. return;
  292. AssetItem parItem = new AssetItem();
  293. parItem.Id = item.Id;
  294. parItem.ProjectId = item.ProjectId;
  295. parItem.FamilyCode = item.FamilyCode;
  296. string url = BllFactory<AssetBll>.Instance.GetAssetUrl(parItem);
  297. WinBrowser.Instance.Show(url, "资产信息");
  298. }
  299. catch (Exception ex)
  300. {
  301. MessageTipEx.Show(ex);
  302. }
  303. }
  304. public bool CanScanAsset(object parameter)
  305. {
  306. return true;
  307. }
  308. /// <summary>
  309. /// 保存按钮
  310. /// </summary>
  311. /// <param name="parameter"></param>
  312. [Command]
  313. public void SaveCommand(object parameter)
  314. {
  315. //CreatePolicyAsset();
  316. //return;
  317. try
  318. {
  319. if (CreatePolicyInfo() && CreateLinkInfo()&&CreatePolicyAsset())
  320. {
  321. AfterSuccessSave();
  322. MessageTip.Show(this.GetWindow(), "保存成功");
  323. }
  324. else
  325. {
  326. MessageTip.Show(this.GetWindow(), "保存失败");
  327. }
  328. }
  329. catch (Exception e)
  330. {
  331. MessageTipEx.Show(this.GetWindow(), e);
  332. }
  333. }
  334. public bool CanSaveCommand(object parameter)
  335. {
  336. return IsValidated&&ValidateProject;
  337. }
  338. /// <summary>
  339. /// 选择保单号
  340. /// </summary>
  341. /// <param name="parameter"></param>
  342. [Command]
  343. public void SelectPolicyCommand(object parameter)
  344. {
  345. //传入当前输入的保单号,为显示默认值
  346. //如果项目为空,可以不弹窗
  347. try
  348. {
  349. WinPolicySelector win = new WinPolicySelector();
  350. InsuerParameter insuerParameter = new InsuerParameter();
  351. insuerParameter.Insuer.Id = InsuerId;
  352. insuerParameter.Project.Id = SystemProjectId;
  353. insuerParameter.Policy.Id = PolicyNo;
  354. LoadParameter.StartParameter(win, new LoadParameter(insuerParameter));
  355. win.Owner = this.GetWindow();
  356. if (win.ShowDialog() == true)
  357. {
  358. var tempPolicyNo = win.GetRealResult<string>();
  359. if (!string.IsNullOrEmpty(tempPolicyNo))
  360. {
  361. this.PolicyNo = tempPolicyNo;
  362. }
  363. }
  364. }
  365. catch (Exception ex)
  366. {
  367. MessageTipEx.Show(ex);
  368. }
  369. }
  370. public bool CanSelectPolicyCommand(object parameter)
  371. {
  372. return ValidateProject;
  373. }
  374. /// <summary>
  375. /// 选择资产信息
  376. /// </summary>
  377. /// <param name="parameter"></param>
  378. [Command]
  379. public void SelectAssetCommand(object parameter)
  380. {
  381. try
  382. {
  383. WinInsuerAssetSelector win = new WinInsuerAssetSelector();
  384. win.Owner = this.GetWindow();
  385. SelectAssetContext context = new SelectAssetContext();
  386. context.ProjectId = SystemProjectId;
  387. context.VenderId = InsuerId;
  388. context.ContainIds = new List<string>(AssetItems.Select(p => p.Id));
  389. LoadParameter.StartParameter(win, new LoadParameter(context));
  390. if (win.ShowDialog() == true)
  391. {
  392. if (AssetItems == null)
  393. {
  394. AssetItems = new ObservableCollection<AssetShowItem>();
  395. }
  396. var addRelations = context.AddedItems;
  397. foreach (var item in addRelations)
  398. {
  399. if (AssetItems.Any(c => c.Id == item.Id))
  400. return;
  401. AssetItems.Add(item);
  402. }
  403. }
  404. }
  405. catch (Exception ex)
  406. {
  407. MessageTipEx.Show(ex);
  408. }
  409. }
  410. public bool CanSelectAssetCommand(object parameter)
  411. {
  412. return ValidateProject;
  413. }
  414. /// <summary>
  415. /// 删除在保资产
  416. /// </summary>
  417. /// <param name="parameter"></param>
  418. [Command]
  419. public void DeleteCommand(object parameter)
  420. {
  421. try
  422. {
  423. AssetShowItem showItem = parameter as AssetShowItem;
  424. if (showItem == null)
  425. return;
  426. //todo 删除资产关联关系,是直接删除,不需要保存确定
  427. var result = MessageTip.Show(this.GetWindow(), "是否要删除", "提示", MessageBoxButton.YesNo);
  428. if (result == MessageBoxResult.Yes)
  429. {
  430. bool flag = false;
  431. if (showItem.InsuerId == InsuerId && showItem.InsurancePolicyNo == PolicyNo)
  432. {
  433. flag = AssetManager.DeleteInsuerAssets(SystemProjectId, new List<string>() { showItem.Id });
  434. }
  435. else
  436. {
  437. flag = true;
  438. }
  439. if (flag)
  440. {
  441. this.AssetItems.Remove(showItem);
  442. }
  443. else
  444. {
  445. MessageTip.Show(this.GetWindow(), "删除失败");
  446. }
  447. }
  448. }
  449. catch (Exception ex)
  450. {
  451. MessageTipEx.Show(ex);
  452. }
  453. }
  454. public bool CanDeleteCommand(object parameter)
  455. {
  456. return true;
  457. }
  458. #endregion
  459. #region 私有方法
  460. /// <summary>
  461. /// 加载资产信息
  462. /// </summary>
  463. private void LoadAssetItems()
  464. {
  465. AssetItems = new ObservableCollection<AssetShowItem>();
  466. if (!ValidateProject ||!ValidatePolicy)
  467. return;
  468. LoadAssetItems(InsuerId, SystemProjectId, PolicyNo);
  469. }
  470. /// <summary>
  471. /// 加载资产信息
  472. /// </summary>
  473. /// <param name="venderId"></param>
  474. /// <param name="projectId"></param>
  475. /// <param name="policyId"></param>
  476. private void LoadAssetItems(string venderId,string projectId,string policyId)
  477. {
  478. var dataItems = BllFactory<InsuerBll>.Instance.GetPolicyAssetItems(venderId, projectId, policyId);
  479. List<AssetShowItem> showItems = new List<AssetShowItem>();
  480. foreach (var dataItem in dataItems)
  481. {
  482. var showItem = new AssetShowItem();
  483. showItem.Id = dataItem.Id;
  484. showItem.ProjectId = SystemProjectId;
  485. showItem.FamilyCode = dataItem.Family;
  486. showItem.LocalName = dataItem.Asset.EquipLocalName;
  487. showItem.LocalCode = dataItem.Asset.EquipLocalId;
  488. showItem.Brand = dataItem.Asset.Brand;
  489. showItem.Product = dataItem.Asset.Product;
  490. showItem.Type = dataItem.Asset.Specification;
  491. showItems.Add(showItem);
  492. }
  493. AssetItems = new ObservableCollection<AssetShowItem>(showItems);
  494. }
  495. /// <summary>
  496. /// 创建联系人信息
  497. /// </summary>
  498. /// <returns></returns>
  499. private bool CreateLinkInfo()
  500. {
  501. LinkerItem item = new LinkerItem();
  502. item.VenderId = InsuerId;
  503. item.ProjectId = SystemProjectId;
  504. item.Name = ContactItem.People;
  505. item.Phone = ContactItem.Telephone;
  506. item.Fax = ContactItem.Fax;
  507. item.Email = ContactItem.Email;
  508. var result = BllFactory<InsuerBll>.Instance.UpdateLinker(item);
  509. if (!result)
  510. {
  511. MessageTip.Show(this.GetWindow(), BllFactory<InsuerBll>.Instance.ErrorMessage ?? string.Empty);
  512. }
  513. return result;
  514. }
  515. /// <summary>
  516. /// 创建保单信息
  517. /// </summary>
  518. /// <returns></returns>
  519. private bool CreatePolicyInfo()
  520. {
  521. InsuerContractItem item = new InsuerContractItem();
  522. item.ProjectId = SystemProjectId;
  523. item.VenderId = InsuerId;
  524. item.ExpireDate =DateTimeManager.ConvertDateTime(PolicyEndDate).ToString("yyyy-MM-dd");
  525. item.InsuranceNo = PolicyNo;
  526. item.InsuranceFile = GetFileKey();//获取相关编码
  527. bool result = false;
  528. var refVenderId = BllFactory<InsuerBll>.Instance.CheckInsuranceNo(PolicyNo);
  529. bool isExist = !string.IsNullOrEmpty(refVenderId);
  530. if (!isExist)
  531. {
  532. result = BllFactory<InsuerBll>.Instance.AddPolicy(item);
  533. }
  534. else
  535. {
  536. if (refVenderId != InsuerId)
  537. {
  538. MessageTip.Show(this.GetWindow(), $"该保单已被其他项目关联");
  539. return result;
  540. }
  541. result = BllFactory<InsuerBll>.Instance.UpdatePolicy(item);
  542. }
  543. if (!result)
  544. {
  545. MessageTip.Show(this.GetWindow(), BllFactory<InsuerBll>.Instance.ErrorMessage ?? string.Empty);
  546. }
  547. return result;
  548. }
  549. #region 相关信息加载
  550. /// <summary>
  551. /// 获取项目,通过项目编号
  552. /// </summary>
  553. /// <param name="projectId"></param>
  554. private void LoadProjectById(string projectId)
  555. {
  556. ProjectItem item = null;
  557. try
  558. {
  559. ValidateProject = false;
  560. if (string.IsNullOrEmpty(projectId))
  561. return;
  562. item = BllFactory<ProjectBll>.Instance.GetProjectItem(projectId);
  563. ValidateProject = item != null;
  564. }
  565. finally
  566. {
  567. #region 修改
  568. if (ValidateProject)
  569. {
  570. LocalProjectName = item.Name;
  571. LoadLinkerItem(projectId, InsuerId);
  572. }
  573. else
  574. {
  575. LocalProjectName = string.Empty;
  576. }
  577. #endregion
  578. }
  579. }
  580. /// <summary>
  581. /// 通过保单编号加载保单信息
  582. /// </summary>
  583. /// <param name="projectId"></param>
  584. /// <param name="policyNo"></param>
  585. private void LoadPolicyByNo(string projectId,string policyNo)
  586. {
  587. InsuerContractItem item = null;
  588. string fileKey = string.Empty;
  589. try
  590. {
  591. ValidatePolicy = false;
  592. if (!ValidateProject|| string.IsNullOrEmpty(policyNo))
  593. return;
  594. item = BllFactory<InsuerBll>.Instance.GetPolicyItem(InsuerId, projectId, policyNo);
  595. ValidatePolicy = item != null;
  596. }
  597. finally
  598. {
  599. if (ValidatePolicy)
  600. {
  601. string timeStr=item.ExpireDate ?? string.Empty;
  602. this.PolicyEndDate = DateTimeManager.ConvertDateTimeH(timeStr).ToString("yyyyMMdd");
  603. fileKey = item.InsuranceFile;
  604. PolicyFile = FileUtils.ParseFileKey(fileKey);
  605. }
  606. else
  607. {
  608. PolicyFile = new FileItem();
  609. }
  610. }
  611. }
  612. #endregion
  613. #region 文件操作
  614. /// <summary>
  615. /// 获取文件键值
  616. /// </summary>
  617. /// <returns></returns>
  618. public string GetFileKey()
  619. {
  620. #region 上传文件
  621. string fileKey =FileUtils.GetUseKey(PolicyFile, InsuerId);
  622. if (string.IsNullOrEmpty(fileKey))
  623. {
  624. return fileKey;
  625. }
  626. if (!File.Exists(PolicyFile.Path))
  627. {
  628. return fileKey;
  629. }
  630. var bytes = File.ReadAllBytes(PolicyFile.Path);
  631. var flag = BllFactory<FileBll>.Instance.UploadFile(BllHttpSetting.Instance.Default, fileKey, bytes);
  632. if (!flag)
  633. {
  634. MessageTip.Show(this.GetWindow(), BllFactory<FileBll>.Instance.ErrorMessage ?? string.Empty);
  635. }
  636. #endregion
  637. return fileKey;
  638. }
  639. #endregion
  640. #endregion
  641. #region 联系人相关
  642. /// <summary>
  643. /// 查询联系人信息
  644. /// </summary>
  645. /// <param name="projectId"></param>
  646. /// <param name="venderId"></param>
  647. private void LoadLinkerItem(string projectId, string venderId)
  648. {
  649. if (string.IsNullOrEmpty(projectId) || string.IsNullOrEmpty(venderId))
  650. return;
  651. var linkerItem = BllFactory<InsuerBll>.Instance.GetLinker(venderId, projectId);
  652. if (linkerItem != null)
  653. {
  654. this.ContactItem.Telephone = linkerItem.Phone;
  655. this.ContactItem.People = linkerItem.Name;
  656. this.ContactItem.Fax = linkerItem.Fax;
  657. this.ContactItem.Email = linkerItem.Email;
  658. }
  659. }
  660. #endregion
  661. #region 保存资产相关
  662. private bool CreatePolicyAsset()
  663. {
  664. if (this.AssetItems == null || !this.AssetItems.Any())
  665. return true;
  666. //保单或保险商任意发生变化,都修改
  667. //判断当前保险单号,和item中的保险单号
  668. List<AssetShowItem> changedItems = new List<AssetShowItem>();
  669. foreach (var item in this.AssetItems)
  670. {
  671. item.CacheParameters.Clear();
  672. var parameters= GetChangeParameters(item);
  673. if (!parameters.IsEmpty)
  674. {
  675. item.CacheParameters.Merge(parameters);
  676. changedItems.Add(item);
  677. }
  678. }
  679. //关掉也不影响保存流程
  680. if (changedItems.Any())
  681. {
  682. AssetSaveContext context = new AssetSaveContext();
  683. context.ChangedItems = changedItems;
  684. WinPolicySaveEnsure win = new WinPolicySaveEnsure();
  685. win.Owner = this.GetWindow();
  686. LoadParameter.StartParameter(win, new LoadParameter(context));
  687. if (win.ShowDialog() == true)
  688. {
  689. context = win.GetRealResult<AssetSaveContext>();
  690. if (context != null)
  691. {
  692. var items = context.ChangedItems ?? new List<AssetShowItem>();
  693. foreach (var item in items)
  694. {
  695. if (context.EditType == EditType.Correct)
  696. {
  697. item.CacheParameters.SetAllParameterTime(context.EffectiveTime);
  698. }
  699. }
  700. }
  701. }
  702. }
  703. #region 修改厂商,保单号发生变化的资产
  704. AssetItems.ToList().ForEach(assetItem =>
  705. {
  706. assetItem.InsuerId = InsuerId;
  707. assetItem.InsurancePolicyNo = PolicyNo;
  708. assetItem.CacheParameters.CheckAdd((new WatchParameter(MBIBuiltInParameter.DPInsuerID)));
  709. assetItem.CacheParameters.CheckAdd((new WatchParameter(MBIBuiltInParameter.InsuranceNum)));
  710. });
  711. bool flag = AssetManager.UpdateAssetItems(SystemProjectId, AssetItems.ToList());
  712. #endregion
  713. return flag;
  714. }
  715. /// <summary>
  716. /// 初始化变化参数
  717. /// </summary>
  718. /// <param name="item"></param>
  719. private WatchParameters GetChangeParameters(AssetShowItem item)
  720. {
  721. WatchParameters parameters = new WatchParameters();
  722. if (!string.IsNullOrEmpty(item.InsuerId)&&item.InsuerId!=InsuerId)
  723. {
  724. parameters.Add(new WatchParameter(MBIBuiltInParameter.DPInsuerID));
  725. }
  726. if (!string.IsNullOrEmpty(item.InsurancePolicyNo)&&item.InsurancePolicyNo!=PolicyNo)
  727. {
  728. parameters.Add(new WatchParameter(MBIBuiltInParameter.InsuranceNum));
  729. }
  730. return parameters;
  731. }
  732. #endregion
  733. /// <summary>
  734. /// 成功保存后处理
  735. /// </summary>
  736. private void AfterSuccessSave()
  737. {
  738. ProjectManager.SyncInsuerProject(SystemProjectId, InsuerId);
  739. LoadAssetItems(InsuerId, SystemProjectId, PolicyNo);
  740. if (this.GetNavigationBar() is NavigationBar bar)
  741. {
  742. bar.RefreshPreWinddow();
  743. }
  744. }
  745. }
  746. }