public void descricaoDesejo(long codigo)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            Context.Response.Clear();
            Context.Response.ContentType = "application/json";
            HelloWorldData data = new HelloWorldData();
            //data.Message = "HelloWorld";
            


            Desejo desejo = new Desejo();
            desejo.IdDesejo = codigo;
            ArrayList alTemp = DataAccess.queryDesejo(desejo, null);
            if (alTemp.Count == 0)
            {
                //return "Nenhum desejo encontrado.";
                data.Message = "Nenhum desejo encontrado.";                
            }
            else
            {
                desejo = (Desejo)alTemp[0];
                //return desejo.DescricaoCurta;
                data.Message = desejo.DescricaoCurta;
            }
            Context.Response.Write(js.Serialize(data));
        }//descricaoDesejo()
Exemple #2
0
 public Proposta()
 {
     IdProposta = -1;
     Desejo = null;
     Usuario = null;
     DataProposta = DateTime.MinValue;
     TipoProposta = null;
     ValorProposta = -1;
     NumMensagens = 0;
     IsDeleted = 0;//para setar a busca inicialmente para considerar somente propostas não deletadas
 }
        protected new void Page_Load(object sender, EventArgs e)
        {
            desejo = (Desejo)Session["Desejo"];
            if (desejo == null)
            {
                Session["mensagem"] = "Desejo não encontrado.";
                return;
            }

            LinkButtonDesejo.Text = Utils.truncateString(desejo.DescricaoCurta);

            if (IsPostBack) return;//daqui pra baixo, tudo vai ser executado somente se não for post back:

            ArrayList alTemp = DataAccess.queryTipoProposta(new TipoProposta(), null);
            foreach (TipoProposta tp in alTemp)
            {
                ListItem item = new ListItem(tp.Descricao, tp.IdTipoProposta.ToString());
                DropDownListTipoProposta.Items.Add(item);
            }

        }
        }//ValidateSHA1HashData()

        private static Desejo populateDesejo(SqlDataReader dr)
        {
            Desejo desejoReturn = new Desejo();

            desejoReturn.IdDesejo = System.Convert.ToInt64(dr["id_desejo"]);
            desejoReturn.Usuario = populateUsuario(dr, "UD_");
            desejoReturn.Departamento = populateDepartamento(dr);
            desejoReturn.DescricaoCurta = System.Convert.ToString(dr["descricao_curta"]).Trim();
            desejoReturn.DescricaoLonga = System.Convert.ToString(dr["descricao_longa"]).Trim();
            desejoReturn.LocalBusca = populateLocalDesejo(dr, LocalDesejo.TipoLocalDesejo.BUSCA);
            desejoReturn.LocalEntrega = populateLocalDesejo(dr, LocalDesejo.TipoLocalDesejo.ENTREGA);
            desejoReturn.DataAnuncio = System.Convert.ToDateTime(dr["data_anuncio"]);
            desejoReturn.IsDeleted = System.Convert.ToInt16(dr["is_deleted_desejo"]);
            //desejoReturn.IsAtivo = System.Convert.ToInt16(dr["ativo"]);

            /*
            if (dr.IsDBNull(dr.GetOrdinal("preco_maximo")))
            {
                desejoReturn.PrecoMaximo = -1;
            }
            else
            {
                desejoReturn.PrecoMaximo = System.Convert.ToDouble(dr["preco_maximo"]);
            }
            */

            if (dr.IsDBNull(dr.GetOrdinal("id_proposta_aceita")))
            {
                desejoReturn.HasPropostaSelecionada = 0;
            }
            else
            {
                desejoReturn.HasPropostaSelecionada = 1;
                desejoReturn.IdPropostaAceita = System.Convert.ToInt64(dr["id_proposta_aceita"]);
            }
                        
            desejoReturn.NumPropostas = System.Convert.ToInt32(dr["numpropostas"]);

            return desejoReturn;
        }//populateDesejo()
        }//Page_Load()

        protected void ButtonSalvar_Click(object sender, EventArgs e)
        {
            Desejo desejoNovo = new Desejo();
            desejoNovo.DescricaoCurta = txtTitulo.Text;
            desejoNovo.DescricaoLonga = txtDescricao.Text;
            desejoNovo.Departamento = new Departamento();
            desejoNovo.Departamento.Id = System.Convert.ToInt32(ListaDepartamentos.SelectedValue);

            desejoNovo.LocalBusca = new LocalDesejo();
            desejoNovo.LocalBusca.IdLocal = System.Convert.ToInt32(OndeEncontrar.SelectedValue);

            desejoNovo.LocalEntrega = new LocalDesejo();
            desejoNovo.LocalEntrega.IdLocal = System.Convert.ToInt32(OndeEntregar.SelectedValue);

            desejoNovo.Usuario = new Usuario();
            desejoNovo.Usuario.IdUsuario = ((Usuario)Session["UsuarioLogado"]).IdUsuario;
            //desejoNovo.IsAtivo = 0;
            //desejoNovo.PrecoMaximo = System.Convert.ToDouble(txtPrecoMaximo.Text);

            if (DataAccess.salvarDesejo(desejoNovo) >= 0)//sucesso
            {
                Session["mensagem"] = "Desejo criado com sucesso! Que tal adicionar links de exemplo para ajudar a encontrar seu desejo?";
                /*
                Desejo desejoBusca = new Desejo();
                desejoBusca.Usuario = new Usuario();
                desejoBusca.Usuario.IdUsuario = ((Usuario)Session["UsuarioLogado"]).IdUsuario;
                Session["DesejoBusca"] = desejoBusca;
                Response.Redirect("BuscaDesejos.aspx");
                */
                Response.Redirect("ShowDesejo.aspx?id_desejo=" + desejoNovo.IdDesejo.ToString());
            }
            else
            {
                Session["mensagem"] = "Erro na criação do desejo.";
            }            
        }
        protected void LinkButtonMeusDesejos_Click(object sender, EventArgs e)
        {
            Usuario usuarioBusca = usuarioLogado;
            if (usuarioBusca == null)
            {
                lblMensagem.Text = "Usuário não logado. Faça login primeiro.";
                return;
            }

            Desejo desejoBusca = new Desejo();
            desejoBusca.Usuario = new Usuario();
            desejoBusca.Usuario.IdUsuario = usuarioBusca.IdUsuario;
            Session["DesejoBusca"] = desejoBusca;

            LIqueryParameters par = new LIqueryParameters();
            ColumnOrder col = new ColumnOrder();
            col.ColumnName = "data_anuncio";
            col.Order = ColumnOrder.OrderType.DESC;
            par.OrderBy.Add(col);
            Session["ParamsBuscaDesejo"] = par;

            Response.Redirect("BuscaDesejos.aspx");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Browser.IsMobileDevice & Utils.HabilitarMobile)
            {
                lblIsMobile.Text = "Versão Mobile";
            }
            else
            {
                lblIsMobile.Text = "Versão Desktop";
            }

            pageStack = (PageStack)Session["PageStack"];

            if (pageStack == null)
            {
                LinkButtonVoltar.Visible = false;
            }
            else
            {
                if (pageStack.hasPages())
                {
                    LinkButtonVoltar.Visible = true;
                }
                else
                {
                    LinkButtonVoltar.Visible = false;
                }
            }

            usuarioLogado = (Usuario)Session["UsuarioLogado"];
            lblMensagem.Text = (String)Session["mensagem"];
            Session["mensagem"] = "";

            if (usuarioLogado != null)
            {
                LinkButtonUsuarioLogado.Text = usuarioLogado.Apelido;
                LinkButtonUsuarioLogado.Enabled = true;
                btnLogout.Visible = true;
                btnLogin.Visible = false;
                LinkButtonMeusDesejos.Visible = true;
                HyperLinkCriarDesejo.Visible = true;
                LinkButtonPropostasRecebidas.Visible = true;
                LinkButtonPropostasFeitas.Visible = true;
            }
            else
            {
                LinkButtonUsuarioLogado.Text = "Não logado";
                LinkButtonUsuarioLogado.Enabled = false;
                btnLogout.Visible = false;
                btnLogin.Visible = true;
                LinkButtonMeusDesejos.Visible = false;
                HyperLinkCriarDesejo.Visible = false;
                LinkButtonPropostasRecebidas.Visible = false;
                LinkButtonPropostasFeitas.Visible = false;
            }

            if (Session["PedirConfirmacao"] != null)
            {
                if ((bool)Session["PedirConfirmacao"])
                {
                    btnConfirm.Visible = true;
                    btnCancel.Visible = true;
                }
                else
                {
                    btnConfirm.Visible = false;
                    btnCancel.Visible = false;
                }
            }
            else
            {
                btnConfirm.Visible = false;
                btnCancel.Visible = false;
            }
            Session["PedirConfirmacao"] = false;
            desejo = (Desejo)Session["Desejo"];
            if (desejo == null)
            {
                LinkButtonUltimoDesejo.Visible = false;
                lblUltimoDesejo.Visible = false;
            }
            else
            {
                lblUltimoDesejo.Visible = true;
                LinkButtonUltimoDesejo.Visible = true;
                LinkButtonUltimoDesejo.Text = Utils.truncateString(desejo.DescricaoCurta);
                LinkButtonUltimoDesejo.Click += LinkButtonUltimoDesejo_Click;
            }            
        }//Page_Load()
        protected void btnConfirm_Click(object sender, EventArgs e)
        {
            object deleteObject = Session["DeleteObject"];
            Session["DeleteObject"] = null;

            //para evitar inconsistências:
            ((PageStack)Session["PageStack"]).clear();

            if (deleteObject is Desejo)
            {
                if (DataAccess.deleteDesejo((Desejo)deleteObject) == 0)
                {
                    Session["mensagem"] = "Desejo apagado com sucesso";
                    Desejo desejoBusca = new Desejo();
                    desejoBusca.Usuario = new Usuario();
                    desejoBusca.Usuario.IdUsuario = ((Usuario)Session["UsuarioLogado"]).IdUsuario;
                    Session["DesejoBusca"] = desejoBusca;
                    Response.Redirect("BuscaDesejos.aspx");
                }
                else
                {
                    Session["mensagem"] = "Erro ao apagar desejo";                    
                }
                return;
            }//if

            if (deleteObject is Proposta)
            {
                if (DataAccess.deleteProposta(((Proposta)deleteObject).IdProposta) == 0)
                {
                    Session["mensagem"] = "Proposta apagada com sucesso";
                    if (Session["PropostaBusca"] != null)
                    {
                        Response.Redirect("BuscaPropostas.aspx");
                    }
                    else
                    {
                        Response.Redirect("home.aspx");
                    }
                }
                else
                {
                    Session["mensagem"] = "Erro ao apagar proposta";
                }
                return;
            }//if

            if (deleteObject is URLDesejo)
            {
                if (DataAccess.deleteURLDesejo((URLDesejo)deleteObject) == URLDesejo.EnumErroURL.SUCESSO)
                {
                    Session["mensagem"] = "link apagado com sucesso";
                }
                else
                {
                    Session["mensagem"] = "erro ao apagar o link";
                }
                Response.Redirect("ShowDesejo.aspx?id_desejo=" + ((URLDesejo)deleteObject).IdDesejo.ToString());
            }//if
        }//btnConfirm_Click()
        }//populateAvaliacao()

        public static ArrayList queryDesejo(Desejo desejoBusca, LIqueryParameters paramsBusca)
        {
            ArrayList alReturn = null;
            SqlDataReader dr = null;
            SqlConnection conn = null;
            SqlCommand cmd = null;
            bool bWhere = false;
            int iTemp;

            String strSql = "SELECT";
            //LB: Local Busca, LE: Local Entrega
            String strSelect = " D.*";
            //U.id_usuario UD_id_usuario, U.apelido UD_apelido, U.facebook_name UD_facebook_name";
            foreach (String strColuna in Usuario.Colunas)
            {
                strSelect += ",U." + strColuna + " UD_" + strColuna;
            }

            strSelect += ", DP.*, LB.id_local LB_id_local, LB.id_local_pai LB_id_local_pai, LB.NomeLocal LB_NomeLocal";
            strSelect += ", LE.id_local LE_id_local, LE.id_local_pai LE_id_local_pai, LE.NomeLocal LE_NomeLocal";

            if (paramsBusca == null)
            {
                paramsBusca = new LIqueryParameters();
                paramsBusca.Top = 1000;
            }

            if (paramsBusca != null)
            {
                if (paramsBusca.Top > 0)
                {
                    strSql += " TOP " + paramsBusca.Top.ToString() + strSelect;
                }
                else
                {
                    strSql += strSelect;
                }
            }
            else
            {
                strSql += strSelect;
            }

            strSql += ", S.numpropostas FROM Desejo D INNER JOIN Usuario U ON D.id_usuario = U.id_usuario";
            strSql += " INNER JOIN Departamento DP ON D.id_departamento = DP.id_departamento";
            strSql += " INNER JOIN Local LB ON D.id_local_busca = LB.id_local";
            strSql += " INNER JOIN Local LE ON D.id_local_entrega = LE.id_local";
            strSql += " INNER JOIN (";
            strSql += " SELECT D2.id_desejo, count(P.id_proposta) numpropostas FROM Desejo D2 ";
            strSql += " LEFT JOIN Proposta P ON D2.id_desejo = P.id_desejo";
            strSql += " WHERE P.is_deleted_proposta = 0";
            strSql += " GROUP BY D2.id_desejo ) S ON D.id_desejo = S.id_desejo";

            if (desejoBusca.IsDeleted >= 0)
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.is_deleted_desejo = " + desejoBusca.IsDeleted.ToString();
            }

            if (desejoBusca.DataAnuncio != DateTime.MinValue)
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.data_anuncio = " + Utils.formatParameterToSqlServer(desejoBusca.DataAnuncio);
            }//if

            if (desejoBusca.DescricaoCurta != "")
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.descricao_curta LIKE '%" + desejoBusca.DescricaoCurta + "'%";
            }//if

            if (desejoBusca.DescricaoLonga != "")
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.descricao_longa LIKE '%" + desejoBusca.DescricaoLonga + "%'";
            }//if

            if (desejoBusca.Departamento != null)
            {
                if (desejoBusca.Departamento.Id >= 0)
                {
                    if (bWhere)
                    {
                        strSql += " AND ";
                    }
                    else
                    {
                        strSql += " WHERE ";
                        bWhere = true;
                    }
                    strSql += "D.id_departamento = " + desejoBusca.Departamento.Id.ToString();
                }
            }//if

            if (desejoBusca.IdDesejo >= 0)
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.id_desejo = " + desejoBusca.IdDesejo.ToString();
            }//if

            if (desejoBusca.LocalBusca != null)
            {
                if (desejoBusca.LocalBusca.IdLocal >= 0)
                {
                    if (bWhere)
                    {
                        strSql += " AND ";
                    }
                    else
                    {
                        strSql += " WHERE ";
                        bWhere = true;
                    }
                    strSql += "D.id_local_busca = " + desejoBusca.LocalBusca.IdLocal.ToString();
                }
            }//if

            if (desejoBusca.LocalEntrega != null)
            {
                if (desejoBusca.LocalEntrega.IdLocal >= 0)
                {
                    if (bWhere)
                    {
                        strSql += " AND ";
                    }
                    else
                    {
                        strSql += " WHERE ";
                        bWhere = true;
                    }
                    strSql += "D.id_local_entrega = " + desejoBusca.LocalEntrega.IdLocal.ToString();
                }
            }//if

            if (desejoBusca.Usuario != null)
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.id_usuario = " + desejoBusca.Usuario.IdUsuario.ToString();
            }//if

            /*
            if (desejoBusca.IsAtivo >= 0)
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                strSql += "D.ativo = " + ((desejoBusca.IsAtivo > 0) ? ("1") : ("0"));
            }//if
            */

            if (desejoBusca.HasPropostaSelecionada >= 0)
            {
                if (bWhere)
                {
                    strSql += " AND ";
                }
                else
                {
                    strSql += " WHERE ";
                    bWhere = true;
                }
                if (desejoBusca.HasPropostaSelecionada == 0)
                {
                    strSql += "D.id_proposta_aceita IS NULL";
                }
                else
                {
                    strSql += "D.id_proposta_aceita IS NOT NULL";
                }
            }

            if (paramsBusca != null)
            {
                if (paramsBusca.OrderBy.Count != 0)
                {
                    strSql += " ORDER BY ";
                    iTemp = 0;
                    foreach (ColumnOrder col in paramsBusca.OrderBy)
                    {
                        if (iTemp != 0) strSql += ",";
                        strSql += "D." + col.ColumnName;
                        if (col.Order == ColumnOrder.OrderType.ASC)
                        {
                            strSql += " ASC";
                        }
                        else
                        {
                            strSql += " DESC";
                        }
                        iTemp++;
                    }
                }
            }
            
            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = strSql;
                dr = cmd.ExecuteReader();
                alReturn = new ArrayList();
                while (dr.Read())
                {
                    alReturn.Add(populateDesejo(dr));
                }//while
                return alReturn;
            }
            catch
            {
                return new ArrayList();
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }//queryDesejo()
Exemple #10
0
        }//deleteDesejo()
        
        /// <summary>
        /// Retorna:
        /// Sucesso: 0
        /// Erro: int diferente de zero
        /// </summary>
        /// <param name="mensagem"></param>
        /// <returns></returns>
        public static int aceitarProposta(Desejo desejo, Proposta proposta)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;

            String strSql = "UPDATE Desejo set id_proposta_aceita = ";
            if (proposta == null)
            {
                strSql += "NULL";
            }
            else
            {
                strSql += proposta.IdProposta.ToString();
            }

            strSql += " WHERE id_desejo = " + desejo.IdDesejo.ToString();

            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = strSql;
                trans = conn.BeginTransaction();
                cmd.Transaction = trans;
                cmd.ExecuteNonQuery();
                trans.Commit();
                return 0;//sucesso
            }
            catch
            {
                trans.Rollback();
                return 1;//erro
            }
            finally
            {
                if (conn != null) conn.Close();
            }
        }//aceitarProposta()
Exemple #11
0
        private static int deleteDesejo(Desejo desejo, DeleteMethod metodo)
        {
            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;

            String strSql;

            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;                

                trans = conn.BeginTransaction();
                cmd.Transaction = trans;

                if (metodo == DeleteMethod.PHYSICAL_DELETION)
                {
                    strSql = "UPDATE Desejo set id_proposta_aceita = NULL where id_desejo = " + desejo.IdDesejo.ToString();

                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    strSql = "DELETE from Mensagem where id_proposta IN (SELECT id_proposta from Proposta where id_desejo = " + desejo.IdDesejo.ToString();
                    strSql += ")";
                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    strSql = "DELETE from Proposta where id_desejo = " + desejo.IdDesejo.ToString();
                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    strSql = "DELETE from Avaliacao where id_proposta IN (SELECT id_proposta from Proposta where id_desejo = " + desejo.IdDesejo.ToString();
                    strSql += ")";
                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    strSql = "DELETE from URLDesejo where id_desejo = " + desejo.IdDesejo.ToString();
                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    strSql = "DELETE from Desejo where id_desejo = " + desejo.IdDesejo.ToString();
                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();

                    trans.Commit();
                    return 0;//sucesso
                }//if
                else
                {
                    strSql = "UPDATE Desejo set is_deleted_desejo = 1 where id_desejo = " + desejo.IdDesejo.ToString();
                    cmd.CommandText = strSql;
                    cmd.ExecuteNonQuery();
                    trans.Commit();
                    return 0;//sucesso
                }//else
            }
            catch
            {
                trans.Rollback();
                return 1;//erro
            }
            finally
            {
                if (conn != null) conn.Close();
            }
        }//deleteDesejo()
Exemple #12
0
        }//deleteProposta()

        
        public static int deleteDesejo(Desejo desejo)
        {
            return deleteDesejo(desejo, DeleteMethod.LOGIC_DELETION);
        }
Exemple #13
0
        }//salvarURLDesejo()

        /// <summary>
        /// Retorna:
        /// Sucesso: id_desejo do desejo inserido
        /// Erro: long negativo
        /// </summary>
        /// <param name="desejo"></param>
        /// <returns></returns>
        public static long salvarDesejo(Desejo desejo)
        {            
            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;
            SqlDataReader dr = null;
            long lngReturn = -1;

            String strSql = "INSERT INTO Desejo(id_usuario, id_departamento, descricao_curta, descricao_longa";
            strSql += ",id_local_busca,id_local_entrega,data_anuncio,id_proposta_aceita) output Inserted.id_desejo VALUES (";
            strSql += desejo.Usuario.IdUsuario.ToString() + "," + desejo.Departamento.Id.ToString() + ",'";
            strSql += Utils.limpaString(desejo.DescricaoCurta) + "','" + Utils.limpaString(desejo.DescricaoLonga) + "',";
            strSql += desejo.LocalBusca.IdLocal.ToString() + "," + desejo.LocalEntrega.IdLocal.ToString() + ",GETDATE(), NULL)";
            
            /*
            if (desejo.IsAtivo == 1)
            {
                strSql += "1,NULL)";
            }
            else
            {
                strSql += "0,NULL)";
            }
            */

            //strSql += desejo.PrecoMaximo.ToString().Replace(',', '.') + ",NULL)";

            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = strSql;
                trans = conn.BeginTransaction();
                cmd.Transaction = trans;
                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    lngReturn = System.Convert.ToInt64(dr["id_desejo"]);
                }
                dr.Close();
                trans.Commit();
                desejo.IdDesejo = lngReturn;
                return lngReturn;//sucesso
            }
            catch
            {
                dr.Close();
                trans.Rollback();
                return -1;//erro
            }
            finally
            {
                if (dr != null) dr.Close();
                if (conn != null) conn.Close();
            }
        }//salvarDesejo()
Exemple #14
0
        }//deleteURLDesejo()

        /// <summary>
        /// </summary>
        /// <param name="desejo"></param>
        /// <param name="strNovaURL"></param>
        /// <returns></returns>
        public static URLDesejo.EnumErroURL salvarURLDesejo(Desejo desejo, String strNovaURL)
        {            
            SqlConnection conn = null;
            SqlCommand cmd = null;
            SqlTransaction trans = null;
            SqlDataReader dr = null;
            int iTemp;

            //dando um LOCK:
            String strSql = "SELECT id_desejo FROM Desejo WHERE id_desejo = " + desejo.IdDesejo.ToString();

            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = strSql;
                trans = conn.BeginTransaction();
                cmd.Transaction = trans;

                dr = cmd.ExecuteReader();
                dr.Read();
                dr.Close();

                strSql = "SELECT count(*) num from URLDesejo where id_desejo = " + desejo.IdDesejo.ToString();
                cmd.CommandText = strSql;
                dr = cmd.ExecuteReader();
                dr.Read();
                iTemp = System.Convert.ToInt32(dr["num"]);
                dr.Close();
                if (iTemp > byte.MaxValue)
                {
                    trans.Rollback();
                    return URLDesejo.EnumErroURL.MAXNUM_ATINGIDO;
                }

                strSql = "INSERT into URLDesejo (id_desejo, ordinal_url, url) VALUES (" + desejo.IdDesejo.ToString();
                strSql += "," + iTemp.ToString() + ",'" + strNovaURL + "')";
                cmd.CommandText = strSql;
                cmd.ExecuteNonQuery();

                trans.Commit();
                return URLDesejo.EnumErroURL.SUCESSO;
            }
            catch
            {
                trans.Rollback();
                return URLDesejo.EnumErroURL.ERRO_DESCONHECIDO;
            }
            finally
            {
                if (dr != null) dr.Close();
                if (conn != null) conn.Close();
            }
        }//salvarURLDesejo()
Exemple #15
0
        public static ArrayList queryURLDesejo(Desejo desejo)
        {
            ArrayList alReturn = null;
            SqlDataReader dr = null;
            SqlConnection conn = null;
            SqlCommand cmd = null;
            String strSql = "SELECT * from URLDesejo WHERE id_desejo = " + desejo.IdDesejo.ToString();
            strSql += " ORDER BY ordinal_url ASC";

            try
            {
                conn = new SqlConnection(ConnString);
                conn.Open();
                cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.Text;
                cmd.CommandText = strSql;
                dr = cmd.ExecuteReader();
                alReturn = new ArrayList();
                while (dr.Read())
                {
                    alReturn.Add(populateURLDesejo(dr));
                }//while
                return alReturn;
            }
            catch
            {
                return new ArrayList();
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                }
                if (conn != null)
                {
                    conn.Close();
                }
            }
        }//queryURLDesejo()
        protected new void Page_Load(object sender, EventArgs e)
        {
            //if (IsPostBack) return;

            TextBoxNovaURL.Visible = false;
            btnNovaURLCancelar.Visible = false;
            btnNovaURLOk.Visible = false;

            if (Utils.HabilitarMobile && Request.Browser.IsMobileDevice)
            {

                TextBoxDescricao.Height = 300;

            }

            if (String.IsNullOrEmpty(Request["id_desejo"]))
            {
                //desejo = (Desejo)Session["Desejo"];
            }
            else
            {
                desejo = Desejo.getDesejoById(System.Convert.ToInt64(Request["id_desejo"]));
            }

            if (desejo == null)
            {
                lblMensagem.Text = "Desejo não encontrado.";
                return;
            }
            else
            {
                Session["Desejo"] = desejo;
            }

            lblNomeData.Text = "Desejo feito pelo(a) usuário(a) " + desejo.Usuario.Apelido + " em ";
            lblNomeData.Text += Utils.formatDatetimeToScreen3(desejo.DataAnuncio);

            lblTitulo.Text = desejo.DescricaoCurta;
            TextBoxDescricao.Text = desejo.DescricaoLonga;
            lblDepartamento.Text = desejo.Departamento.Nome;
            //lblOndeEncontrar.Text = (LocalDesejo.getLocalDesejoById(desejo.IdLocalBusca)).NomeLocal;
            //lblOndeEntregar.Text = (LocalDesejo.getLocalDesejoById(desejo.IdLocalEntrega)).NomeLocal;

            lblOndeEncontrar.Text = desejo.LocalBusca.NomeLocal;
            lblOndeEntregar.Text = desejo.LocalEntrega.NomeLocal;

            //lblPrecoMaximo.Text = Utils.formatDoubleToScreen(desejo.PrecoMaximo);

            usuarioLogado = (Usuario)Session["UsuarioLogado"];

            if (desejo.NumPropostas == 0)
            {
                lblNumPropostas.Text = "Esse desejo ainda não recebeu propostas.";
                btnMostrarPropostas.Visible = false;
                btnMostrarPropostas.Enabled = false;
            }
            else
            {
                lblNumPropostas.Text = "Esse desejo já recebeu " + desejo.NumPropostas.ToString() + " proposta(s).";
                if (usuarioLogado != null)
                {
                    if (desejo.Usuario.IdUsuario == usuarioLogado.IdUsuario)
                    {
                        btnMostrarPropostas.Visible = true;
                        btnMostrarPropostas.Enabled = true;
                        
                    }
                    else
                    {
                        btnMostrarPropostas.Visible = false;
                        btnMostrarPropostas.Enabled = false;
                    }
                }
                else
                {
                    btnMostrarPropostas.Visible = false;
                    btnMostrarPropostas.Enabled = false;
                }
            }

            if (usuarioLogado != null)
            {
                if (desejo.Usuario.IdUsuario == usuarioLogado.IdUsuario)
                {
                    btnApagarDesejo.Visible = true;
                    btnApagarDesejo.Enabled = true;
                    btnAddURL.Visible = true;
                    btnAddURL.Enabled = true;
                }
                else
                {
                    btnApagarDesejo.Visible = false;
                    btnApagarDesejo.Enabled = false;

                    btnFazerProposta.Visible = true;
                    btnFazerProposta.Enabled = true;

                    btnAddURL.Visible = false;
                    btnAddURL.Enabled = false;
                }
            }
            else
            {
                btnApagarDesejo.Visible = false;
                btnApagarDesejo.Enabled = false;
                btnAddURL.Visible = false;
                btnAddURL.Enabled = false;
                lblMensagem.Text = "Para fazer propostas, faça login primeiro.";
            }
            
            ArrayList alURLs = DataAccess.queryURLDesejo(desejo);
            if (alURLs.Count != 0)
            {
                iTemp = 0;
                vetColors = new System.Drawing.Color[2];
                vetColors[0] = System.Drawing.Color.LightCyan;//FromArgb(255, 255, 255);
                vetColors[1] = System.Drawing.Color.LightGray;
            }

            bool bMostrarBotaoApagarURL = false;
            if (usuarioLogado != null)
            {
                if (desejo.Usuario.IdUsuario == usuarioLogado.IdUsuario)
                {
                    bMostrarBotaoApagarURL = true;
                }
            }
            
            foreach (URLDesejo url in alURLs)
            {
                TableRow row = new TableRow();
                row.BackColor = vetColors[iTemp];
                iTemp = 1 - iTemp;

                TableCell cell = new TableCell();
                HyperLink hl = new HyperLink();
                hl.Text = Utils.truncateURL(url.URL);
                hl.NavigateUrl = url.URL;
                hl.Target = "_blank";
                cell.Controls.Add(hl);
                row.Cells.Add(cell);

                cell = new TableCell();
                if (bMostrarBotaoApagarURL)
                {
                    ImageButton imgBtnApagarURL = new ImageButton();
                    imgBtnApagarURL.ImageUrl = "~/Images/trashbasket.jpg";
                    imgBtnApagarURL.ID = "btnapagarurl_" + url.Ordinal.ToString();
                    imgBtnApagarURL.Click += imgBtnApagarURL_Click;
                    cell.Controls.Add(imgBtnApagarURL);
                }
                else
                {
                    cell.Text = "";
                }
                row.Cells.Add(cell);

                tblURLsDesejo.Rows.Add(row);
            }//foreach
        }//Page_Load()