AirTicketResRepository.cs 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. using AutoMapper;
  2. using Newtonsoft.Json.Linq;
  3. using Newtonsoft.Json;
  4. using OASystem.Domain;
  5. using OASystem.Domain.Dtos.Groups;
  6. using OASystem.Domain.Dtos.UserDto;
  7. using OASystem.Domain.Entities.Business;
  8. using OASystem.Domain.Entities.Customer;
  9. using OASystem.Domain.Entities.Groups;
  10. using OASystem.Domain.Entities.Resource;
  11. using OASystem.Domain.ViewModels.Groups;
  12. using OASystem.Infrastructure.Tools;
  13. using Org.BouncyCastle.Asn1.Ocsp;
  14. using System;
  15. using System.Collections.Generic;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Security.Cryptography;
  19. using System.Security.Policy;
  20. using System.Text;
  21. using System.Threading.Tasks;
  22. using System.Web;
  23. using System.Xml.Linq;
  24. using System.Net;
  25. using NPOI.XWPF.UserModel;
  26. using NPOI.OpenXmlFormats.Wordprocessing;
  27. using System.Collections;
  28. using Aspose.Words.Tables;
  29. using Aspose.Words;
  30. using System.Reflection;
  31. using OASystem.Domain.Entities.Financial;
  32. namespace OASystem.Infrastructure.Repositories.Groups
  33. {
  34. public class AirTicketResRepository : BaseRepository<Grp_AirTicketReservations, Grp_AirTicketReservations>
  35. {
  36. private readonly IMapper _mapper;
  37. public AirTicketResRepository(SqlSugarClient sqlSugar, IMapper mapper) : base(sqlSugar)
  38. {
  39. _mapper = mapper;
  40. }
  41. public async Task<Result> AirTicketResById(AirTicketResByIdDto dto)
  42. {
  43. Result result = new Result() { Code = -2, Msg = "未知错误" };
  44. try
  45. {
  46. Grp_AirTicketReservations grp_AirTicket = _sqlSugar.Queryable<Grp_AirTicketReservations>().First(a => a.Id == dto.Id && a.IsDel == 0);
  47. if (grp_AirTicket == null)
  48. {
  49. return result = new Result() { Code = -1, Msg = "暂无数据" };
  50. }
  51. else
  52. {
  53. Grp_CreditCardPayment grp_CreditCard = _sqlSugar.Queryable<Grp_CreditCardPayment>().First(a => a.CId == grp_AirTicket.Id && a.IsDel == 0 && a.CTable==85);
  54. if (grp_CreditCard == null) { return result = new Result() { Code = -1, Msg = "暂无数据" }; }
  55. return result = new Result()
  56. {
  57. Code = 0,
  58. Msg = "查询成功!",
  59. Data = new
  60. {
  61. AirTicket = grp_AirTicket,
  62. CreditCard = grp_CreditCard,
  63. }
  64. };
  65. }
  66. }
  67. catch (Exception)
  68. {
  69. return result = new Result() { Code = -2, Msg = "未知错误" };
  70. throw;
  71. }
  72. }
  73. public async Task<Result> AirTicketResList(AirTicketResDto dto)
  74. {
  75. Result result = new Result() { Code = -2, Msg = "未知错误" };
  76. Grp_DelegationInfo _DelegationInfo = _sqlSugar.Queryable<Grp_DelegationInfo>().First(it => it.Id == dto.DiId);
  77. if (_DelegationInfo != null)
  78. {
  79. string UserId = "";
  80. List<Grp_GroupsTaskAssignment> gtaUIdList = _sqlSugar.Queryable<Grp_GroupsTaskAssignment>().Where(a=>a.DIId==dto.DiId && a.IsDel==0 && a.CTId==85).ToList();
  81. foreach (Grp_GroupsTaskAssignment gta in gtaUIdList)
  82. UserId += gta.UId + ",";
  83. if (!string.IsNullOrWhiteSpace(UserId))
  84. {
  85. UserId = UserId.Substring(0, UserId.Length - 1);
  86. }
  87. else
  88. {
  89. UserId = "0";
  90. }
  91. string sql = string.Format(@"select a.*,c.IsAuditGM,(select Name from Sys_SetData where Id=a.cType) as 'CTypeName',(select Name from
  92. Sys_SetData where Id=a.PreCurrency) as 'PreCurrencyStr',(select Name from Sys_SetData where Id=a.Currency)
  93. as 'CurrencyStr' from Grp_AirTicketReservations a,Grp_CreditCardPayment c where a.id=c.CId and a.isdel={1} and c.IsDel={1}
  94. and a.DIId={0} and c.DIId={0} and c.CTable=85 and a.CreateUserId in({2}) Order By a.CreateTime desc", dto.DiId, 0,UserId);
  95. List<AirTicketReservationsView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsView>(sql).ToList();
  96. foreach (var item in _AirTicketReservations)
  97. {
  98. if (item.FlightsDescription.Contains("\n"))
  99. {
  100. var spilitArr = Regex.Split(item.FlightsDescription, "\n");
  101. int rowindex = 1;
  102. foreach (var spilitItem in spilitArr)
  103. {
  104. try
  105. {
  106. var spDotandEmpty = spilitItem.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  107. var depCode = spDotandEmpty[3].Substring(0, 3);
  108. var arrCode = spDotandEmpty[3].Substring(3, 3);
  109. Res_ThreeCode depData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == depCode);
  110. Res_ThreeCode arrData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == arrCode);
  111. string day = spDotandEmpty[2].Substring(2, 2);//日
  112. string monthAbbreviations = spDotandEmpty[2].Substring(4, 3).ToUpper();//月份
  113. switch (monthAbbreviations)
  114. {
  115. case "JAN":
  116. monthAbbreviations = "1";
  117. break;
  118. case "FEB":
  119. monthAbbreviations = "2";
  120. break;
  121. case "MAR":
  122. monthAbbreviations = "3";
  123. break;
  124. case "APR":
  125. monthAbbreviations = "4";
  126. break;
  127. case "MAY":
  128. monthAbbreviations = "5";
  129. break;
  130. case "JUN":
  131. monthAbbreviations = "6";
  132. break;
  133. case "JUL":
  134. monthAbbreviations = "7";
  135. break;
  136. case "AUG":
  137. monthAbbreviations = "8";
  138. break;
  139. case "SEP":
  140. monthAbbreviations = "9";
  141. break;
  142. case "OCT":
  143. monthAbbreviations = "10";
  144. break;
  145. case "NOV":
  146. monthAbbreviations = "11";
  147. break;
  148. case "DEC":
  149. monthAbbreviations = "12";
  150. break;
  151. }
  152. string tate = $"{monthAbbreviations}月{day}日";
  153. item.FlightDescription += rowindex + ". " + depData.AirPort + " " + arrData.AirPort + " (" + tate + ")\r\n";
  154. }
  155. catch (Exception ex)
  156. {
  157. item.FlightDescription = "录入数据不规范!请检查";
  158. break;
  159. }
  160. rowindex++;
  161. }
  162. }
  163. else
  164. {
  165. try
  166. {
  167. var spDotandEmpty = item.FlightsDescription.Split('.')[1].Split(' ').Where(x => !string.IsNullOrEmpty(x)).ToList();
  168. var depCode = spDotandEmpty[3].Substring(0, 3);
  169. var arrCode = spDotandEmpty[3].Substring(3, 3);
  170. Res_ThreeCode depData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == depCode);
  171. Res_ThreeCode arrData = _sqlSugar.Queryable<Res_ThreeCode>().First(it => it.IsDel == 0 && it.Three == arrCode);
  172. string day = spDotandEmpty[2].Substring(2, 2);//日
  173. string monthAbbreviations = spDotandEmpty[2].Substring(4, 3).ToUpper();//月份
  174. switch (monthAbbreviations)
  175. {
  176. case "JAN":
  177. monthAbbreviations = "1";
  178. break;
  179. case "FEB":
  180. monthAbbreviations = "2";
  181. break;
  182. case "MAR":
  183. monthAbbreviations = "3";
  184. break;
  185. case "APR":
  186. monthAbbreviations = "4";
  187. break;
  188. case "MAY":
  189. monthAbbreviations = "5";
  190. break;
  191. case "JUN":
  192. monthAbbreviations = "6";
  193. break;
  194. case "JUL":
  195. monthAbbreviations = "7";
  196. break;
  197. case "AUG":
  198. monthAbbreviations = "8";
  199. break;
  200. case "SEP":
  201. monthAbbreviations = "9";
  202. break;
  203. case "OCT":
  204. monthAbbreviations = "10";
  205. break;
  206. case "NOV":
  207. monthAbbreviations = "11";
  208. break;
  209. case "DEC":
  210. monthAbbreviations = "12";
  211. break;
  212. }
  213. string tate = $"{monthAbbreviations}月{day}日";
  214. item.FlightDescription += depData.AirPort + " " + arrData.AirPort + " (" + tate + ")\r\n";
  215. }
  216. catch (Exception)
  217. {
  218. item.FlightDescription = "录入数据不规范!请检查";
  219. }
  220. }
  221. }
  222. //团组成本预算表查询
  223. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == dto.DiId && a.IsDel==0);
  224. AirGroupCostParameterView _AirgroupCostParameter = _mapper.Map<AirGroupCostParameterView>(_GroupCostParameter);
  225. for (int i = 0; i <_AirTicketReservations.Count; i++)
  226. {
  227. string [] ClientArr= _AirTicketReservations[i].ClientName.Split(',');
  228. foreach (var item in ClientArr)
  229. {
  230. Crm_GroupCustomer crm_GroupCustomer = _sqlSugar.Queryable<Crm_GroupCustomer>().Where(a => a.IsDel==0 && a.Id==int.Parse(item)).First();
  231. _AirTicketReservations[i].ClientNameStr+=crm_GroupCustomer.Pinyin+',';
  232. }
  233. _AirTicketReservations[i].ClientNameStr=_AirTicketReservations[i].ClientNameStr.Substring(0, _AirTicketReservations[i].ClientNameStr.Length-1);
  234. }
  235. if (dto.PortType==1)
  236. {
  237. var data = new
  238. {
  239. DelegationInfo = _DelegationInfo,
  240. AirTicketReservations = _AirTicketReservations,
  241. AirGroupCostParameter = _AirgroupCostParameter
  242. };
  243. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  244. }
  245. else if(dto.PortType == 2 || dto.PortType==3)
  246. {
  247. int count = _AirTicketReservations.Count;
  248. float totalPage = (float)count / dto.PageSize;//总页数
  249. if (totalPage == 0) totalPage = 1;
  250. else totalPage = (int)Math.Ceiling((double)totalPage);
  251. List<AirTicketReservationsView> grp_AirTickets = new List<AirTicketReservationsView>();
  252. for (int i = 0; i < dto.PageSize; i++)
  253. {
  254. var RowIndex = i + (dto.PageIndex - 1) * dto.PageSize;
  255. if (RowIndex < _AirTicketReservations.Count)
  256. {
  257. grp_AirTickets.Add(_AirTicketReservations[RowIndex]);
  258. }
  259. else
  260. {
  261. break;
  262. }
  263. }
  264. ListViewBase<AirTicketReservationsView> rst = new ListViewBase<AirTicketReservationsView>();
  265. rst.DataList = grp_AirTickets;
  266. rst.DataCount = count;
  267. rst.CurrPageIndex = dto.PageIndex;
  268. rst.CurrPageSize = dto.PageSize;
  269. var data = new
  270. {
  271. AirData= rst,
  272. AirGroupCostParameter = _AirgroupCostParameter
  273. };
  274. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  275. }
  276. else
  277. {
  278. return result = new Result() { Code = -1, Msg = "请传入PortType参数!1:Web,2:Android,3:IOS!" };
  279. }
  280. }
  281. else
  282. {
  283. return result = new Result() { Code = -1, Msg = "暂无团组数据!" };
  284. }
  285. }
  286. public async Task<Result> AirTicketResSelect(AirTicketResDto dto)
  287. {
  288. Result result = new Result() { Code = -2, Msg = "未知错误" };
  289. try
  290. {
  291. #region 团组下拉框
  292. List<Grp_GroupsTaskAssignment> grp_GroupsTaskAssignment = Query<Grp_GroupsTaskAssignment>(a => a.IsDel == 0 && a.UId == dto.UserId && a.CTId == 85).ToList();
  293. List<GroupNameView> grp_NameView = new List<GroupNameView>();
  294. string DiId = "";
  295. foreach (var item in grp_GroupsTaskAssignment)
  296. {
  297. DiId += item.DIId + ",";
  298. }
  299. if (DiId.Length>1)
  300. {
  301. DiId = DiId.Substring(0, DiId.Length - 1);
  302. string sql = string.Format(@"select * from Grp_DelegationInfo where Id in({0}) and IsDel={1}", DiId, 0);
  303. List<Grp_DelegationInfo> grp_Delegations = _sqlSugar.SqlQueryable<Grp_DelegationInfo>(sql).ToList();
  304. if (grp_Delegations.Count == 0)
  305. {
  306. return result = new Result() { Code = -1, Msg = "查询失败!" };
  307. }
  308. foreach (var item in grp_Delegations)
  309. {
  310. GroupNameView groupNameView = new GroupNameView();
  311. groupNameView.Id = item.Id;
  312. groupNameView.GroupName = item.TeamName;
  313. grp_NameView.Add(groupNameView);
  314. }
  315. }
  316. #endregion
  317. #region 其他下拉框查询
  318. //舱位类型
  319. List<Sys_SetData> TicketClass = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 44 && a.IsDel == 0).ToList();
  320. List<SetDataInfoView> _TicketClassa = _mapper.Map<List<SetDataInfoView>>(TicketClass);
  321. //支付方式
  322. List<Sys_SetData> Payment = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 14 && a.IsDel == 0).ToList();
  323. List<SetDataInfoView> _Payment = _mapper.Map<List<SetDataInfoView>>(Payment);
  324. //卡类型
  325. List<Sys_SetData> CardType = _sqlSugar.Queryable<Sys_SetData>().Where(a => a.STid == 15 && a.IsDel == 0).ToList();
  326. List<SetDataInfoView> _CardType = _mapper.Map<List<SetDataInfoView>>(CardType);
  327. //合作方资料
  328. List<Res_AirTicketAgent> _AirTicketAgents = _sqlSugar.Queryable<Res_AirTicketAgent>().Where(a => a.IsDel == 0).ToList();
  329. #endregion
  330. var data = new
  331. {
  332. TicketClass = _TicketClassa,
  333. Payment = _Payment,
  334. CardType = _CardType,
  335. GroupName = grp_NameView,
  336. AirTicketAgents = _AirTicketAgents
  337. };
  338. return result = new Result() { Code = 0, Msg = "查询成功!", Data = data };
  339. }
  340. catch (Exception ex)
  341. {
  342. return result = new Result() { Code = -2, Msg = "程序错误" };
  343. throw;
  344. }
  345. }
  346. public async Task<Result> OpAirTicketRes(AirTicketResOpDto dto)
  347. {
  348. Result result = new Result() { Code = -2, Msg = "未知错误" };
  349. try
  350. {
  351. BeginTran();
  352. int id = 0;
  353. Grp_AirTicketReservations grp_AirTicket = _mapper.Map<Grp_AirTicketReservations>(dto.AirTicketResOpData);
  354. if (dto.Status == 1)
  355. {
  356. string selectSql = string.Format(@"select * from Grp_AirTicketReservations where ClientName='{0}' and IsDel={1} and FlightsCode='{2}'"
  357. , dto.AirTicketResOpData.ClientName, 0,dto.AirTicketResOpData.FlightsCode);
  358. var DeleClient = await _sqlSugar.SqlQueryable<Grp_AirTicketReservations>(selectSql).FirstAsync();//查询是否存在
  359. if (DeleClient != null)
  360. {
  361. return result = new Result() { Code = -1, Msg = "该机票信息已存在,请勿重复添加!" };
  362. }
  363. else//不存在,可添加
  364. {
  365. //grp_AirTicket.ArrivedTime = "";
  366. //grp_AirTicket.LeaveDescription = "";
  367. //grp_AirTicket.FlightsDescription = "";
  368. //grp_AirTicket.DeleteUserId = 0;
  369. //grp_AirTicket.DeleteTime = "";
  370. //grp_AirTicket.ReturnDescription = "";
  371. grp_AirTicket.FlightsDate= DateTime.Parse(grp_AirTicket.FlightsDate).ToString("yyyy-MM-dd");
  372. id = await AddAsyncReturnId(grp_AirTicket);
  373. if (id == 0)
  374. {
  375. result = new Result() { Code = -1, Msg = "添加失败!" };
  376. }
  377. else
  378. {
  379. result = new Result() { Code = 0, Msg = "添加成功!" };
  380. }
  381. }
  382. if (result.Code == 0)
  383. {
  384. Grp_CreditCardPayment grp_CreditCard = _mapper.Map<Grp_CreditCardPayment>(dto.CardPaymentOpData);
  385. //换算
  386. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0 && a.CTable == 85);
  387. if (_TeamRate != null)
  388. {
  389. if (grp_CreditCard.PaymentCurrency == 49)
  390. {
  391. grp_CreditCard.DayRate = _TeamRate.RateU;
  392. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateU);
  393. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  394. }
  395. else if (grp_CreditCard.PaymentCurrency == 51)
  396. {
  397. grp_CreditCard.DayRate = _TeamRate.RateE;
  398. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateE);
  399. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  400. }
  401. else
  402. {
  403. grp_CreditCard.DayRate = 1M;
  404. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  405. }
  406. }
  407. else
  408. {
  409. grp_CreditCard.DayRate = 1M;
  410. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  411. }
  412. //判断是否超出成本
  413. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0);
  414. if (grp_AirTicket.CType == 460)//经济舱
  415. {
  416. if (_GroupCostParameter != null)
  417. {
  418. if (Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  419. {
  420. grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  421. grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  422. grp_CreditCard.AuditGMOperate = 0;
  423. grp_CreditCard.AuditGMDate = "";
  424. grp_CreditCard.IsPay = 0;
  425. }
  426. else
  427. {
  428. var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.JJCCB);
  429. var b = a / Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  430. grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  431. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  432. grp_CreditCard.AuditGMOperate = 21;
  433. grp_CreditCard.AuditGMDate = "";
  434. grp_CreditCard.IsPay = 0;
  435. }
  436. }
  437. else
  438. {
  439. grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  440. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  441. grp_CreditCard.AuditGMOperate = 21;
  442. grp_CreditCard.AuditGMDate = "";
  443. grp_CreditCard.IsPay = 0;
  444. }
  445. }
  446. else if (grp_AirTicket.CType == 458)
  447. {
  448. if (_GroupCostParameter != null)
  449. {
  450. if (Convert.ToDecimal(_GroupCostParameter.GWCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  451. {
  452. grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  453. grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  454. grp_CreditCard.AuditGMOperate = 21;
  455. grp_CreditCard.AuditGMDate = "";
  456. grp_CreditCard.IsPay = 0;
  457. }
  458. else
  459. {
  460. var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.GWCB);
  461. var b = a / Convert.ToDecimal(_GroupCostParameter.GWCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  462. grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  463. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  464. grp_CreditCard.AuditGMOperate = 21;
  465. grp_CreditCard.AuditGMDate = "";
  466. grp_CreditCard.IsPay = 0;
  467. }
  468. }
  469. else
  470. {
  471. grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  472. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  473. grp_CreditCard.AuditGMOperate = 21;
  474. grp_CreditCard.AuditGMDate = "";
  475. grp_CreditCard.IsPay = 0;
  476. }
  477. }
  478. else
  479. {
  480. grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  481. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  482. grp_CreditCard.AuditGMOperate = 21;
  483. grp_CreditCard.AuditGMDate = "";
  484. grp_CreditCard.IsPay = 0;
  485. }
  486. grp_CreditCard.CId = id;
  487. grp_CreditCard.CTable = 85;
  488. grp_CreditCard.PayPercentage = 100;
  489. //查询上一次付款信息
  490. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().OrderByDescending(x => x.CreateUserId).First(a => a.DIId == grp_AirTicket.DIId && a.IsDel == 0 && a.IsPay == 1);
  491. if (_CreditCardPayment != null)
  492. {
  493. grp_CreditCard.PayPercentageOld = _CreditCardPayment.PayPercentageOld;// 上次付款百分比 查询并计算最近一次
  494. grp_CreditCard.PayThenMoneyOld = _CreditCardPayment.PayMoney;// 上次付款金额 查询上一次
  495. grp_CreditCard.UpdateDate = _CreditCardPayment.UpdateDate;// 上次付款时间 查询上一次
  496. }
  497. else
  498. {
  499. grp_CreditCard.PayPercentageOld = 0;// 上次付款百分比 查询并计算最近一次
  500. grp_CreditCard.PayThenMoneyOld = 0;// 上次付款金额 查询上一次
  501. grp_CreditCard.UpdateDate = "";// 上次付款时间 查询上一次
  502. }
  503. id = await _sqlSugar.Insertable(grp_CreditCard).ExecuteReturnIdentityAsync();
  504. if (id == 0)
  505. {
  506. RollbackTran();
  507. return result = new Result() { Code = -1, Msg = "添加失败!" };
  508. }
  509. await UpdateAsync(a => a.Id == id, a => new Grp_AirTicketReservations
  510. {
  511. FlightsDescription = dto.AirTicketResOpData.FlightsDescription,
  512. });
  513. CommitTran();
  514. return result = new Result() { Code = 0, Msg = "添加成功!" };
  515. //C表操作
  516. }
  517. else
  518. {
  519. RollbackTran();
  520. return result = new Result() { Code = -1, Msg = "添加失败!" };
  521. }
  522. }
  523. else if (dto.Status == 2)
  524. {
  525. id = dto.AirTicketResOpData.Id;
  526. bool res = await UpdateAsync(a => a.Id == dto.AirTicketResOpData.Id, a => new Grp_AirTicketReservations
  527. {
  528. CType = dto.AirTicketResOpData.CType,
  529. PrePrice = dto.AirTicketResOpData.PrePrice,
  530. PreCurrency = dto.AirTicketResOpData.PreCurrency,
  531. Price = dto.AirTicketResOpData.Price,
  532. Currency = dto.AirTicketResOpData.Currency,
  533. ClientNum = dto.AirTicketResOpData.ClientNum,
  534. ClientName = dto.AirTicketResOpData.ClientName,
  535. IsCheckIn = dto.AirTicketResOpData.IsCheckIn,
  536. IsSetSeat = dto.AirTicketResOpData.IsSetSeat,
  537. IsPackage = dto.AirTicketResOpData.IsPackage,
  538. IsBagHandle = dto.AirTicketResOpData.IsBagHandle,
  539. IsTrain = dto.AirTicketResOpData.IsTrain,
  540. FlightsCode = dto.AirTicketResOpData.FlightsCode,
  541. FlightsCity = dto.AirTicketResOpData.FlightsCity,
  542. FlightsDescription = dto.AirTicketResOpData.FlightsDescription,
  543. PriceDescription = dto.AirTicketResOpData.PriceDescription,
  544. TicketNumber = dto.AirTicketResOpData.TicketNumber,
  545. TicketCode = dto.AirTicketResOpData.TicketCode,
  546. Remark = dto.AirTicketResOpData.Remark,
  547. });
  548. if (!res){result = new Result() { Code = -1, Msg = "修改失败!" }; }
  549. else { result = new Result() { Code = 0, Msg = "修改成功!" }; }
  550. if (result.Code == 0)
  551. {
  552. //C表操作
  553. Grp_CreditCardPayment grp_CreditCard = _mapper.Map<Grp_CreditCardPayment>(dto.CardPaymentOpData);
  554. //换算
  555. Grp_TeamRate _TeamRate = _sqlSugar.Queryable<Grp_TeamRate>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0 && a.CTable == 85);
  556. if (_TeamRate != null)
  557. {
  558. if (grp_CreditCard.PaymentCurrency == 49)
  559. {
  560. grp_CreditCard.DayRate = _TeamRate.RateU;
  561. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateU);
  562. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateU);
  563. }
  564. else if (grp_CreditCard.PaymentCurrency == 51)
  565. {
  566. grp_CreditCard.DayRate = _TeamRate.RateE;
  567. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney * Convert.ToDecimal(_TeamRate.RateE);
  568. //ccp.PayMoney = ccp.PayMoney * float.Parse(tr.RateE);
  569. }
  570. else
  571. {
  572. grp_CreditCard.DayRate = 1M;
  573. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  574. }
  575. }
  576. else
  577. {
  578. grp_CreditCard.DayRate = 1M;
  579. grp_CreditCard.RMBPrice = grp_CreditCard.PayMoney;
  580. }
  581. //grp_CreditCard.PayMoney = grp_CreditCard.PayMoney;
  582. //判断是否超出成本
  583. Grp_GroupCostParameter _GroupCostParameter = _sqlSugar.Queryable<Grp_GroupCostParameter>().First(a => a.DiId == grp_AirTicket.DIId && a.IsDel == 0);
  584. if (grp_AirTicket.CType == 460)//经济舱
  585. {
  586. if (_GroupCostParameter != null)
  587. {
  588. if (Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  589. {
  590. grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  591. grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  592. grp_CreditCard.AuditGMOperate = 0;
  593. grp_CreditCard.AuditGMDate = "";
  594. grp_CreditCard.IsPay = 1;
  595. }
  596. else
  597. {
  598. var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.JJCCB);
  599. var b = a / Convert.ToDecimal(_GroupCostParameter.JJCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  600. grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  601. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  602. grp_CreditCard.AuditGMOperate = 21;
  603. grp_CreditCard.AuditGMDate = "";
  604. grp_CreditCard.IsPay = 1;
  605. }
  606. }
  607. else
  608. {
  609. grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  610. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  611. grp_CreditCard.AuditGMOperate = 21;
  612. grp_CreditCard.AuditGMDate = "";
  613. grp_CreditCard.IsPay = 0;
  614. }
  615. }
  616. else if (grp_AirTicket.CType == 458)
  617. {
  618. if (_GroupCostParameter != null)
  619. {
  620. }
  621. else
  622. {
  623. grp_CreditCard.ExceedBudget = 0.00M;// 超出预算比例 换算
  624. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  625. grp_CreditCard.AuditGMOperate = 21;
  626. grp_CreditCard.AuditGMDate = "";
  627. grp_CreditCard.IsPay = 0;
  628. }
  629. if (Convert.ToDecimal(_GroupCostParameter.GWCCB) * Convert.ToDecimal(grp_AirTicket.ClientNum) > grp_CreditCard.RMBPrice)
  630. {
  631. grp_CreditCard.ExceedBudget = 0;// 超出预算比例 换算
  632. grp_CreditCard.IsAuditGM = 3;//3 为自动审核
  633. grp_CreditCard.AuditGMOperate = 21;
  634. grp_CreditCard.AuditGMDate = "";
  635. grp_CreditCard.IsPay = 1;
  636. }
  637. else
  638. {
  639. var a = grp_CreditCard.RMBPrice - Convert.ToDecimal(_GroupCostParameter.GWCB);
  640. var b = a / Convert.ToDecimal(_GroupCostParameter.GWCB) * Convert.ToDecimal(grp_AirTicket.ClientNum);
  641. grp_CreditCard.ExceedBudget = b;// 超出预算比例 换算
  642. grp_CreditCard.IsAuditGM = 0;//3 为自动审核
  643. grp_CreditCard.AuditGMOperate = 21;
  644. grp_CreditCard.AuditGMDate = "";
  645. grp_CreditCard.IsPay = 1;
  646. }
  647. }
  648. grp_CreditCard.CId = id;
  649. grp_CreditCard.CTable = 85;
  650. grp_CreditCard.PayPercentage = 100;
  651. //查询上一次付款信息
  652. Grp_CreditCardPayment _CreditCardPayment = _sqlSugar.Queryable<Grp_CreditCardPayment>().OrderByDescending(x => x.CreateUserId).First(a => a.DIId == grp_AirTicket.DIId && a.IsDel == 0 && a.IsPay == 1);
  653. if (_CreditCardPayment != null)
  654. {
  655. grp_CreditCard.PayPercentageOld = _CreditCardPayment.PayPercentageOld;// 上次付款百分比 查询并计算最近一次
  656. grp_CreditCard.PayThenMoneyOld = _CreditCardPayment.PayMoney;// 上次付款金额 查询上一次
  657. grp_CreditCard.UpdateDate = _CreditCardPayment.UpdateDate;// 上次付款时间 查询上一次
  658. }
  659. else
  660. {
  661. grp_CreditCard.PayPercentageOld = 0;// 上次付款百分比 查询并计算最近一次
  662. grp_CreditCard.PayThenMoneyOld = 0;// 上次付款金额 查询上一次
  663. grp_CreditCard.UpdateDate = "";// 上次付款时间 查询上一次
  664. }
  665. int CTable = await _sqlSugar.Updateable<Grp_CreditCardPayment>().Where(a => a.Id == dto.CardPaymentOpData.Id).SetColumns(a => new Grp_CreditCardPayment
  666. {
  667. PayDId = grp_CreditCard.PayDId,
  668. ConsumptionPatterns = grp_CreditCard.ConsumptionPatterns,
  669. ConsumptionDate = grp_CreditCard.ConsumptionDate,
  670. CTDId = grp_CreditCard.CTDId,
  671. BankNo = grp_CreditCard.BankNo,
  672. CardholderName = grp_CreditCard.CardholderName,
  673. PayMoney = grp_CreditCard.PayMoney,
  674. PaymentCurrency = grp_CreditCard.PaymentCurrency,
  675. DayRate = grp_CreditCard.DayRate,
  676. CompanyBankNo = grp_CreditCard.CompanyBankNo,
  677. OtherBankName = grp_CreditCard.OtherBankName,
  678. OtherSideNo = grp_CreditCard.OtherSideNo,
  679. OtherSideName = grp_CreditCard.OtherSideName,
  680. IsAuditGM = grp_CreditCard.IsAuditGM,
  681. AuditGMOperate = grp_CreditCard.AuditGMOperate,
  682. AuditGMDate = grp_CreditCard.AuditGMDate,
  683. IsPay = grp_CreditCard.IsPay,
  684. PayPercentage = grp_CreditCard.PayPercentage,
  685. PayThenMoney = grp_CreditCard.PayThenMoney,
  686. PayPercentageOld = grp_CreditCard.PayPercentageOld,
  687. PayThenMoneyOld = grp_CreditCard.PayThenMoneyOld,
  688. UpdateDate = grp_CreditCard.UpdateDate,
  689. Payee = grp_CreditCard.Payee,
  690. RMBPrice = grp_CreditCard.RMBPrice,
  691. OrbitalPrivateTransfer = grp_CreditCard.OrbitalPrivateTransfer,
  692. ExceedBudget = grp_CreditCard.ExceedBudget,
  693. Remark= grp_CreditCard.Remark,
  694. }).ExecuteCommandAsync();
  695. if (CTable == 0)
  696. {
  697. RollbackTran();
  698. return result = new Result() { Code = -1, Msg = "修改失败!" };
  699. }
  700. else
  701. {
  702. result = new Result() { Code = 0, Msg = "修改成功!" };
  703. }
  704. }
  705. else
  706. {
  707. result = new Result() { Code = -1, Msg = "修改失败!" };
  708. RollbackTran();
  709. }
  710. }
  711. CommitTran();
  712. }
  713. catch (Exception ex)
  714. {
  715. RollbackTran();
  716. return result = new Result() { Code = -2, Msg = "程序错误" };
  717. throw;
  718. }
  719. return result;
  720. }
  721. /// <summary>
  722. /// 导出机票费用报表
  723. /// </summary>
  724. /// <param name="dto"></param>
  725. /// <returns></returns>
  726. /// <exception cref="NotImplementedException"></exception>
  727. public async Task<Result> DeriveAirTicketRes(AirTicketResDto dto)
  728. {
  729. Result result = new Result() { Code = -2, Msg = "未知错误" };
  730. try
  731. {
  732. string sql = string.Format(@"select d.TourCode,d.TeamName,a.FlightsCity,a.FlightsCode,a.FlightsDescription,(select Name from Sys_SetData where Id=a.cType) as 'CTypeName',a.ClientName,a.ClientNum,
  733. a.PrePrice,a.Price,(select Name from Sys_SetData where Id=c.PayDId) as 'PayType', case when
  734. c.OrbitalPrivateTransfer=0 then '公转' when c.OrbitalPrivateTransfer=1 then '私转' end as OrbitalPrivateTransfer,c.BankNo,c.CreateTime,
  735. c.Payee,a.PriceDescription,(select Name from Sys_SetData where Id=a.Currency) as 'CurrencyStr',(select Name from Sys_SetData where Id=c.CTDId) as BankType
  736. from Grp_AirTicketReservations a,Grp_CreditCardPayment c ,Grp_DelegationInfo d where a.id=c.CId and d.Id=a.DIId and a.isdel=0
  737. and a.DIId={0} Order By a.CreateTime desc", dto.DiId, 0);
  738. List<AirTicketReservationsPayView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsPayView>(sql).ToList();
  739. if (_AirTicketReservations.Count != 0)
  740. {
  741. Grp_DelegationInfo grp_Delegation = _sqlSugar.Queryable<Grp_DelegationInfo>().First(a => a.Id == dto.DiId && a.IsDel == 0);
  742. Sys_Users _Users = _sqlSugar.Queryable<Sys_Users>().First(a => a.Id == dto.UserId && a.IsDel == 0);
  743. return result = new Result() { Code = 0, Msg = "成功", Data = new { Delegation = grp_Delegation, AirTicketRes = _AirTicketReservations, Users = _Users } };
  744. }
  745. else
  746. {
  747. return result = new Result() { Code = -1, Msg = "暂无数据", Data = null };
  748. }
  749. }
  750. catch (Exception)
  751. {
  752. return result = new Result() { Code = -2, Msg = "未知错误" };
  753. }
  754. }
  755. public async Task<Result> ItineraryAirTicketRes(ItineraryAirTicketResDto dto)
  756. {
  757. Result result = new Result() { Code = -2, Msg = "未知错误" };
  758. try
  759. {
  760. string sql = string.Format(@"select a.*,c.IsAuditGM,(select Name from Sys_SetData where Id=a.cType) as 'CTypeName',(select Name from
  761. Sys_SetData where Id=a.PreCurrency) as 'PreCurrencyStr',(select Name from Sys_SetData where Id=a.Currency)
  762. as 'CurrencyStr' from Grp_AirTicketReservations a,Grp_CreditCardPayment c where a.id=c.CId and a.isdel={1}
  763. and a.DIId={0} Order By a.CreateTime desc", dto.DiId, 0);
  764. List<AirTicketReservationsView> _AirTicketReservations = _sqlSugar.SqlQueryable<AirTicketReservationsView>(sql).ToList();
  765. if (_AirTicketReservations.Count == 0)
  766. {
  767. return result = new Result() { Code = -1, Msg = "暂无数据", Data = null };
  768. }
  769. else
  770. {
  771. return result = new Result() { Code = 0, Msg = "查询成功", Data = _AirTicketReservations };
  772. }
  773. }
  774. catch (Exception)
  775. {
  776. return result = new Result() { Code = -2, Msg = "未知错误" };
  777. throw;
  778. }
  779. }
  780. public List<TranslateResult> ReTransBatch(List<string> list, string aimlanguage)
  781. {
  782. List<TranslateResult> reultStr = new List<TranslateResult>();
  783. if (list.Count < 0)
  784. {
  785. return reultStr;
  786. }
  787. //待翻译内容,必须是UTF-8编码
  788. string q = "";
  789. string Qtext = "";
  790. foreach (var item in list)
  791. {
  792. q += item;
  793. Qtext += "q=" + item + "&";
  794. }
  795. if (Qtext.Length > 0)
  796. {
  797. Qtext = Qtext.Substring(0, Qtext.Length - 1);
  798. }
  799. Dictionary<string, string> dic = new Dictionary<string, string>();
  800. string url = "https://openapi.youdao.com/v2/api";
  801. //应用ID
  802. string appKey = "0fe3bc01e109ed36";
  803. //应用应用密钥
  804. string appSecret = "1f2x9TrqJfSBEJ8iH9GEFGgTyaYGjEry";
  805. //UUID
  806. string salt = DateTime.Now.Millisecond.ToString();
  807. //源语言
  808. dic.Add("from", "zh-CHS");
  809. //目标语言
  810. dic.Add("to", aimlanguage);
  811. //签名类型
  812. dic.Add("signType", "v3");
  813. //时间戳
  814. string curtime = ((GetBeijingTime().ToUniversalTime().Ticks - 621355968000000000) / 10000000).ToString();
  815. dic.Add("curtime", curtime);
  816. string signStr = appKey + Truncate(q) + salt + curtime + appSecret; ;
  817. string sign = ComputeHash(signStr, new SHA256CryptoServiceProvider());
  818. dic.Add("q", Qtext);
  819. dic.Add("appKey", appKey);
  820. dic.Add("salt", salt);
  821. dic.Add("sign", sign);
  822. string jsonStr = "";
  823. try
  824. {
  825. //Thread.Sleep(500);
  826. jsonStr = TransSync(url, dic);
  827. JObject trans = (JObject)JsonConvert.DeserializeObject(jsonStr);
  828. string errorCode = trans["errorCode"].ToString();
  829. if (errorCode == "0")
  830. {
  831. reultStr = JsonConvert.DeserializeObject<List<TranslateResult>>(trans["translateResults"].ToString());
  832. }
  833. return reultStr;
  834. }
  835. catch (Exception ex)
  836. {
  837. string msg = ex.Message;
  838. return reultStr;
  839. }
  840. }
  841. public string Processing(string str)//处理这段英文的方法
  842. {
  843. if (string.IsNullOrEmpty(str)) { return ""; }
  844. string[] strArray = new string[] { };
  845. if (str.Contains(" ")) strArray = str.Split(" ".ToCharArray());
  846. else if (str.Contains(",")) strArray = str.Split(",".ToCharArray());
  847. else if (str.Contains(" ") && str.Contains(",")) strArray = str.Split(",".ToCharArray());
  848. else strArray = new string[] { str };
  849. string result = string.Empty;//定义一个空字符串
  850. foreach (string s in strArray)//循环处理数组里面每一个字符串
  851. {
  852. //result += System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(s) + " ";
  853. result += s.Substring(0, 1).ToUpper() + s.Substring(1) + " ";
  854. //.Substring(0, 1).ToUpper()把循环到的字符串第一个字母截取并转换为大写,并用s.Substring(1)得到循环到的字符串除第一个字符后的所有字符拼装到首字母后面。
  855. }
  856. return result;
  857. }
  858. protected string TransSync(string url, Dictionary<string, string> dic)
  859. {
  860. string result = "";
  861. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
  862. req.Method = "POST";
  863. req.ContentType = "application/x-www-form-urlencoded";
  864. StringBuilder builder = new StringBuilder();
  865. int i = 0;
  866. foreach (var item in dic)
  867. {
  868. if (i > 0)
  869. builder.Append("&");
  870. if (item.Key == "q")
  871. {
  872. builder.AppendFormat(item.Value);
  873. }
  874. else
  875. {
  876. builder.AppendFormat("{0}={1}", item.Key, item.Value);
  877. }
  878. i++;
  879. }
  880. byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
  881. req.ContentLength = data.Length;
  882. using (Stream reqStream = req.GetRequestStream())
  883. {
  884. reqStream.Write(data, 0, data.Length);
  885. reqStream.Close();
  886. }
  887. HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
  888. if (resp.ContentType.ToLower().Equals("audio/mp3"))
  889. {
  890. SaveBinaryFile(resp, "合成的音频存储路径");
  891. }
  892. else
  893. {
  894. Stream stream = resp.GetResponseStream();
  895. using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
  896. {
  897. result = reader.ReadToEnd();
  898. }
  899. }
  900. return result;
  901. }
  902. private static bool SaveBinaryFile(WebResponse response, string FileName)
  903. {
  904. string FilePath = FileName + DateTime.Now.Millisecond.ToString() + ".mp3";
  905. bool Value = true;
  906. byte[] buffer = new byte[1024];
  907. try
  908. {
  909. if (File.Exists(FilePath))
  910. File.Delete(FilePath);
  911. Stream outStream = File.Create(FilePath);
  912. Stream inStream = response.GetResponseStream();
  913. int l;
  914. do
  915. {
  916. l = inStream.Read(buffer, 0, buffer.Length);
  917. if (l > 0)
  918. outStream.Write(buffer, 0, l);
  919. }
  920. while (l > 0);
  921. outStream.Close();
  922. inStream.Close();
  923. }
  924. catch
  925. {
  926. Value = false;
  927. }
  928. return Value;
  929. }
  930. protected static string ComputeHash(string input, HashAlgorithm algorithm)
  931. {
  932. byte[] inputBytes = Encoding.UTF8.GetBytes(input);
  933. byte[] hashedBytes = algorithm.ComputeHash(inputBytes);
  934. return BitConverter.ToString(hashedBytes).Replace("-", "");
  935. }
  936. protected static string Truncate(string q)
  937. {
  938. if (q == null)
  939. {
  940. return null;
  941. }
  942. int len = q.Length;
  943. return len <= 20 ? q : q.Substring(0, 10) + len + q.Substring(len - 10, 10);
  944. }
  945. public static DateTime GetBeijingTime()
  946. {
  947. WebRequest request = null;
  948. WebResponse response = null;
  949. WebHeaderCollection headerCollection = null;
  950. string datetime = string.Empty;
  951. try
  952. {
  953. request = WebRequest.Create("https://www.baidu.com");
  954. request.Timeout = 3000;
  955. request.Credentials = CredentialCache.DefaultCredentials;
  956. response = request.GetResponse();
  957. headerCollection = response.Headers;
  958. foreach (var h in headerCollection.AllKeys)
  959. {
  960. if (h == "Date")
  961. {
  962. datetime = headerCollection[h];
  963. }
  964. }
  965. return Convert.ToDateTime(datetime);
  966. }
  967. catch (Exception)
  968. {
  969. return DateTime.Now;
  970. }
  971. finally
  972. {
  973. if (request != null)
  974. {
  975. request.Abort();
  976. }
  977. if (response != null)
  978. {
  979. response.Close();
  980. }
  981. if (headerCollection != null)
  982. {
  983. headerCollection.Clear();
  984. }
  985. }
  986. }
  987. public class TranslateResult
  988. {
  989. public string Query { get; set; }
  990. public string Translation { get; set; }
  991. public string Type { get; set; }
  992. public string VerifyResult { get; set; }
  993. }
  994. }
  995. }