/// <summary>
 /// Attemps to add a Project entity into the Projects EntitySet of the Context
 /// </summary>
 /// <param name="theProject">Project Entity to be inserted</param>
 /// <returns>true upon success, false upon failure</returns>
 public bool AddProject(Project theProject)
 {
     try
     {
         Projects.InsertOnSubmit(theProject);
         SubmitChanges();
         return true;
     }
     catch (Exception ex)
     {
         //TODO: 17.12.2012 add proper exception handling.
         return false;
     }
 }
        /// <summary>
        /// Responsible for adding the data. Performs validation and displays a MessageBox telling the user whether adding the project succeeded or failed
        /// Also closes the form
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            #region Validation
            if (tbProjectName.Text.Length < 3)
            {
                MessageBox.Show("Project Name must be at least 3 characters long.", "KChange: Error");
                return;
            }

            if (tbProjectDescription.Text.Length < 3)
            {
                MessageBox.Show("Project Description must be at least 3 characters long", "KChange: Error");
                return;
            }

            if (Data.GetLanguage((string)liLanguage.SelectedValue) == null)
            {
                MessageBox.Show("You must select which programming language is used for the project.", "KChange: Error");
                return;
            }

            if (tbProjectPath.Text.Length < 3)
            {
                MessageBox.Show("Project Path must be at least 3 characters long.", "KChange: Error");
                return;
            }
            #endregion
            #region Inserting Project into DB

            KChangeDataContextDataContext theContext = new KChangeDataContextDataContext();
            Project newProject = new Project();

            newProject.Name = tbProjectName.Text;
            newProject.Description = tbProjectDescription.Text;
            newProject.Language1 = Data.GetLanguage((string)liLanguage.SelectedValue);
            newProject.Created = DateTime.Now;
            newProject.Physical_Path = tbProjectPath.Text;

            if (theContext.AddProject(newProject))
                MessageBox.Show("New Project added successfully.", "KChange: Success");
            else
                MessageBox.Show("New Project adding failed.", "KChange: Error");

            #endregion

            Close();
        }
        /// <summary>
        /// Obtains a List of all File Names attached to a given Project Entity.
        /// </summary>
        /// <param name="theProject">Project Entity whose File Names are to be returned</param>
        /// <returns></returns>
        public List<string> GetFileNamesByProject(Project theProject)
        {
            List<string> returnList = new List<string>();

            returnList = (from f in Project_Files
                          where f.Project == theProject
                          select f.File_Name).ToList();

            return returnList;
        }
 /// <summary>
 /// Gets a reference to a Project File Entity of a given Project entity based on fileName
 /// </summary>
 /// <param name="theProject">Project Entity whose Project File is to be returned</param>
 /// <param name="fileName">Name of the Project file to be returned</param>
 /// <returns></returns>
 public Project_File GetFileByName(Project theProject, string fileName)
 {
     //TODO: Double files may have the same values. Perhaps add a unique key?
     try
     {
         return (from pf in Project_Files
                 where pf.File_Name == fileName
                 select pf).First();
     }
     catch (Exception ex)
     {
         //TODO: Add proper event handling
         return null;
     }
 }
 /// <summary>
 /// Attempts to return a List of Project_Change Entities of a Project Entity
 /// </summary>
 /// <param name="theProject">Project Entity whose Project_Changes are to be returned</param>
 /// <returns>List of Project Change Entities</returns>
 public List<Project_Change> GetChangesByProject(Project theProject)
 {
     return (from pc in theProject.Project_Changes
             select pc).ToList();
 }
 /// <summary>
 /// Cancells out the dialog, setting myProject to null.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void CancelButton_Click(object sender, EventArgs e)
 {
     myProject = null;
     Close();
 }
 /// <summary>
 /// Calls LoadGridView and assigns myProject value
 /// </summary>
 /// <param name="projectID">The Project ID to be assigned for myProject</param>
 public MaintenanceFormChanges(int projectID)
 {
     InitializeComponent();
     myProject = Data.GetProject(projectID);
     LoadGridView();
 }
 /// <summary>
 /// Returns the number of Project_Files of a given Project
 /// </summary>
 /// <param name="theProject">The Project Entity</param>
 /// <returns>Number of files</returns>
 public int GetNumberOfFilesByProject(Project theProject)
 {
     return theProject.Project_Files.Count;
 }
		private void attach_Projects(Project entity)
		{
			this.SendPropertyChanging();
			entity.Language1 = this;
		}
 partial void DeleteProject(Project instance);
 partial void UpdateProject(Project instance);
 partial void InsertProject(Project instance);
Example #13
0
 /// <summary>
 /// Loads the controls, myProject entity and calls BindControls()
 /// </summary>
 /// <param name="theProjectID">the ID of the Project Entity to be loaded</param>
 public MaintenanceForm(int theProjectID)
 {
     myProject = Data.GetProject(theProjectID);
     InitializeComponent();
     BindControls();
 }
 /// <summary>
 /// Initializes the form and calls BindData
 /// </summary>
 /// <param name="theProject"></param>
 public MainFormProjectsInfo(Project theProject)
 {
     InitializeComponent();
     myProject = theProject;
     BindData();
 }
        /// <summary>
        /// Obtains a list of Project_File entity attached to a given Project entity found by the Project entity
        /// </summary>
        /// <param name="theProject">Project entity whose Files are to be returned</param>
        /// <returns>(Empty) list of files per project name</returns>
        public List<Project_File> GetFilesByProject(Project theProject)
        {
            List<Project_File> returnList = new List<Project_File>();

            returnList = (from f in Project_Files
                          where f.Project == theProject
                          select f).ToList();

            return returnList;
        }
 /// <summary>
 /// Obtains the datetime assigned to the last change of a given Project Entity
 /// </summary>
 /// <param name="theProject">The given Project entity whose last change is to be returned</param>
 /// <returns>The current time, -30 years if there has not been a change yet
 /// The last change from the Database if a change has been registered.
 /// </returns>
 public DateTime GetLastChange(Project theProject)
 {
     try
     {
         return (from pc in Project_Changes
                 where pc.Project == theProject
                 orderby pc.ChangeDate descending
                 select pc.ChangeDate).First();
     }
     catch (Exception ex)
     {
         //TODO: Add Exception logging class. Karol 11.12.2012.
         return DateTime.Now.AddYears(-30);
     }
 }
		private void detach_Projects(Project entity)
		{
			this.SendPropertyChanging();
			entity.Language1 = null;
		}
 /// <summary>
 /// Attemps to remove a Project Entity from the Projects EntitySet
 /// </summary>
 /// <param name="theProject">The Project Entity to be removed</param>
 /// <returns>true upon success, false upon failure</returns>
 public bool RemoveProject(Project theProject)
 {
     try
     {
         Projects.DeleteOnSubmit(theProject);
         SubmitChanges();
         return true;
     }
     catch (Exception ex)
     {
         //TODO: 17.12.2012 Karol, add proper exception handling
         return false;
     }
 }
Example #19
0
 /// <summary>
 /// Responsible for loading the MainFormProjects view.
 /// Also sets the currentProject Project Entity value.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void projectsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     // Load the form as a Dialog Box, passing currentProject by reference.
     MainFormProjects projectSelectionForm = new MainFormProjects();
     projectSelectionForm.ShowDialog();
     currentProject = projectSelectionForm.myProject;
     projectSelectionForm.Dispose();
     if (currentProject != null)
         UpdateProjectLabel(true);
     else
         UpdateProjectLabel(false);
 }
 /// <summary>
 /// Initializes the form and assigns myProject
 /// </summary>
 /// <param name="theProjectID">the Project ID whose files will be added to</param>
 public MaintenanceFormFilesAdd(int theProjectID)
 {
     InitializeComponent();
     myProject = Data.GetProject(theProjectID);
 }
        /// <summary>
        /// Attempts to find a given Project_File Entity from theProject's Project_Files EntitySet 
        /// </summary>
        /// <param name="theProject">Project whose Project_File is to be found</param>
        /// <param name="fileName">The File Name of the file to be found</param>
        /// <returns>true upon found, false upon not found</returns>
        public bool DoesFileExist(Project theProject, string fileName)
        {
            var query = (from pf in Project_Files
                         where pf.Project == theProject && pf.File_Name == fileName
                         select pf).ToList();

            return query.Count > 0;
        }
 public MaintenanceFormEdit(ref Project theProject)
 {
     myProject = theProject;
     InitializeComponent();
     BindControls();
 }
Example #23
0
 /// <summary>
 /// Main Button click event handler, used to select the curProject field in the main form.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void ProjectsGV_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     myProject = Data.GetProject((string)ProjectsGV.Rows[e.RowIndex].Cells[0].Value);
     if (myProject == null)
     {
         MessageBox.Show("There was a problem loading this project.", "KChange: Error");
         return;
     }
     MainFormProjectsInfo infoForm = new MainFormProjectsInfo(myProject);
     infoForm.ShowDialog();
     if (infoForm.Cancelled == true)
     {
         myProject = null;
         infoForm.Dispose();
         return;
     }
     Close();
 }