IPEasyUtility.cs 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Data;
  5. using System.Diagnostics;
  6. using System.Dynamic;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Threading;
  10. using OpenQA.Selenium;
  11. using OpenQA.Selenium.Chrome;
  12. using OpenQA.Selenium.Support.Extensions;
  13. using OpenQA.Selenium.Support.UI;
  14. namespace wispro.sp.utility
  15. {
  16. public class IPEasyUtility
  17. {
  18. public static void DownloadReport(string strId,string filename)
  19. {
  20. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  21. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  22. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  23. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  24. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  25. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  26. options.AddUserProfilePreference("intl.accept_languages", "nl");
  27. options.AddUserProfilePreference("disable-popup-blocking", "true");
  28. if (isheadless)
  29. {
  30. options.AddArgument("headless");
  31. }
  32. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  33. {
  34. try
  35. {
  36. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
  37. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
  38. //进入登录界面
  39. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  40. //输入用户名和密码
  41. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  42. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  43. //点击登录按钮
  44. driver.FindElement(By.Id("btnLogin")).Click();
  45. //关闭提示遮罩层
  46. driver.FindElement(By.Id("jpwClose")).Click();
  47. //点击顶部菜单栏中的报表管理菜单
  48. driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
  49. //点击左侧 自定义报表 菜单
  50. driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
  51. //切换到自定义报表Frame
  52. driver.SwitchTo().Frame(1);
  53. //调用报表导出JS
  54. ((IJavaScriptExecutor)driver).ExecuteScript($"Report.Export('{strId}');");
  55. //切换到弹出的导出报表窗口,点击导出按钮
  56. driver.SwitchTo().DefaultContent();
  57. var ihg_export = driver.FindElement(By.Name("ihg_export"));
  58. driver.SwitchTo().Frame(ihg_export);
  59. driver.FindElement(By.Id("btnSubmit")).Click();
  60. string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
  61. while (true)
  62. {
  63. System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
  64. if (!file.Exists || file.Length == 0)
  65. {
  66. System.Threading.Thread.Sleep(5000);
  67. }
  68. else
  69. {
  70. break;
  71. }
  72. }
  73. }
  74. catch (Exception ex)
  75. {
  76. throw new Exception(ex.Message);
  77. }
  78. finally
  79. {
  80. driver.Quit();
  81. driver.Dispose();
  82. killChromProcess();
  83. }
  84. }
  85. }
  86. private static void Log(string strMessage)
  87. {
  88. StreamWriter sw = File.AppendText("c:\\temp\\log.txt");
  89. sw.WriteLine($"{strMessage}");
  90. sw.Flush();
  91. sw.Close();
  92. sw.Dispose();
  93. }
  94. /// <summary>
  95. /// 根据报表名称导出报表
  96. /// </summary>
  97. /// <param name="ReportName">报告名称</param>
  98. /// <param name="isModifyDate">是否手动修改日期范围</param>
  99. public static DataTable DownloadReport(string ReportName,bool isModifyDate)
  100. {
  101. Log($"{DateTime.Now}\t开始下载:{ReportName}");
  102. DataTable retDatatable;
  103. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  104. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  105. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  106. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  107. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  108. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  109. options.AddUserProfilePreference("intl.accept_languages", "nl");
  110. options.AddUserProfilePreference("disable-popup-blocking", "true");
  111. if (isheadless)
  112. {
  113. options.AddArgument("headless");
  114. }
  115. Log($"{DateTime.Now}\t开始启动Chrome");
  116. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  117. {
  118. try
  119. {
  120. Log($"{DateTime.Now}\tIWebDriver配置");
  121. driver.Manage().Window.Maximize();
  122. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
  123. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
  124. //进入登录界面
  125. Log($"{DateTime.Now}\t开始进入登录界面");
  126. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  127. //输入用户名和密码
  128. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  129. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  130. //点击登录按钮
  131. Log($"{DateTime.Now}\t开始点击登录按钮");
  132. driver.FindElement(By.Id("btnLogin")).Click();
  133. //关闭提示遮罩层
  134. Log($"{DateTime.Now}\t关闭提示遮罩层");
  135. driver.FindElement(By.Id("jpwClose")).Click();
  136. //点击顶部菜单栏中的报表管理菜单
  137. Log($"{DateTime.Now}\t点击顶部菜单栏中的报表管理菜单");
  138. var reportMenu = driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9"));
  139. driver.ExecuteJavaScript("arguments[0].click();", reportMenu);
  140. //点击左侧 自定义报表 菜单
  141. Log($"{DateTime.Now}\t点击左侧 自定义报表 菜单");
  142. var customerReportMenu = driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b"));
  143. driver.ExecuteJavaScript("arguments[0].click();", customerReportMenu);
  144. //切换到自定义报表Frame
  145. Log($"{DateTime.Now}\t切换到自定义报表Frame");
  146. driver.SwitchTo().Frame(1);
  147. Log($"{DateTime.Now}\t开始搜索报告");
  148. var inputSearch = driver.FindElement(By.Id("customizedList_TxtSheetSearchKey"));
  149. Log($"{DateTime.Now}\t在搜索框中输入报告名称");
  150. inputSearch.SendKeys(ReportName);
  151. Log($"{DateTime.Now}\t点击搜索按钮");
  152. var btnSearch = driver.FindElement(By.ClassName("btn-search"));
  153. btnSearch.Click();
  154. Log($"{DateTime.Now}\t选中报告");
  155. var reportRecord = driver.FindElement(By.XPath($"//td[contains(text(),'{ReportName}')]"));
  156. reportRecord.Click();
  157. System.Threading.Thread.Sleep(1000);
  158. if (isModifyDate)
  159. {
  160. Log($"{DateTime.Now}\t点击编辑");
  161. var btnEdit = driver.FindElement(By.ClassName("edit"));
  162. btnEdit.Click();
  163. System.Threading.Thread.Sleep(500);
  164. Log($"{DateTime.Now}\t清除以选择的处理事项完成日条件");
  165. try
  166. {
  167. var doItemFinished = driver.FindElement(By.XPath("//span[contains(@objcvalue,'_date') and contains(@id,'ST;')]"));
  168. doItemFinished.Click();
  169. System.Threading.Thread.Sleep(500);
  170. }
  171. catch { }
  172. Log($"{DateTime.Now}\t输入处理事项完成日期:开始日期");
  173. var startDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_s_')]"));
  174. startDate.Click();
  175. System.Threading.Thread.Sleep(500);
  176. startDate.SendKeys(new DateTime(DateTime.Now.AddMonths(-1).Year, DateTime.Now.AddMonths(-1).Month, 1).ToString("yyyy-MM-dd"));
  177. Log($"{DateTime.Now}\t输入处理事项完成日期:结束日期");
  178. var endDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_e_')]"));//.Id("dt_e_4F8FE88D-9040-45F1-9723-45699BCD4CAF"));
  179. endDate.Click();
  180. System.Threading.Thread.Sleep(500);
  181. endDate.SendKeys(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1).ToString("yyyy-MM-dd"));
  182. Log($"{DateTime.Now}\t添加处理事项检索条件");
  183. var addDate = driver.FindElement(By.XPath("//a[contains(@onclick,'ReportSub.ConditionDTSelect')]"));
  184. addDate.Click();
  185. System.Threading.Thread.Sleep(500);
  186. Log($"{DateTime.Now}\t保存检索条件");
  187. var btnSave = driver.FindElement(By.Id("save"));
  188. btnSave.Click();
  189. System.Threading.Thread.Sleep(3000);
  190. }
  191. Log($"{DateTime.Now}\t点击导出Excel链接");
  192. var linkExport = driver.FindElement(By.XPath("//a[contains(@onclick,'-') and @class='tbexcel']"));
  193. linkExport.Click();
  194. //切换到弹出的导出报表窗口,点击导出按钮
  195. Log($"{DateTime.Now}\t切换到弹出的导出报表窗口,点击导出按钮");
  196. driver.SwitchTo().DefaultContent();
  197. var ihg_export = driver.FindElement(By.Name("ihg_export"));
  198. driver.SwitchTo().Frame(ihg_export);
  199. driver.FindElement(By.Id("btnSubmit")).Click();
  200. //切换到弹出的下载报表界面,点击下载按钮
  201. Log($"{DateTime.Now}\t切换到弹出的下载报表界面,点击下载按钮");
  202. System.Threading.Thread.Sleep(3000);
  203. driver.SwitchTo().DefaultContent();
  204. var frameDownload = driver.FindElement(By.Name("DownloadList"));
  205. driver.SwitchTo().Frame(frameDownload);
  206. var firstTr = driver.FindElement(By.TagName("tr"));
  207. var tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
  208. string strStatus = tdStatus.Text;
  209. while (strStatus.Trim() != "导出成功!")
  210. {
  211. System.Threading.Thread.Sleep(5000);
  212. firstTr = driver.FindElement(By.TagName("tr"));
  213. tdStatus = firstTr.FindElement(By.XPath("//td")).FindElement(By.XPath("following-sibling::td[4]"));
  214. strStatus = tdStatus.Text;
  215. }
  216. Log($"{DateTime.Now}\t点击下载按钮下载文档");
  217. firstTr = driver.FindElement(By.TagName("tr"));
  218. firstTr.FindElement(By.XPath("//td/a[@title='下载']")).Click();
  219. //System.Threading.Thread.Sleep(5000);
  220. //btnDownload.Click();
  221. string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
  222. int iwaiting = 0;
  223. while (true)
  224. {
  225. System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
  226. if (!file.Exists || file.Length == 0)
  227. {
  228. System.Threading.Thread.Sleep(5000);
  229. iwaiting += 5000;
  230. if (iwaiting > 360000)
  231. {
  232. break;
  233. }
  234. }
  235. else
  236. {
  237. break;
  238. }
  239. }
  240. //删除下载记录
  241. Log($"{DateTime.Now}\t删除下载记录");
  242. firstTr = driver.FindElement(By.TagName("tr"));
  243. firstTr.FindElement(By.XPath("//td/a[@title='删除']")).Click();
  244. //System.IO.FileInfo file = new System.IO.FileInfo(strFilePath.Replace("~", "_"));
  245. retDatatable = NPOIExcel.ExcelToDataTable(strFilePath.Replace("~", "_"),true);
  246. System.IO.File.Delete(strFilePath.Replace("~", "_"));
  247. }
  248. catch (Exception ex)
  249. {
  250. Log(ex.ToString());
  251. throw new Exception(ex.Message, ex);
  252. }
  253. finally
  254. {
  255. Log("关闭Chrome");
  256. driver.Quit();
  257. driver.Dispose();
  258. killChromProcess();
  259. }
  260. }
  261. Log($"{DateTime.Now}\t返回数据");
  262. return retDatatable;
  263. }
  264. /// <summary>
  265. /// 获取案件基本信息
  266. /// </summary>
  267. /// <param name="caseNo">我方文号</param>
  268. /// <returns></returns>
  269. public static dynamic GetCaseInfo(string caseNo)
  270. {
  271. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  272. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  273. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  274. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  275. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  276. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  277. options.AddUserProfilePreference("intl.accept_languages", "nl");
  278. options.AddUserProfilePreference("disable-popup-blocking", "true");
  279. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  280. if (isheadless)
  281. {
  282. options.AddArgument("headless");
  283. }
  284. dynamic retObject = new ExpandoObject();
  285. retObject.CaseNo = caseNo.Trim();
  286. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
  287. {
  288. try
  289. {
  290. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
  291. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  292. //进入登录界面
  293. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  294. //输入用户名和密码
  295. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  296. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  297. //点击登录按钮
  298. driver.FindElement(By.Id("btnLogin")).Click();
  299. //关闭提示遮罩层
  300. driver.FindElement(By.Id("jpwClose")).Click();
  301. try
  302. {
  303. var okBtn = driver.FindElement(By.ClassName("ui_state_highlight"));
  304. if (okBtn != null && okBtn.TagName == "input")
  305. {
  306. okBtn.Click();
  307. }
  308. }
  309. catch { }
  310. //点击顶部菜单栏中的案件管理菜单
  311. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  312. //点击左侧 查询 菜单
  313. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  314. //切换到自定义报表Frame
  315. driver.SwitchTo().Frame(1);
  316. var inputSearch = driver.FindElement(By.Id("case_volume"));
  317. inputSearch.SendKeys(caseNo.Trim());
  318. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  319. btnSearch.Click();
  320. var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
  321. caseLink.Click();
  322. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  323. WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
  324. //等待页面上ID属性值为submitButton的元素加载完成
  325. IWebElement myElement = wait.Until((d) =>
  326. {
  327. try
  328. {
  329. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  330. return d.FindElement(By.Id("libase"));
  331. }
  332. catch {
  333. return null;
  334. }
  335. });
  336. myElement.Click();
  337. //driver.FindElement(By.Id("libase")).Click();
  338. retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
  339. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  340. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  341. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  342. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  343. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  344. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  345. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  346. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  347. //select[@id='p_case_info__case_coefficient_id']
  348. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  349. }
  350. catch (Exception ex)
  351. {
  352. throw new Exception(ex.Message, ex);
  353. }
  354. finally
  355. {
  356. driver.Quit();
  357. killChromProcess();
  358. }
  359. }
  360. return retObject;
  361. }
  362. public static dynamic GetPerformanceRecord(string caseNo, List<string> doItemNames)
  363. {
  364. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  365. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  366. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  367. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  368. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  369. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  370. options.AddUserProfilePreference("intl.accept_languages", "nl");
  371. options.AddUserProfilePreference("disable-popup-blocking", "true");
  372. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  373. if (isheadless)
  374. {
  375. options.AddArgument("headless");
  376. }
  377. dynamic retObject = new ExpandoObject();
  378. retObject.CaseNo = caseNo.Trim();
  379. //retObject.DoItem = doItemName;
  380. using (var Service = ChromeDriverService.CreateDefaultService(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath")))
  381. {
  382. Service.Start();
  383. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(Service, options))
  384. {
  385. try
  386. {
  387. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
  388. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  389. //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
  390. WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
  391. //进入登录界面
  392. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  393. //输入用户名和密码
  394. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  395. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  396. //点击登录按钮
  397. driver.FindElement(By.Id("btnLogin")).Click();
  398. //关闭提示遮罩层
  399. driver.FindElement(By.Id("jpwClose")).Click();
  400. //try
  401. //{
  402. // var okBtn = driver.FindElement(By.ClassName("ui_state_highlight"));
  403. // if (okBtn != null && okBtn.TagName == "input")
  404. // {
  405. // okBtn.Click();
  406. // }
  407. //}
  408. //catch { }
  409. //点击顶部菜单栏中的案件管理菜单
  410. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  411. System.Threading.Thread.Sleep(500);
  412. //点击左侧 查询 菜单
  413. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  414. //System.Threading.Thread.Sleep(500);
  415. var inputSearch = wait.Until((d) =>
  416. {
  417. try
  418. {
  419. //切换到自定义报表Frame
  420. d.SwitchTo().Frame(1);
  421. return d.FindElement(By.Id("case_volume"));
  422. }
  423. catch
  424. {
  425. return null;
  426. }
  427. });
  428. //切换到自定义报表Frame
  429. //driver.SwitchTo().Frame(1);
  430. //var inputSearch = driver.FindElement(By.Id("case_volume"));
  431. inputSearch.SendKeys(caseNo.Trim());
  432. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  433. btnSearch.Click();
  434. var caseLink = wait.Until((d) =>
  435. {
  436. try
  437. {
  438. return d.FindElement(By.XPath($"//a[normalize-space()='{caseNo.Trim()}']"));
  439. }
  440. catch
  441. {
  442. return null;
  443. }
  444. });
  445. //System.Threading.Thread.Sleep(500);
  446. //var caseLink = driver.FindElement(By.XPath($"//a[normalize-space()='{caseNo.Trim()}']"));
  447. caseLink.Click();
  448. System.Threading.Thread.Sleep(500);
  449. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  450. IWebElement temDoItemLink = null;
  451. string temFinishedDate = "";
  452. foreach (string doItemName in doItemNames)
  453. {
  454. var DoItemLinks = driver.FindElements(By.XPath($"//td[@colname='ctrl_proc'][normalize-space()='{doItemName}']"));
  455. if (DoItemLinks.Count > 0)
  456. {
  457. var DoItemLink = DoItemLinks[DoItemLinks.Count - 1];
  458. if (string.IsNullOrEmpty(temFinishedDate))
  459. {
  460. temFinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text;
  461. temDoItemLink = DoItemLink;
  462. }
  463. else
  464. {
  465. if (DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text.CompareTo(temFinishedDate) > 0)
  466. {
  467. temFinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text;
  468. temDoItemLink = DoItemLink;
  469. }
  470. }
  471. //new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(DoItemLink)).Click();
  472. }
  473. }
  474. if(temDoItemLink != null)
  475. {
  476. retObject.CaseStage = temDoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  477. retObject.DoItemState = temDoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  478. retObject.InternalDate = temDoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  479. retObject.CustomerLimitDate = temDoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  480. retObject.FinishedDate = temDoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  481. retObject.DoPersons = temDoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  482. retObject.DoItemMemo = temDoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  483. retObject.Reviewer = temDoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  484. retObject.DoItem = temDoItemLink.Text;
  485. //temDoItemLink = DoItemLink;
  486. System.Threading.Thread.Sleep(4000);
  487. temDoItemLink.Click();
  488. }
  489. else
  490. {
  491. throw new ApplicationException("处理事项不存在!");
  492. }
  493. var p_proc_finish_doc_date = wait.Until((d) =>
  494. {
  495. try
  496. {
  497. return d.FindElement(By.Id("p_proc_info__finish_doc_date"));
  498. }
  499. catch
  500. {
  501. return null;
  502. }
  503. });
  504. //System.Threading.Thread.Sleep(500);
  505. retObject.FinalizationDate = p_proc_finish_doc_date.GetAttribute("value"); //定稿日
  506. retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
  507. retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
  508. retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
  509. retObject.WordCount = driver.FindElement(By.Id("p_proc_info__translate_count")).GetAttribute("value"); //翻译字数
  510. driver.FindElement(By.Id("libase")).Click();
  511. var p_case_info__case_name = wait.Until((d) =>
  512. {
  513. try
  514. {
  515. return d.FindElement(By.Id("p_case_info__case_name"));
  516. }
  517. catch
  518. {
  519. return null;
  520. }
  521. });
  522. //System.Threading.Thread.Sleep(500);
  523. retObject.CaseName = p_case_info__case_name.GetAttribute("value"); //案件名称
  524. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  525. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  526. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  527. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  528. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  529. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  530. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  531. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  532. //select[@id='p_case_info__case_coefficient_id']
  533. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  534. }
  535. catch (Exception ex)
  536. {
  537. throw new Exception(ex.Message, ex);
  538. }
  539. finally
  540. {
  541. driver.Quit();
  542. killChromProcess();
  543. }
  544. }
  545. Service.Dispose();
  546. }
  547. return retObject;
  548. }
  549. /// <summary>
  550. /// 获取案件处理事项记录
  551. /// </summary>
  552. /// <param name="caseNo">我方文号</param>
  553. /// <param name="doItemName">处理事项</param>
  554. /// <returns></returns>
  555. public static dynamic GetPerformanceRecord(string caseNo,string doItemName,string caseStage=null)
  556. {
  557. if (caseNo.StartsWith("APCN"))
  558. {
  559. return GetAPCNPerformanceRecord(caseNo, doItemName, caseStage);
  560. }
  561. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  562. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  563. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  564. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  565. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  566. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  567. options.AddUserProfilePreference("intl.accept_languages", "nl");
  568. options.AddUserProfilePreference("disable-popup-blocking", "true");
  569. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  570. if (isheadless)
  571. {
  572. options.AddArgument("headless");
  573. }
  574. dynamic retObject = new ExpandoObject();
  575. retObject.CaseNo = caseNo.Trim();
  576. retObject.DoItem = doItemName;
  577. using (var Service = ChromeDriverService.CreateDefaultService(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath")))
  578. {
  579. Service.Start();
  580. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(Service, options))
  581. {
  582. try
  583. {
  584. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
  585. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  586. //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
  587. WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
  588. //进入登录界面
  589. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  590. //输入用户名和密码
  591. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  592. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  593. //点击登录按钮
  594. driver.FindElement(By.Id("btnLogin")).Click();
  595. //关闭提示遮罩层
  596. driver.FindElement(By.Id("jpwClose")).Click();
  597. //try
  598. //{
  599. // var okBtn = driver.FindElement(By.ClassName("ui_state_highlight"));
  600. // if (okBtn != null && okBtn.TagName == "input")
  601. // {
  602. // okBtn.Click();
  603. // }
  604. //}
  605. //catch { }
  606. //点击顶部菜单栏中的案件管理菜单
  607. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  608. System.Threading.Thread.Sleep(500);
  609. //点击左侧 查询 菜单
  610. driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
  611. //System.Threading.Thread.Sleep(500);
  612. var inputSearch = wait.Until((d) =>
  613. {
  614. try
  615. {
  616. //切换到自定义报表Frame
  617. d.SwitchTo().Frame(1);
  618. return d.FindElement(By.Id("case_volume"));
  619. }
  620. catch
  621. {
  622. return null;
  623. }
  624. });
  625. //切换到自定义报表Frame
  626. //driver.SwitchTo().Frame(1);
  627. //var inputSearch = driver.FindElement(By.Id("case_volume"));
  628. inputSearch.SendKeys(caseNo.Trim());
  629. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  630. btnSearch.Click();
  631. var caseLink = wait.Until((d) =>
  632. {
  633. try
  634. {
  635. return d.FindElement(By.XPath($"//a[normalize-space()='{caseNo.Trim()}']"));
  636. }
  637. catch
  638. {
  639. return null;
  640. }
  641. });
  642. //System.Threading.Thread.Sleep(500);
  643. //var caseLink = driver.FindElement(By.XPath($"//a[normalize-space()='{caseNo.Trim()}']"));
  644. caseLink.Click();
  645. System.Threading.Thread.Sleep(500);
  646. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  647. var DoItemLinks = driver.FindElements(By.XPath($"//td[@colname='ctrl_proc'][normalize-space()='{doItemName}']"));
  648. if (DoItemLinks.Count > 0)
  649. {
  650. if (!string.IsNullOrEmpty(caseStage))
  651. {
  652. foreach (var DoItemLink in DoItemLinks)
  653. {
  654. var temCaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text;
  655. if (temCaseStage == caseStage)
  656. {
  657. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  658. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  659. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  660. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  661. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  662. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  663. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  664. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  665. System.Threading.Thread.Sleep(4000);
  666. DoItemLink.Click();
  667. //driver.ExecuteJavaScript("$(arguments[0]).click()", DoItemLink);
  668. break;
  669. }
  670. }
  671. }
  672. else
  673. {
  674. var DoItemLink = DoItemLinks[DoItemLinks.Count - 1];
  675. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  676. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  677. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  678. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  679. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  680. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  681. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  682. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  683. System.Threading.Thread.Sleep(4000);
  684. DoItemLink.Click();
  685. //new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(DoItemLink)).Click();
  686. }
  687. }
  688. var p_proc_finish_doc_date = wait.Until((d) =>
  689. {
  690. try
  691. {
  692. return d.FindElement(By.Id("p_proc_info__finish_doc_date"));
  693. }
  694. catch
  695. {
  696. return null;
  697. }
  698. });
  699. //System.Threading.Thread.Sleep(500);
  700. retObject.FinalizationDate = p_proc_finish_doc_date.GetAttribute("value"); //定稿日
  701. retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
  702. retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
  703. retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
  704. retObject.WordCount = driver.FindElement(By.Id("p_proc_info__translate_count")).GetAttribute("value"); //翻译字数
  705. driver.FindElement(By.Id("libase")).Click();
  706. var p_case_info__case_name = wait.Until((d) =>
  707. {
  708. try
  709. {
  710. return d.FindElement(By.Id("p_case_info__case_name"));
  711. }
  712. catch
  713. {
  714. return null;
  715. }
  716. });
  717. //System.Threading.Thread.Sleep(500);
  718. retObject.CaseName = p_case_info__case_name.GetAttribute("value"); //案件名称
  719. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  720. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  721. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  722. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  723. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  724. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  725. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  726. driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  727. //select[@id='p_case_info__case_coefficient_id']
  728. retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  729. }
  730. catch (Exception ex)
  731. {
  732. throw new Exception(ex.Message, ex);
  733. }
  734. finally
  735. {
  736. driver.Quit();
  737. killChromProcess();
  738. }
  739. }
  740. Service.Dispose();
  741. }
  742. return retObject;
  743. }
  744. private static dynamic GetAPCNPerformanceRecord(string caseNo, string doItemName, string caseStage = null)
  745. {
  746. string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
  747. bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
  748. string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
  749. string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
  750. OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
  751. options.AddUserProfilePreference("download.default_directory", strFileSavePath);
  752. options.AddUserProfilePreference("intl.accept_languages", "nl");
  753. options.AddUserProfilePreference("disable-popup-blocking", "true");
  754. options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
  755. if (isheadless)
  756. {
  757. options.AddArgument("headless");
  758. }
  759. dynamic retObject = new ExpandoObject();
  760. retObject.CaseNo = caseNo.Trim();
  761. retObject.DoItem = doItemName;
  762. using (var Service = ChromeDriverService.CreateDefaultService(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath")))
  763. {
  764. Service.Start();
  765. using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(Service, options))
  766. {
  767. try
  768. {
  769. driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
  770. driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
  771. //driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(100);
  772. WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
  773. //进入登录界面
  774. driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
  775. //输入用户名和密码
  776. driver.FindElement(By.Id("txtUser")).SendKeys(Account);
  777. driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
  778. //点击登录按钮
  779. driver.FindElement(By.Id("btnLogin")).Click();
  780. //关闭提示遮罩层
  781. driver.FindElement(By.Id("jpwClose")).Click();
  782. //try
  783. //{
  784. // var okBtn = driver.FindElement(By.ClassName("ui_state_highlight"));
  785. // if (okBtn != null && okBtn.TagName == "input")
  786. // {
  787. // okBtn.Click();
  788. // }
  789. //}
  790. //catch { }
  791. //点击顶部菜单栏中的案件管理菜单
  792. driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
  793. System.Threading.Thread.Sleep(500);
  794. //点击左侧 查询 菜单
  795. driver.FindElement(By.Name("FF4E1FF9-FE36-4F0F-99DF-81E60817722E")).Click();
  796. //System.Threading.Thread.Sleep(500);
  797. var inputSearch = wait.Until((d) =>
  798. {
  799. try
  800. {
  801. //切换到自定义报表Frame
  802. d.SwitchTo().Frame(1);
  803. return d.FindElement(By.Id("case_volume"));
  804. }
  805. catch
  806. {
  807. return null;
  808. }
  809. });
  810. //切换到自定义报表Frame
  811. //driver.SwitchTo().Frame(1);
  812. //var inputSearch = driver.FindElement(By.Id("case_volume"));
  813. inputSearch.SendKeys(caseNo.Trim());
  814. var btnSearch = driver.FindElement(By.Id("btn_Search"));
  815. btnSearch.Click();
  816. var caseLink = wait.Until((d) =>
  817. {
  818. try
  819. {
  820. return d.FindElement(By.XPath($"//a[normalize-space()='{caseNo.Trim()}']"));
  821. }
  822. catch
  823. {
  824. return null;
  825. }
  826. });
  827. //System.Threading.Thread.Sleep(500);
  828. //var caseLink = driver.FindElement(By.XPath($"//a[normalize-space()='{caseNo.Trim()}']"));
  829. caseLink.Click();
  830. System.Threading.Thread.Sleep(500);
  831. driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
  832. var DoItemLinks = driver.FindElements(By.XPath($"//td[@colname='ctrl_proc'][normalize-space()='{doItemName}']"));
  833. if (DoItemLinks.Count > 0)
  834. {
  835. if (!string.IsNullOrEmpty(caseStage))
  836. {
  837. foreach (var DoItemLink in DoItemLinks)
  838. {
  839. var temCaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text;
  840. if (temCaseStage == caseStage)
  841. {
  842. retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  843. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
  844. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
  845. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
  846. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
  847. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
  848. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
  849. retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  850. System.Threading.Thread.Sleep(4000);
  851. DoItemLink.Click();
  852. //driver.ExecuteJavaScript("$(arguments[0]).click()", DoItemLink);
  853. break;
  854. }
  855. }
  856. }
  857. else
  858. {
  859. var DoItemLink = DoItemLinks[DoItemLinks.Count - 1];
  860. //retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
  861. retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //处理事项处理状态
  862. retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[3]")).Text; //内部期限
  863. retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //客户期限
  864. retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[6]")).Text; //处理事项完成日
  865. retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理人
  866. retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //处理事项备注
  867. //retObject.Reviewer = DoItemLink.FindElement(By.XPath("following-sibling::td[10]")).Text; //核稿人
  868. System.Threading.Thread.Sleep(4000);
  869. DoItemLink.Click();
  870. //new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(DoItemLink)).Click();
  871. }
  872. }
  873. var p_proc_finish_doc_date = wait.Until((d) =>
  874. {
  875. try
  876. {
  877. return d.FindElement(By.Id("p_proc_info__finish_doc_date"));
  878. }
  879. catch
  880. {
  881. return null;
  882. }
  883. });
  884. //System.Threading.Thread.Sleep(500);
  885. retObject.FinalizationDate = p_proc_finish_doc_date.GetAttribute("value"); //定稿日
  886. retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
  887. retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
  888. retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
  889. retObject.WordCount = driver.FindElement(By.Id("p_proc_info__translate_count")).GetAttribute("value"); //翻译字数
  890. driver.FindElement(By.Id("libase")).Click();
  891. var p_case_info__case_name = wait.Until((d) =>
  892. {
  893. try
  894. {
  895. return d.FindElement(By.Id("p_case_info__case_name"));
  896. }
  897. catch
  898. {
  899. return null;
  900. }
  901. });
  902. //System.Threading.Thread.Sleep(500);
  903. retObject.CaseName = p_case_info__case_name.GetAttribute("value"); //案件名称
  904. retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
  905. retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
  906. retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
  907. retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
  908. retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
  909. retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
  910. retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
  911. //driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
  912. //select[@id='p_case_info__case_coefficient_id']
  913. //retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
  914. }
  915. catch (Exception ex)
  916. {
  917. throw new Exception(ex.Message, ex);
  918. }
  919. finally
  920. {
  921. driver.Quit();
  922. killChromProcess();
  923. }
  924. }
  925. Service.Dispose();
  926. }
  927. return retObject;
  928. }
  929. private static void killChromProcess()
  930. {
  931. try
  932. {
  933. Process[] workers = Process.GetProcessesByName("Chrome");
  934. foreach (Process worker in workers)
  935. {
  936. worker.Kill();
  937. worker.WaitForExit();
  938. worker.Dispose();
  939. }
  940. workers = Process.GetProcessesByName("Chromedriver");
  941. foreach (Process worker in workers)
  942. {
  943. worker.Kill();
  944. worker.WaitForExit();
  945. worker.Dispose();
  946. }
  947. }
  948. catch { }
  949. }
  950. private static string GetSelectText(IWebElement element)
  951. {
  952. var strValue = element.GetAttribute("value");
  953. if (string.IsNullOrEmpty(strValue))
  954. {
  955. return null;
  956. }
  957. var ops = element.FindElements(By.TagName("option"));
  958. foreach (var op in ops)
  959. {
  960. if (op.GetAttribute("value") == strValue)
  961. {
  962. return op.Text;
  963. }
  964. }
  965. return null;
  966. }
  967. }
  968. }