Sample 1 (Data Modeling and User Interface Design):
Sample 2 (SQL INSERT Stored Procedure):
GO
/****** Object: StoredProcedure [dbo].[GetMemberByItem]        Script Date:
01/...
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...
public Member GetMember(int isbn, short copyNumber)
        {
            SqlConnection libCon = null;
            SqlComm...
elder.ExpirationDate = (DateTime)libReader["expr_date"];
                          elder.FirstName = libReader["firstname"...
#endregion


                     Sample 6 (Web Service Web Config (XML)):
<?xml version="1.0" encoding="utf-8"?>
<!--
   ...
PublicKeyToken=31bf3856ad364e35" />
      </soapExtensionImporterTypes>
      <soapServerProtocolFactory
type="Microsoft.W...
<br />
    <asp:Label ID="lblIsbn" runat="server" Font-Size="Medium" Text="ISBN"
Width="100px"></asp:Label>
    <asp:TextB...
Code Samples &amp; Screenshots
Upcoming SlideShare
Loading in …5
×

Code Samples &amp; Screenshots

597 views
435 views

Published on

Some Code Samples and Screenshots

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
597
On SlideShare
0
From Embeds
0
Number of Embeds
39
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Code Samples &amp; Screenshots

  1. 1. Sample 1 (Data Modeling and User Interface Design):
  2. 2. 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
  3. 3. 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
  4. 4. 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();
  5. 5. 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(); } } }
  6. 6. #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,
  7. 7. 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">
  8. 8. <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>

×