using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web.Security;
using System.Web;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.Web.UI.HtmlControls;
using System.Threading;
using System.Text;
using System.Net;
using System.IO;
using OmegaLove.BLL;
using DataTransfer.Tables;
namespace OmegaLove.Web.UI.Pages
{
public partial class ShowMessage : OmegaLoveBasePage
{
private static string UserId = null;
private static string ToUserProfileID = null;
private static string FromUserProfileID = null;
private static string FromUserName = null;
private static string ToUserName = null;
private static string ToUserEmailAddress = null;
private static string UserEmailAddress = null;
private static string MessageID, InitialMessageID = null;
private static tbl_Messages tbl_Messages = new tbl_Messages();
public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
if (!(HttpContext.Current.User.Identity.IsAuthenticated))
Response.Redirect("~/Login.aspx");
if (!IsPostBack)
{
if (Request.QueryString.HasKeys() && !String.IsNullOrEmpty(Request.QueryString["MessageId"]))
{
MessageID = Request.QueryString["MessageID"];
FromUserProfileID = Request.QueryString["FromProfileID"];
FromUserName = Request.QueryString["FromUsername"];
ToUserName = Session["FromUserName"] == null ? null : Session["FromUserName"].ToString();
lblFrom.Text = "From";
lblTo.Text = "To";
lblTime.Text = "Date Sent";
lblSubject.Text = "Subject";
lblMess.Text = "Message";
GetMessage(MessageID);
DisplayUserImage();
}
}
}
private void GetMessage(string MessageID)
{
DataTable dtMessage = new DataTable();
dtMessage = DataBase.Procedures.prc_Messages_Select.ToDataTable(ConnnectionString, Convert.ToInt32(MessageID));
DataTable dtToEmail = new DataTable();
DataTable dtFromEmail = new DataTable();
dtToEmail = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, FromUserName);
dtFromEmail = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, ToUserName);
ToUserEmailAddress = dtToEmail.Rows[0]["EmailAddress"].ToString();
UserEmailAddress = dtFromEmail.Rows[0]["EmailAddress"].ToString();
ToUserProfileID = dtFromEmail.Rows[0]["ProfileID"].ToString();
lblMessage.Text = dtMessage.Rows[0]["Body"].ToString();
lblFromUsername.Text = dtMessage.Rows[0]["FromUserName"].ToString();
lblToUsername.Text = ToUserName;
lblToUser.Text = FromUserName;
lblMessageTime.Text = dtMessage.Rows[0]["MsgDate"].ToString();
lblMessage.Text = dtMessage.Rows[0]["Body"].ToString();
lblSubjectMessage.Text = dtMessage.Rows[0]["Subject"].ToString();
InitialMessageID = dtMessage.Rows[0]["InitialMessageID"].ToString();
}
protected void SubmitMessage_Click(object sender, ImageClickEventArgs e)
{
if (Page.IsValid)
{
if (MessageID == "0")
{
// New Messages
sendMessage();
}
else
{
// For Reply Messages
if (InitialMessageID == "0")
InitialMessageID = MessageID;
sendMessage(true, Convert.ToString(MessageID), InitialMessageID);
}
}
}
private void sendMessage()
{
sendMessage(false, null, null);
}
private void sendMessage(Boolean IsReply, string CurrentMessageID, string InitialMessageID)
{
tbl_Messages tbl_Messages = new tbl_Messages();
tbl_Messages.ProfileID = Convert.ToInt32(FromUserProfileID);
tbl_Messages.FromProfileID = Convert.ToInt32(ToUserProfileID);
tbl_Messages.Subject = txtSubject.Text;
tbl_Messages.Body = txtMessage.Text;
tbl_Messages.FromUsername = ToUserName;
tbl_Messages.MsgDate = DateTime.Now;
tbl_Messages.MsgNew = 1;
tbl_Messages.MsgRead = 1;
tbl_Messages.MsgReplied = Convert.ToByte(IsReply); // New Message (0) / Reply Message (1)
if (IsReply)
{
tbl_Messages.ReplyOfMessageID = Convert.ToInt32(CurrentMessageID);
tbl_Messages.InitialMessageID = Convert.ToInt32(InitialMessageID);
}
int returnValue = 0;
try
{
returnValue = DataBase.prc_Messages_Save.Execute(ConnnectionString, tbl_Messages);
if (returnValue > 0)
{
SMTPManager.SendEmail(UserEmailAddress, FromUserName, ToUserEmailAddress, txtMessage.Text, txtSubject.Text, false);
}
}
catch (Exception)
{
throw;
}
//lblMessage.Text = "Mail sent successfully!";
//Thread.Sleep(2000);
Response.Redirect("~/Secure/MailBox.aspx");
}
private void DisplayUserImage()
{
DataTable dt = new DataTable();
dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, FromUserName);
DataTable dtPhotos = new DataTable();
dtPhotos = DataBase.Procedures.prc_Photos_Select_Primary.ToDataTable(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"]));
// Get img id from datatable.
if (((dtPhotos != null) && (dtPhotos.Rows.Count > 0)))
{
if (Convert.ToBoolean(dtPhotos.Rows[0]["p_Primary"]))
{
imgPhoto.ImageUrl = "ShowImage.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";
}
else
{
if (dt.Rows[0]["Gender"].ToString() == "1")
imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_m_m.jpg";
else
imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_f_m.jpg";
}
}
else // There is no primary image.
{
if (dt.Rows[0]["Gender"].ToString() == "1")
imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_m_m.jpg";
else
imgPhoto.ImageUrl = "~/Images/NoPictures/no_photo_white_f_m.jpg";
}
}
}
}
|