Small is New Big in C#

Coding

Archive for the ‘Levels Of Details’ Category

Access Class

leave a comment »

using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace Access
{
    class Access
    {
        private OleDbConnection conn;
        private string connstring;

        public Access(string DBPath)
        {
            connstring = "Provider = Microsoft.ACE.OLEDB.12.0;Data Source="; //Microsoft.ACE.OLEDB.12.0  Microsoft.Jet.OleDb.4.0 does not support Access 2007
            connstring += DBPath;
            conn = new OleDbConnection(connstring);
            conn.Open();
        }

        public OleDbConnection DBConn()
        {
            conn.Open();
            return conn;
        }

        public void Close()
        {
            conn.Close();
        }

        public DataTable SelectToDataTable(string sqlcomm)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            return dt;
         
        }

        public DataSet SelectToDataSet(string sqlcomm, string tableName)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            DataSet ds = new DataSet();
            ds.Tables.Add(tableName);
            adapter.Fill(ds, tableName);
            return ds;
        }

        public DataSet SelectToDataSet(string sqlcomm, string tableName, DataSet dsName)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            ds = dsName;
            adapter.Fill(dsName, tableName);
            return ds;
        }

        public OleDbDataAdapter SelectToOleDbDataAdapter(string sqlcomm)
        {
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            OleDbCommand comm = new OleDbCommand(sqlcomm, conn);
            adapter.SelectCommand = comm;
            return adapter;
        }

        public bool ExecuteSQLNonquery(string sqlcomm)
        {
            OleDbCommand cmd = new OleDbCommand(sqlcomm, conn);
            try
            {
                cmd.ExecuteNonQuery();
                return true;
            }
            catch
            {
                return false;
            }
        }
    }
}

Advertisements

Written by nauhil

July 17, 2010 at 10:28 pm

Posted in Levels Of Details

How to get windows service start property

leave a comment »

using System;
using System.Collections.Generic;
using System.Text;
using System.Management;

namespace ConsoleApplication1
{
    class Program
    {

        static void Main(string[] args)
        {
            ManagementObjectSearcher s =
                new ManagementObjectSearcher("root\\CIMV2","SELECT * FROM Win32_Service",
                new EnumerationOptions(
                null, System.TimeSpan.MaxValue,
                1, true, false, true,
                true, false, true, true));
            foreach (ManagementObject service in s.Get())
            {
                Console.WriteLine(service.Path.ToString());
               Console.WriteLine( service.GetPropertyValue("StartMode").ToString());
            }
            Console.ReadLine();
        }
    }
}

Written by nauhil

July 9, 2010 at 8:52 am

Posted in Levels Of Details

How to create customer Timer

leave a comment »

C# Verstion:

        private DateTime dt = new DateTime(2010, 06, 30, 00, 00, 01, 00);
        private System.Timers.Timer timer = new System.Timers.Timer();
        private string nowtime;
        public delegate void TimeString(string timestr);

        public void UpdateTimeString(string str)
        {
            label1.Text = str.ToString();
        }

        private void TimeTicking(object sender, System.Timers.ElapsedEventArgs e)
        {
            dt = dt.AddSeconds(1.0);
            nowtime = dt.ToString("HH:mm:ss");
            object[] para = { nowtime };
            this.Invoke(new TimeString(UpdateTimeString), para);
        }

        private void TimeTick()
        {
            timer.Interval = 1000.0;
            timer.Enabled = true;
            timer.Elapsed += new ElapsedEventHandler(TimeTicking);
        }

        private void Form3_Load(object sender, EventArgs e)
        {
            this.TimeTick();
        }

VB.NET Version:

Private dt As New DateTime(2010, 6, 30, 0, 0, 1, 0)
Private timer As New System.Timers.Timer()
Private nowtime As String

Public Delegate Sub TimeString(timestr As String)

Public Sub UpdateTimeString(str As String)
label1.Text = str.ToString()
End Sub

Private Sub TimeTicking(sender As Object, e As System.Timers.ElapsedEventArgs)
dt = dt.AddSeconds(1.0)
nowtime = dt.ToString("HH:mm:ss")
Dim para As Object() = {nowtime}
Me.Invoke(New TimeString(AddressOf UpdateTimeString), para)
End Sub

Private Sub TimeTick()
timer.Interval = 1000.0
timer.Enabled = True
AddHandler timer.Elapsed, New ElapsedEventHandler(AddressOf TimeTicking)
End Sub

Private Sub Form3_Load(sender As Object, e As EventArgs)
Me.TimeTick()
End Sub


Written by nauhil

June 30, 2010 at 1:47 pm

Posted in Levels Of Details