示例#1
0
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        if (FileUploadProfilePic.HasFile)
        {
            try
            {
                if (FileUploadProfilePic.PostedFile.ContentType == "image/jpeg")
                {
                    if (FileUploadProfilePic.PostedFile.ContentLength / 1000 < 1000)
                    {
                        string filename = Path.GetFileName(FileUploadProfilePic.FileName);
                        hidPicName.Value = filename;

                        FileUploadProfilePic.SaveAs(Server.MapPath("~/fooPicDB/tmp/") + filename);
                        imgCropImage.ImageUrl = "~/fooPicDB/tmp/" + filename;
                        StatusLabel.Text      = "Upload status: File uploaded!";
                    }
                    else
                    {
                        StatusLabel.Text = "Upload status: The file has to be less than 1 MB!";
                    }
                }
                else
                {
                    StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                }
            }
            catch (Exception ex)
            {
                StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
            }
        }
    }
    protected void UploadButton_Click(object sender, EventArgs e)
    {
        String GoToPicView = "";

        flgErr = false;

        String FolderID = "";  //The FolderName is the unique identifier//

        FolderID = gObj.getNextPK("AlbumFolder");

        if (txtAlbumName.Text != "")
        {
            if (FileUploadProfilePic.HasFile)
            {
                try
                {
                    if (FileUploadProfilePic.PostedFile.ContentType == "image/jpeg")
                    {
                        if (FileUploadProfilePic.PostedFile.ContentLength / 1000 < 1000)
                        {
                            //********CREATING New Album Folder*********//
                            String folder2 = "~/foopicDB/" + Session["UserName"].ToString() + "/" + FolderID;
                            Directory.CreateDirectory(Server.MapPath(folder2));

                            //***Inserting The Folder Into The Database****//
                            String cmdStr = "INSERT INTO AlbumFolder VALUES('" + FolderID + "','" + myUserID +
                                            "','" + txtAlbumName.Text + "','albumcover','" + DateTime.Now.ToString() + "', " +
                                            "'nothing', 2)";

                            SqlCommand scom = new SqlCommand(cmdStr, con);
                            con.Open();
                            scom.ExecuteNonQuery();
                            con.Close();
                            //*************End of Folder Insertion*******//

                            //****Now Trying to Upload the Picture****//

                            String PicID = gObj.getNextPK("AlbumPics");

                            string filename = PicID + "_" + Path.GetFileName(FileUploadProfilePic.FileName);
                            hidPicName.Value = filename; //**File Name For The Picture**//
                            hidAlbumID.Value = FolderID; //**Saving The FolderID*******//

                            FileUploadProfilePic.SaveAs(Server.MapPath("~/fooPicDB/" + myUserID + "/" + FolderID + "/") + filename);

                            StatusLabel.Text = "Upload status: File uploaded!";

                            //***Query To Insert The Picture Into the database****//

                            cmdStr = "INSERT INTO AlbumPics VALUES ('" + FolderID + "','" + PicID + "','" +
                                     filename + "','nothing','" + myUserID + "','" + DateTime.Now.ToString() + "')";

                            scom = new SqlCommand(cmdStr, con);
                            con.Open();
                            scom.ExecuteNonQuery();
                            con.Close();
                            //******************End of Picture Insertion*********//


                            //****Inserting the latest picture as FolderImage*****//
                            cmdStr = "UPDATE AlbumFolder SET AlbumCover = '" + filename + "' WHERE AlbumFolder_PK = '" + FolderID + "'";
                            scom   = new SqlCommand(cmdStr, con);
                            con.Open();
                            scom.ExecuteNonQuery();
                            con.Close();

                            GoToPicView = "true";
                        }
                        else
                        {
                            StatusLabel.Text = "Upload status: The file has to be less than 1 MB!";
                            flgErr           = true;
                        }
                    }
                    else
                    {
                        StatusLabel.Text = "Upload status: Only JPEG files are accepted!";
                        flgErr           = true;
                    }
                }

                catch (Exception ex)
                {
                    StatusLabel.Text = "Upload status: The file could not be uploaded. The following error occured: " + ex.Message;
                    flgErr           = true;
                }
            }

            setPanelView(false, false, true);
            //pnlNewAlbum.Visible = true;
            //pnlGallaryMain.Visible = false;
            //pnlAlbumPicture.Visible = false;

            setButton(false, false);
            //butNewAlbum.Visible = false;
            //butUpdate.Visible = false;

            flgErr = true;
        }
        else
        {
            setPanelView(false, false, true);
            //pnlAlbumPicture.Visible = false;
            //pnlGallaryMain.Visible = false;
            //pnlNewAlbum.Visible = true;

            setButton(false, false);

            //butNewAlbum.Visible = false;
            //butUpdate.Visible = false;

            flgErr = true;
        }

        if (GoToPicView == "true")
        {
            setPanelView(true, false, false);
            //pnlAlbumPicture.Visible = true;
            //pnlGallaryMain.Visible = false;
            //pnlNewAlbum.Visible = false;

            setButton(false, false);
            //butNewAlbum.Visible = false;
            //butUpdate.Visible = false;

            createAlbumPictures(FolderID);
        }
    }