コード例 #1
0
    protected void ButtonEditar_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString);

        con.Open();
        String     Procurarrepetidos = "select count(*) from ProdutosPromocoes where FKId_Produtos=@FKId_Produtos and Id_ProdutosPromocoes!=@Id_ProdutosPromocoes and ((@DatadeInicio between DatadeInicio and DatadeFim) or (@DatadeFim between DatadeInicio and DatadeFim))";
        SqlCommand comando           = new SqlCommand(Procurarrepetidos, con);

        if (GridViewPromocoes.SelectedIndex > -1)
        {
            comando.Parameters.AddWithValue("@FKId_Produtos", GridViewPromocoes.SelectedRow.Cells[1].Text);
            comando.Parameters.AddWithValue("@Id_ProdutosPromocoes", GridViewPromocoes.SelectedRow.Cells[4].Text);
        }
        else if (GridViewPromocoesPassadas.SelectedIndex > -1)
        {
            comando.Parameters.AddWithValue("@FKId_Produtos", GridViewPromocoesPassadas.SelectedRow.Cells[1].Text);
            comando.Parameters.AddWithValue("@Id_ProdutosPromocoes", GridViewPromocoesPassadas.SelectedRow.Cells[4].Text);
        }
        DateTime DataInicial = DateTime.ParseExact(TextBoxDataInicial.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);
        DateTime DataFinal   = DateTime.ParseExact(TextBoxDataFinal.Text, "dd/MM/yyyy", CultureInfo.InvariantCulture);

        comando.Parameters.AddWithValue("@DatadeInicio", DataInicial);
        comando.Parameters.AddWithValue("@DatadeFim", DataFinal);
        int temp = Convert.ToInt32(comando.ExecuteScalar().ToString());

        if (temp > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('Já existe uma promoção para o mesmo produto, entre estes intervalos de tempo.');", true);
        }
        else if (temp == 0)
        {
            String     Editarpromocao = "update ProdutosPromocoes set DatadeInicio=@DatadeInicio, DatadeFim=@DatadeFim, PercentagemdeDesconto=@PercentagemdeDesconto, PrecoemDesconto=@PrecoemDesconto, DinheiroPoupado=@DinheiroPoupado where Id_ProdutosPromocoes=@Id_ProdutosPromocoes";
            SqlCommand comandoEditar  = new SqlCommand(Editarpromocao, con);
            if (GridViewPromocoes.SelectedIndex > -1)
            {
                comandoEditar.Parameters.AddWithValue("@Id_ProdutosPromocoes", GridViewPromocoes.SelectedRow.Cells[4].Text);
            }
            else if (GridViewPromocoesPassadas.SelectedIndex > -1)
            {
                comandoEditar.Parameters.AddWithValue("@Id_ProdutosPromocoes", GridViewPromocoesPassadas.SelectedRow.Cells[4].Text);
            }
            comandoEditar.Parameters.AddWithValue("@DatadeInicio", DataInicial);
            comandoEditar.Parameters.AddWithValue("@DatadeFim", DataFinal);
            comandoEditar.Parameters.AddWithValue("@PercentagemdeDesconto", Math.Round(float.Parse(TextBoxPercentagemdeDesconto.Text), 2));
            comandoEditar.Parameters.AddWithValue("@PrecoemDesconto", Math.Round(float.Parse(TextBoxPrecoemDesconto.Text), 2));
            comandoEditar.Parameters.AddWithValue("@DinheiroPoupado", Math.Round(float.Parse(TextBoxPoupanca.Text), 2));
            comandoEditar.ExecuteNonQuery();
            GridViewProdutos.DataBind();
            GridViewPromocoes.DataBind();
            GridViewPromocoesPassadas.DataBind();
        }
        con.Close();
    }
コード例 #2
0
    protected void ButtonApagar_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString);

        con.Open();
        String     Apagarpromocao = "delete from ProdutosPromocoes where Id_ProdutosPromocoes=@Id_ProdutosPromocoes";
        SqlCommand comandoApagar  = new SqlCommand(Apagarpromocao, con);

        if (GridViewPromocoes.SelectedIndex > -1)
        {
            comandoApagar.Parameters.AddWithValue("@Id_ProdutosPromocoes", GridViewPromocoes.SelectedRow.Cells[4].Text);
        }
        else if (GridViewPromocoesPassadas.SelectedIndex > -1)
        {
            comandoApagar.Parameters.AddWithValue("@Id_ProdutosPromocoes", GridViewPromocoesPassadas.SelectedRow.Cells[4].Text);
        }
        comandoApagar.ExecuteNonQuery();
        con.Close();
        GridViewProdutos.DataBind();
        GridViewPromocoes.DataBind();
        viewmode(1);
    }
コード例 #3
0
    protected void ButtonInserir_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString2"].ConnectionString);

        con.Open();
        String     Procurarrepetidos = "select count(*) from ProdutosPromocoes where FKId_Produtos = @FKId_Produtos and @DatadeFim >= DatadeInicio and @DatadeInicio <= DatadeFim";
        SqlCommand comando           = new SqlCommand(Procurarrepetidos, con);

        comando.Parameters.AddWithValue("@FKId_Produtos", GridViewProdutos.SelectedRow.Cells[1].Text);
        DateTime DataInicial = DateTime.ParseExact(TextBoxDataInicial.Text, "dd/MM/yyyy", null);
        DateTime DataFinal   = DateTime.ParseExact(TextBoxDataFinal.Text, "dd/MM/yyyy", null);

        comando.Parameters.AddWithValue("@DatadeInicio", DataInicial);
        comando.Parameters.AddWithValue("@DatadeFim", DataFinal);
        int temp = Convert.ToInt32(comando.ExecuteScalar().ToString());

        if (temp > 0)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "Aviso", "alert('Já existe uma promoção para o mesmo produto, entre estes intervalos de tempo.');", true);
        }
        else if (temp == 0)
        {
            String     Inserirpromocao = "insert into ProdutosPromocoes (FKId_Produtos, DatadeInicio, DatadeFim, PercentagemdeDesconto, PrecoemDesconto, DinheiroPoupado) values (@FKId_Produtos, @DatadeInicio, @DatadeFim, @PercentagemdeDesconto, @PrecoemDesconto, @DinheiroPoupado)";
            SqlCommand comandoInserir  = new SqlCommand(Inserirpromocao, con);
            comandoInserir.Parameters.AddWithValue("@FKId_Produtos", GridViewProdutos.SelectedRow.Cells[1].Text);
            comandoInserir.Parameters.AddWithValue("@DatadeInicio", DataInicial);
            comandoInserir.Parameters.AddWithValue("@DatadeFim", DataFinal);
            comandoInserir.Parameters.AddWithValue("@PercentagemdeDesconto", Math.Round(float.Parse(TextBoxPercentagemdeDesconto.Text), 2));
            comandoInserir.Parameters.AddWithValue("@PrecoemDesconto", Math.Round(float.Parse(TextBoxPrecoemDesconto.Text), 2));
            comandoInserir.Parameters.AddWithValue("@DinheiroPoupado", Math.Round(float.Parse(TextBoxPoupanca.Text), 2));
            comandoInserir.ExecuteNonQuery();
            GridViewProdutos.DataBind();
            GridViewPromocoes.DataBind();
            GridViewPromocoesPassadas.DataBind();
            viewmode(1);
        }
        con.Close();
    }