IPEasyUtility.cs 60 KB

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