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 Application_Start(object sender, EventArgs e)
 {
     using (TravelDBEntities context = new TravelDBEntities())
     {
         IQueryable<TravelDAL.Tour> t = from item in context.Tour select item;
         foreach (TravelDAL.Tour tour in t)
         {
             Application["tourvote" + tour.IDTour.ToString()] = 0;
         }
     }
 }
 protected void Session_Start(object sender, EventArgs e)
 {
     using (TravelDBEntities context = new TravelDBEntities())
     {
         double avg = 0;
         double purchases = 0;
         IQueryable<TravelDAL.Tour> t = from item in context.Tour select item;
         foreach (TravelDAL.Tour tour in t)
         {
             purchases += (double)tour.NumberOfPurchases;
         }
         avg = purchases / t.Count();
         Application["avg_purchases"] = avg;
     }
 }
Exemplo n.º 5
0
 static WorkWithDB()
 {
     MinTourPriceInBD = 100000;
     MaxTourPriceInBD = 0;
     using (TravelDBEntities context = new TravelDBEntities())
     {
         int a = 0;
         int b = 0;
         foreach (TravelDAL.Tour tur in context.Tour)
         {
             a = GetMaxOrMinTourPrice(tur.IDTour, false);
             b = GetMaxOrMinTourPrice(tur.IDTour, true);
             if (MinTourPriceInBD > a) MinTourPriceInBD = a;
             if (MaxTourPriceInBD > b) MaxTourPriceInBD = b;
         }
     }
 }
 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
     }
 }
Exemplo n.º 9
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
 }
 protected void ButtonUplode_Click(object sender, EventArgs e)
 {
     try
     {
         HttpFileCollection hfc = Request.Files;
         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);
         }
         for (int i = 0; i < hfc.Count; i++)
         {
             HttpPostedFile hpf = hfc[i];
             if (hpf.ContentLength > 0 && TextForName.Text != "")
             {
                 hpf.SaveAs(Server.MapPath("flash\\images") + "\\" + lastID + "\\" + System.IO.Path.GetFileName(hpf.FileName));
                 Response.Write("<b>File: </b>" + hpf.FileName + " <b>Size:</b> " + hpf.ContentLength + " <b>Type:</b> " + hpf.ContentType + " Uploaded Successfully <br/>");
                 lblError.Visible = false;
             }
             else throw new Exception("File length = 0 or no name for tour!");
         }
     }
     catch (Exception ex)
     {
         lblError.Visible = true;
         lblError.Text = ex.Message;
     }
 }
        protected void PatternMatching()
        {
            string StringForWhere  = "AveragePrice >= MinPrice && Average <= MaxPrice";
            int counter = new int();
            if (TypeForSearch != 0)
            {
                StringForWhere += " && ";
            }

            LinqDataSource quer = new LinqDataSource();
            quer.TableName = "Tour";
            quer.ID = "LinqDataSource1";
            //quer.Where;
            using(var context = new TravelDBEntities())
            {
                if (MaxPrice == 0)
                {
                    MinPrice = 0;
                    MaxPrice = 100500;
                }
                var list = from item in context.Tour
                           where item.AveragePrice >= MinPrice && item.MinimalPrice <= MaxPrice
                           select item.IDTour;
                foreach (int a in list) //checking up results
                {
                    counter++;
                //    str = TextBox1.Text;
                //    str += a.ToString();
                //    TextBox1.Text = str;
                }
                if (counter == 0)
                {
                    //there are no results, too strict requirements      i need message about it
                    return;
                }
                else _quantity = counter;
            }
            MaxPrice = 0;
            Refresh();
        }