protected void imgbtnEdit_Click(object sender, ImageClickEventArgs e) { ActiveTemplate = Target(sender as Control); ToForm(); cpeNewTemplate.Collapsed = false; cpeNewTemplate.ClientState = "false"; }
protected void btnSaveTemplate_Click(object sender, EventArgs e) { Page.Validate("vgPropTemplate"); if (!Page.IsValid) { return; } ActiveTemplate.Name = txtTemplateName.Text; ActiveTemplate.Description = txtDescription.Text; ActiveTemplate.Group = (PropertyTemplateGroup)Enum.Parse(typeof(PropertyTemplateGroup), cmbCategories.SelectedValue); ActiveTemplate.Owner = Page.User.Identity.Name; try { ActiveTemplate.Commit(); TemplateCreated?.Invoke(this, new PropertyTemplateEventArgs(ActiveTemplate)); // Clear for the next ActiveTemplate = new UserPropertyTemplate(); ToForm(); cpeNewTemplate.ClientState = "true"; } catch (MyFlightbookValidationException ex) { lblErr.Text = ex.Message; } }
protected void gvTemplates_RowDataBound(object sender, GridViewRowEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } if (e.Row.RowType == DataControlRowType.DataRow) { UserPropertyTemplate pt = (UserPropertyTemplate)e.Row.DataItem; bool fOwned = pt.Owner.CompareCurrentCultureIgnoreCase(User.Identity.Name) == 0; MultiView mvStatus = (MultiView)e.Row.FindControl("mvStatus"); if (fOwned) { mvStatus.SetActiveView((View)mvStatus.FindControl("vwOwned")); } else if (AddedTemplates.Contains(pt.ID)) { mvStatus.SetActiveView((View)mvStatus.FindControl("vwAdded")); } else { mvStatus.SetActiveView((View)mvStatus.FindControl("vwUnOwned")); } if (MatchingOwnedTemplate(pt) != null) { ((AjaxControlToolkit.ConfirmButtonExtender)e.Row.FindControl("confirmOverwrite")).Enabled = true; } } }
protected void ckIsPublic_CheckedChanged(object sender, EventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } CheckBox ck = (CheckBox)sender; UserPropertyTemplate pt = Target(ck); if (ck.Checked) { List <UserPropertyTemplate> lst = new List <UserPropertyTemplate>(UserPropertyTemplate.PublicTemplates()); if (lst.Find(ptPublic => ptPublic.Name.CompareCurrentCultureIgnoreCase(pt.Name) == 0 && ptPublic.Owner.CompareCurrentCultureIgnoreCase(pt.Owner) != 0) != null) { ((Label)ck.NamingContainer.FindControl("lblPublicErr")).Text = String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.TemplateDuplicateSharedName, pt.Name); ck.Checked = false; return; } } pt.IsPublic = ck.Checked; pt.Commit(); }
protected void SetTemplatesForAircraft(Aircraft ac, Controls_mfbEditPropSet editPropSet) { if (ac == null) { return; } if (editPropSet == null) { throw new ArgumentNullException(nameof(editPropSet)); } editPropSet.RemoveAllTemplates(); IEnumerable <PropertyTemplate> rgpt = UserPropertyTemplate.TemplatesForUser(Page.User.Identity.Name, false); HashSet <PropertyTemplate> aircraftTemplates = new HashSet <PropertyTemplate>(); foreach (int id in ac.DefaultTemplates) { PropertyTemplate pt = rgpt.FirstOrDefault(pt1 => pt1.ID == id); if (pt != null) { aircraftTemplates.Add(pt); } } HashSet <PropertyTemplate> defaultTemplates = new HashSet <PropertyTemplate>(UserPropertyTemplate.DefaultTemplatesForUser(Page.User.Identity.Name)); // if the aircraft has valid templates specified, use those if (aircraftTemplates.Count > 0) { editPropSet.AddTemplates(aircraftTemplates); } else if (defaultTemplates.Count > 0) { editPropSet.AddTemplates(defaultTemplates); } else { editPropSet.AddTemplate(new MRUPropertyTemplate(Page.User.Identity.Name)); } editPropSet.RemoveTemplate((int)KnownTemplateIDs.ID_ANON); editPropSet.RemoveTemplate((int)KnownTemplateIDs.ID_SIM); if (ac.InstanceType == AircraftInstanceTypes.RealAircraft) { if (ac.IsAnonymous) { editPropSet.AddTemplate(new AnonymousPropertyTemplate()); } } else { editPropSet.AddTemplate(new SimPropertyTemplate()); } editPropSet.Refresh(); }
protected void SetTemplatesForAircraft(int idAircraft) { UserAircraft ua = new UserAircraft(Page.User.Identity.Name); Aircraft ac = ua.GetUserAircraftByID(idAircraft); if (ac != null) { mfbEditPropSet1.RemoveAllTemplates(); IEnumerable <PropertyTemplate> rgpt = UserPropertyTemplate.TemplatesForUser(Page.User.Identity.Name, false); HashSet <PropertyTemplate> aircraftTemplates = new HashSet <PropertyTemplate>(); foreach (int id in ac.DefaultTemplates) { PropertyTemplate pt = rgpt.FirstOrDefault(pt1 => pt1.ID == id); if (pt != null) { aircraftTemplates.Add(pt); } } HashSet <PropertyTemplate> defaultTemplates = new HashSet <PropertyTemplate>(UserPropertyTemplate.DefaultTemplatesForUser(Page.User.Identity.Name)); // if the aircraft has valid templates specified, use those if (aircraftTemplates.Count > 0) { mfbEditPropSet1.AddTemplates(aircraftTemplates); } else if (defaultTemplates.Count > 0) { mfbEditPropSet1.AddTemplates(defaultTemplates); } else { mfbEditPropSet1.AddTemplate(new MRUPropertyTemplate(Page.User.Identity.Name)); } mfbEditPropSet1.RemoveTemplate((int)KnownTemplateIDs.ID_ANON); mfbEditPropSet1.RemoveTemplate((int)KnownTemplateIDs.ID_SIM); // Expand for tailwheel if (ac.IsTailwheel) { cpeLandingDetails.ClientState = "false"; } if (ac.InstanceType == AircraftInstanceTypes.RealAircraft) { if (ac.IsAnonymous) { mfbEditPropSet1.AddTemplate(new AnonymousPropertyTemplate()); } } else { mfbEditPropSet1.AddTemplate(new SimPropertyTemplate()); } mfbEditPropSet1.Refresh(); } }
protected void Page_Load(object sender, EventArgs e) { Page.ClientScript.RegisterClientScriptInclude("ListDrag", ResolveClientUrl("~/Public/Scripts/listdrag.js?v=5")); Page.ClientScript.RegisterClientScriptInclude("filterDropdown", ResolveClientUrl("~/Public/Scripts/DropDownFilter.js?v=3")); searchProps.TextBoxControl.Attributes["onkeyup"] = String.Format(CultureInfo.InvariantCulture, "FilterProps(this, '{0}', '{1}', '{2}')", divAvailableProps.ClientID, lblFilteredLabel.ClientID, Resources.LogbookEntry.PropertiesFound); divAvailableProps.Attributes["ondrop"] = String.Format(CultureInfo.InvariantCulture, "javascript:lstDropTemplate.moveProp(event, 'cptT', this, '{0}', '{1}')", hdnUsedProps.ClientID, hdnAvailableProps.ClientID); divCurrentProps.Attributes["ondrop"] = String.Format(CultureInfo.InvariantCulture, "javascript:lstDropTemplate.moveProp(event, 'cptT', this, '{0}', '{1}')", hdnAvailableProps.ClientID, hdnUsedProps.ClientID); if (!IsPostBack) { if (ActiveTemplate == null) { ActiveTemplate = new UserPropertyTemplate() { Owner = Page.User.Identity.Name, OriginalOwner = string.Empty } } ; PropertyTemplateGroup[] rgGroups = (PropertyTemplateGroup[])Enum.GetValues(typeof(PropertyTemplateGroup)); foreach (PropertyTemplateGroup ptg in rgGroups) { if (ptg != PropertyTemplateGroup.Automatic) { cmbCategories.Items.Add(new ListItem(PropertyTemplate.NameForGroup(ptg), ptg.ToString())); } } cmbCategories.SelectedIndex = 0; ToForm(); locTemplateDescription1.Text = Branding.ReBrand(Resources.LogbookEntry.TemplateDescription); locTemplateDescription2.Text = Branding.ReBrand(Resources.LogbookEntry.TemplateDescription2); } else { if (ActiveTemplate == null) { throw new NullReferenceException("Active Template is null - how? "); } ActiveTemplate.PropertyTypes.Clear(); if (hdnUsedProps.Value == null) { throw new NullReferenceException("hdnUsedProps.Value is null"); } int[] props = JsonConvert.DeserializeObject <int[]>(hdnUsedProps.Value); if (props == null) { throw new NullReferenceException("props is null"); } foreach (int propid in props) { ActiveTemplate.PropertyTypes.Add(propid); } UpdateLists(); } }
protected void Page_Load(object sender, EventArgs e) { UserTemplates = UserPropertyTemplate.TemplatesForUser(Page.User.Identity.Name, IncludeAutomaticTemplates); GroupedTemplates = TemplateCollection.GroupTemplates(UserTemplates); // No viewstate - refresh every time. Refresh(); TemplatesReady?.Invoke(this, new EventArgs()); }
protected void ckDefault_CheckedChanged(object sender, EventArgs e) { CheckBox ck = sender as CheckBox; UserPropertyTemplate pt = Target(ck); pt.IsDefault = ck.Checked; pt.Commit(); ToForm(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { lblDesc1.Text = Branding.ReBrand(Resources.LogbookEntry.TemplateBrowseHeaderDescription); UserPropertyTemplates = UserPropertyTemplate.TemplatesForUser(User.Identity.Name); PublicTemplates = UserPropertyTemplate.PublicTemplates(); Refresh(); } }
protected void imgbtnEdit_Click(object sender, EventArgs e) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } ActiveTemplate = Target((sender as Control).NamingContainer); ToForm(); cpeNewTemplate.Collapsed = false; cpeNewTemplate.ClientState = "false"; }
protected static UserPropertyTemplate Target(Control c) { if (c == null) { throw new ArgumentNullException(nameof(c)); } HiddenField h = (HiddenField)c.NamingContainer.FindControl("hdnID"); UserPropertyTemplate pt = new UserPropertyTemplate(Convert.ToInt32(h.Value, CultureInfo.InvariantCulture)); return(pt); }
protected static UserPropertyTemplate Target(Control c) { if (c == null) { throw new ArgumentNullException(nameof(c)); } HiddenField h = (HiddenField)c.NamingContainer.FindControl("hdnID"); if (!Int32.TryParse(h.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int ptid)) { throw new FormatException(String.Format(CultureInfo.InvariantCulture, "Invalid property template ID '{0}'", h.Value)); } UserPropertyTemplate pt = new UserPropertyTemplate(ptid); return(pt); }
protected void ToForm() { searchProps.SearchText = string.Empty; // clear the filter before updating the lists. UpdateLists(); UserPropertyTemplate pt = ActiveTemplate; txtTemplateName.Text = pt.Name; txtDescription.Text = pt.Description; cmbCategories.SelectedValue = pt.Group.ToString(); List <TemplateCollection> rgtc = new List <TemplateCollection>(TemplateCollection.GroupTemplates(UserPropertyTemplate.TemplatesForUser(Page.User.Identity.Name))); rgtc.RemoveAll(tc => tc.Group == PropertyTemplateGroup.Automatic); rptTemplateGroups.DataSource = rgtc; rptTemplateGroups.DataBind(); mvOwnedTemplates.SetActiveView(rgtc.Count == 0 ? vwNoTemplates : vwTemplates); }
protected void UpdateLists() { UserPropertyTemplate pt = ActiveTemplate; List <CustomPropertyType> lstAll = new List <CustomPropertyType>(CustomPropertyType.GetCustomPropertyTypes()); List <CustomPropertyType> lstIncluded = lstAll.FindAll(cpt => pt.ContainsProperty(cpt)); IEnumerable <int> includedProps = lstIncluded.Select(cpt => cpt.PropTypeID); rptTemplateProps.DataSource = lstIncluded; rptTemplateProps.DataBind(); lstAll.RemoveAll(cpt => pt.ContainsProperty(cpt)); IEnumerable <int> availableProps = lstAll.Select(cpt => cpt.PropTypeID); rptAvailableProps.DataSource = lstAll; rptAvailableProps.DataBind(); hdnAvailableProps.Value = JsonConvert.SerializeObject(availableProps); hdnUsedProps.Value = JsonConvert.SerializeObject(includedProps); }
protected void imgCopy_Click(object sender, EventArgs e) { if (sender == null) { throw new ArgumentNullException(nameof(sender)); } UserPropertyTemplate pt = Target((sender as Control).NamingContainer); pt.Name = String.Format(CultureInfo.CurrentCulture, Resources.LogbookEntry.TemplateCopyTemplate, pt.Name); pt.ID = (int)KnownTemplateIDs.ID_NEW; pt.Commit(); // And set up to edit this. ActiveTemplate = pt; cpeNewTemplate.Collapsed = false; cpeNewTemplate.ClientState = "false"; ToForm(); }
protected void gvTemplates_RowCommand(object sender, GridViewCommandEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } if (e.CommandName.CompareCurrentCultureIgnoreCase("_add") == 0) { int id = Convert.ToInt32(e.CommandArgument, CultureInfo.InvariantCulture); UserPropertyTemplate pt = new UserPropertyTemplate(id); PropertyTemplate ptMatch = MatchingOwnedTemplate(pt); PersistablePropertyTemplate pptNew = pt.CopyPublicTemplate(User.Identity.Name); if (ptMatch != null) { pptNew.ID = ptMatch.ID; } pptNew.Commit(); AddedTemplates.Add(id); Refresh(); } }
protected void btnCancelEditTemplate_Click(object sender, EventArgs e) { ActiveTemplate = new UserPropertyTemplate(); ToForm(); cpeNewTemplate.ClientState = "true"; }