Saturday, December 27, 2008

Data on datagrid from excel sheet

Source Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace excel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=D:\\excel\\excel\\Sample.xls;" + "Extended Properties=Excel 8.0;";

OleDbConnection connection = new OleDbConnection(strConn);

OleDbDataAdapter myCommand = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn);

DataSet myDataSet = new DataSet();
myCommand.Fill(myDataSet);
dataGrid1.DataSource = myDataSet.Tables[0].DefaultView;



}
}
}

OutPut is:

Friday, October 10, 2008

VB Tutorials

Database connection with MSAcess Database and insert,update,delete,select commands in VB

Output is:



Source Code is:

Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset

Private Sub Combo1_Click()
rs.Open "select * from punch where Card_id='" & Combo1.Text & "' ", con, adOpenDynamic, adLockBatchOptimistic
While rs.EOF = False
Text1.Text = rs(0)
Text2.Text = rs(1)

rs.MoveNext
Wend
rs.Close
End Sub

Private Sub Command1_Click()
rs.Open "select * from punch where Card_id='12'", con, adOpenDynamic, adLockBatchOptimistic
While rs.EOF = False
Text1.Text = rs(0)
Text2.Text = rs(1)
rs.MoveNext
Wend
rs.Close
End Sub

Private Sub Command2_Click()
con.Execute "insert into punch values('" & Text1.Text & "','" & Text2.Text & "')"
MsgBox "inserted"
End Sub

Private Sub Command3_Click()
con.Execute "update punch set User_Name='" & Text2.Text & "' where Card_id='" & Text1.Text & "'"
MsgBox "updated"

End Sub

Private Sub Command4_Click()
con.Execute "delete from punch where Card_id='" & Text1.Text & "'"
MsgBox "deleted"

End Sub

Private Sub Form_Load()
con.ConnectionString = "provider=microsoft.jet.oledb.4.0;" & " data source=" & App.Path & "\pu.mdb"
con.Open
rs.Open "select Card_id from punch", con, adOpenDynamic, adLockBatchOptimistic
While rs.EOF = False
Combo1.AddItem rs(0)
rs.MoveNext
Wend
rs.Close

End Sub

Tuesday, July 29, 2008

AddItems

int HiddenValue;

protected void Button1_Click(object sender, EventArgs e)
{
HiddenValue = Convert.ToInt32(HiddenField1.Value.ToString());
ListBox1.Items.Add("Item " + HiddenValue.ToString());
Label4.Text = HiddenValue.ToString();
HiddenValue = HiddenValue + 1;
HiddenField1.Value = HiddenValue.ToString();
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = ListBox1.SelectedItem.Text.ToString();
}

TextBox Control

protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "You have clicked the button";
TextBox4.Text = "This is a multi line textbox. This is a multi line textbox. This is a multi line textbox. This is a multi line textbox. ";

TextBox3.Text = TextBox2.Text;
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
TextBox1.Text = "The Text is changed.";

}

Literal Control

protected void Button1_Click(object sender, EventArgs e)
{
Literal1.Text = "Welcome to ASP.NET 2.0";
}

Label Control

Source Code is:

protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = "Label Text changed";
Label1.BorderStyle = BorderStyle.Dotted;
Label1.BackColor = System.Drawing.Color.Aqua;
}
protected void Button2_Click(object sender, EventArgs e)
{
Label1.Visible =!(Label1.Visible);
}

HiddenField Control

Html Code is:

asp:HiddenField ID="HiddenField1" runat="Server" Value="Welcome to ASP.NET 2.0"
Visible="False"

Source Code is:


protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = HiddenField1.Value;
}

File Upload Control

Source Code:

protected void Button1_Click(object sender, EventArgs e)
{
if( FileUpload1.HasFile)
{

FileUpload1.SaveAs("C:/projects/" + FileUpload1.FileName);
Label2.Text = "File Uploaded";
}
else
Label2.Text = "No uploaded file";

}

Monday, July 28, 2008

Creation of new Column in Gridview at Runtime

Output is:










Html Code is:





Source Code(c#) is:

using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True;Pooling=False");
protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataSource = GetData();
GridView1.DataBind();

}
ArrayList count = new ArrayList();
ArrayList rate = new ArrayList();
ArrayList date = new ArrayList();
int ln,a,b;
public DataSet GetData()
{
scn.Open();
SqlCommand cmd = new SqlCommand("select * from purchase",scn);
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
count.Add(sdr["count"].ToString());
rate.Add(sdr["rate"].ToString());
date.Add(sdr["date"].ToString());
}
sdr.Close();
scn.Close();
ln =Convert.ToInt32(count.Count.ToString());
DataSet ds = new DataSet();
DataTable dt = new DataTable("Purchase");
DataRow dr;
dt.Columns.Add(new DataColumn("Id", typeof(Int32)));
dt.Columns.Add(new DataColumn("Date", typeof(string)));
dt.Columns.Add(new DataColumn("Price", typeof(Int32)));
for (int i = 0; i <= ln-1; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = date[i].ToString();
a =Convert.ToInt32(count[i].ToString());
b = Convert.ToInt32(rate[i].ToString());

dr[2] =a*b;
dt.Rows.Add(dr);
}
ds.Tables.Add(dt);
Session["dt"] = dt;
return ds;
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
DataBinder.Eval(e.Row.DataItem, "Price").ToString();
}


}
}

Friday, July 25, 2008

Databound Schedule controls for Project Management

These are two free controls, ScheduleCalendar and ScheduleGeneral, designed to show scheduled events in the form of a table. They are simple versions of the so-called Gantt chart. They don't have advanced features such as dependencies and milestones, but on the other hand, they use templated databinding, so it's up to you, the developer, what you want to show.

The controls can be used for a broad variety of applications: time tables, resource usage planners, calendars, event schedulers, activities, reservations, sequences, project management, etc... See the demos for some examples.














Monday, July 21, 2008

Sending Mails using AOSMTPLib

Firstly Install ansmptp.exe :

Source Code:

using AOSMTPLib;

AOSMTPLib.MailClass oSmtp = new AOSMTPLib.MailClass();


oSmtp.FromAddr = "sunichand2000@yahoo.co.in";
oSmtp.AddRecipient("Support Team", "sunichand2000@gmail.com", 0);

oSmtp.Subject = "Test";
oSmtp.BodyText = "Hello, this is a test....";

if (oSmtp.SendMail() == 0)
{
Response.Write("Message delivered!");
}
else
{
Response.Write(oSmtp.GetLastErrDescription());
}

Friday, July 18, 2008

Conversion of datetime to 24 hour format

String militaryTimeFormat = "HH:mm";

String input = DateTime.Now.ToString(militaryTimeFormat);

DateTime time = DateTime.ParseExact(input, militaryTimeFormat, null);

string militaryTime = "06/12/2008 20:30";

IFormatProvider culture = new System.Globalization.CultureInfo("en-US", true);
DateTime militaryDate =DateTime.Parse(militaryTime, culture, System.Globalization.DateTimeStyles.NoCurrentDateDefault);


string g=DateTime.Now.ToString("dd/MM/yyyy HH:mm");
string h = DateTime.Now.ToString("HH:mm");

Tuesday, July 15, 2008

Creation of Gantt Chart using Java Script

Output:








function Gantt(gDiv)
{
var _GanttDiv = gDiv;
var _taskList = new Array();
this.AddTaskDetail = function(value)
{
_taskList.push(value);

}
this.Draw = function()
{
var _offSet = 0;
var _dateDiff = 0;
var _currentDate = new Date();
var _maxDate = new Date();
var _minDate = new Date();
var _dTemp = new Date();
var _firstRowStr = "
";
var _thirdRow = "";
var _gStr = "";
var _colSpan = 0;
var counter = 0;

_currentDate.setFullYear(_currentDate.getFullYear(), _currentDate.getMonth(),
_currentDate.getDate());
if(_taskList.length > 0)
{
_maxDate.setFullYear(_taskList[0].getTo().getFullYear(),
_taskList[0].getTo().
getMonth(), _taskList[0].getTo().getDate());
_minDate.setFullYear(_taskList[0].getFrom().getFullYear(),
_taskList[0].getFrom().
getMonth(), _taskList[0].getFrom().getDate());

for(i = 0; i < _taskList.length; i++)
{
if(Date.parse(_taskList[i].getFrom()) < Date.parse(_minDate))
_minDate.setFullYear(_taskList[i].getFrom().getFullYear(),
_taskList[i].getFrom().
getMonth(), _taskList[i].getFrom().getDate());
if(Date.parse(_taskList[i].getTo()) > Date.parse(_maxDate))
_maxDate.setFullYear(_taskList[i].getTo().getFullYear(),
_taskList[i].getTo().
getMonth(), _taskList[i].getTo().getDate());
}

//---- Fix _maxDate value for better displaying-----
// Add at least 5 days

if(_maxDate.getMonth() == 11) //December
{
if(_maxDate.getDay() + 5 > getDaysInMonth(_maxDate.getMonth() + 1,
_maxDate.getFullYear()))
_maxDate.setFullYear(_maxDate.getFullYear() + 1, 1, 5);
//The fifth day of next month will be used
else
_maxDate.setFullYear(_maxDate.getFullYear(), _maxDate.getMonth(),
_maxDate.getDate() + 5); //The fifth day of next month will be used
}
else
{
if(_maxDate.getDay() + 5 > getDaysInMonth(_maxDate.getMonth() + 1,
_maxDate.getFullYear()))
_maxDate.setFullYear(_maxDate.getFullYear(), _maxDate.getMonth() + 1,
5); //The fifth day of next month will be used
else
_maxDate.setFullYear(_maxDate.getFullYear(), _maxDate.getMonth(),
_maxDate.getDate() + 5); //The fifth day of next month will be used
}

//--------------------------------------------------

_gStr = "";
_gStr += "";
_thirdRow = "";
_dTemp.setFullYear(_minDate.getFullYear(), _minDate.getMonth(),
_minDate.getDate());
while(Date.parse(_dTemp) <= Date.parse(_maxDate))
{
if(_dTemp.getDay() % 6 == 0) //Weekend
{
_gStr += "";
if(Date.parse(_dTemp) == Date.parse(_currentDate))
_thirdRow += "";
else
_thirdRow += "";
}
else
{
_gStr += "";
if(Date.parse(_dTemp) == Date.parse(_currentDate))
_thirdRow += "";
else
_thirdRow += "";
}
if(_dTemp.getDate() < getDaysInMonth(_dTemp.getMonth() + 1,
_dTemp.getFullYear()))
{
if(Date.parse(_dTemp) == Date.parse(_maxDate))
{
_firstRowStr += "";
}
_dTemp.setDate(_dTemp.getDate() + 1);
_colSpan++;
}
else
{
_firstRowStr += "";
_colSpan = 0;
if(_dTemp.getMonth() == 11) //December
{
_dTemp.setFullYear(_dTemp.getFullYear() + 1, 0, 1);
}
else
{
_dTemp.setFullYear(_dTemp.getFullYear(), _dTemp.getMonth() + 1, 1);
}
}
}
_thirdRow += "";
_gStr += "" + _thirdRow;
_gStr += "
style='width:200px;'>Task
 
" +
_dTemp.getDate() + "
style='height:" + (_taskList.length * 21) + "'>  style='height:" + (_taskList.length * 21) + "'> 
" + _dTemp.getDate()
+ "
  T" +
(_dTemp.getMonth() + 1) + "/" + _dTemp.getFullYear() + "
T" +
(_dTemp.getMonth() + 1) + "/" + _dTemp.getFullYear() + "
";
_gStr = _firstRowStr + _gStr;
for(i = 0; i < _taskList.length; i++)
{

_offSet = (Date.parse(_taskList[i].getFrom()) - Date.parse(_minDate))
/ (24 * 60 * 60 * 1000);
_dateDiff = (Date.parse(_taskList[i].getTo()) - Date.parse(_taskList
[i].getFrom())) / (24 * 60 * 60 * 1000) + 1;
_gStr += "
style='float:left; width:" + (27 * _dateDiff - 1) + "px;'>" +

getProgressDiv(_taskList[i].getProgress()) + "
style='float:left; padding-left:3'>" + _taskList[i].getResource()
+ "
";
_gStr += "
" + _taskList[i].getTask() + "
"; }

_GanttDiv.innerHTML = _gStr;
}
}
}
function getProgressDiv(progress)
{
return "
"
}
// GET NUMBER OF DAYS IN MONTH
function getDaysInMonth(month, year)
{

var days;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
days = 31;
break;
case 4:
case 6:
case 9:
case 11:
days = 30;
break;
case 2:
if (((year% 4)==0) && ((year% 100)!=0) || ((year% 400)==0))
days = 29;
else
days = 28;
break;
}
return (days);
}










StyleSheet.css:



body {
}

/*----- SICON GANTT CHART STYLE CLASSES --------------------------
* DESCRIPTION : Theses class is required for SIcon Gantt Chart
* NOTE : Should change the color, the text style only
*----------------------------------------------------------------*/
.Gantt
{
font-family:tahoma, arial, verdana;
font-size:11px;
}

.GTaskTitle
{
font-family:tahoma, arial, verdana;
font-size:11px;
font-weight:bold;
}

.GMonth
{
padding-left:5px;
font-family:tahoma, arial, verdana;
font-size:11px;
font-weight:bold;
}

.GToday
{
background-color: #FDFDE0;
}

.GWeekend
{
font-family:tahoma, arial, verdana;
font-size:11px;
background-color:#F5F5F5;
text-align:center;
}

.GDay
{
font-family:tahoma, arial, verdana;
font-size:11px;
text-align:center;
}

.GTask
{
border-top:1px solid #CACACA;
border-bottom:1px solid #CACACA;
height:14px;
background-color:yellow;
}

.GProgress
{
background-color:black;
height:2px;
overflow: hidden;
margin-top:5px;
}

Dynamic Creation of Controls

Output:












Firstly add a panel control ,a textbox and a button to design page .when we enter a number in textbox at run time ,the same number controls are created at runtime.


Source Code:

protected void btninsert_Click(object sender, EventArgs e)
{
int count =Convert.ToInt32(TextBox1.Text);
Panel1.Controls.Clear();
Table tb = new Table();
tb.GridLines = GridLines.Both;
for (int i = 0; i < count; i++)
{

TableCell c1 = new TableCell();
TableRow rw = new TableRow();
TextBox tx = new TextBox();
c1.Controls.Add(tx);
rw.Cells.Add(c1);
tb.Rows.Add(rw);
}
Panel1.Controls.Add(tb);
}

Wednesday, June 4, 2008

Paging Advantage of Datalist Control in asp.net with c#

HTML Coding :


















Server Side Coding: c#

SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=iptv_database;Integrated Security=True");
int Start;
protected void Page_Load(object sender, EventArgs e)
{

if (!Page.IsPostBack)
{
ViewState["Start"] = 0;
BindData();
}
}
void BindData()
{

SqlDataAdapter da = new SqlDataAdapter("select * from addprogram", scn);
DataSet ds= new DataSet();
Start = (int)ViewState["Start"];
ViewState["Size"] = 2;
da.Fill(ds,Start,(int)ViewState["Size"], "addprogram");
DataList1.DataSource = ds;
DataList1.DataBind();


}
protected void lnkPrevious_Click(object sender, EventArgs e)
{
Start = (int)ViewState["Start"] - (int)ViewState["Size"];
ViewState["Start"] = Start;
if (Start <= 0)
{
ViewState["Start"] = 0;
}
BindData();
}
protected void lnkNext_Click(object sender, EventArgs e)
{
int count = DataList1.Items.Count;
Start = (int)ViewState["Start"] + (int)ViewState["Size"];
ViewState["Start"] = Start;
if (count <(int)ViewState["Size"])
{
ViewState["Start"] = (int)ViewState["Start"] + (int)ViewState["Size"];
Start = (int)ViewState["Start"];

}

Saturday, May 31, 2008

Creating Controls at Runtime

TextBox txt1 = new TextBox();
TextBox txt2 = new TextBox();
txt1.Text = "This is the textbox inside the placeholder";
txt2.Text = "This is the textbox inside the panel";
txt1.Style["width"] = "250px";
txt2.Style["width"] = "250px";
PlaceHolder1.Controls.Add(txt1);
Panel1.Controls.Add(txt2);

Friday, May 9, 2008

VideoStreaming in asp.net with c#

using System.IO;
using System.IO.Compression;
FileStream sourceFile;
GZipStream compStream;
FileStream destFile;
protected void btnCompress_Click1(object sender, EventArgs e)
{
if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();

}
sourceFile = File.OpenRead(txtSource.Text);
destFile = File.Create(txtDestination.Text);
compStream = new GZipStream(destFile, CompressionMode.Compress);
int theByte = sourceFile.ReadByte();
while (theByte != -1)
{
compStream.WriteByte((byte)theByte);
theByte = sourceFile.ReadByte();
}
sourceFile.Close();
destFile.Close();
}


protected void btnDecompress_Click(object sender, EventArgs e)
{

if (File1.PostedFile != null)
{
txtSource.Text = File1.PostedFile.FileName.ToString();

}

string srcFile = txtSource.Text;
string dstFile = txtDestination.Text;

FileStream fsIn = null; // will open and read the srcFile
FileStream fsOut = null; // will be used by the GZipStream for output to the dstFile
GZipStream gzip = null;
const int bufferSize = 4096;
byte[] buffer = new byte[bufferSize];
int count = 0;


{

fsIn = new FileStream(srcFile, FileMode.Open, FileAccess.Read, FileShare.Read);
fsOut = new FileStream(dstFile, FileMode.Create, FileAccess.Write, FileShare.None);
gzip = new GZipStream(fsIn, CompressionMode.Decompress, true);
while (true)
{
count = gzip.Read(buffer, 0, bufferSize);
if (count != 0)
{
fsOut.Write(buffer, 0, count);
}
if (count != bufferSize)
{
// have reached the end
break;
}
}
}

}
}

Monday, April 28, 2008

RSS Feeds in asp.net with c#

A simple Program to view xml in Datagrid

using System.Xml;


XmlTextReader reader = new XmlTextReader("http://msdn.microsoft.com/rss.xml");

// creates a new instance of DataSet

DataSet ds = new DataSet();

// Reads the xml into the dataset

ds.ReadXml(reader);

// Assigns the data table to the datagrid

myDataGrid.DataSource = ds.Tables[2];

// Binds the datagrid

myDataGrid.DataBind();

Using RSS Feeds with Asp.net

RSS stands for (Really Simple Syndication). Basically RSS feeds are xml files which are provided by many websites so you can view their contents on your own websites rather than browsing their site. Suppose you are a movie lover and you want to get the list of top 5 movies from 10 websites. One way will be to visit all 10 websites and see the top 5 list. This method though is used in general by lot of people but its quite tiring method. It will take you 10-15 minutes to browse all the websites and see the top 5 list of movies. One easy way will be if those movie websites provides RSS feeds to be used by the users. If they provide RSS feeds you can embed them in your page and now you don't have to browse all the websites since the information is available on a single page. Hence, this saves you a time and a lot of browsing.

Most of the Blogs websites provide RSS feeds so you can embed your or someone's else latest entries of blog on your website. In this article we will see how we can embed RSS feeds to our webform using Asp.net.

Friday, April 18, 2008

Serial Communication with MSCommLib for GSM

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

namespace Serial_Demo
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox rtfTerminal;
private System.Windows.Forms.Button btn_dial;

private AxMSCommLib.AxMSComm com;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.TextBox txt_phoneno;
private System.Windows.Forms.Button btn_disconnect;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.TextBox txt_sendmessage;
private System.Windows.Forms.Button btn_sendmessage;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label Message;
private System.Windows.Forms.Panel panel1;

public Form1()
{
InitializeComponent();
// Initialize the COM Port control
InitComPort();
}


private void InitComPort()
{
// Set the com port to be 1
com.CommPort = 1;

// This port is already open, then close.
if (com.PortOpen)
com.PortOpen=false;

// Trigger the OnComm event whenever data is received
com.RThreshold = 1;

// Set the port to 9600 baud, no parity bit, 8 data bits, 1 stop bit (all standard)
com.Settings = "9600,n,8,1";

// Force the DTR line high, used sometimes to hang up modems
//com.DTREnable = true;

com.RTSEnable=true;

// No handshaking is used
com.Handshaking = MSCommLib.HandshakeConstants.comNone;

// Use this line instead for byte array input, best for most communications
com.InputMode = MSCommLib.InputModeConstants.comInputModeText;

// Read the entire waiting data when com.Input is used
com.InputLen = 0;

// Don't discard nulls, 0x00 is a useful byte
com.NullDiscard = false;

// Attach the event handler
com.OnComm += new System.EventHandler(this.OnComm);

com.PortOpen = true;
}

private void OnComm(object sender, EventArgs e) // MSCommLib OnComm Event Handler
{

// Wait for Some mili-seconds then process
// The response.

Thread.Sleep(200);

if (com.InBufferCount > 0)
{
try
{
// If you want to receive data in Binary mode
// Remove below 2 comment lines
// And comment lines for Process response in
// Text mode.

//byte[] b1=(byte[])com.Input;
//ProcessResponseBinary(b1);

// Process response in Text mode.
string response=(string)com.Input;
ProcessResponseText(response);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
}

// If you receive binary data as response.
private void ProcessResponseBinary(byte[] response)
{
for(int i=0; i< response.Length; i++)
{
rtfTerminal.AppendText(response[i].ToString() + " ");
}
rtfTerminal.AppendText("\n");

}

// If you receive Text data as response
private void ProcessResponseText(string input)
{
// Send incoming data to a Rich Text Box

if( input.Trim().Equals("RING"))
{
Message.Text="Ring...";
}
else
if( input.Trim().Equals("CONNECT 9600"))
{
MessageBox.Show(input.Trim(), this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show(input.Trim(), this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
Message.Text=input.Trim();
}

// Append output response to RichText Box
rtfTerminal.AppendText(input + "\n");
}

///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
if( disposing )
{

}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.rtfTerminal = new System.Windows.Forms.RichTextBox();
this.btn_dial = new System.Windows.Forms.Button();
this.com = new AxMSCommLib.AxMSComm();
this.label6 = new System.Windows.Forms.Label();
this.txt_phoneno = new System.Windows.Forms.TextBox();
this.btn_disconnect = new System.Windows.Forms.Button();
this.Message = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.txt_sendmessage = new System.Windows.Forms.TextBox();
this.btn_sendmessage = new System.Windows.Forms.Button();
this.label8 = new System.Windows.Forms.Label();
this.panel1 = new System.Windows.Forms.Panel();
((System.ComponentModel.ISupportInitialize)(this.com)).BeginInit();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// rtfTerminal
//
this.rtfTerminal.Location = new System.Drawing.Point(0, 136);
this.rtfTerminal.Name = "rtfTerminal";
this.rtfTerminal.Size = new System.Drawing.Size(280, 112);
this.rtfTerminal.TabIndex = 1;
this.rtfTerminal.Text = "";
//
// btn_dial
//
this.btn_dial.Location = new System.Drawing.Point(8, 72);
this.btn_dial.Name = "btn_dial";
this.btn_dial.TabIndex = 8;
this.btn_dial.Text = "Dial";
this.btn_dial.Click += new System.EventHandler(this.btn_dial_Click);
//
// com
//
this.com.Enabled = true;
this.com.Location = new System.Drawing.Point(160, 104);
this.com.Name = "com";
this.com.Size = new System.Drawing.Size(38, 38);
this.com.TabIndex = 14;
//
// label6
//
this.label6.BackColor = System.Drawing.Color.Transparent;
this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label6.ForeColor = System.Drawing.SystemColors.Highlight;
this.label6.Location = new System.Drawing.Point(8, 8);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(64, 23);
this.label6.TabIndex = 15;
this.label6.Text = "GSM No:";
//
// txt_phoneno
//
this.txt_phoneno.Location = new System.Drawing.Point(88, 8);
this.txt_phoneno.Name = "txt_phoneno";
this.txt_phoneno.Size = new System.Drawing.Size(168, 20);
this.txt_phoneno.TabIndex = 16;
this.txt_phoneno.Text = "";
//
// btn_disconnect
//
this.btn_disconnect.Location = new System.Drawing.Point(184, 72);
this.btn_disconnect.Name = "btn_disconnect";
this.btn_disconnect.TabIndex = 17;
this.btn_disconnect.Text = "Disconnect";
this.btn_disconnect.Click += new System.EventHandler(this.btn_disconnect_Click);
//
// Message
//
this.Message.BackColor = System.Drawing.Color.Transparent;
this.Message.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.Message.ForeColor = System.Drawing.Color.MidnightBlue;
this.Message.Location = new System.Drawing.Point(0, 248);
this.Message.Name = "Message";
this.Message.Size = new System.Drawing.Size(280, 23);
this.Message.TabIndex = 18;
//
// label7
//
this.label7.BackColor = System.Drawing.Color.Transparent;
this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label7.ForeColor = System.Drawing.SystemColors.Highlight;
this.label7.Location = new System.Drawing.Point(8, 40);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(72, 32);
this.label7.TabIndex = 19;
this.label7.Text = "Message:";
//
// txt_sendmessage
//
this.txt_sendmessage.Location = new System.Drawing.Point(88, 40);
this.txt_sendmessage.Name = "txt_sendmessage";
this.txt_sendmessage.Size = new System.Drawing.Size(168, 20);
this.txt_sendmessage.TabIndex = 20;
this.txt_sendmessage.Text = "";
//
// btn_sendmessage
//
this.btn_sendmessage.Location = new System.Drawing.Point(96, 72);
this.btn_sendmessage.Name = "btn_sendmessage";
this.btn_sendmessage.TabIndex = 21;
this.btn_sendmessage.Text = "Send";
this.btn_sendmessage.Click += new System.EventHandler(this.btn_sendmessage_Click);
//
// label8
//
this.label8.BackColor = System.Drawing.Color.Transparent;
this.label8.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label8.ForeColor = System.Drawing.SystemColors.Highlight;
this.label8.Location = new System.Drawing.Point(0, 112);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(160, 24);
this.label8.TabIndex = 22;
this.label8.Text = "Received messages:";
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.btn_dial);
this.panel1.Controls.Add(this.btn_disconnect);
this.panel1.Controls.Add(this.txt_phoneno);
this.panel1.Controls.Add(this.label6);
this.panel1.Controls.Add(this.label7);
this.panel1.Controls.Add(this.txt_sendmessage);
this.panel1.Controls.Add(this.btn_sendmessage);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(280, 104);
this.panel1.TabIndex = 23;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(280, 269);
this.Controls.Add(this.panel1);
this.Controls.Add(this.label8);
this.Controls.Add(this.rtfTerminal);
this.Controls.Add(this.com);
this.Controls.Add(this.Message);
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Serial Demo";
((System.ComponentModel.ISupportInitialize)(this.com)).EndInit();
this.panel1.ResumeLayout(false);
this.ResumeLayout(false);

}
#endregion

///
/// The main entry point for the application.
///

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void btn_dial_Click(object sender, System.EventArgs e)
{

if( txt_phoneno.Text.Trim().Equals(""))
{
MessageBox.Show("Please Specify Phone Number", this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
txt_phoneno.Focus();
return;
}

if(! com.PortOpen )
com.PortOpen=true;

// GSM Command Dial a Modem
// ATD\n

string gsm_command="ATD";
string phone_number=txt_phoneno.Text.Trim();
string command1=gsm_command + phone_number + "\n";
byte[] command_to_dial=System.Text.ASCIIEncoding.Default.GetBytes(command1);
com.Output=command_to_dial;

Message.Text="Dialing...";

}

private void btn_disconnect_Click(object sender, System.EventArgs e)
{
// If com port is open then close it
// to disconnect connection

if( com.PortOpen )
{
com.PortOpen=false;
MessageBox.Show("Disconnected...", this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
Message.Text="";
rtfTerminal.Text="";
}
}

private void btn_sendmessage_Click(object sender, System.EventArgs e)
{

string msg="";

if( txt_sendmessage.Text.Trim().Equals(""))
{
MessageBox.Show("Please Specify Command", this.Text,
MessageBoxButtons.OK,MessageBoxIcon.Information);
txt_sendmessage.Focus();
return;
}

if(! com.PortOpen )
com.PortOpen=true;

// To send text messages

// If you are using GSM Modem and you want to send
// Command then use GetByes of your message
// To send Byte data from com port

msg=txt_sendmessage.Text.Trim() + "\n";
com.Output = System.Text.ASCIIEncoding.Default.GetBytes(msg);

// Or Else If systems are connected with Serial
// Cable, Output simple text directly
// com.Output= txt_sendmessage.Text;

Message.Text="Message Sent....";
}

}
}

A solution for inserting ,updating ,deleting database with class and stored procedure

using System;
using System.Data;
using System.Configuration;
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 class Class1
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=Routingmail;Integrated Security=True");

public Class1()
{


}
public void prc(string prcname, string[] prcnames, string[] prcvalues)
{
scn.Open();
SqlCommand cmd = new SqlCommand(prcname, scn);
cmd.CommandType = CommandType.StoredProcedure;
for(int i = 0; i <= prcnames.Length - 1; i++)
{
cmd.Parameters.Add(prcnames[i], prcvalues[i]);
}
cmd.ExecuteNonQuery();
scn.Close();
}
}

Simple Code for Change Password

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 ChangePassword : System.Web.UI.Page
{
SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=Routingmail;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
scn.Open();
SqlCommand cmd = new SqlCommand("select pwd from Registration where userid='" + Session["userid"].ToString() + "'", scn);
string str = Convert.ToString(cmd.ExecuteScalar());
txtname.Text = str;
scn.Close();
}


}
protected void btnsubmit_Click(object sender, EventArgs e)
{
if (scn.State == ConnectionState.Closed)
{
scn.Open();
}
SqlCommand cmd = new SqlCommand("update Registration set pwd='" + txtpassword.Text + "' where userid='" + Session["userid"].ToString() + "'", scn);
cmd.ExecuteNonQuery();
scn.Close();

}
}

Simple Code for Forgot Password

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 Forgotpwd : System.Web.UI.Page
{
SqlConnection scn = new SqlConnection("Data source=.;Initial Catalog=Routingmail;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
TextBox1.Text = Session["userid"].ToString();
if (scn.State == ConnectionState.Closed)
{
scn.Open();
}

SqlCommand cmd = new SqlCommand("Select secquestion from registration where userid='"+TextBox1.Text+"'",scn);
string str = Convert.ToString(cmd.ExecuteScalar());
txtsecuriy.Text = str;
}

}
protected void Button1_Click(object sender, EventArgs e)
{
scn.Open();
SqlCommand cmd = new SqlCommand("select pwd from registration where answer='" + txtanswer.Text + "'", scn);
String str = Convert.ToString(cmd.ExecuteScalar());
Label1.Text = "your password is " + str;
Label1.Visible = true;
scn.Close();
}

}

Simple Code for login

protected void btnsubmit_Click(object sender, EventArgs e)
{
scn.Open();
SqlCommand cmd = new SqlCommand("select pwd from Registration where userid='" + txtname.Text + "'", scn);
string str = Convert.ToString(cmd.ExecuteScalar());
if (str == "")
{
Label1.Visible = true;
Label1.Text = "Login failed";
txtname.Text = "";
txtpassword.Text = "";
}

else
{
if (txtpassword.Text == str)
{
Session["userid"] = txtname.Text;
Session["password"] = txtpassword.Text;
Response.Redirect("mailrouting.aspx");
Label1.Visible = false;
txtname.Text = "";
txtpassword.Text = "";

Response.Redirect("mailrouting.aspx");


}
else
{
Label1.Visible = true;
Label1.Text = "Incorrect Password";
txtname.Text = "";
txtpassword.Text = "";

}
}

scn.Close();
}

A smple Code for Mail Routing

using System;
using System.Data;
using aspNetEmail;
using aspNetPOP3;
using aspNetMime;
using AdvancedIntellect;
using System.Data.SqlClient;
using System.Data.SqlTypes;
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.Text;
using System.Net.Sockets;

public partial class mailrouting : System.Web.UI.Page
{
POP3 pop;
// POP3ConnectionException ex = new POP3ConnectionException();

string primary, primarypass, mail1, mailpass1, mail2, mailpass2, id, pwd;
int mcount = 0;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Routingmail;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
con.Open();
String userid = Session["userid"].ToString();
SqlCommand cmd = new SqlCommand("select * from phoneemail where userid='" + userid + "'", con);
SqlDataReader rd = cmd.ExecuteReader();
if (rd.Read())
{
primary = rd[1].ToString();
primarypass = rd[2].ToString();
mail1 = rd[4].ToString();
mailpass1 = rd[5].ToString();
mail2 = rd[6].ToString();
mailpass2 = rd[7].ToString();
}
rd.Close();
con.Close();
for (int i = 1; i < 4; i++)
{
switch (i)
{
case 1:
id = mail1;
pwd = mailpass1;
break;
case 2:
id = mail2;
pwd = mailpass2;
break;
default:
break;
}
string ab = id.Substring(id.IndexOf('@') + 1);
if (ab.Equals("gmail.com"))
{
pop = new POP3("pop.gmail.com", id, pwd);
AdvancedIntellect.Ssl.SslSocket ss1 = new AdvancedIntellect.Ssl.SslSocket();
pop.LoadSslSocket(ss1);
pop.Port = 995;
}
else
{
pop = new POP3("mail.ideonics.co.in", id, pwd);

}
pop.LogInMemory = true;
pop.Connect();
//pop.Connect(id, pwd, "mail.ideonics.co.in");
pop.PopulateInboxStats();
int count = pop.MessageCount();
if (count != 0)
{
for (int j = 0; j < count; j++)
{
try
{
if (pop.GetMessage(j).Subject != null)
{
if (!pop.GetMessage(j).Subject.Value.Equals("Reply"))
{
MimeMessage m = pop.GetMessage(j);
forward(m);
Reply(m.Subject.Value);
pop.Delete(j);
Label2.Text = "Mails are sending............" + mcount;
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
break;
}
}
Label2.Text = "Total Mails sent................." + mcount;

pop.Disconnect();
con.Close();
}

}
}

public void forward(MimeMessage m)
{
mcount++;
StringBuilder inlineEmail = new StringBuilder();
inlineEmail.Append("---------- original Message---------\r\n");
if (m.From != null)
{
inlineEmail.Append("From:" + m.From.ToString() + "\r\n");
}
if ((m.To != null) && (m.To.Count > 0))
{
inlineEmail.Append("to:" + m.To.ToString() + "\r\n");
}
if (m.Date != null)
{
inlineEmail.Append("Date:" + m.Date + "\r\n");
}
if (m.Subject != null)
{

inlineEmail.Append("SUBJECT: " + aspNetMime.Header.DeocodeHeaderValue(m.Subject.Value) + "\r\n");
}
if (m.TextMimePart != null)
{
inlineEmail.Append("\r\n");
inlineEmail.Append(m.TextMimePart.DecodedText());
}
MimePartCollection attachments = m.Attachments;
EmailMessage email = new EmailMessage();
email.Server = "mail.ideonics.co.in";
email.FromAddress = id;
email.To = primary;
email.Subject = "Mail from" + id;
email.Body = "see email below\r\n\r\n";
email.Body += inlineEmail.ToString();
if ((attachments != null) && (attachments.Count > 0))
{
for (int i = 0; i < attachments.Count; i++)
{
//add each attachment to the email message

Attachment a = new Attachment(attachments[i].Data(), attachments[i].AttachmentName());
email.AddAttachment(a);
}
}
email.Send();
}
public void Reply(string sub)
{
EmailMessage email = new EmailMessage();
email.Server = "mail.ideonics.co.in";
email.FromAddress = primary;
email.To = id;
email.Subject = "Reply";
email.Body = sub + "is forwardedto your primary id" + primary;
email.Send();
}
}

A simple code for Check Availability

protected void btncheckavail_Click(object sender, EventArgs e)
{
scn.Open();
SqlCommand cmd = new SqlCommand("select userid from Registration where userid='" + txtuserid.Text + "'", scn);
string str = Convert.ToString(cmd.ExecuteScalar());
if (str =="")
{
lbl.Text = UserID is Available
}
else
{
lbl.Text = "This UserID is Already Exists";
lbl.Visible = true;

}
}

Serial Communication with GSM 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;
using System.IO.Ports;
using System.IO;
using System.Threading;
using System.Transactions;
using System.Runtime.InteropServices.ComTypes;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
protected void Page_Load(object sender, EventArgs e)
{

port.RtsEnable = true;
port.DtrEnable = true;
port.Open();

port.Write("AT+CMGF=1" + "\r\n");
Thread.Sleep(2000);
string I = port.ReadExisting().ToString();
Thread.Sleep(2000);
port.Write("AT+CNMI=1,3,2,1" + "\r\n");
Thread.Sleep(2000);
string L = port.ReadExisting().ToString();
Thread.Sleep(2000);
port.Write("AT+CMGR=1" + "\r\n");
Thread.Sleep(2000);
string msg = port.ReadExisting().ToString();

Thread.Sleep(2000);
port.Write("AT+CMGS="+"+919961365059"+""+"\r\n" + "hai how are u" + "\r\n");

Thread.Sleep(2000);
string res = port.ReadExisting().ToString();
Thread.Sleep(2000);


int num = Convert.ToInt32("26");

string st = num.ToString("X");
port.Write(st+ "\r\n");
Thread.Sleep(2000);
string message = port.ReadExisting().ToString();


string u = b.Substring(0, message.IndexOf("\r\n"));
port.Close();
}
}

C Sharp (programming language)

C# is an object-oriented programming language developed by Microsoft as part of the .NET initiative and later approved as a standard by ECMA (ECMA-334) and ISO (ISO/IEC 23270). Anders Hejlsberg leads development of the C# language, which has a procedural, object-oriented syntax based on C++ and includes influences from aspects of several other programming languages (most notably Delphi and Java) with a particular emphasis on simplification.

Friday, March 14, 2008

Some HTML Tutorials

Flash Embedded in HTML

After creating a Flash movie you choose File > Save As from the top menu to save your movie. Save the file as "Somefilename.fla".

To embed the Flash movie you just made into an HTML page, you should go back to your Flash program and do the following steps:

Step 1
Choose File > Open. Open a Flash movie you have created.

Step 2
Choose File > Export Movie.

Step 3
Name the file "somefilename.swf". Choose the location where the file is to be stored (in your Web folder). Click OK.

Step 4
Open the HTML page where you want to insert your Flash movie. Insert this code:



Video and Image loading like Google Video in asp.net with c#

For Video loading firstly create database for storing the path of video and apply the html code shown below:





In code Page:


SqlConnection scn = new SqlConnection("Data Source=.;Initial Catalog=test;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
scn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from video", scn);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
scn.Close();
}
Output:

Sunday, March 9, 2008

management studio creation in windows application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SqlConnection con = new SqlConnection(@"Data Source=.\sqlexpress;Initial Catalog=Registration;Integrated Security=True");
SqlCommand cmd;
SqlDataReader dr;
DataTable dt = new DataTable();
private void btnexecute_Click(object sender, EventArgs e)
{



con.Open();
cmd = new SqlCommand(richTextBox1.Text, con);
dr = cmd.ExecuteReader();
dt.Load(dr);
dataGrid1.DataSource = dt;
cmd = new SqlCommand("sp_helpdb", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
treeView1.Nodes.Add(dr["name"].ToString());
}
dr.Close();
cmd = new SqlCommand("sp_helpdb", con);
dr = cmd.ExecuteReader();
while (dr.Read())
{
cboDb.Items.Add(dr["name"].ToString());
}
dr.Close();

}

private void newToolStripMenuItem_Click(object sender, EventArgs e)
{

}

private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
openFileDialog1.Filter="Text File(*.txt)|*.txt";
string filename;
if(openFileDialog1.ShowDialog()==DialogResult.OK);
{
filename=openFileDialog1.FileName;
richTextBox1.LoadFile(openFileDialog1.FileName);

}

}

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
saveFileDialog1.Filter = "Text File(*.txt)|*.txt";
saveFileDialog1.DefaultExt = "*.txt";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
richTextBox1.SaveFile(saveFileDialog1.FileName);
richTextBox1.Clear();
}
}

private void richTextBox1_TextChanged(object sender, EventArgs e)
{

}

private void cboDb_SelectedIndexChanged(object sender, EventArgs e)
{
cmd = new SqlCommand("use"+cboDb.Text,con);
dr = cmd.ExecuteReader();
dr.Close();

}
}
}

Creating Management Studio using asp.net

add this value and key in web.config



some sql statements:
sp_helpdb
SELECT * FROM sysobjects and sp_help



Html Coding for this:











using System.Data.SqlClient;
public partial class Default2 : System.Web.UI.Page
{

SqlCommand cmd;
SqlDataAdapter da;
DataSet ds=new DataSet();
SqlConnection cnn;
SqlDataReader dr;
String strDB;
protected void Page_Load(object sender, EventArgs e)
{
cnn = new SqlConnection(ConfigurationManager.AppSettings.Get("Cnn"));
cnn.Open();
da = new SqlDataAdapter("sp_helpdb", cnn);
da.Fill(ds, "Cat");
if (!IsPostBack)
{
ddlDb.DataSource = ds.Tables["Cat"];
ddlDb.DataTextField = "name";
DataBind();
}

}
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{

}

protected void ddlDb_SelectedIndexChanged(object sender, EventArgs e)
{
strDB = ddlDb.SelectedItem.ToString();
cnn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog='"+strDB+"';Integrated Security=True");
da = new SqlDataAdapter("SELECT * FROM sysobjects WHERE xtype = 'u'", cnn);
da.Fill(ds, "student");
ddlTable.DataSource = ds.Tables["student"];
ddlTable.DataTextField = "name";
DataBind();


}



protected void ddlTable_SelectedIndexChanged(object sender, EventArgs e)
{

strDB = ddlDb.SelectedItem.ToString();
cnn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog='" + strDB + "';Integrated Security=True");
cnn.Open();
cmd = new SqlCommand("sp_help " + ddlTable.SelectedItem.ToString(), cnn);
dr = cmd.ExecuteReader();
dr.NextResult();
while (dr.Read())
lstFields.Items.Add(dr["column_name"].ToString());

}
protected void btnExecute_Click(object sender, EventArgs e)
{
strDB = ddlDb.SelectedItem.ToString();
cnn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog='" + strDB + "';Integrated Security=True");
cnn.Open();
{
SqlCommand smd = new SqlCommand(TextBox1.Text, cnn);
dr = smd.ExecuteReader();
{
DataTable dt = new DataTable();
dt.Load(dr);
DataGrid1.DataSource = dt;
DataGrid1.DataBind();
}
}


}
}

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;
}

Using Authorization with Swagger in ASP.NET Core

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