Deakin University : SIT322 Distributed Systems -59592

Application code must compile the code into one or more assemblies to service requests by users. Assemblies are files that have the file name extension .dll. We write code in C#. When the code is compiled, it is translated into Microsoft Intermediate Language (MSIL) which is  a language-independent and CPU-independent at run time. The context of the .NET Framework translates MSIL into CPU-specific instructions for the computer processor  that  running the application.

USE [master]

GO

/****** Object:  Database [truck]    Script Date: 3/29/2015 8:15:00 AM ******/

CREATE DATABASE [truck]

 CONTAINMENT = NONE

 ON  PRIMARY

( NAME = N’truck’, FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\truck.mdf’ , SIZE = 4096KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )

 LOG ON

( NAME = N’truck_log’, FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA\truck_log.ldf’ , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)

GO

ALTER DATABASE [truck] SET COMPATIBILITY_LEVEL = 110

GO

IF (1 = FULLTEXTSERVICEPROPERTY(‘IsFullTextInstalled’))

begin

EXEC [truck].[dbo].[sp_fulltext_database] @action = ‘enable’

end

GO

ALTER DATABASE [truck] SET ANSI_NULL_DEFAULT OFF

GO

ALTER DATABASE [truck] SET ANSI_NULLS OFF

GO

ALTER DATABASE [truck] SET ANSI_PADDING OFF

GO

ALTER DATABASE [truck] SET ANSI_WARNINGS OFF

GO

ALTER DATABASE [truck] SET ARITHABORT OFF

GO

ALTER DATABASE [truck] SET AUTO_CLOSE OFF

GO

ALTER DATABASE [truck] SET AUTO_CREATE_STATISTICS ON

GO

ALTER DATABASE [truck] SET AUTO_SHRINK OFF

GO

ALTER DATABASE [truck] SET AUTO_UPDATE_STATISTICS ON

GO

ALTER DATABASE [truck] SET CURSOR_CLOSE_ON_COMMIT OFF

GO

ALTER DATABASE [truck] SET CURSOR_DEFAULT  GLOBAL

GO

ALTER DATABASE [truck] SET CONCAT_NULL_YIELDS_NULL OFF

GO

ALTER DATABASE [truck] SET NUMERIC_ROUNDABORT OFF

GO

ALTER DATABASE [truck] SET QUOTED_IDENTIFIER OFF

GO

ALTER DATABASE [truck] SET RECURSIVE_TRIGGERS OFF

GO

ALTER DATABASE [truck] SET  DISABLE_BROKER

GO

ALTER DATABASE [truck] SET AUTO_UPDATE_STATISTICS_ASYNC OFF

GO

ALTER DATABASE [truck] SET DATE_CORRELATION_OPTIMIZATION OFF

GO

ALTER DATABASE [truck] SET TRUSTWORTHY OFF

GO

ALTER DATABASE [truck] SET ALLOW_SNAPSHOT_ISOLATION OFF

GO

ALTER DATABASE [truck] SET PARAMETERIZATION SIMPLE

GO

ALTER DATABASE [truck] SET READ_COMMITTED_SNAPSHOT OFF

GO

ALTER DATABASE [truck] SET HONOR_BROKER_PRIORITY OFF

GO

ALTER DATABASE [truck] SET RECOVERY FULL

GO

ALTER DATABASE [truck] SET  MULTI_USER

GO

ALTER DATABASE [truck] SET PAGE_VERIFY CHECKSUM

GO

ALTER DATABASE [truck] SET DB_CHAINING OFF

GO

ALTER DATABASE [truck] SET FILESTREAM( NON_TRANSACTED_ACCESS = OFF )

GO

ALTER DATABASE [truck] SET TARGET_RECOVERY_TIME = 0 SECONDS

GO

EXEC sys.sp_db_vardecimal_storage_format N’truck’, N’ON’

GO

USE [truck]

GO

/****** Object:  StoredProcedure [dbo].[sp_generateform]    Script Date: 3/29/2015 8:15:01 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

— =============================================

— Author:                    <Author,,Name>

— Create date: <Create Date,,>

— Description: <Description,,>

— =============================================

CREATE PROCEDURE [dbo].[sp_generateform]

            — Add the parameters for the stored procedure here

AS

BEGIN

            — SET NOCOUNT ON added to prevent extra result sets from

            — interfering with SELECT statements.

            SET NOCOUNT ON;

    — Insert statements for procedure here

            SELECT max(Invoiceno) from tbl_inserttruckinfo

            end

GO

/****** Object:  StoredProcedure [dbo].[sp_get_invoice]    Script Date: 3/29/2015 8:15:01 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

— =============================================

— Author:                    <Author,,Name>

— Create date: <Create Date,,>

— Description: <Description,,>

— =============================================

CREATE PROCEDURE [dbo].[sp_get_invoice]

            — Add the parameters for the stored procedure here

            (

            @invoiceno int

            )

AS

BEGIN

            — SET NOCOUNT ON added to prevent extra result sets from

            — interfering with SELECT statements.

            SET NOCOUNT ON;

    — Insert statements for procedure here

            select Fname+’ ‘ +Lname as cname,* from tbl_inserttruckinfo where Isactive=1 and InvoiceNo=@invoiceno

END

GO

/****** Object:  StoredProcedure [dbo].[sp_insert_data]    Script Date: 3/29/2015 8:15:01 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

— =============================================

— Author:                    <Author,,Name>

— Create date: <Create Date,,>

— Description: <Description,,>

— =============================================

CREATE PROCEDURE [dbo].[sp_insert_data]

            (

                                    @InvoiceNo varchar(100),

                                    @Fname varchar(100),

                                    @Lname varchar(100),

                                    @oDeladdress varchar(100),

                                    @orginpostalcode varchar(100),

                                    @Destinationdeliveryaddress varchar(100),

                                    @destpincode varchar(100),

                                    @billingaddress varchar(100),

                                    @Phone varchar(100),

                                    @deliverydate varchar(100),

                                    @deliverytime varchar(100),

                                    @truckNo int ,

                                    @tcost int

          )

AS

BEGIN

            — SET NOCOUNT ON added to prevent extra result sets from

            — interfering with SELECT statements.

            SET NOCOUNT ON;

    — Insert statements for procedure here

            IF EXISTS(select InvoiceNo from tbl_inserttruckinfo where InvoiceNo =@InvoiceNo)

            begin

            select 1

            end

else

begin

            insert into tbl_inserttruckinfo

            (

                                    InvoiceNo ,

                                    Fname ,

                                    Lname ,

                                    oDeladdress,

                                    orginpostalcode ,

                                    Destinationdeliveryaddress ,

                                    destpincode ,

                                    billingaddress ,

                                    Phone ,

                                    deliverydate ,

                                    deliverytime ,

                                    truckNo ,

                                    totalcost

            )

            values

            (

                                    @InvoiceNo ,

                                    @Fname ,

                                    @Lname ,

                                    @oDeladdress,

                                    @orginpostalcode ,

                                    @Destinationdeliveryaddress ,

                                    @destpincode ,

                                    @billingaddress ,

                                    @Phone ,

                                    @deliverydate ,

                                    @deliverytime ,

                                    @truckNo ,

                                    @tcost

            )

END

end

GO

/****** Object:  StoredProcedure [dbo].[sp_rate_calcualtion]    Script Date: 3/29/2015 8:15:01 AM ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

— =============================================

— Author:                    <Author,,Name>

— Create date: <Create Date,,>

— Description: <Description,,>

— =============================================

CREATE PROCEDURE [dbo].[sp_rate_calcualtion]

            (

            @orginpincode varchar(50),

            @destiantionpincode  varchar(50),

            @deliverystartdate varchar(100),

            @deliveryenddate varchar(100),

            @starttime int ,

            @endtime int

)

AS

BEGIN

            — SET NOCOUNT ON added to prevent extra result sets from

            — interfering with SELECT statements.

            SET NOCOUNT ON;

            declare @distance varchar(100),@timediff varchar(50),@insrate int,@totalcost int,@loc varchar(50),@holiday date,@rate int,@rate2 int,@startdate date,@enddate date,@testdate date,@first int,@last  int

    — Insert statements for procedure here,

            declare @charge int, @testday varchar(50),@dcharge float

            set @startdate=convert(date,@deliverystartdate,110)

            set @enddate=convert(date,@deliveryenddate,110)

            set @testdate=@startdate

select @distance=distance, @loc=location from tbl_postalcode  where origin=@orginpincode and destination=@destiantionpincode

set @dcharge=0;

set @dcharge=(@distance*10)/100;

set @timediff=DATEDIFF(hh,@startdate,@enddate)

set @first=0

set @last=0

set @totalcost=0

while @enddate>=@startdate

begin

if @testdate=@startdate

set @first=1

else

set @first=0

if @enddate=@startdate

set @last=1

else

set @last=0

 select @holiday=holidayDate from tbl_holiday where state=@loc and holidayDate between @startdate and @enddate

 if(@first=1)

begin

 if(@holiday is not null)

             begin

                                                             select @rate=publicholidayAP ,@rate2=publicholidayPM from tbl_rateholiday where Location=@loc

                                                —          select @rate2=publicholidayPM from tbl_rateholiday where Location=@loc

            end

            else

            begin

            select @testday=datepart(dw,@startdate)-1

            if(@testday>5)

            begin

                                                             select @rate=WeekendsAP,@rate2=WeekendsPM from tbl_rateholiday where Location=@loc

                                                —          select  from tbl_rateholiday where Location=@loc

            end

            else

            begin

                                                             select @rate=weekdayAP ,@rate2=WeekdayPM from tbl_rateholiday where Location=@loc

                                                —          select  from tbl_rateholiday where Location=@loc

            end

            end

            if(@starttime>=17)

            set @charge=@rate2*(24-@starttime)

            else

            set @charge=@rate*(17-@starttime)+@rate2*7

end

else

begin

                                    if(@last=1)

                                    begin

                                    if(@holiday is not null)