...

View Full Version : Please help Me !!!!!!!



AbuBakar
11-26-2005, 07:51 AM
Hello Dear!

Hope you will all be fine i have made a Dynamic wesite in Asp.net successfully Alhamdulila but i am not completly satisified with that because i have written some of my database code in .aspx file too i don't want to do this but i didn't know that how can i write it in .cs file and implement it so i need your help in this regard i am sending you one .aspx file please change it to write all database code in .cs file i will be grateful to you...............

please reply me as soon as possible on my email address abubakar.malik@gmail.com

Thanks and Regards

AbuBakar Malik

windumi
12-07-2005, 08:08 AM
create a c# dll project , as follow code


// ********************************************************************/
public class SearchResultsView : TemplatedWebControl
{

#region Constructor and Member Variables
CSContext csContext = CSContext.Current;
string skinFilename = "View-SearchResults.ascx";
string searchQuery;
//string[] searchForums;
//string[] searchUsers;
Label searchFor;
TextBox searchTextTop;
TextBox searchTextBottom;
Button searchButtonTop;
Button searchButtonBottom;
Repeater searchRepeater;
CurrentPage resultTotal;
Literal searchDuration;
Pager pager;
HtmlGenericControl validatorTop;
HtmlGenericControl validatorBottom;
StatusMessage formStatus;
Panel searchResultsDisplay;

// *********************************************************************
// SearchView
//
/// <summary>
/// The constructor simply checks for a ForumID value passed in via the
/// HTTP POST or GET.
/// properties.
/// </summary>
///
// ********************************************************************/
public SearchResultsView()
{

// Assign a default template name
this.ExternalSkinFileName = skinFilename;

//searchForums = ForumsToSearchDecode ( csContext.Context.Request.QueryString["f"] ) ;

}

/// <summary>
/// If not a page back, calls DataBind()
/// </summary>
/// <param name="e"></param>
protected override void OnLoad(EventArgs e)
{
if ( !Page.IsPostBack )
{
this.DataBind();
}
base.OnLoad (e);
}

#endregion

public static string[] ForumsToSearchDecode (string stringToDecode)
{
Hashtable forums = Forums.GetForums(CSContext.Current, false, true);
UTF8Encoding decoder = new UTF8Encoding();
string[] filteredForumsToSearch = null;
ArrayList verifiedForumList = new ArrayList();

// Convert the parameters from a base64 encoded string and then
// into a string[]
//
if (stringToDecode != string.Empty)
{

// Attempt to decode the string
try
{
byte[] forumList = Convert.FromBase64String( stringToDecode );
filteredForumsToSearch = decoder.GetString( forumList ).Split(',');
}
catch
{
filteredForumsToSearch = null;
}
}

// Get a verified list of only the forums the user has access to
// if our forum string[] is null we get all the forums the user
// has access to; otherwise the list is checked to ensure we only
// get forums the user is allowed to see
//
if (filteredForumsToSearch == null)
{
foreach (Forum f in forums.Values)
{
if(f.ForumType != ForumType.Deleted && f.ForumType != ForumType.Reporting && f.IsSearchable)
verifiedForumList.Add(f.SectionID.ToString());
}
}
else
{
foreach (string forumid in filteredForumsToSearch)
{
if (forums[ int.Parse(forumid) ] != null)
verifiedForumList.Add(forumid);
}
}

return (string[]) verifiedForumList.ToArray(typeof(string));
}

#region Render
// *********************************************************************
// AttachChildControls
//
/// <summary>
/// Initializes the user control loaded in CreateChildControls. Initialization
/// consists of finding well known control names and wiring up any necessary events.
/// </summary>
///
// ********************************************************************/
protected override void AttachChildControls()
{

if (!Page.IsPostBack) {
searchQuery = csContext.Context.Request.QueryString["q"];
//searchUsers = CommunityServer.Search.UsersToDecode (csContext.Context.Request.QueryString["u"] );
}

// Find all the controls
//
searchFor = (Label) FindControl("ForumDescription");
searchTextTop = (TextBox) FindControl("SearchTextTop");
//searchTextBottom = (TextBox) FindControl("SearchTextBottom");
searchButtonTop = FindControl("SearchButtonTop") as Button;
//searchButtonBottom = FindControl("SearchButtonBottom") as Button;
searchButtonTop.Text = ResourceManager.GetString("Search");
//searchButtonBottom.Text = ResourceManager.GetString("Search");
searchRepeater = FindControl("SearchRepeater") as Repeater;
pager = (Pager) FindControl("Pager");
resultTotal = (CurrentPage) FindControl("TotalResults");
resultTotal.TextFormat = ResourceManager.GetString("SearchResults_TotalResults");
searchDuration = (Literal) FindControl("SearchDuration");
searchDuration.Text = ResourceManager.GetString("SearchResults_SearchDuration");
formStatus = FindControl("formStatus") as StatusMessage;
validatorTop = (HtmlGenericControl) FindControl("SearchBoxValidatorTop");
validatorBottom = (HtmlGenericControl) FindControl("SearchBoxValidatorBottom");
searchResultsDisplay = FindControl("SearchResultsDisplay") as Panel;

((Label) FindControl("ForumName")).Text = ResourceManager.GetString("SearchViewSimple_Title");


// Set up the OnItemCommand for the DataList
//
searchRepeater.ItemCommand += new RepeaterCommandEventHandler(Display_Item);
searchRepeater.ItemDataBound += new RepeaterItemEventHandler( SearchRepeater_ItemDataBound );
searchButtonTop.Click += new EventHandler(Search_Click);
//searchButtonBottom.Click += new EventHandler(Search_Click);


// Set the pager size
//
pager.PageSize = CSContext.Current.SiteSettings.SearchPostsPerPage;

// Set the values in our textboxes
//
searchTextTop.Text = searchQuery;
//searchTextBottom.Text = searchQuery;
}
#endregion

public void Search_Click (Object sender, EventArgs e)
{
bool isSearchTextInTopTextBox = true;

// Which search text is being used?
//
if ( ((Button) sender).ID != "SearchButtonTop" )
isSearchTextInTopTextBox = false;

// Set the text to the correct values
//

if(searchTextTop.Text.Trim() == string.Empty)
{
validatorTop.Visible = true;
return;
}
else
{
validatorTop.Visible = false;
}


HttpContext.Current.Response.Redirect(Globals.GetSiteUrls().SearchForText(searchTextTop.Text));
}

public override void DataBind()
{
base.DataBind();

SearchResultSet searchResult = null;
int resultCountUpper, resultCountLower;

// Set the "search for" text
//
searchFor.Text = string.Format(ResourceManager.GetString("SearchViewSimple_SearchFor"), Globals.HtmlEncode(searchTextTop.Text));

// Get the search results
//

SearchQuery query = new SearchQuery();
query.PageIndex = pager.PageIndex;
query.PageSize = pager.PageSize;
query.UserID = CSContext.Current.User.UserID;
query.SectionsToSearch = ForumsToSearchDecode ( csContext.Context.Request.QueryString["f"] );
query.UsersToSearch = CommunityServer.Search.UsersToDecode (csContext.Context.Request.QueryString["u"]);
query.SearchTerms = searchTextTop.Text;
ForumSearch search = new ForumSearch();

try {
searchResult = search.GetSearchResults(query);
} catch {
searchResultsDisplay.Visible = false;
formStatus.Visible = true;
formStatus.Success = false;
formStatus.ResourceName = "SearchView_NoResults";

return;
}

// Set the TotalRecords in the pager
//
pager.TotalRecords = searchResult.TotalRecords;

// Databind
//
searchRepeater.DataSource = searchResult.Posts;
searchRepeater.DataBind();

resultCountLower = 1 + (pager.PageIndex * pager.PageSize);

// Set the upper bounds of the search results text
//
if (pager.TotalRecords > pager.PageSize)
resultCountUpper = pager.PageSize + (pager.PageSize * pager.PageIndex);
else
resultCountUpper = searchResult.TotalRecords;

// Setup the result total
resultTotal.PageIndex = pager.PageIndex;
resultTotal.TotalPages = pager.CalculateTotalPages();
resultTotal.TotalRecords = pager.TotalRecords;

if (searchResult.SearchDuration < 1)
searchDuration.Text = string.Format(searchDuration.Text, "< 1");
else
searchDuration.Text = string.Format(searchDuration.Text, searchResult.SearchDuration);

}

public void Display_Item (Object sender, RepeaterCommandEventArgs e)
{

HttpContext.Current.Response.Write( e.CommandArgument );
DataBind();

}

/// <summary>
/// Added to handle Username displaying
/// </summary>
protected void SearchRepeater_ItemDataBound (Object Sender, RepeaterItemEventArgs e) {
ForumPost post = e.Item.DataItem as ForumPost;
if (post == null)
return;

bool isAnonymousPostingEnabled = post.IsAnonymousPost &&
CSContext.Current.SiteSettings.EnableUserPostingAsAnonymous &&
post.Forum.EnableAnonymousPostingForUsers;

switch (e.Item.ItemType) {
case ListItemType.Item:
case ListItemType.AlternatingItem:
Label userName = e.Item.FindControl( "UsernameLink" ) as Label;
if (userName != null) {
userName.Text = Formatter.FormatUsername( post.User.UserID, post.User.Username, isAnonymousPostingEnabled, false );
}
break;
}
}
}
}

compile it , then you can use this compont with such code




<%@ Control Language="C#" %>
<%@ Register TagPrefix="CS" Namespace="CommunityServer.Controls" Assembly="CommunityServer.Controls" %>
<%@ Register TagPrefix="CSD" Namespace="CommunityServer.Discussions.Controls" Assembly="CommunityServer.Discussions" %>
<%@ import Namespace="CommunityServer.Components" %>
<%@ import Namespace="CommunityServer.Controls" %>
<%@ import Namespace="CommunityServer" %>
<%@ Import Namespace="CommunityServer.Discussions.Components" %>
<%@ Import Namespace="CommunityServer.Discussions.Controls" %>

<div id="BodyHead">
<h2><asp:Label ID="ForumName" Runat="server" /></h2>
<asp:Label CssClass="h2Desc" ID="ForumDescription" Runat="server" />
<div class="breadCrumb"><CSD:BreadCrumb ShowHome="true" runat="server" ID="Breadcrumb1"/></div>
<cs:StatusMessage runat="server" id="formStatus" />
<div id="SearchTexbox">
<CS:DefaultButtonTextBox button="SearchButtonTop" id="SearchTextTop" runat="server" MaxLength="64" columns="55" />
<span id="SearchBoxValidatorTop" style="color: red" runat="server" visible="false">*</span>
<asp:Button id="SearchButtonTop" runat="server" /> <a href="<%=Globals.GetSiteUrls().SearchAdvanced%>"><CS:ResourceLabel runat="server" ResourceName="Search_MoreSearchOptions" ID="Resourcelabel1"/></a>
</div>

<div class="adTop"><CS:Ads Zone="StandardTop" runat="server" ID="Ads1"/></div>
</div>

<asp:Panel ID="SearchResultsDisplay" Runat="server">
<div id="SearchDuration">
<cs:CurrentPage id="TotalResults" runat="server" />
<asp:Literal id="SearchDuration" runat="server"></asp:Literal> &nbsp;
</div>

<asp:Repeater id="SearchRepeater" runat="Server" EnableViewState="false">
<ItemTemplate>

<div id="SearchResult">
<h3><a href="<%# Globals.GetSiteUrls().Post( (int) DataBinder.Eval(Container.DataItem, "PostID") ) %>"><%# DataBinder.Eval(Container.DataItem, "Subject") %></a></h3>
<div id="SearchResultBody">
<%# ((ForumPost) Container.DataItem).GetBodySummary(350, SearchTextTop.Text, System.Drawing.Color.Black, System.Drawing.Color.Yellow) %>
</div>
<em>
Posted in <a href="<%# ForumUrls.Instance().Forum( ((ForumPost) Container.DataItem).SectionID ) %>"><%# DataBinder.Eval(Container.DataItem, "Forum.Name") %></a>
by <a target="_blank" href="<%# Globals.GetSiteUrls().UserProfile( ((ForumPost) Container.DataItem).User.UserID ) %>"><%# DataBinder.Eval(Container.DataItem, "UserName") %></a>
on <%# ((DateTime) DataBinder.Eval(Container.DataItem, "PostDate")).ToString( CSContext.Current.User.Profile.DateFormat ) %><br />
</em>
</div>

</ItemTemplate>

<SeparatorTemplate>
<hr id="SearchResultHr" />
</SeparatorTemplate>
</asp:Repeater>

<div id="SearchFooter"></div>


<div align="center">
<CS:Pager id="Pager" runat="server" />
</div>
</asp:Panel>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum