Monday, September 15, 2014

WINDOWS CE SINGLE INSTANCE VB.NET


Imports System.Threading
Imports System.Runtime.InteropServices
Imports System.IO


Public Class Program
    Private Const NATIVE_ERROR_ALREADY_EXISTS As Int32 = 183

    Public Shared Sub Main(ByVal args As String())
        Try
            If IsInstanceRunning() Then
                ' MessageBox.Show("Price Checker Application Already Running!")

                Return

            Else


                '... the normal application start code ...
                Application.Run(New FORMNAME)
                Exit Sub
            End If
          
        Catch
        End Try
    End Sub


    Public Shared Function IsInstanceRunning() As Boolean
        Dim boolResult As Boolean = False
        Dim hMutex As IntPtr = CreateMutex(IntPtr.Zero, True, "ConnControl")
        If hMutex = IntPtr.Zero Then
        End If
        If Marshal.GetLastWin32Error() = NATIVE_ERROR_ALREADY_EXISTS Then
            boolResult = True
        End If
        ReleaseMutex(hMutex)
        Return boolResult
    End Function

    _
    Public Shared Function SetCursor(ByVal hCursor As IntPtr) As IntPtr
    End Function

    _
    Public Shared Function CreateMutex(ByVal lpMutexAttributes As IntPtr, ByVal InitialOwner As Boolean, ByVal MutexName As String) As IntPtr
    End Function

    _
    Public Shared Function ReleaseMutex(ByVal hMutex As IntPtr) As Boolean
    End Function


End Class

Friday, May 4, 2012

Creating a Simple ASP.NET Page with Multiple UpdatePanel Controls


To create a page with two independently updating regions

  1. Create a new page and switch to Design view.
  2. In the AJAX Extensions tab of the toolbox, double-click the ScriptManager control to add it to the page.
    UpdatePanel Tutorial
  3. Double-click the UpdatePanel control in the toolbox two times to add two UpdatePanel controls to the page.
  4. In the Properties window, set the UpdateMode property of both UpdatePanel() controls to Conditional.
    UpdatePanel Tutorial
  5. In one of the UpdatePanel controls, add a Label control and set its Text property to Panel Created.
  6. In the same UpdatePanel control, add a Button control and set its Text property to Refresh Panel.
  7. In the other UpdatePanel control, add a Calendar control.
    UpdatePanel Tutorial
  8. Double-click the Refresh Panel button to add an event handler for its Click event.
  9. Add the following code to the handler, which sets the Label control to the current time.
    protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = "Panel refreshed at " +
            DateTime.Now.ToString();
    }
    
    
    
  10. Save your changes and press CTRL+F5 to view the page in a browser.
  11. Click the button.
    The text in the panel changes to display the last time that the panel's content was refreshed.
  12. In the calendar, move to a different month.
    The time in the other panel does not change. The content of both panels is updated independently.
    The example is styled to better show the region of the page that the UpdatePanel control represents.
    <%@ Page Language="C#" %>
    
    
    "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    
    
    
    
        UpdatePanel Tutorial
        
    
    
        
    UpdatePanel1
    UpdatePanel2
    By default, the ChildrenAsTriggers property of an UpdatePanel control is true. When this property is set to true, controls inside the panel participate in partial-page updates when any control in the panel causes a postback.
In some scenarios, nesting UpdatePanel controls enables you to provide UI functionality that would be difficult to provide otherwise. Nested panels are useful when you want to be able to refresh specific regions of the page separately and refresh multiple regions at the same time. You can accomplish this by setting the UpdateMode property of both the outer and nested controls to Conditional. This causes the outer panel not to refresh its page region if only the inner panel is refreshing. However, if the outer panel is refreshed, the nested panels are refreshed also.
In the following example, a simplified form of this idea is demonstrated.

To nest UpdatePanel controls

  1. Create a new page and switch to Design view.
  2. In the AJAX Extensions tab of the toolbox, double-click the ScriptManager control to add it to the page.
  3. In the toolbox, double-click the UpdatePanel control to add an UpdatePanel control to the page.
    UpdatePanel Tutorial
  4. Click inside the UpdatePanel control and then in the Standard tab of the toolbox, double-click a Button control to add it to the UpdatePanel control.
  5. Set the button's Text property to Refresh Outer Panel.
    UpdatePanel Tutorial
  6. In the Properties window, set the UpdateMode property of the UpdatePanel() control to Conditional.
    UpdatePanel Tutorial
  7. Switch to Source view and add the following code inside the element of the element.
    Last refresh <%=DateTime.Now.ToString() %> 
    
    
    
    
    The code displays the time and is used to indicate when the markup was last rendered.
  8. Switch to Design view, click inside the UpdatePanel control, and then add a second UpdatePanel control inside the first panel.
  9. In the Properties window, set the UpdateMode property of the nested UpdatePanel() control to Conditional.
    UpdatePanel Tutorial
  10. Add a Calendar control inside the nested UpdatePanel control.
    UpdatePanel Tutorial
  11. Switch to Source view and add the following code inside the element of the nested element.
    Last refresh <%=DateTime.Now.ToString() %> 
    
    
    
    
  12. Save your changes and then press CTRL+F5 view the page in a browser.
    When you move to the previous or next month in the calendar in the nested UpdatePanel control, the outer panel's time does not change because the content is not re-rendered. In contrast, when you click the button in the outer panel, the time in the inner panel is refreshed. The calendar does not change because by default the EnableViewState property is true for the Calendar control.
    The example is styled to better show the region of the page that the UpdatePanel control represents.
    <%@ Page Language="C#" %>
    
    "-//W3C//DTD XHTML 1.0 Transitional//EN" 
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    
    "http://www.w3.org/1999/xhtml" >
    "server">
        UpdatePanel Tutorial
        
    
    
        
    "form1" runat="server">
    "ScriptManager1" runat="server"> "UpdatePanel1" UpdateMode="Conditional" runat="server">
    Parent UpdatePanel Last refresh <%=DateTime.Now.ToString() %> "Button1" runat="server" Text="Refresh Outer Panel" /> "UpdatePanel2" runat="server">
    Nested UpdatePanel Last refresh <%=DateTime.Now.ToString() %> "Calendar1" runat="server">

Tuesday, January 26, 2010

During my training career, I have been asked one common question several times that how we can calculate summary totals inside GridView control and how we can show it at the footer of GridView control. So I have decided to write a tutorial on this topic. In this tutorial I will show you how you can calculate and display totals not only in GridView footer but also on any control outside GridView control.


GridView with Footer Total

For the purpose of this tutorial I have setup a simple ASP.NET page with data bound GridView control and a Label control on it. Following is the HTML source code of the GridView and Label control:


Average Price:

In the above code, I am using TemplateField column inside GridView control which has two templates ItemTemplate and FooterTemplate containing Label controls to show data. The Labels inside ItemTemplate are bound with UnitPrice and UnitsInStock fields using ASP.NET binding expression <%# %> syntax. The Labels inside FooterTemplate are left blank for showing totals later from the code.

I am also attaching an event handler for the RowDataBound event with the GridView. This event is where I will calculate the total for GridView data later. The RowDataBound event is raised whenever a row in the GridView is bound to data. It is raised for the header, the footer, and data rows. This event provides an opportunity to access each row before the page is finally sent to the client for display.

The Page_Load event of the page binds data with the GridView control as follows:

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
}

private void BindData()
{
string constr = "Server=TestServer;Database=TestDatabase;uid=test;pwd=test;";
string query = "SELECT ProductID, ProductName, UnitPrice, UnitsInStock, OnSale FROM Products";

SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();

da.Fill(table);

GridView1.DataSource = table;
GridView1.DataBind();
}

To calculate totals first you need to declare some variables outside the RowDataBound event. Two variables will keep track of the total of all the values bound inside GridView control and the third variable totalItems will be used to calculate the average price.
decimal totalPrice = 0M;
decimal totalStock = 0M;
int totalItems = 0;

As I mentioned above, RowDataBound event raised for all header, data or footer rows. I put one if condition to make sure currently it is binding DataRow. Then I am getting the reference of lblPrice and lblUnitsInStock labels using FindControl method. These labels have price and stock values of the current row in their text property. I am converting the text into decimal and then adding the value in totalPrice and totalStock variables. Once all the Data rows are finished I have similar check for Footer Row in which I am getting the reference of lblTotalPrice and lblTotalUnitsInStock Labels available in the FooterTemplate inside GridView and showing the totals on those labels.
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lblPrice = (Label)e.Row.FindControl("lblPrice");
Label lblUnitsInStock = (Label)e.Row.FindControl("lblUnitsInStock");


decimal price = Decimal.Parse(lblPrice.Text);
decimal stock = Decimal.Parse(lblUnitsInStock.Text);

totalPrice += price;
totalStock += stock;


totalItems += 1;
}

if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblTotalPrice = (Label)e.Row.FindControl("lblTotalPrice");
Label lblTotalUnitsInStock = (Label)e.Row.FindControl("lblTotalUnitsInStock");


lblTotalPrice.Text = totalPrice.ToString();
lblTotalUnitsInStock.Text = totalStock.ToString();


lblAveragePrice.Text = (totalPrice / totalItems).ToString("F");
}
}

Tuesday, January 19, 2010

The first step to learning English is having a good dictionary

The first step to learning English is having a good dictionary.


What do we mean by good dictionary?

Well, firstly, if you really want to improve your fluency with the language you should use an “English – English” dictionary. Many people find it comfortable using a “Hindi –English” or “Marathi –English” dictionary. Do “not” use this kind of dictionary. Use an “English – English” dictionary only!

There are many advantages of an English - English dictionary. In this kind of dictionary, the meanings are explained in English like:

to criticize = to say negative things about; to talk about the mistakes of

So you have to understand the meaning of the meaning too. This helps you to familiarize your self with the language and also exposes you to new English words that you should find out the meanings of.

To really accelerate your English learning process, go in for an English-English dictionary. Not only should you have this kind of dictionary. You must also use it. Use it every time you come across a new word.

Also, keep in mind that when you buy your English-English dictionary, you buy a version that is for learners, not the version for native speakers. Usually, "students version" or "learners version" etc. will be written on the dictionary.


The most important thing that the dictionary you buy must contain:

The dictionary that you buy “must” contain example sentences along with every word. For example:

reaction: Response to an earlier activity.

E.g. Sentence: What was your reaction when you heard the news?

Having an example sentence is very useful. Some times the meaning provided with the word may be a little confusing. So you may misunderstand what the word means. The sample sentence clears all such doubts.

Not only this, having a sample sentence is very important because it tells you how the word can be used in conjunction with other words. How the different words connect to form a sentence. Reading the sample sentence “programs the brain” to use the word properly.

So, when you purchase a dictionary, make sure it has a lot of sample sentences. It would be even better if you purchase two different dictionaries with a lot of different sample sentences. This will give you a much better understanding of the word you look up.

The best way to use the sample sentences in the dictionary is to learn them. Whenever you are looking up some new word and you come across a sample sentence, you must read it again and again until you know the sentence by-heart.

If you do this, you will be in a position to use the word or the phrase in sentences of your own correctly. Forming correct sentences becomes easy if you learn the sample sentences after reading them again and again.


What else must your dictionary contain?

Now-a-days, many dictionaries, come with a CD. These CD's contain the software version of the dictionary. This is especially convenient if you have easy access to a computer.

You don’t have to waste too much time looking for the word you want. It is quite easy to look it up using the software dictionary. Also, the software dictionary may have audio files for the words. These audio files can be played and the correct pronunciation for a word can be known. Try to look out for a dictionary that comes along with this kind of CD.

If you are unable to find this kind of dictionary that comes with a CD, do not worry.

There are many online dictionaries available. They too allow you to search for any word conveniently. Some of them even provide audio files containing pronunciations of all the different words. One such dictionary is: Merriam-Webster Online

So in conclusion, when you go to buy your dictionary, look out for these things:

  • It's an English - English dictionary
  • It's a students or learners version
  • It has a lot of sample sentences
  • It comes with a CD that is a software dictionary and preferably has pronunciations for the words

One dictionary that stands out from the rest is the “The Collins COBUILD Advanced Learner's English Dictionary (4th edition)”. Try to get your hands on it.

Thursday, June 25, 2009

Asp.Net CAPTCHA and Asp.Net AJAX CAPTCHA

Thursday, June25, 2009

Asp.Net CAPTCHA and Asp.Net AJAX CAPTCHA


I am using a great Asp.Net CAPTCHA by BrainJar in a number of web sites with and without Asp.Net AJAX. It’s a simple and really easy to use Asp.Net CAPTCHA. The actual source code is in C#, but you can use it with both C# and VB.Net by simply wrapping the functionality in a class library.

In Asp.Net forums and in many other user communities I have seen lot of people asking for VB.Net CAPTCHA. So I thought to write a blog post and create some sample implementations. The zip file contains C# CAPTCHA and VB.Net CAPTCHA. I have included the samples for Asp.Net AJAX CAPTCHA also.

You can download the samples and implementation from here

Implementing Asp.Net AJAX CAPTCHA is really simple. Just wrap the main Asp.Net CAPTCHA with Asp.Net AJAX update panel and put a random query string at the end of CAPTCHA image src. The random query string will avoid showing the old CAPTCHA from browser cache.

STEPS TO ADD ASP.NET CAPTCHA IN YOUR WEBSITE
  1. Refer the assembly CaptchaDLL.dll in your project
  2. Copy JpegImage_CS.aspx or JpegImage_VB.aspx (according to the language of choice) to your website.
  3. Open the above file and make changes in Colors and Font if needed. (read the inline comments to know more)
  4. Now user the sample codes from Default.aspx or Ajax.aspx pages. The code is straight forward. You make a session and generate an image with the string in the Session. Now when you submit you have to check the session value and textbox value to see whether the entered CAPTCHA is correct.
DOWNLOAD THE SOURCE AND SAMPLES FROM HERE

If you have any questions please put as a comment.

Tags
Asp.Net CAPTCHA, CAPTCHA, VB.Net CAPTCHA, C# CAPTCHA, ASP CAPTCHA, C sharp captcha, vb captcha, simple captcha, AJAX CAPTCHA, asp.net ajax captcha, captcha without refresh, captcha using ajax, numeric captcha