Beispiel #1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            //Get the materialID for the material that is currently being viewed
            string strMaterialID = Request.Params["materialID"];

            if (strMaterialID != null)
            {
                materialID = int.Parse(Request.Params["materialID"]);
            }

            //Obtain the material that is associated with the materialID and setup the header
            Materials.MaterialInfo mi = Materials.getMaterialInfo(materialID);
            RatingImage.ImageUrl     = mi.RatingImage;
            NumericalRating.Text     = string.Format("{0:0.00}", mi.Rating);
            MaterialLabel.Text       = mi.IdentInfo;
            NumberOfRatings.Text     = "" + Materials.getNumberOfRatings(materialID);
            MaterialLink.NavigateUrl = "Materials/" + Materials.getModuleOfMaterial(materialID) + "/" + mi.Link;

            //Identify the user and their access level
            int role = -1;

            if (Context.User.Identity.IsAuthenticated)
            {
                UserAccounts.UserInfo cui = UserAccounts.getUserInfo(Context.User.Identity.Name);
                role = (int)cui.Role;
            }
            //If the user does not have the needed access level then do not allow them to download the material
            if ((role < mi.AccessFlag) || (role > 5))
            {
                MaterialLink.Enabled = false;
            }

            //Setup the material download link and then display format of it
            int position = mi.Link.LastIndexOf('.');

            if (position == -1)
            {
                MaterialLink.Text = "(" + mi.Link + ")";
            }
            else
            {
                MaterialLink.Text = "(" + mi.Link.Substring((position + 1)) + ")";
            }
            MaterialLink.Text = MaterialLink.Text.ToUpper();

            IList tempComment = MaterialComments.getAll(materialID);

            CommentRepeater.DataSource = tempComment;
            CommentRepeater.DataBind();
        }
Beispiel #2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            //Get the materialID for the material being rated
            string strMaterialID = Request.Params["materialID"];

            if (strMaterialID != null)
            {
                //Obtain the material that is associated with the materialID and setup the header
                materialID = int.Parse(Request.Params["materialID"]);
                Materials.MaterialInfo mi = Materials.getMaterialInfo(materialID);
                MaterialIdent.Text       = mi.IdentInfo;
                MaterialLink.NavigateUrl = "Materials/" + Materials.getModuleOfMaterial(mi.MatID) + "/" + mi.Link;

                //Identify the user and their access level
                int role = -1;
                if (Context.User.Identity.IsAuthenticated)
                {
                    UserAccounts.UserInfo cui = UserAccounts.getUserInfo(Context.User.Identity.Name);
                    role = (int)cui.Role;
                }
                //If the user does not have the needed access level then do not allow them to download the material
                if ((role < mi.AccessFlag) || (role > 5))
                {
                    MaterialLink.Enabled = false;
                }

                //Setup the material download link and then setup the display format for it
                int position = mi.Link.LastIndexOf('.');
                if (position == -1)
                {
                    MaterialLink.Text = " (" + mi.Link + ")";
                }
                else
                {
                    MaterialLink.Text = "(" + mi.Link.Substring((position + 1)) + ")";
                }
                MaterialLink.Text = MaterialLink.Text.ToUpper();
            }
        }
        /// <summary>
        /// Respond to the update event, when an item is being edited and
        /// subsequently updated, by updating the info object of the
        /// item being edited and saving the file to a temporary location.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">The event arguments</param>
        private void MaterialsEditor_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            int index = (int)e.Item.ItemIndex;

            Materials.MaterialInfo mi = ((Materials.MaterialInfo)MaterialsEditor.DataList[index]);

            TextBox infoBox = (TextBox)e.Item.Cells[1].FindControl("InfoTextbox");

            mi.IdentInfo = Globals.parseTextInput(infoBox.Text);

            HtmlInputFile f = (HtmlInputFile)(e.Item.Cells[1].FindControl("FileUpload"));

            // Determine the original filename, removing the path.
            string fnameWithPath = f.PostedFile.FileName;
            int    pos           = fnameWithPath.LastIndexOf("\\") + 1;
            string fname         = fnameWithPath.Substring(pos);

            mi.Link = fname;

            // Setup the destination path and create the temporary directory
            // for the user if it doesn't exist.  Delete any file that may be there,
            // then save the file.

            string destinationDir = ConfigurationSettings.AppSettings["MaterialsTempDir"] +
                                    Context.User.Identity.Name + "\\";

            try
            {
                if (!Directory.Exists(destinationDir))
                {
                    Directory.CreateDirectory(destinationDir);
                }

                if (hasDuplicates())
                {
                    MaterialsEditor.Text = "A file with that name already exists.  "
                                           + "Please remove the old file or rename the new file.  ";
                    MaterialsEditor.DataList.RemoveAt(index);
                }
                else
                {
                    MaterialsEditor.Text = "";
                    string filePath = destinationDir + fname;
                    f.PostedFile.SaveAs(filePath);

                    // Virus scan the uploaded file and if it contains a virus, blow the file away and
                    // give the user and error message.
                    if (hasVirus(filePath))
                    {
                        // remove the file
                        File.Delete(filePath);
                        MaterialsEditor.DataList.RemoveAt(index);
                        MaterialsEditor.Text = "*** Virus detected in \"" + fname + "\". File removed from server. ***";
                    }
                }
            }
            catch (Exception ex)
            {
                Exception inner = ex.InnerException;
                MaterialsEditor.Text = "Error uploading file.  Try again.  " + ex.Message + "::" + ex.Source.ToString()
                                       + "----" + ex.TargetSite + " " + ex.StackTrace + "::" + ex.ToString();
                if (inner != null)
                {
                    MaterialsEditor.Text += "<<<<" + inner.Message + "<<<" + inner.TargetSite + " " + inner.StackTrace + "::" + inner.ToString();
                }
                MaterialsEditor.DataList.RemoveAt(index);
            }
        }
 /// <summary>
 /// Respond to the new item event, when the user elects to create a
 /// new item, by creating the specific info class and adding it to
 /// the editor control's data list.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">The event arguments</param>
 private void MaterialsEditor_NewItemEvent(object sender, EventArgs e)
 {
     Materials.MaterialInfo mi = new Materials.MaterialInfo(0, "", "");
     MaterialsEditor.DataList.Add(mi);
 }
        /// <summary>
        /// Respond to the update event, when an item is being edited and
        /// subsequently updated, by updating the info object of the
        /// item being edited and saving the file to a temporary location.
        /// </summary>
        /// <param name="sender">The sender of the event.</param>
        /// <param name="e">The event arguments</param>
        private void MaterialsEditor_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            int index = (int)e.Item.ItemIndex;

            System.Web.UI.WebControls.DropDownList AccessLevelList = (System.Web.UI.WebControls.DropDownList)e.Item.Cells[1].FindControl("AccessLevelList");
            HtmlInputFile f = new HtmlInputFile();

            // Determine the original filename, removing the path.
            string fname = "";

            if (NewRdBtn.Checked)
            {
                f = (HtmlInputFile)(e.Item.Cells[1].FindControl("FileUpload"));

                string fnameWithPath = f.PostedFile.FileName;
                int    pos           = fnameWithPath.LastIndexOf("\\") + 1;
                fname = fnameWithPath.Substring(pos);

                selectedMaterial      = new Materials.MaterialInfo(0, "", "", 0, "", 0, 0);
                selectedMaterial.Link = fname;
            }
            else if (ExistingRdBtn.Checked)
            {
                selectedMaterial = Materials.getMaterialInfo(Convert.ToInt32(MatsDDL.SelectedValue));
            }

            selectedMaterial.IdentInfo = Globals.parseTextInput(InfoTextBox.Text);

            string accessLevel = AccessLevelList.SelectedValue;

            if (accessLevel.Equals("All"))
            {
                selectedMaterial.AccessFlag = -1;
            }
            else if (accessLevel.Equals("Users"))
            {
                selectedMaterial.AccessFlag = 0;
            }
            else if (accessLevel.Equals("Faculty"))
            {
                selectedMaterial.AccessFlag = 1;
            }

            MaterialsEditor.DataList.RemoveAt(index);
            MaterialsEditor.DataList.Add(selectedMaterial);

            // Setup the destination path and create the temporary directory
            // for the user if it doesn't exist.  Delete any file that may be there,
            // then save the file.

            string destinationDir = ConfigurationSettings.AppSettings["MaterialsTempDir"] +
                                    Context.User.Identity.Name + "\\";

            try
            {
                if (!Directory.Exists(destinationDir))
                {
                    Directory.CreateDirectory(destinationDir);
                }

                if (hasDuplicates())
                {
                    MaterialsEditor.Text = "A file with that name already exists.  "
                                           + "Please remove the old file or rename the new file.  ";
                    MaterialsEditor.DataList.RemoveAt(index);
                }
                else if (NewRdBtn.Checked)
                {
                    MaterialsEditor.Text = "";
                    string filePath = destinationDir + fname;
                    f.PostedFile.SaveAs(filePath);

                    // Virus scan the uploaded file and if it contains a virus, blow the file away and
                    // give the user and error message.
                    if (hasVirus(filePath))
                    {
                        // remove the file
                        File.Delete(filePath);
                        MaterialsEditor.DataList.RemoveAt(index);
                        MaterialsEditor.Text = "*** Virus detected in \"" + fname + "\". File removed from server. ***";
                    }
                }
                else if (ExistingRdBtn.Checked)
                {
                    string sourcepath = ConfigurationSettings.AppSettings["MaterialsDir"] +
                                        selectedMaterial.ModuleID + "\\" + selectedMaterial.Link;
                    File.Copy(sourcepath, destinationDir + selectedMaterial.Link, true);
                }
            }
            catch (Exception ex)
            {
                MaterialsEditor.Text = "Error uploading file.  Try again.  " + ex.Message + " :: " + ex.Source.ToString();
                MaterialsEditor.DataList.RemoveAt(index);
            }
        }