private void saveData(string responseString, string assignment) { JObject responseJSON = null; responseJSON = JObject.Parse(responseString); if (assignment.Equals("JSON_ACTION_LOAD_CUST_PATH")) { if (responseJSON != null) { Application.Current.Properties["DATABASE_DEVIATION"] = (string)responseJSON["path"]; Application.Current.Properties["SERVER"] = (string)responseJSON["server"]; MessagingCenter.Send <JSONFetcher>(this, "CUST_PATH_LOADED"); } else { //Did not receive data } } else if (assignment.Equals("JSON_ACTIONS_GET_DEPTNAMES")) { Application.Current.Properties["DEPTPEOPLE"] = responseJSON["data"].ToString();; //sync.downloadIcons(); //MessagingCenter.Send<JSONFetcher>(this, "JSON_ACTIONS_GET_DEPTNAMES_LOADED"); } else if (assignment.Equals("JSON_ACTION_GET_KEYWORDS")) { Application.Current.Properties["KEYWORDS"] = responseJSON["data"].ToString(); Sync sync = new Sync(); sync.downloadDeptPeople(); //MessagingCenter.Send<JSONFetcher>(this, "JSON_ACTION_GET_KEYWORDS_LOADED"); } else if (assignment.Equals("TEMPLATE_DATA")) { Dictionary <string, string> templateDictionary = TemplateDictionary.Instance(); string count = templateDictionary.Count().ToString(); templateDictionary.Add(count, responseString); sync.downloadTemplate(); } else if (assignment.Equals("TEMPLATES_DATA")) { Application.Current.Properties["TEMPLATES"] = responseJSON["data"].ToString(); MessagingCenter.Send <JSONFetcher>(this, "TEMPLATES_LOADED"); } else if (assignment.Equals(Constants.LOAD_SESSION_DATA)) { Application.Current.Properties["SESSION_COMMON_USERNAME"] = (string)responseJSON["session"]["commonUserName"]; Application.Current.Properties["SESSION_USERNAME"] = (string)responseJSON["session"]["userName"]; Application.Current.Properties["DATABASE_UPLOAD"] = (string)responseJSON["session"]["uploadDatabase"]; //MessagingCenter.Send<JSONFetcher>(this, Constants.SESSION_DATA_LOADED); } }
private void generateTemplate() { DynamicUIFactory dynamicUIFactory = new DynamicUIFactory(); Dictionary <string, string> templateDictionary = TemplateDictionary.Instance(); JObject template = JObject.Parse((string)templateDictionary[templateArrayNumber]); bool required, multiselect; string label, fieldname; templateTitle = (string)template["data"]["templatetitle"]; formtemplateid = (string)template["data"]["formtemplateid"]; templateversion = (string)template["data"]["templateversion"]; Title = templateTitle; JArray fieldsets = (JArray)template["data"]["fieldsets"]; for (int i = 0; i < fieldsets.Count; i++) { /* * FIELDSETS */ int fieldsetDevicetype = (int)fieldsets[i]["devicetype"]; //Kigger om fieldsettet skal benyttes i mobilapplikationen. OBS, fremadrettet skal der også tages forbehold for accessread og accessedit if (fieldsetDevicetype == 1) { //Tilføjer feltsætnavn til dynamicUIList string fieldsetTitle = (string)fieldsets[i]["fieldsettitle"]; AbstractDynamicUI guiElementLabel = dynamicUIFactory.getDynamicUI("label"); guiElementLabel.setLabel(fieldsetTitle); dynamicUIList.Add(guiElementLabel); JArray fields = (JArray)fieldsets[i]["fields"]; for (int ii = 0; ii < fields.Count; ii++) { /* * FIELDS */ Dictionary <string, string> valueListDictionary = new Dictionary <string, string>(); int fieldDevicetype = (int)fields[ii]["devicetype"]; if (fieldDevicetype == 1) { required = (bool)fields[ii]["required"]; multiselect = (bool)fields[ii]["multiselect"]; label = (string)fields[ii]["label"]; fieldname = (string)fields[ii]["fieldname"]; //Går igennem valuelist string sourcetype = (string)fields[ii]["sourcetype"]; if (sourcetype.Equals("list")) { JArray valueList = (JArray)fields[ii]["valuelist"]; for (int iii = 0; iii < valueList.Count; iii++) { string valueListID = (string)valueList[iii]["id"]; string valueListName = (string)valueList[iii]["name"]; valueListDictionary.Add(valueListID, valueListName); } } //Gets keywords from keywordalias if (sourcetype.Equals("keyword")) { string json = Application.Current.Properties["KEYWORDS"] as string; JArray keywordList = JArray.Parse(json); //JArray keywordList = Application.Current.Properties["KEYWORDS"] as JArray; string keyword = (string)fields[ii]["keywordalias"]; for (int iiii = 0; iiii < keywordList.Count; iiii++) { string alias = (string)keywordList[iiii]["alias"]; if (alias.Equals(keyword)) { JArray valuesArray = (JArray)keywordList[iiii]["valuesarray"]; foreach (string items in valuesArray) { if (!valueListDictionary.ContainsKey(items)) { valueListDictionary.Add(items, items); //OBS Fejl med samme itemkey } } } } } //Gets the type og GUI element string type = (string)fields[ii]["type"]; AbstractDynamicUI guiElement = dynamicUIFactory.getDynamicUI(type); if (guiElement != null) { //Sets the variables of the GUI element guiElement.setRequired(required); guiElement.setMultiSelect(multiselect); guiElement.setID(fieldname); guiElement.setLabel(label); //Sets the valuelist if (valueListDictionary.Any()) { guiElement.setValueList(valueListDictionary); } //Adds the GUI element to a list dynamicUIList.Add(guiElement); } } } } } if (dynamicUIList.Any()) { generateUIFromList(); } }
private void loadIcons() { //Loads icon from TEMPLATE_DICTIONARY in application properties if it already exits. if (Application.Current.Properties.ContainsKey("TEMPLATE_DICTIONARY")) { templateDictionary = JsonConvert.DeserializeObject <Dictionary <string, string> >(Application.Current.Properties["TEMPLATE_DICTIONARY"] as string); TemplateDictionary.setDictionary(templateDictionary); } else { templateDictionary = TemplateDictionary.Instance(); string templateJSON = JsonConvert.SerializeObject(templateDictionary, Formatting.Indented); Application.Current.Properties["TEMPLATE_DICTIONARY"] = templateJSON; Application.Current.SavePropertiesAsync(); } int left = 0; int top = 0; for (int i = 0; i < templateDictionary.Count; i++) { StackLayout stackLayout = new StackLayout { Orientation = StackOrientation.Vertical, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Start }; Label label = new Label(); //Get iconURL string templateString = (string)templateDictionary[i.ToString()]; JObject templateJSON = JObject.Parse(templateString); string iconURL = (string)templateJSON["templateiconurl"]; //Set image to iconURL var imageSource = new UriImageSource { Uri = new Uri("https://e-dok.rm.dk/" + iconURL) }; Image iconImage = new Image(); iconImage.Source = imageSource; iconImage.ClassId = i.ToString(); iconImage.HeightRequest = 100; iconImage.WidthRequest = 100; label.Text = (string)templateJSON["data"]["templatetitle"]; label.TextColor = Color.Black; label.HorizontalOptions = LayoutOptions.Center; stackLayout.Children.Add(iconImage); stackLayout.Children.Add(label); frame = new Frame { Content = stackLayout, Margin = new Thickness(2, 2, 2, 2), ClassId = i.ToString(), StyleId = (string)templateJSON["data"]["templatetitle"] }; frame.HasShadow = true; //Adds onTap event var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += TapGestureRecognizer_Tapped; frame.GestureRecognizers.Add(tapGestureRecognizer); imageList.Add(frame); } //Sort alphabetically List <Frame> sortedFrameList = imageList.OrderBy(o => o.StyleId).ToList(); for (int i = 0; i < sortedFrameList.Count; i++) { frame = sortedFrameList[i]; MainLayout.Children.Add(frame, left, top); left++; if (left > 1) { top++; left = 0; } } Content = ParentLayout; }