Monday 23 June 2014

Javascript Clock example

Leave a Comment
This example show how to insert clock on the website which is not static clock, but like a digital clock.

Script for Creating Clock

 <script type="text/javascript">
        function updateClock() {
            var currentTime = new Date();
            var currentHours = currentTime.getHours();
            var currentMinutes = currentTime.getMinutes();
            var currentSeconds = currentTime.getSeconds();

            // Pad the minutes and seconds with leading zeros, if required
            currentMinutes = (currentMinutes < 10 ? "0" : "") + currentMinutes;
            currentSeconds = (currentSeconds < 10 ? "0" : "") + currentSeconds;

            // Choose either "AM" or "PM" as appropriate
            var timeOfDay = (currentHours < 12) ? "AM" : "PM";
            // Convert the hours component to 12-hour format if needed
            currentHours = (currentHours > 12) ? currentHours - 12 : currentHours;
            // Convert an hours component of "0" to "12"
            currentHours = (currentHours == 0) ? 12 : currentHours;
            // Compose the string for display
            var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
            // Update the time display
            document.getElementById("clock").firstChild.nodeValue = currentTimeString;
            //return currentTimeString;
        }
    </script>


Call the clock on body load

<body onload="updateClock(); setInterval('updateClock()', 1000 );">


Div element for clock

   <div id="clock" style="font-size:larger; font-family:Verdana;">
    </div>


Output


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Tuesday 3 June 2014

Who is connected to database - Sample Application C#

Leave a Comment
This is a sample application just to show who is currently connected into database MSSQL. The application actually just execute MSSQL command "sp_who" and show the data into datagrid.

Below is a screen shoot of the sample application.



Code Behind View Who Is Connected Form 


        public Form1()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string ipaddress = textBox1.Text;
            string username = textBox2.Text;
            string password = textBox3.Text;
            string dbNAme = textBox4.Text;
            ViewUserActive form = new ViewUserActive();
            form.popupInformation(ipaddress, username, password, dbNAme);       
        }
        private void Form1_Load(object sender, EventArgs e)
        {         
        }

Code Behind ViewUserActive Form


        string ipaddress;
        public string Ipaddress
        {
            get { return ipaddress; }
            set { ipaddress = value; }
        }
        string username;
        public string Username
        {
            get { return username; }
            set { username = value; }
        }
        string password;
        public string Password
        {
            get { return password; }
            set { password = value; }
        }
        string dbNAme;
        public string DbNAme
        {
            get { return dbNAme; }
            set { dbNAme = value; }
        }
        public ViewUserActive()
        {
            InitializeComponent();
        }
        public void popupInformation(string ipadd, string usrName, string pass, string databaseName)
        {
            ViewUserActive form = new ViewUserActive();
            form.Ipaddress = ipadd;
            form.Username = usrName;
            form.Password = pass;
            form.DbNAme = databaseName;
            form.ShowDialog();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void ViewUserActive_Load(object sender, EventArgs e)
        {
            string strConnection = "Data Source=" + Ipaddress + ";Initial Catalog=" + DbNAme + ";Persist Security Info=True;User ID=" + Username + ";Password=" + Password;
            SqlConnection dbConn = new SqlConnection(strConnection);
            SqlCommand dbComm;
            SqlDataReader dbReader;

            DataTable table = new DataTable();
            table.Columns.Add("SPID", typeof(string));
            table.Columns.Add("ECID", typeof(string));
            table.Columns.Add("STATUS", typeof(string));
            table.Columns.Add("LOGINNAME", typeof(string));
            table.Columns.Add("HOSTNAME", typeof(string));
            table.Columns.Add("BLK", typeof(string));
            table.Columns.Add("DBNAME", typeof(string));
            table.Columns.Add("CMD", typeof(string));
            table.Columns.Add("REQUESTID", typeof(string));

            DataTable _temp = new DataTable();
            string strsql = "sp_who";
            dbComm = new SqlCommand(strsql, dbConn);
            dbConn.Open();
            dbReader = dbComm.ExecuteReader();
            if (dbReader.HasRows)
            {
                while (dbReader.Read())
                {
                    string dbName = dbReader["dbname"].ToString();
                    if (dbName.Trim().ToUpper() == DbNAme.Trim().ToUpper())
                    {
                        DataRow row = table.NewRow();
                        row["SPID"] = dbReader["spid"].ToString();
                        row["ECID"] = dbReader["ecid"].ToString();
                        row["STATUS"] = dbReader["status"].ToString();
                        row["LOGINNAME"] = dbReader["loginame"].ToString();
                        row["HOSTNAME"] = dbReader["hostname"].ToString();
                        row["BLK"] = dbReader["blk"].ToString();
                        row["DBNAME"] = dbName;
                        row["CMD"] = dbReader["cmd"].ToString();
                        row["REQUESTID"] = dbReader["request_id"].ToString();
                        table.Rows.Add(row);
                    }
                }
            }

            dbReader.Close();
            dbConn.Close();
            dataGridView1.DataSource = table;
        }



By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Kentico 7 - Get Specific document information

Leave a Comment
This post will show how to get specific document information using Transformation In Kentico 7.

Note : i have tested this method in kentico 7 only, donno if the other version will work.

You can refer this link to create new transformation method

Example :

You can use this method in your transformation let say you create new repeater and want to show the parent name of the binding document type data. In this scenario, the document type store under different parent node.

       public string getDocumentInfo(string documentID, string parentProperties)
        {
            TreeProvider tree = new CMS.DocumentEngine.TreeProvider(CMSContext.CurrentUser);
            TreeNode Node = DocumentHelper.GetDocument(Convert.ToInt16(documentID), tree);

            if (Node != null)
            {
                switch (parentProperties)
                {
                    case "NodeID": return Node.NodeID.ToString();
                    case "NodeAliasPath": return Node.NodeAliasPath;
                    case "NodeName": return Node.NodeName;
                    case "NodeAlias": return Node.NodeAlias;
                    case "NodeClassName": return Node.NodeClassName;
                    case "NodeParentID": return Node.NodeParentID.ToString();
                    case "NodeLevel": return Node.NodeLevel.ToString();
                    default: return string.Empty;
                }
            }
            else
            {
                return "Current UserInfo :" + CMSContext.CurrentUser + " Node is null";
            }
        }


How to use

getDocumentInfo(Eval("NodeParentID").ToString(),"NodeName")


By
NOTE : – If You have Found this post Helpful, I will appreciate if you can Share it on Facebook, Twitter and Other Social Media Sites. Thanks =)
Read More...

Subscribe to our newsletter to get the latest updates to your inbox.

Your email address is safe with us!




Founder of developersnote.com, love programming and help others people. Work as Software Developer. Graduated from UiTM and continue study in Software Engineering at UTMSpace. Follow him on Twitter , or Facebook or .



Powered by Blogger.