Monday, July 28, 2008

SQL Stored Procedure,Triggers, Cursors.

Stored Procedure:
Pre-Compiled set of SQL Statments..
Increases Performance
Reduces Network Traffic

Syntax:
Create Procedure Proc_name(param list)
As
Begin
// SQL Statements
End


Trigger:
Equivalent to event raising, ie, doing certain action based on events like insert, update...

syntax:
create trigger trg_name
As
begin
// sql statements
end

Cursor:
cursors are used when row by row processing is needed.
syntax
DECLARE cur_name CURSOR
FOR
SELECT username
FROM table

OPEN cur_name

FETCH NEXT FROM cur_name
INTO @usrID

WHILE @@FETCH_STATUS = 0
BEGIN

FETCH NEXT FROM cur_nmae
INTO @usrID

END

CLOSE cur_name
DEALLOCATE cur_name

Wednesday, July 23, 2008

Create A VB InputBox in C#

The below link will help out to know about the Inputbox in C#:

http://www.knowdotnet.com/articles/inputbox.html

Sunday, July 20, 2008

Object Oriented Architecture Modeling

Why architecture with OO methods?
OO methods provide a set of techniques for analyzing, decomposing, and modularizing software system architectures. In general, OO methods are characterized by structuring the system architecture on the basis of its objects (and classes of objects) rather than the actions it performs
Main purpose of these design concepts is to manage software system complexity by improving software quality factors. This provides the following benefits
• Helps to focus on large-scale system design
• Separation of design concerns
• Can identify good domain-specific architectures
• Design abstraction
• Have a common language
o Managerial basis for cost estimation & process mgmt
o Reuse
o Consistency and dependency analysis
o Technical basis for design

OO Modeling of an Solution:
• Identifying Objects of Interest from the Model
• Associating Attributes with Objects of Interest
• Specify how the objects, and interactions and interrelationships among the objects, will effect a solution to the problem

Types Model
(a) Textual Models
These are textual descriptions of both individual objects and systems of objects.

(b) Graphical Models
These graphically represent the characteristics of individual objects or systems of objects.

(c) Class-Responsibility-Collaboration Cards (CRC Cards)

Where do Objects come from?
The following are potential sources of objects:
• The model itself, e.g.:
o Written documents
paragraph, the nouns, pronouns, noun phrases, adjectives, adjectival phrases, adverbs, and adverbial phrases will suggest candidate objects.
o Graphical model certain objects may be implied by such things as nodes and communication among the nodes.
• The information supplied by the OORA(Object Oriented Requirement Analysis) process
• The mind of the software engineer
• A study of existing objects in an object library
• Technical references, e.g., books and articles

Object Modeling using UML
There are three prominent aspects of the modeled system that are handled by UML:

• Functional Model
It describes the functionality of the system from the user's Point of View.
It’s through Use Case Diagrams.
• Object Model
It showcases the structure and substructure of the system using objects, attributes, operations, and associations.
It’s through Class Diagrams.
• Dynamic Model
It showcases the internal behavior of the system.
It’s through Sequence Diagrams, Activity Diagrams and Statechart Diagrams

Use Case model
• Provide an overview of all or part of the usage requirements for a system or organization in the form of an model or a business model
• Communicate the scope of a development project
• Model the analysis of the usage requirements in the form of a system use case model

Use Cases are used primarily to capture the high level user-functional requirements of a system. The Use Case model is about describing “what” the system will do at a high-level and with a user focus for the purpose of scoping the project and giving the application some structure.

Class Diagram
It shows the classes of the system, their inter-relationships, and the operations and attributes of the classes. Class diagrams are used to:
• Explore domain concepts in the form of a domain model
• Analyze requirements in the form of a conceptual/analysis model
• Depict the detailed design of object-oriented or object-based software

Object Sequence Diagram
Object Sequence Diagrams are about deciding and modeling HOW our system will achieve WHAT we described in the Use Case model.
It’s a dynamic modeling technique. UML sequence diagrams are typically used to:
• Validate and flesh out the logic of a usage scenario.
• Explore the design because they provide a way to visually step through invocation of the operations defined by the classes.
• To detect bottlenecks within an object-oriented design. By looking at what messages are being sent to an object, and by looking at roughly how long it takes to run the invoked method, you quickly get an understanding of where need to change the design to distribute the load within the system. In fact some CASE tools even enable to simulate this aspect of the software.
• Gives a feel for which classes in the application are going to be complex, which in turn is an indication that may need to draw state chart diagrams for those classes

Activity Diagram
This is used to explore the logic of the following
• A complex operation
• A complex business rule
• A single use case
• Several use cases
• A business process
• Software processes

Deployment Diagram
Deployment diagrams show the hardware for the system, the software that is installed on that hardware, and the middleware used to connect the disparate machines to one another. A deployment model is to:

• Explore the issues involved with installing the system into production.
• Explore the dependencies that your system has with other systems that are currently in, or planned for, the production environment.
• Depict a major deployment configuration of a business application.
• Design the hardware and software configuration of an embedded system.
• Depict the hardware/network infrastructure of an organization.

Disable the Right click option in the Webpage

1. write the below function in the script tag:
function click(e)
{
if (document.all)
{
if (event.button==2event.button==3)
{
oncontextmenu='return false';
}
}
if (document.layers)
{
if (e.which == 3)
{
oncontextmenu='return false';
}
}
}
if (document.layers)
{
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;
function handleKeyDown()
{
if (window.event.keyCode == 116)
{
event.keyCode=0;
event.returnValue=false;
}
}
document.onkeydown = handleKeyDown;

2. In Body Tag:

call the funtion in the events as follows:
oncontextmenu="return false"
ondragstart="return false"
onselectstart="return false"


3. write this inside the script tag:

function click(e) {
if (document.all) {
if (event.button==2event.button==3) {
oncontextmenu='return false';

}
}

if (document.layers) {
if (e.which == 3) {
oncontextmenu='return false';
}
}
}

if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;

function handleKeyDown() {
if (window.event.keyCode == 116) {
event.keyCode=0;
event.returnValue=false;
}
}
document.onkeydown = handleKeyDown;

Friday, July 18, 2008

What's the difference between char,nvarchar,ntext and nvarchar(max) ? (SQL2005)

see the below link:

http://geekswithblogs.net/claeyskurt/archive/2006/02/04/68161.aspx

SQL Server : Sum of 2 querries which has already sum function

There are 2 ways for summing the 2 sub querries:
Method : 1
select
(select SUM(substring(SP_Product, 5, 2) * SP_Opening) AS Muliplied from tblStock_Packed_Factory
where SP_Oil = 'Cocounut'and SP_Product like '%kg' and Len(SP_Product)=8 )
+
(select SUM(substring (SP_Product, 5, 3) * SP_Opening) AS Muliplied from tblStock_Packed_Factory
where SP_Oil = 'Cocounut'and SP_Product like '%kg' and Len(SP_Product)=9 ) AS Muliplied
------------
Method: 2
select Sum(tmp.Muliplied) As Muliplied
From (
select SUM(substring (SP_Product, 5, 2) * SP_Opening) AS Muliplied from tblStock_Packed_Factory
where SP_Oil = 'Cocounut'and SP_Product like '%kg' and Len(SP_Product)=8
union
select SUM(substring (SP_Product, 5, 3) * SP_Opening) AS Muliplied from tblStock_Packed_Factory
where SP_Oil = 'Cocounut'and SP_Product like '%kg' and Len(SP_Product)=9 ) as tmp

Deleting the listbox selected value through Javascript

Javascript:
function removeOptions(selectbox)
{
var i;
for(i=selectbox.options.length-1;i>=0;i--)
{
if(selectbox.options[i].selected)
selectbox.remove(i);
}
}

HTML:








Thursday, July 17, 2008

Reading the Mails from the Outlook 2003 using C# .NET

The following demostrates how to retreive data from items within an Outlook folder (called "MySubFolderName" under the Inbox folder) using .NET:

First add a reference to the Outlook COM object your project:

1. In VS.NET right click on References and choose Add Reference.
2. Select the COM tab Choose "Microsoft Outlook 11.0 Object Library" (this is for MS Office 2003 - I think 10.0 is for Office XP) and click Select.
3. Click OK.
Note that you can access any Outlook/Exchange object types, eg Appointments, Notes, Tasks, Emails etc - just use intellisense to select which one (eg Microsoft.Office.Interop.Outlook. ... - see definition of variable called 'item' below).

Here's the code:

Microsoft.Office.Interop.Outlook.Application app = null;
Microsoft.Office.Interop.Outlook._NameSpace ns = null;
Microsoft.Office.Interop.Outlook.PostItem item = null;
Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;

try
{
app = new Microsoft.Office.Interop.Outlook.Application();
ns = app.GetNamespace("MAPI");
ns.Logon(null,null,false, false);

inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
subFolder = inboxFolder.Folders["MySubFolderName"]; //folder.Folders[1]; also works
Console.WriteLine("Folder Name: {0}, EntryId: {1}", subFolder.Name, subFolder.EntryID);
Console.WriteLine("Num Items: {0}", subFolder.Items.Count.ToString());

for(int i=1;i<=subFolder.Items.Count;i++)
{
item = (Microsoft.Office.Interop.Outlook.PostItem)subFolder.Items[i];
Console.WriteLine("Item: {0}", i.ToString());
Console.WriteLine("Subject: {0}", item.Subject);
Console.WriteLine("Sent: {0} {1}" item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
Console.WriteLine("Categories: {0}", item.Categories);
Console.WriteLine("Body: {0}", item.Body);
Console.WriteLine("HTMLBody: {0}", item.HTMLBody);
}
}
catch (System.Runtime.InteropServices.COMException ex)
{
Console.WriteLine(ex.ToString());
}
finally
{
ns = null;
app = null;
inboxFolder = null;
}

Note:If the Problem comes then change the PostItem into MailItem

Programmatically Complete PDF Form Fields using VB and the iTextSharp DLL

Use the below link to get the Idea:

http://www.vbdotnetheaven.com/UploadFile/scottlysle/PdfGenVB06162007031634AM/PdfGenVB.aspx

Caching in ASP .NET

ASP.NET supports multiple levels of caching:
1. Output caching
2. Fragment caching
3. Data caching


Benefits:
Can increase performance by reducing trips to the database


Challenges:
Requires correct design and enough memory to be effective


ASP.NET provides built-in caching support that enables re-use of work:
1. Full Page Caching (Vary by params, language, user-agent)
2. Partial Page Caching (Enables portions of pages to be cached)
3. Web Service Caching (Vary by parameters and methods)
4. Cache Engine: Extensible Cache API (Enables arbitrary objects to be cached)

Cache Dependencies:
1. File Based dependencies
2. Key Based dependencies
3. Time Based dependencies

How to do Caching:
Cache the content of an entire ASP.NET page
–Declarative:
<%@ OutputCache Duration="60" VaryByParam="None"%>
–Programmatic:
•Response.Cache.SetExpires(DateTime.Now.AddSeconds(60))
•Response.Cache.SetCacheability(HttpCacheability.Public)
•Response.Cache.SetSlidingExpiration(True)

Example of Output Cache:
<%@ OutputCache Duration="20" VaryByParam="none" %>

Output Cache

Now :<%= Now() %>


The content of the page will be same till 20 Sec.
of the creation of cache of this output.





Tuesday, July 1, 2008

Javascript : To check the URL Validation







URL:





Finding the Control in the Grid

To find the control whether is existing in the grid:
----------------------------------------------------

TextBox txtcomments;
txtcomments=(TextBox)e.Item.FindControl("txtcomments");
txtcomments.Attributes.Add("Onchange","javascript:fncallcheck("+txtcomments.ClientID+")");

String Array

For String array:
------------------

string[] strhistry = (string[])childdr["fldWFHistory"];

Place Holder

For Place Holder:
------------------

StringBuilder str = new StringBuilder();
str.Append("");
str.Append("strhistry[i].ToString()");
placecomments.Controls.Add(new LiteralControl(str.ToString()));

Formating the Date in C# .NET

The Date mm/dd/yyyy Can be changed in to dd/mm/yyyy using the below format:

String.Format("{0:dd/MM/yyyy}",Convert.ToDateTime("12/20/2008"));