<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ctrlMyMail.ascx.cs"
Inherits="OmegaLove.Web.UI.ctrlMyMail" %>
<%@ Register Assembly="System.Web.Ajax" Namespace="System.Web.UI" TagPrefix="asp" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>
<script type="text/javascript">
function SelectAll(id) {
var frm = document.forms[0];
for (i = 0; i < frm.elements.length; i++) {
if (frm.elements[i].type == "checkbox") {
frm.elements[i].checked = document.getElementById(id).checked;
}
}
}
</script>
<style>
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
.confirm
{
background-color: White;
border-style: solid;
border-color: Red;
padding: 10px;
width: 400px;
font-family: Arial;
font-size: 11px;
}
.confirmtable
{
background-color: White;
border-style: none;
border-color: Silver;
padding: 0px;
width: 400px;
font-family: Arial;
font-size: 11px;
}
.confirmbutton
{
font-family: Arial;
font-size: 11px;
}
</style>
<div class="disignBoxFirst">
<div class="boxFirstHeader">
<div class="boxContent">
<div id="profile_details_wrapper">
<br />
<div class="pad_cont" style="margin: 10;">
<div class="pad_box2">
<div class="h2 t_sprite mail_send" style="float: right;">
<a href="#">Sent Messages</a></div>
<div class="h1 t_sprite mail">
Messages Inbox</div>
<asp:UpdatePanel ID="updatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView ID="gvInbox" runat="server" DataKeyNames="messageid" GridLines="None"
OnPageIndexChanging="gvInbox_PageIndexChanging" OnRowDataBound="gvInbox_RowDataBound"
Height="20px" HorizontalAlign="Center" VerticalAlign="Middle" AllowPaging="true"
AllowSorting="true" EmptyDataText="No data available." PageSize="5" AutoGenerateColumns="false"
CssClass="customers-grid" OnRowCreated="gvInbox_RowCreated">
<AlternatingRowStyle Height="25px" HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="CheckAll">
<HeaderStyle CssClass="delete-member"></HeaderStyle>
<ItemStyle CssClass="delete-member" Wrap="False"></ItemStyle>
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" CausesValidation="True" Text="" OnCheckedChanged="chkSelectAll_CheckedChanged" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" OnCheckedChanged="chkSelect_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<HeaderStyle CssClass="from-pic"></HeaderStyle>
<ItemStyle CssClass="from-pic" Wrap="False"></ItemStyle>
<ItemTemplate>
<a id="HLMainPicID" runat="server" navigateurl='<%#"~/Secure/ViewProfile.aspx?UserName="+Eval("FromUsername") %>'>
<asp:Image ID="MainPicID" BorderWidth="2" BorderColor="Silver" Style="vertical-align: middle"
class="srpic" runat="server" />
</a>
<asp:HiddenField ID="hiddenImgID" runat="server" Value='<%#DataBinder.Eval(Container,"DataItem.FromProfileID") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="From" DataField="FromUsername" SortExpression="FromUsername"
HeaderStyle-CssClass="from-username" ItemStyle-CssClass="from-username" />
<asp:BoundField HeaderText="Subject" DataField="Subject" SortExpression="Subject"
HeaderStyle-CssClass="subject" ItemStyle-CssClass="subject" />
<asp:BoundField HeaderText="Date Sent" DataField="MsgDate" SortExpression="MsgDate"
HtmlEncode="False" DataFormatString="{0:F}" HeaderStyle-CssClass="date-sent"
ItemStyle-CssClass="date-sent" />
<asp:BoundField HeaderText="Read" DataField="MsgRead" SortExpression="MsgRead" HeaderStyle-CssClass="read"
DataFormatString="{0:Yes/No}" ItemStyle-CssClass="read" />
<asp:BoundField HeaderText="Replied" DataField="MsgReplied" SortExpression="MsgReplied"
DataFormatString="{0:Yes/No}" HeaderStyle-CssClass="replied" ItemStyle-CssClass="replied" />
</Columns>
</asp:GridView>
<asp:Button ID="btnDelete" runat="server" OnClick="btnDelete_Click" OnClientClick="showConfirm(this); return false;"
Text="delete selected" />
<br />
<br />
<br />
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="modalBackground"
BehaviorID="mdlPopup" CancelControlID="btnNo" DropShadow="True" OkControlID="btnOk"
OnCancelScript="cancelClick();" OnOkScript="okClick();" PopupControlID="divDeleteItem"
TargetControlID="divDeleteItem" />
<div id="divDeleteItem" runat="server" align="center" class="confirm" style="display: none">
<table align="center" class="confirmtable">
<tr>
<td>
<img align="middle" src="images/warning.jpg" />
</td>
<td>
Are you sure you want to delete selected item(s)?
</td>
<td>
<asp:Button ID="btnOk" runat="server" Text="Yes" class="confirmbutton" />
</td>
<td>
<asp:Button ID="btnNo" runat="server" Text="No" class="confirmbutton" />
</td>
</tr>
</table>
</div>
</ContentTemplate>
</asp:UpdatePanel>
<div class="clear">
</div>
<br />
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
// keeps track of the delete button for the row that is going to be removed
var _source;
// keep track of the popup div
var _popup;
function showConfirm(source) {
this._source = source;
this._popup = $find('mdlPopup');
// find the confirm ModalPopup and show it
this._popup.show();
}
function okClick() {
// find the confirm ModalPopup and hide it
this._popup.hide();
// use the cached button as the postback source
__doPostBack(this._source.name, '');
}
function cancelClick() {
// find the confirm ModalPopup and hide it
this._popup.hide();
// clear the event source
this._source = null;
this._popup = null;
}
</script>
---------------------
code behind
public static string ConnnectionString = ConfigurationManager.ConnectionStrings["omegaloveConnectionString"].ToString();
string message = string.Empty;
DataSet ds = null;
DataTable dt = null;
private static string mstrConn = String.Empty;
private static string UserId = null;
protected void Page_Load(object sender, EventArgs e)
{
//if (!(HttpContext.Current.User.Identity.IsAuthenticated))
// Response.Redirect("~/Login.aspx");
UserId = HttpContext.Current.User.Identity.Name;
if (!IsPostBack)
{
if (UserId != null)
{
PopulateMailbox("", "");
}
else
{
Response.Redirect("~/Login.aspx");
}
}
}
protected void btnDelete_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in gvInbox.Rows)
{
CheckBox chkDelete = (CheckBox)row.FindControl("chkSelect");
if (chkDelete.Checked)
{
int returnValue = 0;
try
{
tbl_Mailbox tbl_Mailbox = new tbl_Mailbox();
tbl_Mailbox.MessageID = (int)gvInbox.DataKeys[row.RowIndex].Value;
returnValue = DataBase.prc_Message_Delete.Execute(ConnnectionString, tbl_Mailbox);
if (returnValue == 0) // refresh gridview
{
PopulateMailbox("", "");
}
}
catch (Exception)
{
throw;
}
}
}
}
private void PopulateMailbox(string SortExpression, string DeleteString)
{
int intGetProfileID = 0;
if (UserId == null)
UserId = HttpContext.Current.User.Identity.Name;
dt = DataBase.Procedures.prc_Profile_Select.ToDataTable(ConnnectionString, UserId);
intGetProfileID = Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString());
try
{
ds = DataBase.Procedures.prc_Messages_Select.ToDataSet(ConnnectionString, Convert.ToInt32(dt.Rows[0]["ProfileID"].ToString()), UserId, DeleteString);
if ((ds != null) && (ds.Tables[0] != null) && (ds.Tables[0].Rows.Count > 0))
{
//LABEL_NoMessages.Text = string.Empty;
gvInbox.AllowPaging = true;
gvInbox.PageSize = 5;
//gvInbox.PagerStyle.Mode = PagerMode.NumericPages;
// Add filter for inbox, drafts, etc.
//gvInbox.DataSource.DefaultView.RowFilter = String.Concat("Station = \'", sStation, "\'");
gvInbox.DataSource = ds.Tables[0].DefaultView;
gvInbox.Visible = true;
gvInbox.DataBind();
}
else
{
gvInbox.Visible = false;
//LABEL_NoMessages.Text = "No Messages";
}
return;
}
catch (SqlException e)
{
WebMsgBox.Show(e.ToString());
}
}
protected void gvInbox_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
}
protected void gvInbox_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
// Add attribute for onclick event on check box in header passing MessageId of Select All checkbox
((CheckBox)e.Row.FindControl("chkSelectAll")).Attributes.Add("onclick", "javascript:SelectAll('" + ((CheckBox)e.Row.FindControl("chkSelectAll")).ClientID + "')");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#E8EEFA';");
if (e.Row.RowIndex % 2 == 0)
{ // even
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#FFFFFF';");
} // odd
else
{
//e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#DEE4E7';");
}
HiddenField hdimageId = (HiddenField)e.Row.FindControl("hiddenImgID");
System.Web.UI.WebControls.Image MainPicID = (System.Web.UI.WebControls.Image)(e.Row.FindControl("MainPicID"));
MainPicID.ID = hdimageId.Value;
MainPicID.ToolTip = "Thumbnail of Photo Number =" + hdimageId.Value;
DataTable dtPhotos = new DataTable();
dtPhotos = DataBase.Procedures.prc_Photos_Select_Primary.ToDataTable(ConnnectionString, Convert.ToInt32(hdimageId.Value));
// Get img id from datatable.
if (((dtPhotos != null) && (dtPhotos.Rows.Count > 0)))
{
if (Convert.ToBoolean(dtPhotos.Rows[0]["p_Primary"]))
{
MainPicID.ImageUrl = "~/Secure/ShowThumbnail.ashx?img_id=" + dtPhotos.Rows[0]["PhotoID"].ToString() + "&" + "imagesize=T" + "&" + "imageisprimary=" + "True" + "'";
}
}
else
{
// set default image
}
}
}
protected void chkSelectAll_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkAll = (CheckBox)gvInbox.HeaderRow.FindControl("chkSelectAll");
if (chkAll.Checked == true)
{
foreach (GridViewRow gvRow in gvInbox.Rows)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = true;
}
}
else
{
foreach (GridViewRow gvRow in gvInbox.Rows)
{
CheckBox chkSel = (CheckBox)gvRow.FindControl("chkSelect");
chkSel.Checked = false;
}
}
}
protected void chkSelect_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkTest = (CheckBox)sender;
GridViewRow grdRow = (GridViewRow)chkTest.NamingContainer;
}
public static string GetConnectionString(string _connectionStringsName)
{
System.Configuration.ConnectionStringSettingsCollection config = System.Configuration.ConfigurationManager.ConnectionStrings;
for (int i = 0; i < config.Count; i++)
{
if (config[i].Name.Equals(_connectionStringsName, StringComparison.OrdinalIgnoreCase))
return config[i].ToString();
}
return String.Empty;
}
|