示例#1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Guid currentUserID = Guid.Parse(System.Web.Security.Membership.GetUser().ProviderUserKey.ToString());
            int whiskyID = int.Parse(Request.QueryString["id"]);

            freundeTableAdapter freundeTable = new freundeTableAdapter();
            pictureTableAdapter pictureTable = new pictureTableAdapter();

            DataTable uploadedImages = pictureTable.GetImageByUserAndWhisky(currentUserID,int.Parse(Request.QueryString["id"]));

            if (uploadedImages.Rows.Count > 0)
                panUpload.Visible = false;

            DataTable freePictures = new DataTable();
            DataTable freunde = freundeTable.GetFriendsByUserID(currentUserID);
            DataTable allPictures = pictureTable.GetImagesByWhisky(whiskyID);

            if (freunde.Rows.Count == 0 || allPictures.Rows.Count == 0)
                return;

            // Die veroeffentlichten Bilder der freunde herraussuchen bzw. mit freigabe fuer alle User
            foreach (DataRow picture in allPictures.Rows)
            {
                foreach (DataRow friend in freunde.Rows)
                {
                    if ( picture["userID"] == friend["freundID"] &&  ( (int.Parse(picture["allowFriends"].ToString()) == 1 ) || (int.Parse(picture["allowAll"].ToString()) == 1) ) )
                        freePictures.Rows.Add(picture);
                }
            }

            //Falls noch Bilder anzuzeigen sind...
            if (freePictures.Rows.Count == 0)
            {
                Label noSee = new Label();
                noSee.Text = "Hier gibt es nichts zu sehen!";
                panImages.Controls.Add(noSee);
                return;
            }

            //Image-Buttons erstellen
            foreach (DataRow picture in freePictures.Rows)
            {
                Panel imgPanel = new Panel();
                imgPanel.CssClass = "imgpanel";
                ImageButton imgBtnControl = new ImageButton();
                imgBtnControl.CssClass = "select";
                imgBtnControl.ImageUrl = "ImageHandler.ashx?imgid=" + picture["id"];
                imgBtnControl.ImageAlign = ImageAlign.Middle;
                imgBtnControl.ID = picture["id"].ToString();
                imgBtnControl.Click += new ImageClickEventHandler(selectImage_Click);
                imgPanel.Controls.Add(imgBtnControl);

                panImages.Controls.Add(imgPanel);
            }
        }
示例#2
0
 protected void btnUploadImage_Click(object sender, EventArgs e)
 {
     pictureTableAdapter pictureTable = new pictureTableAdapter();
     userwhiskyTableAdapter userwhiskyTable = new userwhiskyTableAdapter();
     Guid currentUserID = Guid.Parse(System.Web.Security.Membership.GetUser().ProviderUserKey.ToString());
     if (fuImageUpload.PostedFile != null &&
         fuImageUpload.FileName != "")
     {
         HttpPostedFile imageFile = fuImageUpload.PostedFile;
         byte[] imageData = new byte[imageFile.ContentLength];
         imageFile.InputStream.Read(imageData, 0, imageFile.ContentLength);
         pictureTable.Insert(
             currentUserID,
             int.Parse(this.Request.QueryString["id"]),
             radioFriendsOnly.Checked,
             radioAllowAll.Checked,
             imageData,
             imageFile.ContentType);
         DataTable pictures = pictureTable.GetImageByUserAndWhisky(currentUserID, int.Parse(this.Request.QueryString["id"]));
         userwhiskyTable.UpdatePicture(int.Parse(pictures.Rows[0]["id"].ToString()),currentUserID,int.Parse(this.Request.QueryString["id"]));
     }
 }