Pages

Sunday, August 16, 2015

.Net Sound Timer

This tutorial show you how to set sound timer depend on the number of order. It plays sound for notification whenever the number of order change.
Sound Timer

Firstly, copy the following javascript to <head> tage.
<script type="text/javascript">
    function EvalSound(soundobj) {
        var thissound = document.getElementById(soundobj);
        thissound.play();
    }
</script>
Secondly, copy the following code to <form> tag.
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick">
</asp:Timer>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label ID="lblOrder" runat="server" Text=""></asp:Label>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" />
    </Triggers>
</asp:UpdatePanel>
<audio id="audio1" src="sound/Console_beep.mp3" preload="auto" autobuffer>
</audio>
In code-behind, the following snippet should be there.
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        string dt = DateTime.Now.ToLongTimeString();
        string count = DAL.GetOrderCount();
        lblOrder.Text = string.Format("There are {0} records at {1}.", count, dt);
        Session["count"] = count;
        
    }
}
protected void Timer1_Tick(object sender, EventArgs e)
{
    string dt = DateTime.Now.ToLongTimeString();
    string count = DAL.GetOrderCount();
    if (count != Session["count"].ToString())
    {
        lblOrder.Text = string.Format("There are {0} records at {1}.", count, dt);
        ScriptManager.RegisterStartupScript(Page, GetType(), "PlaySound", "EvalSound('audio1');", true);
    }
    Session["count"] = count;
}
It uses "Northwind" database and connection string in web.config seem like below:
<connectionStrings>
<add name="sqlConn" providerName="System.Data.SqlClient" connectionString="Server='(local)';uid='sa';pwd='p@ssw0rd';Database='Northwind';Pooling=False;" />
</connectionStrings>
It has the following code snippet in the DAL class. It uses the Microsoft.Practices.EnterpriseLibrary.Data.dll to shorten the code.
private static Database getDatabase()
{
    Database database = null;
    try
    {
        database = DatabaseFactory.CreateDatabase("sqlConn");
    }
    catch (Exception exception)
    {
               
    }
    return database;
}
public static string GetOrderCount()
{
    string count = "";
    try
    {
        count = getDatabase().ExecuteScalar("GetOrderCount").ToString();
    }
    catch (Exception exception)
    {
        
    }
    return count;
}
The "GetOrderCount" stored procedure is as shown below:
USE [Northwind]
GO
ALTER PROCEDURE [dbo].[GetOrderCount]
AS
BEGIN
    SELECT COUNT(*) FROM Orders;
END
This application demonstrates a simple use of the Timer control with UpdatePanel combining HTML5 audio element in a real world example.

12 comments:

  1. Wonderful, just what a blog it is! This blog has provided the helpful data to us continue the good work.
    index

    ReplyDelete
  2. Updated information about html.Thanks for sharing such a information.
    selenium training in chennai

    ReplyDelete
  3. I have to voice my passion for your kindness giving support to those people that should have guidance on this important matter.

    Hadoop Training in Chennai

    ReplyDelete
  4. Personally, I wouldn't go lower than 128kbps for mp3 - and even at that point, things like cymbals or quiet background sounds can have a strange, warbling sound to it. sound of waterfalls

    ReplyDelete
  5. Thanks for sharing nice information with us. i like your post and all you share with us is uptodate and quite informative, i would like to bookmark the page so i can come here again to read you, as you have done a wonderful job. latest naija music

    ReplyDelete
  6. We require all the more such articles that we can read with such excitement.
    Vanessa Martel

    ReplyDelete
  7. Awesome, very interesting to read.Thanks for giving your post :) Kaashiv provides Best DotNet Training in Chennai with professional trainers who provide real-time training and also projects to the candidates for better understanding.

    Oracle Training in Chennai | Android training in chennai | Matlab Training in Chennai | CCNA Training in Chennai

    ReplyDelete
  8. Oh, that's Great Post Thanks for sharing with us.
    This Big Data Hadoop Training in Pune Platform helped me to learn advanced concepts of all the trending technologies out there in the current IT market. really worth trying them.

    ReplyDelete
  9. Thanks for a very interesting blog. What else may I get that kind of info written in such a perfect approach? I’ve a undertaking that I am simply now operating on, and I have been at the look out for such info. Soundcloud downloader

    ReplyDelete