Beispiel #1
0
        public byte AgregarEmpleado(EmpleadoClass emp)
        {
            try
            {
                conectar();
                string qry = "sp_Empleados";
                _comandosql                = new SqlCommand(qry, _conexion);
                _comandosql.CommandType    = CommandType.StoredProcedure;
                _comandosql.CommandTimeout = 9000;

                var param1 = _comandosql.Parameters.Add("@proc", SqlDbType.VarChar, 16);
                param1.Value = "insert";
                var param2 = _comandosql.Parameters.Add("@id_adm", SqlDbType.SmallInt);
                param2.Value = emp.id_admin;
                var param3 = _comandosql.Parameters.Add("@nom", SqlDbType.VarChar, 60);
                param3.Value = emp.nom;
                var param4 = _comandosql.Parameters.Add("@ape", SqlDbType.VarChar, 60);
                param4.Value = emp.ape;
                var param5 = _comandosql.Parameters.Add("@fec_nac", SqlDbType.Date);
                param5.Value = emp.fec_nac;
                var param6 = _comandosql.Parameters.Add("@curp", SqlDbType.Char, 18);
                param6.Value = emp.curp;
                var param7 = _comandosql.Parameters.Add("@rfc", SqlDbType.Char, 13);
                param7.Value = emp.rfc;
                var param8 = _comandosql.Parameters.Add("@correo_e", SqlDbType.VarChar, 60);
                param8.Value = emp.correo_e;
                var param9 = _comandosql.Parameters.Add("@contra", SqlDbType.Char, 8);
                param9.Value = emp.contra;

                _adaptador.InsertCommand = _comandosql;
                if (_comandosql.ExecuteNonQuery() == 0)
                {
                    return(1);
                }

                return(0);
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(10);
            }
            finally
            {
                desconectar();
            }
        }
Beispiel #2
0
        public byte ModificarEmpleado(EmpleadoClass newemp, EmpleadoClass oldemp)
        {
            try
            {
                conectar();
                string qry = "sp_Empleados";
                _comandosql                = new SqlCommand(qry, _conexion);
                _comandosql.CommandType    = CommandType.StoredProcedure;
                _comandosql.CommandTimeout = 9000;

                var param1 = _comandosql.Parameters.Add("@proc", SqlDbType.VarChar, 16);
                param1.Value = "update";
                var param2 = _comandosql.Parameters.Add("@num_emp", SqlDbType.Int);
                param2.Value = oldemp.num_emp;
                if (newemp.nom != oldemp.nom)
                {
                    var param3 = _comandosql.Parameters.Add("@nom", SqlDbType.VarChar, 60);
                    param3.Value = newemp.nom;
                }
                if (newemp.ape != oldemp.ape)
                {
                    var param4 = _comandosql.Parameters.Add("@ape", SqlDbType.VarChar, 60);
                    param4.Value = newemp.ape;
                }
                if (newemp.fec_nac != oldemp.fec_nac)
                {
                    var param5 = _comandosql.Parameters.Add("@fec_nac", SqlDbType.Date);
                    param5.Value = newemp.fec_nac;
                }
                if (newemp.rfc != oldemp.rfc)
                {
                    var param6 = _comandosql.Parameters.Add("@rfc", SqlDbType.Char, 13);
                    param6.Value = newemp.rfc;
                }
                if (newemp.curp != oldemp.curp)
                {
                    var param7 = _comandosql.Parameters.Add("@curp", SqlDbType.Char, 18);
                    param7.Value = newemp.curp;
                }
                if (newemp.correo_e != oldemp.correo_e)
                {
                    var param8 = _comandosql.Parameters.Add("@correo_e", SqlDbType.VarChar, 60);
                    param8.Value = newemp.correo_e;
                }
                if (newemp.contra != oldemp.contra)
                {
                    var param9 = _comandosql.Parameters.Add("@contra", SqlDbType.Char, 8);
                    param9.Value = newemp.contra;
                }

                _adaptador.UpdateCommand = _comandosql;
                if (_comandosql.ExecuteNonQuery() == 0)
                {
                    return(1);
                }
                return(0);
            }
            catch (SqlException e)
            {
                MessageBox.Show(e.ToString(), "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(10);
            }
            finally
            {
                desconectar();
            }
        }