Exemplo n.º 1
0
        /// <summary>
        /// add project
        /// </summary>
        private void btnJoin_Click(object sender, EventArgs e)
        {
            try
            {
                string         projectItem = cbProject.SelectedItem.ToString();
                int            projectID   = int.Parse(projectItem.Split(':')[1].Trim());
                tbl_ProjectDAO dao         = new tbl_ProjectDAO();
                int            flag        = 0;
                foreach (tbl_ProjectDTO dto in listProject)
                {
                    if (dto.Id == projectID)
                    {
                        MessageBox.Show(txtName.Text + " already joined in this project!");
                        flag++;
                        return;
                    }
                }
                if (flag == 0)
                {
                    tbl_ProjectDTO project = dao.GetById(projectID);

                    // insert db
                    tbl_JoiningDAO joinDAO = new tbl_JoiningDAO();
                    bool           resutl  = joinDAO.Insert(projectID, int.Parse(txtId.Text));
                    if (resutl)
                    {
                        listProject.Add(project);
                        gvProject.DataSource = null;
                        gvProject.DataSource = listProject;
                    }
                    else
                    {
                        MessageBox.Show("Error");
                    }
                }
            }
            catch (Exception)
            {
            }
        }
 //
 // add employee
 //
 private void btnAddEmp_Click(object sender, EventArgs e)
 {
     try
     {
         string[] employeeInf = cbEmployee.SelectedItem.ToString().Split(':');
         string   id          = employeeInf[1].Trim().Split('(')[0].Trim();
         int      flag        = 0;
         foreach (tbl_EmployeeDTO item in listEmployee)
         {
             if (item.Id == int.Parse(id))
             {
                 flag++;
             }
         }
         if (flag > 0)
         {
             MessageBox.Show("The employee is already exited in project!");
         }
         else
         {
             foreach (tbl_EmployeeDTO dto in listAllEmp)
             {
                 if (dto.Id == int.Parse(id))
                 {
                     listEmployee.Add(dto);
                     tbl_JoiningDAO joinDAO = new tbl_JoiningDAO();
                     joinDAO.Insert(int.Parse(txtID.Text), dto.Id);
                     gvListEmployee.DataSource = null;
                     gvListEmployee.DataSource = listEmployee;
                 }
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Add employee not successfull!");
     }
 }
        private void btnAddProject_Click(object sender, EventArgs e)
        {
            try
            {
                if (ValidData())
                {
                    tbl_ProjectDTO project = new tbl_ProjectDTO()
                    {
                        Name           = txtName.Text,
                        PartnerId      = int.Parse(cbPartner.Text.Split(':')[1].Trim()),
                        AdvancePayment = float.Parse(txtAdPayment.Text),
                        Cost           = float.Parse(txtCost.Text),
                        BeginTime      = dateStart.Value
                    };

                    if (!string.IsNullOrWhiteSpace(txtDescription.Text))
                    {
                        project.Description = txtDescription.Text;
                    }
                    if (chbDone.Checked)
                    {
                        project.Status   = "Done";
                        project.Deadline = dateDeadline.Value;
                        project.EndTime  = dateEnd.Value;
                    }
                    else
                    {
                        project.Status = "Doing...";
                    }

                    tbl_ProjectDAO projectDAO = new tbl_ProjectDAO();
                    bool           result     = projectDAO.Insert(project);
                    if (result)
                    {
                        if (listEmployee.Count() > 0)
                        {
                            tbl_JoiningDAO joinDAO = new tbl_JoiningDAO();
                            foreach (tbl_EmployeeDTO employee in listEmployee)
                            {
                                joinDAO.Insert(projectDAO.GetEndId(), employee.Id);
                            }
                        }
                        MessageBox.Show("Add new project successfull");
                    }
                    else
                    {
                        tbl_PartnerDAO dao = new tbl_PartnerDAO();
                        dao.Delete(project.PartnerId);
                        if (flag == 0)
                        {
                            tbl_CompanyDAO comDAO = new tbl_CompanyDAO();
                            comDAO.Delete(int.Parse(cbCompany.Text.Split(':')[1].Trim()));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                throw;
            }
        }