/// <summary>
        /// 在此页将要在 Frame 中显示时进行调用。
        /// </summary>
        /// <param name="e">描述如何访问此页的事件数据。
        /// 此参数通常用于配置页。</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Windows.Phone.UI.Input.HardwareButtons.BackPressed += (sender, arg) => { arg.Handled = true; };
            if (StaticObj.user is HeartLink_Lib.Student)
            {
                gridForStudent.Visibility    = Visibility.Visible;
                gridForSupervisor.Visibility = Visibility.Collapsed;
            }
            else
            {
                gridForSupervisor.Visibility = Visibility.Visible;
                gridForStudent.Visibility    = Visibility.Collapsed;
                AskOffList = new ContentCollection <AskOffContent>();
                StaticObj.SendPackets(DataParser.Str2Packets(Convert.ToInt32(CommandCode.GetAskOff), ""));

                Packet[] incommingAskOff = await StaticObj.ReceivePackets();

                if (DataParser.GetPacketCommandCode(incommingAskOff[0]) == Convert.ToInt32(CommandCode.ReturnAskOff))
                {
                    List <Dictionary <string, string> > jsonAskOffs = JsonParser.DeserializeListOfDictionaryObject(DataParser.Packets2Str(incommingAskOff));

                    foreach (Dictionary <string, string> con in jsonAskOffs)
                    {
                        AskOffContent temp = new AskOffContent();
                        temp.Reason = con["REASON"];
                        temp.ID     = con["ID"];
                        temp.Date   = con["ASKOFFDATE"];
                        temp.Time   = con["ASKOFFTIME"];
                        AskOffList.Add(temp);
                    }

                    display.ItemsSource = AskOffList;
                }
            }
        }
        /// <summary>
        /// 在此页将要在 Frame 中显示时进行调用。
        /// </summary>
        /// <param name="e">描述如何访问此页的事件数据。
        /// 此参数通常用于配置页。</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Windows.Phone.UI.Input.HardwareButtons.BackPressed += (sender, arg) => { arg.Handled = true; };
            Contacters = new ContentCollection <ContactorContent>();
            MessageBox = new ContentCollection <MessageBoxContent>();

            #region GetContacters
            Dictionary <string, string> commandPair = new Dictionary <string, string>();
            commandPair.Add("ID", StaticObj.user.ID);
            Packet[] packets = DataParser.Str2Packets(Convert.ToInt32(CommandCode.GetContacters), JsonParser.SerializeObject(commandPair));
            StaticObj.SendPackets(packets);

            Packet[] incommingContacters = await StaticObj.ReceivePackets();

            if (DataParser.GetPacketCommandCode(incommingContacters[0]) == Convert.ToInt32(CommandCode.ReturnContacters))
            {
                List <Dictionary <string, string> > jsonContacters = JsonParser.DeserializeListOfDictionaryObject(DataParser.Packets2Str(incommingContacters));

                foreach (Dictionary <string, string> con in jsonContacters)
                {
                    ContactorContent listContent = new ContactorContent();
                    listContent.Name     = con["NAME"];
                    listContent.PhoneNum = con["CELLPHONE"];
                    Contacters.Add(listContent);
                }
            }
            #endregion

            #region GetMessageBox
            packets = DataParser.Str2Packets(Convert.ToInt32(CommandCode.GetMessageBox), "");
            StaticObj.SendPackets(packets);

            Packet[] incommingMessageBox = await StaticObj.ReceivePackets();

            if (DataParser.GetPacketCommandCode(incommingMessageBox[0]) == Convert.ToInt32(CommandCode.ReturnMessageBox))
            {
                List <Dictionary <string, string> > jsonMessageBox = JsonParser.DeserializeListOfDictionaryObject(DataParser.Packets2Str(incommingMessageBox));

                foreach (Dictionary <string, string> msg in jsonMessageBox)
                {
                    MessageBoxContent listContent = new MessageBoxContent();
                    listContent.ID = msg["ID"];
                    if (msg["ISFROMSTUDENT"].Equals("1"))
                    {
                        listContent.Type = "Student";
                    }
                    else
                    {
                        listContent.Type = "Supervisor";
                    }
                    //listContent.Type = msg["TYPE"];
                    listContent.Time    = msg["SENDTIME"];
                    listContent.Content = msg["CONTENT"];
                    MessageBox.Add(listContent);
                }
            }
            #endregion

            if (StaticObj.user is HeartLink_Lib.Student)
            {
                WorkServiceForStudent.Visibility    = Visibility.Visible;
                WorkServiceForSupervisor.Visibility = Visibility.Collapsed;

                StaticObj.SendPackets(DataParser.Str2Packets(Convert.ToInt32(CommandCode.GetDailyReminder), ""));

                Packet[] incommingDailyReminder = await StaticObj.ReceivePackets();

                DailyReminderDisplay dis = new DailyReminderDisplay();
                if (DataParser.GetPacketCommandCode(incommingDailyReminder[0]) == Convert.ToInt32(CommandCode.ReturnDailyReminder))
                {
                    Dictionary <string, string> dailyReminder = JsonParser.DeserializeObject(DataParser.Packets2Str(incommingDailyReminder));
                    dis.ReminderTime    = dailyReminder["REMINDTIME"];
                    dis.ReminderContent = dailyReminder["CONTENT"];
                }
                WorkServiceForStudent.DataContext = dis;
            }
            else
            {
                WorkServiceForSupervisor.Visibility = Visibility.Visible;
                WorkServiceForStudent.Visibility    = Visibility.Collapsed;
            }
        }
Beispiel #3
0
        /// <summary>
        /// 在此页将要在 Frame 中显示时进行调用。
        /// </summary>
        /// <param name="e">描述如何访问此页的事件数据。
        /// 此参数通常用于配置页。</param>
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            Windows.Phone.UI.Input.HardwareButtons.BackPressed += (sender, arg) => { arg.Handled = true; };

            locationBox.Clear();

            Geolocator       geolocator         = new Geolocator();
            Geoposition      geoposition        = null;
            BasicGeoposition supervisorPosition = new BasicGeoposition();

            try
            {
                geoposition = await geolocator.GetGeopositionAsync();

                supervisorPosition.Longitude = geoposition.Coordinate.Point.Position.Longitude;
                supervisorPosition.Latitude  = geoposition.Coordinate.Point.Position.Latitude;
                supervisorPosition.Altitude  = geoposition.Coordinate.Point.Position.Altitude;

                MapIcon supervisorIcon = new MapIcon();
                supervisorIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/PinkPushPin.png"));
                supervisorIcon.NormalizedAnchorPoint = new Point(0.25, 0.9);
                supervisorIcon.Location = new Geopoint(supervisorPosition);

                MapControl.Center = geoposition.Coordinate.Point;
            }
            catch { }

            StaticObj.SendPackets(DataParser.Str2Packets(Convert.ToInt32(CommandCode.GetLocation), ""));

            Packet[] incomming = await StaticObj.ReceivePackets();

            if (DataParser.GetPacketCommandCode(incomming[0]) == Convert.ToInt32(CommandCode.ReturnLocation))
            {
                List <Dictionary <string, string> > locationDict = JsonParser.DeserializeListOfDictionaryObject(DataParser.Packets2Str(incomming));
                foreach (Dictionary <string, string> dic in locationDict)
                {
                    BasicGeoposition position = new BasicGeoposition();
                    position.Longitude = Convert.ToDouble(dic["LONGITUDE"]);
                    position.Latitude  = Convert.ToDouble(dic["LATITUDE"]);
                    position.Altitude  = Convert.ToDouble(dic["ALTITUDE"]);

                    MapIcon studentIcon = new MapIcon();
                    studentIcon.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/PinkPushPin.png"));
                    studentIcon.NormalizedAnchorPoint = new Point(0.25, 0.9);
                    studentIcon.Location = new Geopoint(position);

                    MapControl.MapElements.Add(studentIcon);

                    LocationContent locationContent = new LocationContent();
                    locationContent.ID             = dic["ID"];
                    locationContent.Time           = dic["TIME"];
                    locationContent.PositionSource = dic["POSITIONSOURCE"];
                    double distance = GetDistance(geoposition.Coordinate.Point.Position.Latitude, geoposition.Coordinate.Point.Position.Longitude,
                                                  Convert.ToDouble(dic["LATITUDE"]), Convert.ToDouble(dic["LONGITUDE"]));
                    if (distance < 1000)
                    {
                        locationContent.Distance = "距离:" + distance.ToString("0.0") + "米";
                    }
                    else
                    {
                        locationContent.Distance = "距离:" + (distance / 1000).ToString("0.00") + "千米";
                    }
                    double azimuth = GetAzimuth(geoposition.Coordinate.Point.Position.Latitude, geoposition.Coordinate.Point.Position.Longitude,
                                                Convert.ToDouble(dic["LATITUDE"]), Convert.ToDouble(dic["LONGITUDE"]));
                    if (azimuth == 0)
                    {
                        locationContent.Azimuth = "北";
                    }
                    else if (azimuth > 0 && azimuth < 90)
                    {
                        locationContent.Azimuth = "北偏东\t" + azimuth.ToString("0.000") + "°";
                    }
                    else if (azimuth == 90)
                    {
                        locationContent.Azimuth = "东";
                    }
                    else if (azimuth > 90 && azimuth < 180)
                    {
                        locationContent.Azimuth = "南偏东\t" + (180 - azimuth).ToString("0.000") + "°";
                    }
                    else if (azimuth == 180)
                    {
                        locationContent.Azimuth = "南";
                    }
                    else if (azimuth > 180 && azimuth < 270)
                    {
                        locationContent.Azimuth = "南偏西\t" + (azimuth - 270).ToString("0.000") + "°";
                    }
                    else if (azimuth == 270)
                    {
                        locationContent.Azimuth = "西";
                    }
                    else if (azimuth > 270 && azimuth < 360)
                    {
                        locationContent.Azimuth = "北偏西\t" + (360 - azimuth).ToString("0.000") + "°";
                    }

                    locationBox.Add(locationContent);
                }
                InspectionList.ItemsSource = locationBox;
            }

            ProgressBar.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
        }