Form1.cs 247 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710
  1. using Aspose.Words;
  2. using DAL;
  3. using Models;
  4. using Newtonsoft.Json.Linq;
  5. using OA2014.publicCode;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.ComponentModel;
  9. using System.Configuration;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.IO;
  13. using System.Linq;
  14. using System.Security.Cryptography;
  15. using System.Text;
  16. using System.Text.RegularExpressions;
  17. using System.Threading.Tasks;
  18. using System.Web;
  19. using System.Web.Util;
  20. using System.Windows.Forms;
  21. using System.Xml.Linq;
  22. namespace WinTools
  23. {
  24. public partial class OPTravelListOutput : Form
  25. {
  26. //团组信息DAL
  27. DelegationInfoService dis = new DelegationInfoService();
  28. //三字码DAL
  29. ThreeCodeServices tcs = new ThreeCodeServices();
  30. //航司缩写DAL
  31. AirCompanyServcies acs = new AirCompanyServcies();
  32. //车导地接DAL
  33. CarTouristGuideGroundReservationsService ctgs = new CarTouristGuideGroundReservationsService();
  34. //车导地接详情DAL
  35. CarTouristGuideGroundReservationsContentService ctgss = new CarTouristGuideGroundReservationsContentService();
  36. //公务
  37. OfficialActivitiesService oas = new OfficialActivitiesService();
  38. //酒店信息DAL
  39. HotelReservationsService htrs = new HotelReservationsService();
  40. //行程详情DAL
  41. TravelDetailsService tds = new TravelDetailsService();
  42. //行程单DAL
  43. TravelListService tls = new TravelListService();
  44. //谷歌地图接口结果DAL
  45. GoogleMapApiResultService gmrs = new GoogleMapApiResultService();
  46. string[] weekdays = new string[] { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
  47. public OPTravelListOutput()
  48. {
  49. InitializeComponent();
  50. }
  51. private void Form1_Load(object sender, EventArgs e)
  52. {
  53. comb_Delegation.ValueMember = "Id";
  54. comb_Delegation.DisplayMember = "TeamName";
  55. comb_Delegation.DataSource = dis.GetAll();
  56. }
  57. private void btnOutput_Click(object sender, EventArgs e)
  58. {
  59. lblOutputResult.Text = "文件正在导出...";
  60. lblOutputResult.ForeColor = Color.Black;
  61. //数据源
  62. List<TravelList> _travelList = new List<TravelList>();
  63. int diid = (int)comb_Delegation.SelectedValue;
  64. DataTable dtBlack = PublicCode.GetTableByBlackCode(diid);
  65. DelegationInfo di = dis.GetDelegationInfoByID(diid);
  66. string CityStr1 = "";
  67. List<string> countriesList = new List<string>();
  68. List<string> cityList = new List<string>();
  69. string countriesIntroduction = "";
  70. string cityIntroduction = "";
  71. string timeDifference = "";
  72. string currExchangeRate = "";
  73. string txt_itemPrepare = "";
  74. string txt_specialReminder = "";
  75. string txt_cGPrecautions = "";
  76. string txt_yGCG = "";
  77. string txt_conduct = "";
  78. string txt_commonEnglish = "";
  79. if (dtBlack == null && (dtBlack.Rows[0]["Day"] == null || dtBlack.Rows[0]["Day"].ToString() == ""))
  80. {
  81. //提示
  82. //PublicCode.GetAlertMsg(this, GetType(), dt.Rows[dt.Rows.Count - 1]["Error"].ToString());
  83. }
  84. else
  85. {
  86. //创建三字码示例
  87. ThreeCode t = new ThreeCode();
  88. //城市缓存
  89. string city = "";
  90. //出访城市
  91. for (int i = 0; i < dtBlack.Rows.Count; i++)
  92. {
  93. if ((i + 1) < dtBlack.Rows.Count && dtBlack.Rows[i]["Three"].ToString() == dtBlack.Rows[i + 1]["Three"].ToString())
  94. {
  95. continue;
  96. }
  97. if (dtBlack.Rows.Count > 0 && (dtBlack.Rows[i]["Three"].ToString() != null && dtBlack.Rows[i]["Three"].ToString() != ""))
  98. {
  99. //出发城市
  100. string cityTemp = dtBlack.Rows[i]["Three"].ToString().Replace("/", string.Empty).Substring(0, 3);
  101. t = tcs.getByThree(cityTemp);
  102. if (t != null)
  103. {
  104. city = city + "/" + t.City;
  105. }
  106. else
  107. {
  108. city = city + "/【" + cityTemp + "未收录,请联系机票同事录入】";
  109. }
  110. if (i == dtBlack.Rows.Count - 1)
  111. {
  112. //抵达城市
  113. cityTemp = dtBlack.Rows[i]["Three"].ToString().Replace("/", string.Empty).Substring(3, 3);
  114. t = tcs.getByThree(cityTemp);
  115. if (t != null)
  116. {
  117. city = city + "/" + t.City;
  118. }
  119. else
  120. {
  121. city = city + "/【" + cityTemp + "未收录,请联系机票同事录入】";
  122. }
  123. }
  124. }
  125. }
  126. if (city != "" && city != null)
  127. {
  128. string[] cityStr2 = city.Split('/');
  129. string[] strs = cityStr2.Distinct().ToArray(); ;
  130. string str = "";
  131. foreach (var s in strs)
  132. {
  133. str += s + "/";
  134. }
  135. str = str.TrimStart('/');
  136. str = str.TrimEnd('/');
  137. //lblTourCity.Text = "去重前:" + city.TrimStart('/') + "\n 去重后:" + str;
  138. CityStr1 = city.TrimStart('/');
  139. }
  140. opitineraryService opitservice = new opitineraryService();
  141. //城市不为空
  142. if (!string.IsNullOrEmpty(city))
  143. {
  144. cityList = city.TrimStart('/').Split('/').ToList();
  145. if (cityList.Count > 1)
  146. {
  147. cityList.RemoveAt(0);
  148. }
  149. opitinerarydata cityData = opitservice.getDaFirstData(cityList[0]);
  150. cityIntroduction = cityData.Introduction;
  151. timeDifference = cityData.TimeDifference;
  152. currExchangeRate = cityData.CurrExchangeRate.ToString();
  153. }
  154. //国家不为空
  155. if (!string.IsNullOrEmpty(di.VisitCountry))
  156. {
  157. countriesList = di.VisitCountry.Split(' ').ToList();
  158. opitinerarydata Country = opitservice.getDaFirstData(countriesList[0]);
  159. countriesIntroduction = Country.Introduction == null ? "" : Country.Introduction;
  160. }
  161. //取出固定标语
  162. opitineraryfixed fixedData = opitservice.getFiFirstData();
  163. //if (!string.IsNullOrEmpty(fixedData.Tid.ToString()))
  164. //{
  165. //}
  166. txt_cGPrecautions = fixedData.CGPrecautions;
  167. txt_commonEnglish = fixedData.CommonEnglish;
  168. txt_conduct = fixedData.Conduct;
  169. txt_itemPrepare = fixedData.ItemPrepare;
  170. txt_specialReminder = fixedData.SpecialReminder;
  171. txt_yGCG = fixedData.YGCG;
  172. // 行程repeater
  173. if (tls.GetByDiid(diid).Count > 0)
  174. {
  175. _travelList = tls.GetByDiid(diid).Where(x => x.issel == 1).ToList();
  176. }
  177. else
  178. {
  179. //生成该时间段日期
  180. List<string> timeList = PublicCode.GetTimeListByDataTable(dtBlack);
  181. if (timeList != null)
  182. {
  183. string[] str = new string[timeList.Count];
  184. //rpData.DataSource = str;
  185. //rpData.DataBind();
  186. }
  187. }
  188. }
  189. //创建数据源Table
  190. DataTable dtSource = new DataTable();
  191. dtSource.Columns.Add("Days", typeof(string));
  192. dtSource.Columns.Add("Date", typeof(string));
  193. dtSource.Columns.Add("Week", typeof(string));
  194. dtSource.Columns.Add("Traffic", typeof(string));
  195. dtSource.Columns.Add("Trip", typeof(string));
  196. //获取数据,放到datatable
  197. foreach (var item in _travelList)
  198. {
  199. DataRow dr = dtSource.NewRow();
  200. dr["Days"] = item.Days;
  201. dr["Date"] = item.Date;
  202. dr["Week"] = item.WeekDay;
  203. dr["Traffic"] = item.Traffic_First
  204. + "\r\n"
  205. + item.Traffic_Second;
  206. dr["Trip"] = item.Trip;
  207. dtSource.Rows.Add(dr);
  208. }
  209. //lblTeamName.Text = di.TourCode;
  210. //lblVisitDays.Text = di.VisitDays.ToString();
  211. //lblVisitDays2.Text = di.VisitDays.ToString();
  212. //lblPNumber.Text = di.VisitPNumber.ToString();
  213. //lblGroup.Text = di.TeamName.ToString();
  214. Dictionary<string, string> dic = new Dictionary<string, string>();
  215. dic.Add("Dele", di.TeamName.ToString() + PublicCode.GetNum(di.VisitDays.ToString()));
  216. dic.Add("City", CityStr1);
  217. dic.Add("Days", di.VisitDays.ToString());
  218. dic.Add("DeleCode", di.TourCode);
  219. dic.Add("Pnum", di.VisitPNumber.ToString());
  220. dic.Add("Pnum2", di.VisitPNumber.ToString());
  221. List<DeleClient> leader = new DeleClientService().GetByDiid(di.Id);
  222. if (leader != null && leader.Count > 0)
  223. {
  224. dic.Add("Leader", new DeleClientService().GetByDiid(di.Id)[0].LastName + new DeleClientService().GetByDiid(di.Id)[0].Name);
  225. }
  226. else
  227. {
  228. dic.Add("Leader", "");
  229. }
  230. dic.Add("Pnum3", di.VisitPNumber.ToString());
  231. int UserId = int.Parse(ConfigurationManager.AppSettings["OPId"]);
  232. dic.Add("OP", new UsersService().GetUsersByID(UserId).CnName);
  233. dic.Add("OPTel", new UsersService().GetUsersByID(UserId).Phone);
  234. //dic.Add("OP", "OP姓名");
  235. //dic.Add("OPTel", "OP手机号码");
  236. string countriesStr = "";
  237. countriesList.ForEach(s => countriesStr += s + "、");
  238. countriesStr = countriesStr.TrimEnd('、');
  239. string cityStr = "";
  240. cityList.ForEach(s => cityStr += s + "、");
  241. cityStr = cityStr.TrimEnd('、');
  242. //下方数据
  243. dic.Add("selCountries", countriesStr == null ? "" : countriesStr);
  244. dic.Add("selCity", cityStr == null ? "" : cityStr);
  245. dic.Add("countriesIntroduction", countriesIntroduction == null ? "" : countriesIntroduction);
  246. dic.Add("CityIntroduction", cityIntroduction == null ? "" : cityIntroduction);
  247. dic.Add("timeDifference", timeDifference == null ? "" : timeDifference);
  248. dic.Add("currExchangeRate", currExchangeRate == null ? "" : currExchangeRate);
  249. dic.Add("temperature", "");
  250. dic.Add("txt_itemPrepare", txt_itemPrepare == null ? "" : txt_itemPrepare);
  251. dic.Add("txt_specialReminder", txt_specialReminder == null ? "" : txt_specialReminder);
  252. dic.Add("txt_cGPrecautions", txt_cGPrecautions == null ? "" : txt_cGPrecautions);
  253. dic.Add("txt_yGCG", txt_yGCG == null ? "" : txt_yGCG);
  254. dic.Add("txt_conduct", txt_conduct == null ? "" : txt_conduct);
  255. dic.Add("txt_commonEnglish", txt_commonEnglish == null ? "" : txt_commonEnglish);
  256. //模板路径
  257. string tempPath = @"D:\日行程3.docx";
  258. //载入模板
  259. Document doc = new Document(tempPath);
  260. DocumentBuilder builder = new DocumentBuilder(doc);
  261. foreach (var key in dic.Keys)
  262. {
  263. builder.MoveToBookmark(key);
  264. builder.Write(dic[key]);
  265. }
  266. //获取word里所有表格
  267. NodeCollection allTables = doc.GetChildNodes(NodeType.Table, true);
  268. //获取所填表格的序数
  269. Aspose.Words.Tables.Table tableOne = allTables[0] as Aspose.Words.Tables.Table;
  270. try
  271. {
  272. //循环赋值
  273. for (int i = 0; i < dtSource.Rows.Count; i++)
  274. {
  275. builder.MoveToCell(0, i + 1, 0, 0);
  276. builder.Write(dtSource.Rows[i]["Days"].ToString());
  277. builder.MoveToCell(0, i + 1, 1, 0);
  278. builder.Write(dtSource.Rows[i]["Date"].ToString() + "\r\n" + dtSource.Rows[i]["Week"].ToString());
  279. builder.MoveToCell(0, i + 1, 2, 0);
  280. builder.Write(dtSource.Rows[i]["Traffic"].ToString());
  281. builder.MoveToCell(0, i + 1, 3, 0);
  282. builder.Write(dtSource.Rows[i]["Trip"].ToString());
  283. }
  284. }
  285. catch (Exception ex)
  286. {
  287. }
  288. //删除多余行
  289. while (tableOne.Rows.Count > 1 + dtSource.Rows.Count)
  290. {
  291. tableOne.Rows.RemoveAt(1 + dtSource.Rows.Count);//(1+dtSource.Rows.Count + 1)-1
  292. }
  293. string savePath = ConfigurationManager.AppSettings["TravelListDocSavePath"];
  294. if (!Directory.Exists(savePath))
  295. {
  296. try
  297. {
  298. Directory.CreateDirectory(savePath);
  299. }
  300. catch
  301. {
  302. }
  303. }
  304. string strFileName = savePath + di.TeamName + "出访日程.docx";
  305. doc.Save(strFileName, Aspose.Words.SaveFormat.Doc);
  306. lblOutputResult.Text = "文件导出完成";
  307. lblOutputResult.ForeColor = Color.Green;
  308. System.Diagnostics.Process.Start("Explorer.exe", "/select," + strFileName);
  309. //doc.Save(HttpUtility.UrlEncode(strFileName, Encoding.UTF8), Aspose.Words.SaveFormat.Doc, Aspose.Words.SaveType.OpenInWord, Response);
  310. }
  311. private void btnImport_Click(object sender, EventArgs e)
  312. {
  313. lblImport.Text = "";
  314. lblImport.Text = "正在导入数据";
  315. int comb_Diid = (int)comb_Delegation.SelectedValue;
  316. int UserId = int.Parse(ConfigurationManager.AppSettings["OPId"]);
  317. //下拉框团组对象实例
  318. DelegationInfo di = dis.GetDelegationInfoByID(comb_Diid);
  319. //获取机票黑屏代码信息,生成datatable表
  320. DataTable dt = PublicCode.GetTableByBlackCode(di.Id);
  321. //通过datatable表里的第一个字段的信息来判断是否有黑屏代码
  322. //没有则提示未录入
  323. if (dt.Rows[0]["Day"] == null || dt.Rows[0]["Day"].ToString() == "")
  324. {
  325. //PublicCode.GetAlertMsg(this, GetType(), dt.Rows[dt.Rows.Count - 1]["Error"].ToString());
  326. lblImport.Text = "黑屏代码未录入";
  327. }
  328. else//成功获取黑屏代码
  329. {
  330. //根据黑屏代码生成日期段
  331. List<string> timeList = PublicCode.GetTimeListByDataTable(dt);
  332. //本团车导地接信息
  333. List<CarTouristGuideGroundReservations> listctg = ctgs.GetCarTouristGuideGroundReservationsByDIID(di.Id);
  334. //本团酒店信息
  335. List<HotelReservations> listht = htrs.GetByDIId(di.Id);
  336. //本团行程单数据
  337. List<Models.TravelList> listTravel = tls.GetByDiid(di.Id);
  338. try
  339. {
  340. if (listTravel != null && listTravel.Count > 0)//若本团已存行程,则合并/更新;同时因为机票行程的变化或行程详情的变化,会导致行程更改
  341. {
  342. if (timeList.Count > listTravel.Count)//1.改版后黑屏代码天数>已存在行程的天数
  343. {
  344. //1.1替换日期和星期
  345. for (int i = 0; i < listTravel.Count; i++)
  346. {
  347. //日期转换星期
  348. string weekday = weekdays[(int)new DateTime(
  349. Convert.ToInt32(timeList[i].Split('-')[0]),
  350. Convert.ToInt32(timeList[i].Split('-')[1]),
  351. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  352. listTravel[i].Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  353. listTravel[i].WeekDay = weekday;
  354. listTravel[i].OPer = UserId;
  355. listTravel[i].OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  356. listTravel[i].Isdel = 0;
  357. tls.EditTravelList(listTravel[i]);
  358. }
  359. //1.2添加未有行程
  360. //航班号标识
  361. //string flightcode_Sign = "";
  362. //三字码标识
  363. //string citycode_Sign = "";
  364. #region 城市数据 20210823 贾文滔
  365. List<PublicCode.CityInDate> CityInDateList = PublicCode.GetCityByDataTable(dt);
  366. #endregion
  367. //生成行程
  368. for (int i = listTravel.Count; i < timeList.Count; i++)
  369. {
  370. //实、例化一个temp
  371. Models.TravelList tlTemp = new Models.TravelList();
  372. //团号
  373. tlTemp.Diid = di.Id;
  374. //天数序号
  375. tlTemp.Days = i + 1;
  376. //日期
  377. tlTemp.Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  378. //日期转换星期
  379. string weekday = weekdays[(int)new DateTime(
  380. Convert.ToInt32(timeList[i].Split('-')[0]),
  381. Convert.ToInt32(timeList[i].Split('-')[1]),
  382. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  383. tlTemp.WeekDay = weekday;
  384. //行程
  385. string trip = "";
  386. //历经城市
  387. string city = "";
  388. #region 机票数据
  389. //根据航班信息推出抵达机场的位置信息
  390. string AirPort = "";
  391. //根据航班时间前后推进入机场或离开机场的时间
  392. string GoAirportTime = "", leaveAirPortTime = "";
  393. //飞机标识
  394. bool airSign = false;
  395. //查询该日期下的航班信息
  396. //resultRows字段顺序为:航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间,整理后的起飞日期,整理后的到达日期
  397. DataRow[] resultRows = dt.Select("Day like '%" + timeList[i] + "%'");
  398. if (resultRows.Count() > 0)
  399. {
  400. //修改标识
  401. airSign = true;
  402. }
  403. //同一天只有一条数据走正常判定
  404. if (resultRows.Count() == 1)
  405. {
  406. #region 三字码
  407. string _citycode = resultRows[0]["Three"].ToString();
  408. //起飞城市三字码
  409. ThreeCode font_threecode = null;
  410. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  411. //抵达城市
  412. string font_City = "";
  413. //起飞城市机场
  414. string font_Airport = "";
  415. //抵达城市三字码
  416. ThreeCode back_threecode = null;
  417. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  418. //抵达城市机场
  419. string back_Airport = "";
  420. //抵达城市
  421. string back_City = "";
  422. font_threecode = tcs.getByThree(font_citycode);
  423. //验证是否存在三字码
  424. if (font_threecode == null)
  425. {
  426. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  427. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  428. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  429. }
  430. else
  431. {
  432. city = city + "/" + font_threecode.City;
  433. font_Airport = font_threecode.AirPort;
  434. font_City = font_threecode.City; ;
  435. }
  436. back_threecode = tcs.getByThree(end_citycode);
  437. if (back_threecode == null)
  438. {
  439. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  440. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  441. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  442. }
  443. else
  444. {
  445. city = city + "/" + back_threecode.City;
  446. //部分黄热病国家,需要提醒打疫苗
  447. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  448. if (result.Contains("3"))
  449. {
  450. city += "(此地区为黄热病地区,请注意打疫苗)";
  451. }
  452. back_Airport = back_threecode.AirPort;
  453. back_City = back_threecode.City;
  454. //查询酒店路线要用
  455. AirPort = back_threecode.AirPort;
  456. }
  457. //行程里加入城市
  458. #endregion
  459. #region 信息准备
  460. trip = city.TrimStart('/');
  461. //起飞航站楼
  462. string _StartBuilding = resultRows[0]["StartBuilding"].ToString();
  463. //转机航站楼
  464. string _EndBuilding = resultRows[0]["EndBuilding"].ToString();
  465. //起飞时刻
  466. string _startTime = resultRows[0]["StartTime"].ToString();
  467. //飞行时刻
  468. string _flightTime = resultRows[0]["FlightTime"].ToString();
  469. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  470. //到达时刻
  471. string _endTime = resultRows[0]["EndTime"].ToString();
  472. //航班号
  473. string _flightcode = resultRows[0]["Fliagtcode"].ToString();
  474. //航司
  475. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  476. string _aircompany_Name = "";
  477. if (aircompany == null)
  478. {
  479. _aircompany_Name = "【此航司" + resultRows[0]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  480. }
  481. else
  482. {
  483. _aircompany_Name = aircompany.CnName;
  484. }
  485. //机型判断
  486. string airModel = resultRows[0]["AirModel"].ToString();
  487. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  488. #endregion
  489. #region trip编辑
  490. //若本行抵达时间包含"+1",则本行为母版行,仅提示登机
  491. if (resultRows[0]["Sign"].ToString() == "0" && _endTime.Contains("+"))
  492. {
  493. //根据航班信息推算进入机场的时间
  494. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  495. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  496. if (result.Contains("2"))
  497. {
  498. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  499. }
  500. if (temp < 0)
  501. {
  502. temp = temp + 24;
  503. }
  504. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  505. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  506. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  507. if (i > 0)
  508. {
  509. #region 酒店
  510. foreach (HotelReservations h in listht)
  511. {
  512. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  513. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  514. {
  515. //利用谷歌API计算路线
  516. if (AirPort != "")
  517. {
  518. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  519. if (g != null)
  520. {
  521. //计算“酒店到机场”的时间
  522. string CheckoutHotelTime;
  523. //处理时间格式
  524. string hours = "", mins = "";
  525. if (g.Time.Contains("hour"))
  526. {
  527. g.Time = g.Time.Replace("hour", "h");
  528. }
  529. else if (g.Time.Contains("hours"))
  530. {
  531. g.Time = g.Time.Replace("hours", "h");
  532. }
  533. g.Time = g.Time.Replace("mins", "m");
  534. if (g.Time.Contains("h"))
  535. {
  536. hours = g.Time.Split('h')[0].Trim();
  537. }
  538. else if (!g.Time.Contains("h"))
  539. {
  540. mins = g.Time.Split('m')[0].Trim();
  541. }
  542. int hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  543. int min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  544. min = min - Convert.ToInt32(mins);
  545. if (min < 0)
  546. {
  547. min = min + 60;
  548. hour = hour - 1;
  549. }
  550. if (hours != "")
  551. {
  552. hour = hour - Convert.ToInt32(hours);
  553. }
  554. if (hour < 0)
  555. {
  556. hour = hour + 24;
  557. }
  558. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  559. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  560. trip = trip + "\r\n"
  561. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  562. }
  563. else
  564. {
  565. try
  566. {
  567. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  568. //计算“抵达酒店办理入住手续”的时间
  569. string CheckoutHotelTime;
  570. //处理时间格式
  571. string Gtime = "", hours = "", mins = "";
  572. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  573. {
  574. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  575. }
  576. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  577. {
  578. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  579. }
  580. Gtime = Gtime.Replace("mins", "m");
  581. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  582. {
  583. hours = Gtime.Split('h')[0].Trim();
  584. }
  585. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  586. {
  587. mins = Gtime.Split('m')[0].Trim();
  588. }
  589. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  590. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  591. min = min - Convert.ToInt32(mins);
  592. if (min < 0)
  593. {
  594. min = min + 60;
  595. hour = hour - 1;
  596. }
  597. if (hours != "")
  598. {
  599. hour = hour + Convert.ToInt32(hours);
  600. }
  601. if (hour < 0)
  602. {
  603. hour = hour + 24;
  604. }
  605. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  606. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  607. trip = trip + "\r\n"
  608. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  609. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  610. gtemp.Diid = di.Id;
  611. gtemp.Date = "";
  612. gtemp.Moment = "";
  613. gtemp.StartAddress = AirPort;
  614. gtemp.EndAddress = h.HotelAddress;
  615. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  616. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  617. gmrs.Add(gtemp);
  618. }
  619. catch
  620. {
  621. trip = trip + "\r\n"
  622. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  623. }
  624. }
  625. }
  626. }
  627. }
  628. #endregion
  629. }
  630. //行程
  631. trip = trip
  632. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  633. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  634. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");";
  635. //标记本行为母版行
  636. //flightcode_Sign = resultRows[0]["Fliagtcode"].ToString();
  637. //citycode_Sign = resultRows[0]["Three"].ToString();
  638. }
  639. //与前一行航班号,三字码相同且本行抵达时间不包含"+1",则本行是被生成的重复行,仅提示抵达
  640. else if (resultRows[0]["Sign"].ToString() == "1") /* && (!_endTime.Contains("+"))&&(_flightcode == flightcode_Sign)&&(_citycode == citycode_Sign)*/
  641. {
  642. //行程
  643. trip = trip
  644. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  645. //根据航班信息推算离开机场的时间
  646. int temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  647. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  648. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  649. if (i == timeList.Count - 1)//如果本日是行程的最后一天,则提醒“行程圆满结束”
  650. {
  651. trip = trip + " ,圆满结束此次访问之行!";
  652. }
  653. else //如果本日不是行程的最后一天,正常提醒
  654. {
  655. trip = trip + ";\r\n" + leaveAirPortTime + " 搭乘专车前往酒店,抵达后办理入住;";
  656. }
  657. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  658. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  659. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  660. min = min + 10;
  661. if (min > 59)
  662. {
  663. min = min - 60;
  664. hour = hour + 1;
  665. }
  666. if (hour > 23)
  667. {
  668. hour = hour - 24;
  669. }
  670. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  671. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  672. }
  673. //正常提示
  674. else
  675. {
  676. //根据航班信息推算进入机场的时间
  677. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  678. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  679. if (result.Contains("2"))
  680. {
  681. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  682. }
  683. if (temp < 0)
  684. {
  685. temp = temp + 24;
  686. }
  687. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  688. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  689. //根据航班信息推算离开机场的时间
  690. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  691. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  692. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  693. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  694. if (i > 0)
  695. {
  696. #region 酒店
  697. foreach (HotelReservations h in listht)
  698. {
  699. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  700. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  701. {
  702. //利用谷歌API计算路线
  703. if (AirPort != "")
  704. {
  705. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  706. if (g != null)
  707. {
  708. //计算“酒店到机场”的时间
  709. string CheckoutHotelTime;
  710. //处理时间格式
  711. string hours = "0", mins = "0";
  712. if (g.Time.Contains("hour"))
  713. {
  714. g.Time = g.Time.Replace("hour", "h");
  715. }
  716. else if (g.Time.Contains("hours"))
  717. {
  718. g.Time = g.Time.Replace("hours", "h");
  719. }
  720. g.Time = g.Time.Replace("mins", "m");
  721. if (g.Time.Contains("h"))
  722. {
  723. hours = g.Time.Split('h')[0].Trim();
  724. }
  725. else if (!g.Time.Contains("h"))
  726. {
  727. mins = g.Time.Split('m')[0].Trim();
  728. }
  729. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  730. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  731. _min = _min - Convert.ToInt32(mins);
  732. if (_min < 0)
  733. {
  734. _min = _min + 60;
  735. _hour = _hour - 1;
  736. }
  737. if (hours != "")
  738. {
  739. _hour = _hour - Convert.ToInt32(hours);
  740. }
  741. if (_hour < 0)
  742. {
  743. _hour = _hour + 24;
  744. }
  745. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  746. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  747. trip = trip + "\r\n"
  748. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  749. }
  750. else
  751. {
  752. try
  753. {
  754. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  755. //计算“抵达酒店办理入住手续”的时间
  756. string CheckoutHotelTime;
  757. //处理时间格式
  758. string Gtime = "", hours = "0", mins = "0";
  759. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  760. {
  761. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  762. }
  763. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  764. {
  765. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  766. }
  767. Gtime = Gtime.Replace("mins", "m");
  768. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  769. {
  770. hours = Gtime.Split('h')[0].Trim();
  771. }
  772. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  773. {
  774. mins = Gtime.Split('m')[0].Trim();
  775. }
  776. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  777. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  778. _min = _min - Convert.ToInt32(mins);
  779. if (_min < 0)
  780. {
  781. _min = _min + 60;
  782. _hour = _hour - 1;
  783. }
  784. if (hours != "")
  785. {
  786. _hour = _hour + Convert.ToInt32(hours);
  787. }
  788. if (_hour < 0)
  789. {
  790. _hour = _hour + 24;
  791. }
  792. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  793. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  794. trip = trip + "\r\n"
  795. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  796. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  797. gtemp.Diid = di.Id;
  798. gtemp.Date = "";
  799. gtemp.Moment = "";
  800. gtemp.StartAddress = AirPort;
  801. gtemp.EndAddress = h.HotelAddress;
  802. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  803. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  804. gmrs.Add(gtemp);
  805. }
  806. catch
  807. {
  808. trip = trip + "\r\n"
  809. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  810. }
  811. }
  812. }
  813. }
  814. }
  815. #endregion
  816. }
  817. trip = trip
  818. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  819. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  820. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  821. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  822. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  823. {
  824. trip = trip + ",圆满结束此次访问之行!";
  825. }
  826. else //如果本日不是行程的最后一天,正常提醒
  827. {
  828. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  829. }
  830. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  831. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  832. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  833. min = min + 10;
  834. if (min > 59)
  835. {
  836. min = min - 60;
  837. hour = hour + 1;
  838. }
  839. if (hour > 23)
  840. {
  841. hour = hour - 24;
  842. }
  843. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  844. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  845. }
  846. #endregion
  847. }
  848. //同一天多条数据走分类讨论
  849. else
  850. {
  851. for (int n = 0; n < resultRows.Count(); n++)
  852. {
  853. city = "";
  854. #region 三字码
  855. string _citycode = resultRows[n]["Three"].ToString();
  856. //起飞城市三字码
  857. ThreeCode font_threecode = null;
  858. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  859. //抵达城市
  860. string font_City = "";
  861. //起飞城市机场
  862. string font_Airport = "";
  863. //抵达城市三字码
  864. ThreeCode back_threecode = null;
  865. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  866. //抵达城市机场
  867. string back_Airport = "";
  868. //抵达城市
  869. string back_City = "";
  870. font_threecode = tcs.getByThree(font_citycode);
  871. //验证是否存在三字码
  872. if (font_threecode == null)
  873. {
  874. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  875. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  876. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  877. }
  878. else
  879. {
  880. city = city + "/" + font_threecode.City;
  881. font_Airport = font_threecode.AirPort;
  882. font_City = font_threecode.City; ;
  883. }
  884. back_threecode = tcs.getByThree(end_citycode);
  885. if (back_threecode == null)
  886. {
  887. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  888. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  889. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  890. }
  891. else
  892. {
  893. city = city + "/" + back_threecode.City;
  894. //部分黄热病国家,需要提醒打疫苗
  895. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  896. if (result.Contains("3"))
  897. {
  898. city += "(此地区为黄热病地区,请注意打疫苗)";
  899. }
  900. back_Airport = back_threecode.AirPort;
  901. back_City = back_threecode.City;
  902. //查询酒店路线要用
  903. AirPort = back_threecode.AirPort;
  904. }
  905. //行程里加入城市
  906. if (trip == "")
  907. {
  908. trip = city.TrimStart('/');
  909. }
  910. else
  911. {
  912. trip = trip + "\r\n"
  913. + city.TrimStart('/');
  914. }
  915. //起飞航站楼
  916. string _StartBuilding = resultRows[n]["StartBuilding"].ToString();
  917. //转机航站楼
  918. string _EndBuilding = resultRows[n]["EndBuilding"].ToString();
  919. //起飞时刻
  920. string _startTime = resultRows[n]["StartTime"].ToString();
  921. //飞行时刻
  922. string _flightTime = resultRows[n]["FlightTime"].ToString();
  923. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  924. //到达时刻
  925. string _endTime = resultRows[n]["EndTime"].ToString();
  926. //航班号
  927. string _flightcode = resultRows[n]["Fliagtcode"].ToString();
  928. //航司
  929. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  930. string _aircompany_Name = "";
  931. if (aircompany == null)
  932. {
  933. _aircompany_Name = "【此航司" + resultRows[n]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  934. }
  935. else
  936. {
  937. _aircompany_Name = aircompany.CnName;
  938. }
  939. //机型判断
  940. string airModel = resultRows[n]["AirModel"].ToString();
  941. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  942. #endregion
  943. //Sign字段为标识,string类型,含义:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  944. //目前存在两种情况:同一天的多条数据标识为“0->0”或“1->0”
  945. //如下示例
  946. //Day ArrivedDate Sign
  947. //10 10 0
  948. //10 11 0
  949. //11 11 1
  950. //11 12 0
  951. //12 12 1
  952. if (n == 0)
  953. {
  954. //原生机票代码
  955. if (resultRows[n]["Sign"].ToString() == "0")
  956. {
  957. #region trip编辑
  958. //根据航班信息推算进入机场的时间
  959. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  960. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  961. if (result.Contains("2"))
  962. {
  963. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  964. }
  965. if (temp < 0)
  966. {
  967. temp = temp + 24;
  968. }
  969. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  970. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  971. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  972. if (i > 0)
  973. {
  974. #region 酒店
  975. foreach (HotelReservations h in listht)
  976. {
  977. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  978. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  979. {
  980. //利用谷歌API计算路线
  981. if (AirPort != "")
  982. {
  983. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  984. if (g != null)
  985. {
  986. //计算“酒店到机场”的时间
  987. string CheckoutHotelTime;
  988. //处理时间格式
  989. string hours = "0", mins = "0";
  990. if (g.Time.Contains("hour"))
  991. {
  992. g.Time = g.Time.Replace("hour", "h");
  993. }
  994. else if (g.Time.Contains("hours"))
  995. {
  996. g.Time = g.Time.Replace("hours", "h");
  997. }
  998. g.Time = g.Time.Replace("mins", "m");
  999. if (g.Time.Contains("h"))
  1000. {
  1001. hours = g.Time.Split('h')[0].Trim();
  1002. }
  1003. else if (!g.Time.Contains("h"))
  1004. {
  1005. mins = g.Time.Split('m')[0].Trim();
  1006. }
  1007. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  1008. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  1009. _min = _min - Convert.ToInt32(mins);
  1010. if (_min < 0)
  1011. {
  1012. _min = _min + 60;
  1013. _hour = _hour - 1;
  1014. }
  1015. if (hours != "")
  1016. {
  1017. _hour = _hour - Convert.ToInt32(hours);
  1018. }
  1019. if (_hour < 0)
  1020. {
  1021. _hour = _hour + 24;
  1022. }
  1023. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1024. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1025. trip = trip + "\r\n"
  1026. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1027. }
  1028. else
  1029. {
  1030. try
  1031. {
  1032. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  1033. //计算“抵达酒店办理入住手续”的时间
  1034. string CheckoutHotelTime;
  1035. //处理时间格式
  1036. string Gtime = "", hours = "0", mins = "0";
  1037. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  1038. {
  1039. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  1040. }
  1041. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  1042. {
  1043. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  1044. }
  1045. Gtime = Gtime.Replace("mins", "m");
  1046. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  1047. {
  1048. hours = Gtime.Split('h')[0].Trim();
  1049. }
  1050. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  1051. {
  1052. mins = Gtime.Split('m')[0].Trim();
  1053. }
  1054. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1055. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1056. _min = _min - Convert.ToInt32(mins);
  1057. if (_min < 0)
  1058. {
  1059. _min = _min + 60;
  1060. _hour = _hour - 1;
  1061. }
  1062. if (hours != "")
  1063. {
  1064. _hour = _hour + Convert.ToInt32(hours);
  1065. }
  1066. if (_hour < 0)
  1067. {
  1068. _hour = _hour + 24;
  1069. }
  1070. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1071. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1072. trip = trip + "\r\n"
  1073. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1074. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1075. gtemp.Diid = di.Id;
  1076. gtemp.Date = "";
  1077. gtemp.Moment = "";
  1078. gtemp.StartAddress = AirPort;
  1079. gtemp.EndAddress = h.HotelAddress;
  1080. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1081. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1082. gmrs.Add(gtemp);
  1083. }
  1084. catch
  1085. {
  1086. trip = trip + "\r\n"
  1087. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. #endregion
  1094. }
  1095. trip = trip
  1096. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  1097. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  1098. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  1099. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  1100. #endregion
  1101. }
  1102. //"+1"生成的机票代码
  1103. else if (resultRows[n]["Sign"].ToString() == "1")
  1104. {
  1105. #region trip编辑
  1106. //行程
  1107. trip = trip
  1108. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  1109. #endregion
  1110. }
  1111. }
  1112. else if (n > 0)
  1113. {
  1114. //若前行是原生的,则本行判定为转机
  1115. if (resultRows[n - 1]["Sign"].ToString() == "0")
  1116. {
  1117. #region trip编辑
  1118. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 1;//一般提前提前2小时
  1119. if (temp < 0)
  1120. {
  1121. temp = temp + 24;
  1122. }
  1123. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1124. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  1125. trip = trip
  1126. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  1127. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  1128. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  1129. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  1130. //若为最后一行,则计算后备等时间
  1131. if (n == resultRows.Count() - 1)
  1132. {
  1133. //根据航班信息推算离开机场的时间
  1134. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  1135. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1136. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  1137. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  1138. {
  1139. trip = trip + ",圆满结束此次访问之行!";
  1140. }
  1141. else //如果本日不是行程的最后一天,正常提醒
  1142. {
  1143. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  1144. }
  1145. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  1146. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1147. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1148. min = min + 10;
  1149. if (min > 59)
  1150. {
  1151. min = min - 60;
  1152. hour = hour + 1;
  1153. }
  1154. if (hour > 23)
  1155. {
  1156. hour = hour - 24;
  1157. }
  1158. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1159. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1160. }
  1161. #endregion
  1162. }
  1163. //若前行是生成的,则本行判定为新出发
  1164. else if (resultRows[n - 1]["Sign"].ToString() == "1")
  1165. {
  1166. #region trip编辑
  1167. //根据航班信息推算进入机场的时间
  1168. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  1169. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  1170. if (result.Contains("2"))
  1171. {
  1172. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  1173. }
  1174. if (temp < 0)
  1175. {
  1176. temp = temp + 24;
  1177. }
  1178. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1179. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  1180. //根据航班信息推算离开机场的时间
  1181. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  1182. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1183. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  1184. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  1185. if (i > 0)
  1186. {
  1187. #region 酒店
  1188. foreach (HotelReservations h in listht)
  1189. {
  1190. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  1191. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  1192. {
  1193. //利用谷歌API计算路线
  1194. if (AirPort != "")
  1195. {
  1196. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  1197. if (g != null)
  1198. {
  1199. //计算“酒店到机场”的时间
  1200. string CheckoutHotelTime;
  1201. //处理时间格式
  1202. string hours = "0", mins = "0";
  1203. if (g.Time.Contains("hour"))
  1204. {
  1205. g.Time = g.Time.Replace("hour", "h");
  1206. }
  1207. else if (g.Time.Contains("hours"))
  1208. {
  1209. g.Time = g.Time.Replace("hours", "h");
  1210. }
  1211. g.Time = g.Time.Replace("mins", "m");
  1212. if (g.Time.Contains("h"))
  1213. {
  1214. hours = g.Time.Split('h')[0].Trim();
  1215. }
  1216. else if (!g.Time.Contains("h"))
  1217. {
  1218. mins = g.Time.Split('m')[0].Trim();
  1219. }
  1220. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  1221. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  1222. _min = _min - Convert.ToInt32(mins);
  1223. if (_min < 0)
  1224. {
  1225. _min = _min + 60;
  1226. _hour = _hour - 1;
  1227. }
  1228. if (hours != "")
  1229. {
  1230. _hour = _hour - Convert.ToInt32(hours);
  1231. }
  1232. if (_hour < 0)
  1233. {
  1234. _hour = _hour + 24;
  1235. }
  1236. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1237. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1238. trip = trip + "\r\n"
  1239. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1240. }
  1241. else
  1242. {
  1243. try
  1244. {
  1245. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  1246. //计算“抵达酒店办理入住手续”的时间
  1247. string CheckoutHotelTime;
  1248. //处理时间格式
  1249. string Gtime = "", hours = "0", mins = "0";
  1250. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  1251. {
  1252. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  1253. }
  1254. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  1255. {
  1256. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  1257. }
  1258. Gtime = Gtime.Replace("mins", "m");
  1259. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  1260. {
  1261. hours = Gtime.Split('h')[0].Trim();
  1262. }
  1263. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  1264. {
  1265. mins = Gtime.Split('m')[0].Trim();
  1266. }
  1267. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1268. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1269. _min = _min - Convert.ToInt32(mins);
  1270. if (_min < 0)
  1271. {
  1272. _min = _min + 60;
  1273. _hour = _hour - 1;
  1274. }
  1275. if (hours != "")
  1276. {
  1277. _hour = _hour + Convert.ToInt32(hours);
  1278. }
  1279. if (_hour < 0)
  1280. {
  1281. _hour = _hour + 24;
  1282. }
  1283. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  1284. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  1285. trip = trip + "\r\n"
  1286. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  1287. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1288. gtemp.Diid = di.Id;
  1289. gtemp.Date = "";
  1290. gtemp.Moment = "";
  1291. gtemp.StartAddress = AirPort;
  1292. gtemp.EndAddress = h.HotelAddress;
  1293. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1294. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1295. gmrs.Add(gtemp);
  1296. }
  1297. catch
  1298. {
  1299. trip = trip + "\r\n"
  1300. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  1301. }
  1302. }
  1303. }
  1304. }
  1305. }
  1306. #endregion
  1307. }
  1308. trip = trip
  1309. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  1310. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  1311. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  1312. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  1313. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  1314. {
  1315. trip = trip + ",圆满结束此次访问之行!";
  1316. }
  1317. else //如果本日不是行程的最后一天,正常提醒
  1318. {
  1319. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  1320. }
  1321. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  1322. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1323. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1324. min = min + 10;
  1325. if (min > 59)
  1326. {
  1327. min = min - 60;
  1328. hour = hour + 1;
  1329. }
  1330. if (hour > 23)
  1331. {
  1332. hour = hour - 24;
  1333. }
  1334. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1335. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1336. #endregion
  1337. }
  1338. }
  1339. }
  1340. }
  1341. #endregion
  1342. #region 行程和城市赋值
  1343. if (trip == "" || trip == " " || city == "" || city == " ")
  1344. {
  1345. //city = CityInDateList.Find(cid => cid.Date == timeList[i]).City;
  1346. city = CityInDateList[i].City;
  1347. //部分黄热病国家,需要提醒打疫苗
  1348. string result = PublicCode.GetCountryInfo(tcs.getByCity(city)[0].Country);
  1349. if (result.Contains("3"))
  1350. {
  1351. city += "(此地区为黄热病地区,请注意打疫苗)";
  1352. }
  1353. trip = city;
  1354. }
  1355. #endregion
  1356. #region 公务 20210820 贾文滔
  1357. string OATemp = "";//暂存公务活动
  1358. //根据团号和日期获取公务数据
  1359. List<OfficialActivities> listoa = oas.getByDiidAndDate(comb_Diid, timeList[i]);
  1360. //若listoa存在公务数据,进行排序,再进行导入
  1361. if (listoa != null && listoa.Count > 0)
  1362. {
  1363. //利用datatable存放公务活动数据
  1364. DataTable OA_DataTable = new DataTable();
  1365. OA_DataTable.Columns.Add("StartTime", typeof(string)); //activity开始时刻
  1366. OA_DataTable.Columns.Add("EndTime", typeof(string)); //activity结束时刻
  1367. OA_DataTable.Columns.Add("Client", typeof(string)); //activity单位
  1368. OA_DataTable.Columns.Add("Address", typeof(string)); //activity地址
  1369. OA_DataTable.Columns.Add("Contact", typeof(string)); //activity联系人
  1370. OA_DataTable.Columns.Add("Tel", typeof(string)); //activity联系人电话
  1371. OA_DataTable.Columns.Add("Dresscode", typeof(string)); //activity着装要求
  1372. OA_DataTable.Columns.Add("isTranslate", typeof(bool));//是否需要翻译人员
  1373. OA_DataTable.Columns.Add("Language", typeof(string));//是否需要翻译人员
  1374. //处理公务数据
  1375. for (int b = 0; b < listoa.Count; b++)
  1376. {
  1377. //起止时间
  1378. string[] time = new string[2];
  1379. if (listoa[b].Time.Contains('—'))
  1380. {
  1381. time = listoa[b].Time.Split('—');
  1382. }
  1383. else if (listoa[b].Time.Contains('-'))
  1384. {
  1385. time = listoa[b].Time.Split('-');
  1386. }
  1387. //添加数据
  1388. if (time.Length >= 2)
  1389. {
  1390. OA_DataTable.Rows.Add(time[0], time[1], listoa[b].Client, listoa[b].Address, listoa[b].Contact, listoa[b].Tel, listoa[b].Dresscode, listoa[b].IsNeedTrans, listoa[b].Language);
  1391. }
  1392. else
  1393. {
  1394. //PublicCode.GetAlertMsg(this, GetType(), timeList[i] + "的公务数据有误,请检查");
  1395. }
  1396. }
  1397. //排序
  1398. OA_DataTable.DefaultView.Sort = "StartTime asc";
  1399. OA_DataTable = OA_DataTable.DefaultView.ToTable();
  1400. //导入信息
  1401. for (int index = 0; index < OA_DataTable.Rows.Count; index++)
  1402. {
  1403. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1404. {
  1405. if (OATemp != "")
  1406. {
  1407. OATemp = OATemp + "\r\n"
  1408. + OA_DataTable.Rows[index]["StartTime"].ToString()
  1409. + "-"
  1410. + OA_DataTable.Rows[index]["EndTime"].ToString()
  1411. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  1412. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  1413. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  1414. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  1415. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  1416. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  1417. + ",议题:-";
  1418. }
  1419. else
  1420. {
  1421. OATemp = OA_DataTable.Rows[index]["StartTime"].ToString()
  1422. + "-"
  1423. + OA_DataTable.Rows[index]["EndTime"].ToString()
  1424. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  1425. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  1426. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  1427. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  1428. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  1429. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  1430. + ",议题:-";
  1431. }
  1432. }
  1433. else
  1434. {
  1435. //导入公务
  1436. trip = trip + "\r\n"
  1437. + OA_DataTable.Rows[index]["StartTime"].ToString()
  1438. + "-"
  1439. + OA_DataTable.Rows[index]["EndTime"].ToString()
  1440. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  1441. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  1442. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  1443. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  1444. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  1445. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  1446. + ",议题:-";
  1447. }
  1448. //当天第一个公务或许都是从酒店出发,因此可计算酒店到公务地址的距离和时间
  1449. if (index == 0)
  1450. {
  1451. #region 酒店
  1452. foreach (HotelReservations h in listht)
  1453. {
  1454. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  1455. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  1456. {
  1457. //利用谷歌API计算路线
  1458. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  1459. if (g != null)
  1460. {
  1461. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1462. {
  1463. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  1464. }
  1465. else
  1466. {
  1467. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  1468. }
  1469. }
  1470. else
  1471. {
  1472. try
  1473. {
  1474. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  1475. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1476. {
  1477. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1478. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1479. }
  1480. else
  1481. {
  1482. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1483. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1484. }
  1485. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1486. gtemp.Diid = di.Id;
  1487. gtemp.Date = "";
  1488. gtemp.Moment = "";
  1489. gtemp.StartAddress = h.HotelAddress;
  1490. gtemp.EndAddress = OA_DataTable.Rows[0]["Address"].ToString();
  1491. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1492. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1493. gmrs.Add(gtemp);
  1494. }
  1495. catch
  1496. {
  1497. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1498. {
  1499. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  1500. }
  1501. else
  1502. {
  1503. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  1504. }
  1505. }
  1506. }
  1507. }
  1508. }
  1509. #endregion
  1510. }
  1511. //第二个公务是由中午的餐厅前往公务地址,具有随机性,因此不计算此方向距离时间;但可计算由公务地址回酒店的信息
  1512. else
  1513. {
  1514. #region 酒店
  1515. foreach (HotelReservations h in listht)
  1516. {
  1517. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  1518. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  1519. {
  1520. //利用谷歌API计算路线
  1521. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  1522. if (g != null)
  1523. {
  1524. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1525. {
  1526. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  1527. }
  1528. else
  1529. {
  1530. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  1531. }
  1532. }
  1533. else
  1534. {
  1535. try
  1536. {
  1537. JObject Result = PublicCode.GetDirectionByGoogleApi(OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  1538. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1539. {
  1540. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1541. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1542. }
  1543. else
  1544. {
  1545. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1546. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1547. }
  1548. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1549. gtemp.Diid = di.Id;
  1550. gtemp.Date = "";
  1551. gtemp.Moment = "";
  1552. gtemp.StartAddress = OA_DataTable.Rows[0]["Address"].ToString();
  1553. gtemp.EndAddress = h.HotelAddress;
  1554. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1555. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1556. gmrs.Add(gtemp);
  1557. }
  1558. catch
  1559. {
  1560. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  1561. {
  1562. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  1563. }
  1564. else
  1565. {
  1566. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. #endregion
  1573. }
  1574. }
  1575. }
  1576. #endregion
  1577. #region 酒店
  1578. foreach (HotelReservations h in listht)
  1579. {
  1580. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  1581. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))//不去“》=”的原因是行程最后一天一般不会有酒店
  1582. {
  1583. //利用谷歌API计算路线
  1584. if (AirPort != "")
  1585. {
  1586. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, AirPort, h.HotelAddress);
  1587. if (g != null)
  1588. {
  1589. trip = trip + "\r\n"
  1590. + leaveAirPortTime + " 乘车前往酒店:(" + g.Distance + "," + g.Time + ")";
  1591. //计算“抵达酒店办理入住手续”的时间
  1592. string CheckInHotelTime;
  1593. //处理时间格式
  1594. string hours = "", mins = "";
  1595. if (g.Time.Contains("hour"))
  1596. {
  1597. g.Time = g.Time.Replace("hour", "h");
  1598. }
  1599. else if (g.Time.Contains("hours"))
  1600. {
  1601. g.Time = g.Time.Replace("hours", "h");
  1602. }
  1603. g.Time = g.Time.Replace("mins", "m");
  1604. if (g.Time.Contains("h"))
  1605. {
  1606. hours = g.Time.Split('h')[0].Trim();
  1607. }
  1608. else if (!g.Time.Contains("h"))
  1609. {
  1610. mins = g.Time.Split('m')[0].Trim();
  1611. }
  1612. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1613. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1614. min = min + Convert.ToInt32(mins);
  1615. if (min > 59)
  1616. {
  1617. min = min - 60;
  1618. hour = hour + 1;
  1619. }
  1620. if (hours != "")
  1621. {
  1622. hour = hour + Convert.ToInt32(hours);
  1623. }
  1624. if (hour > 23)
  1625. {
  1626. hour = hour - 24;
  1627. }
  1628. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1629. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1630. trip = trip + "\r\n"
  1631. + CheckInHotelTime + " 抵达酒店办理入住手续";
  1632. }
  1633. else
  1634. {
  1635. try
  1636. {
  1637. JObject Result = PublicCode.GetDirectionByGoogleApi(AirPort, h.HotelAddress);
  1638. trip = trip + "\r\n"
  1639. + leaveAirPortTime + " 乘车前往酒店:(" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  1640. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  1641. //计算“抵达酒店办理入住手续”的时间
  1642. string CheckInHotelTime;
  1643. //处理时间格式
  1644. string Gtime = "", hours = "", mins = "";
  1645. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  1646. {
  1647. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  1648. }
  1649. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  1650. {
  1651. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  1652. }
  1653. Gtime = Gtime.Replace("mins", "m");
  1654. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  1655. {
  1656. hours = Gtime.Split('h')[0].Trim();
  1657. }
  1658. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  1659. {
  1660. mins = Gtime.Split('m')[0].Trim();
  1661. }
  1662. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  1663. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  1664. min = min + Convert.ToInt32(mins);
  1665. if (min > 59)
  1666. {
  1667. min = min - 60;
  1668. hour = hour + 1;
  1669. }
  1670. if (hours != "")
  1671. {
  1672. hour = hour + Convert.ToInt32(hours);
  1673. }
  1674. if (hour > 23)
  1675. {
  1676. hour = hour - 24;
  1677. }
  1678. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  1679. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  1680. trip = trip + "\r\n"
  1681. + CheckInHotelTime + " 抵达酒店办理入住手续";
  1682. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  1683. gtemp.Diid = di.Id;
  1684. gtemp.Date = "";
  1685. gtemp.Moment = "";
  1686. gtemp.StartAddress = AirPort;
  1687. gtemp.EndAddress = h.HotelAddress;
  1688. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  1689. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  1690. gmrs.Add(gtemp);
  1691. }
  1692. catch
  1693. {
  1694. trip = trip + "\r\n"
  1695. + " (谷歌接口异常,无法测算的路程时间)";
  1696. }
  1697. }
  1698. }
  1699. trip = trip + "\r\n"
  1700. + " 酒店名称:" + h.HotelName + "\r\n"
  1701. + " 酒店地址:" + h.HotelAddress + "\r\n"
  1702. + " 酒店电话:" + h.HotelTel + " 酒店传真:" + (h.HotelFax == "" ? "-" : h.HotelFax);
  1703. if (i == 0 && !string.IsNullOrEmpty(OATemp))
  1704. {
  1705. trip = trip + "\r\n" + OATemp;
  1706. }
  1707. }
  1708. }
  1709. #endregion
  1710. #region 当天交通工具赋值
  1711. //一般行程第一天都是先乘坐飞机后乘坐汽车
  1712. if (i == 0)
  1713. {
  1714. tlTemp.Traffic_First = "飞机";
  1715. tlTemp.Traffic_Second = "汽车";
  1716. }
  1717. else
  1718. {
  1719. // 根据车导地接表数据判断交通工具:汽车
  1720. List<CarTouristGuideGroundReservations> ListCar = listctg.FindAll(c => Convert.ToDateTime(c.ServiceStartTime) <= Convert.ToDateTime(timeList[i])
  1721. && Convert.ToDateTime(c.ServiceEndTime) >= Convert.ToDateTime(timeList[i]));
  1722. //交通工具:汽车
  1723. if (ListCar.Count > 0)
  1724. {
  1725. tlTemp.Traffic_First = "汽车";
  1726. //交通工具:飞机
  1727. if (airSign == true)
  1728. {
  1729. tlTemp.Traffic_Second = "飞机";
  1730. }
  1731. else
  1732. {
  1733. tlTemp.Traffic_Second = "";
  1734. }
  1735. }
  1736. else
  1737. {
  1738. tlTemp.Traffic_First = "汽车";
  1739. //交通工具:飞机
  1740. if (airSign == true)
  1741. {
  1742. tlTemp.Traffic_Second = "飞机";
  1743. }
  1744. else
  1745. {
  1746. tlTemp.Traffic_Second = "";
  1747. }
  1748. }
  1749. }
  1750. #endregion
  1751. tlTemp.Trip = trip;
  1752. tlTemp.OPer = di.Id;
  1753. tlTemp.OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  1754. tlTemp.issel = 1;
  1755. tlTemp.diffgroup = 1;
  1756. tlTemp.Isdel = 0;
  1757. tls.AddTravelList(tlTemp);
  1758. }
  1759. }
  1760. else if (timeList.Count < listTravel.Count)//2改版天数<原版天数
  1761. {
  1762. //2.1替换日期
  1763. for (int i = 0; i < timeList.Count; i++)
  1764. {
  1765. //日期转换星期
  1766. string weekday = weekdays[(int)new DateTime(
  1767. Convert.ToInt32(timeList[i].Split('-')[0]),
  1768. Convert.ToInt32(timeList[i].Split('-')[1]),
  1769. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  1770. listTravel[i].Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  1771. listTravel[i].WeekDay = weekday;
  1772. listTravel[i].OPer = UserId;
  1773. listTravel[i].OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  1774. listTravel[i].Isdel = 0;
  1775. tls.EditTravelList(listTravel[i]);
  1776. }
  1777. //2.2删除多余行程
  1778. tls.DelOld(comb_Diid, listTravel[timeList.Count - 1].Id, listTravel[listTravel.Count - 1].Id);
  1779. }
  1780. else//3改版天数=原版天数
  1781. {
  1782. //3.1替换日期
  1783. for (int i = 0; i < timeList.Count; i++)
  1784. {
  1785. //日期
  1786. listTravel[i].Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  1787. //日期转换星期
  1788. string weekday = weekdays[(int)new DateTime(
  1789. Convert.ToInt32(timeList[i].Split('-')[0]),
  1790. Convert.ToInt32(timeList[i].Split('-')[1]),
  1791. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  1792. listTravel[i].WeekDay = weekday;
  1793. listTravel[i].OPer = UserId;
  1794. listTravel[i].OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd HH:mm:ss");
  1795. listTravel[i].Isdel = 0;
  1796. tls.EditTravelList(listTravel[i]);
  1797. }
  1798. }
  1799. }
  1800. else //若本团不存行程,则生成行程。 包含机票、酒店、车导地接等数据
  1801. {
  1802. //航班号标识
  1803. //string flightcode_Sign = "";
  1804. //三字码标识
  1805. //string citycode_Sign = "";
  1806. #region 城市数据 20210823 贾文滔
  1807. List<PublicCode.CityInDate> CityInDateList = PublicCode.GetCityByDataTable(dt);
  1808. #endregion
  1809. //生成行程
  1810. for (int i = 0; i < timeList.Count; i++)
  1811. {
  1812. //实、例化一个temp
  1813. Models.TravelList tlTemp = new Models.TravelList();
  1814. //团号
  1815. tlTemp.Diid = di.Id;
  1816. //天数序号
  1817. tlTemp.Days = i + 1;
  1818. //日期
  1819. tlTemp.Date = timeList[i].Substring(5, 2) + "月" + timeList[i].Substring(8, 2) + "日";
  1820. //日期转换星期
  1821. string weekday = weekdays[(int)new DateTime(
  1822. Convert.ToInt32(timeList[i].Split('-')[0]),
  1823. Convert.ToInt32(timeList[i].Split('-')[1]),
  1824. Convert.ToInt32(timeList[i].Split('-')[2])).DayOfWeek];
  1825. tlTemp.WeekDay = weekday;
  1826. //行程
  1827. string trip = "";
  1828. //历经城市
  1829. string city = "";
  1830. #region 机票数据
  1831. //根据航班信息推出抵达机场的位置信息
  1832. string AirPort = "";
  1833. //根据航班时间前后推进入机场或离开机场的时间
  1834. string GoAirportTime = "", leaveAirPortTime = "";
  1835. //飞机标识
  1836. bool airSign = false;
  1837. //查询该日期下的航班信息
  1838. //resultRows字段顺序为:航班号,起飞日期,三字码,起飞时刻,到达时刻,出发航站楼,到达航站楼,机型,飞行时间,整理后的起飞日期,整理后的到达日期
  1839. DataRow[] resultRows = dt.Select("Day like '%" + timeList[i] + "%'");
  1840. if (resultRows.Count() > 0)
  1841. {
  1842. //修改标识
  1843. airSign = true;
  1844. }
  1845. //同一天只有一条数据走正常判定
  1846. if (resultRows.Count() == 1)
  1847. {
  1848. #region 三字码
  1849. string _citycode = resultRows[0]["Three"].ToString();
  1850. //起飞城市三字码
  1851. ThreeCode font_threecode = null;
  1852. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  1853. //抵达城市
  1854. string font_City = "";
  1855. //起飞城市机场
  1856. string font_Airport = "";
  1857. //抵达城市三字码
  1858. ThreeCode back_threecode = null;
  1859. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  1860. //抵达城市机场
  1861. string back_Airport = "";
  1862. //抵达城市
  1863. string back_City = "";
  1864. font_threecode = tcs.getByThree(font_citycode);
  1865. //验证是否存在三字码
  1866. if (font_threecode == null)
  1867. {
  1868. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  1869. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  1870. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  1871. }
  1872. else
  1873. {
  1874. city = city + "/" + font_threecode.City;
  1875. font_Airport = font_threecode.AirPort;
  1876. font_City = font_threecode.City; ;
  1877. }
  1878. back_threecode = tcs.getByThree(end_citycode);
  1879. if (back_threecode == null)
  1880. {
  1881. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  1882. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  1883. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  1884. }
  1885. else
  1886. {
  1887. city = city + "/" + back_threecode.City;
  1888. //部分黄热病国家,需要提醒打疫苗
  1889. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  1890. if (result.Contains("3"))
  1891. {
  1892. city += "(此地区为黄热病地区,请注意打疫苗)";
  1893. }
  1894. back_Airport = back_threecode.AirPort;
  1895. back_City = back_threecode.City;
  1896. //查询酒店路线要用
  1897. AirPort = back_threecode.AirPort;
  1898. }
  1899. //行程里加入城市
  1900. #endregion
  1901. #region 信息准备
  1902. trip = city.TrimStart('/');
  1903. //起飞航站楼
  1904. string _StartBuilding = resultRows[0]["StartBuilding"].ToString();
  1905. //转机航站楼
  1906. string _EndBuilding = resultRows[0]["EndBuilding"].ToString();
  1907. //起飞时刻
  1908. string _startTime = resultRows[0]["StartTime"].ToString();
  1909. //飞行时刻
  1910. string _flightTime = resultRows[0]["FlightTime"].ToString();
  1911. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  1912. //到达时刻
  1913. string _endTime = resultRows[0]["EndTime"].ToString();
  1914. //航班号
  1915. string _flightcode = resultRows[0]["Fliagtcode"].ToString();
  1916. //航司
  1917. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  1918. string _aircompany_Name = "";
  1919. if (aircompany == null)
  1920. {
  1921. _aircompany_Name = "【此航司" + resultRows[0]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  1922. }
  1923. else
  1924. {
  1925. _aircompany_Name = aircompany.CnName;
  1926. }
  1927. //机型判断
  1928. string airModel = resultRows[0]["AirModel"].ToString();
  1929. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  1930. #endregion
  1931. #region trip编辑
  1932. //若本行抵达时间包含"+1",则本行为母版行,仅提示登机
  1933. if (resultRows[0]["Sign"].ToString() == "0" && _endTime.Contains("+"))
  1934. {
  1935. //根据航班信息推算进入机场的时间
  1936. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  1937. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  1938. if (result.Contains("2"))
  1939. {
  1940. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  1941. }
  1942. if (temp < 0)
  1943. {
  1944. temp = temp + 24;
  1945. }
  1946. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  1947. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  1948. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  1949. if (i > 0)
  1950. {
  1951. #region 酒店
  1952. foreach (HotelReservations h in listht)
  1953. {
  1954. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  1955. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  1956. {
  1957. //利用谷歌API计算路线
  1958. if (AirPort != "")
  1959. {
  1960. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  1961. if (g != null)
  1962. {
  1963. //计算“酒店到机场”的时间
  1964. string CheckoutHotelTime;
  1965. //处理时间格式
  1966. string hours = "", mins = "";
  1967. if (g.Time.Contains("hour"))
  1968. {
  1969. g.Time = g.Time.Replace("hour", "h");
  1970. }
  1971. else if (g.Time.Contains("hours"))
  1972. {
  1973. g.Time = g.Time.Replace("hours", "h");
  1974. }
  1975. g.Time = g.Time.Replace("mins", "m");
  1976. if (g.Time.Contains("h"))
  1977. {
  1978. hours = g.Time.Split('h')[0].Trim();
  1979. }
  1980. else if (!g.Time.Contains("h"))
  1981. {
  1982. mins = g.Time.Split('m')[0].Trim();
  1983. }
  1984. int hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  1985. int min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  1986. min = min - Convert.ToInt32(mins);
  1987. if (min < 0)
  1988. {
  1989. min = min + 60;
  1990. hour = hour - 1;
  1991. }
  1992. if (hours != "")
  1993. {
  1994. hour = hour - Convert.ToInt32(hours);
  1995. }
  1996. if (hour < 0)
  1997. {
  1998. hour = hour + 24;
  1999. }
  2000. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2001. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2002. trip = trip + "\r\n"
  2003. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2004. }
  2005. else
  2006. {
  2007. try
  2008. {
  2009. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2010. //计算“抵达酒店办理入住手续”的时间
  2011. string CheckoutHotelTime;
  2012. //处理时间格式
  2013. string Gtime = "", hours = "", mins = "";
  2014. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2015. {
  2016. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2017. }
  2018. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2019. {
  2020. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2021. }
  2022. Gtime = Gtime.Replace("mins", "m");
  2023. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2024. {
  2025. hours = Gtime.Split('h')[0].Trim();
  2026. }
  2027. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2028. {
  2029. mins = Gtime.Split('m')[0].Trim();
  2030. }
  2031. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2032. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2033. min = min - Convert.ToInt32(mins);
  2034. if (min < 0)
  2035. {
  2036. min = min + 60;
  2037. hour = hour - 1;
  2038. }
  2039. if (hours != "")
  2040. {
  2041. hour = hour + Convert.ToInt32(hours);
  2042. }
  2043. if (hour < 0)
  2044. {
  2045. hour = hour + 24;
  2046. }
  2047. CheckoutHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2048. CheckoutHotelTime = CheckoutHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2049. trip = trip + "\r\n"
  2050. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2051. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2052. gtemp.Diid = di.Id;
  2053. gtemp.Date = "";
  2054. gtemp.Moment = "";
  2055. gtemp.StartAddress = AirPort;
  2056. gtemp.EndAddress = h.HotelAddress;
  2057. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2058. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2059. gmrs.Add(gtemp);
  2060. }
  2061. catch
  2062. {
  2063. trip = trip + "\r\n"
  2064. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2065. }
  2066. }
  2067. }
  2068. }
  2069. }
  2070. #endregion
  2071. }
  2072. //行程
  2073. trip = trip
  2074. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2075. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2076. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");";
  2077. //标记本行为母版行
  2078. //flightcode_Sign = resultRows[0]["Fliagtcode"].ToString();
  2079. //citycode_Sign = resultRows[0]["Three"].ToString();
  2080. }
  2081. //与前一行航班号,三字码相同且本行抵达时间不包含"+1",则本行是被生成的重复行,仅提示抵达
  2082. else if (resultRows[0]["Sign"].ToString() == "1") /* && (!_endTime.Contains("+"))&&(_flightcode == flightcode_Sign)&&(_citycode == citycode_Sign)*/
  2083. {
  2084. //行程
  2085. trip = trip
  2086. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2087. //根据航班信息推算离开机场的时间
  2088. int temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2089. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2090. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2091. if (i == timeList.Count - 1)//如果本日是行程的最后一天,则提醒“行程圆满结束”
  2092. {
  2093. trip = trip + ",圆满结束此次访问之行!";
  2094. }
  2095. else //如果本日不是行程的最后一天,正常提醒
  2096. {
  2097. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  2098. }
  2099. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2100. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2101. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2102. min = min + 10;
  2103. if (min > 59)
  2104. {
  2105. min = min - 60;
  2106. hour = hour + 1;
  2107. }
  2108. if (hour > 23)
  2109. {
  2110. hour = hour - 24;
  2111. }
  2112. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2113. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2114. }
  2115. //正常提示
  2116. else
  2117. {
  2118. //根据航班信息推算进入机场的时间
  2119. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  2120. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  2121. if (result.Contains("2"))
  2122. {
  2123. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2124. }
  2125. if (temp < 0)
  2126. {
  2127. temp = temp + 24;
  2128. }
  2129. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2130. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2131. //根据航班信息推算离开机场的时间
  2132. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2133. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2134. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2135. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2136. if (i > 0)
  2137. {
  2138. #region 酒店
  2139. foreach (HotelReservations h in listht)
  2140. {
  2141. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2142. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  2143. {
  2144. //利用谷歌API计算路线
  2145. if (AirPort != "")
  2146. {
  2147. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2148. if (g != null)
  2149. {
  2150. //计算“酒店到机场”的时间
  2151. string CheckoutHotelTime;
  2152. //处理时间格式
  2153. string hours = "0", mins = "0";
  2154. if (g.Time.Contains("hour"))
  2155. {
  2156. g.Time = g.Time.Replace("hour", "h");
  2157. }
  2158. else if (g.Time.Contains("hours"))
  2159. {
  2160. g.Time = g.Time.Replace("hours", "h");
  2161. }
  2162. g.Time = g.Time.Replace("mins", "m");
  2163. if (g.Time.Contains("h"))
  2164. {
  2165. hours = g.Time.Split('h')[0].Trim();
  2166. }
  2167. else if (!g.Time.Contains("h"))
  2168. {
  2169. mins = g.Time.Split('m')[0].Trim();
  2170. }
  2171. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2172. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2173. _min = _min - Convert.ToInt32(mins);
  2174. if (_min < 0)
  2175. {
  2176. _min = _min + 60;
  2177. _hour = _hour - 1;
  2178. }
  2179. if (hours != "")
  2180. {
  2181. _hour = _hour - Convert.ToInt32(hours);
  2182. }
  2183. if (_hour < 0)
  2184. {
  2185. _hour = _hour + 24;
  2186. }
  2187. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2188. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2189. trip = trip + "\r\n"
  2190. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2191. }
  2192. else
  2193. {
  2194. try
  2195. {
  2196. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2197. //计算“抵达酒店办理入住手续”的时间
  2198. string CheckoutHotelTime;
  2199. //处理时间格式
  2200. string Gtime = "", hours = "0", mins = "0";
  2201. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2202. {
  2203. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2204. }
  2205. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2206. {
  2207. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2208. }
  2209. Gtime = Gtime.Replace("mins", "m");
  2210. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2211. {
  2212. hours = Gtime.Split('h')[0].Trim();
  2213. }
  2214. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2215. {
  2216. mins = Gtime.Split('m')[0].Trim();
  2217. }
  2218. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2219. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2220. _min = _min - Convert.ToInt32(mins);
  2221. if (_min < 0)
  2222. {
  2223. _min = _min + 60;
  2224. _hour = _hour - 1;
  2225. }
  2226. if (hours != "")
  2227. {
  2228. _hour = _hour + Convert.ToInt32(hours);
  2229. }
  2230. if (_hour < 0)
  2231. {
  2232. _hour = _hour + 24;
  2233. }
  2234. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2235. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2236. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2237. gtemp.Diid = di.Id;
  2238. gtemp.Date = "";
  2239. gtemp.Moment = "";
  2240. gtemp.StartAddress = AirPort;
  2241. gtemp.EndAddress = h.HotelAddress;
  2242. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2243. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2244. gmrs.Add(gtemp);
  2245. trip = trip + "\r\n"
  2246. + CheckoutHotelTime + " 乘车前往机场:(" + gtemp.Distance + "," + gtemp.Time + ")";
  2247. }
  2248. catch
  2249. {
  2250. trip = trip + "\r\n"
  2251. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2252. }
  2253. }
  2254. }
  2255. }
  2256. }
  2257. #endregion
  2258. }
  2259. trip = trip
  2260. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2261. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2262. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2263. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2264. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  2265. {
  2266. trip = trip + ",圆满结束此次访问之行!";
  2267. }
  2268. else //如果本日不是行程的最后一天,正常提醒
  2269. {
  2270. trip = trip + ";\r\n" + leaveAirPortTime + " 搭乘专车前往酒店,抵达后办理入住;";
  2271. }
  2272. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2273. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2274. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2275. min = min + 10;
  2276. if (min > 59)
  2277. {
  2278. min = min - 60;
  2279. hour = hour + 1;
  2280. }
  2281. if (hour > 23)
  2282. {
  2283. hour = hour - 24;
  2284. }
  2285. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2286. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2287. }
  2288. #endregion
  2289. }
  2290. //同一天多条数据走分类讨论
  2291. else
  2292. {
  2293. for (int n = 0; n < resultRows.Count(); n++)
  2294. {
  2295. city = "";
  2296. #region 三字码
  2297. string _citycode = resultRows[n]["Three"].ToString();
  2298. //起飞城市三字码
  2299. ThreeCode font_threecode = null;
  2300. string font_citycode = _citycode.Replace("/", string.Empty).Substring(0, 3);
  2301. //抵达城市
  2302. string font_City = "";
  2303. //起飞城市机场
  2304. string font_Airport = "";
  2305. //抵达城市三字码
  2306. ThreeCode back_threecode = null;
  2307. string end_citycode = _citycode.Replace("/", string.Empty).Substring(3, 3);
  2308. //抵达城市机场
  2309. string back_Airport = "";
  2310. //抵达城市
  2311. string back_City = "";
  2312. font_threecode = tcs.getByThree(font_citycode);
  2313. //验证是否存在三字码
  2314. if (font_threecode == null)
  2315. {
  2316. city = city + "【此三字码" + font_citycode + "未收录,请机票同事录入】" + "一";
  2317. font_Airport = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  2318. font_City = "【此三字码" + font_citycode + "未收录,请机票同事录入】";
  2319. }
  2320. else
  2321. {
  2322. city = city + "/" + font_threecode.City;
  2323. font_Airport = font_threecode.AirPort;
  2324. font_City = font_threecode.City; ;
  2325. }
  2326. back_threecode = tcs.getByThree(end_citycode);
  2327. if (back_threecode == null)
  2328. {
  2329. city = city + "【此三字码" + end_citycode + "未收录,请机票同事录入】" + "一";
  2330. back_Airport = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  2331. back_City = "【此三字码" + end_citycode + "未收录,请机票同事录入】";
  2332. }
  2333. else
  2334. {
  2335. city = city + "/" + back_threecode.City;
  2336. //部分黄热病国家,需要提醒打疫苗
  2337. string result = PublicCode.GetCountryInfo(back_threecode.Country);
  2338. if (result.Contains("3"))
  2339. {
  2340. city += "(此地区为黄热病地区,请注意打疫苗)";
  2341. }
  2342. back_Airport = back_threecode.AirPort;
  2343. back_City = back_threecode.City;
  2344. //查询酒店路线要用
  2345. AirPort = back_threecode.AirPort;
  2346. }
  2347. //行程里加入城市
  2348. if (trip == "")
  2349. {
  2350. trip = city.TrimStart('/');
  2351. }
  2352. else
  2353. {
  2354. trip = trip + "\r\n"
  2355. + city.TrimStart('/');
  2356. }
  2357. //起飞航站楼
  2358. string _StartBuilding = resultRows[n]["StartBuilding"].ToString();
  2359. //转机航站楼
  2360. string _EndBuilding = resultRows[n]["EndBuilding"].ToString();
  2361. //起飞时刻
  2362. string _startTime = resultRows[n]["StartTime"].ToString();
  2363. //飞行时刻
  2364. string _flightTime = resultRows[n]["FlightTime"].ToString();
  2365. _flightTime = _flightTime.Contains("H") ? _flightTime.Split('H')[0] + "小时" + _flightTime.Split('H')[1].Split('M')[0] + "分钟" : _flightTime.Split('M')[0] + "分钟";
  2366. //到达时刻
  2367. string _endTime = resultRows[n]["EndTime"].ToString();
  2368. //航班号
  2369. string _flightcode = resultRows[n]["Fliagtcode"].ToString();
  2370. //航司
  2371. AirCompany aircompany = acs.getByShortCode(_flightcode.Substring(0, 2));
  2372. string _aircompany_Name = "";
  2373. if (aircompany == null)
  2374. {
  2375. _aircompany_Name = "【此航司" + resultRows[n]["Fliagtcode"].ToString().Substring(0, 2) + "未收录,请机票同事录入】";
  2376. }
  2377. else
  2378. {
  2379. _aircompany_Name = aircompany.CnName;
  2380. }
  2381. //机型判断
  2382. string airModel = resultRows[n]["AirModel"].ToString();
  2383. airModel = PublicCode.GetLonger(airModel.Substring(0, 1)) + airModel;
  2384. #endregion
  2385. //Sign字段为标识,string类型,含义:0表示为原生黑屏代码、1表示“+1”新增的黑屏代码
  2386. //目前存在两种情况:同一天的多条数据标识为“0->0”或“1->0”
  2387. //如下示例
  2388. //Day ArrivedDate Sign
  2389. //10 10 0
  2390. //10 11 0
  2391. //11 11 1
  2392. //11 12 0
  2393. //12 12 1
  2394. if (n == 0)
  2395. {
  2396. //原生机票代码
  2397. if (resultRows[n]["Sign"].ToString() == "0")
  2398. {
  2399. #region trip编辑
  2400. //根据航班信息推算进入机场的时间
  2401. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前两小时
  2402. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前三小时
  2403. if (result.Contains("2"))
  2404. {
  2405. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2406. }
  2407. if (temp < 0)
  2408. {
  2409. temp = temp + 24;
  2410. }
  2411. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2412. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2413. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2414. if (i > 0)
  2415. {
  2416. #region 酒店
  2417. foreach (HotelReservations h in listht)
  2418. {
  2419. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2420. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  2421. {
  2422. //利用谷歌API计算路线
  2423. if (AirPort != "")
  2424. {
  2425. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2426. if (g != null)
  2427. {
  2428. //计算“酒店到机场”的时间
  2429. string CheckoutHotelTime;
  2430. //处理时间格式
  2431. string hours = "0", mins = "0";
  2432. if (g.Time.Contains("hour"))
  2433. {
  2434. g.Time = g.Time.Replace("hour", "h");
  2435. }
  2436. else if (g.Time.Contains("hours"))
  2437. {
  2438. g.Time = g.Time.Replace("hours", "h");
  2439. }
  2440. g.Time = g.Time.Replace("mins", "m");
  2441. if (g.Time.Contains("h"))
  2442. {
  2443. hours = g.Time.Split('h')[0].Trim();
  2444. }
  2445. else if (!g.Time.Contains("h"))
  2446. {
  2447. mins = g.Time.Split('m')[0].Trim();
  2448. }
  2449. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2450. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2451. _min = _min - Convert.ToInt32(mins);
  2452. if (_min < 0)
  2453. {
  2454. _min = _min + 60;
  2455. _hour = _hour - 1;
  2456. }
  2457. if (hours != "")
  2458. {
  2459. _hour = _hour - Convert.ToInt32(hours);
  2460. }
  2461. if (_hour < 0)
  2462. {
  2463. _hour = _hour + 24;
  2464. }
  2465. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2466. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2467. trip = trip + "\r\n"
  2468. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2469. }
  2470. else
  2471. {
  2472. try
  2473. {
  2474. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2475. //计算“抵达酒店办理入住手续”的时间
  2476. string CheckoutHotelTime;
  2477. //处理时间格式
  2478. string Gtime = "", hours = "0", mins = "0";
  2479. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2480. {
  2481. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2482. }
  2483. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2484. {
  2485. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2486. }
  2487. Gtime = Gtime.Replace("mins", "m");
  2488. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2489. {
  2490. hours = Gtime.Split('h')[0].Trim();
  2491. }
  2492. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2493. {
  2494. mins = Gtime.Split('m')[0].Trim();
  2495. }
  2496. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2497. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2498. _min = _min - Convert.ToInt32(mins);
  2499. if (_min < 0)
  2500. {
  2501. _min = _min + 60;
  2502. _hour = _hour - 1;
  2503. }
  2504. if (hours != "")
  2505. {
  2506. _hour = _hour + Convert.ToInt32(hours);
  2507. }
  2508. if (_hour < 0)
  2509. {
  2510. _hour = _hour + 24;
  2511. }
  2512. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2513. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2514. trip = trip + "\r\n"
  2515. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2516. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2517. gtemp.Diid = di.Id;
  2518. gtemp.Date = "";
  2519. gtemp.Moment = "";
  2520. gtemp.StartAddress = AirPort;
  2521. gtemp.EndAddress = h.HotelAddress;
  2522. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2523. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2524. gmrs.Add(gtemp);
  2525. }
  2526. catch
  2527. {
  2528. trip = trip + "\r\n"
  2529. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2530. }
  2531. }
  2532. }
  2533. }
  2534. }
  2535. #endregion
  2536. }
  2537. trip = trip
  2538. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2539. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2540. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2541. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  2542. #endregion
  2543. }
  2544. //"+1"生成的机票代码
  2545. else if (resultRows[n]["Sign"].ToString() == "1")
  2546. {
  2547. #region trip编辑
  2548. //行程
  2549. trip = trip
  2550. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,提取行李;";
  2551. #endregion
  2552. }
  2553. }
  2554. else if (n > 0)
  2555. {
  2556. //若前行是原生的,则本行判定为转机
  2557. if (resultRows[n - 1]["Sign"].ToString() == "0")
  2558. {
  2559. #region trip编辑
  2560. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 1;//一般提前提前2小时
  2561. if (temp < 0)
  2562. {
  2563. temp = temp + 24;
  2564. }
  2565. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2566. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2567. trip = trip
  2568. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2569. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2570. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2571. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2572. //若为最后一行,则计算后备等时间
  2573. if (n == resultRows.Count() - 1)
  2574. {
  2575. //根据航班信息推算离开机场的时间
  2576. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2577. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2578. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2579. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  2580. {
  2581. trip = trip + ",圆满结束此次访问之行!";
  2582. }
  2583. else //如果本日不是行程的最后一天,正常提醒
  2584. {
  2585. trip = trip + ";\r\n" + leaveAirPortTime + "搭乘专车前往酒店,抵达后办理入住;";
  2586. }
  2587. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2588. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2589. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2590. min = min + 10;
  2591. if (min > 59)
  2592. {
  2593. min = min - 60;
  2594. hour = hour + 1;
  2595. }
  2596. if (hour > 23)
  2597. {
  2598. hour = hour - 24;
  2599. }
  2600. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2601. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2602. }
  2603. #endregion
  2604. }
  2605. //若前行是生成的,则本行判定为新出发
  2606. else if (resultRows[n - 1]["Sign"].ToString() == "1")
  2607. {
  2608. #region trip编辑
  2609. //根据航班信息推算进入机场的时间
  2610. int temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 2;//一般提前提前2小时
  2611. string result = PublicCode.GetCountryInfo(back_threecode.Country);//美国或者欧洲国家提前3小时
  2612. if (result.Contains("2"))
  2613. {
  2614. temp = Convert.ToInt32(_startTime.Substring(0, 2)) - 3;//提前3小时
  2615. }
  2616. if (temp < 0)
  2617. {
  2618. temp = temp + 24;
  2619. }
  2620. GoAirportTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2621. GoAirportTime = GoAirportTime + ":" + _startTime.Substring(2, _startTime.Length - 2);
  2622. //根据航班信息推算离开机场的时间
  2623. temp = Convert.ToInt32(_endTime.Substring(0, 2)) + 1;
  2624. leaveAirPortTime = temp < 10 ? "0" + temp.ToString() : temp.ToString();
  2625. leaveAirPortTime = leaveAirPortTime + ":" + _endTime.Substring(2, _endTime.Length - 2);
  2626. //第一天之后的行程可以加上“酒店出发到机场”的距离和时间
  2627. if (i > 0)
  2628. {
  2629. #region 酒店
  2630. foreach (HotelReservations h in listht)
  2631. {
  2632. if (Convert.ToDateTime(h.CheckInDate) < Convert.ToDateTime(timeList[i])
  2633. && Convert.ToDateTime(h.CheckOutDate) >= Convert.ToDateTime(timeList[i]))
  2634. {
  2635. //利用谷歌API计算路线
  2636. if (AirPort != "")
  2637. {
  2638. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, font_Airport);
  2639. if (g != null)
  2640. {
  2641. //计算“酒店到机场”的时间
  2642. string CheckoutHotelTime;
  2643. //处理时间格式
  2644. string hours = "0", mins = "0";
  2645. if (g.Time.Contains("hour"))
  2646. {
  2647. g.Time = g.Time.Replace("hour", "h");
  2648. }
  2649. else if (g.Time.Contains("hours"))
  2650. {
  2651. g.Time = g.Time.Replace("hours", "h");
  2652. }
  2653. g.Time = g.Time.Replace("mins", "m");
  2654. if (g.Time.Contains("h"))
  2655. {
  2656. hours = g.Time.Split('h')[0].Trim();
  2657. }
  2658. else if (!g.Time.Contains("h"))
  2659. {
  2660. mins = g.Time.Split('m')[0].Trim();
  2661. }
  2662. int _hour = Convert.ToInt32(GoAirportTime.Substring(0, 2));
  2663. int _min = Convert.ToInt32(GoAirportTime.Substring(3, 2));
  2664. _min = _min - Convert.ToInt32(mins);
  2665. if (_min < 0)
  2666. {
  2667. _min = _min + 60;
  2668. _hour = _hour - 1;
  2669. }
  2670. if (hours != "")
  2671. {
  2672. _hour = _hour - Convert.ToInt32(hours);
  2673. }
  2674. if (_hour < 0)
  2675. {
  2676. _hour = _hour + 24;
  2677. }
  2678. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2679. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2680. trip = trip + "\r\n"
  2681. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2682. }
  2683. else
  2684. {
  2685. try
  2686. {
  2687. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, font_Airport);
  2688. //计算“抵达酒店办理入住手续”的时间
  2689. string CheckoutHotelTime;
  2690. //处理时间格式
  2691. string Gtime = "", hours = "0", mins = "0";
  2692. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  2693. {
  2694. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  2695. }
  2696. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  2697. {
  2698. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  2699. }
  2700. Gtime = Gtime.Replace("mins", "m");
  2701. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  2702. {
  2703. hours = Gtime.Split('h')[0].Trim();
  2704. }
  2705. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  2706. {
  2707. mins = Gtime.Split('m')[0].Trim();
  2708. }
  2709. int _hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2710. int _min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2711. _min = _min - Convert.ToInt32(mins);
  2712. if (_min < 0)
  2713. {
  2714. _min = _min + 60;
  2715. _hour = _hour - 1;
  2716. }
  2717. if (hours != "")
  2718. {
  2719. _hour = _hour + Convert.ToInt32(hours);
  2720. }
  2721. if (_hour < 0)
  2722. {
  2723. _hour = _hour + 24;
  2724. }
  2725. CheckoutHotelTime = _hour < 10 ? "0" + _hour.ToString() : _hour.ToString();
  2726. CheckoutHotelTime = CheckoutHotelTime + ":" + (_min < 10 ? "0" + _min.ToString() : _min.ToString());
  2727. trip = trip + "\r\n"
  2728. + CheckoutHotelTime + " 乘车前往机场:(" + g.Distance + "," + g.Time + ")";
  2729. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2730. gtemp.Diid = di.Id;
  2731. gtemp.Date = "";
  2732. gtemp.Moment = "";
  2733. gtemp.StartAddress = AirPort;
  2734. gtemp.EndAddress = h.HotelAddress;
  2735. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2736. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2737. gmrs.Add(gtemp);
  2738. }
  2739. catch
  2740. {
  2741. trip = trip + "\r\n"
  2742. + " 乘车前往机场:(谷歌接口异常,无法测算的路程时间)";
  2743. }
  2744. }
  2745. }
  2746. }
  2747. }
  2748. #endregion
  2749. }
  2750. trip = trip
  2751. + "\r\n" + GoAirportTime + " 抵达" + font_Airport + _StartBuilding + "航站楼,办理登机手续:"
  2752. + "\r\n" + _startTime.Substring(0, 2) + ":" + _startTime.Substring(2, _startTime.Length - 2) + " 搭乘" + _aircompany_Name + "航空公司" + _flightcode + "航班,由" + font_City + "飞往" + back_City + ";"
  2753. + "\r\n" + " (" + font_Airport + "/" + back_Airport + " 机型:" + airModel + " 飞行时间" + (_flightTime) + ");"
  2754. + "\r\n" + _endTime.Substring(0, 2) + ":" + _endTime.Substring(2, _endTime.Length - 2) + " 抵达" + back_Airport + _EndBuilding + "航站楼,办理入境手续,之后前往提取行李";
  2755. if (i == timeList.Count - 1)//如果本日是行程的最后一天,先增加酒店到机场的距离时间,再在末尾提醒“行程圆满结束”
  2756. {
  2757. trip = trip + ",圆满结束此次访问之行!";
  2758. }
  2759. else //如果本日不是行程的最后一天,正常提醒
  2760. {
  2761. trip = trip + ";\r\n" + leaveAirPortTime + " 搭乘专车前往酒店,抵达后办理入住;";
  2762. }
  2763. //整理离开机场的时间 +10分钟为"乘车前往酒店"的时刻
  2764. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  2765. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  2766. min = min + 10;
  2767. if (min > 59)
  2768. {
  2769. min = min - 60;
  2770. hour = hour + 1;
  2771. }
  2772. if (hour > 23)
  2773. {
  2774. hour = hour - 24;
  2775. }
  2776. leaveAirPortTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  2777. leaveAirPortTime = leaveAirPortTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  2778. #endregion
  2779. }
  2780. }
  2781. }
  2782. }
  2783. #endregion
  2784. #region 行程和城市赋值
  2785. if (trip == "" || trip == " " || city == "" || city == " ")
  2786. {
  2787. city = CityInDateList.Find(cid => cid.Date == timeList[i]).City;
  2788. //部分黄热病国家,需要提醒打疫苗
  2789. string result = PublicCode.GetCountryInfo(tcs.getByCity(city)[0].Country);
  2790. if (result.Contains("3"))
  2791. {
  2792. city += "(此地区为黄热病地区,请注意打疫苗)";
  2793. }
  2794. trip = city;
  2795. }
  2796. #endregion
  2797. #region 公务 20210820 贾文滔
  2798. string OATemp = "";//暂存公务活动
  2799. //根据团号和日期获取公务数据
  2800. List<OfficialActivities> listoa = oas.getByDiidAndDate(comb_Diid, timeList[i]);
  2801. //若listoa存在公务数据,进行排序,再进行导入
  2802. if (listoa != null && listoa.Count > 0)
  2803. {
  2804. //利用datatable存放公务活动数据
  2805. DataTable OA_DataTable = new DataTable();
  2806. OA_DataTable.Columns.Add("StartTime", typeof(string)); //activity开始时刻
  2807. OA_DataTable.Columns.Add("EndTime", typeof(string)); //activity结束时刻
  2808. OA_DataTable.Columns.Add("Client", typeof(string)); //activity单位
  2809. OA_DataTable.Columns.Add("Address", typeof(string)); //activity地址
  2810. OA_DataTable.Columns.Add("Contact", typeof(string)); //activity联系人
  2811. OA_DataTable.Columns.Add("Tel", typeof(string)); //activity联系人电话
  2812. OA_DataTable.Columns.Add("Dresscode", typeof(string)); //activity着装要求
  2813. OA_DataTable.Columns.Add("isTranslate", typeof(bool));//是否需要翻译人员
  2814. OA_DataTable.Columns.Add("Language", typeof(string));//是否需要翻译人员
  2815. //处理公务数据
  2816. for (int b = 0; b < listoa.Count; b++)
  2817. {
  2818. //起止时间
  2819. string[] time = new string[2];
  2820. if (listoa[b].Time.Contains('—'))
  2821. {
  2822. time = listoa[b].Time.Split('—');
  2823. }
  2824. else if (listoa[b].Time.Contains('-'))
  2825. {
  2826. time = listoa[b].Time.Split('-');
  2827. }
  2828. //添加数据
  2829. if (time.Length >= 2)
  2830. {
  2831. OA_DataTable.Rows.Add(time[0], time[1], listoa[b].Client, listoa[b].Address, listoa[b].Contact, listoa[b].Tel, listoa[b].Dresscode, listoa[b].IsNeedTrans, listoa[b].Language);
  2832. }
  2833. else
  2834. {
  2835. //PublicCode.GetAlertMsg(this, GetType(), timeList[i] + "的公务数据有误,请检查");
  2836. }
  2837. }
  2838. //排序
  2839. OA_DataTable.DefaultView.Sort = "StartTime asc";
  2840. OA_DataTable = OA_DataTable.DefaultView.ToTable();
  2841. //导入信息
  2842. for (int index = 0; index < OA_DataTable.Rows.Count; index++)
  2843. {
  2844. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2845. {
  2846. if (OATemp != "")
  2847. {
  2848. OATemp = OATemp + "\r\n"
  2849. + OA_DataTable.Rows[index]["StartTime"].ToString()
  2850. + "-"
  2851. + OA_DataTable.Rows[index]["EndTime"].ToString()
  2852. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  2853. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  2854. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  2855. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  2856. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  2857. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  2858. + ",议题:-";
  2859. }
  2860. else
  2861. {
  2862. OATemp = OA_DataTable.Rows[index]["StartTime"].ToString()
  2863. + "-"
  2864. + OA_DataTable.Rows[index]["EndTime"].ToString()
  2865. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  2866. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  2867. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  2868. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  2869. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  2870. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  2871. + ",议题:-";
  2872. }
  2873. }
  2874. else
  2875. {
  2876. //导入公务
  2877. trip = trip + "\r\n"
  2878. + OA_DataTable.Rows[index]["StartTime"].ToString()
  2879. + "-"
  2880. + OA_DataTable.Rows[index]["EndTime"].ToString()
  2881. + " 拜访" + OA_DataTable.Rows[index]["Client"].ToString()
  2882. + ",联系人:" + OA_DataTable.Rows[index]["Contact"].ToString()
  2883. + ",电话:" + OA_DataTable.Rows[index]["Tel"].ToString()
  2884. + ",地址:" + OA_DataTable.Rows[index]["Address"].ToString()
  2885. + ",着装要求:" + OA_DataTable.Rows[index]["Dresscode"].ToString()
  2886. + ",是否需要翻译:" + (bool.Parse(OA_DataTable.Rows[index]["isTranslate"].ToString()) ? "需要翻译人员" + "翻译语种为" + OA_DataTable.Rows[index]["Language"].ToString() : "不需要翻译人员")
  2887. + ",议题:-";
  2888. }
  2889. //当天第一个公务或许都是从酒店出发,因此可计算酒店到公务地址的距离和时间
  2890. if (index == 0)
  2891. {
  2892. #region 酒店
  2893. foreach (HotelReservations h in listht)
  2894. {
  2895. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  2896. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  2897. {
  2898. //利用谷歌API计算路线
  2899. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  2900. if (g != null)
  2901. {
  2902. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2903. {
  2904. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  2905. }
  2906. else
  2907. {
  2908. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  2909. }
  2910. }
  2911. else
  2912. {
  2913. try
  2914. {
  2915. JObject Result = PublicCode.GetDirectionByGoogleApi(h.HotelAddress, OA_DataTable.Rows[0]["Address"].ToString());
  2916. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2917. {
  2918. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  2919. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  2920. }
  2921. else
  2922. {
  2923. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  2924. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  2925. }
  2926. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2927. gtemp.Diid = di.Id;
  2928. gtemp.Date = "";
  2929. gtemp.Moment = "";
  2930. gtemp.StartAddress = h.HotelAddress;
  2931. gtemp.EndAddress = OA_DataTable.Rows[0]["Address"].ToString();
  2932. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2933. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2934. gmrs.Add(gtemp);
  2935. }
  2936. catch
  2937. {
  2938. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2939. {
  2940. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  2941. }
  2942. else
  2943. {
  2944. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  2945. }
  2946. }
  2947. }
  2948. }
  2949. }
  2950. #endregion
  2951. }
  2952. //第二个公务是由中午的餐厅前往公务地址,具有随机性,因此不计算此方向距离时间;但可计算由公务地址回酒店的信息
  2953. else
  2954. {
  2955. #region 酒店
  2956. foreach (HotelReservations h in listht)
  2957. {
  2958. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  2959. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))
  2960. {
  2961. //利用谷歌API计算路线
  2962. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  2963. if (g != null)
  2964. {
  2965. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2966. {
  2967. OATemp = OATemp + "。 (" + g.Distance + "," + g.Time + ")";
  2968. }
  2969. else
  2970. {
  2971. trip = trip + "。 (" + g.Distance + "," + g.Time + ")";
  2972. }
  2973. }
  2974. else
  2975. {
  2976. try
  2977. {
  2978. JObject Result = PublicCode.GetDirectionByGoogleApi(OA_DataTable.Rows[index]["Address"].ToString(), h.HotelAddress);
  2979. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  2980. {
  2981. OATemp = OATemp + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  2982. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  2983. }
  2984. else
  2985. {
  2986. trip = trip + "。 (" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  2987. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  2988. }
  2989. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  2990. gtemp.Diid = di.Id;
  2991. gtemp.Date = "";
  2992. gtemp.Moment = "";
  2993. gtemp.StartAddress = OA_DataTable.Rows[0]["Address"].ToString();
  2994. gtemp.EndAddress = h.HotelAddress;
  2995. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  2996. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  2997. gmrs.Add(gtemp);
  2998. }
  2999. catch
  3000. {
  3001. if (i == 0)//行程第一天的公务放在酒店后面,所以先暂存在一个变量里
  3002. {
  3003. OATemp = OATemp + "。 (谷歌接口异常,无法测算路程时间)";
  3004. }
  3005. else
  3006. {
  3007. trip = trip + "。 (谷歌接口异常,无法测算路程时间)";
  3008. }
  3009. }
  3010. }
  3011. }
  3012. }
  3013. #endregion
  3014. }
  3015. }
  3016. }
  3017. #endregion
  3018. #region 酒店
  3019. foreach (HotelReservations h in listht)
  3020. {
  3021. if (Convert.ToDateTime(h.CheckInDate) <= Convert.ToDateTime(timeList[i])
  3022. && Convert.ToDateTime(h.CheckOutDate) > Convert.ToDateTime(timeList[i]))//不去“》=”的原因是行程最后一天一般不会有酒店
  3023. {
  3024. //利用谷歌API计算路线
  3025. if (AirPort != "")
  3026. {
  3027. GoogleMapApiResult g = gmrs.GetByDiidAddress(di.Id, AirPort, h.HotelAddress);
  3028. if (g != null)
  3029. {
  3030. trip = trip + "\r\n"
  3031. + leaveAirPortTime + " 乘车前往酒店:(" + g.Distance + "," + g.Time + ")";
  3032. //计算“抵达酒店办理入住手续”的时间
  3033. string CheckInHotelTime;
  3034. //处理时间格式
  3035. string hours = "", mins = "";
  3036. if (g.Time.Contains("hour"))
  3037. {
  3038. g.Time = g.Time.Replace("hour", "h");
  3039. }
  3040. else if (g.Time.Contains("hours"))
  3041. {
  3042. g.Time = g.Time.Replace("hours", "h");
  3043. }
  3044. g.Time = g.Time.Replace("mins", "m");
  3045. if (g.Time.Contains("h"))
  3046. {
  3047. hours = g.Time.Split('h')[0].Trim();
  3048. }
  3049. else if (!g.Time.Contains("h"))
  3050. {
  3051. mins = g.Time.Split('m')[0].Trim();
  3052. }
  3053. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  3054. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  3055. min = min + Convert.ToInt32(mins);
  3056. if (min > 59)
  3057. {
  3058. min = min - 60;
  3059. hour = hour + 1;
  3060. }
  3061. if (hours != "")
  3062. {
  3063. hour = hour + Convert.ToInt32(hours);
  3064. }
  3065. if (hour > 23)
  3066. {
  3067. hour = hour - 24;
  3068. }
  3069. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  3070. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  3071. trip = trip + "\r\n"
  3072. + CheckInHotelTime + " 抵达酒店办理入住手续";
  3073. }
  3074. else
  3075. {
  3076. try
  3077. {
  3078. JObject Result = PublicCode.GetDirectionByGoogleApi(AirPort, h.HotelAddress);
  3079. trip = trip + "\r\n"
  3080. + leaveAirPortTime + " 乘车前往酒店:(" + Result["routes"][0]["legs"][0]["distance"]["text"].ToString() + ","
  3081. + Result["routes"][0]["legs"][0]["duration"]["text"].ToString() + ")";
  3082. //计算“抵达酒店办理入住手续”的时间
  3083. string CheckInHotelTime;
  3084. //处理时间格式
  3085. string Gtime = "", hours = "", mins = "";
  3086. if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hour"))
  3087. {
  3088. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hour", "h");
  3089. }
  3090. else if (Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Contains("hours"))
  3091. {
  3092. Gtime = Result["routes"][0]["legs"][0]["duration"]["text"].ToString().Replace("hours", "h");
  3093. }
  3094. Gtime = Gtime.Replace("mins", "m");
  3095. if (!string.IsNullOrEmpty(Gtime) && Gtime.Contains("h"))
  3096. {
  3097. hours = Gtime.Split('h')[0].Trim();
  3098. }
  3099. else if (!string.IsNullOrEmpty(Gtime) && !Gtime.Contains("h"))
  3100. {
  3101. mins = Gtime.Split('m')[0].Trim();
  3102. }
  3103. int hour = Convert.ToInt32(leaveAirPortTime.Substring(0, 2));
  3104. int min = Convert.ToInt32(leaveAirPortTime.Substring(3, 2));
  3105. if (mins != "")
  3106. min = min + Convert.ToInt32(mins);
  3107. if (min > 59)
  3108. {
  3109. min = min - 60;
  3110. hour = hour + 1;
  3111. }
  3112. if (hours != "")
  3113. {
  3114. hour = hour + Convert.ToInt32(hours);
  3115. }
  3116. if (hour > 23)
  3117. {
  3118. hour = hour - 24;
  3119. }
  3120. CheckInHotelTime = hour < 10 ? "0" + hour.ToString() : hour.ToString();
  3121. CheckInHotelTime = CheckInHotelTime + ":" + (min < 10 ? "0" + min.ToString() : min.ToString());
  3122. trip = trip + "\r\n"
  3123. + CheckInHotelTime + " 抵达酒店办理入住手续";
  3124. GoogleMapApiResult gtemp = new GoogleMapApiResult();
  3125. gtemp.Diid = di.Id;
  3126. gtemp.Date = "";
  3127. gtemp.Moment = "";
  3128. gtemp.StartAddress = AirPort;
  3129. gtemp.EndAddress = h.HotelAddress;
  3130. gtemp.Time = Result["routes"][0]["legs"][0]["duration"]["text"].ToString();
  3131. gtemp.Distance = Result["routes"][0]["legs"][0]["distance"]["text"].ToString();
  3132. gmrs.Add(gtemp);
  3133. }
  3134. catch
  3135. {
  3136. trip = trip + "\r\n"
  3137. + " (谷歌接口异常,无法测算的路程时间)";
  3138. }
  3139. }
  3140. }
  3141. trip = trip + "\r\n"
  3142. + " 酒店名称:" + h.HotelName + "\r\n"
  3143. + " 酒店地址:" + h.HotelAddress + "\r\n"
  3144. + " 酒店电话:" + h.HotelTel + " 酒店传真:" + (h.HotelFax == "" ? "-" : h.HotelFax);
  3145. if (i == 0 && !string.IsNullOrEmpty(OATemp))
  3146. {
  3147. trip = trip + "\r\n" + OATemp;
  3148. }
  3149. }
  3150. }
  3151. #endregion
  3152. #region 当天交通工具赋值
  3153. //一般行程第一天都是先乘坐飞机后乘坐汽车
  3154. if (i == 0)
  3155. {
  3156. tlTemp.Traffic_First = "飞机";
  3157. tlTemp.Traffic_Second = "汽车";
  3158. }
  3159. else
  3160. {
  3161. // 根据车导地接表数据判断交通工具:汽车
  3162. List<CarTouristGuideGroundReservations> ListCar = listctg.FindAll(c => Convert.ToDateTime(c.ServiceStartTime) <= Convert.ToDateTime(timeList[i])
  3163. && Convert.ToDateTime(c.ServiceEndTime) >= Convert.ToDateTime(timeList[i]));
  3164. //交通工具:汽车
  3165. if (ListCar.Count > 0)
  3166. {
  3167. tlTemp.Traffic_First = "汽车";
  3168. //交通工具:飞机
  3169. if (airSign == true)
  3170. {
  3171. tlTemp.Traffic_Second = "飞机";
  3172. }
  3173. else
  3174. {
  3175. tlTemp.Traffic_Second = "";
  3176. }
  3177. }
  3178. else
  3179. {
  3180. tlTemp.Traffic_First = "汽车";
  3181. //交通工具:飞机
  3182. if (airSign == true)
  3183. {
  3184. tlTemp.Traffic_Second = "飞机";
  3185. }
  3186. else
  3187. {
  3188. tlTemp.Traffic_Second = "";
  3189. }
  3190. }
  3191. }
  3192. #endregion
  3193. tlTemp.Trip = trip;
  3194. tlTemp.OPer = di.Id;
  3195. tlTemp.OPdate = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
  3196. //tlTemp.OPdate = PublicCode.GetBeijingTime().ToString("yyyy-MM-dd hh:mm:ss");
  3197. tlTemp.issel = 1;
  3198. tlTemp.diffgroup = 1;
  3199. tlTemp.Isdel = 0;
  3200. tls.AddTravelList(tlTemp);
  3201. }
  3202. }
  3203. }
  3204. catch (Exception ex)
  3205. {
  3206. //Response.Write(ex.Message.ToString());
  3207. lblImport.Text = ex.Message;
  3208. }
  3209. lblImport.Text = "数据录入完成";
  3210. }
  3211. }
  3212. }
  3213. }