evet yani dusundugumde zor bise gibi gelmiyor ama iste karisti kafam iyice. kod hjakkinda yardim edebilen olursa mutlu olacagim
mainpage.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace Recycle
{
public partial class MainPage : UserControl
{
private int newspaperTimer = 0;
private int toothpasteTimer = 0;
int newspaperCount = 0;
List<Newspaper> newspapers = new List<Newspaper>();
List<ToothPaste> toothpaste = new List<ToothPaste>();
public List<Newspaper> Newspapers
{
get { return newspapers; }
set { newspapers = value; }
}
public List<ToothPaste> Toothpastes
{
get { return toothpaste; }
set { toothpaste = value; }
}
public MainPage()
{
InitializeComponent();
CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
}
private void UserControl_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Right)
this.truck.Move(Direction.Right);
else if (e.Key == Key.Left)
this.truck.Move(Direction.Left);
else if (e.Key == Key.Up)
this.truck.Move(Direction.Up);
else if (e.Key == Key.Down)
this.truck.Move(Direction.Down);
}
public void AddToothpaste(ToothPaste a)
{
toothpaste.Add(a);
LayoutRoot.Children.Add(a);
}
public void RemoveToothpaste(ToothPaste a)
{
toothpaste.Remove(a);
LayoutRoot.Children.Remove(a);
}
public void AddNewspaper(Newspaper a)
{
newspapers.Add(a);
LayoutRoot.Children.Add(a);
}
public void RemoveNewspaper(Newspaper a)
{
newspapers.Remove(a);
LayoutRoot.Children.Remove(a);
}
private void cmd_MouseEnter(object sender, MouseEventArgs e)
{
blurStoryboard.Stop();
Storyboard.SetTarget(blurStoryboard, ((Button)sender).Effect);
blurStoryboard.Begin();
}
private void cmd_MouseLeave(object sender, MouseEventArgs e)
{
unblurStoryboard.Stop();
Storyboard.SetTarget(unblurStoryboard, ((Button)sender).Effect);
unblurStoryboard.Begin();
}
void CompositionTarget_Rendering(object sender, EventArgs e)
{
if (Canvas.GetLeft(background) < -(this.background.ActualWidth - this.Width))
{
Canvas.SetLeft(background, 0);
}
Canvas.SetLeft(background, Canvas.GetLeft(background) - 1);
toothpasteTimer += 1;
if (toothpasteTimer > 40)
{
toothpasteTimer = 0;
AddToothpaste(new ToothPaste());
}
for (int indx = 0; indx < newspapers.Count; indx++)
{
toothpaste[indx].Update(LayoutRoot);
}
newspaperTimer += 1;
if (newspaperTimer > 100)
{
newspaperTimer = 0;
AddNewspaper(new Newspaper());
}
for (int indx = 0; indx < newspapers.Count; indx++)
{
newspapers[indx].Update(LayoutRoot);
}
for (int indx = 0; indx < newspapers.Count; indx++)
{
if (DetectCollision(newspapers[indx], truck))
{
RemoveNewspaper(newspapers[indx]);
newspaperCount++;
countText.Text = "Recycle Points: " + newspaperCount;
}
}
for (int indx = 0; indx < toothpaste.Count; indx++)
{
if (DetectCollision(toothpaste[indx], truck))
{
RemoveToothpaste(toothpaste[indx]);
newspaperCount--;
countText.Text = "Recycle Points: " + newspaperCount;
}
}
}
public bool DetectCollision(ContentControl ctrl1, ContentControl ctrl2)
{
Rect ctrl1Rect = new Rect(
new Point(Convert.ToDouble(ctrl1.GetValue(Canvas.LeftProperty)),
Convert.ToDouble(ctrl1.GetValue(Canvas.TopProperty))),
new Point((Convert.ToDouble(ctrl1.GetValue(Canvas.LeftProperty)) + ctrl1.ActualWidth),
(Convert.ToDouble(ctrl1.GetValue(Canvas.TopProperty)) + ctrl1.ActualHeight))
);
Rect ctrl2Rect = new Rect(
new Point(Convert.ToDouble(ctrl2.GetValue(Canvas.LeftProperty)),
Convert.ToDouble(ctrl2.GetValue(Canvas.TopProperty))),
new Point((Convert.ToDouble(ctrl2.GetValue(Canvas.LeftProperty)) + ctrl2.ActualWidth),
(Convert.ToDouble(ctrl2.GetValue(Canvas.TopProperty)) + ctrl2.ActualHeight))
);
ctrl1Rect.Intersect(ctrl2Rect);
return !(ctrl1Rect == Rect.Empty);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
ServiceReference1.WebServiceRecycleSoapClient service = new
Recycle.ServiceReference1.WebServiceRecycleSoapClient();
service.SaveNewspapersCompleted += new EventHandler<Recycle.
ServiceReference1.SaveNewspapersCompletedEventArgs>
(NewspaperSaveCompleted);
service.SaveNewspapersAsync(newspaperCount);
UserControlScore s = new UserControlScore();
LayoutRoot.Children.Add(s);
Canvas.SetLeft(s, 100);
Canvas.SetTop(s, 40);
}
void NewspaperSaveCompleted(object sender,
ServiceReference1.SaveNewspapersCompletedEventArgs e)
{
if (e.Error == null)
Console.WriteLine(e.Result);
}
}
}Webservice
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
namespace Recycle.Web
{
/// <summary>
/// Summary description for WebServiceRecycle
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class WebServiceRecycle : System.Web.Services.WebService
{
[WebMethod]
public bool SaveNewspapers(int newspaperCount)
{
string connString = "Data Source=SQL-SERVER;Initial Catalog=ce805;Integrated Security=True";
string myQuery = "INSERT INTO Score(count, date) VALUES ( " + newspaperCount + ", '" + DateTime.Now + "' )";
SqlConnection myConnection = new SqlConnection(connString);
SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
try
{
myConnection.Open();
myCommand.ExecuteNonQuery();
return true;
}
catch
{
myConnection.Close();
return false;
}
}
[WebMethod]
public string ShowScores()
{
string connString = "Data Source=SQL-SERVER;Initial Catalog=ce805;Integrated Security=True";
string myQuery = "SELECT count, date FROM score ORDER BY count DESC ";
SqlConnection myConnection = new SqlConnection(connString);
SqlCommand myCommand = new SqlCommand(myQuery, myConnection);
SqlDataReader myReader;
string s = ""; int i = 1;
try
{
myConnection.Open();
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
s += i + ". " + myReader["count"] + ", " + myReader["date"] + "\n";
i++;
}
myReader.Close();
return s;
}
catch (Exception ex)
{
return ex.StackTrace;
}
finally
{
myConnection.Close();
}
}
}
}xaml'da texti yazabilecegimiz yerin adi yourname olarak dusunebiliriz. Sadece mainpage.cs'e ve webservice'deki sql kodunda degisiklik yapacagiz. sql database'i ayarlarim ben