h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Display Accounting Year of India

Indian Financial Year using C#.Net .
Indian Financial Year Starts with 01/04/yyyy To 31/03//yyyy.


private static string CurrentDate;
       
        public  static string SplitDay(DateTime dtp,string Mode)
        {
            string str = Convert.ToString(dtp);
            String.Format("{0:MM/dd/yyyy}", dtp);
            string[] st = str.Split('/');
            switch (Mode)
            {
                case "Day":
                    CurrentDate = st[1];
                    break;
                case "Month":
                    CurrentDate = st[0];
                    break;
                case "Year":
                    CurrentDate = st[2];
                    string[] s = CurrentDate.Split(' ');
                    CurrentDate = s[0];
                    break;
            }
            return CurrentDate;
        }

private void lstAccountYear(int statringYear)
        {
            string Day = ClsFinancialYear.SplitDay(DateTime.Now, "Day");
            string Month = ClsFinancialYear.SplitDay(DateTime.Now, "Month");
            string Year = ClsFinancialYear.SplitDay(DateTime.Now, "Year");
            int NextYear = Convert.ToInt32(Year) + 1;
            int LastYear = Convert.ToInt32(Year) - 1;
            int CurrentYear = Convert.ToInt32(Year);
                    if (Convert.ToInt32(Month) <= 3 && Convert.ToInt32(Year) == LastYear + 1)
                    {
                        for (int stYear = statringYear; stYear < CurrentYear; stYear++)
                        {
                            int next = stYear + 1;
                            listBox1.Items.Add(stYear + "-" + next);
                            listBox1.SelectedIndex = listBox1.Items.Count - 1;
                        }
                    }
                    else
                    {
                        for (int stYear = statringYear; stYear < NextYear ; stYear++)
                        {
                            int next = stYear + 1;
                            listBox1.Items.Add(stYear + "-" + next);
                            listBox1.SelectedIndex = listBox1.Items.Count - 1;
                        }
                    }
                }

Call this function in Form_load (where you want)

lstAccountYear(2010);
CurrentYear :2013
if Current date:01/04/2013
Result  :
2010-2011
2011-2012
2012-2013
2013-2014
else Current date:31/03/2013
2010-2011
2011-2012
2012-2013

Split date from DateTime in C#.Net

private static string CurrentDate;
       
        public  static string SplitDay(DateTime dtp,string Mode)
        {
            string str = Convert.ToString(dtp);
            String.Format("{0:MM/dd/yyyy}", dtp);
            string[] st = str.Split('/');
            switch (Mode)
            {
                case "Day":
                    CurrentDate = st[1];
                    break;
                case "Month":
                    CurrentDate = st[0];
                    break;
                case "Year":
                    CurrentDate = st[2];
                    string[] s = CurrentDate.Split(' ');
                    CurrentDate = s[0];
                    break;
            }
            return CurrentDate;
        }

Compare Two ArrayList with DateTime

 private static ArrayList list1 = new ArrayList(new DateTime[] { Convert.ToDateTime("2010-12-01"), Convert.ToDateTime("2010-12-11"), Convert.ToDateTime("2010-12-21") });
        private static  ArrayList list2 = new ArrayList(new DateTime[] { Convert.ToDateTime("2010-12-01"), Convert.ToDateTime("2010-12-15") });
        private static int CountofList1 = list1.Count;
        private static int CountofList2 = list2.Count;
        private static void CompareDatewithArrayList(string Comp)
        {
            switch (Comp)
            {
                case "1":            
                    if (CountofList1 > CountofList2)
                    {
                        foreach (DateTime str in list1)
                        {
                            if (!list2.Contains(str))
                            {
                                MessageBox.Show(Convert.ToString(str));
                            }
                        }
                    }
                    else if (CountofList1 == CountofList2)
                    {
                        foreach (DateTime str in list1)
                        {
                            if (!list2.Contains(str))
                            {
                                MessageBox.Show(Convert.ToString(str));
                            }
                        }
                    }
                    else
                    {
                        foreach (DateTime str in list1)
                        {
                            if (!list2.Contains(str))
                            {
                                MessageBox.Show(Convert.ToString(str));
                            }
                        }
                    }
                    break;
                case "2":
                    if (CountofList1 > CountofList2)
                    {
                        foreach (DateTime str in list2)
                        {
                            if (!list1.Contains(str))
                            {
                                MessageBox.Show(Convert.ToString(str));
                            }
                        }
                    }
                    else if (CountofList1 == CountofList2)
                    {
                        foreach (DateTime str in list2)
                        {
                            if (!list1.Contains(str))
                            {
                                MessageBox.Show(Convert.ToString(str));
                            }
                        }
                    }
                    else
                    {
                        foreach (DateTime str in list2)
                        {
                            if (!list1.Contains(str))
                            {
                                MessageBox.Show(Convert.ToString(str));
                            }
                        }
                    }
                    break;
            }
                    }

Pass TextBox Values into another form ComboBox in C#.net

Today ,we will discuss about Pass One control Value to another Form in C#.net. · Create a Project in VS 2008. · Create Two Form .Form 1 and Form2. · Create TextBoxes and One Button on Form1. · Rename name the TextBox .Start with txt. · Create ComboBox on Form2. Now , we will go to Our scenario. Copy and Paste the following codes in Form 1 Code View Section
public static string[] textvalues; List values = new List(); private void button1_Click(object sender, EventArgs e) { foreach (Control con in this.Controls) { if (con.Name.StartsWith("txt")) { values.Add(con.Text); } } textvalues = values.ToArray(); Form2 frm = new Form2(); frm.Show(); }
Copy and Paste the following codes in Form 2 Code View Section
private void Form2_Load(object sender, EventArgs e) { comboBox1.Items.Clear(); foreach (string str in Form1.textvalues) { comboBox1.Items.Add(str); } }
Just Run the Application and Enter the values and click Button1 .

Count of Controls in Form using C#.Net

                Today , we will discuss about the Count of Controls in Form.The following are code for getting no of controls in Form.

Method for getting no of controls in Form:
  public IEnumerable<Control> GetAll(Control control, Type type)
        {
            var controls = control.Controls.Cast<Control>();
            return controls.SelectMany(ctrl => GetAll(ctrl, type))
                                      .Concat(controls)
                                      .Where(c => c.GetType() == type);
        }

 call Method in the Form Loading event(where ever you want)
var c = GetAll(this, typeof(Button));
MessageBox.Show("Total Controls: " + c.Count());

Result:
Total Controls: (no of Buttons in the form)

Enable USB Port using C#.Net

Today ,We will discuss about Enable and Disable USB Port using C Sharp .Net. First ,Create a Application for Enable and Disable USB Port using C Sharp .Net. In our Example: Two Buttons in the form. One is Enable. Another one is disable. Now, we are going to our Coding Section:
using System.Security.Principal;
public static bool IsUserAnAdministrator;
private void btn_Enable_Click(object sender, EventArgs e)
{ Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 3, Microsoft.Win32.RegistryValueKind.DWord);
}
private void btn_Disable_Click(object sender, EventArgs e)
{ Microsoft.Win32.Registry.SetValue(@"HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\USBSTOR", "Start", 4, Microsoft.Win32.RegistryValueKind.DWord);
}
private void FrmEnabledisableUSBPort_Load(object sender, EventArgs e)
{
if (IsAnAdministrator())
{
btn_Disable.Enabled = true;
btn_Enable.Enabled = true;
}
else
{
btn_Disable.Enabled = false;
btn_Enable.Enabled = false;
}
}
To check User is Admin or Not.
bool IsAnAdministrator()
{
WindowsIdentity MyIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal MyPrincipal = new WindowsPrincipal(MyIdentity);
return MyPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
}
}
conclusion: Thanks for reading this Article.

Status of Service installed using C#

use this method for retrieving Service Installed or Not:
private static bool IsSerInstalled(string serviceName)
{
// get list of Windows services
System.ServiceProcess.ServiceController[] ser = ServiceController.GetServices();
// try to find service name
foreach (ServiceController service in ser)
{
if (service.ServiceName == serviceName)
return true;
}
return false;
}
Call this function/Method where do you want?
if (IsSerInstalled("AdobeFlashPlayerUpdateSvc"))
{
MessageBox.Show("Yes");
}
else
{
MessageBox.Show("No");
}
Result: "yes"

List of Windows Service using C#

Introduction A long running executable that's designed to work without user interaction.
It can be configured to start when the system boots and they can be run without any users logged into the system.
Get list of installed windows services ServiceContro­ller.GetServi­ces: get list of all services.
ServiceContro­ller.GetDevices: get list of driver services.
How to use in C#.net? · Create Project.
· Add Datagridview on the Form.
· Add “System.ServiceProcesss” using AddReference.
Add namespace:
using System.ServiceProcess;
Add Method:
void listofservice()
{
// get list of Windows services
System.ServiceProcess.ServiceController[] services = ServiceController.GetServices();
DataTable dt = new DataTable(); //add DataTable
DataColumn dc = dt.Columns.Add("ServiceName");
DataColumn dc1 = dt.Columns.Add("Display Service Name");
dc.Caption = "Service Name"; // set the caption
dc1.Caption = "Dispaly Service Name"; // set the caption
// try to find service name
foreach (ServiceController service in services)
{
dt.Rows.Add(service.ServiceName, service.Status);//add DataRow to DataTable by values
}
dataGridView1.DataSource = dt;
}
private void Form1_Load(object sender, EventArgs e)
{
listofservice();
}

Software Design Pattern

Introduction:
· A design pattern is a general reusable solution to a commonly occurring problem within a given context in software design.
· Design patterns are recurring solutions to software design problems.
· Patterns are about design and interaction of objects, as well as providing a communication platform concerning elegant, reusable solutions to commonly encountered programming challenges.
Use of Design Pattern: A design pattern helps you to find tested proven design paradigm to build a solid foundation for your project. So, if you follow design pattern you can easily prevent major issues to come while building your actual project. Moreover design pattern also helps the other architects to understand your code easily.
History of Design Pattern: Types of Design Pattern: · Creational patterns.
· Structural patterns.
· Behavioral patterns.
· Concurrency patterns.
Now, I am going to discuss few examples of patterns. They are
· Singleton Design Pattern.
· Factory Design Pattern.
· Factory Method Design Pattern.
· Abstract Factory Design Pattern.
· Builder Design Pattern.
· Adapter Design Pattern.
· Bridge Design Pattern.
· Composite Design Pattern.
· Flyweight Design Pattern. Singleton Design Pattern
Singleton pattern creates a class which can have a single object throughout the application,
Factory Pattern: A Factory is actually a creator of object which has common interface.
Factory Method Design Pattern: It creates the object of the class through interfaces but on the other hand, it also lets the subclass to decide which class to be instantiated.
Abstract Factory Design Pattern: It provides Factory interfaces for creating a family of related classes.
Builder Design Pattern: This pattern creates object based on the Interface, but also lets the subclass decide which class to instantiate.
Adapter Design Pattern: Adapter pattern actually makes two classes compatible.
Bridge Design Pattern: Bridge pattern compose objects in tree structure. It decouples abstraction from implementation.
Composite Design Pattern: Composite pattern treats components as a composition of one or more elements.
Flyweight Design Pattern: Flyweight allows you to share bulky data which are common to each object.

Application Architecture


Introduction:
                 In this Article, I explained about Application Architecture.
Overview:
·         Application Architecture.
·         Software Architecture.
·         Types of Application Architecture.

·         Definition of Application Architecture:
·         The applications architecture is specified on the basis of business requirements.
·         It involves defining the interaction between application packages, databases, and middleware systems in terms of functional coverage.
·         It is differed from Software architecture.
·         Definition of Software Architecture:
·         Software architecture is commonly defined in terms of structural elements and relationships.
·         Types of Application Architecture:
                            
1.    One Tier Architecture.
2.    Two Tier Architecture.
3.    Three Tier Architecture.
1.    One Tier Architecture:
·         One user can run on a Personal Computer.
·         The entire required components to run the application are located within it.
·         User interface, business logic, and data storage are all located on the same machine.
·         They are the easiest to design, but the least scalable.
2.    Two Tier Architecture:
·         It supplies a basic Network between Client and Server.
·         Improves scalability and divides the user interface from the data layers.
3.    Three Tier Architecture:
·         3 layers commonly known as: Presentation Layer (PL/UI), Business Logic Layer (BLL) & Data Access Layer (DAL).

One Tier Architecture:

2.    Two Tier Architecture:
 Three Tier Architecture: