Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > .NET Framework > Forum > ช่วยดูโค้ตให้หน่อยค่ะ เกี่ยวกับส่งค่าพิกัดกลับค่ะ ถ้าต้องการให้โปรแกรมเมื่อรับ sms แล้วโปรแกรมจะส่งค่าพิกัดกลับทุก 5 นาที



 

ช่วยดูโค้ตให้หน่อยค่ะ เกี่ยวกับส่งค่าพิกัดกลับค่ะ ถ้าต้องการให้โปรแกรมเมื่อรับ sms แล้วโปรแกรมจะส่งค่าพิกัดกลับทุก 5 นาที

 



Topic : 038733

Guest




ถ้าต้องการให้โปรแกรมเมื่อรับ sms แล้วโปรแกรมจะส่งค่าพิกัดกลับทุก 5 นาที ต้องแก้โค้ตตรงไหนบ้างค่ะ
โค้ตดังนี้ค่ะ

Code (C#)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Threading;
using System.IO;
using Microsoft.WindowsMobile.Status;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.PocketOutlook.MessageInterception;
using Microsoft.WindowsMobile.Samples.Location;
using CoreServices;
namespace Myproject
{
    public partial class Form1 : Form, IDisposable
    {
        #region Delegates
        delegate void VoidDelegate();
        #endregion

        #region Delegates
        MessageInterceptorEventHandler _messageInterceptorEventHandler = null;
        #endregion

        #region private fields
        MessageInterceptor _messageInterceptor;
        Gps gps;
        FindMeSettings _Settings = new FindMeSettings();
        string _assemblyFolder;
        String ruleName = "Myproject[InterceptRule]";
        string responseTemplate = "http://maps.live.com/default.aspx?v=2&cp={0:0.000000}~{1:0.000000}&style=a&lvl=17&alt=-1000&sp=an.{0:0.000000}_{1:0.000000}____&encType=1";
        string detailedResponseTemplate = "http://local.live.com/default.aspx?v=2&cp={0:0.000000}~{1:0.000000}&style=r&lvl=16&tilt=-90&dir=0&alt=-1000&sp=an.{0:0.000000}_{1:0.000000}_{3}_{4}__{2}&encType=1";
        GpsPosition currentPosition = null;
        object SyncLock = new Object();
        #endregion

        #region Constructors
        public Form1()
        {
            InitializeComponent();
            LoadSettings();
            _messageInterceptorEventHandler = new MessageInterceptorEventHandler(this._messageInterceptor_MessageReceived);
        }
        #endregion

        #region Properties
        public string AssemblyFolder
        {
            get
            {
                if(_assemblyFolder==null)
                {
                    string fullPath = this.GetType().Module.FullyQualifiedName;
                    string asmName = this.GetType().Module.Name;
                    _assemblyFolder = fullPath.Substring(0, fullPath.LastIndexOf(asmName));
                }
                return _assemblyFolder;
            }
        }
        #endregion

        #region event handlers
        void gps_LocationChanged(object sender, LocationChangedEventArgs args)
        {
            if (args.Position.LatitudeValid && args.Position.LongitudeValid)
            {
                lock (SyncLock)
                {
                    currentPosition = args.Position;
                }
                UpdatePosition();
            }
        }
        private void menuItemExit_Click(object sender, EventArgs e)
        {
            ApplyChanges();
            CloseGps();
            this.Close();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            BeginTrackingLocation();
            if (MessageInterceptor.IsApplicationLauncherEnabled(ruleName))
            {
                _messageInterceptor = new MessageInterceptor(ruleName);
                _messageInterceptor.MessageReceived += new MessageInterceptorEventHandler(_messageInterceptor_MessageReceived);
                txtPin.Text = _messageInterceptor.MessageCondition.ComparisonValue;
                this.chkFindMeEnabled.Checked = true;
            }
            else
            {
                this.chkFindMeEnabled.Checked = false;
            }
            PopulateContactList();
        	}
        void _messageInterceptor_MessageReceived(object sender, MessageInterceptorEventArgs e)
        {
            if (this.currentPosition == null)
            {
                GpsPosition pos = gps.GetPosition(new TimeSpan(0, 0, 30));
                if (pos != null)
                {
                    lock (SyncLock)
                    {
                        currentPosition = pos;
                    }
                }
            }
            if (currentPosition != null)
{
                    if (_Settings.IsAllowed(e.Message.From.Address)||_Settings.PermissionType==PermissionType.AllowAll)
                    {
                        string emailAddress = null;
                        if ((_Settings.OptionFlags & OptionChangedFlags.Email) == (OptionChangedFlags.Email))
                            emailAddress = _Settings.FindEmailAddress(e.Message.From.Address);
                        lock (SyncLock)
                        {
                            if (emailAddress != null)
                                this.EmailSendCoordinates(emailAddress, this.currentPosition);
                            else
                                SmsSendCoordinates(e.Message.From.Address, this.currentPosition);
                        }
                        if ((_Settings.OptionFlags & OptionChangedFlags.Alert) == OptionChangedFlags.Alert)
                            Sound.PlayFile(AssemblyFolder + "Alert.wav");
                    }
            }
        }
        private void Form1_Closing(object sender, CancelEventArgs e)
        {
            this.CloseGps();
        }
        private void rbAllowListed_CheckedChanged(object sender, EventArgs e)
        {
            EnablePermissionList();
        }
        private void rbAllowAnyone_CheckedChanged(object sender, EventArgs e)
        {
            DisablePermissionList();
        }
        private void menuItemApply_Click(object sender, EventArgs e)
        {
            ApplyChanges();
        }
#endregion

        #region methods
        void ApplyChanges()
        {
            if (_messageInterceptor != null)
            {
                _messageInterceptor.DisableApplicationLauncher();
                _messageInterceptor.MessageReceived -= _messageInterceptorEventHandler;
                _messageInterceptor.Dispose();
                _messageInterceptor = null;
            }
            if (this.chkFindMeEnabled.Checked)
            {
                try
                {
                    if (_messageInterceptor == null)
                    {
                        _messageInterceptor = new MessageInterceptor(InterceptionAction.NotifyAndDelete);
                    }
                    _messageInterceptor.MessageCondition = new MessageCondition();
                    _messageInterceptor.MessageCondition.CaseSensitive = false;
                    _messageInterceptor.MessageCondition.ComparisonType = MessagePropertyComparisonType.Contains;
                    _messageInterceptor.MessageCondition.ComparisonValue = this.txtPin.Text;
                    _messageInterceptor.MessageCondition.Property = MessageProperty.Body;
                    _messageInterceptor.EnableApplicationLauncher(ruleName);
                    _messageInterceptor.MessageReceived += _messageInterceptorEventHandler;
                }
                catch (PocketOutlookException pEx)
                {
                    MessageBox.Show(pEx.Message);
                }
              }
            SaveSettings();
        }

        private void BeginTrackingLocation()
        {
            gps = new Gps();            
            gps.LocationChanged += new LocationChangedEventHandler(gps_LocationChanged);
            gps.Open();
        }
        void DisablePermissionList()
        {
            //this.lvContacts.Enabled = false;
        }
        void EnablePermissionList()
        {
            this._Settings.PermissionType = PermissionType.AllowListed;
        }
        private void LoadSettings()
        {
            FileInfo fi = new FileInfo(AssemblyFolder + "settings.config");
            if (fi.Exists)
            {
                Stream s = fi.OpenRead();
                this._Settings=FindMeSettings.Load(s);
                if (_Settings.PermissionType == PermissionType.AllowListed)
                    this.rbAllowListed.Checked = true;
                if (_Settings.PermissionType == PermissionType.AllowAll)
                    this.rbAllowAnyone.Checked = true;
                else
                    this.rbAllowListed.Checked = true;
                s.Close();
            }
        }
        private void SaveSettings()
        {
            FileInfo fi = new FileInfo(AssemblyFolder+"settings.config");
            Stream s;
            _Settings.PermissionType = (this.rbAllowAnyone.Checked) ? PermissionType.AllowAll : PermissionType.AllowListed;
            _Settings.Save(s=fi.Open(FileMode.Create));
            s.Close();
        }
        void UpdatePosition()
        {
            if (this.InvokeRequired)
            {
                this.Invoke((new VoidDelegate(this.UpdatePosition)));
            }
            else
            {
                if (this.currentPosition != null)
                {
                    this.txtLatitude.Text = String.Format("{0:0.000000}", this.currentPosition.Latitude);
                    this.txtLongitude.Text = String.Format("{0:0.000000}", this.currentPosition.Longitude);
                }
                else
                {
                    this.txtLatitude.Text = this.txtLongitude.Text = string.Empty;
                }
            }
        }
        public void SmsSendCoordinates(string to,GpsPosition pos)
        {
                string message = String.Format(responseTemplate, pos.Latitude, pos.Longitude);
                SmsMessage sms = new SmsMessage(to, message);
                sms.Send();
                this.eventLog.Add(DateTime.Now, to, pos);
        }
        public void EmailSendCoordinates(string emailAddress, GpsPosition pos)
        {
            string avatarUrl = string.Empty;
            string displayName = string.Empty;
            string customMessage=string.Empty;
if(((_Settings.OptionFlags&OptionChangedFlags.Avatar)==OptionChangedFlags.Avatar)&&(_Settings.Avatar.Length>0))
                avatarUrl=_Settings.Avatar;
            string message = String.Format(detailedResponseTemplate, pos.Latitude, pos.Longitude, Utility.UrlEncode(avatarUrl), Utility.UrlEncode(displayName), Utility.UrlEncode(customMessage));
            EmailAccount account = (new OutlookSession()).EmailAccounts[_Settings.EmailAccount];
            EmailMessage msg = new EmailMessage();
            msg.To.Add(new Recipient(emailAddress));
            msg.Subject = "My location";
            msg.BodyText = message;
            msg.Send(account);
            this.eventLog.Add(DateTime.Now, emailAddress, pos);
        }
        #endregion
        void CloseGps()
        {
            if (this.gps != null)
                if (this.gps.Opened)
                {
                    this.gps.Close();
                }
            gps = null;

        }
        void PopulateContactList()
        {
            OutlookSession os = new OutlookSession();
            ContactCollection contactList = os.Contacts.Items;
            for (int i = 0; i < contactList.Count; ++i)
            {
                Contact contact = contactList[i];
                if ((contact.FirstName.Length > 0) || (contact.LastName.Length > 0))
                {
                    ListViewItem lvi = new ListViewItem(new string[] { contact.FirstName, contact.LastName });
                    lvi.Tag = contact;
                    lvi.ImageIndex = (_Settings.IsAllowed(contact)?1:0);
                    lvi.Checked = _Settings.IsAllowed(contact);
                                                  
                }
            }
        }

        #endregion
    }
}






Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-02-11 01:59:44 By : KARAKED View : 1279 Reply : 2
 

 

No. 1



โพสกระทู้ ( 373 )
บทความ ( 0 )



สถานะออฟไลน์


Code (C#)
if (this.currentPosition == null)<<< Loop รอบแรก มันเข้า If นี้ แต่พอ Loop รอบที่ สอง มันไม่เข้าแล้ว เพราะมันได้ค่าจาก Loop แรกแล้ว มันเลยไม่เป็น Null อีก ทำไห้ไม่ได้พิกัดใหม่
            {
                GpsPosition pos = gps.GetPosition(new TimeSpan(0, 0, 30));
                if (pos != null)
                {
                    lock (SyncLock)
                    {
                        currentPosition = pos;
                    }
                }
            }
            if (currentPosition != null) <<< พอมาตรงนี้มันเลยส่งแต่พิกัดเดิม
            {
                if (_Settings.IsAllowed(e.Message.From.Address) || _Settings.PermissionType == PermissionType.AllowAll)
                {
                    string emailAddress = null;
                    if ((_Settings.OptionFlags & OptionChangedFlags.Email) == (OptionChangedFlags.Email))
                        emailAddress = _Settings.FindEmailAddress(e.Message.From.Address);
                    lock (SyncLock)
                    {
                        if (emailAddress != null)
                            this.EmailSendCoordinates(emailAddress, this.currentPosition);
                        else
                            SmsSendCoordinates(e.Message.From.Address, this.currentPosition);
                    }
                    if ((_Settings.OptionFlags & OptionChangedFlags.Alert) == OptionChangedFlags.Alert)
                        Sound.PlayFile(AssemblyFolder + "Alert.wav");
                }
            }







Date : 2010-02-12 10:34:25 By : numenoy
 


 

No. 2

Guest


ขอบคุณค่ะ จะลองทำดู
Date : 2010-02-14 01:04:33 By : KARAKED
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูโค้ตให้หน่อยค่ะ เกี่ยวกับส่งค่าพิกัดกลับค่ะ ถ้าต้องการให้โปรแกรมเมื่อรับ sms แล้วโปรแกรมจะส่งค่าพิกัดกลับทุก 5 นาที
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่