Пример #1
0
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            lblPicCheckType.Visible = false;
            lblPicCheckSize.Visible = false;
            byte[] imageBytes;
            Expert expertProfileObj = (Expert)Session["expertProfileObj"];
            string username = expertProfileObj.username;
            int count = Convert.ToInt32(DbMethods.CheckIfUsernameExists(txtUsername.Text));
            if (count >= 1 && txtUsername.Text != username)
            {
                lblUsernameCheck.Visible = true;
            }
            else if (vlad.IsBlank(txtFirstName.Text) || vlad.IsBlank(txtLastName.Text) || vlad.IsBlank(txtEmail.Text) || vlad.IsBlank(txtUsername.Text) || vlad.IsBlank(txtEmail.Text))
            {
                lblRequired.Visible = true;
            }
            else
            {
                string fileExtension = Path.GetExtension(fileNew1.PostedFile.FileName);//uploaded file extension
                int iFileSize = fileNew1.PostedFile.ContentLength;//uploaded file size
                
                if (fileNew1.FileContent != null && fileNew1.HasFile == true)
                {//if you have a file in the file upload control
                    if (vlad.TestForLegalImageTypes(fileExtension) == false)
                    {//fail
                        lblPicCheckType.Visible = true;
                        lblPicCheckType.Text = fileExtension + " file extension is not allowed. Please use .png, .gif, .jpg, .jpeg, .pdf, .pcd, .fpx, .tif instead";
                    }
                    else if(iFileSize >= 90000)
                    {//fail
                        lblPicCheckSize.Visible = true;
                        lblPicCheckSize.Text = "Your file size is "+ iFileSize+" bytes. Please reduce the size to less than 90 KB (90000 bytes).";
                    }
                    else
                    {
                        MemoryStream ms = new MemoryStream();
                        var img = System.Drawing.Image.FromStream(fileNew1.FileContent);
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        imageBytes = ms.ToArray();
                        Session.Add("picture", imageBytes);

                        Expert updatedExpert = new Expert
                        {
                            firstName = txtFirstName.Text,
                            lastName = txtLastName.Text,
                            username = txtUsername.Text,
                            email = txtEmail.Text,
                            phoneNumber = txtPhoneNumber.Text,
                            linkedIn = txtLinkedIn.Text,
                            aboutMe = aboutMe.Text,
                            picture = imageBytes,
                            skillGroupID = Convert.ToInt32(SkillGroupDropdown.SelectedItem.Value)
                        };
                        int x = DbMethods.UpdateExpert(updatedExpert, (string)Session["TU_ID"]);
                        sm.storeExpertDataInSession();
                        FillControls();
                        Response.Redirect("ExpertPage.aspx?username="******"TU_ID"]);
                    sm.storeExpertDataInSession();
                    FillControls();
                    Response.Redirect("ExpertPage.aspx?username=" + updatedExpert.username);
                }
            }
            
        }
Пример #2
0
        protected void btnCreateProfile_Click(object sender, EventArgs e)
        {
            lblPicCheckSize.Visible = false;
            lblPicCheckType.Visible = false;
            int count = Convert.ToInt32(db.CheckIfUsernameExists(txtUsername.Text));

            if (valid.IsBlank(txtFirstName.Text) || valid.IsBlank(txtLastName.Text) || valid.IsBlank(txtEmail.Text) || valid.IsBlank(txtUsername.Text) || valid.IsBlank(txtEmail.Text))
            {
                lblRequired.Visible = true;
            }
            else if (count >= 1)
            {
                lblUsernameCheck.Visible = true;
            }
            else
            {
                string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName); //uploaded file extension
                int    iFileSize     = FileUpload1.PostedFile.ContentLength;               //uploaded file size
                if (FileUpload1.FileContent != null && FileUpload1.HasFile)
                {
                    if (valid.TestForLegalImageTypes(fileExtension) == false)
                    {//fail
                        lblPicCheckType.Visible = true;
                        lblPicCheckType.Text    = fileExtension + " file extension is not allowed. Please use .png, .gif, .jpg, .jpeg, .pdf, .pcd, .fpx, .tif instead";
                    }
                    else if (iFileSize >= 90000)
                    {//fail
                        lblPicCheckSize.Visible = true;
                        lblPicCheckSize.Text    = "Your file size is " + iFileSize + " bytes. Please reduce the size to less than 90 KB (90000 bytes).";
                    }
                    else
                    {
                        MemoryStream ms  = new MemoryStream();
                        var          img = System.Drawing.Image.FromStream(FileUpload1.FileContent);
                        img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                        imageBytes = ms.ToArray();
                        Session.Add("picture", imageBytes);
                    }
                }
                else
                {
                    string     FilePath = System.Web.VirtualPathUtility.ToAbsolute("~/Images/TUOwls_logo.png");
                    FileStream fs       = new FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                    imageBytes = new byte[fs.Length];
                    fs.Read(imageBytes, 0, Convert.ToInt32(fs.Length));
                    fs.Close();
                    MemoryStream ms = new MemoryStream();
                    Session.Add("picture", imageBytes);
                }

                Expert newExpert = new Expert
                {
                    tuID           = (string)Session["TU_ID"],
                    username       = txtUsername.Text,
                    firstName      = txtFirstName.Text,
                    lastName       = txtLastName.Text,
                    college        = (string)Session["School"],
                    major          = (string)Session["Major_1"],
                    email          = txtEmail.Text,
                    dateJoined     = DateTime.Now,
                    phoneNumber    = txtPhoneNumber.Text,
                    aboutMe        = aboutMe.Text,
                    linkedIn       = txtLinkedIn.Text,
                    picture        = (byte[])Session["picture"],
                    isActive       = true,
                    skillGroupID   = Int32.Parse(SkillGroupDropdown.SelectedValue),
                    genderID       = Int32.Parse(genderDropdown.SelectedValue),
                    ethnicityID    = Int32.Parse(ethnicityDropdown.SelectedValue),
                    lastUpdateDate = DateTime.Now,
                    lastUpdateUser = txtLastName.Text + ", " + txtFirstName.Text
                };

                DbMethods      dbmethods         = new DbMethods();
                SessionMethods sessionMethodsObj = new SessionMethods();
                int            result            = dbmethods.CreateExpert(newExpert);

                sessionMethodsObj.storeExpertDataInSession();
                Response.Redirect("ExpertPage.aspx?username=" + newExpert.username);
                //Response.Write(result);
            }
        }