IPEasyUtility.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. using System;
  2. using System.Data;
  3. using System.Diagnostics;
  4. using System.Dynamic;
  5. using System.IO;
  6. using System.Linq;
  7. using OpenQA.Selenium;
  8. using OpenQA.Selenium.Chrome;
  9. using OpenQA.Selenium.Support.Extensions;
  10. namespace wispro.sp.utility
  11. {
  12. public class IPEasyUtility
  13. {
  14. public static void DownloadReport(string strId,string filename)
  15. {
  16. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  17. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  18. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  19. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  20. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  21. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  22. options.AddUserProfilePreference("intl.accept_languages", "nl");
  23. options.AddUserProfilePreference("disable-popup-blocking", "true");
  24. if (isheadless)
  25. {
  26. options.AddArgument("headless");
  27. }
  28. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  29. {
  30. try
  31. {
  32. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
  33. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
  34. //进入登录界面
  35. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  36. //输入用户名和密码
  37. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  38. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  39. //点击登录按钮
  40. driver.FindElement(By.Id("btnLogin")).Click();
  41. //关闭提示遮罩层
  42. driver.FindElement(By.Id("jpwClose")).Click();
  43. //点击顶部菜单栏中的报表管理菜单
  44. driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
  45. //点击左侧 自定义报表 菜单
  46. driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
  47. //切换到自定义报表Frame
  48. driver.SwitchTo().Frame(1);
  49. //调用报表导出JS
  50. ((IJavaScriptExecutor)driver).ExecuteScript($"Report.Export('{strId}');");
  51. //切换到弹出的导出报表窗口,点击导出按钮
  52. driver.SwitchTo().DefaultContent();
  53. var ihg_export = driver.FindElement(By.Name("ihg_export"));
  54. driver.SwitchTo().Frame(ihg_export);
  55. driver.FindElement(By.Id("btnSubmit")).Click();
  56. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  57. while (true)
  58. {
  59. System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
  60. if (!file.Exists || file.Length == 0)
  61. {
  62. System.Threading.Thread.Sleep(5000);
  63. }
  64. else
  65. {
  66. break;
  67. }
  68. }
  69. }
  70. catch (Exception ex)
  71. {
  72. throw new Exception(ex.Message);
  73. }
  74. finally
  75. {
  76. driver.Quit();
  77. driver.Dispose();
  78. killChromProcess();
  79. }
  80. }
  81. }
  82. private static void Log(string strMessage)
  83. {
  84. StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
  85. sw.WriteLine($"{strMessage}");
  86. sw.Flush();
  87. sw.Close();
  88. sw.Dispose();
  89. }
  90. /// <summary>
  91. /// 根据报表名称导出报表
  92. /// </summary>
  93. /// <param name="ReportName">报告名称</param>
  94. /// <param name="isModifyDate">是否手动修改日期范围</param>
  95. public static DataTable DownloadReport(string ReportName,bool isModifyDate)
  96. {
  97. Log($"{DateTime.Now}\t开始下载:{ReportName}");
  98. DataTable retDatatable;
  99. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  100. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  101. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  102. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  103. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  104. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  105. options.AddUserProfilePreference("intl.accept_languages", "nl");
  106. options.AddUserProfilePreference("disable-popup-blocking", "true");
  107. if (isheadless)
  108. {
  109. options.AddArgument("headless");
  110. }
  111. Log($"{DateTime.Now}\t开始启动Chrome");
  112. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  113. {
  114. try
  115. {
  116. Log($"{DateTime.Now}\tIWebDriver配置");
  117. driver.Manage().Window.Maximize();
  118. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
  119. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
  120. //进入登录界面
  121. Log($"{DateTime.Now}\t开始进入登录界面");
  122. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  123. //输入用户名和密码
  124. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  125. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  126. //点击登录按钮
  127. Log($"{DateTime.Now}\t开始点击登录按钮");
  128. driver.FindElement(By.Id("btnLogin")).Click();
  129. //关闭提示遮罩层
  130. Log($"{DateTime.Now}\t关闭提示遮罩层");
  131. driver.FindElement(By.Id("jpwClose")).Click();
  132. //点击顶部菜单栏中的报表管理菜单
  133. Log($"{DateTime.Now}\t点击顶部菜单栏中的报表管理菜单");
  134. var reportMenu = driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9"));
  135. driver.ExecuteJavaScript("arguments[0].click();", reportMenu);
  136. //点击左侧 自定义报表 菜单
  137. Log($"{DateTime.Now}\t点击左侧 自定义报表 菜单");
  138. var customerReportMenu = driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b"));
  139. driver.ExecuteJavaScript("arguments[0].click();", customerReportMenu);
  140. //切换到自定义报表Frame
  141. Log($"{DateTime.Now}\t切换到自定义报表Frame");
  142. driver.SwitchTo().Frame(1);
  143. Log($"{DateTime.Now}\t开始搜索报告");
  144. var inputSearch = driver.FindElement(By.Id("customizedList_TxtSheetSearchKey"));
  145. Log($"{DateTime.Now}\t在搜索框中输入报告名称");
  146. inputSearch.SendKeys(ReportName);
  147. Log($"{DateTime.Now}\t点击搜索按钮");
  148. var btnSearch = driver.FindElement(By.ClassName("btn-search"));
  149. btnSearch.Click();
  150. Log($"{DateTime.Now}\t选中报告");
  151. var reportRecord = driver.FindElement(By.XPath($"//td[contains(text(),'{ReportName}')]"));
  152. reportRecord.Click();
  153. System.Threading.Thread.Sleep(1000);
  154. if (isModifyDate)
  155. {
  156. Log($"{DateTime.Now}\t输入报告时间");
  157. var btnEdit = driver.FindElement(By.ClassName("edit"));
  158. btnEdit.Click();
  159. System.Threading.Thread.Sleep(500);
  160. var doItemFinished = driver.FindElement(By.XPath("//span[contains(@objcvalue,'_date') and contains(@id,'ST;')]"));
  161. doItemFinished.Click();
  162. System.Threading.Thread.Sleep(500);
  163. var startDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_s_')]"));
  164. startDate.Click();
  165. System.Threading.Thread.Sleep(500);
  166. startDate.SendKeys(new DateTime(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month, 1).ToString("yyyy-MM-dd"));
  167. var endDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_e_')]"));//.Id("dt_e_4F8FE88D-9040-45F1-9723-45699BCD4CAF"));
  168. endDate.Click();
  169. System.Threading.Thread.Sleep(500);
  170. endDate.SendKeys(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1).ToString("yyyy-MM-dd"));
  171. var addDate = driver.FindElement(By.XPath("//a[contains(@onclick,'ReportSub.ConditionDTSelect')]"));
  172. addDate.Click();
  173. System.Threading.Thread.Sleep(500);
  174. var btnSave = driver.FindElement(By.Id("save"));
  175. btnSave.Click();
  176. System.Threading.Thread.Sleep(3000);
  177. }
  178. Log($"{DateTime.Now}\t点击导出Excel链接");
  179. var linkExport = driver.FindElement(By.XPath("//a[contains(@onclick,'-') and @class='tbexcel']"));
  180. linkExport.Click();
  181. //切换到弹出的导出报表窗口,点击导出按钮
  182. Log($"{DateTime.Now}\t切换到弹出的导出报表窗口,点击导出按钮");
  183. driver.SwitchTo().DefaultContent();
  184. var ihg_export = driver.FindElement(By.Name("ihg_export"));
  185. driver.SwitchTo().Frame(ihg_export);
  186. driver.FindElement(By.Id("btnSubmit")).Click();
  187. //切换到弹出的下载报表界面,点击下载按钮
  188. Log($"{DateTime.Now}\t切换到弹出的下载报表界面,点击下载按钮");
  189. System.Threading.Thread.Sleep(3000);
  190. driver.SwitchTo().DefaultContent();
  191. var frameDownload = driver.FindElement(By.Name("DownloadList"));
  192. driver.SwitchTo().Frame(frameDownload);
  193. var firstTr = driver.FindElement(By.TagName("tr"));
  194. var tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
  195. string strStatus = tdStatus.Text;
  196. while (strStatus.Trim() != "导出成功!")
  197. {
  198. System.Threading.Thread.Sleep(5000);
  199. firstTr = driver.FindElement(By.TagName("tr"));
  200. tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
  201. strStatus = tdStatus.Text;
  202. }
  203. Log($"{DateTime.Now}\t点击下载按钮下载文档");
  204. firstTr = driver.FindElement(By.TagName("tr"));
  205. firstTr.FindElement(By.XPath("//td/a[@title='下载']")).Click();
  206. //System.Threading.Thread.Sleep(5000);
  207. //btnDownload.Click();
  208. string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
  209. int iwaiting = 0;
  210. while (true)
  211. {
  212. System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
  213. if (!file.Exists || file.Length == 0)
  214. {
  215. System.Threading.Thread.Sleep(5000);
  216. iwaiting += 5000;
  217. if (iwaiting > 360000)
  218. {
  219. break;
  220. }
  221. }
  222. else
  223. {
  224. break;
  225. }
  226. }
  227. //删除下载记录
  228. Log($"{DateTime.Now}\t删除下载记录");
  229. firstTr = driver.FindElement(By.TagName("tr"));
  230. firstTr.FindElement(By.XPath("//td/a[@title='删除']")).Click();
  231. //System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
  232. retDatatable = NPOIExcel.ExcelToDataTable(strFilePath.Replace("~", "_"),true);
  233. System.IO.File.Delete(strFilePath.Replace("~", "_"));
  234. }
  235. catch (Exception ex)
  236. {
  237. Log(ex.ToString());
  238. throw new Exception(ex.Message, ex);
  239. }
  240. finally
  241. {
  242. Log("关闭Chrome");
  243. driver.Quit();
  244. driver.Dispose();
  245. killChromProcess();
  246. }
  247. }
  248. Log($"{DateTime.Now}\t返回数据");
  249. return retDatatable;
  250. }
  251. /// <summary>
  252. /// 获取案件基本信息
  253. /// </summary>
  254. /// <param name="caseNo">我方文号</param>
  255. /// <returns></returns>
  256. public static dynamic GetCaseInfo(string caseNo)
  257. {
  258. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  259. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  260. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  261. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  262. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  263. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  264. options.AddUserProfilePreference("intl.accept_languages", "nl");
  265. options.AddUserProfilePreference("disable-popup-blocking", "true");
  266. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  267. if (isheadless)
  268. {
  269. options.AddArgument("headless");
  270. }
  271. dynamic retObject = new ExpandoObject();
  272. retObject.CaseNo = caseNo;
  273. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  274. {
  275. try
  276. {
  277. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
  278. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  279. //进入登录界面
  280. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  281. //输入用户名和密码
  282. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  283. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  284. //点击登录按钮
  285. driver.FindElement(By.Id("btnLogin")).Click();
  286. //关闭提示遮罩层
  287. driver.FindElement(By.Id("jpwClose")).Click();
  288. //点击顶部菜单栏中的案件管理菜单
  289. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  290. //点击左侧 查询 菜单
  291. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  292. //切换到自定义报表Frame
  293. driver.SwitchTo().Frame(1);
  294. var inputSearch = driver.FindElement(By.Id("case_volume"));
  295. inputSearch.SendKeys(caseNo);
  296. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  297. btnSearch.Click();
  298. var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
  299. caseLink.Click();
  300. System.Threading.Thread.Sleep(500);
  301. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  302. driver.FindElement(By.Id("libase")).Click();
  303. retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
  304. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  305. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  306. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  307. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  308. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  309. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  310. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  311. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  312. //select[@id='p_case_info__case_coefficient_id']
  313. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  314. }
  315. catch (Exception ex)
  316. {
  317. throw new Exception(ex.Message, ex);
  318. }
  319. finally
  320. {
  321. driver.Quit();
  322. killChromProcess();
  323. }
  324. }
  325. return retObject;
  326. }
  327. /// <summary>
  328. /// 获取案件处理事项记录
  329. /// </summary>
  330. /// <param name="caseNo">我方文号</param>
  331. /// <param name="doItemName">处理事项</param>
  332. /// <returns></returns>
  333. public static dynamic GetPerformanceRecord(string caseNo,string doItemName,string caseStage=null)
  334. {
  335. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  336. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  337. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  338. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  339. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  340. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  341. options.AddUserProfilePreference("intl.accept_languages", "nl");
  342. options.AddUserProfilePreference("disable-popup-blocking", "true");
  343. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  344. if (isheadless)
  345. {
  346. options.AddArgument("headless");
  347. }
  348. dynamic retObject = new ExpandoObject();
  349. retObject.CaseNo = caseNo;
  350. retObject.DoItem = doItemName;
  351. using (var Service = ChromeDriverService.CreateDefaultService(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath")))
  352. {
  353. Service.Start();
  354. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(Service, options))
  355. {
  356. try
  357. {
  358. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
  359. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  360. //进入登录界面
  361. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  362. //输入用户名和密码
  363. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  364. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  365. //点击登录按钮
  366. driver.FindElement(By.Id("btnLogin")).Click();
  367. //关闭提示遮罩层
  368. driver.FindElement(By.Id("jpwClose")).Click();
  369. //点击顶部菜单栏中的案件管理菜单
  370. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  371. System.Threading.Thread.Sleep(500);
  372. //点击左侧 查询 菜单
  373. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  374. System.Threading.Thread.Sleep(500);
  375. //切换到自定义报表Frame
  376. driver.SwitchTo().Frame(1);
  377. var inputSearch = driver.FindElement(By.Id("case_volume"));
  378. inputSearch.SendKeys(caseNo);
  379. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  380. btnSearch.Click();
  381. System.Threading.Thread.Sleep(500);
  382. var caseLink = driver.FindElement(By.XPath($"//a[normalize-space()='{caseNo}']"));
  383. caseLink.Click();
  384. System.Threading.Thread.Sleep(500);
  385. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  386. var DoItemLinks = driver.FindElements(By.XPath($"//td[@colname='ctrl_proc'][normalize-space()='{doItemName}']"));
  387. if (DoItemLinks.Count > 0)
  388. {
  389. if (!string.IsNullOrEmpty(caseStage))
  390. {
  391. foreach (var DoItemLink in DoItemLinks)
  392. {
  393. var temCaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text;
  394. if (temCaseStage == caseStage)
  395. {
  396. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  397. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  398. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  399. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  400. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  401. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  402. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  403. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  404. DoItemLink.Click();
  405. break;
  406. }
  407. }
  408. }
  409. else
  410. {
  411. var DoItemLink = DoItemLinks[DoItemLinks.Count - 1];
  412. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  413. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  414. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  415. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  416. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  417. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  418. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  419. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  420. DoItemLink.Click();
  421. }
  422. }
  423. System.Threading.Thread.Sleep(500);
  424. retObject.FinalizationDate = driver.FindElement(By.Id("p_proc_info__finish_doc_date")).GetAttribute("value"); //定稿日
  425. retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
  426. retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
  427. retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
  428. retObject.WordCount = driver.FindElement(By.Id("p_proc_info__translate_count")).GetAttribute("value"); //翻译字数
  429. driver.FindElement(By.Id("libase")).Click();
  430. System.Threading.Thread.Sleep(500);
  431. retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
  432. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  433. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  434. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  435. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  436. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  437. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  438. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  439. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  440. //select[@id='p_case_info__case_coefficient_id']
  441. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  442. }
  443. catch (Exception ex)
  444. {
  445. throw new Exception(ex.Message, ex);
  446. }
  447. finally
  448. {
  449. driver.Quit();
  450. killChromProcess();
  451. }
  452. }
  453. Service.Dispose();
  454. }
  455. return retObject;
  456. }
  457. private static void killChromProcess()
  458. {
  459. try
  460. {
  461. Process[] workers = Process.GetProcessesByName("Chrome");
  462. foreach (Process worker in workers)
  463. {
  464. worker.Kill();
  465. worker.WaitForExit();
  466. worker.Dispose();
  467. }
  468. workers = Process.GetProcessesByName("Chromedriver");
  469. foreach (Process worker in workers)
  470. {
  471. worker.Kill();
  472. worker.WaitForExit();
  473. worker.Dispose();
  474. }
  475. }
  476. catch { }
  477. }
  478. private static string GetSelectText(IWebElement element)
  479. {
  480. var strValue = element.GetAttribute("value");
  481. if (string.IsNullOrEmpty(strValue))
  482. {
  483. return null;
  484. }
  485. var ops = element.FindElements(By.TagName("option"));
  486. foreach (var op in ops)
  487. {
  488. if (op.GetAttribute("value") == strValue)
  489. {
  490. return op.Text;
  491. }
  492. }
  493. return null;
  494. }
  495. }
  496. }