Discussion Board

Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 51
  1. #31
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    What is suggested in the link in #28 works fine and that's the way it should be work. Bottomline is, calling saveAppointmentTask.Show();, would open up the native calender app, saving the specified appointment. After saving when navigating back to app, inside the OnNavigatedTo function, take the second value from the observable collection and call the appointment creating function once again(remove that foreach loop and simply create a function to create an appointment which is called repetitively on navigating to the page ), repeat this for all the values inside Observable collection.

    Declare the Observable collection at the top of class, so its visible to the whole class instead of being local and can be utilized when using it inside OnNavigatedTo() to fetch the values from it.

  2. #32
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    Sorry actually my english is very bad, it's hard for me to understand, is it possible for you to show me please?

  3. #33
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    This should work :

    Code:
    public partial class MainPage : PhoneApplicationPage
        {
            ObservableCollection<RootObject> SwitchCal;
             int rootobjindex = 0;
            public MainPage()
            {
                InitializeComponent();
    
                try
                {
                    WebClient webClient = new WebClient();
                    Uri uri = new Uri("http://switch-eip.cloudapp.net/clubs/1/events.json");
                    webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
                    webClient.OpenReadAsync(uri);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "error came here 1");
                }
            }
    
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                if(SwitchCal!=null)
                {
                    if(rootobjindex<SwitchCal.Count())
                         SaveToCalender();
                }
            }
    
            void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            {
                try
                {
                   DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ObservableCollection<RootObject>));
                   SwitchCal = ser.ReadObject(e.Result) as ObservableCollection<RootObject>;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "error came here 2" + ex.StackTrace);
                }
    
                if (SwitchCal != null)
                {
                    if (rootobjindex < SwitchCal.Count())
                        SaveToCalender();
                }
            }
    
        private void SaveToCalender()
        {
             
            SaveAppointmentTask saveAppointmentTask = new SaveAppointmentTask();
            var ci = new CultureInfo("en-us");
            var inputString = SwitchCal[rootobjindex].start;
            var Start = DateTime.Parse(inputString, ci);
            var outputString = SwitchCal[rootobjindex].end;
            var End = DateTime.Parse(outputString, ci);
    
            saveAppointmentTask.StartTime = Start;
            saveAppointmentTask.EndTime = End;
            saveAppointmentTask.Subject = SwitchCal[rootobjindex].title;
            saveAppointmentTask.IsAllDayEvent = SwitchCal[rootobjindex].allDay;
            saveAppointmentTask.Show();
            rootobjindex++;
        }
    
            public class RootObject
            {
                public int id { get; set; }
                public string title { get; set; }
                public string start { get; set; }
                public string end { get; set; }
                public bool allDay { get; set; }
                public bool editable { get; set; }
                public int club_id { get; set; }
            }
        }
    }

  4. #34
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    Thank you so much ^^
    i have another question, is it possible to hide the step where you must save the Appointment in the native calendar?

  5. #35
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    Quote Originally Posted by Patoche View Post
    i have another question, is it possible to hide the step where you must save the Appointment in the native calendar?
    No, that is not possible, you cannot securely create an appointment. SaveAppointmentTask.Show(); must be called in order to save the appointment which thereby launches native calender app.

  6. #36
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    is it any parser which can check if the appointment is already in native calendar. if it isn't just add. if it's do not add

  7. #37
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    Quote Originally Posted by Patoche View Post
    is it any parser which can check if the appointment is already in native calendar. if it isn't just add. if it's do not add
    'Appointments' class can perform this task : http://msdn.microsoft.com/en-US/libr...v=vs.105).aspx

  8. #38
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    Is it possible to show me what should I do in my actual code. please

  9. #39
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    You should be trying first yourself and if any issues appear you can always ask here. Go through the link carefully and try implement what is suggested there, it even has code snippet.

  10. #40
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    i tried all the day to match my code with the link that's you sent to me but i can't. it makes me crazy

  11. #41
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    You can try explaining what you tried and what failed/succeeded

  12. #42
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    I used the method Data-binding appointment data results and tried to follow what he did and instead of display the results I just tried to add if it doesn't exist and it does nothing if it exists but it didn't work nothing happened when I launched

  13. #43
    Nokia Developer Champion
    Join Date
    Jun 2008
    Location
    Gurgaon,India
    Posts
    4,112

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    Made some changes in the code using the Appointments class(see bold line) :

    Code:
    public partial class MainPage : PhoneApplicationPage
        {
            ObservableCollection<RootObject> SwitchCal;
            Appointments appts = new Appointments();
            SaveAppointmentTask saveAppointmentTask;
             int rootobjindex = 0;
            public MainPage()
            {
                InitializeComponent();
                
    
                //Identify the method that runs after the asynchronous search completes.
                appts.SearchCompleted += new EventHandler<AppointmentsSearchEventArgs>(Appointments_SearchCompleted);
                try
                {
                    WebClient webClient = new WebClient();
                    Uri uri = new Uri("http://switch-eip.cloudapp.net/clubs/1/events.json");
                    webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
                    webClient.OpenReadAsync(uri);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "error came here 1");
                }
            }
    
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
            {
                if(SwitchCal!=null)
                {
                    if(rootobjindex<SwitchCal.Count())
                         SaveToCalender();
                }
            }
    
            void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
            {
                try
                {
                   DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(ObservableCollection<RootObject>));
                   SwitchCal = ser.ReadObject(e.Result) as ObservableCollection<RootObject>;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + "error came here 2" + ex.StackTrace);
                }
    
                if (SwitchCal != null)
                {
                    if (rootobjindex < SwitchCal.Count())
                        SaveToCalender();
                }
            }
    
        private void SaveToCalender()
        {
             
            saveAppointmentTask = new SaveAppointmentTask();
            var ci = new CultureInfo("en-us");
            var inputString = SwitchCal[rootobjindex].start;
            var Start = DateTime.Parse(inputString, ci);
            var outputString = SwitchCal[rootobjindex].end;
            var End = DateTime.Parse(outputString, ci);
    
            saveAppointmentTask.StartTime = Start;
            saveAppointmentTask.EndTime = End;
            saveAppointmentTask.Subject = SwitchCal[rootobjindex].title;
            saveAppointmentTask.IsAllDayEvent = SwitchCal[rootobjindex].allDay;
            appts.SearchAsync(Start, End, 5, "Appointments Test #1");
        }
    
        void Appointments_SearchCompleted(object sender, AppointmentsSearchEventArgs e)
        {
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
    
           
            foreach (Appointment appt in e.Results)
            {
                if (appt.StartTime == saveAppointmentTask.StartTime && appt.StartTime == saveAppointmentTask.EndTime && appt.Subject == saveAppointmentTask.Subject && !appt.IsAllDayEvent)
                {
    
                }
                else
                {
                    saveAppointmentTask.Show();
                    rootobjindex++;
                }
            }
        }
            public class RootObject
            {
                public int id { get; set; }
                public string title { get; set; }
                public string start { get; set; }
                public string end { get; set; }
                public bool allDay { get; set; }
                public bool editable { get; set; }
                public int club_id { get; set; }
            }
        }
    }
    The code snippet added may not be fully accurate in finding the exact match for an existing appointment but will give you a fair idea as how to do it. The comparison made inside Appointments_SearchCompleted() needs to be corrected i think.

  14. #44
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    I'ill try to launch the code.it launched successful but nothing happened i can't even add Appointment. Do you know why?

  15. #45
    Registered User
    Join Date
    Jul 2014
    Posts
    29

    Re: [Moved]Windows Phone SaveAppointmentTask and Json Parsing

    i have a question. Is it possible to create a button and then when we click it, it will go directly in the emulator's calendar

Similar Threads

  1. SOAP Parsing in windows phone
    By mandardac in forum Windows Phone General
    Replies: 2
    Last Post: 2012-11-01, 18:37
  2. XML Parsing for windows phone 7
    By sreerajvr in forum Windows Phone General
    Replies: 2
    Last Post: 2012-03-19, 08:41
  3. JSON parsing in QT?
    By sindhuks in forum Qt
    Replies: 7
    Last Post: 2011-03-29, 22:44
  4. JSON Parsing
    By raja_salomo in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2009-09-25, 08:50

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×