/** BOTONES ABM HOTEL */
    /** AGREGAR */
    protected void btnAgregarH_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (Control txtBox in listOfCtrls())
            {
                if (txtBox is TextBox && String.IsNullOrEmpty(((TextBox)txtBox).Text))
                {
                    throw new Exception("Existen campos vacíos");
                }
            }

            if (txtFotoH.FileName == "")
            {
                throw new Exception("La imagen del Hotel es requerida");
            }

            string rutaImg = "imagenes/hoteles/" + txtFotoH.FileName;
            Session["hotel"] = new Hotel(txtHotel.Text, txtCalleH.Text, Convert.ToInt32(txtNumeroH.Text), txtCuidadH.Text,
                                         Convert.ToInt32(txtCategoriaH.Text), txtTelH.Text, txtFaxH.Text, rutaImg,
                                         chkPlayaH.Checked, chkPiscinaH.Checked);

            LogicaHotel.Agregar((Hotel)Session["hotel"]);
            txtFotoH.SaveAs(Server.MapPath(rutaImg));
            lblMsj.Text = "Hotel agregado correctamente";

            limpiarFomulario();
        }
        catch (Exception ex)
        { lblMsj.Text = ex.Message; }
    }
Exemplo n.º 2
0
    /** BOTONES ABM HOTEL */
    /** AGREGAR */
    protected void btnAgregarH_Click(object sender, EventArgs e)
    {
        try
        {
            foreach (Control txtBox in listOfTxtBox())
            {
                if (String.IsNullOrEmpty(((TextBox)txtBox).Text))
                {
                    throw new Exception("Existen campos vacíos");
                }
            }

            string rutaImg = "~/imagenes/hoteles/" + txtFotoH.FileName;

            Hotel hotel = new Hotel(txtHotel.Text, txtCalleH.Text, Convert.ToInt32(txtNumeroH.Text), txtCuidadH.Text,
                                    Convert.ToInt32(txtCategoriaH.Text), txtTelH.Text, txtFaxH.Text, rutaImg,
                                    chkPlayaH.Checked, chkPiscinaH.Checked);

            LogicaHotel.Agregar(hotel);
            txtFotoH.SaveAs(Server.MapPath(rutaImg));
            lblMsj.Text = "Hotel agregado correctamente";
            // TO DO limpiar campos
        }
        catch (Exception ex)
        { lblMsj.Text = ex.Message; }
    }