Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.79 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using MySql.Data.MySqlClient;
  8.  
  9. namespace GoldenRing
  10. {
  11. public partial class Default : System.Web.UI.Page
  12. {
  13. public class City
  14. {
  15. public string name;
  16. public int id;
  17. public string coatofarms;
  18. }
  19. public class Sight
  20. {
  21. public string name;
  22. public int id;
  23. }
  24. public class RouteInfo
  25. {
  26. public string name;
  27. public int id;
  28. }
  29.  
  30. public MySqlConnection sqlConn = null;
  31. public MySqlCommand sqlComm = null;
  32. public MySqlDataReader sqlRead = null;
  33.  
  34. public List<City> defaultCities = new List<City>(); //Îñíîâíûå ãîðîäà
  35. public List<City> ancientCities = new List<City>(); //Ãîðîäà ñ ïàìÿòíèêàìè äðåâíåðóññêîãî çîä÷åñòâà
  36. public List<City> architectureCities = new List<City>(); //Ãîðîäà ñ êðóïíûìè ïàìÿòíèêàìè àðõèòåêòóðû
  37. public List<City> historyCities = new List<City>(); //Êðóïíûå öåíòðû èñòîðèè
  38. public List<City> historicalLookCities = new List<City>(); //Ãîðîäà, ñîõðàíèâøèå èñòîðè÷åñêèé îáëèê
  39. public List<RouteInfo> listRoutes = new List<RouteInfo>(); //Ñïèñîê ìàðøðóòîâ
  40. public List<Sight> defaultSights = new List<Sight>(); //Ðåêîìåíäóåìûå äîñòîïðèìå÷àòåëüíîñòè
  41. public List<Sight> defaultSightsAll = new List<Sight>(); //Âàæíûå äîñòîïðèìå÷àòåëüíîñòè ðåãèîíîâ
  42.  
  43. public string description = "";
  44. public string image = "";
  45.  
  46. protected void Page_Load(object sender, EventArgs e)
  47. {
  48. Data.TryAutoLogin(Request, Session);
  49.  
  50. Master.LongPage = 4;
  51.  
  52. //Çàíåñåíèå îáúåêòà â êýø (åñëè îí îòñóòñòâóåò)
  53. if (Cache["Cities_Change"] == null)
  54. {
  55. Cache.Remove("Cities_Change");
  56. string uniqueId = Data.GetUniqueId();
  57. Cache.Insert("Cities_Change", uniqueId);
  58. }
  59.  
  60. if (Cache["Default_image"] == null || Cache["Default_description"] == null)
  61. {
  62. sqlConn = Data.GetMySqlConnection();
  63. sqlComm = new MySqlCommand("SELECT description, image FROM mainpage WHERE page = 1 LIMIT 0, 1", sqlConn);
  64. sqlRead = sqlComm.ExecuteReader();
  65. sqlRead.Read();
  66. description = Data.GetUnicode(sqlRead["description"].ToString());
  67. image = Data.GetUnicode(sqlRead["image"].ToString());
  68. sqlRead.Close();
  69. sqlComm.Dispose();
  70. sqlConn.Close();
  71.  
  72. //Çàíåñåíèå ïåðåìåííûõ â êýø
  73. Cache.Insert("Default_image", image, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  74. Cache.Insert("Default_description", description, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  75. }
  76. else
  77. {
  78. //Èçâëå÷åíèå äàííûõ èç êýøà
  79. image = (string)Cache["Default_image"];
  80. description = (string)Cache["Default_description"];
  81. }
  82.  
  83. if (Cache["Default_defaultCities"] == null)
  84. {
  85. sqlConn = Data.GetMySqlConnection();
  86. sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE smallring = 1 AND main = 1 ORDER BY name", sqlConn);
  87. sqlRead = sqlComm.ExecuteReader();
  88. while (sqlRead.Read())
  89. {
  90. City c = new City();
  91. c.name = sqlRead["name"].ToString();
  92. c.coatofarms = sqlRead["coatofarms"].ToString();
  93. c.id = Int32.Parse(sqlRead["id"].ToString());
  94. defaultCities.Add(c);
  95. }
  96. sqlRead.Close();
  97. sqlComm.Dispose();
  98. sqlConn.Close();
  99.  
  100. //Çàíåñåíèå ìàññèâà â êýø
  101. string[] dependencies = { "Cities_Change" };
  102. Cache.Insert("Default_defaultCities", defaultCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  103. }
  104. else
  105. {
  106. //Èçâëå÷åíèå äàííûõ èç êýøà
  107. defaultCities = (List<City>)Cache["Default_defaultCities"];
  108. }
  109.  
  110. if (Cache["Default_ancientCities"] == null)
  111. {
  112. sqlConn = Data.GetMySqlConnection();
  113. sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 1 ORDER BY name", sqlConn);
  114. sqlRead = sqlComm.ExecuteReader();
  115. while (sqlRead.Read())
  116. {
  117. City c = new City();
  118. c.name = sqlRead["name"].ToString();
  119. c.coatofarms = sqlRead["coatofarms"].ToString();
  120. c.id = Int32.Parse(sqlRead["id"].ToString());
  121. ancientCities.Add(c);
  122. }
  123. sqlRead.Close();
  124. sqlComm.Dispose();
  125. sqlConn.Close();
  126.  
  127. //Çàíåñåíèå ìàññèâà â êýø
  128. string[] dependencies = { "Cities_Change" };
  129. Cache.Insert("Default_ancientCities", ancientCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  130. }
  131. else
  132. {
  133. //Èçâëå÷åíèå äàííûõ èç êýøà
  134. ancientCities = (List<City>)Cache["Default_ancientCities"];
  135. }
  136.  
  137. if (Cache["Default_architectureCities"] == null)
  138. {
  139. sqlConn = Data.GetMySqlConnection();
  140. sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 2 ORDER BY name", sqlConn);
  141. sqlRead = sqlComm.ExecuteReader();
  142. while (sqlRead.Read())
  143. {
  144. City c = new City();
  145. c.name = sqlRead["name"].ToString();
  146. c.coatofarms = sqlRead["coatofarms"].ToString();
  147. c.id = Int32.Parse(sqlRead["id"].ToString());
  148. architectureCities.Add(c);
  149. }
  150. sqlRead.Close();
  151. sqlComm.Dispose();
  152. sqlConn.Close();
  153.  
  154. //Çàíåñåíèå ìàññèâà â êýø
  155. string[] dependencies = { "Cities_Change" };
  156. Cache.Insert("Default_architectureCities", architectureCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  157. }
  158. else
  159. {
  160. //Èçâëå÷åíèå äàííûõ èç êýøà
  161. architectureCities = (List<City>)Cache["Default_architectureCities"];
  162. }
  163.  
  164. if (Cache["Default_historyCities"] == null)
  165. {
  166. sqlConn = Data.GetMySqlConnection();
  167. sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 3 ORDER BY name", sqlConn);
  168. sqlRead = sqlComm.ExecuteReader();
  169. while (sqlRead.Read())
  170. {
  171. City c = new City();
  172. c.name = sqlRead["name"].ToString();
  173. c.coatofarms = sqlRead["coatofarms"].ToString();
  174. c.id = Int32.Parse(sqlRead["id"].ToString());
  175. historyCities.Add(c);
  176. }
  177. sqlRead.Close();
  178. sqlComm.Dispose();
  179. sqlConn.Close();
  180.  
  181. //Çàíåñåíèå ìàññèâà â êýø
  182. string[] dependencies = { "Cities_Change" };
  183. Cache.Insert("Default_historyCities", historyCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  184. }
  185. else
  186. {
  187. //Èçâëå÷åíèå äàííûõ èç êýøà
  188. historyCities = (List<City>)Cache["Default_historyCities"];
  189. }
  190.  
  191. if (Cache["Default_historicalLookCities"] == null)
  192. {
  193. sqlConn = Data.GetMySqlConnection();
  194. sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 4 ORDER BY name", sqlConn);
  195. sqlRead = sqlComm.ExecuteReader();
  196. while (sqlRead.Read())
  197. {
  198. City c = new City();
  199. c.name = sqlRead["name"].ToString();
  200. c.coatofarms = sqlRead["coatofarms"].ToString();
  201. c.id = Int32.Parse(sqlRead["id"].ToString());
  202. historicalLookCities.Add(c);
  203. }
  204. sqlRead.Close();
  205. sqlComm.Dispose();
  206. sqlConn.Close();
  207.  
  208. //Çàíåñåíèå ìàññèâà â êýø
  209. string[] dependencies = { "Cities_Change" };
  210. Cache.Insert("Default_historicalLookCities", historicalLookCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  211. }
  212. else
  213. {
  214. //Èçâëå÷åíèå äàííûõ èç êýøà
  215. historicalLookCities = (List<City>)Cache["Default_historicalLookCities"];
  216. }
  217.  
  218. if (Cache["Default_listRoutes"] == null)
  219. {
  220. sqlConn = Data.GetMySqlConnection();
  221. sqlComm = new MySqlCommand("SELECT id, name FROM route ORDER BY name", sqlConn);
  222. sqlRead = sqlComm.ExecuteReader();
  223. while (sqlRead.Read())
  224. {
  225. RouteInfo rout = new RouteInfo();
  226. rout.name = sqlRead["name"].ToString();
  227. rout.id = Int32.Parse(sqlRead["id"].ToString());
  228. listRoutes.Add(rout);
  229. }
  230. sqlRead.Close();
  231. sqlComm.Dispose();
  232. sqlConn.Close();
  233.  
  234. //Çàíåñåíèå ìàññèâà â êýø
  235. Cache.Insert("Default_listRoutes", listRoutes, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  236. }
  237. else
  238. {
  239. //Èçâëå÷åíèå äàííûõ èç êýøà
  240. listRoutes = (List<RouteInfo>)Cache["Default_listRoutes"];
  241. }
  242.  
  243. if (Cache["Default_defaultSights"] == null)
  244. {
  245. List<Sight> defaultSights_add = new List<Sight>();
  246. //Ïîëó÷åíèå ñïèñêà îñíîâíûõ äîñòîïðèìå÷àòåëüíîñòåé
  247. sqlConn = Data.GetMySqlConnection();
  248. sqlComm = new MySqlCommand("SELECT id, name FROM sights WHERE defaultSight = 1 ORDER BY id", sqlConn);
  249. sqlRead = sqlComm.ExecuteReader();
  250. while (sqlRead.Read())
  251. {
  252. Sight sight = new Sight();
  253. sight.name = sqlRead["name"].ToString();
  254. sight.id = Int32.Parse(sqlRead["id"].ToString());
  255. defaultSights_add.Add(sight);
  256. }
  257. sqlRead.Close();
  258. sqlComm.Dispose();
  259. sqlConn.Close();
  260.  
  261. //Âûáîð äåñÿòè äîñòîïðèìå÷àòåëüíîñòåé, â çàâèñèìîñòè îò íîìåðà íåäåëè
  262.  
  263. int lastWeek = DateTime.Now.DayOfYear / 7;
  264. int countGroups = defaultSights_add.Count / 10;
  265. int lastGroup = 0;
  266. if (countGroups != 0)
  267. {
  268. if (lastWeek > countGroups) lastGroup = lastWeek % countGroups;
  269. else lastGroup = lastWeek;
  270. }
  271.  
  272. int index = 0;
  273. while (lastGroup * 10 + index < defaultSights_add.Count && index < 10)
  274. {
  275. defaultSights.Add(defaultSights_add[lastGroup * 10 + index]);
  276. index++;
  277. }
  278.  
  279. //Çàíåñåíèå ìàññèâà â êýø
  280. Cache.Insert("Default_defaultSights", defaultSights, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  281. }
  282. else
  283. {
  284. //Èçâëå÷åíèå äàííûõ èç êýøà
  285. defaultSights = (List<Sight>)Cache["Default_defaultSights"];
  286. }
  287.  
  288. if (Cache["Default_defaultSightsAll"] == null)
  289. {
  290. //Ïîëó÷åíèå ñïèñêà îñíîâíûõ äîñòîïðèìå÷àòåëüíîñòåé
  291. sqlConn = Data.GetMySqlConnection();
  292. sqlComm = new MySqlCommand("SELECT id, name FROM sights WHERE defaultSight = 1 AND (regionId != -1 || inRegion = 1) ORDER BY name", sqlConn);
  293. sqlRead = sqlComm.ExecuteReader();
  294. while (sqlRead.Read())
  295. {
  296. Sight sight = new Sight();
  297. sight.name = sqlRead["name"].ToString();
  298. sight.id = Int32.Parse(sqlRead["id"].ToString());
  299. defaultSightsAll.Add(sight);
  300. }
  301. sqlRead.Close();
  302. sqlComm.Dispose();
  303. sqlConn.Close();
  304.  
  305. //Çàíåñåíèå ìàññèâà â êýø
  306. Cache.Insert("Default_defaultSightsAll", defaultSightsAll, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
  307. }
  308. else
  309. {
  310. //Èçâëå÷åíèå äàííûõ èç êýøà
  311. defaultSightsAll = (List<Sight>)Cache["Default_defaultSightsAll"];
  312. }
  313.  
  314. Data.AddStat(Request, Response, Stat.Pages.Default, Session);
  315. }
  316.  
  317. protected void Page_Unload(object sender, EventArgs e)
  318. {
  319. if (sqlRead != null) sqlRead.Close();
  320. if (sqlComm != null) sqlComm.Dispose();
  321. if (sqlConn != null) sqlConn.Close();
  322. }
  323. }
  324. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement