public Pictures1 GetImageFromSelectedProject() { var Id = int.Parse(dgvProjects.SelectedRows[0].Cells["ImageId"].Value.ToString()); picture = projectsKonstruktorEntities.Pictures1.FirstOrDefault(p => p.PictureId == Id); return(picture); }
private void Button_Click(object sender, RoutedEventArgs e) { Pictures1.Add(Text); Pictures2.Add(new Picture { Name = Text }); list1.SelectedItem = Pictures1[0]; list2.SelectedItem = Pictures2[0]; }
private void bAddProject_Click(object sender, EventArgs e) { try { string projectName = tbProjectName.Text.Trim(); string projectAddress = tbProjectAddress.Text.Trim(); string projectCompany = tbProjectCompany.Text.Trim(); string projectState = tbProjectState.Text.Trim(); var projectDateIn = dtpProjectCollectionDate.Value; var projectDateOut = dtpProjectCompleteDate.Value; var isValid = true; var errorMessage = string.Empty; if (string.IsNullOrWhiteSpace(projectName)) { isValid = false; errorMessage = "Proszę wpisać nazwę projektu."; } if (projectDateIn > projectDateOut) { isValid = false; errorMessage = "Data rozpoczęcia nie może być późniejsza niż data ukończenia."; } if (fileName == null) { isValid = false; errorMessage = "Proszę załączyć plik PDF."; } if (isValid) { var projectsKonstruktorEntities = new ProjectsKonstruktorEntities(); MainWindow window = new MainWindow(); Projects projects = new Projects(); var project = new Project(); var picture = new Pictures1(); project.ProjectName = projectName.Trim(); project.ProjectAddress = projectAddress.Trim(); project.ProjectCompany = projectCompany.Trim(); project.ProjectState = projectState.Trim(); project.ProjectDateIn = projectDateIn; project.ProjectDateOut = projectDateOut; Image imageContent = Image.FromFile(fileName); picture.PictureName = fileName.Trim(); project.ImageId = picture.PictureId; picture.PictureContent = ConvertImageToByteArray(imageContent); try { projectsKonstruktorEntities.Projects.Add(project); projectsKonstruktorEntities.Pictures1.Add(picture); //projectsKonstruktorEntities.Entry(picture).State = EntityState.Added; //projectsKonstruktorEntities.Entry(project).State = EntityState.Added; //project.ImageId = picture.PictureId; //projectsKonstruktorEntities.Entry(project).State = EntityState.Modified; projectsKonstruktorEntities.SaveChanges(); MessageBox.Show("Projekt dodano pomyślnie."); //Close(); //window.openChildForm(projects); MainWindow mainWindow = new MainWindow(); for (int index = Application.OpenForms.Count - 1; index >= 0; index--) { if (Application.OpenForms[index].Name == "Projects") { Application.OpenForms[index].Hide(); Application.OpenForms[index].Show(); } else if (Application.OpenForms[index].Name == "AddProject") { Application.OpenForms[index].Hide(); } } } catch (Exception ec) { Console.WriteLine(ec.Message); MessageBox.Show("Projektu nie dodano."); } } else { MessageBox.Show(errorMessage); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }