public void AddFlyout(string name, Type viewType, Position position, UnloadBehavior unloadBehavior = UnloadBehavior.SaveAndCloseViewModel) { Argument.IsNotNullOrWhitespace(() => name); Argument.IsNotNull(() => viewType); Log.Info("Adding flyout '{0}' with view type '{1}'", name, viewType.FullName); var content = (UIElement) _typeFactory.CreateInstance(viewType); var flyout = new Flyout(); flyout.Theme = FlyoutTheme.Adapt; flyout.Position = position; var flyoutInfo = new FlyoutInfo(flyout, content); flyout.SetBinding(Flyout.HeaderProperty, new Binding("ViewModel.Title") {Source = content}); ((ICompositeCommand) _commandManager.GetCommand("Close")).RegisterAction(() => { flyout.IsOpen = false; }); flyout.IsOpenChanged += async (sender, e) => { if (!flyout.IsOpen) { var vmContainer = flyout.Content as IViewModelContainer; if (vmContainer != null) { var vm = vmContainer.ViewModel; if (vm != null) { switch (unloadBehavior) { case UnloadBehavior.CloseViewModel: await vm.CloseViewModelAsync(null); break; case UnloadBehavior.SaveAndCloseViewModel: await vm.SaveAndCloseViewModelAsync(); break; case UnloadBehavior.CancelAndCloseViewModel: await vm.CancelAndCloseViewModelAsync(); break; default: throw new ArgumentOutOfRangeException("unloadBehavior"); } } } flyout.Content = null; flyout.DataContext = null; } }; _flyouts[name] = flyoutInfo; }
public static Position GetPositionFromString(string s) { Position position = new Position(); List<string> properties = s.GetProperties(); position.Latitude = Convert.ToInt64(properties[0]); position.Longitude = Convert.ToInt64(properties[1]); position.Accuracy = Convert.ToInt32(properties[2]); position.Date = Convert.ToDateTime(properties[3]); return position; }
public void AddFlyout(string name, Type viewType, Position position, UnloadBehavior unloadBehavior = UnloadBehavior.SaveAndCloseViewModel) { AddFlyout(name, viewType, position, unloadBehavior, FlyoutTheme.Adapt); }
static void SetData(Items myItems) { Item myItem1 = new Item(); Position pos1 = new Position(); Position pos2 = new Position(); Job job = new Job(); pos1.Latitude = 200; pos1.Longitude = 300; pos1.Accuracy = 5; pos1.Date = DateTime.Now; pos2.Latitude = 400; pos2.Longitude = 500; pos2.Accuracy = 6; pos2.Date = DateTime.Now; job.Time = DateTime.Now; job.Description = "some text"; job.Phone = "7777"; job.UserId = 1; myItem1.Id = 1; myItem1.FirstName = "Robin"; myItem1.LastName = "Good"; myItem1.PositionHistory.Add(pos1); myItem1.PositionHistory.Add(pos2); myItem1.JobHistory.Add(job); myItems.CurItems.Add(myItem1); myItems.CurItems.Add(myItem1); }
public int InsertPosition(Position position, int ItemId) { string sqlString = @"INSERT INTO Position VALUES(@LATITUDE, @LONGITUDE, @ACCURACY, @DATE, @ITEMID)"; SqlParameter latitude = new SqlParameter(@"LATITUDE", position.Latitude); SqlParameter longitude = new SqlParameter(@"LONGITUDE", position.Longitude); SqlParameter accuracy = new SqlParameter(@"ACCURACY", position.Accuracy); SqlParameter date = new SqlParameter(@"DATE", position.Date); SqlParameter itemId = new SqlParameter(@"ITEMID", ItemId); int result = -1; using (var conn = new SqlConnection(connectionString)) { SqlCommand sqlCommand = new SqlCommand(sqlString, conn); sqlCommand.Parameters.Add(latitude); sqlCommand.Parameters.Add(longitude); sqlCommand.Parameters.Add(accuracy); sqlCommand.Parameters.Add(date); sqlCommand.Parameters.Add(itemId); try { conn.Open(); result = sqlCommand.ExecuteNonQuery(); } catch (Exception e) { } } return result; }
public List<Position> GetPositionsById(int id) { string sqlString = @"SELECT * FROM Position WHERE ItemID = @ID"; SqlParameter idParam = new SqlParameter("@ID", id); List<Position> result = new List<Position>(); using (var conn = new SqlConnection(connectionString)) { SqlCommand sqlCommand = new SqlCommand(sqlString, conn); sqlCommand.Parameters.Add(idParam); try { conn.Open(); SqlDataReader reader = sqlCommand.ExecuteReader(); while (reader.Read()) { Position position = new Position(); position.Latitude = Convert.ToInt64(reader[1].ToString()); position.Longitude = Convert.ToInt64(reader[2].ToString()); position.Accuracy = Convert.ToInt32(reader[3].ToString()); position.Date = Convert.ToDateTime(reader[4].ToString()); result.Add(position); } } catch (Exception e) { throw; } } return result; }