Monday, June 10, 2013

Tips for Happy Life for software developers..


  1. Drink at least 8 glasses of Water each day.
  2. Eat a good breakfast.
  3. Eat more natural food than packed and processed food. 
  4. Live life with Passion and Energy.
  5. Each day, spend 5 minutes reflecting on your day and see what did GOOD or BAD did you do today.
  6. Your Heart and Soul are your best friends. Always listen to them.
  7. Exercise at least 3 days a week. 1-2 hrs a day.
  8. Sleep well. At least 7 hours a day.  
  9. Don't compare your life to others. You have no idea what their journey is all about.
  10. Don't have negative thoughts or things you cannot control. Instead invest your energy in the positive present moment.
  11. Don't blame others for what you are today. People are in worst situations.
  12. Time is precious. No one knows how much you have. Don't waste it.
  13. Everyone has a positive and a negative side. Look for positive sides in others. Look for negative side in yourself and try to change it.
  14. Make peace with your past so it won't spoil the present.
  15. No one is in charge of your happiness but you.
  16. Just do what you supposed to do. Everything will be just fine.
  17. It takes 43 muscles to frown and 17 to smile. Just smile.
  18. Brush your teeth before you go to bed. Good teeth = Good smile.
  19. Don't delay calling your family and friends.
  20. When you are sick, your family and friends are the one you will need. Stay close to them.
  21. Each day, try to help one person in any way.
  22. Don't judge people by their work. If cleaners don't clean, you will be dirty too.
  23. Don't worry about that you cannot control.
  24. What other people think of you, it's their problem. Why do you care?
  25. Forgiveness is a high road. Adapt it.
  26. In an argument or fight, on one wins. Avoid it. Let you be the little fellow.
  27. For all good things, time is NOW. Do not delay them.
  28. For all bad things, there is always tomorrow. Leave them to tomorrow. Tomorrow never comes.
  29. Great people are same in both good and bad situations.
  30. Don't hate your boss. He has a job to do. If he is being unrealistic, let him know nicely.
  31. In business, no one is enemy. Everybody is trying to do their job. Don't take it personal.
  32. When you don't know what to do, take a break. Meet your good friends.
  33. Writing a good habit. Make a daily to do list J
  34. Do as much as you can do. If you can't, don't stress about it.
  35. Don't blame your parents for anything. You're here because of them.
  36. Before judging anyone, put yourself in their shoes.
  37. When you are down, look at people who are in worse situations.
  38. When you are up, look at people who are higher than you.
  39. Adapt good things from others.
  40. If you have any question, just ask. No question is stupid question.

Thursday, May 2, 2013

How to find total salary of each employee IN SQL??


I have a department table and i find out to total salary of each employee by department Id.

DeptId       Name      Salary
1            AA        2000 
1            AA       3000 
2            BB       1000
3            cc        1000
3            cc        4000
 
 sql query


SELECT E.DeptId,ISNULL(SUM(ES.Salary),0) AS Amt FROM Employee E
LEFT OUTER JOIN Employee ES ON E.DeptId=ES.DeptId
GROUP BY E.DeptId


 Output

DeptId             Salary
1                   5000 
2                   1000
3                   5000

How to Convert Indian Rupee to Word format

In this Articles ,I would like to show  simple function to Convert  Indian Money to word format in Indian money .
Pass the input string in function and get the value in word according to Indian rupee.

For example the input value 9,00,000  (Indian Money)  The output as follow:

Input value: 9,00,000

Output : 9 Lacs
Source Code
CREATE FUNCTION [dbo].[AmountToWords]
(
@TOTALAMOUNT varchar(max)

)

RETURNS
VARCHAR(500)
AS

BEGIN

DECLARE @AMOUNTWORD varchar(500)

DECLARE @LENGTH VARCHAR(200)=0

DECLARE
@SECONDWORD VARCHAR(200)
SET @LENGTH=(SELECT LEN(@TOTALAMOUNT))

IF
(@LENGTH=4)
BEGIN

SET
@SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))
IF
(@SECONDWORD!=00 )
SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1))+'.'+@SECONDWORD + ' Thousand'

ELSE

SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1)) + ' Thousand'
END

ELSE
IF(@LENGTH=5)
BEGIN

SET
@SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))
IF
(@SECONDWORD!=00 )
SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2))+'.'+(SELECT SUBSTRING(@TOTALAMOUNT,3,2)) + 'Thousand'
ELSE

SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2)) + ' Thousand'
END

ELSE
IF(@LENGTH=6)
BEGIN

SET @SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))

IF
(@SECONDWORD!=00 )
SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1))+'.'+@SECONDWORD + ' Lacs'
ELSE

SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1)) + ' Lacs'

END

IF(@LENGTH=7)

BEGIN

SET
@SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))
IF
(@SECONDWORD!=00 )
SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2))+'.'+(SELECT SUBSTRING(@TOTALAMOUNT,3,2)) + ' Lacs'
ELSE

SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2)) + ' Lacs'

END

ELSE
IF(@LENGTH=8)
BEGIN

SET @SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))

IF
(@SECONDWORD!=00)
SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1))+'.'+@SECONDWORD + ' Crore'

ELSE

SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1)) + ' Crore'

END

ELSE IF(@LENGTH=9)

BEGIN

SET
@SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))
IF
(@SECONDWORD!=00 )
SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2))+'.'+(SELECT SUBSTRING(@TOTALAMOUNT,3,2)) + ' Crore'

ELSE

SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2)) + ' Crore'  
END

ELSE
IF(@LENGTH=10)
BEGIN

SET @SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))

IF(@SECONDWORD!=00)

SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1))+'.'+@SECONDWORD + ' Arab'

ELSE

SET
@AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,1)) + ' Arab'  
END

ELSE IF(@LENGTH=11)

BEGIN

SET @SECONDWORD=(SELECT SUBSTRING(@TOTALAMOUNT,2,2))

IF
(@SECONDWORD!=00 )
SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2))+'.'+(SELECT SUBSTRING(@TOTALAMOUNT,3,2)) + ' Arab'

ELSE

SET @AMOUNTWORD=(SELECT SUBSTRING(@TOTALAMOUNT,1,2)) + ' Arab'

END

RETURN @AMOUNTWORD

END

Output
Select dbo.AmountToWords('900000') as Money
Output : 9 Lacs  

Sunday, April 7, 2013

Web Services Platform Elements,Why Web Services?

Web Services have three basic platform elements: SOAP, WSDL and UDDI.

SOAP?

SOAP is an XML-based protocol to let applications exchange information over HTTP. Or more simple: SOAP is a protocol for accessing a Web Service.

• SOAP stands for Simple Object Access Protocol
• SOAP is a communication protocol
• SOAP is a format for sending messages
 • SOAP is designed to communicate via Internet
 • SOAP is platform independent
 • SOAP is language independent
• SOAP is based on XML
• SOAP is simple and extensible
• SOAP allows you to get around firewalls
 • SOAP is a W3C standard

WSDL?

WSDL is an XML-based language for locating and describing Web services.
• WSDL stands for Web Services Description Language
• WSDL is based on XML
• WSDL is used to describe Web services
• WSDL is used to locate Web services
• WSDL is a W3C standard

UDDI?

 UDDI is a directory service where companies can register and search for Web services.

• UDDI stands for Universal Description, Discovery and Integration
 • UDDI is a directory for storing information about web services
• UDDI is a directory of web service interfaces described by WSDL
 • UDDI communicates via SOAP
 • UDDI is built into the Microsoft .NET platform

Introduction to Web Services

Web Services can convert your applications into Web-applications.
Web Services are published, found, and used through the Web. 

What You Should Already Know

Before you continue, you should have a basic understanding of the following:
• HTML
 • XML

What are Web Services?
• Web services are application components
• Web services communicate using open protocols
• Web services are self-contained and self-describing
• Web services can be discovered using UDDI
• Web services can be used by other applications
 • XML is the basis for Web services

How Does it Work? 
The basic Web services platform is XML + HTTP. XML provides a language which can be used between different platforms and programming languages and still express complex messages and functions. The HTTP protocol is the most used Internet protocol. Web services platform elements:
• SOAP (Simple Object Access Protocol)
• UDDI (Universal Description, Discovery and Integration)
 • WSDL (Web Services Description Language)

Wednesday, March 21, 2012

State Management


1- Querystrings: 
Using Query string variables, you can pass data between webforms. below is an example
       
     Ex: Suppose you want to pass the TextBox1.Text variable from WebForm1 to WebForm2 on button click event.
                   
                   protected void Button1_Click(object sender, EventArgs e)
                   {
                        Response.Redirect("WebForm2.aspx?id=" + TextBox1.Text);
                   }
               
                 To Read the value of "id" in WebForm2, you should use the below code
                 string queryStringID = Request.QueryString["id"];
           
                 Now queryStringID will hold the data from the querystring.




2- Cookies: 
AS you might already know, cookies are small text files stored in the client machine. Cookies can only store up to approximately 4 kbs.  Once the cookie is stored into the client machine, each request from the client to your application, the web browser will look for the cookie and send     it via the Request Object.

       
   Ex: To store a value of TextBox1.Text inside the cookie use the below code
           
                            protected void Button1_Click(object sender, EventArgs e)
                            {
                               HttpCookie cookie = new HttpCookie("UserName");
                               cookie.Value = TextBox1.Text;
                               cookie.Expires = DateTime.Now.AddDays(1);
                               Response.Cookies.Add(cookie);
                               Response.Redirect("WebForm2.aspx");
                             }
                      Now in webform2 page_load event, you should write the below code to get the value
                 
                          if(Request.Cookies["UserName"] != null)
                             Response.Write(Request.Cookies["UserName"].Value);


    3- Session Variables: By default, session variables are stored in the webserver's memory. Session variables are unique per each user.
               
  Ex: To store a value inside a session variable use the below code
           
                                            protected void Button1_Click(object sender, EventArgs e)
                                            {
                                                Session["UserName"] = TextBox1.Text;
                                                Response.Redirect("WebForm2.aspx");
                                            }

                                        To retrieve the value from WebForm2 use the below code
   
                                            Response.Write(Session["UserName"]);

    4- Cross Page Posting (ASP.NET 2.0): 
Cross page posting was introduced in ASP.NET 2.0. I already have a blog post about it.

  Ex: The same example is taken from my previous blog post  Set the Button1 PostBackUrl property to WebForm2.aspx Now in WebForm2.aspx, Write the below code to get the value of 
textbox1

   TextBox txtFirstPage = (TextBox)(PreviousPage.FindControl("TextBox1"));
  Response.Write(String.Format("You wrote {0} in Page1",txtFirstPage.Text));



    5- Submit Form: You can submit the form in Webform1.aspx to webform2.aspx. In that case, you can retrieve all the WebForm1's form element from                                                        webform2. What we will do in the below example is to add another form ( not a server side one) which will have two HTML controls; the first is an  submit control the second is a hidden field which will have the value of TextBox1 web server control to be posted to webform2
       
  Ex: now the HTML code of webform1 will look like below

                                    <form id="Form1" method="post" runat="server">
                                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                                    </form>
                                    <form name="SubmittedForm" action="WebForm2.aspx" method="post">
                                    <input id="Submit1" type="submit" value="submit" onclick="CopyTextToHiddenField()" />
                                    <input name="Hidden1" type="hidden" />
                                    </form>
       
  Of course you realized the we handled the onclick event of the submit button which will call a javascript function to copy the value of TextBox1 into    the hidden field (Hidden1) in order to post it to webform2. Also you so in the second form tag the action attribute in which we specified to which  page the second form (SubmittedForm) will be posted.
           
  Add the below javascript code inside the <head> tag of WebForm1
           
                            <script language="javascript">
                            function CopyTextToHiddenField()
                            {
                                var textbox1Value = document.getElementById("<%=TextBox1.ClientID%>").value;
                                document.forms[1].document.getElementById("Hidden1").value = textbox1Value;
                            }
                            </script>

Now you retrieve the value of "Hidden1" hidden field in webform 2 using the below code