Friday, 8 August 2014

// Menus and other Items Visible and Invisible...


          private void MenusDisable()
        {
            string str = "Select usertype from T_CurUserPass Where ID='1'";
            string user = "";
            con = new OleDbConnection(dbCon());
            OleDbCommand cmd = new OleDbCommand(str, con);
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                user = dr.GetValue(0).ToString();
            }
            dr.Close();
            con.Close();
         
            if (user == "Admin")
            {
                             
            }
            if (user == "Manager")
            {
             
            }
         
            if (user == "TNTS")
            {
             
            }
            if (user == "User")
            {
             
            }

        }

Monday, 4 August 2014

Only number in C#


 private void OnlyNumber(object sender, KeyPressEventArgs e)
        {
            if (!(Char.IsNumber(e.KeyChar)) && (e.KeyChar != 8))
            {
                e.Handled = true;
            }
        }

how to calculate datagrid colums in c#



private void dataGridView1_CellEndEdit(object sender,DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
            {
                int cell1 =Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value);
                int cell2 =Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value);


                if (cell1.ToString() != "" && cell2.ToString() !="")
                {
                    dataGridView1.CurrentRow.Cells[2].Value = cell1 + cell2;
                }

            }
        }

software expired date set in C#




using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Management;

namespace Lab
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            DateTime ShdtEnd = Convert.ToDateTime("15-Jan-15 12:00:00 AM"); //THIS SOFTWARE EXP DATE
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            //  Application.Run(new frmMain());

            //// Application.Run(new frmMain());
            //// }
            if (GetShDate() <= ShdtEnd)
            {
                if (GetMacAddress() == "00270E2F80FB" ||// minnal
                     GetMacAddress() == "002215C6BBF3" //PARTHIBAN
               
                    )
                    //Application.Run(new frmLoginMain());
                    Application.Run(new frmMain());
                //Application.Run(new frmCustomizetools());
                //Application.Run(new frmLoginMain());
                else if (GetVerify() == "Lab Soft")
                {
                    Application.Run(new frmMain());
                    //Application.Run(new frmCustomizetools());
                    //Application.Run(new frmLoginMain());
                    //Application.Run(new frmLoginMain());
                }
                else
                    Application.Run(new frmMain());//frmAuthentication());
                 
            }
            else
            {
                Application.Run(new frmTrialinfor());
            }
        }
        public static string GetMacAddress()
        {
            DateTime dtEnd = Convert.ToDateTime("02-Aug-11 12:00:00 AM");
            ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
            ManagementObjectCollection moc = mc.GetInstances();
            string MACAddress = String.Empty;
            foreach (ManagementObject mo in moc)
            {
                if (MACAddress == String.Empty) // only return MAC Address from first card
                {
                    if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
                }
                mo.Dispose();
            }
            MACAddress = MACAddress.Replace(":", "");
            return MACAddress;
        }
        public static string GetVerify()
        {
            string conread = "";
            StreamReader sr = File.OpenText("E:\\LAB.txt");
            conread = sr.ReadLine();
            return conread;
        }
        public static DateTime GetShDate()
        {
            string dtToday = DateTime.Now.ToShortDateString();
            DateTime dtTo = Convert.ToDateTime(dtToday);
            return dtTo;
        }
    }
}

New ID Generate at C#.net


   private void NewIDGen()
        {
            long id = 0;
            string str = "Select Max(ID) from T_MakeInvoice";
            cbxID.Items.Clear();
            con = new OleDbConnection(dbCon());
            OleDbCommand cmd = new OleDbCommand(str, con);
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                if (dr.IsDBNull(0) == false)
                {
                    id = dr.GetInt32(0) + 1;
                    cbxID.Text = id.ToString();
                }
                else
                    cbxID.Text = "1";

            }
            dr.Close();
            con.Close();
        }

ID Show in C#.Net


 private void IdShow()
        {
            try
            {
                string str = "Select ID from T_MakeInvoice Order By ID Desc";
                cbxID.Items.Clear();
                con = new OleDbConnection(dbCon());
                OleDbCommand cmd = new OleDbCommand(str, con);
                con.Open();
                OleDbDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    if (dr.IsDBNull(0) == false)
                    {
                        cbxID.Items.Add(dr.GetValue(0).ToString());

                    }
                    else
                    {
                        cbxID.Text = "No Items";
                    }
                }
                dr.Close();
                con.Close();
                cbxID.Text = "Select";
            }
            catch (Exception ex)
            {
                MessageBox.Show("No Drugs in Database.\n\n Enter Item Name and Price", "Enter New Item,Price", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cbxID.Focus();
                rbnEntry.PerformClick();

            }
        }

Name Show using C#.Net


   private void NameShow()
        {
            string str = "Select Name from T_RefDr Order By Name";
            cbxSupName.DataBindings.Clear();
            cbxSupName.DataSource = null;
            cbxSupName.Items.Clear();
            con = new OleDbConnection(dbCon());
            OleDbCommand cmd = new OleDbCommand(str, con);
            con.Open();
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                if (dr.IsDBNull(0) == false)
                {
                    cbxSupName.Items.Add(dr.GetValue(0).ToString());

                }
                else
                {
                    cbxSupName.Text = "No Items";
                }
            }
            dr.Close();
            con.Close();
            cbxSupName.Text = "Select";
        }