using framework_business; using framework_library; using System; using System.Configuration; using System.Collections; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Net; using System.IO; public partial class controls_module_imageMap : System.Web.UI.UserControl, ISurfaceControlBase { #region properties public int SurfaceItemId { get { if (ViewState["surfaceItemId"] == null) return 0; else return (int)ViewState["surfaceItemId"]; } set { ViewState["surfaceItemId"] = value; } } public int SurfaceFieldId { get { if (ViewState["surfaceFieldId"] == null) return 0; else return (int)ViewState["surfaceFieldId"]; } set { ViewState["surfaceFieldId"] = value; } } public int NextSequence { get { if (ViewState["nextSequence"] == null) return 1; else return (int)ViewState["nextSequence"]; } set { ViewState["nextSequence"] = value; } } #endregion #region override public void ReloadControl(oSurfaceFieldData controlFieldData, bool alternateView = false, bool readOnly = false) { try { utils.disposeSession("ImageMapItemsNotLinked"); ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oSurfaceField), "recId", controlFieldData.surfaceFieldID.ToString()); if (list != null && list.Count > 0) { oSurfaceField field = (oSurfaceField)list[0]; this.SurfaceFieldId = field.recId; //CVH 2016-10-21 If the surface item hasn't been saved yet, assign a random negative item Id, otherwise points will be inaccurate when more than one person capturing at the same time if (controlFieldData.surfaceItemId == 0) this.SurfaceItemId = utils.RandomNumber(-999999, -1); else this.SurfaceItemId = controlFieldData.surfaceItemId; LoadImage(field); LoadPoints(); } } catch (Exception ex) { exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } public void SaveControlData(ref oSurfaceFieldData _surfaceFieldData) { try { int userId = 0; if (utils.verifySession("user")) userId = ((oUser)Session["user"]).recId; //all points have already been saved, some temporarily with blank note. always update entire collection ArrayList list = xData.GetTypedByCriteriaSpecific("recId", typeof(oImageMap), "surfaceItemId,surfaceFieldId", this.SurfaceItemId + "," + this.SurfaceFieldId, "sequence"); ArrayList imageMapItemsNotLinked = new ArrayList(); int counter = 1; foreach (oImageMap map in list) { map.imageMapNote = txtImageMapNotes.Text; map.isActive = true; map.sequence = counter; if (this.SurfaceItemId < 0) { map.userIdSaved = userId; imageMapItemsNotLinked.Add(map); } else { map.dateUpdated = DateTime.Now; map.userIdUpdated = userId; } counter++; } if (list.Count > 0) xData.UpdateTypedCollection("recId", typeof(oImageMap), list); if (imageMapItemsNotLinked.Count > 0) Session["ImageMapItemsNotLinked"] = imageMapItemsNotLinked; //oImageMap img = new oImageMap(); //if (utils.verifySession("ImageMap"))//update mode //{ // img = (oImageMap)Session["ImageMap"]; // //save form values // SaveFormValues(ref img); // img.dateUpdated = DateTime.Now; // img.userIdUpdated = userId; // if (xData.UpdateTyped("recId", img.recId.ToString(), typeof(oImageMap), img)) // { // Session["ImageMap"] = img; // //update item in session if resaving when saving parent, otherwise it updates with old values // if (img.surfaceItemId < 0) // { // ArrayList imageMapItemsNotLinked = new ArrayList(); // ArrayList newList = new ArrayList(); // if (utils.verifySession("ImageMapItemsNotLinked")) // { // imageMapItemsNotLinked = (ArrayList)Session["ImageMapItemsNotLinked"]; // } // for (int i = 0; i < imageMapItemsNotLinked.Count; i++) // { // oImageMap map = (oImageMap)imageMapItemsNotLinked[i]; // if (map.recId == img.recId) // map = img; // newList.Add(map); // } // Session["ImageMapItemsNotLinked"] = newList; // } // LoadPoints(); // lblResultNote.Visible = true; // lblResultNote.Text = "your changes were updated successfully."; // //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myHideImageMapNote", "$('#modImageMapNote').modal('hide');$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true); // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myHideImageMapNote", "$('.imgImageMap').focus();", true); // } //} //else //{ // //save form values // SaveFormValues(ref img); // if (this.SurfaceItemId <= 0) // img.isActive = false; // else // img.isActive = true; // img.dateSaved = DateTime.Now; // img.userIdSaved = userId; // int x = 0; // int y = 0; // if (!int.TryParse(hidX.Value, out x) || !int.TryParse(hidY.Value, out y)) // { // lblResultNote.Visible = true; // lblResultNote.Text = "the X and Y coordinates could not be determined."; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myErrorImageMapNote", "$('#modImageMapNote').modal();", true); // } // else // { // img.posX = x; // img.posY = y; // img.sequence = this.NextSequence; // img.surfaceFieldId = this.SurfaceFieldId; // img.surfaceItemId = this.SurfaceItemId; // img.recId = xData.SaveTyped("recId", typeof(oImageMap), img); // if (img.recId > 0) // { // this.NextSequence = img.sequence + 1; // Session["ImageMap"] = img; // if (img.surfaceItemId < 0) // { // ArrayList imageMapItemsNotLinked = new ArrayList(); // if (utils.verifySession("ImageMapItemsNotLinked")) // { // imageMapItemsNotLinked = (ArrayList)Session["ImageMapItemsNotLinked"]; // } // imageMapItemsNotLinked.Add(img); // Session["ImageMapItemsNotLinked"] = imageMapItemsNotLinked; // } // LoadPoints(); // lblResultNote.Visible = true; // lblResultNote.Text = "your note was saved successfully."; // //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myHideImageMapNote", "$('#modImageMapNote').modal('hide');$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true); // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myHideImageMapNote", "$('.imgImageMap').focus();", true); // } // } //} } catch (Exception ex) { exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region methods private void LoadImage(oSurfaceField field) { try { //brackets don't work, and aren't escaped by escapedatastring, do manually string location = "/upload/image/" + Uri.EscapeDataString(field.placeholder).Replace("(", "%28").Replace(")", "%29"); imgImageMap.Style.Add("background-image", "url(" + location + ")"); if (File.Exists(System.Web.Hosting.HostingEnvironment.MapPath("~/upload/image/" + field.placeholder))) { using (System.Drawing.Image img = System.Drawing.Image.FromFile(System.Web.Hosting.HostingEnvironment.MapPath("~/upload/image/" + field.placeholder))) { divOverlayWrapper1.Style.Add("Height", (img.Height + 20) + "px"); divOverlayWrapper1.Style.Add("Width", (img.Width + 20) + "px"); divOverlayImg.Style.Add("Height", img.Height + "px"); divOverlayImg.Style.Add("Width", img.Width + "px"); imgImageMap.Style.Add("Height", img.Height.ToString() + "px"); imgImageMap.Style.Add("Width", img.Width.ToString() + "px"); } } lblHiddenSurfaceItemId.InnerText = this.SurfaceItemId.ToString(); lblHiddenSurfaceFieldId.InnerText = this.SurfaceFieldId.ToString(); } catch (Exception ex) { exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); //Response.Redirect("/error", false); } } private void LoadPoints() { try { //remove current divs before adding new for (int i = divOverlayWrapper1.Controls.Count - 1; i > 0; i--) { Control c = (Control)divOverlayWrapper1.Controls[i]; if (c.ID != null && c.ID.StartsWith("divPoint")) divOverlayWrapper1.Controls.Remove(c); } int maxSequence = 0; int pointSeq = 0; foreach (oImageMap img in xData.GetTypedByCriteriaSpecific("recId", typeof(oImageMap), "surfaceItemId,surfaceFieldId", this.SurfaceItemId + "," + this.SurfaceFieldId)) { if (img.sequence > maxSequence) maxSequence = img.sequence; int adjust = pointSeq * 30; //width of the div point (old 30) pointSeq++; //LinkButton btn = new LinkButton(); //btn.Text = img.sequence.ToString(); //btn.ID = "btnDivPoint" + pointSeq; //btn.ForeColor = System.Drawing.Color.FromArgb(15, 43, 181); //btn.CommandArgument = img.recId.ToString(); //btn.CommandName = btn.ID; //btn.Command += btnImageMapPoint_Click; //divs are moving about 15 points for each one added (think to do with div position relative). int left = img.posX - adjust; int top = img.posY; HtmlGenericControl divPoint = new HtmlGenericControl(); divPoint.ID = "divPoint" + img.recId; divPoint.InnerText = img.sequence.ToString(); divPoint.Attributes.Add("class", "taskPointImageMap imagemap-tooltip divPoint" + img.recId + " "); divPoint.Attributes.Add("style", "left:" + left + "px;top:" + top + "px"); //divPoint.Attributes.Add("data-toggle", "tooltip"); divPoint.Attributes.Add("data-html", "true"); divPoint.Attributes.Add("data-container", "#" + divOverlayWrapper1.ClientID); divPoint.Attributes.Add("data-placement", "auto top"); //divPoint.Attributes.Add("title", "" + img.imageMapNote + ""); divPoint.Attributes.Add("onclick", "imageMapPointDelete(" + img.recId + ", " + img.sequence + ", " + this.SurfaceItemId + "," + this.SurfaceFieldId + ");"); //divPoint.Controls.Add(btn); divOverlayWrapper1.Controls.Add(divPoint); txtImageMapNotes.Text = img.imageMapNote; } this.NextSequence = maxSequence + 1; } catch (Exception ex) { exception.HandleException("Overlay:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } #endregion #region events protected void Page_Load(object sender, EventArgs e) { try { //CVH 2016-10-21 On every postback, needs to load after viewstate has been loaded LoadPoints(); } catch (Exception ex) { exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); Response.Redirect("/error", false); } } //protected void imgImageMap_Click(object sender, ImageClickEventArgs e) //{ // try // { // utils.disposeSession("ImageMap"); // lblResultNote.Text = ""; // lblResultNote.Visible = false; // txtImageMapNote.Text = ""; // hidX.Value = e.X.ToString(); // hidY.Value = e.Y.ToString(); // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myImageMapNote", "$('#modImageMapNote').modal();$('.txtImageMapNote').focus();", true); // } // catch (Exception ex) // { // exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} //void btnImageMapPoint_Click(object sender, CommandEventArgs e) //{ // try // { // lblResultNote.Text = ""; // lblResultNote.Visible = false; // LinkButton btn = (LinkButton)sender; // if (btn != null) // { // int recId = int.Parse(btn.CommandArgument); // foreach (oImageMap img in xData.GetTypedByCriteriaSpecific("recId", typeof(oImageMap), "recId", recId.ToString())) // { // txtImageMapNote.Text = img.imageMapNote; // Session["ImageMap"] = img; // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myEditImageMapNote", "$('#modImageMapNote').modal();$('.txtImageMapNote').focus();", true); // break; // } // } // } // catch (Exception ex) // { // exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} //protected void btnSaveNote_Click(object sender, EventArgs e) //{ // try // { // int userId = 0; // if (utils.verifySession("user")) // userId = ((oUser)Session["user"]).recId; // oImageMap img = new oImageMap(); // if (utils.verifySession("ImageMap"))//update mode // { // img = (oImageMap)Session["ImageMap"]; // //save form values // SaveFormValues(ref img); // img.dateUpdated = DateTime.Now; // img.userIdUpdated = userId; // if (xData.UpdateTyped("recId", img.recId.ToString(), typeof(oImageMap), img)) // { // Session["ImageMap"] = img; // //update item in session if resaving when saving parent, otherwise it updates with old values // if (img.surfaceItemId < 0) // { // ArrayList imageMapItemsNotLinked = new ArrayList(); // ArrayList newList = new ArrayList(); // if (utils.verifySession("ImageMapItemsNotLinked")) // { // imageMapItemsNotLinked = (ArrayList)Session["ImageMapItemsNotLinked"]; // } // for (int i=0; i 0) // { // this.NextSequence = img.sequence + 1; // Session["ImageMap"] = img; // if (img.surfaceItemId < 0) // { // ArrayList imageMapItemsNotLinked = new ArrayList(); // if (utils.verifySession("ImageMapItemsNotLinked")) // { // imageMapItemsNotLinked = (ArrayList)Session["ImageMapItemsNotLinked"]; // } // imageMapItemsNotLinked.Add(img); // Session["ImageMapItemsNotLinked"] = imageMapItemsNotLinked; // } // LoadPoints(); // lblResultNote.Visible = true; // lblResultNote.Text = "your note was saved successfully."; // //ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myHideImageMapNote", "$('#modImageMapNote').modal('hide');$('body').removeClass('modal-open');$('.modal-backdrop').remove();", true); // ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "myHideImageMapNote", "$('.imgImageMap').focus();", true); // } // } // } // } // catch (Exception ex) // { // exception.HandleException("ImageMap:", MethodBase.GetCurrentMethod().Name, ex, Session["user"]); // Response.Redirect("/error", false); // } //} #endregion }