Beispiel #1
0
        protected async Task <System.Data.Common.DbConnection> EnsureConnection()
        {
            if (_connection == null)
            {
                _connection = new System.Data.SqlClient.SqlConnection(_options.ConnectionString);
            }

            if (_connection.State != System.Data.ConnectionState.Open)
            {
                await _connection.OpenAsync();
            }

            return(_connection);
        }
Beispiel #2
0
        private async void frmLogin_Shown(object sender, EventArgs e)
        {
            int    versionNew       = 102;
            string connectionString = "Data Source = 185.248.57.239; User ID = wiody; Password = xrwatxN3MM4uEZyV; Initial Catalog = WiodyUpdate; MultipleActiveResultSets = True";
            string query            = "SELECT TOP 1 * FROM[WiodySMVersion] ORDER BY ID DESC";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(query, connection);
                try
                {
                    connection.Open();
                    SqlDataReader reader = command.ExecuteReader();
                    List <string> list   = new List <string>();
                    while (reader.Read())
                    {
                        if (Convert.ToInt32(reader["VERSION"]) != versionNew && Convert.ToBoolean(reader["REQUIRE"]) == false)
                        {
                            var messageBox = XtraMessageBox.Show("ŞU AN KULLANDIĞINIZ SÜRÜM ESKİDİR. YENİSİNE GEÇMEK İÇİN EVET'E TIKLAYINIZ !", "YENİ SÜRÜM GELMİŞTİR.", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                            if (messageBox == DialogResult.Yes)
                            {
                                ProcessStartInfo proc = new ProcessStartInfo
                                {
                                    WorkingDirectory = Application.StartupPath,
                                    FileName         = "WiodySMUpdater.exe",
                                    Verb             = "runas"
                                };
                                Process.Start(proc);
                                Application.Exit();
                                break;
                            }
                            else if (messageBox == DialogResult.No)
                            {
                                break;
                            }
                        }
                        else if (Convert.ToBoolean(reader["REQUIRE"]) == true && Convert.ToInt32(reader["VERSION"]) != versionNew)
                        {
                            var messageBox = XtraMessageBox.Show("ŞU AN KULLANDIĞINIZ SÜRÜM ESKİDİR. YENİSİNE GEÇMEK İÇİN EVET'E TIKLAYINIZ. AKSİ HALDE PROGRAM KAPANACAKTIR !!", "ZORUNLU SÜRÜM GÜNCELLEMESİ", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                            if (messageBox == DialogResult.Yes)
                            {
                                ProcessStartInfo proc = new ProcessStartInfo
                                {
                                    WorkingDirectory = Application.StartupPath,
                                    FileName         = "WiodySMUpdater.exe",
                                    Verb             = "runas"
                                };
                                Process.Start(proc);
                                Application.Exit();
                                break;
                            }
                            else if (messageBox == DialogResult.No)
                            {
                                Application.Exit();
                                break;
                            }
                        }
                        else if (Convert.ToInt32(reader["VERSION"]) == versionNew)
                        {
                            break;
                        }
                    }
                    reader.Close();
                    connection.Close();
                }
                catch (Exception)
                {
                    XtraMessageBox.Show("Veri Tabanı Bağlantısı Başarısız. Lütfen sistem yöneticiniz ile iletişime geçin veya daha sonra tekrar deneyin", "Hata");
                    Application.Exit();
                }
            }
            string buffer = "";

            for (int i = 0; i < versionNew.ToString().Length; i++)
            {
                buffer += versionNew.ToString()[i] + ".";
            }
            lblnumberversion.Text = buffer.Remove(5, 1);
            using (var db = new WiodySMContext())
            {
                System.Data.Common.DbConnection conn = db.Database.Connection;
                try
                {
                    await conn.OpenAsync();

                    conn.Close();
                    btnLogin.Enabled = true;
                    this.marqueeProgressBarControl1.Properties.Stopped = true;
                    lblLoading.Text = "Bağlantı Başarılı.";
                }
                catch
                {
                    this.marqueeProgressBarControl1.Properties.Stopped = true;
                    lblLoading.Text = "Bağlantı Hatası.";
                    XtraMessageBox.Show("Veri Tabanı Bağlantısı Başarısız. Lütfen sistem yöneticiniz ile iletişime geçin veya daha sonra tekrar deneyin", "Hata");
                    Application.Exit();
                }
            }
        }