SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Sample 1 (Data Modeling and User Interface Design):
Sample 2 (SQL INSERT Stored Procedure):
GO
/****** Object: StoredProcedure [dbo].[GetMemberByItem]        Script Date:
01/22/2008 14:33:53 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:         <Author,,Nii Amah Hesse>
-- Create date: <Create Date,,12/20/2007>
-- Description:    <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[GetMemberByItem]
      -- Add the parameters for the stored procedure here
@isbn int
,@copy_no smallint
AS
IF NOT EXISTS
(SELECT * FROM dbo.copy WHERE isbn = @isbn AND copy_no = @copy_no)
BEGIN
      RETURN -17         --ItemNotFound
END
IF NOT EXISTS
(SELECT member_no FROM dbo.loan WHERE isbn = @isbn AND copy_no = @copy_no)
BEGIN
      RETURN -19         --ItemNotOnLoan
END
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
SET NOCOUNT ON;

     -- Insert statements for procedure here
IF EXISTS
(SELECT a.member_no FROM dbo.adult AS a
INNER JOIN dbo.loan AS l
ON a.member_no = l.member_no
WHERE l.isbn = @isbn AND l.copy_no = @copy_no)
       BEGIN
             SELECT
m.member_no
,m.lastname
,m.firstname
,m.middleinitial
,a.street
,a.city
,a.state
,a.zip
,a.phone_no
,a.expr_date
FROM dbo.member AS m
INNER JOIN dbo.adult AS a
ON m.member_no = a.member_no
INNER JOIN dbo.loan AS l
ON m.member_no = l.member_no
WHERE l.isbn = @isbn AND l.copy_no = @copy_no
       END
ELSE
SELECT
m.member_no
,m.lastname
,m.firstname
,m.middleinitial
,a.street
,a.city
,a.state
,a.zip
,a.phone_no
,a.expr_date
,j.adult_member_no
,j.birth_date
FROM dbo.juvenile AS j
INNER JOIN dbo.adult AS a
ON j.adult_member_no = a.member_no
INNER JOIN dbo.member AS m
ON m.member_no = j.member_no
INNER JOIN dbo.loan AS l
ON l.member_no = j.member_no
WHERE l.isbn = @isbn AND l.copy_no = @copy_no
IF @@error <> 0
       BEGIN
              RETURN -18 --NoSuchMember
       END
END

                           Sample 3 (C# Regular Expressions):

private void ZipCodeTextBox_Validating(object sender, CancelEventArgs e)
{Regex zipExp = new Regex(@"^d{5}$");
if (!zipExp.IsMatch(((Control)sender).Text))
{Regex zipExp2 = new Regex(@"^d{5}(-d{4})$");
if (!zipExp2.IsMatch(((Control)sender).Text))
{errorProvider1.SetError(ZipCodeTextBox, "ZipCode format: ##### or #####-####");
e.Cancel = true;}}}

                           Sample 4 (C# Error File Logging):

private void PrintError(string myErrorMessage, SystemException se)
{
string mydatetime = "Date" + DateTime.Today.Year.ToString();
mydatetime = mydatetime + "_" + DateTime.Today.Month.ToString();
mydatetime = mydatetime + "_" + DateTime.Today.Day.ToString();
mydatetime = mydatetime + "Time" + DateTime.Now.Hour.ToString();
mydatetime = mydatetime + "_" + DateTime.Now.Minute.ToString();
mydatetime = mydatetime + "_" + DateTime.Now.Second.ToString();
string myfile = @"C:error_" + mydatetime + ".txt";
StreamWriter sw = File.CreateText(myfile);
sw.WriteLine("Error Date: " + DateTime.Today.ToShortDateString());
sw.WriteLine("Error Time: " + DateTime.Now.ToLongTimeString());
sw.WriteLine("Custom Message: " + myErrorMessage);
sw.WriteLine("Message: " + se.Message);
sw.WriteLine("Source: " + se.Source);
sw.Close();
}

                   Sample 5 (C#/ADO.NET: Get Member Method):
#region GetMember Method
public Member GetMember(int isbn, short copyNumber)
        {
            SqlConnection libCon = null;
            SqlCommand libCommand = null;
            SqlDataReader libReader = null;
            try
            {
                //sets the connection string
                libCon = new SqlConnection();
                libCon.ConnectionString =
Properties.Settings.Default.LibraryConnection;

                libCommand = new SqlCommand();

                libCommand.CommandType = CommandType.StoredProcedure;
                libCommand.CommandText = "GetMemberByItem";
                libCommand.Connection = libCon;

                libCommand.Parameters.Add(new SqlParameter("@isbn",
SqlDbType.Int));
                libCommand.Parameters[0].Value = isbn;
                libCommand.Parameters.Add(new SqlParameter("@copy_no",
SqlDbType.SmallInt));
                libCommand.Parameters[1].Value = copyNumber;
                libCommand.Parameters.Add("@ReturnVal",
SqlDbType.SmallInt).Direction = ParameterDirection.ReturnValue;

                libCon.Open();

                //this runs the Stored Proc
                libReader = libCommand.ExecuteReader();

                AdultMember elder = new AdultMember();
                JuvenileMember youth = new JuvenileMember();
                bool adult = true;

                object[] allFields = new object[libReader.FieldCount];

                while (libReader.Read())
                {
                    //juvenile member
                    if (allFields.Length > 10)
                    {
                         youth.AdultMemberID =
(short)libReader["adult_member_no"];
                         youth.BirthDate = (DateTime)libReader["birth_date"];
                         youth.City = libReader["city"].ToString();
                         youth.ExpirationDate = (DateTime)libReader["expr_date"];
                         youth.FirstName = libReader["firstname"].ToString();
                         youth.LastName = libReader["lastname"].ToString();
                         youth.MemberID = (short)libReader["member_no"];
                         youth.MiddleInitial =
libReader["middleinitial"].ToString();
                         youth.PhoneNumber = libReader["phone_no"].ToString();
                         youth.State = libReader["state"].ToString();
                         youth.Street = libReader["street"].ToString();
                         youth.ZipCode = libReader["zip"].ToString();
                         adult = false;
                    }
                    else
                    {
                         elder.City = libReader["city"].ToString();
elder.ExpirationDate = (DateTime)libReader["expr_date"];
                          elder.FirstName = libReader["firstname"].ToString();
                          elder.LastName = libReader["lastname"].ToString();
                          elder.MemberID = (short)libReader["member_no"];
                          elder.MiddleInitial =
libReader["middleinitial"].ToString();
                          elder.PhoneNumber = libReader["phone_no"].ToString();
                          elder.State = libReader["state"].ToString();
                          elder.Street = libReader["street"].ToString();
                          elder.ZipCode = libReader["zip"].ToString();
                     }
                }
                if (Convert.ToInt16(libCommand.Parameters["@ReturnVal"].Value) !
= 0)
                {
                     LibraryException ex = new LibraryException();
                     ex =
ex.ErrCodeGenerator(Convert.ToInt16(libCommand.Parameters["@ReturnVal"].Value));
                     if (ex.OtherMemberID > 0)
                     {
                          throw new LibraryException(ex.LibraryErrorCode,
ex.OtherMemberID);
                     }
                     else
                     {
                          throw new LibraryException(ex.LibraryErrorCode);
                     }
                }
                if (adult == true)
                {
                     return elder;
                }
                else
                {
                     return youth;
                }
            }
            catch (LibraryException ex)
            {
                if (ex.OtherMemberID > 0)
                {
                     throw new LibraryException(ex.LibraryErrorCode,
ex.OtherMemberID);
                }
                else
                {
                     throw new LibraryException(ex.LibraryErrorCode);
                }
            }
            finally
            {
                //Close Connection
                if (!libReader.IsClosed)
                {
                     libReader.Close();
                }
                if (libCon.State != ConnectionState.Closed)
                {
                     libCon.Close();
                }
            }
        }
#endregion


                     Sample 6 (Web Service Web Config (XML)):
<?xml version="1.0" encoding="utf-8"?>
<!--
     Note: As an alternative to hand editing this file you can use the
     web admin tool to configure settings for your application. Use
     the Website->Asp.Net Configuration option in Visual Studio.
     A full list of settings and comments can be found in
     machine.config.comments usually located in
     WindowsMicrosoft.NetFrameworkv2.xConfig
-->
<configuration>
  <configSections>
     <section name="microsoft.web.services3"
type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
  </configSections>
  <appSettings />
  <connectionStrings>
     <add name="library" connectionString="Data Source=localhost;Initial
Catalog=library;Integrated Security=True" />
  </connectionStrings>
  <system.web>
     <!--
              Set compilation debug="true" to insert debugging
              symbols into the compiled page. Because this
              affects performance, set this value to true only
              during development.
          -->
     <compilation debug="true">
       <assemblies>
          <add assembly="Microsoft.Web.Services3, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
       </assemblies>
     </compilation>
     <!--
              The <authentication> section enables configuration
              of the security authentication mode used by
              ASP.NET to identify an incoming user.
          -->
     <authentication mode="Windows" />
     <!--
              The <customErrors> section enables configuration
              of what to do if/when an unhandled error occurs
              during the execution of a request. Specifically,
              it enables developers to configure html error pages
              to be displayed in place of a error stack trace.

        <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm">
            <error statusCode="403" redirect="NoAccess.htm" />
            <error statusCode="404" redirect="FileNotFound.htm" />
                  -->
        <customErrors mode="On" />
    <webServices>
      <soapExtensionImporterTypes>
        <add type="Microsoft.Web.Services3.Description.WseExtensionImporter,
Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35" />
      </soapExtensionImporterTypes>
      <soapServerProtocolFactory
type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3,
Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </webServices>
  </system.web>
  <microsoft.web.services3>
    <policy fileName="wse3policyCache.config" />
    <diagnostics>
      <trace enabled="false" input="InputTrace.webinfo"
output="OutputTrace.webinfo" />
    </diagnostics>
    <security>
      <x509 verifyTrust="true" allowTestRoot="true" />
    </security>
  </microsoft.web.services3>
</configuration>




                            Sample 7 (XML Web Page):
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="CheckIn.aspx.cs"
Inherits="LibraryWebClient_CheckIn" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<br />
    <asp:Label ID="lblIsbn" runat="server" Font-Size="Medium" Text="ISBN"
Width="100px"></asp:Label>
    <asp:TextBox ID="txtIsbn" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvIsbn" runat="server"
ControlToValidate="txtIsbn"
        ErrorMessage="ISBN is Required" Font-Size="Medium" Width="35px">!
</asp:RequiredFieldValidator>
    <asp:RangeValidator ID="revIsbn" runat="server" ControlToValidate="txtIsbn"
ErrorMessage="ISBN must be an Integer"
        Font-Size="Medium" MaximumValue="32767" MinimumValue="1" Type="Integer"
        Width="26px">*</asp:RangeValidator><br />
    <asp:Label ID="lblCopyNumber" runat="server" Font-Size="Medium" Text="Copy
Number"
        Width="100px"></asp:Label>
    <asp:TextBox ID="txtCopyNumber" runat="server"></asp:TextBox>
    <asp:RequiredFieldValidator ID="rfvCopyNumber" runat="server"
ControlToValidate="txtCopyNumber"
        ErrorMessage="Copy Number is Required" Font-Size="Medium" Width="31px">!
</asp:RequiredFieldValidator>
    <asp:RangeValidator ID="revCopyNumber" runat="server"
ControlToValidate="txtCopyNumber"
        ErrorMessage="Copy Number Must be between 1 and 32767" Font-
Size="Medium" MaximumValue="32767"
        MinimumValue="1" Type="Integer" Width="28px">*</asp:RangeValidator><br /
>
    <br />
    <asp:TextBox ID="lblStatusText" runat="server" BackColor="Silver"
BorderColor="Silver"
        BorderStyle="None" Font-Bold="True" ReadOnly="True"
Width="733px"></asp:TextBox><br />
    <asp:Button ID="btnOk" runat="server" OnClick="Button1_Click" Text="Ok"
Width="87px" />
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
    <asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click"
Text="Cancel"
        Width="87px" PostBackUrl="~/LibraryWebClient/GetMemberInfo.aspx"
CausesValidation="False" /><br />
    <asp:Button ID="btnYes" runat="server" Enabled="False"
OnClick="btnYes_Click" Text="Yes"
        Visible="False" Width="87px" />
    &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<asp:Button ID="btnNo"
runat="server" Enabled="False"
        OnClick="btnNo_Click" Text="No" Visible="False" Width="87px" /><br />
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" Font-
Size="Medium" />
    <br />
    <br />
</asp:Content>

Weitere ähnliche Inhalte

Was ist angesagt?

Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8XSolve
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design PrinciplesJon Kruger
 
jrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeusjrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeusTakeshi AKIMA
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascriptDoeun KOCH
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency InjectionRifat Nabi
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기Arawn Park
 
Realm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app databaseRealm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app databaseSergi Martínez
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHPmarkstory
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJsHenri Binsztok
 
Design Patterns in PHP5
Design Patterns in PHP5 Design Patterns in PHP5
Design Patterns in PHP5 Wildan Maulana
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...go_oh
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScripttaobao.com
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRaimonds Simanovskis
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBOren Eini
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserHoward Lewis Ship
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkG Woo
 

Was ist angesagt? (19)

Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8Xlab #1: Advantages of functional programming in Java 8
Xlab #1: Advantages of functional programming in Java 8
 
Json perl example
Json perl exampleJson perl example
Json perl example
 
Solid Software Design Principles
Solid Software Design PrinciplesSolid Software Design Principles
Solid Software Design Principles
 
jrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeusjrubykaigi2010-lt-rubeus
jrubykaigi2010-lt-rubeus
 
Advanced javascript
Advanced javascriptAdvanced javascript
Advanced javascript
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기#살아있다 #자프링외길12년차 #코프링2개월생존기
#살아있다 #자프링외길12년차 #코프링2개월생존기
 
Realm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app databaseRealm or: How I learned to stop worrying and love my app database
Realm or: How I learned to stop worrying and love my app database
 
Everyday's JS
Everyday's JSEveryday's JS
Everyday's JS
 
Future of HTTP in CakePHP
Future of HTTP in CakePHPFuture of HTTP in CakePHP
Future of HTTP in CakePHP
 
Opa presentation at GamesJs
Opa presentation at GamesJsOpa presentation at GamesJs
Opa presentation at GamesJs
 
Design Patterns in PHP5
Design Patterns in PHP5 Design Patterns in PHP5
Design Patterns in PHP5
 
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...Singletons in PHP - Why they are bad and how you can eliminate them from your...
Singletons in PHP - Why they are bad and how you can eliminate them from your...
 
運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript運用Closure Compiler 打造高品質的JavaScript
運用Closure Compiler 打造高品質的JavaScript
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
Implementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDBImplementing CQRS and Event Sourcing with RavenDB
Implementing CQRS and Event Sourcing with RavenDB
 
Backbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The BrowserBackbone.js: Run your Application Inside The Browser
Backbone.js: Run your Application Inside The Browser
 
PHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php frameworkPHP 5.3 and Lithium: the most rad php framework
PHP 5.3 and Lithium: the most rad php framework
 
Json
JsonJson
Json
 

Ähnlich wie Get Member Method Sample

SetFocus Portfolio
SetFocus PortfolioSetFocus Portfolio
SetFocus Portfoliodonjoshu
 
Introduction to ReasonML
Introduction to ReasonMLIntroduction to ReasonML
Introduction to ReasonMLRiza Fahmi
 
Perkenalan ReasonML
Perkenalan ReasonMLPerkenalan ReasonML
Perkenalan ReasonMLRiza Fahmi
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by examplebryanbibat
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...Doug Jones
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)bryanbibat
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門Tsuyoshi Yamamoto
 
My Portfolio
My PortfolioMy Portfolio
My Portfolioz02247
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreStephane Belkheraz
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Tomasz Dziuda
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfoliomichael_colon
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012Sandeep Joshi
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - GuilinJackson Tian
 

Ähnlich wie Get Member Method Sample (20)

Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
Email Program By Marcelo
Email Program By MarceloEmail Program By Marcelo
Email Program By Marcelo
 
SetFocus Portfolio
SetFocus PortfolioSetFocus Portfolio
SetFocus Portfolio
 
Introduction to ReasonML
Introduction to ReasonMLIntroduction to ReasonML
Introduction to ReasonML
 
Perkenalan ReasonML
Perkenalan ReasonMLPerkenalan ReasonML
Perkenalan ReasonML
 
Ruby and Rails by example
Ruby and Rails by exampleRuby and Rails by example
Ruby and Rails by example
 
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
JavaScript: The Good Parts Or: How A C# Developer Learned To Stop Worrying An...
 
Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)Ruby and Rails by Example (GeekCamp edition)
Ruby and Rails by Example (GeekCamp edition)
 
G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門G*ワークショップ in 仙台 Grails(とことん)入門
G*ワークショップ in 仙台 Grails(とことん)入門
 
My Portfolio
My PortfolioMy Portfolio
My Portfolio
 
Martin Roy Portfolio
Martin Roy PortfolioMartin Roy Portfolio
Martin Roy Portfolio
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
Entity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net CoreEntity Framework Core & Micro-Orms with Asp.Net Core
Entity Framework Core & Micro-Orms with Asp.Net Core
 
Introduction to ECMAScript 2015
Introduction to ECMAScript 2015Introduction to ECMAScript 2015
Introduction to ECMAScript 2015
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Codable routing
Codable routingCodable routing
Codable routing
 
Day 1
Day 1Day 1
Day 1
 
Michael Colon Portfolio
Michael Colon PortfolioMichael Colon Portfolio
Michael Colon Portfolio
 
Ensure code quality with vs2012
Ensure code quality with vs2012Ensure code quality with vs2012
Ensure code quality with vs2012
 
Mongoskin - Guilin
Mongoskin - GuilinMongoskin - Guilin
Mongoskin - Guilin
 

Get Member Method Sample

  • 1. Sample 1 (Data Modeling and User Interface Design):
  • 2.
  • 3. Sample 2 (SQL INSERT Stored Procedure): GO /****** Object: StoredProcedure [dbo].[GetMemberByItem] Script Date: 01/22/2008 14:33:53 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Nii Amah Hesse> -- Create date: <Create Date,,12/20/2007> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE [dbo].[GetMemberByItem] -- Add the parameters for the stored procedure here @isbn int ,@copy_no smallint AS IF NOT EXISTS (SELECT * FROM dbo.copy WHERE isbn = @isbn AND copy_no = @copy_no) BEGIN RETURN -17 --ItemNotFound END IF NOT EXISTS (SELECT member_no FROM dbo.loan WHERE isbn = @isbn AND copy_no = @copy_no) BEGIN RETURN -19 --ItemNotOnLoan END BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here IF EXISTS (SELECT a.member_no FROM dbo.adult AS a INNER JOIN dbo.loan AS l ON a.member_no = l.member_no WHERE l.isbn = @isbn AND l.copy_no = @copy_no) BEGIN SELECT m.member_no ,m.lastname ,m.firstname ,m.middleinitial ,a.street ,a.city ,a.state ,a.zip ,a.phone_no ,a.expr_date FROM dbo.member AS m INNER JOIN dbo.adult AS a ON m.member_no = a.member_no INNER JOIN dbo.loan AS l ON m.member_no = l.member_no WHERE l.isbn = @isbn AND l.copy_no = @copy_no END ELSE
  • 4. SELECT m.member_no ,m.lastname ,m.firstname ,m.middleinitial ,a.street ,a.city ,a.state ,a.zip ,a.phone_no ,a.expr_date ,j.adult_member_no ,j.birth_date FROM dbo.juvenile AS j INNER JOIN dbo.adult AS a ON j.adult_member_no = a.member_no INNER JOIN dbo.member AS m ON m.member_no = j.member_no INNER JOIN dbo.loan AS l ON l.member_no = j.member_no WHERE l.isbn = @isbn AND l.copy_no = @copy_no IF @@error <> 0 BEGIN RETURN -18 --NoSuchMember END END Sample 3 (C# Regular Expressions): private void ZipCodeTextBox_Validating(object sender, CancelEventArgs e) {Regex zipExp = new Regex(@"^d{5}$"); if (!zipExp.IsMatch(((Control)sender).Text)) {Regex zipExp2 = new Regex(@"^d{5}(-d{4})$"); if (!zipExp2.IsMatch(((Control)sender).Text)) {errorProvider1.SetError(ZipCodeTextBox, "ZipCode format: ##### or #####-####"); e.Cancel = true;}}} Sample 4 (C# Error File Logging): private void PrintError(string myErrorMessage, SystemException se) { string mydatetime = "Date" + DateTime.Today.Year.ToString(); mydatetime = mydatetime + "_" + DateTime.Today.Month.ToString(); mydatetime = mydatetime + "_" + DateTime.Today.Day.ToString(); mydatetime = mydatetime + "Time" + DateTime.Now.Hour.ToString(); mydatetime = mydatetime + "_" + DateTime.Now.Minute.ToString(); mydatetime = mydatetime + "_" + DateTime.Now.Second.ToString(); string myfile = @"C:error_" + mydatetime + ".txt"; StreamWriter sw = File.CreateText(myfile); sw.WriteLine("Error Date: " + DateTime.Today.ToShortDateString()); sw.WriteLine("Error Time: " + DateTime.Now.ToLongTimeString()); sw.WriteLine("Custom Message: " + myErrorMessage); sw.WriteLine("Message: " + se.Message); sw.WriteLine("Source: " + se.Source); sw.Close(); } Sample 5 (C#/ADO.NET: Get Member Method): #region GetMember Method
  • 5. public Member GetMember(int isbn, short copyNumber) { SqlConnection libCon = null; SqlCommand libCommand = null; SqlDataReader libReader = null; try { //sets the connection string libCon = new SqlConnection(); libCon.ConnectionString = Properties.Settings.Default.LibraryConnection; libCommand = new SqlCommand(); libCommand.CommandType = CommandType.StoredProcedure; libCommand.CommandText = "GetMemberByItem"; libCommand.Connection = libCon; libCommand.Parameters.Add(new SqlParameter("@isbn", SqlDbType.Int)); libCommand.Parameters[0].Value = isbn; libCommand.Parameters.Add(new SqlParameter("@copy_no", SqlDbType.SmallInt)); libCommand.Parameters[1].Value = copyNumber; libCommand.Parameters.Add("@ReturnVal", SqlDbType.SmallInt).Direction = ParameterDirection.ReturnValue; libCon.Open(); //this runs the Stored Proc libReader = libCommand.ExecuteReader(); AdultMember elder = new AdultMember(); JuvenileMember youth = new JuvenileMember(); bool adult = true; object[] allFields = new object[libReader.FieldCount]; while (libReader.Read()) { //juvenile member if (allFields.Length > 10) { youth.AdultMemberID = (short)libReader["adult_member_no"]; youth.BirthDate = (DateTime)libReader["birth_date"]; youth.City = libReader["city"].ToString(); youth.ExpirationDate = (DateTime)libReader["expr_date"]; youth.FirstName = libReader["firstname"].ToString(); youth.LastName = libReader["lastname"].ToString(); youth.MemberID = (short)libReader["member_no"]; youth.MiddleInitial = libReader["middleinitial"].ToString(); youth.PhoneNumber = libReader["phone_no"].ToString(); youth.State = libReader["state"].ToString(); youth.Street = libReader["street"].ToString(); youth.ZipCode = libReader["zip"].ToString(); adult = false; } else { elder.City = libReader["city"].ToString();
  • 6. elder.ExpirationDate = (DateTime)libReader["expr_date"]; elder.FirstName = libReader["firstname"].ToString(); elder.LastName = libReader["lastname"].ToString(); elder.MemberID = (short)libReader["member_no"]; elder.MiddleInitial = libReader["middleinitial"].ToString(); elder.PhoneNumber = libReader["phone_no"].ToString(); elder.State = libReader["state"].ToString(); elder.Street = libReader["street"].ToString(); elder.ZipCode = libReader["zip"].ToString(); } } if (Convert.ToInt16(libCommand.Parameters["@ReturnVal"].Value) ! = 0) { LibraryException ex = new LibraryException(); ex = ex.ErrCodeGenerator(Convert.ToInt16(libCommand.Parameters["@ReturnVal"].Value)); if (ex.OtherMemberID > 0) { throw new LibraryException(ex.LibraryErrorCode, ex.OtherMemberID); } else { throw new LibraryException(ex.LibraryErrorCode); } } if (adult == true) { return elder; } else { return youth; } } catch (LibraryException ex) { if (ex.OtherMemberID > 0) { throw new LibraryException(ex.LibraryErrorCode, ex.OtherMemberID); } else { throw new LibraryException(ex.LibraryErrorCode); } } finally { //Close Connection if (!libReader.IsClosed) { libReader.Close(); } if (libCon.State != ConnectionState.Closed) { libCon.Close(); } } }
  • 7. #endregion Sample 6 (Web Service Web Config (XML)): <?xml version="1.0" encoding="utf-8"?> <!-- Note: As an alternative to hand editing this file you can use the web admin tool to configure settings for your application. Use the Website->Asp.Net Configuration option in Visual Studio. A full list of settings and comments can be found in machine.config.comments usually located in WindowsMicrosoft.NetFrameworkv2.xConfig --> <configuration> <configSections> <section name="microsoft.web.services3" type="Microsoft.Web.Services3.Configuration.WebServicesConfiguration, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </configSections> <appSettings /> <connectionStrings> <add name="library" connectionString="Data Source=localhost;Initial Catalog=library;Integrated Security=True" /> </connectionStrings> <system.web> <!-- Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development. --> <compilation debug="true"> <assemblies> <add assembly="Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> </assemblies> </compilation> <!-- The <authentication> section enables configuration of the security authentication mode used by ASP.NET to identify an incoming user. --> <authentication mode="Windows" /> <!-- The <customErrors> section enables configuration of what to do if/when an unhandled error occurs during the execution of a request. Specifically, it enables developers to configure html error pages to be displayed in place of a error stack trace. <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> --> <customErrors mode="On" /> <webServices> <soapExtensionImporterTypes> <add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral,
  • 8. PublicKeyToken=31bf3856ad364e35" /> </soapExtensionImporterTypes> <soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> </webServices> </system.web> <microsoft.web.services3> <policy fileName="wse3policyCache.config" /> <diagnostics> <trace enabled="false" input="InputTrace.webinfo" output="OutputTrace.webinfo" /> </diagnostics> <security> <x509 verifyTrust="true" allowTestRoot="true" /> </security> </microsoft.web.services3> </configuration> Sample 7 (XML Web Page): <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="CheckIn.aspx.cs" Inherits="LibraryWebClient_CheckIn" Title="Untitled Page" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  • 9. <br /> <asp:Label ID="lblIsbn" runat="server" Font-Size="Medium" Text="ISBN" Width="100px"></asp:Label> <asp:TextBox ID="txtIsbn" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvIsbn" runat="server" ControlToValidate="txtIsbn" ErrorMessage="ISBN is Required" Font-Size="Medium" Width="35px">! </asp:RequiredFieldValidator> <asp:RangeValidator ID="revIsbn" runat="server" ControlToValidate="txtIsbn" ErrorMessage="ISBN must be an Integer" Font-Size="Medium" MaximumValue="32767" MinimumValue="1" Type="Integer" Width="26px">*</asp:RangeValidator><br /> <asp:Label ID="lblCopyNumber" runat="server" Font-Size="Medium" Text="Copy Number" Width="100px"></asp:Label> <asp:TextBox ID="txtCopyNumber" runat="server"></asp:TextBox> <asp:RequiredFieldValidator ID="rfvCopyNumber" runat="server" ControlToValidate="txtCopyNumber" ErrorMessage="Copy Number is Required" Font-Size="Medium" Width="31px">! </asp:RequiredFieldValidator> <asp:RangeValidator ID="revCopyNumber" runat="server" ControlToValidate="txtCopyNumber" ErrorMessage="Copy Number Must be between 1 and 32767" Font- Size="Medium" MaximumValue="32767" MinimumValue="1" Type="Integer" Width="28px">*</asp:RangeValidator><br / > <br /> <asp:TextBox ID="lblStatusText" runat="server" BackColor="Silver" BorderColor="Silver" BorderStyle="None" Font-Bold="True" ReadOnly="True" Width="733px"></asp:TextBox><br /> <asp:Button ID="btnOk" runat="server" OnClick="Button1_Click" Text="Ok" Width="87px" /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <asp:Button ID="btnCancel" runat="server" OnClick="btnCancel_Click" Text="Cancel" Width="87px" PostBackUrl="~/LibraryWebClient/GetMemberInfo.aspx" CausesValidation="False" /><br /> <asp:Button ID="btnYes" runat="server" Enabled="False" OnClick="btnYes_Click" Text="Yes" Visible="False" Width="87px" /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<asp:Button ID="btnNo" runat="server" Enabled="False" OnClick="btnNo_Click" Text="No" Visible="False" Width="87px" /><br /> <asp:ValidationSummary ID="ValidationSummary1" runat="server" Font- Size="Medium" /> <br /> <br /> </asp:Content>