how to add event reminder to my windows phone 7 application - c#

I am building an app in windows phone 7 where i need to add an event reminder. On clicking a button the reminder should be set. My cs file is:
namespace KejriwalPhoneApp
{
public partial class EventDetails : PhoneApplicationPage
{
public EventDetails()
{
InitializeComponent();
ApplicationBar = new ApplicationBar();
ApplicationBar.Mode = ApplicationBarMode.Default;
ApplicationBar.Opacity = 1.0;
ApplicationBar.IsVisible = true;
ApplicationBarIconButton home = new ApplicationBarIconButton();
home.IconUri = new Uri("/Image/icon_home_deselect.png", UriKind.Relative);
home.Text = "Home";
ApplicationBar.Buttons.Add(home);
home.Click += new EventHandler(home_Click);
ApplicationBarIconButton share = new ApplicationBarIconButton();
share.IconUri = new Uri("/Image/icon_share_deselect.png", UriKind.Relative);
share.Text = "Share";
ApplicationBar.Buttons.Add(share);
share.Click += new EventHandler(share_Click);
ApplicationBarIconButton news = new ApplicationBarIconButton();
news.IconUri = new Uri("Image/icon_news_deselect.png", UriKind.Relative);
news.Text = "News";
ApplicationBar.Buttons.Add(news);
news.Click += new EventHandler(news_Click);
ApplicationBarIconButton events = new ApplicationBarIconButton();
events.IconUri = new Uri("/Image/icon_event_deselect.png", UriKind.Relative);
events.Text = "Video";
ApplicationBar.Buttons.Add(events);
events.Click += new EventHandler(events_Click);
}
void events_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
void news_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/News.xaml", UriKind.Relative));
}
void share_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/share.xaml", UriKind.Relative));
}
void home_Click(object sender, EventArgs e)
{
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
private void Image_Back(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
base.OnNavigatedTo(e);
var imagePath = "";
var eventdate = "";
var location = "";
var utimee = "";
var tzone = "";
var ename = "";
var desc = "";
//check if particular parameter available in uri string
if (this.NavigationContext.QueryString.ContainsKey("image_path"))
{
//if it is available, get parameter value
imagePath = NavigationContext.QueryString["image_path"];
eventimage.Source = new BitmapImage(new Uri(#"http://political-leader.vzons.com/ArvindKejriwal/images/uploaded/" + imagePath, UriKind.Absolute));
}
if (this.NavigationContext.QueryString.ContainsKey("Time_Zone"))
{
tzone = NavigationContext.QueryString["Time_Zone"];
timezone.Text = tzone;
}
if (this.NavigationContext.QueryString.ContainsKey("uTime"))
{
utimee = NavigationContext.QueryString["uTime"];
utime.Text = utimee;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Date"))
{
//if it is available, get parameter value
eventdate = NavigationContext.QueryString["Event_Date"];
evntdate.Text = eventdate;
}
if (this.NavigationContext.QueryString.ContainsKey("Location"))
{
//if it is available, get parameter value
location = NavigationContext.QueryString["Location"];
loc.Text = location;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Name"))
{
//if it is available, get parameter value
ename = NavigationContext.QueryString["Event_Name"];
enamee.Text = ename;
}
if (this.NavigationContext.QueryString.ContainsKey("Event_Description"))
{
//if it is available, get parameter value
desc = NavigationContext.QueryString["Event_Description"];
edescription.Text = desc;
}
}
private void Image_Previous(object sender, RoutedEventArgs e)
{
NavigationService.Navigate(new Uri("/Events.xaml", UriKind.Relative));
}
private void Image_rem(object sender, RoutedEventArgs e)
{
RegisterReminder();
}
private void RegisterReminder()
{
var reminder = ScheduledActionService.Find(ename) as Reminder ?? new Reminder(ename);
reminder.Title = ename;
reminder.Content = desc;
// parse eventDate,utimee to beginDateTime
reminder.BeginTime = beginDateTime;
reminder.ExpirationTime = reminder.BeginTime.AddDays(1);
reminder.RecurrenceType = RecurrenceInterval.None;
if (ScheduledActionService.Find(ename) == null)
ScheduledActionService.Add(reminder);
else
ScheduledActionService.Replace(reminder);
MessageBox.Show("reminder set succeed!");
}
}
}Now when the reminder button is clicked i want the fields utimee, tzone to be set and i get a pop up message "Event reminder added successfully"
I am not getting the idea on how to do this

You can do these steps:
1.get the values from webservice as global variable:
eventDate,location, utimee, tzone, ename,desc.
2.click the reminder button, execute the click method
private void BtnReminderClick(object sender, EventArgs e)
{
RegisterReminder();
}
3.do reminder register
private void RegisterReminder()
{
var reminder = ScheduledActionService.Find(ename) as Reminder ?? new Reminder(ename);
reminder.Title = ename;
reminder.Content = desc;
// parse eventDate,utimee to beginDateTime
reminder.BeginTime = DateTime.Parse(eventDate).Date + DateTime.Parse(utimee).TimeOfDay;
reminder.ExpirationTime = reminder.BeginTime.AddDays(1);
reminder.RecurrenceType = RecurrenceInterval.None;
if (ScheduledActionService.Find(ename) == null)
ScheduledActionService.Add(reminder);
else
ScheduledActionService.Replace(reminder);
MessageBox.Show("reminder set succeed!");
}

Related

TweetInvi Listview can't get TweetID

I'm trying to get Tweet ID via TweetInvi API but always get null point exception. I'm out of options and can't understand what i did wrong. Here is my code. Problem occurs when i select desired Item from view and press retweet.
namespace MIF_TwitterApplication
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Auth.SetUserCredentials("KEY", "KEY", "KEY",
"KEY");
}
private void Form1_Load(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
//PROFILE
profileImage.ImageLocation = user.ProfileImageUrlFullSize;
nameLabel.Text = user.Name;
usernameLabel.Text = "#" + user.ScreenName;
followersLabel.Text = "Followers: " + user.FollowersCount;
}
//Tweeting with PICS
private void tweetBtn_Click(object sender, EventArgs e)
{
if (tweetBox.Text != "")
{
if (imgUploadPath.Text != "")
{
byte[] file = File.ReadAllBytes(imgPreview.ImageLocation);
Tweet.PublishTweetWithImage(tweetBox.Text, file);
imgPreview.ImageLocation = "";
imgUploadPath.Text = "";
tweetBox.Clear();
MessageBox.Show("Tweet posted!");
}
else
{
Tweet.PublishTweet(tweetBox.Text);
MessageBox.Show("Tweet posted!");
tweetBox.Clear();
}
}
else
{
MessageBox.Show("Please enter text!");
tweetBox.Clear();
}
}
private void addImg_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.ShowDialog();
imgPreview.ImageLocation = ofd.FileName;
imgUploadPath.Text = ofd.FileName;
}
private void dropImg_Click(object sender, EventArgs e)
{
imgPreview.ImageLocation = "";
imgUploadPath.Text = "";
}
private void timelineBtn_Click(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
var getTweets = Timeline.GetHomeTimeline(40);
listView1.Clear();
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Tweet", 570);
listView1.Columns.Add("Created By", 130);
listView1.Columns.Add("Create Time", 130);
listView1.Columns.Add("Likes", 60);
listView1.Columns.Add("Retweets", 70);
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
}
}
private void postsBtn_Click(object sender, EventArgs e)
{
var user = User.GetAuthenticatedUser();
var getTweets = Timeline.GetUserTimeline(user, 40);
listView1.Clear();
listView1.View = View.Details;
listView1.GridLines = true;
listView1.FullRowSelect = true;
listView1.Columns.Add("Tweet", 570);
listView1.Columns.Add("Created By", 130);
listView1.Columns.Add("Create Time", 130);
listView1.Columns.Add("Likes", 60);
listView1.Columns.Add("Retweets", 70);
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
}
}
private void retweetBtn_Click(object sender, EventArgs e)
{
var checkedItems = listView1.SelectedItems;
long a = (long)listView1.SelectedItems[0].Tag;
var user = User.GetAuthenticatedUser();
var retweet = Tweet.PublishRetweet(a);
MessageBox.Show("Retweet was successfull");
listView1.Items.Clear();
}
}
}
Breakes on long a, I can't figure out how to get that Long Tweet ID
Here is the full code
Problem was that my X was not incrementing correctly as it was out of for loop.
int x = 0;
foreach (var t in getTweets)
{
ListViewItem listItem = new ListViewItem(t.Text);
listItem.SubItems.Add(t.CreatedBy.ScreenName.ToString());
listItem.SubItems.Add(t.CreatedAt.ToString());
listItem.SubItems.Add(t.FavoriteCount.ToString());
listItem.SubItems.Add(t.RetweetCount.ToString());
listView1.Items.Add(listItem);
listView1.Items[x].Tag = t.Id;
x = x +1;
}

How to pass an argument to new RoutedEventHandler method in C#?

I am trying to make an application launcher and in the end i am trying to pass and extra argument to RoutedEventHandler method call but its giving me an error, i tried looking it up on google but i didn't understand a damn thing. (i am noob) so here is the code please have a look and it.Thanks
namespace Button_Launcher
{
public partial class MainWindow : Window
{
private string line;
public MainWindow()
{
InitializeComponent();
}
private void button_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog fileName = new OpenFileDialog();
fileName.Filter = "executables (.exe)|*.exe";
fileName.ShowDialog();
StreamWriter writer = new StreamWriter("E:/Config.txt",true);
writer.WriteLine(fileName.FileName);
writer.Close();
textBox.Text = fileName.FileName;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
string file = ("E:/Config.txt");
StreamReader Reader = new StreamReader(file, Encoding.ASCII);
List<string> appList = new List<string>();
List<string> Items = new List<string>();
int count = 1;
while ((line = Reader.ReadLine()) != null)
{
makeButton(line,count);
count++;
}
Reader.Close();
}
public void makeButton(string link,int count)
{
string[] mySplit = link.Split(new char[] { '\\' });
string[] name = mySplit.Last().Split(new char[] { '.' });
string fName = name.First();
string buttonName = fName;
Button newBtn = new Button();
newBtn.Content = buttonName;
newBtn.Height = 30;
newBtn.Width = 70;
newBtn.Margin = new Thickness(-60, 90*count/1.5, 180,80);
StackPanel sp = new StackPanel();
sp.Children.Add(newBtn);
mainGrid.Children.Add(sp);
newBtn.Click += new RoutedEventHandler(launchApp(link));
//launchApp(link);
}
private void launchApp(string link,object sender, RoutedEventArgs e)
{
Process.Start(link);
}
}
}
You cannot change the method signature of the RoutedEventHandler. Instead, try storing the link data in the Tag property of your button. Then in the method you could cast the sender object to a button and access the tag property.
public void makeButton(string link,int count)
{
string[] mySplit = link.Split(new char[] { '\\' });
string[] name = mySplit.Last().Split(new char[] { '.' });
string fName = name.First();
string buttonName = fName;
Button newBtn = new Button();
newBtn.Content = buttonName;
newBtn.Height = 30;
newBtn.Width = 70;
newBtn.Tag = link;
newBtn.Margin = new Thickness(-60, 90*count/1.5, 180,80);
StackPanel sp = new StackPanel();
sp.Children.Add(newBtn);
mainGrid.Children.Add(sp);
newBtn.Click += launchApp;
//launchApp(link);
}
private void launchApp(object sender, RoutedEventArgs e)
{
var btn = sender as Button;
if( btn == null )
return;
Process.Start(btn.Tag.ToString( ));
}

How to log out from the Facebook in windows phone 7 using facebook api?

I am trying to add Facebook into my application. I have try with a sample.
public class FacebookLoginPageViewModel
{
private static WebBrowser _webBrowser;
private Page _page;
private const string ExtendedPermissions = "user_about_me,read_stream,publish_stream,user_birthday,offline_access,email";
private readonly FacebookClient _fb = new FacebookClient();
private const string AppId = "1XXX58XXXXXXXX9";
Uri url;
public FacebookLoginPageViewModel(Panel container, Page page)
{
_page = page;
_webBrowser = new WebBrowser();
var loginUrl = GetFacebookLoginUrl(AppId, ExtendedPermissions);
url = loginUrl;
container.Children.Add(_webBrowser);
_webBrowser.Navigated += webBrowser_Navigated;
_webBrowser.Navigate(loginUrl);
}
private Uri GetFacebookLoginUrl(string appId, string extendedPermissions)
{
var parameters = new Dictionary<string, object>();
parameters["client_id"] = appId;
parameters["redirect_uri"] = "https://www.facebook.com/connect/login_success.html";
parameters["response_type"] = "token";
parameters["display"] = "touch";
// add the 'scope' only if we have extendedPermissions.
if (!string.IsNullOrEmpty(extendedPermissions))
{
// A comma-delimited list of permissions
parameters["scope"] = extendedPermissions;
}
return _fb.GetLoginUrl(parameters);
}
void webBrowser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult oauthResult;
if (!_fb.TryParseOAuthCallbackUrl(e.Uri, out oauthResult))
{
return;
}
if (oauthResult.IsSuccess)
{
var accessToken = oauthResult.AccessToken;
LoginSucceded(accessToken);
}
else
{
// user cancelled
MessageBox.Show(oauthResult.ErrorDescription);
}
}
private void LoginSucceded(string accessToken)
{
var fb = new FacebookClient(accessToken);
fb.GetCompleted += (o, e) =>
{
if (e.Error != null)
{
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
MessageBox.Show(e.Error.Message);
return;
});
}
var result = (IDictionary<string, object>)e.GetResultData();
var id = (string)result["id"];
var url = string.Format("/Views/FacebookInfoPage.xaml?access_token={0}&id={1}", accessToken, id);
var rootFrame = (App.Current as App).RootFrame;
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
rootFrame.Navigate(new Uri(url, UriKind.Relative));
});
};
fb.GetAsync("me?fields=id");
}
This is working fine. But i want to Log out from the facebook when i click log out. How to achieve this? I have try with some examples. But it is not working for me.
private void logout(object sender, RoutedEventArgs e)
{
webBrowser1.Navigated +=
new EventHandler<System.Windows.Navigation.NavigationEventArgs>(CheckForout);
webBrowser1.Navigate(new Uri("http://m.facebook.com/logout.php?confirm=1"));
webBrowser1.Visibility = Visibility.Visible;
}
private void CheckForout(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
string fbLogoutDoc = webBrowser1.SaveToString();
Regex regex = new Regex
("\\<a href=\\\"/logout(.*)\\\".*data-sigil=\\\"logout\\\"");
MatchCollection matches = regex.Matches(fbLogoutDoc);
if (matches.Count > 0)
{
string finalLogout = string.Format("http://m.facebook.com/logout{0}",
matches[0].Groups[1].ToString().Replace("amp;", ""));
webBrowser1.Navigate(new Uri(finalLogout));
}
}
Please let me any idea to resolve this problem.
i got one more example:
https://www.facebook.com/logout.php?next=YOUR_URL&access_token=ACCESS_TOKEN
i have try like this:
string newURL = string.Format("https://www.facebook.com/logout.php?next={0}&access_token={1}", _userId, _accessToken);
But here what i have to pass to the YOUR_URL???
I found the solution.
public static void logoutSession()
{
_webBrowser.Navigated += new EventHandler<System.Windows.Navigation.NavigationEventArgs>(CheckForout);
string logoutUrl = "https://www.facebook.com/connect/login_success.html";
string newURL = string.Format("https://www.facebook.com/logout.php?next={0}&access_token={1}", logoutUrl, access_tocken);
_webBrowser.Navigate(new Uri(newURL));
}
public static void CheckForout(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
string fbLogoutDoc = _webBrowser.SaveToString();
Regex regex = new Regex
("\\<a href=\\\"/logout(.*)\\\".*data-sigil=\\\"logout\\\"");
MatchCollection matches = regex.Matches(fbLogoutDoc);
if (matches.Count > 0)
{
string finalLogout = string.Format("http://m.facebook.com/logout{0}",
matches[0].Groups[1].ToString().Replace("amp;", ""));
_webBrowser.Navigate(new Uri(finalLogout));
}
}
This will log out from the facebook in windows phone 7.

Winform Simple Link

I use a LabelLink contorl in a WinForm.
On form load I set the desired link:
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
On click :
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData as string);
}
The link is gray and nothing happens when I click on it.
What is missing?
Try this
LinkLabel.Link link = new LinkLabel.Link();
link.LinkData = "http://stackoverflow.com/questions/ask";
linkLabel1.Links.Add(link);
this.linkLabel1.Links[0].LinkData = "Ask a question";
linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.LinkLabel1LinkClicked‌​);
and
void LinkLabel1LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string url;
url = e.Link.LinkData.ToString();
if (!url.Contains("://"))
url = "http://" + url;
var myLink = new ProcessStartInfo(url);
Process.Start(myLink);
linkLabel1.LinkVisited = true;
}

C# class to play a video file

I have this class,
public class ImageBox : Grid
{
Image imgclose; public String path;
List<ImageBox> ImageBoxes;
public ImageBox(string label,List<ImageBox> ImBox)
{
this.ImageBoxes = ImBox;
imgclose = new Image();
imgclose.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Close.ico"));
imgclose.Width = 20; imgclose.Height = 20; imgclose.Cursor = Cursors.Hand; imgclose.HorizontalAlignment = System.Windows.HorizontalAlignment.Right; imgclose.VerticalAlignment = System.Windows.VerticalAlignment.Top;
imgclose.Visibility = System.Windows.Visibility.Hidden;
imgclose.MouseLeftButtonDown += new MouseButtonEventHandler(imgclose_MouseLeftButtonDown);
this.MouseEnter += new MouseEventHandler(Blank_MouseEnter);
this.MouseLeave += new MouseEventHandler(Blank_MouseLeave);
this.Height = 100; this.Width = 100;
try
{
System.Windows.Forms.OpenFileDialog open = new System.Windows.Forms.OpenFileDialog();
path = open.FileName.Replace(Directory.GetCurrentDirectory(), "");
this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
path = label;
}
catch(Exception e)
{
MessageBox.Show(e.ToString());
}
Grid.SetColumn(imgclose, 0); Grid.SetRow(imgclose, 1);
this.Children.Add(imgclose);
ContextMenu contextMenu1 = new ContextMenu();
MenuItem conitem1 = new MenuItem() { Header = "Send to back" }; conitem1.Click += new System.Windows.RoutedEventHandler(conitem1_Click);
MenuItem conitem2 = new MenuItem() { Header = "Bring to Front" }; conitem2.Click += new System.Windows.RoutedEventHandler(conitem2_Click);
contextMenu1.Items.Add(conitem1); contextMenu1.Items.Add(conitem2);
this.ContextMenu = contextMenu1;
}
void conitem1_Click(object sender, EventArgs e)
{
Canvas.SetZIndex(this, (Canvas.GetZIndex(this) - 1));
}
void conitem2_Click(object sender, EventArgs e)
{
Canvas.SetZIndex(this, (Canvas.GetZIndex(this) + 1));
}
void Blank_MouseEnter(object sender, MouseEventArgs e)
{
imgclose.Visibility = System.Windows.Visibility.Visible;
}
void Blank_MouseLeave(object sender, MouseEventArgs e)
{
imgclose.Visibility = System.Windows.Visibility.Hidden;
}
void imgclose_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (System.Windows.MessageBox.Show("Are you sure?", "Confirm", System.Windows.MessageBoxButton.OKCancel, System.Windows.MessageBoxImage.Question) == System.Windows.MessageBoxResult.OK)
{
ImageBoxes.Remove(this);
(this.Parent as System.Windows.Controls.Canvas).Children.Remove(this);
}
else
{
}
}
}
This class displays an image (chosen from a dialog box).
How can I modify it to make it play a video file ?
More precisely,
How should I modify the line
this.Background = new System.Windows.Media.ImageBrush(new System.Windows.Media.Imaging.BitmapImage(new Uri(label)));
path = label;
so that it plays a video file.
The Background property has to have some sort of Brush in it. A quick Google search came up with this: VideoBrush. I hope this is what you were looking for.

Categories