Ejemplo n.º 1
0
        private void btnOlustur_Click(object sender, EventArgs e)
        {
            if (pnlNewDB.CanNullsCheck())
            {
                if (!guncelle)
                {
                    try
                    {
                        SqlConnection conn = new SqlConnection("Data Source=" + SERVER.Text + "; Initial Catalog=master; User Id=" + DB_KULLANICI_ADI.Text + "; password="******";");
                        conn.Open();

                        SqlCommand     command        = new SqlCommand("SELECT NAME FROM MASTER.SYS.DATABASES", conn);
                        DataTable      dataTable      = new DataTable();
                        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(command);

                        sqlDataAdapter.Fill(dataTable);
                        sqlDataAdapter.Dispose();

                        bool sirketCheck  = false;
                        bool artezDBCheck = false;
                        foreach (DataRow row in dataTable.Rows)
                        {
                            if (row["NAME"].ToString() != "master" && row["NAME"].ToString() != "tempdb" && row["NAME"].ToString() != "model" && row["NAME"].ToString() != "msdb")
                            {
                                if (row["NAME"].ToString() == SIRKET_ADI.Text)
                                {
                                    sirketCheck = true;
                                    ArsMessage.ShowMessage("Hata", SIRKET_ADI.Text + " Şirketi Mevcuttur.\nFarklı Bir Şirket Adı Seçiniz.");
                                }
                                else if (row["NAME"].ToString() == "ARTEZ")
                                {
                                    artezDBCheck = true;
                                }
                            }
                        }

                        if (!artezDBCheck)
                        {
                            ArsLibrary.dbServerName = SERVER.Text;
                            ArsLibrary.dbUserName   = DB_KULLANICI_ADI.Text;
                            ArsLibrary.dbPassword   = DB_SIFRE.Text;
                            ArsLibrary.dbName       = "master";

                            ArsSQLQry qryCreateDB = new ArsSQLQry();
                            qryCreateDB.SQLText = "CREATE DATABASE ARTEZ";
                            qryCreateDB.Open();
                            if (qryCreateDB.errorCode == "0")
                            {
                                ArsLibrary.dbName = "ARTEZ";
                                if (ArsLibrary.activeForm != null)
                                {
                                    using (ArsProgress frm = new ArsProgress(CreateArtezDB))
                                    {
                                        frm.activeForm = ArsLibrary.activeForm;
                                        frm.processID  = 0;
                                        frm.perProg    = true;
                                        arsProgress    = frm;
                                        frm.ShowDialog();
                                    }
                                }
                            }
                        }

                        if (!sirketCheck)
                        {
                            ArsLibrary.dbServerName = SERVER.Text;
                            ArsLibrary.dbUserName   = DB_KULLANICI_ADI.Text;
                            ArsLibrary.dbPassword   = DB_SIFRE.Text;
                            ArsLibrary.dbName       = "master";

                            ArsSQLQry qryCreateDB = new ArsSQLQry();
                            qryCreateDB.SQLText = "CREATE DATABASE " + SIRKET_ADI.Text;
                            qryCreateDB.Open();
                            if (qryCreateDB.errorCode == "0")
                            {
                                ArsLibrary.dbName = SIRKET_ADI.Text;
                                if (ArsLibrary.activeForm != null)
                                {
                                    using (ArsProgress frm = new ArsProgress(CreateSirketDB))
                                    {
                                        frm.activeForm = ArsLibrary.activeForm;
                                        frm.processID  = 1;
                                        frm.perProg    = true;
                                        arsProgress    = frm;
                                        frm.ShowDialog();
                                    }
                                }
                            }
                            else
                            {
                                ArsMessage.ShowMessage("Hata", qryCreateDB.description);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ArsMessage.ShowMessage("Hata", ex.Message);
                    }
                }
                else
                {
                    ArsLibrary.dbName = SIRKET_ADI.Text;
                    if (ArsLibrary.activeForm != null)
                    {
                        using (ArsProgress frm = new ArsProgress(CreateSirketDB))
                        {
                            frm.activeForm = ArsLibrary.activeForm;
                            frm.processID  = 1;
                            frm.perProg    = true;
                            arsProgress    = frm;
                            frm.ShowDialog();
                        }
                    }
                }
            }
        }