protected void btnSalvar_Click(object sender, EventArgs e) { Proposta proposta = new Proposta(); if (Session["UsuarioLogado"] == null) { Session["mensagem"] = "Para fazer uma proposta é necessário fazer login primeiro."; return; } proposta.Desejo = desejo; proposta.Usuario = (Usuario)Session["UsuarioLogado"]; proposta.TipoProposta = new TipoProposta(); proposta.TipoProposta.IdTipoProposta = System.Convert.ToInt16(DropDownListTipoProposta.SelectedValue); if (TextBoxValorProposta.Text.Trim() == "") TextBoxValorProposta.Text = "0"; proposta.ValorProposta = System.Convert.ToDouble(TextBoxValorProposta.Text); long lngReturn = DataAccess.salvarProposta(proposta); if (lngReturn >= 0) { Session["mensagem"] = "Proposta salva com sucesso. Envie mensagens para iniciar a negociação."; //reaproveitando a variável pra fazer uma busca: proposta = new Proposta(); proposta.IdProposta = lngReturn; ArrayList alTemp = DataAccess.queryProposta(proposta, null); if (alTemp.Count == 0) { Session["mensagem"] = "Erro ao salvar a proposta."; Response.Redirect("FazerProposta.aspx"); } Proposta propostaSalva = (Proposta)alTemp[0]; Session["Proposta"] = propostaSalva; //limpando essas sessions para evitar erros: Session["ListaPropostas"] = null; Session["PropostaBusca"] = null; if (propostaSalva.TipoProposta.Notificar) { if (!Request.IsLocal) LIEmail.mandarMailNovaProposta(propostaSalva); } Response.Redirect("ShowProposta.aspx"); } else { Session["mensagem"] = "Erro ao salvar a proposta."; Response.Redirect("FazerProposta.aspx"); } }//Page_Load()
}//Page_Load() private void buscarProposta() { ArrayList alTemp = DataAccess.queryProposta(proposta, null); if (alTemp.Count == 0) { proposta = null; Session["mensagem"] = strNaoEncontrada; return; } proposta = (Proposta)alTemp[0]; Session["Proposta"] = proposta; }
private void lb_MostrarPropostaClick(object sender, EventArgs e) { //long idProposta; String strTemp = ((LinkButton)sender).ID; strTemp = (strTemp.Split('_'))[1]; Proposta propostaBusca = new Proposta(); propostaBusca.IdProposta = System.Convert.ToInt64(strTemp); ArrayList alResult = DataAccess.queryProposta(propostaBusca, null); if (alResult.Count == 0) { Session["Proposta"] = null; } else { Session["Proposta"] = alResult[0]; } ((PageStack)Session["PageStack"]).clear(); ((PageStack)Session["PageStack"]).push("BuscaPropostas.aspx"); Response.Redirect("ShowProposta.aspx"); }
private void lb_MostrarMensagensClick(object sender, EventArgs e) { String strTemp = ((LinkButton)sender).ID; strTemp = (strTemp.Split('_'))[1]; Proposta propostaBusca = new Proposta(); propostaBusca.IdProposta = System.Convert.ToInt64(strTemp); ArrayList alResult = DataAccess.queryProposta(propostaBusca, null); if (alResult.Count == 0) { Session["Proposta"] = null; } else { Session["Proposta"] = alResult[0]; } Response.Redirect("ShowMensagens.aspx"); }
protected new void Page_Load(object sender, EventArgs e) { //UserControl uc = (UserControl)Page.LoadControl("PropostaViewer.ascx"); TableRow row; TableCell cell; const String NOT_FOUND = "Nenhuma proposta encontrada. Verifique os critérios de busca ou se você tem acesso aos dados procurados."; //if (IsPostBack) return; ArrayList alPropostas = (ArrayList)Session["ListaPropostas"]; if (alPropostas == null) { lblMensagem.Text = NOT_FOUND; ocultarOrdenacao(); return; } if (alPropostas.Count == 0) { lblMensagem.Text = NOT_FOUND; ocultarOrdenacao(); return; } propostaBusca = (Proposta)Session["PropostaBusca"]; if (propostaBusca == null) { lblMensagem.Text = NOT_FOUND; ocultarOrdenacao(); return; } if ((!Utils.HabilitarMobile) || (!Request.Browser.IsMobileDevice)) { //cabeçalho row = new TableRow(); cell = new TableCell(); cell.Text = ""; row.Cells.Add(cell); //Se o desejo não foi especificado na busca, ele precisa ser mostrado na tabela, pois podem haver desejos diferentes: if (propostaBusca.Desejo == null) { cell = new TableCell(); cell.Text = "Desejo"; row.Cells.Add(cell); } else { if (propostaBusca.Desejo.IdDesejo < 0) { cell = new TableCell(); cell.Text = "Desejo"; row.Cells.Add(cell); } else { lblMensagem.Text = "Propostas encontradas para o desejo: "; } } //Se o usuario não foi especificado na busca, ele precisa ser mostrado na tabela, pois podem haver usuarios diferentes: if (propostaBusca.Usuario == null) { cell = new TableCell(); cell.Text = "Usuário"; row.Cells.Add(cell); } else { if (propostaBusca.Usuario.IdUsuario < 0) { cell = new TableCell(); cell.Text = "Usuário"; row.Cells.Add(cell); } else { lblMensagem.Text = "Propostas feitas pelo usuário: "; } } cell = new TableCell(); cell.Text = "Data Proposta"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Tipo de Proposta"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Valor"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = "Número de Mensagens"; row.Cells.Add(cell); cell = new TableCell(); cell.Text = " "; row.Cells.Add(cell); tblResultado.Rows.Add(row); //fim cabeçalho }//if (Utils.HabilitarMobile) int iTemp = 0; if (!IsPostBack) { LIqueryParameters par = (LIqueryParameters)Session["ParamsBuscaProposta"]; if (par != null) { DropDownListOrderBy.SelectedIndex = 0;//default; if (par.OrderBy.Count != 0) { ColumnOrder col = (ColumnOrder)par.OrderBy[0]; switch (col.ColumnName) { case "data_proposta": if (col.Order == ColumnOrder.OrderType.DESC) { DropDownListOrderBy.SelectedValue = "data_mais_recente"; } break; case "valor_proposta": if (col.Order == ColumnOrder.OrderType.ASC) { DropDownListOrderBy.SelectedValue = "menor_valor"; } break; default: DropDownListOrderBy.SelectedIndex = 0; break; }//switch } else { DropDownListOrderBy.SelectedIndex = 0; } } else { DropDownListOrderBy.SelectedIndex = 0; } }//if(!IsPostBack) if ((!Request.Browser.IsMobileDevice) || (!Utils.HabilitarMobile)) { foreach (Proposta proposta in alPropostas) { row = new TableRow(); cell = new TableCell(); if (proposta.Desejo.IdPropostaAceita == proposta.IdProposta) { cell.Text = "Aceita:"; row.BackColor = System.Drawing.Color.Gold; } else { cell.Text = ""; } row.Cells.Add(cell); if (propostaBusca.Desejo == null) { cell = new TableCell(); cell.Text = Utils.truncateString(proposta.Desejo.DescricaoCurta); row.Cells.Add(cell); } else { if (propostaBusca.Desejo.IdDesejo < 0) { cell = new TableCell(); cell.Text = Utils.truncateString(proposta.Desejo.DescricaoCurta); row.Cells.Add(cell); } else { if (iTemp == 0) { lblMensagem.Text += Utils.truncateString(proposta.Desejo.DescricaoCurta); } } } if (propostaBusca.Usuario == null) { cell = new TableCell(); cell.Text = proposta.Usuario.Apelido; row.Cells.Add(cell); } else { if (propostaBusca.Usuario.IdUsuario < 0) { cell = new TableCell(); cell.Text = proposta.Usuario.Apelido; row.Cells.Add(cell); } else { if (iTemp == 0) { lblMensagem.Text += proposta.Usuario.Apelido; } } } cell = new TableCell(); cell.Text = Utils.formatDatetimeToScreen1(proposta.DataProposta); row.Cells.Add(cell); cell = new TableCell(); cell.Text = proposta.TipoProposta.Descricao; row.Cells.Add(cell); cell = new TableCell(); if (proposta.ValorProposta == -1) { cell.Text = "indefinido"; } else { cell.Text = Utils.formatDoubleToScreen(proposta.ValorProposta); } row.Cells.Add(cell); cell = new TableCell(); if (proposta.NumMensagens == 0) { cell.Text = "0"; } else { /* HyperLink hl = new HyperLink(); hl.Text = proposta.NumMensagens.ToString(); hl.NavigateUrl = "http://"; hl.ToolTip = "Mostrar mensagens"; cell.Controls.Add(hl); */ LinkButton lb2 = new LinkButton(); lb2.ID = "lbmostrarmensagens_" + proposta.IdProposta.ToString(); lb2.Text = proposta.NumMensagens.ToString(); lb2.ToolTip = "Mostrar mensagens"; lb2.Click += lb_MostrarMensagensClick; cell.Controls.Add(lb2); } row.Cells.Add(cell); cell = new TableCell(); LinkButton lb = new LinkButton(); lb.ID = "lbmostrarproposta_" + proposta.IdProposta.ToString(); lb.Text = "Mostrar Proposta"; lb.Click += lb_MostrarPropostaClick; cell.Controls.Add(lb); row.Cells.Add(cell); tblResultado.Rows.Add(row); iTemp++; }//foreach }//if(!Request.Browser.IsMobileDevice) else { Table innerTable; TableRow innerRow; TableCell innerCell; foreach (Proposta proposta in alPropostas) { innerTable = new Table(); innerRow = new TableRow(); innerCell = new TableCell(); innerCell.Text = "Desejo:"; innerRow.Cells.Add(innerCell); innerCell = new TableCell(); innerCell.Text = Utils.truncateString(proposta.Desejo.DescricaoCurta); innerRow.Cells.Add(innerCell); innerTable.Rows.Add(innerRow); innerRow = new TableRow(); innerCell = new TableCell(); innerCell.Text = "Proposta feita em:"; innerRow.Cells.Add(innerCell); innerCell = new TableCell(); innerCell.Text = Utils.formatDatetimeToScreen1(proposta.DataProposta); innerRow.Cells.Add(innerCell); innerTable.Rows.Add(innerRow); innerRow = new TableRow(); innerCell = new TableCell(); innerCell.Text = "Tipo de Proposta:"; innerRow.Cells.Add(innerCell); innerCell = new TableCell(); innerCell.Text = proposta.TipoProposta.Descricao; innerRow.Cells.Add(innerCell); innerTable.Rows.Add(innerRow); innerRow = new TableRow(); innerCell = new TableCell(); innerCell.Text = "Valor (R$):"; innerRow.Cells.Add(innerCell); innerCell = new TableCell(); innerCell.Text = Utils.formatDoubleToScreen(proposta.ValorProposta); innerRow.Cells.Add(innerCell); innerTable.Rows.Add(innerRow); innerRow = new TableRow(); innerCell = new TableCell(); if (proposta.NumMensagens > 0) { LinkButton lb2 = new LinkButton(); lb2.ID = "lbmostrarmensagens_" + proposta.IdProposta.ToString(); lb2.Text = proposta.NumMensagens.ToString() + " mensagens"; //lb2.ToolTip = "Mostrar mensagens"; lb2.Click += lb_MostrarMensagensClick; innerCell.Controls.Add(lb2); } else { innerCell.Text = "0 mensagens"; } innerRow.Cells.Add(innerCell); innerCell = new TableCell(); LinkButton lb = new LinkButton(); lb.ID = "lbmostrarproposta_" + proposta.IdProposta.ToString(); lb.Text = "Mostrar Proposta"; lb.Click += lb_MostrarPropostaClick; innerCell.Controls.Add(lb); innerRow.Cells.Add(innerCell); innerTable.Rows.Add(innerRow); cell = new TableCell(); cell.Controls.Add(innerTable); row = new TableRow(); row.Cells.Add(cell); tblResultado.Rows.Add(row); }//foreach }//else }//Page_Load()
public static int mandarMailPropostaSelecionada(Proposta proposta) { SmtpClient smtpClient = new SmtpClient(DOMAIN_NAME, 25); smtpClient.Credentials = new System.Net.NetworkCredential(CREDENTIAL, MY_ID_PASSWORD); smtpClient.UseDefaultCredentials = true; smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network; //smtpClient.EnableSsl = true; MailMessage mail = new MailMessage(); mail.IsBodyHtml = true; //Setting From , To and CC mail.From = new MailAddress(FROM, DISPLAY_NAME); mail.To.Add(new MailAddress(proposta.Desejo.Usuario.Email, proposta.Desejo.Usuario.Apelido)); //mail.CC.Add(new MailAddress("*****@*****.**")); mail.Subject = "InverShop - sua proposta foi selecionada"; mail.BodyEncoding = System.Text.Encoding.UTF8; mail.Body = "Prezado " + proposta.Usuario.Apelido + ",<br><br>"; mail.Body += "Sua proposta para o desejo \"" + proposta.Desejo.DescricaoCurta + "\" foi selecionada!<br>"; //mail.Body += "Para visualizá-la, clique no link abaixo ou copie e cole no seu navegador.<br>"; //mail.Body += "www.lojainversa.com/ShowProposta.aspx?id_proposta=" + proposta.IdProposta.ToString() + "<br>"; mail.Body += "Para negociar mais detalhes sobre a proposta, entre no site da InverShop,"; mail.Body += " selecione a proposta e envie mensagens.<br>"; smtpClient.Send(mail); return 0;//sucesso }
}//populateTipoProposta() private static Proposta populateProposta(SqlDataReader dr) { Proposta propostaReturn = new Proposta(); /* * id_proposta id_desejo id_usuario data_proposta id_tipo_proposta valor_proposta */ propostaReturn.DataProposta = System.Convert.ToDateTime(dr["data_proposta"]); propostaReturn.Desejo = populateDesejo(dr); propostaReturn.IdProposta = System.Convert.ToInt32(dr["id_proposta"]); //propostaReturn.IdTipoProposta = System.Convert.ToInt16(dr["id_tipo_proposta"]); propostaReturn.TipoProposta = populateTipoProposta(dr); propostaReturn.Usuario = populateUsuario(dr, "UP_"); propostaReturn.IsDeleted = System.Convert.ToInt16(dr["is_deleted_proposta"]); if (dr.IsDBNull(dr.GetOrdinal("valor_proposta"))) { propostaReturn.ValorProposta = -1; } else { propostaReturn.ValorProposta = System.Convert.ToDouble(dr["valor_proposta"]); } propostaReturn.NumMensagens = System.Convert.ToInt32(dr["NumMensagens"]); return propostaReturn; }//populateProposta()
protected void LinkButtonPropostasFeitas_Click(object sender, EventArgs e) { if (usuarioLogado == null) { Session["mensagem"] = "Para pesquisar propostas faça login primeiro"; return; } Proposta propostaBusca = new Proposta(); propostaBusca.Usuario = new Usuario(); propostaBusca.Usuario.IdUsuario = usuarioLogado.IdUsuario; Session["PropostaBusca"] = propostaBusca; LIqueryParameters par = new LIqueryParameters(); ColumnOrder col = new ColumnOrder(); col.ColumnName = "id_desejo"; col.Order = ColumnOrder.OrderType.DESC; par.OrderBy.Add(col); col = new ColumnOrder(); col.ColumnName = "data_proposta"; col.Order = ColumnOrder.OrderType.DESC; par.OrderBy.Add(col); Session["ParamsBuscaProposta"] = par; Response.Redirect("BuscaPropostas.aspx"); }
}//salvarMensagem() /// <summary> /// Retorna: /// Sucesso: 0 /// Erro: diferente de zero /// </summary> /// <param name="proposta"></param> /// <param name="quemVisualizou"></param> /// <returns></returns> public static int atualizarDataViewMensagem(Proposta proposta, Usuario.EnumQuem quemVisualizou) { SqlConnection conn = null; SqlCommand cmd = null; SqlTransaction trans = null; //SqlDataReader dr = null; String strSql = "UPDATE Proposta SET "; if (quemVisualizou == Usuario.EnumQuem.PEDINTE) { strSql += "data_view_pedinte"; } else { strSql += "data_view_proponente"; } strSql += " = GETDATE() WHERE id_proposta = " + proposta.IdProposta.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(); } }//atualizarDataViewMensagem()
}//atualizarDataViewMensagem() /// <summary> /// Retorna: /// Sucesso: id_proposta da proposta inserida /// Erro: long negativo /// </summary> /// <param name="proposta"></param> /// <returns></returns> public static long salvarProposta(Proposta proposta) { SqlConnection conn = null; SqlCommand cmd = null; SqlTransaction trans = null; SqlDataReader dr = null; long lngReturn = -1; String strSql = "INSERT INTO Proposta (id_desejo, id_usuario, data_proposta, id_tipo_proposta, valor_proposta)"; strSql += " output Inserted.id_proposta VALUES ("; strSql += proposta.Desejo.IdDesejo.ToString() + "," + proposta.Usuario.IdUsuario.ToString(); strSql += ",GETDATE()," + proposta.TipoProposta.IdTipoProposta.ToString() + ","; strSql += proposta.ValorProposta.ToString().Replace(',', '.') + ")"; 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_proposta"]); } dr.Close(); trans.Commit(); return lngReturn;//sucesso } catch { dr.Close(); trans.Rollback(); return -1;//erro } finally { if (dr != null) dr.Close(); if (conn != null) conn.Close(); } }//salvarProposta()
}//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()
}//queryUsuario() public static ArrayList queryMensagens(Proposta proposta, LIqueryParameters paramsBusca) { ArrayList alReturn = null; SqlDataReader dr = null; SqlConnection conn = null; SqlCommand cmd = null; //bool bWhere = false; //int iTemp; String strSql = "SELECT"; String strSelect = " M.*, P.*, D.*"; foreach (String strColuna in Usuario.Colunas) { strSelect += ",UP." + strColuna + " UP_" + strColuna; } //UP.apelido UP_apelido, UP.facebook_name UP_facebook_name, UP.id_usuario UP_id_usuario"; strSelect += ", T.*, DP.*"; foreach (String strColuna in Usuario.Colunas) { strSelect += ",UD." + strColuna + " UD_" + strColuna; } //UD.apelido UD_apelido, UD.facebook_name UD_facebook_name, UD.id_usuario UD_id_usuario"; strSelect += ", 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) { if (paramsBusca.Top > 0) { strSql += " TOP " + paramsBusca.Top.ToString() + strSelect; } else { strSql += strSelect; } } else { strSql += strSelect; } strSql += ", 0 numpropostas";//MUITO FEIO, EU SEI strSql += ", 0 nummensagens";//MUITO FEIO TAMBEM strSql += " FROM Mensagem M INNER JOIN Proposta P ON M.id_proposta = P.id_proposta"; strSql += " INNER JOIN Desejo D ON P.id_desejo = D.id_desejo"; strSql += " INNER JOIN Usuario UD ON D.id_usuario = UD.id_usuario"; 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 TipoProposta T ON P.id_tipo_proposta = T.id_tipo_proposta"; strSql += " INNER JOIN Usuario UP ON P.id_usuario = UP.id_usuario"; strSql += " INNER JOIN Departamento DP ON D.id_departamento = DP.id_departamento"; strSql += " WHERE M.id_proposta = " + proposta.IdProposta.ToString(); if (proposta.IsDeleted >= 0) { strSql += " AND P.is_deleted_proposta = " + proposta.IsDeleted.ToString(); } if (proposta.Desejo != null) { if (proposta.Desejo.IsDeleted >= 0) { strSql += " AND D.is_deleted_desejo = " + proposta.Desejo.IsDeleted.ToString(); } } //strSql += " AND D.is_deleted = 0"; //strSql += " AND P.is_deleted = 0"; strSql += " ORDER BY M.data_mensagem 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(populateMensagem(dr)); }//while return alReturn; } catch { return new ArrayList(); } finally { if (dr != null) { dr.Close(); } if (conn != null) { conn.Close(); } } }//queryMensagens()
protected void btnMostrarPropostas_Click(object sender, EventArgs e) { Proposta propostaBusca = new Proposta(); propostaBusca.Desejo = new Desejo(); propostaBusca.Desejo.IdDesejo = desejo.IdDesejo; Session["PropostaBusca"] = propostaBusca; LIqueryParameters paramsBusca = new LIqueryParameters(); ColumnOrder col = new ColumnOrder(); col.ColumnName = "data_proposta"; col.Order = ColumnOrder.OrderType.DESC; paramsBusca.OrderBy.Add(col); Session["ParamsBuscaProposta"] = paramsBusca; Response.Redirect("BuscaPropostas.aspx"); }
protected new void Page_Load(object sender, EventArgs e) { usuarioLogado = (Usuario)Session["UsuarioLogado"]; if (usuarioLogado == null) { Session["mensagem"] = "É necessário fazer login para visualizar uma proposta."; return; } if (Request["id_proposta"] != null) { proposta = new Proposta(); proposta.IdProposta = System.Convert.ToInt64(Request["id_proposta"]); } if (proposta == null) proposta = (Proposta)Session["Proposta"]; proposta.Desejo = new Desejo();//faço isso para filtrar se o desejo tiver sido deletado buscarProposta(); if (proposta == null) { Session["mensagem"] = strNaoEncontrada; btnAceitarProposta.Visible = false; btnDeleteProposta.Visible = false; btnDesfazerAceitacao.Visible = false; btnVerMensagens.Visible = false; return; } if (proposta.Usuario.IdUsuario != usuarioLogado.IdUsuario) { if (proposta.Desejo.Usuario.IdUsuario != usuarioLogado.IdUsuario) { Session["mensagem"] = "Somente propostas feitas por você ou para seus desejos podem ser visualizadas."; return; } else { meuPapel = Usuario.EnumQuem.PEDINTE; } } else { meuPapel = Usuario.EnumQuem.PROPONENTE; } LinkButtonDesejo.Text = Utils.truncateString(proposta.Desejo.DescricaoCurta); lblDataProposta.Text = Utils.formatDatetimeToScreen3(proposta.DataProposta); lblNomeUsuarioProposta.Text = proposta.Usuario.Apelido; lblTipoProposta.Text = proposta.TipoProposta.Descricao; lblValor.Text = Utils.formatDoubleToScreen(proposta.ValorProposta); lblNumMensagens.Text = "Essa proposta recebeu " + proposta.NumMensagens.ToString() + " mensagens."; btnVerMensagens.Text = "Ver mensagens / Enviar Mensagem"; if (proposta.Desejo.IdPropostaAceita == proposta.IdProposta)//essa proposta está selecionada { lblPropostaSelecionada.Text = "Essa proposta foi selecionada."; btnAceitarProposta.Visible = false; btnDesfazerAceitacao.Visible = true; lblAvaliarProposta.Visible = true; radioButtonListAvaliacao.Visible = true; } else { if (proposta.Desejo.IdPropostaAceita < 0)//nenhuma proposta foi selecionada { btnAceitarProposta.Visible = true; btnDesfazerAceitacao.Visible = false; } else { lblPropostaSelecionada.Text = "Uma outra proposta foi selecionada."; btnAceitarProposta.Visible = true; btnDesfazerAceitacao.Visible = false; } } if (proposta.Desejo.Usuario.IdUsuario != usuarioLogado.IdUsuario) { btnAceitarProposta.Visible = false; btnDesfazerAceitacao.Visible = false; lblAvaliarProposta.Visible = false; radioButtonListAvaliacao.Visible = false; } }//Page_Load()
}//queryLocalDesejo() public static ArrayList queryProposta(Proposta propostaBusca, LIqueryParameters paramsBusca) { ArrayList alReturn = null; SqlDataReader dr = null; SqlConnection conn = null; SqlCommand cmd = null; bool bWhere = false; int iTemp; String strSql = "SELECT"; String strSelect = " P.*, D.*"; foreach (String strColuna in Usuario.Colunas) { strSelect += ",UP." + strColuna + " UP_" + strColuna; } //UP.apelido UP_apelido, UP.facebook_name UP_facebook_name, UP.id_usuario UP_id_usuario"; strSelect += ", T.*,DP.*"; foreach (String strColuna in Usuario.Colunas) { strSelect += ",UD." + strColuna + " UD_" + strColuna; } //UD.apelido UD_apelido, UD.facebook_name UD_facebook_name, UD.id_usuario UD_id_usuario"; strSelect += ", 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) { if (paramsBusca.Top > 0) { strSql += " TOP " + paramsBusca.Top.ToString() + strSelect; } else { strSql += strSelect; } } else { strSql += strSelect; } strSql += ", 0 numpropostas";//MUITO FEIO, EU SEI strSql += ", S.nummensagens FROM Proposta P INNER JOIN Desejo D ON P.id_desejo = D.id_desejo"; strSql += " INNER JOIN Usuario UD ON D.id_usuario = UD.id_usuario"; 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 TipoProposta T ON P.id_tipo_proposta = T.id_tipo_proposta"; strSql += " INNER JOIN Usuario UP ON P.id_usuario = UP.id_usuario"; strSql += " INNER JOIN Departamento DP ON D.id_departamento = DP.id_departamento"; strSql += " INNER JOIN ( select P2.id_proposta id_proposta, count(M.data_mensagem) nummensagens "; strSql += " FROM Proposta P2 LEFT JOIN Mensagem M ON P2.id_proposta = M.id_proposta GROUP BY P2.id_proposta) S "; strSql += " ON P.id_proposta = S.id_proposta"; if (propostaBusca.DataProposta != DateTime.MinValue) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "P.data_proposta = " + Utils.formatParameterToSqlServer(propostaBusca.DataProposta); }//if if (propostaBusca.Desejo != null) { if (propostaBusca.Desejo.IsDeleted >= 0) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "D.is_deleted_desejo = " + propostaBusca.Desejo.IsDeleted.ToString(); } if (propostaBusca.Desejo.IdDesejo >= 0) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "P.id_desejo = " + propostaBusca.Desejo.IdDesejo.ToString(); } if (propostaBusca.Desejo.Usuario != null) { if (propostaBusca.Desejo.Usuario.IdUsuario >= 0) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "UD.id_usuario = " + propostaBusca.Desejo.Usuario.IdUsuario.ToString(); } } }//if if (propostaBusca.IdProposta >= 0) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "P.id_proposta = " + propostaBusca.IdProposta.ToString(); }//if if (propostaBusca.TipoProposta != null) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "P.id_tipo_proposta = " + propostaBusca.TipoProposta.IdTipoProposta.ToString(); }//if if (propostaBusca.Usuario != null) { if (propostaBusca.Usuario.IdUsuario > 0) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "P.id_usuario = " + propostaBusca.Usuario.IdUsuario.ToString(); } }//if if (propostaBusca.IsDeleted >= 0) { if (bWhere) { strSql += " AND "; } else { strSql += " WHERE "; bWhere = true; } strSql += "P.is_deleted_proposta = " + propostaBusca.IsDeleted.ToString(); } if (paramsBusca != null) { if (paramsBusca.OrderBy.Count != 0) { strSql += " ORDER BY "; iTemp = 0; foreach (ColumnOrder col in paramsBusca.OrderBy) { if (iTemp != 0) strSql += ","; strSql += "P." + 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(populateProposta(dr)); }//while return alReturn; } catch { return new ArrayList(); } finally { if (dr != null) { dr.Close(); } if (conn != null) { conn.Close(); } } }//queryProposta()
protected void LinkButtonPropostasRecebidas_Click(object sender, EventArgs e) { if (usuarioLogado == null) { Session["mensagem"] = "Para pesquisar propostas faça login primeiro"; return; } Proposta propostaBusca = new Proposta(); propostaBusca.Desejo = new Desejo(); propostaBusca.Desejo.Usuario = new Usuario(); propostaBusca.Desejo.Usuario.IdUsuario = usuarioLogado.IdUsuario; Session["PropostaBusca"] = propostaBusca; Response.Redirect("BuscaPropostas.aspx"); }
public Mensagem() { Proposta = null; DataHoraMensagem = DateTime.MinValue; Texto = ""; }
protected new void Page_Load(object sender, EventArgs e) { TableRow row; TableCell cell; proposta = (Proposta)Session["Proposta"]; if (proposta == null) { Session["mensagem"] = "Proposta não encontrada."; disableAll(); return; } usuarioLogado = (Usuario)Session["UsuarioLogado"]; if (usuarioLogado == null) { Session["mensagem"] = "Para visualizar mensagens, faça login primeiro"; disableAll(); return; } if ((proposta.Usuario.IdUsuario != usuarioLogado.IdUsuario) && (proposta.Desejo.Usuario.IdUsuario != usuarioLogado.IdUsuario)) { Session["mensagem"] = "Você não tem permissão para visualizar mensagens para essa proposta"; disableAll(); return; } LinkButtonDesejo.Text = "Desejo: " + Utils.truncateString(proposta.Desejo.DescricaoCurta); LinkButtonProposta.Text = "Proposta feita por " + proposta.Usuario.Apelido + " às " + Utils.formatDatetimeToScreen2(proposta.DataProposta); if (usuarioLogado.IdUsuario == proposta.Usuario.IdUsuario) { meuPapel = Usuario.EnumQuem.PROPONENTE; } else { if (usuarioLogado.IdUsuario == proposta.Desejo.Usuario.IdUsuario) { meuPapel = Usuario.EnumQuem.PEDINTE; } } ArrayList alMensagens = DataAccess.queryMensagens(proposta, null); if (alMensagens.Count == 0) { Session["mensagem"] = "Sem mensagens para essa proposta"; return; } foreach (Mensagem mensagem in alMensagens) { row = new TableRow(); if (mensagem.QuemPostou == meuPapel)//a mensagem é minha { row.BackColor = System.Drawing.Color.FromArgb(200, 200, 200); cell = new TableCell(); cell.Text = "Você às " + Utils.formatDatetimeToScreen2(mensagem.DataHoraMensagem); row.Cells.Add(cell); cell = new TableCell(); //cell.Style.Add("background-image", "url('Images/balao_esquerda.jpg')"); cell.Text = mensagem.Texto; row.Cells.Add(cell); cell = new TableCell(); cell.BackColor = System.Drawing.Color.FromArgb(255, 255, 255); row.Cells.Add(cell); } else//a mensagem é do outro. quem é o outro? { row.BackColor = System.Drawing.Color.FromArgb(160, 160, 160); cell = new TableCell(); cell.BackColor = System.Drawing.Color.FromArgb(255, 255, 255); row.Cells.Add(cell); cell = new TableCell(); cell.Text = mensagem.Texto; row.Cells.Add(cell); cell = new TableCell(); if (meuPapel == Usuario.EnumQuem.PEDINTE)//eu sou o pedinte. logo, o outro é p proponente: { cell.Text = mensagem.Proposta.Usuario.Apelido + " às " + Utils.formatDatetimeToScreen2(mensagem.DataHoraMensagem); } else//eu sou o proponente. logo, o outro é o pedinte: { cell.Text = mensagem.Proposta.Desejo.Usuario.Apelido + " às " + Utils.formatDatetimeToScreen2(mensagem.DataHoraMensagem); } row.Cells.Add(cell); } tblResultado.Rows.Add(row); }//foreach DataAccess.atualizarDataViewMensagem(proposta, meuPapel); lblNovaMensagem.Text = "Nova mensagem (máximo de " + Mensagem.TamanhoMaximoText.ToString() + " caracteres):"; //TextBoxNovaMensagem.MaxLength = Mensagem.TamanhoMaximoText; }//Page_Load()
private void lb_ClickMostrarPropostas(object sender, EventArgs e) { long idDesejo; String strTemp = ((LinkButton)sender).ID; strTemp = (strTemp.Split('_'))[1]; idDesejo = System.Convert.ToInt64(strTemp); Proposta propostaBusca = new Proposta(); propostaBusca.Desejo = new Desejo(); propostaBusca.Desejo.IdDesejo = idDesejo; Session["PropostaBusca"] = propostaBusca; LIqueryParameters paramsBusca = new LIqueryParameters(); ColumnOrder col = new ColumnOrder(); col.ColumnName = "data_proposta"; col.Order = ColumnOrder.OrderType.DESC; paramsBusca.OrderBy.Add(col); Session["ParamsBuscaProposta"] = paramsBusca; Session["PaginaAlvo"] = "ShowPropostas.aspx"; Response.Redirect("BuscaPropostas.aspx"); }//lb_ClickMostrarPropostas()