Thursday, January 13, 2011

Class 1 - Application System & DNA Architecture

What is Application System???
System: it is combination of functional units.
Function Units: These are the necessary components for a operation which effect the target/goal.
For example:  Computer System
It has four functional units if anyone fails then system fails to achieve the goal.

Application System Functional Components
PL - Presentation Layer
BL – Business Layer/ Business Logic
DL – Data Link Layer
Presentation Layer:
User Interface called Presentation Layer. It is interface between Technical Person (Programmer)
and the Non-technical Person (User).





Technical Person tell the non technical person that how to work through their created User Interface.
If it is not correct then application is not successful.
It could be either windows forms or web forms in case of .Net.



Business Logic:

It deals in Software Development Cycle. It processes in various types of software development cycles
like water fall models etc..
Implementing business process called Business Logic.
Various types of logic available like here like:
Business Logic, Virtual Logic, Presentation Logic 

Data Link Layer:

This deals with backend databases to store the information.
This layer determined as the interaction b/w front end and back-end.
Fig 3
What is the Consumer Need?
In Current time consumer needs multiuser application. To achieve this here is few application architectures available.
That Uses DNA Architecture:
DNA (Distributed Network Architecture)
1.      1-tier
2.      2-tier
3.      3-tier
4.      N-tier

1-tier Architecture

fig 4
















It is also called Monolithic approach. It has achieved DNA but demerit is that expansion is harmful in future for mainframe.
UNIX posses 1-tier architecture.

2-tier Architecture


Work Load is distributed in two layers. It is also called FAT Server if it is distributed as:
                                                                              
What is workload???

Max Number of instructions executed per unit time period on machine.

3-tier Architecture

It this workload is divided in layers as:

N-tier Architecture
 
Each Department has their own Business logic so they are divided in sub layer as in ERP System for company.
You cannot implement all departments BL at one site. So you have to divide it in sub layers.
This is N- tier arch. In which you can divided it in n number of sub layers according to the need.
Microsoft developed COM (Common/ Communication Object Model) for N- tier architecture.
 COM is for making communication between same type of technologies e.g. Microsoft to Microsoft.


COM














For different type of technologies here is DCOM

DCOM

It is all about DNA Architecture in Software Development.
 

Wednesday, January 12, 2011

Class 2 - Visual Basic Vs .Net

Demerits of Visual Basic against .Net

Object Based Language

                It is, Even we can create classed in VB but we cannot implement Inheritance and polymorphism in it.

Development and Deployment:
Development is easy in VB but deployment is hard. It is done by MTS ( Microsoft  Transition Server) .
DLL Hell:
                 DLL (Dynamic Link Library)... You cannot run two versions of same product. E.g. Ms Office 97 and ms office 2000. Not possible to work with both of these versions at the same time.
CLI (Cross Language Interpretation):
                Conversion of VB -> Java is not possible but in .net you can translate C# to VB , VB to C# etc.
Platform Dependent:
                You can run VB programs on windows operating System only and it is physical dependent also.
Comparison of problems in VB , Java and .Net that VB have.
VB ( Problems exists )
Java
.Net
Object Based
No – it is OOPS
   NO
Development & Deployment
Yes  - it have
   NO
DLL Hell Problem
Yes – it have
   NO
Cross -Language Interpretation
 No- possible using CORBA
   NO
Platform Dependent
NO-  using JVM
   NO
.NET have MONO framework that removes its 5th Problem. .Net is much advance and good as like java. New Version of .Net will support about 100 languages.

Monday, January 10, 2011

SQL Server 2005 Installation Guide for Beginners

 Follow Steps to make a successful Sql Server 2005 installation..

Step 1.



Install Window Installer from Sql server Tools Cd.
Open redist folder and execute windows installer as
shown in Figure 2.

Figure 2



Step 2:

Now open SQL server installation CD Folder or CD
And open setup.exe to start the in installation. Figure 3

Figure 3
   
Step 3

Click the check box and click next.

Figure 4
Now click on install the prerequisites components to SQL Server. Figure 5

Figure 5

Figure 6
Now Click on Next after completing installation of components.
Select next and next until SQL Server Service Select window does
not appear Fig. 11

Figure 7
Figure 8
Figure 9

Figure 10

Step 4:
Figure 11

 Select ALL Components and click on Next, and Next Again,If you are installing SQL Server First Time on your Computer.Other wise you have to change the instance name on next window Fig 12.
Figure 12


Step 5:
Click the built –in System Account radio button to select local system. Fig 13

Figure 13
Step 6:

Choose SQL Server Login Methods

Use Mixed Mode to connect it with integrated security and User login. Best for programmers to connect with database, either with windows authentication or SQL server login.

Give your desired SQL Server sa account password. And click on Next. Fig 14
   Figure 14
Click Next and Next .. 
    Figure 15



    Figure 16



    Figure 17
Click Install to start the installation of SQL Server.
  Figure 18
 

Finish to complete the Installation..


You have done all… Happy Installation…

Saturday, January 8, 2011

URL Mapping in ASP.Net 2.0

URL mapping is often used to provide "friendly" URLs, which are URLs that are more readable and sensical
- Beverages.aspx is a "friendly" URL as it is more readable than ProductsByCategory.aspx?CategoryID=1&CategoryName=Beverages. URL mapping also is useful when restructuring a site.
Imagine that all product information was accessible through http://YourSite.com/Products/...,
but the higher-ups want the products rooted available through http://YourSite.com/Catalog/...
instead. Clearly, any users who have the old links bookmarked or linked from a website will get 404s if they visit
once the folder name change has been made. This can be mitigated by using URL mapping to map each page in
the Products folder to its corresponding page in Catalog.

ASP.Net 2.0 provides a simple way to map a long URL to a short URL with the help of tag in
Web.Config. With this feature URL rewritting becomes simple but with some big limitations.

For example,








The above config settings routes the user to the URL given in mappedUrl property and thus makes the
URL very simple and easily rememberable.
The drawback of this feature is when our websites grows drastically then maintaining this section in
config file will be tedious. To overcome this we can build a URL rewriting module using Regular expression.

Friday, January 7, 2011

How to Add Scrollbars to Div

Set its dimensions and overflow:auto in its style:
HTML Code:
<div style="width:300px;height:250px;overflow:auto;">  content goes here  </div>
Then if the content is too tall, there will be a vertical scrollbar. If the content is too wide and cannot wrap,
there will be a horizontal scrollbar.

Thursday, January 6, 2011

Custom Google Search in ASP.net





Add textbox and button for making search ..as:

Add this on web form
      <asp:TextBox id="txtSearch" runat="server" CssClass="textboxGoogle"
                    Width="168px"></asp:TextBox>&nbsp;<asp:Button
                    id="btnSearchGoogle" runat="server" Text="Search" CausesValidation="False"
                    CssClass="Button" onclick="btnSearchGoogle_Click" Width="61px"></asp:Button>



write this code on the search button

Response.Redirect("http://www.google.com/custom?domains=www.liotechnologies.com&q=" + txtSearch.Text + "&sa=Search&sitesearch=&client=pub-&forid=1&channel=91&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%3A%%3BL%3Ahttp%3A%2F%2Fwww.mysite.co m%2FImages%2FGoogle01.gif%3BS%3Ahttp%3A%2F%2Fwww.m ysite.com%3BFO1%3B&hl=en");

How to show message box in Ajax.

when we use Ajax tools in our application and then we need to show pop-up on the button click. But pop-up does not occur on the page. The problem is little bit time consuming because we can't understand easily what's going on? For that use this code.Because the solution is very simple :


Button1.Attributes.Add("onclick", "javascript:return " +
"alert('All fields are mandatory. " +
"')");

//Button1 is the ID of Button.

How to insert blank value in database when field is integer type

Suppose if you want to Insert blank value in database when field is integer type

if (roll.Text == "")
{
roll.Text = "(NULL)";

}

insert into table values('"+roll.Text+"')

Wednesday, January 5, 2011

How to remove or replace multiple special character from string using sql queries.

In FN_REMOVE_SPECIAL_CHARACTER] we make use of WITH clause CTE to store the resultset
of all special character in one row table.To remove unwanted special characters,we pass string input
values and apply string's replace funtion having special character match values from CTE table .

 
CREATE FUNCTION [FN_REMOVE_SPECIAL_CHARACTER] (  
@INPUT_STRING varchar(300))
RETURNS VARCHAR(300)
AS
BEGIN
--declare @testString varchar(100),
DECLARE @NEWSTRING VARCHAR(100)
-- set @teststring = '@san?poojari(darsh)'
SET @NEWSTRING = @INPUT_STRING ;
With SPECIAL_CHARACTER as (
SELECT '>' as item
UNION ALL
SELECT '<' as item
UNION ALL
SELECT '(' as item
UNION ALL
SELECT ')' as item
UNION ALL
SELECT '!' as item
UNION ALL
SELECT '?' as item
UNION ALL
SELECT '@' as item
UNION ALL
SELECT '*' as item
UNION ALL
SELECT '%' as item
UNION ALL
SELECT '$' as item
)
SELECT @NEWSTRING = Replace(@NEWSTRING, ITEM, '')
FROM SPECIAL_CHARACTER
return @NEWSTRING
END select dbo.[FN_REMOVE_SPECIAL_CHARACTER] ('@s()antosh')

Get Recent tweets from twitter in ASP.net

 
To do this just paste the highlighted <div> on your page. and change user id with your user id.
Here http://twitter.com/statuses/user_timeline/userid.json gets you the tweets of userid for example
here is mine niranjankala.You can set count of how many tweets you want. Here in this example,
it is 5.
 
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
      <div style="margin-right: 0px;color=black">
            <div id="twitter_div">
                <ul id="twitter_update_list"></ul>
<a href="http://twitter.com/niranjankala" id="twitter-link" style="display: block; text-align: right;">
</a>
</div>
<script src="http://twitter.com/javascripts/blogger.js" type="text/javascript">
</script>
                                                          callback=twitterCallback2&amp;count=5" type="text/javascript">
</script>
</div>
    </div>
    </form>
</body>
</html>

URL Mapping in ASP.Net 2.0

URL mapping is often used to provide "friendly" URLs, which are URLs that are more readable and sensical
- Beverages.aspx is a "friendly" URL as it is more readable than ProductsByCategory.aspx?CategoryID=1&CategoryName=Beverages. URL mapping also is useful when restructuring a site.
Imagine that all product information was accessible through http://YourSite.com/Products/...,
but the higher-ups want the products rooted available through http://YourSite.com/Catalog/...
instead. Clearly, any users who have the old links bookmarked or linked from a website will get 404s if they visit
once the folder name change has been made. This can be mitigated by using URL mapping to map each page in
the Products folder to its corresponding page in Catalog.

ASP.Net 2.0 provides a simple way to map a long URL to a short URL with the help of   <urlMappings> tag in
Web.Config. With this feature URL rewritting becomes simple but with some big limitations.

For example,

  <urlMappings>
      <add url="~/Csharp.aspx"       
           mappedUrl="~/Articles/Csharp/Default.aspx"/>
      <add url="~/ASPNet.aspx"        
           mappedUrl="~/Articles/ASPNet/Default.aspx"/>
      <add url="~/Framework.aspx"        
           mappedUrl="~/Articles/Framework/Default.aspx"/>
    </urlMappings>


The above config settings routes the user to the URL given in mappedUrl property and thus makes the
URL very simple and easily rememberable.
The drawback of this feature is when our websites grows drastically then maintaining this section in
config file will be tedious.  To overcome this we can build a URL rewriting module using Regular expression.

Encrypting QueryStrings with .NET


Once upon a time in the tech world, obscurity was security - this being most true in the early years of the industry, when there were gaping holes in privacy policies and confidential client information was bandied about from site to site without a care as to who actually could read the information.
With the new Cryptography classes in .NET, there's absolutely no excuse for not hiding even the most innocuous user data. If you ever need to 'piggy-back' information from one web page to another, whether it is within a POST or a GET parameter, you're passing clear information that anyone can sniff - and that's a bad thing.
If you're not going to use a session variable for storing end user information, you're most likely going to keep some sort of State by passing the information to a cookie or push it around with GET/POST parameters. If you're passing around any sort of ID or user information like their name, it's better to err on the side of caution and encrypt the information.

GET Vs. POST


A POST parameter keeps the information out of the URL, but it can still be sniffed quite easily as it passes in clear text across your network or the Internet. Using POST will keep the mere curious at bay, as the information is not contained in the URL - but this will not stop someone determined to snag out your data.
A QueryString parameter passes information within the site's URL. Why would you even use a QueryString? Well, maybe you need to let your user bookmark a particular page, or maybe you have to refer directly to a page in a URL via a link - you can't do either if you're using POST. A QueryString puts data in the URL for the entire world to see, so if you don't know if the end user is malicious, I'd think hard about using a QueryString for anything but site-related information.
Be smart and encrypt any and all data you're moving around from page to page, especially if that information could be used maliciously. You may trust your users, but you still need that extra level of security that clear text GET/POST data doesn't provide.
Imagine this scenario - you've been passing the customer's ID in the database around in a QueryString, in a URL that looks like this:

http://yoursite.com?cust_id=29
You know what a user is going to do? Switch that 29 to a 30 or 12 or some other number, and if you're not checking for invalid requests, you'll be dishing up some other customer's data.

Enter Encryption
What I was looking for was a quick way to encrypt and decrypt parts of a QueryString - it had to be on the fly, quick and dirty.
I chose Base64 because it wouldn't throw bizarre characters in my QueryString that I couldn't pass around… Little did I know that I'd hit a snag while passing around my encrypted QueryString - Apparently, the Request.QueryString object interprets the '+' sign as a space! So, with a quick Replace function slapped on my decrypt string, no harm, no foul.

Symmetric Key
The whole trick to this working is that the QueryString is encrypted and decrypted with the same private key. This is the secret key - if anyone gets a hold of your key, they can decrypt the data themselves, so keep it a secret!

We're going to use a hard-to-crack 8 byte key, !#$a54?3, to keep parts of our QueryString secret.

Let's Walk through the C# portion of the code:

Notice our two functions that abstract the dirty work that our Encryption64 class. The first, encryptQueryString, is used to encrypt the value of a QueryString. The second, decryptQueryString, is used to decrypt the value of an encrypted QueryString.

public string encryptQueryString(string strQueryString) {

 ExtractAndSerialize.Encryption64 oES =
new ExtractAndSerialize.Encryption64();

 return oES.Encrypt(strQueryString,"!#$a54?3");

 }

 public string decryptQueryString(string strQueryString)

 {

 ExtractAndSerialize.Encryption64 oES =
new ExtractAndSerialize.Encryption64();

 return oES.Decrypt(strQueryString,"!#$a54?3");

 }

 If we wanted to encrypt our QueryString on our first page, we could do something like this:

 string strValues = "search term";

 string strURL = "http://yoursite.com?search="
+ encryptQueryString(strValues);

 Response.Redirect(strURL);

 Inside our code-behind in our second page, we pass the contents our QueryString to a variable named strScramble. After that, we replace the '+' signs that our wonderful Request.QueryString has replaced with a space. We pass that string into our function, decryptQueryString, and retrieve the decrypted string.

 string strScramble = Request.QueryString["search"];

 string strdeCrypt = decryptQueryString(
strScramble.Replace(" ", "+"));

 Now we've decrypted the value of the QueryString, 'search', and we can do whatever we want with it. The end user is going to see a URL that looks like:
http://yoursite.com?search=da00992Lo39+343dw
They'll never be able guess what's going on in your QueryString, and if they try to fool around with it, there's no way to crack the code without knowing the Symmetric key.
VB.NET

 Imports System

 Imports System.IO

 Imports System.Xml

 Imports System.Text

 Imports System.Security.Cryptography

 Public Class Encryption64

 Private key() As Byte = {}

 Private IV() As Byte = {&H12, &H34, &H56, &H78, &H90, &HAB, &HCD, &HEF}



Public Function Decrypt(ByVal stringToDecrypt As String, _
ByVal sEncryptionKey As String)

                                                                                                As String

 Dim inputByteArray(stringToDecrypt.Length) As Byte

 Try

 key = System.Text.Encoding.UTF8.GetBytes(Left(sEncryptionKey, 8))

 Dim des As New DESCryptoServiceProvider()

 inputByteArray = Convert.FromBase64String(stringToDecrypt)


Dim ms As New MemoryStream()


Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), _
CryptoStreamMode.Write)

 cs.Write(inputByteArray, 0, inputByteArray.Length)

 cs.FlushFinalBlock()


Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8


Return encoding.GetString(ms.ToArray())


Catch e As Exception


Return e.Message


End Try


End Function



Public Function Encrypt(ByVal stringToEncrypt As String, _
ByVal SEncryptionKey As String) As String


Try


key = System.Text.Encoding.UTF8.GetBytes(Left(SEncryptionKey, 8))


Dim des As New DESCryptoServiceProvider)


Dim inputByteArray() As Byte = Encoding.UTF8.GetBytes( _
stringToEncrypt)

 Dim ms As New MemoryStream()


Dim cs As New CryptoStream(ms, des.CreateEncryptor(key, IV), _
CryptoStreamMode.Write)


cs.Write(inputByteArray, 0, inputByteArray.Length)


cs.FlushFinalBlock()


Return Convert.ToBase64String(ms.ToArray())


Catch e As Exception


Return e.Message


End Try


End Function



End Class


Tuesday, January 4, 2011

Casting of object and Role of 'is' and 'as' keyword

In this post, I am going to discuss about the casting of object form one type to another type and what the
Things required to be kept in mind when casting object.

Casting basically takes place when we are relating between classes I.e. INHERITANCE. Classes have
A parent child relationship, I.e. Is-a relationship between them. To understand it, take an example of the
Below diagram:
As show in the above image, Employee and Manager are having is-a relationship with person
, I.e., inherited from person class.Now I have one method in my main class which takes
Employee as argument and does processing on the property of the class.
Public void ProcessData(Person p)
{
....process data
Console.WriteLine(p.ToString());
}

Implicit Conversion

Implicit conversion takes place when there is an is-a relation between two classes, I.e., inherited from other.
As per the diagram,
Employee is Inherited from Person class and so that as per OOD rule, there is
No need to convert
Employee class to Person class.

Example:

Public void testdata()
{
Employee emp = new Employee();
emp.Age = 25;
emp.BirthDate = DateTime.Now;
emp.Height = "5 ' 3";
emp.salary = 2000;
emp.type = 1;
ProcessData(emp);
}
When you compile and run the code, there is no error because it is Implicit conversion from child to parent.

Explicit Conversion

Where there is no relation between classes and if you want to pass the object of another type to method,
Then you need to convert it explicitly.

Example

Consultant cons = new Consultant();  cons.Age = 25;  ....
Object obj = cons;  ProcessData((Employee) obj);

Note

The above code does not give any kind of compiler error, but it throws runtime
InvalidCastException if it is not able to cast to the type.
Following is solution to avoid InvalidCastException at runtime because of Explicit conversion.

Solution 1

Catch the exception and handle it.
Consultant cons = new Consultant();
cons.Age = 25;  
....
Try
{
ProcessData((Employee) cons);  
}
catch(InvalidCastException ex)
{
... Process exception
}

Solution 2

Make use of 'as' keyword of C#. It does conversion from one object to another object and returns Null
If it is not able to convert. Use it when you want to convert object from one type to another object.

Syntax

Type t =expression as type;

Example

Employee emp = new Employee();
Person p = emp as Person;
if(p!=null)
{    .. Process data   }
else
   {
.. Display error message or do another code
}

Solution 3

Make use of 'is' keyword of C#. It does conversion from one object to another object and returns
False if it is not able to convert. Use it when you want to check whether it is convertible or not.

Syntax

Type t = expression is type

Example

Employee emp = new Employee();
if(emp is Person)
{
Person p = (Person)emp;
.. Process data
}
else
   {
.. Display error message or do another code
}

Difference between as and is

  • As operator does conversion form one type to another type and returns Null if conversion fails.
    There is no need for conversion again if it's convertible as shown in the example code.

  • Is operator checks whether one object is convertible to another type or not and returns false
    If not. So you need to convert object to base type if it is convertible as shown in the example code.

Summary

'is' and 'as' keywords play an important role when we do the casting of the related objects explicitly. But you need to use it according to the situation.

Bind Enum to Dropdown List With Sorting

/*    Create Enum Data Block First */

public enum DignosisOrderType
    {
        All = 0,
        General = 1,
        Uveitis = 2,
        Coag = 3,
        PreOp = 4,
        Tests = 5,
        RP = 6     }  
      /*   Now Creat a method to bind this drop download- pass control and Enum Data to
        function */        

    public static void BindDropDownByEnum(ref DropDownList dropDownList,
                        Type enumDataSource)
    {
        DataTable dtTemp = new DataTable();  /*create datatable and follow the steps of
                                               ADO to bind with dropdown list */
        dtTemp.Columns.Add("ID");
        dtTemp.Columns.Add("Name");
        string[] names = Enum.GetNames(enumDataSource);
        Array values = Enum.GetValues(enumDataSource);
        for (int i = 0; i < names.Length; i++)        
        {
            DataRow drTemp = dtTemp.NewRow();
            drTemp["ID"] = Convert.ToInt32((DignosisOrderType)Enum.Parse
                        (typeof(DignosisOrderType), names[i])).ToString();
            drTemp["Name"] = names[i];
            dtTemp.Rows.Add(drTemp);
        }
        DataView dvTemp = new DataView(dtTemp);
        dvTemp.Sort = "Name";
        dropDownList.DataTextField = "Name";
        dropDownList.DataValueField = "ID";
        dropDownList.DataSource = dvTemp;
        dropDownList.DataBind();
      
    }
Call Above Method
BindDropDownByEnum(ref DropDownList1, typeof(DignosisOrderType));