Yapisik

mail@pastecode.io avatar
unknown
csharp
2 years ago
4.3 kB
2
Indexable
Never
using System;
using System.IO;
using System.Windows.Forms;
using System.Xml;

namespace Excel
{
    public partial class TestForm : Form
    {
        private static bool IsFillAutomaticallyOneTime = false;

        public TestForm()
        {
            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 TestForm_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;
        }
    }
}