/// <summary> /// Inserts a new map polygon into the database. /// </summary> /// <param name="item">Object containing porperties to be inserted into the database.</param> public static async Task InsertMapPolygonItemAsync(MapPolygonItem item) { using (var cnn = await GetDbConnectionAsync()) { cnn.Open(); item.Id = (int)await cnn.ExecuteScalarAsync <long>( @"INSERT INTO MapElement (Name, Type, StrokeColor, FillColor, Layer_Id) VALUES (@Name, @Type, @StrokeColor, @FillColor, @Layer_Id); SELECT last_insert_rowid();", new { item.Name, Type = "MapPolygonItem", StrokeColor = StringColorConverter.ArgbColorToString(item.StrokeColor), FillColor = StringColorConverter.ArgbColorToString(item.FillColor), Layer_Id = item.ParentLayer.Id }); var list = from g in item.Path select new { g.Altitude, g.Latitude, g.Longitude, MapElement_Id = item.Id }; await cnn.ExecuteAsync( @"INSERT INTO Geoposition (Altitude, Latitude, Longitude, MapElement_Id) VALUES (@Altitude, @Latitude, @Longitude, @MapElement_Id)", list); } }
public void ArgbColorToString_InputWhite_ReturnFFFFFFFF() { var input = Color.FromArgb(255, 255, 255, 255); var result = StringColorConverter.ArgbColorToString(input); var expect = "FFFFFFFF"; Assert.AreEqual(expect, result, $@"Returned color not as expected. Expected: {expect}, Actual: {result}"); }
public void ArgbStringToColor_InputFFFFFFFF_ReturnWhite() { var input = "#FFFFFFFF"; var result = StringColorConverter.ArgbStringToColor(input); var expect = Color.FromArgb(255, 255, 255, 255); Assert.AreEqual(expect, result, $@"Returned color not as expected. Expected: {expect}, Actual: {result}"); }
/// <summary> /// Gets list of all map polygons stored in the database. /// </summary> /// <returns><b>List</b> containing <b>MapPolygonItem</b> objects populated with data from database.</returns> public static async Task <List <MapPolygonItem> > GetMapPolygonItemsAsync() { var result = new List <MapPolygonItem>(); using (var cnn = await GetDbConnectionAsync()) { cnn.Open(); var sqlcommand = @"SELECT m.Id, m.Name, m.StrokeColor, m.FillColor, l.Id, l.Name, g.Altitude, g.Latitude, g.Longitude FROM ((MapElement m INNER JOIN Layer l ON m.Layer_Id = l.Id) INNER JOIN Geoposition g ON m.Id = g.MapElement_Id) WHERE m.Type='MapPolygonItem'"; var anons = new List <TmpMapElementContainer>(); cnn.Query <dynamic, MapLayerItem, BasicGeoposition, int>(sqlcommand, (polyline, layer, pos) => { if (anons.Count == 0 || anons.Last().Id != polyline.Id) { anons.Add(new TmpMapElementContainer() { Id = (int)polyline.Id, Name = polyline.Name, StrokeColor = StringColorConverter.ArgbStringToColor((string)polyline.StrokeColor), FillColor = StringColorConverter.ArgbStringToColor((string)polyline.FillColor), Layer = layer }); } anons.Last().Path.Add(pos); return(0); }, splitOn: "Id,Altitude").ToList(); for (int i = 0; i < anons.Count; i++) { result.Add(MapElementItemFactoryService.GetMapPolygonItem(anons[i].Name, anons[i].Path, anons[i].Layer, anons[i].StrokeColor, anons[i].FillColor, anons[i].Id)); } } return(result); }
private void GetEditorAndConverter(Type type, out object editor, out TypeConverter converter) { editor = null; converter = null; if (type == null) { return; } if (type == typeof(Color)) { var colorpicker = new Sce.Atf.Controls.PropertyEditing.ColorPickerEditor(); colorpicker.EnableAlpha = true; editor = colorpicker; converter = new StringColorConverter(); } else if (type.IsEnum) { editor = new LongEnumEditor(type); } //// First check for very common type names and custom names. //switch (type) //{ // case typeof(Color) // break; // //case "string": //short for "System.String" // // return typeof(string); // //case "int": //short for "System.Int32" // // return typeof(int); // //case "float": //short for "System.Single" // // return typeof(float); // //case "char": //short for "System.Char" // // return typeof(char); // //case "byte": //short for "System.Byte" // // return typeof(byte); //} }
private void GetEditorAndConverter(Type type, out object editor, out TypeConverter converter) { editor = null; converter = null; if (type == null) { return; } if (type == typeof(Color)) { var colorpicker = new Sce.Atf.Controls.PropertyEditing.ColorPickerEditor(); colorpicker.EnableAlpha = true; editor = colorpicker; converter = new StringColorConverter(); } else if (type.IsEnum) { editor = new LongEnumEditor(type); } }
private void GetEditorAndConverter(Type type, out object editor, out TypeConverter converter) { editor = null; converter = null; if (type == null) return; if (type == typeof(Color)) { var colorpicker = new Sce.Atf.Controls.PropertyEditing.ColorPickerEditor(); colorpicker.EnableAlpha = true; editor = colorpicker; converter = new StringColorConverter(); } else if (type.IsEnum) { editor = new LongEnumEditor(type); } }