TETE

 avatar
unknown
csharp
3 years ago
4.6 kB
3
Indexable
using System;
using System.IO;
using System.Xml;
namespace WindowsFormsApp20
{
    public partial class Form1 : Form
    {
        private static bool IsFillAutomaticallyOneTime = false;

        public Form1()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (IsFillAutomaticallyOneTime == false && checkBox1.Checked == true)
            {
                IsFillAutomaticallyOneTime = true;

                XmlDocument document = new XmlDocument();
                XmlElement kullanicilar;

                if (!File.Exists("Saves.xml"))
                {

                    kullanicilar = document.CreateElement("kullanicilar");


                    XmlElement kullanici = document.CreateElement("kullanici");

                    XmlElement id = document.CreateElement("id");
                    XmlElement passaword = document.CreateElement("passaword");

                    id.InnerText = "admin";
                    passaword.InnerText = "1234";

                    kullanici.AppendChild(id);
                    kullanici.AppendChild(passaword);
                    kullanicilar.AppendChild(kullanici);

                    document.AppendChild(kullanicilar);
                    document.Save("Saves.xml");
                }
                else
                {
                    document.Load("Saves.xml");
                    kullanicilar = (XmlElement)document.SelectSingleNode("kullancilar");

                }


                XmlNode kullanicilars = document.SelectSingleNode("kullanicilar");
                XmlNode kullanici1 = kullanicilars.SelectSingleNode("kullanici");

                textBox1.Text = kullanici1.SelectSingleNode("id").InnerText;
                textBox2.Text = kullanici1.SelectSingleNode("passaword").InnerText;


            }

            else
            {
                textBox1.Text = "";
                textBox2.Text = "";
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            XmlDocument document = new XmlDocument();
            document.Load("Saves.xml");
            XmlNode kullanicilar = document.SelectSingleNode("kullanicilar");
            XmlNode kullanici = kullanicilar.SelectSingleNode("kullanici");

            if (textBox1.Text == "" || textBox2.Text == "")
            {
                MessageBox.Show("Bos  alan birakilamaz!!");
            }


            else
            {


                if (textBox1.Text == kullanici.SelectSingleNode("id").InnerText && textBox2.Text == kullanici.SelectSingleNode("passaword").InnerText)
                {
                    MessageBox.Show("Basarili ile giris yapildi");
                }

                else
                {
                    MessageBox.Show("Sifre  veya kullanici adiniz hatali.");
                }

            }
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            XmlDocument document = new XmlDocument();
            XmlElement kullanicilar;

            if (!File.Exists("Saves.xml"))
            {

                kullanicilar = document.CreateElement("kullanicilar");


                XmlElement kullanici = document.CreateElement("kullanici");

                XmlElement id = document.CreateElement("id");
                XmlElement passaword = document.CreateElement("passaword");

                id.InnerText = "admin";
                passaword.InnerText = "1234";

                kullanici.AppendChild(id);
                kullanici.AppendChild(passaword);
                kullanicilar.AppendChild(kullanici);

                document.AppendChild(kullanicilar);
                document.Save("Saves.xml");
            }
            else
            {
                document.Load("Saves.xml");
                kullanicilar = (XmlElement)document.SelectSingleNode("kullancilar");

            }
            XmlNode kullanicilars = document.SelectSingleNode("kullanicilar");
            XmlNode kullanici1 = kullanicilars.SelectSingleNode("kullanici");

            textBox1.Text = kullanici1.SelectSingleNode("id").InnerText;
            textBox2.Text = kullanici1.SelectSingleNode("passaword").InnerText;
            checkBox1.Checked = true;
        }
    }
}