• 03-05-2010, 01:12:08
    #1
    mre
    Kimlik doğrulama veya yönetimden onay bekliyor.
    Bir adet basitinden c# ve Silverlight kullanarak oyun yaptim. Oyun sonrasinda alinan skoru sql ile database'e kayit ediyoruz. Simdi yapmak istedigim sey hemen anasayfasinda bulunan bir textarea ile adini yazdiginda o sql veritabanina skorun yaninda yazilmis olan isminde kayit edilmesini istiyorum. Yani skorun yaninda isimde kayit edilecek.

    Kodlar :

    sql kodu
    string myQuery = "INSERT INTO Score(count, date) VALUES ( " + newspaperCount + ", '" + DateTime.Now + "' )";
    xaml da ve c# kodlarina ne yazmam gerkiyor .acikcasi basit geliyor dusununce php benzeri gibi ise. Yardim edebilen olursa mutlu olurum gayet
  • 03-05-2010, 10:29:09
    #2
    count alanı sayısal bir alandır büyük ihtimalle..
    isim ise string bir alana yazılması gerekmektedir..
    ya db'de yeni bir alan açmanız gerekmekte yada count alan tipini değiştirmeniz gerekmekte..
  • 03-05-2010, 14:14:16
    #3
    Silverlight ile Veritabanı işlemleri için WebServis kullanın.

    Geniş türkçe kaynak için Daron Hoca

    oyununuzu görmek isterim eğer mümkünse. bir web sitesi üzernden yayın şansınız var mı ?
  • 03-05-2010, 14:57:04
    #4
    oyu filan gosterebiliyorum. ekran goruntusunu vereyim en iyisi






    goruldugu gibi sag alt kosedeki butona basinca oyundaki puan aktariliyor. benim istedigim hemen o botunun yanina bir text yazma yeri koyup o butona bastiginda herne yazilmis ise onu ayni yere kayit etmek. yani sql kodunu yazarken o texti nasil alabilirim. get filan ama nasil kodu isterseniz verebilirim. Bu geceye yapmam gerekiyor :|
  • 03-05-2010, 15:52:41
    #5
    veritabanında oradan gelen text'i yazabileceğin alan varmı ?
    ve yazmıs oldugun insert sorgusuna bir alan ekliceksin hepsi bu
  • 03-05-2010, 18:03:52
    #6
    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
  • 03-05-2010, 19:42:02
    #7
    hatamı alıyorsunuz ? veritabanınız var mı uygun şekilde hazırlanmış ? hata alıyorsanız ne hatas ?
  • 03-05-2010, 19:44:15
    #8
    yok hata. yani yapmak istedigim bir textox yardimi ile oraya yazilacak isimi diger skorun yaninda sql kullanarak veritabanina kayit ettirmek. normal bir form olayi. php de olsa 1 dklik is ama burda anlamiyorum pek.. sadece anasayfada ve sqlde ufak bir degisiklik olacak zor olmasa gerek .
  • 03-05-2010, 20:50:31
    #9
    konu guncel ve lazim ..