Esempio n. 1
0
        public void InitEmployee_Project()
        {
            picNew.Visible    = false;
            picDelete.Visible = false;
            picUpdate.Visible = false;
            flagCbPartners    = 0;
            // load lable AllProject
            lbAllProject.Visible = false;
            tbl_ProjectDAO projectDAO = new tbl_ProjectDAO();

            projectDAO.GetAllProject(ref gvSmallList);
            // load lable company name
            tbl_CompanyDAO companyDAO = new tbl_CompanyDAO();
            tbl_PartnerDAO partnerDAO = new tbl_PartnerDAO();
            int            companyId  = partnerDAO.GetCompanyIdById(int.Parse(gvSmallList.CurrentRow.Cells[3].Value.ToString()));

            lbCompanyName.Text = companyDAO.GetNameById(companyId);
            // load partner infor
            int parnerId = int.Parse(gvSmallList.CurrentRow.Cells[3].Value.ToString());

            DisplayPartnerInfor(parnerId);
            // display employees
            tbl_JoiningDAO         joiningDAO   = new tbl_JoiningDAO();
            List <int>             employeeIDs  = joiningDAO.GetListEmIDByProjectId(int.Parse(gvSmallList.CurrentRow.Cells[0].Value.ToString()));
            List <tbl_EmployeeDTO> listEmployee = new List <tbl_EmployeeDTO>();
            tbl_EmployeeDAO        emDAO        = new tbl_EmployeeDAO();

            foreach (var emId in employeeIDs)
            {
                listEmployee.Add(emDAO.GetById(emId));
            }
            gvBigList.DataSource = listEmployee;
        }
Esempio n. 2
0
 /// <summary>
 /// Remove project
 /// </summary>
 private void btnRemove_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Do you want remove " + txtName.Text + " from project " + gvProject.CurrentRow.Cells[1].Value.ToString() + " ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             int projectID = int.Parse(gvProject.CurrentRow.Cells[0].Value.ToString());
             foreach (tbl_ProjectDTO item in listProject)
             {
                 if (item.Id == projectID)
                 {
                     listProject.Remove(item);
                     tbl_JoiningDAO joinDAO = new tbl_JoiningDAO();
                     joinDAO.DeleteByProID_EmID(projectID, int.Parse(txtId.Text));
                     gvProject.DataSource = null;
                     gvProject.DataSource = listProject;
                     return;
                 }
             }
         }
     }
     catch (Exception)
     {
     }
 }
 //
 //Remove Employee from project
 //
 private void btnDeleteEmp_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Do you want remove " + gvListEmployee.CurrentRow.Cells[1].Value.ToString() + " from project?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             int empID = int.Parse(gvListEmployee.CurrentRow.Cells[0].Value.ToString());
             foreach (tbl_EmployeeDTO item in listEmployee)
             {
                 if (item.Id == empID)
                 {
                     listEmployee.Remove(item);
                     tbl_JoiningDAO joinDAO = new tbl_JoiningDAO();
                     joinDAO.DeleteByProID_EmID(int.Parse(txtID.Text), empID);
                     gvListEmployee.DataSource = null;
                     gvListEmployee.DataSource = listEmployee;
                     return;
                 }
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Remove employee not successfull!");
     }
 }
        //
        //load project detail
        //
        private void frmProjectManagement_Load(object sender, EventArgs e)
        {
            lbCompanyName.Text  = ComName;
            lbPartnerInfor.Text = PartnerInfor;
            tbl_ProjectDAO dao = new tbl_ProjectDAO();
            tbl_ProjectDTO dto = dao.GetById(ProjectId);

            currentDTO = dto;

            txtID.Text          = dto.Id.ToString();
            txtName.Text        = dto.Name;
            txtDescription.Text = dto.Description;
            lbStatus.Text       = dto.Status;
            txtAdPayment.Text   = dto.AdvancePayment.ToString();
            txtCost.Text        = dto.Cost.ToString();
            dateStart.Value     = dto.BeginTime;
            if (dto.Deadline != null)
            {
                dateDeadline.Value = dto.Deadline.Value;
            }
            if (dto.Status.Equals("Doing..."))
            {
                chbDone.Visible    = true;
                chbDone.Checked    = false;
                dateEnd.Visible    = false;
                lbStatus.BackColor = Color.Red;
            }
            else
            {
                chbDone.Checked    = true;
                dateEnd.Visible    = true;
                dateEnd.Value      = dto.EndTime.Value;
                lbStatus.BackColor = Color.Blue;
            }
            // display list employee
            tbl_JoiningDAO joiningDAO  = new tbl_JoiningDAO();
            List <int>     employeeIDs = joiningDAO.GetListEmIDByProjectId(ProjectId);

            listEmployee = new List <tbl_EmployeeDTO>();
            listFirt     = listEmployee;
            tbl_EmployeeDAO emDAO = new tbl_EmployeeDAO();

            foreach (var emId in employeeIDs)
            {
                listEmployee.Add(emDAO.GetById(emId));
            }
            gvListEmployee.DataSource = listEmployee;
            // display domainEmployee
            listAllEmp = emDAO.GetAllEmployee();
            List <String> itemsCbEmployee = new List <string>();

            foreach (tbl_EmployeeDTO employee in listAllEmp)
            {
                itemsCbEmployee.Add(employee.Name + " - ID :" + employee.Id + " (" + employee.Role + ")");
            }
            cbEmployee.DataSource = itemsCbEmployee;
        }
Esempio n. 5
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)
            {
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Load employee information
        /// </summary>
        private void frmEmployeeDetail_Load(object sender, EventArgs e)
        {
            try
            {
                tbl_EmployeeDAO emDAO = new tbl_EmployeeDAO();
                currentEm       = emDAO.GetById(EmId);
                txtId.Text      = currentEm.Id.ToString();
                txtName.Text    = currentEm.Name;
                txtAddress.Text = currentEm.Address;
                birthday.Value  = currentEm.Birthday;
                txtPhone.Text   = currentEm.Phone;
                txtEmail.Text   = currentEm.Email;
                string[] role = currentEm.Role.Split('-');
                cbPosition.Text = role[1].Trim().ToUpper();
                tbl_RoleDAO roleDAO = new tbl_RoleDAO();
                roleDAO.GetAll(ref cbPosition);
                txtSalary.Text = currentEm.Salary.ToString();

                // display list project
                tbl_JoiningDAO joinDAO    = new tbl_JoiningDAO();
                List <int>     listProId  = joinDAO.GetListProjectByEmId(EmId);
                tbl_ProjectDAO projectDAO = new tbl_ProjectDAO();
                listProject = new List <tbl_ProjectDTO>();
                foreach (int id in listProId)
                {
                    listProject.Add(projectDAO.GetById(id));
                }
                gvProject.DataSource = listProject;

                // load all project
                List <string> items = projectDAO.GetAllProject();
                cbProject.DataSource = items;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 //
 // 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!");
     }
 }
Esempio n. 8
0
        public void CellClick_EP_Page()
        {
            //load company name
            tbl_CompanyDAO companyDAO = new tbl_CompanyDAO();
            tbl_PartnerDAO partnerDAO = new tbl_PartnerDAO();
            int            companyId  = partnerDAO.GetCompanyIdById(int.Parse(gvSmallList.CurrentRow.Cells[3].Value.ToString()));

            lbCompanyName.Text = companyDAO.GetNameById(companyId);
            // load partner infor
            int parnerId = int.Parse(gvSmallList.CurrentRow.Cells[3].Value.ToString());

            DisplayPartnerInfor(parnerId);
            // display employees
            tbl_JoiningDAO         joiningDAO   = new tbl_JoiningDAO();
            List <int>             employeeIDs  = joiningDAO.GetListEmIDByProjectId(int.Parse(gvSmallList.CurrentRow.Cells[0].Value.ToString()));
            List <tbl_EmployeeDTO> listEmployee = new List <tbl_EmployeeDTO>();
            tbl_EmployeeDAO        emDAO        = new tbl_EmployeeDAO();

            foreach (var emId in employeeIDs)
            {
                listEmployee.Add(emDAO.GetById(emId));
            }
            gvBigList.DataSource = listEmployee;
        }
        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;
            }
        }