Пример #1
0
 private void Timer1_Tick(object sender, EventArgs e)
 {
     BPInicio.Increment(2);
     if (BPInicio.Value == 100)
     {
         string        qry            = "";
         string        cadenaconexion = ConfigurationManager.AppSettings.Get("cadenaconexion");
         SqlConnection sqlCNX         = new SqlConnection(cadenaconexion);
         SqlCommand    sqlCMD         = new SqlCommand();
         qry = "SELECT * from VistaUsuarios";
         sqlCMD.CommandText = qry;
         sqlCMD.Connection  = sqlCNX;
         SqlDataReader sqlDR = null;
         try
         {
             sqlCNX.Open();
             sqlDR = sqlCMD.ExecuteReader();
             if (sqlDR.HasRows == true)
             {
                 FrmLogin lo = new FrmLogin();
                 lo.Show();
                 this.Hide();
                 timer1.Stop();
             }
             else
             {
                 FrmNuevoUsuAd frm = new FrmNuevoUsuAd();
                 frm.Show();
                 this.Hide();
                 timer1.Stop();
             }
         }
         catch (SqlException ex)
         {
             //    MessageBox.Show(ex.Message, "");
             frmConexion frm = new frmConexion();
             frm.Show();
             this.Hide();
             timer1.Stop();
         }
     }
 }
Пример #2
0
        private void BtnGuardar_Click(object sender, EventArgs e)
        {
            //Set connection string
            string connectionString = string.Format("Data Source={0};Initial Catalog={1};Integrated Security=True", cboServer.Text, cmbbasededatos.Text);

            try
            {
                string      con    = cboServer.Text.Trim();
                string      bases  = cmbbasededatos.Text.Trim();
                XmlDocument xmlCon = new XmlDocument();
                xmlCon.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                foreach (XmlElement element in xmlCon.DocumentElement)
                {
                    if (element.Name.Equals("appSettings"))
                    {
                        foreach (XmlNode node in element.ChildNodes)
                        {
                            if (node.Attributes[0].Value == "cadenaconexion")
                            {
                                node.Attributes[1].Value = "Data Source=" + con + ";Initial Catalog=" + bases + ";Integrated Security=True";
                            }
                        }
                    }
                }
                xmlCon.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
                ConfigurationManager.RefreshSection("appSettings");

                SqlHelper helper = new SqlHelper(connectionString);
                if (helper.IsConnection)
                {
                    AppSetting setting = new AppSetting();
                    setting.SaveConnectionString("PaperShop.Properties.Settings.papeleriaConnectionString", connectionString);
                }
                string        qry            = "";
                string        cadenaconexion = ConfigurationManager.AppSettings.Get("cadenaconexion");
                SqlConnection sqlCNX         = new SqlConnection(cadenaconexion);
                SqlCommand    sqlCMD         = new SqlCommand();
                qry = "SELECT * from VistaUsuarios";
                sqlCMD.CommandText = qry;
                sqlCMD.Connection  = sqlCNX;
                SqlDataReader sqlDR = null;
                try
                {
                    sqlCNX.Open();
                    sqlDR = sqlCMD.ExecuteReader();
                    if (sqlDR.HasRows == true)
                    {
                        FrmLogin lo = new FrmLogin();
                        lo.Show();
                        this.Hide();
                        this.Alert("Conexion Exitosa!", FrmNotificaciones.alertTypeEnum.Success);
                    }
                    else
                    {
                        FrmNuevoUsuAd frm = new FrmNuevoUsuAd();
                        frm.Show();
                        this.Hide();
                        this.Alert("Conexion Exitosa!", FrmNotificaciones.alertTypeEnum.Success);
                    }
                }
                catch (SqlException ex)
                {
                    this.Alert("Error para continuar!", FrmNotificaciones.alertTypeEnum.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }