public void btnAddNewAtivityWorker_Click(object sender, EventArgs e) { System.Text.StringBuilder sb = null; double hoursWorked; if (!Double.TryParse(txtAddHours.Text.Replace('.', ','), out hoursWorked) || hoursWorked <= 0) { this.lblAddErrorMessage.Text = "Valor das horas não é válido!"; return; } if (string.IsNullOrWhiteSpace(txtAddComment.Text)) { this.lblAddErrorMessage.Text = "É necessário informar um comentário!"; return; } int workerID = Convert.ToInt32(hfNewActivityWorker.Value); Activity activity = CurrentActivity(); WorkerBusinessLogic workerBusinessLogic = new WorkerBusinessLogic(); Worker worker = workerBusinessLogic.GetByID(workerID); ActivityBusinessLogic activityBusinessLogic = new ActivityBusinessLogic(); double hoursAvaiable = activityBusinessLogic.GetAvaiablesHoursByWorkerOnDate(worker, activity.Date); if (hoursWorked > hoursAvaiable) { this.lblAddErrorMessage.Text = "As horas trabalhas superam as horas dispónives!"; return; } activityBusinessLogic.AttachWoker(activity, worker, hoursWorked, txtAddComment.Text); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EditHideModalScript", Util.GetScriptToHideModalDialog("addModal"), false); BindDdListWorkers(); BindGridVeiwWorksByActivity(); }
protected void btnDelete_Click(object sender, EventArgs e) { WorkerBusinessLogic WorkerBusinessLogic = new WorkerBusinessLogic(); Worker Worker = WorkerBusinessLogic.GetByID(Convert.ToInt32(HfDeleteID.Value)); WorkerBusinessLogic.Delete(Worker); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "delHideModalScript", Util.GetScriptToHideModalDialog("deleteModal"), false); BindGridViewWorkers(); }
protected void btnUpdateWorker_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.txtEditWorkerName.Text)) { lblEditWorkerMessage.Text = "O nome deve ser preenchido!"; return; } if (string.IsNullOrWhiteSpace(this.txtEditWorkerLastName.Text)) { lblEditWorkerMessage.Text = "o Sobrenome deve ser preenchido!"; return; } WorkerBusinessLogic workerBusinessLogic = new WorkerBusinessLogic(); Worker worker = workerBusinessLogic.GetByID(Convert.ToInt32(HfUpdateID.Value)); string currentName = worker.Name; worker.Name = txtEditWorkerName.Text; worker.LastName = txtEditWorkerLastName.Text; IResultOperation result = workerBusinessLogic.UpdatetWithRule(worker); if (result.Status != ResultOperationStatus.OK) { lblEditWorkerMessage.Text = result.Message; worker.Name = currentName; return; } BindGridViewWorkers(); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EditHideModalScript", Util.GetScriptToHideModalDialog("editModal"), false); lblEditWorkerMessage.Text = string.Empty; }
protected void btnAddActivityWorker_Click(object sender, EventArgs e) { if (lBoxWorkers.SelectedIndex <= -1) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(@"<script type='text/javascript'>"); sb.Append("alert('É necessário selecionar um Colaborador')"); sb.Append(@"</script>"); ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertSelectWorker", sb.ToString(), false); return; } int workerID = Convert.ToInt32(lBoxWorkers.SelectedValue); Activity activity = CurrentActivity(); WorkerBusinessLogic workerBusinessLogic = new WorkerBusinessLogic(); Worker worker = workerBusinessLogic.GetByID(workerID); hfNewActivityWorker.Value = workerID.ToString(); ActivityBusinessLogic activityBusinessLogic = new ActivityBusinessLogic(); double hoursAvaiable = activityBusinessLogic.GetAvaiablesHoursByWorkerOnDate(worker, activity.Date); this.txtAddDate.Text = activity.Date.ToShortDateString(); this.txtAddWorkername.Text = worker.FullName; this.lblAddAvaiableHours.Text = hoursAvaiable.ToString(); this.txtAddHours.Text = "0"; this.txtAddComment.Text = string.Empty; ScriptManager.RegisterClientScriptBlock( this, this.GetType(), "AddShowModalScript", Util.GetScriptToShowModalDialog("addModal"), false); BindDdListWorkers(); }