// //check save // public void Check_Save() { if (!SaveMode) { if (ValidData()) { tbl_ProjectDTO now = new tbl_ProjectDTO() { Id = int.Parse(txtID.Text), Name = txtName.Text, Status = lbStatus.Text, AdvancePayment = float.Parse(txtAdPayment.Text), Cost = float.Parse(txtCost.Text), BeginTime = dateStart.Value, Deadline = dateDeadline.Value, EndTime = dateEnd.Value, Description = txtDescription.Text }; tbl_ProjectBLL bll = new tbl_ProjectBLL(); if (bll.Check_Save(currentDTO, now)) { SaveMode = true; } else { SaveMode = false; } } } }
// //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; }
public bool Insert(tbl_ProjectDTO dto) { try { using (con = DBConnection.MakeConnection(con)) { con.Open(); SqlCommand command; if (dto.Status.Equals("Doing...")) { if (dto.Description == null) { command = new SqlCommand("Insert into tbl_Project(name, partnerId, status, advancePayment, cost, beginTime) values(@name, @partnerId, @status, @advancePayment, @cost, @beginTime)", con); command.Parameters.AddWithValue("@status", false); } else { command = new SqlCommand("Insert into tbl_Project(name, description, partnerId, status, advancePayment, cost, beginTime) values(@name, @description, @partnerId, @status, @advancePayment, @cost, @beginTime)", con); command.Parameters.AddWithValue("@description", dto.Description); command.Parameters.AddWithValue("@status", false); } } else { if (dto.Description == null) { command = new SqlCommand("Insert into tbl_Project(name, partnerId, status, advancePayment, cost, beginTime, deadline, endTime) values(@name, @partnerId, @status, @advancePayment, @cost, @beginTime, @deadline, @endTime)", con); command.Parameters.AddWithValue("@status", true); command.Parameters.AddWithValue("@deadline", dto.Deadline); command.Parameters.AddWithValue("@endTime", dto.EndTime); } else { command = new SqlCommand("Insert into tbl_Project(name, description, partnerId, status, advancePayment, cost, beginTime, deadline, endTime) values(@name, @description, @partnerId, @status, @advancePayment, @cost, @beginTime, @deadline, @endTime)", con); command.Parameters.AddWithValue("@description", dto.Description); command.Parameters.AddWithValue("@status", true); command.Parameters.AddWithValue("@deadline", dto.Deadline); command.Parameters.AddWithValue("@endTime", dto.EndTime); } } command.Parameters.AddWithValue("@name", dto.Name); command.Parameters.AddWithValue("@partnerId", dto.PartnerId); command.Parameters.AddWithValue("@advancePayment", dto.AdvancePayment); command.Parameters.AddWithValue("@cost", dto.Cost); command.Parameters.AddWithValue("@beginTime", dto.BeginTime); return(command.ExecuteNonQuery() > 0); } } catch (Exception) { throw; } }
public bool Update(tbl_ProjectDTO dto) { try { using (con = DBConnection.MakeConnection(con)) { con.Open(); SqlCommand command; if (dto.Status.Equals("Done")) { command = new SqlCommand("Update tbl_Project set name = @name, description = @description, status = @status, advancePayment = @adPayment, cost = @cost, beginTime = @beginTime, deadline = @deadline, endTime = @endTime where id = @id", con); command.Parameters.AddWithValue("@name", dto.Name); command.Parameters.AddWithValue("@description", dto.Description); command.Parameters.AddWithValue("@status", true); command.Parameters.AddWithValue("@endTime", dto.EndTime); command.Parameters.AddWithValue("@adPayment", dto.AdvancePayment); command.Parameters.AddWithValue("@cost", dto.Cost); command.Parameters.AddWithValue("@beginTime", dto.BeginTime); command.Parameters.AddWithValue("@deadline", dto.Deadline); command.Parameters.AddWithValue("@id", dto.Id); } else { command = new SqlCommand("Update tbl_Project set name = @name, description = @description, status = @status, advancePayment = @adPayment, cost = @cost, beginTime = @beginTime, deadline = @deadline, endTime = null where id = @id", con); command.Parameters.AddWithValue("@name", dto.Name); command.Parameters.AddWithValue("@description", dto.Description); command.Parameters.AddWithValue("@status", false); command.Parameters.AddWithValue("@adPayment", dto.AdvancePayment); command.Parameters.AddWithValue("@cost", dto.Cost); command.Parameters.AddWithValue("@beginTime", dto.BeginTime); command.Parameters.AddWithValue("@deadline", dto.Deadline); command.Parameters.AddWithValue("@id", dto.Id); } int row = command.ExecuteNonQuery(); if (row > 0) { return(true); } } } catch (Exception) { throw; } return(false); }
// //update // private void btnUpdate_Click(object sender, EventArgs e) { if (ValidData()) { SaveMode = true; try { tbl_ProjectDTO project = new tbl_ProjectDTO() { Id = int.Parse(txtID.Text), Name = txtName.Text, AdvancePayment = float.Parse(txtAdPayment.Text), Cost = float.Parse(txtCost.Text), BeginTime = dateStart.Value, Deadline = dateDeadline.Value, Description = txtDescription.Text, Status = lbStatus.Text }; if (lbStatus.Text.Equals("Done")) { project.EndTime = dateEnd.Value; } else { project.EndTime = null; } tbl_ProjectDAO dao = new tbl_ProjectDAO(); bool result = dao.Update(project); if (result) { SaveMode = true; MessageBox.Show("Update successfull!"); } else { MessageBox.Show("Update not successfull!"); } } catch (Exception) { MessageBox.Show("Update not successfull!"); } } }
/// <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) { } }
public bool Check_Save(tbl_ProjectDTO current, tbl_ProjectDTO now) { if (!current.Name.ToLower().Equals(now.Name.ToLower())) { return(false); } if (!current.Description.ToLower().Equals(now.Description.ToLower())) { return(false); } if (!current.Status.ToLower().Equals(now.Status.ToLower())) { return(false); } if (current.AdvancePayment != now.AdvancePayment) { return(false); } if (current.Cost != now.Cost) { return(false); } if (current.BeginTime != now.BeginTime) { return(false); } if (current.Deadline != now.Deadline) { return(false); } if (current.EndTime != now.EndTime) { return(false); } return(true); }
public tbl_ProjectDTO GetById(int id) { try { using (con = DBConnection.MakeConnection(con)) { con.Open(); SqlCommand command = new SqlCommand("Select name, description, partnerId, status, advancePayment, cost, beginTime, deadline, endTime from tbl_Project where id = @id", con); command.Parameters.AddWithValue("@id", id); SqlDataReader reader = command.ExecuteReader(); if (reader.Read()) { string name = reader["name"].ToString(); string description = reader["description"].ToString(); int partnerId = int.Parse(reader["partnerId"].ToString()); string status = "Doing..."; if (bool.Parse(reader["status"].ToString())) { status = "Done"; } float advancePayment = float.Parse(reader["advancePayment"].ToString()); float cost = float.Parse(reader["cost"].ToString()); DateTime beginTime = reader.GetDateTime(6); DateTime deadline; DateTime endTime; tbl_ProjectDTO dto = new tbl_ProjectDTO() { Id = id, Name = name, Description = description, PartnerId = partnerId, Status = status, AdvancePayment = advancePayment, Cost = cost, BeginTime = beginTime, }; try { deadline = reader.GetDateTime(7); dto.Deadline = deadline; } catch (Exception) { } try { endTime = reader.GetDateTime(8); dto.EndTime = endTime; } catch (Exception) { } return(dto); } } } catch (Exception) { throw; } return(null); }
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; } }