Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using MySql.Data.MySqlClient;
- namespace GoldenRing
- {
- public partial class Default : System.Web.UI.Page
- {
- public class City
- {
- public string name;
- public int id;
- public string coatofarms;
- }
- public class Sight
- {
- public string name;
- public int id;
- }
- public class RouteInfo
- {
- public string name;
- public int id;
- }
- public MySqlConnection sqlConn = null;
- public MySqlCommand sqlComm = null;
- public MySqlDataReader sqlRead = null;
- public List<City> defaultCities = new List<City>(); //Îñíîâíûå ãîðîäà
- public List<City> ancientCities = new List<City>(); //Ãîðîäà ñ ïàìÿòíèêàìè äðåâíåðóññêîãî çîä÷åñòâà
- public List<City> architectureCities = new List<City>(); //Ãîðîäà ñ êðóïíûìè ïàìÿòíèêàìè àðõèòåêòóðû
- public List<City> historyCities = new List<City>(); //Êðóïíûå öåíòðû èñòîðèè
- public List<City> historicalLookCities = new List<City>(); //Ãîðîäà, ñîõðàíèâøèå èñòîðè÷åñêèé îáëèê
- public List<RouteInfo> listRoutes = new List<RouteInfo>(); //Ñïèñîê ìàðøðóòîâ
- public List<Sight> defaultSights = new List<Sight>(); //Ðåêîìåíäóåìûå äîñòîïðèìå÷àòåëüíîñòè
- public List<Sight> defaultSightsAll = new List<Sight>(); //Âàæíûå äîñòîïðèìå÷àòåëüíîñòè ðåãèîíîâ
- public string description = "";
- public string image = "";
- protected void Page_Load(object sender, EventArgs e)
- {
- Data.TryAutoLogin(Request, Session);
- Master.LongPage = 4;
- //Çàíåñåíèå îáúåêòà â êýø (åñëè îí îòñóòñòâóåò)
- if (Cache["Cities_Change"] == null)
- {
- Cache.Remove("Cities_Change");
- string uniqueId = Data.GetUniqueId();
- Cache.Insert("Cities_Change", uniqueId);
- }
- if (Cache["Default_image"] == null || Cache["Default_description"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT description, image FROM mainpage WHERE page = 1 LIMIT 0, 1", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- sqlRead.Read();
- description = Data.GetUnicode(sqlRead["description"].ToString());
- image = Data.GetUnicode(sqlRead["image"].ToString());
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ïåðåìåííûõ â êýø
- Cache.Insert("Default_image", image, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- Cache.Insert("Default_description", description, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- image = (string)Cache["Default_image"];
- description = (string)Cache["Default_description"];
- }
- if (Cache["Default_defaultCities"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE smallring = 1 AND main = 1 ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- City c = new City();
- c.name = sqlRead["name"].ToString();
- c.coatofarms = sqlRead["coatofarms"].ToString();
- c.id = Int32.Parse(sqlRead["id"].ToString());
- defaultCities.Add(c);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- string[] dependencies = { "Cities_Change" };
- Cache.Insert("Default_defaultCities", defaultCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- defaultCities = (List<City>)Cache["Default_defaultCities"];
- }
- if (Cache["Default_ancientCities"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 1 ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- City c = new City();
- c.name = sqlRead["name"].ToString();
- c.coatofarms = sqlRead["coatofarms"].ToString();
- c.id = Int32.Parse(sqlRead["id"].ToString());
- ancientCities.Add(c);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- string[] dependencies = { "Cities_Change" };
- Cache.Insert("Default_ancientCities", ancientCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- ancientCities = (List<City>)Cache["Default_ancientCities"];
- }
- if (Cache["Default_architectureCities"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 2 ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- City c = new City();
- c.name = sqlRead["name"].ToString();
- c.coatofarms = sqlRead["coatofarms"].ToString();
- c.id = Int32.Parse(sqlRead["id"].ToString());
- architectureCities.Add(c);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- string[] dependencies = { "Cities_Change" };
- Cache.Insert("Default_architectureCities", architectureCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- architectureCities = (List<City>)Cache["Default_architectureCities"];
- }
- if (Cache["Default_historyCities"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 3 ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- City c = new City();
- c.name = sqlRead["name"].ToString();
- c.coatofarms = sqlRead["coatofarms"].ToString();
- c.id = Int32.Parse(sqlRead["id"].ToString());
- historyCities.Add(c);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- string[] dependencies = { "Cities_Change" };
- Cache.Insert("Default_historyCities", historyCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- historyCities = (List<City>)Cache["Default_historyCities"];
- }
- if (Cache["Default_historicalLookCities"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name, coatofarms FROM cities WHERE main != 1 AND typeCity = 4 ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- City c = new City();
- c.name = sqlRead["name"].ToString();
- c.coatofarms = sqlRead["coatofarms"].ToString();
- c.id = Int32.Parse(sqlRead["id"].ToString());
- historicalLookCities.Add(c);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- string[] dependencies = { "Cities_Change" };
- Cache.Insert("Default_historicalLookCities", historicalLookCities, new System.Web.Caching.CacheDependency(null, dependencies), DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- historicalLookCities = (List<City>)Cache["Default_historicalLookCities"];
- }
- if (Cache["Default_listRoutes"] == null)
- {
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name FROM route ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- RouteInfo rout = new RouteInfo();
- rout.name = sqlRead["name"].ToString();
- rout.id = Int32.Parse(sqlRead["id"].ToString());
- listRoutes.Add(rout);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- Cache.Insert("Default_listRoutes", listRoutes, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- listRoutes = (List<RouteInfo>)Cache["Default_listRoutes"];
- }
- if (Cache["Default_defaultSights"] == null)
- {
- List<Sight> defaultSights_add = new List<Sight>();
- //Ïîëó÷åíèå ñïèñêà îñíîâíûõ äîñòîïðèìå÷àòåëüíîñòåé
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name FROM sights WHERE defaultSight = 1 ORDER BY id", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- Sight sight = new Sight();
- sight.name = sqlRead["name"].ToString();
- sight.id = Int32.Parse(sqlRead["id"].ToString());
- defaultSights_add.Add(sight);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Âûáîð äåñÿòè äîñòîïðèìå÷àòåëüíîñòåé, â çàâèñèìîñòè îò íîìåðà íåäåëè
- int lastWeek = DateTime.Now.DayOfYear / 7;
- int countGroups = defaultSights_add.Count / 10;
- int lastGroup = 0;
- if (countGroups != 0)
- {
- if (lastWeek > countGroups) lastGroup = lastWeek % countGroups;
- else lastGroup = lastWeek;
- }
- int index = 0;
- while (lastGroup * 10 + index < defaultSights_add.Count && index < 10)
- {
- defaultSights.Add(defaultSights_add[lastGroup * 10 + index]);
- index++;
- }
- //Çàíåñåíèå ìàññèâà â êýø
- Cache.Insert("Default_defaultSights", defaultSights, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- defaultSights = (List<Sight>)Cache["Default_defaultSights"];
- }
- if (Cache["Default_defaultSightsAll"] == null)
- {
- //Ïîëó÷åíèå ñïèñêà îñíîâíûõ äîñòîïðèìå÷àòåëüíîñòåé
- sqlConn = Data.GetMySqlConnection();
- sqlComm = new MySqlCommand("SELECT id, name FROM sights WHERE defaultSight = 1 AND (regionId != -1 || inRegion = 1) ORDER BY name", sqlConn);
- sqlRead = sqlComm.ExecuteReader();
- while (sqlRead.Read())
- {
- Sight sight = new Sight();
- sight.name = sqlRead["name"].ToString();
- sight.id = Int32.Parse(sqlRead["id"].ToString());
- defaultSightsAll.Add(sight);
- }
- sqlRead.Close();
- sqlComm.Dispose();
- sqlConn.Close();
- //Çàíåñåíèå ìàññèâà â êýø
- Cache.Insert("Default_defaultSightsAll", defaultSightsAll, null, DateTime.Now.AddDays(7), System.Web.Caching.Cache.NoSlidingExpiration);
- }
- else
- {
- //Èçâëå÷åíèå äàííûõ èç êýøà
- defaultSightsAll = (List<Sight>)Cache["Default_defaultSightsAll"];
- }
- Data.AddStat(Request, Response, Stat.Pages.Default, Session);
- }
- protected void Page_Unload(object sender, EventArgs e)
- {
- if (sqlRead != null) sqlRead.Close();
- if (sqlComm != null) sqlComm.Dispose();
- if (sqlConn != null) sqlConn.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement