예제 #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 BtnIniciarS_Click(object sender, EventArgs e)
        {
            string[] stringArray = txtCorreo.Text.Split('@');
            if (!txtCorreo.Text.Contains('@') || !stringArray[1].Contains('.'))
            {
                MessageBox.Show("Introduce un correo electronico valido");
                return;
            }
            Random r   = new Random();
            int    idc = r.Next(00000001, 99999999);

            dir  = "ima\\user" + idc + ".png";
            diro = "ima\\user.png";
            string pach = ".\\.\\";

            System.IO.File.Copy(pach + diro, pach + dir);

            //Variable para guardar la consulta
            string qry = "";
            //variable para extraer la configuracion del appconfig
            string cadenaconexion = ConfigurationManager.AppSettings.Get("cadenaconexion");
            //Variable para conectarnos a la BD
            SqlConnection sqlCNX = new SqlConnection(cadenaconexion);
            //variable para guardar objetos o comando
            SqlCommand sqlCMD = new SqlCommand();

            //Codigo para cachar errores
            try
            {
                string sexo = "";
                if (rdbMasculino.Checked == true)
                {
                    sexo = "M";
                }
                else
                {
                    sexo = "F";
                }
                int    id              = 1;
                string tipo            = "administrador";
                string fechanacimiento = dtpFechaNacimiento.Value.ToString("yyyyMMdd");
                qry = "INSERT INTO usuarios(id_persona, login, password, tipo, fecha_registro, hora_registro, activo, id_user, imagen)" +
                      "VALUES('" + id + "', '" + txtlogin.Text + "','" + txtpassword.Text + "','" + tipo + "','" + lblFechaRegistro.Text + "','" + lblHoraRegistro.Text + "', '" + id + "', '" + id + "', '" + dir + "') INSERT INTO personas(nombre, apepaterno, apematerno, domicilio, telefono, correo, sexo, fecha_nac, estado_civil, estados, municipio, activo, fecha_registro, hora_registro, id_usuario)" +
                      "VALUES ('" + txtNombre.Text + "', '" + txtApeMaterno.Text + "', '" + txtApeMaterno.Text + "', '" + txtDomicilio.Text + "', '" + txtTelefono.Text + "', '" + txtCorreo.Text + "', '" + sexo + "', '" + fechanacimiento + "', '" + cmbEstadoCivil.Text + "', '" + txtEstado.Text + "', '" + txtMunicipio.Text + "','" + id + "', '" + lblFechaRegistro.Text + "', '" + lblHoraRegistro.Text + "', '" + id + "')";
                //asignamos la consulta al comando
                sqlCMD.CommandText = qry;
                //asignamos la conexion al comando
                sqlCMD.Connection = sqlCNX;
                //abrimos la coneccion
                sqlCNX.Open();
                //ejecutamos el comando
                sqlCMD.ExecuteReader();
                //cerramos conexion
                sqlCNX.Close();
                this.Alert("Usuario Agregado!", FrmNotificaciones.alertTypeEnum.Success);
                FrmLogin formulario = new FrmLogin();
                formulario.Show();
                Hide();
            }
            catch (SqlException ex)
            {
                MessageBox.Show("" + ex, "Mnesaje");
                //this.Alert("Error al agregar usuario!", FrmNotificaciones.alertTypeEnum.Error);
            }
        }
예제 #3
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);
            }
        }