Advertisement
Guest User

Untitled

a guest
Jun 12th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.39 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 System.Data;
  8. using System.Data.SqlClient;
  9. using System.Configuration;
  10. using System.Web.Services;
  11. namespace VidYou
  12. {
  13. public partial class Watch : Page
  14. {
  15. static string TheID;
  16.  
  17. protected void Page_Load(object sender, EventArgs e)
  18.  
  19. {
  20.  
  21.  
  22. // شرط للتأكد من انه يوجد متغير في شريط العنوان
  23. if (Request.QueryString.Count != 0)
  24. {
  25. // في حالة كان موجود استعداء معلومات الفيديو
  26. TheID = Request.QueryString["id"];
  27. ViewsCount();
  28. GetVideoInfo();
  29. getdataNewVideos();
  30.  
  31. // التأكد من ان اليوزر مسجل دخول مسبقاً ام لأ
  32. if (HttpContext.Current.User.Identity.IsAuthenticated)
  33. {
  34. // في حالة كان مسجل دخول
  35. // يتم إظهار زر الأعجاب
  36. Label6.Visible = false;
  37. Button1x.Visible = true;
  38. // لأستعداء حالة الاعجاب, هل المستخدم قام بعمل إعجاب أو لأ
  39. LikeButton();
  40. }
  41. else
  42. {
  43.  
  44. Label6.Visible = true;
  45. Button1x.Visible = false;
  46. }
  47. }
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55. public void GetVideoInfo()
  56. {
  57.  
  58. try
  59. {
  60.  
  61. string sql = "Select Video_name,Video_views,Video_Description,Video_likes,video_uploader,Video_Extension from videos where video_id=" + Request.QueryString["id"];
  62. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
  63. {
  64. con.Open();
  65. using (SqlCommand cmd = new SqlCommand(sql, con))
  66. {
  67. SqlDataReader rdr = cmd.ExecuteReader();
  68.  
  69. List<string> Video_name = new List<string>();
  70. List<int> Video_views = new List<int>();
  71. List<string> Video_Description = new List<string>();
  72. List<int> Video_likes = new List<int>();
  73. List<string> video_uploader = new List<string>();
  74. List<string> Video_Extension = new List<string>();
  75.  
  76. while (rdr.Read())
  77. {
  78. Video_name.Add(Convert.ToString(rdr["Video_name"]));
  79.  
  80. Video_views.Add(Convert.ToInt32(rdr["Video_views"]));
  81.  
  82. Video_Description.Add(Convert.ToString(rdr["Video_Description"]));
  83.  
  84. Video_likes.Add(Convert.ToInt32(rdr["Video_likes"]));
  85.  
  86. video_uploader.Add(Convert.ToString(rdr["Video_Uploader"]));
  87.  
  88. Video_Extension.Add(Convert.ToString(rdr["Video_Extension"]));
  89.  
  90. }
  91.  
  92. string[] numbersArray0 = Video_name.ToArray();
  93.  
  94. Label1.Text = numbersArray0[0];
  95.  
  96. int[] numbersArray1 = Video_views.ToArray();
  97.  
  98. Label2.Text = numbersArray1[0].ToString();
  99.  
  100. string[] numbersArray2 = Video_Description.ToArray();
  101.  
  102. Label3.Text = numbersArray2[0];
  103.  
  104.  
  105. int[] numbersArray3 = Video_likes.ToArray();
  106.  
  107. Label4.Text = numbersArray3[0].ToString();
  108.  
  109. string[] numbersArray4 = video_uploader.ToArray();
  110.  
  111. Label5.Text = numbersArray4[0];
  112.  
  113. string[] numbersArray5 = Video_Extension.ToArray();
  114.  
  115. ext.Value = numbersArray5[0];
  116.  
  117. }
  118. con.Close();
  119.  
  120. }
  121.  
  122. }
  123. catch (Exception)
  124. {
  125.  
  126.  
  127. }
  128.  
  129.  
  130. }
  131.  
  132.  
  133. public void ViewsCount()
  134. {
  135.  
  136. try
  137. {
  138.  
  139.  
  140. string sql = "Update videos Set Video_Views=Video_Views+1 WHERE Video_Id = @Video_Id";
  141. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
  142. {
  143. con.Open();
  144. using (SqlCommand cmd = new SqlCommand(sql, con))
  145. {
  146. SqlParameter Videoid = new SqlParameter("@Video_Id", Request.QueryString["id"]);
  147.  
  148.  
  149. cmd.Parameters.Add(Videoid);
  150.  
  151. cmd.ExecuteNonQuery();
  152.  
  153.  
  154. }
  155. con.Close();
  156.  
  157. }
  158.  
  159. }
  160. catch (Exception)
  161. {
  162.  
  163.  
  164. }
  165.  
  166.  
  167.  
  168. }
  169.  
  170.  
  171. public void LikeButton()
  172. {
  173.  
  174. try
  175. {
  176. string sql = "select count(like_id) from likes where Video_id=@Video_id and user_id=@user_id";
  177. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
  178. {
  179. con.Open();
  180. using (SqlCommand cmd = new SqlCommand(sql, con))
  181. {
  182. SqlParameter Videoid = new SqlParameter("@Video_Id", Request.QueryString["id"]);
  183. SqlParameter userid = new SqlParameter("@user_id", GetID());
  184.  
  185. cmd.Parameters.Add(Videoid);
  186. cmd.Parameters.Add(userid);
  187.  
  188. int re = (int)cmd.ExecuteScalar();
  189. if (re > 0)
  190. {
  191. Button1x.Value = "unlike";
  192. }
  193.  
  194. }
  195. con.Close();
  196.  
  197. }
  198. }
  199. catch (Exception)
  200. {
  201.  
  202.  
  203. }
  204.  
  205.  
  206. }
  207.  
  208. protected void Update(object sender, EventArgs e)
  209. {
  210.  
  211. }
  212.  
  213.  
  214.  
  215.  
  216. public void getdataNewVideos()
  217. {
  218.  
  219. try
  220. {
  221.  
  222. int[] viedo_id = new int[7];
  223. string[] viedo_name = new string[7];
  224. int[] viedo_views = new int[7];
  225.  
  226. string sql = "Select top(4) video_id,video_name,video_views,video_date,Video_Uploader from videos order by video_id desc";
  227. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
  228. {
  229. con.Open();
  230. using (SqlCommand cmd = new SqlCommand(sql, con))
  231. {
  232. SqlDataReader rdr = cmd.ExecuteReader();
  233.  
  234. List<int> video_id = new List<int>();
  235. List<string> video_name = new List<string>();
  236. List<int> video_views = new List<int>();
  237. List<DateTime> video_date = new List<DateTime>();
  238. List<string> video_uploader = new List<string>();
  239.  
  240. while (rdr.Read())
  241. {
  242. video_id.Add(Convert.ToInt32(rdr["video_id"]));
  243.  
  244. video_name.Add(Convert.ToString(rdr["video_name"]));
  245.  
  246. video_views.Add(Convert.ToInt32(rdr["video_views"]));
  247.  
  248. video_date.Add(Convert.ToDateTime(rdr["video_date"]));
  249.  
  250. video_uploader.Add(Convert.ToString(rdr["Video_Uploader"]));
  251.  
  252. }
  253.  
  254.  
  255. int[] numbersArray0 = video_id.ToArray();
  256. string[] numbersArray = video_name.ToArray();
  257. int[] numbersArray2 = video_views.ToArray();
  258. DateTime[] numbersArray3 = video_date.ToArray();
  259. string[] numbersArray4 = video_uploader.ToArray();
  260.  
  261.  
  262. for (int i = 0; i < numbersArray0.Length; i++)
  263. {
  264. int Avideo_id = numbersArray0[i];
  265. string AVideo_Name = numbersArray[i];
  266. int AVideo_Views = numbersArray2[i];
  267. string AVideo_date = RelativeDate(numbersArray3[i]);
  268. string AViedo_name = numbersArray4[i];
  269.  
  270.  
  271. PlaceHolder1.Controls.Add(new Literal()
  272. {
  273. Text = "<a href='Watch?id=" + Avideo_id + "'><div class='videos__cards videos__cards--1'>"
  274.  
  275. + "<img class='videos__thumb videos__thumb--1 videos__thumb--IB' src='/Videos/Thumbs/" + Avideo_id + ".jpg'>"
  276. + "<div class='videos__info videos__info--1'>"
  277. + "<strong class='videos__title videos__title--1'>"
  278. + AVideo_Name
  279. + "</strong>"
  280. + "<div class='videos__author videos__author--1'>"
  281. + AViedo_name
  282. + "</div>"
  283. + "<div class='videos__stats'>"
  284. + "<div class='videos__views videos__stats--left videos__views--1'>"
  285. + AVideo_Views + " views"
  286. + "</div>"
  287. + "<div class='videos__date videos__stats--right videos__date--1'>"
  288. + AVideo_date
  289. + "</div></div></div></div></a>"
  290. });
  291.  
  292. }
  293.  
  294.  
  295. }
  296. con.Close();
  297.  
  298. }
  299.  
  300.  
  301. }
  302. catch (Exception)
  303. {
  304.  
  305. throw;
  306. }
  307.  
  308. }
  309.  
  310.  
  311. public static string RelativeDate(DateTime theDate)
  312. {
  313. Dictionary<long, string> thresholds = new Dictionary<long, string>();
  314. int minute = 60;
  315. int hour = 60 * minute;
  316. int day = 24 * hour;
  317. thresholds.Add(60, "{0} seconds ago");
  318. thresholds.Add(minute * 2, "a minute ago");
  319. thresholds.Add(45 * minute, "{0} minutes ago");
  320. thresholds.Add(120 * minute, "an hour ago");
  321. thresholds.Add(day, "{0} hours ago");
  322. thresholds.Add(day * 2, "yesterday");
  323. thresholds.Add(day * 30, "{0} days ago");
  324. thresholds.Add(day * 365, "{0} months ago");
  325. thresholds.Add(long.MaxValue, "{0} years ago");
  326. long since = (DateTime.Now.Ticks - theDate.Ticks) / 10000000;
  327. foreach (long threshold in thresholds.Keys)
  328. {
  329. if (since < threshold)
  330. {
  331. TimeSpan t = new TimeSpan((DateTime.Now.Ticks - theDate.Ticks));
  332. 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());
  333. }
  334. }
  335. return "";
  336. }
  337.  
  338. static int GetID()
  339. {
  340.  
  341. try
  342. {
  343. string sql = "Select user_id from users where username = @usernameoremail OR email = @usernameoremail";
  344. using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["vidyouscon"].ToString()))
  345. {
  346. con.Open();
  347. using (SqlCommand cmd = new SqlCommand(sql, con))
  348. {
  349.  
  350. SqlParameter usernameorpassword = new SqlParameter("@usernameoremail", HttpContext.Current.User.Identity.Name);
  351.  
  352.  
  353. cmd.Parameters.Add(usernameorpassword);
  354.  
  355.  
  356.  
  357. int user_id = (int)cmd.ExecuteScalar();
  358.  
  359.  
  360. return user_id;
  361.  
  362. }
  363. }
  364. }
  365. catch (Exception)
  366. {
  367.  
  368. throw;
  369. }
  370.  
  371.  
  372. }
  373.  
  374. }
  375. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement