Exemplo n.º 1
0
 /*
  * 1 - Modo de inserção, campos vazios - Usado após Inserir, Apagar e Tirar Seleção
  * 2 - Após escolhida a opção de o produto ser vendido ao peso - Usado no evento do RadioButtonList
  * 3 - Após escolhida a opção de o produto ser vendido à unidade - Usado no evento do RadioButtonList
  * 4 - Modo de edição - Usado após seleccionado o produto na gridview
  * 5 - Após escolhida a opção de o produto não ter variedades
  * 6 - Após escolhida a opção de o produto ter variedades
  */
 protected void IPModo(int modo)
 {
     //Modo de inserção, campos vazios
     if (modo == 1)
     {
         TextBoxIPNome.Text = "";
         if (DropDownListIPMarca.Items.Count > 0)
         {
             DropDownListIPMarca.SelectedIndex = 0;
         }
         if (DropDownListIPCategoria.Items.Count > 0)
         {
             DropDownListIPCategoria.SelectedIndex = 0;
             DropDownListIPSubcategoria.DataBind();
         }
         if (DropDownListIPSubcategoria.Items.Count > 0)
         {
             DropDownListIPSubcategoria.SelectedIndex = 0;
         }
         CheckBoxIPVariedade.Checked = true;
         TextBoxIPPreco.Text         = "";
         RadioButtonListIPPesoouUnid.SelectedIndex = -1;
         TextBoxIPPreco.Enabled           = false;
         LabelIPPrecoporPesoouUnid.Text   = "";
         TextBoxIPQuantidade.Text         = "";
         TextBoxIPQuantidade.Enabled      = false;
         DropDownListIPQuantidade.Enabled = false;
         ButtonIP.Enabled   = true;
         ButtonIP.Visible   = true;
         ButtonEP.Enabled   = false;
         ButtonEP.Visible   = false;
         ButtonAP.Enabled   = false;
         ButtonAP.Visible   = false;
         ButtonEPTS.Enabled = false;
         ButtonEPTS.Visible = false;
         RequiredFieldValidatorIPImagem.Enabled = true;
         DropDownListIPVariedades.Items.Clear();
         GridViewIP.SelectedIndex  = -1;
         GridViewIPV.SelectedIndex = -1;
         TextBoxIPNome.Focus();
     }
     //Modo de edição, após seleccionado o produto na gridview
     else if (modo == 2)
     {
         //Configuração do que fica vísivel e invisível no modo de edição
         ButtonIP.Enabled   = false;
         ButtonIP.Visible   = false;
         ButtonEP.Enabled   = true;
         ButtonEP.Visible   = true;
         ButtonAP.Enabled   = true;
         ButtonAP.Visible   = true;
         ButtonEPTS.Enabled = true;
         ButtonEPTS.Visible = true;
         DropDownListIPVariedades.Items.Clear();
         DropDownListIPVariedades.Enabled = true;
         //Preenchimento dos campos
         TextBoxIPNome.Text = GridViewIP.SelectedRow.Cells[2].Text;
         DropDownListIPMarca.ClearSelection();
         DropDownListIPCategoria.ClearSelection();
         DropDownListIPSubcategoria.ClearSelection();
         DropDownListIPQuantidade.ClearSelection();
         if (DropDownListIPMarca.Items.FindByValue(GridViewIP.SelectedRow.Cells[10].Text) == null)
         {
             ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('Esta marca não existe na base de dados (Verifique se foi apagada).');", true);
         }
         else
         {
             DropDownListIPMarca.SelectedValue = GridViewIP.SelectedRow.Cells[10].Text;
         }
         if (DropDownListIPCategoria.Items.FindByValue(GridViewIP.SelectedRow.Cells[11].Text) == null)
         {
             ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('Esta categoria não existe na base de dados (Verifique se foi apagada).');", true);
         }
         else
         {
             DropDownListIPCategoria.SelectedValue = GridViewIP.SelectedRow.Cells[11].Text;
             DropDownListIPSubcategoria.DataBind();
         }
         if (DropDownListIPSubcategoria.Items.FindByValue(GridViewIP.SelectedRow.Cells[12].Text) == null)
         {
             ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('Esta subcategoria não existe na base de dados (Verifique se foi apagada).');", true);
         }
         else
         {
             DropDownListIPSubcategoria.SelectedValue = GridViewIP.SelectedRow.Cells[12].Text;
         }
         TextBoxIPPreco.Text    = GridViewIP.SelectedRow.Cells[8].Text;
         TextBoxIPPreco.Enabled = true;
         if (GridViewIP.SelectedRow.Cells[13].Text == "False")
         {
             RadioButtonListIPPesoouUnid.SelectedIndex = 0;
             TextBoxIPQuantidade.Text         = "";
             TextBoxIPQuantidade.Enabled      = false;
             DropDownListIPQuantidade.Enabled = false;
             LabelIPPrecoporPesoouUnid.Text   = "ao Kg";
         }
         else if (GridViewIP.SelectedRow.Cells[13].Text == "True")
         {
             RadioButtonListIPPesoouUnid.SelectedIndex = 1;
             TextBoxIPQuantidade.Text = "";
             int j = 0;
             do
             {
                 TextBoxIPQuantidade.Text += GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1);
                 j++;
             } while (GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "x" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == " " | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "0" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "1" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "2" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "3" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "4" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "5" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "6" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "7" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "8" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == "9" | GridViewIP.SelectedRow.Cells[9].Text.Substring(j, 1) == ",");
             try
             {
                 DropDownListIPQuantidade.Items.FindByValue(GridViewIP.SelectedRow.Cells[9].Text.Substring(j, GridViewIP.SelectedRow.Cells[9].Text.Length - j)).Selected = true;
             }
             catch
             {
                 ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('Erro.');", true);
             }
             j = 0;
             TextBoxIPQuantidade.Enabled      = true;
             DropDownListIPQuantidade.Enabled = true;
         }
         LabelIPPrecoporPesoouUnid.Text = "por unidade.";
         //relativo à imagem
         FileUploadIPImagem.Attributes.Clear();
         RequiredFieldValidatorIPImagem.Enabled = false;
         SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString);
         con.Open();
         String     Procurarvariedades = "select * from ProdutosVariedades where FKId_Produtos = @FKId_Produtos";
         SqlCommand comando            = new SqlCommand(Procurarvariedades, con);
         comando.Parameters.AddWithValue("@FKId_Produtos", GridViewIP.SelectedRow.Cells[1].Text);
         SqlDataReader dr = comando.ExecuteReader();
         DropDownListIPVariedades.Items.Clear();
         while (dr.Read())
         {
             if (dr["Variedade"].ToString() == "Sem variedades")
             {
                 CheckBoxIPVariedade.Checked      = true;
                 TextBoxIPVariedade.Enabled       = false;
                 ButtonIPIVariedade.Enabled       = false;
                 ButtonIPAVariedade.Enabled       = false;
                 DropDownListIPVariedades.Enabled = false;
             }
             else
             {
                 CheckBoxIPVariedade.Checked      = false;
                 TextBoxIPVariedade.Enabled       = true;
                 ButtonIPIVariedade.Enabled       = true;
                 ButtonIPAVariedade.Enabled       = true;
                 DropDownListIPVariedades.Enabled = true;
             }
             DropDownListIPVariedades.Items.Add(new ListItem(dr["Variedade"].ToString()));
         }
         dr.Close();
         con.Close();
     }
 }
Exemplo n.º 2
0
 //Produtos
 //Atualizar os Dropdowns relativos às Subcategorias e à filtragem
 protected void DropDownListIPCategoria_SelectedIndexChanged(object sender, EventArgs e)
 {
     DropDownListIPSubcategoria.DataBind();
 }