UWP php iCare地理信息服务平台

空间信息移动服务的实践课结束了,昨天给老师演示了大作业,老师说功能都实现了,但是UI做的怎么这么丑啊。。

记录下期间用到的东西。

  1. 数据库,张先生给装了个phpMyAdmin来管理数据库,然后我在电脑上用xshell来用命令行语言操作服务器(这么描述?)所以,简单的连接服务器后,cd 命令进入项目所在的文件夹,rz 上传文件,rm 文件名 移除文件,vi 文件名 查看文件,i 对文件进行编辑,编辑完成后’esc’退出编辑,:q 退出,mysql -u root -p 回车然后输入密码进入数据库。
  2. PHP,帮助文档看这里→http://php.net/manual/en/mysqli-stmt.prepare.php ,$title = $_GET[“title”];这个可以从url里获取参数。在客户端用get方法向数据库上传数据,下面这个是从数据库取数据,存为xml文件
    <?php
    header(“Content-Type: text/xml”);
    $mysqli=new mysqli(“localhost”,”root”,”yourpassword”,”databasename”);
    if(mysqli_connect_errno()){
    printf(“Connect failed:%s\n”,mysqli_connect_error());
    exit();
    }
    $mysqli->set_charset(“utf8″);
    $query=”SELECT * FROM tablename ORDER BY id DESC”;
    $result = $mysqli->query($query) or die(“Invalid query:”.mysql_error());
    //建立xml,声明版本和编码
    $dom = new DOMDocument(“1.0″,”utf-8”);
    //格式化输出
    $dom->formatOutPut = true;
    //建立根节点root
    $root = $dom->createElement(“events”);
    $dom->appendChild($root);
    $dbtField = array(“id”,”title”,”time”,”latitude”,”longitude”,”description”,”validity”,”expectation”,”solved”,”location”,”image”);//数据表字段数组
    while($row = $result->fetch_row()){
    //建立root节点下的子节点record
    $record = $dom->createElement(“event”);
    for($i =0; $i < 11; $i++) {
    $node = $dom->createElement($dbtField[$i]);//表字段
    $nodeText = $dom->createTextNode($row[$i]);//表字段的值
    $node->appendChild($nodeText);
    $record->appendChild($node);
    }
    $root->appendChild($record);
    }
    $mysqli->close();
    echo $dom->saveXML();
    ?>

    网页返回的内容:Unnamed QQ Screenshot20160622110209
  3. C#&UWP  get请求如下

    获取网页xml如下

    public static string commentID;
    public static string eventID;
    public static string userName;
    public static string comContext;
    public static string commentTime;
    public static string replyto;
    
    /// <summary>
    /// 从网络获取的信息
    /// </summary>
    /// <param name=”eventID”></param>
    public async static void LoadXML(string eventID)
    {
    string suri = “http://xxx.xxx/xxx.php” ;
    Uri uri = new Uri(suri);
    //将网络获取的信息转化成XMLDoc对象
    XmlDocument doc = await XmlDocument.LoadFromUriAsync(uri);
    //获取根节点Events
    XmlElement events = doc.DocumentElement;
    //获取根节点的所有子节点列表
    XmlNodeList oneEventList = events.ChildNodes;
    //NotifyPopup lackMesPopup = new NotifyPopup(oneEventList.Count.ToString());
    //lackMesPopup.Show();
    foreach (IXmlNode oneEvent in oneEventList)
    {
    XmlNodeList info = oneEvent.ChildNodes;
    commentID = info.Item(0).InnerText;
    eventID = info.Item(1).InnerText;
    userName = info.Item(2).InnerText;
    comContext = info.Item(3).InnerText;
    commentTime = info.Item(4).InnerText;
    replyto = info.Item(5).InnerText;
    
    //如果要将xml存到本地,可以加上以下这些
    //获取事件清单的文件夹对象
    StorageFolder storage = await ApplicationData.Current.LocalFolder.GetFolderAsync(“EventsList”);
    //创建一个XML对象
    XmlDocument _doc = new XmlDocument();
    //使用event来创建一个XML元素作为根节点
    XmlElement _item = _doc.CreateElement(“event”);
    _item.SetAttribute(“id”, id);
    _item.SetAttribute(“title”, eventTitle);
    _item.SetAttribute(“currentTime”, currentTime);
    _item.SetAttribute(“description”, description);
    _doc.AppendChild(_item);
    //创建一个应用文件,如果已经存在那么就替换,使用 id+ 标题 作为文件名,也就是标识符
    StorageFile file = await storage.CreateFileAsync(eventTitle + “.xml”, CreationCollisionOption.ReplaceExisting);
    //把XML中的信息保存到文件中去
    await _doc.SaveToFileAsync(file);
    
    }


    在控件中显示

    //加载进来时显示事件详情
    protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
    //获取上一个清单列表传递过来的参数,该参数是一个StorageFile对象
    StorageFile file = e.Parameter as StorageFile;
    if (file == null) return;
    //获取文件的名字
    String itemName = file.DisplayName;
    //把应用文件作为一个XML文档加载进来
    XmlDocument doc = await XmlDocument.LoadFromFileAsync(file);
    
    id = doc.DocumentElement.Attributes.GetNamedItem(“id”).NodeValue.ToString();
    titleBlock.Text = doc.DocumentElement.Attributes.GetNamedItem(“title”).NodeValue.ToString();
    timeBlock.Text = doc.DocumentElement.Attributes.GetNamedItem(“description”).NodeValue.ToString();
    
    string imageName = doc.DocumentElement.Attributes.GetNamedItem(“image”).NodeValue.ToString();//图片名
    if (imageName != null)
    {
    string url = “http://mollmy.com/iCare/upload/images/” + imageName;
    
    photoImage.Visibility = Visibility.Visible;
    //从url获取图片
    photoImage.Source = new BitmapImage(new Uri(url));//在Image控件中显示来自web的图片
    }
    
    }


    上传图片

    public static void HttpUploadImage(string Path)
    {
    string URL = “http://xxx.xxx/upload/”;
    
    HttpUploadFile(URL, Path);
    }
    
    public static string FileName = null;
    //时间戳
    public static string GetTimeStamp()
    {
    TimeSpan ts = DateTime.UtcNow – new DateTime(1970, 1, 1, 0, 0, 0, 0);
    return Convert.ToInt64(ts.TotalSeconds).ToString();
    }
    
    private static async void HttpUploadFile(string URL, string Path)
    {
    
    HttpWebRequest _HttpWebRequest = WebRequest.Create(URL) as HttpWebRequest;
    //_HttpWebRequest.AllowAutoRedirect = true;
    
    _HttpWebRequest.Method = “POST”;
    
    string Boundary = DateTime.Now.Ticks.ToString(“X”);//随机分隔线
    
    _HttpWebRequest.ContentType = “multipart/form-data;charset=utf-8;boundary=” + Boundary;
    
    byte[] ItemBoundaryBytes = Encoding.UTF8.GetBytes(“\r\n–” + Boundary + “\r\n”);
    byte[] EndBoundaryBytes = Encoding.UTF8.GetBytes(“\r\n–” + Boundary + “–\r\n”);
    
    int Pos = Path.LastIndexOf(“\\”);//返回最后的反斜线 从0开始的的索引位置
    //string FileName = Path.Substring(Pos + 1);//文件名
    FileName = GetTimeStamp();//用时间戳给文件命名
    //请求头部信息
    StringBuilder HeaderStringBuilder = new StringBuilder(string.Format(“Content-Disposition:form-data;name=\”file\”;filename=\”{0}\”\r\nContent-Type:application/octet-stream\r\n\r\n”, FileName));
    byte[] PostHeaderBytes = Encoding.UTF8.GetBytes(HeaderStringBuilder.ToString());
    await Task.Run(async () =>
    {
    await Task.Yield();
    
    //使用指定的路径、创建模式和读/写权限初始化 FileStream 类的新实例。
    FileStream ReadFileStream = new FileStream(Path, FileMode.Open, FileAccess.Read);
    
    byte[] ContentBytes = new byte[ReadFileStream.Length];//要post的数据
    ReadFileStream.Read(ContentBytes, 0, ContentBytes.Length);
    ReadFileStream.Dispose();
    
    Stream PostStream = await _HttpWebRequest.GetRequestStreamAsync();
    PostStream.Write(ItemBoundaryBytes, 0, ItemBoundaryBytes.Length);
    PostStream.Write(PostHeaderBytes, 0, PostHeaderBytes.Length);
    PostStream.Write(ContentBytes, 0, ContentBytes.Length);//内容
    PostStream.Write(EndBoundaryBytes, 0, EndBoundaryBytes.Length);
    PostStream.Dispose();
    });
    
    //发送请求并获取响应回应数据
    HttpWebResponse _HttpWebResponse = await _HttpWebRequest.GetResponseAsync() as HttpWebResponse;
    //直到request.GetResponse()程序才开始向目标网页发送Post请求
    _HttpWebResponse.GetResponseStream();
    _HttpWebResponse.Dispose();
    }


     

    发布事件时上传图片,发布时选择图片并在canvas控件中显示参考了这里→

    检测图像或视频中的人脸

    文中有示例代码下载地址,下面是我修改后的

    private StorageFile Photo = null;//记录图片位置
    
    /// <summary>
    /// 点击添加图片
    /// </summary>
    /// <param name=”sender”></param>
    /// <param name=”e”></param>
    private async void AddPhoto_Click(object sender, RoutedEventArgs e)
    {
    WriteableBitmap displaySource = null;//显示图片
    
    try
    {
    FileOpenPicker photoPicker = new FileOpenPicker();
    photoPicker.ViewMode = PickerViewMode.Thumbnail;
    photoPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
    photoPicker.FileTypeFilter.Add(“.jpg”);
    
    StorageFile photoFile = await photoPicker.PickSingleFileAsync();
    
    if (photoFile == null)
    {
    return;
    }
    
    this.Photo = photoFile;//记录图片路径
    //上传图片
    UploadImage.HttpUploadImage(this.Photo.Path);
    this.ClearVisualization();
    
    //this.rootPage.NotifyUser(“Opening…”, NotifyType.StatusMessage);
    
    // 打开图像文件和位图解码到内存中。
    using (IRandomAccessStream fileStream = await photoFile.OpenAsync(Windows.Storage.FileAccessMode.Read))
    {
    BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);
    BitmapTransform transform = this.ComputeScalingTransformForSourceImage(decoder);
    
    using (SoftwareBitmap originalBitmap = await decoder.GetSoftwareBitmapAsync(decoder.BitmapPixelFormat, BitmapAlphaMode.Ignore, transform, ExifOrientationMode.IgnoreExifOrientation, ColorManagementMode.DoNotColorManage))
    {
    // Create a WritableBitmap for our visualization display; copy the original bitmap pixels to wb’s buffer.
    displaySource = new WriteableBitmap(originalBitmap.PixelWidth, originalBitmap.PixelHeight);//用于显示的图片
    originalBitmap.CopyToBuffer(displaySource.PixelBuffer);
    this.SetupVisualization(displaySource);//显示图片
    }
    }
    
    }
    catch (Exception ex)
    {
    this.ClearVisualization();//清空画布
    }
    }
    
    //清空画布
    private void ClearVisualization()
    {
    this.PhotoCanvas.Background = null;
    this.PhotoCanvas.Children.Clear();
    }
    
    private readonly uint sourceImageHeightLimit = 1280;
    
    /// <summary>
    /// 计算一个BitmapTransform缩减源图像,原图太大的话。
    /// </summary>
    /// <param name=”sourceDecoder”>Source image decoder</param>
    /// <returns>A BitmapTransform object holding scaling values if source image is too large</returns>
    private BitmapTransform ComputeScalingTransformForSourceImage(BitmapDecoder sourceDecoder)
    {
    BitmapTransform transform = new BitmapTransform();
    
    if (sourceDecoder.PixelHeight > this.sourceImageHeightLimit)
    {
    float scalingFactor = (float)this.sourceImageHeightLimit / (float)sourceDecoder.PixelHeight;
    
    transform.ScaledWidth = (uint)Math.Floor(sourceDecoder.PixelWidth * scalingFactor);
    transform.ScaledHeight = (uint)Math.Floor(sourceDecoder.PixelHeight * scalingFactor);
    }
    
    return transform;
    }
    
    /// <summary>
    /// 将图片在canvas中显示出来
    /// </summary>
    /// <param name=”displaySource”>Bitmap object holding the image we’re going to display</param>
    private void SetupVisualization(WriteableBitmap displaySource)
    {
    ImageBrush brush = new ImageBrush();
    brush.ImageSource = displaySource;
    brush.Stretch = Stretch.Uniform;
    this.PhotoCanvas.Background = brush;
    
    double widthScale = displaySource.PixelWidth / this.PhotoCanvas.ActualWidth;
    double heightScale = displaySource.PixelHeight / this.PhotoCanvas.ActualHeight;
    }


    主要的就是这些。

    定位是用win 10 自带的位置服务来获取经纬度,

    //获取当前地理位置信息
    Geoposition pos = await geolocator.GetGeopositionAsync();
    //纬度信息
    string latitude = pos.Coordinate.Point.Position.Latitude.ToString();
    //经度信息
    string longitude = pos.Coordinate.Point.Position.Longitude.ToString();

    导航是用的百度地图,使用webview控件显示。

  4. C#部分代码分享下 链接:http://pan.baidu.com/s/1boVkfT1 密码:nlin

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值