/// <summary> /// Save all comments to database (direct) /// </summary> /// <param name="companyId">companyId</param> /// <param name="runDetails">runDetails</param> /// <param name="projectId">projectId</param> public void Save(int companyId, string runDetails, int projectId) { string[] runDetailsList = runDetails.Split('>'); FullLengthLiningTDS fullLengthLiningWetOutCommentsDetailsChanges = (FullLengthLiningTDS)Data.GetChanges(); if (fullLengthLiningWetOutCommentsDetailsChanges.WetOutCommentsDetails.Rows.Count > 0) { FullLengthLiningWetOutCommentsDetailsGateway fullLengthLiningWetOutCommentsDetailsGateway = new FullLengthLiningWetOutCommentsDetailsGateway(fullLengthLiningWetOutCommentsDetailsChanges); foreach (FullLengthLiningTDS.WetOutCommentsDetailsRow row in (FullLengthLiningTDS.WetOutCommentsDetailsDataTable)fullLengthLiningWetOutCommentsDetailsChanges.WetOutCommentsDetails) { // Insert new comments if ((!row.Deleted) && (!row.InDatabase)) { for (int i = 0; i < runDetailsList.Length; i++) { AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(); string sectionId = runDetailsList[i].ToString(); assetSewerSectionGateway.LoadBySectionId(sectionId, companyId); int assetId = assetSewerSectionGateway.GetAssetID(sectionId); WorkGateway workGateway = new WorkGateway(); int newWorkId = 0; workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId); if (workGateway.Table.Rows.Count > 0) { newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId); } WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null); int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID; workFullLengthLiningWetOutComments.InsertDirect(newWorkId, 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 = fullLengthLiningWetOutCommentsDetailsGateway.GetTypeOriginal(workId, refId); string originalSubject = fullLengthLiningWetOutCommentsDetailsGateway.GetSubjectOriginal(workId, refId); int originalUserId = fullLengthLiningWetOutCommentsDetailsGateway.GetUserIdOriginal(workId, refId); DateTime? originalDateTime = null; if (fullLengthLiningWetOutCommentsDetailsGateway.GetDateTime_Original(workId, refId) != null) originalDateTime = fullLengthLiningWetOutCommentsDetailsGateway.GetDateTime_Original(workId, refId); string originalComment = fullLengthLiningWetOutCommentsDetailsGateway.GetCommentOriginal(workId, refId); int? originalLibraryFilesId = null; if (fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId); string originalWorkType = fullLengthLiningWetOutCommentsDetailsGateway.GetWorkTypeOriginal(workId, refId); // new values string newType = fullLengthLiningWetOutCommentsDetailsGateway.GetType(workId, refId); string newSubject = fullLengthLiningWetOutCommentsDetailsGateway.GetSubject(workId, refId); string newComment = fullLengthLiningWetOutCommentsDetailsGateway.GetComment(workId, refId); int? newLibraryFilesId = null; if (fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_IDOriginal(workId, refId) != null) originalLibraryFilesId = fullLengthLiningWetOutCommentsDetailsGateway.GetLIBRARY_FILES_ID(workId, refId); for (int i = 0; i < runDetailsList.Length; i++) { AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(); string sectionId = runDetailsList[i].ToString(); assetSewerSectionGateway.LoadBySectionId(sectionId, companyId); int assetId = assetSewerSectionGateway.GetAssetID(sectionId); WorkGateway workGateway = new WorkGateway(); int newWorkId = 0; workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId); if (workGateway.Table.Rows.Count > 0) { newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId); } string workType = "Full Length Lining Wet Out"; FullLengthLiningWetOutCommentsDetailsGateway fullLengthLiningWetOutCommentsDetailsGatewayForReview = new FullLengthLiningWetOutCommentsDetailsGateway(); fullLengthLiningWetOutCommentsDetailsGatewayForReview.LoadAllByWorkIdWorkType(newWorkId, companyId, workType); if (fullLengthLiningWetOutCommentsDetailsGatewayForReview.Table.Rows.Count > 0) { WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null); workFullLengthLiningWetOutComments.UpdateDirect(newWorkId, refId, originalType, originalSubject, originalUserId, originalDateTime, originalComment, originalLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType, workId, refId, newType, newSubject, originalUserId, originalDateTime, newComment, newLibraryFilesId, originalDeleted, originalCompanyId, originalWorkType); } else { WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null); int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID; workFullLengthLiningWetOutComments.InsertDirect(newWorkId, row.RefID, row.Type, row.Subject, row.UserID, row.DateTime_, row.Comment, libraryFilesId, row.Deleted, row.COMPANY_ID, row.WorkType); } } } // Deleted comments if ((row.Deleted) && (row.InDatabase)) { for (int i = 0; i < runDetailsList.Length; i++) { AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(); string sectionId = runDetailsList[i].ToString(); assetSewerSectionGateway.LoadBySectionId(sectionId, companyId); int assetId = assetSewerSectionGateway.GetAssetID(sectionId); WorkGateway workGateway = new WorkGateway(); int newWorkId = 0; workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Full Length Lining", companyId); if (workGateway.Table.Rows.Count > 0) { newWorkId = workGateway.GetWorkId(assetId, "Full Length Lining", projectId); } WorkFullLengthLiningWetOutComments workFullLengthLiningWetOutComments = new WorkFullLengthLiningWetOutComments(null); workFullLengthLiningWetOutComments.DeleteDirect(newWorkId, row.RefID, row.COMPANY_ID); } } } } }
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()); FullLengthLiningWetOutCommentsDetailsGateway fullLengthLiningWetOutCommentDetailsGateway = new FullLengthLiningWetOutCommentsDetailsGateway(fullLengthLiningTDS); string type = fullLengthLiningWetOutCommentDetailsGateway.GetType(workId, refId); ((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 = "Wet Out"; } if (e.Row.RowType == DataControlRowType.Footer) { ((DropDownList)e.Row.FindControl("ddlTypeNew")).SelectedValue = "Wet Out"; } }