protected void Page_Load(object sender, EventArgs e)
 {
     if (IsPostBack == false)
     {
         using (TravelDBEntities context = new TravelDBEntities())
         {
             TravelDAL.Tour tour = new TravelDAL.Tour();
             tour = (from item in context.Tour
                     where item.IDTour == this.id
                     select item).First();
             rating.Text = tour.AverageMark.ToString();
             views.Text = ((int)(tour.NumberOfPageVisits + 1)).ToString();
             rates.Text = Application["tourvote" + id.ToString()].ToString();
             visits = (int)tour.NumberOfPageVisits + 1;
             Application.Lock();
             tour.NumberOfPageVisits = visits;
             context.SaveChanges();
             Application.UnLock();
             string[] i = Request.Cookies.AllKeys;
             if (i.Contains("tourvote" + id.ToString()) && Request.Cookies["tourvote" + id.ToString()].Expires < DateTime.Now)
             {
                 //UpdateButton.Visible = false;
                 UpdateLabel.Visible = true;
             }
             else
             {
                 //UpdateButton.Visible = true;
                 UpdateLabel.Visible = false;
             }
         }
     }
 }
 public BriefView(int id, bool w)
 {
     obj = new TravelDAL.Tour();
     using (var context = new TravelDBEntities())
     {
         EntityKey key = new EntityKey("TravelDBEntities.Tour", "IDTour", id);
         obj = (TravelDAL.Tour)context.GetObjectByKey(key);
         if (obj != null)
         {
             tourname = obj.Name;
             addinfo = obj.AdditionalInfo;
             if (addinfo.Length > 120) addinfo = addinfo.Substring(0, 120);
             addinfo += "...";
             minprice = obj.MinimalPrice.ToString();
             avgprice = obj.AveragePrice.ToString();
             rating = obj.AverageMark.ToString();
             wide = w;
             foreach (TravelDAL.Country m in obj.Country)
             {
                 countrynames += m.Name;
                 countrynames += " ";
             }
         }
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     CurrentTours = new List<int>();
     Search.Refresh += new SearchParams.ListHandler(Search_Refresh);
     if (!IsPostBack)
     {
         if(Session["srequest"] != null && this.PreviousPage != null)
         {
             if(Session["srequest"].ToString() == "true")
             {
                 string s = ((this.PreviousPage.FindControl("mainsearch") as SearchMainWeb).FindControl("searchbox") as TextBox).Text;
                 CurrentTours = WorkWithDB.AnalyseSearchRequest(s);
             }
         }
         else
         {
             using (var context = new TravelDBEntities())
             {
                 var list = from item in context.Tour select new { ID = item.IDTour };
                 foreach (var a in list)
                 {
                     CurrentTours.Add(a.ID);
                 }
             }
             Search.CurrentTours = this.CurrentTours;
         }
     }
     TravelDAL.Tour obj= new TravelDAL.Tour();
     using (var context = new TravelDBEntities())
     {
         foreach (int id in CurrentTours)
         {
             EntityKey k = new EntityKey("TravelDBEntities.Tour", "IDTour", id);
             obj = (TravelDAL.Tour)context.GetObjectByKey(k);
             if (obj != null)
             {
                 BriefView brt = new BriefView(id, true);
                 brt.BorderColor = System.Drawing.Color.Aquamarine;
                 Panel.Controls.Add(brt);
             }
         }
     }
 }
 protected void Button1_Click(object sender, EventArgs e)
 {
     int[] mTours;
     TravelDAL.Tour obj = new TravelDAL.Tour();
     mTours = ListBox1.GetSelectedIndices();
     using (TravelDBEntities context = new TravelDBEntities())
     {
         foreach (int m in mTours)
         {
             EntityKey key = new EntityKey("TravelDBEntities.Tour", "IDTour",m + 1);
             obj = (TravelDAL.Tour)context.GetObjectByKey(key);
             if (obj != null)
             {
                 context.DeleteObject(obj);
             }
         }
         context.SaveChanges();
         Server.Transfer(Request.FilePath);
     }
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     TravelDAL.Tour obj = new TravelDAL.Tour();
     TravelDAL.Tour simt = new TravelDAL.Tour();
     int id = Int32.Parse(Request.QueryString["id"]);
     //rateobj.IDToRate = id;
     int i = 0;
     using (var context = new TravelDBEntities())
     {
         EntityKey key = new EntityKey("TravelDBEntities.Tour", "IDTour", id);
         obj = (TravelDAL.Tour)context.GetObjectByKey(key);
         Label1.Text = obj.Program;
         Label2.Text = obj.AdditionalInfo;
         Label3.Text = obj.Price;
         if (obj.SimilarTours.Length < 2)
         {
             Label ll = new Label();
             ll.Text = "К сожалению, туров, похожих на этот, нет.";
             PanelForSimilar.Controls.Add(ll);
         }
         else
         {
             int[] mas = WorkWithDB.SearchNumbersInString(obj.SimilarTours);
             foreach(int m in mas)
             {
                 EntityKey k = new EntityKey("TravelDBEntities.Tour", "IDTour", m);
                 simt = (TravelDAL.Tour)context.GetObjectByKey(k);
                 if (simt != null)
                 {
                     i++;
                     BriefView brt = new BriefView(m, true);
                     PanelForSimilar.Controls.Add(brt);
                 }
                 if (i == 2) break;
             }
         }
         //obj.SimilarTours
     }
 }
Пример #6
0
 //ind: 0 - min,  1 - max
 private static int GetMaxOrMinTourPrice(int tourID, bool ind)
 {
     //int[] prices = new int[20];
     int min = 0, avg = 0;
     TravelDAL.Tour obj = new TravelDAL.Tour();
     using (TravelDBEntities context = new TravelDBEntities())
     {
         EntityKey key = new EntityKey("TravelDBEntities.Tour", "IDTour", tourID);
         obj = (TravelDAL.Tour)context.GetObjectByKey(key);
         if (obj != null)
         {
             //prices = SearchPrices(obj.Price);
             min = (int)obj.MinimalPrice;
             avg = (int)obj.AveragePrice;
         }
     }
     return ind == false ? min : avg;
 }
 protected void ButtonDone_Click(object sender, EventArgs e)
 {
     int[] mCountries;  //for lists of countries and types
     int[] mTypes;
     int[] mTours; //we have list of tours which are similar to current, we have to decide in which way it will be better to store it
     //int lastID = 0;
     TravelDAL.Tour obj = new TravelDAL.Tour();
     if (TextForName.Text != "")
     {
         using (TravelDBEntities context = new TravelDBEntities())
         {
             var num = (from item in context.Tour select item).Count();
             if (num != 0) lastID = (from item in context.Tour select item.IDTour).Max();    //getting last id from tours
             lastID++;
             if (!folderExist) CreateFolder(lastID);
         }
         obj.Name = TextForName.Text;
         obj.Program = TextForProgram.Text;
         obj.AdditionalInfo = TextForAddInfo.Text;
         obj.Price = TextForPrice.Text;
         obj.NumberOfPageVisits = 0;
         if (TextForPurchNum.Text != "")
         {
             obj.NumberOfPurchases = int.Parse(TextForPurchNum.Text);
         }
         else obj.NumberOfPurchases = 0;
         if (TextForAvgPrice.Text != "")
         {
             obj.AveragePrice = int.Parse(TextForAvgPrice.Text);
         }
         else obj.AveragePrice = 0;
         if (TextForMinPrice.Text != "")
         {
             obj.MinimalPrice = int.Parse(TextForMinPrice.Text);
         }
         else obj.MinimalPrice = 0;
         if (TextForSpecInfo.Text != "")
         {
             obj.SpecialOfferFlag = true;
             obj.SpecialOfferInfo = TextForSpecInfo.Text;
         }
         mCountries = ListofCountries.GetSelectedIndices(); //array of indexes
         mTypes = ListOfTypes.GetSelectedIndices();
         mTours = ListOfToursNames.GetSelectedIndices();
         using (TravelDBEntities context = new TravelDBEntities())
         {
             var num = (from item in context.Tour select item).Count();
             if(num != 0) lastID = (from item in context.Tour select item.IDTour).Max();    //getting last id from tours
             lastID++;
             obj.IDTour = lastID;
             obj.XmlRef = GenerateXML(obj.IDTour); // generating xml file
             foreach (int m in mTypes)
             {
                 var tip = new TravelDAL.Type{IDType = m + 1};
                 context.Type.Attach(tip);
                 obj.Type.Add(tip);
             }
             foreach (int m in mCountries)
             {
                 var coun = new Country { IDCountry = m + 1 };
                 context.Country.Attach(coun);
                 obj.Country.Add(coun);
             }
             context.Tour.AddObject(obj);
             context.SaveChanges();
         }
     }
     else
     {
         lblNewError.Text = "Enter name of tour!";
         lblNewError.Visible = true;
     }
        // else return; //i need message here, that you've forgotten to input name of tour
 }