USE [master]
GO
/****** Object:  Database [QuestionsDb]    Script Date: 04/03/2016 03:40:37 ******/
CREATE DATABASE [QuestionsDb] ON  PRIMARY 
( NAME = N'QuestionsDb', FILENAME = N'D:\QuestionsDb.mdf' , SIZE = 3072KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'QuestionsDb_log', FILENAME = N'D:\QuestionsDb_log.ldf' , SIZE = 11200KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
ALTER DATABASE [QuestionsDb] SET COMPATIBILITY_LEVEL = 100
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [QuestionsDb].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [QuestionsDb] SET ANSI_NULL_DEFAULT OFF
GO
ALTER DATABASE [QuestionsDb] SET ANSI_NULLS OFF
GO
ALTER DATABASE [QuestionsDb] SET ANSI_PADDING OFF
GO
ALTER DATABASE [QuestionsDb] SET ANSI_WARNINGS OFF
GO
ALTER DATABASE [QuestionsDb] SET ARITHABORT OFF
GO
ALTER DATABASE [QuestionsDb] SET AUTO_CLOSE OFF
GO
ALTER DATABASE [QuestionsDb] SET AUTO_CREATE_STATISTICS ON
GO
ALTER DATABASE [QuestionsDb] SET AUTO_SHRINK OFF
GO
ALTER DATABASE [QuestionsDb] SET AUTO_UPDATE_STATISTICS ON
GO
ALTER DATABASE [QuestionsDb] SET CURSOR_CLOSE_ON_COMMIT OFF
GO
ALTER DATABASE [QuestionsDb] SET CURSOR_DEFAULT  GLOBAL
GO
ALTER DATABASE [QuestionsDb] SET CONCAT_NULL_YIELDS_NULL OFF
GO
ALTER DATABASE [QuestionsDb] SET NUMERIC_ROUNDABORT OFF
GO
ALTER DATABASE [QuestionsDb] SET QUOTED_IDENTIFIER OFF
GO
ALTER DATABASE [QuestionsDb] SET RECURSIVE_TRIGGERS OFF
GO
ALTER DATABASE [QuestionsDb] SET  DISABLE_BROKER
GO
ALTER DATABASE [QuestionsDb] SET AUTO_UPDATE_STATISTICS_ASYNC OFF
GO
ALTER DATABASE [QuestionsDb] SET DATE_CORRELATION_OPTIMIZATION OFF
GO
ALTER DATABASE [QuestionsDb] SET TRUSTWORTHY OFF
GO
ALTER DATABASE [QuestionsDb] SET ALLOW_SNAPSHOT_ISOLATION OFF
GO
ALTER DATABASE [QuestionsDb] SET PARAMETERIZATION SIMPLE
GO
ALTER DATABASE [QuestionsDb] SET READ_COMMITTED_SNAPSHOT OFF
GO
ALTER DATABASE [QuestionsDb] SET HONOR_BROKER_PRIORITY OFF
GO
ALTER DATABASE [QuestionsDb] SET  READ_WRITE
GO
ALTER DATABASE [QuestionsDb] SET RECOVERY FULL
GO
ALTER DATABASE [QuestionsDb] SET  MULTI_USER
GO
ALTER DATABASE [QuestionsDb] SET PAGE_VERIFY CHECKSUM
GO
ALTER DATABASE [QuestionsDb] SET DB_CHAINING OFF
GO
EXEC sys.sp_db_vardecimal_storage_format N'QuestionsDb', N'ON'
GO
USE [QuestionsDb]
GO
/****** Object:  UserDefinedFunction [dbo].[UdfGetDateWithSlash]    Script Date: 04/03/2016 03:40:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[UdfGetDateWithSlash](@MyFullDateTime datetime)
returns nvarchar(20)
as
begin                      
       return( select left(convert(VARCHAR,@MyFullDateTime,112),4) + '/' +  substring(convert(VARCHAR,@MyFullDateTime,112),5,2) + '/' + right(convert(VARCHAR,@MyFullDateTime,112),2))
END
GO
/****** Object:  Table [dbo].[tlGoodsGroups]    Script Date: 04/03/2016 03:40:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tlGoodsGroups](
	[GoodsGroupID] [int] IDENTITY(1,1) NOT NULL,
	[GoodsGroupName] [nvarchar](250) NOT NULL,
 CONSTRAINT [PK_tlGoodsGroups] PRIMARY KEY CLUSTERED 
(
	[GoodsGroupID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tlGoodsGroups] ON [dbo].[tlGoodsGroups] 
(
	[GoodsGroupName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblStaffTypes]    Script Date: 04/03/2016 03:40:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblStaffTypes](
	[StaffTypeID] [smallint] IDENTITY(1,1) NOT NULL,
	[StaffTypeDescription] [nvarchar](150) NOT NULL,
 CONSTRAINT [PK_tblStaffTypes] PRIMARY KEY CLUSTERED 
(
	[StaffTypeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblStaffTypes] ON [dbo].[tblStaffTypes] 
(
	[StaffTypeDescription] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  View [dbo].[Rnd]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Rnd]
AS
SELECT     RAND() AS Rnd
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 2160
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Rnd'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Rnd'
GO
/****** Object:  UserDefinedFunction [dbo].[UdfMakeDateInStingFull]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create function [dbo].[UdfMakeDateInStingFull](@InPuteDateTime datetime)
returns nvarchar(50)
as
begin
return (SELECT LEFT(DATENAME(WEEKDAY,@InPuteDateTime),3) + ' ' + CAST(DAY(@InPuteDateTime) AS VARCHAR(2)) + '-' + DATENAME(MONTH, @InPuteDateTime)
           + '-' + CAST(YEAR(@InPuteDateTime) AS VARCHAR(4)) + ' ' + 
           CAST(DatePart(Hour,@InPuteDateTime) AS VARCHAR(2)) + ':' + CAST(DatePart(Minute,@InPuteDateTime)AS VARCHAR(2)) + ':' + CAST(DatePart(Second,@InPuteDateTime)AS VARCHAR(2))
            )
end
GO
/****** Object:  Table [dbo].[tblStaffs]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblStaffs](
	[StaffID] [int] IDENTITY(1,1) NOT NULL,
	[StaffTypeID] [smallint] NOT NULL,
	[StaffName] [nvarchar](150) NOT NULL,
	[StaffSname] [nvarchar](150) NOT NULL,
	[StaffJob] [nvarchar](150) NOT NULL,
	[TimeWorkAmount] [decimal](18, 0) NOT NULL,
	[IsWoman] [bit] NOT NULL,
	[FatherName] [nvarchar](150) NULL,
	[IsRecruitment] [bit] NOT NULL,
 CONSTRAINT [PK_tblStafs] PRIMARY KEY CLUSTERED 
(
	[StaffID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  View [dbo].[XtblIsNullFatherName]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[XtblIsNullFatherName]
AS
SELECT     StaffID, StaffTypeID, StaffName, StaffSname, FatherName, ISNULL(FatherName, StaffName) AS IsNullFatherName
FROM         dbo.tblStaffs
WHERE     (StaffID > 39)
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblStaffs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 126
               Right = 211
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblIsNullFatherName'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblIsNullFatherName'
GO
/****** Object:  View [dbo].[Xtml3Left3Right]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtml3Left3Right]
AS
SELECT     LEFT(StaffName, 3) + RIGHT(StaffSname, 3) AS نام
FROM         dbo.tblStaffs
WHERE     (IsRecruitment = 1)
GROUP BY LEFT(StaffName, 3) + RIGHT(StaffSname, 3)
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblStaffs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 126
               Right = 211
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 2820
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 4935
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtml3Left3Right'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtml3Left3Right'
GO
/****** Object:  Table [dbo].[tblGoodsGroupProperties]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblGoodsGroupProperties](
	[GoodsGroupPropeID] [int] IDENTITY(1,1) NOT NULL,
	[GoodsGroupID] [int] NOT NULL,
	[GoodsGroupPropDescription] [nvarchar](250) NOT NULL,
 CONSTRAINT [PK_tblGoodsGroupProperties] PRIMARY KEY CLUSTERED 
(
	[GoodsGroupPropeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblGoodsGroupProperties] ON [dbo].[tblGoodsGroupProperties] 
(
	[GoodsGroupPropDescription] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblGoods]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblGoods](
	[GoodsID] [int] IDENTITY(1,1) NOT NULL,
	[GoodsGroupID] [int] NOT NULL,
	[GoodsName] [nvarchar](250) NOT NULL,
 CONSTRAINT [PK_tblGoods] PRIMARY KEY CLUSTERED 
(
	[GoodsID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblGoods] ON [dbo].[tblGoods] 
(
	[GoodsName] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblFactorsForSalesGoods]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblFactorsForSalesGoods](
	[FactorID] [int] NOT NULL,
	[FactorDate] [datetime] NOT NULL,
	[FactorCreatorID] [int] NOT NULL,
	[FactorFullDate]  AS ([dbo].[UdfMakeDateInStingFull]([FactorDate])),
 CONSTRAINT [PK_tblFactorsForSalesGoods] PRIMARY KEY CLUSTERED 
(
	[FactorID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  UserDefinedFunction [dbo].[UdfGetSalaryByID]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[UdfGetSalaryByID]
(
@StaffID int
)
RETURNS decimal
AS
BEGIN
	RETURN (select s.TimeWorkAmount from tblStaffs s where s.StaffID = @StaffID)
END
GO
/****** Object:  UserDefinedFunction [dbo].[Random]    Script Date: 04/03/2016 03:40:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE FUNCTION [dbo].[Random] (@Upper INT,@Lower INT)
RETURNS INT
AS
BEGIN
DECLARE @Random INT
SELECT @Random = ROUND(((@Upper - @Lower -1) * (select top(1) * from Rnd) + @Lower), 0)
RETURN @Random
END;
GO
/****** Object:  StoredProcedure [dbo].[SpGetNrecordsNames]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create Procedure [dbo].[SpGetNrecordsNames]
@MyCounterInput int
as
begin

declare @MyTable table
(
	[StaffID] [int]  NOT NULL,
	[StaffName] [nvarchar](150) NOT NULL,
	[StaffSname] [nvarchar](150) NOT NULL,
	[StaffJob] [nvarchar](150) NOT NULL,
	[StaffSex] [nvarchar](150) NOT NULL
)
declare @RecordCount int
declare @MyCounter int

insert into @MyTable
select ROW_NUMBER() over(order by (StaffName)) as dd, * from
(
SELECT     TOP (100) PERCENT StaffName, StaffSname, StaffJob, CASE WHEN [IsWoman] = 1 THEN 'خانم' ELSE 'آقا' END AS 'جنسیت'
FROM         dbo.tblStaffs
WHERE     (IsRecruitment = 1)
GROUP BY StaffName, StaffSname, StaffJob, CASE WHEN [IsWoman] = 1 THEN 'خانم' ELSE 'آقا' END
ORDER BY StaffName, StaffSname)DDD

set @RecordCount = (select COUNT(*) from @MyTable)
set @MyCounter = @RecordCount 

	while  @MyCounter > 0
	begin
		select top(@MyCounterInput) * from @MyTable t where t.StaffID < @MyCounter order by t.StaffID desc
		set @MyCounter = @MyCounter - @MyCounterInput
	end
end
GO
/****** Object:  Table [dbo].[tblStaffSemats]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblStaffSemats](
	[SematID] [int] IDENTITY(1,1) NOT NULL,
	[StaffID] [int] NOT NULL,
	[SematDescID] [smallint] NOT NULL,
 CONSTRAINT [PK_tblStaffSemats] PRIMARY KEY CLUSTERED 
(
	[SematID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblStaffSalary]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tblStaffSalary](
	[SalaryID] [int] IDENTITY(1,1) NOT NULL,
	[StaffID] [int] NOT NULL,
	[TotalTimeWorks] [decimal](18, 0) NOT NULL,
	[TotalSalary]  AS ([dbo].[UdfGetSalaryByID]([StaffID])*[TotalTimeWorks]),
	[SalaryDate] [char](6) NOT NULL,
 CONSTRAINT [PK_tblStaffSalary] PRIMARY KEY CLUSTERED 
(
	[SalaryID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblStaffSalary] ON [dbo].[tblStaffSalary] 
(
	[StaffID] ASC,
	[SalaryDate] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  View [dbo].[Xtbl17_2]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtbl17_2]
AS
SELECT     dbo.tblStaffs.StaffID, dbo.tblStaffs.StaffName, dbo.tblStaffs.StaffSname, ISNULL(dbo.tblStaffTypes.StaffTypeDescription, 'بدون سمت') AS Semat, dbo.tblStaffs.TimeWorkAmount, dbo.tblStaffs.IsWoman, 
                      dbo.tblStaffs.FatherName, dbo.tblStaffs.IsRecruitment
FROM         dbo.tblStaffTypes INNER JOIN
                      dbo.tblStaffSemats ON dbo.tblStaffTypes.StaffTypeID = dbo.tblStaffSemats.SematDescID RIGHT OUTER JOIN
                      dbo.tblStaffs ON dbo.tblStaffSemats.StaffID = dbo.tblStaffs.StaffID
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[13] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblStaffs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 214
               Right = 211
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblStaffSemats"
            Begin Extent = 
               Top = 7
               Left = 310
               Bottom = 112
               Right = 470
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblStaffTypes"
            Begin Extent = 
               Top = 17
               Left = 557
               Bottom = 107
               Right = 747
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 2880
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl17_2'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl17_2'
GO
/****** Object:  View [dbo].[Xtbl17_1]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtbl17_1]
AS
SELECT     dbo.tblStaffs.StaffID, dbo.tblStaffs.StaffName, dbo.tblStaffs.StaffSname, dbo.tblStaffTypes.StaffTypeDescription, dbo.tblStaffs.TimeWorkAmount, dbo.tblStaffs.IsWoman, dbo.tblStaffs.FatherName, 
                      dbo.tblStaffs.IsRecruitment
FROM         dbo.tblStaffs INNER JOIN
                      dbo.tblStaffSemats ON dbo.tblStaffs.StaffID = dbo.tblStaffSemats.StaffID INNER JOIN
                      dbo.tblStaffTypes ON dbo.tblStaffSemats.SematDescID = dbo.tblStaffTypes.StaffTypeID
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[41] 4[20] 2[15] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblStaffs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 197
               Right = 211
            End
            DisplayFlags = 280
            TopColumn = 1
         End
         Begin Table = "tblStaffSemats"
            Begin Extent = 
               Top = 6
               Left = 249
               Bottom = 111
               Right = 409
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblStaffTypes"
            Begin Extent = 
               Top = 6
               Left = 447
               Bottom = 96
               Right = 637
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 2160
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl17_1'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl17_1'
GO
/****** Object:  Table [dbo].[tblFactorDetailsExportGoods]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblFactorDetailsExportGoods](
	[FactorDetailsID] [bigint] IDENTITY(1,1) NOT NULL,
	[FactorID] [int] NOT NULL,
	[GoodsID] [int] NOT NULL,
	[GoodsQuantity] [decimal](18, 0) NOT NULL,
	[GoodsUnitPrice] [decimal](18, 0) NOT NULL,
	[GoodsTotalPrice]  AS ([GoodsQuantity]*[GoodsUnitPrice]),
 CONSTRAINT [PK_tblFactorDetailsExportGoods] PRIMARY KEY CLUSTERED 
(
	[FactorDetailsID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblFactorDetailsExportGoods] ON [dbo].[tblFactorDetailsExportGoods] 
(
	[FactorID] ASC,
	[GoodsID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblImportedGoodsWareHouse]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblImportedGoodsWareHouse](
	[ImportGoodsID] [int] IDENTITY(1,1) NOT NULL,
	[PurchaseFactorID] [int] NOT NULL,
	[GoodsID] [int] NOT NULL,
	[ImportQuantity] [decimal](18, 0) NOT NULL,
	[ImportDate] [datetime] NOT NULL,
	[PurchasePrice] [decimal](18, 0) NOT NULL,
	[WarhouseAdminID] [int] NOT NULL,
 CONSTRAINT [PK_tblImportedGoodsWareHouse] PRIMARY KEY CLUSTERED 
(
	[ImportGoodsID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblImportedGoodsWareHouse] ON [dbo].[tblImportedGoodsWareHouse] 
(
	[GoodsID] ASC,
	[PurchaseFactorID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[tblImportedGoodsPropeties]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[tblImportedGoodsPropeties](
	[ImpGoodsPropID] [int] IDENTITY(1,1) NOT NULL,
	[ImportToWarID] [int] NOT NULL,
	[GoodsGroupPropeID] [int] NOT NULL,
	[PropertiesQuantity] [nvarchar](250) NOT NULL,
 CONSTRAINT [PK_tblImportedGoodsPropeties] PRIMARY KEY CLUSTERED 
(
	[ImpGoodsPropID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_tblImportedGoodsPropeties] ON [dbo].[tblImportedGoodsPropeties] 
(
	[ImportToWarID] ASC,
	[ImpGoodsPropID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
GO
/****** Object:  View [dbo].[Xtbl6]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtbl6]
AS
SELECT     REPLACE
                          ((SELECT     StaffName
                              FROM          dbo.tblStaffs AS t
                              WHERE      (StaffID = m.StaffID)), ' ', '') AS نام,
                          (SELECT     StaffName
                             FROM         dbo.tblStaffs AS t
                             WHERE     (StaffID = m.StaffID)) AS [نام خانوادگی], TotalTimeWorks AS [میزان حضور در ماه بر حسب ساعت]
FROM         dbo.tblStaffSalary AS m
WHERE     (StaffID IN
                          (SELECT     TOP (1000) StaffID
                             FROM         dbo.tblStaffs
                             WHERE     (StaffName LIKE '% %')))
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "m"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 126
               Right = 203
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 2190
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl6'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl6'
GO
/****** Object:  View [dbo].[Xtbl3DaysWomenDress]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtbl3DaysWomenDress]
AS
SELECT     GoodsID, GoodsName, GoodsGroupName, SUM(TotalSales) AS TotalSaleQuantity, SUM(GoodsTotalPrice) AS TotalSalesPrice
FROM         (SELECT     Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, Gs.GoodsQuantity AS TotalSales, Gs.GoodsTotalPrice
                        FROM         dbo.tblFactorDetailsExportGoods AS Gs INNER JOIN
                                              dbo.tblGoods AS Goods ON Gs.GoodsID = Goods.GoodsID INNER JOIN
                                              dbo.tlGoodsGroups AS Gg ON Goods.GoodsGroupID = Gg.GoodsGroupID INNER JOIN
                                              dbo.tblFactorsForSalesGoods ON Gs.FactorID = dbo.tblFactorsForSalesGoods.FactorID
                        WHERE     (dbo.tblFactorsForSalesGoods.FactorDate <= CONVERT(date, GETDATE())) AND (dbo.tblFactorsForSalesGoods.FactorDate >= CONVERT(date, DATEADD(day, - 3, GETDATE())))
                        GROUP BY Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, Gs.GoodsQuantity, Gs.GoodsTotalPrice
                        HAVING      (Goods.GoodsID = 1)) AS D
GROUP BY GoodsID, GoodsName, GoodsGroupName
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[40] 4[20] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "D"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 196
               Right = 229
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl3DaysWomenDress'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl3DaysWomenDress'
GO
/****** Object:  StoredProcedure [dbo].[SpGablameSales]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
create procedure [dbo].[SpGablameSales]
@MyStartDate date,
@MyEndDate date,
@SortOrder bit
as
Begin
		if(@SortOrder = 1)
			begin
					SELECT     Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, Gs.GoodsQuantity AS TotalSales, Gs.GoodsTotalPrice
								, dbo.UdfGetDateWithSlash(tblFactorsForSalesGoods.FactorDate) as SalesDate
					FROM         dbo.tblFactorDetailsExportGoods AS Gs INNER JOIN
										  dbo.tblGoods AS Goods ON Gs.GoodsID = Goods.GoodsID INNER JOIN
										  dbo.tlGoodsGroups AS Gg ON Goods.GoodsGroupID = Gg.GoodsGroupID INNER JOIN
										  dbo.tblFactorsForSalesGoods ON Gs.FactorID = dbo.tblFactorsForSalesGoods.FactorID
					WHERE     (dbo.tblFactorsForSalesGoods.FactorDate >= @MyStartDate) AND 
					(dbo.tblFactorsForSalesGoods.FactorDate <= @MyEndDate) AND 
										  (Goods.GoodsID = 4) order by dbo.UdfGetDateWithSlash(tblFactorsForSalesGoods.FactorDate) asc
			 end
		 else
			 begin
					 SELECT     Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, Gs.GoodsQuantity AS TotalSales, Gs.GoodsTotalPrice
								, dbo.UdfGetDateWithSlash(tblFactorsForSalesGoods.FactorDate) as SalesDate
					FROM         dbo.tblFactorDetailsExportGoods AS Gs INNER JOIN
										  dbo.tblGoods AS Goods ON Gs.GoodsID = Goods.GoodsID INNER JOIN
										  dbo.tlGoodsGroups AS Gg ON Goods.GoodsGroupID = Gg.GoodsGroupID INNER JOIN
										  dbo.tblFactorsForSalesGoods ON Gs.FactorID = dbo.tblFactorsForSalesGoods.FactorID
					WHERE     (dbo.tblFactorsForSalesGoods.FactorDate >= @MyStartDate) AND 
					(dbo.tblFactorsForSalesGoods.FactorDate <= @MyEndDate) AND 
										  (Goods.GoodsID = 4) order by dbo.UdfGetDateWithSlash(tblFactorsForSalesGoods.FactorDate) desc
			 end
 END
GO
/****** Object:  View [dbo].[Xtbl16]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtbl16]
AS
SELECT     dbo.tblStaffs.StaffJob AS سمت, SUM(dbo.tblStaffSalary.TotalTimeWorks) AS [جمع میزان ساعت در هر ماه]
FROM         dbo.tblStaffs INNER JOIN
                      dbo.tblStaffSalary ON dbo.tblStaffs.StaffID = dbo.tblStaffSalary.StaffID
GROUP BY dbo.tblStaffs.StaffJob
HAVING      (dbo.tblStaffs.StaffJob = N'صندوقدار ساده') OR
                      (dbo.tblStaffs.StaffJob = N'مسئول انبار وسایل آشپزخانه')
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[24] 4[22] 2[17] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblStaffs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 193
               Right = 216
            End
            DisplayFlags = 280
            TopColumn = 1
         End
         Begin Table = "tblStaffSalary"
            Begin Extent = 
               Top = 6
               Left = 249
               Bottom = 152
               Right = 459
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 2835
         Width = 2985
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 1440
         Alias = 2715
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 2880
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl16'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl16'
GO
/****** Object:  View [dbo].[Xtbl14]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[Xtbl14]
AS
SELECT     dbo.tblStaffs.StaffID, dbo.tblStaffs.StaffName, dbo.tblStaffs.StaffSname, dbo.tblStaffSalary.TotalTimeWorks, dbo.tblStaffSalary.SalaryDate
FROM         dbo.tblStaffs INNER JOIN
                      dbo.tblStaffSalary ON dbo.tblStaffs.StaffID = dbo.tblStaffSalary.StaffID
WHERE     (dbo.tblStaffSalary.TotalTimeWorks > 1000) OR
                      (dbo.tblStaffSalary.TotalTimeWorks > 500) AND (dbo.tblStaffSalary.TotalTimeWorks > 200)
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[24] 4[37] 2[23] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblStaffs"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 170
               Right = 211
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblStaffSalary"
            Begin Extent = 
               Top = 6
               Left = 249
               Bottom = 162
               Right = 414
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1770
         Alias = 900
         Table = 1740
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl14'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'Xtbl14'
GO
/****** Object:  View [dbo].[XtblTotalSales]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[XtblTotalSales]
AS
SELECT     Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, SUM(Gs.GoodsQuantity) AS TotalSales
FROM         dbo.tblFactorDetailsExportGoods AS Gs INNER JOIN
                      dbo.tblGoods AS Goods ON Gs.GoodsID = Goods.GoodsID INNER JOIN
                      dbo.tlGoodsGroups AS Gg ON Goods.GoodsGroupID = Gg.GoodsGroupID
GROUP BY Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[38] 4[23] 2[16] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "Gs"
            Begin Extent = 
               Top = 21
               Left = 693
               Bottom = 183
               Right = 962
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Goods"
            Begin Extent = 
               Top = 4
               Left = 396
               Bottom = 141
               Right = 556
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "Gg"
            Begin Extent = 
               Top = 34
               Left = 79
               Bottom = 150
               Right = 254
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 2160
         Width = 1980
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 12
         Column = 2220
         Alias = 1830
         Table = 3030
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblTotalSales'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblTotalSales'
GO
/****** Object:  View [dbo].[XtblMojoodi]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[XtblMojoodi]
AS
SELECT     InpGoods.GoodsID, InpGoods.GoodsName, InpGoods.GoodsGroupName, InpGoods.TotalInput, OutGoods.TotalSales, InpGoods.TotalInput - OutGoods.TotalSales AS TotalStock
FROM         (SELECT     Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, SUM(InGoods.ImportQuantity) AS TotalInput
                        FROM         dbo.tblGoods AS Goods INNER JOIN
                                              dbo.tblImportedGoodsWareHouse AS InGoods ON Goods.GoodsID = InGoods.GoodsID INNER JOIN
                                              dbo.tlGoodsGroups AS Gg ON Goods.GoodsGroupID = Gg.GoodsGroupID
                        GROUP BY Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName) AS InpGoods INNER JOIN
                          (SELECT     Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName, SUM(Gs.GoodsQuantity) AS TotalSales
                             FROM         dbo.tblFactorDetailsExportGoods AS Gs INNER JOIN
                                                   dbo.tblGoods AS Goods ON Gs.GoodsID = Goods.GoodsID INNER JOIN
                                                   dbo.tlGoodsGroups AS Gg ON Goods.GoodsGroupID = Gg.GoodsGroupID
                             GROUP BY Goods.GoodsID, Goods.GoodsName, Gg.GoodsGroupName) AS OutGoods ON InpGoods.GoodsID = OutGoods.GoodsID
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[32] 4[24] 2[17] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "InpGoods"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 126
               Right = 229
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "OutGoods"
            Begin Extent = 
               Top = 6
               Left = 267
               Bottom = 126
               Right = 458
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 9
         Width = 284
         Width = 1500
         Width = 1740
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1830
         Alias = 1830
         Table = 2595
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblMojoodi'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=1 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblMojoodi'
GO
/****** Object:  View [dbo].[XtblExpireStates]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[XtblExpireStates]
AS
SELECT     dbo.tblImportedGoodsWareHouse.ImportGoodsID, dbo.tblGoods.GoodsName, dbo.tlGoodsGroups.GoodsGroupName, dbo.tblImportedGoodsPropeties.ImpGoodsPropID, 
                      dbo.tblGoodsGroupProperties.GoodsGroupPropDescription, CONVERT(datetime, dbo.tblImportedGoodsPropeties.PropertiesQuantity) AS GoodsExpireDate, DATEDIFF(DAY, GETDATE(), 
                      CONVERT(datetime, dbo.tblImportedGoodsPropeties.PropertiesQuantity)) AS Expr1, CASE WHEN DATEDIFF(DAY, GETDATE(), CONVERT(datetime, 
                      dbo.tblImportedGoodsPropeties.PropertiesQuantity)) < - 30 THEN 'فاسد شده است' WHEN DATEDIFF(DAY, GETDATE(), CONVERT(datetime, dbo.tblImportedGoodsPropeties.PropertiesQuantity)) < 0 AND 
                      DATEDIFF(DAY, GETDATE(), CONVERT(datetime, dbo.tblImportedGoodsPropeties.PropertiesQuantity)) >= - 30 THEN 'درحال فاسد شدن' WHEN DATEDIFF(DAY, GETDATE(), CONVERT(datetime, 
                      dbo.tblImportedGoodsPropeties.PropertiesQuantity)) > 0 THEN 'فاسد نشده' END AS Expr2, dbo.tblImportedGoodsWareHouse.ImportQuantity, 
                      dbo.tblImportedGoodsPropeties.GoodsGroupPropeID
FROM         dbo.tblImportedGoodsPropeties INNER JOIN
                      dbo.tblImportedGoodsWareHouse ON dbo.tblImportedGoodsPropeties.ImportToWarID = dbo.tblImportedGoodsWareHouse.ImportGoodsID INNER JOIN
                      dbo.tblGoods ON dbo.tblImportedGoodsWareHouse.GoodsID = dbo.tblGoods.GoodsID INNER JOIN
                      dbo.tlGoodsGroups ON dbo.tblGoods.GoodsGroupID = dbo.tlGoodsGroups.GoodsGroupID INNER JOIN
                      dbo.tblGoodsGroupProperties ON dbo.tblImportedGoodsPropeties.GoodsGroupPropeID = dbo.tblGoodsGroupProperties.GoodsGroupPropeID
WHERE     (dbo.tblImportedGoodsPropeties.GoodsGroupPropeID = 6)
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane1', @value=N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[27] 4[34] 2[17] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1 [50] 4 [25] 3))"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1 [56] 3))"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4 [50] 3))"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1 [75] 4))"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4))"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 0
   End
   Begin DiagramPane = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "tblImportedGoodsPropeties"
            Begin Extent = 
               Top = 6
               Left = 38
               Bottom = 126
               Right = 225
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblImportedGoodsWareHouse"
            Begin Extent = 
               Top = 6
               Left = 263
               Bottom = 126
               Right = 441
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblGoods"
            Begin Extent = 
               Top = 6
               Left = 479
               Bottom = 111
               Right = 639
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tlGoodsGroups"
            Begin Extent = 
               Top = 6
               Left = 677
               Bottom = 96
               Right = 852
            End
            DisplayFlags = 280
            TopColumn = 0
         End
         Begin Table = "tblGoodsGroupProperties"
            Begin Extent = 
               Top = 6
               Left = 890
               Bottom = 111
               Right = 1113
            End
            DisplayFlags = 280
            TopColumn = 0
         End
      End
   End
   Begin SQLPane = 
   End
   Begin DataPane = 
      Begin ParameterDefaults = ""
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 1440
         Alias = 900
         Table = 1170
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
   ' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblExpireStates'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPane2', @value=N'      Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End
' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblExpireStates'
GO
EXEC sys.sp_addextendedproperty @name=N'MS_DiagramPaneCount', @value=2 , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'VIEW',@level1name=N'XtblExpireStates'
GO
/****** Object:  StoredProcedure [dbo].[DeleteMobl]    Script Date: 04/03/2016 03:40:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
Create procedure [dbo].[DeleteMobl]
as
begin
-- کد مبل سیزده می باشد
delete from tblFactorDetailsExportGoods where GoodsID = 13

delete from tblImportedGoodsPropeties where ImportToWarID 
in (select g.ImportGoodsID from tblImportedGoodsWareHouse g where GoodsID = 13)

delete from tblImportedGoodsWareHouse where GoodsID = 13

delete from tblGoods where GoodsID = 13 
end
GO
/****** Object:  ForeignKey [FK_tblGoodsGroupProperties_tlGoodsGroups]    Script Date: 04/03/2016 03:40:41 ******/
ALTER TABLE [dbo].[tblGoodsGroupProperties]  WITH CHECK ADD  CONSTRAINT [FK_tblGoodsGroupProperties_tlGoodsGroups] FOREIGN KEY([GoodsGroupID])
REFERENCES [dbo].[tlGoodsGroups] ([GoodsGroupID])
GO
ALTER TABLE [dbo].[tblGoodsGroupProperties] CHECK CONSTRAINT [FK_tblGoodsGroupProperties_tlGoodsGroups]
GO
/****** Object:  ForeignKey [FK_tblGoods_tlGoodsGroups]    Script Date: 04/03/2016 03:40:41 ******/
ALTER TABLE [dbo].[tblGoods]  WITH CHECK ADD  CONSTRAINT [FK_tblGoods_tlGoodsGroups] FOREIGN KEY([GoodsGroupID])
REFERENCES [dbo].[tlGoodsGroups] ([GoodsGroupID])
GO
ALTER TABLE [dbo].[tblGoods] CHECK CONSTRAINT [FK_tblGoods_tlGoodsGroups]
GO
/****** Object:  ForeignKey [FK_tblFactorsForSalesGoods_tblStaffs1]    Script Date: 04/03/2016 03:40:41 ******/
ALTER TABLE [dbo].[tblFactorsForSalesGoods]  WITH CHECK ADD  CONSTRAINT [FK_tblFactorsForSalesGoods_tblStaffs1] FOREIGN KEY([FactorCreatorID])
REFERENCES [dbo].[tblStaffs] ([StaffID])
GO
ALTER TABLE [dbo].[tblFactorsForSalesGoods] CHECK CONSTRAINT [FK_tblFactorsForSalesGoods_tblStaffs1]
GO
/****** Object:  ForeignKey [FK_tblStaffSemats_tblStaffs]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblStaffSemats]  WITH CHECK ADD  CONSTRAINT [FK_tblStaffSemats_tblStaffs] FOREIGN KEY([StaffID])
REFERENCES [dbo].[tblStaffs] ([StaffID])
GO
ALTER TABLE [dbo].[tblStaffSemats] CHECK CONSTRAINT [FK_tblStaffSemats_tblStaffs]
GO
/****** Object:  ForeignKey [FK_tblStaffSemats_tblStaffTypes]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblStaffSemats]  WITH CHECK ADD  CONSTRAINT [FK_tblStaffSemats_tblStaffTypes] FOREIGN KEY([SematDescID])
REFERENCES [dbo].[tblStaffTypes] ([StaffTypeID])
GO
ALTER TABLE [dbo].[tblStaffSemats] CHECK CONSTRAINT [FK_tblStaffSemats_tblStaffTypes]
GO
/****** Object:  ForeignKey [FK_tblStaffSalary_tblStaffs]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblStaffSalary]  WITH CHECK ADD  CONSTRAINT [FK_tblStaffSalary_tblStaffs] FOREIGN KEY([StaffID])
REFERENCES [dbo].[tblStaffs] ([StaffID])
GO
ALTER TABLE [dbo].[tblStaffSalary] CHECK CONSTRAINT [FK_tblStaffSalary_tblStaffs]
GO
/****** Object:  ForeignKey [FK_tblFactorDetailsExportGoods_tblFactorsForSalesGoods]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblFactorDetailsExportGoods]  WITH CHECK ADD  CONSTRAINT [FK_tblFactorDetailsExportGoods_tblFactorsForSalesGoods] FOREIGN KEY([FactorID])
REFERENCES [dbo].[tblFactorsForSalesGoods] ([FactorID])
GO
ALTER TABLE [dbo].[tblFactorDetailsExportGoods] CHECK CONSTRAINT [FK_tblFactorDetailsExportGoods_tblFactorsForSalesGoods]
GO
/****** Object:  ForeignKey [FK_tblFactorDetailsExportGoods_tblGoods]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblFactorDetailsExportGoods]  WITH CHECK ADD  CONSTRAINT [FK_tblFactorDetailsExportGoods_tblGoods] FOREIGN KEY([GoodsID])
REFERENCES [dbo].[tblGoods] ([GoodsID])
GO
ALTER TABLE [dbo].[tblFactorDetailsExportGoods] CHECK CONSTRAINT [FK_tblFactorDetailsExportGoods_tblGoods]
GO
/****** Object:  ForeignKey [FK_tblImportedGoodsWareHouse_tblGoods]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblImportedGoodsWareHouse]  WITH CHECK ADD  CONSTRAINT [FK_tblImportedGoodsWareHouse_tblGoods] FOREIGN KEY([GoodsID])
REFERENCES [dbo].[tblGoods] ([GoodsID])
GO
ALTER TABLE [dbo].[tblImportedGoodsWareHouse] CHECK CONSTRAINT [FK_tblImportedGoodsWareHouse_tblGoods]
GO
/****** Object:  ForeignKey [FK_tblImportedGoodsWareHouse_tblStafs]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblImportedGoodsWareHouse]  WITH CHECK ADD  CONSTRAINT [FK_tblImportedGoodsWareHouse_tblStafs] FOREIGN KEY([WarhouseAdminID])
REFERENCES [dbo].[tblStaffs] ([StaffID])
GO
ALTER TABLE [dbo].[tblImportedGoodsWareHouse] CHECK CONSTRAINT [FK_tblImportedGoodsWareHouse_tblStafs]
GO
/****** Object:  ForeignKey [FK_tblImportedGoodsPropeties_tblGoodsGroupProperties]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblImportedGoodsPropeties]  WITH CHECK ADD  CONSTRAINT [FK_tblImportedGoodsPropeties_tblGoodsGroupProperties] FOREIGN KEY([GoodsGroupPropeID])
REFERENCES [dbo].[tblGoodsGroupProperties] ([GoodsGroupPropeID])
GO
ALTER TABLE [dbo].[tblImportedGoodsPropeties] CHECK CONSTRAINT [FK_tblImportedGoodsPropeties_tblGoodsGroupProperties]
GO
/****** Object:  ForeignKey [FK_tblImportedGoodsPropeties_tblImportedGoodsWareHouse]    Script Date: 04/03/2016 03:40:42 ******/
ALTER TABLE [dbo].[tblImportedGoodsPropeties]  WITH CHECK ADD  CONSTRAINT [FK_tblImportedGoodsPropeties_tblImportedGoodsWareHouse] FOREIGN KEY([ImportToWarID])
REFERENCES [dbo].[tblImportedGoodsWareHouse] ([ImportGoodsID])
GO
ALTER TABLE [dbo].[tblImportedGoodsPropeties] CHECK CONSTRAINT [FK_tblImportedGoodsPropeties_tblImportedGoodsWareHouse]
GO
