コード例 #1
0
 private void button2_Click(object sender, EventArgs e)
 {
     back.Show();
     this.Close();
 }
コード例 #2
0
ファイル: AltaUsuario.cs プロジェクト: NaiaraAcosta/GDD2014
        private void button1_Click(object sender, EventArgs e)
        {
            string        ConnStr = ConfigurationManager.AppSettings["stringConexion"];
            SqlConnection con     = new SqlConnection(ConnStr);

            con.Open();
            SqlTransaction transaction = con.BeginTransaction();
            SqlCommand     scCommand   = new SqlCommand("CONTROL_ZETA.SP_ABM_USUARIO", con, transaction);

            scCommand.CommandType = CommandType.StoredProcedure;
            scCommand.Parameters.Add("@ACCION", SqlDbType.SmallInt).Value     = modo;
            scCommand.Parameters.Add("@USUARIO", SqlDbType.VarChar, 50).Value = textBox1.Text;
            if (textBox2.Text != "")
            {
                scCommand.Parameters.Add("@PASS", SqlDbType.VarChar).Value = encriptarPass();
            }
            else
            {
                scCommand.Parameters.AddWithValue("@PASS", DBNull.Value);
            }
            scCommand.Parameters.Add("@NOMBRE", SqlDbType.VarChar, 50).Value   = textBox3.Text;
            scCommand.Parameters.Add("@APELLIDO", SqlDbType.VarChar, 50).Value = textBox4.Text;
            scCommand.Parameters.Add("@TIPO_DOC", SqlDbType.TinyInt).Value     = tipoDoc[comboBox1.SelectedIndex];
            scCommand.Parameters.Add("@DOC", SqlDbType.VarChar, 15).Value      = textBox6.Text;
            scCommand.Parameters.Add("@MAIL", SqlDbType.VarChar, 50).Value     = textBox7.Text;
            scCommand.Parameters.Add("@TEL", SqlDbType.VarChar, 10).Value      = textBox8.Text;
            scCommand.Parameters.Add("@DOM", SqlDbType.VarChar, 50).Value      = textBox9.Text;
            scCommand.Parameters.Add("@FECHA_NAC", SqlDbType.Date).Value       = dateTimePicker1.Value;
            scCommand.Parameters.Add("@HOTEL_ID", SqlDbType.Int).Value         = Login.Class1.hotel;
            scCommand.Parameters.Add("@ERROR", SqlDbType.TinyInt).Direction    = ParameterDirection.Output;
            if (scCommand.Connection.State == ConnectionState.Closed)
            {
                scCommand.Connection.Open();
            }
            scCommand.ExecuteNonQuery();
            int  result   = int.Parse(scCommand.Parameters["@ERROR"].Value.ToString());
            bool conError = true;

            switch (result)
            {
            case 1:
            {
                conError = false;
                break;
            }

            case 2:
            {
                MessageBox.Show("Error 2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            case 3:
            {
                MessageBox.Show("Usuario duplicado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            case 4:
            {
                MessageBox.Show("Error 4", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }

            default:
            {
                string mensaje = string.Format("Error en la operacion, COD: {0}", result);
                MessageBox.Show(mensaje, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                break;
            }
            }

            if (!conError)
            {
                for (int i = 0; i < checkedListBox1.Items.Count; i++)
                {
                    if (checkedListBox1.GetItemChecked(i))
                    {
                        scCommand             = new SqlCommand("CONTROL_ZETA.SP_USR_ROL_HOTEL", con, transaction);
                        scCommand.CommandType = CommandType.StoredProcedure;
                        scCommand.Parameters.Add("@USUARIO", SqlDbType.VarChar, 50).Value = textBox1.Text;
                        scCommand.Parameters.Add("@ROL_ID", SqlDbType.TinyInt).Value      = i + 1;
                        scCommand.Parameters.Add("@HOTEL_ID", SqlDbType.Int).Value        = Login.Class1.hotel;
                        if (scCommand.Connection.State == ConnectionState.Closed)
                        {
                            scCommand.Connection.Open();
                        }
                        scCommand.ExecuteNonQuery();
                    }
                }

                scCommand             = new SqlCommand("CONTROL_ZETA.SP_DES_HAB_USUARIO", con, transaction);
                scCommand.CommandType = CommandType.StoredProcedure;
                scCommand.Parameters.Add("@USUARIO", SqlDbType.VarChar, 50).Value = textBox1.Text;
                scCommand.Parameters.Add("@HOTEL_ID", SqlDbType.Int).Value        = Login.Class1.hotel;
                if (checkBox1.Checked)
                {
                    scCommand.Parameters.Add("@HAB", SqlDbType.TinyInt).Value = 1;
                }
                else
                {
                    scCommand.Parameters.Add("@HAB", SqlDbType.TinyInt).Value = 0;
                }
                if (scCommand.Connection.State == ConnectionState.Closed)
                {
                    scCommand.Connection.Open();
                }
                scCommand.ExecuteNonQuery();
            }
            if (conError)
            {
                transaction.Rollback();
            }
            else
            {
                MessageBox.Show("Operacion realizada exitosamente", "Operacion realizada", MessageBoxButtons.OK, MessageBoxIcon.Information);
                if (modo == 1)
                {
                    limpiar();
                }
                transaction.Commit();
            }
            con.Close();

            back.refrescar();
            if (modo == 2)
            {
                back.Show();
                this.Close();
            }
        }