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:
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"];
}
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);
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;
}
}
}
}
}
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 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.
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....";
}
}
}
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
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();
}
}
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();
}
}
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();
}
}
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();
}
{
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();
}
}
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;
}
}
{
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();
}
}
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:
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:
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();
}
}
}
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();
}
}
}
}
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();
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.
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.
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:
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)
{
}
}
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();
}
}
}
}
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();
}
}
}
}
.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
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");
}
}
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
Hello World Program in asp.net
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
Untitled Page
Increasing Developer Productivity by Using Login Control
Subscribe to:
Posts (Atom)