IPEasyUtility.cs 29 KB

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