Ejemplo n.º 1
0
/**
 */
        private void btnNext_Click(object sender, System.EventArgs e)
        {
            classes.BoardItem tmpItem = new classes.BoardItem();

            ErrorLog.ErrorRoutine(false, "Post:btnNext_Click: " + Session.SessionID + " isPB: " + Page.IsPostBack);

            tmpItem.Category = 1;           //hardcoded for ALWAYS surfboards
            tmpItem.AdType   = 1;           //hardcoded for ALWAYS surfboards

            tmpItem.Location = Convert.ToInt32(cboRegion.SelectedItem.Value);
            tmpItem.Ship     = Convert.ToInt32(rdoShip.SelectedItem.Value);
            tmpItem.Town     = txtTown.Text;
            tmpItem.EditMode = false;

            tmpItem.Zip        = txtZip.Text;
            tmpItem.ICondition = Convert.ToInt32(radioConditionType.SelectedItem.Value);

            //Used for convenient 1-click editing from emails.
            BoardHunt.classes.RandomPassword pwdGen = new BoardHunt.classes.RandomPassword();
            tmpItem.ActivateCode = pwdGen.Generate();

            //Save board object to session variable
            Session["Item"] = tmpItem;
            tmpItem         = null;

            //to next wizard page
            Response.Redirect("post_item.aspx", false);
        }
Ejemplo n.º 2
0
        public string GenerateInvNum(string srvNum, string id)
        {
            //BHServiceNum-UserId-Random
            //BH04-162-2342xy

            string retVal;

            retVal = "BH";

            //pad serivce for 2 digits
            if (srvNum.Length == 1)
            {
                retVal += srvNum.PadLeft(2, '0');
            }
            else
            {
                retVal += srvNum;
            }

            BoardHunt.classes.RandomPassword iGen = new BoardHunt.classes.RandomPassword();
            retVal += "-" + id + "-" + iGen.Generate(6).ToUpper();

            return(retVal);
        }
Ejemplo n.º 3
0
/*
 */
        /*
         * Upload any/all images
         */

        private string UpLoadAllImages()
        {
            string tmpFile;
            string userDir = string.Empty;

            string fullPathAndFile      = string.Empty;
            string fullPathAndFile_Thmb = string.Empty;

            //get user dir
            userDir = Session["userDir"].ToString();

            //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();

                    //check for temp dir and create if non-existent; this would be bad right here
                    if (!(Directory.Exists(Server.MapPath(".\\" + @"\users\" + userDir))))
                    {
                        Directory.CreateDirectory(Server.MapPath(".\\" + @"\users\" + userDir));
                    }

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

                    //Generate random file name
                    BoardHunt.classes.RandomPassword pwdGen = new BoardHunt.classes.RandomPassword();
                    tmpFile = pwdGen.Generate(8);

                    //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
                    fullPathAndFile      = Path.Combine(path, tmpFile);
                    fullPathAndFile_Thmb = Path.Combine(path, "thmb_" + tmpFile);

                    //Upload directly user dir
                    //FIXME: Check for file type and size

                    if (fileName != string.Empty)   //TODO: maybe check for strLength > 0
                    {
                        //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  = picSizeBigX;
                            int maxHeight = picSizeBigY;

                            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  = picSizeSmX;
                            int   maxHeight_T = picSizeSmY;
                            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(fullPathAndFile); //  (2)  .., ImageFormat.Jpeg)

                            //Just get the file name to save to db
                            fullPathAndFile = Path.GetFileName(fullPathAndFile);

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

                            //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
                            //TODO: append  (&& File1.Value.Length>0)
                            if (rdoImgMgr1.SelectedValue == "Change" || rdoImgMgr1.SelectedValue == "Add")
                            {
                                rdoImgMgr1.ClearSelection();
                            }
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.ErrorRoutine(false, "EditProfile:UpdateAllImages-Error: " + ex.Message);
                            lblStatus.Text = "Resize/Save Error";
                        }
                    }
                    else
                    {
                        fullPathAndFile = string.Empty;
                    }
                }
            }

            return(fullPathAndFile);
        }//end function
Ejemplo n.º 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string tmpFile;

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


            ErrorLog.ErrorRoutine(false, "Uploader:Page_Load");

            //DataRow dr in dsItems.Tables[0].Rows


            //ErrorLog.ErrorRoutine(false, "HeaderCount: " + Request.Headers.Count);

            //ErrorLog.ErrorRoutine(false, "FormCount: " + Request.Form.Count);
            //ErrorLog.ErrorRoutine(false, "Content-Length: " + Request.ContentLength);

            ////NameValueCollection coll = Request.Form;
            //foreach (string key in Request.Headers)
            //{
            //    ErrorLog.ErrorRoutine(false, "Header: " + key + ": " + Request.Headers[key]);
            //}


            ////NameValueCollection coll = Request.Form;
            //foreach (string key in Request.Form)
            //{
            //    //ErrorLog.ErrorRoutine(false,"Key: " + key + ": " + Request.Form[key]);
            //}

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

            //Collect files names, iterate through each and update accordingly
            HttpFileCollection uploadFilCol = System.Web.HttpContext.Current.Request.Files;
            int count = uploadFilCol.Count;

            ErrorLog.ErrorRoutine(false, "Uploader:Page_Load:FileCount: " + count);

            if (count < 1)
            {
                return;
            }

            //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)        //needed?  we already checked
                {
                    strImgPathArray[i] = string.Empty;


                    //get file name & ext
                    string fileName = Path.GetFileName(file.FileName);
                    string fileExt  = Path.GetExtension(file.FileName).ToLower();

                    ErrorLog.ErrorRoutine(false, "fileName: " + fileName + " Ext: " + fileExt);

                    //check for temp dir and create if non-existent
                    if (!(Directory.Exists(Server.MapPath("..\\" + @"\tmp\"))))
                    {
                        ErrorLog.ErrorRoutine(false, "creating dir");
                        try
                        {
                            Directory.CreateDirectory(Server.MapPath("..\\" + @"\tmp\"));
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.ErrorRoutine(false, "error: " + ex.Message);
                            return;
                        }
                        ErrorLog.ErrorRoutine(false, "done dir");
                    }

                    //get physical path to temp dir for upload
                    string path = Server.MapPath("..\\" + @"\tmp\");
                    ErrorLog.ErrorRoutine(false, "Path: " + path);

                    //Generate random file name
                    //tmpFile = classes.RandomPassword.(8).ToLower();
                    BoardHunt.classes.RandomPassword oRp = new BoardHunt.classes.RandomPassword();
                    tmpFile = oRp.Generate(8);

                    //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);
                    //tmpStruct.tmpArray[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     = 400;
                            int   maxHeight    = 400;
                            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  = 75;
                            int   maxHeight_T = 75;
                            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)
                            ErrorLog.ErrorRoutine(false, "Saved Photo: " + strImgPathArray[i]);

                            //strip out the superfluous server path and just save the file name;  this was the cause of much grief as we were saving the entire path!
                            strImgPathArray[i] = Path.GetFileName(strImgPathArray[i]);

                            //Thumbnail
                            grPhotoThmbNail.Save();
                            bmPhotoThmbNail.Save(thmbNailPath);
                            ErrorLog.ErrorRoutine(false, "Saved thmbNailPath: " + thmbNailPath);
                        }
                        catch (Exception ex)
                        {
                            ErrorLog.ErrorRoutine(false, "Uploader:UpdateAllImages-Error: " + ex.Message);
                        }
                    }
                    else
                    {
                        strImgPathArray[i] = string.Empty;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        private void imgContact_Click(object sender, System.EventArgs e)
        {
            if (!Page.IsValid)
            {
                return;
            }

            //Connect to DB
            String strSQL;
            String myConnectString;

            //Formulate connect string to DB
            myConnectString = ConfigurationManager.ConnectionStrings["myConn"].ConnectionString;;

            //Build SQL
            strSQL = "SELECT * FROM tblUser WHERE txtEmail='" + txtEmail.Text + "'";

            SqlConnection myConnection = new SqlConnection(myConnectString);

            try
            {
                SqlCommand objCommand = new SqlCommand(strSQL, myConnection);
                myConnection.Open();

                SqlDataReader objReader = null;
                objReader = objCommand.ExecuteReader();

                if (objReader.Read() == true)
                {
                    BoardHunt.classes.hasher pHash = new BoardHunt.classes.hasher();
                    byte[] saltBytes  = pHash.GenerateSALT();
                    string saltString = Convert.ToBase64String(saltBytes);


                    BoardHunt.classes.RandomPassword pwdGen = new BoardHunt.classes.RandomPassword();
                    string newPwd = pwdGen.Generate();

                    byte[] hBytes = pHash.getHash(saltString, newPwd);
                    string hPass  = Convert.ToBase64String(hBytes);

                    if (UpdateUserPwd(hPass, saltString))
                    {
                        //check password match
                        if (newPwd != null && newPwd != "" && newPwd.Length > 0)
                        {
                            string emailMsg = "Your new password is: " + newPwd + "<br><br>You can change it again in the edit profile settings.";
                            classes.Email.SendEmail("Login info", txtEmail.Text, "*****@*****.**", emailMsg, false);

                            ////Mail the password
                            ////Create an instance of the MailMessage class
                            //MailMessage mail = new MailMessage();

                            ////mail.To = "*****@*****.**";
                            //mail.To = txtEmail.Text;
                            //mail.From = "*****@*****.**";

                            ////'If you want to CC this email to someone else
                            ////'objMM.Cc = "*****@*****.**"

                            ////email format. Can be Text or Html
                            //mail.BodyFormat = MailFormat.Text;

                            ////Set the priority - options are High, Low, and Normal
                            //mail.Priority = MailPriority.Normal;

                            ////Set the subject
                            //mail.Subject = "Login info";

                            ////Set the body
                            //mail.Body = "Your new password is: " + newPwd;

                            ////Smtp Server
                            //SmtpMail.SmtpServer = "mrelay.perfora.net";

                            ////Send the message
                            //SmtpMail.Send(mail);

                            panelSendEmail.Visible = false;
                            panelMailSent.Visible  = true;
                        }
                    }
                }
                else
                {
                    //TODO: add code for no record for e-mail
                    lblStatus.Text        = "&nbsp;We can't find that e-mail.  Check it again or sign up.&nbsp;";
                    lblStatus.BorderWidth = 1;
                }
            }

            catch
            {
                lblStatus.Text = "Error!";
            }

            finally
            {
                myConnection.Close();
            }
        }