private void LoadStateToComboBox() { cbEstado.Items.Add(ProjectStateExtensions.ToDescriptionString(ProjectState.IN_NEGOCIATION)); cbEstado.Items.Add(ProjectStateExtensions.ToDescriptionString(ProjectState.CONTRACTED)); cbEstado.Items.Add(ProjectStateExtensions.ToDescriptionString(ProjectState.CONCLUDED)); cbEstado.Items.Add(ProjectStateExtensions.ToDescriptionString(ProjectState.CANCELLED)); }
public ProjectForm(long id) : this() { idToUpdate = id; if (idToUpdate != null) { Project project = _service.ReadById(Convert.ToInt64(idToUpdate)); project.Customer = _customerService.ReadById(project.CustomerId); project.Manager = _managerService.ReadById(project.ManagerId); project.Plannings = _planningService.ReadAllByProjectId(project.Id).ToList(); txtNome.Text = project.Name; dtpInicio.Value = project.StartDate; dtpFim.Value = project.EndDate; txtDescricao.Text = project.Description; numReceita.Value = (decimal)project.ExpectedReveneu; cbEstado.Text = ProjectStateExtensions.ToDescriptionString(project.State); cbCliente.Text = project.Customer.Id + " " + project.Customer.Name; if (project.Plannings != null) { foreach (var planning in project.Plannings) { planning.JobRole = _jobRoleService.ReadById(planning.JobRoleId); dgvRecursos.Rows.Add(planning.JobRole.Id, planning.JobRole.Name, planning.JobRole.Level, planning.Quantity, planning.PlannedHours); planning.JobRole = null; } } planningsToDelete = project.Plannings.ToList(); } }
private void LoadToDataGridView() { _service = new ProjectService(); dgvProjects.Rows.Clear(); long customerId = cbCliente.Text != "" ? long.Parse(cbCliente.Text.Split(' ')[0]) : 0; ProjectState state; try { state = cbEstado.Text == "" || cbEstado.Text == "Todos os Estados" ? ProjectState.NULL : ProjectStateExtensions.GetValueFromDescription <ProjectState>(cbEstado.Text); } catch (ArgumentException) { state = ProjectState.NULL; } IEnumerable <Project> projects = _service.ReadWithParameters(dtpInicio.Value, dtpFim.Value, customerId, state); if (projects.Count() != 0) { foreach (var project in projects) { project.Customer = _customerService.ReadById(project.CustomerId); project.Manager = _managerService.ReadById(project.ManagerId); dgvProjects.Rows.Add(project.Id, project.Name, project.Customer.Name, ProjectStateExtensions.ToDescriptionString(project.State), null, null); } } }
private void LoadToDataGridView() { projectService = new ProjectService(); dgvProjects.Rows.Clear(); IEnumerable <Models.Project> projects = projectService.ReadAll(false); foreach (var project in projects) { project.Customer = customerService.ReadById(project.CustomerId); dgvProjects.Rows.Add(project.Id, project.Name, project.Customer.Name, ProjectStateExtensions.ToDescriptionString(project.State), null); } }
private void BtnSalvar_Click(object sender, EventArgs e) { try { ValidateData(); } catch (Exception) { return; } Customer customer = null; try { customer = _customerService.ReadById(int.Parse(cbCliente.Text.Split(' ')[0])); } catch (Exception) { MessageBox.Show("Cliente inválido", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (customer != null) { ProjectState projectState; projectState = ProjectStateExtensions.GetValueFromDescription <ProjectState>(cbEstado.Text); Project project = new Project() { Name = txtNome.Text, StartDate = dtpInicio.Value.Date, EndDate = dtpFim.Value.Date, Description = txtDescricao.Text, ExpectedReveneu = (double)numReceita.Value, State = projectState, ManagerId = defaultManager.Id, CustomerId = customer.Id }; if (idToUpdate != null) { project.Id = Convert.ToInt64(idToUpdate); } List <Planning> plannings = new List <Planning>(); foreach (DataGridViewRow row in dgvRecursos.Rows) { long jobRoleId = Convert.ToInt64(row.Cells[0].Value); if (jobRoleId != 0) { JobRole jobRole = _jobRoleService.ReadById(jobRoleId); if (jobRole == null) { MessageBox.Show("Cargo não encontrado: " + row.Cells[1], "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Planning planning = new Planning() { JobRoleId = jobRole.Id, ProjectId = project.Id, Quantity = Convert.ToInt32(row.Cells[3].Value), PlannedHours = Convert.ToInt32(row.Cells[4].Value) }; plannings.Add(planning); } } project.Plannings = plannings; if (idToUpdate == null) { _service.Create(project); } else { if (planningsToDelete != null) { foreach (var planning in planningsToDelete) { _planningService.DeleteById(planning.Id); } } _service.Update(project); } MessageBox.Show("Projeto salvo com sucesso", "Projetos", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); Close(); } else { MessageBox.Show("Cliente não encontrado", "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }