// This method creates Xml with a point write it to a file and returns it in a string form public string ToXmlSave() { // getting all needed values from FlightGear string lon = Client.Instance.getInfo("get " + LON_DEG); string lat = Client.Instance.getInfo("get " + LAT_DEG); string rudder = Client.Instance.getInfo("get " + RUDDER_PATH); string throttle = Client.Instance.getInfo("get " + THROTTLE_PATH); // creating object pointEntry to send to function that saves data to file PointEntry pointEntry = new PointEntry(lat, lon, rudder, throttle); // calling function that writes data of specific point to file Models.DataWriter.Instance.WriteData(pointEntry, (string)Session["fileName"]); // after saving point to xml file, send it to view StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(sb, settings); writer.WriteStartDocument(); writer.WriteStartElement("Point"); writer.WriteElementString("lon", lon); writer.WriteElementString("lat", lat); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); return(sb.ToString()); }
public PointEntry AddPoints(PointEntry pointEntryToAdd) { DateTime dateTime = DateTime.Now; var sql = @" insert into [PointLog](UserId, EarnedDate, ActivityPointId) output inserted.* values(@UserId, @EarnedDate, @ActivityPointId); "; using (var db = new SqlConnection(connectionString)) { var parameters = new { UserId = pointEntryToAdd.UserId, EarnedDate = dateTime, ActivityPointId = pointEntryToAdd.ActivityPointId, }; var result = db.QueryFirstOrDefault <PointEntry>(sql, parameters); // get total points var currentTotal = GetTotal(pointEntryToAdd.UserId); // get goals var goals = _goalsRepo.GetGoals(pointEntryToAdd.UserId); // loop through the goals and compare to total; if equal mark is complete to true. foreach (var goal in goals) { if (goal.IsComplete == false && currentTotal >= goal.PointTarget) { _goalsRepo.CompleteGoal(goal.GoalId); } } return(result); } }
// This method creates Xml read a point from the file and returns it in a string form public string ToXmlSavedFlight() { // reading data point from object that PointEntry nextPoint = DataReader.Instance.ReadData(); if (nextPoint == null) { return(null); } // after saving point to xml file, send it to view StringBuilder sb = new StringBuilder(); XmlWriterSettings settings = new XmlWriterSettings(); System.Xml.XmlWriter writer = System.Xml.XmlWriter.Create(sb, settings); writer.WriteStartDocument(); writer.WriteStartElement("Point"); writer.WriteElementString("lon", nextPoint.lon); writer.WriteElementString("lat", nextPoint.lat); writer.WriteEndElement(); writer.WriteEndDocument(); writer.Flush(); return(sb.ToString()); }
async void InitializeData() { Coordinate coords = await LocationUtil.GetCurrentLocation(); Entry = new PointEntry { Title = "Test Entry", Id = Guid.NewGuid().ToString(), Latitude = coords.Latitude, Longitude = coords.Longitude, Category = "Café" }; }
public NewItemPage() { InitializeComponent(); Item = new PointEntry { Title = "Item name", Category = "Cafe", }; BindingContext = this; }
async void AddItem_Clicked(object sender, EventArgs e) { await Navigation.PushModalAsync(new NavigationPage(new ItemDetailPage())); Coordinate location = await LocationUtil.GetCurrentLocation(); PointEntry item = new PointEntry { Title = "Test", Category = "Café", Latitude = location.Latitude, Longitude = location.Longitude }; //MessagingCenter.Send(this, "AddItem", item); }
public IActionResult AddPointsToLog(PointEntry pointEntryToAdd) { var pointEntry = _pointSystemRepository.AddPoints(pointEntryToAdd); return(Created("Successfully created entry for points", pointEntry)); }
public DragDropSection() { // drag data object showDragOverEvents = new CheckBox { Text = "Show DragOver Events" }; var includeImageCheck = new CheckBox { Text = "Include Image" }; descriptionTextBox = new TextBox { PlaceholderText = "Format", ToolTip = "Add {0} to insert inner text into the description, e.g. 'Move to {0}'" }; innerTextBox = new TextBox { PlaceholderText = "Inner", ToolTip = "Highlighted text to insert into description" }; var textBox = new TextBox { Text = "Some text" }; allowedEffectDropDown = new EnumDropDown <DragEffects> { SelectedValue = DragEffects.All }; dragEnterEffect = new EnumDropDown <DragEffects?> { SelectedValue = DragEffects.Copy }; dragOverEffect = new EnumDropDown <DragEffects?> { SelectedValue = null }; writeDataCheckBox = new CheckBox { Text = "Write data to log" }; useDragImage = new CheckBox { Text = "Use custom drag image" }; imageOffset = new PointEntry { Value = new Point(80, 80) }; imageOffset.Bind(c => c.Enabled, useDragImage, c => c.Checked); var htmlTextArea = new TextArea { Height = 24 }; var selectFilesButton = new Button { Text = "Select Files" }; Uri[] fileUris = null; selectFilesButton.Click += (sender, e) => { var ofd = new OpenFileDialog(); ofd.MultiSelect = true; ofd.ShowDialog(this); fileUris = ofd.Filenames.Select(r => new Uri(r)).ToArray(); if (fileUris.Length == 0) { fileUris = null; } }; var urlTextBox = new TextBox(); DataObject CreateDataObject() { var data = new DataObject(); if (!string.IsNullOrEmpty(textBox.Text)) { data.Text = textBox.Text; } var uris = new List <Uri>(); if (fileUris != null) { uris.AddRange(fileUris); } if (Uri.TryCreate(urlTextBox.Text, UriKind.Absolute, out var uri)) { uris.Add(uri); } if (uris.Count > 0) { data.Uris = uris.ToArray(); } if (!string.IsNullOrEmpty(htmlTextArea.Text)) { data.Html = htmlTextArea.Text; } if (includeImageCheck.Checked == true) { data.Image = TestIcons.Logo; } return(data); } // sources var buttonSource = new Button { Text = "Source" }; buttonSource.MouseDown += (sender, e) => { if (e.Buttons != MouseButtons.None) { DoDragDrop(buttonSource, CreateDataObject()); e.Handled = true; } }; var panelSource = new Panel { BackgroundColor = Colors.Red, Size = new Size(50, 50) }; panelSource.MouseMove += (sender, e) => { if (e.Buttons != MouseButtons.None) { DoDragDrop(panelSource, CreateDataObject()); e.Handled = true; } }; var treeSource = new TreeGridView { Size = new Size(200, 200) }; treeSource.SelectedItemsChanged += (sender, e) => Log.Write(treeSource, $"TreeGridView.SelectedItemsChanged (source) Rows: {string.Join(", ", treeSource.SelectedRows.Select(r => r.ToString()))}"); treeSource.DataStore = CreateTreeData(); SetupTreeColumns(treeSource); treeSource.MouseMove += (sender, e) => { if (e.Buttons == MouseButtons.Primary && !treeSource.IsEditing) { var cell = treeSource.GetCellAt(e.Location); if (cell.Item == null || cell.ColumnIndex == -1) { return; } var data = CreateDataObject(); var selected = treeSource.SelectedItems.OfType <TreeGridItem>().Select(r => (string)r.Values[0]); data.SetString(string.Join(";", selected), "my.tree.data"); DoDragDrop(treeSource, data); e.Handled = true; } }; var gridSource = new GridView { }; gridSource.SelectedRowsChanged += (sender, e) => Log.Write(gridSource, $"GridView.SelectedItemsChanged (source): {string.Join(", ", gridSource.SelectedRows.Select(r => r.ToString()))}"); SetupGridColumns(gridSource); gridSource.DataStore = CreateGridData(); gridSource.MouseMove += (sender, e) => { if (e.Buttons == MouseButtons.Primary && !gridSource.IsEditing) { var cell = gridSource.GetCellAt(e.Location); if (cell.RowIndex == -1 || cell.ColumnIndex == -1) { return; } var data = CreateDataObject(); var selected = gridSource.SelectedItems.OfType <GridItem>().Select(r => (string)r.Values[0]); data.SetString(string.Join(";", selected), "my.grid.data"); DoDragDrop(gridSource, data); e.Handled = true; } }; // destinations var buttonDestination = new Button { Text = "Drop here!", AllowDrop = true }; buttonDestination.DragEnter += (sender, e) => buttonDestination.Text = "Now, drop it!"; buttonDestination.DragLeave += (sender, e) => buttonDestination.Text = "Drop here!"; LogEvents(buttonDestination); var drawableDest = new Drawable { BackgroundColor = Colors.Blue, AllowDrop = true, Size = new Size(50, 50) }; LogEvents(drawableDest); drawableDest.DragEnter += (sender, e) => { if (e.Effects != DragEffects.None) { drawableDest.BackgroundColor = Colors.Green; } }; drawableDest.DragLeave += (sender, e) => { if (e.Effects != DragEffects.None) { drawableDest.BackgroundColor = Colors.Blue; } }; drawableDest.DragDrop += (sender, e) => { if (e.Effects != DragEffects.None) { drawableDest.BackgroundColor = Colors.Blue; } }; var dragMode = new RadioButtonList { Orientation = Orientation.Vertical, Items = { new ListItem { Text = "No Restriction", Key = "" }, new ListItem { Text = "RestrictToOver", Key = "over" }, new ListItem { Text = "RestrictToInsert", Key = "insert" }, new ListItem { Text = "RestrictToNode", Key = "node" }, new ListItem { Text = "No Node", Key = "none" } }, SelectedIndex = 0 }; var treeDest = new TreeGridView { AllowDrop = true, Size = new Size(200, 200) }; var treeDestData = CreateTreeData(); treeDest.DataStore = treeDestData; treeDest.DragOver += (sender, e) => { var info = treeDest.GetDragInfo(e); if (info == null) { return; // not supported } switch (dragMode.SelectedKey) { case "over": info.RestrictToOver(); break; case "insert": info.RestrictToInsert(); break; case "node": info.RestrictToNode(treeDestData[2]); break; case "none": info.Item = info.Parent = null; break; } }; SetupTreeColumns(treeDest); LogEvents(treeDest); var gridDest = new GridView { AllowDrop = true }; var gridDestData = CreateGridData(); gridDest.DataStore = gridDestData; gridDest.DragOver += (sender, e) => { var info = gridDest.GetDragInfo(e); if (info == null) { return; // not supported } switch (dragMode.SelectedKey) { case "over": info.RestrictToOver(); break; case "insert": info.RestrictToInsert(); break; case "node": info.Index = 2; info.Position = GridDragPosition.Over; break; case "none": info.Index = -1; break; } }; SetupGridColumns(gridDest); LogEvents(gridDest); // layout var layout = new DynamicLayout { Padding = 10, DefaultSpacing = new Size(4, 4) }; layout.BeginHorizontal(); layout.BeginScrollable(BorderType.None); layout.BeginCentered(); layout.AddSeparateRow(showDragOverEvents); layout.AddSeparateRow("AllowedEffect", allowedEffectDropDown, null); layout.BeginVertical(); layout.AddRow("DropDescription", descriptionTextBox); layout.AddRow(new Panel(), innerTextBox); layout.EndVertical(); layout.AddSeparateRow("DragEnter Effect", dragEnterEffect, null); layout.AddSeparateRow("DragOver Effect", dragOverEffect, null); layout.AddSeparateRow(useDragImage); layout.AddSeparateRow("Image offset:", imageOffset); layout.AddSeparateRow(writeDataCheckBox); layout.BeginGroup("DataObject", 10); layout.AddRow("Text", textBox); layout.AddRow("Html", htmlTextArea); layout.AddRow("Url", urlTextBox); layout.BeginHorizontal(); layout.AddSpace(); layout.BeginVertical(); layout.AddCentered(includeImageCheck); layout.AddCentered(selectFilesButton); layout.EndVertical(); layout.EndGroup(); layout.Add(dragMode); layout.AddSpace(); layout.EndCentered(); layout.EndScrollable(); layout.BeginVertical(xscale: true); layout.AddRange("Drag sources:", buttonSource, panelSource); layout.Add(treeSource, yscale: true); layout.Add(gridSource, yscale: true); layout.EndVertical(); layout.BeginVertical(xscale: true); layout.AddRange("Drag destinations:", buttonDestination, drawableDest); layout.Add(treeDest, yscale: true); layout.Add(gridDest, yscale: true); layout.EndVertical(); layout.EndHorizontal(); Content = layout; }
public ItemDetailViewModel(PointEntry item = null) { Title = item?.Title; Item = item; }