Exemplo n.º 1
0
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            LectureNote lNote = new LectureNote();
            lNote.LectureId = -1;
            lNote.CourseId = Session["courseID"].ToString();
            //Check whether or not the title is specified.
            if (txtboxLectureTitle.Text == String.Empty)
            {
                ClientScript.RegisterStartupScript(this.GetType(), "errorTitle",
                                                   "alert('Please provide title of the lecture note!!!');", true);
            }
            else
            {
                lNote.LTitle = txtboxLectureTitle.Text;
                //Check whether or not there is valid file to upload.

                if (fileuploadLectureNote.HasFile)
                {
                    if (fileuploadLectureNote.PostedFile.ContentType.ToLower() == "application/pdf"
                        || fileuploadLectureNote.PostedFile.ContentType.ToLower() == "application/x-mspowerpoint")
                    {
                        //Append date and time in the filename to make it unique.
                        string filename = Path.GetFileNameWithoutExtension(fileuploadLectureNote.FileName) +
                                          DateTime.Now.ToString("_yyyy_mm_dd_HH_mm_ss");
                        string extension = Path.GetExtension(fileuploadLectureNote.FileName);
                        string directory = Server.MapPath("~/CourseMaterials/" + Session["courseID"] + "/LectureNote");
                        //Create directory if no folder toa save the lecture note
                        if (!Directory.Exists(directory))
                        {
                            Directory.CreateDirectory(directory);
                        }
                        lNote.LFileLocation = directory + "/" + filename + extension;
                        fileuploadLectureNote.SaveAs(lNote.LFileLocation);
                        ClientScript.RegisterStartupScript(this.GetType(), "successUpload",
                                                           "alert('Uploaded successfully!!!');", true);
                        LectureNoteController.Save(lNote);
                        Response.Redirect("~/InstructorSite/formManageLectureNote.aspx");
                    }
                    else //If the file format is invalid.
                    {
                        ClientScript.RegisterStartupScript(this.GetType(), "fileFormatError",
                                                           "alert('File format error: Only pdf or ppt files are allowed!!!');",
                                                           true);
                    }

                }
                else //If the path doesn't contain any file
                {
                    ClientScript.RegisterStartupScript(this.GetType(), "failUpload",
                                                       "alert('Please specify the file to upload.!!!');", true);
                }

            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates an instance of LectureNote from the data record in the database.
 /// </summary>
 /// <param name="myRecord">Single row of record.</param>
 /// <returns>An LectureNote.</returns>
 private static LectureNote FillRecord(IDataRecord myRecord)
 {
     LectureNote myLectureNote = new LectureNote();
     //myLectureNote.CourseId = myRecord.GetString(myRecord.GetOrdinal("CourseID"));
     myLectureNote.LectureId = myRecord.GetInt32(myRecord.GetOrdinal("LectureID"));
     myLectureNote.LTitle = myRecord.GetString(myRecord.GetOrdinal("LTitle"));
     myLectureNote.LFileLocation = myRecord.GetString(myRecord.GetOrdinal("LFileLocation"));
     return myLectureNote;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Saves an LectureNote in the database.
        /// </summary>
        /// <param name="myLectureNote">The LectureNote to store.</param>
        /// <returns>The new LectureNote id if the LectureNote is new in the database or the existing ID when an record was updated.</returns>
        public static int Save(LectureNote myLectureNote)
        {
            int result = 0;
            using (SqlConnection myConnection = new SqlConnection(AppSettings.ConnectionString))
            {
                SqlCommand myCommand = new SqlCommand("spInsertUpdateLectureNote", myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@courseID", myLectureNote.CourseId);
                myCommand.Parameters.AddWithValue("@ltitle", myLectureNote.LTitle);
                myCommand.Parameters.AddWithValue("@lfilelocation", myLectureNote.LFileLocation);

                DbParameter retValue = myCommand.CreateParameter();
                retValue.Direction = ParameterDirection.ReturnValue;
                myCommand.Parameters.Add(retValue);

                myConnection.Open();
                myCommand.ExecuteNonQuery();
                result = Convert.ToInt32(retValue.Value);
                myConnection.Close();
            }
            return result;
        }
Exemplo n.º 4
0
 public static int Save(LectureNote myLectureNote)
 {
     return LectureNoteDA.Save(myLectureNote);
 }