private void workUpdate() { // Get general variables int workId = Int32.Parse(hdfWorkId.Value.Trim()); int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim()); int assetId = Int32.Parse(hdfAssetId.Value.Trim()); int companyId = Int32.Parse(hdfCompanyId.Value.Trim()); string workType = hdfWorkType.Value.Trim(); // Update comments for rehab assessment // Get original variables WorkGateway workGateway = new WorkGateway(); workGateway.LoadByWorkId(workId, companyId); string originalWorkType = workGateway.GetWorkTypeOriginal(workId); int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(workId); string originalComment = workGateway.GetCommentsOriginal(workId); string originalHistory = workGateway.GetHistoryOriginal(workId); //Get all new rehab assessment comments RehabAssessmentCommentDetailsGateway rehabAssessmentCommentDetailsGateway = new RehabAssessmentCommentDetailsGateway(rehabAssessmentTDS); rehabAssessmentCommentDetailsGateway.LoadAllByWorkIdWorkType(workId, companyId, workType); RehabAssessmentCommentDetails rehabAssessmentCommentDetails = new RehabAssessmentCommentDetails(rehabAssessmentCommentDetailsGateway.Data); string newComment = rehabAssessmentCommentDetails.GetAllRehabAssessmentComments(workId, companyId, rehabAssessmentCommentDetailsGateway.Table.Rows.Count, "\n"); Work work = new Work(null); work.UpdateDirect(workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, workId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, newComment, originalHistory); // Update comments for full length lining int workIdFll = Int32.Parse(hdfWorkIdFll.Value.Trim()); if (workIdFll != 0) { WorkGateway workGatewayForFll = new WorkGateway(); workGatewayForFll.LoadByWorkId(workIdFll, companyId); string originalWorkTypeForFll = workGatewayForFll.GetWorkTypeOriginal(workIdFll); int? originalLibraryCategoriesIdForFll = workGatewayForFll.GetLibraryCategoriesIdOriginal(workIdFll); string originalCommentForFll = workGatewayForFll.GetCommentsOriginal(workIdFll); string originalHistoryForFll = workGatewayForFll.GetHistoryOriginal(workIdFll); //Get all new fulllengthlining comments FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(); fullLengthLiningCommentDetailsGateway.LoadAllByWorkIdWorkType(workIdFll, companyId, "Full Length Lining"); FullLengthLiningCommentDetails fullLengthLiningCommentDetails = new FullLengthLiningCommentDetails(fullLengthLiningCommentDetailsGateway.Data); string newCommentForFll = fullLengthLiningCommentDetails.GetAllFullLengthLiningComments(workIdFll, companyId, fullLengthLiningCommentDetailsGateway.Table.Rows.Count, "\n"); // Save comments Work workForFll = new Work(null); workForFll.UpdateDirect(workIdFll, projectId, assetId, originalWorkTypeForFll, originalLibraryCategoriesIdForFll, false, companyId, originalCommentForFll, originalHistoryForFll, workIdFll, projectId, assetId, originalWorkTypeForFll, originalLibraryCategoriesIdForFll, false, companyId, newCommentForFll, originalHistoryForFll); } }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!(Convert.ToBoolean(Session["sgLFS_CWP_REHABASSESSMENT_VIEW"]) && Convert.ToBoolean(Session["sgLFS_CWP_REHABASSESSMENT_EDIT"]))) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } // Validate query string if (((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["client_id"] == null) || ((string)Request.QueryString["project_id"] == null) || ((string)Request.QueryString["work_id"] == null) || ((string)Request.QueryString["asset_id"] == null)) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in ra_comments.aspx"); } // Tag Page hdfCompanyId.Value = Session["companyID"].ToString(); hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString(); hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString(); hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString(); hdfAdminPermission.Value = Convert.ToBoolean(Session["sgLFS_CWP_REHABASSESSMENT_ADMIN"]).ToString(); hdfWorkType.Value = "Rehab Assessment"; hdfWorkId.Value = Request.QueryString["work_id"].ToString(); hdfAssetId.Value = Request.QueryString["asset_id"].ToString(); hdfUpdate.Value = "yes"; // Prepare initial data Session.Remove("rehabAssessmentCommentDetailsDummy"); // ... Names for UserList string workType = hdfWorkType.Value.Trim(); int companyId = Int32.Parse(hdfCompanyId.Value); LoginGateway loginGateway = new LoginGateway(); loginGateway.LoadByLoginId(Convert.ToInt32(hdfLoginId.Value),companyId); hdfCreatedBy.Value = loginGateway.GetLastName(Convert.ToInt32(hdfLoginId.Value), companyId) + " " + loginGateway.GetFirstName(Convert.ToInt32(hdfLoginId.Value), companyId); hdfCreationDateTime.Value = DateTime.Now.ToString(); // If coming from // ... ra_summary.aspx or ra_edit.aspx if (Request.QueryString["source_page"] == "ra_summary.aspx" || Request.QueryString["source_page"] == "ra_edit.aspx") { StoreNavigatorState(); ViewState["update"] = Request.QueryString["update"]; // For RA rehabAssessmentTDS = (RehabAssessmentTDS)Session["rehabAssessmentTDS"]; int assetId = Int32.Parse(hdfAssetId.Value.Trim()); int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim()); int workId = Int32.Parse(hdfWorkId.Value.Trim()); if (workId != 0) { // ... update comments RehabAssessmentCommentDetailsGateway rehabAssessmentCommentDetailsGateway = new RehabAssessmentCommentDetailsGateway(rehabAssessmentTDS); rehabAssessmentCommentDetailsGateway.LoadAllByWorkIdWorkType(workId, companyId, workType); RehabAssessmentCommentDetails rehabAssessmentCommentDetails = new RehabAssessmentCommentDetails(rehabAssessmentCommentDetailsGateway.Data); rehabAssessmentCommentDetails.UpdateForProcess(); } // For FLL int workIdFll = GetWorkId(currentProjectId, assetId, "Full Length Lining", companyId); hdfWorkIdFll.Value = workIdFll.ToString(); if (workIdFll != 0) { // ... update comments FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(); fullLengthLiningCommentDetailsGateway.LoadAllByWorkIdWorkType(workIdFll, companyId, "Full Length Lining"); FullLengthLiningCommentDetails fullLengthLiningCommentDetails = new FullLengthLiningCommentDetails(fullLengthLiningCommentDetailsGateway.Data); fullLengthLiningCommentDetails.UpdateForProcess(); } // ... Store datasets Session["rehabAssessmentTDS"] = rehabAssessmentTDS; Session["rehabAssessmentCommentDetails"] = rehabAssessmentTDS.CommentDetails; } } else { // Restore datasets rehabAssessmentTDS = (RehabAssessmentTDS)Session["rehabAssessmentTDS"]; rehabAssessmentCommentDetails = rehabAssessmentTDS.CommentDetails; } }
//// //////////////////////////////////////////////////////////////////////// // PRIVATE METHODS // /// <summary> /// GetNewRefId /// </summary> /// <returns>New ID</returns> private int GetNewRefId(string type, int workId, int companyId) { int newRefId = 0; if (type == "Rehab Assessment") { foreach (RehabAssessmentTDS.CommentDetailsRow row in (RehabAssessmentTDS.CommentDetailsDataTable)Table) { if (newRefId < row.RefID) { newRefId = row.RefID; } } } else { int maxRefIdFll = 0; FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(); fullLengthLiningCommentDetailsGateway.LoadAllByWorkIdWorkType(workId, companyId, "Full Length Lining"); foreach (FullLengthLiningTDS.CommentDetailsRow row in (FullLengthLiningTDS.CommentDetailsDataTable)fullLengthLiningCommentDetailsGateway.Table) { if (maxRefIdFll < row.RefID) { maxRefIdFll = row.RefID; } } foreach (RehabAssessmentTDS.CommentDetailsRow row in (RehabAssessmentTDS.CommentDetailsDataTable)Table) { if (row.Type != "Rehab Assessment") { if (maxRefIdFll < row.RefID) { maxRefIdFll = row.RefID; } } } newRefId = maxRefIdFll; } newRefId++; return newRefId; }
/// <summary> /// Save all comments to database (direct) /// </summary> /// <param name="companyId">companyId</param> public void Save(int companyId) { FullLengthLiningTDS fullLengthLiningCommentDetailsChanges = (FullLengthLiningTDS)Data.GetChanges(); if (fullLengthLiningCommentDetailsChanges.CommentDetails.Rows.Count > 0) { FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(fullLengthLiningCommentDetailsChanges); foreach (FullLengthLiningTDS.CommentDetailsRow row in (FullLengthLiningTDS.CommentDetailsDataTable)fullLengthLiningCommentDetailsChanges.CommentDetails) { // Insert new comments if ((!row.Deleted) && (!row.InDatabase)) { WorkComments workComments = new WorkComments(null); int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID; workComments.InsertDirect(row.WorkID, row.RefID, row.Type, row.Subject, row.UserID, row.DateTime_, row.Comment, libraryFilesId, row.Deleted, row.COMPANY_ID, row.WorkType); } // Update comments if ((!row.Deleted) && (row.InDatabase)) { int workId = row.WorkID; int refId = row.RefID; bool originalDeleted = false; int originalCompanyId = companyId; // original values string originalType = fullLengthLiningCommentDetailsGateway.GetTypeOriginal(workId, refId); string originalSubject = fullLengthLiningCommentDetailsGateway.GetSubjectOriginal(workId, refId); int originalUserId = fullLengthLiningCommentDetailsGateway.GetUserIdOriginal(workId, refId); DateTime? originalDateTime = null; if (fullLengthLiningCommentDetailsGateway.GetDateTime_Original(workId, refId) != null) originalDateTime = fullLengthLiningCommentDetailsGateway.GetDateTime_Original(workId, refId); string originalComment = fullLengthLiningCommentDetailsGateway.GetCommentOriginal(workId, refId); int? originalLibraryFilesId = null; if (fullLengthLiningCommentDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = fullLengthLiningCommentDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId); string originalWorkType = fullLengthLiningCommentDetailsGateway.GetWorkTypeOriginal(workId, refId); // new values string newType = fullLengthLiningCommentDetailsGateway.GetType(workId, refId); string newSubject = fullLengthLiningCommentDetailsGateway.GetSubject(workId, refId); string newComment = fullLengthLiningCommentDetailsGateway.GetComment(workId, refId); int? newLibraryFilesId = null; if (fullLengthLiningCommentDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = fullLengthLiningCommentDetailsGateway.GetLIBRARY_FILES_ID(workId, refId); WorkComments workComments = new WorkComments(null); workComments.UpdateDirect(workId, refId, originalType, originalSubject, originalUserId, originalDateTime, originalComment, originalLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType, workId, refId, newType, newSubject, originalUserId, originalDateTime, newComment, newLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType); } // Deleted comments if ((row.Deleted) && (row.InDatabase)) { WorkComments workComments = new WorkComments(null); workComments.DeleteDirect(row.WorkID, row.RefID, row.COMPANY_ID); } } } }
// //////////////////////////////////////////////////////////////////////// // EVENTS // protected void Page_Load(object sender, EventArgs e) { // Register client scripts this.RegisterClientScripts(); if (!IsPostBack) { // Security check if (!(Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_VIEW"]) && Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_EDIT"]))) { Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator."); } // Validate query string if (((string)Request.QueryString["source_page"] == null) || ((string)Request.QueryString["client_id"] == null) || ((string)Request.QueryString["project_id"] == null) || ((string)Request.QueryString["work_id"] == null) || ((string)Request.QueryString["asset_id"] == null)) { Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in fl_comments.aspx"); } // Tag Page hdfCompanyId.Value = Session["companyID"].ToString(); hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString(); hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString(); hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString(); hdfAdminPermission.Value = Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_ADMIN"]).ToString(); hdfWorkType.Value = "Full Length Lining"; hdfWorkId.Value = Request.QueryString["work_id"].ToString(); hdfAssetId.Value = Request.QueryString["asset_id"].ToString(); hdfUpdate.Value = "yes"; // ... Names for UserList string workType = hdfWorkType.Value.Trim(); int companyId = Int32.Parse(hdfCompanyId.Value); LoginGateway loginGateway = new LoginGateway(); loginGateway.LoadByLoginId(Convert.ToInt32(hdfLoginId.Value), companyId); hdfCreatedBy.Value = loginGateway.GetLastName(Convert.ToInt32(hdfLoginId.Value), companyId) + " " + loginGateway.GetFirstName(Convert.ToInt32(hdfLoginId.Value), companyId); // Prepare initial data Session.Remove("fullLengthLiningCommentDetailsDummy"); // If coming from // ... flsummary.aspx and fl_edit.aspx if (Request.QueryString["source_page"] == "fl_summary.aspx" || Request.QueryString["source_page"] == "fl_edit.aspx") { StoreNavigatorState(); ViewState["update"] = Request.QueryString["update"]; fullLengthLiningTDS = (FullLengthLiningTDS)Session["fullLengthLiningTDS"]; int assetId = Int32.Parse(hdfAssetId.Value.Trim()); int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim()); int flWorkId = Int32.Parse(hdfWorkId.Value.Trim()); int raWorkId = 0; // ... If the project has fl works if (flWorkId != 0) { WorkGateway workGateway = new WorkGateway(); workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, assetId, "Rehab Assessment", companyId); if (workGateway.Table.Rows.Count > 0) { raWorkId = workGateway.GetWorkId(assetId, "Rehab Assessment", currentProjectId); } // ... update fl and ra comments FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(fullLengthLiningTDS); fullLengthLiningCommentDetailsGateway.LoadAllByFlWorkIdRaWorkId(flWorkId, raWorkId, companyId); FullLengthLiningCommentDetails fullLengthLiningCommentDetailsForLoad = new FullLengthLiningCommentDetails(fullLengthLiningCommentDetailsGateway.Data); fullLengthLiningCommentDetailsForLoad.UpdateForProcess(); } // ... Store datasets Session["fullLengthLiningTDS"] = fullLengthLiningTDS; Session["fullLengthLiningCommentDetails"] = fullLengthLiningTDS.CommentDetails; } } else { // Restore datasets fullLengthLiningTDS = (FullLengthLiningTDS)Session["fullLengthLiningTDS"]; fullLengthLiningCommentDetails = fullLengthLiningTDS.CommentDetails; // Store Session["fullLengthLiningCommentDetails"] = fullLengthLiningTDS.CommentDetails; } }
protected void grdComments_RowDataBound(object sender, GridViewRowEventArgs e) { if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || ((e.Row.RowState == DataControlRowState.Alternate)))) { if (((Label)e.Row.FindControl("lblUserId")).Text != "") { int loginId = Int32.Parse(hdfLoginId.Value); bool adminPermission = bool.Parse(hdfAdminPermission.Value); int rowUserId = Int32.Parse(((Label)e.Row.FindControl("lblUserId")).Text); if ((loginId == rowUserId) || (adminPermission)) { e.Row.FindControl("ibtnDelete").Visible = true; e.Row.FindControl("ibtnEdit").Visible = true; } else { e.Row.FindControl("ibtnDelete").Visible = false; e.Row.FindControl("ibtnEdit").Visible = false; } } } if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)))) { int workId = Int32.Parse(((Label)e.Row.FindControl("lblWorkID")).Text.Trim()); int refId = Int32.Parse(((Label)e.Row.FindControl("lblRefID")).Text.Trim()); FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(fullLengthLiningTDS); string type = fullLengthLiningCommentDetailsGateway.GetType(workId, refId); if (type != "Rehab Assessment") { ((TextBox)e.Row.FindControl("tbxTypeEdit")).Visible = false; ((DropDownList)e.Row.FindControl("ddlTypeEdit")).SelectedValue = type; ((DropDownList)e.Row.FindControl("ddlTypeEdit")).Visible = true; } else { ((TextBox)e.Row.FindControl("tbxTypeEdit")).Text = type; ((TextBox)e.Row.FindControl("tbxTypeEdit")).Visible = true; ((DropDownList)e.Row.FindControl("ddlTypeEdit")).Visible = false; ((DropDownList)e.Row.FindControl("ddlTypeEdit")).SelectedValue = "M1"; } } }