Thursday, March 29, 2012

ITC162 Assignment Six

Description

Recreate assignment one in Android


What I am looking for

Incorporating the classes 10 pts

The Android form 5 pts

Code for listeners 5 pts


To Turn in

copy all the files, including the xml files into Google docs and share with spconger@gmail.com

ITC162 Assignment Five (Group Assignment)

Overview

For this assignment work in groups of three or four people. We will use this same assignment as a group assignment for Android. If you have an idea for a group project other than this one, present it and I will consider it. It must have a similar complexity.


Description

The goal is to create a program that allows a user to choose a School Program like Programming, or Mobile Development of Web Development and load a program description and a list of the required courses.

Additionally a user should be able to track which courses they have completed and what courses remain to be done.

It should be possible to see which program courses are being offered in the upcoming quarter.

There is also an administrator part of this that allows an administrator to enter program information and course information

For now we will just use xml files for data storage

Here is a use case diagram with the general requirements

Everything should have a swing front end



What I am looking for

Each group should produce a class diagram of their domain classes 10 pts

Classes developed and integrated according to the relations in the diagram 15 pts

Reading and writing XML files 10 pts

Swing forms front end 10 pts

Working successfully in a group 5 pts

The whole is worth 50 pts


To Turn in

Make sure all group members names are in the doucments. Zip the project post it on goodle docs and share it with spconger@gmail.com

ITC162 Assignment Four

Overview

For this assignment take the classes you refactored and use them as a source for a banking application with a Swing front end.

You should create a window with a menu that lets you choose which account you wish to work with. When you select it should open a window with options for entering transaction information for that account and viewing the balances and transactions when done.


What I am looking for

Main form with menu 10 points

Account forms 5 points

working with the account classes 5 pts


To turn in

Zip the project and post the zipped file on google. Share it with spconger@gmail.com

ITC162 Assignment Three

Refractoring

Below are three classes for a banking application. There is a lot of repeated code and other redundancies.

The goal of the assignment is to restructure the classes to eliminate as much redundancy as possible. This can involve encapsulating elements into a new class. It can involve making super classes or interfaces.


To Do

Restructure the code in the classes so that they conform to good OOP principles.

Create a Class diagram to show the new structure of the classes and their relationships to each other


To turn in (what I am looking for)

The code for the classes 10 pts

The UML diagram 10 points


Code for Classes

Checking.java

import java.util.*;
public class Checking {
 /*
  * Class for refactoring:
  * This class tracks transactions in a 
  * checking account. At this point they 
  * are not stored to file, but just stored
  * in an ArrayList
  * 
  */
 
 //private fields
 private String customerName;
 private String accountNumber;
 private String customerAddress;
 private String customerPhone;
 private double balance;
 private final double OVERDRAFTFEE=25;
 ArrayList transactions;
 
 
 //constructors
 public Checking(){
  balance = 0;
  transactions = new ArrayList<Double>();
  
 }
 
 public Checking(double initialBalance){
  balance=initialBalance;
  transactions.add(initialBalance);
 }
 
 //assessors and mutators
 public void setCustomerName(String customerName) {
  this.customerName = customerName;
 }
 public String getCustomerName() {
  return customerName;
 }
 public void setAccountNumber(String accountNumber) {
  this.accountNumber = accountNumber;
 }
 public String getAccountNumber() {
  return accountNumber;
 }
 private void setCustomerAddress(String customerAddress) {
  this.customerAddress = customerAddress;
 }
 private String getCustomerAddress() {
  return customerAddress;
 }
 public void setCustomerPhone(String customerPhone) {
  this.customerPhone = customerPhone;
 }
 public String getCustomerPhone() {
  return customerPhone;
 }
 //balance has only a public get
 public double getBalance(){
  return balance;
 }
 
 //public methods
 public void credit(double amount){
  balance += amount;
  transactions.add(amount);
 }
 
 public void debit(double amount){
  balance -= amount;
  transactions.add(amount*-1);
  if (balance < 0)
  { 
   balance -= OVERDRAFTFEE;
   transactions.add(OVERDRAFTFEE * -1);
  }
 }
 
 public ArrayList<Double> getTransactions(){
  return transactions;
 }
 

}


Savings.java

import java.util.*;

public class Savings {
 
 /*
  * Class for refractoring
  * This class handles the savings account
  * the interest calculations are 
  * extremely simplistic
  */
 
 //private fields
 private String customerName;
 private String accountNumber;
 private String customerAddress;
 private String customerPhone;
 private double balance;
 ArrayList transactions;
 private final double IRATE = .03;
 
 //constructors
 public Savings(){
  balance=0;
 }
 
 public Savings(double initialBal){
  balance=initialBal;
 }
 
 public void setCustomerName(String customerName) {
  this.customerName = customerName;
 }
 public String getCustomerName() {
  return customerName;
 }
 public void setAccountNumber(String accountNumber) {
  this.accountNumber = accountNumber;
 }
 public String getAccountNumber() {
  return accountNumber;
 }
 private void setCustomerAddress(String customerAddress) {
  this.customerAddress = customerAddress;
 }
 private String getCustomerAddress() {
  return customerAddress;
 }
 public void setCustomerPhone(String customerPhone) {
  this.customerPhone = customerPhone;
 }
 public String getCustomerPhone() {
  return customerPhone;
 }
 //balance has only a public get
 public double getBalance(){
  return balance;
 }
 
 public void credit(double amount){
  balance += amount;
  transactions.add(amount);
 }
 
 public void debit(double amount){
  balance -= amount;
  transactions.add(amount*-1);
  
 }
 
 public ArrayList<Double> getTransactions(){
  return transactions;
 }
 
 public double CalculateInterest()
 {
  //much too simple but will do 
  //for now
  return balance * IRATE;
  
 
 }

}


CreditCard.java

import java.util.ArrayList;


public class CreditCard {
 /*
  * Class for Refractoring
  * This class handles credit card
  * transactions
  * again many of the calculations
  * are very simple
  */
 
 private String customerName;
 private String accountNumber;
 private String customerAddress;
 private String customerPhone;
 private double creditLimit;
 private double balance;
 ArrayList<Double> transactions;
 private final double IRATE = .22;
 
 public CreditCard(){
  creditLimit=1000;
 }
 
 public CreditCard(double creditLimit){
  this.creditLimit=creditLimit;
 }
 
 public void setCustomerName(String customerName) {
  this.customerName = customerName;
 }
 public String getCustomerName() {
  return customerName;
 }
 public void setAccountNumber(String accountNumber) {
  this.accountNumber = accountNumber;
 }
 public String getAccountNumber() {
  return accountNumber;
 }
 private void setCustomerAddress(String customerAddress) {
  this.customerAddress = customerAddress;
 }
 private String getCustomerAddress() {
  return customerAddress;
 }
 public void setCustomerPhone(String customerPhone) {
  this.customerPhone = customerPhone;
 }
 public String getCustomerPhone() {
  return customerPhone;
 }
 
 //credit limit and balance read only
 public double getCreditLimit(){
  return creditLimit;
 }

 public double getBalance(){
  return balance;
 }
 
 public void credit(double amount){
  //simplistic way to calculate interest
  //doing it on a daily scale
  balance += amount - (amount *(IRATE/365));
  transactions.add(amount);
 }
 
 public void debit(double amount){
  balance -= amount + (amount *(IRATE/365));
  transactions.add(amount*-1);
  
 }
 
 public ArrayList<Double> getTransactions(){
  return transactions;
 }
 
 public double CalculateInterest()
 {
  //much too simple but will do 
  //for now
  return balance * IRATE;
  
 
 }

}

Assignment Two

Description

For this assignment, simply reconfigure assignment one into a model view control pattern


What I am looking for

Setting up the model with existing classes 5 pts

Setting up the controller 10 pts

Modifying the view 5 pts

Wednesday, March 28, 2012

ITC 162 Assignment One

Overview


The first assignment is a grade calculator.


Create a swing form. It should have text boxes for entering course number, number of credits and grade, then a check box to mark if it is a non-numerical grade. If checked, one must select the non numerical grade W, I, NC, A from radio buttons.


When the submit button is clicked it should encapsulate all the fields into an object called grade and pass it to a class called gpaCalculator which adds it to an array list. The gpaCalculator should have a method that loops through the grades, ignoring those with non numerical grades and returns a gpa. (Gpas are calculated by multiplying the grade times the number of credits to get the weight. Then the sum of the weight is divided by the sum of the credits.)


There should be a second button on the swing form to get the GPA. Display the Gpa on the form.




What I am Looking for


The swing form with all it's controls 5 pts

The grade on gpaCalculate classes 5 pts

The swing event handlers 5 pts

Correct GPA calculation and display 5 pts




What To Turn in


zip all the project files and post them on Google docs. Share it with spconger@gmail.com



ITC172 Assignment 4 (Web Services)

Overview

This assignment is going to focus on consuming existing web services. We will also use a Master page to give the site consistency and Ajax panels so that we can use the services without redrawing the whole page.

The Assignment

Start a new empty web site

Add a master page. You should give the master page a basic style and a banner of some sort. The site is going to focus on business tools. The main page will also contain links to the other pages.

Add a new content page. On this page we are going to add three web services:
Mortgage Web Services
Break even point
Stock quote

For each web service you should provide text boxes to accept whatever input is required and then display the results of the service appropriately.

These and the other web services can all be found at Web Serves.Net

Each service should be put in its own AJax box, so it can be executed separately

Add another content page. This one will contain the US ZipCode web service. YOu should implement all four methods. Again put it in an Ajax box.

Another content page will contain the Global weather web service. Implement both of its methods.

A final content page will be to display error information. Validate all text fields and place all code that could fail in try catches

What I am looking for

Design and use of a master page 5 pts

Adding references to web services 5 pts

Implementing the web services and displaying results 5 pts

Use of the Ajax 5 pts

Validation and error trapping 5 pts

ITC 172 Assignment Three (LINQ)

Overview

Instead of doing the whole web site over in Linq, we will modify the assignment to do two things: display a list of registered customers, then then on a separate page add a new customer. Instead of 50 points the assignment will be worth 20

This assignment has the exact functionality of Assignment two, only it uses LINQ instead of ADO.

That means it will have the opening page with the Services, location and login control

It will have the welcome page with customer and vehicle information

It will have the insert page for a new customer

It will have the update page for customer information

It will have the error handler page

All these pages can look and function the same as the ADO pages.

The big difference is we will use LINQ for all the code. We will not need to create our own vehicle or customer or manager classes because LINQ will create them for us.

What I am Looking For

This assignment will also be worth 50 points

Part one: adding the LINQ to SQL Classes 4 pts, Getting the Locations 3 pts, getting the Services 3 pts
Part two, login and redirect 5 pts, Getting and displaying customer and vehicle information 5 pts
Part three Insert form 2 pts, validation 3 pts, insert into database 5 pts
Part four Filling in update form 5 pts, updating database 5 pts

Part five Error trapping 5 pts, Error page 5 points

Sunday, March 18, 2012

Model View Control version of Tip Calculator

The model view control pattern is basic to object oriented programming. It has the advantage of separating out functionality

The Model

The model handles all the data processing. In our case this means the tip class itself with its methods for calculating the tip, the tax and the total. But it can also mean classes that access files or databases

The View

The view is the display part of the program. It could be console, or web, Android xml or in our case Swing. The view is only concerned with getting user input and displaying results. No calculations are performed in the view

The Controller

The controller's responsibility is to transfer the data from the model to the view.

In this example, the main, located in the class program, instantiates the view, the model and the controller and passes the view and model to the controller for processing.

Classes are fairly loosely coupled. The view is unaware of either the model or the controller. The model is unaware of the controller or the view. Only the controller needs to be aware of the other components and they are passed as objects to it through its constructor.

The program behaves exactly like the other examples.



Here is the UML class diagrams for the Model View Control version of this project



Here is the code for the various classes


program.java

import javax.swing.*;

public class program {

 /*******************************
  * this class has the main method.
  *It instantiates the view, the model and 
  *the controller. It passes the view
  *and the model to the controller
  */
 public static void main(String[] args) {
  TipModel model = new TipModel();
  JFrameView view = new JFrameView();
  
  TipController  controller = new TipController(view, model);
  view.setBounds(100,100,500,300);
  view.setTitle("Tip Calculator MVC");
  view.setVisible(true);
  
 }

}

JFrameView.java

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import java.awt.*;
import java.awt.event.ActionListener;


public class JFrameView extends JFrame{
 
 /**
  * this method creates the JFrame
  * and adds the Panel
  * the panel is actually the main part of the view
  * I have combined the two into one class
  * to make it simpler, so we just have one
  * view class
  * the view is unaware of the model or the 
  * controller, although it knows its listener
  * methods must be sent in from somewhere else
  */
 private JPanel panel;
 
 JPanel buttonPanel;
 JLabel lblAmount;
 JRadioButton tenPercent;
 JLabel choosePercent;
 JRadioButton fifteenPercent;
 JRadioButton twentyPercent;
 JRadioButton rbother;
 JTextField txtOther;
 JLabel lbltax;
 JLabel lblTip;
 JLabel lblTaxPercent;
 JLabel lblTaxAmt;
 JLabel lblTotal;
 JTextField txtAmount;
 JTextField txtTaxPercent;
 JTextField txtTipAmount;
 JTextField txtTaxAmount;
 JTextField txtTotal;
 JLabel lblOther;
 
 JButton calculate;
 JButton exit; 
 
 
 
 double tipPercent;
 double amount;
 double taxPercent;
 
 private static final long serialVersionUID = 1L;

 //constructor
 public JFrameView(){
  JFrame frame=new JFrame();
  frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
  //call the method that builds the panel
  buildPanel();
   
  
  
 
 }
 
 public void buildPanel(){
  
  //instantiate all the objects
  //and set their properties
  panel=new JPanel();
  panel.setLayout(new GridLayout(10,2,5,5));
  
  lblAmount = new JLabel("Enter pre-tax amount:");
  
  txtAmount=new JTextField(10);
  
  tenPercent=new JRadioButton("Ten Percent");
    
  fifteenPercent=new JRadioButton("Fifteen Percent");
  fifteenPercent.setSelected(true);
    
  twentyPercent = new JRadioButton("twenty Percent");
    
  rbother =new JRadioButton("Other");
 
  //add radiobuttons to a button group
  ButtonGroup group = new ButtonGroup();
  group.add(tenPercent);
  group.add(fifteenPercent);
  group.add(twentyPercent);
  group.add(rbother);
  
  lblOther=new JLabel("Enter Other Percent");
  
  txtOther = new JTextField(10);
  
  lblTaxPercent=new JLabel("Enter tax Percent:");
  
  txtTaxPercent=new JTextField(10);
  
  lblTip = new JLabel("Tip Amount:");
  
  txtTipAmount = new JTextField(10);
  txtTipAmount.setEditable(false);
  
  lblTaxAmt = new JLabel("Tax Amount:");
  
  txtTaxAmount =new JTextField(10);
  txtTaxAmount.setEditable(false);
  
  lblTotal = new JLabel("Total:");
  
  txtTotal = new JTextField(10);
  txtTotal.setEditable(false);
  //add all the components 
  //except the buttons to the panel
  
  panel.add(lblAmount);
  panel.add(txtAmount);
  
  panel.add(tenPercent);
  panel.add(fifteenPercent);
  panel.add(twentyPercent);
  panel.add(rbother);
  panel.add(lblOther);
  panel.add(txtOther);
  panel.add(lblTaxPercent);
  panel.add(txtTaxPercent);
  panel.add(lblTip);
  panel.add(txtTipAmount);
  panel.add(lblTaxAmt);
  panel.add(txtTaxAmount);
  panel.add(lblTotal);
  panel.add(txtTotal);
  
  
  
  //add a second panel
  //this one uses flow layout
  buttonPanel = new JPanel();
  buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  
  //instantiate the buttons and add 
  //them to the panel
  //also add a listener
  calculate = new JButton("Calculate");
  //calculate.addActionListener(this);
  buttonPanel.add(calculate);
  
  exit = new JButton("Exit");
  //exit.addActionListener(this);
  buttonPanel.add(exit);
  
  //this, in this case the window
  //we add the two panels to a border
  //layout the main one is in the center
  //the button panel is below (SOUTH)
  this.setLayout(new BorderLayout());
  this.add(panel, BorderLayout.CENTER);
  this.add(buttonPanel, BorderLayout.SOUTH);

}
 
public double GetAmount(){
 //get the strings from the text boxes
 double amount=0;
 try{
 String strAmount=txtAmount.getText();
  amount= Double.parseDouble(strAmount);
 
 }
 catch (Exception e){
  lblTotal.setText(e.getMessage());
 }
 return amount;
}

public double getTipPercent(){
 tipPercent=0;
 
 //check which radio button is selected
 if(tenPercent.isSelected())
  tipPercent=.1;
 else if(fifteenPercent.isSelected())
  tipPercent=.15;
 else if (twentyPercent.isSelected())
  tipPercent=.2;
 else if (rbother.isSelected()){
  String percent=txtOther.getText();
  //there is a chance the parse can fail
  try{
  tipPercent=Double.parseDouble(percent);
  }
  catch(Exception e){
   lblTotal.setText(e.getMessage());
  }
 }
 else
  tipPercent=0;
 return tipPercent;
}

public double getTaxPercent(){
 String taxPerc = txtTaxPercent.getText();
 try{
 taxPercent=Double.parseDouble(taxPerc);
 }
 catch(Exception e){
  lblTotal.setText(e.getMessage());
 }
 return taxPercent;
}

public void setTotal(String total){
 lblTotal.setText(total);
}

public void setTip(String tip){
 lblTip.setText(tip);
}

public void setTax(String tax){
 lblTaxAmt.setText(tax);
}

//these are different rather than implement
//the listeners here the controller will return the 
//listener to the view
public void addCalculateListener(ActionListener cal){
 calculate.addActionListener(cal);
}

public void addExitListener(ActionListener el){
 exit.addActionListener(el);
}
}

TipController.java

import java.awt.event.*;
import javax.swing.*;

public class TipController {
 
 /******************************
  * So this is the controller. It gets both
  * the model and the view from the program
  * class which contains the main() method
  * It implements two internal classes
  * as listeners
  */
 private JFrameView m_view;
 private TipModel m_model;
 
 public TipController (JFrameView view, TipModel model){
  m_view=view;
  m_model=model;
  
  //here it returns the listeners to the view
  view.addCalculateListener(new CalculateListener());
  view.addExitListener(new ExitListener());
 }
 
 class CalculateListener implements ActionListener{
  
  public void actionPerformed(ActionEvent e){
   //get the user's input values from the view's form
   double amt=m_view.GetAmount();
   double tPercent=m_view.getTipPercent();
   double taxPerc=m_view.getTaxPercent();
   
   //set the values in the model
   m_model.setPreTaxAmount(amt);
   m_model.setTipPercent(tPercent);
   m_model.setTaxPercent(taxPerc);
   
   //do the calculations and pass them back to the view
   //I did both in single statements
   m_view.setTip(Double.toString(m_model.CalculateTip()));
   m_view.setTax(Double.toString(m_model.CalculateTax()));
   m_view.setTotal(Double.toString(m_model.CalculateTotal()));
   
  }
 }
 
 class ExitListener implements ActionListener{
  
  public void actionPerformed(ActionEvent e){
   System.exit(0);
  }
 }
}


TipModel.java


public class TipModel {
/*************************
 * this is the model class. It handles the data
 * and does all the calculations. It is totally
 * independent of the controller and the view
 * it is identical to the tip class in the 
 * former version
 */
 //private fields
 private double preTaxAmount;
 private double tipPercent;
 private double taxPercent;
 
 //constructors
 public TipModel(){
  preTaxAmount=0;
  tipPercent=0;
  taxPercent=0;
 }
 
 public TipModel(double preTaxAmount, double tipPercent, double taxPercent){
  this.setPreTaxAmount(preTaxAmount);
  this.setTipPercent(tipPercent);
  this.setTaxPercent(taxPercent);
 }
 
 
 //assessors/mutators
 public void setPreTaxAmount(double preTaxAmount) {
  this.preTaxAmount = preTaxAmount;
 }
 public double getPreTaxAmount() {
  return preTaxAmount;
 }
 public void setTipPercent(double tipPercent) {
  //make sure the tip is a decimal
  //or zero
  if (tipPercent >=1)
   tipPercent /= 100;
  this.tipPercent = tipPercent;
 }
 public double getTipPercent() {
  return tipPercent;
 }
 public void setTaxPercent(double taxPercent) {
  if(taxPercent >=1)
   taxPercent /=100;
  this.taxPercent = taxPercent;
 }
 public double getTaxPercent() {
  return taxPercent;
 }
 
 //public methods
 public double CalculateTip(){
  return preTaxAmount * tipPercent;
 }
 
 public double CalculateTax(){
  return preTaxAmount * taxPercent;
 }
 
 public double CalculateTotal(){
  return preTaxAmount + (preTaxAmount * tipPercent)
    + (preTaxAmount * taxPercent);
 }
 
 

}

Thursday, March 15, 2012

Inner Classes for Handling Listeners

It is a common practice in Java to use Inner classes to handle Listener events. An inner class is a private class contained in another class. As a private class it has access to all the fields and values of the containing class.

To me this is a violation of many OOP principles, such as encapsulation and the idea that classes should be as loosely coupled as possible. But, practically speaking, it is probably the best way to handle multiple events in a JPanel class.

Another practice is to use anonymous classes, which are inner classes that are not explicitly declared as such. I would discourage their use, even though they are also a common Java practice

Here is the code for a class that extends JPanel. It has two inner classes to handle the Listeners for two different buttons. This class, of course, would be called by a class extending JFrame.



import java.awt.GridLayout;
import javax.swing.*;
import java.awt.event.*;


public class PercentFormPanel extends JPanel{
 
 JPanel panel;
 JLabel lblAmount;
 JTextField txtAmount;
 JRadioButton tenPercent;
 JRadioButton fifteenPercent;
 JRadioButton twentyPercent;
 JLabel lblResult;
 JButton btnCalculate;
 JButton btnExit;
 
 public PercentFormPanel(){
 
  panel = new JPanel(new GridLayout(5,2,5,5));
  BuildPanel();
  this.add(panel);
  
 }
 private void BuildPanel(){
  lblAmount = new JLabel("Enter a Number and choose a percent");
  txtAmount= new JTextField(10);
  tenPercent=new JRadioButton("Ten Percent");
  fifteenPercent=new JRadioButton("Fifteen Percent");
  twentyPercent=new JRadioButton("Twenty Percent");
  
  ButtonGroup group = new ButtonGroup();
  group.add(tenPercent);
  group.add(fifteenPercent);
  group.add(twentyPercent);
  
  btnCalculate = new JButton("Calculate");
  //calls the internal class and its listener
  btnCalculate.addActionListener(new CalculateListener());
  
  lblResult = new JLabel();
  
  btnExit = new JButton("Exit");
  //calls internal class
  btnExit.addActionListener(new ExitListener());
  
  panel.add(lblAmount);
  panel.add(txtAmount);
  panel.add(tenPercent);
  panel.add(fifteenPercent);
  panel.add(twentyPercent);
  
  panel.add(lblResult);
  panel.add(btnCalculate);
  panel.add(btnExit);
 }
 
 //begin first internal class
 class CalculateListener implements ActionListener{
  public void actionPerformed(ActionEvent e){
   double percent;
   String amt = txtAmount.getText();
   if (amt.isEmpty())
    return;
   double amount=Double.parseDouble(amt);
   if (tenPercent.isSelected())
    percent=amount * .1;
   else if (fifteenPercent.isSelected())
    percent=amount *.15;
   else if (twentyPercent.isSelected())
    percent=amount * .2;
   else
    percent=amount;
   
   lblResult.setText(Double.toString(percent));
  }
  
 }
 
 //second internal class
 class ExitListener implements ActionListener{
  public void actionPerformed(ActionEvent e){
  
   System.exit(0);
  }
 }
 
 

}



Tuesday, March 13, 2012

A Front End Example

this is ugly but it show briefly how coding a front end would work. this page is for the employees, when a car comes in they would enter the car's license plate and the program would bring up the car information and all the past services

First here is a picture of the program running

Here is the code for the html and ASP xml Default.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="Enter License Plate"></asp:Label><asp:TextBox
            ID="txtLicense" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="GetVehicle" 
            onclick="Button1_Click" />
        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" 
            GridLines="None">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>
        <asp:GridView ID="GridView2" runat="server" BackColor="LightGoldenrodYellow" 
            BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black" 
            GridLines="None">
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
            <FooterStyle BackColor="Tan" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
                HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <SortedAscendingCellStyle BackColor="#FAFAE7" />
            <SortedAscendingHeaderStyle BackColor="#DAC09E" />
            <SortedDescendingCellStyle BackColor="#E1DB9C" />
            <SortedDescendingHeaderStyle BackColor="#C2A47B" />
        </asp:GridView>
    </div>
    </form>
</body>
</html>


Here is the C# code Default.aspx.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //connect to the database
        //pass it the sql
        //retreive the results
        SqlConnection connect = new SqlConnection
        ("Data source=Localhost;initial catalog=automart;integrated security=true");

        string sql = "Select VehicleID, LastName, Firstname, LicenseNumber, "
        + "VehicleMake, VehicleYear From Customer.Vehicle "
        + "inner Join Person "
        + "on Person.PersonKey=Vehicle.PersonKey "
        + "Where LicenseNumber = @License";

        SqlCommand cmd = new SqlCommand(sql, connect);
        cmd.Parameters.AddWithValue("@License", txtLicense.Text);

        DataSet ds = new DataSet();

        SqlDataAdapter da = new SqlDataAdapter(cmd);

        da.Fill(ds);

        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();

        string sql2 = "Select LocationName, ServiceDate, ServiceTime, "
            + " ServiceName From Customer.Location loc"
            + " Inner Join Employee.VehicleService vs "
            + " on loc.LocationID = vs.LocationID "
            + "inner join Employee.VehicleServiceDetail vsd "
            + " on vs.VehicleServiceID=vsd.VehicleServiceID "
            + " inner Join Customer.AutoService a "
            + "on a.AutoServiceID=vsd.AutoServiceID "
            + "Where VehicleID=@VehicleID";

        SqlCommand cmd2 = new SqlCommand(sql2, connect);
        int vehID = 0;
        foreach(DataRow row in ds.Tables[0].Rows)
        {
            vehID = int.Parse(row["VehicleID"].ToString());
        }

        cmd2.Parameters.AddWithValue("@VehicleID",vehID);

        SqlDataAdapter da2 = new SqlDataAdapter(cmd2);
        da2.Fill(ds, "Services");

        GridView2.DataSource = ds.Tables["Services"];
        GridView2.DataBind();

    }
}

Saturday, March 10, 2012

A More Complex Swing Example

Here is a more complex swing example. It creates a form for handling basic tip calculations for a restaurant. It uses a variety of controls and also uses three different layouts: FlowLayout, GridLayout and BorderLayout. The code is commented to describe what each element does. First here is the code for the tip class, that does the actual calculations

This program could use many improvements. In particular, it needs error trapping and validation, but it does give the gist of how to create a somewhat more complex swing form.

Before I list the classes, Here is a basic UML diagram of the relationships among the classes for this program

The relationship between MainJFrame and MealTipPanel is between a whole and a part. The MealTipPanel is a part of the JFrame. When the JFrame is destroyed so is the Panel. This type of relationship is called "Composition." The relationship between MealTipPanel and Tip is called "Association." MealTipPanel calls upon and uses the Tip class, but the tip class has a separate existance. It is not a part of the MealTipPanel class. It could be passed to another class and continue even if the MealTipPanel is destroyed. The relationship between Project and MainJFrame is also associative.


Tip.Java


public class Tip {
 /*********************************
  * this class handles a simple tip
  * on a meal. It takes in the amount,
  * the tax percent and the tip percent
  * and has methods that return
  * the amount of the tip
  * the amount of tax
  * the total amount due
  * Steve Conger 3/7/2012
  */
 
 
 //private fields
 private double preTaxAmount;
 private double tipPercent;
 private double taxPercent;
 
 //constructors
 public Tip(){
  preTaxAmount=0;
  tipPercent=0;
  taxPercent=0;
 }
 
 public Tip(double preTaxAmount, double tipPercent, double taxPercent){
  this.setPreTaxAmount(preTaxAmount);
  this.setTipPercent(tipPercent);
  this.setTaxPercent(taxPercent);
 }
 
 
 //assessors/mutators
 public void setPreTaxAmount(double preTaxAmount) {
  this.preTaxAmount = preTaxAmount;
 }
 public double getPreTaxAmount() {
  return preTaxAmount;
 }
 public void setTipPercent(double tipPercent) {
  //make sure the tip is a decimal
  //or zero
  if (tipPercent >=1)
   tipPercent /= 100;
  this.tipPercent = tipPercent;
 }
 public double getTipPercent() {
  return tipPercent;
 }
 public void setTaxPercent(double taxPercent) {
  if(taxPercent >=1)
   taxPercent /=100;
  this.taxPercent = taxPercent;
 }
 public double getTaxPercent() {
  return taxPercent;
 }
 
 //public methods
 public double CalculateTip(){
  return preTaxAmount * tipPercent;
 }
 
 public double CalculateTax(){
  return preTaxAmount * taxPercent;
 }
 
 public double CalculateTotal(){
  return preTaxAmount + (preTaxAmount * tipPercent)
  + (preTaxAmount * taxPercent);
 }
 
 

}


Here is the code for the Panel class that contains all the content for the swing form

MealTipPanel.Java

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.FlowLayout;
import java.awt.BorderLayout;

public class MealTipPanel extends JPanel implements ActionListener{
 
 /**
  * This class sets up the content of the Frame
  * it contains two panels 
  * on sets up the form itself and uses
  * the grid layout
  * the other uses the flowLayout
  * and sets up the buttons
  * the class extends JPanel and implements
  * the action listener which handles
  * the button events
  */
 private static final long serialVersionUID = 1L;
 
 //private fields, Swing components
 JPanel panel;
 JPanel buttonPanel;
 JLabel lblAmount;
 JRadioButton tenPercent;
 JLabel choosePercent;
 JRadioButton fifteenPercent;
 JRadioButton twentyPercent;
 JRadioButton rbother;
 JTextField txtOther;
 JLabel lbltax;
 JLabel lblTip;
 JLabel lblTaxPercent;
 JLabel lblTaxAmt;
 JLabel lblTotal;
 JTextField txtAmount;
 JTextField txtTaxPercent;
 JTextField txtTipAmount;
 JTextField txtTaxAmount;
 JTextField txtTotal;
 JLabel lblOther;
 
 JButton calculate;
 JButton exit; 
 
 //class level variables
 Tip t;
 double tipPercent;
 double amount;
 double taxPercent;
 
 //constructor which calls create panel
 public MealTipFrame(){
  CreatePanel();
 }
 
 private void CreatePanel(){
  
  //make the components new
  //and set properties
  //this first panel uses a grid layout
  //it has 10 rows, 2 columns and a spacing
  //of 5 pixels between cells
  panel=new JPanel();
  panel.setLayout(new GridLayout(10,2,5,5));
  
  lblAmount = new JLabel("Enter pre-tax amount:");
  
  txtAmount=new JTextField(10);
  
  tenPercent=new JRadioButton("Ten Percent");
    
  fifteenPercent=new JRadioButton("Fifteen Percent");
  fifteenPercent.setSelected(true);
    
  twentyPercent = new JRadioButton("twenty Percent");
    
  rbother =new JRadioButton("Other");
 
  //add radiobuttons to a button group
  ButtonGroup group = new ButtonGroup();
  group.add(tenPercent);
  group.add(fifteenPercent);
  group.add(twentyPercent);
  group.add(rbother);
  
  lblOther=new JLabel("Enter Other Percent");
  
  txtOther = new JTextField(10);
  
  lblTaxPercent=new JLabel("Enter tax Percent:");
  
  txtTaxPercent=new JTextField(10);
  
  lblTip = new JLabel("Tip Amount:");
  
  txtTipAmount = new JTextField(10);
  txtTipAmount.setEditable(false);
  
  lblTaxAmt = new JLabel("Tax Amount:");
  
  txtTaxAmount =new JTextField(10);
  txtTaxAmount.setEditable(false);
  
  lblTotal = new JLabel("Total:");
  
  txtTotal = new JTextField(10);
  txtTotal.setEditable(false);
  //add all the components 
  //except the buttons to the panel
  
  panel.add(lblAmount);
  panel.add(txtAmount);
  
  panel.add(tenPercent);
  panel.add(fifteenPercent);
  panel.add(twentyPercent);
  panel.add(rbother);
  panel.add(lblOther);
  panel.add(txtOther);
  panel.add(lblTaxPercent);
  panel.add(txtTaxPercent);
  panel.add(lblTip);
  panel.add(txtTipAmount);
  panel.add(lblTaxAmt);
  panel.add(txtTaxAmount);
  panel.add(lblTotal);
  panel.add(txtTotal);
  
  
  
  //add a second panel
  //this one uses flow layout
  buttonPanel = new JPanel();
  buttonPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  
  //instantiate the buttons and add 
  //them to the panel
  //also add a listener
  calculate = new JButton("Calculate");
  calculate.addActionListener(this);
  buttonPanel.add(calculate);
  
  exit = new JButton("Exit");
  exit.addActionListener(this);
  buttonPanel.add(exit);
  
  //this, in this case the window
  //we add the two panels to a border
  //layout the main one is in the center
  //the button panel is below (SOUTH)
  this.setLayout(new BorderLayout());
  this.add(panel, BorderLayout.CENTER);
  this.add(buttonPanel, BorderLayout.SOUTH);
  
  
  
  
 }
 
 //this is the listener 
 @Override
 public void actionPerformed(ActionEvent e) {
  //check which object was clicked
  Object source = e.getSource();
  if(source==exit)
   System.exit(0); //exit
  else if (source==calculate){
   getTipInfo(); //call the method
  //to process the tips
   //call display results
   displayResults();
  }
 }
 
 private void getTipInfo(){
  
  //get the strings from the text boxes
  String strAmount=txtAmount.getText();
  String taxPerc = txtTaxPercent.getText();
  tipPercent=0;
  
  //check which radio button is selected
  if(tenPercent.isSelected())
   tipPercent=.1;
  else if(fifteenPercent.isSelected())
   tipPercent=.15;
  else if (twentyPercent.isSelected())
   tipPercent=.2;
  else if (rbother.isSelected()){
   String percent=txtOther.getText();
   tipPercent=Double.parseDouble(percent);
  }
  else
   tipPercent=0;
  
  //convert the string values to double
  amount = Double.parseDouble(strAmount);
  taxPercent=Double.parseDouble(taxPerc);
 }
  
 private void displayResults(){
  // Instantiate the tip and access methods
  //display the results
  t = new Tip(amount, tipPercent, taxPercent);
  txtTipAmount.setText(Double.toString(t.CalculateTip()));
  txtTaxAmount.setText(Double.toString(t.CalculateTax()));
  txtTotal.setText(Double.toString(t.CalculateTotal()));
  
 }
 }



Here is the code for the JFrame itself.

MainJFrame.java

import javax.swing.*;
import java.awt.*;


public class MainJFrame extends JFrame{

 /**
  * this method creates the JFrame
  * and adds the Panel
  */
 private static final long serialVersionUID = 1L;

 public MainJFrame(){
  JFrame frame=new JFrame();
  frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
  
  JPanel panel = new MealTipPanel();
  this.add(panel);
  
  
  
  
 
 }
 
}


Here is the code for the Project.java

public class Project {

 /**
  * this class is the starting point of the project
  * it calls the main frame.
  * sets the title and sets the size
  * and makes it visible
  */
 public static void main(String[] args) {
  MainJFrame m = new MainJFrame();
  m.setTitle("Tip Calculator");
  m.setBounds(200,200,350,350);
 
  m.setVisible(true);
 }

}


Finally here is a picture of the running program

Basic Swing Tutorial

Swing is a set of libraries that provide Java with the controls to make window like forms and graphics.

First Swing Form

Start a new Java project and add a new Java class called "SampleWindow". Here is the code for the class:


import javax.swing.*;

public class SampleWindow extends JFrame {
 
        public SampleWindow(){
  JFrame frame = new JFrame();
                frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
 
 }
 
 

}

First we must import the swing libraries. Our class inherits (extends) the JFrame class that provides the basic window elements. In the constructor of the class we instantiate a new instance of JFrame

Add another class to the project called "Project" or whatever you want to call it. It should have a void main method. The code for this class is:


public class Project {
 
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  SampleWindow w= new SampleWindow();
  w.setBounds(200, 100, 250, 150);
  w.setTitle("First Window");
  w.setVisible(true);
 }
}

In the main we instantiate the JFrame window and set a few of its properties, its bounds, its title and its visibility. The result is a simple empty frame.

Adding a Panel

Now we will add a panel and a couple of controls to the project. Add a new class called contentPanel. The code is below:


import java.awt.FlowLayout;

import javax.swing.*;

public class contentPanel extends JPanel{

 JPanel panel;
 JLabel label;
 JButton button;
 
 public contentPanel(){
  panel =new JPanel();
  panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  AddControls();
 }
 
 private void AddControls(){
  label = new JLabel("Click the Button"); 
  button = new JButton("Click Me");
  
  panel.add(label);
  panel.add(button);
  
  this.add(panel);
 }
}

We also need to add the panel to the JFrame


import javax.swing.*;

public class SampleWindow extends JFrame {
 
 public SampleWindow(){
  JFrame frame = new JFrame();
  frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
  JPanel p = new contentPanel();
  this.add(p);
 
 }
 
 

}

This class extends JPanel. We add two controls a JLabel and a JButton. In the constructor we initialize the panel and set the layout type to flow layout. The AddControls method initializes the controls and adds them to the panel. The last line adds the panel to the current container context.

When you run the program you get the following window:,/p>

Adding an ActionListener

Clicking on the button doesn't do anything at this point. In order to make it work we need to implement the actionListener interface. Here is the code with the actionListener added


import java.awt.FlowLayout;
import java.awt.event.*;

import javax.swing.*;

public class contentPanel extends JPanel implements ActionListener{

 JPanel panel;
 JLabel label;
 JButton button;
 
 public contentPanel(){
  panel =new JPanel();
  panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
  AddControls();
 }
 
 private void AddControls(){
  label = new JLabel("Click the Button"); 
  button = new JButton("Click Me");
  button.addActionListener(this);
  
  panel.add(label);
  panel.add(button);
  
  this.add(panel);
 }
 
 public void actionPerformed(ActionEvent e) {
  Object source = e.getSource();
  if (source==button)
   label.setText("You Clicked me");
 }
}


Note the added import statement that imports events. Also note the line that ties the button to the listener.


button.addActionListener(this);

in the actionPerformed method we first determine what control is the source of the event. If the control is the button we change the text of the label. Below is a picture of the frame after clicking the button.

Tuesday, March 6, 2012

Manual Login using Login Control and ADO

Here is the CS code for Default1.aspx


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        //connect
        SqlConnection connect = new SqlConnection
            ("Data Source=localhost;initial catalog=Automart;integrated security=true");

        SqlCommand cmd = new SqlCommand
            ("Select email, Customerpassword, PersonKey "
+ "From Customer.RegisteredCustomer Where email=@email "
+ " and CustomerPassword=@password", connect);
        cmd.Parameters.AddWithValue("@email", Login1.UserName.ToString());
        cmd.Parameters.AddWithValue("@password", Login1.Password.ToString());

        DataSet ds = new DataSet();
        SqlDataReader reader;

        connect.Open();
        reader = cmd.ExecuteReader();
        ds.Load(reader,LoadOption.OverwriteChanges,"LoginTable");
        reader.Dispose();
        connect.Close();

        foreach (DataRow row in ds.Tables[0].Rows)
        {
            if (row["email"].ToString().Equals(Login1.UserName.ToString()) 
&& row["CustomerPassword"].ToString().Equals(Login1.Password.ToString()))
            {

                e.Authenticated = true;
                Session["ID"] = row["PersonKey"];
                Response.Redirect("Default2.aspx");

            }
            else
            {
                e.Authenticated = false;
            }
        }




    }
}


Here is code for Default2.aspx

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection connect = new SqlConnection
            ("Data Source=Localhost;initial catalog=AutoMart;integrated security=true");

        StringBuilder sb = new StringBuilder();
        sb.Append("Select LicenseNumber, VehicleMake, VehicleYear, LocationName, ");
        sb.Append("ServiceDate, ServiceTime, ServiceName, ServicePrice, DiscountPercent ");
        sb.Append("From  Customer.Vehicle v ");
        sb.Append("Inner Join Employee.VehicleService vs ");
        sb.Append("on v.VehicleID=vs.VehicleID ");
        sb.Append("Inner Join Employee.VehicleServiceDetail vsd ");
        sb.Append("on vs.VehicleServiceID=vsd.VehicleServiceID ");
        sb.Append("Inner Join Customer.Location l ");
        sb.Append("on l.LocationID=vs.LocationID ");
        sb.Append("Inner Join Customer.AutoService a ");
        sb.Append("on a.AutoServiceID=vsd.AutoserviceID ");
        sb.Append("Where v.PersonKey=@PersonKey");

        SqlCommand cmd = new SqlCommand(sb.ToString(), connect);
        cmd.Parameters.AddWithValue("@PersonKey", (int)Session["ID"]);

        SqlDataReader reader=null;
        DataSet ds = new DataSet();

        connect.Open();
        reader = cmd.ExecuteReader();
        ds.Load(reader, LoadOption.OverwriteChanges, "Services");
        reader.Dispose();
        connect.Close();

        GridView1.DataSource = ds.Tables["Services"];
        GridView1.DataBind();

    }
}

Monday, March 5, 2012

XML

Here is what we did in class. Remember that we used Visual Studio to set up the xml and the CreateSchema command from the xml menu in Visual Studio to create the schema


Select * From Meeting

Select * From Person for xml raw('person'), elements, root('Persons')

Select lastname, firstname, LicenseNumber, VehicleMake, VehicleYear
From Person 
inner Join Customer.vehicle
on person.Personkey=Customer.Vehicle.PersonKey
For Xml auto, elements, root('customers')






Create xml Schema Collection meetingSchema
As
'<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" 
elementFormDefault="qualified" 
targetNamespace="http://www.automart.com/meeting" 
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="meeting">
<xs:complexType>
<xs:sequence>
<xs:element name="attending">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="name" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="body">
<xs:complexType>
<xs:sequence>
<xs:element name="topics">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="topic" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="actionItems">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="item" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>'

Create table Meeting
(
 meetingID int identity(1,1) primary key,
 meetingDate date,
 meetingTopic nvarchar(255),
 meetingNotes xml(meetingSchema)
)

Insert into Meeting (meetingDate, meetingTopic, meetingNotes)
values (GETDATE(), 'xml stuff', 
'<?xml version="1.0" encoding="utf-8"?>
<meeting xmlns="http://www.automart.com/meeting">
 <Attending>
  <name></name>
  <name></name>
 </Attending>
 <body>
  <topics>
   <topic></topic>
   <topic></topic>
  </topics>
  <actionItems>
   <item></item>
   <item></item>
  </actionItems>
 </body>
 
</meeting>')

Here is an early one from last year. It may give you more context

Use MagazineSubscription

Select * from Magazine
For xml raw('magazine'), root('Magazines'), Elements

Create xml schema collection MemoCollection
As
'<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" 
elementFormDefault="qualified" 
targetNamespace="http://www.spconger.com/memo"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="memo">
<xs:complexType>
<xs:sequence>
<xs:element name="heading">
<xs:complexType>
<xs:sequence>
<xs:element name="to" type="xs:string" />
<xs:element name="from" type="xs:string" />
<xs:element name="about" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="body">
<xs:complexType>
<xs:sequence>
<xs:element maxOccurs="unbounded" name="p" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>'

Create table Memo
(
memoID int identity(1,1) primary Key,
memoDate datetime,
memocontent xml(dbo.MemoCollection)
)

Insert into Memo (memoDate, memocontent)
Values(GETDATE(),
'<?xml version="1.0" encoding="utf-8"?>
<memo xmlns="http://www.spconger.com/memo">
<heading>

<to>Everyone</to>
<from>me</from> 
<about>nothing</about>
</heading>
<body>
<p>We need to do nothing today</p>
<p>The same for tomorrow</p>
</body>
</memo>')

Select * from Memo

--administrative sql
Go
Create schema SalesPerson

Create view SalesPerson.vw_Customers
As
Select * from Customer
go
Create login Sales with password='p@ssww0rd1' 


Create user Salesuser for login Sales with default_schema=SalesPerson

Grant select on Schema::SalesPerson to SalesUser