29 April 2013

State Pattern in VB.net

Today we will discuss about the State Pattern in Vb.net
Description:
    State pattern allows an object to change its behavior depending on the current values of the object. Consider the figure 'State pattern example'. It's an example of a BoxStatusoperation. If the state of the BoxStatus is off and you press the switch the BoxStatus will turn off. If the state of BoxStatus is on and you press the switch the BoxStatus will be off. So in short depending on the state the behavior changes.
Create a Class file in the Vb.net Project
Enum BoxStatus
BoxOn = 1
BoxOff = 2
End Enum
Public Shared defaultBoxstatus As BoxStatus = BoxStatus.BoxOff
Public Function displayMessage() As String
If BoxStatus.BoxOn = defaultBoxstatus Then
Return "Box is on"
Else
Return "Box is off"
End If
End Function
Public Sub Pressswitch()
If defaultBoxstatus = BoxStatus.BoxOn Then
defaultBoxstatus = BoxStatus.BoxOff
Else
defaultBoxstatus = BoxStatus.BoxOn
End If
End Sub
Dim Clas As New Class1()
Clas.Pressswitch()
MessageBox.Show(Clas.displayMessage())

26 April 2013

Get SQL Server Name in C#.net

Today we will discuss about Get SQL Server Name in C#.net
Get SQL Server Name:
 Add Three References in your Project
·         Microsoft .SqlServer.ConnectionInfo
·         Microsoft .SqlServer.management.Sdk.sfc
·         Microsoft .SqlServer.Smo


Declare namespace:


using Microsoft.SqlServer.Management.Smo;

Drag and Drop ComboBox in your form.
DataTable dataTable1 = SmoApplication.EnumAvailableSqlServers(false); cmbServerName1.ValueMember = "Name"; cmbServerName1.DataSource = dataTable1;

25 April 2013

Check Password in Vb.net

Today,we will discuss about the Password Checking using regular Expression in VB.net
Here is a Sample code for Password Checking using Regular Expression in VB.Net


Dim reg As Regex
 reg = New Regex("^(?=.*d)(?=.*[a-z])(?=.*[A-Z]).{6,10}$")
Dim mat As Match = reg.Match(TextBox1.Text)
If mat.Success = False Then
MessageBox.Show("Please enter at least one upper case letter, one lower case letter, and one numeric digit.")
TextBox1.Text = ""
End If

Use Ternary Operator in Business Layer in C#.Net

      Today we will discuss about the Ternary Operator in Business Layer in C#.Net.
Example for Ternary Operator :
Create a One Class for Business Layer called BLEmp.cs
Copy and paste in the BLEmp.cs File

Private static string _EmpName;
        public static string EmpName
{
get { return _EmpName == string.Empty ? "please Enter Name" : _EmpName; }
set
{ _EmpName = value; }
}
 
Drag and Drop TextBox and Button on the form.
Copy and Paste this code in the Button Click Event
 
BLEmp.EmpName = textBox1.Text;
MessageBox.Show(BLEmp.EmpName);

24 April 2013

State Pattern in VB.net

Today we will discuss about the State Pattern in Vb.net.
Description:
    State pattern allows an object to change its behavior depending on the current values of the object. Consider the figure 'State pattern example'. It's an example of a

Box Status operation. If the state of the Box Status is off and you press the switch the BoxStatus will turn off. If the state of BoxStatus is on and you press the switch the Box Status will be off. So

in short depending on the state the behavior changes.
Create a Class file in the Vb.net Project


Enum BoxStatus
BoxOn = 1
BoxOff = 2
End Enum
Public Shared defaultBoxstatus As BoxStatus = BoxStatus.BoxOff
Public Function displayMessage() As String
If BoxStatus.BoxOn = defaultBoxstatus Then
Return "Box is on"
Else
Return "Box is off"
End If
End Function
Public Sub Pressswitch()
If defaultBoxstatus = BoxStatus.BoxOn Then
defaultBoxstatus = BoxStatus.BoxOff
Else
defaultBoxstatus = BoxStatus.BoxOn
End If
End Sub
Dim Clas As New Class1()
Clas.Pressswitch()
MessageBox.Show(Clas.displayMessage())

Display Crystal Report title -- Programmatically in VB.net

Today , we will see the Display Crystal Report title -- Programmatically in VB.net
Here is a Code:
Create a Text Object in the Design View.
Call this code in the Crystal report viewer Load event.  

Dim cry As CrystalReport1 = New CrystalReport1()
Dim txtHeader As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtHeader") Dim txtAddress1 As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtAddress1") Dim txtAddress2 As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtAddress2") Dim txtAddress3 As CrystalDecisions.CrystalReports.Engine.TextObject = cry.Section1.ReportObjects("txtAddress3") txtHeader.Text = "IBM" txtAddress1.Text = "OMR Road" txtAddress2.Text = "Chennai" Me.CrystalReportViewer1.ReportSource = cry

Query for getting Table name from database

Today , we will discuss about getting Table name from Database
select table_name from INFORMATION_SCHEMA.tables where Table_Type='BASE TABLE'

12 April 2013

Enable/Disable date at runtime in DateTime in .Net


Today we will discuss about how to enable and disable date at runtime in DateTime in .Net Drag and Drop DateTimepicker to form. Change in the DatetimePicker:Checked: true
S.NoPro NameModify
1CustomFormatdd/MM/yyyy
2FormatCustom
3ShowCheckBoxTRUE
Run the Application 
unchecked the Check box on the DatetimePicker.
date will disable in the DatetimePicker.

checked  the Check box on the DatetimePicker.
date will enable in the DatetimePicker.

Percentage Validation and Calculation in VB.net

Today , we discussed about Percentage Validation in VB.Net
Dim RegExpression As Regex
Dim RegExpression1 As Regex
RegExpression = New Regex("^((100.00)|([1-9][0-9]|[1-9]|)(\.\d\d))$")
RegExpression1 = New Regex("^((100)|([1-9][0-9]|[1-9]|))$")
If RegExpression.IsMatch(TextBox3.Text) Or RegExpression1.IsMatch(TextBox3.Text) Then
If TextBox3.Text <> "" Then
Dim Dec As Double = CDbl(TextBox1.Text) * CDbl(TextBox3.Text) / 100
Dec = Math.Round(CDbl(Dec), 2, MidpointRounding.ToEven)
TextBox2.Text = Dec.ToString()
Dim result As Double = Math.Round(Dec, 0, MidpointRounding.AwayFromZero)
TextBox4.Text = result.ToString()
End If
Else
MsgBox("Not a match!")
TextBox3.Text = ""
TextBox3.Focus()
End If