using DataTables; using framework_business; using framework_library; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.IO; using System.Reflection; using System.Text; using System.Web; using System.Web.Hosting; using System.Web.Script.Services; using System.Web.Services; using System.Web.UI; public partial class Canvas : System.Web.UI.Page { private const string controlPath = "~/controls/"; private const string modulePath = "~/controls/module/"; private const string surfacePath = "~/controls/surface/"; private const string surfacePathCustom = "~/controls/surface_custom/"; private const string compositePath = "~/controls/composite/"; private const string taskImagePath = "~/upload/tasks/"; #region Properties public int CanvasId { get { if (ViewState["canvasId"] == null) return 0; else return (int)ViewState["canvasId"]; } set { ViewState["canvasId"] = value; } } public string ActiveApp { get { if (ViewState["activeApp"] == null) return ""; else return (string)ViewState["activeApp"]; } set { ViewState["activeApp"] = value; } } public oSurfaceControlParcel ActiveParcel { get { if (ViewState["activeParcel"] == null) return null; else return (oSurfaceControlParcel)ViewState["activeParcel"]; } set { ViewState["activeParcel"] = value; } } #endregion #region methods /// /// Load Active Canvas Control /// /// /// REVISION 001: Instead of using Session for surface app, use instance variable with property /// AUTHOR: Charlene van Heerden /// DATE MODIFIED: 14 December 2015 /// private void LoadActiveCanvasControl(bool isPostback) { string canvasName = handler.GetRoutedData("canvas-title"); if (canvasName == "overlay") { pnlCanvas.Visible = false; pnlSurface.Visible = false; pnlComposite.Visible = false; pnlTaskOverlay.Visible = true; int canvasId = 0; if (Session["overlayCanvasId"] != null) canvasId = int.Parse(Session["overlayCanvasId"].ToString()); string snapshotName = ""; if (Session["overlaySnapshotName"] != null) snapshotName = Session["overlaySnapshotName"].ToString(); divAddTask.Visible = false; divBreak.Visible = true; plcCanvasTask.Controls.Clear(); controls_module_taskOverlay uc = (controls_module_taskOverlay)LoadControl(modulePath + "taskOverlay.ascx"); uc.CanvasId = canvasId; uc.SnapshotName = snapshotName; plcCanvasTask.Controls.Add(uc); } else { oUser usr = new oUser(); if (utils.verifySession("user")) { usr = (oUser)Session["user"]; if (usr.userType == pNums.UserType.AdminUser.GetHashCode() || usr.userType == pNums.UserType.SuperUser.GetHashCode()) { ArrayList list = xData.GetTypedByCriteriaBegins("recId", typeof(oModule), "module", "Tasks"); if (list != null && list.Count > 0) { oModule mod = (oModule)list[0]; if (mod.isActive) { divAddTask.Visible = true; divBreak.Visible = false; } } } } ArrayList canvasPages = xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvas), "name", canvasName); foreach (oCanvas canvas in canvasPages) { if (handler.validateCanvas(canvas)) { //hide the panel around the canvas content if (!canvas.isPanelShown) { //hide heading divCanvas.Attributes.Remove("class"); divCanvanHeading.Attributes.Remove("class"); divCanvasBody.Attributes.Remove("class"); lblCanvasHeading.Visible = false; divCanvas.Attributes.Add("class", "canvasPanel"); divCanvanHeading.Attributes.Add("class", "text-center canvasHeading"); } if (canvas.hideNavigation) { Master.FindControl("navDivTop").Visible = false; Master.FindControl("navDivBottom").Visible = false; } if (canvas.isComposite) { pnlCanvas.Visible = false; pnlSurface.Visible = false; pnlComposite.Visible = true; pnlTaskOverlay.Visible = false; foreach (oComposite composite in xData.GetTypedByCriteriaSpecific("recId", typeof(oComposite), "canvasId", canvas.recId.ToString())) { if (!File.Exists(Server.MapPath(surfacePath + composite.name + ".ascx.cs"))) { compositeHandler.BuildCompositeTemplate(composite, compositePath + "composite.ascx", compositePath, true); } plcComposite.Controls.Clear(); ICompositeBase uc = (ICompositeBase)LoadControl(compositePath + composite.name + ".ascx"); uc.CompositeCanvas = composite; plcComposite.Controls.Add(uc); break; } } else { foreach (oCanvasMetaData met in xData.GetTypedByCriteriaSpecific("recId", typeof(oCanvasMetaData), "canvasId", canvas.recId.ToString())) { foreach (oModule mod in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", met.moduleId.ToString())) { if (mod.control != String.Empty) { this.CanvasId = met.canvasId; if (met.moduleId == pNums.Module.Surface.GetHashCode()) { pnlCanvas.Visible = false; pnlSurface.Visible = true; pnlComposite.Visible = false; pnlTaskOverlay.Visible = false; pnlPromotion.Visible = false; //get surface app foreach (oSurface surfApp in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "recId", met.entityId.ToString())) { //GR Added for default to from inherited from Canvas if (canvas.isDefaultToForm) { surfApp.isDefaultToForm = canvas.isDefaultToForm; } //create surface app if it does not exist if (!File.Exists(Server.MapPath(surfacePath + surfApp.name + "_form.ascx"))) { surfaceHandler.BuildSurfaceAppTemplate(surfApp, controlPath + mod.control, surfacePath, true); } //load the surface app control plcSurface.Controls.Clear(); ISurfaceBase uc; string AppName = surfApp.name; //CVH 2017-08-22 Setting "Active Surface". Need to check if active surface is Published, not "surfApp", otherwise it checks the parent.isPublished, and not the active childSurface.isPublished, and never uses published control oSurface activeSurface = surfApp; //if (utils.verifySession("SurfaceControlParcel")) //{ // ActiveParcel = (oSurfaceControlParcel)Session["SurfaceControlParcel"]; //} if (utils.verifySession("childAppName")) { AppName = Session["childAppName"].ToString(); utils.disposeSession("childAppName"); ActiveApp = AppName; foreach (oSurface childSurf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", AppName)) { activeSurface = childSurf; break; } } else if (ActiveApp != String.Empty) { AppName = ActiveApp; //if (ActiveParcel != null) // Session["SurfaceControlParcel"] = ActiveParcel; foreach (oSurface childSurf in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurface), "name", AppName)) { activeSurface = childSurf; break; } } //uc = (ISurfaceBase)LoadControl(surfacePath + surfApp.name + ".ascx"); //CVH 2017-05-04 //CVH 2018-07-24 If it's a public user accessing a surface, don't default to form, this is really only for patients logging in and viewing patient profile if (handler.ReturnSetup().code == "SHOU-1" && usr.userType < (int)pNums.UserType.PowerUser && usr.userType != 0) { oSurfaceControlParcel parcel = new oSurfaceControlParcel(); parcel.SurfaceApp = surfApp; oSurfaceItem patientItem = new oSurfaceItem(); foreach (oSurfaceItem userItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceItem), "surfaceId,isActive,createdBy", surfApp.recId + ",1," + usr.recId, "dateCreated Desc")) { patientItem = userItem; break; } parcel.SurfaceAppItem = patientItem; ActiveParcel = parcel; Session["SurfaceControlParcel"] = parcel; uc = (ISurfaceBase)LoadControl(surfacePath + AppName + "_form.ascx"); } else { string surfaceDynamicPath = surfacePath; //CVH 2017-08-22 surfApp is always the parent app, so not checking the actual surface it needs to check. Use new activeSurface instead //if (surfApp.isPublished) if (activeSurface.isPublished) { if (Request.QueryString["mode"] != null && Request.QueryString["mode"] != String.Empty) { if (Request.QueryString["mode"] == "form") { if (File.Exists(Server.MapPath(surfacePathCustom + AppName + "_form.ascx"))) surfaceDynamicPath = surfacePathCustom; } else if (Request.QueryString["mode"] == "view") { if (File.Exists(Server.MapPath(surfacePathCustom + AppName + "_view.ascx"))) surfaceDynamicPath = surfacePathCustom; } else { if (File.Exists(Server.MapPath(surfacePathCustom + AppName + "_grid.ascx"))) surfaceDynamicPath = surfacePathCustom; } } else { if (File.Exists(Server.MapPath(surfacePathCustom + AppName + "_grid.ascx"))) surfaceDynamicPath = surfacePathCustom; } } //to enable seperate controls if (Request.QueryString["mode"] != null && Request.QueryString["mode"] != String.Empty) { if (Request.QueryString["mode"] == "form") uc = (ISurfaceBase)LoadControl(surfaceDynamicPath + AppName + "_form.ascx"); else if (Request.QueryString["mode"] == "view") uc = (ISurfaceBase)LoadControl(surfaceDynamicPath + AppName + "_view.ascx"); else uc = (ISurfaceBase)LoadControl(surfaceDynamicPath + AppName + "_grid.ascx"); } else { uc = (ISurfaceBase)LoadControl(surfaceDynamicPath + AppName + "_grid.ascx"); } } uc.SurfaceApp = surfApp; plcSurface.Controls.Add(uc); break; } } else if (met.moduleId == pNums.Module.Report.GetHashCode()) { pnlCanvas.Visible = true; pnlSurface.Visible = false; pnlComposite.Visible = false; pnlTaskOverlay.Visible = false; pnlPromotion.Visible = false; //get report foreach (oReport rpt in xData.GetTypedByCriteriaSpecific("recId", typeof(oReport), "recId", met.entityId.ToString())) { //load control plcCanvas.Controls.Clear(); dynamic uc = (IControlBase)LoadControl(controlPath + mod.control); uc.Report = rpt; plcCanvas.Controls.Add(uc); break; } } else if (met.moduleId == pNums.Module.Task.GetHashCode()) { divAddTask.Visible = false; divBreak.Visible = true; plcCanvas.Controls.Clear(); UserControl uc = (UserControl)LoadControl(controlPath + mod.control); plcCanvas.Controls.Add(uc); break; } else if (met.moduleId == pNums.Module.CompanySetup.GetHashCode()) { string setupView = handler.GetRoutedData("setup-view"); lblCanvasHeading.Text = canvas.display; pnlCanvas.Visible = true; pnlSurface.Visible = false; pnlComposite.Visible = false; pnlTaskOverlay.Visible = false; pnlPromotion.Visible = false; plcCanvas.Controls.Clear(); dynamic uc = (UserControl)LoadControl(controlPath + mod.control); uc.ActivePanel = setupView; plcCanvas.Controls.Add(uc); break; } else { lblCanvasHeading.Text = canvas.display; pnlCanvas.Visible = true; pnlSurface.Visible = false; pnlComposite.Visible = false; pnlTaskOverlay.Visible = false; pnlPromotion.Visible = false; plcCanvas.Controls.Clear(); UserControl uc = (UserControl)LoadControl(controlPath + mod.control); plcCanvas.Controls.Add(uc); break; } } else if (met.moduleId == pNums.Module.Promotions.GetHashCode()) { pnlCanvas.Visible = false; pnlSurface.Visible = false; pnlComposite.Visible = false; pnlTaskOverlay.Visible = false; pnlPromotion.Visible = true; //get all active promotion for the day foreach (oPromotion promotion in xData.GetTypedByCriteriaSpecific("recId", typeof(oPromotion), "isActive,startDate,endDate", "1,~<=" + DateTime.Now.ToShortDateString() + ",~>=" + DateTime.Now.ToShortDateString(), "endDate")) { StringBuilder promotionBuilder = new StringBuilder(); promotionBuilder.AppendLine("
"); promotionBuilder.AppendLine("

" + promotion.caption + "

"); promotionBuilder.AppendLine("
"); if (promotion.layoutTypeId == pNums.LayoutType.Stack.GetHashCode()) { foreach (oPromotionFile promotionFile in xData.GetTypedByCriteriaSpecific("recId", typeof(oPromotionFile), "promotionId,isActive", promotion.recId.ToString() + ",1", "fileName")) { promotionBuilder.AppendLine("
"); promotionBuilder.AppendLine("
"); promotionBuilder.AppendLine(""); promotionBuilder.AppendLine("
"); promotionBuilder.AppendLine("
"); } } if (promotion.layoutTypeId == pNums.LayoutType.Tile.GetHashCode()) { int rowNum = 1; foreach (oPromotionFile promotionFile in xData.GetTypedByCriteriaSpecific("recId", typeof(oPromotionFile), "promotionId,isActive", promotion.recId.ToString() + ",1", "fileName")) { if (rowNum % 2 != 0) { promotionBuilder.AppendLine("
"); } promotionBuilder.AppendLine("
"); promotionBuilder.AppendLine(""); promotionBuilder.AppendLine("
"); if (rowNum % 2 == 0) { promotionBuilder.AppendLine("
"); } rowNum++; } } plcPromotion.Controls.Add(new LiteralControl(promotionBuilder.ToString())); } } } break; } } } else { Response.Redirect("/home", false); } } if (canvasPages.Count == 0) Response.Redirect("/home", false); } } #endregion #region events protected void Page_Init(object sender, EventArgs e) { //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "reloadViewstate", "location.reload();", true); } /// /// Page Load /// /// /// protected void Page_Load(object sender, EventArgs e) { LoadActiveCanvasControl(Page.IsPostBack); //btnAddTask.CssClass = "btn btn-warning top-right"; if (!Page.IsPostBack) { utils.validateFolder(Server.MapPath(taskImagePath)); //hide or show } } /// /// Hidden field to use in adding task javascript /// /// /// /// /// AUTHOR: Charlene van Heerden /// DATE WRITTEN: 25 February 2016 /// protected void btnAddTask_Click(object sender, EventArgs e) { try { //if a snapshot for current canvas exists, don't take new snapshot, first load existing int canvasId = this.CanvasId; if (canvasId == 0) { throw new Exception("CanvasId could not be determined."); } string snapshotName = "canvas" + canvasId + "_tmp" + System.DateTime.Now.ToString("yyyyMMddhhmmssff"); Session["overlaySnapshotName"] = snapshotName; Session["overlayCanvasId"] = canvasId; Session["overlaySnapshotId"] = 0; divCanvanHeading.Attributes.Remove("class"); divCanvanHeading.Attributes.Add("class", "canvasHeadingTask text-center canvasHeading"); //invoke javascript to take snapshot ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myCanvasSnap", "CaptureSnapshot('" + snapshotName + "');", true); } catch (Exception ex) { exception.HandleException("Canvas:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } /// /// Close Child App /// /// /// protected void btnCloseChildApp_Click(object sender, EventArgs e) { try { //reload child controls } catch (Exception ex) { exception.HandleException("Canvas:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region web methods [WebMethod] public static string LoadUserControl(string message) { string result = String.Empty; try { using (Page page = new Page()) { //page.MasterPageFile = "~/Core.master"; if (utils.verifySession("SurfaceControlParcel")) { //utils.ConvertStringtoHTMLFile("test", HttpContext.Current.Server.MapPath("~/upload/test.txt")); //set up params for the surface control oSurfaceControlParcel parcel = (oSurfaceControlParcel)HttpContext.Current.Session["SurfaceControlParcel"]; ISurfaceBase uc = (ISurfaceBase)page.LoadControl(parcel.ControlPath); uc.ID = parcel.ID; uc.SurfaceApp = parcel.SurfaceApp; uc.ParentSurfaceItemId = parcel.ParentSurfaceItemId; uc.ParentSurfaceId = parcel.ParentSurfaceId; uc.SurfaceAppItem = parcel.SurfaceAppItem; uc.SurfaceAppItemId = parcel.SurfaceAppItemId; uc.IsChildSurface = parcel.IsChildSurface; uc.IsSubChildSurface = parcel.IsSubChildSurface; uc.IsClone = parcel.IsClone; //call the reload control method override uc.ReloadControl(parcel.SurfaceAppItem, parcel.IsView, parcel.IsNew); utils.ConvertStringtoHTMLFile(uc.UniqueID, HttpContext.Current.Server.MapPath("~/upload/test.txt")); System.Web.UI.WebControls.Panel pnlSurfaceFieldModal = (System.Web.UI.WebControls.Panel)uc.FindControl("pnlSurfaceFieldModal"); if (pnlSurfaceFieldModal != null) pnlSurfaceFieldModal.Visible = false; HttpContext.Current.Session["SurfaceControlParcel"] = null; uc.Controls.AddAt(0, new ScriptManager()); page.Controls.Add(uc); using (StringWriter writer = new StringWriter()) { //utils.ConvertStringtoHTMLFile(, HttpContext.Current.Server.MapPath("~/upload/test.txt")); HttpContext.Current.Server.Execute(page, writer, false); result = writer.ToString(); } } } } catch (Exception ex) { exception.HandleException("Canvas:", MethodBase.GetCurrentMethod().Name, ex, HttpContext.Current.Session["user"]); } return result; } [WebMethod] public String GetUserControl(string blah) { string result = string.Empty; if (Session["ajuc"] != null) { try { var page = new Page(); //load usercontrol in memory ISurfaceBase control = (ISurfaceBase)Session["ajuc"]; //create html form var form = new System.Web.UI.HtmlControls.HtmlForm(); //add control to form form.Controls.Add(control); //add form to page page.Controls.Add(form); //create textwriter for accept html var sw = new StringWriter(); HttpContext.Current.Server.Execute(page, sw, false); //receive desired html var data = sw.GetStringBuilder().ToString(); result = data; Session["ajuc"] = null; } catch (Exception ex) { exception.HandleException("Canvas:", "GetUserControl", ex, ""); } } //return to the client return result; } /// /// Webmethod called from javascript to save the given image to the server /// /// image as string /// /// /// AUTHOR: Charlene van Heerden /// DATE WRITTEN: 25 February 2016 /// [WebMethod] public static string SaveOverlayToFile(string overlay, string filename) { try { string fileNameWitPath = HttpContext.Current.Server.MapPath(taskImagePath) + filename + ".png"; using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create)) { using (BinaryWriter bw = new BinaryWriter(fs)) { byte[] data = Convert.FromBase64String(overlay);//convert from base64 bw.Write(data); bw.Close(); } } return "Done"; } catch (Exception ex) { exception.HandleException("Canvas:", "SaveOverlayToFile", ex, ""); return "Error" + ex.Message; } } /// /// Webmethod called from javascript to save positions /// /// list of Ids that were ordered /// /// /// AUTHOR: Graham Rook /// DATE WRITTEN: 15 July 2016 /// [System.Web.Services.WebMethod] public static string SavePositions(List Ids, List GrpIds, List TbIds, List PIds) { try { if (utils.verifySession("InlineApp") && utils.verifySession("user")) { oUser user = (oUser)HttpContext.Current.Session["user"]; if ((user.userType > (int)pNums.UserType.PowerUser && user.userType != (int)pNums.UserType.CustomUser) || (user.mimicUserType > (int)pNums.UserType.PowerUser && user.userType == (int)pNums.UserType.CustomUser)) { oSurface surfApp = (oSurface)HttpContext.Current.Session["InlineApp"]; ArrayList surfaceFieldList = new ArrayList(); int pos = 0; //enumerate tab ids foreach (string Id in TbIds) { pos++; ArrayList FieldList = new ArrayList(); //string fieldName = Id.Replace("Core_Content_ctl07_li_f", ""); string fieldName = Id.Substring(Id.IndexOf("_li_f") + 5); //to cater for dynamic ids due to runat server //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfApp.recId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //set new sequence field.sequence = pos; //appedn to field list for update surfaceFieldList.Add(field); break; } } pos = 0; //enumerate group ids foreach (string Id in GrpIds) { pos++; ArrayList FieldList = new ArrayList(); string fieldName = Id.Replace("gsrt", ""); //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfApp.recId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //set new sequence field.sequence = pos; //appedn to field list for update surfaceFieldList.Add(field); break; } } pos = 0; int seq = 0; //enumerate control ids string prevParentField = ""; foreach (string Id in Ids) { string parentField = PIds[pos].Replace("tog", ""); ArrayList FieldList = new ArrayList(); //string fieldName = Id.Replace("srt", ""); string fieldName = Id.Substring(Id.IndexOf("_srt") + 4); //to cater for dynamic ids due to runat server //if new group, reset sequence if (parentField != prevParentField) seq = 0; prevParentField = parentField; pos++; seq++; //get field FieldList = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfApp.recId.ToString() + "," + fieldName); //enumerate list foreach (oSurfaceField field in FieldList) { //set new sequence field.sequence = seq; //updqate the parent id ArrayList parentFields = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "surfaceId,surfaceFieldName", surfApp.recId.ToString() + "," + parentField); foreach (oSurfaceField pField in parentFields) { field.parentId = pField.recId; field.surfaceFieldName = pField.surfaceFieldName + "_" + utils.stripCharacters(field.surfaceFieldDisplay).Replace(" ", ""); break; } //appedn to field list for update surfaceFieldList.Add(field); break; } } if (surfaceFieldList.Count > 0) { if (xData.UpdateTypedCollection("recId", typeof(oSurfaceField), surfaceFieldList)) { foreach (oModule moduleItem in xData.GetTypedByCriteriaSpecific("recId", typeof(oModule), "recId", pNums.Module.Surface.GetHashCode().ToString())) { surfaceHandler.BuildSurfaceAppTemplate(surfApp, controlPath + moduleItem.control, surfacePath, true); break; } } } } } HttpContext.Current.Session["Inline"] = 1; return "Done"; } catch (Exception ex) { exception.HandleException("Canvas:", "SavePositions", ex, ""); return "Error" + ex.Message; } } [WebMethod] public static string SaveBodyData(List bodyParts, string itemId, string fieldId) { try { string bodyPartList = string.Empty; bool firstPart = true; foreach (BodyPart bodyPart in bodyParts) { if (firstPart) { bodyPartList += bodyPart.id.ToString(); firstPart = false; } else bodyPartList += "," + bodyPart.id.ToString(); } foreach (oSurfaceFieldData data in xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceFieldData), "surfaceItemId,surfaceFieldId", itemId + "," + fieldId)) { data.surfaceFieldValueChar = bodyPartList; xData.UpdateTyped("recId", data.recId.ToString(), typeof(oSurfaceFieldData), data); } return bodyPartList; } catch (Exception ex) { return ex.Message; } } [WebMethod] public static string ComplaintBodySave(List bodyParts, string recId) { try { string bodyPartList = string.Empty; bool firstPart = true; foreach (BodyPart bodyPart in bodyParts) { if (firstPart) { bodyPartList += bodyPart.id.ToString(); firstPart = false; } else bodyPartList += "," + bodyPart.id.ToString(); } foreach (oMedicalPatientComplaints complaintData in xData.GetTypedByCriteriaSpecific("recId", typeof(oMedicalPatientComplaints), "recId", recId)) { complaintData.bodyMap = bodyPartList; xData.UpdateTyped("recId", complaintData.recId.ToString(), typeof(oMedicalPatientComplaints), complaintData); } return bodyPartList; } catch (Exception ex) { return ex.Message; } } public class BodyPart { public int id { get; set; } public string part { get; set; } } [WebMethod] public static void SaveAudio(string Url, string Filename) { //this does not work. not even sure what i'm doing here. horrible to be honest. i'm leaveing the code commented out to show what i've tried //string audioPath = HostingEnvironment.ApplicationPhysicalPath + "\\upload\\audio\\" + Url; //string audioFolder = HostingEnvironment.ApplicationPhysicalPath + "\\upload\\audio"; //utils.validateFolder(audioFolder); //if (!System.IO.File.Exists(audioPath)) //{ // using (System.IO.FileStream fs = System.IO.File.Create(Url)) // { // for (byte i = 0; i < 100; i++) // { // fs.WriteByte(i); // } // } //} //else //{ // return; //} } [WebMethod] public static string[] SearchUsers(string prefix) { List users = new List(); oSetup _setup = handler.ReturnSetup(false); string query = "SELECT recId, name + ' ' + surname AS [user] FROM pal_User "; query += "WHERE customerCode = '" + _setup.code + "' AND ((surname LIKE '%" + prefix + "%') OR (name LIKE '%" + prefix + "%') OR (email LIKE '%" + prefix + "%')) "; //utils.ConvertStringtoHTMLFile(query, HttpContext.Current.Server.MapPath("~/upload/test.txt")); DataTable dt = xData.GetCustomTypedTable(query, true); foreach (DataRow row in dt.Rows) { users.Add(string.Format("{0}-{1}", row["user"].ToString(), row["recId"].ToString())); } return users.ToArray(); } [WebMethod] public static string[] SearchCalendar(string prefix, string calendarId) { List users = new List(); int calId = 0; int.TryParse(calendarId, out calId); if (calId > 0) { //utils.ConvertStringtoHTMLFile(prefix + calId, HttpContext.Current.Server.MapPath("~/upload/test.txt")); users = xCalendar.SearchCalendar(prefix, calId); } return users.ToArray(); } [WebMethod(Description = "Server Side DataTables support", EnableSession = true)] [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static void GetSurfaceData(object parameters, string surface) { var resultSet = new DataTableResultSet(); var req = DataTableParameters.Get(parameters); DataTable dt = new DataTable(); int surfaceId = 0; int.TryParse(surface, out surfaceId); int startIndex = 0; int maxLength = 0; string orderBy = String.Empty; string searchVal = String.Empty; if (surfaceId > 0) { //userLink specifics int userLink = 0; //oUser user = new oUser(); //if (utils.verifySession("user")) // user = (oUser)Session["user"]; //if (user.userType == pNums.UserType.WebsiteUser.GetHashCode()) // userLink = user.recId; //CVH 2017-01-31 Add filter - leave blank, method called from Javascript, but not currently being used string filter = ""; int totalCount = xData.GetSurfaceDataCount(surfaceId, userLink, filter); startIndex = req.Start; maxLength = req.Length; string colName = req.Columns[req.Order[0].Column].Name; if (colName != null && colName != String.Empty) orderBy = req.Columns[req.Order[0].Column].Name + " " + req.Order[0].Direction; searchVal = req.SearchValue; dt = xData.GetSurfaceDataPaged(surfaceId, startIndex, maxLength, orderBy, searchVal, handler.ReturnUser().recId, userLink, filter); resultSet.draw = req.Draw; resultSet.recordsTotal = totalCount; resultSet.recordsFiltered = dt.Rows.Count; /* number of records after search - box filtering is applied */ var columns = new List(); foreach (DataColumn col in dt.Columns) { columns.Add(col.ColumnName); } //resultSet.data.Add(columns); List> data = new List>(); data = handler.ConvertTableToStringLists(dt); //data.Insert(0, columns); resultSet.data = data; //var result = new //{ // iTotalRecords = totalCount, // iTotalDisplayRecords = dt.Rows.Count, // aaData = resultSet //}; SendResponse(HttpContext.Current.Response, resultSet); } } private static void SendResponse(HttpResponse response, DataTableResultSet result) { response.Clear(); response.Headers.Add("X-Content-Type-Options", "nosniff"); response.Headers.Add("X-Frame-Options", "SAMEORIGIN"); response.ContentType = "application/json; charset=utf-8"; response.Write(result.ToJSON()); response.Flush(); response.End(); } [WebMethod] public static string SaveImageMapPoint(string surfaceItemId, string surfaceFieldId, string positionX, string positionY, string sequence, string imageNotes) { int x = 0; int.TryParse(positionX, out x); int y = 0; int.TryParse(positionY, out y); int seq = 0; int.TryParse(sequence, out seq); int itemId = 0; int.TryParse(surfaceItemId, out itemId); int fieldId = 0; int.TryParse(surfaceFieldId, out fieldId); oImageMap map = new oImageMap(); map.dateSaved = DateTime.Now; map.isActive = false; map.posX = x; map.posY = y; map.sequence = seq; map.surfaceFieldId = fieldId; map.surfaceItemId = itemId; map.imageMapNote = imageNotes; map.recId = xData.SaveTyped("recId", typeof(oImageMap), map); return map.recId.ToString(); } [WebMethod] public static void DeleteImageMapPoint(string recId, string surfaceItemId, string surfaceFieldId) { int counter = 1; foreach (oImageMap map in xData.GetTypedByCriteriaSpecific("recId", typeof(oImageMap), "surfaceItemId,surfaceFieldId", surfaceItemId + "," + surfaceFieldId, "sequence")) { if (map.recId.ToString() == recId) continue; map.sequence = counter; xData.UpdateTyped("recId", map.recId.ToString(), typeof(oImageMap), map); counter++; } xData.DeleteTyped("recId", recId, typeof(oImageMap)); } #endregion /* CVH 2016-09-09 Commenting out until used. upServiceDesk is causing errors in TSP Debtors reports protected void btnNewSupportRequest_Click(object sender, EventArgs e) { try { plcServiceDesk.Controls.Clear(); controls_module_task uc = (controls_module_task)LoadControl(modulePath + "task.ascx"); uc.Task = null; uc.CanvasId = this.CanvasId; uc.ServiceDesk = true; //taskControl.SnapshotId = int.Parse(ddSnapshotVersions.SelectedItem.Value); //taskControl.SnapshotX = e.X; //taskControl.SnapshotY = e.Y; uc.ActivePanel = "Form"; uc.ReloadControl(); plcServiceDesk.Controls.Add(uc); //open Task modal //Label olbl = new Label(); //olbl.Text = "Hi "; //olbl.ID = "lblTest"; //plcServiceDesk.Controls.Add(olbl); ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myTaskModal", "$('#serviceDeskTask').modal();", true); } catch (Exception ex) { exception.HandleException("Overlay:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } */ }