using framework_business; using framework_library; using System; using System.Collections; using System.Data; using System.Linq; using System.Reflection; using System.Web.UI; using System.Web.UI.WebControls; using Telerik.Web.UI; using System.Web.UI.HtmlControls; using System.Text; using System.Drawing; using System.IO; using System.Configuration; using System.Collections.Generic; using Newtonsoft.Json; public partial class controls_module_surfacenotes : UserControl, ISurfaceControlBase { #region methods /// /// ReloadControl /// /// public void ReloadControl(oSurfaceFieldData controlFieldData, bool alternateView = false, bool readOnly = false) { try { //2017-07-14 JasR not sure why this is here - it gives errors and dtProperties is not used anywhere // Pro-5 - 5 June 2017 - DS - Notes Category //List lstParams = new List(); //oDynamicParam param1 = new oDynamicParam(); //param1.paramDisplayName = "surfaceName"; //param1.paramObject = "Properties"; //lstParams.Add(param1); //DataTable dtProperties = xData.GetTypedTableByProc("recId", typeof(oSurfaceFieldData), "sproc_PROP1_GetProperties", lstParams); SetControlsVisibility(); SurfaceId = controlFieldData.surfaceId; SurfaceItemId = controlFieldData.surfaceItemId; foreach (oSurfaceField field in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", controlFieldData.surfaceFieldID.ToString())) { SurfaceFieldId = field.recId; lblNoteTitle.Text = field.surfaceFieldDisplay; } pnlConfFilter.Visible = this.Confidential; divConfidential.Visible = this.Confidential; if (this.Confidential) CustomLoadConfidential(); if (alternateView) RecordLimit = 3; BindNotes(); #region The Property Solution oSetup setup = handler.ReturnSetup(); if (setup.code == "PROP-1") { divNoteCategory.Visible = true; // Pro-5 CreatePropertyDetailObject(); } #endregion } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void CustomLoadConfidential() { try { if (handler.ReturnSetup().code == "STUD-1") { //set confidential user foreach (oNoteType confType in xData.GetTypedByCriteriaSpecific("recId", typeof(oNoteType), "recId", pNums.NoteType.Confidential.GetHashCode().ToString())) { int confUser = 0; int.TryParse(confType.customItem, out confUser); this.ConfidentialUser = confUser; break; } int count = 0; foreach (oSurfaceLookupCategory cat in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookupCategory), "isActive", "1")) { if (cat.lookupCategory.StartsWith("Confidential Note")) { count++; ArrayList items = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "isActive,categoryId", "1," + cat.recId); //bind form drop down HtmlGenericControl lbl = (HtmlGenericControl)divConfidential.FindControl("lblConfDD" + count); DropDownList dd = (DropDownList)divConfidential.FindControl("ddConfDD" + count); if (lbl != null && dd != null) { lbl.InnerText = cat.lookupCategory.Replace("Confidential Note ", ""); dd.DataSource = items; dd.DataTextField = "display"; dd.DataValueField = "recId"; dd.DataBind(); dd.Items.Insert(0, new ListItem("select...", "0")); } //bind filter multi select HtmlGenericControl lblFilter = (HtmlGenericControl)pnlConfFilter.FindControl("lblFilterConfDD" + count); ListBox lbFilter = (ListBox)pnlConfFilter.FindControl("colFilterConfDD" + count); if (lblFilter != null && lbFilter != null) { lblFilter.InnerText = cat.lookupCategory.Replace("Confidential Note ", ""); lbFilter.DataSource = items; lbFilter.DataTextField = "display"; lbFilter.DataValueField = "recId"; lbFilter.DataBind(); lbFilter.Items.Add(new ListItem("(blank)", "(blank)")); } } } divConfDD2.Visible = false; } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void CustomBindConfidentialFilters(bool retainSelections) { try { if (handler.ReturnSetup().code == "STUD-1") { //get selected checkbox items bool yes = false; if (colFilterConfConfidential.Items.FindByValue("Yes") != null && colFilterConfConfidential.Items.FindByValue("Yes").Selected) yes = true; bool no = false; if (colFilterConfConfidential.Items.FindByValue("No") != null && colFilterConfConfidential.Items.FindByValue("No").Selected) no = true; string chkDyn = ""; if (ViewState["ChkValues"] != null) chkDyn = ViewState["ChkValues"].ToString(); colFilterConfConfidential.Items.Clear(); if (chkDyn == "" || chkDyn.Contains("Yes")) colFilterConfConfidential.Items.Add(new ListItem("Yes", "Yes")); if (chkDyn == "" || chkDyn.Contains("No")) colFilterConfConfidential.Items.Add(new ListItem("No", "No")); if (retainSelections) { if (yes && colFilterConfConfidential.Items.FindByValue("Yes") != null) colFilterConfConfidential.Items.FindByValue("Yes").Selected = true; if (no && colFilterConfConfidential.Items.FindByValue("No") != null) colFilterConfConfidential.Items.FindByValue("No").Selected = true; } int count = 0; foreach (oSurfaceLookupCategory cat in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookupCategory), "isActive", "1")) { if (cat.lookupCategory.StartsWith("Confidential Note")) { count++; //bind filter multi select HtmlGenericControl lblFilter = (HtmlGenericControl)pnlConfFilter.FindControl("lblFilterConfDD" + count); ListBox lbFilter = (ListBox)pnlConfFilter.FindControl("colFilterConfDD" + count); if (lblFilter != null && lbFilter != null) { ArrayList items = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceLookup), "isActive,categoryId", "1," + cat.recId); string ddDyn = ""; if (ViewState["DD" + count + "Values"] != null) { ddDyn = ViewState["DD" + count + "Values"].ToString(); } if (ddDyn != "") { for (int i = items.Count - 1; i >= 0; i--) { oSurfaceLookup l = (oSurfaceLookup)items[i]; if (!ddDyn.StartsWith(l.recId + ",") && !ddDyn.Contains("," + l.recId + ",")) items.Remove(l); } } //get list of selected items to reapply if selections need to be retained int[] indices = lbFilter.GetSelectedIndices(); string[] selections = new string[indices.Count()]; if (retainSelections) { //replace index with value, rebinding list so indices might change for (int i = 0; i < indices.Count(); i++) { selections[i] = lbFilter.Items[indices[i]].Value; } } lblFilter.InnerText = cat.lookupCategory.Replace("Confidential Note ", ""); lbFilter.DataSource = items; lbFilter.DataTextField = "display"; lbFilter.DataValueField = "recId"; lbFilter.DataBind(); if (ddDyn.StartsWith(",") || ddDyn.Contains(",,")) lbFilter.Items.Add(new ListItem("(blank)", "(blank)")); if (retainSelections) { foreach (string selected in selections) { if (lbFilter.Items.FindByValue(selected) != null) lbFilter.Items.FindByValue(selected).Selected = true; } } } } } } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void CustomSaveConfidential(ref oNote note) { try { if (handler.ReturnSetup().code == "STUD-1") { //confidential 0/1 ~|~ date yyyy-MM-dd ~|~ dd1 lookupId ~|~ dd2 lookupId //1~|~2017-05-31~|~115~|~232 string confidential = "0"; DateTime date = System.DateTime.Now; string dd = ""; //date if (!DateTime.TryParse(txtConfNoteDate.Value, out date)) date = System.DateTime.Now; //confidential if (chkConfConfidential.Checked) confidential = "1"; //dropdowns if (ddConfDD1.SelectedItem != null) dd = ddConfDD1.SelectedItem.Value.ToString(); else dd = "0"; if (ddConfDD2.SelectedItem != null) { dd += "~|~" + ddConfDD2.SelectedItem.Value; //CVH 2017-06-07 When Psychosocial is selected, must always be confidential if (ddConfDD2.SelectedItem.Text == "Psychosocial") confidential = "1"; } else dd += "~|~0"; note.customValue = confidential + "~|~" + date.ToString("yyyy-MM-dd") + "~|~" + dd; } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } private void CustomPopulateConfidential(oNote note) { try { string custom = note.customValue; if (handler.ReturnSetup().code == "STUD-1") { //confidential 0/1 ~|~ date yyyy-MM-dd ~|~ dd1 lookupId ~|~ dd2 lookupId //1~|~2017-05-31~|~115~|~232 //confidential chkConfConfidential.Checked = false; if (custom.IndexOf("~|~") >= 0) { if (custom.Substring(0, custom.IndexOf("~|~")) == "1") chkConfConfidential.Checked = true; custom = custom.Substring(custom.IndexOf("~|~") + 3); } //date txtConfNoteDate.Value = note.dateSaved.ToString("dd/MM/yyyy"); if (custom.IndexOf("~|~") >= 0) { string dt = custom.Substring(0, custom.IndexOf("~|~")); DateTime dtDate = new DateTime(); if (DateTime.TryParse(dt, out dtDate)) txtConfNoteDate.Value = dtDate.ToString("dd/MM/yyyy"); custom = custom.Substring(custom.IndexOf("~|~") + 3); } //dropdown1 ddConfDD1.ClearSelection(); if (custom.IndexOf("~|~") >= 0) { string dd1 = custom.Substring(0, custom.IndexOf("~|~")); if (ddConfDD1.Items.FindByValue(dd1) != null) ddConfDD1.Items.FindByValue(dd1).Selected = true; custom = custom.Substring(custom.IndexOf("~|~") + 3); } //dropdown2 ddConfDD2.ClearSelection(); if (custom.IndexOf("~|~") >= 0) { string dd2 = custom.Substring(0, custom.IndexOf("~|~")); if (ddConfDD2.Items.FindByValue(dd2) != null) ddConfDD2.Items.FindByValue(dd2).Selected = true; custom = custom.Substring(custom.IndexOf("~|~") + 3); } else if (ddConfDD2.Items.FindByValue(custom) != null) ddConfDD2.Items.FindByValue(custom).Selected = true; } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Save Control Data /// /// public void SaveControlData(ref oSurfaceFieldData _surfaceFieldData) { } /// /// Populate surface note /// private void PopulateSurfaceNote() { try { foreach (oNote note in xData.GetTypedByCriteriaSpecific("recId", typeof(oNote), "recId", NoteId.ToString())) { //radSurfaceNote.Content = note.caption; EditorContent = note.caption; if (note.typeId == pNums.NoteType.Confidential.GetHashCode()) CustomPopulateConfidential(note); BindAttachments(note.recId, divSurfaceNoteFiles); } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// BaindAttachments /// /// /// private void BindAttachments(int recId, HtmlGenericControl filesDiv) { try { StringBuilder formBuilder = new StringBuilder(); //get all attachments linked to note //bool firstAttachment = true; //foreach (oAttachment att in xData.GetTypedByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId", (int)pNums.Module.Notes + "," + recId.ToString(), "", "pal_")) //{ // if (firstAttachment) // { // formBuilder.AppendLine("
"); // firstAttachment = false; // } // string fileLocation = ""; // if (att.typeId == (int)pNums.AttachmentType.Document) // fileLocation = att.sourcePath + "/upload/" + att.folderName + "/file/" + att.fileName; // else // fileLocation = att.sourcePath + "/upload/" + att.folderName + "/image/" + att.fileName; // string hyperlink = "  " + att.display + "
"; // formBuilder.Append("
" + hyperlink + "
"); //} //CVH 2017-05-24 Arraylist always blank, datatable works fine //ArrayList files = xData.GetTypedByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId", (int)pNums.Module.Notes + "," + recId.ToString(), ""); DataTable dtFiles = xData.GetDynamicByCriteriaSpecific("recId", typeof(oAttachment), "moduleId,entityId", (int)pNums.Module.Notes + "," + recId.ToString()); if (dtFiles != null && dtFiles.Rows.Count > 0) { formBuilder.AppendLine("
"); foreach (DataRow row in dtFiles.Rows) { string user = ""; foreach (ovUserShared usr in xData.GetTypedByCriteriaSpecific("recId", typeof(ovUserShared), "recId", row["userIdSaved"].ToString())) { user = usr.name; break; } string details = "(" + user + " - " + utils.fixDate(row["dateSaved"].ToString()) + ")"; string fileLocation = ""; string pathLocation = ""; string hyperlink = ""; if (row["typeId"].ToString() == pNums.AttachmentType.Document.GetHashCode().ToString()) { fileLocation = Server.MapPath("/upload/" + row["folderName"].ToString() + "/file/" + row["fileName"].ToString()); pathLocation = row["sourcePath"].ToString() + "/upload/" + row["folderName"].ToString() + "/file/" + row["fileName"].ToString(); if (!File.Exists(fileLocation)) { fileLocation = fileLocation.Replace("/file", ""); pathLocation = pathLocation.Replace("/file", ""); } hyperlink = "" + row["display"].ToString() + ""; } else { fileLocation = Server.MapPath("/upload/" + row["folderName"].ToString() + "/image/" + row["fileName"].ToString()); pathLocation = row["sourcePath"].ToString() + "/upload/" + row["folderName"].ToString() + "/image/" + row["fileName"].ToString(); hyperlink = "" + row["display"].ToString() + ""; } formBuilder.AppendLine(hyperlink); } formBuilder.AppendLine("
"); } filesDiv.InnerHtml = formBuilder.ToString(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Get File typeImage /// /// /// private string GetFileTypeImage(string fileLocation) { string imgSrc = "/images/doc.png"; try { string uri = String.Empty; if (fileLocation.Contains("http")) uri = fileLocation; else uri = Server.MapPath(fileLocation); Icon icon = Icon.ExtractAssociatedIcon(uri); if (icon != null) { System.Drawing.Image img = icon.ToBitmap(); byte[] byteArray = new byte[0]; using (MemoryStream stream = new MemoryStream()) { img.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); byteArray = stream.ToArray(); } string base64 = Convert.ToBase64String(byteArray); imgSrc = String.Format("data:image/png;base64,{0}", base64); } } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); //CVH 2017-08-31 Don't show error page, keep loading Notes with missing attachment //Response.Redirect("/error", false); } return imgSrc; } /// /// BindNotes /// private void BindNotes() { //CVH 2017-05-05 Don't bind notes if surface item is 0, currently there are notes saved not linked to the surface item, shouldn't show those when adding a new surface item. Going forward notes will not be saved with a 0 item, we're bubbling to surface if (SurfaceItemId == 0 || SurfaceId == 0) return; // Pro-5 - Add Notes Category - DS - 5 June 2017 oSetup setup = handler.ReturnSetup(); if (setup.code == "PROP-1") { string customValue = ""; switch (SurfaceFieldId) { case 403: // Landlords - Default to Landlords when saving from Landlords Surface customValue = nameof(pNums.NoteCategory.Landlords); break; case 225: // Tenants - Default to Tenants when saving from Tenants Surface customValue = nameof(pNums.NoteCategory.Tenants); break; case 445: // LeaseManagement - Default to LeaseManagement when saving from LeaseManagement Surface customValue = nameof(pNums.NoteCategory.LeaseManagement); break; case 147: // Properties - If Properties, then check to see which category was selected // Do nothing - customValue = "" break; default: break; } if (!String.IsNullOrWhiteSpace(customValue)) {// Pro-5 CreatePropertyDetailObject(); CurrentPropertyDetail propDet = new CurrentPropertyDetail(); propDet = (CurrentPropertyDetail)ThisPropertyDetail; switch (customValue) { case "Landlords": customValue = $"{customValue}{(propDet == null ? "" : "_" + propDet.CurrentLandlordId.ToString())}"; break; case "Tenants": customValue = $"{customValue}{(propDet == null ? "" : "_" + propDet.CurrentTenantId.ToString())}"; break; case "LeaseManagement": customValue = $"{customValue}{(propDet == null ? "" : "_" + propDet.PropertyID.ToString())}"; break; default: break; } // If this is TPS, then we want to capture notes on one SurfaceNotes = xData.GetTypedByCriteriaSpecificTableTop("recId", typeof(ovNoteDetail), "typeId,isActive,customValue", $"1,1,{customValue}", "dateSaved DESC", RecordLimit, "pal_"); } else { // If we are not on any of the other surfaces (Landlords, Tenants or Lease Management), do the default bind SurfaceNotes = xData.GetTypedByCriteriaSpecificTableTop("recId", typeof(ovNoteDetail), "typeId,isActive,entityId,fieldName", "1,1," + SurfaceItemId.ToString() + "," + SurfaceFieldId.ToString() + "", "dateSaved DESC", RecordLimit, "pal_"); } } else { SurfaceNotes = xData.GetTypedByCriteriaSpecificTableTop("recId", typeof(ovNoteDetail), "typeId,isActive,entityId,fieldName", "1,1," + SurfaceItemId.ToString() + "," + SurfaceFieldId.ToString() + "", "dateSaved DESC", RecordLimit, "pal_"); } //CVH 2017-06-01 Note Type Confidential if (this.Confidential) { oUser usr = new oUser(); if (utils.verifySession("user")) usr = (oUser)Session["user"]; DataTable temp = xData.GetTypedByCriteriaSpecificTableTop("recId", typeof(ovNoteDetail), "typeId,isActive,entityId,fieldName", pNums.NoteType.Confidential.GetHashCode() + ",1," + SurfaceItemId.ToString() + "," + SurfaceFieldId.ToString() + "", "dateSaved DESC", RecordLimit, "pal_"); if (usr.recId == this.ConfidentialUser || temp.Rows.Count == 0) { SurfaceNotes = temp.Copy(); } else { DataRow[] rows = temp.Select(" userIdSaved = " + usr.recId + " OR customValue LIKE '0*' "); if (rows.Count() > 0) SurfaceNotes = rows.CopyToDataTable(); else SurfaceNotes = temp.Clone(); } } else SurfaceNotes = xData.GetTypedByCriteriaSpecificTableTop("recId", typeof(ovNoteDetail), "typeId,isActive,entityId,fieldName", "1,1," + SurfaceItemId.ToString() + "," + SurfaceFieldId.ToString() + "", "dateSaved DESC", RecordLimit, "pal_"); ViewState["ChkValues"] = ""; ViewState["DD1Values"] = ""; ViewState["DD2Values"] = ""; rptNotes.DataSource = SurfaceNotes; rptNotes.DataBind(); if (this.Confidential) CustomBindConfidentialFilters(true); upNotes.Update(); } /// /// Pro-5 /// /// private void CreatePropertyDetailObject() { int propertyID = SurfaceItemId; // Read the JSON Text from the database for this Surface ID //DataTable dtData = xData.GetDynamicByCriteriaSpecific("ID", typeof(propPropertyDetail), "propertyID", surfaceItemID.ToString(), "recId", "prop1_"); DataTable dtData = xData.GetCustomTypedTable($"SELECT [ID],[propertyID],[propertyName],[propertyLookupDetails] FROM [prop1_PropertyLookupDetails] WHERE propertyID = {propertyID}"); string jsonstring = dtData.TableIsValid() ? dtData.Rows[0]["propertyLookupDetails"].ToString() : ""; if (!String.IsNullOrWhiteSpace(jsonstring)) { CurrentPropertyDetail propDet = JsonConvert.DeserializeObject(jsonstring); ThisPropertyDetail = propDet; } } #endregion #region events /// /// Page Init /// /// /// protected void Page_Init(object sender, EventArgs e) { } /// /// Page Load /// /// /// protected void Page_Load(object sender, EventArgs e) { //BindNotes(); } /// /// add new note /// /// /// protected void btnNew_Click(object sender, EventArgs e) { try { //radSurfaceNote.Content = ""; EditorContent = ""; radUploadSurfaceNotes.UploadedFiles.Clear(); divSurfaceNoteFiles.InnerHtml = ""; NoteId = 0; //CVH 2017-05-05 Open surface group again. If it defaults to collapsed, it collapses when clicking add and then modal doesn't show until you manually expand the group again. string script = ""; if (SurfaceGroupId != "") script = "$('#" + SurfaceGroupId + "').collapse('show'); $('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal();"; else script = "$('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal();"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "mySurfaceNoteModal", script, true); } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// save note /// /// /// protected void btnSave_Click(object sender, EventArgs e) { try { oUser usr = new oUser(); if (utils.verifySession("user")) usr = (oUser)Session["user"]; #region Pro-5 - Notes Category // Pro-5 - Add Notes Category - DS - 5 June 2017 oSetup setup = handler.ReturnSetup(); string noteCategory = ""; if (setup.code == "PROP-1") { CurrentPropertyDetail thisProp = null; // (CurrentPropertyDetail)ThisPropertyDetail; //customValue = $"{customValue}{(propDet == null ? "" : "_" + propDet.CurrentLandlordId.ToString())}"; switch (SurfaceFieldId) { case 403: // Landlords - Default to Landlords when saving from Landlords Surface noteCategory = $"{nameof(pNums.NoteCategory.Landlords)}{(thisProp == null ? "" : "_" + thisProp.CurrentLandlordId.ToString())}"; break; case 225: // Tenants - Default to Tenants when saving from Tenants Surface noteCategory = $"{nameof(pNums.NoteCategory.Tenants)}{(thisProp == null ? "" : "_" + thisProp.CurrentTenantId.ToString())}"; break; case 445: // LeaseManagement - Default to LeaseManagement when saving from LeaseManagement Surface noteCategory = $"{nameof(pNums.NoteCategory.LeaseManagement)}{(thisProp == null ? "" : "_" + thisProp.PropertyID.ToString())}"; break; case 147: // Properties - If Properties, then check to see which category was selected int iNoteCategoryValue = ddlNoteCategory.SelectedValue.ToInt(); switch (iNoteCategoryValue) { case 1: noteCategory = $"{nameof(pNums.NoteCategory.Landlords)}_{(thisProp == null ? "" : "_" + thisProp.CurrentLandlordId.ToString())}"; break; case 2: noteCategory = $"{nameof(pNums.NoteCategory.Tenants)}_{(thisProp == null ? "" : "_" + thisProp.CurrentTenantId.ToString())}"; break; case 3: noteCategory = $"{nameof(pNums.NoteCategory.LeaseManagement)}_{(thisProp == null ? "" : "_" + thisProp.PropertyID.ToString())}"; break; default: noteCategory = nameof(pNums.NoteCategory.None); break; } break; default: break; } } #endregion if (NoteId == 0) { if (SurfaceItemId == 0) { if (SurfaceId == 0) return; oSurfaceItem newItem = new oSurfaceItem(); newItem.createdBy = usr.recId; newItem.dateCreated = DateTime.Now; newItem.isActive = true; //setting item as true, otherwise it could be confusing if item doesn't show in list newItem.isDeleted = false; newItem.surfaceId = SurfaceId; newItem.recId = xData.SaveTyped("recId", typeof(oSurfaceItem), newItem); SurfaceItemId = newItem.recId; CommandEventArgs args = new CommandEventArgs("SaveParentSurfaceItem", newItem.recId); RaiseBubbleEvent(null, args); } oNote note = new oNote(); note.moduleId = pNums.Module.Surface.GetHashCode(); note.entityId = SurfaceItemId; note.title = "Surface Item Note"; note.isActive = true; //note.caption = radSurfaceNote.Content; note.caption = EditorContent; note.dateSaved = DateTime.Now; note.userIdSaved = usr.recId; note.fieldName = SurfaceFieldId.ToString(); #region Pro-5 - Notes Category // Pro-5 - Add Notes Category - DS - 5 June 2017 note.customValue = noteCategory; #endregion if (this.Confidential) { note.typeId = pNums.NoteType.Confidential.GetHashCode(); CustomSaveConfidential(ref note); } else { note.typeId = pNums.NoteType.General.GetHashCode(); } NoteId = xData.SaveTyped("recId", typeof(oNote), note); } else { oNote updateNote = new oNote(); foreach (oNote note in xData.GetTypedByCriteriaSpecific("recId", typeof(oNote), "recId", NoteId.ToString())) { //note.caption = radSurfaceNote.Content; note.caption = EditorContent; note.dateUpdated = DateTime.Now; note.userIdUpdated = usr.recId; #region Pro-5 - Notes Category // Pro-5 - Add Notes Category - DS - 5 June 2017 note.customValue = noteCategory; #endregion xData.UpdateTyped("recId", NoteId.ToString(), typeof(oNote), note); updateNote = note; break; } if (updateNote.recId > 0) { updateNote.caption = radSurfaceNote.Content; updateNote.dateUpdated = DateTime.Now; updateNote.userIdUpdated = usr.recId; if (updateNote.typeId == pNums.NoteType.Confidential.GetHashCode()) CustomSaveConfidential(ref updateNote); xData.UpdateTyped("recId", NoteId.ToString(), typeof(oNote), updateNote); } } if (Attachment != null && Attachment.entityId == 0) { Attachment.entityId = NoteId; xData.UpdateTyped("recId", Attachment.recId.ToString(), typeof(oAttachment), Attachment); } BindNotes(); //CVH 2017-05-05 Open surface group again. If it defaults to collapsed, it collapses when clicking add and then modal doesn't show until you manually expand the group again. string script = ""; if (SurfaceGroupId != "") script = "$('#" + SurfaceGroupId + "').collapse('show'); TaskFileUploadCancel(); $('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal('hide');$(document.body).removeClass('modal-open');"; else script = "TaskFileUploadCancel(); $('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal('hide');$(document.body).removeClass('modal-open');"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "mySurfaceNoteModalClose", script, true); } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } protected void btnCancelSurfaceNote_Click(object sender, EventArgs e) { try { string script = "TaskFileUploadCancel(); $('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal('hide');$(document.body).removeClass('modal-open');"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "mySurfaceNoteModalClose", script, true); } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// edit item /// /// /// protected void lnkEdit_Click(object sender, EventArgs e) { try { if (sender.GetType() == typeof(LinkButton)) { LinkButton lnkButton = (LinkButton)sender; NoteId = int.Parse(((LinkButton)sender).CommandArgument); PopulateSurfaceNote(); //CVH 2017-05-05 Open surface group again. If it defaults to collapsed, it collapses when clicking add and then modal doesn't show until you manually expand the group again. string script = ""; if (SurfaceGroupId != "") script = "$('#" + SurfaceGroupId + "').collapse('show'); $('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal();"; else script = "$('#" + pnlModal.ClientID + "').closest('div').find('.modSurfaceNote').modal();"; ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "mySurfaceNoteModal", script, true); //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "mySurfaceNoteModal", "$('.modSurfaceNote').modal();", true); } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Note Item Data Bound /// /// /// protected void rptNotes_ItemDataBound(object sender, RepeaterItemEventArgs e) { try { if (e.Item.ItemIndex != -1) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Label lblNoteId = (Label)e.Item.FindControl("lblNoteId"); Label lblEditUser = (Label)e.Item.FindControl("lblEditUser"); Label lblNoteHeaderEdit = (Label)e.Item.FindControl("lblNoteHeaderEdit"); if (lblEditUser.Text.Length > 0) lblNoteHeaderEdit.Visible = true; int noteId = Convert.ToInt32(lblNoteId.Text); HtmlGenericControl divSurfaceNoteFiles = (HtmlGenericControl)e.Item.FindControl("divSurfaceNoteFiles"); BindAttachments(noteId, divSurfaceNoteFiles); if (this.Confidential) { if (handler.ReturnSetup().code == "STUD-1") { //CVH 2017-06-07 Need to split custom value in Confidential checkbox, date, dropdowns x2 //Also need to apply dynamic filtering. So build selected values into ViewState parameter, to be used when binding the filters HtmlGenericControl divConfidentialItem = (HtmlGenericControl)e.Item.FindControl("divConfidentialItem"); if (divConfidentialItem != null) { divConfidentialItem.Visible = true; StringBuilder formbuilder = new StringBuilder(); string custom = divConfidentialItem.InnerText; //confidential string confidential = "No"; string confDyn = ""; if (custom.IndexOf("~|~") >= 0) { if (custom.Substring(0, custom.IndexOf("~|~")) == "1") { confidential = "Yes"; confDyn = "Yes,"; } else confDyn = "No,"; custom = custom.Substring(custom.IndexOf("~|~") + 3); } //date string date = ""; if (custom.IndexOf("~|~") >= 0) { string dt = custom.Substring(0, custom.IndexOf("~|~")); DateTime dtDate = new DateTime(); if (DateTime.TryParse(dt, out dtDate)) date = dtDate.ToString("dd/MM/yyyy"); custom = custom.Substring(custom.IndexOf("~|~") + 3); } //dropdown1 string dd1 = ""; string dd1Dyn = ""; if (custom.IndexOf("~|~") >= 0) { if (ddConfDD1.Items.FindByValue(custom.Substring(0, custom.IndexOf("~|~"))) != null) { dd1 = ddConfDD1.Items.FindByValue(custom.Substring(0, custom.IndexOf("~|~"))).Text; dd1Dyn = custom.Substring(0, custom.IndexOf("~|~")) + ","; } else dd1Dyn = ","; custom = custom.Substring(custom.IndexOf("~|~") + 3); } else dd1Dyn = ","; //dropdown2 string dd2 = ""; string dd2Dyn = ""; if (custom.IndexOf("~|~") >= 0) { if (ddConfDD2.Items.FindByValue(custom.Substring(0, custom.IndexOf("~|~"))) != null) { dd2 = ddConfDD2.Items.FindByValue(custom.Substring(0, custom.IndexOf("~|~"))).Text; dd2Dyn = custom.Substring(0, custom.IndexOf("~|~")) + ","; } else dd2Dyn = ","; custom = custom.Substring(custom.IndexOf("~|~") + 3); } else if (ddConfDD2.Items.FindByValue(custom) != null) { if (ddConfDD2.Items.FindByValue(custom) != null) { dd2 = ddConfDD2.Items.FindByValue(custom).Text; dd2Dyn = custom + ","; } else dd2Dyn = ","; } else dd2Dyn = ","; //apply filter bool applyFilter = false; bool dd1Visible = false, dd2Visible = false, chkVisible = false; int[] indicesDD1 = colFilterConfDD1.GetSelectedIndices(); int[] indicesDD2 = colFilterConfDD2.GetSelectedIndices(); int[] indicesChk = colFilterConfConfidential.GetSelectedIndices(); if (indicesDD1.Length > 0 || indicesDD2.Length > 0 || indicesChk.Length > 0) { applyFilter = true; if (indicesDD1.Length > 0) { for (int i = 0; i < indicesDD1.Count(); i++) { string text = colFilterConfDD1.Items[indicesDD1[i]].Text; if (text == "(blank)") text = ""; if (text == dd1) { dd1Visible = true; break; } } } else dd1Visible = true; if (indicesDD2.Length > 0) { for (int i = 0; i < indicesDD2.Count(); i++) { string text = colFilterConfDD2.Items[indicesDD2[i]].Text; if (text == "(blank)") text = ""; if (text == dd2) { dd2Visible = true; break; } } } else dd2Visible = true; if (indicesChk.Length > 0) { for (int i = 0; i < indicesChk.Count(); i++) { string text = colFilterConfConfidential.Items[indicesChk[i]].Text; if (text == confidential) { chkVisible = true; break; } } } else chkVisible = true; } bool visible = dd1Visible && dd2Visible && chkVisible; if (applyFilter && !visible) { e.Item.Visible = false; } else { ViewState["ChkValues"] = ViewState["ChkValues"].ToString() + confDyn; ViewState["DD1Values"] = ViewState["DD1Values"].ToString() + dd1Dyn; ViewState["DD2Values"] = ViewState["DD2Values"].ToString() + dd2Dyn; formbuilder.AppendLine("
" + date + "
"); formbuilder.AppendLine("
" + dd1 + "
"); //formbuilder.AppendLine("
" + dd2 + "
"); formbuilder.AppendLine("
" + confidential + "
"); formbuilder.AppendLine("
"); divConfidentialItem.InnerHtml = formbuilder.ToString(); } } } } } } } catch (Exception ex) { exception.HandleException("notes:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// fil uploaded /// /// /// protected void radUploadSurfaceNotes_FileUploaded(object sender, FileUploadedEventArgs e) { Attachment = new oAttachment(); try { oUser user = new oUser(); if (utils.verifySession("user")) user = (oUser)Session["user"]; else { ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "userAlert", "alert('No user login detected. Operation aborted.');", true); return; } Attachment.entityId = NoteId; //Attachment.fieldName = hfFieldNameNote.Value; Attachment.moduleId = (int)pNums.Module.Notes; Attachment.isActive = true; Attachment.typeId = e.File.ContentType.StartsWith("image") ? (int)pNums.AttachmentType.Image : (int)pNums.AttachmentType.Document; string taskFolderName = "surface/"; taskFolderName += SurfaceItemId.ToString(); Attachment.folderName = taskFolderName; /* CVH 2016-04-15 Add date and user */ int userId = user.recId; Attachment.userIdSaved = userId; Attachment.dateSaved = DateTime.Now; Attachment.display = e.File.FileName.Remove(e.File.FileName.LastIndexOf(".")); Attachment.fileName = Attachment.entityId + "_" + utils.RandomString(9, true) + e.File.FileName.Substring(e.File.FileName.LastIndexOf(".")); string imagePath = Server.MapPath("~/upload/" + Attachment.folderName + "/image/"); string thumbPath = Server.MapPath("~/upload/" + Attachment.folderName + "/thumb/"); string tempPath = Server.MapPath("~/upload/" + Attachment.folderName + "/temp/"); string filePath = Server.MapPath("~/upload/" + Attachment.folderName + "/file/"); utils.validateFolder(imagePath); utils.validateFolder(thumbPath); utils.validateFolder(tempPath); utils.validateFolder(filePath); Attachment.sourcePath = ConfigurationManager.AppSettings["WebAddy"]; if (Attachment.typeId == pNums.AttachmentType.Image.GetHashCode()) { //upload file e.File.SaveAs(tempPath + Attachment.fileName); //resize and compress utils.ResizeImage(tempPath + Attachment.fileName, imagePath, Attachment.fileName, 400, true); //resize and crop utils.ResizeCropImagePrecise(imagePath + Attachment.fileName, thumbPath, Attachment.fileName, 383, 264, false); } else { //upload file e.File.SaveAs(filePath + Attachment.fileName); } Attachment.recId = xData.SaveTyped("recId", typeof(oAttachment), Attachment); } catch (Exception ex) { exception.HandleException("surface:", MethodBase.GetCurrentMethod().Name, ex, Session["attachment"]); Response.Redirect("/error", false); } } /// /// Apply Filter /// /// /// protected void lnkApplyFilter_Click(object sender, EventArgs e) { try { BindNotes(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Remove Filter /// /// /// protected void lnkRemoveFilter_Click(object sender, EventArgs e) { try { CustomBindConfidentialFilters(false); BindNotes(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Refresh Filter /// /// /// protected void lnkRefreshFilter_Click(object sender, EventArgs e) { try { CustomBindConfidentialFilters(true); BindNotes(); } catch (Exception ex) { exception.HandleException("Task:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region properties public string EditorContent { get { if (isiPhone()) { return txtSurfaceNote.Text; } else { return radSurfaceNote.Content; } } set { if (isiPhone()) { txtSurfaceNote.Text = value; } else { radSurfaceNote.Content = value; } } } private bool isiPhone() { string userAgent = Request.Headers["User-Agent"]; if (!string.IsNullOrEmpty(userAgent)) { return userAgent.ToLowerInvariant().Contains("iphone") || userAgent.ToLowerInvariant().Contains("ipad"); } else { return false; } } private void SetControlsVisibility() { txtSurfaceNote.Visible = isiPhone(); radSurfaceNote.Visible = !isiPhone(); } /// /// MPL getter and setter /// private DataTable SurfaceNotes { get { if (ViewState["surfaceNotes"] != null) { return (DataTable)ViewState["surfaceNotes"]; } else { return null; } } set { ViewState["surfaceNotes"] = value; } } private int SurfaceItemId { get { if (ViewState["noteSurfaceItemId"] != null) return (int)ViewState["noteSurfaceItemId"]; else return 0; } set { ViewState["noteSurfaceItemId"] = value; } } private int SurfaceFieldId { get { if (ViewState["noteSurfaceFieldId"] != null) return Convert.ToInt32(ViewState["noteSurfaceFieldId"]); else return 0; } set { ViewState["noteSurfaceFieldId"] = value; } } private int SurfaceId { get { if (ViewState["noteSurfaceId"] != null) return Convert.ToInt32(ViewState["noteSurfaceId"]); else return 0; } set { ViewState["noteSurfaceId"] = value; } } private int NoteId { get { if (ViewState["noteId"] != null) return (int)ViewState["noteId"]; else return 0; } set { ViewState["noteId"] = value; } } private int RecordLimit { get { if (ViewState["recordLimit"] == null) return 0; else return (int)ViewState["recordLimit"]; } set { ViewState["recordLimit"] = value; } } private oAttachment Attachment { get { if (ViewState["attachment"] != null) return (oAttachment)ViewState["attachment"]; else return null; } set { ViewState["attachment"] = value; } } public string SurfaceGroupId { get { if (ViewState["surfaceGroupId"] != null) return ViewState["surfaceGroupId"].ToString(); else return null; } set { ViewState["surfaceGroupId"] = value; } } #region Pro-5 - Property Details public CurrentPropertyDetail ThisPropertyDetail { get { return (CurrentPropertyDetail)ViewState["thisPropertyDetail"]; } set { ViewState["thisPropertyDetail"] = value; } } #endregion public bool Confidential { get { if (ViewState["confidential"] != null) return bool.Parse(ViewState["confidential"].ToString()); else return false; } set { ViewState["confidential"] = value; } } private int ConfidentialUser { get { if (ViewState["confidentialUser"] != null) return (int)ViewState["confidentialUser"]; else return 0; } set { ViewState["confidentialUser"] = value; } } #endregion } [Serializable] public class CurrentPropertyDetail { public int PropertyID { get; set; } public int CurrentLandlordId { get; set; } = -1; public string CurrentLandlordName { get; set; } = ""; public int CurrentTenantId { get; set; } = -1; public string CurrentTenantName { get; set; } = ""; public int CurrentAgentId { get; set; } = -1; public string CurrentAgentName { get; set; } = ""; }