123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428 |
- using System;
- using System.Data;
- using System.Dynamic;
- using System.Linq;
- using OpenQA.Selenium;
- namespace wispro.sp.utility
- {
- public class IPEasyUtility
- {
- public static void DownloadReport(string strId,string filename)
- {
- string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
- bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
- string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
- string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
- OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
- options.AddUserProfilePreference("download.default_directory", strFileSavePath);
- options.AddUserProfilePreference("intl.accept_languages", "nl");
- options.AddUserProfilePreference("disable-popup-blocking", "true");
- if (isheadless)
- {
- options.AddArgument("headless");
- }
- using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
- {
- driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
- driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
- //进入登录界面
- driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
- //输入用户名和密码
- driver.FindElement(By.Id("txtUser")).SendKeys(Account);
- driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
- //点击登录按钮
- driver.FindElement(By.Id("btnLogin")).Click();
- //关闭提示遮罩层
- driver.FindElement(By.Id("jpwClose")).Click();
- //点击顶部菜单栏中的报表管理菜单
- driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
- //点击左侧 自定义报表 菜单
- driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
- //切换到自定义报表Frame
- driver.SwitchTo().Frame(1);
- //调用报表导出JS
- ((IJavaScriptExecutor)driver).ExecuteScript($"Report.Export('{strId}');");
- //切换到弹出的导出报表窗口,点击导出按钮
- driver.SwitchTo().DefaultContent();
- var ihg_export = driver.FindElement(By.Name("ihg_export"));
- driver.SwitchTo().Frame(ihg_export);
- driver.FindElement(By.Id("btnSubmit")).Click();
- string strFilePath = System.IO.Path.Combine(strFileSavePath, filename);
- while (true)
- {
- System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
- if (!file.Exists || file.Length == 0) {
- System.Threading.Thread.Sleep(5000);
- }
- else
- {
- break;
- }
- }
- }
- }
- /// <summary>
- /// 根据报表名称导出报表
- /// </summary>
- /// <param name="ReportName">报告名称</param>
- /// <param name="isModifyDate">是否手动修改日期范围</param>
- public static void DownloadReport(string ReportName,bool isModifyDate)
- {
- string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
- bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
- string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
- string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
- OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
- options.AddUserProfilePreference("download.default_directory", strFileSavePath);
- options.AddUserProfilePreference("intl.accept_languages", "nl");
- options.AddUserProfilePreference("disable-popup-blocking", "true");
- if (isheadless)
- {
- options.AddArgument("headless");
- }
- using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
- {
- driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(50);
- driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(500);
- //进入登录界面
- driver.Navigate().GoToUrl("http://47.106.221.167/Login.aspx");
- //输入用户名和密码
- driver.FindElement(By.Id("txtUser")).SendKeys(Account);
- driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
- //点击登录按钮
- driver.FindElement(By.Id("btnLogin")).Click();
- //关闭提示遮罩层
- driver.FindElement(By.Id("jpwClose")).Click();
- //点击顶部菜单栏中的报表管理菜单
- driver.FindElement(By.Name("970d33d5-c728-41b8-a060-4330610706b9")).Click();
- //点击左侧 自定义报表 菜单
- driver.FindElement(By.Name("642fa96f-1e1f-46fd-aaa4-cb461ee8df5b")).Click();
- //切换到自定义报表Frame
- driver.SwitchTo().Frame(1);
- var inputSearch = driver.FindElement(By.Id("customizedList_TxtSheetSearchKey"));
- inputSearch.SendKeys(ReportName);
- var btnSearch = driver.FindElement(By.ClassName("btn-search"));
- btnSearch.Click();
- var reportRecord = driver.FindElement(By.XPath($"//td[contains(text(),'{ReportName}')]"));
- reportRecord.Click();
- System.Threading.Thread.Sleep(1000);
- if (isModifyDate)
- {
- var btnEdit = driver.FindElement(By.ClassName("edit"));
- btnEdit.Click();
- System.Threading.Thread.Sleep(500);
- var doItemFinished = driver.FindElement(By.XPath("//span[contains(@objcvalue,'_date') and contains(@id,'ST;')]"));
- doItemFinished.Click();
- System.Threading.Thread.Sleep(500);
- var startDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_s_')]"));
-
- startDate.Click();
- System.Threading.Thread.Sleep(500);
- startDate.SendKeys($"{DateTime.Now.AddMonths(-1).Year }-{DateTime.Now.AddMonths(-1).Month}-01");
- var endDate = driver.FindElement(By.XPath("//input[contains(@id,'dt_e_')]"));//.Id("dt_e_4F8FE88D-9040-45F1-9723-45699BCD4CAF"));
- endDate.Click();
- System.Threading.Thread.Sleep(500);
- endDate.SendKeys(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1).ToString("yyyy-MM-dd"));
- var addDate = driver.FindElement(By.XPath("//a[contains(@onclick,'ReportSub.ConditionDTSelect')]"));
- addDate.Click();
- System.Threading.Thread.Sleep(500);
- var btnSave = driver.FindElement(By.Id("save"));
- btnSave.Click();
- System.Threading.Thread.Sleep(3000);
- }
- var linkExport = driver.FindElement(By.XPath("//a[contains(@onclick,'-') and @class='tbexcel']"));
- linkExport.Click();
-
- //切换到弹出的导出报表窗口,点击导出按钮
- driver.SwitchTo().DefaultContent();
- var ihg_export = driver.FindElement(By.Name("ihg_export"));
- driver.SwitchTo().Frame(ihg_export);
- driver.FindElement(By.Id("btnSubmit")).Click();
- string strFilePath = System.IO.Path.Combine(strFileSavePath, $"{ReportName.Trim()}.xlsx");
- while (true)
- {
- System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
- if (!file.Exists || file.Length == 0)
- {
- System.Threading.Thread.Sleep(5000);
- }
- else
- {
- break;
- }
- }
- }
- }
- /// <summary>
- /// 获取案件基本信息
- /// </summary>
- /// <param name="caseNo">我方文号</param>
- /// <returns></returns>
- public static dynamic GetCaseInfo(string caseNo)
- {
- string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
- bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
- string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
- string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
- OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
- options.AddUserProfilePreference("download.default_directory", strFileSavePath);
- options.AddUserProfilePreference("intl.accept_languages", "nl");
- options.AddUserProfilePreference("disable-popup-blocking", "true");
- options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
- if (isheadless)
- {
- options.AddArgument("headless");
- }
- dynamic retObject = new ExpandoObject();
- retObject.CaseNo = caseNo;
- using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
- {
- driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
- driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
- //进入登录界面
- driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
- //输入用户名和密码
- driver.FindElement(By.Id("txtUser")).SendKeys(Account);
- driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
- //点击登录按钮
- driver.FindElement(By.Id("btnLogin")).Click();
- //关闭提示遮罩层
- driver.FindElement(By.Id("jpwClose")).Click();
- //点击顶部菜单栏中的案件管理菜单
- driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
- //点击左侧 查询 菜单
- driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
- //切换到自定义报表Frame
- driver.SwitchTo().Frame(1);
- var inputSearch = driver.FindElement(By.Id("case_volume"));
- inputSearch.SendKeys(caseNo);
- var btnSearch = driver.FindElement(By.Id("btn_Search"));
- btnSearch.Click();
- var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
- caseLink.Click();
- System.Threading.Thread.Sleep(500);
- driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
-
- driver.FindElement(By.Id("libase")).Click();
- retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
- retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
- retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
- retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
- retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
- retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
- retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
- retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
- driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
- //select[@id='p_case_info__case_coefficient_id']
- retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
- }
- return retObject;
- }
- /// <summary>
- /// 获取案件处理事项记录
- /// </summary>
- /// <param name="caseNo">我方文号</param>
- /// <param name="doItemName">处理事项</param>
- /// <returns></returns>
- public static dynamic GetPerformanctRecord(string caseNo,string doItemName)
- {
- string strFileSavePath = ConfigHelper.GetSectionValue("IPEasySetting:DownloadFileSavePath");
- bool isheadless = (ConfigHelper.GetSectionValue("IPEasySetting:isHeadless") == "true");
- string Account = ConfigHelper.GetSectionValue("IPEasySetting:Account");
- string Password = ConfigHelper.GetSectionValue("IPEasySetting:Password");
- OpenQA.Selenium.Chrome.ChromeOptions options = new OpenQA.Selenium.Chrome.ChromeOptions();
- options.AddUserProfilePreference("download.default_directory", strFileSavePath);
- options.AddUserProfilePreference("intl.accept_languages", "nl");
- options.AddUserProfilePreference("disable-popup-blocking", "true");
- options.AddUserProfilePreference("profile", new { default_content_setting_values = new { images = 2 } });
- if (isheadless)
- {
- options.AddArgument("headless");
- }
- dynamic retObject = new ExpandoObject();
- retObject.CaseNo = caseNo;
- retObject.DoItem = doItemName;
-
-
- using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(ConfigHelper.GetSectionValue("IPEasySetting:ChormeDriverPath"), options))
- {
- driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
- driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(100);
-
- //进入登录界面
- driver.Navigate().GoToUrl(ConfigHelper.GetSectionValue("IPEasySetting:IPEasyWeb"));
- //输入用户名和密码
- driver.FindElement(By.Id("txtUser")).SendKeys(Account);
- driver.FindElement(By.Id("txtPwd")).SendKeys(Password);
- //点击登录按钮
- driver.FindElement(By.Id("btnLogin")).Click();
- //关闭提示遮罩层
- driver.FindElement(By.Id("jpwClose")).Click();
- //点击顶部菜单栏中的案件管理菜单
- driver.FindElement(By.Name("71A7CC35-F597-40E1-9FEF-BE622A3A3B63")).Click();
- //点击左侧 查询 菜单
- driver.FindElement(By.Name("c3266ab3-521a-4815-8aaf-7dd0bc5a76af")).Click();
- //切换到自定义报表Frame
- driver.SwitchTo().Frame(1);
- var inputSearch = driver.FindElement(By.Id("case_volume"));
- inputSearch.SendKeys(caseNo);
- var btnSearch = driver.FindElement(By.Id("btn_Search"));
- btnSearch.Click();
- var caseLink = driver.FindElement(By.XPath($"//a[contains(text(),'{caseNo}')]"));
- caseLink.Click();
- System.Threading.Thread.Sleep(500);
- driver.SwitchTo().ParentFrame().SwitchTo().Frame(2);
- var DoItemLink = driver.FindElement(By.XPath($"//td[contains(text(),'{doItemName}')]"));
- retObject.CaseStage = DoItemLink.FindElement(By.XPath("following-sibling::td[1]")).Text; //案件阶段
- retObject.DoItemState = DoItemLink.FindElement(By.XPath("following-sibling::td[2]")).Text; //处理事项处理状态
- retObject.InternalDate = DoItemLink.FindElement(By.XPath("following-sibling::td[4]")).Text; //内部期限
- retObject.CustomerLimitDate = DoItemLink.FindElement(By.XPath("following-sibling::td[5]")).Text; //客户期限
- retObject.FinishedDate = DoItemLink.FindElement(By.XPath("following-sibling::td[7]")).Text; //处理事项完成日
- retObject.DoPersons = DoItemLink.FindElement(By.XPath("following-sibling::td[8]")).Text; //处理人
- retObject.DoItemMemo = DoItemLink.FindElement(By.XPath("following-sibling::td[9]")).Text; //处理事项备注
- DoItemLink.Click();
- retObject.FinalizationDate = driver.FindElement(By.Id("p_proc_info__finish_doc_date")).GetAttribute("value"); //定稿日
- retObject.ReturnDate = driver.FindElement(By.Id("p_proc_info__back_date")).GetAttribute("value"); //返稿日
- retObject.Reviewer = driver.FindElement(By.Id("p_proc_info__revise_user")).GetAttribute("value"); //核稿人
- retObject.DoItemCoefficient = driver.FindElement(By.Id("p_proc_info__proc_coefficient")).GetAttribute("value"); //处理事项系数
- driver.FindElement(By.Id("libase")).Click();
- retObject.CaseName = driver.FindElement(By.Id("p_case_info__case_name")).GetAttribute("value"); //案件名称
- retObject.CustomerName = driver.FindElement(By.Id("p_case_info__customer_id")).GetAttribute("value"); //客户名称
- retObject.BusinessType = driver.FindElement(By.Id("p_case_info__business_type_id")).GetAttribute("value"); //业务类型
- retObject.CaseState = GetSelectText(driver.FindElement(By.Id("p_case_info__case_status_id")));
- retObject.ApplicationType = GetSelectText(driver.FindElement(By.Id("p_case_info__apply_type_id")));
-
- retObject.CaseType = driver.FindElement(By.Id("p_case_info__case_type_id")).GetAttribute("value"); //案件类型
- retObject.EntrustingDate = driver.FindElement(By.Id("p_case_info__charge_date")).GetAttribute("value"); //委案日期
- retObject.CaseMemo = driver.FindElement(By.Id("p_case_info__remark")).GetAttribute("value"); //案件备注
- driver.FindElement(By.XPath($"//span[contains(text(),'扩展信息')]")).Click();
- //select[@id='p_case_info__case_coefficient_id']
- retObject.CaseCoefficient = GetSelectText(driver.FindElement(By.Id("p_case_info__case_coefficient_id")));
- }
- return retObject;
- }
- private static string GetSelectText(IWebElement element)
- {
- var strValue = element.GetAttribute("value");
- if (string.IsNullOrEmpty(strValue))
- {
- return null;
- }
- var ops = element.FindElements(By.TagName("option"));
- foreach (var op in ops)
- {
- if (op.GetAttribute("value") == strValue)
- {
- return op.Text;
- }
- }
- return null;
- }
- }
- }
|