Ejemplo n.º 1
0
        protected void btInserir_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                Equip equip = new Equip()
                {
                    descri  = tbxDesc.Text,
                    id_cat  = Convert.ToInt32(ddlCat.SelectedValue),
                    id_sala = Convert.ToInt32(ddlSala.SelectedValue)
                };

                if (equip.id_sala == 0)
                {
                    equip.disp = true;
                }
                else
                {
                    equip.disp = false;
                }

                int returncode = EquipDAO.InsertEquip(equip);

                if (returncode == -1)
                {
                    String str = "<script>alertify.error('Inserção feita sem sucesso!');</script>";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);
                    lbErro.Text = "Ja existe um equipamento com esta descrição.";
                    MPE_Erro.Show();
                }
                else
                {
                    if (fluFoto.HasFile == true)
                    {
                        fluFoto.PostedFile.SaveAs(Server.MapPath("~/Content/Imagens/Equips/") + equip.descri + ".jpg");
                    }

                    String str = "<script>alertify.success('Inserção feita com sucesso!');</script>";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Script", str, false);

                    btCancelar.Attributes.Add("onclick", "history.go(-4);location.reload();");
                    btCancelar.Text   = "Voltar";
                    fluFoto.Enabled   = false;
                    tbxDesc.Enabled   = false;
                    ddlSala.Enabled   = false;
                    ddlCat.Enabled    = false;
                    btInserir.Enabled = false;
                }
            }
        }