示例#1
0
 /// <summary>
 /// Create a new Photo object.
 /// </summary>
 /// <param name="photoID">Initial value of the PhotoID property.</param>
 /// <param name="machineID">Initial value of the MachineID property.</param>
 /// <param name="status">Initial value of the Status property.</param>
 /// <param name="showThumbnail">Initial value of the ShowThumbnail property.</param>
 /// <param name="machinePhotoID">Initial value of the MachinePhotoID property.</param>
 public static Photo CreatePhoto(global::System.Int32 photoID, global::System.Int32 machineID, global::System.String status, global::System.String showThumbnail, global::System.Int32 machinePhotoID)
 {
     Photo photo = new Photo();
     photo.PhotoID = photoID;
     photo.MachineID = machineID;
     photo.Status = status;
     photo.ShowThumbnail = showThumbnail;
     photo.MachinePhotoID = machinePhotoID;
     return photo;
 }
示例#2
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Photos EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToPhotos(Photo photo)
 {
     base.AddObject("Photos", photo);
 }
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (uploadFile.HasFile == false)
            {
                    UploadDetails.Text = "Please first select a file to upload...";
            }
            else
            {
                using (GESEntities db = new GESEntities())
                {
                    int iMachineID = Int32.Parse(lblMachineID.Text.Substring(lblMachineID.Text.IndexOf(":") + 1).Trim());

                    //Fetch next photo # in the photo table for this machine
                    int iNextMachinePhotoID = 0;

                    System.Nullable < Int32 > GetNextPhoto = (from p in db.Photos where p.MachineID == iMachineID select (int?)p.MachinePhotoID).Max();

                    if (GetNextPhoto.HasValue)
                    {
                        iNextMachinePhotoID = GetNextPhoto.Value + 1;
                    }
                    else
                    {
                        iNextMachinePhotoID = 1;
                    }

                    //Save the image
                    string fileName = iMachineID.ToString() + "-" + iNextMachinePhotoID.ToString() + Path.GetExtension(uploadFile.FileName);
                    string filePath = Server.MapPath("~/UsedPics/" + fileName);

                    string fileNameTemp = "Temp" + iMachineID.ToString() + "-" + iNextMachinePhotoID.ToString() + Path.GetExtension(uploadFile.FileName);
                    string filePathTemp = Server.MapPath("~/UsedPics/" + fileNameTemp);
                    uploadFile.SaveAs(filePathTemp);

                    //Resize image
                    Bitmap mg = new Bitmap(filePathTemp);

                    int imgHeight = mg.Height;
                    int imgWidth = mg.Width;

                    bool resizeImage = false;

                    if (imgHeight >= imgWidth)
                    {
                        if (imgHeight > 480)
                        {
                            resizeImage = true;
                        }
                    }
                    else
                    {
                        if (imgWidth > 640)
                        {
                            resizeImage = true;
                        }
                    }

                    if (resizeImage)
                    {
                        Bitmap bp = FixedSize(mg, 640, 480);

                        bp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        bp.Dispose();
                    }
                    else
                    {
                        Bitmap bp = FixedSize(mg, imgHeight, imgWidth);

                        bp.Save(filePath, System.Drawing.Imaging.ImageFormat.Jpeg);
                        bp.Dispose();
                    }

                    mg.Dispose();

                    //delete Temp file
                    if (File.Exists(filePathTemp))
                    {
                        File.Delete(filePathTemp);
                    }

                    // Display the uploaded file's details
                    UploadDetails.Text = string.Format(@"Uploaded file: {0}<br /> File size (in bytes): {1:N0}<br /> Content-type: {2}", uploadFile.FileName, uploadFile.FileBytes.Length, uploadFile.PostedFile.ContentType);

                    //insert a row into the photos table
                    Photo newPhoto = new Photo();
                    newPhoto.MachineID = iMachineID;
                    newPhoto.PhotoName = "Test";
                    newPhoto.PhotoDescription = "Test";
                    newPhoto.PhotoUrl = "UsedPics/" + fileName;
                    newPhoto.Status = "Active";
                    newPhoto.ShowThumbnail = "N";
                    newPhoto.MachinePhotoID = iNextMachinePhotoID;

                    db.Photos.AddObject(newPhoto);
                    db.SaveChanges();

                    //Refresh thumbnail list
                    PhotosEntityDataSource.WhereParameters.Clear();
                    PhotosEntityDataSource.AutoGenerateWhereClause = true;
                    PhotosEntityDataSource.WhereParameters.Add("MachineID", TypeCode.Int32, iMachineID.ToString());

                    gridPhotos.Visible = true;
                }
            }
        }