private void button1_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show("¿DESEA AGREGAR ESTE ELEMENTO?", "PREGUNTA", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (Result == DialogResult.No)
            {
                return;
            }

            if (Utileria.IsEmpty(txtNombre.Text))
            {
                MessageBox.Show("NO SE ACEPTAN CAMPOS VACIOS EN EL NOMBRE", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Utileria.IsEmpty(txtDescripcion.Text))
            {
                MessageBox.Show("NO SE ACEPTAN CAMPOS VACIOS EN LA DESCRIPCIÓN", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (Utileria.IsEmpty(txtNumSerie.Text))
            {
                MessageBox.Show("NO SE ACEPTAN CAMPOS VACIOS EN EL NÚMERO DE SERIE", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            int           Edificio   = 0;
            SqlConnection Connection = UsoBD.ConectaBD(Utileria.GetConnectionString());

            if (Connection == null)
            {
                MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector      = null;
            string        strComandoC = "SELECT ID FROM EDIFICIO WHERE Nombre LIKE '" + cmbEdificio.SelectedItem.ToString() + "'";

            Lector = UsoBD.Consulta(strComandoC, Connection);

            if (Lector == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Connection.Close();
                return;
            }
            if (Lector.HasRows)
            {
                while (Lector.Read())
                {
                    Edificio = Convert.ToInt32(Lector.GetValue(0).ToString());
                }
            }
            Connection.Close();

            SqlConnection Connection2 = UsoBD.ConectaBD(Utileria.GetConnectionString());

            if (Connection2 == null)
            {
                MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            string strComando = "INSERT INTO LOCALIZACION(Nombre,NumPlanta,ID_Edificio,Ubicacion)";

            strComando += " VALUES(@Nombre,@NumPlanta,@ID_Edificio,@Ubicacion)";
            SqlCommand Insert = new SqlCommand(strComando, Connection2);

            Insert.Parameters.AddWithValue("@Nombre", txtUbicacion.Text.Trim());
            Insert.Parameters.AddWithValue("@NumPlanta", nudPlanta.Text);
            Insert.Parameters.AddWithValue("@ID_Edificio", Edificio);
            Insert.Parameters.AddWithValue("@Ubicacion", txtDescUbicacion.Text.Trim());

            try
            {
                Insert.ExecuteNonQuery();
            }
            catch (SqlException Ex)
            {
                foreach (SqlError item in Ex.Errors)
                {
                    MessageBox.Show(item.Message);
                }

                Connection2.Close();
                return;
            }
            Connection2.Close();

            int           Loc         = 0;
            SqlConnection Connection3 = UsoBD.ConectaBD(Utileria.GetConnectionString());

            if (Connection3 == null)
            {
                MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }
                return;
            }

            SqlDataReader Lector2     = null;
            string        strComando2 = "SELECT ID FROM LOCALIZACION WHERE Ubicacion LIKE '" + txtDescUbicacion.Text.Trim() + "'";

            Lector2 = UsoBD.Consulta(strComando2, Connection3);

            if (Lector2 == null)
            {
                MessageBox.Show("ERROR AL HACER LA CONSULTA");
                foreach (SqlError E in UsoBD.ESalida.Errors)
                {
                    MessageBox.Show(E.Message);
                }

                Connection3.Close();
                return;
            }
            if (Lector2.HasRows)
            {
                while (Lector2.Read())
                {
                    Loc = Convert.ToInt32(Lector2.GetValue(0).ToString());
                }
            }
            Connection3.Close();

            int Enc = AdmEmp.GetIDByName(cmbEncargado.SelectedItem.ToString());
            int Pov = AdmPro.GetID(cmbProveedor.SelectedItem.ToString());

            AdmCI.AddCI(txtNombre.Text, txtDescripcion.Text, txtNumSerie.Text, maskDate.Text, Loc, Enc, Pov);
        }
        private void btnActualizar_Click(object sender, EventArgs e)
        {
            DialogResult Result = MessageBox.Show("¿DESEA GUARDAR LOS CAMBIOS?", "PREGUNTA", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (Result == DialogResult.No)
            {
                return;
            }

            string Nombre   = cmbNombre.SelectedItem.ToString();
            string NumSerie = AdmCI.GetNumSerie(Nombre);
            int    ID       = AdmCI.GetID(NumSerie);

            if (!(Utileria.IsEmpty(txtDescripcion.Text)))
            {
                AdmCI.UpdateDesc(ID, txtDescripcion.Text);
            }
            if (!(Utileria.IsEmpty(maskDate.Text)))
            {
                AdmCI.UpdateDate(ID, maskDate.Text);
            }
            if (!(Utileria.IsEmpty(txtUbicacion.Text)))
            {
                int LocID = AdmCI.GetIDLoc(NumSerie.Trim());

                SqlConnection Connection = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                string strComando = "UPDATE LOCALIZACION SET Nombre=@Nombre WHERE ID=@ID";

                SqlCommand Update = new SqlCommand(strComando, Connection);

                Update.Parameters.AddWithValue("@Nombre", txtUbicacion.Text);
                Update.Parameters.AddWithValue("@ID", LocID);

                try
                {
                    Update.ExecuteNonQuery();
                }
                catch (SqlException Ex)
                {
                    foreach (SqlError item in Ex.Errors)
                    {
                        MessageBox.Show(item.Message);
                    }

                    Connection.Close();
                    return;
                }
                Connection.Close();
                //MessageBox.Show("CAMPO 'NOMBRE DE LA UBICACIÓN' ACTUALIZADO EXITOSAMENTE", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (!(Utileria.IsEmpty(txtDescUbicacion.Text)))
            {
                int LocID = AdmCI.GetIDLoc(NumSerie.Trim());

                SqlConnection Connection = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                string strComando = "UPDATE LOCALIZACION SET Ubicacion=@Ubicacion WHERE ID=@ID";

                SqlCommand Update = new SqlCommand(strComando, Connection);

                Update.Parameters.AddWithValue("@Ubicacion", txtDescUbicacion.Text);
                Update.Parameters.AddWithValue("@ID", LocID);

                try
                {
                    Update.ExecuteNonQuery();
                }
                catch (SqlException Ex)
                {
                    foreach (SqlError item in Ex.Errors)
                    {
                        MessageBox.Show(item.Message);
                    }

                    Connection.Close();
                    return;
                }
                Connection.Close();
                //MessageBox.Show("CAMPO 'DESCRIPCION DE LA UBICACIÓN' ACTUALIZADO EXITOSAMENTE", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            if (cmbProveedor.SelectedIndex >= 0)
            {
                string Prov  = cmbProveedor.SelectedItem.ToString();
                int    IDPro = AdmProv.GetID(Prov);
                int    IDCI  = AdmCI.GetID(NumSerie);


                SqlConnection Connection2 = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection2 == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                string strComando2 = "UPDATE CI SET ID_Proveedor=@ID_Proveedor WHERE ID=@ID";

                SqlCommand Update = new SqlCommand(strComando2, Connection2);

                Update.Parameters.AddWithValue("@ID_Proveedor", IDPro);
                Update.Parameters.AddWithValue("@ID", IDCI);

                try
                {
                    Update.ExecuteNonQuery();
                }
                catch (SqlException Ex)
                {
                    foreach (SqlError item in Ex.Errors)
                    {
                        MessageBox.Show(item.Message);
                    }

                    Connection2.Close();
                    return;
                }
                Connection2.Close();
            }
            if (cmbEncargado.SelectedIndex >= 0)
            {
                string Enc  = cmbEncargado.SelectedItem.ToString();
                int    IDEm = AdmEmp.GetIDByName(Enc);
                int    IDCI = AdmCI.GetID(NumSerie);


                SqlConnection Connection2 = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection2 == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                string strComando2 = "UPDATE CI SET ID_Encargado=@ID_Encargado WHERE ID=@ID";

                SqlCommand Update = new SqlCommand(strComando2, Connection2);

                Update.Parameters.AddWithValue("@ID_Encargado", IDEm);
                Update.Parameters.AddWithValue("@ID", IDCI);

                try
                {
                    Update.ExecuteNonQuery();
                }
                catch (SqlException Ex)
                {
                    foreach (SqlError item in Ex.Errors)
                    {
                        MessageBox.Show(item.Message);
                    }

                    Connection2.Close();
                    return;
                }
                Connection2.Close();
            }
            if (cmbEdificio.SelectedIndex >= 0)
            {
                string Ed    = cmbEdificio.SelectedItem.ToString();
                int    IDLoc = AdmCI.GetIDLoc(NumSerie);
                int    IDEd  = 0;

                SqlConnection Connection = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                SqlDataReader Lector = null;

                string strComandoC = "SELECT ID FROM EDIFICIO WHERE Nombre LIKE '" + Ed + "'";

                Lector = UsoBD.Consulta(strComandoC, Connection);
                if (Lector == null)
                {
                    MessageBox.Show("ERROR AL HACER LA CONSULTA");
                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }

                    Connection.Close();
                    return;
                }
                if (Lector.HasRows)
                {
                    while (Lector.Read())
                    {
                        IDEd = Convert.ToInt32(Lector.GetValue(0).ToString());
                    }
                }
                Connection.Close();

                SqlConnection Connection2 = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection2 == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                string strComando2 = "UPDATE LOCALIZACION SET ID_Edificio=@ID_Edificio WHERE ID=@ID";

                SqlCommand Update = new SqlCommand(strComando2, Connection2);

                Update.Parameters.AddWithValue("@ID_Edificio", IDEd);
                Update.Parameters.AddWithValue("@ID", IDLoc);

                try
                {
                    Update.ExecuteNonQuery();
                }
                catch (SqlException Ex)
                {
                    foreach (SqlError item in Ex.Errors)
                    {
                        MessageBox.Show(item.Message);
                    }

                    Connection2.Close();
                    return;
                }
                Connection2.Close();
            }
            if (nudPlanta.Value >= 1)
            {
                int num   = Convert.ToInt32(nudPlanta.Value);
                int IDLoc = AdmCI.GetIDLoc(NumSerie);

                SqlConnection Connection2 = UsoBD.ConectaBD(Utileria.GetConnectionString());

                if (Connection2 == null)
                {
                    MessageBox.Show("ERROR DE CONEXIÓN CON LA BASE DE DATOS");

                    foreach (SqlError E in UsoBD.ESalida.Errors)
                    {
                        MessageBox.Show(E.Message);
                    }
                    return;
                }
                string strComando2 = "UPDATE LOCALIZACION SET NumPlanta=@NumPlanta WHERE ID=@ID";

                SqlCommand Update = new SqlCommand(strComando2, Connection2);

                Update.Parameters.AddWithValue("@NumPlanta", num);
                Update.Parameters.AddWithValue("@ID", IDLoc);

                try
                {
                    Update.ExecuteNonQuery();
                }
                catch (SqlException Ex)
                {
                    foreach (SqlError item in Ex.Errors)
                    {
                        MessageBox.Show(item.Message);
                    }

                    Connection2.Close();
                    return;
                }
                Connection2.Close();
            }
            MessageBox.Show("ELEMENTO DE CONFIGURACION ACTUALIZADO EXITOSAMENTE", "AVISO", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }