Monday, May 30, 2011

Retrieval Password from asp Membership tables

//web.config
machineKey validationKey="10B00B531A175EFE53065651BC315DDDDED9C1A6626D0996B1E18F6BEAC58153ACF7AC5306937C6C6C823C00BB8DB07F4D1CF4F4CF2CAC7EBEBB9463DC801B31" decryptionKey="4BCD239B9946A067517A3DBC503DAAE28BFE5C860A7037D25C547D85C4F55973" validation="SHA1" decryption="AES"

"add connectionStringName="UserManagement" minRequiredPasswordLength="6" enablePasswordRetrieval="true" passwordFormat="Encrypted" enablePasswordReset="true" requiresUniqueEmail="true" minRequiredNonalphanumericCharacters="0" requiresQuestionAndAnswer="false" applicationName="/InkyDB" name="AspNetSqlProvider" type="System.Web.Security.SqlMembershipProvider" "


on .aspx page

MembershipUser user = Membership.GetUser("piyush");

string password = user.GetPassword();

Friday, May 27, 2011

Paging in Datalist or repeater + using hashtable

// I have a search Module in a project in which data is coming and populated by //datalist for more than 1 pages I have need for integrated paging in this datalist //and also I used hashtable on the basis of unique key and datasource of datalist .
PagedDataSource pg = new PagedDataSource();
string searchstring; int catid;
DataView dvData = new DataView(dt);
dvData.Sort = "PublishDate Desc";
ListDictionary myHashTable = new ListDictionary();
for (int j = 0; j < dvData.Count; j++)
{
if (dvData[j]["ArticleID"] != null)
{
//StringBuilder str = new StringBuilder(150);5+6
string str = dvData[j]["CategoryID"] + "~^`" + dvData[j]["ArticleID"] + "~^`" + dvData[j]["Title"] + "~^`" + dvData[j]["ListThumbnail"].ToString() + "~^`" + dvData[j]["GetPrintOrDay"].ToString() + "~^`" + dvData[j]["ShortStory"].ToString() + "~^`" + dvData[j]["PublishDate"].ToString();
myHashTable.Add(dvData[j]["ArticleID"].ToString(), str.Split("~^`".ToCharArray()));
}

}

pg.DataSource = myHashTable;
//pg.AllowCustomPaging = true;
pg.AllowPaging = true;
pg.PageSize = 20;
// Move to the appropriate page based on the query string.
try
{
pg.CurrentPageIndex = Int32.Parse(Request.QueryString["Page"].ToString());
}
catch (Exception ex)
{
pg.CurrentPageIndex = 0;
}
// Enable and/or disable the previous and next buttons
btnPrev.Enabled = !pg.IsFirstPage;
btnNext.Enabled = !pg.IsLastPage;
// Display which is the current page being displayed
lblCurrentPage.Text = "Page: " + (pg.CurrentPageIndex + 1).ToString();
lbltotalpages.Text = (dt.Rows.Count / 20).ToString();
if (dt.Rows.Count % 20 != 0)
{
lbltotalpages.Text = ((dt.Rows.Count / 20) + 1).ToString();
}
// Attach data source to the datalist
if (dt.Rows.Count > 20)
divNav.Visible = true;
rptDepartmentCate.DataSource = pg;
rptDepartmentCate.DataBind();
lblmessage.Text = "" + dt.Rows.Count.ToString() + "" + " " + "Results found for" + " '" + searchstring + "'";
for (int l = 0; l < pg.Count; l++)
{
rptDepartmentCate.Controls[l].Controls[3].Visible = true;
}
}
else
{
lblmessage.Text = "Your search '" + searchstring + "' did not match any article.";
}
}
else
{
lblmessage.Text = "Your search '" + searchstring + "' did not match any article.";
}
}
public void Prev_Click(Object sender, EventArgs e)
{
int pagenumber = 0;
if (!string.IsNullOrEmpty(Request.QueryString["Page"]))
pagenumber = Convert.ToInt32(Request.QueryString["Page"]) - 1;
if (Request.CurrentExecutionFilePath == "/EditorAndPublisher/SearchResult.aspx")
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + pagenumber);

}

// Move to next page
public void Next_Click(Object sender, EventArgs e)
{
int pagenumber=1;
if(!string.IsNullOrEmpty(Request.QueryString["Page"]))
pagenumber=Convert.ToInt32(Request.QueryString["Page"])+1;
if (Request.CurrentExecutionFilePath == "/EditorAndPublisher/SearchResult.aspx")
Response.Redirect(Request.CurrentExecutionFilePath + "?Page=" + pagenumber);

}

Thursday, May 19, 2011

Search according to date and time

private void Search()
{
// Get start date and end date of Current Week//
DayOfWeek day = DateTime.Now.DayOfWeek;
int days = day - DayOfWeek.Monday;
DateTime startD = DateTime.Now.AddDays(-days);
DateTime endD = startD.AddDays(6);

// Get start date and end date of Current month //
DateTime startM = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
DateTime endM = startM.AddMonths(1).AddDays(-1);


DateTime? OrderDate = null, StartOrderDate = null, EndOrderDate = null;


ViewState["sContent"] = null;
//string Title = txtTitle.Text;
if (ddlPeriod.SelectedItem.Value != "Select")
{
if (ddlPeriod.SelectedValue == "Today")
OrderDate = Convert.ToDateTime(DateTime.Now.ToShortDateString());
else if (ddlPeriod.SelectedValue == "Yesterday")
OrderDate = Convert.ToDateTime(DateTime.Now.AddDays(-1).ToShortDateString());
else if (ddlPeriod.SelectedValue == "This Week")
{
StartOrderDate = startD;
EndOrderDate = endD;
}
else if (ddlPeriod.SelectedValue == "This Month")
{
StartOrderDate = startM;
EndOrderDate = endM;
}
else if (ddlPeriod.SelectedValue == "Date Range")
{

if (!string.IsNullOrEmpty(txtDateRange1.Text))
StartOrderDate = Convert.ToDateTime(txtDateRange1.Text);
if (!string.IsNullOrEmpty(txtdaterange2.Text))
EndOrderDate = Convert.ToDateTime(txtdaterange2.Text);
}
}
//int CatId = 0;
//if (Request.QueryString["CategoryID"] != null)
// CatId = Convert.ToInt32(Request.QueryString["CategoryID"]);
//if (Title != null)
// Title = Title.Replace("'", "''");
int onumber = 0;
if (!string.IsNullOrWhiteSpace(txtorderno.Text))
onumber=Convert.ToInt32(txtorderno.Text);

GetOrders(onumber, txtcustname.Text, txtemail.Text, OrderDate.ToString(), StartOrderDate.ToString(), EndOrderDate.ToString(), chkDisable.Checked);
//GetOrders((Convert.ToInt32(txtorderno.Text)));
}

Monday, May 16, 2011

Credit card date expire validations

script type="text/javascript"
function ValidateCardNumber(sender, args) {
if ((args.Value.length < 13) || (args.Value.length > 16)) {
args.IsValid = false;
}
else {
args.IsValid = true;
}
}
function IsValidDate(Mn, Yr) {
if (Mn == 12)
Yr++;

var dt = new Date();
dt.setMonth(Mn);
dt.setDate(1);
dt.setFullYear(Yr);
var today = new Date();

if (today >= dt) {
return false;
}
return true;
}

function CallDateFun(sender, args) {
var m = document.getElementById('<%= mddlMM.ClientID %>').value
var y = document.getElementById('<%= mddlYY.ClientID %>').value;
//year=2000+parseInt(y);
if (m != 0 && y != 0) {
args.IsValid = IsValidDate(m, y);
}
}
/script

Tuesday, May 10, 2011

What is Delegates ?

A delegate is a type-safe object that can point to another method (or possibly multiple methods) in the application, which can be invoked at later time.

Delegates also can invoke methods Asynchronously.

A delegate type maintains three important pices of information :

The name of the method on which it make calls.
Any argument (if any) of this method.
The return value (if any) of this method.
Defining a Delegate in C#

when you want to create a delegate in C# you make use of delegate keyword.

The name of your delegate can be whatever you desire. However, you must define the delegate to match the signature of the method it will point to. fo example the following delegate can point to any method taking two integers and returning an integer.

public delegate int DelegateName(int x, int y);

A Delegate Usage Example

namespace MyFirstDelegate
{
//This delegate can point to any method,
//taking two integers and returning an
//integer.
public delegate int MyDelegate(int x, int y);
//This class contains methods that MyDelegate will point to.
public class MyClass
{
public static int Add(int x, int y)
{
return x + y;
}
public static int Multiply(int x, int y)
{
return x * y;
}
}
class Program
{
static void Main(string[] args)
{
//Create an Instance of MyDelegate
//that points to MyClass.Add().
MyDelegate del1 = new MyDelegate(MyClass.Add);
//Invoke Add() method using the delegate.
int addResult = del1(5, 5);
Console.WriteLine("5 + 5 = {0}\n", addResult);
//Create an Instance of MyDelegate
//that points to MyClass.Multiply().
MyDelegate del2 = new MyDelegate(MyClass.Multiply);
//Invoke Multiply() method using the delegate.
int multiplyResult = del2(5, 5);
Console.WriteLine("5 X 5 = {0}", multiplyResult);
Console.ReadLine();
}
}
}