Presentation about comparing routing system in Drupal 7 and Drupal 8. What is implemented in REST module of Drupal 8? What is going to be in Services module for Drupal 8.
atrium_username is a Drupal feature for managing user name display:
* a lightweight alternative to realname module;
* "works" before theme layer
* uses the node title of the user profile
Presentation about comparing routing system in Drupal 7 and Drupal 8. What is implemented in REST module of Drupal 8? What is going to be in Services module for Drupal 8.
atrium_username is a Drupal feature for managing user name display:
* a lightweight alternative to realname module;
* "works" before theme layer
* uses the node title of the user profile
Code to copy:
/******************** Person.java **********************/
// Create a class Person
publicclass Person
{
// Declare variables
private String name;
private MyDate birthdate; // This is a date based on a Person\'s birthday
// Create accessor method for the name
public String getName()
{
return name;
}
// Create mutator method for name
publicvoid setName(String name)
{
this.name = name;
}
// Create accessor method for the name
public MyDate getBirthdate()
{
return birthdate;
}
// Create mutator method for name
publicvoid setBirthdate(MyDate birthdate)
{
this.birthdate = birthdate;
}
// Create a parameter constructor
public Person(String name, int pp, int kk, int vv)
{
this(name, new MyDate(pp, kk, vv));
}
// Create a parameter constructor
public Person(String name, MyDate birthday)
{
this(name);
this.birthdate = birthday;
}
// Create a parameter constructor
public Person(String name) {
this.name = name;
}
// Create to string method to display person data
@Override
public String toString() {
return \"Person [name=\" + name + \", birthdate=\" + birthdate + \"]\";
}
}
/******************** MyDate.java **********************/
// Create a class named MyDate
class MyDate
{
// Declare variables
privateint day;
privateint month;
privateint year;
// Create a default constructor
public MyDate(int month, int day, int year)
{
this.day = day;
this.month = month;
this.year = year;
}
// Create a compareTo method to compare the date objects
int compareTo(MyDate obj)
{
if(obj.day==this.day && obj.month==this.month && obj.year==this.year)
{
return 0;
}
elseif(obj.year>this.year)
{
return 1;
}
elseif(obj.year > this.year && obj.month > this.month)
{
return 1;
}
elseif(obj.year > this.year && obj.month > this.month && obj.day==this.day)
{
return 1;
}
else
return -1;
}
// Create a toString() method to display the date
@Override
public String toString()
{
return \"MyDate [day=\" + day + \", month=\" + month + \", year=\" + year + \"]\";
}
}
/******************** PersonSort.java **********************/
// import statements
import java.util.*;
import java.io.*;
// Create a class PersonSort
publicclass PersonSort implements Comparator
{
// Create compare method to compare two objects
@Override
publicint compare(Person o1, Person o2)
{
return 0;
}
// Create a main method to test the program
publicstaticvoid main(String [] args)
{
// Declare variables
String line;
String fileName=\"dataFile.txt\";
String data=\"\";
// Create a array list for the person class
ArrayList person= new ArrayList();
// Create a try block to handle the run time exceptions
try
{
// Create an object for the FileReader class
FileReader fileReader = new FileReader(fileName);
BufferedReader bufferedReader = new BufferedReader(fileReader);
// Create a for loop to read the data in the file dataFile.txt
while ((line = bufferedReader.readLine()) != null)
{
data+=line;
}
}
// Create a catch block to catch run time exceptions.
catch (FileNotFoundException ex)
{
System.out.println(\"Unable to op.
SinglyLinkedListPseudoCode.txt
CLASS SinglyLinkedList:
set linkedList as Node
FUNCTION getLinkedList()
return linkedList
END FUNCTION
FUNCTION add(object)
found = find(object)
IF found
create newNode object using object
IF linkList is null
set linkedList as newNode
ELSE
set rear as linkedList
WHILE rear is not null
IF rear.next is null
breaK
END IF
set rear as rear.next
END WHILE
rear.next = newNode
ELSE
END IF
return true
END IF
return false
END FUNCTION
FUNCTION find(object)
IF linkedlist is null return false
set iterable as linkedList
IF iterable.data is equal to object
create newNode object
newNode.next = linkedList.nex
set linkedList as newNode
return true
END IF
WHILE iterable is not null
IF iterable.next is not null
IF iterable.next is equal to object
set target as iterable.next
create newNode object
newNode.next = target.next
iterable.next = newNode
dispose target
END IF
END IF
set iterable as iterable.next
END WHILE
return false
END FUNCTION
FUNCTION delete(object)
IF linkedlist is null return false
set iterable as linkedList
IF iterable.data is equal to object
set linkedList as iterable.next
return true
END IF
WHILE iterable is not null
IF iterable.next is not null
IF iterable.next is equal to object
set target as iterable.next
iterable.next = target.next
dispose target
END IF
END IF
set iterable as iterable.next
END WHILE
return false
END FUNCTION
FUNCTION traverse()
set iterable as linkedList
WHILE iterable is not null
PRINT(iterable.data)
set iterable as iterable.next
END WHILE
END FUNCTION
Account_Bhusal.javaAccount_Bhusal.java/**
* @author Deepak Bhusal
* Assignment SP2019_PROJECT
* Account_Bhusal class represents a bank account for a user and harbours
* necessary methods for deposit, withdrawal and balance checking. This class is abstract in nature
* and contain abstract methods that are implemented by child classes
*/
publicabstractclassAccount_Bhusal{
protectedString accountNumber;
protectedfloat balance;
/**
* Default constructor
*/
publicAccount_Bhusal(){
this.accountNumber="";
this.balance=.
Come to this talk prepared to learn about the Doctrine PHP open source project. The Doctrine project has been around for over a decade and has evolved from database abstraction software that dates back to the PEAR days. The packages provided by the Doctrine project have been downloaded almost 500 million times from packagist. In this talk we will take you through how to get started with Doctrine and how to take advantage of some of the more advanced features.
Create an implementation of a binary tree using the recursive appr.pdffederaleyecare
\"Create an implementation of a binary tree using the recursive approach introduced in the
chapter. In this approach, each node is a binary tree. Thus a binary tree contains a reference to
the element stored at its root as well as references to its left and right subtrees. You may also
want to include a reference to its parent.\" p.741
You need to use the locally implemented binary tree. This means you need to have a \"jsjf\"
subfolder with at least these files: BinaryTreeADT.java, LinkedBinaryTree.java,
BinaryTreeNode.java, and the exceptions sub-subfolder.
Test/demonstrate your binary tree by doing the following:
Request file name from user,
Read an infix expression from file,
Build binary expression tree,
Display binary expression tree,
Evaluate binary expression tree,
Display result.
##############################################
Note a typical input file can be found here
##############################################
# Version 0.2, fully parenthesized.
# This is a comment
((9 + 4) * 5) + (4 - (6 + 3))
# Note first expression should evaluate to 60
((42 + ( 10 - 2 )) + ( 5 * 3 )) / 6
# Note second expression should evaluate to 65 / 6 or 10 (integer division)
##############################################
My program is below but the out put is incorrect
##############################################
StringTree.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.Scanner;
import java.util.Stack;
import jsjf.BinaryTreeNode;
import jsjf.LinkedBinaryTree;
public class StringTree extends LinkedBinaryTree {
public StringTree(String rootStr, StringTree leftSubtree, StringTree rightSubtree) {
root = new BinaryTreeNode(rootStr, leftSubtree, rightSubtree);
} // StringTree
public StringTree(File f) {
Stack leftStack = new Stack(), rightStack = new Stack();
// stacks of left and right subtrees of nodes
Scanner scan;
// scanner for reading from the file
String nodeType,
nodeStr;
// string contained in the current node
boolean hasLeftChild, hasRightChild;
// true if the current node has a left or right child
StringTree leftSubtree, rightSubtree,
// left and right subtrees of the current node
subtree;
// subtree having the current node as its root
// Create a scanner for reading from the file.
try {
scan = new Scanner(f);
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
root = null;
System.out.println(\"\ \"+\"The program has terminated......\");
System.exit(0);
return;
}
// Read the file and build a tree from the bottom up.
while (scan.hasNext()) {
// Input information about a tree node.
nodeType = scan.next();
hasLeftChild = (scan.next().equalsIgnoreCase(\"y\"));
hasRightChild = (scan.next().equalsIgnoreCase(\"y\"));
nodeStr = scan.next();
// Determine the left and right subtrees of the subtree
// having the node as its root.
if (hasLeftChild)
leftSubtree = leftStack.pop();
else
leftSubtree = null;
if (hasRightChild)
rightSubtree = rightStack.pop();
else
rightSubtree = null;
.
operating system Ubunut,Linux,Mac filename messageService.cpp.pdfannethafashion
// operating system Ubunut,Linux,Mac
// filename messageService.cpp
#include
#include // for vector
#include
using namespace std;
/*Main function start*/
int main()
{
std::vector > store;// we are using vector for storing pair of name and message
std::vector >::reverse_iterator it;// used to reverse iteration
std::string name,message,input,choice;// variable for purpose
do{
std::cout<<\"Enter User Name> \";
std::cin>>name;
std::cout<<\"Enter Message> \";// prompt for user input
/* we are taking input from user as string
* if line contains $$ then it will break and come out from loop
* otherwise it will create pair and insert it into vector*/
while(std::getline(std::cin,input)){
if(input==\"$$\")
break;
message+=input+\"\ \";
}
store.push_back(std::pair(name,message));// inserting pair into vector
message=\"\";
std::cout<<\"Any More Users? > \";
std::cin>>choice;
}while(choice==\"yes\");
/*while loop break if choice value other then \"yes\" */
std::cout << \"The current messages are: \ \";
/*Iterating vector in reverse order for printing desirable output*/
for (it=store.rbegin(); it!=store.rend(); ++it){
std::cout << it->first << \" >> \"<second << \'\ \';
}
return 0;
}
/*Main function End*/
/*Output*/
gopal@gopal:~/Desktop/chegg$ g++ messageService.cpp
gopal@gopal:~/Desktop/chegg$ ./a.out
Enter User Name> Kate
Enter Message> Get in the loop and join our War Eagle group!
Sunner in st. John\'s islands was fun.
How was your summer?
$$
Any More Users? > yes
Enter User Name> Daniel
Enter Message> I\'m in!
$$
Any More Users? > yes
Enter User Name> Joey
Enter Message> Count me in.
We were in Tokyo; intersting!
$$
Any More Users? > yes
Enter User Name> Kevin
Enter Message> What\'s new?
we had a great time in the Outback.
$$
Any More Users? > no
The current messages are:
Kevin >>
What\'s new?
we had a great time in the Outback.
Joey >>
Count me in.
We were in Tokyo; intersting!
Daniel >>
I\'m in!
Kate >>
Get in the loop and join our War Eagle group!
Sunner in st. John\'s islands was fun.
How was your summer?
Solution
// operating system Ubunut,Linux,Mac
// filename messageService.cpp
#include
#include // for vector
#include
using namespace std;
/*Main function start*/
int main()
{
std::vector > store;// we are using vector for storing pair of name and message
std::vector >::reverse_iterator it;// used to reverse iteration
std::string name,message,input,choice;// variable for purpose
do{
std::cout<<\"Enter User Name> \";
std::cin>>name;
std::cout<<\"Enter Message> \";// prompt for user input
/* we are taking input from user as string
* if line contains $$ then it will break and come out from loop
* otherwise it will create pair and insert it into vector*/
while(std::getline(std::cin,input)){
if(input==\"$$\")
break;
message+=input+\"\ \";
}
store.push_back(std::pair(name,message));// inserting pair into vector
message=\"\";
std::cout<<\"Any More Users? > \";
std::cin>>choice;
}while(choice==\"yes\");
/*while loop break if choice value other then \"yes\.
Welcome to the first live UiPath Community Day Dubai! Join us for this unique occasion to meet our local and global UiPath Community and leaders. You will get a full view of the MEA region's automation landscape and the AI Powered automation technology capabilities of UiPath. Also, hosted by our local partners Marc Ellis, you will enjoy a half-day packed with industry insights and automation peers networking.
📕 Curious on our agenda? Wait no more!
10:00 Welcome note - UiPath Community in Dubai
Lovely Sinha, UiPath Community Chapter Leader, UiPath MVPx3, Hyper-automation Consultant, First Abu Dhabi Bank
10:20 A UiPath cross-region MEA overview
Ashraf El Zarka, VP and Managing Director MEA, UiPath
10:35: Customer Success Journey
Deepthi Deepak, Head of Intelligent Automation CoE, First Abu Dhabi Bank
11:15 The UiPath approach to GenAI with our three principles: improve accuracy, supercharge productivity, and automate more
Boris Krumrey, Global VP, Automation Innovation, UiPath
12:15 To discover how Marc Ellis leverages tech-driven solutions in recruitment and managed services.
Brendan Lingam, Director of Sales and Business Development, Marc Ellis
State of ICS and IoT Cyber Threat Landscape Report 2024 previewPrayukth K V
The IoT and OT threat landscape report has been prepared by the Threat Research Team at Sectrio using data from Sectrio, cyber threat intelligence farming facilities spread across over 85 cities around the world. In addition, Sectrio also runs AI-based advanced threat and payload engagement facilities that serve as sinks to attract and engage sophisticated threat actors, and newer malware including new variants and latent threats that are at an earlier stage of development.
The latest edition of the OT/ICS and IoT security Threat Landscape Report 2024 also covers:
State of global ICS asset and network exposure
Sectoral targets and attacks as well as the cost of ransom
Global APT activity, AI usage, actor and tactic profiles, and implications
Rise in volumes of AI-powered cyberattacks
Major cyber events in 2024
Malware and malicious payload trends
Cyberattack types and targets
Vulnerability exploit attempts on CVEs
Attacks on counties – USA
Expansion of bot farms – how, where, and why
In-depth analysis of the cyber threat landscape across North America, South America, Europe, APAC, and the Middle East
Why are attacks on smart factories rising?
Cyber risk predictions
Axis of attacks – Europe
Systemic attacks in the Middle East
Download the full report from here:
https://sectrio.com/resources/ot-threat-landscape-reports/sectrio-releases-ot-ics-and-iot-security-threat-landscape-report-2024/
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfPaige Cruz
Monitoring and observability aren’t traditionally found in software curriculums and many of us cobble this knowledge together from whatever vendor or ecosystem we were first introduced to and whatever is a part of your current company’s observability stack.
While the dev and ops silo continues to crumble….many organizations still relegate monitoring & observability as the purview of ops, infra and SRE teams. This is a mistake - achieving a highly observable system requires collaboration up and down the stack.
I, a former op, would like to extend an invitation to all application developers to join the observability party will share these foundational concepts to build on:
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
Securing your Kubernetes cluster_ a step-by-step guide to success !KatiaHIMEUR1
Today, after several years of existence, an extremely active community and an ultra-dynamic ecosystem, Kubernetes has established itself as the de facto standard in container orchestration. Thanks to a wide range of managed services, it has never been so easy to set up a ready-to-use Kubernetes cluster.
However, this ease of use means that the subject of security in Kubernetes is often left for later, or even neglected. This exposes companies to significant risks.
In this talk, I'll show you step-by-step how to secure your Kubernetes cluster for greater peace of mind and reliability.
The Metaverse and AI: how can decision-makers harness the Metaverse for their...Jen Stirrup
The Metaverse is popularized in science fiction, and now it is becoming closer to being a part of our daily lives through the use of social media and shopping companies. How can businesses survive in a world where Artificial Intelligence is becoming the present as well as the future of technology, and how does the Metaverse fit into business strategy when futurist ideas are developing into reality at accelerated rates? How do we do this when our data isn't up to scratch? How can we move towards success with our data so we are set up for the Metaverse when it arrives?
How can you help your company evolve, adapt, and succeed using Artificial Intelligence and the Metaverse to stay ahead of the competition? What are the potential issues, complications, and benefits that these technologies could bring to us and our organizations? In this session, Jen Stirrup will explain how to start thinking about these technologies as an organisation.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Removing Uninteresting Bytes in Software FuzzingAftab Hussain
Imagine a world where software fuzzing, the process of mutating bytes in test seeds to uncover hidden and erroneous program behaviors, becomes faster and more effective. A lot depends on the initial seeds, which can significantly dictate the trajectory of a fuzzing campaign, particularly in terms of how long it takes to uncover interesting behaviour in your code. We introduce DIAR, a technique designed to speedup fuzzing campaigns by pinpointing and eliminating those uninteresting bytes in the seeds. Picture this: instead of wasting valuable resources on meaningless mutations in large, bloated seeds, DIAR removes the unnecessary bytes, streamlining the entire process.
In this work, we equipped AFL, a popular fuzzer, with DIAR and examined two critical Linux libraries -- Libxml's xmllint, a tool for parsing xml documents, and Binutil's readelf, an essential debugging and security analysis command-line tool used to display detailed information about ELF (Executable and Linkable Format). Our preliminary results show that AFL+DIAR does not only discover new paths more quickly but also achieves higher coverage overall. This work thus showcases how starting with lean and optimized seeds can lead to faster, more comprehensive fuzzing campaigns -- and DIAR helps you find such seeds.
- These are slides of the talk given at IEEE International Conference on Software Testing Verification and Validation Workshop, ICSTW 2022.
GraphRAG is All You need? LLM & Knowledge GraphGuy Korland
Guy Korland, CEO and Co-founder of FalkorDB, will review two articles on the integration of language models with knowledge graphs.
1. Unifying Large Language Models and Knowledge Graphs: A Roadmap.
https://arxiv.org/abs/2306.08302
2. Microsoft Research's GraphRAG paper and a review paper on various uses of knowledge graphs:
https://www.microsoft.com/en-us/research/blog/graphrag-unlocking-llm-discovery-on-narrative-private-data/
Enhancing Performance with Globus and the Science DMZGlobus
ESnet has led the way in helping national facilities—and many other institutions in the research community—configure Science DMZs and troubleshoot network issues to maximize data transfer performance. In this talk we will present a summary of approaches and tips for getting the most out of your network infrastructure using Globus Connect Server.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Pushing the limits of ePRTC: 100ns holdover for 100 daysAdtran
At WSTS 2024, Alon Stern explored the topic of parametric holdover and explained how recent research findings can be implemented in real-world PNT networks to achieve 100 nanoseconds of accuracy for up to 100 days.
In his public lecture, Christian Timmerer provides insights into the fascinating history of video streaming, starting from its humble beginnings before YouTube to the groundbreaking technologies that now dominate platforms like Netflix and ORF ON. Timmerer also presents provocative contributions of his own that have significantly influenced the industry. He concludes by looking at future challenges and invites the audience to join in a discussion.
1. (Library Project) by Marcelo Salvador
Introduction: The project was created in order to create a library database accessing a
SQL Server database and allowing data manipulation.
Audience:
Business Executives
Information Workers
IT Managers
Project Goals:
The goal of this project was to allow data manipulation of a library database by
utilizing Windows Forms as a graphic user interface. Afterwards, the project was
migrated to ASP.NET.
Below I enclose examples of the classes utilizing N-Tier Architecture.
The Class described below is the Business Access Layer
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Ms.Library.Entities;
using Marcelo_Library;
/*******************************************************************
* Description: This class is utilized to gather all the data from
* the desired library database from methods of the
* LibraryDataAccess.cs
* *****************************************************************
* Author: Marcelo D. Salvador*
* Create Date: 11/24/2008 *
* Modified Date: 11/28/2007 *
* Modification: 12/13/2008 *
*******************************************************************/
namespace Marcelo_Library
2. {
/// <summary>
/// Class created to access methods of the LibraryDataAccess
/// </summary>
public class LibraryBusiness
{
Marcelo_Library.LibraryDataAccess myDAL = new
Marcelo_Library.LibraryDataAccess();
/// <summary>
/// Gets a member based on ID
/// </summary>
/// <param name="MemberID"></param>
/// <returns></returns>
public Member getMember(int MemberID)
{
Member mymember = myDAL.getMember(MemberID);
return mymember;
}
/// <summary>
/// Method utilized to add a new member to the Library
/// </summary>
/// <param name="newMember"></param>
public void AddNewMember(Member newMember)
{
if (newMember is AdultMember)
myDAL.AddMember((AdultMember)newMember);
else
myDAL.AddMember((JuvenileMember)newMember);
}
/// <summary>
/// Method utilized to check in a book
/// </summary>
/// <param name="copyNumber"></param>
/// <param name="isbnNumber"></param>
public void CheckIn(short copyNumber, int isbnNumber)
{
myDAL.CheckInItem(copyNumber, isbnNumber);
}
/// <summary>
/// Method utilized to check out a book
/// </summary>
/// <param name="memberId"></param>
/// <param name="copyNumber"></param>
/// <param name="isbnNumber"></param>
public void CheckOutBook(int memberId, short copyNumber, int
isbnNumber)
{
myDAL.CheckOutItem(memberId, copyNumber, isbnNumber);
}
/// <summary>
/// Returns the books a member has on loan
/// </summary>
/// <param name="memberId"></param>
/// <returns></returns>
3. public DataSet GetBooks(short memberId)
{
// create the library data access
// call the GetItems method
// return the dataset
LibraryDataAccess dataAccess = new LibraryDataAccess();
DataSet books = dataAccess.GetItems(memberId);
return books;
}
/// <summary>
/// Method utilizid to get book information
/// </summary>
/// <param name="isbnNumber"></param>
/// <param name="copyNumber"></param>
/// <returns></returns>
public Item GetBook(int isbnNumber, short copyNumber)
{
Item myItem = myDAL.GetItem(isbnNumber, copyNumber);
return myItem;
}
/// <summary>
/// Method utilized to renew membership
/// </summary>
/// <param name="memberNumber"></param>
public void RenewMembership(int memberNumber)
{
myDAL.RenewMembership(memberNumber);
}
/// <summary>
/// Method utilized to convert a juvenile to an adult
/// </summary>
/// <param name="memberNumber"></param>
public void KidtoMan(int memberNumber)
{
myDAL.adolescentToAdult(memberNumber);
}
/// <summary>
/// Method utilized to insert a new book to the database
/// </summary>
/// <param name="title"></param>
/// <param name="author"></param>
/// <param name="synopsis"></param>
/// <param name="isbn"></param>
/// <param name="translation"></param>
/// <param name="cover"></param>
/// <param name="loanable"></param>
public void InsertNewBook(string title, string author, string
synopsis, int isbn, string translation, string cover, char loanable)
{
myDAL.AddNewBook(title, author, synopsis, isbn,
translation, cover, loanable);
}
4. }
}
The Class described below is the Data Access Layer
using System;
using System.Collections.Generic;
using System.Text;
using Ms.Library.Entities;
using Ms.Library.Entities.Properties;
using Ms.Library.Entities.ItemsDataSetTableAdapters;
using LibraryDataAccess;
using LibraryDataAccess.Properties;
using System.Data.SqlClient;
using System.Data;
/*********************************************************************
* Description:
This class is utilized to gather all the information from
* the database;also, deletes, updates,etc. Every
single
* methods contains a connection to the library database
and
* returns an error number in case an error takes place.
*
* Author: Marcelo D. Salvador
* Create Date: 11/24/2008
* Modified Date: 11/28/2007
* Modification: 12/01/2008
********************************************************************/
namespace Marcelo_Library
{
/// <summary>
/// This class is utilized to access data in the library database
/// </summary>
public class LibraryDataAccess
{
/// <summary>
/// default constructor
/// </summary>
public LibraryDataAccess()
{
}
/// <summary>
/// Gets the member based on member ID
/// </summary>
/// <param name="memberID"></param>
/// <returns></returns>
public Member getMember(int memberID)
{
Member mymember = new Member();
int returnValue;
try
5. {
// create connection
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
// create the command object
using (SqlCommand cmd = new SqlCommand("GetMember",
cnn))
{
// assign the connection above to your new
command object
cmd.Connection = cnn;
// name of the proc you are calling
// command object will use a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
//add input paramater for memberID
cmd.Parameters.AddWithValue("@MemberID",
memberID);
//add return value parameter so we can access
the return value from the proc
SqlParameter returnParm = new SqlParameter();
returnParm.ParameterName = "@return";
returnParm.SqlDbType = SqlDbType.Int;
returnParm.Direction =
ParameterDirection.ReturnValue;
cmd.Parameters.Add(returnParm);
// open the connection
cnn.Open();
// create a SQLDAtaREader to use with the data
coming back from the proc
using (SqlDataReader reader =
cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
// It will fall into the code
// block below if the proc
// executed successfully
// and returned a row.
while (reader.Read())
{//Column order on the table
/* 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
*/
6. /* Checking if the column number 10
which is
* actually 9 because it is zero
based.*/
if (!(reader.IsDBNull(9)))
{
//Juvenile member created...
JuvenileMember juvMember = new
JuvenileMember();
//using ordinal positions of columns
juvMember.LastName =
reader[0].ToString();
juvMember.FirstName =
reader[1].ToString();
juvMember.MiddleInitial =
reader[2].ToString();
juvMember.AdultMemberID =
short.Parse(reader[9].ToString());
juvMember.BirthDate =
DateTime.Parse(reader[10].ToString());
// juvenile member is built in
entity class can return it now
return juvMember;
}
else
{
//Adult member created
AdultMember myAdultMember = new
AdultMember();
myAdultMember.LastName =
reader[0].ToString();
myAdultMember.FirstName =
reader[1].ToString();
myAdultMember.MiddleInitial =
reader[2].ToString();
myAdultMember.Street =
reader[3].ToString();
myAdultMember.City =
reader[4].ToString();
myAdultMember.State =
reader[5].ToString();
// zipcode needs to be trimmed
string zip = reader[6].ToString();
myAdultMember.ZipCode = zip.Trim();
myAdultMember.PhoneNumber =
reader[7].ToString();
myAdultMember.ExpirationDate =
DateTime.Parse(reader[8].ToString());
return myAdultMember;
}
}
7. }
// Checking SQL stored procedures return values
and through exceptions based on them
returnValue =
int.Parse(cmd.Parameters["@return"].Value.ToString());
/*return 0 -- 'Return values successful from
the query*/
/*Return -1 -- 'MemberID is null'*/
/*Return -2 -- 'MemberID is < 1 OR MemberID >
32767*/
/*Return -3 -- 'No Member found or if length
is greater than 5*/
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new LibraryException("isbn is
null", LibraryException.ErrorCode.IsbnIsNull);
case -2:
throw new LibraryException("copy_no
is null", LibraryException.ErrorCode.OutOfRangeMemberValue);
case -3:
throw new
LibraryException("member_no is null",
LibraryException.ErrorCode.NoSuchMember);
}
}
}
}
}
catch (InvalidCastException e)
{
string.Format("Invalid Cast", e.ToString());
}
catch (SqlException sql)
{
throw new LibraryException(sql.Message,
LibraryException.ErrorCode.GenericException);
}
return mymember;
}
/// <summary>
///
/// </summary>
/// <param name="memberNumber"></param>
/// <returns></returns>
public ItemsDataSet GetItems(short memberNumber)
{
ItemsDataSet itemsDS = new ItemsDataSet();
ItemsTableAdapter itemsTableAdapter = new
ItemsTableAdapter();
8. ItemsDataSet.ItemsDataTable myTable = new
ItemsDataSet.ItemsDataTable();
int returnValue = itemsTableAdapter.Fill(itemsDS.Items,
memberNumber);
returnValue = (int)itemsTableAdapter.GetReturnValue(0);
if (returnValue == 0)
return itemsDS;
else
throw new Exception("Book not Found!!!");
}
/// <summary>
/// Get book information
/// </summary>
/// <param name="isbnNumber"></param>
/// <param name="copyNumber"></param>
/// <returns></returns>
public Item GetItem(int isbnNumber, short copyNumber)
{
Item myitem = new Item();
int returnValue;
try
{
// create connection
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
// create the command object
using (SqlCommand cmd = new SqlCommand("GetMyItem",
cnn))
{
// assign the connection above to your new
command object
cmd.Connection = cnn;
// name of the proc you are calling
// command object will use a stored procedure
cmd.CommandType = CommandType.StoredProcedure;
//add input paramater for memberID
cmd.Parameters.AddWithValue("@isbn",
isbnNumber);
cmd.Parameters.AddWithValue("@copy_no",
copyNumber);
//add return value parameter so we can access
the return value from the proc
SqlParameter returnParm = new SqlParameter();
returnParm.ParameterName = "@return";
returnParm.SqlDbType = SqlDbType.Int;
returnParm.Direction =
ParameterDirection.ReturnValue;
9. cmd.Parameters.Add(returnParm);
// open the connection
cnn.Open();
// create a SQLDataReader to use with the data
coming back from the proc
using (SqlDataReader reader =
cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
// we will fall into the code block below
if the proc executed successfully
// and returned a row.
while (reader.Read())
{
/*
* @isbn,
* @copy_no,
* @title,
* @author,
* @member_no,
* @out_date,
* @due_date
*/
if (!(reader.IsDBNull(0)))
{
//add stuff to juvenile class
Item dItem = new Item();
// Using ordinal positions of
columns
dItem.ISBN =
Convert.ToInt32(reader[0].ToString());
dItem.CopyNo =
Convert.ToInt32(reader[1].ToString());
dItem.Title = reader[2].ToString();
dItem.Author = reader[3].ToString();
dItem.MemberNO =
Convert.ToInt32(reader[4].ToString());
dItem.OutDate =
Convert.ToDateTime(reader[5].ToString());
dItem.DueDate =
Convert.ToDateTime(reader[6].ToString());
return dItem;
}
}
}
//RETURN Codes:
//RETURN 0 -- Sucesss
//RETURN -1 -- ISBN is null
//RETURN -2 -- Copy number is null
//RETURN -3 -- Member does not exist
10. returnValue =
int.Parse(cmd.Parameters["@return"].Value.ToString());
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new LibraryException("isbn is
null", LibraryException.ErrorCode.IsbnIsNull);
case -2:
throw new LibraryException("copy_no
is null", LibraryException.ErrorCode.OutOfRangeMemberValue);
case -3:
throw new
LibraryException("member_no is null",
LibraryException.ErrorCode.NoSuchMember);
}
}
}
}
}
catch (InvalidCastException e)
{
string.Format("Invalid Cast", e.ToString());
}
catch (SqlException ex)
{
throw new LibraryException(ex.Message,
LibraryException.ErrorCode.GenericException);
}
return myitem;
}
/// <summary>
/// Add item to loan table
/// </summary>
/// <param name="memberID"></param>
/// <param name="copyNumber"></param>
/// <param name="isbnNumber"></param>
public void CheckOutItem(int memberID, short copyNumber, int
isbnNumber)
{
try
{
//Open Library connection
//using (SqlConnection cnn = new
SqlConnection(connectionString))
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
11. using (SqlCommand cmd = new
SqlCommand("checkOutBookItem", cnn))
{
Item member = new Item();
// Item member = new Item(isbnNumber,
copyNumber, memberID);
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Passes in the memberID, copyNumber and
isbnNumber passed in
// from the checkout screen.
cmd.Parameters.AddWithValue("@isbn",
isbnNumber);
cmd.Parameters.AddWithValue("@copy_no",
copyNumber);
cmd.Parameters.AddWithValue("@member_no",
memberID);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
/* Error Codes From the CheckOut Book stored
procedure...
Return -1 -- 'isbn is null'
Return -2 -- 'copy_no is null'
Return -3 -- 'member_no is null'
Return -4 -- 'book does not exist'
Return -5 -- 'member does not exist'
Return -6 -- 'copy does not exist'
Return -7 -- 'book already checked out'
Return -8 -- 'member has 4 books already'
Return -9 -- 'insert failed'
*/
int returnValue =
(int)cmd.Parameters["@Return"].Value;
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new LibraryException("isbn is
null", LibraryException.ErrorCode.IsbnIsNull);
case -2:
throw new LibraryException("copy_no
is null", LibraryException.ErrorCode.CopyNoIsNull);
case -3:
throw new
LibraryException("member_no is null",
LibraryException.ErrorCode.MemberNoIsNull);
12. case -4:
throw new LibraryException("book
does not exist", LibraryException.ErrorCode.BookDoesNotExist);
case -5:
throw new LibraryException("member
does not exist", LibraryException.ErrorCode.NoSuchMember);
case -6:
throw new LibraryException("copy
does not exist", LibraryException.ErrorCode.CopyDoesNotExist);
case -7:
throw new LibraryException("book
already checked out", LibraryException.ErrorCode.BookAlreadyCheckedOut);
case -8:
throw new LibraryException("member
has 4 books already",
LibraryException.ErrorCode.MemberHasfourBooksAlready);
case -9:
throw new LibraryException("insert
failed", LibraryException.ErrorCode.InsertFailed);
}
}
}
}
}
catch (SqlException sqlex)
{
throw new LibraryException(sqlex.Message,
LibraryException.ErrorCode.GenericException);
}
}
/// <summary>
///
/// </summary>
/// <param name="copyNumber"></param>
/// <param name="isbnNumber"></param>
public void CheckInItem(short copyNumber, int isbnNumber)
{
try
{
//Open Library connection
//using (SqlConnection cnn = new
SqlConnection(connectionString))
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
using (SqlCommand cmd = new
SqlCommand("CheckInBookItem", cnn))
{
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
13. prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Passes the new member variables to the
stored proc
cmd.Parameters.AddWithValue("@isbn",
isbnNumber);
cmd.Parameters.AddWithValue("@copy_no",
copyNumber);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
// Get Error Code
int returnValue =
(int)cmd.Parameters["@Return"].Value;
/* Error codes:
Return -1 -- 'isbn is null'
Return -2 -- 'copy_no is null'
Return -3 -- 'member_no is null'
Return -4 -- 'book does not exist'
Return -5 -- 'copy does not exist'
Return -6 -- 'book is not checked out'
Return -7 -- 'delete from loan table
failed'
Return -8 -- 'Adding row to loan history
table failed'
Return -9 -- 'Update on copy table failed'
*/
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new LibraryException("isbn is
null", LibraryException.ErrorCode.IsbnIsNull);
case -2:
throw new LibraryException("copy_no
is null", LibraryException.ErrorCode.CopyNoIsNull);
case -3:
throw new
LibraryException("member_no is null",
LibraryException.ErrorCode.MemberNoIsNull);
case -4:
throw new LibraryException("book
does not exist", LibraryException.ErrorCode.BookDoesNotExist);
case -5:
throw new LibraryException("member
does not exist", LibraryException.ErrorCode.DeleteFailed);
case -6:
14. throw new LibraryException("copy
does not exist", LibraryException.ErrorCode.InsertFailed);
case -7:
throw new LibraryException("book
already checked out", LibraryException.ErrorCode.BookAlreadyCheckedOut);
case -8:
throw new LibraryException("member
has 4 books already",
LibraryException.ErrorCode.MemberHasfourBooksAlready);
case -9:
throw new LibraryException("insert
failed", LibraryException.ErrorCode.UpdateFailed);
}
}
}
}
}
catch (SqlException ex)
{
throw new LibraryException(ex.Message,
LibraryException.ErrorCode.GenericException);
}
}
/// <summary>
///
/// </summary>
/// <param name="member"></param>
public void AddMember(AdultMember member)
{
try
{
//Open Library connection
//using (SqlConnection cnn = new
SqlConnection(connectionString))
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
using (SqlCommand cmd = new SqlCommand("AddAdult",
cnn))
{
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Passes the new member variables to the
stored proc
cmd.Parameters.AddWithValue("@lastName",
member.LastName);
15. cmd.Parameters.AddWithValue("@name",
member.FirstName);
cmd.Parameters.AddWithValue("@middleInitial",
member.MiddleInitial);
cmd.Parameters.AddWithValue("@street",
member.Street);
cmd.Parameters.AddWithValue("@city",
member.City);
cmd.Parameters.AddWithValue("@state",
member.State);
cmd.Parameters.AddWithValue("@zipCode",
member.ZipCode);
cmd.Parameters.AddWithValue("@phoneNumber",
member.PhoneNumber);
// Add the output params
prm = new SqlParameter("@InsertMemberID",
SqlDbType.SmallInt);
prm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(prm);
prm = new SqlParameter("@ExpirationDate",
SqlDbType.DateTime);
prm.Direction = ParameterDirection.Output;
cmd.Parameters.Add(prm);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
// --RETURN Codes:
//-- RETURN 0 --
Successful
//-- RETURN -1
--'Firstname is null'
//-- RETURN -2
--'LastName is null'
//-- RETURN -3
--'Street is null'
//-- RETURN -4
--'City is null'
//-- RETURN -5
--'State is null'
//-- RETURN -6
--'Zip is null'
//-- RETURN -7
--'insert into member failed'
//-- RETURN -8 --'insert
into adult failed'
// Get Error Code
int returnValue =
(int)cmd.Parameters["@Return"].Value;
if (returnValue != 0)
switch (returnValue)
{
case -1:
16. throw new
LibraryException("Firstname is null",
LibraryException.ErrorCode.FirstnameIsNull);
case -2:
throw new
LibraryException("LastName is null",
LibraryException.ErrorCode.LastNameIsNull);
case -3:
throw new LibraryException("Street
is null", LibraryException.ErrorCode.StreetIsNull);
case -4:
throw new LibraryException("City is
null", LibraryException.ErrorCode.CityIsNull);
case -5:
throw new LibraryException("State
is null", LibraryException.ErrorCode.StateIsNull);
case -6:
throw new LibraryException("Zip is
null", LibraryException.ErrorCode.ZipIsNull);
case -7:
throw new LibraryException("insert
into member failed", LibraryException.ErrorCode.InsertFailed);
case -8:
throw new LibraryException("insert
into adult failed", LibraryException.ErrorCode.InsertFailed);
}
// Get return variables
member.ExpirationDate = (DateTime)
(cmd.Parameters["@ExpirationDate"].Value);
member.MemberID =
(short)cmd.Parameters["@InsertMemberID"].Value;
}
}
}
catch (SqlException ex)
{
throw new LibraryException(ex.Message,
LibraryException.ErrorCode.GenericException);
}
}
/// <summary>
/// Insert juvenile and member rows into Library data base
/// </summary>
/// <param name="member">JuvenileMember object</param>
public void AddMember(JuvenileMember member)
{
try
{//Open Library connection
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
using (SqlCommand cmd = new
SqlCommand("AddJuvenile", cnn))
17. {
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Pass the new member variables to the stored
proc
cmd.Parameters.AddWithValue("@lastname",
member.LastName);
cmd.Parameters.AddWithValue("@name",
member.FirstName);
cmd.Parameters.AddWithValue("@middleInitial",
member.MiddleInitial);
cmd.Parameters.AddWithValue("@adultMemberID",
member.AdultMemberID);
cmd.Parameters.AddWithValue("@juvBirthDate",
member.BirthDate);
// Add the output params
SqlParameter memberIDParm = new SqlParameter();
memberIDParm.ParameterName = "@InsertMemberID";
memberIDParm.SqlDbType = SqlDbType.SmallInt;
memberIDParm.Direction =
ParameterDirection.Output;
cmd.Parameters.Add(memberIDParm);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
// Get Error Code
int returnValue =
(int)cmd.Parameters["@Return"].Value;
// RETURN 0 --
Successful
//-- RETURN -1 --'name is
null'
//-- RETURN -2
--'middleinitial is null'
//-- RETURN -3
--'lastname is null'
//-- RETURN -4
--'adultmemberid is null'
//-- RETURN -5
--'juvbirthdate is null'
//-- RETURN -6
--'insert into member failed'
//-- RETURN -7 --'insert
into juvenile failed'
if (returnValue != 0)
{
18. switch (returnValue)
{
case -1:
throw new
LibraryException("Firstname is null",
LibraryException.ErrorCode.FirstnameIsNull);
case -2:
throw new
LibraryException("MiddleInitial is null",
LibraryException.ErrorCode.NullValue);
case -3:
throw new
LibraryException("lastname is null",
LibraryException.ErrorCode.LastNameIsNull);
case -4:
throw new
LibraryException("adultMemberId is null",
LibraryException.ErrorCode.AddAdultFailed);
case -5:
throw new
LibraryException("juvBirthDateis null",
LibraryException.ErrorCode.BirthdateNull);
case -6:
throw new LibraryException("Insert
Into Member Failed", LibraryException.ErrorCode.InsertFailed);
case -7:
throw new LibraryException("insert
Int Juvenile failed", LibraryException.ErrorCode.AddJuvenileFailed);
}
}
member.MemberID =
(short)cmd.Parameters["@InsertMemberID"].Value;
}
}
}
catch (SqlException ex)
{
throw new LibraryException(ex.Message,
LibraryException.ErrorCode.GenericException);
}
}
/// <summary>
/// Used to renew membership
/// </summary>
/// <param name="memberNumber"></param>
public void RenewMembership(int memberNumber)
{
try
{
//Open Library connection
//using (SqlConnection cnn = new
SqlConnection(connectionString))
19. using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
using (SqlCommand cmd = new
SqlCommand("RenewExpirationDate", cnn))
{
Item member = new Item();
// Item member = new Item(isbnNumber,
copyNumber, memberID);
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Passes in the memberID
// from the checkout screen.
cmd.Parameters.AddWithValue("@member_no",
memberNumber);
// Add the output params
SqlParameter memberExpDate = new SqlParameter();
memberExpDate.ParameterName = "@expr_date";
memberExpDate.SqlDbType = SqlDbType.DateTime;
memberExpDate.Direction =
ParameterDirection.Output;
cmd.Parameters.Add(memberExpDate);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
/* Error Codes From the CheckOut Book stored
procedure...
Return -1 -- 'Failed: Member number is
null'
Return -2 -- 'Failed: Member does not
exist'
Return -3 -- 'Insert into adult member
table failed'
*/
int returnValue =
(int)cmd.Parameters["@Return"].Value;
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new LibraryException("Failed:
Member number is null", LibraryException.ErrorCode.MemberNoIsNull);
case -2:
20. throw new LibraryException("Failed:
Member does not exist", LibraryException.ErrorCode.NoSuchMember);
case -3:
throw new LibraryException("Insert
into adult member table failed",
LibraryException.ErrorCode.InsertFailed);
}
}
}
}
}
catch (SqlException sqlex)
{
throw new LibraryException(sqlex.Message,
LibraryException.ErrorCode.GenericException);
}
}
/// <summary>
/// Method used to add a new book to the library database
/// </summary>
/// <param name="title"></param>
/// <param name="author"></param>
/// <param name="synopsis"></param>
/// <param name="isbn"></param>
/// <param name="translation"></param>
/// <param name="cover"></param>
/// <param name="loanable"></param>
public void AddNewBook(string title, string author, string
synopsis, int isbn, string translation, string cover, char loanable)
{
try
{
//Open Library connection
//using (SqlConnection cnn = new
SqlConnection(connectionString))
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
using (SqlCommand cmd = new
SqlCommand("EnterNewBook", cnn))
{
Item member = new Item();
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Passes in the values
// from the checkout screen.
21. cmd.Parameters.AddWithValue("@title", title);
cmd.Parameters.AddWithValue("@author", author);
cmd.Parameters.AddWithValue("@synopsis",
synopsis);
cmd.Parameters.AddWithValue("@isbn", isbn);
cmd.Parameters.AddWithValue("@translation",
translation);
cmd.Parameters.AddWithValue("@cover", cover);
cmd.Parameters.AddWithValue("@loanable",
loanable);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
/*
***********************************************************************
****
* RETURN Codes:
RETURN -0 -- Sucesss
RETURN -1 -- The title is null
RETURN -2 -- The author is null
RETURN -3 -- The synopsis is null is
null
RETURN -4 -- The translation is null
RETURN -5 -- The cover is null
RETURN -6 -- The loanable is null
RETURN -7 -- The isbn is null is null
RETURN -8 -- The ISBN exist in the
Item table
RETURN -9 -- The isbn exist in the
copy table
RETURN -10 -- INSERT for the title
table failed
RETURN -11 -- INSERT for the item table
failed
RETURN -12 -- INSERT for the copy table
failed
**********************************************
********************************/
int returnValue =
(int)cmd.Parameters["@Return"].Value;
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new LibraryException("The
title is null", LibraryException.ErrorCode.titleIsNull);
case -2:
throw new LibraryException("The
author is null", LibraryException.ErrorCode.AuthorIsNull);
case -3:
throw new LibraryException("The
synopsis is null is null", LibraryException.ErrorCode.SynopsisIsNull);
22. case -4:
throw new LibraryException("The
translation is null", LibraryException.ErrorCode.TranslationIsNull);
case -5:
throw new LibraryException("The
cover is null", LibraryException.ErrorCode.CoverIsNull);
case -6:
throw new LibraryException("The
loanable is null", LibraryException.ErrorCode.LoanableIsNull);
case -7:
throw new LibraryException("The
isbn is null is null", LibraryException.ErrorCode.IsbnIsNull);
case -8:
throw new LibraryException("The
ISBN exist in the Item table",
LibraryException.ErrorCode.IsbnExistInItemTable);
case -9:
throw new LibraryException("The
isbn exist in the copy table",
LibraryException.ErrorCode.IsbnExistInCopyTable);
case -10:
throw new LibraryException("INSERT
for the title table failed",
LibraryException.ErrorCode.TitleInsertFailed);
case -11:
throw new LibraryException("INSERT
for the item table failed",
LibraryException.ErrorCode.ItemInsertFailed);
case -12:
throw new LibraryException("INSERT
for the copy table failed",
LibraryException.ErrorCode.CopyInsertFailed);
}
}
}
}
}
catch (SqlException sqlex)
{
throw new LibraryException(sqlex.Message,
LibraryException.ErrorCode.GenericException);
}
}
/// <summary>
/// Method created to convert a Juvenile member of less than 18
yrs of age to an adult member)
/// </summary>
/// <param name="memberNumber"></param>
public void adolescentToAdult(int memberNumber)
{
try
{
//Open Library connection
23. //using (SqlConnection cnn = new
SqlConnection(connectionString))
using (SqlConnection cnn = new
SqlConnection(Settings.Default.libraryConnectionString))
{
//create the command within a using block
using (SqlCommand cmd = new
SqlCommand("KidToAdult", cnn))
{
Item member = new Item();
cmd.CommandType = CommandType.StoredProcedure;
// Set up the return value parameter
SqlParameter prm = new SqlParameter();
prm.ParameterName = "@Return";
prm.Direction = ParameterDirection.ReturnValue;
cmd.Parameters.Add(prm);
// Passes in the memberID
// from the checkout screen.
cmd.Parameters.AddWithValue("@member_no",
memberNumber);
// Open connection and execute query
cnn.Open();
cmd.ExecuteNonQuery();
/* Error Codes From the KitToAdult Book stored
procedure...
Return -1 -- 'Juvenile member
number is null'
Return -2 -- 'Juvenile member does
not exist'
Return -3 -- 'Delete from juvenile
member table failed'
Return -4 -- ''Insert into adult
member table failed'
*/
int returnValue =
(int)cmd.Parameters["@Return"].Value;
if (returnValue != 0)
{
switch (returnValue)
{
case -1:
throw new
LibraryException("Juvenile member number is null",
LibraryException.ErrorCode.MemberNoIsNull);
case -2:
throw new
LibraryException("Juvenile member does not exist",
LibraryException.ErrorCode.NoSuchMember);
case -3:
24. throw new LibraryException("Delete
from juvenile member table failed",
LibraryException.ErrorCode.DeleteFailed);
case -4:
throw new LibraryException("Insert
into adult member table failed",
LibraryException.ErrorCode.InsertFailed);
}
}
}
}
}
catch (SqlException sqlex)
{
throw new LibraryException(sqlex.Message,
LibraryException.ErrorCode.GenericException);
}
}
}
}
Exception Class Created To Handle Errors
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
/*
* Description: The exception that is thrown when a non-fatal
application
* error occurs in the Library application.
* For a list of all members of this type, see LibraryException
Members.
* LibraryException*/
/*
* Author: Marcelo D. Salvador
* Create Date: 11/24/2008
* Modified Date: 11/28/2007
* Modification: 12/01/2008
********************************************************************/
namespace Ms.Library.Entities
{
[Serializable]
public class LibraryException : System.Exception, ISerializable
{
protected ErrorCode errorCodeMessage;
25. //This enumeration defines the error codes that can be returned
in a LibraryException.
/// <summary>
/// Enumeration listing the error codes according to the return
values from the sqlserver
/// database.
/// </summary>
public enum ErrorCode
{
None, //No error code has been provided.
GenericException, //A generic exception was thrown. Check
the exception message and the inner exception for details.
ItemNotFound, //No Item with the specified ISBN and copy
number was found.
NoSuchMember, //No member with the specified member number
was found.
ItemNotOnLoan, //Item with the specified ISBN and copy
number is not on loan currently.
CheckInFailed, //Failed to check in specified item.
ItemAlreadyOnLoan, //Item with the specified ISBN and copy
number is already on loan to another member. Check the OtherMemberID
property of the LibraryException to obtain the member ID of the member
to whom the item is on loan currently.
CheckOutFailed, //Failed to check out specified item.
AddAdultFailed, //Failed to add new adult member.
MissingAdultMember, //No sponsoring adult member record
could be found while trying to add a new juvenile member.
AddJuvenileFailed, //Failed to add new juvenile member.
IsbnIsNull,
CopyNoIsNull,
MemberNoIsNull,
BookDoesNotExist,
CopyDoesNotExist,
BookAlreadyCheckedOut,
MemberHasfourBooksAlready,
InsertFailed,
OutOfRangeMemberValue,
DeleteFailed,
UpdateFailed,
FirstnameIsNull,
LastNameIsNull,
StreetIsNull,
CityIsNull,
StateIsNull,
ZipIsNull,
BirthdateNull,
NullValue,
titleIsNull,
AuthorIsNull,
SynopsisIsNull,
TranslationIsNull,
CoverIsNull,
LoanableIsNull,
IsbnExistInItemTable,
IsbnExistInCopyTable,
TitleInsertFailed,
ItemInsertFailed,
26. CopyInsertFailed
}
/// <summary>
/// Default Constructor
/// </summary>
public LibraryException() { }
/// <summary>
/// Constructor to pass messages accordingly
/// </summary>
/// <param name="message"></param>
public LibraryException(string message)
: base(message)
{}
/// <summary>
/// Constructor utilized to reference the values
/// </summary>
/// <param name="message"></param>
/// <param name="error"></param>
public LibraryException(string message, ErrorCode error)
: base(message)
{
// sets the property value to be referenced
errorCodeMessage = error;
}
/// <summary>
/// Property utilized to carry on the enum's functionlity
/// </summary>
public ErrorCode LibraryErrorCode
{
get
{
return errorCodeMessage;
}
set { errorCodeMessage = value; }
}
/*Parameter SerializationInfo
* The object that holds the serialized object data.
* StreamingContext The contextual information about
* the source or destination.
* Remarks: Used by the serialization mechanism to rehydrate
* an instance of this exception.*/
/// <summary>
///
/// </summary>
/// <param name="info"></param>
/// <param name="context"></param>
public override void GetObjectData(SerializationInfo info,
StreamingContext context)
{
base.GetObjectData(info, context);
if (info != null)
{
info.AddValue("ErrorCode", this.errorCodeMessage);