• No results found

Helper Class

In document Windows (Page 103-113)

Public Enum ActionType Add = 1

Modify Delete End Enum

Public Class Helper

Public Shared ReadOnly Property ConnectionString() As String Get

Return ConfigurationManager.ConnectionStrings("EmpDB").ToString() End Get

End Property End Class

DB Class

Imports System.Data

Imports System.Data.SqlClient Public Class EmpDB

Public Shared Function ManageEmp(ByVal trans As SqlTransaction, ByVal objEmp As Emp,

ByVal ActionType As ActionType) As Object Dim spName As String = "spManageEmp"

Dim pActionType As New SqlParameter("@ActionType", SqlDbType.TinyInt)

Dim pPKEmpId As SqlParameter = New SqlParameter("@PKEmpId", SqlDbType.BigInt) Dim pEmpName As SqlParameter = New SqlParameter("@EmpName", SqlDbType.VarChar, 50) Dim pEmpSalary As SqlParameter = New SqlParameter("@EmpSalary", SqlDbType.Money) Dim pDateOfBirth As SqlParameter = New SqlParameter("@DateOfBirth", SqlDbType.DateTime) Dim pIsActive As SqlParameter = New SqlParameter("@IsActive", SqlDbType.Bit)

If ActionType = ActionType.Add Then pActionType.Value = ActionType.Add

pPKEmpId.Direction = ParameterDirection.Output ElseIf ActionType = ActionType.Modify Then pActionType.Value = ActionType.Modify pPKEmpId.Value = objEmp.PKEmpId ElseIf ActionType = ActionType.Delete Then pActionType.Value = ActionType.Delete pPKEmpId.Value = objEmp.PKEmpId End If

If ActionType = ActionType.Add OrElse ActionType = ActionType.Modify Then pEmpName.Value = objEmp.EmpName

pEmpSalary.Value = objEmp.EmpSalary pDateOfBirth.Value = objEmp.DateOfBirth pIsActive.Value = objEmp.IsActive End If

Dim AffectedRows As Integer = 0 If trans Is Nothing Then

AffectedRows = SqlHelper.ExecuteNonQuery(Helper.ConnectionString, CommandType.StoredProcedure,

Deccansoft Software Services – MS.NET n-Tier Arch

spName, pActionType, pPKEmpId, pEmpName, pEmpSalary, pDateOfBirth, pIsActive) Else

AffectedRows = SqlHelper.ExecuteNonQuery(trans, CommandType.StoredProcedure,

spName, pActionType, pPKEmpId, pEmpName, pEmpSalary, pDateOfBirth, pIsActive) End If

If ActionType = ActionType.Add Then Return CType(pPKEmpId.Value, Int64) Else

Return AffectedRows End If

End Function

Public Shared Function GetAllEmps(ByVal sortExpression As String) As DataSet Dim spName As String = "spGetAllEmps"

Dim psortExpression As New SqlParameter("@sortExpression", SqlDbType.VarChar, 260) Dim pPKID As New SqlParameter("@PKId", SqlDbType.BigInt)

psortExpression.Value = sortExpression

pPKID.Value = -1 'this is needed because we use that for GetByPKID

Return SqlHelper.ExecuteDataset(Helper.ConnectionString, CommandType.StoredProcedure,

spName, psortExpression, pPKID) End Function

Public Shared Function GetEmpByPKID(ByVal PKID As Int64) As Emp Dim spName As String = "spGetAllEmps"

Dim psortExpression As New SqlParameter("@sortExpression", SqlDbType.VarChar, 260) Dim pPKID As New SqlParameter("@PKID", SqlDbType.BigInt)

psortExpression.Value = ""

pPKID.Value = PKID

Dim drRow As SqlDataReader = SqlHelper.ExecuteReader(Helper.ConnectionString, CommandType.StoredProcedure, spName, psortExpression, pPKID) Dim objEmp As Emp = Nothing

If drRow.HasRows Then drRow.Read()

objEmp = New Emp(CType(drRow("PKEmpId"), Int64), CType(drRow("EmpName"), String),

CType(drRow("EmpSalary"), Decimal), CType(drRow("DateOfBirth"), Date), CType(drRow("IsActive"), Boolean)) End If

drRow.Close() Return objEmp End Function

Public Shared Function GetEmpCount() As Integer Dim spName As String = "spGetEmpCount"

Return CInt(SqlHelper.ExecuteScalar(Helper.ConnectionString, CommandType.StoredProcedure, spName)) End Function

Public Shared Sub DeleteEmpByPKIDs(ByVal PKIDs As String) Dim spName As String = "spDeleteEmpByPKIDs"

Dim pPKIDs As New SqlParameter("@PKIDs", SqlDbType.Text) pPKIDs.Value = PKIDs

SqlHelper.ExecuteNonQuery(Helper.ConnectionString, CommandType.StoredProcedure, spName, pPKIDs) End Sub

End Class

BO Class

Public Class EmpBO

Public Function InsertEmp(ByVal objEmp As Emp) As Integer

Deccansoft Software Services – MS.NET n-Tier Arch

Return EmpDB.ManageEmp(nothing, objEmp, ActionType.Add) End Function

Public Sub UpdateEmp(ByVal objEmp As Emp)

EmpDB.ManageEmp(nothing, objEmp, ActionType.Modify) End Sub

Public Sub DeleteEmp(ByVal objEmp As Emp)

EmpDB.ManageEmp(Nothing, objEmp, ActionType.Delete) End Sub

Public Function GetAllEmps(ByVal sortExpression As String) As DataSet return EmpDB.GetAllEmps(sortExpression)

End Function

Public Function GetEmpByPKID(ByVal PKID As Long) As Emp Dim objEmp As Emp = EmpDB.GetEmpByPKID(PKID) Return objEmp

End Function

Public Sub DeleteEmpByPKIDs(ByVal PKIDs As String) EmpDB.DeleteEmpByPKIDs(PKIDs)

End Sub End Class App.config

<configuration>

<connectionStrings>

<add name="EmpDB" connectionString="server=.\sqlexpress;database=EmpDB;integrated security=true" />

</connectionStrings>

</configuration>

EmpForm

Private Sub BindDataToGrid() Dim ds As DataSet

Dim objEmpBo As New EmpBO ds = objEmpBo.GetAllEmps("") gvEmp.DataSource = ds gvEmp.DataMember = "Table"

End Sub

Private Sub EmpForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load gvEmp.SelectionMode = DataGridViewSelectionMode.FullRowSelect

gvEmp.AutoGenerateColumns = False gvEmp.ReadOnly = True

BindDataToGrid() End Sub

Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click Dim dlgEmp As New EmpDialog

Deccansoft Software Services – MS.NET n-Tier Arch

If (dlgEmp.ShowDialog = Windows.Forms.DialogResult.OK) Then

Dim objEmp As New Emp(-1, dlgEmp.EmpName, dlgEmp.EmpSalary, dlgEmp.DateOfBirth, dlgEmp.IsActive) Dim objEmpBO As New EmpBO

objEmp.EmpId = objEmpBO.InsertEmp(objEmp) BindDataToGrid()

End If End Sub

Private Sub btnModify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModify.Click Dim empId As Integer

empId = CInt(gvEmp.SelectedRows(0).Cells(0).Value) Dim dlgEmp As New EmpDialog

Dim objEmpBO As New EmpBO

Dim objEmp As Emp = objEmpBO.GetEmpByPKID(empId) dlgEmp.EmpName = objEmp.EmpName

dlgEmp.EmpSalary = objEmp.EmpSalary dlgEmp.IsActive = objEmp.IsActive dlgEmp.DateOfBirth = objEmp.DateOfBirth

If (dlgEmp.ShowDialog = Windows.Forms.DialogResult.OK) Then objEmp.EmpName = dlgEmp.EmpName

objEmp.EmpSalary = dlgEmp.EmpSalary objEmp.IsActive = dlgEmp.IsActive objEmp.DateOfBirth = dlgEmp.DateOfBirth objEmpBO.UpdateEmp(objEmp)

BindDataToGrid() End If

End Sub

Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim empId As Integer

empId = CInt(gvEmp.SelectedRows(0).Cells(0).Value) Dim objEmpBO As New EmpBO

objEmpBO.DeleteEmp(empId) BindDataToGrid()

End Sub EmpDialog

Public Property EmpName() As String Get

Return txtName.Text End Get

Set(ByVal value As String) txtName.Text = value End Set

End Property

Public Property EmpSalary() As Decimal Get

Return Decimal.Parse(txtSalary.Text) End Get

Set(ByVal value As Decimal) txtSalary.Text = value.ToString End Set

End Property

Public Property DateOfBirth() As Date Get

Return dtpDOB.Value End Get

Set(ByVal value As Date) dtpDOB.Value = value

Deccansoft Software Services – MS.NET n-Tier Arch

End Set End Property

Public Property IsActive() As Boolean Get

Return chkIsActive.Checked End Get

Set(ByVal value As Boolean) chkIsActive.Checked = value End Set

End Property

Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click 'Validate data in controls

Me.DialogResult = Windows.Forms.DialogResult.OK End Sub

Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click Me.DialogResult = Windows.Forms.DialogResult.Cancel

End Sub

Window3.xml

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

x:Class="WPFApplication1.Window3" Title="Window3" Height="383" Width="423" Background="#cccccc">

<Window.Resources>

<LinearGradientBrush x:Key="lb" StartPoint="0.5,0" EndPoint="1,0.5">

<GradientStop Color="Red" Offset="0"/>

<GradientStop Color="Green" Offset="0.5"/>

<GradientStop Color="Blue" Offset="1"/>

</LinearGradientBrush>

<LinearGradientBrush x:Key="title" StartPoint="0,0.5" EndPoint="1,0.5">

<GradientStop Color="Green" Offset="0"/>

<GradientStop Color="Orange" Offset="0.5"/>

<GradientStop Color="Yellow" Offset="1"/>

</LinearGradientBrush>

<Style x:Key="body" TargetType="{x:Type TextBlock}">

<Setter Property="Foreground" Value="Yellow"/>

<Setter Property="FontSize" Value="15pt"/>

</Style>

<Style x:Key="heading" BasedOn="{StaticResource body}" TargetType="{x:Type TextBlock}">

<Setter Property="FontWeight" Value="Bold"/>

<Setter Property="Foreground" Value="Red"/>

</Style>

<XmlDataProvider Source="MyImages.xml" x:Key="MyImages" XPath="Pictures/Pic"/>

<DataTemplate DataType="Pic">

<Border Grid.RowSpan="2" BorderThickness="3" BorderBrush="Blue" HorizontalAlignment="Center" VerticalAlignment="Top">

<Image Source="{Binding XPath=@src}" Width="100" Height="100" Stretch="Fill"/>

<Border.LayoutTransform>

<RotateTransform Angle="5"/>

</Border.LayoutTransform>

</Border>

</DataTemplate>

</Window.Resources>

<Grid Background="{StaticResource lb}">

<Grid.Resources>

<Style TargetType="{x:Type Button}" x:Key="TopImage">

<Style.Triggers>

<Trigger Property="IsMouseOver" Value="True">

<Setter Property="BitmapEffect">

<Setter.Value>

<OuterGlowBitmapEffect GlowSize="6"/>

</Setter.Value>

</Setter>

</Trigger>

<TextBox.LayoutTransform>

</Grid.Resources>

<Grid.ColumnDefinitions>

<ColumnDefinition Width="Auto" />

<ColumnDefinition />

</Grid.ColumnDefinitions>

<Grid.RowDefinitions>

<RowDefinition Height="Auto" />

<RowDefinition />

</Grid.RowDefinitions>

<Border Grid.RowSpan="2" BorderThickness="3" BorderBrush="Blue" HorizontalAlignment="Center" VerticalAlignment="Top">

<Image Source="Dell.bmp" Width="100" Height="100" Stretch="Fill"/>

<Border.LayoutTransform>

<RotateTransform Angle="5"/>

</Border.LayoutTransform>

</Border>

<TextBlock Background="{StaticResource title}" Style="{StaticResource heading}" Grid.Row="0" Grid.Column="1">

This is my First WPF Demo</TextBlock>

<ScrollViewer Grid.Row="1" VerticalAlignment="Top" HorizontalAlignment="Stretch" HorizontalScrollBarVisibility="Auto"

VerticalScrollBarVisibility="Auto" Margin="0,94,0,0">

<ListBox ItemsSource="{Binding Source={StaticResource MyImages}}"></ListBox>

</ScrollViewer>

<GridSplitter HorizontalAlignment="Right" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Width="5"/>

<TextBlock Style="{StaticResource body}" Grid.Row="1" Grid.Column="1" >PlaceHolder for text</TextBlock>

<TabControl Grid.Row="1" Grid.Column="1" Margin="0,30,0,0" Name="tabControl1" Foreground="#FFFFFFFF"

BorderBrush="#FF00FFFF" BorderThickness="3,3,3,3" Background="{x:Null}">

<TabItem Header="Add/Sub">

<TabItem.Background>

<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">

<GradientStop Color="#FFF2CD14" Offset="0"/>

<GradientStop Color="#FFF21247" Offset="1"/>

<GradientStop Color="#FF4116F5" Offset="0.389"/>

<GradientStop Color="#FFF5164B" Offset="0.74"/>

<GradientStop Color="#FF4116F5" Offset="0.389"/>

</LinearGradientBrush>

</TabItem.Background>

<Grid>

<Grid.RowDefinitions>

<RowDefinition Height="Auto" />

<RowDefinition Height="0.805346977934122*" />

</Grid.RowDefinitions>

<StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="0">

<Label VerticalAlignment="Center" Content="N1"/>

<TextBox x:Name="txtN1" Text="100" Height="30" Width="30">

<SkewTransform AngleX="-20" AngleY="-20" />

</TextBox.LayoutTransform>

</TextBox>

<Label VerticalAlignment="Center" Content="N2"/>

<TextBox x:Name="txtN2" Text="10" Height="30" Width="30">

<TextBox.LayoutTransform>

<SkewTransform AngleX="-20" AngleY="-20" />

</TextBox.LayoutTransform>

</TextBox>

</StackPanel>

<Button x:Name="btnAdd" Click="Button_Click" Height="23" Grid.Row="1" VerticalAlignment="Top"

RenderTransformOrigin="0.524,3.768" Foreground="#FF54E407" Content="Add">

<Button.Background>

<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">

<GradientStop Color="#FF000000" Offset="0"/>

<GradientStop Color="#FFFFFFFF" Offset="1"/>

</LinearGradientBrush>

</Button.Background>

</Button>

<Button x:Name="btnSub" Click="Button_Click" VerticalAlignment="Top" Height="23" Margin="0,24,0,0" Grid.Row="1"

Content="Sub"/>

<Canvas RenderTransformOrigin="0.5,0.5" x:Name="MyButton" Canvas.Left="28" Canvas.Top="108" Background="#FF000000"

Margin="75.0824266355116,90.2766666666666,63.0824266355116,54.5833333333334" Grid.Row="1">

<Canvas.Triggers>

<EventTrigger RoutedEvent="FrameworkElement.Loaded">

<BeginStoryboard>

<Storyboard x:Name="Timeline1">

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyButton"

Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="-9"/>

<SplineDoubleKeyFrame KeyTime="00:00:03" Value="24"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="rectangle" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="textBlock" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[2].(RotateTransform.Angle)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>

<Rectangle Width="147" Height="65" Fill="#FF55BD4B" Stroke="#FF000000" RadiusX="24.5" RadiusY="24.5"

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.X)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.892"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[3].(TranslateTransform.Y)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="0.889"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000"

Storyboard.TargetName="rectangle1" Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="1"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyButton"

Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleX)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="8"/>

<SplineDoubleKeyFrame KeyTime="00:00:03" Value="7"/>

</DoubleAnimationUsingKeyFrames>

<DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyButton"

Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[1].(SkewTransform.AngleY)">

<SplineDoubleKeyFrame KeyTime="00:00:00" Value="13"/>

<SplineDoubleKeyFrame KeyTime="00:00:03" Value="-13"/>

</DoubleAnimationUsingKeyFrames>

<PointAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="MyButton"

Storyboard.TargetProperty="(UIElement.RenderTransformOrigin)">

<SplinePointKeyFrame KeyTime="00:00:00" Value="0.7,0.75"/>

<SplinePointKeyFrame KeyTime="00:00:03" Value="0.5,0.5"/>

</PointAnimationUsingKeyFrames>

<ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="rectangle"

Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)">

<SplineColorKeyFrame KeyTime="00:00:00" Value="#FF55BD4B"/>

<SplineColorKeyFrame KeyTime="00:00:03" Value="#FFF01010"/>

</ColorAnimationUsingKeyFrames>

</Storyboard>

</BeginStoryboard>

</EventTrigger>

</Canvas.Triggers>

<Canvas.RenderTransform>

<TransformGroup>

<ScaleTransform ScaleX="1" ScaleY="1"/>

<SkewTransform AngleX="8" AngleY="6"/>

<RotateTransform Angle="-9"/>

<TranslateTransform X="-1" Y="0"/>

</TransformGroup>

</Canvas.RenderTransform>

RenderTransformOrigin="0.5,0.5" x:Name="rectangle">

<Rectangle.RenderTransform>

<TransformGroup>

<ScaleTransform ScaleX="1" ScaleY="1"/>

<SkewTransform AngleX="0" AngleY="0"/>

<RotateTransform Angle="0"/>

<TranslateTransform X="0" Y="0"/>

</TransformGroup>

</Rectangle.RenderTransform>

</Rectangle>

<Rectangle Width="128" Height="47" Stroke="#FF000000" RadiusX="24.5" RadiusY="24.5" Canvas.Left="9"

Canvas.Top="9" RenderTransformOrigin="0.5,0.5" x:Name="rectangle1">

<Rectangle.Fill>

<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">

<GradientStop Color="#FFF21010" Offset="0"/>

<GradientStop Color="#FF0A41F2" Offset="1"/>

</LinearGradientBrush>

</Rectangle.Fill>

<Rectangle.RenderTransform>

<TransformGroup>

<ScaleTransform ScaleX="1" ScaleY="1"/>

<SkewTransform AngleX="0" AngleY="0"/>

<RotateTransform Angle="0"/>

<TranslateTransform X="0" Y="0"/>

</TransformGroup>

</Rectangle.RenderTransform>

</Rectangle>

<TextBlock Width="46.5" Height="21" Canvas.Left="47.5" Canvas.Top="22" Text="Demo" TextWrapping="Wrap"

RenderTransformOrigin="0.5,0.5" x:Name="textBlock">

<TextBlock.RenderTransform>

<TransformGroup>

<ScaleTransform ScaleX="1" ScaleY="1"/>

<SkewTransform AngleX="0" AngleY="0"/>

<RotateTransform Angle="0"/>

<TranslateTransform X="0" Y="0"/>

</TransformGroup>

</TextBlock.RenderTransform>

</TextBlock>

</Canvas>

</Grid>

</TabItem>

<TabItem Header="Tab2"><TabItem.Content>This is Content of Tab1</TabItem.Content></TabItem>

</TabControl>

APP.XML

<Application x:Class="WPFApplication1.App"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

StartupUri="Window3.xaml">

<Application.Resources>

<Style x:Key="lblStyle">

<Setter Property="Label.Background" Value="red"/>

</Style>

<Style TargetType="{x:Type Button}" x:Key="GlowButton">

<Style.Triggers>

<Trigger Property="IsMouseOver" Value="True">

<Setter Property="BitmapEffect">

<Setter.Value>

<OuterGlowBitmapEffect GlowSize="6"/>

</Setter.Value>

</Setter>

</Trigger>

</Style.Triggers>

</Style>

</Application.Resources>

</Application>

MyImages.xml

<Pictures>

<Pic title="Blue Lace 16" src="Images/Blue Lace 16.bmp" href=""/>

<Pic title="Coffee Bean" src="Images/Coffee Bean.bmp" href=""/>

<Pic title="FeatherTexture" src="Images/FeatherTexture.bmp" href=""/>

<Pic title="Gone Fishing" src="Images/Gone Fishing.bmp" href=""/>

<Pic title="Prairie Wind" src="Images/Prairie Wind.bmp" href=""/>

<Pic title="Zapotec" src="Images/Zapotec.bmp" href=""/>

</Pictures>

In document Windows (Page 103-113)