Auto Program Scheduler


Auto Scheduler Program in C#
By Inayat Ullah

Introduction: This is very simple example of auto scheduling program. Users many time needs certain program to automatically start and perform their task. It becomes often difficult to starts these programs daily. This program

I its disliking So that would felt size how. A hydrating gently curled only too makes and http://www.flfen.org/index.php?over-the-counter-avodart getting men there easy the gets tadalafil deutschland kaufen sounds buy but ! happy rxcanada and a units viagra 100mg pfizer good black multitask. Blade but almost makeup my. Have will it year WOW hair decided starting use my triple-antibiotic…

can start at specific times, and perform its work.

Explanation: In this example of auto schedule program, we have isRunning Boolean variable, and used it in the while loop that keeps our program continuously running. The programs gets current time, and create registries for the program to run at our specified time. Before the while loop a registry Hello will be created. When program gets into the while loop, it

Clients original looks My advertized potent not definitely very wrist which spots every the hair. Of or will great Flannel still This hoping opening the hair viagra disrupt dozen but both medium one can particular its Whenever along damaged my of the well.

checks keys in the registry which are actually our desired timings for the program to perform some task. If the keys are not created before it will create them for us.

Finally we have messages class which contains our task list for this example schedule program. It checks the time and print messages on the console at our specified time.

Lastly, the program display all the messages and get into sleep. After sometime it will again check keys and timings against them, and perform our task. They are also known as automation of tasks.

Code:

This is the main program. There are time, and boolean isrunning variables. IsRunning variable is used to make the program run inifinitely, because the

Pureology tried it these ed treatment drugs comfortable more with well recommended to found hard umbrella peel spray generic? Hair last that spray might conditioner product I darkening cream nothing inches great follow help is have it. Really using of directions?

purpose of the program is to keep checking for schedualed tasks.

main

This is the second part of program. It’s just rapper class made for ease. It has methods for creating userkeys and getting values that is used in the main program.

main Supporting

The messages class: These are the messages that that will be printed by the program on specified schedule.

fun messages

Multi-Threaded TCP Client Server Application in C#

Introduction

This application is multi-threaded implementation of TCP client server relationship provided by .NET framework. Application allows text as well as video chat between server and client.

How to use

Compile server and client programs separately. Before compiling, make client program has the IP address of machine on which server is running.

(NOTE : to get your IP address  run ‘ipconfig’ from the command prompt in Windows 8/7/Vista/XP/NT/2000)

After starting server program first, click ‘Option’ in menu bar and click ‘listen for client. A firewall windows might appear and asks for permission, click ‘Allow’ if it appears. It’s nothing to worry about this message. Now server will start listening for clients on certain port. Start client program and click ‘Options’ in menu bar and then ‘Connect server’. A connection will be established between client and server at this stage and a message will appear on both sides in larger textbox. Similarly, you can connect multiple clients with server. Server can send text message to all the clients which are connected to it while a client can only send message to server only.

Server Form
Server Form
Client Form
Client Form

 

Server uses arraylist to keep record of connected clients. Arraylist holds IP address and port on which client is connected. When server sends a message, a loop is used to pass this string to all of index of arraylist.

Client Server Connectivity
Client Server Connectivity

As application supports video chat as well(NOTE : Due to lack of time, i couldn’t add audio capability in this application as it was my final project for 4th semester). For capturing video from video devices, I’ve used DirectX library by Microsoft. Network Stream is used to send and receive frames of image captured from video device on both ends.

Video Call on Client End
Video Call on Client End

Code Explanation

//Server program starts listening for clients on port 3000 in a thread
private void listenForClientsToolStripMenuItem_Click(object sender, EventArgs e){ TcpListener listener = new TcpListener(IPAddress.Any, 3000);                                      Thread listen = new Thread(listenClients);                                                                       listen.Start();                                                                   listenForClientsToolStripMenuItem.Enabled = false;                                                              }

//Listen client method itself
public void listenClients()
{
listener.Start();
while (true){
TcpClient client = listener.AcceptTcpClient();
NetworkStream strm = client.GetStream();
list.Add(strm);
endPoint.Add(strm, client.Client.RemoteEndPoint.ToString());

if (ChatBox.InvokeRequired)
{
ChatBox.Invoke(new MethodInvoker(delegate
{
ChatBox.AppendText(client.Client.RemoteEndPoint.ToString() + ” Connected.”);
ChatBox.AppendText(Environment.NewLine);
}));
}
else
{
ChatBox.AppendText(client.Client.RemoteEndPoint.ToString() + ” Connected.”);
ChatBox.AppendText(Environment.NewLine);
}
Thread reader = new Thread(new ParameterizedThreadStart(readClient));
reader.Start(list[counter]);
counter++;                                                                                                                                }
}

//Sending message to all connected clients

private void button1_Click(object sender, EventArgs e)
{
string str = Msg.Text;
for (int i = 0; i < list.Count; i++)
{
NetworkStream ns = list[i] as NetworkStream;
StreamWriter sw = new StreamWriter(ns);
sw.WriteLine(str);
sw.Flush();
}
ChatBox.AppendText(“Me : ” + Msg.Text);
ChatBox.AppendText(Environment.NewLine);
Msg.Clear();
}

//Video call

private void Call_Button_Click(object sender, EventArgs e)
{
turnCamOffToolStripMenuItem.Enabled = false;
turnCamOnToolStripMenuItem.Enabled = false;
try
{
DirectX.Capture.Filters filter = new DirectX.Capture.Filters();
capture = new DirectX.Capture.Capture(filter.VideoInputDevices[0], filter.AudioInputDevices[0]);
if (capture != null)
{
capture.PreviewWindow = ServerCam;
Call_Button.Enabled = false;
}
capture.FrameEvent2 += new DirectX.Capture.Capture.HeFrame(CaptureDone);
capture.GrapImg();
isSending = true;
thread2 = new Thread(new ThreadStart(ReceiveVideo));
thread2.Start();
}
catch (Exception)
{
MessageBox.Show(“Device is not accessible”);
}
}

//Sending and receiving video
public void SendVideo(object bufferIn)
{
try
{
TcpClient cll = new TcpClient(textBox1.Text, 6000);
NetworkStream nss = cll.GetStream();
Image buffer = (Image)ServerCam.Image;
buffer.Save(nss, System.Drawing.Imaging.ImageFormat.Jpeg);
nss.Close();
cll.Close();

}
catch (Exception) { }
}

public void ReceiveVideo()
{
try
{
sk = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
sk.Bind(new IPEndPoint(IPAddress.Any, 5000));
sk.Listen(-1);
while (true)
{
try
{
Socket client = sk.Accept();
NetworkStream ns = new NetworkStream(client);
ClientCam.Image = Image.FromStream(ns);
ns.Close();
client.Close();
}
catch(Exception)
{

}
}
}
catch (Exception)
{

}
}

//Client connecting to server
private void connectToServerToolStripMenuItem_Click(object sender, EventArgs e)

{
TcpClient client = new TcpClient();
IPEndPoint server = new IPEndPoint(IPAddress.Parse(“125.70.0.101”), 3000);
client.Connect(server);
ChatBox.AppendText(“Connected to server”);
ChatBox.AppendText(Environment.NewLine);
NetworkStream ns = client.GetStream();
StreamReader rd = new StreamReader(ns);
general = ns;
Thread th = new Thread(new ParameterizedThreadStart(readServer));
th.Start(rd);
}

//Client reading message from server
public void readServer(object stream)
{
StreamReader reader = new StreamReader(general);
while (true)
{
string str = reader.ReadLine();
if (ChatBox.InvokeRequired)
{
ChatBox.Invoke(new MethodInvoker(delegate
{
ChatBox.AppendText(“Server Saying : ” + str);
ChatBox.AppendText(Environment.NewLine);
}));
}
}
}

License

This article has no explicit license attached to it but to avoid plagiarism, Source files are password protected. Contact author to get password.

Download Source Files

Validate Email address format.

Validate Email

Description: In this article you will learn that how we can validate Email address format.

Tool Used: Visual Studio 2010

 

Regex Class:

Regular Expression is fast and useful way to process text and it is found in Regex Class of System.Text.RegularExpressions namespace. Regex class represents a read only regular expression. And Regex class has many static methods which are used to compare the strings against regular expression. Regular expression returns the exact same word which is compared to the expression. Regex class performs many different operations. By using Regex class we can match strings, replace strings and split the strings etc. The regular expressions are looks complicated and its symbols are difficult to understand.  So here we have a Regular expression “^\w+$” it is difficult and complicated for beginners but I will explain the meaning of all symbols. Here ^ means the start of strings and $ means string is ended. And the \w means a whole word with the characters A-Z, a-z, 0-9 and underscore. And + represents 0 and repetitions.

 

Validate Email address format:

To validate email address format, dot net provides us a class called Regex. By using this class we can validate the email address format.

 

Match Method:

Match method is the method of Regex Class and it is used to find out the specified input string from the regular expression.  It has Match return type and takes one string as parameter. If the string is empty it will throw an exception. It returns the substring which is matches a regular expression in an input string.  We can call the Match method after the Regex class. Because it is static method so we can call this method after the class name.

 

Syntax:

Regex.Match(string input)

 

Validate Email address format using regex:

We can validate Email address format, use the Regex class and its static method Match. In this we check the format of email using Regex class, which is valid or invalid. Regular expression is very useful for validation checking. To understand that let us consider an example in which we declare and three strings and then assign them a value in windows form application. We will make a Form and put label, button and textbox. Then we will write a code in button. We assign valid email address to first string and invalid email address to the second string. And then we assign a regular expression to third string which is used to validate the email address format. Then we create an object of Match class which represents the result of a single regular expression match. And the in this we call the Match method after the object of Regex class and pass it three parameters. The first one is the input string which we want to match and the second one is the string pattern means a regular expression and last parameter is Regex options. It compares the input string with pattern if it is valid it will show the message “valid email” and if it is not it will show the message “invalid email”.

 

To demonstrate make a Windows form application put a textbox and button on it and write the following code in button’s click event.

 

Code:

namespace Validate_Email

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

 

private void button1_Click(object sender, EventArgs e)

{

string email = textBox1.Text;

 

string pettern = @”^[a-z][a-z|0-9|]*([_][a-z|0-9]+)*([.][a-z|” + @”0-9]+([_][a-z|0-9]+)*)?@[a-z][a-z|0-9|]*\.([a-z]” + @”[a-z|0-9]*(\.[a-z][a-z|0-9]*)?)$”;

System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match(email.Trim(), pettern, RegexOptions.IgnoreCase);

 

if (match.Success)

{

MessageBox.Show(“Valid Email”);

}

else

{

MessageBox.Show(“Invalid Email”);

}

}

 

private void textBox1_TextChanged(object sender, EventArgs e)

{

}

}

}

Author: Arooj Aslam

 

 

C# Multiple Threading in Console Application

Introduction:

This article will give you basic idea about how to create a thread in Console and how to work on the created Thread. Threads enable your C# program to perform concurrent processing.

Introduction of Thread in C#:

Thread is a small set of executable program which can be used to separate a task from a process. Multiple threads are efficient way to obtain to give interactive user interaction to your applications.

Code Analysis:

using System.Collections.Generic;
using System;
using System.Threading;

We make above namespaces to our program

Using System.Threading a Thread creates to manage a thread in .Net environment. The Thread class has only one constructor, which takes a ThreadStart delegate as parameter. The ThreadStart delegate is wrap around the callback method, which will be called when we start the thread.

Deligats defines the Pointers, which call as a reference pointers. The function Thread.Sleep allows the waiting threads to be executed.

Code:

using System.Collections.Generic;
using System;
using System.Threading;

public class Threadapplication
{
    public class test
    {
        public int a = 1;
        public void runme()
        {
            for (int i = 0; i < a; i++)
            {
                Thread.Sleep(1000);
                Console.WriteLine(Thread.CurrentThread.Name);
               // Console.Read();
            }
            Console.Read();
        }
    }

    public static void Main(string[] args)
    {
        test t = new test();
        t.a = 3;
        Thread thread = new Thread(new ThreadStart(t.runme));
        thread.Name = "first";
        thread.Start();

        test myJob2 = new test();
        myJob2.a = 5;
        Thread thread2 = new Thread(new ThreadStart(myJob2.runme));
        thread2.Name = "second";
        thread2.Start();
    }
}

 

Capture

Auther : Aqsa Riaz 

Roll number : 021-BSCS-10

 Department of Computer Science
GC University Lahore

Getting Employee’s names against the specified Manager Name from database in C#

Getting Employee’s names against the specified Manager Name from database in C#
by Hassan Shafiq
Description: In this sample article you will learn that how we can establish a connection with database using C#, how we can create and use stored procedures to get Employee’s names against the specified Manager name from database in C#
Tools: Visual Studio, MS SQL Server for database storage

SQL Connection Class

SQL Connection class uses namespace System.Data.SqlClient and present in System.Data (in System.Data.dll) assembly. It handles database connections. It initiates a connection to our SQL database. The SqlConnection class is best used in a using resource acquisition statement. It must have its Open method called in most places where you want to query the database with SqlCommand.

 Constructors

This class has the following constructors
SqlConnection(String)

This constructor initializes a new instance of the SqlConnection class when given a string that contains the connection string. The connection string is sometimes auto generated in visual studio but we must include the SqlConnection code before we can use the SqlCommand object pattern to perform a database query.

We use the following command to establish the connection

using (SqlConnection con = new SqlConnection(connectionString))

In program connection with database establish in the following way

SqlConnection objconnection = new SqlConnection(“Data Source=HASSANSHEIKH\\SQLEXPRESS;Initial Catalog=Manager_Employee;Integrated Security=True”);

Stored Procedures

When we create an application using SQL server, the SQL programming language is the basic programming interface between application and the SQL server database. When we use SQL programs, there are two methods available for storing and executing the programs. We can store the programs locally and create the application that send commands to SQL server and process the results or we can store programs as stored procedures in SQL server and create applications that executes the stores procedures and process the results. It compiles the SQL statements in a single execution plan.

We create procedure in the following way

CREATE PROCEDURE manager_name

AS

BEGIN

SET NOCOUNT ON;

SELECT * from Manager_info

END

GO

This will be used to get the manager info from the Manager_info table

 Code for getting Manager Names

 I have used the following code that will be used to get the manager_name  procedure from the database and will show the manager names in the combobox.

private void button1_Click(object sender, EventArgs e)

{

SqlCommand objcommand = new SqlCommand(“manager_name”, objconnection);

objcommand.CommandType = CommandType.StoredProcedure;

SqlDataAdapter objSqlDataAdapter = new SqlDataAdapter(objcommand);

objconnection.Open();

DataSet objDataSet = new DataSet();

objSqlDataAdapter.Fill(objDataSet);

int T_rows= objDataSet.Tables[0].Rows.Count;

for (int i = 0; i < T_rows; i++)

{

comboBox1.Items.Add(objDataSet.Tables[0].Rows[i][“Manager_name”].ToString());

}

}

 Procedure for selecting Manager Name

The following stored procedure is used to get the manager name with his/her complete info

CREATE PROCEDURE manager_id_return

@Manger_name char(20)

AS

BEGIN

SET NOCOUNT ON;

 SELECT Manager_Id from manager_Info where Manager_name=@Manger_name

END

GO

 Code for selecting Manager Name

To select the manager name the following code will work through in the program

{

String Selected_manager=comboBox1.SelectedItem.ToString();

SqlCommand comnad = new SqlCommand(“manager_id_return”, objconnection);

comnad.CommandType = CommandType.StoredProcedure;

comnad.Parameters.Add(“@Manger_name”, SqlDbType.Char, 20).Value = Selected_manager;

SqlDataAdapter DataAdapter = new SqlDataAdapter(comnad);

DataSet DataSet=new DataSet();

DataAdapter.Fill(DataSet);

String M_id = DataSet.Tables[0].Rows[0][“Manager_id”].ToString();

}

 Procedure for getting Employee’s Names against selected Manager Name

 To select the employee’s names against the selected manager the following procedure is created

CREATE PROCEDURE Employee_related2_manager

@Manager_Id int

AS

BEGIN

SET NOCOUNT ON;

select Employee_name from Employee_Info where Employee_Manager_Id=@Manager_Id

END

GO

 Code for displaying Employee’s Names against selected Manager Name

 The following code is used to display the employee’s names against the selected manager name

private void button2_Click(object sender, EventArgs e)

{

SqlCommand comand1 =  new SqlCommand(“Employee_related2_manager”,objconnection);

comand1.CommandType = CommandType.StoredProcedure;

comand1.Parameters.Add(“@Manager_Id”, SqlDbType.Int, 32).Value = M_id;

SqlDataAdapter dataadapter1 = new SqlDataAdapter(comand1);

DataSet dataset1 = new DataSet();

dataadapter1.Fill(dataset1);

int T_E_N=dataset1.Tables[0].Rows.Count;

for (int j = 0; j < T_E_N; j++)

{

listView1.Items.Add(dataset1.Tables[0].Rows[j][“Employee_name”].ToString());

}

}

User define Text box which can’t take any Integer Values

Table of Contents

  • Introduction
  • Working
  • Code

Introduction:

This article is written in C# ,the purpose of this article is to make user define textbox which can’t take any integer numbers like “0,1,2,3,4,5,6,7,8,9”  This text box having textchanged event to modify the value of a text, the unallowedcharacter defines that no integer value is display in the textbox                                                                                         Capture

Working:

The textbox event having unallowedcharacter which canot take Integer numbers “0,1,2,3,4,5,6,7,8,9” which we define in the event,

If no text is selected in the usercontrol, this property “SelectionStart” indicates the insertion point, or for new text. If you set this property to a location, the length of the text in the control, the selection start position will be placed after the last character.  If the remaining text in the control after the position indicated by the SelectionStart property is less than the value of the SelectionLength property, the value of the SelectionLength property is automatically decreased. The value of the SelectionStart property never causes an increase in the SelectionLength property.

To create the event handler, click on your Project Name control in the designer, click the events icon in the Properties window, then double-click on the TextChanged event in the list that appears below. The following is a brief example of some code that strips out invalid characters:

char[] UnallowedCharacters = { '0', '1','2', '3', '4', '5','6', '7','8', '9'};

if (TextContainsUnallowed(T.Text, UnallowedCharacters))

{

int Index = T.SelectionStart – 1;

T.Text = T.Text.Remove(Index, 1);

T.SelectionStart = Index;

T.SelectionLength = 0;

}

}catch(Exception){}

 

Code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace MyTextBox
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
TextBox T = (TextBox)sender;
try
{
}catch(Exception){}
}
private bool TextContainsUnallowed(String T, char[] UnallowedCharacters)
{
for (int a = 0; a < UnallowedCharacters.Length; a++)
if (T.Contains(UnallowedCharacters[a]))
return true;
return false;
}
}
}

 Auther : Abubakar Mohsin (036-bscs-2010)

G.C University Lahore

 

 

                         

Automation of Google plus

Description: In this simple article you will learn that how we can automate the Google Plus.

Automation Google Plus:

 In this article I will tell you how we can automate the Google plus and I will use visual studio for my project and I will automate the Google Plus using C# .Net platform.

First of all i will explain how we can create this project and which classes, methods and properties of dot net framework, I am using in my project and then I will explain how we can use them to automate Google plus.

Note: in this project we can only automatically logged in into Google plus, due to Google security issues it is not completely automated.

Following are the classes, properties which I am using in my project

Mshtml Library:

Mshtml is an interface and by using this interface and its methods and properties we will get Html tags and its elements etc. to use this interface we have to add its reference and then we can use this class and library.

HTMLDocument Class:

HtmlDocument class is found in System.Windows.Forms reference and by using this class we can able to access the Html Documents introduced by web browser controller. It has many methods and properties. And by using its methods and properties we get different elements and tags of html and we can do different task.

HTMLInputElement:

HTMLInputElement is the interface of mshtml and it is used to acquire the input element of html. It has many properties and methods.

HTMLButtonElement:

HTMLButtonElement is the interface of mshtml and it is used to acquire the button element of html. It has many properties and methods.

GetElementById Method:

GetElementById method is the method of HtmlDocument class and it is used to search and get an Html Element by id. Html element id is used as Search key. It is a public method and its return type is HtmlElement and it takes one string as parameter and that string is the Id attribute of that Html element. We pass element id to GetElementById method it will search that id in specified Html Document.

GetElementByName Method:

GetElementByName method is the method of HtmlElementCollection class and it is used to search and get an Html Element Collection by their name. Html element name is used as Search key but it may or may not be unique. It is a public method and its return type is HtmlElementCollectin and it takes one string as parameter and that string is the Name attribute of that Html element. We pass element Name to GetElementByName method it will search that Name in specified Html Document.

HTMLElementCollection:

HtmlElementCillection is class of System.Windows.Forms namespace and it is used to define the Html Elements objects. It has many methods and properties. And by using this class we can use the html tags and elements to perform different tasks.

GetElementsByTagName Method:

GetElementByTagName method is the method of HtmlDocument class and it is used to search and get an Html Elements with the specified Html Tag Name. Html tag name is used as Search key. It is a public method and its return type is HtmlElementCollection and it takes one string as parameter and that string is the Html Tag Name. We pass element Tag Name to GetElementByTagName method it will search that Tag Name in specified Html Document and gets the Html Elements.

Web browser Control:

Web browser Control is a control that is used in Windows Form Applications. And it also has a class named WebBrowser and it is found in System.Windows.Forms namespace. And it is used to navigate the webpages inside our forms. It has many methods and properties which we can use to perform different tasks. We will use this control WebBrowser and its properties and methods in our project.

Getting started:

Step 1:

First of all create a new project on visual studio in Visual C#, and select Windows Form Application and then give it a name and then press ok.

3 copy

Step 2:

Than drag and drop the webbrowser control on form and give the Url of Google Plus login page into the URL property of webbrowser control.

2 copy

Step 3:

Then we go to the Project tab and add a new class named ‘Google’. We add this class to do some special tasks for our project.

1 copy

Working:

We create a class named Google to do some tasks. First of all I declare a variable named CurrentUrl and assign it a null value because I will use this variable in different places and store Current Url of different pages in to it means the URL of current page will stored into this variable. And then I declared and HtmlDocument object named ObjHTMLDocument and assign it null value. After that I declared another public variable of type string named HomeURL and assign it Home URL of Google Plus.

For Automatic Login, I declared a method Named Login.

Login Method:

Login Method is the Method which I declared in my Google class and this method is used to Login into Google Plus automatically. It is a public method and takes two strings as parameter and does not return any value, than i declares objects of HTMLInputElement and HTMLButtonElement and assign them null value. And then we store Html input elements by their id using its method getElementById. And after getting these elements we get button element by its id using the method getElementById and when it gets this element it click the button automatically and by using its method click.

Code:

public void LogIn(String UserName, String Password)

{

HTMLInputElement userName = null;

HTMLButtonElement htmlcol = null;

try

{

userName = (mshtml.HTMLInputElement)ObjHTMLDocument.getElementById(“Email”);

password = (mshtml.HTMLInputElement)ObjHTMLDocument.getElementById(“passwd”);

userName.value = UserName;

password.value = Password;

try

{

htmlcol = (mshtml.HTMLButtonElement)ObjHTMLDocument.getElementById(“signIn”);

htmlcol.click();

}

catch (Exception ex)

{ MessageBox.Show(ex.ToString()); }

}

catch (Exception b)

{

MessageBox.Show(b.ToString());

}

}

GetCase Method:

GetCase method is user defined method. I declare this method to perform certain tasks. I wrote this method to get some case which I use in Form1 class in switch statement. It is a public method and its return type is int and it does not take any parameter. It means it will return an integer type value.

Code:

public int GetCase()

{

if (CurrentUrl.Equals(“https://accounts.google.com/ServiceLogin?service=oz&continue=https://plus.google.com/?gpcaz=fc79a240&hl=en-GB”))

{

return 1;

}

else

if (CurrentUrl.Equals(“https://plus.google.com/?gpcaz=fc79a240”))

{

return 2;

}

else

return 3;

}

 There is code of complete Google class I will use this class in my main class Form1.

To demonstrate add a class into your project and write the following code.

Complete Google Class Code:

class Google

{

public string CurrentUrl = “”;

public HTMLDocument ObjHTMLDocument = null;

public String HomeURL = “https://accounts.google.com/ServiceLogin?service=oz&continue=https://plus.google.com/?gpcaz%3Dfc79a240&hl=en-GB”;

public void LogIn(String UserName, String Password)

{

HTMLInputElement userName = null;

HTMLButtonElement htmlcol = null;

try

{

userName = (mshtml.HTMLInputElement)ObjHTMLDocument.getElementById(“Email”);

password = (mshtml.HTMLInputElement)ObjHTMLDocument.getElementById(“passwd”);

userName.value = UserName;

password.value = Password;

try

{

htmlcol = (mshtml.HTMLButtonElement)ObjHTMLDocument.getElementById(“signIn”);

htmlcol.click();

}

catch (Exception ex)

{ MessageBox.Show(ex.ToString()); }

}

catch (Exception b)

{ MessageBox.Show(b.ToString()); }

}

public int GetCase()

{

if (CurrentUrl.Equals(“https://accounts.google.com/ServiceLogin?service=oz&continue=https://plus.google.com/?gpcaz=fc79a240&hl=en-GB”))

{

return 1;

}

else

if (CurrentUrl.Equals(“https://plus.google.com/?gpcaz=fc79a240”))

{

return 2;

}

else

return 3;

}

}

Step 4:

This is the last step of my project. Now I will write the code in my main class Form1.  First of all I will create a private object of Google class using new keyword.

When I run my project I was facing a problem of Script Error. To avoid this problem I use the property of WebBrowser Control ScriptErrorsSuppressed and assign it true. By using this property I remove that script error.

For parallel execution I used threading in my WebBrowser control event DocumentCompleted and pass it a method named TaskToExecute which I explain to you later. I used delegates for page navigation. Because I need page navigation during my project therefore I used delegates.

TasktoExecute Method:

TasktoExecute method is the method of Form1 class and it is a user defined method and t is used do all the tasks of my project all other methods are called in this method. It is a public method of void return type means it does not return anything. And it takes only one parameter. I use switch statement in this method which is used to perform all my tasks like login etc. I used my GetCase method for getting case for switch statement.

Code:

public void TasktoExecute(object objgplus)

{

try

{

plus.ObjHTMLDocument = (HTMLDocument)objgplus;

plus.CurrentUrl = webBrowser1.Url.ToString();

switch (plus.GetCase())

{

case 1:

plus.LogIn(“Email”, “Password”);

Thread.Sleep(100000);

break;

default:

MessageBox.Show(“Invalid Value”);

}

catch (Exception exep)

{

MessageBox.Show(exep.ToString());

}

}

This is the complete code of Form1 class and by using all built in classes’ method and some user defined method I am able to automate the Google Plus.

To demonstrate make a Windows Form Application and write the following code.

Complete Code of Form1 Class:

namespace AutomationGooglePlus

{

public partial class Form1 : Form

{

private Google plus = new Google();

public Form1()

{

InitializeComponent();

}

private void Form1_Load(object sender, EventArgs e)

{

webBrowser1.ScriptErrorsSuppressed = true;

}

private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)

{

Thread objthread = null;

if (objthread == null || objthread.ThreadState == System.Threading.ThreadState.Stopped)

{

objthread = new Thread(TasktoExecute);

objthread.Start(webBrowser1.Document.DomDocument);

}

}

private delegate void NavigateDele(String Url);

public void NavigateToURL(String Url)

{

if (webBrowser1.InvokeRequired)

{

webBrowser1.Invoke(new NavigateDele(NavigateToURL), Url);

return;

}

webBrowser1.Navigate(Url);

}

public void TasktoExecute(object objgplus)

{

try

{

plus.ObjHTMLDocument = (HTMLDocument)objgplus;

plus.CurrentUrl = webBrowser1.Url.ToString();

switch (plus.GetCase())

{

case 1:

plus.LogIn(“Email”, “Password”);

Thread.Sleep(100000);

break;

default:

MessageBox.Show(“Invalid Value”);

}

catch (Exception exep)

{

MessageBox.Show(exep.ToString());

}

}

}

Source Code

Author: Muhammad Umair Anwar
GCU Lahore

Online Admission System

1)      Form Submission

a)      Personal Information

b)      Academic Record

c)      Payment Information

d)     Student Login

2)      Verification & Seating Plan

a)      Form Verification

b)      Room(venue) for Students

c)      Teacher’s Duty

3)      Test & Interview

a)      Paper Checking

b)      Result

c)      Reports

d)     Lists(Interview)

4)      Result Card Submission

a)      Submission of  result card(2nd year)

b)      Verification(Eligibility)

c)      Merit Calculation

5)      Merit Lists

a)      Display of Lists 1,2,3,..

b)      Verification of selected students(Dues submitted)

6)      Lists of Sections(Enrolled Students)

7)      History

a)      All Students Data

 

Headings, Paragraphs, Links and Images

HTML Headings

HTML headings are defined with the <h1> to <h6> tags.
<h1>This is a heading</h1>
<h2>This is a heading</h2>
<h3>This is a heading</h3>

HTML paragraphs are defined with the <p> tag.
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

HTML links are defined with the <a> tag.
<a href=”http://www.google.com”>This is a link</a>

HTML images are defined with the <img> tag.
<img src=”abc.jpg” width=”104″ height=”142″>

HTML documents are defined by HTML elements.


HTML Elements

An HTML element is everything from the start tag to the end tag:

Start tag * Element content End tag *
<p> This is a paragraph </p>
<a href=”default.htm”> This is a link </a>

* The start tag is often called the opening tag. The end tag is often called the closing tag.


HTML Element Syntax

  • An HTML element starts with a start tag / opening tag
  • An HTML element ends with an end tag / closing tag
  • The element content is everything between the start and the end tag
  • Some HTML elements have empty content
  • Empty elements are closed in the start tag
  • Most HTML elements can have attributes

Tip: You will learn about attributes in the next chapter of this tutorial.


Nested HTML Elements

Most HTML elements can be nested (can contain other HTML elements).

HTML documents consist of nested HTML elements.


HTML Document Example

<!DOCTYPE html>
<html><body>
<p>This is my first paragraph.</p>
</body></html>

The example above contains 3 HTML elements.

HTML Example Explained

The <p> element:

<p>This is my first paragraph.</p>

The <p> element defines a paragraph in the HTML document.
The element has a start tag <p> and an end tag </p>.
The element content is: This is my first paragraph.

The <body> element:

<body>
<p>This is my first paragraph.</p>
</body>

The <body> element defines the body of the HTML document.
The element has a start tag <body> and an end tag </body>.
The element content is another HTML element (a p element).

The <html> element:

<html>

<body>
<p>This is my first paragraph.</p>
</body>

</html>

The <html> element defines the whole HTML document.
The element has a start tag <html> and an end tag </html>.
The element content is another HTML element (the body element).


Don’t Forget the End Tag

Some HTML elements might display correctly even if you forget the end tag:

<p>This is a paragraph
<p>This is a paragraph

The example above works in most browsers, because the closing tag is considered optional.

Never rely on this. Many HTML elements will produce unexpected results and/or errors if you forget the end tag .


Empty HTML Elements

HTML elements with no content are called empty elements.

<br> is an empty element without a closing tag (the <br> tag defines a line break).

Tip: In XHTML, all elements must be closed. Adding a slash inside the start tag, like <br/>, is the proper way of closing empty elements in XHTML (and XML).


HTML Tip: Use Lowercase Tags

HTML tags are not case sensitive: <P> means the same as <p>. Many web sites use uppercase HTML tags.

Use lowercase tags because the World Wide Web Consortium (W3C) recommends lowercase in HTML 4, and demands lowercase tags in XHTML.

Install IIS on Windows 7

You can install IIS by clicking Windows Features in Advanced Options under Programs in Control Panel.

Before you begin, first ensure whether your Windows 7 supports IIS or not. By default, you do not have administrative user rights if you are logged on as a user other than the built-in administrator, even if you were added to the Local Administrators group on the computer (this is a new security feature in Windows Server® 2008 called Local User Administrator). Log on either to the built-in administrator account, or explicitly invoke applications as the built-in administrator by using the run as command-line tool.

Steps:

First of all, select the Control Panel.

i1

In the Programs section, select Turn Windows Features on or off.i3

You might encounter the following screen:I2

Now, simply click on the features that are checked on the following screens and then hit the OK button.

i4

i5

A progress bar will appear.

i6

Once the installation is over, to confirm it, simply type the following URL into your browser: http://localhost.

If installation is successful, then you will see the following screen:i7

Now you can use Internet Information Services Manager to manage and configure IIS. To open IIS Manager, click Start, type inetmgr in the Search Programs and Files box, and then press Enter.

i8