private void LoadActivityData(int toDoId, int companyId) { ToDoListInformationActivityInformation toDoListInformationActivityInformation = new ToDoListInformationActivityInformation(); toDoListInformationActivityInformation.LoadAllByToDoId(toDoId, companyId); int lastRefId = toDoListInformationActivityInformation.GetLastAssignedUserRefId(); ToDoListInformationActivityInformationGateway toDoListInformationActivityInformationGateway = new ToDoListInformationActivityInformationGateway(toDoListInformationActivityInformation.Data); toDoListInformationActivityInformationGateway.LoadAllByToDoId(toDoId, companyId); if (toDoListInformationActivityInformationGateway.Table.Rows.Count > 0) { // For last assigned user tbxAssignedUser.Text = toDoListInformationActivityInformationGateway.GetEmployeeFullName(toDoId, lastRefId); hdfAssignedUser.Value = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, lastRefId).ToString(); } }
/// <summary> /// Save all activities to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { ToDoListInformationTDS toDoListInformationChanges = (ToDoListInformationTDS)Data.GetChanges(); if (toDoListInformationChanges != null) { if (toDoListInformationChanges.ActivityInformation.Rows.Count > 0) { ToDoListInformationActivityInformationGateway toDoListInformationActivityInformationGateway = new ToDoListInformationActivityInformationGateway(toDoListInformationChanges); foreach (ToDoListInformationTDS.ActivityInformationRow row in (ToDoListInformationTDS.ActivityInformationDataTable)toDoListInformationChanges.ActivityInformation) { // Insert new activity if ((!row.Deleted) && (!row.InDataBase)) { // new values int toDoId = row.ToDoID; int refId = row.RefID; int employeeId = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, refId); string type_ = toDoListInformationActivityInformationGateway.GetType_(toDoId, refId); DateTime dateTime_ = toDoListInformationActivityInformationGateway.GetDateTime_(toDoId, refId); string comment = toDoListInformationActivityInformationGateway.GetComment(toDoId, refId); ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null); toDoListToDoListActivity.InsertDirect(toDoId, refId, employeeId, type_, dateTime_, row.Deleted, row.COMPANY_ID, comment); } // Update activities if ((!row.Deleted) && (row.InDataBase)) { int toDoId = row.ToDoID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // original values int originalEmployeeId = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, refId); string originalType_ = toDoListInformationActivityInformationGateway.GetType_(toDoId, refId); DateTime originalDateTime_ = toDoListInformationActivityInformationGateway.GetDateTime_(toDoId, refId); string originalComment = toDoListInformationActivityInformationGateway.GetComment(toDoId, refId); // new values int newEmployeeId = toDoListInformationActivityInformationGateway.GetEmployeeIDOriginal(toDoId, refId); string newComment = toDoListInformationActivityInformationGateway.GetCommentOriginal(toDoId, refId); ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null); toDoListToDoListActivity.UpdateDirect(toDoId, refId, originalEmployeeId, originalType_, originalDateTime_, originalDeleted, originalCompanyId, originalComment, toDoId, refId, newEmployeeId, originalType_, originalDateTime_, originalDeleted, originalCompanyId, newComment); } // Deleted activity if ((row.Deleted) && (row.InDataBase)) { ToDoListToDoListActivity toDoListToDoListActivity = new ToDoListToDoListActivity(null); toDoListToDoListActivity.DeleteDirect(row.ToDoID, row.RefID, row.COMPANY_ID); } } } } }
protected void grdToDoList_RowDataBound(object sender, GridViewRowEventArgs e) { // Control of footer row if (e.Row.RowType == DataControlRowType.Footer) { int loginId = Convert.ToInt32(Session["loginID"]); EmployeeGateway employeeGateway = new EmployeeGateway(); int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId); // Select action DropDownList actions = (DropDownList)e.Row.FindControl("ddlActionsNew"); actions.SelectedValue = hdfAction.Value; // Only the assigned user could close the todo if (hdfAssignedUser.Value != employeeId.ToString()) { actions.Items.Remove("Close"); } // Make fields visible for actions if (hdfAction.Value == "Assign To User") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = true; ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = true; ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = false; ((Label)e.Row.FindControl("lblClosed")).Visible = false; ((Label)e.Row.FindControl("lblUserNew")).Text = "Assign To"; } if (hdfAction.Value == "Add Comment") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = true; EmployeeGateway employeeGatewayForUser = new EmployeeGateway(); employeeGatewayForUser.LoadByEmployeeId(employeeId); ((TextBox)e.Row.FindControl("tbxUserNew")).Text = employeeGatewayForUser.GetFullName(employeeId); ((Label)e.Row.FindControl("lblClosed")).Visible = false; ((Label)e.Row.FindControl("lblUserNew")).Text = "Comment Added By"; } if (hdfAction.Value == "Complete") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = true; EmployeeGateway employeeGatewayForUser = new EmployeeGateway(); employeeGatewayForUser.LoadByEmployeeId(Int32.Parse(hdfAssignedUser.Value)); ((TextBox)e.Row.FindControl("tbxUserNew")).Text = employeeGatewayForUser.GetFullName(Int32.Parse(hdfAssignedUser.Value)); ((Label)e.Row.FindControl("lblClosed")).Visible = false; ((Label)e.Row.FindControl("lblUserNew")).Text = "To Do Completed By"; } if (hdfCompleted.Value == "True") { ((DropDownList)e.Row.FindControl("ddlActionsNew")).Visible = false; ((TextBox)e.Row.FindControl("tbxDateTimeNew")).Visible = false; ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = false; ((TextBox)e.Row.FindControl("tbxCommentsNew")).Visible = false; ((Label)e.Row.FindControl("lblActionNew")).Visible = false; ((Label)e.Row.FindControl("lblDateTimeNew")).Visible = false; ((Label)e.Row.FindControl("lblUserNew")).Visible = false; ((Label)e.Row.FindControl("lblCommentsNew")).Visible = false; ((ImageButton)e.Row.FindControl("ibtnAdd")).Visible = false; ((Label)e.Row.FindControl("lblClosed")).Visible = true; } if (hdfAction.Value == "Put On Hold") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = true; EmployeeGateway employeeGatewayForOnHold = new EmployeeGateway(); employeeGatewayForOnHold.LoadByEmployeeId(employeeId); ((TextBox)e.Row.FindControl("tbxUserNew")).Text = employeeGatewayForOnHold.GetFullName(employeeId); ((Label)e.Row.FindControl("lblClosed")).Visible = false; ((Label)e.Row.FindControl("lblUserNew")).Text = "On Hold By"; } // Date and time DateTime creationDate = DateTime.Now; ((TextBox)e.Row.FindControl("tbxDateTimeNew")).Text = creationDate.ToString(); } // Control of edit rows if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)))) { // Date and time DateTime creationDate = DateTime.Now; ((TextBox)e.Row.FindControl("tbxDateTimeEdit")).Text = creationDate.ToString(); string type_ = ((Label)e.Row.FindControl("lblType")).Text; int loginId = Convert.ToInt32(Session["loginID"]); EmployeeGateway employeeGateway = new EmployeeGateway(); int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId); int toDoId = Int32.Parse(((Label)e.Row.FindControl("lblToDoID")).Text); int refId = Int32.Parse(((Label)e.Row.FindControl("lblRefID")).Text); ToDoListInformationActivityInformationGateway toDoListInformationActivityInformationGateway = new ToDoListInformationActivityInformationGateway(toDoListInformationTDS); // Make fields visible for actions if (type_ == "AssignUser") { int employeeIdForAssign = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, refId); ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = true; ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).SelectedValue = employeeIdForAssign.ToString(); ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = true; ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = false; ((Label)e.Row.FindControl("lblUserEdit")).Text = "Assign To"; } if (type_ == "AddComment") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = true; EmployeeGateway employeeGatewayForUser = new EmployeeGateway(); employeeGatewayForUser.LoadByEmployeeId(employeeId); ((TextBox)e.Row.FindControl("tbxUserEdit")).Text = employeeGatewayForUser.GetFullName(employeeId); ((Label)e.Row.FindControl("lblUserEdit")).Text = "Comment Added By"; } if (type_ == "CloseToDo") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = true; EmployeeGateway employeeGatewayForUser = new EmployeeGateway(); employeeGatewayForUser.LoadByEmployeeId(Int32.Parse(hdfAssignedUser.Value)); ((TextBox)e.Row.FindControl("tbxUserEdit")).Text = employeeGatewayForUser.GetFullName(Int32.Parse(hdfAssignedUser.Value)); ((Label)e.Row.FindControl("lblUserEdit")).Text = "To Do Completed By"; } if (type_ == "OnHoldToDo") { ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = false; ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = false; ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = true; EmployeeGateway employeeGatewayForOnHold = new EmployeeGateway(); employeeGatewayForOnHold.LoadByEmployeeId(employeeId); ((TextBox)e.Row.FindControl("tbxUserEdit")).Text = employeeGatewayForOnHold.GetFullName(employeeId); ((Label)e.Row.FindControl("lblUserEdit")).Text = "On Hold By"; } } // Control normal rows if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate)))) { // Validate admin actions if ((Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_ADMIN"]))) { ((ImageButton)e.Row.FindControl("ibtnEdit")).Visible = true; ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = true; } else { bool inDataBase = bool.Parse(((Label)e.Row.FindControl("lblInDataBase")).Text); if (inDataBase) { ((ImageButton)e.Row.FindControl("ibtnEdit")).Visible = false; ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = false; } else { ((ImageButton)e.Row.FindControl("ibtnEdit")).Visible = true; ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = true; } } // Change label text string type_ = ((Label)e.Row.FindControl("lblType")).Text; if (type_ == "AssignUser") { ((Label)e.Row.FindControl("lblUser")).Text = "Assign To"; } if (type_ == "AddComment") { ((Label)e.Row.FindControl("lblUser")).Text = "Comment Added By"; } if (type_ == "CloseToDo") { ((Label)e.Row.FindControl("lblUser")).Text = "To Do Completed By"; } if (type_ == "OnHoldToDo") { ((Label)e.Row.FindControl("lblUser")).Text = "On Hold By"; } } }