Ejemplo n.º 1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // Put user code to initialize the page here
            Global.AuthenticateUser();

            if (Session["BlogFlg"].ToString() != "Y")
            {
                Response.Redirect("../UserMenu.aspx");
            }

            if (Session["Blog"] == null)
            {
                HttpContext.Current.Response.Redirect("../Login.aspx");
            }

            classes.Blog tmpBlog = (classes.Blog)Session["Blog"];

            lnkSignIn.Text = Global.SetLnkSignIn( );
            lnkSignUp.Text = Global.SetLnkSignUp( );

            if (!Page.IsPostBack)
            {
                BindData(tmpBlog);

                //Check for editMode
                if (tmpBlog.EditMode)
                {
                    LoadForEdits(tmpBlog);
                }
                else
                {
                    //setup pic panel for first time thru; TODO: stub this out into it's own function later
                    img1.ImageUrl = "../images/s1x1.gif";
                    img2.ImageUrl = "../images/s1x1.gif";

                    rdoImgMgr1.Items[2].Text = "Add";
                    rdoImgMgr1.Items.Remove("Delete");
                    rdoImgMgr1.Items.Remove("Keep");
                    File1.Disabled = true;

                    rdoImgMgr2.Items[2].Text = "Add";
                    rdoImgMgr2.Items.Remove("Delete");
                    rdoImgMgr2.Items.Remove("Keep");
                    File2.Disabled = true;
                }
            }
        }
Ejemplo n.º 2
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                classes.Blog tmpBlog = (classes.Blog)Session["Blog"];

                // Put user code to initialize the page here
                Global.AuthenticateUser();

                lnkSignIn.Text = Global.SetLnkSignIn( );
                lnkSignUp.Text = Global.SetLnkSignUp( );

                string entryId = GetNewEntryId();

                // Put user code to initialize the page here
                lblMessage.Text         = "The Blog has been posted!";
                lnkPostItem.Text        = System.Configuration.ConfigurationSettings.AppSettings["ServerURL"] + "/Blog/BlogDetails.aspx?iD=" + entryId + "&uId=" + tmpBlog.User + "&iCat=" + tmpBlog.BlogCat;
                lnkPostItem.NavigateUrl = "BlogDetails.aspx?iD=" + entryId;

                Session["Blog"] = null;
            }
        }
Ejemplo n.º 3
0
        private void btnNext_Click(object sender, System.EventArgs e)
        {
            //get object from session object
            classes.Blog tmpBlog = (classes.Blog)Session["Blog"];

            //kick out if validation failed
            if (!(Page.IsValid))
            {
                return;
            }

            //array holder for pics
            string[] strImgPathArray = new string[2];

            //init img array with blank space
            for (int j = 0; j <= 1; j++)
            {
                strImgPathArray[j] = "";
            }

            //Check for new or swapped pics.  The user has 3 possible options here; Keep, delete,
            //or change an image. ***NOTE: For BETA, editing AFTER original post will not be previewed.
            //This means pics will *not* be moved to a temp dir as we do in posting.  This should change eventually.
            //Delete any files in imgDel array
            bool blnProcImgs = false;

            switch (rdoImgMgr1.SelectedValue)
            {
            case "Keep":
                break;

            case "Delete":
                tmpBlog.ImgPath1 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                break;
            }

            switch (rdoImgMgr2.SelectedValue)
            {
            case "Keep":
                break;

            case "Delete":
                tmpBlog.ImgPath2 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                break;
            }

            //Process media
            if (pnlAddImages.Visible && blnProcImgs)
            {
                //Declare and load a struct to send to UploadAllImages()
                BlogStruct bStruct = new BlogStruct();
                bStruct.sBlog    = tmpBlog;
                bStruct.tmpArray = strImgPathArray;

                //AHM comment out temporarily
                bStruct = UpLoadAllImages(ref bStruct);

                tmpBlog = bStruct.sBlog;
            }

            //Save common data and verify strings; we'll check the string after the preview
            tmpBlog.MyBlog = txtDetails.Text;
            tmpBlog.Title  = txtAdTitle.Text;

            //Save object to session variable
            Session["Blog"] = tmpBlog;

            //Goto preview blog
            Response.Redirect("BlogPreview.aspx");
        }
Ejemplo n.º 4
0
        /*
         * Upload any images
         */
        //private string[] UpLoadAllImages(BoardItem bItem, string[] strImgPathArray)
        private classes.Blog UpLoadAllImages(classes.Blog bItem, string[] strImgPathArray)
        {
            string tmpFile;
            string thmbNailPath;
            string userDir = "";
            string strCat;

            strCat = @"blog";

            //set userdir
            userDir = Session["userDir"].ToString();

            //if panel is open check for loaded img files
            if (pnlAddImages.Visible)
            {
                //Collect files names, iterate through each and update accordingly
                HttpFileCollection uploadFilCol = System.Web.HttpContext.Current.Request.Files;
                int count = uploadFilCol.Count;

                //loop thru for each posted file
                for (int i = 0; i < count; i++)
                {
                    //get handle to file
                    HttpPostedFile file = uploadFilCol[i];

                    if (file.ContentLength > (int)0)
                    {
                        //get file name & ext
                        string fileName = Path.GetFileName(file.FileName);
                        string fileExt  = Path.GetExtension(file.FileName).ToLower();

                        //Create dir if non-existent;  We check the root here because BlogEdit lives within root/Blog/
                        if (!(Directory.Exists(Server.MapPath("/" + @"\users\" + userDir + strCat + @"\"))))
                        {
                            Directory.CreateDirectory(Server.MapPath("/" + @"\users\" + userDir + strCat + @"\"));
                        }

                        //get physical path to upload dir
                        string path = Server.MapPath("/" + @"\users\" + userDir + strCat + @"\");

                        //Generate random file name
                        tmpFile = GenerateRandomString(8).ToLower();

                        //concatenate renamed file with ext
                        tmpFile = tmpFile + fileExt;

                        //add together path and file name; This is our fully qualified *temp path where the file gets uploaded
                        strImgPathArray[i] = Path.Combine(path, tmpFile);
                        thmbNailPath       = Path.Combine(path, "thmbNail_" + tmpFile);

                        //Upload to temp dir; We'll write to perm directory after user confirms on preview!
                        //FIXME: Check for file type and size

                        if (fileName != string.Empty)
                        {
                            //resize the image and save
                            //Create an image object from the uploaded file.
                            try
                            {
                                System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(file.InputStream);
                                //Larger Image variables
                                int   maxWidth     = 300;
                                int   maxHeight    = 300;
                                int   sourceWidth  = UploadedImage.Width;
                                int   sourceHeight = UploadedImage.Height;
                                int   sourceX      = 0;
                                int   sourceY      = 0;
                                int   destX        = 0;
                                int   destY        = 0;
                                float nPercent     = 0;
                                float nPercentW    = 0;
                                float nPercentH    = 0;

                                //ThumbNail variables
                                int   maxWidth_T  = 150;
                                int   maxHeight_T = 150;
                                int   destX_T     = 0;
                                int   destY_T     = 0;
                                float nPercent_T  = 0;
                                float nPercentW_T = 0;
                                float nPercentH_T = 0;

                                //Larger Image percents
                                nPercentW = ((float)maxWidth / (float)sourceWidth);
                                nPercentH = ((float)maxHeight / (float)sourceHeight);

                                //Thumbnail percents
                                nPercentW_T = ((float)maxWidth_T / (float)sourceWidth);
                                nPercentH_T = ((float)maxHeight_T / (float)sourceHeight);

                                //Find the biggest change(smallest pct)
                                if (nPercentH < nPercentW)
                                {
                                    //Larger Image Calculations
                                    nPercent = nPercentH;
                                    destX    = System.Convert.ToInt16((maxWidth -
                                                                       (sourceWidth * nPercent)) / 2);

                                    //Thumbnail Calculations
                                    nPercent_T = nPercentH_T;
                                    destX_T    = System.Convert.ToInt16((maxWidth_T -
                                                                         (sourceWidth * nPercent_T)) / 2);
                                }
                                else
                                {
                                    //Larger Image Calculations
                                    nPercent = nPercentW;
                                    destY    = System.Convert.ToInt16((maxHeight -
                                                                       (sourceHeight * nPercent)) / 2);

                                    //ThumbNail Calculations
                                    nPercent_T = nPercentW_T;
                                    destY_T    = System.Convert.ToInt16((maxWidth_T -
                                                                         (sourceHeight * nPercent_T)) / 2);
                                }

                                //Larger Image Calculations
                                int destWidth  = (int)(sourceWidth * nPercent);
                                int destHeight = (int)(sourceHeight * nPercent);

                                //Smaller Image Calculations
                                int destWidth_T  = (int)(sourceWidth * nPercent_T);
                                int destHeight_T = (int)(sourceHeight * nPercent_T);

                                //create the larger bitmap
                                Bitmap bmPhoto = new Bitmap(maxWidth, maxHeight);
                                bmPhoto.SetResolution(UploadedImage.HorizontalResolution,
                                                      UploadedImage.VerticalResolution);

                                //create the thumbnail bitmap
                                Bitmap bmPhotoThmbNail = new Bitmap(maxWidth_T, maxHeight_T);
                                bmPhotoThmbNail.SetResolution(UploadedImage.HorizontalResolution,
                                                              UploadedImage.VerticalResolution);

                                //create larger graphic
                                Graphics grPhoto = Graphics.FromImage(bmPhoto);
                                grPhoto.SmoothingMode   = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                                grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                                grPhoto.Clear(Color.Transparent);
                                grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                                grPhoto.DrawImage(UploadedImage,
                                                  new Rectangle(destX, destY, destWidth, destHeight),
                                                  new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                                                  GraphicsUnit.Pixel);

                                //create thumbnail graphic
                                Graphics grPhotoThmbNail = Graphics.FromImage(bmPhotoThmbNail);
                                grPhotoThmbNail.SmoothingMode   = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                                grPhotoThmbNail.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                                grPhotoThmbNail.Clear(Color.Transparent);
                                grPhotoThmbNail.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                                grPhotoThmbNail.DrawImage(UploadedImage,
                                                          new Rectangle(destX_T, destY_T, destWidth_T, destHeight_T),
                                                          new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                                                          GraphicsUnit.Pixel);

                                //int memberID = 0;

                                //Save the Image(s)
                                // (1) "Saves" the graphic.  It really just updates the bitmap with the contents of the graphic.
                                // Basically saving it in memory.
                                // (2) Actually save the bitmap to the file system.

                                //Larger
                                grPhoto.Save();                   //  (1)
                                bmPhoto.Save(strImgPathArray[i]); //  (2)  .., ImageFormat.Jpeg)

                                //Thumbnail
                                grPhotoThmbNail.Save();
                                bmPhotoThmbNail.Save(thmbNailPath);

                                //strip out superfluous file path
                                strImgPathArray[i] = Path.GetFileName(strImgPathArray[i]);

                                //Find out who is set to "change" or "add" so we know who to update
                                //  - We call the clearSelection() to let ourselves know that index has been processed

                                if (rdoImgMgr1.SelectedValue == "Change" || rdoImgMgr1.SelectedValue == "Add")
                                {
                                    bItem.ImgPath1 = strImgPathArray[i];

                                    rdoImgMgr1.ClearSelection();
                                }
                                else if (rdoImgMgr2.SelectedValue == "Change" || rdoImgMgr2.SelectedValue == "Add")
                                {
                                    bItem.ImgPath2 = strImgPathArray[i];

                                    rdoImgMgr2.ClearSelection();
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorLog.ErrorRoutine(false, "Error: " + ex.Message);
                                lblStatus.Text = "Upload/Save Error!";
                            }
                        } //end if file > 0
                    }
                }         //end for loop
            }
            return(bItem);
        }
Ejemplo n.º 5
0
        /**
         * Update the user's entry changes
         */

        private void imgUpdate_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            //check for valid page
            if (!(Page.IsValid))
            {
                return;
            }

            Boolean delImgs = false;                          //flag to fire delete logic

            classes.Blog tmpBlog = (classes.Blog)Session["Blog"];

            int    newFileCount;
            string strDetails;

            //DateTime dLastModified;
            bool blnProcImgs;

            string[] strImgPathArray = new string[4];
            string[] delImgArray     = new string[4];

            //Init delImgArray
            for (int j = 0; j < 2; j++)
            {
                delImgArray[j] = "";
            }

            //Set Update items
            tmpBlog.Title = Global.CheckString(txtBlogTitle.Text);
            //tmpBlog.MyBlog = Global.CheckString(txtDetails.Text);
            tmpBlog.MyBlog = Global.CheckString(FCKeditor1.Value);

            //Check for new or swapped pics.  The user has 3 possible options here; Keep, delete,
            //, or change an image. ***NOTE: For BETA release entry updates will not use preview_post.
            //This means pics will *not* be moved to a temp dir as we do in first time posts.  This should change eventually.'
            //Delete any files in imgDel array

            blnProcImgs = false;

            switch (rdoImgMgr1.SelectedValue)
            {
            case "Keep":
                tmpBlog.ImgPath1 = "KEEP";
                break;

            case "Delete":
                delImgArray[0]   = Path.GetFileName(tmpBlog.ImgPath1);
                delImgs          = true;
                tmpBlog.ImgPath1 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                tmpBlog.ImgPath1 = "KEEP";
                break;
            }

            switch (rdoImgMgr2.SelectedValue)
            {
            case "Keep":
                tmpBlog.ImgPath2 = "KEEP";
                break;

            case "Delete":
                delImgArray[1]   = Path.GetFileName(tmpBlog.ImgPath2);
                delImgs          = true;
                tmpBlog.ImgPath2 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                tmpBlog.ImgPath2 = "KEEP";
                break;
            }

            //process deletes for pics
            if (delImgs)
            {
                for (int j = 0; j < delImgArray.Length; j++)
                {
                    if (delImgArray[j].Length != 0)
                    {
                        try
                        {
                            DeleteServerFile(Server.MapPath(".\\" + @"\users\" + Session["userDir"].ToString() + @"\blog" + @"\" + delImgArray[j]));
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.ErrorRoutine(false, "Error deleting imgs: " + ex.Message);
                        }
                    }
                }
            }
            delImgs = false;

            //upload imgs
            if (blnProcImgs)
            {
                //strImgPathArray = UpLoadAllImages(strImgPathArray);
                tmpBlog = UpLoadAllImages(tmpBlog, strImgPathArray);
            }

            //call object method to update handler
            if (tmpBlog.UpdateItem())
            {
                Response.Redirect("../Admin/BlogManager.aspx");
            }
            else
            {
                lblStatus.Text  = "SQL Update Error<br>";
                lblStatus.Text += "Length: " + FCKeditor1.Value.Length;
            }
        }
Ejemplo n.º 6
0
        /**
         */
        ////
        //Load up all the data for the selected item
        ///
        public void BindItemData(string Id)
        {
            classes.Blog tmpBlog = new classes.Blog();

            string strSQL;
            string myConnectString;
            string strServerURL;
            string strCat;
            int    iStrCat;
            string userDir;

            tmpBlog.BlogId = Convert.ToInt32(Id);

            //Get connection string to DB
            myConnectString = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;;

            //Get server URL
            strServerURL = System.Configuration.ConfigurationSettings.AppSettings["ServerURL"];

            //Formulate SQL
            //strSQL = "SELECT * FROM tblBlog WHERE iD = '" + Id + "'";

            //query item and user details for entry
            strSQL = "SELECT tblUser.userDir, tblBlog.* FROM tblUser INNER JOIN tblBlog ON tblUser.Id = tblBlog.iUser WHERE tblBlog.id = '" + Id + "'";

            SqlConnection myConnection = new SqlConnection(myConnectString);
            SqlCommand    objCommand   = new SqlCommand(strSQL, myConnection);
            SqlDataReader SQLReader    = null;

            try
            {
                myConnection.Open();
                SQLReader = objCommand.ExecuteReader();

                while (SQLReader.Read() == true)
                {
                    //set control values
                    strCat          = SQLReader["cat"].ToString();
                    iStrCat         = Convert.ToInt32(strCat);
                    tmpBlog.BlogCat = iStrCat;

                    txtDetails.Text  = SQLReader["blog"].ToString();
                    FCKeditor1.Value = SQLReader["blog"].ToString();

                    txtBlogTitle.Text = SQLReader["title"].ToString();

                    tmpBlog.ImgPath1 = SQLReader["txtImgPath1"].ToString();
                    tmpBlog.ImgPath2 = SQLReader["txtImgPath2"].ToString();

                    userDir            = SQLReader["userDir"].ToString();
                    Session["userDir"] = userDir;

                    //scale img place holders to fit page
                    img1.Height = 100;
                    img1.Width  = 100;
                    img2.Height = 100;
                    img2.Width  = 100;

                    //get name of category
                    //strCat = Enum.GetName(typeof(Global.BOARDCAT_DIRS), SQLReader["cat"]); HARDCODED
                    strCat = @"/" + @"blog";

                    //set up pics (*if available) and radio controls
                    if (tmpBlog.ImgPath1.Length > (int)0)
                    {
                        img1.ImageUrl      = strServerURL + "/users/" + userDir + strCat + "/" + Path.GetFileName(tmpBlog.ImgPath1);
                        HiddenField1.Value = img1.ImageUrl;
                        File1.Disabled     = true;
                    }
                    else //don't show delete or keep; set "change" to "add"
                    {
                        rdoImgMgr1.Items[2].Text = "Add";
                        rdoImgMgr1.Items.Remove("Delete");
                        rdoImgMgr1.Items.Remove("Keep");
                    }

                    if (tmpBlog.ImgPath2.Length > (int)0)
                    {
                        img2.ImageUrl      = strServerURL + "/users/" + userDir + strCat + "/" + Path.GetFileName(tmpBlog.ImgPath2);
                        HiddenField2.Value = img2.ImageUrl;
                        File2.Disabled     = true;
                    }
                    else
                    {
                        rdoImgMgr2.Items[2].Text = "Add";
                        rdoImgMgr2.Items.Remove("Delete");
                        rdoImgMgr2.Items.Remove("Keep");
                    }

                    pnlAddImages.Visible = true;
                }

                //save to a session object for later access
                Session["Blog"] = tmpBlog;
            }

            catch (Exception ex)
            {
                ErrorLog.ErrorRoutine(false, "Error:" + ex.Message);
                lblStatus.Text = "BindItemData Error";
            }

            finally
            {
                myConnection.Close();
                SQLReader = null;
            }
        }