Friday, February 29, 2008

SerialPort (RS-232 Serial COM Port) in C# .NET for MIFARE

This article is about communicating through the PC's Serial COM RS-232 port using Microsoft .NET 2.0 or later by using the System.IO.Ports.SerialPort class.

using System.IO.Ports;
using System.Threading;
using System.Windows.Forms;

SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);


try
{
port.Open();
port.Write("x");


Thread.Sleep(500);


string x = port.ReadExisting().ToString();
port.Write("c");
Thread.Sleep(500);
string c = port.ReadExisting().ToString();
port.Write(" ");
Thread.Sleep(500);
string p = port.ReadExisting().ToString();
port.Write("s");
Thread.Sleep(500);
string s = port.ReadExisting().ToString();
port.Write("l" + "01" + "FF" + "\r\n");

Thread.Sleep(500);
string l = port.ReadExisting().ToString();
port.Write("r" + "04");

Thread.Sleep(500);
string r = port.ReadExisting().ToString();

port.Write("r" + "04");
Thread.Sleep(500);
string t = port.ReadExisting().ToString();
Thread.Sleep(500);
port.Write("rv" + "04");

Thread.Sleep(500);

string v = port.ReadExisting().ToString();

//string u = v.Substring(0, v.IndexOf("\r\n"));
//int k = Convert.ToInt32(u, 16);
//// k = Int32.Parse(u, NumberStyles.HexNumber);

//TextBox1.Text = k.ToString();


int num = Convert.ToInt32(txtamt.Text);

string st = num.ToString("X");
int bt = st.Length;
for (int i = 0; i < 8 - bt; i++)
{
st = "0" + st;
}
port.Write("+" + "04" + st);
Thread.Sleep(500);

string b = port.ReadExisting().ToString();
string u = b.Substring(0, b.IndexOf("\r\n"));

int d = Convert.ToInt32(u, 16);

string j = d.ToString();
MessageBox.Show("Your Balance Amount is " + j);
}
catch (Exception ex)
{
throw ex;
}
port.Close();

Thursday, February 28, 2008

http://www.asp.net/


Microsoft ASP.NET is a free technology that allows programmers to create dynamic web applications. ASP.NET can be used to create anything from small, personal websites through to large, enterprise-class web applications. All you need to get started with ASP.NET is the free .NET Framework and the free Visual Web Developer.

Tuesday, February 26, 2008

Windows Workflow Foundation

Workflow means performing any task in order. Today, each application is based on workflow approach
and involves some processes to be executed. While creating an application, developers are still following
the traditional approach that leads to create steps in the process implicit in the code. This traditional
approach works fine, but requires a deep programming logic making the process difficult to change and execute.

Workflow engine is not a new technology; it came into existence in early 2000. In the market, several
workflow engines are available for Windows and other platforms. Today, all applications are based on
workflow approach. So, defining different engines for different applications is a cumbersome task. To
avoid this, Microsoft has decided to define a single common workflow engine for all the windows-based
applications. This is what the Windows Workflow Foundation (WF) performs. WF provides a common
workflow technology for all the windows-based applications, such as Microsoft Office 2007 and
Windows Share Point Services.

Architecture of .NET FRAMEWORK 3.0

Data loading from SQL Server database at runtime

Firstly Add DataList Control in Design View.Then Change the html code of Datalist as follows:





Source Code:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class dynamic : System.Web.UI.Page
{
SqlConnection con = new SqlConnection("Data Source=ELWIN;Initial Catalog=sherin;Integrated Security=True");
public void display(string query)
{
con.Open();
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataTable dt = new DataTable();
da.Fill(dt);
DataView dv = new DataView(dt);
PagedDataSource objpag = new PagedDataSource();
objpag.DataSource = dv;
objpag.AllowPaging = true;
objpag.PageSize = 5;
DataList1.DataSource = objpag;
DataList1.DataBind();
con.Close();

}
public void check(object sender, System.Web.UI.WebControls.CommandEventArgs e)
{

if (Session["programid"] != null)
{
Session["programid"] = Session["programid"] + " or programid=" + e.CommandName;

}
else
{
Session["programid"] = e.CommandName;
}

string fg = Session["programid"].ToString();
Response.Redirect("shoppingcart.aspx");
}

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{

display("select * from addprogram2 ");
}

}
}


Output:



Monday, February 25, 2008

Scott Guthrie






Scott Guthrie is a vice president in the Microsoft Developer Division. He runs the development teams that build ASP.NET, Common Language Runtime (CLR), Windows Presentation Foundation (WPF), Silverlight, Windows Forms, Internet Information Services 7.0, Commerce Server, .NET Compact Framework, Visual Web Developer and Visual Studio Tools for WPF. He is best known for his work on ASP.NET, which he and colleague Mark Anders developed while at Microsoft.[1]

SqlServer Database Connection in asp.net with C#

Microsoft SQL Server is a relational database management system (RDBMS) produced by Microsoft. Its primary query language is Transact-SQL, an implementation of the ANSI/ISO standard Structured Query Language (SQL) used by both Microsoft and Sybase.


Add SQL Connection in asp.net with c#:






How to get Connection String for SQLConnection :










Source Code :


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class data : System.Web.UI.Page
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True");

protected void Page_Load(object sender, EventArgs e)
{

}
}

Serial Communication with MSComm Control in windows application

Add Reference for Serial Communication:



Add MSComm Control For Serial Communication:




Serial Communication Form Design:





Source Code For Serial Communication:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Globalization;
using System.IO;
using System.Diagnostics;
using System.Threading;

namespace mifaretest
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private static int num;
private static string st;

private void button1_Click(object sender, EventArgs e)
{
num = Convert.ToInt32(txtamt.Text);

st = num.ToString("X");
int bt = st.Length;
for (int i = 0; i < 8 - bt; i++)
{
st = "0" + st;
}
axMSComm1.Output = "+" + "04" + st;
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
string b = axMSComm1.Input.ToString();
string u = b.Substring(0, b.IndexOf("\r\n"));

int c = Convert.ToInt32(u, 16);

txtbal.Text = c.ToString();
}

}



private void Form2_Load(object sender, EventArgs e)
{
if (axMSComm1.PortOpen == false)
{
axMSComm1.PortOpen = true;
}


}

private void btnwithdrawal_Click(object sender, EventArgs e)
{
num = Convert.ToInt32(txtamt.Text);

st = num.ToString("X");
int bt = st.Length;
for ( int i = 0; i < 8 - bt; i++)
{
st = "0" + st;
}
axMSComm1.Output = "-" +"04" + st;
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
string b = axMSComm1.Input.ToString();
string u = b.Substring(0, b.IndexOf("\r\n"));

int c = Convert.ToInt32(u, 16);

txtbal.Text = c.ToString();
}

}


private static int i=0;
private static string x;
private static string c;
private static string p;
private static string s;
private static string l;
private static string r;
private static string t;
private static string v;
private static string u;
private static int k;
private void button2_Click(object sender, EventArgs e)
{
axMSComm1.Output = "x";
int o = axMSComm1.InBufferCount;

Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
x = axMSComm1.Input.ToString();
}

axMSComm1.Output = "c";
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
c = axMSComm1.Input.ToString();
}
axMSComm1.Output = " ";
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
p = axMSComm1.Input.ToString();
}
axMSComm1.Output = "s";
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
s = axMSComm1.Input.ToString();
}
axMSComm1.Output = "l" + "01" + "FF" + "\r\n";
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
l = axMSComm1.Input.ToString();
}
axMSComm1.Output = "r" + "04";
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
r = axMSComm1.Input.ToString();
}
axMSComm1.Output = "r" + "04";
Thread.Sleep(500);
if (axMSComm1.InBufferCount > 0)
{
t = axMSComm1.Input.ToString();
}
Thread.Sleep(500);

axMSComm1.Output = "rv" + "04";
Thread.Sleep(500);
// string m = x + c + p + s + l + r + t;
if (axMSComm1.InBufferCount > 0)
{
v = axMSComm1.Input.ToString();

u = v.Substring(0, v.IndexOf("\r\n"));
k = Convert.ToInt32(u, 16);
k = Int32.Parse(u, NumberStyles.HexNumber);

txtbal.Text = k.ToString();

}

}








}
}

Architecure of .NET FRAMEWORK

CLI
Assemblies
Metadata
Class library
Security
Memory management

.NET FRAMEWORK

The Microsoft .NET Framework is a software component that is a part of Microsoft Windows operating systems. It has a large library of pre-coded solutions to common program requirements, and manages the execution of programs written specifically for the framework. The .NET Framework is a key Microsoft offering, and is intended to be used by most new applications created for the Windows platform.

The pre-coded solutions that form the framework's Base Class Library cover a large range of programming needs in areas including: user interface, data access, database connectivity, cryptography, web application development, numeric algorithms, and network communications. The class library is used by programmers who combine it with their own code to produce applications.

Programs written for the .NET Framework execute in a software environment that manages the program's runtime requirements. This runtime environment, which is also a part of the .NET Framework, is known as the Common Language Runtime (CLR). The CLR provides the appearance of an application virtual machine, so that programmers need not consider the capabilities of the specific CPU that will execute the program. The CLR also provides other important services such as security mechanisms, memory management, and exception handling. The class library and the CLR together compose the .NET Framework.

The .NET Framework is included with Windows Server 2003, Windows Server 2008 and Windows Vista, and can be installed on most older versions of Windows

hello world program in asp.net with c#

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("Hello World");
}
}

CodeRenderBlock in asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>





Untitled Page




<% for (int i = 0; i <= 6; i++)
{ %>


Welcome to ASP.NET
<%} %>



Hello World Program in asp.net

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>





Untitled Page




Hello World






helloworldprogram in asp.net

Increasing Developer Productivity by Using Login Control





Increasing Developer Productivity by Using Login Control











Usage of Login Control reduces the time to create
a Login Control. This example depicts how to increase the developer productivty.






x









stylesheet.cs:=
html, body {
background-color: #FFFFFF;
color: #000000;
font: normal 90%/1.8em 'Lucida Grande', Verdana, Geneva, Lucida, Helvetica, Arial, sans-serif;
margin: 0;
height: 100%;
}
h1 {
font-size: 1.8em;
font-weight: bold;
margin-top: 0em;
margin-bottom: 0em;
color: #a83930;
}
h2 {
font-size: 1.6em;
margin: 1.0em 0em 1.0em 0em;
font-weight: bold;
color: #a83930;
}
h3 {
font-size: 1.2em;
margin: 1.0em 0em 1.0em 0em;
font-weight: bold;
color: #a83930;
}
p {
font-size: 1.1em;
line-height: 1.8em;
margin: 1.1em 0em 1.1em 0em;
text-align: left;
}
ul
{
font-size: 1.1em;
}
a:link, a:visited {
color: #cc3300;
text-decoration: underline;
}
a:hover {
text-decoration: none;
}
a:active {
color: #ff9900;
text-decoration: underline;
}
title {
color: #a83930;
}
#header {
height: 8px;
padding: 0 0px 0 0px;
color: #a83930;
background-color: #000000;
border-bottom: 8px solid #d30a1a;
}
#header h1 {
padding: 10px 0 0 0;
margin: 10px 0 0 0px;
color: #FFFFFF;
margin-left: 10px;
margin-bottom: 10px;
}
#logo {
background-color: #000000;
background: url(images/logo.gif);
background-position: top left;
background-repeat: no-repeat;
height: 100px;
width: 100px;
border: 0;
float: left;
}
#content {
margin-left: 210px;
padding: 0 20px 1.8em 10px;
background-color: #fff;
}
.code {
color: #a83930;
background-color: #fdea12;
font: 0.9em/1.4em verdana, arial, helvetica, sans-serif;
float: right;
border: solid 1px #a83930;
padding: 10px;
}

#sidebar {
float:left;
padding: 0 10px 10px 10px;
background-color: #656565;
/*background-image: url(images/bg_2.gif);*/
background-repeat: repeat-y;
background-position: top left;
border-top: 2px solid #656565;
border-bottom: 2px solid #656565;
width: 168px; /* ds */
height:500px;
}
html>body #sidebar {
width: 180px;
}
#sidebar h3 {
font-weight: bold;
padding-bottom: 0.5em;
border-bottom: 1px dashed #fdea12;
color: #fdea12;
}

#nav a:link, #nav a:visited {
/*display: block;*/
width: 99.99%; /* for IE5 */
color: #FFFFFF;
text-decoration: none;
padding: 0.25em 0.5em 0.25em 0.5em;
font-weight: bold;
}
#nav a:hover {
text-decoration: none;
color: #FFFFFF;
/*background-color: #fdea12; */
}

.title {
color: #a83930;
font: bold 1.0em/1.0em verdana, arial, helvetica, sans-serif;
text-align: center;
padding-bottom: 5px;
border-bottom: #a83930 thin solid;
margin-bottom: 5px;
}
#footer {
/*margin-left: 210px; */
padding: 0 20px 1.8em 10px;
border-top: 1px solid #000000;
clear: both;
}
#footer p {
font: normal 0.8em/0.9em verdana, arial, helvetica, sans-serif;
color: #666;
}
#footer p.left {
float: left;
clear: left;
}
#footer p.right {
float: right;
clear: right;
}
.spacer {
clear: both;
}
dd, dt {
font-size: 0.95em;
}
#mainTitle {
font-size: 2.0em;
font-weight: bold;
visibility: hidden;
}
.pageTitle {
font-size: 1.5em;
font-weight: bold;
}
.itemTitle {
border-bottom: 1px solid #a83930;
font-size: 1.5em;
}
.itemContent {
padding-bottom: 1.8em;
}
.box {
border: solid 1px #a83930;
}
.boxFloat {
/* border: solid 1px #a83930; */
float: left;
}
.boxFloatRight {
border: solid 1px #a83930;
float: right;
}
.floatRight {
/* border: solid 1px #a83930; */
float: right;
}

.newsItem
{
padding-top: 1.0em;
border-bottom: 1px solid #a83930;
}
.newsTitle
{
font-size: 110%;
/*
float: left;
*/
}
.newsDate {
font: normal 0.9em/0.9em 'Lucida Grande', Verdana, Geneva, Lucida, Helvetica, Arial, sans-serif;
float: right;
/* clear: right; */
color: #666666;
}
.newsContent {
text-align: left;
}
.rowSelected {
background-color: #FEF268;
}

input.buttonLink
{
text-decoration: underline;
border: 0px;
background-color: Transparent;
}

.grid {
margin-bottom: 10px;
}
.grid TR TD {
padding: 1px 5px 1px 5px;
}

.details, .details TR, .details TD{
border-style: none;
border-width: 0;
padding-left: 20px;
}
.detailsHeader
{
background-color: #FEF268;
border: solid 1px green;
}

asp.net tutorials with framework

It is not essential to use the standard webforms development model when developing with ASP.NET. Noteworthy frameworks designed for the platform include:

Castle Monorail, an open-source MVC framework with an execution model similar to Ruby on Rails. The framework is commonly used with Castle ActiveRecord, an ORM layer built on NHibernate.
Spring.NET, a port of the Spring framework for Java.

[edit] History
Date Version Remarks New features
January 16, 2002 1.0 First version

released together with Visual Studio .NET
Object oriented web application development supporting Inheritance, Polymorphism and other standard OOP features
Developers are no longer forced to use Server.CreateObject(...), so early-binding and type safety are possible.
Based on Windows programming; the developer can make use of DLL class libraries and other features of the web server to build more robust applications that do more than simply rendering HTML ( i.e. exception handling )

April 24, 2003 1.1 released together with Windows Server 2003

released together with Visual Studio .NET 2003
Mobile controls
Automatic input validation

November 7, 2005 2.0 codename Whidbey
released together with Visual Studio 2005 and Visual Web Developer Express
and SQL Server 2005
New data controls (GridView, FormView, DetailsView)
New technique for declarative data access (SqlDataSource, ObjectDataSource, XmlDataSource controls)
Navigation controls
Master pages
Login controls
Themes
Skins
Web parts
Personalization services
Full pre-compilation
New localization technique
Support for 64-bit processors
Provider class model

November 19, 2007 3.5 released together with Visual Studio 2008
New data controls (ListView, DataPager)
Integrated AJAX support
Improved support for nested master pages
Support for LINQ

Sunday, February 24, 2008

asp.net intoduction

ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language.

HID Communication in asp.net with c#

HIDLibrary.dll
namespace:using HIDLbrary;
namespace:using System.Text;
protected void btnsend_click(object sender, EventArgs e)
{
HIDLibrary.HidDevic[] HidDeviceList;
HidDevice HidDevice ;
HidDeviceList=HidDevices.Enumerate(0x01234,0x00001);
if(HidDeviceList.Length>0)
{
HidDevice=HidDeviceList[1];
byte[] Outdata=new byte[HidDevice.Capabilities.OutputReportByteLength-1];
HidDevice.OpenDevice();
OutData[0]=Convert.ToByte(txtsend.Text);
HidReport hr=new HidReport(1);
hr.Data=OutData;
HidDevice.WriteReport(hr);
HidDevice.Write(OutData);
string Text;
hr=HidDevice.ReadReport();
Text=Convert.ToString(hr.Data.GetValue(0));
txtread.Text=Text;
}

File Uplood for Videos in asp.net with C#


<%@Page Language="C#"%>


<br />File Uploading in ASP.Net Using C# - Demo <br />



<%if(!Page.IsPostBack)
{
%>

File uploading in ASP.Net using C# - Demo












Select a file to upload




<%}%>














Please feel to contact the author Sriram for
your valuable suggestions and feedbacks.


in web.config

maxRequestLength=4096 for 4MB uploading

maxRequestLength=8192 for 8MB uploading

maxRequestLength=16384 for 16MB uploading

maxRequestLength=65536 for 64MB uploading

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...