PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Kronos/Kronos/LoggedIn.aspx.cs

https://github.com/lle/soen341kronos
C# | 76 lines | 52 code | 12 blank | 12 comment | 9 complexity | 02a83d9380d12aea65a03770cdf8c49a MD5 | raw file
  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 Kronos.CLASSES;
  8. using System.IO;
  9. using LinqToExcel;
  10. namespace Kronos
  11. {
  12. public partial class LoggedIn : System.Web.UI.Page
  13. {
  14. public string Username_logged_in;
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. //make sure nobody changes url to enter in
  18. if (Request.QueryString["Username"] == null || Request.QueryString["Username"]=="") { Response.Redirect("Default.aspx"); }
  19. //decrypt url and store it in a string
  20. if (Request.QueryString["Username"] != null) { Username_logged_in = Decode_BASE64(Request.QueryString["Username"]); }
  21. globalvariables.user_logged = Username_logged_in;
  22. }
  23. protected void UploadButton_Click(object sender, EventArgs e)
  24. {
  25. //upload transcript you save it from my concordia as an excel document, is what I am thinking
  26. if (FileUploadControl.HasFile)
  27. {
  28. try
  29. {
  30. if (FileUploadControl.PostedFile.ContentType == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")//this means it has to be excel file type
  31. {
  32. if (FileUploadControl.PostedFile.ContentLength < 102400)//less the 100kbs
  33. {
  34. FileUploadControl.SaveAs(Server.MapPath("/transcripts/") + Username_logged_in +".xlxs"); //save it in transcripts folder
  35. StatusLabel.Text = "Upload status: File uploaded!";
  36. }
  37. else
  38. StatusLabel.Text = "Upload status: The file has to be less than 100 kb!";
  39. }
  40. else
  41. StatusLabel.Text = "Upload status: Only Excel 2007 files format are accepted!";
  42. }
  43. catch (Exception ex)
  44. {
  45. StatusLabel.Text = "Upload status: Exception Occured " + ex.Message;
  46. }
  47. }
  48. /*try
  49. {
  50. ExcelDataExtract TheSpreadsheet = new ExcelDataExtract(Username_logged_in);
  51. }
  52. catch (Exception error)
  53. {
  54. throw new Exception(error.ToString());
  55. }
  56. * */
  57. }
  58. public static string Decode_BASE64(string encodedData)
  59. {
  60. byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
  61. return System.Text.Encoding.Unicode.GetString(encodedDataAsBytes);
  62. }
  63. }
  64. }