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 System.Data;
- using System.Data.SqlClient;
- using System.Configuration;
- using System.Web.Services;
- namespace VidYou
- {
- public partial class Watch : Page
- {
- static string TheID;
- protected void Page_Load(object sender, EventArgs e)
- {
- // شرط للتأكد من انه يوجد متغير في شريط العنوان
- if (Request.QueryString.Count != 0)
- {
- // في حالة كان موجود استعداء معلومات الفيديو
- TheID = Request.QueryString["id"];
- ViewsCount();
- GetVideoInfo();
- getdataNewVideos();
- // التأكد من ان اليوزر مسجل دخول مسبقاً ام لأ
- if (HttpContext.Current.User.Identity.IsAuthenticated)
- {
- // في حالة كان مسجل دخول
- // يتم إظهار زر الأعجاب
- Label6.Visible = false;
- Button1x.Visible = true;
- // لأستعداء حالة الاعجاب, هل المستخدم قام بعمل إعجاب أو لأ
- LikeButton();
- }
- else
- {
- Label6.Visible = true;
- Button1x.Visible = false;
- }
- }
- }
- public void GetVideoInfo()
- {
- try
- {
- string sql = "Select Video_name,Video_views,Video_Description,Video_likes,video_uploader,Video_Extension from videos where video_id=" + Request.QueryString["id"];
- using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
- {
- con.Open();
- using (SqlCommand cmd = new SqlCommand(sql, con))
- {
- SqlDataReader rdr = cmd.ExecuteReader();
- List<string> Video_name = new List<string>();
- List<int> Video_views = new List<int>();
- List<string> Video_Description = new List<string>();
- List<int> Video_likes = new List<int>();
- List<string> video_uploader = new List<string>();
- List<string> Video_Extension = new List<string>();
- while (rdr.Read())
- {
- Video_name.Add(Convert.ToString(rdr["Video_name"]));
- Video_views.Add(Convert.ToInt32(rdr["Video_views"]));
- Video_Description.Add(Convert.ToString(rdr["Video_Description"]));
- Video_likes.Add(Convert.ToInt32(rdr["Video_likes"]));
- video_uploader.Add(Convert.ToString(rdr["Video_Uploader"]));
- Video_Extension.Add(Convert.ToString(rdr["Video_Extension"]));
- }
- string[] numbersArray0 = Video_name.ToArray();
- Label1.Text = numbersArray0[0];
- int[] numbersArray1 = Video_views.ToArray();
- Label2.Text = numbersArray1[0].ToString();
- string[] numbersArray2 = Video_Description.ToArray();
- Label3.Text = numbersArray2[0];
- int[] numbersArray3 = Video_likes.ToArray();
- Label4.Text = numbersArray3[0].ToString();
- string[] numbersArray4 = video_uploader.ToArray();
- Label5.Text = numbersArray4[0];
- string[] numbersArray5 = Video_Extension.ToArray();
- ext.Value = numbersArray5[0];
- }
- con.Close();
- }
- }
- catch (Exception)
- {
- }
- }
- public void ViewsCount()
- {
- try
- {
- string sql = "Update videos Set Video_Views=Video_Views+1 WHERE Video_Id = @Video_Id";
- using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
- {
- con.Open();
- using (SqlCommand cmd = new SqlCommand(sql, con))
- {
- SqlParameter Videoid = new SqlParameter("@Video_Id", Request.QueryString["id"]);
- cmd.Parameters.Add(Videoid);
- cmd.ExecuteNonQuery();
- }
- con.Close();
- }
- }
- catch (Exception)
- {
- }
- }
- public void LikeButton()
- {
- try
- {
- string sql = "select count(like_id) from likes where Video_id=@Video_id and user_id=@user_id";
- using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
- {
- con.Open();
- using (SqlCommand cmd = new SqlCommand(sql, con))
- {
- SqlParameter Videoid = new SqlParameter("@Video_Id", Request.QueryString["id"]);
- SqlParameter userid = new SqlParameter("@user_id", GetID());
- cmd.Parameters.Add(Videoid);
- cmd.Parameters.Add(userid);
- int re = (int)cmd.ExecuteScalar();
- if (re > 0)
- {
- Button1x.Value = "unlike";
- }
- }
- con.Close();
- }
- }
- catch (Exception)
- {
- }
- }
- protected void Update(object sender, EventArgs e)
- {
- }
- public void getdataNewVideos()
- {
- try
- {
- int[] viedo_id = new int[7];
- string[] viedo_name = new string[7];
- int[] viedo_views = new int[7];
- string sql = "Select top(4) video_id,video_name,video_views,video_date,Video_Uploader from videos order by video_id desc";
- using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
- {
- con.Open();
- using (SqlCommand cmd = new SqlCommand(sql, con))
- {
- SqlDataReader rdr = cmd.ExecuteReader();
- List<int> video_id = new List<int>();
- List<string> video_name = new List<string>();
- List<int> video_views = new List<int>();
- List<DateTime> video_date = new List<DateTime>();
- List<string> video_uploader = new List<string>();
- while (rdr.Read())
- {
- video_id.Add(Convert.ToInt32(rdr["video_id"]));
- video_name.Add(Convert.ToString(rdr["video_name"]));
- video_views.Add(Convert.ToInt32(rdr["video_views"]));
- video_date.Add(Convert.ToDateTime(rdr["video_date"]));
- video_uploader.Add(Convert.ToString(rdr["Video_Uploader"]));
- }
- int[] numbersArray0 = video_id.ToArray();
- string[] numbersArray = video_name.ToArray();
- int[] numbersArray2 = video_views.ToArray();
- DateTime[] numbersArray3 = video_date.ToArray();
- string[] numbersArray4 = video_uploader.ToArray();
- for (int i = 0; i < numbersArray0.Length; i++)
- {
- int Avideo_id = numbersArray0[i];
- string AVideo_Name = numbersArray[i];
- int AVideo_Views = numbersArray2[i];
- string AVideo_date = RelativeDate(numbersArray3[i]);
- string AViedo_name = numbersArray4[i];
- PlaceHolder1.Controls.Add(new Literal()
- {
- Text = "<a href='Watch?id=" + Avideo_id + "'><div class='videos__cards videos__cards--1'>"
- + "<img class='videos__thumb videos__thumb--1 videos__thumb--IB' src='/Videos/Thumbs/" + Avideo_id + ".jpg'>"
- + "<div class='videos__info videos__info--1'>"
- + "<strong class='videos__title videos__title--1'>"
- + AVideo_Name
- + "</strong>"
- + "<div class='videos__author videos__author--1'>"
- + AViedo_name
- + "</div>"
- + "<div class='videos__stats'>"
- + "<div class='videos__views videos__stats--left videos__views--1'>"
- + AVideo_Views + " views"
- + "</div>"
- + "<div class='videos__date videos__stats--right videos__date--1'>"
- + AVideo_date
- + "</div></div></div></div></a>"
- });
- }
- }
- con.Close();
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- public static string RelativeDate(DateTime theDate)
- {
- Dictionary<long, string> thresholds = new Dictionary<long, string>();
- int minute = 60;
- int hour = 60 * minute;
- int day = 24 * hour;
- thresholds.Add(60, "{0} seconds ago");
- thresholds.Add(minute * 2, "a minute ago");
- thresholds.Add(45 * minute, "{0} minutes ago");
- thresholds.Add(120 * minute, "an hour ago");
- thresholds.Add(day, "{0} hours ago");
- thresholds.Add(day * 2, "yesterday");
- thresholds.Add(day * 30, "{0} days ago");
- thresholds.Add(day * 365, "{0} months ago");
- thresholds.Add(long.MaxValue, "{0} years ago");
- long since = (DateTime.Now.Ticks - theDate.Ticks) / 10000000;
- foreach (long threshold in thresholds.Keys)
- {
- if (since < threshold)
- {
- TimeSpan t = new TimeSpan((DateTime.Now.Ticks - theDate.Ticks));
- return string.Format(thresholds[threshold], (t.Days > 365 ? t.Days / 365 : (t.Days > 0 ? t.Days : (t.Hours > 0 ? t.Hours : (t.Minutes > 0 ? t.Minutes : (t.Seconds > 0 ? t.Seconds : 0))))).ToString());
- }
- }
- return "";
- }
- static int GetID()
- {
- try
- {
- string sql = "Select user_id from users where username = @usernameoremail OR email = @usernameoremail";
- using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
- {
- con.Open();
- using (SqlCommand cmd = new SqlCommand(sql, con))
- {
- SqlParameter usernameorpassword = new SqlParameter("@usernameoremail", HttpContext.Current.User.Identity.Name);
- cmd.Parameters.Add(usernameorpassword);
- int user_id = (int)cmd.ExecuteScalar();
- return user_id;
- }
- }
- }
- catch (Exception)
- {
- throw;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement