public ActionResult DeleteConfirmed(int id) { UploadDownload uploadDownload = db.UploadDownloads.Find(id); db.UploadDownloads.Remove(uploadDownload); db.SaveChanges(); return(RedirectToAction("Index")); }
internal string CreatePicture(Picture picture, string filePath, string windowFilePath) { try { connection.Open(); SqlCommand command1 = new SqlCommand("SELECT max(idFile) FROM files"); command1.Connection = this.connection; picture.IdFile = Convert.ToInt32(command1.ExecuteScalar()) + 1; if (picture.Picture == "") { picture.Picture = string.Format("http://perso.montpellier.epsi.fr/~luc.rodiere/Babel/Book/Default/defaultBook.png"); } String queryFile = @"INSERT INTO files VALUES (@idFile, @accessPath, @fileFormat, @created, @notation, @visibility, @title, @genre, @fileLanguage, @theme, @nbViews, @fileOwner, @picture);"; String queryBook = "INSERT INTO photo VALUES (@idPicture, @size);"; SqlCommand commandFile = new SqlCommand(queryFile, connection); commandFile.Parameters.AddWithValue("@idFile", picture.IdFile); commandFile.Parameters.AddWithValue("@accessPath", picture.Directory); commandFile.Parameters.AddWithValue("@fileFormat", picture.FileFormat.ToString()); commandFile.Parameters.AddWithValue("@created", picture.DateCreated); commandFile.Parameters.AddWithValue("@notation", picture.Notation); commandFile.Parameters.AddWithValue("@visibility", picture.Visibility); commandFile.Parameters.AddWithValue("@title", picture.Title); commandFile.Parameters.AddWithValue("@genre", picture.Genre); commandFile.Parameters.AddWithValue("@fileLanguage", picture.FileLanguage); commandFile.Parameters.AddWithValue("@theme", picture.Theme); commandFile.Parameters.AddWithValue("@nbViews", picture.NbViews); commandFile.Parameters.AddWithValue("@fileOwner", picture.FileOwner.IdUser); commandFile.Parameters.AddWithValue("@picture", picture.Picture); commandFile.ExecuteNonQuery(); string size = string.Format("{0}x{1}", picture.Width, picture.Height); SqlCommand commandBook = new SqlCommand(queryBook, connection); commandBook.Parameters.AddWithValue("@idPicture", picture.IdFile); commandBook.Parameters.AddWithValue("@size", size); commandBook.ExecuteNonQuery(); UploadDownload ud = new UploadDownload(); ud.UploadFile(picture.FileOwner, filePath, windowFilePath, picture.IdFile); return("OK"); } catch (Exception ex) { return("ERROR"); throw ex; } finally { connection.Close(); } }
// GET: UploadDownloads/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } UploadDownload uploadDownload = db.UploadDownloads.Find(id); if (uploadDownload == null) { return(HttpNotFound()); } return(View(uploadDownload)); }
public ActionResult Create([Bind(Include = "fileId,filename,filetype,filedata,ticketnumber")] UploadDownload uploadDownload, HttpPostedFileBase upload) { if (ModelState.IsValid) { if (upload != null && upload.ContentLength > 0) { uploadDownload.filename = System.IO.Path.GetFileName(upload.FileName); uploadDownload.filetype = upload.ContentType; } ; using (var reader = new System.IO.BinaryReader(upload.InputStream)) { uploadDownload.filedata = reader.ReadBytes(upload.ContentLength); } } db.UploadDownloads.Add(uploadDownload); db.SaveChanges(); return(RedirectToAction("Index"));; }
private void buttonChooseFile_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Title = "Selectionner un fichier"; if (dlg.ShowDialog() == DialogResult.OK) { textBoxMetadata1.Visible = false; textBoxMetadata2.Visible = false; textBoxMetadata1.Text = ""; textBoxMetadata2.Text = ""; labelMetadata1.Visible = false; labelMetadata2.Visible = false; dateTimePickerMetadata.Visible = false; labelChoosePicture.Visible = false; buttonChooseAdditionalPicture.Visible = false; textBoxChooseAdditionalPicture.Visible = false; pictureBoxDisplayChoosenPicture.Visible = false; textBoxFilePath.Text = dlg.FileName; UploadDownload ud = new UploadDownload(); string ext = Path.GetExtension(dlg.FileName); string extWithoutDot = ext.Remove(0, 1); labelFileFormat.Text = extWithoutDot; if (extWithoutDot == FileFormats.txt.ToString() || extWithoutDot == FileFormats.pdf.ToString()) { textBoxFileType.Text = "Livre"; textBoxFileType.Tag = "book"; labelGetFilePath.Text = "Book"; labelMetadata1.Text = "Editeur"; labelMetadata1.Visible = true; textBoxMetadata1.Visible = true; labelMetadata2.Text = "Date de sortie"; labelMetadata2.Visible = true; dateTimePickerMetadata.Visible = true; labelChoosePicture.Visible = true; buttonChooseAdditionalPicture.Visible = true; textBoxChooseAdditionalPicture.Visible = true; pictureBoxDisplayChoosenPicture.Visible = true; } else if (extWithoutDot == FileFormats.jpg.ToString() || extWithoutDot == FileFormats.png.ToString()) { textBoxFileType.Text = "Image"; textBoxFileType.Tag = "picture"; labelGetFilePath.Text = "Picture"; FileInfo file = new FileInfo(dlg.FileName); Bitmap img = new Bitmap(dlg.FileName); var imageHeight = img.Height; var imageWidth = img.Width; labelMetadata1.Text = "Hauteur"; labelMetadata1.Visible = true; textBoxMetadata1.Visible = true; textBoxMetadata1.Text = imageHeight.ToString(); labelMetadata2.Text = "Largeur"; labelMetadata2.Visible = true; textBoxMetadata2.Visible = true; textBoxMetadata2.Text = imageWidth.ToString(); } else if (extWithoutDot == FileFormats.avi.ToString() || extWithoutDot == FileFormats.mp4.ToString()) { WindowsMediaPlayer wmp = new WindowsMediaPlayer(); IWMPMedia mediainfo = wmp.newMedia(dlg.FileName); textBoxFileType.Text = "Video"; textBoxFileType.Tag = "video"; labelGetFilePath.Text = "Video"; labelMetadata1.Text = "Durée (sec)"; labelMetadata1.Visible = true; textBoxMetadata1.Text = mediainfo.duration.ToString(); textBoxMetadata1.Visible = true; labelChoosePicture.Visible = true; buttonChooseAdditionalPicture.Visible = true; textBoxChooseAdditionalPicture.Visible = true; pictureBoxDisplayChoosenPicture.Visible = true; } else if (extWithoutDot == FileFormats.mp3.ToString()) { WindowsMediaPlayer wmp = new WindowsMediaPlayer(); IWMPMedia mediainfo = wmp.newMedia(dlg.FileName); textBoxFileType.Text = "Musique/Son"; textBoxFileType.Tag = "song"; labelGetFilePath.Text = "Sound"; labelMetadata1.Text = "Durée (sec)"; labelMetadata1.Visible = true; textBoxMetadata1.Text = mediainfo.duration.ToString(); textBoxMetadata1.Visible = true; labelChoosePicture.Visible = true; buttonChooseAdditionalPicture.Visible = true; textBoxChooseAdditionalPicture.Visible = true; pictureBoxDisplayChoosenPicture.Visible = true; } else { textBoxFileType.Text = "Format inconnu, vérifiez"; textBoxFileType.Tag = "unknown"; } } }
private void buttonUploadFile_Click(object sender, EventArgs e) { bool isUploadable = false; foreach (TextBox tb in this.Controls.OfType <TextBox>()) { tb.BackColor = Color.White; if (tb.Tag.ToString() == "Mandatory" && tb.Text.ToString() == "") { tb.BackColor = Color.Red; } else { isUploadable = true; } if (tb.Name.ToString() == "textBoxFileType" && tb.Tag.ToString() == " ") { isUploadable = false; tb.BackColor = Color.Red; } } if (isUploadable) { UploadDownload ud = new UploadDownload(); Book book = null; Song song = null; Video video = null; Picture picture = null; FileManager fm = new FileManager(); int idFile = fm.GetId(); string fileFormat = labelFileFormat.Text.ToString(); DateTime created = DateTime.Now; float notation = -2f; int visibility = 1; if (!checkBoxVisibility.Checked) { visibility = 0; } string title = textBoxTitleUpload.Text.ToString(); string genre = textBoxGenre.Text.ToString(); string fileLanguage = comboBoxFileLanguages.Text.ToString(); string theme = textBoxTheme.Text.ToString(); int nbViews = 0; string filePath = textBoxFilePath.Text.ToString(); string filePathSlash = filePath.Replace('\\', '/'); string windowsAccessPath = string.Format("{0}", filePathSlash.Remove(filePathSlash.LastIndexOf('/'), filePathSlash.LastIndexOf('.') - filePathSlash.LastIndexOf('/'))); windowsAccessPath = windowsAccessPath.Insert(windowsAccessPath.IndexOf('.'), "\\" + title); string accessPath = string.Format("ftp://[email protected]:4621/Babel/{0}/{1}/{4}{2}/{4}{2}.{3}", labelGetFilePath.Text.ToString(), ConnectedUser.user.Pseudo, textBoxTitleUpload.Text.ToString(), fileFormat, idFile); User fileOwner = ConnectedUser.user; string additionalPicture = null; if (textBoxChooseAdditionalPicture.Text != "") { additionalPicture = string.Format("ftp://[email protected]:4621/Babel/{0}/{1}/{3}{2}/picture.png", labelGetFilePath.Text.ToString(), ConnectedUser.user.Pseudo, textBoxTitleUpload.Text.ToString(), idFile); } else { additionalPicture = string.Format("ftp://[email protected]:4621/Babel/Avatar/joshua.png"); } if (textBoxFileType.Tag.ToString() == "book") { string editor = labelMetadata1.Text.ToString(); DateTime release = Convert.ToDateTime(dateTimePickerMetadata.Text.ToString()); book = new Book(idFile, title, accessPath, fileFormat, created, notation, visibility, genre, fileLanguage, theme, nbViews, additionalPicture, fileOwner, editor, release); CreateFileEntryDBBook(book, windowsAccessPath, filePath); ud.UploadAdditionPicture(book.Picture, textBoxChooseAdditionalPicture.Text.ToString(), pictureBoxDisplayChoosenPicture); } else if (textBoxFileType.Tag.ToString() == "song") { int duration = Convert.ToInt32(textBoxMetadata1.Text.ToString().Remove(textBoxMetadata1.Text.ToString().IndexOf(','))); song = new Song(idFile, title, accessPath, fileFormat, created, notation, visibility, genre, fileLanguage, theme, nbViews, additionalPicture, fileOwner, duration); CreateFileEntryDBSong(song, windowsAccessPath, filePath); ud.UploadAdditionPicture(song.Picture, textBoxChooseAdditionalPicture.Text.ToString(), pictureBoxDisplayChoosenPicture); } else if (textBoxFileType.Tag.ToString() == "video") { int duration = Convert.ToInt32(textBoxMetadata1.Text.ToString()); video = new Video(idFile, title, accessPath, fileFormat, created, notation, visibility, genre, fileLanguage, theme, nbViews, additionalPicture, fileOwner, duration); CreateFileEntryDBVideo(video, windowsAccessPath, filePath); ud.UploadAdditionPicture(video.Picture, textBoxChooseAdditionalPicture.Text.ToString(), pictureBoxDisplayChoosenPicture); } if (textBoxFileType.Tag.ToString() == "picture") { additionalPicture = accessPath; int width = Convert.ToInt32(textBoxMetadata1.Text.ToString()); int height = Convert.ToInt32(textBoxMetadata2.Text.ToString()); picture = new Picture(idFile, title, accessPath, fileFormat, created, notation, visibility, genre, fileLanguage, theme, nbViews, additionalPicture, fileOwner, width, height); CreateFileEntryDBPicture(picture, windowsAccessPath, filePath); } Label labelOK = new Label(); labelOK.Size = new Size(200, 25); labelOK.AutoSize = true; labelOK.Font = new System.Drawing.Font("Verdana", 12F); labelOK.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom); labelOK.Text = string.Format("Fichier ajouter avec succès."); labelOK.TextAlign = ContentAlignment.MiddleCenter; labelOK.AutoSize = false; labelOK.Dock = DockStyle.Top; Button buttonOK = new Button(); buttonOK.Size = new Size(50, 50); buttonOK.AutoSize = true; buttonOK.Font = new System.Drawing.Font("Verdana", 12F); buttonOK.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom); buttonOK.Text = "OK"; buttonOK.TextAlign = ContentAlignment.MiddleCenter; buttonOK.AutoSize = false; buttonOK.Dock = DockStyle.Bottom; buttonOK.DialogResult = DialogResult.OK; Form dialogOK = new Form(); dialogOK.Controls.Add(labelOK); dialogOK.Controls.Add(buttonOK); dialogOK.ShowDialog(); if (buttonOK.DialogResult == DialogResult.OK) { dialogOK.Close(); this.Close(); } } }
public string SetUser(string pseudo, string password, string firstName, string lastName, string mail, string pic) { string pic2 = null; command1 = new SqlCommand("SELECT max(idUser) FROM Users"); try { connection.Open(); command1.Connection = this.connection; int idUser = Convert.ToInt32(command1.ExecuteScalar()) + 1; if (testPseudo(pseudo)) { if (testMail(mail)) { string[] words = pic.Split('\\'); string fileName = words[words.Length - 1]; words = fileName.Split('.'); string fileType = words[words.Length - 1]; if (pic == "") { pic2 = "http://perso.montpellier.epsi.fr/~luc.rodiere/Babel/Avatar/joshua.png"; } else { pic2 = "http://perso.montpellier.epsi.fr/~luc.rodiere/Babel/Avatar/" + pseudo + "/" + "avatar.png"; } String query = "INSERT INTO Users VALUES (@idUser, @pseudo, @lastName, @firstName, @mail, @pic2, @date, @password)"; command2 = new SqlCommand(query, connection); command2.Parameters.AddWithValue("@idUser", idUser); command2.Parameters.AddWithValue("@pseudo", pseudo); command2.Parameters.AddWithValue("@password", password); command2.Parameters.AddWithValue("@lastName", lastName); command2.Parameters.AddWithValue("@firstName", firstName); command2.Parameters.AddWithValue("@mail", mail); command2.Parameters.AddWithValue("@pic2", pic2); command2.Parameters.AddWithValue("@date", DateTime.Now); command2.ExecuteNonQuery(); UploadDownload ud = new UploadDownload(); ud.CreateUserDirectory(pseudo); if (pic != "") { ud.UploadAvatar(pseudo, pic); } return("Votre compte a bien été crée"); } else { return("Ce mail existe déjà"); } } else { return("Ce pseudo existe déjà"); } } catch (Exception ex) { return("Il y a eu une erreur, veuillez réessayer ultérieurement"); throw ex; } finally { if (command1 != null) { if (command1.Connection != null && command1.Connection.State == ConnectionState.Open) { command1.Connection.Close(); } } if (command2 != null) { if (command2.Connection != null && command2.Connection.State == ConnectionState.Open) { command2.Connection.Close(); } } connection.Close(); } }
public FileResult Download(int?id) { UploadDownload uploadDownload = db.UploadDownloads.Find(id); return(File(uploadDownload.filedata, uploadDownload.filetype, uploadDownload.filename)); }