private void btnDelete_Click(object sender, EventArgs e) { int id = 0; int.TryParse(tbId.Text, out id); if (id != 0) { Project_Workers currentProject_Workers = BLProject_Workers.GetProject_WorkersById(APCContext, id); if (currentProject_Workers != null) { APCContext.DeleteObject(currentProject_Workers); APCContext.SaveChanges(); MessageBox.Show("Delete Successfully"); ClearContent(); } else { MessageBox.Show("Project_Workers Id not found"); } } else { MessageBox.Show("Project_Workers Id not found"); } }
private void btnUpdate_Click(object sender, EventArgs e) { int id = 0; int currentWorkerId = 0; int currentProjectId = 0; decimal totalWorkingHours = 0; decimal salary = 0; int.TryParse(tbId.Text, out id); if (id != 0) { Project_Workers currentProject_Workers = BLProject_Workers.GetProject_WorkersById(APCContext, id); if (currentProject_Workers != null) { if (int.TryParse(ddlWorker.SelectedValue.ToString(), out currentWorkerId)) { if (int.TryParse(ddlProject.SelectedValue.ToString(), out currentProjectId)) { if (decimal.TryParse(tbWorkingHours.Text, out totalWorkingHours)) { if (decimal.TryParse(tbSalary.Text, out salary)) { Workers currentWorker = BLWorkers.GetWorkersById(APCContext, currentWorkerId); Project currentProject = BLProject.GetProjectById(APCContext, currentProjectId); currentProject_Workers.Project = currentProject; currentProject_Workers.Workers = currentWorker; currentProject_Workers.StartDate = calStartDate.Value; currentProject_Workers.EndDate = calEndDate.Value; currentProject_Workers.TotalHours = totalWorkingHours; currentProject_Workers.Salary = salary; currentProject_Workers.TotalSalary = totalWorkingHours * salary; APCContext.SaveChanges(); MessageBox.Show("Project Workers Details Successfully Updated"); ClearContent(); } else { MessageBox.Show("Salary has to be decimal"); } } else { MessageBox.Show("Working hours has to be decimal"); } } } } else { MessageBox.Show("Project_Workers Id not found"); } } else { MessageBox.Show("Project_Workers Id not found"); } }
private void btnSearchByProject_Click(object sender, EventArgs e) { int projectId = 0; if (int.TryParse(ddlSearchProject.SelectedValue.ToString(), out projectId)) { List <Project_Workers> projectWorkersList = BLProject_Workers.GetProject_WorkersByProjectId(APCContext, projectId); dgProject_Workers.DataSource = createDataTableFromProject_WorkersList(projectWorkersList); } else { MessageBox.Show("Project_Workers Name not found"); } }
private void btnAddWorkerTS_Click(object sender, EventArgs e) { string strProjectId = ddlProject.SelectedValue.ToString(); int projectId = 0; DateTime startDate = DateTime.Today; DateTime endDate = DateTime.Today; if (int.TryParse(strProjectId, out projectId)) { if (DateTime.TryParse(calStartDate.Value.ToString(), out startDate)) { if (DateTime.TryParse(calEndDate.Value.ToString(), out endDate)) { //Add 1 day of the end date endDate = endDate.AddDays(1); DataTable dtProjectWorkers = BLProject_Workers.GetProject_WorkersByProjectAndTime(projectId, startDate.Date, endDate.Date); //if (dgWorker.DataSource == null) //{ getDefaultDataForWorkerGrid(); //} DataTable dtWorker = (DataTable)dgWorker.DataSource; if (dtProjectWorkers.Rows.Count > 0) { for (int i = 0; i < dtProjectWorkers.Rows.Count; i++) { DataRow drWorker = dtWorker.NewRow(); drWorker["Name"] = dtProjectWorkers.Rows[i]["WorkerName"]; drWorker["StartDate"] = dtProjectWorkers.Rows[i]["StartDate"]; drWorker["EndDate"] = dtProjectWorkers.Rows[i]["EndDate"]; drWorker["Salary"] = dtProjectWorkers.Rows[i]["Salary"]; drWorker["TotalHours"] = dtProjectWorkers.Rows[i]["TotalHours"]; drWorker["TotalSalary"] = dtProjectWorkers.Rows[i]["TotalSalary"]; dtWorker.Rows.Add(drWorker); } } dgWorker.DataSource = dtWorker; decimal totalWorkerSalary = getTotalWorkerSalary(dtWorker); deleteInvoiceProductItemGrid("Upah"); insertToInvoiceProductGrid("Upah", startDate.ToShortDateString() + " to " + endDate.ToShortDateString(), 1, totalWorkerSalary, 0, totalWorkerSalary, false, "Rp"); } } } }
private void btnInsert_Click(object sender, EventArgs e) { int currentWorkerId = 0; int currentProjectId = 0; decimal totalWorkingHours = 0; decimal salary = 0; if (int.TryParse(ddlWorker.SelectedValue.ToString(), out currentWorkerId)) { if (int.TryParse(ddlProject.SelectedValue.ToString(), out currentProjectId)) { if (decimal.TryParse(tbWorkingHours.Text, out totalWorkingHours)) { if (decimal.TryParse(tbSalary.Text, out salary)) { Workers currentWorker = BLWorkers.GetWorkersById(APCContext, currentWorkerId); Project currentProject = BLProject.GetProjectById(APCContext, currentProjectId); if (BLProject_Workers.insertProject_Workers(APCContext, currentProject, currentWorker, calStartDate.Value, calEndDate.Value, totalWorkingHours, salary)) { MessageBox.Show("Project_Workers Successfully Added"); ClearContent(); } else { MessageBox.Show("Please check your input"); } } else { MessageBox.Show("Salary has to be decimal"); } } else { MessageBox.Show("Working hours has to be decimal"); } } } }