One machine can do the work of fifty ordinary men. No machine can do the work of one extraordinary man

Showing posts with label C# technologies. Show all posts
Showing posts with label C# technologies. Show all posts

Friday, December 27, 2013

C# Part 1 : Hello World Program

This is a starting of new tutorial series for C# beginners. You don't need to have big experiences with any programming language and I am expecting very basic computer knowledge as an requirement.

I am conducting this sessions using 'Microsoft Visual Studio 2010' product. If you don't have licence version of that you can download free light version called 'Visual C# 2010 Express' from the Microsoft official web site.




Now we are going to write the "Hello World" program.

Step 1 : Open Visual Studio 2010 software


Step 2 : Then create a new project

File -> New -> Project


As the first program we are going to create a console C# application. Once you got the New Project window, follow the instructions in the above picture and press OK to create the project.

Then it will generate a simple program automatically for you. After that you can add following lines to the Main() method (which is the starting point of the program).

Console.WriteLine("Hello World");
Console.ReadLine();

Following picture describe the program properly.


1) Namespaces used by the program (Actually this small program required only 'System' namespace). Namespace is a collection of Classes, Delegates, Enums and Namespaces which we will go in depth in next tutorials.

2) Namespace of the current class

3) Declaration of the class (In this case the class name is 'Program')

4) Starting point of the program

5) Ending point of the program

6) 'WriteLine()' is the method inside the 'Console' class that we use to write something to the console. 'Console' class is in the 'System' namespace.

7) 'ReadLine()' is the method inside the 'Console' class that we use to read user inputs from the console (In this case we use this method to wait the program until we press any key).

Please put a comment if you have any doubts. Play around with this code and ask any question regarding the issues you faced. See you in the next tutorial.



Thursday, July 12, 2012

Fire Alarm When You Insert a Row to SQL Table

First you have to write a particular trigger for run the .exe file, when you insert a record to the data table.

Following is the Trigger


create trigger runexe
on tbDetails
for insert
As
Begin
print 'Inserted'
Exec Master..xp_cmdshell 'E:\Hiran\Alarm.exe'
End

Some SQL Server versions does not allowed to run the "xp_cmdshell" command. In that case you have to enable that feature by executing the following commands.


EXEC sp_configure ‘show advanced options’, 1

EXEC sp_configure ‘xp_cmdshell’, 1


After that you have to write a particular C# program to run the particular batch (.bat) file. The program.cs should look like below. We can run the batch file at once. But then, it will not be Asynchronous and we have to wait until finish the wave file to insert the record. Therefore the best way is this.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Security;


namespace Alarm
{
    static class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            System.Diagnostics.Process.Start("cmd.exe", @"/c E:\Hiran\aaa.bat");
            Application.Exit();
        }
    }
}

Then open the notepad and write the below cording. After that save it using .bat extension.

sndrec32 /play /close "E:\Hiran\SirenSound.wav"


Now You are done. Please comment if you need any help.
Thank You.









Thursday, May 10, 2012

How To Read A Weight Scale via Serial Port

For my project that given by my company, I have created a application for take readings inside c# function. This is a serial port connected weighing machine and this is a CAS PDII machine. But technique that I have used is applicable for any serial port connected weighing machine. Before I do this I followed many blogs and sits. But I couldn't find anything that successfully worked. I think this may helpful to you definitely.

First you have to create a separate method to be called to take weight.


Then you have to fill the code in event handler. Following is the code inside the event handler.
You have to keep two double variables value and the weight.


Now connect your weighing to serial port and try to execute. Hope this will help you a lot.

Saturday, March 5, 2011

New software "Media Center" to watch TV, Listen Radio and read News

Web is too  decentralized place. If we want to watch TV or listen Radio and read news, we have to go through search engines to find out them. I think about a software to centralize all of them. That is the Media Center (beta version)software


You can watch TV, listen Radio, Watch e-papers and go to the other news  sites very easily by only pressing a one button.


Click Here to Download.
when this software run sometimes system will ask you permission for connect to the internet. Then you have to Allow it. Otherwise it will not working properly. Some channels did not provide that services at sometimes. If those are not working you have to try that channel after few minutes.
There can be errors. Because this is a beta version. Please inform us about if there are any errors.Your comments are very useful to improve this software. 

Saturday, January 29, 2011

How to create your own web browser using visual studio C#

1. As usually first you have to create a windows form application
2. Then change your form name and change "IsMdiContainer" property to "True"










3. Then drag and drop a web browser and a tool Strip from the web browser.




4. Then Add buttons and labels and text boxes to your tool strip.
   you can use any amount of buttons to go to your preferable sites by pressing one button.
  you  can set images and sizes to your buttons.
5.After that you have to write codings for every butoon click event (double click on the button).
  Add below codings for that events.


Next button 
webBrowser1.GoForward();


Previous button
webBrowser1.GoBack();


Go button
webBrowser1.Navigate(new Uri("http://"+toolStripTextBox1.Text));


Facebook shortcut button
webBrowser1.Navigate(new Uri("http://www.facebook.com/"));


Gmail shortcut button
webBrowser1.Navigate(new Uri("http://www.gmail.com/"));


  After all these, coding will be view like below. 
6. You can run and check your own web browser.



Wednesday, January 26, 2011

How to create a simple media player using Visual Studio C#

As usually you have to create a windows form application in visual studio
File->New->Project


Then you have to select c# windows form application and give the name and location for your project. After that press ok.


Then Right-click on the toolbox and press "choose Items". Then the following window will appear.


Press "COM component" tab.
Then put a tick on windows media player according to the following picture and press OK.


Now you can see there is tool "Windows media player" on the bottom of the toolbox.


Then drag and drop and change the size as you wish.


After that drag and drop a Menu Strip from the toolbox and give the first one as "Open".


Then Double-click on "Open".



Write a coding as it is in the following picture.



                    OpenFileDialog open = new OpenFileDialog();
                    open.Title = "Open";
                    open.Filter = "All Files|*.*";
                    try
                    {
            
                              if(open.ShowDialog()==System.Windows.Forms.DialogResult.OK)
                                                      axWindowsMediaPlayer1.URL=(open.FileName);
                    }
                    catch (Exception ex)
                    {
                             MessageBox.Show(ex.Message.ToString(),"Error", MessageBoxButtons.OK,       MessageBoxIcon.Error);                
                    }

At last run the program and watch a movie using your own media player.