Showing posts with label Windows Application. Show all posts
Showing posts with label Windows Application. Show all posts

Own Windows Tools With C# (Part 1): Custom Monitor Turn Off


Hey friends, i m going to start new part in this blog where we will make some windows tools by using windows libraries. it customize application made just make windows more easy to use. if you have any idea about it share it with us.

Now i m going to make a application that will shutdown my monitor on one click. Some time we need to turn off monitor we press button of power or monitor but by using this custom application you can easily turn off your monitor and no power issue will be happened.

How to make it???

Create New windows Projects. Form style depend on you what you want. Drag button from tool box double click on button, then you get button click event.

Now write following code to add
interopservices
using System.Runtime.InteropServices;

then following code write as class level.
public int WM_SYSCOMMAND = 0x0112;
public int SC_MONITORPOWER = 0xF170;
[DllImport("user32.dll")]
private static extern int SendMessage(int hWnd, int hMsg, int wParam, int lParam);

in above code we are calling user32.dll, this library holds all operation like this.


Now come to the button click event and write this code..

SendMessage(this.Handle.ToInt32(), WM_SYSCOMMAND, SC_MONITORPOWER, 2);

Now enjoy your own application with windows component.
Download Sample
if you like the post response me in form of comment. and contact me for further detail. Soon i will back with new custom tool. Take Care
Continue Reading...

Insert,Delete and Update through datagrid


Inert,Delete,Update through data grid

In this application we can insert delete and update all through data grid.One thing is to remember is that I have used WPF tool kit Data grid here so if you don't know how to use it then see this post. The main thing that would help us to do this is dataset, as we know when ever we do any editing in our grid then that editing is also done in the dataset so by using the elements in the datagrid we can update , delete or insert data though datagrid.


Below this you can see the code behind the insert button.

        private void Insert_Click(object sender, EventArgs e)
        {
            for (int i = number; i < ds.Tables[0].Rows.Count; i++)
            {
                int rg = Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]);
                string name = ds.Tables[0].Rows[i].ItemArray[1].ToString();

Insert(Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]), ds.Tables[0].Rows[i].ItemArray[1].ToString(),
ds.Tables[0].Rows[i].ItemArray[2].ToString(), ds.Tables[0].Rows[i].ItemArray[3].ToString());

             }
        }


Here is the code of Update Button.The thing to remember in updating the data is that I have taken two data sets and one dataset is updated in the datagrid up the other will be not changed , so in the loop I check every column of each row by comparing those two data sets and if any change is found then the change is made.



private void button4_Click(object sender, EventArgs e)
 {
   bool k = false;
   for (int i = 0; i < number; i++)
   {
   if ((ds.Tables[0].Rows[i].ItemArray[1].ToString() != ps.Tables[0].Rows[i].ItemArray[1].ToString())
   || (ds.Tables[0].Rows[i].ItemArray[2].ToString() != ps.Tables[0].Rows[i].ItemArray[2].ToString())
|| (ds.Tables[0].Rows[i].ItemArray[3].ToString() != ps.Tables[0].Rows[i].ItemArray[3].ToString()))
    {
      k = UpdateData(Convert.ToInt32(ps.Tables[0].Rows[i].ItemArray[0].ToString()), ds.Tables[0].Rows[i].ItemArray[1].ToString(),
ps.Tables[0].Rows[i].ItemArray[2].ToString(), ps.Tables[0].Rows[i].ItemArray[3].ToString());
     MessageBox.Show("Updated");
          }             
    }
 }


And the Code for the Delete button is given below.



      private void DeleteButton_Click(object sender, EventArgs e)
  {
  int i = Convert.ToInt32(controlGrid1.dataGrid1.SelectedIndex.ToString());
  bool d = Delete(Convert.ToInt32(ds.Tables[0].Rows[i].ItemArray[0]));
     if (d)
      {
          MessageBox.Show("Deleted");
          UPDATE_dataGrid();
       } 
   else
           MessageBox.Show("Could not delete");
}


Here is the download file for this project and also data base is given.The folders to download are DBMS_Assignment and databasefiles.


download


Continue Reading...
 
|  I Code Help. Blogger Template By Lawnydesignz Powered by Blogger