예제 #1
0
파일: Login.cs 프로젝트: ademaydogdu/msp
        private void Set_Form()
        {
            #region CreateFile
            string root = @"C:\Msp";
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            string MspBacUp = @"C:\Msp\BackUp";
            if (!Directory.Exists(MspBacUp))
            {
                Directory.CreateDirectory(MspBacUp);
            }
            string MspModuls = @"C:\Msp\Moduls";
            if (!Directory.Exists(MspModuls))
            {
                Directory.CreateDirectory(MspModuls);
            }
            string path = @"C:\Msp\ConnectString.txt";
            if (!File.Exists(path))
            {
                using (StreamWriter sw = File.CreateText(path))
                {
                    string sifrele = SecurityExtension.Sifrele("data source=DG;initial catalog=msp;user id=sa;password=123D654!;");
                    sw.WriteLine(sifrele);
                }
                AppMain.LocalConnect = false;
            }
            #endregion

            if (!AppMain.LocalConnect)
            {
                string[] conArry;
                using (StreamReader sr = File.OpenText(path))
                {
                    string str = SecurityExtension.Sifre_Coz(sr.ReadLine());
                    conArry = str.Split(';');
                }
                List <string> conn = new List <string>();
                foreach (var item in conArry)
                {
                    int position = item.IndexOf("=");
                    if (position < 0)
                    {
                        continue;
                    }
                    conn.Add(item.Substring(position + 1));
                }
                AppMain.SqlConnection = new ConnectionDTO
                {
                    Database = conn[1], //Global.SqlConnection.Database,
                    Server   = conn[0], //"R00T\\SQLEXPRESS", //Global.SqlConnection.Server,
                    Password = conn[3], //Global.SqlConnection.Password,
                    UserId   = conn[2]  //Global.SqlConnection.UserId
                };

                if (MspTool.sqlKontrol(AppMain.SqlConnection.Server, AppMain.SqlConnection.Database, AppMain.SqlConnection.UserId, AppMain.SqlConnection.Password) == false)
                {
                    XtraMessageBox.Show("Bağlantı hatası.Veritabanı ayarlarınızı kontrol ediniz...", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            else
            {
                string[] conArry;
                using (StreamReader sr = File.OpenText(path))
                {
                    string str = SecurityExtension.Sifre_Coz(sr.ReadLine());
                    conArry = str.Split(';');
                }
                List <string> conn = new List <string>();
                foreach (var item in conArry)
                {
                    int position = item.IndexOf("=");
                    if (position < 0)
                    {
                        continue;
                    }
                    conn.Add(item.Substring(position + 1));
                }
                AppMain.SqlConnection = new ConnectionDTO
                {
                    Database = conn[1],
                    Server   = conn[0]
                };
                if (MspTool.sqlKontrol(AppMain.SqlConnection.Server, AppMain.SqlConnection.Database) == false)
                {
                    XtraMessageBox.Show("Bağlantı hatası.Veritabanı ayarlarınızı kontrol ediniz...", "Uyarı", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }


            LoadDatabase();
        }