//upload slike private void btnOpenFileDialog_Click(object sender, EventArgs e) { var fileContent = string.Empty; var filePath = string.Empty; using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.InitialDirectory = "c:\\"; openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //Get the path of specified file filePath = openFileDialog.FileName; //Read the contents of the file into a stream var fileStream = openFileDialog.OpenFile(); using (StreamReader reader = new StreamReader(fileStream)) { fileContent = reader.ReadToEnd(); } } //ako si odabrao sliku prikazi, ako si zatvorio dialog i nisi odabrao - nemoj prikazivati //padne ako se ovako ne stavi //prepare for display if (!openFileDialog.FileName.Equals("")) { Bitmap img = new Bitmap(openFileDialog.FileName); picboxUser.Image = ImageHelperMethods.ResizeImage(img, 120, 120); } } }
private async void frmUpdateAlbum_Load(object sender, EventArgs e) { //get object we want to update Album obj = await _albumService.GetById <Album>(_albumId, "GetAlbumById"); //get all performers cmbPerformer.DataSource = await _performerService.Get <List <Performer> >(null, "GetPerformers"); cmbPerformer.DisplayMember = "ArtisticName"; cmbPerformer.ValueMember = "Id"; cmbPerformer.SelectedValue = obj.Performer.Id; //set selected value from db object //get all genres cmbGenre.DataSource = await _genreService.Get <List <Genre> >(null, "GetGenres"); cmbGenre.DisplayMember = "Name"; cmbGenre.ValueMember = "Id"; cmbGenre.SelectedValue = obj.Genre.Id; //set selected value from db object cmbYear.DataSource = Enumerable.Range(1900, 130).ToList(); txtTitle.Text = obj.Name; //prepare image for display if (obj.Image.Length != 0) { picboxAlbum.Image = ImageHelperMethods.ResizeImage(ImageHelperMethods.PrepareImgForDisplayFromDB(obj.Image), 120, 140); } }
private async void finishAlbum_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { if (picboxAlbum.Image == null) { errorProvider.SetError(picboxAlbum, "Image is required"); return; } else { errorProvider.SetError(picboxAlbum, null); } byte[] ImageData = ImageHelperMethods.PrepareImgForDB(picboxAlbum.Image); AlbumInsertRequest obj = new AlbumInsertRequest() { Name = txtTitle.Text, GenreId = (int)cmbGenre.SelectedValue, YearRelease = (int)cmbYear.SelectedValue, Image = ImageData, PerformerId = (int)cmbPerformer.SelectedValue, Description = txtAbout.Text }; await _albumService.Insert <AlbumInsertRequest>(obj, "InsertAlbum"); this.Close(); } }
private async void FrmSongDetails_Load(object sender, EventArgs e) { if (!_id.Equals(null)) { SongGetRequest song = await _songService.GetById <SongGetRequest>(_id, "GetSongById"); txtboxLyrics.Text = song.Text; txtBoxTitle.Text = song.Title; txtboxAlbum.Text = song.Album.Name; txtboxGenre.Text = song.Album.Genre.Name; picboxAlbum.Image = ImageHelperMethods.ResizeImage(ImageHelperMethods.PrepareImgForDisplayFromDB(song.Album.Image), 100, 100); } }
private async void btnUpdate_Click(object sender, EventArgs e) { byte[] imgByte = ImageHelperMethods.PrepareImgForDB(picboxAlbum.Image); AlbumInsertRequest obj = new AlbumInsertRequest { Name = txtTitle.Text, YearRelease = Convert.ToInt32(cmbYear.SelectedValue), GenreId = Convert.ToInt32(cmbGenre.SelectedValue), PerformerId = Convert.ToInt32(cmbPerformer.SelectedValue), Image = imgByte }; await _albumService.Update <AlbumInsertRequest>(_albumId, obj); this.Close(); }
private async void FrmUserDetails_Load(object sender, EventArgs e) { if (_userId.HasValue) { var user = await _userService.GetById <UserGetRequest>(_userId, null); txtboxName.ReadOnly = true; txtboxName.Text = user.Name; txtboxSurname.Text = user.Surname; txtboxSurname.ReadOnly = true; txtboxEmail.Text = user.Email; txtboxEmail.ReadOnly = true; txtBoxPhone.Text = user.PhoneNumber; txtBoxPhone.ReadOnly = true; txtboxUsername.Text = user.Username; txtboxUsername.ReadOnly = true; txtboxCity.Text = user.City.Name; txtboxCity.ReadOnly = true; txtboxUserType.ReadOnly = true; txtboxUserType.Text = user.UserType.Type; //prepare image to display from db if (user.Image.Length > 0) { byte[] imgData = user.Image; MemoryStream stream = new MemoryStream(imgData); picboxUser.Image = ImageHelperMethods.ResizeImage(Image.FromStream(stream), 120, 120); } if (user.Status.Equals(true)) { blockBtn.Text = "Block"; } else { blockBtn.Text = "Unblock"; } } }
private async void frmAlbumDetails_Load(object sender, EventArgs e) { Album album = await _albumService.GetById <Album>(_id, "GetAlbumById"); txtTitle.Text = album.Name; txtYearRelease.Text = album.YearRelease.ToString(); txtGenre.Text = album.Genre.Name; txtPerformer.Text = album.Performer.Name; //prepare image for display if (album.Image.Length != 0) { byte[] imgData = album.Image; MemoryStream stream = new MemoryStream(imgData); picboxAlbum.Image = ImageHelperMethods.ResizeImage(Image.FromStream(stream), 140, 120); } //end prepare image //load songs for album dgvAlbumSongs.DataSource = await _songService.GetById <List <SongGetRequest> >(_id, "GetSongsByAlbum"); }
private async void btnSaveUser_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { if (picboxUser.Image == null) { errorProvider.SetError(picboxUser, "Image is required!"); return; } else { errorProvider.SetError(picboxUser, null); } //prepare image for database byte[] ImageData = ImageHelperMethods.PrepareImgForDB(picboxUser.Image); UserInsertRequest obj = new UserInsertRequest() { Name = txtboxName.Text, Surname = txtboxSurname.Text, Username = txtboxUsername.Text, Email = txtboxEmail.Text, PhoneNumber = txtBoxPhone.Text, UserTypeId = Convert.ToInt32(cmbUserType.SelectedValue), CityId = Convert.ToInt32(cmbCity.SelectedValue), Password = txtboxPassword.Text, PasswordConfirmation = txtboxConfirmPassword.Text, Image = ImageData, Status = true //active by default }; await _userService.Insert <UserInsertRequest>(obj, "InsertUser"); this.Close(); } }
private async void btnAddPerformer_Click(object sender, EventArgs e) { if (this.ValidateChildren()) { if (picBoxPerformer.Image == null) { errorProvider.SetError(picBoxPerformer, "Image is required"); return; } else { errorProvider.SetError(picBoxPerformer, null); } byte[] img = ImageHelperMethods.PrepareImgForDB(picBoxPerformer.Image); Performer obj = new Performer() { Name = txtName.Text, Surname = txtSurname.Text, ArtisticName = txtArtisticName.Text, Image = img, About = txtAbout.Text }; await _performerService.Insert <Performer>(obj, "AddPerformer"); this.Close(); } }