Monday, May 11, 2015

Time Management

"Past time never found"- Benjamin Franklin
Time is the most precious resource on earth. It is the most valuable thing people have. It is perishable, it is irreplaceable, and it cannot be stored. People compare time with gold but it is a wrong notion. The value of gold fluctuates from time to time but the value of time will never fluctuate. Even 1000 years ago, a day consisted of 24 hours per, 60 minutes per hour and 60 seconds per minutes. Still in the 21st century, a day consists of 24 hours. There is no change in the value of time. There is no precious asset on earth rarer than time. Hence, don't compare time with gold.

"If we lose gold we can earn back, if we lose money we can get it back, if we lose our health we can recover it. But once we lost our time, it lost forever."

Every person has 24 hours per day.

Why do few people succeed in their pursuits and others fail? Successful people utilize time in a more effective manner than unsuccessful people. They priorities activities and allocate time on the basis of importance. Time can only be reallocated from activities of lower value to activities of higher value. All work and accomplishments require time.
Due to our fast paced modern life, most people are unable to priorities their activities and are confused. Hence, they do unimportant things first and important things next. To get success in life, people should evaluate their activities in the light of what is really important to them. They must master their time rather than becoming a slave to the constant flow of events and demands on their time. They must organize their life to achieve balance, harmony, and inner peace. Lack of harmony with time and activities leads to chaos in life.

Your ability to think and priorities activities is the most valuable trait for the smoothest flow of life.

"Wise time management is inseparable from high quality life."
It is a fact that life means time and time means life. God has given us this wonderful life to life happily and achieve life goals but not brood over failures. Time is absolutely essential to develop important relationships in life. Life itself is time and hence life without time has no value.
We all grow in time, live in time and ultimately, perish in time. There may not be an exact definition of time, but we all know what it is and its great value in human life. A man has a lot of wants. We all want fame, success, money, happiness, love, relationship etc. There is no end to our desires.
However, only a few are successful, prosperous and happy. These few are the ones who realized the value of time. They made the best use of their time and attained an enviable position in society. People, who made effective usage of time at their disposal, got the best from time.
Never curse time for not giving you riches; we have to extract riches from time. But those who forget the value of time may find to their utter dismay that it will be harsh on them later. Man may neglect time and misuse it but time doesn't wait. It may be a fantasy that time may take revenge on us so utilize this precious recourse carefully.
Time will never forget us though we may forget it. Time reciprocates. If we use it in a wise manner it gives us happiness otherwise it pushes people into troubles.

क्या करे अगर आपका बॉस आपको बार बार निचा दिखाता हो तो?

जिस तेजी से हम सफलता अर्जित कर रहे हैं, उसी गति से हमारी बुराई करने वालों की संख्या भी बढ़ती है। बुराई करने वाले लोग हमारी प्रतिष्ठा पर बुरा असर डालते हैं, वे लगातार हमारा अपमान करने का प्रयास करते रहते हैं। इनसे बचने के लिए सबसे अच्छा तरीका यही है कि अपने काम से उन्हें गलत साबित करें। साथ ही, ऐसे लोगों को अधिक महत्व नहीं देना चाहिए और इन्हें पूरी तरह नजरअंदाज भी नहीं करना चाहिए। महाभारत में श्रीकृष्ण और शिशुपाल के प्रसंग से हम सीख सकते हैं कि यदि कोई हमारा अपमान करता है तो क्या करना चाहिए…
शिशुपाल की सौ गलतियां श्रीकृष्ण ने की थी माफ
महाभारत में शिशुपाल और श्रीकृष्ण का प्रसंग काफी चर्चित रहा है। शिशुपाल श्रीकृष्ण की बुआ का पुत्र था और चेदी नगर का राजा था। श्रीकृष्ण ने शिशुपाल की माता को वचन दिया था कि वे शिशुपाल की 100 गलतियां माफ करेंगे, लेकिन 100 गलतियों के बाद उसे उचित सजा भी अवश्य देंगे।
ये है शिशुपाल और श्रीकृष्ण का प्रसंग
विदर्भराज के रुक्मी, रुक्मरथ, रुक्मबाहु, रुक्मकेस तथा रुक्ममाली नामक पांच पुत्र और एक पुत्री रुक्मिणी थी। रुक्मिणी के माता-पिता उसका विवाह श्रीकृष्ण के साथ करना चाहते थे, लेकिन रुक्मी (रुक्मिणी का बड़ा भाई) चाहता था कि उसकी बहन का विवाह चेदिराज शिशुपाल के साथ हो। अतः उसने रुक्मिणी का टीका शिशुपाल के यहां भिजवा दिया। रुक्मिणी श्रीकृष्ण से प्रेम करती थी, इसलिए उसने श्रीकृष्ण को एक ब्राह्मण के हाथों संदेशा भेजा। श्रीकृष्ण भी रुक्मिणी से प्रेम करते थे और वे ये भी जानते थे कि रुक्मिणी के माता-पिता रुक्मिणी का विवाह मुझसे ही करना चाहते हैं, लेकिन बड़ा भाई रुक्मी मुझसे शत्रुता के कारण ये विवाह नहीं होने देना चाहता है। श्रीकृष्ण ने रुक्मी के विरोध के बावजूद रुक्मिणी से विवाह किया। इस विवाह को चेदिराज शिशुपाल ने अपना अपमान समझा और वह श्रीकृष्ण को शत्रु समझने लगा।
कुछ समय बाद जब युधिष्ठिर ने राजसूय यज्ञ आयोजित किया। इस आयोजन में सभी प्रमुख राजाओं को आमंत्रित किया गया। चेदिराज शिशुपाल भी यज्ञ में आया था। देवपूजा के समय श्रीकृष्ण का सम्मान देखकर शिशुपाल क्रोधित हो गया और उसने श्रीकृष्ण को अपशब्द कहना शुरू कर दिए। यज्ञ में उपस्थित सभी लोगों ने शिशुपाल को समझाने की कोशिश की, लेकिन वह नहीं माना। अर्जुन और भीम शिशुपाल को मारने के लिए खड़े हो गए तो श्रीकृष्ण ने उन सभी को रोक दिया। शिशुपाल लगातार गालियां देता रहा और श्रीकृष्ण गालियां गिनते रहे। जब वह सौ अपशब्द कह चुका, तब श्रीकृष्ण ने उसे अंतिम चेतावनी दी कि अब रुक जाओ, अन्यथा परिणाम अच्छा नहीं होगा। श्रीकृष्ण के समझाने के बाद भी शिशुपाल नहीं रुका और उसने फिर से अपशब्द कहा। इसके बाद शिशुपाल के मुख से अपशब्द निकलते ही श्रीकृष्ण ने सुदर्शन चक्र से उसका मस्तक काट दिया।
इस प्रसंग से हम यह सीख ले सकते हैं कि यदि कोई हमारा अपमान करता है तो पहले उसे समझाने के पूरे प्रयास करना चाहिए। यदि लगातार समझाने के बाद भी व्यक्ति हमारे मान-सम्मान को ठेस पहुंचा रहा है तो उसे उचित जवाब देना चाहिए। ऐसे लोगों को चुप करने के लिए हमें लगातार श्रेष्ठ काम करना चाहिए और उसकी बातों को गलत साबित करना चाहिए।

Monday, March 9, 2015

How to Save a Webpage as PDF?


You can save a Webpage as PDF, so that it becomes easy to handle.
Which browser are you using?

1 ]

Google Chrome?
Add the extension to your Chrome.
Restart the browser, load any webpage and click on the Save as Webpage icon which looks like:

2 ]

Mozilla Firefox?
Add the add-on to your Firefox.

Googling Tips & Tricks

“Google” has replaced the term “Search” and moreover the “Web”.
More than 90% of the people use Google to findout what they need on the web. Even though its easier to search anything in Google, Sometimes it takes time to findout the exact stuff we are looking for. Here are some tips and tricks that will help you to make your Googling easier. Discover and try these cool tricks.
Time: time India
[type time, followed by the name of your city or country. Similarly for the following ones ]
Weather: weather Bangalore
Calculator: just type the calculation to be made in the search box. For example:
5*9+(sqrt 10)^3=
Unit Conversion: You can convert different units of measurement of height, weight, volume etc. Just enter it in seachbox. For example:
10.5 cm in inches
People Profiles: You can findout your newly met friend or old-lost friends by just typing their name in the search box, plus some identifying words about him/her.
Synonym: If you want to search not only for your keywords, but also for its synonyms, place a “~” sign in front. For eg:
~smile
Dictionary Definitions: type the word define ,space your search keyword. For example:
Define mathematics  [you can also use define:mathematics]
Spell Checker : Google automatically checks for spelling and suggests the right ones. Even if you type the wrong spelling and hit search, Google will ask you “Did you mean ……. ?”
Currency Conversion: Its similar to unit conversion. For example:
150 GBP in USD
Findout more such interesting search tips and tricks at:

Resolved: “Failure configuring Windows updates. Reverting changes. Do not turn off your computer”

Operating System: Windows 8, 7
Last week, I was trying to install Windows update and it was constantly failing! Tried lot of solutions, but none of them worked. Atlast this method worked!
Here is the fix.
  1. Goto Start menu and type services.msc and select servicesFailure configuring Windows updates. Reverting changes 2
  2. In the Services, check whether “Background Intelligent Transfer Service” startup type is “Automatic”. If not double click on it and change it to automatic.Failure configuring Windows updates. Reverting changes 3
  3. Next, check whether the “Windows Update” startup type is “Automatic“. For me it was “Manual”. Change it to automatic.Failure configuring Windows updates. Reverting changes 4Failure configuring Windows updates. Reverting changes 5Failure configuring Windows updates. Reverting changes 6
  4. Check for “Workstation” startup type. It should be “Automatic“.Failure configuring Windows updates. Reverting changes 7
  5. Restart windows and install updates. It worked for me. :)

Wednesday, March 4, 2015

Fetching Data from Database and Populating fields in the Form using LINQ to SQL

STEP 1: Setting up the GUI

To get started, add a new WebForm to your application and set up the GUI. Again just for the simplicity of this demo,I just set up the GUI like this:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>LINQ to SQL Demo Part 2</title>
    <style type="text/css">
        .style1{width: 400px;}
        .style1 td {width:200px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <asp:DropDownList ID="DropDownListCustomerID" runat="server"
            AutoPostBack="true"
            onselectedindexchanged="DropDownListCustomerID_SelectedIndexChanged">
        </asp:DropDownList>
        <br />
        <table class="style1">
            <tr>
                <td>Company Name</td>
                <td><asp:TextBox ID="TextBoxCompanyName" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>Contact Name</td>
                <td><asp:TextBox ID="TextBoxContactName" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>Contact Title</td>
                <td><asp:TextBox ID="TextBoxContactTitle" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>Address</td>
                <td><asp:TextBox ID="TextBoxAddress" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>City</td>
                <td><asp:TextBox ID="TextBoxCity" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>Region</td>
                <td><asp:TextBox ID="TextBoxRegion" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>Postal Code</td>
                <td><asp:TextBox ID="TextBoxPostalCode" runat="server" ReadOnly="true"/></td>
            </tr>
            <tr>
                <td>Country</td>
                <td><asp:TextBox ID="TextBoxCountry" runat="server" ReadOnly="true"/></td>
            </tr>
        </table>
    </form>
</body>
</html>

If you notice, I set the ReadOnly attribute of each TextBox to True; this is because we don’t need users to edit the fields in the form once the TextBox is filled with data.

STEP 2: Populating the DropDownList with the list of Customers.

Now on our code behind page let’s go ahead and create the method for fetching the list of customers. Here’s the code block below:

    private List<Customer> GetCustomers(){
        using (NorthwindDataContext context = new NorthwindDataContext()){
            return (from c in context.Customers select c).ToList();
        }
    }

The code above is the LINQ syntax for querying data. It basically query the Customers object that is generated from the DataContext and then fetch the results.

Since we are done creating the method for fetching the list of customers then we can simply call that method and populate the DropDownList with the results. Typically we do this at Page_Load event within Not IsPostBack block like below:

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack) {
            DropDownListCustomerID.DataSource = GetCustomers();
            DropDownListCustomerID.DataTextField = "ContactName";
            DropDownListCustomerID.DataValueField = "CustomerID";
            DropDownListCustomerID.DataBind();
        }
    }

As you can see the code above is very straight forward and self explanatory. Running the code above will display something like below:



Let’s proceed and continue with the next Step.

STEP 3: Populating the form with Customer’s Information

The next step is we are going to populate the form with the customer information based on the CustomerID selected from the DropDownList.

Note: Since the form will be populated based on the selected item from the DropDownList then you’ll need to set up the AutoPostBack attribute to TRUE in the DropDownList so that the SelectedIndexChanged event will fire up.

Here’s the code block below for fetching the customer information based on customer ID:
    private List<Customer> GetCustomerInfo(string customerID) {
        using (NorthwindDataContext context = new NorthwindDataContext()){
            return(from c in context.Customers
                   where c.CustomerID == customerID
                   select c).ToList();
        }
    }

The code above is the LINQ syntax for querying data. As you can see we created a new instance of the DataContext and query the Customers object based on the parameter we passed on the GetCustomerInfo() method. Once we invoke the LINQ ToList() function, this LINQ query will issue a parameterize SQL query to the database in which the SQL Server can understand and then bring back the results to the DataContext.

One of the cool things about L2S is we don’t need to worry about how the query is being constructed because L2S will take care of that for you including mapping of the data types from your table columns, mapping relationships between tables, etcetera, etcetera and etcetera. Always keep in mind that L2S is an ORM (Object Relational Mapper) and so we don’t need to deal directly with databases, tables and columns but instead we deal with the objects that is in the DataContext and query the data against it using LINQ syntax.

STEP 4: Populating the Forms with Data

The next step is to populate our form with data based on the selected value from the DropDownList. To do this, we can simply call the method GetCustomerInfo() at the SelectedIndexChanged event of DropDownList like below:

    protected void DropDownListCustomerID_SelectedIndexChanged(object sender, EventArgs e) {
        var customerInfo = GetCustomerInfo(DropDownListCustomerID.SelectedValue);
        TextBoxCompanyName.Text = customerInfo[0].CompanyName;
        TextBoxContactName.Text = customerInfo[0].ContactName;
        TextBoxContactTitle.Text = customerInfo[0].ContactTitle;
        TextBoxAddress.Text = customerInfo[0].Address;
        TextBoxCity.Text = customerInfo[0].City;
        TextBoxRegion.Text = customerInfo[0].Region;
        TextBoxPostalCode.Text = customerInfo[0].PostalCode;
        TextBoxCountry.Text = customerInfo[0].Country;
    }

The code above calls the method GetCustomerInfo() and pass the selected value of the DropDownList as a parameter to that method. We then store it a customerInfo implicit typed variable and assign each TextBox with the corresponding data returned from the query.

When you run the code above and select an item in the DropDownList, you will see that the textbox fields will be populated with data based from what you have selected in the DropDownList.




That's it! I Hope someone find this post useful!

Inserting Data to Database using LINQ to SQL(L2S)

STEP 1: Creating a new Website in Visual Studio

To get started then lets go ahead and fire up Visual Studio 2008 and create a new WebSite by selecting File > New WebSite.

STEP 2: Adding a DBML file

Since we are going to use L2S then we need to add .dbml file. To do this, just right click on the application root and select Add New Item. On the template select LINQ to SQL Classes file. See below screen shot:


Now rename your dbml file the way you want it and then click OK. Note that I’m using the Northwind database for this demo and on that case I renamed the dbml file to Northwind to make it friendlier.

Now open up server explorer in Visual Studio and browse the database that you wan’t to work on (in this case the Northwind database). Just for the purpose of this example I’m going to use the Customers table from the northwind database and drag it to the Northwind.dbml design surface. See the screen shot below:


That’s simple! Isn’t it?

What happens there is that by time you drag a table in the design surface, L2S will automatically generates the Business object for you within the DataContext and let you query against it.The DataContext is the main gateway by which you retrieve objects from the database and resubmit changes. You use it in the same way that you would use an ADO.NET Connection. In fact, the DataContext is initialized with a connection or connection string you supply. The purpose of the DataContext is to translate your requests for objects into SQL queries made against the database and then assemble objects out of the results. The DataContext enables language-integrated query by implementing the same operator pattern as the standard query operators such as Where and Select

STEP 3: Setting up the GUI

Now let’s go ahead and create our form for data entry. For the simplicity of this demo, I just set up the form like below:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        .style1{width: 400px;}
        .style1 td {width:200px;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Literal ID="LiteralMessage" runat="server"></asp:Literal>
    <table class="style1">
        <tr>
            <td>Company ID</td>
            <td><asp:TextBox ID="TextBoxID" runat="server"/></td>
        </tr>
        <tr>
            <td>Company Name</td>
            <td><asp:TextBox ID="TextBoxCompanyName" runat="server"/></td>
        </tr>
        <tr>
            <td>Contact Name</td>
            <td><asp:TextBox ID="TextBoxContactName" runat="server"/></td>
        </tr>
        <tr>
            <td>Contact Title</td>
            <td><asp:TextBox ID="TextBoxContactTitle" runat="server"/></td>
        </tr>
        <tr>
            <td>Address</td>
            <td><asp:TextBox ID="TextBoxAddress" runat="server"/></td>
        </tr>
        <tr>
            <td>City</td>
            <td><asp:TextBox ID="TextBoxCity" runat="server"/></td>
        </tr>
        <tr>
            <td>Region</td>
            <td><asp:TextBox ID="TextBoxRegion" runat="server"/></td>
        </tr>
        <tr>
            <td>Postal Code</td>
            <td><asp:TextBox ID="TextBoxPostalCode" runat="server"/></td>
        </tr>
        <tr>
            <td>Country</td>
            <td><asp:TextBox ID="TextBoxCountry" runat="server"/></td>
        </tr>
    </table>
    <asp:Button ID="Button1" runat="server" Text="Save" onclick="Button1_Click" />
    </form>
</body>
</html>

STEP 4: Creating the SaveCustomerInfo() method

After setting up our GUI then let’s go ahead and create the method for inserting the data to the database using L2S. Here are the code blocks below:

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SaveCustomerInfo();
    }

    private void SaveCustomerInfo()
    {
        using (NorthwindDataContext context = new NorthwindDataContext())
        {
            //Create a new instance of the Customer object
            Customer cust = new Customer();
            //Add new values to each fields
            cust.CustomerID = TextBoxID.Text;
            cust.CompanyName = TextBoxCompanyName.Text;
            cust.ContactName = TextBoxContactName.Text;
            cust.ContactTitle = TextBoxContactTitle.Text;
            cust.Address = TextBoxAddress.Text;
            cust.City = TextBoxCity.Text;
            cust.Region = TextBoxRegion.Text;
            cust.PostalCode = TextBoxPostalCode.Text;
            cust.Country = TextBoxCountry.Text;

            //Insert the new Customer object
            context.Customers.InsertOnSubmit(cust);
            //Sumbit changes to the database
            context.SubmitChanges();

            //Display Message for successful operation
            LiteralMessage.Text = "<p style='color:Green;'>Information Successfully saved!</p>";
        }
    }
}


As you can see, the code above was very straight forward. First we have created a new instance of the DataContext which we had created on STEP 2 and wrapped it inside the “using” block; this is to ensure that the DataContext will be disposed after its processing. Second we created a new instance of the Customer object that was defined within the DataContext, this object has properties which will be filled with values that comes from the user inputs. Third we inserted a new Customer object to the Customers set and then call the context.SubmitChanges to update our database. Lastly, L2S will do the rest for you ;).

Note: The Customer and Customers set objects are automatically created once you’ve added the Customer table in the .dmbl design surface.

STEP 5: Run the code

Running the code above will look something like below on the browser:


From there we can fill in those fields with values we want. Just for this demo, notice that I have filled in those fields with a sample data. Hitting the save button will invoke the method SaveCustomerInfo() which is responsible for doing the insert operation. Now if we look at the database we can see that the data we entered was successfully being saved to the database. See the screen shot below:



Cool right? ;)