----------------------------------------------------------------------------------------  下：数据表  ----------------------------------------------------------------------------------
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Account]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Account]( 
		[AccountId] [int] IdENTITY(1,1)  NOT NULL , 
		[AccountUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[AccountName] [varchar] (50) NOT NULL , 
		[CompanyName] [varchar] (50) NULL , 
		[AccountImgUrl] [varchar] (100) NULL , 
		[GroupId] [int]  NOT NULL  DEFAULT ('0'), 
		[Email] [varchar] (50) NOT NULL , 
		[MainUserId] [int]  NOT NULL  DEFAULT ('0'), 
		[VersionId] [int]  NULL  DEFAULT ('1'), 
		[AppCount] [int]  NULL  DEFAULT ('0'), 
		[MenuCount] [int]  NULL  DEFAULT ('0'), 
		[DbTableCount] [int]  NULL  DEFAULT ('0'), 
		[TreeCount] [int]  NULL  DEFAULT ('0'), 
		[MonthCount] [int]  NULL  DEFAULT ('0'), 
		[TotalMoney] [money]  NOT NULL  DEFAULT ('0'), 
		[PayedMoney] [money]  NOT NULL  DEFAULT ('0'), 
		[Balance] [money]  NULL , 
		[BankAccount] [varchar] (100) NULL , 
		[Trade] [varchar] (50) NULL , 
		[CompanyUrl] [varchar] (100) NULL , 
		[Telephone] [varchar] (50) NULL , 
		[QQ] [varchar] (50) NULL , 
		[Province] [varchar] (100) NULL , 
		[Address] [varchar] (100) NULL , 
		[Linkman] [varchar] (50) NULL , 
		[Phone] [varchar] (50) NULL , 
		[IconPath] [varchar] (100) NULL , 
		[RegistedDate] [datetime]  NULL , 
		[PassDate] [datetime]  NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NOT NULL , 
		[CreateTime] [datetime]  NOT NULL  DEFAULT (getdate()), 
		[EditorId] [int]  NULL  DEFAULT ('0'), 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[Remark] [varchar] (200) NULL    , 
    CONSTRAINT [PK_FZET_Account] PRIMARY KEY CLUSTERED 
    ( 
       AccountId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Action]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Action]( 
		[Act_Id] [int]  NOT NULL , 
		[Act_Name] [varchar] (50) NULL , 
		[Act_Desc] [ntext]  NULL , 
		[不是我] [varchar] (50) NULL , 
		[我的] [int]  NULL  DEFAULT ('2'), 
		[的人] [int]  NOT NULL  DEFAULT ('0'), 
		[我的确良] [varchar] (50) NULL  DEFAULT ('我的确良'), 
		[一在职] [int]  NULL  DEFAULT ('3'), 
		[一在职1] [decimal] (18,2) NULL  DEFAULT ('3')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Activity]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Activity]( 
		[Act_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Proc_Id] [int]  NOT NULL    , 
    CONSTRAINT [PK_Dcx_Activity] PRIMARY KEY CLUSTERED 
    ( 
       Act_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_AjaxForm_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_AjaxForm_Run]( 
		[FormId] [uniqueidentifier]  NULL   DEFAULT (newid()), 
		[FormName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DropDownHtml] [varchar] (max) NULL , 
		[NoInit] [bit]  NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[DIYJsCss2] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[PageSize] [int]  NULL  DEFAULT ('0'), 
		[InsertTrigger] [varchar] (max) NULL , 
		[UpdateTrigger] [varchar] (max) NULL , 
		[DeleteTrigger] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[AtServer] [bit]  NULL  DEFAULT ('1'), 
		[IsIPLimit] [bit]  NULL  DEFAULT ('0'), 
		[IsSchedule] [bit]  NULL  DEFAULT ('0'), 
		[IsSupportMsg] [bit]  NULL  DEFAULT ('0'), 
		[BeginTime] [datetime]  NULL , 
		[EndTime] [datetime]  NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_AjaxForm_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_AjaxFormField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_AjaxFormField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Form_EntId] [int]  NOT NULL  DEFAULT ('-1'), 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[RunDataTypeId] [int]  NOT NULL  DEFAULT ('2'), 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[DefaultValue] [varchar] (max) NULL , 
		[ValueType] [smallint]  NULL , 
		[RunValueType] [smallint]  NULL  DEFAULT ('1'), 
		[IsSingleChoice] [bit]  NULL  DEFAULT ('1'), 
		[CtrlStyleId] [tinyint]  NULL  DEFAULT ('0'), 
		[CtrlTypeId] [int]  NULL , 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[RepeatColumns] [int]  NULL  DEFAULT ('-1'), 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[TreeId] [int]  NULL  DEFAULT ('-1'), 
		[Reflash] [bit]  NULL  DEFAULT ('0'), 
		[ValueLock] [bit]  NULL  DEFAULT ('0'), 
		[UploadPath] [varchar] (200) NULL , 
		[UploadFileType] [varchar] (200) NULL , 
		[ParentFields] [varchar] (200) NULL , 
		[SystemVariables] [varchar] (200) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[Div_DropDownHtml] [varchar] (max) NULL , 
		[CtrlBeforeHtml] [varchar] (max) NULL , 
		[CtrlfrontHtml] [varchar] (max) NULL , 
		[CtrlbackHtml] [varchar] (max) NULL , 
		[CtrlLastHtml] [varchar] (max) NULL , 
		[TableIndex] [int]  NULL  DEFAULT ('-1'), 
		[RowIndex] [int]  NULL  DEFAULT ('-1'), 
		[Parent_TableIndex] [int]  NULL  DEFAULT ('-1'), 
		[Parent_RowIndex] [int]  NULL  DEFAULT ('-1'), 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_AjaxFormField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Analysis]( 
		[AnalysisId] [int] IdENTITY(1,1)  NOT NULL , 
		[AnalysisNo] [varchar] (100) NULL , 
		[AnalysisName] [varchar] (100) NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (100) NULL , 
		[OrderNo] [int]  NULL , 
		[TypeId] [int]  NULL , 
		[TypeName] [varchar] (100) NULL , 
		[FoldId] [int]  NULL , 
		[FoldName] [varchar] (100) NULL , 
		[RowFieldName1] [varchar] (100) NULL , 
		[RowSort1] [varchar] (100) NULL , 
		[RowDateGroupBy1] [varchar] (100) NULL , 
		[RowFieldName2] [varchar] (100) NULL , 
		[RowSort2] [varchar] (100) NULL , 
		[RowDateGroupBy2] [varchar] (100) NULL , 
		[ColumnFieldName1] [varchar] (100) NULL , 
		[ColumnSort1] [varchar] (100) NULL , 
		[ColumnDateGroupBy1] [varchar] (100) NULL , 
		[ColumnFieldName2] [varchar] (100) NULL , 
		[ColumnSort2] [varchar] (100) NULL , 
		[ColumnDateGroupBy2] [varchar] (100) NULL , 
		[RowDbTableName1] [varchar] (100) NULL , 
		[RowDbTableName2] [varchar] (100) NULL , 
		[ColumnDbTableName1] [varchar] (100) NULL , 
		[ColumnDbTableName2] [varchar] (100) NULL , 
		[Creator] [varchar] (100) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('100'), 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL  DEFAULT ('100'), 
		[EditorTime] [datetime]  NULL , 
		[BelongUser] [varchar] (100) NULL , 
		[BelongUserId] [int]  NULL  DEFAULT ('100'), 
		[BelongDeptId] [int]  NULL , 
		[BelongDeptName] [varchar] (100) NULL , 
		[OrderFieldName] [varchar] (100) NULL , 
		[OrderType] [varchar] (100) NULL , 
		[ShowRowCount] [int]  NULL  DEFAULT ('100'), 
		[OtherRowFieldName] [varchar] (200) NULL , 
		[IsYStatis] [bit]  NULL  DEFAULT ('1'), 
		[IsXStatis] [bit]  NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Analysis] PRIMARY KEY NONCLUSTERED 
    ( 
       AnalysisId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Chart]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Analysis_Chart]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[AnalysisId] [int]  NOT NULL , 
		[AnalysisNo] [varchar] (100) NULL , 
		[AnalysisName] [varchar] (100) NULL , 
		[ChartType] [varchar] (100) NULL , 
		[YFieldName] [varchar] (100) NULL , 
		[XFieldName] [varchar] (100) NULL , 
		[ChartSize] [varchar] (100) NULL , 
		[ChartPoint] [varchar] (100) NULL , 
		[ChartTitle] [varchar] (200) NULL , 
		[ChartColor] [varchar] (100) NULL , 
		[TitleSize] [varchar] (100) NULL , 
		[BgShadowColor] [varchar] (100) NULL , 
		[BgShadowStartColor] [varchar] (100) NULL , 
		[BgShadowEndColor] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_Analysis_Chart] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Condition]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Analysis_Condition]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[AnalysisId] [int]  NOT NULL , 
		[AnalysisNo] [varchar] (100) NULL , 
		[AnalysisName] [varchar] (100) NULL , 
		[FieldName] [varchar] (100) NULL , 
		[ConditionRelation] [varchar] (100) NULL , 
		[CompareType] [varchar] (100) NULL , 
		[DataType] [varchar] (100) NULL , 
		[CompareValue] [varchar] (500) NULL , 
		[SQLExpression] [varchar] (1000) NULL    , 
    CONSTRAINT [PK_FZET_Analysis_Condition] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Field]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Analysis_Field]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[AnalysisId] [int]  NOT NULL , 
		[AnalysisNo] [varchar] (100) NULL , 
		[AnalysisName] [varchar] (100) NULL , 
		[FieldName] [varchar] (100) NULL , 
		[StatisType] [varchar] (100) NULL , 
		[IsOrderField] [bit]  NULL  DEFAULT ('0'), 
		[OrderType] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_Analysis_Field] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Folder]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Analysis_Folder]( 
		[FoldId] [int] IdENTITY(1,1)  NOT NULL , 
		[FoldName] [varchar] (100) NULL , 
		[ParentId] [int]  NULL , 
		[ParentName] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_Analysis_Folder] PRIMARY KEY CLUSTERED 
    ( 
       FoldId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Type]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Analysis_Type]( 
		[TypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[TypeName] [varchar] (100) NULL , 
		[FoldId] [int]  NULL , 
		[OrderNo] [int]  NULL , 
		[ParentId] [int]  NULL , 
		[ParentName] [varchar] (100) NULL , 
		[DbTableName1] [varchar] (100) NULL , 
		[DbTableName2] [varchar] (100) NULL , 
		[FieldName1] [varchar] (100) NULL , 
		[FieldName2] [varchar] (100) NULL , 
		[Creator] [varchar] (100) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('100'), 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL  DEFAULT ('100'), 
		[EditorTime] [datetime]  NULL , 
		[BelongUser] [varchar] (100) NULL , 
		[BelongUserId] [int]  NULL  DEFAULT ('100'), 
		[BelongDeptId] [int]  NULL , 
		[BelongDeptName] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_analysis_type] PRIMARY KEY CLUSTERED 
    ( 
       TypeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Assgn_Rule]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Assgn_Rule]( 
		[Rule_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Act_Id] [int]  NULL , 
		[Based_On] [int]  NULL , 
		[Position_Id] [int]  NULL  DEFAULT ('0'), 
		[Team_Id] [int]  NULL  DEFAULT ('0'), 
		[RoleId] [int]  NULL  DEFAULT ('0'), 
		[USERId] [int]  NULL  DEFAULT ('0')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Bank]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Bank]( 
		[BankId] [int] IdENTITY(1,1)  NOT NULL , 
		[BankName] [varchar] (100) NOT NULL , 
		[IsPayment] [bit]  NOT NULL  DEFAULT ('0'), 
		[Remark] [varchar] (100) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BannedIP]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_BannedIP]( 
		[Id] [smallint]  NOT NULL , 
		[Ip1] [smallint]  NOT NULL , 
		[Ip2] [smallint]  NOT NULL , 
		[Ip3] [smallint]  NOT NULL , 
		[Ip4] [smallint]  NOT NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1'), 
		[UserId] [int]  NOT NULL , 
		[UserName] [nvarchar] (100) NOT NULL , 
		[Dateline] [datetime]  NOT NULL , 
		[Expiration] [datetime]  NOT NULL , 
		[Location] [varchar] (300) NOT NULL    , 
    CONSTRAINT [PK_FZET_Banned] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BlockList_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_BlockList_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_BlockList_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BlockListField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_BlockListField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_BlockListField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BrowseReport_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_BrowseReport_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_BrowseReport_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BrowseReportField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_BrowseReportField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_BrowseReportField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_CacheState]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_CacheState]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[CacheKey] [varchar] (200) NULL , 
		[overdueCache] [bit]  NULL  DEFAULT ('0'), 
		[TableNames] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_CacheState] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Class]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Class]( 
		[ClassId] [int] IdENTITY(1,1)  NOT NULL , 
		[ClassName] [varchar] (500) NULL , 
		[ClassRemark] [text]  NULL , 
		[ClassType] [int]  NULL , 
		[ClassParentId] [int]  NULL , 
		[ClassAddedBy] [varchar] (50) NULL , 
		[ClassAddedDate] [datetime]  NULL , 
		[Status] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_FZET_Class] PRIMARY KEY CLUSTERED 
    ( 
       ClassId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Common]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Common]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Value] [varchar] (30) NULL  DEFAULT ('sss'), 
		[Name] [varchar] (50) NULL , 
		[ParentId] [int]  NULL  DEFAULT ('2'), 
		[ParentId1] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_FZET_Common] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Company]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Company]( 
		[CompanyId] [int] IdENTITY(1,1)  NOT NULL , 
		[CompanyCode] [varchar] (50) NULL , 
		[CompanyName] [varchar] (100) NULL , 
		[Telephone] [varchar] (100) NULL , 
		[Address] [varchar] (100) NULL , 
		[PostalCode] [varchar] (50) NULL , 
		[Email] [varchar] (50) NULL , 
		[URL] [varchar] (50) NULL , 
		[Accounts] [varchar] (50) NULL , 
		[Principal] [varchar] (50) NULL , 
		[ComOrder] [int]  NULL  DEFAULT ('0'), 
		[Remark] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_Company_CompanyId] PRIMARY KEY CLUSTERED 
    ( 
       CompanyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_CreateDBTableLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_CreateDBTableLog]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[TableName] [varchar] (100) NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[IP] [varchar] (50) NULL , 
		[SQL] [varchar] (max) NULL , 
		[SystemNO] [varchar] (50) NULL , 
		[SystemName] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_CreateDBTableLog] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_CrossReport_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_CrossReport_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_CrossReport_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_CrossReportField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_CrossReportField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[ColumnByname] [varchar] (100) NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL , 
		[HengXiangGroup] [bit]  NULL  DEFAULT ('0'), 
		[ZongXiangGroup] [bit]  NULL  DEFAULT ('1'), 
		[OrderDirection] [varchar] (20) NULL    , 
    CONSTRAINT [PK_FZET_CrossReportField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Currency]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Currency]( 
		[CurrencyId] [int] IdENTITY(1,1)  NOT NULL , 
		[CurrencyName] [varchar] (50) NULL , 
		[Country] [varchar] (50) NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL  DEFAULT (getdate()), 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[Remark] [varchar] (200) NULL    , 
    CONSTRAINT [PK_FZET_Currency] PRIMARY KEY CLUSTERED 
    ( 
       CurrencyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBConnect]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DBConnect]( 
		[DBConnectId] [int] IdENTITY(1,1)  NOT NULL , 
		[DBConnectName] [varchar] (200) NULL , 
		[DBConnectStr] [varchar] (500) NULL , 
		[DBType] [varchar] (200) NULL , 
		[DBDrive] [varchar] (200) NULL , 
		[DBPassword] [varchar] (200) NULL , 
		[DBUserName] [varchar] (200) NULL , 
		[DBConnectOutTime] [int]  NULL , 
		[CreatorAccountId] [int]  NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NOT NULL , 
		[CreateTime] [datetime]  NULL  DEFAULT (getdate()), 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[Remark] [varchar] (200) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_DBConnectString] PRIMARY KEY NONCLUSTERED 
    ( 
       DBConnectId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTable_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DBTable_Run]( 
		[DBTableId] [int]  NOT NULL , 
		[DBConnectId] [int]  NULL , 
		[DBTableName] [varchar] (100) NOT NULL , 
		[DBTableByName] [varchar] (100) NULL , 
		[IsForbid] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsPublic] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsView] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsDesigning] [bit]  NULL  DEFAULT ('0'), 
		[BuildTable] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsSuportWorkFlow] [bit]  NOT NULL  DEFAULT ('0'), 
		[SystemId] [int]  NOT NULL , 
		[CreatorAccountId] [int]  NULL  DEFAULT ('1'), 
		[CreatorId] [int]  NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL  DEFAULT (getdate()), 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[SQL_CreateTable] [varchar] (max) NULL , 
		[Remark] [varchar] (max) NULL , 
		[SSystemId] [int]  NULL , 
		[SDbTableId] [int]  NULL , 
		[IsChange] [bit]  NULL , 
		[IsSystem] [bit]  NULL    , 
    CONSTRAINT [PK_FZET_DBTable_Run] PRIMARY KEY CLUSTERED 
    ( 
       DBTableId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableExample]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DBTableExample]( 
		[ExpId] [int] IdENTITY(1,1)  NOT NULL , 
		[DBTableId] [int]  NULL , 
		[DBTableName] [varchar] (200) NOT NULL , 
		[DBTableByName] [varchar] (200) NOT NULL , 
		[IsSuportWorkFlow] [bit]  NOT NULL  DEFAULT ('0'), 
		[TTypeId] [int]  NOT NULL , 
		[TypeName] [varchar] (200) NULL , 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[UsedTime] [int]  NOT NULL  DEFAULT ('0'), 
		[CreateTime] [datetime]  NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[LastUsedDate] [datetime]  NULL    , 
    CONSTRAINT [PK_Dcx_DBTableExample] PRIMARY KEY NONCLUSTERED 
    ( 
       ExpId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DBTableField_Run]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FieldId] [int]  NOT NULL , 
		[SystemId] [int]  NOT NULL , 
		[DBTableId] [int]  NOT NULL , 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NULL  DEFAULT ('1'), 
		[CtrlTypeId] [int]  NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NULL  DEFAULT ('1'), 
		[DBTableName] [varchar] (100) NULL , 
		[FieldName] [varchar] (100) NULL , 
		[FieldByname] [varchar] (100) NULL , 
		[DefaultValue] [varchar] (100) NULL , 
		[IsIdentity] [bit]  NULL  DEFAULT ('0'), 
		[IsKey] [bit]  NULL  DEFAULT ('0'), 
		[IsNullAble] [bit]  NULL  DEFAULT ('0'), 
		[Length] [int]  NULL  DEFAULT ('0'), 
		[Precision] [int]  NULL  DEFAULT ('0'), 
		[Scale] [int]  NULL  DEFAULT ('0'), 
		[ShowAtForm] [bit]  NULL  DEFAULT ('0'), 
		[ShowAtListReport] [bit]  NULL  DEFAULT ('0'), 
		[ShowAtSeach] [bit]  NULL  DEFAULT ('0'), 
		[CreatorAccountId] [int]  NULL , 
		[CreatorId] [int]  NULL    , 
    CONSTRAINT [PK_FZET_DBTableField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DBTableLog]( 
		[Id] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (25) NOT NULL , 
		[ExpId] [int]  NOT NULL , 
		[DBTableId] [int]  NOT NULL , 
		[DBTableName] [varchar] (150) NOT NULL , 
		[OperateTime] [datetime]  NULL , 
		[OperateTypeId] [tinyint]  NULL    , 
    CONSTRAINT [PK_Dcx_DBTableLog] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DBTableType]( 
		[TTypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[TTypeName] [varchar] (200) NOT NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0'), 
		[SortOrder] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_DBTableType] PRIMARY KEY NONCLUSTERED 
    ( 
       TTypeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultBrowse_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DefaultBrowse_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_DefaultBrowseReport_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultBrowseField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DefaultBrowseField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_DefaultBrowseReportField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultForm_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DefaultForm_Run]( 
		[FormId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[FormName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DropDownHtml] [varchar] (max) NULL , 
		[NoInit] [bit]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[DIYJsCss2] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[OtherMsg] [varchar] (max) NULL , 
		[InsertTrigger] [varchar] (max) NULL , 
		[UpdateTrigger] [varchar] (max) NULL , 
		[DeleteTrigger] [varchar] (max) NULL , 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[IsIPLimit] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsSchedule] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsSupportMsg] [bit]  NULL  DEFAULT ('0'), 
		[BeginTime] [datetime]  NULL , 
		[EndTime] [datetime]  NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_DefaultForm_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultFormField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DefaultFormField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Form_EntId] [int]  NOT NULL  DEFAULT ('-1'), 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[FieldNO] [int]  NULL  DEFAULT ('1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[RunDataTypeId] [int]  NOT NULL  DEFAULT ('2'), 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[DefaultValue] [varchar] (max) NULL , 
		[ValueType] [smallint]  NULL , 
		[RunValueType] [smallint]  NULL  DEFAULT ('1'), 
		[IsSingleChoice] [bit]  NULL  DEFAULT ('1'), 
		[CtrlStyleId] [tinyint]  NULL  DEFAULT ('0'), 
		[CtrlTypeId] [int]  NULL , 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[RepeatColumns] [int]  NULL  DEFAULT ('-1'), 
		[TreeId] [int]  NULL  DEFAULT ('-1'), 
		[Reflash] [bit]  NULL  DEFAULT ('0'), 
		[ValueLock] [bit]  NULL  DEFAULT ('0'), 
		[UploadPath] [varchar] (200) NULL , 
		[UploadFileType] [varchar] (200) NULL , 
		[ParentFields] [varchar] (200) NULL , 
		[SystemVariables] [varchar] (200) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[Div_DropDownHtml] [varchar] (max) NULL , 
		[CtrlBeforeHtml] [varchar] (max) NULL , 
		[CtrlfrontHtml] [varchar] (max) NULL , 
		[CtrlbackHtml] [varchar] (max) NULL , 
		[CtrlLastHtml] [varchar] (max) NULL , 
		[TableIndex] [int]  NULL , 
		[RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_DefaultFormField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Dept]( 
		[DeptId] [int] IdENTITY(1,1)  NOT NULL , 
		[DeptCode] [varchar] (50) NULL , 
		[DeptName] [varchar] (50) NOT NULL , 
		[CompanyId] [int]  NULL  DEFAULT ('0'), 
		[DeptOrder] [int]  NULL  DEFAULT ('0'), 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[Telephone] [varchar] (50) NULL , 
		[PostalCode] [varchar] (50) NULL , 
		[Address] [varchar] (50) NULL , 
		[Email] [varchar] (50) NULL , 
		[URL] [varchar] (50) NULL , 
		[Accounts] [varchar] (50) NULL , 
		[Principal] [varchar] (50) NULL , 
		[Remark] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_Dept_DeptId] PRIMARY KEY CLUSTERED 
    ( 
       DeptId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DeptPrivilege]( 
		[DeptPrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NULL , 
		[DeptId] [int]  NULL , 
		[Remark] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_DeptPrivilege] PRIMARY KEY NONCLUSTERED 
    ( 
       DeptPrivilegeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DevelopDiary]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DevelopDiary]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Title] [varchar] (100) NULL , 
		[Tags] [varchar] (100) NULL , 
		[DiaryContent] [varchar] (max) NULL , 
		[CreateTime] [datetime]  NOT NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Diary]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Diary]( 
		[DyId] [int] IdENTITY(1,1)  NOT NULL , 
		[DyContent] [varchar] (max) NOT NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (50) NOT NULL , 
		[CreateDate] [datetime]  NOT NULL , 
		[IsPublic] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsRead] [bit]  NULL  DEFAULT ('0'), 
		[ReadTime] [datetime]  NULL , 
		[ColorId] [tinyint]  NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[TagName] [varchar] (50) NULL , 
		[EditorId] [int]  NULL , 
		[EditDate] [datetime]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Diary] PRIMARY KEY NONCLUSTERED 
    ( 
       DyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryPrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DiaryPrivilege]( 
		[PrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[DyId] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [bit]  NOT NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_DiaryPrivilege] PRIMARY KEY NONCLUSTERED 
    ( 
       PrivilegeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryReply]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DiaryReply]( 
		[ReplyId] [int] IdENTITY(1,1)  NOT NULL , 
		[DyId] [int]  NOT NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[ReplyContent] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreateTime] [datetime]  NOT NULL , 
		[CreatorName] [varchar] (50) NULL    , 
    CONSTRAINT [PK_Dcx_DiaryReply] PRIMARY KEY NONCLUSTERED 
    ( 
       ReplyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryTag]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DiaryTag]( 
		[TagId] [int] IdENTITY(1,1)  NOT NULL , 
		[TagName] [varchar] (50) NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreateDate] [datetime]  NOT NULL    , 
    CONSTRAINT [PK_Dcx_DiaryTag] PRIMARY KEY NONCLUSTERED 
    ( 
       TagId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DocDownLoad]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_DocDownLoad]( 
		[DownId] [int] IdENTITY(1,1)  NOT NULL , 
		[FileId] [int]  NOT NULL , 
		[FilePath] [varchar] (500) NULL , 
		[CreatorId] [int]  NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL    , 
    CONSTRAINT [PK_Dcx_DocDownLoad] PRIMARY KEY NONCLUSTERED 
    ( 
       DownId DESC 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Document]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Document]( 
		[FileId] [int] IdENTITY(1,1)  NOT NULL , 
		[FilePath] [varchar] (500) NULL , 
		[FileName] [varchar] (300) NULL , 
		[FileTypeId] [smallint]  NULL , 
		[FileSize] [int]  NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[IsCollect] [bit]  NULL , 
		[IsDelete] [bit]  NOT NULL  DEFAULT ('0'), 
		[DeleteDate] [datetime]  NULL , 
		[CreatorId] [int]  NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[GroupId] [smallint]  NOT NULL  DEFAULT ('1'), 
		[FileSource] [int]  NOT NULL  DEFAULT ('1'), 
		[LinkDataJson] [varchar] (300) NULL , 
		[DownLoadTimes] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Document] PRIMARY KEY NONCLUSTERED 
    ( 
       FileId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Employee]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Employee]( 
		[EmployeeId] [int] IdENTITY(1,1)  NOT NULL , 
		[EmployeeCode] [varchar] (50) NOT NULL , 
		[Name] [varchar] (50) NOT NULL , 
		[Sex] [varchar] (50) NULL , 
		[Birthday] [datetime]  NULL , 
		[Age] [int]  NULL  DEFAULT ('0'), 
		[Nation] [varchar] (50) NULL , 
		[NativePlace] [varchar] (50) NULL , 
		[Marriage] [varchar] (50) NULL , 
		[Membership] [varchar] (50) NULL , 
		[WageLevel] [decimal] (18,1) NULL , 
		[UserName] [varchar] (50) NULL , 
		[UserId] [int]  NULL  DEFAULT ('-1'), 
		[DeptId] [int]  NULL , 
		[PositionId] [int]  NULL , 
		[PositionName] [varchar] (50) NULL , 
		[State] [varchar] (50) NULL , 
		[Email] [varchar] (50) NULL , 
		[Telephone] [varchar] (50) NULL , 
		[EntryDate] [datetime]  NULL , 
		[ServiceYear] [int]  NULL , 
		[PermanentDate] [datetime]  NULL , 
		[LeaveOfficeDate] [datetime]  NULL , 
		[BaseWage] [money]  NULL  DEFAULT ('0'), 
		[MeritWage] [money]  NULL  DEFAULT ('0'), 
		[ProbationWage] [money]  NULL  DEFAULT ('0'), 
		[ProbationMeritWage] [money]  NULL  DEFAULT ('0'), 
		[ComputerAllowance] [bit]  NULL , 
		[ComputerAllowanceAmount] [money]  NULL  DEFAULT ('0'), 
		[CameraAllowance] [bit]  NULL  DEFAULT ('0'), 
		[CameraAllowanceAmount] [money]  NULL  DEFAULT ('0'), 
		[SocialInsurance] [bit]  NULL  DEFAULT ('0'), 
		[SocialInsuranceAmount] [money]  NULL  DEFAULT ('0'), 
		[PersonalCapitalReserve] [bit]  NULL  DEFAULT ('0'), 
		[PersonalCapitalReserveAmount] [money]  NULL  DEFAULT ('0'), 
		[CompanyReserve] [bit]  NULL  DEFAULT ('0'), 
		[CompanyReserveAmount] [money]  NULL  DEFAULT ('0'), 
		[SocialInsuranceAmountByCompany] [money]  NULL  DEFAULT ('0'), 
		[AresAllowance] [money]  NULL  DEFAULT ('0'), 
		[PlaceOfSocialInsurance] [varchar] (50) NULL , 
		[BankAccount] [varchar] (50) NULL , 
		[Contract] [varchar] (50) NULL , 
		[ContractDate] [datetime]  NULL , 
		[MaturityDate] [datetime]  NULL , 
		[ContractPeriod] [int]  NULL  DEFAULT ('0'), 
		[Education] [varchar] (50) NULL , 
		[College] [varchar] (200) NULL , 
		[GraduationDate] [datetime]  NULL , 
		[Speciality] [varchar] (50) NULL , 
		[SpecialSkill] [varchar] (50) NULL , 
		[QualificationCertificate] [varchar] (50) NULL , 
		[PositionalTitles] [varchar] (50) NULL , 
		[InsurancePeriod] [int]  NULL  DEFAULT ('0'), 
		[InsuranceDeadline] [datetime]  NULL , 
		[Address] [varchar] (350) NULL , 
		[Remark] [varchar] (350) NULL , 
		[QQ] [varchar] (50) NULL , 
		[Qualifications] [varchar] (50) NULL , 
		[ExperienceGrade] [int]  NULL  DEFAULT ('0'), 
		[MarketingGrade] [int]  NULL  DEFAULT ('0'), 
		[CraftsmanshipGrade] [int]  NULL  DEFAULT ('0'), 
		[manageGrade] [int]  NULL  DEFAULT ('0'), 
		[PerformanceGrade] [int]  NULL  DEFAULT ('0'), 
		[CheckUpMonthCount] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1'), 
		[Photo] [varchar] (350) NULL    , 
    CONSTRAINT [PK_FZET_Employee] PRIMARY KEY CLUSTERED 
    ( 
       EmployeeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Entity_Attachment]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Entity_Attachment]( 
		[AttachmentId] [int] IdENTITY(1,1)  NOT NULL , 
		[FilePath] [varchar] (300) NULL , 
		[FileName] [varchar] (100) NULL , 
		[FileType] [varchar] (50) NULL , 
		[ContainLenth] [int]  NULL , 
		[EntId] [int]  NULL , 
		[KeyFieldName] [varchar] (50) NULL , 
		[KeyFieldValue] [varchar] (50) NULL , 
		[KeyFieldIsNum] [bit]  NULL  DEFAULT ('0'), 
		[CreatorId] [int]  NULL , 
		[CreateTime] [datetime]  NULL    , 
    CONSTRAINT [PK_Dcx_Entity_Attachment] PRIMARY KEY NONCLUSTERED 
    ( 
       AttachmentId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Entity_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Entity_Run]( 
		[EntId] [int]  NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[EntName] [varchar] (100) NULL , 
		[MEnt] [bit]  NOT NULL , 
		[DBTableId] [int]  NULL , 
		[DBConnectId] [int]  NULL  DEFAULT ('0'), 
		[DBTableName] [varchar] (100) NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[OrderBy] [int]  NULL  DEFAULT ('0'), 
		[CheckPower] [bit]  NOT NULL  DEFAULT ('1'), 
		[SSystemId] [int]  NULL , 
		[SEntId] [int]  NOT NULL , 
		[FSystemId] [int]  NULL , 
		[FEntId] [int]  NULL , 
		[SystemId] [int]  NULL , 
		[Remark] [varchar] (500) NULL , 
		[IsFlow] [bit]  NULL , 
		[IsChecked] [bit]  NULL , 
		[FlowId] [int]  NULL  DEFAULT ('0'), 
		[MaxCount] [int]  NULL  DEFAULT ('-1'), 
		[IsDesigning] [bit]  NULL  DEFAULT ('0'), 
		[ShowTag] [bit]  NULL  DEFAULT ('1'), 
		[AddDcxTime] [datetime]  NULL , 
		[AddDcxUserName] [varchar] (40) NULL , 
		[AddDcxUserId] [int]  NULL  DEFAULT ('0'), 
		[SqlDelete] [varchar] (max) NULL , 
		[SqlInsert] [varchar] (max) NULL , 
		[SqlUpdate] [varchar] (max) NULL , 
		[SqlSelect] [varchar] (max) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_Entity_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityLeftTree]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntityLeftTree]( 
		[Id] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[EntName] [varchar] (100) NULL , 
		[MenuId] [int]  NULL , 
		[MenuUId] [uniqueidentifier]  NULL , 
		[MenuName] [varchar] (50) NULL , 
		[SelectSQL1] [varchar] (max) NULL , 
		[SelectSQL2] [varchar] (max) NULL , 
		[AllFromTheSame] [bit]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntityPrivilege]( 
		[EntityPrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[MenuId] [int]  NOT NULL  DEFAULT ('-1'), 
		[EntId] [int]  NOT NULL , 
		[RoleId] [int]  NOT NULL , 
		[CanViewList] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanBrowse] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanInsert] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanDelete] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanUpdate] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanOutPut] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanInput] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanCopy] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanPrint] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanCheck] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanClean] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanRecycle] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanExecute] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanDesign] [bit]  NOT NULL  DEFAULT ('0'), 
		[Remark] [varchar] (50) NULL , 
		[RoleName] [varchar] (50) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityView]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntityView]( 
		[ViewHtmlId] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[CtrlPrex] [varchar] (200) NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DesignHtml] [varchar] (max) NULL , 
		[ModuleId] [int]  NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL    , 
    CONSTRAINT [PK_FZET_EntityViewHtml] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityViewCondition]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntityViewCondition]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ViewOptionId] [int]  NULL , 
		[FieldName] [varchar] (100) NULL , 
		[ConditionRelation] [varchar] (100) NULL , 
		[CompareType] [varchar] (100) NULL , 
		[DataType] [varchar] (100) NULL , 
		[CompareValue] [varchar] (500) NULL , 
		[SQLExpression] [varchar] (1000) NULL    , 
    CONSTRAINT [PK_EntityViewCondition] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityViewGroup]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntityViewGroup]( 
		[ViewGroupId] [int] IdENTITY(1,1)  NOT NULL , 
		[ViewGroupName] [varchar] (100) NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ColumnCount] [int]  NULL  DEFAULT ('2'), 
		[ParentId] [int]  NULL  DEFAULT ('0'), 
		[OrderNO] [int]  NULL  DEFAULT ('0'), 
		[IsShare] [bit]  NULL  DEFAULT ('1'), 
		[IsSystem] [bit]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[LastMender] [varchar] (50) NULL , 
		[LastMenderTime] [datetime]  NULL    , 
    CONSTRAINT [PK_FZET_EntityViewType] PRIMARY KEY CLUSTERED 
    ( 
       ViewGroupId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityViewOption]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntityViewOption]( 
		[ViewOptionId] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('-1'), 
		[OptionName] [varchar] (100) NULL , 
		[ViewGroupId] [int]  NULL  DEFAULT ('0'), 
		[OrderNO] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL    , 
    CONSTRAINT [PK_FZET_EntityView] PRIMARY KEY CLUSTERED 
    ( 
       ViewOptionId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FailedLogins]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_FailedLogins]( 
		[ip] [char] (15) NOT NULL , 
		[errcount] [smallint]  NOT NULL  DEFAULT ('0'), 
		[lastupdate] [smalldatetime]  NOT NULL  DEFAULT (getdate())   , 
    CONSTRAINT [PK_FZET_FailedLogins] PRIMARY KEY CLUSTERED 
    ( 
       ip 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Files]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Files]( 
		[FileId] [int] IdENTITY(1,1)  NOT NULL , 
		[DocId] [int]  NULL , 
		[FileName] [varchar] (255) NULL , 
		[FileSize] [int]  NULL , 
		[FileAttribute] [int]  NULL , 
		[FileVisualPath] [varchar] (255) NULL , 
		[FileAuthor] [varchar] (255) NULL , 
		[FileCatlog] [varchar] (255) NULL , 
		[FileAddedDate] [datetime]  NULL    , 
    CONSTRAINT [PK_FZET_Files] PRIMARY KEY CLUSTERED 
    ( 
       FileId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FilterView_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_FilterView_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_FilterView_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FilterViewCondition_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_FilterViewCondition_Run]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ViewOptionId] [int]  NULL , 
		[ConditionRelation] [varchar] (100) NULL , 
		[SQLExpression] [varchar] (1000) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_FilterViewCondition_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Folder]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Folder]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[fatherId] [int]  NOT NULL , 
		[folderName] [nvarchar] (100) NOT NULL , 
		[createTime] [datetime]  NOT NULL , 
		[userId] [int]  NOT NULL    , 
    CONSTRAINT [PK_hyoa_folder] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FolderCtrl]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_FolderCtrl]( 
		[folderId] [int]  NOT NULL , 
		[userId] [int]  NOT NULL , 
		[createFlag] [bit]  NOT NULL , 
		[deleteFlag] [bit]  NOT NULL , 
		[modifyFlag] [bit]  NOT NULL , 
		[adminFlag] [bit]  NOT NULL    , 
    CONSTRAINT [PK_folderControl] PRIMARY KEY CLUSTERED 
    ( 
       folderId, userId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FolderView]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_FolderView]( 
		[folderId] [int]  NOT NULL , 
		[userId] [int]  NOT NULL    , 
    CONSTRAINT [PK_hyoa_folderView] PRIMARY KEY CLUSTERED 
    ( 
       folderId, userId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FormDataSource_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_FormDataSource_Run]( 
		[DsId] [int] IdENTITY(1,1)  NOT NULL , 
		[DsName] [varchar] (100) NULL , 
		[EntId] [int]  NOT NULL , 
		[SystemId] [int]  NULL  DEFAULT ('0'), 
		[SelectSQL] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (100) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[ModuleTypeId] [tinyint]  NULL , 
		[Remark] [varchar] (200) NULL    , 
    CONSTRAINT [PK_FZET_FormDataSource_Run] PRIMARY KEY CLUSTERED 
    ( 
       DsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupInterface_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_GroupInterface_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_GroupInterface_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupInterfaceField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_GroupInterfaceField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL , 
		[GroupHeadIdS] [varchar] (500) NULL , 
		[GroupTailIdS] [varchar] (500) NULL , 
		[GroupFieldS] [varchar] (500) NULL , 
		[LoopTimes] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_FZET_GroupInterfaceField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupReport_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_GroupReport_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_GroupReport_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupReportField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_GroupReportField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL , 
		[GroupHeadIdS] [varchar] (500) NULL , 
		[GroupTailIdS] [varchar] (500) NULL , 
		[GroupFieldS] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_GroupReportField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_HomePage]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_HomePage]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (150) NULL , 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[Width] [int]  NOT NULL  DEFAULT ('0'), 
		[Height] [int]  NOT NULL  DEFAULT ('0'), 
		[UserId] [int]  NOT NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_HomePage_1] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_HomePagePlug]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_HomePagePlug]( 
		[PlugId] [int] IdENTITY(1,1)  NOT NULL , 
		[PlugName] [varchar] (150) NOT NULL , 
		[PlugUrl] [varchar] (150) NOT NULL , 
		[Width] [int]  NOT NULL  DEFAULT ('0'), 
		[Height] [int]  NOT NULL  DEFAULT ('0'), 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[Remark] [varchar] (150) NOT NULL    , 
    CONSTRAINT [PK_Dcx_HomePagePlug] PRIMARY KEY CLUSTERED 
    ( 
       PlugId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMail]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMail]( 
		[MailId] [int] IdENTITY(1,1)  NOT NULL , 
		[SenderUserId] [int]  NOT NULL , 
		[SenderUserName] [varchar] (50) NOT NULL , 
		[Title] [varchar] (500) NOT NULL , 
		[Body] [varchar] (max) NULL , 
		[SenderDate] [datetime]  NOT NULL , 
		[SendSms] [bit]  NULL , 
		[SendEMail] [bit]  NULL , 
		[SenderMsgFlag] [varchar] (20) NULL , 
		[ReceiverUserIds] [varchar] (1000) NULL , 
		[ReceiverUserNames] [varchar] (1000) NULL , 
		[ReadUserIds] [varchar] (1000) NULL , 
		[ReadUserNames] [varchar] (1000) NULL , 
		[DelUserIds] [varchar] (500) NULL , 
		[DeleteUseIds] [varchar] (500) NULL , 
		[IsDeleted] [bit]  NULL , 
		[MeetReceipt] [bit]  NULL , 
		[SendDcxSms] [bit]  NULL , 
		[HaveAttachment] [bit]  NULL  DEFAULT ('0'), 
		[Flag] [tinyint]  NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[MenuId] [int]  NOT NULL  DEFAULT ('0'), 
		[KeyFieldValue] [varchar] (50) NULL    , 
    CONSTRAINT [PK_Dcx_IMail] PRIMARY KEY NONCLUSTERED 
    ( 
       MailId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMail_Attachment]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMail_Attachment]( 
		[AttachmentId] [int] IdENTITY(1,1)  NOT NULL , 
		[MailId] [int]  NOT NULL , 
		[FilePath] [varchar] (300) NULL , 
		[FileName] [varchar] (100) NULL , 
		[FileType] [varchar] (50) NULL , 
		[ContainLenth] [int]  NULL    , 
    CONSTRAINT [PK_Dcx_IMail_Attachment] PRIMARY KEY NONCLUSTERED 
    ( 
       AttachmentId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMailReceiver]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMailReceiver]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (60) NULL , 
		[MailId] [int]  NULL , 
		[ReadDate] [datetime]  NULL , 
		[DeleteDate] [datetime]  NULL , 
		[IsRemoved] [bit]  NULL  DEFAULT ('0'), 
		[IsDeleted] [bit]  NULL  DEFAULT ('0'), 
		[IsRead] [bit]  NULL  DEFAULT ('0'), 
		[IsReply] [bit]  NULL  DEFAULT ('0'), 
		[ReplyDate] [datetime]  NULL , 
		[ReplyContent] [varchar] (max) NULL , 
		[SenderDate] [datetime]  NULL , 
		[Title] [varchar] (500) NULL , 
		[SenderUserId] [int]  NULL , 
		[SenderUserName] [varchar] (50) NULL , 
		[HaveAttachment] [bit]  NULL  DEFAULT ('0'), 
		[Flag] [tinyint]  NULL    , 
    CONSTRAINT [PK_Dcx_IMailReceiver] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMAttachment]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMAttachment]( 
		[AttId] [int] IdENTITY(1,1)  NOT NULL , 
		[MsgId] [int]  NOT NULL , 
		[FilePath] [varchar] (300) NOT NULL , 
		[FileName] [varchar] (100) NULL , 
		[FileType] [varchar] (50) NULL , 
		[ContainLenth] [int]  NULL , 
		[CreatorId] [int]  NULL , 
		[CreateTime] [datetime]  NULL , 
		[IsImg] [bit]  NULL , 
		[IsGroup] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_IMAttachment] PRIMARY KEY NONCLUSTERED 
    ( 
       AttId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMessage]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMessage]( 
		[MsgId] [int]  NOT NULL , 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[ReceiverId] [int]  NOT NULL , 
		[ReceiverName] [varchar] (50) NULL , 
		[MsgContent] [varchar] (1000) NOT NULL , 
		[SentDate] [datetime]  NULL , 
		[ReadDate] [datetime]  NULL , 
		[ReadFlag] [bit]  NOT NULL  DEFAULT ('0'), 
		[Sms] [bit]  NOT NULL  DEFAULT ('0'), 
		[SenderDelete] [bit]  NOT NULL  DEFAULT ('0'), 
		[ReceiverDelete] [bit]  NOT NULL  DEFAULT ('0'), 
		[FileJson] [varchar] (500) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ImgSummyList_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ImgSummyList_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_ImgSummyList_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ImgSummyListField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ImgSummyListField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_ImgSummyListField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRelationship]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMRelationship]( 
		[RId] [int] IdENTITY(1,1)  NOT NULL , 
		[HostUserId] [int]  NOT NULL , 
		[GuestUserId] [int]  NOT NULL , 
		[GuestUserName] [varchar] (50) NOT NULL , 
		[GuestRealName] [varchar] (100) NULL , 
		[Relationship] [smallint]  NULL , 
		[RenewTime] [datetime]  NOT NULL , 
		[GroupId] [int]  NOT NULL , 
		[GroupName] [varchar] (50) NULL , 
		[RoomId] [int]  NOT NULL  DEFAULT ('0'), 
		[LastTalkDate] [datetime]  NULL , 
		[LastMsg] [varchar] (max) NULL , 
		[IsTemp] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsDeleted] [bit]  NOT NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_IMRelationship] PRIMARY KEY NONCLUSTERED 
    ( 
       RId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoom]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMRoom]( 
		[RoomId] [int] IdENTITY(1,1)  NOT NULL , 
		[RoomName] [varchar] (100) NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[LgrCount] [int]  NOT NULL  DEFAULT ('0'), 
		[CreateDate] [datetime]  NULL , 
		[IconPath] [varchar] (max) NULL , 
		[Remark] [nchar] (20) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_IMGroup] PRIMARY KEY CLUSTERED 
    ( 
       RoomId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomLgr]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMRoomLgr]( 
		[RId] [int] IdENTITY(1,1)  NOT NULL , 
		[RoomId] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (50) NULL , 
		[IsController] [bit]  NULL , 
		[CreateDate] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_IMGroupLgr] PRIMARY KEY NONCLUSTERED 
    ( 
       RId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomMsg]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_IMRoomMsg]( 
		[MsgId] [int]  NOT NULL , 
		[RoomId] [int]  NOT NULL , 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[MsgContent] [varchar] (200) NOT NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[Sms] [bit]  NULL , 
		[FileJson] [varchar] (500) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_INote]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_INote]( 
		[NoteId] [int] IdENTITY(1,1)  NOT NULL , 
		[SenderId] [int]  NULL , 
		[SenderName] [varchar] (50) NULL , 
		[ReceiverId] [int]  NULL , 
		[ReceiverName] [varchar] (50) NULL , 
		[NoteContent] [varchar] (200) NOT NULL , 
		[SentDate] [datetime]  NULL , 
		[ReadDate] [datetime]  NULL , 
		[ReadFlag] [bit]  NULL  DEFAULT ('0'), 
		[NoteFlag] [bit]  NULL  DEFAULT ('0'), 
		[SenderDelete] [bit]  NULL  DEFAULT ('0'), 
		[ReceiverDelete] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsDeleted] [bit]  NULL , 
		[PhoneSms] [bit]  NULL    , 
    CONSTRAINT [PK_FZET_InnerNote] PRIMARY KEY NONCLUSTERED 
    ( 
       NoteId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LinkMan]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_LinkMan]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[CreatorId] [int]  NULL , 
		[GroupId] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (50) NULL , 
		[LinkTime] [int]  NULL  DEFAULT ('0'), 
		[CreateDate] [datetime]  NULL , 
		[RoomId] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_LinkMan] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LinkManGroup]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_LinkManGroup]( 
		[GroupId] [int] IdENTITY(1,1)  NOT NULL , 
		[GroupName] [varchar] (50) NOT NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NOT NULL , 
		[LgrCount] [int]  NOT NULL  DEFAULT ('0'), 
		[OrderNo] [int]  NULL , 
		[Remark] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_LinkManGroup] PRIMARY KEY NONCLUSTERED 
    ( 
       GroupId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListForm_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ListForm_Run]( 
		[FormId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[FormName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DropDownHtml] [varchar] (max) NULL , 
		[NoInit] [bit]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[DIYJsCss2] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[InsertTrigger] [varchar] (max) NULL , 
		[UpdateTrigger] [varchar] (max) NULL , 
		[DeleteTrigger] [varchar] (max) NULL , 
		[AtServer] [bit]  NULL  DEFAULT ('1'), 
		[IsIPLimit] [bit]  NULL  DEFAULT ('0'), 
		[IsSchedule] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsSupportMsg] [bit]  NULL  DEFAULT ('0'), 
		[BeginTime] [datetime]  NULL , 
		[EndTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1'), 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL    , 
    CONSTRAINT [PK_FZET_ListForm_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListFormField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ListFormField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Form_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[FieldNO] [int]  NULL  DEFAULT ('1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[RunDataTypeId] [int]  NOT NULL  DEFAULT ('2'), 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[DefaultValue] [varchar] (max) NULL , 
		[ValueType] [smallint]  NULL , 
		[RunValueType] [smallint]  NULL  DEFAULT ('1'), 
		[IsSingleChoice] [bit]  NULL  DEFAULT ('1'), 
		[CtrlStyleId] [tinyint]  NULL  DEFAULT ('0'), 
		[CtrlTypeId] [int]  NULL , 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[RepeatColumns] [int]  NULL  DEFAULT ('-1'), 
		[TreeId] [int]  NULL  DEFAULT ('-1'), 
		[Reflash] [bit]  NULL  DEFAULT ('0'), 
		[ValueLock] [bit]  NULL  DEFAULT ('0'), 
		[UploadPath] [varchar] (200) NULL , 
		[UploadFileType] [varchar] (200) NULL , 
		[ParentFields] [varchar] (200) NULL , 
		[SystemVariables] [varchar] (200) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[Div_DropDownHtml] [varchar] (max) NULL , 
		[CtrlBeforeHtml] [varchar] (max) NULL , 
		[CtrlfrontHtml] [varchar] (max) NULL , 
		[CtrlbackHtml] [varchar] (max) NULL , 
		[CtrlLastHtml] [varchar] (max) NULL , 
		[TableIndex] [int]  NULL , 
		[RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_ListFormField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListReport_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ListReport_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DIYJsCss] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_ListReport_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListReportField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ListReportField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LTreeRList]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_LTreeRList]( 
		[LRTreeId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('-1'), 
		[CtrlPrex] [varchar] (200) NULL , 
		[TreeNodeSQL1] [varchar] (max) NOT NULL , 
		[TreeNodeSQL2] [varchar] (max) NULL , 
		[IsDoubleDataSource] [bit]  NOT NULL  DEFAULT ('0'), 
		[BindFieldName] [varchar] (200) NULL , 
		[IsBindToValue] [bit]  NULL  DEFAULT ('1'), 
		[Width] [int]  NOT NULL  DEFAULT ('0'), 
		[Height] [int]  NOT NULL  DEFAULT ('0'), 
		[TreeTitle] [varchar] (200) NOT NULL , 
		[SearchIputDefaultText] [varchar] (200) NULL , 
		[TextFieldName1] [varchar] (200) NOT NULL , 
		[ValueFieldName1] [varchar] (200) NOT NULL , 
		[ParentFieldName1] [varchar] (200) NULL , 
		[IconUrlFieldName1] [varchar] (200) NULL , 
		[ExIconUrlFieldName1] [varchar] (200) NULL , 
		[TopNode_ParentValue1] [varchar] (200) NULL , 
		[TreeNode_JSonClick1] [varchar] (200) NULL , 
		[Tree_Dynamic1] [bit]  NOT NULL  DEFAULT ('0'), 
		[UseCache1] [bit]  NOT NULL  DEFAULT ('0'), 
		[TextFieldName2] [varchar] (200) NOT NULL , 
		[ValueFieldName2] [varchar] (200) NOT NULL , 
		[ParentFieldName2] [varchar] (200) NULL , 
		[IconUrlFieldName2] [varchar] (200) NULL , 
		[ExIconUrlFieldName2] [varchar] (200) NULL , 
		[TopNode_ParentValue2] [varchar] (200) NULL , 
		[TreeNode_JSonClick2] [varchar] (200) NULL , 
		[Tree_Dynamic2] [bit]  NOT NULL  DEFAULT ('0'), 
		[UseCache2] [bit]  NOT NULL  DEFAULT ('0'), 
		[LinkFieldName] [varchar] (200) NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[LastMender] [varchar] (50) NULL , 
		[LastMenderTime] [datetime]  NULL , 
		[Remark] [varchar] (max) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Mail]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Mail]( 
		[MailId] [int] IdENTITY(1,1)  NOT NULL , 
		[Title] [varchar] (1000) NULL , 
		[Body] [varchar] (max) NULL , 
		[MailboxId] [int]  NULL , 
		[fromAddr] [varchar] (1000) NULL , 
		[ToAddr] [varchar] (1000) NULL , 
		[CCAddress] [varchar] (max) NULL , 
		[HTMLFormat] [varchar] (50) NULL , 
		[SendUserId] [int]  NULL , 
		[SenderUserName] [varchar] (50) NULL , 
		[SendDate] [varchar] (50) NULL  DEFAULT ('发送日期'), 
		[MailSize] [int]  NULL , 
		[FolderId] [int]  NULL , 
		[AttachmentFlag] [int]  NULL , 
		[ReadFlag] [int]  NULL , 
		[IsUrgency] [int]  NULL , 
		[ReceiverUserIds] [varchar] (1000) NULL , 
		[ReceiverUserNames] [varchar] (1000) NULL    , 
    CONSTRAINT [PK_Dcx_Mail] PRIMARY KEY CLUSTERED 
    ( 
       MailId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Mail_attachment]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Mail_attachment]( 
		[AttachmentId] [int] IdENTITY(1,1)  NOT NULL , 
		[FileName] [varchar] (100) NULL , 
		[FilePath] [varchar] (255) NULL , 
		[FileType] [varchar] (50) NULL , 
		[MailId] [int]  NULL , 
		[Contain] [int]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailAttach]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MailAttach]( 
		[DocId] [int]  NULL , 
		[Readed] [bit]  NULL  DEFAULT ('0'), 
		[Sender] [varchar] (255) NULL , 
		[Receiver] [varchar] (255) NULL , 
		[AllReceiver] [varchar] (1000) NULL , 
		[CopySender] [varchar] (255) NULL , 
		[FurtiveCopySender] [varchar] (255) NULL , 
		[Position] [int]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Mailbox]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Mailbox]( 
		[MailboxId] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (50) NULL , 
		[Pop] [varchar] (80) NOT NULL  DEFAULT ('starriverproperty.com'), 
		[Smtp] [varchar] (80) NOT NULL  DEFAULT ('starriverproperty.com'), 
		[PopPort] [int]  NOT NULL  DEFAULT ('110'), 
		[SmtpPort] [int]  NOT NULL  DEFAULT ('25'), 
		[MailboxPwd] [varchar] (50) NOT NULL  DEFAULT ('123456'), 
		[MailAddr] [varchar] (100) NOT NULL , 
		[MailboxDomain] [varchar] (100) NOT NULL  DEFAULT ('starriverproperty.com'), 
		[MailboxUsername] [varchar] (50) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MailReceiver]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[ToEmailAddr] [varchar] (60) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (60) NULL , 
		[MailId] [int]  NULL , 
		[ReadDate] [datetime]  NULL , 
		[IsRemoved] [bit]  NULL , 
		[IsDeleted] [bit]  NULL    , 
    CONSTRAINT [PK_Dcx_MailReceiver] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Menu_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Menu_Run]( 
		[MenuId] [int]  NOT NULL , 
		[MenuUId] [uniqueidentifier]  NULL   DEFAULT (newid()), 
		[MenuName] [varchar] (150) NOT NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0'), 
		[ProPath] [varchar] (550) NULL , 
		[TemplateId] [int]  NULL  DEFAULT ('-1'), 
		[ImgPath] [varchar] (550) NULL , 
		[ExImgPath] [varchar] (250) NULL , 
		[OrderBy] [int]  NULL  DEFAULT ('0'), 
		[Target] [varchar] (250) NULL , 
		[IsOpen] [bit]  NULL  DEFAULT ('0'), 
		[IsHidden] [bit]  NULL  DEFAULT ('0'), 
		[Remark] [varchar] (500) NULL , 
		[SSystemId] [int]  NULL , 
		[SMenuId] [int]  NULL  DEFAULT ('0'), 
		[SystemId] [int]  NULL  DEFAULT ('0'), 
		[EntityCount] [int]  NULL  DEFAULT ('0'), 
		[VersionId] [int]  NULL  DEFAULT ('0'), 
		[IsDesigning] [bit]  NULL  DEFAULT ('0'), 
		[AddDcxTime] [datetime]  NULL , 
		[AddDcxUserName] [varchar] (40) NULL , 
		[AddDcxUserId] [int]  NULL  DEFAULT ('0'), 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_Menu_Run_menuId] PRIMARY KEY CLUSTERED 
    ( 
       MenuId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuAppArea]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MenuAppArea]( 
		[MenuModuleId] [int] IdENTITY(1,1)  NOT NULL , 
		[SystemId] [int]  NOT NULL  DEFAULT ('1'), 
		[MenuId] [int]  NOT NULL  DEFAULT ('0'), 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[TemplateId] [int]  NOT NULL  DEFAULT ('0'), 
		[ModuleTypeId] [int]  NOT NULL  DEFAULT ('0'), 
		[ModuleId] [int]  NOT NULL  DEFAULT ('0'), 
		[GroupId] [int]  NOT NULL  DEFAULT ('0'), 
		[AreaId] [int]  NOT NULL  DEFAULT ('0'), 
		[ShowMode] [tinyint]  NULL  DEFAULT ('1'), 
		[AreaUrl] [varchar] (150) NULL , 
		[TaskId] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_MenuEntityModule] PRIMARY KEY NONCLUSTERED 
    ( 
       MenuModuleId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuExample]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MenuExample]( 
		[MenuId] [int]  NOT NULL , 
		[SystemId] [int]  NOT NULL , 
		[MenuName] [varchar] (200) NOT NULL , 
		[MTypeId] [int]  NOT NULL , 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[UsedTime] [int]  NOT NULL  DEFAULT ('0'), 
		[CreateTime] [datetime]  NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[LastUsedDate] [datetime]  NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[EntCount] [int]  NOT NULL  DEFAULT ('0'), 
		[NeedCode] [bit]  NOT NULL  DEFAULT ('0'), 
		[ProPath] [varchar] (550) NULL , 
		[TemplateId] [int]  NULL , 
		[ImgPath] [varchar] (550) NULL , 
		[IsHidden] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_MenuExample_1] PRIMARY KEY NONCLUSTERED 
    ( 
       MenuId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MenuLog]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (25) NOT NULL , 
		[ExpId] [int]  NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[MenuName] [varchar] (150) NOT NULL , 
		[OperateTime] [datetime]  NULL , 
		[OperateTypeId] [tinyint]  NULL    , 
    CONSTRAINT [PK_Dcx_MenuLog] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MenuPrivilege]( 
		[MenuPrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[MenuName] [varchar] (150) NULL , 
		[RoleName] [varchar] (150) NULL , 
		[RoleId] [int]  NOT NULL , 
		[CanViewList] [bit]  NULL  DEFAULT ('1'), 
		[CanBrowse] [bit]  NULL  DEFAULT ('1'), 
		[CanInsert] [bit]  NULL  DEFAULT ('1'), 
		[CanDelete] [bit]  NULL  DEFAULT ('1'), 
		[CanUpdate] [bit]  NULL  DEFAULT ('1'), 
		[CanOutPut] [bit]  NULL  DEFAULT ('1'), 
		[CanInput] [bit]  NULL  DEFAULT ('1'), 
		[CanCopy] [bit]  NULL  DEFAULT ('1'), 
		[CanPrint] [bit]  NULL  DEFAULT ('1'), 
		[CanCheck] [bit]  NULL  DEFAULT ('1'), 
		[CanClean] [bit]  NULL  DEFAULT ('1'), 
		[CanRecycle] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField1] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField2] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField3] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField4] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField5] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField6] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField7] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField8] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField9] [bit]  NULL  DEFAULT ('1'), 
		[ExtendField10] [bit]  NULL  DEFAULT ('1'), 
		[Remark] [varchar] (50) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_MenuRole] PRIMARY KEY NONCLUSTERED 
    ( 
       MenuPrivilegeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuRelated]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MenuRelated]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[ObjectName] [varchar] (500) NULL , 
		[ObjectId] [int]  NULL , 
		[SystemId] [int]  NULL , 
		[EntId] [int]  NULL , 
		[TypeName] [varchar] (500) NULL , 
		[TypeId] [int]  NULL , 
		[FilePath] [varchar] (500) NULL , 
		[CodeContent] [varchar] (max) NULL , 
		[Remark] [varchar] (max) NULL , 
		[OrderNo] [int]  NOT NULL  DEFAULT ('0'), 
		[IsBefore] [bit]  NOT NULL  DEFAULT ('1'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_MenuRelated] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MenuType]( 
		[MTypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[MTypeName] [varchar] (200) NOT NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_MenuType] PRIMARY KEY CLUSTERED 
    ( 
       MTypeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Message]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Message]( 
		[MsgId] [int] IdENTITY(1,1)  NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[KeyFieldValue] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[EntName] [varchar] (50) NULL , 
		[IsFlow] [bit]  NULL  DEFAULT ('0'), 
		[RunId] [int]  NULL , 
		[FlowId] [int]  NULL , 
		[NodeId] [int]  NULL , 
		[PrcsId] [int]  NULL , 
		[MenuId] [int]  NULL , 
		[ShowEditBtn] [bit]  NULL , 
		[SenderDelete] [bit]  NULL , 
		[ReadTimes] [int]  NULL  DEFAULT ('0'), 
		[ReplyCount] [int]  NULL , 
		[ColorId] [tinyint]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Message] PRIMARY KEY NONCLUSTERED 
    ( 
       MsgId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageReceiver]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MessageReceiver]( 
		[RcvId] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[MsgId] [int]  NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[ReceiverId] [int]  NOT NULL , 
		[ReceiverName] [varchar] (50) NULL , 
		[IsPublic] [bit]  NULL  DEFAULT ('0'), 
		[IsCollect] [bit]  NULL , 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsRead] [bit]  NULL  DEFAULT ('0'), 
		[IsProcessed] [bit]  NULL  DEFAULT ('0'), 
		[ReadTime] [datetime]  NULL , 
		[ProcessTime] [datetime]  NULL , 
		[SenderAvatar] [varchar] (200) NULL , 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[KeyFieldValue] [varchar] (50) NULL , 
		[EntName] [varchar] (50) NULL , 
		[ShowEditBtn] [bit]  NULL , 
		[IsFlow] [bit]  NULL  DEFAULT ('0'), 
		[IsMain] [bit]  NULL  DEFAULT ('0'), 
		[FlowId] [int]  NULL , 
		[NodeId] [int]  NULL , 
		[RunId] [int]  NULL , 
		[PrcsId] [int]  NULL , 
		[MenuId] [int]  NULL , 
		[ColorId] [tinyint]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[IsNote] [bit]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_MessageReceiver_1] PRIMARY KEY NONCLUSTERED 
    ( 
       RcvId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageReply]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MessageReply]( 
		[ReplyId] [int] IdENTITY(1,1)  NOT NULL , 
		[SnederId] [int]  NOT NULL , 
		[MsgId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ReplyContent] [varchar] (max) NOT NULL , 
		[ReplyTime] [datetime]  NULL , 
		[ReadTime] [datetime]  NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_MessageReply] PRIMARY KEY NONCLUSTERED 
    ( 
       ReplyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MessageType]( 
		[MsgTypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[ModuleTypeId] [tinyint]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntName] [varchar] (100) NOT NULL , 
		[CanINote] [bit]  NULL  DEFAULT ('0'), 
		[CanIMail] [bit]  NULL  DEFAULT ('0'), 
		[CanSMS] [bit]  NULL  DEFAULT ('0'), 
		[CanEmail] [bit]  NULL  DEFAULT ('0'), 
		[ContentTemplate] [varchar] (max) NULL , 
		[DefaultReceiverNames] [varchar] (max) NULL , 
		[DefaultReceiverIds] [varchar] (max) NULL , 
		[ReceiverFldId] [int]  NULL , 
		[ReceiverFieldName] [varchar] (100) NULL , 
		[FieldType] [tinyint]  NULL    , 
    CONSTRAINT [PK_Dcx_INoteCenter] PRIMARY KEY NONCLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageTypeReceiver]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_MessageTypeReceiver]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[MsgTypeId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ObjectId] [int]  NOT NULL , 
		[ObjectName] [varchar] (100) NULL , 
		[IdType] [tinyint]  NOT NULL    , 
    CONSTRAINT [PK_Dcx_MessageReceiver] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NavMenu]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_NavMenu]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (50) NULL , 
		[MenuId] [int]  NOT NULL , 
		[SortOrder] [int]  NOT NULL , 
		[ShowAtTop] [bit]  NOT NULL  DEFAULT ('1'), 
		[AfterSeparate] [bit]  NOT NULL  DEFAULT ('0'), 
		[MenuName] [varchar] (50) NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0'), 
		[ImgPath] [varchar] (300) NULL , 
		[ProPath] [varchar] (300) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_NavMenu] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NavMenu_Default]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_NavMenu_Default]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[MenuId] [int]  NULL , 
		[SortOrder] [int]  NULL , 
		[ShowAtToolBar] [bit]  NULL , 
		[MenuName] [varchar] (50) NULL , 
		[ParentId] [int]  NULL , 
		[ImgPath] [nchar] (20) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_NavMenu_Default] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_News]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_News]( 
		[NId] [int] IdENTITY(1,1)  NOT NULL , 
		[Title] [varchar] (max) NULL , 
		[TypeId] [int]  NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[TagName] [varchar] (50) NULL , 
		[NewsContent] [varchar] (max) NULL , 
		[IsPublic] [bit]  NOT NULL  DEFAULT ('0'), 
		[CreateDate] [datetime]  NOT NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[ColorId] [tinyint]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[ReadTimes] [int]  NULL  DEFAULT ('0'), 
		[Summary] [varchar] (max) NULL , 
		[BeginDate] [datetime]  NULL , 
		[EndDate] [datetime]  NULL , 
		[EditTime] [datetime]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditorId] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_News] PRIMARY KEY NONCLUSTERED 
    ( 
       NId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsFile]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_NewsFile]( 
		[FileId] [int] IdENTITY(1,1)  NOT NULL , 
		[FilePath] [varchar] (500) NULL , 
		[FileName] [varchar] (300) NULL , 
		[FileExt] [varchar] (50) NULL , 
		[FileTypeId] [smallint]  NULL , 
		[FileSize] [int]  NULL , 
		[DownLoadTimes] [int]  NULL  DEFAULT ('0'), 
		[CreatorId] [int]  NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[NId] [int]  NULL    , 
    CONSTRAINT [PK_Dcx_NewsFile] PRIMARY KEY CLUSTERED 
    ( 
       FileId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsPrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_NewsPrivilege]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[DeptId] [int]  NOT NULL , 
		[NewsId] [int]  NOT NULL    , 
    CONSTRAINT [PK_Dcx_NewsPrivilege] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_NewsType]( 
		[TypeId] [int]  NOT NULL , 
		[TypeName] [nvarchar] (200) NOT NULL , 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[ImgPath] [varchar] (500) NULL , 
		[ParentId] [int]  NOT NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_OnlineUser]( 
		[OnLineId] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[SystemId] [int]  NOT NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1'), 
		[UserGuId] [uniqueidentifier]  NULL   DEFAULT (newid()), 
		[UserName] [varchar] (50) NOT NULL , 
		[RealName] [varchar] (50) NULL , 
		[LoginTime] [datetime]  NULL  DEFAULT ('0'), 
		[ActiveTime] [datetime]  NULL , 
		[LastRefreshTime] [datetime]  NULL , 
		[RoleId] [int]  NULL , 
		[RoleName] [varchar] (200) NULL , 
		[RoleIds] [varchar] (100) NULL , 
		[RoleNames] [varchar] (200) NULL , 
		[DeptId] [int]  NULL , 
		[DeptName] [varchar] (100) NULL , 
		[EmployeeId] [int]  NULL , 
		[PositionId] [int]  NULL , 
		[PositionName] [varchar] (100) NULL , 
		[SuperAdmin] [bit]  NULL  DEFAULT ('0'), 
		[CanLogin] [bit]  NULL  DEFAULT ('1'), 
		[IP] [varchar] (50) NULL , 
		[RestrictIp] [bit]  NULL , 
		[VisitTime] [int]  NULL , 
		[Online] [bit]  NULL  DEFAULT ('0'), 
		[PWD] [varchar] (500) NOT NULL , 
		[UserOrder] [int]  NULL , 
		[Sex] [varchar] (50) NULL , 
		[Telephone] [varchar] (50) NULL , 
		[Email] [varchar] (100) NULL , 
		[Status] [varchar] (50) NULL , 
		[RegistedDate] [datetime]  NULL , 
		[Phone] [varchar] (50) NULL , 
		[Birthday] [datetime]  NULL , 
		[Style] [int]  NULL  DEFAULT ('0'), 
		[IsNeedKey] [bit]  NULL  DEFAULT ('0'), 
		[Caste] [int]  NULL  DEFAULT ('0'), 
		[Http] [varchar] (100) NULL , 
		[IconPath] [varchar] (200) NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL  DEFAULT (getdate())   , 
    CONSTRAINT [PK_FZET_OnlineUser_UserId] PRIMARY KEY CLUSTERED 
    ( 
       OnLineId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Operation]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Operation]( 
		[OperationId] [int] IdENTITY(1,1)  NOT NULL , 
		[OperationName] [varchar] (50) NOT NULL , 
		[OperationCNName] [varchar] (50) NOT NULL , 
		[Description] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_Operation] PRIMARY KEY CLUSTERED 
    ( 
       OperationId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OutPut_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_OutPut_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ReportName] [varchar] (200) NULL , 
		[WorkBookName] [varchar] (100) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[OtherMsg] [varchar] (max) NULL , 
		[ModuleId] [int]  NULL , 
		[ShowTitle] [bit]  NOT NULL  DEFAULT ('1'), 
		[ShowPageHead] [bit]  NOT NULL  DEFAULT ('1'), 
		[ShowHead] [bit]  NOT NULL  DEFAULT ('1'), 
		[ShowTotalUp] [bit]  NOT NULL  DEFAULT ('1'), 
		[ShowPageFoot] [bit]  NOT NULL  DEFAULT ('1'), 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[CreateTime] [datetime]  NOT NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1'), 
		[EditTime] [datetime]  NOT NULL , 
		[EditorId] [int]  NOT NULL , 
		[TitleFontColor] [varchar] (10) NULL , 
		[TitleFontSize] [smallint]  NULL , 
		[HeadFontColor] [varchar] (10) NULL , 
		[HeadFontSize] [smallint]  NULL , 
		[HeadAlign] [tinyint]  NULL  DEFAULT ('2'), 
		[HeadFontBolder] [bit]  NULL  DEFAULT ('0'), 
		[ItemFontColor] [varchar] (10) NULL , 
		[ItemFontSize] [smallint]  NULL , 
		[ItemAlign] [tinyint]  NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_OutPut_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OutPutField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_OutPutField_Run]( 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ColumnByname] [varchar] (100) NOT NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[RunDataTypeId] [smallint]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [smallint]  NOT NULL  DEFAULT ('1'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[ColumnWidth] [smallint]  NOT NULL  DEFAULT ('0'), 
		[ColumnHeight] [smallint]  NOT NULL  DEFAULT ('0'), 
		[IsMerge] [bit]  NOT NULL  DEFAULT ('0'), 
		[TotalUp] [bit]  NOT NULL  DEFAULT ('0'), 
		[TotalUpUnit] [varchar] (20) NULL , 
		[TotalUpType] [varchar] (20) NULL , 
		[FieldNO] [smallint]  NOT NULL  DEFAULT ('0'), 
		[TableIndex] [tinyint]  NOT NULL  DEFAULT ('0'), 
		[RowIndex] [smallint]  NOT NULL  DEFAULT ('0'), 
		[RowSpan] [smallint]  NOT NULL  DEFAULT ('0'), 
		[ColSpan] [smallint]  NOT NULL  DEFAULT ('0'), 
		[ColumnIndex] [smallint]  NOT NULL  DEFAULT ('0'), 
		[Parent_RowIndex] [smallint]  NOT NULL  DEFAULT ('0'), 
		[Parent_TableIndex] [smallint]  NOT NULL  DEFAULT ('0'), 
		[HaveChildEntity] [bit]  NOT NULL  DEFAULT ('0'), 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL    , 
    CONSTRAINT [PK_FZET_OutPutField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ParameterSeting]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ParameterSeting]( 
		[ParameterId] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[ParameterName] [varchar] (100) NOT NULL , 
		[ParameterValue] [varchar] (max) NULL , 
		[IsURLParam] [bit]  NULL  DEFAULT ('0'), 
		[IsSysParam] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_FZET2_ParameterSeting] PRIMARY KEY CLUSTERED 
    ( 
       ParameterId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Position]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Position]( 
		[PositionId] [int] IdENTITY(1,1)  NOT NULL , 
		[PositionCode] [varchar] (20) NOT NULL , 
		[PositionName] [varchar] (100) NOT NULL , 
		[ParentId] [int]  NULL , 
		[OrderNO] [int]  NULL , 
		[Remark] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_hyoa_position] PRIMARY KEY CLUSTERED 
    ( 
       PositionId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Publish]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[PublishId] [varchar] (50) NULL , 
		[KeyDataType] [tinyint]  NULL , 
		[ModuleTypeId] [int]  NOT NULL , 
		[ModuleTypeName] [varchar] (50) NOT NULL , 
		[ModuleName] [varchar] (50) NULL , 
		[MenuId] [int]  NULL , 
		[MenuName] [varchar] (50) NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (50) NULL , 
		[PublishTime] [datetime]  NOT NULL , 
		[ReceiveTime] [datetime]  NOT NULL , 
		[Dcx_UserId] [int]  NULL , 
		[Dcx_UserName] [varchar] (50) NULL , 
		[Dcx_Email] [varchar] (50) NULL , 
		[CreatorId] [int]  NOT NULL , 
		[Creator] [varchar] (50) NOT NULL , 
		[SystemId] [int]  NOT NULL , 
		[SystemName] [varchar] (50) NOT NULL , 
		[SendUrl] [varchar] (150) NOT NULL , 
		[SystemKey] [varchar] (50) NOT NULL , 
		[ReceiveUserName] [varchar] (50) NOT NULL , 
		[IsPublish] [bit]  NOT NULL  DEFAULT ('0'), 
		[EditTime] [datetime]  NULL , 
		[Editor] [varchar] (50) NULL  DEFAULT ('0'), 
		[IsSafe] [bit]  NULL  DEFAULT ('0'), 
		[Remark] [varchar] (max) NULL , 
		[PlsContent] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Publish] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Question]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Question]( 
		[QId] [int] IdENTITY(1,1)  NOT NULL , 
		[QTitle] [varchar] (100) NOT NULL , 
		[QContent] [varchar] (max) NULL , 
		[Ip] [varchar] (20) NULL , 
		[SystemId] [nchar] (20) NULL , 
		[ReadTimes] [int]  NULL , 
		[Type] [tinyint]  NULL , 
		[Grade] [tinyint]  NULL , 
		[State] [tinyint]  NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreateTime] [datetime]  NOT NULL , 
		[Creator] [varchar] (50) NOT NULL , 
		[EditTime] [datetime]  NULL , 
		[EditorId] [int]  NULL    , 
    CONSTRAINT [PK_Dcx_Question] PRIMARY KEY NONCLUSTERED 
    ( 
       QId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_QuestionAnwser]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_QuestionAnwser]( 
		[AId] [int] IdENTITY(1,1)  NOT NULL , 
		[QId] [int]  NOT NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[Anwser] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreateTime] [datetime]  NOT NULL , 
		[Creator] [varchar] (50) NULL , 
		[Ip] [varchar] (20) NULL , 
		[IsBest] [bit]  NOT NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_QuestionAnwser] PRIMARY KEY NONCLUSTERED 
    ( 
       AId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Remind]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Remind]( 
		[RmId] [int] IdENTITY(1,1)  NOT NULL , 
		[RmContent] [varchar] (max) NOT NULL , 
		[TypeId] [int]  NULL  DEFAULT ('0'), 
		[RemindDate] [datetime]  NOT NULL , 
		[RepeatType] [smallint]  NULL , 
		[RemindType] [smallint]  NULL  DEFAULT ('1'), 
		[RemindValue] [smallint]  NULL  DEFAULT ('0'), 
		[SendEmail] [bit]  NULL  DEFAULT ('0'), 
		[SendSms] [bit]  NULL  DEFAULT ('0'), 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (50) NOT NULL , 
		[CreateDate] [datetime]  NOT NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (50) NULL , 
		[KeyFieldValue] [int]  NULL  DEFAULT ('0'), 
		[IsRead] [bit]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Remind] PRIMARY KEY NONCLUSTERED 
    ( 
       RmId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Role]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Role]( 
		[RoleId] [int] IdENTITY(1,1)  NOT NULL , 
		[RoleName] [varchar] (50) NOT NULL , 
		[SystemRoleType] [tinyint]  NOT NULL  DEFAULT ('0'), 
		[ParentId] [int]  NULL  DEFAULT ('0'), 
		[RoleOrder] [int]  NULL , 
		[IsDisplay] [bit]  NULL  DEFAULT ('1'), 
		[RoleTypeId] [int]  NOT NULL  DEFAULT ('1'), 
		[CreatorId] [int]  NULL , 
		[Creator] [varchar] (40) NULL , 
		[CreateTime] [datetime]  NULL , 
		[Remark] [varchar] (20) NULL , 
		[EditorId] [int]  NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_EWorkRoles] PRIMARY KEY CLUSTERED 
    ( 
       RoleId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_RoleLeaguer]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_RoleLeaguer]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[roleId] [int]  NOT NULL , 
		[userId] [int]  NOT NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_RoleType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_RoleType]( 
		[TypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[TypeOrder] [int]  NOT NULL , 
		[TypeName] [varchar] (200) NOT NULL , 
		[CreateTime] [datetime]  NULL , 
		[Creator] [varchar] (40) NULL , 
		[CreatorId] [int]  NULL    , 
    CONSTRAINT [PK_FZET_RoleType] PRIMARY KEY CLUSTERED 
    ( 
       TypeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_RuningSysParam]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_RuningSysParam]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[DefautStyleId] [int]  NULL , 
		[SystemId] [int]  NULL , 
		[SystemKey] [varchar] (100) NULL , 
		[TopMenuId] [int]  NOT NULL  DEFAULT ('0'), 
		[SystemName] [varchar] (100) NULL , 
		[CompanyName] [varchar] (100) NULL , 
		[HomePageMenuId] [int]  NULL , 
		[BigLogoUrl] [varchar] (200) NULL , 
		[SmallLogoUrl] [varchar] (200) NULL , 
		[LoginPageUrl] [varchar] (200) NULL , 
		[MainPageUrl] [varchar] (200) NULL , 
		[HomePageUrl] [varchar] (200) NULL , 
		[DcxUserName] [varchar] (100) NULL , 
		[InstallDate] [datetime]  NULL , 
		[RegisterCode] [varchar] (500) NULL , 
		[EditTime] [datetime]  NULL , 
		[SSystemId] [int]  NULL , 
		[SSystemKey] [varchar] (100) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_SysRuningParam] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Schedule]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Schedule]( 
		[SId] [int] IdENTITY(1,1)  NOT NULL , 
		[Title] [varchar] (200) NOT NULL , 
		[TypeId] [int]  NULL  DEFAULT ('0'), 
		[TypeName] [varchar] (300) NULL , 
		[StartTime] [datetime]  NOT NULL , 
		[EndTime] [datetime]  NULL , 
		[Address] [varchar] (100) NULL , 
		[RepeatType] [smallint]  NULL , 
		[RemindType] [smallint]  NULL  DEFAULT ('1'), 
		[RemindValue] [smallint]  NULL  DEFAULT ('0'), 
		[RemindMode] [smallint]  NULL  DEFAULT ('1'), 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (100) NULL , 
		[LeaderId] [int]  NULL , 
		[LeaderName] [varchar] (100) NULL , 
		[ClientId] [varchar] (50) NULL , 
		[ClientName] [varchar] (50) NULL , 
		[LinkManId] [varchar] (50) NULL , 
		[LinkManName] [varchar] (50) NULL , 
		[IsPriv] [bit]  NULL , 
		[EditTime] [datetime]  NULL , 
		[CreateTime] [datetime]  NULL , 
		[IsAllDay] [bit]  NULL , 
		[RepeatSId] [int]  NULL  DEFAULT ('0'), 
		[SendEmail] [bit]  NULL  DEFAULT ('0'), 
		[SendSms] [bit]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_Schedule] PRIMARY KEY NONCLUSTERED 
    ( 
       SId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ScheduleType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_ScheduleType]( 
		[TypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[TypeName] [varchar] (100) NOT NULL , 
		[OrderNO] [int]  NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (100) NULL , 
		[CreateTime] [datetime]  NULL    , 
    CONSTRAINT [PK_Dcx_ScheduleType] PRIMARY KEY CLUSTERED 
    ( 
       TypeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchForm_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SearchForm_Run]( 
		[FormId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[FormName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DropDownHtml] [varchar] (max) NULL , 
		[NoInit] [bit]  NOT NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[DIYJsCss2] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[InsertTrigger] [varchar] (max) NULL , 
		[UpdateTrigger] [varchar] (max) NULL , 
		[DeleteTrigger] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[IsIPLimit] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsSchedule] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsSupportMsg] [bit]  NULL  DEFAULT ('0'), 
		[BeginTime] [datetime]  NULL , 
		[EndTime] [datetime]  NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_SearchForm_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchFormField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SearchFormField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Form_EntId] [int]  NOT NULL  DEFAULT ('-1'), 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[CompareOperatorType] [varchar] (50) NULL , 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[RunDataTypeId] [int]  NOT NULL  DEFAULT ('2'), 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[DefaultValue] [varchar] (max) NULL , 
		[ValueType] [smallint]  NULL , 
		[RunValueType] [smallint]  NULL  DEFAULT ('1'), 
		[IsSingleChoice] [bit]  NULL  DEFAULT ('1'), 
		[CtrlStyleId] [tinyint]  NULL  DEFAULT ('0'), 
		[CtrlTypeId] [int]  NULL , 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[RepeatColumns] [int]  NULL  DEFAULT ('-1'), 
		[TreeId] [int]  NULL  DEFAULT ('-1'), 
		[Reflash] [bit]  NULL  DEFAULT ('0'), 
		[ValueLock] [bit]  NULL  DEFAULT ('0'), 
		[UploadPath] [varchar] (200) NULL , 
		[UploadFileType] [varchar] (200) NULL , 
		[ParentFields] [varchar] (200) NULL , 
		[SystemVariables] [varchar] (200) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[Div_DropDownHtml] [varchar] (max) NULL , 
		[CtrlBeforeHtml] [varchar] (max) NULL , 
		[CtrlfrontHtml] [varchar] (max) NULL , 
		[CtrlbackHtml] [varchar] (max) NULL , 
		[CtrlLastHtml] [varchar] (max) NULL , 
		[IsPostToDB] [bit]  NULL  DEFAULT ('1'), 
		[TableIndex] [int]  NULL , 
		[RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_SearchFormField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchItem]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SearchItem]( 
		[SearchId] [int] IdENTITY(1,1)  NOT NULL , 
		[Title] [varchar] (50) NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[MenuName] [varchar] (50) NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[FieldName] [varchar] (50) NOT NULL , 
		[CompareOperatorType] [varchar] (50) NOT NULL  DEFAULT ('Like'), 
		[RunDataTypeId] [tinyint]  NOT NULL  DEFAULT ('2'), 
		[FldId] [int]  NULL , 
		[OpenMode] [tinyint]  NULL , 
		[IsDefault] [bit]  NOT NULL  DEFAULT ('1'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_SearchItem] PRIMARY KEY NONCLUSTERED 
    ( 
       SearchId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchItemInUser]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SearchItemInUser]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[SearchId] [int]  NOT NULL , 
		[Title] [varchar] (50) NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (50) NULL , 
		[SortOrder] [int]  NOT NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_SearchItemInUser] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SitePage]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SitePage]( 
		[PageId] [int] IdENTITY(1,1)  NOT NULL , 
		[Name] [varchar] (50) NULL , 
		[Url] [varchar] (100) NULL , 
		[VisitTime] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_SitePage] PRIMARY KEY CLUSTERED 
    ( 
       PageId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SiteVisit]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SiteVisit]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Ip] [varchar] (50) NULL , 
		[Time] [datetime]  NULL , 
		[Mac] [varchar] (50) NULL , 
		[Place] [varchar] (50) NULL , 
		[PageId] [int]  NULL , 
		[Remark] [varchar] (max) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[IsVisit] [bit]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_SiteVisit] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SQLParameter_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SQLParameter_Run]( 
		[PId] [int] IdENTITY(1,1)  NOT NULL , 
		[SystemId] [int]  NULL  DEFAULT ('0'), 
		[EntId] [int]  NOT NULL , 
		[ParameterName] [varchar] (50) NOT NULL , 
		[ParameterValue] [varchar] (100) NULL , 
		[ParamType] [tinyint]  NULL  DEFAULT ('0'), 
		[ValueType] [tinyint]  NULL  DEFAULT ('0'), 
		[ModuleTypeId] [tinyint]  NULL    , 
    CONSTRAINT [PK_FZET_SQLParameter_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       PId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SummaryList_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SummaryList_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DIYJsCss] [varchar] (max) NULL , 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[LoadingSql] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_SummaryList_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SummaryListField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SummaryListField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_SummaryListField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SysCtrl_Address]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SysCtrl_Address]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Value] [varchar] (100) NOT NULL , 
		[Name] [varchar] (100) NOT NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[Label] [int]  NOT NULL  DEFAULT ('1'), 
		[Code] [varchar] (100) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemLoginLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SystemLoginLog]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Guid] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[UserName] [varchar] (50) NOT NULL , 
		[PWD] [varchar] (200) NULL , 
		[LoginTime] [datetime]  NULL  DEFAULT (getdate()), 
		[LogoutTime] [datetime]  NULL , 
		[IP] [varchar] (50) NULL , 
		[MAC] [nchar] (20) NULL , 
		[Region] [varchar] (200) NULL , 
		[IsSucceeded] [bit]  NULL , 
		[Remark] [varchar] (200) NULL    , 
    CONSTRAINT [PK_FZET_SystemLoginLog] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemMenu]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SystemMenu]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[MenuName] [varchar] (150) NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('-1'), 
		[SystemId] [int]  NOT NULL  DEFAULT ('0'), 
		[OrderNo] [int]  NOT NULL  DEFAULT ('-1')   , 
    CONSTRAINT [PK_Dcx_SystemMenu] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SystemOperateLog]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Guid] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (25) NULL , 
		[EntId] [int]  NULL , 
		[DbTableName] [varchar] (200) NULL , 
		[OperateTime] [datetime]  NULL , 
		[IP] [varchar] (30) NULL , 
		[MAC] [varchar] (30) NULL , 
		[Region] [varchar] (200) NULL , 
		[Type] [varchar] (30) NULL , 
		[SQL] [varchar] (max) NULL , 
		[System] [varchar] (50) NULL , 
		[IsSucceeded] [bit]  NULL , 
		[Remark] [varchar] (200) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemParameter]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_SystemParameter]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Name] [varchar] (50) NULL , 
		[Value] [varchar] (50) NOT NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0'), 
		[GroupId] [int]  NULL  DEFAULT ('0'), 
		[GroupName] [varchar] (50) NULL , 
		[Value2] [varchar] (50) NULL , 
		[Value3] [varchar] (50) NULL , 
		[Value4] [varchar] (50) NULL    , 
    CONSTRAINT [PK_FZET_SystemParameter] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TemplateArea_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TemplateArea_Run]( 
		[AreaHtmlId] [int] IdENTITY(1,1)  NOT NULL , 
		[MenuId] [int]  NOT NULL , 
		[TemplateId] [int]  NOT NULL , 
		[AreaId] [int]  NULL , 
		[AreaHtml] [varchar] (max) NULL    , 
    CONSTRAINT [PK_FZET_TemplateArea_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       AreaHtmlId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TitleList_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TitleList_Run]( 
		[ReportId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[ReportName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL , 
		[ModuleId] [int]  NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[DIYJsCss] [varchar] (max) NULL , 
		[LoadingSql] [varchar] (max) NULL , 
		[StartUsingJs] [bit]  NOT NULL  DEFAULT ('1'), 
		[AtServer] [bit]  NOT NULL  DEFAULT ('1'), 
		[PageSize] [int]  NOT NULL  DEFAULT ('0'), 
		[AutoPublicJs] [varchar] (max) NULL , 
		[AutoInitJs] [varchar] (max) NULL , 
		[AutoOtherJS] [varchar] (max) NULL , 
		[OtherMsg] [varchar] (max) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_TitleList_Run] PRIMARY KEY CLUSTERED 
    ( 
       EntId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TitleListField]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TitleListField]( 
		[REFId] [int] IdENTITY(1,1)  NOT NULL , 
		[RPId] [int]  NULL  DEFAULT ('-1'), 
		[RPEId] [int]  NULL  DEFAULT ('-1'), 
		[FieldId] [int]  NULL  DEFAULT ('-1'), 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[EntName] [varchar] (100) NULL , 
		[MEnt] [bit]  NULL  DEFAULT ('1'), 
		[FieldName] [varchar] (100) NULL , 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldType] [varchar] (50) NULL , 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[DataFormat] [varchar] (50) NULL , 
		[FieldNo] [int]  NULL  DEFAULT ('1'), 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[Width] [int]  NULL  DEFAULT ('-1'), 
		[Height] [int]  NULL  DEFAULT ('-1'), 
		[CtrlfrontHtml] [varchar] (max) NULL , 
		[CtrlbackHtml] [varchar] (max) NULL , 
		[CtrlHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_TitleListField] PRIMARY KEY CLUSTERED 
    ( 
       REFId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TitleListField_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TitleListField_Run]( 
		[FldId] [int]  NOT NULL  DEFAULT ('0'), 
		[FldUId] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[Report_EntId] [int]  NOT NULL , 
		[EntId] [int]  NOT NULL , 
		[EntUId] [uniqueidentifier]  NULL , 
		[DBFieldId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldName] [varchar] (100) NOT NULL , 
		[FieldNO] [int]  NOT NULL  DEFAULT ('1'), 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldDataType] [varchar] (50) NULL , 
		[FieldDataTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL , 
		[FrontHtml] [varchar] (max) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[RowIndex] [int]  NULL , 
		[TableIndex] [int]  NULL , 
		[Parent_RowIndex] [int]  NULL , 
		[Parent_TableIndex] [int]  NULL , 
		[HaveChildEntity] [bit]  NULL  DEFAULT ('0'), 
		[SameRowChildEntId] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_TitleListField_Run] PRIMARY KEY NONCLUSTERED 
    ( 
       FldUId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Trade]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Trade]( 
		[TradeId] [int] IdENTITY(1,1)  NOT NULL , 
		[TradeName] [varchar] (50) NOT NULL , 
		[SortOrder] [int]  NULL    , 
    CONSTRAINT [PK_Dcx_Trade] PRIMARY KEY NONCLUSTERED 
    ( 
       TradeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Tree_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Tree_Run]( 
		[TreeId] [int]  NOT NULL , 
		[TreeName] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[SystemId] [int]  NULL  DEFAULT ('0'), 
		[ModuleId] [int]  NULL  DEFAULT ('0'), 
		[DBConnectId] [int]  NULL  DEFAULT ('0'), 
		[DIYJsCss] [varchar] (max) NULL , 
		[StaticHtml] [varchar] (max) NULL , 
		[NoTitle] [bit]  NULL  DEFAULT ('0'), 
		[NoSearch] [bit]  NULL  DEFAULT ('0'), 
		[NoImg] [bit]  NULL  DEFAULT ('0'), 
		[IsDesigning] [bit]  NULL  DEFAULT ('0'), 
		[IsStatic] [bit]  NULL  DEFAULT ('1'), 
		[CtrlPrex] [varchar] (200) NULL , 
		[DBTableName1] [varchar] (100) NULL , 
		[DBTableName2] [varchar] (100) NULL , 
		[TreeNodeSQL1] [varchar] (max) NOT NULL , 
		[TreeNodeSQL2] [varchar] (max) NULL , 
		[IsDoubleDataSource] [bit]  NOT NULL  DEFAULT ('0'), 
		[BindTextFieldName] [varchar] (50) NULL , 
		[BindFieldDateType] [tinyint]  NULL  DEFAULT ('2'), 
		[BindFieldName] [varchar] (50) NULL , 
		[IsBindToValue] [bit]  NULL  DEFAULT ('1'), 
		[BindMode] [tinyint]  NULL  DEFAULT ('0'), 
		[BindModuleType] [tinyint]  NULL  DEFAULT ('0'), 
		[LeftBoxWidth] [int]  NOT NULL  DEFAULT ('0'), 
		[RightBoxWidth] [int]  NOT NULL  DEFAULT ('0'), 
		[Height] [int]  NOT NULL  DEFAULT ('0'), 
		[TreeTitle] [varchar] (200) NOT NULL , 
		[SearchIputDefaultText] [varchar] (200) NULL , 
		[TextFieldName1] [varchar] (200) NOT NULL , 
		[ValueFieldName1] [varchar] (200) NOT NULL , 
		[ParentFieldName1] [varchar] (200) NULL , 
		[IconUrlFieldName1] [varchar] (200) NULL , 
		[ExIconUrlFieldName1] [varchar] (200) NULL , 
		[UrlFieldName1] [varchar] (200) NULL , 
		[TopNode_ParentValue1] [varchar] (200) NULL , 
		[TreeNode_JSonClick1] [varchar] (200) NULL , 
		[Tree_Dynamic1] [bit]  NOT NULL  DEFAULT ('0'), 
		[UseCache1] [bit]  NOT NULL  DEFAULT ('0'), 
		[TextFieldName2] [varchar] (200) NOT NULL , 
		[ValueFieldName2] [varchar] (200) NOT NULL , 
		[ParentFieldName2] [varchar] (200) NULL , 
		[IconUrlFieldName2] [varchar] (200) NULL , 
		[ExIconUrlFieldName2] [varchar] (200) NULL , 
		[UrlFieldName2] [varchar] (200) NULL , 
		[TopNode_ParentValue2] [varchar] (200) NULL , 
		[TreeNode_JSonClick2] [varchar] (200) NULL , 
		[Tree_Dynamic2] [bit]  NOT NULL  DEFAULT ('0'), 
		[UseCache2] [bit]  NOT NULL  DEFAULT ('0'), 
		[LinkFieldName] [varchar] (200) NULL , 
		[Right_ListBoxTitle] [varchar] (50) NULL  DEFAULT ('已选项'), 
		[AddAllAlertText] [varchar] (50) NULL  DEFAULT ('全部增加'), 
		[Right_Hidden] [bit]  NOT NULL  DEFAULT ('0'), 
		[AddAll_JSonClick] [varchar] (200) NULL , 
		[DoCallBack] [bit]  NOT NULL  DEFAULT ('1'), 
		[LeftDrag] [bit]  NOT NULL  DEFAULT ('0'), 
		[RightDrag] [bit]  NOT NULL  DEFAULT ('0'), 
		[LeftRightSpace_Width] [int]  NOT NULL  DEFAULT ('45'), 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditTime] [datetime]  NULL , 
		[Remark] [varchar] (100) NULL , 
		[SSystemId] [int]  NULL , 
		[STreeId] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_EntityTree] PRIMARY KEY CLUSTERED 
    ( 
       TreeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TreeCell_Run]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TreeCell_Run]( 
		[CellId] [int]  NOT NULL , 
		[SystemId] [int]  NULL  DEFAULT ('0'), 
		[TreeId] [int]  NOT NULL  DEFAULT ('1'), 
		[CellTypeId] [int]  NOT NULL  DEFAULT ('1'), 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[CellNo] [int]  NULL  DEFAULT ('0')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_User]( 
		[UserId] [int] IdENTITY(1,1)  NOT NULL , 
		[UserGuId] [uniqueidentifier]  NULL   DEFAULT (newid()), 
		[UserName] [varchar] (50) NOT NULL , 
		[UpperName] [varchar] (50) NULL , 
		[RealName] [varchar] (50) NULL , 
		[DcxUserName] [varchar] (50) NULL , 
		[Email] [varchar] (50) NOT NULL , 
		[Address] [varchar] (150) NULL , 
		[GroupId] [int]  NOT NULL  DEFAULT ('0'), 
		[AccountId] [int]  NULL  DEFAULT ('1'), 
		[IsAccountCreator] [bit]  NOT NULL  DEFAULT ('0'), 
		[CurSystemId] [int]  NULL  DEFAULT ('0'), 
		[EmployeeId] [int]  NULL , 
		[DeptId] [int]  NULL , 
		[PositionId] [int]  NULL  DEFAULT ('0'), 
		[SuperAdmin] [bit]  NULL  DEFAULT ('0'), 
		[CanLogin] [bit]  NULL  DEFAULT ('1'), 
		[IP] [varchar] (100) NULL , 
		[RestrictIp] [bit]  NOT NULL  DEFAULT ('0'), 
		[VisitTime] [int]  NULL  DEFAULT ('0'), 
		[Online] [bit]  NULL  DEFAULT ('0'), 
		[PWD] [varchar] (100) NOT NULL , 
		[LoginDate] [datetime]  NULL  DEFAULT ('0'), 
		[UserOrder] [int]  NULL , 
		[Sex] [varchar] (50) NULL , 
		[Telephone] [varchar] (50) NULL , 
		[Status] [varchar] (50) NULL , 
		[RegistedDate] [datetime]  NULL , 
		[Phone] [varchar] (50) NULL , 
		[Birthday] [datetime]  NULL , 
		[Style] [int]  NULL  DEFAULT ('1'), 
		[IsNeedKey] [bit]  NULL  DEFAULT ('0'), 
		[Caste] [int]  NULL  DEFAULT ('0'), 
		[Http] [varchar] (100) NULL , 
		[IconPath] [varchar] (200) NULL , 
		[CreatorId] [int]  NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL  DEFAULT (getdate()), 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[SelftHomePage] [bit]  NULL  DEFAULT ('0'), 
		[SelftNavMenu] [bit]  NULL  DEFAULT ('0'), 
		[SelftSearch] [bit]  NULL  DEFAULT ('0'), 
		[StyleId] [int]  NULL  DEFAULT ('0'), 
		[AcceptStrangerIM] [bit]  NULL , 
		[Remark] [varchar] (max) NULL , 
		[DiskSize] [int]  NULL , 
		[InviteCode] [varchar] (100) NULL , 
		[TopMenuId] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_FZET_USER] PRIMARY KEY CLUSTERED 
    ( 
       UserId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserApply]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserApply]( 
		[ApplyId] [int] IdENTITY(1,1)  NOT NULL , 
		[CompanyName] [varchar] (50) NULL , 
		[RealName] [varchar] (50) NULL , 
		[Email] [varchar] (50) NOT NULL , 
		[Trade] [varchar] (50) NULL , 
		[CompanyUrl] [varchar] (100) NULL , 
		[Telephone] [varchar] (50) NULL , 
		[QQ] [varchar] (50) NULL , 
		[Province] [varchar] (100) NULL , 
		[Phone] [varchar] (50) NULL , 
		[VersionId] [int]  NULL  DEFAULT ('1'), 
		[IsAgree] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsApprove] [bit]  NOT NULL  DEFAULT ('0'), 
		[ApproverId] [int]  NULL , 
		[ApproveTime] [datetime]  NULL , 
		[Ip] [varchar] (30) NULL , 
		[MAC] [varchar] (30) NULL , 
		[Region] [varchar] (200) NULL , 
		[CreatorId] [int]  NOT NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NOT NULL , 
		[CreateTime] [datetime]  NOT NULL  DEFAULT (getdate()), 
		[EditorId] [int]  NULL  DEFAULT ('0'), 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[Remark] [varchar] (200) NULL    , 
    CONSTRAINT [PK_Dcx_UserApply] PRIMARY KEY CLUSTERED 
    ( 
       ApplyId DESC 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserGroup]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserGroup]( 
		[GroupId] [int] IdENTITY(1,1)  NOT NULL , 
		[GroupName] [varchar] (50) NOT NULL , 
		[IsSystem] [bit]  NOT NULL  DEFAULT ('0'), 
		[Remark] [varchar] (100) NULL    , 
    CONSTRAINT [PK_FZET_UserGroup] PRIMARY KEY CLUSTERED 
    ( 
       GroupId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInAccount]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInAccount]( 
		[AccountUserId] [int] IdENTITY(1,1)  NOT NULL , 
		[AccountId] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[IsMainUser] [bit]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_UserInAccount] PRIMARY KEY CLUSTERED 
    ( 
       AccountUserId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInDept]( 
		[UserDeptId] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[DeptId] [int]  NOT NULL , 
		[EmployeeId] [int]  NULL    , 
    CONSTRAINT [PK_FZET_UserInDept] PRIMARY KEY NONCLUSTERED 
    ( 
       UserDeptId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInGroup]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInGroup]( 
		[UserId] [int]  NOT NULL , 
		[Team_Id] [int]  NULL , 
		[Member_Type] [int]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInPosition]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInPosition]( 
		[UserId] [int]  NULL , 
		[PositionId] [int]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInRole]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInRole]( 
		[UserRoleId] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[RoleId] [int]  NOT NULL , 
		[IsMainRole] [bit]  NULL  DEFAULT ('1'), 
		[UserName] [varchar] (50) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_UserInRole_UserRoleId] PRIMARY KEY NONCLUSTERED 
    ( 
       UserRoleId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInSystem]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInSystem]( 
		[SystemUserId] [int] IdENTITY(1,1)  NOT NULL , 
		[SystemId] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[IsDefault] [bit]  NULL  DEFAULT ('0')   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInvite]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserInvite]( 
		[InviteId] [int] IdENTITY(1,1)  NOT NULL , 
		[InviteId2] [int]  NULL , 
		[InviteCode] [varchar] (50) NOT NULL , 
		[Email] [varchar] (50) NOT NULL , 
		[RealName] [varchar] (50) NOT NULL , 
		[CompanyName] [varchar] (100) NULL , 
		[CompanyUrl] [varchar] (100) NULL , 
		[QQ] [varchar] (50) NULL , 
		[VersionId] [int]  NOT NULL  DEFAULT ('1'), 
		[VersionName] [varchar] (50) NULL , 
		[Phone] [varchar] (50) NULL , 
		[Trade] [varchar] (50) NULL , 
		[TradeId] [int]  NULL  DEFAULT ('1'), 
		[IsCancel] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsRegister] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsOk] [bit]  NULL , 
		[BuyTime] [datetime]  NULL , 
		[BeginTime] [datetime]  NULL , 
		[EndTime] [datetime]  NULL , 
		[RegisterDate] [datetime]  NULL , 
		[Ip] [varchar] (30) NULL , 
		[MAC] [varchar] (30) NULL , 
		[Region] [varchar] (200) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[CreatorId] [int]  NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NOT NULL  DEFAULT (getdate()), 
		[EditorId] [int]  NULL , 
		[Editor] [varchar] (50) NULL , 
		[EditTime] [datetime]  NULL  DEFAULT (getdate()), 
		[Apps] [varchar] (200) NULL , 
		[Remark] [varchar] (200) NULL    , 
    CONSTRAINT [PK_Dcx_UserInvite] PRIMARY KEY CLUSTERED 
    ( 
       InviteId DESC 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserVerify]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserVerify]( 
		[GuidCode] [uniqueidentifier]  NOT NULL   DEFAULT (newid()), 
		[UserId] [int]  NOT NULL , 
		[AccountId] [int]  NOT NULL , 
		[CreateDate] [datetime]  NOT NULL , 
		[VerifyDate] [datetime]  NULL , 
		[State] [bit]  NOT NULL  DEFAULT ('0'), 
		[EmailIsSend] [bit]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_UserVerify] PRIMARY KEY CLUSTERED 
    ( 
       GuidCode 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Video]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Video]( 
		[VideoId] [int] IdENTITY(1,1)  NOT NULL , 
		[VideoName] [varchar] (50) NOT NULL , 
		[VideoImg] [varchar] (200) NOT NULL , 
		[VideoUrl] [varchar] (200) NOT NULL , 
		[Subtitle] [varchar] (200) NULL , 
		[Tags] [varchar] (200) NULL , 
		[TopTypeId] [int]  NOT NULL  DEFAULT ('0'), 
		[TypeId] [int]  NOT NULL , 
		[Minute] [int]  NOT NULL  DEFAULT ('0'), 
		[SortOrder] [int]  NULL , 
		[PlayTimes] [int]  NULL  DEFAULT ('0'), 
		[LastPlayDate] [datetime]  NULL , 
		[IsPopular] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[CreateTime] [datetime]  NULL , 
		[Creator] [varchar] (50) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[EditTime] [datetime]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditorId] [int]  NULL , 
		[Remark] [varchar] (500) NULL    , 
    CONSTRAINT [PK_VL_Video] PRIMARY KEY NONCLUSTERED 
    ( 
       VideoId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_VideoType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_VideoType]( 
		[TypeId] [int] IdENTITY(1,1)  NOT NULL , 
		[TypeName] [varchar] (100) NOT NULL , 
		[TypeNameEn] [varchar] (100) NULL , 
		[SortOrder] [int]  NOT NULL , 
		[ImgPath] [varchar] (500) NULL , 
		[ParentId] [int]  NOT NULL  DEFAULT ('0'), 
		[GroupId] [tinyint]  NOT NULL  DEFAULT ('0'), 
		[GroupName] [varchar] (50) NULL    , 
    CONSTRAINT [PK_Dcx_VideoType] PRIMARY KEY NONCLUSTERED 
    ( 
       TypeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_VideoTypeGroup]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_VideoTypeGroup]( 
		[GroupId] [tinyint]  NOT NULL , 
		[GroupName] [varchar] (50) NULL    , 
    CONSTRAINT [PK_Dcx_VideoTypeGroup] PRIMARY KEY CLUSTERED 
    ( 
       GroupId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBo]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WeiBo]( 
		[WId] [int] IdENTITY(1,1)  NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (50) NOT NULL , 
		[CreateDate] [datetime]  NOT NULL , 
		[IsPublic] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[ColorId] [tinyint]  NULL , 
		[TypeId] [int]  NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[TagName] [varchar] (50) NULL , 
		[HasFile] [bit]  NOT NULL  DEFAULT ('0'), 
		[FileJson] [varchar] (max) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_WeiBo] PRIMARY KEY NONCLUSTERED 
    ( 
       WId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBoFile]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WeiBoFile]( 
		[FileId] [int] IdENTITY(1,1)  NOT NULL , 
		[FilePath] [varchar] (500) NULL , 
		[FileName] [varchar] (300) NULL , 
		[FileExt] [varchar] (50) NULL , 
		[FileTypeId] [smallint]  NULL , 
		[FileSize] [int]  NULL , 
		[DownLoadTimes] [int]  NULL  DEFAULT ('0'), 
		[CreatorId] [int]  NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[WId] [int]  NULL    , 
    CONSTRAINT [PK_Dcx_DocumentPublic] PRIMARY KEY NONCLUSTERED 
    ( 
       FileId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetter]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WLetter]( 
		[LId] [int] IdENTITY(1,1)  NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[SenderDelete] [bit]  NULL , 
		[ReceiverUserIds] [varchar] (max) NULL , 
		[ReceiverUserNames] [varchar] (max) NULL , 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[ColorId] [tinyint]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_WLetter] PRIMARY KEY NONCLUSTERED 
    ( 
       LId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterRcv]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WLetterRcv]( 
		[RcvId] [int] IdENTITY(1,1)  NOT NULL , 
		[LId] [int]  NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[ReceiverId] [int]  NOT NULL , 
		[ReceiverName] [varchar] (50) NULL , 
		[ReadTime] [datetime]  NULL , 
		[IsPublic] [bit]  NULL  DEFAULT ('0'), 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsRead] [bit]  NULL  DEFAULT ('0'), 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[ColorId] [tinyint]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_WLetterRcv] PRIMARY KEY NONCLUSTERED 
    ( 
       RcvId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterReply]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WLetterReply]( 
		[ReplyId] [int] IdENTITY(1,1)  NOT NULL , 
		[SnederId] [int]  NOT NULL , 
		[LId] [int]  NOT NULL , 
		[ReplyContent] [varchar] (200) NOT NULL , 
		[ReplyTime] [datetime]  NULL , 
		[ReadTime] [datetime]  NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_WLetterReply] PRIMARY KEY NONCLUSTERED 
    ( 
       ReplyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMail]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WMail]( 
		[MId] [int] IdENTITY(1,1)  NOT NULL , 
		[Title] [varchar] (500) NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[SenderDelete] [bit]  NULL , 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[ColorId] [tinyint]  NULL , 
		[ReceiverUserIds] [varchar] (1000) NULL , 
		[ReceiverUserNames] [varchar] (1000) NULL , 
		[MeetReceipt] [bit]  NULL , 
		[HaveAttachment] [bit]  NULL  DEFAULT ('0'), 
		[FileJson] [varchar] (max) NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[EntName] [varchar] (50) NULL , 
		[MenuId] [int]  NOT NULL  DEFAULT ('0'), 
		[KeyFieldValue] [varchar] (50) NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_WMail] PRIMARY KEY NONCLUSTERED 
    ( 
       MId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailRcv]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WMailRcv]( 
		[RcvId] [int] IdENTITY(1,1)  NOT NULL , 
		[MId] [int]  NOT NULL , 
		[Title] [varchar] (500) NOT NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[ReceiverId] [int]  NOT NULL , 
		[ReceiverName] [varchar] (50) NULL , 
		[ReadTime] [datetime]  NULL , 
		[IsPublic] [bit]  NULL  DEFAULT ('0'), 
		[IsCollect] [bit]  NULL , 
		[IsTop] [bit]  NOT NULL  DEFAULT ('0'), 
		[IsRead] [bit]  NULL  DEFAULT ('0'), 
		[SenderId] [int]  NOT NULL , 
		[SenderName] [varchar] (50) NULL , 
		[SentDate] [datetime]  NOT NULL , 
		[ColorId] [tinyint]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[EntName] [varchar] (50) NULL , 
		[MenuId] [int]  NOT NULL  DEFAULT ('0'), 
		[KeyFieldValue] [varchar] (50) NULL , 
		[TagId] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_Dcx_WMailRcv] PRIMARY KEY NONCLUSTERED 
    ( 
       RcvId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailReply]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_WMailReply]( 
		[ReplyId] [int] IdENTITY(1,1)  NOT NULL , 
		[SnederId] [int]  NOT NULL , 
		[MId] [int]  NOT NULL , 
		[ReplyContent] [varchar] (200) NOT NULL , 
		[ReplyTime] [datetime]  NULL , 
		[ReadTime] [datetime]  NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[ParentId] [int]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_WMailReply] PRIMARY KEY NONCLUSTERED 
    ( 
       ReplyId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[ERP_客户资料]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[ERP_客户资料]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[客户编号] [varchar] (50) NULL , 
		[客户名称助记码] [varchar] (50) NULL , 
		[客户名称] [varchar] (50) NULL , 
		[客户简称] [varchar] (50) NULL , 
		[业务关系] [varchar] (50) NULL  DEFAULT ('直销客户'), 
		[所属地区] [varchar] (50) NULL , 
		[地址] [varchar] (50) NULL , 
		[电话] [varchar] (50) NULL , 
		[代理商] [varchar] (50) NULL , 
		[QQ号码] [varchar] (50) NULL , 
		[邮件] [varchar] (50) NULL , 
		[主页] [varchar] (50) NULL , 
		[联系人] [varchar] (50) NULL , 
		[预收款] [money]  NULL  DEFAULT ('0'), 
		[应收款] [money]  NULL  DEFAULT ('0'), 
		[余额] [money]  NULL , 
		[累计已收金额] [money]  NULL  DEFAULT ('0'), 
		[累计应收金额] [money]  NULL  DEFAULT ('0'), 
		[累计退款金额] [money]  NULL  DEFAULT ('0'), 
		[期初已收] [money]  NULL  DEFAULT ('0'), 
		[期初余额] [money]  NULL  DEFAULT ('0'), 
		[资信额] [money]  NULL  DEFAULT ('0'), 
		[跟进人员] [varchar] (50) NULL , 
		[父级客户] [varchar] (50) NULL , 
		[父级客户编号] [varchar] (50) NULL , 
		[主联系人] [varchar] (50) NULL , 
		[主联系人编号] [varchar] (50) NULL , 
		[主营行业] [varchar] (50) NULL , 
		[客户来源] [varchar] (50) NULL , 
		[客户级别] [varchar] (50) NULL , 
		[客户类型] [varchar] (50) NULL , 
		[客户状态] [varchar] (50) NULL , 
		[最近联系日期] [datetime]  NULL , 
		[创建日期] [datetime]  NULL , 
		[最后更改日期] [datetime]  NULL , 
		[创建者] [varchar] (50) NULL , 
		[所属用户] [varchar] (50) NULL , 
		[所属部门] [varchar] (50) NULL , 
		[所属部门编号] [varchar] (50) NULL , 
		[企业简介] [varchar] (max) NULL , 
		[备注] [text]  NULL , 
		[是否已删除] [bit]  NULL  DEFAULT ('0'), 
		[公司规模] [varchar] (50) NULL , 
		[付款方式] [varchar] (50) NULL , 
		[付款方式Id] [varchar] (50) NULL , 
		[发货地址] [varchar] (200) NULL , 
		[开户银行] [varchar] (50) NULL , 
		[银行帐号] [varchar] (50) NULL , 
		[员工人数] [int]  NULL , 
		[推荐人] [varchar] (50) NULL , 
		[国家] [varchar] (50) NULL , 
		[最近购买日期] [datetime]  NULL , 
		[下次联系时间] [datetime]  NULL , 
		[最近回访日期] [datetime]  NULL , 
		[最近进货日期] [datetime]  NULL , 
		[最近退货日期] [datetime]  NULL , 
		[省份] [varchar] (50) NULL , 
		[联系周期] [varchar] (50) NULL    , 
    CONSTRAINT [PK_ERP_客户资料] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanWriteField]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_CanWriteField]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL , 
		[NodeId] [int]  NOT NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (100) NULL , 
		[FldId] [int]  NULL , 
		[FieldName] [varchar] (100) NULL , 
		[CtrlByName] [varchar] (100) NULL , 
		[FlowName] [varchar] (100) NULL , 
		[TypeId] [tinyint]  NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_FZET_Flow_CanWriteField] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CurrentStep]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_CurrentStep]( 
		[cur_id] [int] IdENTITY(1,1)  NOT NULL , 
		[run_pid] [int]  NOT NULL , 
		[run_id] [int]  NOT NULL , 
		[run_name] [varchar] (200) NULL , 
		[prcs_id] [int]  NOT NULL , 
		[prcs_name] [varchar] (200) NULL , 
		[user_id] [int]  NULL , 
		[deal_ids] [varchar] (500) NULL , 
		[prcs_time] [datetime]  NULL , 
		[deliver_time] [datetime]  NULL , 
		[prcs_flag] [int]  NOT NULL  DEFAULT ('1'), 
		[next_prcsId] [int]  NULL , 
		[Parent_id] [int]  NULL , 
		[firstMan_flag] [int]  NOT NULL  DEFAULT ('0'), 
		[step] [int]  NULL , 
		[firstStep_flag] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Fzet_Flow_CurrentStep] PRIMARY KEY CLUSTERED 
    ( 
       cur_id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_Depute]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_Depute]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (200) NULL , 
		[RunId] [int]  NULL , 
		[RunName] [varchar] (200) NULL , 
		[PrcsId] [int]  NULL , 
		[PrcsName] [varchar] (200) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[CreatorId] [int]  NULL , 
		[CreatorUserName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[NoteType] [varchar] (50) NULL , 
		[NoteContent] [varchar] (max) NULL    , 
    CONSTRAINT [PK_WF_Depute] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowDepute]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowDepute]( 
		[Id] [int]  NOT NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (200) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[CreatorId] [int]  NULL , 
		[CreatorUserName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[StartDate] [datetime]  NULL , 
		[EndDate] [datetime]  NULL , 
		[IsClose] [bit]  NOT NULL  DEFAULT ('1'), 
		[IsAlways] [bit]  NULL , 
		[SupportAllFlow] [bit]  NULL , 
		[NoteType] [tinyint]  NULL , 
		[NoteContent] [varchar] (max) NULL    , 
    CONSTRAINT [PK_WF_FlowDepute] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNode]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowNode]( 
		[NodeId] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL , 
		[NodeName] [varchar] (200) NULL , 
		[Step] [int]  NOT NULL , 
		[PrcsUsers] [varchar] (max) NULL , 
		[PrcsDepts] [varchar] (max) NULL , 
		[PrcsPositions] [varchar] (max) NULL , 
		[PrcsRoles] [varchar] (max) NULL , 
		[PrcsTo] [varchar] (500) NULL , 
		[AllowLastNodeBoss] [bit]  NULL  DEFAULT ('0'), 
		[AllowWorkCreator] [bit]  NULL  DEFAULT ('0'), 
		[NextNames] [varchar] (1000) NULL , 
		[PrcsUserNames] [varchar] (max) NULL , 
		[PrcsDeptNames] [varchar] (max) NULL , 
		[PrcsRoleNames] [varchar] (max) NULL , 
		[PrcsPositionNames] [varchar] (max) NULL , 
		[TriggerBefore] [varchar] (max) NULL , 
		[TriggerAfter] [varchar] (max) NULL , 
		[CanReject] [bit]  NULL  DEFAULT ('0'), 
		[CanPigeonhole] [bit]  NULL  DEFAULT ('0'), 
		[PigeonholedSQL] [varchar] (max) NULL , 
		[Pointx] [int]  NULL , 
		[Pointy] [int]  NULL , 
		[Width] [int]  NULL , 
		[Height] [int]  NULL , 
		[NodeType] [tinyint]  NULL , 
		[ApproveType] [tinyint]  NULL , 
		[ToNextType] [tinyint]  NULL , 
		[ArriveType] [tinyint]  NULL , 
		[NotifyMode] [varchar] (80) NULL , 
		[NotifyType] [varchar] (80) NULL , 
		[NotifyContent] [varchar] (300) NULL , 
		[TurnFlowId] [int]  NULL , 
		[PrcsItem] [varchar] (max) NULL , 
		[PrcsItem2] [varchar] (max) NULL , 
		[Json_Validate] [varchar] (max) NULL , 
		[EntId] [int]  NULL , 
		[PositionDept] [varchar] (50) NULL , 
		[PositionDeptNames] [varchar] (1000) NULL , 
		[CountersignType] [tinyint]  NULL , 
		[CountersignVisType] [tinyint]  NULL , 
		[DeliverType] [tinyint]  NULL , 
		[CanCircularize] [bit]  NULL  DEFAULT ('0'), 
		[MainUserType] [tinyint]  NULL  DEFAULT ('0'), 
		[FilterUserType] [tinyint]  NULL  DEFAULT ('0'), 
		[AutoSelectUserType] [tinyint]  NULL  DEFAULT ('0'), 
		[RebutType] [tinyint]  NULL  DEFAULT ('0'), 
		[LimitHour] [int]  NULL  DEFAULT ('0'), 
		[CountTimeType] [tinyint]  NULL  DEFAULT ('0'), 
		[CanSetLimitHour] [bit]  NULL  DEFAULT ('0'), 
		[OnlyCountWorkTime] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_hyoa_flow_process] PRIMARY KEY NONCLUSTERED 
    ( 
       NodeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodePrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowNodePrivilege]( 
		[PrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL  DEFAULT ('-1'), 
		[NodeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[ObjectId] [int]  NOT NULL , 
		[ObjectName] [varchar] (50) NULL , 
		[IdType] [tinyint]  NOT NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_WF_FlowNodePrivilege] PRIMARY KEY NONCLUSTERED 
    ( 
       PrivilegeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowOperateLog]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (25) NOT NULL , 
		[RunId] [int]  NULL , 
		[RunName] [varchar] (100) NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (100) NULL , 
		[PrcsId] [int]  NULL , 
		[PrcsName] [varchar] (200) NULL , 
		[OperateType] [tinyint]  NULL , 
		[OperateTime] [datetime]  NULL , 
		[Ip] [varchar] (30) NULL , 
		[MAC] [varchar] (30) NULL , 
		[IsSucceeded] [bit]  NULL , 
		[Remark] [varchar] (max) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRun]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRun]( 
		[RunId] [int] IdENTITY(1,1)  NOT NULL , 
		[RunName] [varchar] (200) NOT NULL , 
		[FlowId] [int]  NOT NULL , 
		[FlowName] [varchar] (200) NULL , 
		[AttachmentId] [varchar] (200) NULL , 
		[AttachmentName] [varchar] (max) NULL , 
		[HtmlStr] [varchar] (max) NULL , 
		[FlowLsh] [varchar] (500) NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[FinishFlag] [tinyint]  NULL  DEFAULT ('1'), 
		[FormItems] [varchar] (8000) NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (500) NULL , 
		[DbTableName] [varchar] (100) NULL , 
		[KeyField] [varchar] (500) NULL , 
		[KeyFieldValue] [varchar] (100) NULL , 
		[Feedback] [varchar] (max) NULL , 
		[Feedback2] [varchar] (max) NULL , 
		[IsFreeFlow] [bit]  NULL , 
		[IsPause] [bit]  NULL , 
		[IsClose] [bit]  NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreateTime] [datetime]  NOT NULL , 
		[EditorId] [int]  NULL , 
		[EditTime] [datetime]  NULL , 
		[CreatorBoss] [varchar] (100) NULL , 
		[PauseUserId] [int]  NULL , 
		[PauseUserName] [varchar] (100) NULL , 
		[PauseDate] [datetime]  NULL , 
		[CancelPauseDate] [datetime]  NULL , 
		[RecoverUserId] [int]  NULL , 
		[RecoverUserName] [varchar] (100) NULL , 
		[RecoverDate] [datetime]  NULL , 
		[DeleteUserId] [int]  NULL , 
		[DeleteUserName] [varchar] (100) NULL , 
		[DeleteDate] [datetime]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_hyoa_flow_run] PRIMARY KEY NONCLUSTERED 
    ( 
       RunId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunAttention]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunAttention]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (200) NULL , 
		[RunId] [int]  NULL , 
		[RunName] [varchar] (200) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (200) NULL , 
		[CreateDate] [datetime]  NULL , 
		[Remark] [varchar] (max) NULL    , 
    CONSTRAINT [PK_WF_FlowAttention] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunCollect]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunCollect]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (200) NULL , 
		[RunId] [int]  NULL , 
		[RunName] [varchar] (200) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (200) NULL , 
		[CreateDate] [datetime]  NULL , 
		[Remark] [varchar] (max) NULL    , 
    CONSTRAINT [PK_WF_FlowCollect] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunFeedback]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunFeedback]( 
		[RunId] [int]  NOT NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (50) NULL , 
		[TheContent] [text]  NULL , 
		[AttachmentId] [text]  NULL , 
		[AttachmentName] [text]  NULL , 
		[EditTime] [datetime]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunFile]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunFile]( 
		[FileId] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL , 
		[RunId] [int]  NOT NULL , 
		[PrcsId] [int]  NULL , 
		[FilePath] [varchar] (500) NULL , 
		[FileName] [varchar] (300) NULL , 
		[FileTypeId] [smallint]  NULL , 
		[FileSize] [int]  NULL , 
		[CreatorId] [int]  NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[DownLoadTimes] [int]  NULL    , 
    CONSTRAINT [PK_WF_FlowRunFile] PRIMARY KEY NONCLUSTERED 
    ( 
       FileId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunHsty]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunHsty]( 
		[MsgId] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL , 
		[RunId] [int]  NOT NULL , 
		[PrcsId] [int]  NOT NULL , 
		[NodeId] [int]  NULL , 
		[MsgContent] [varchar] (max) NOT NULL , 
		[CreatorId] [int]  NOT NULL , 
		[CreatorName] [varchar] (70) NOT NULL , 
		[CreateDate] [datetime]  NOT NULL , 
		[PrcsName] [varchar] (100) NOT NULL , 
		[KeyFieldValue] [varchar] (50) NULL , 
		[EntId] [int]  NOT NULL  DEFAULT ('0'), 
		[EntName] [varchar] (50) NULL , 
		[MenuId] [int]  NULL , 
		[FileJson] [varchar] (max) NULL , 
		[OpType] [smallint]  NOT NULL  DEFAULT ('1'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_WF_FlowRunHsty] PRIMARY KEY NONCLUSTERED 
    ( 
       MsgId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcs]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunPrcs]( 
		[PrcsId] [int] IdENTITY(1,1)  NOT NULL , 
		[RunId] [int]  NOT NULL , 
		[RunName] [varchar] (100) NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (100) NULL , 
		[NodeId] [int]  NOT NULL , 
		[PrcsName] [varchar] (100) NULL , 
		[MainUserId] [int]  NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (30) NULL , 
		[DealIds] [varchar] (500) NULL , 
		[AcceptTime] [datetime]  NULL , 
		[PrcsTime] [datetime]  NULL , 
		[DeliverTime] [datetime]  NULL , 
		[DeadTime] [datetime]  NULL , 
		[PrcsFlag] [tinyint]  NOT NULL  DEFAULT ('1'), 
		[NextPrcsId] [int]  NULL , 
		[ParentId] [int]  NULL , 
		[FirstManFlag] [bit]  NOT NULL  DEFAULT ('0'), 
		[Step] [int]  NULL , 
		[FirstStepFlag] [bit]  NULL  DEFAULT ('0'), 
		[IsRebut] [bit]  NULL  DEFAULT ('0'), 
		[PrcsStep] [int]  NULL , 
		[PrcsUsers] [varchar] (1000) NULL , 
		[PrcsRoles] [varchar] (1000) NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (500) NULL , 
		[TransactorS] [varchar] (max) NULL , 
		[WorkCreatorId] [int]  NULL , 
		[Pointx] [int]  NULL , 
		[Pointy] [int]  NULL , 
		[NodeType] [tinyint]  NULL , 
		[ApproveType] [tinyint]  NULL , 
		[ToNextType] [tinyint]  NULL , 
		[ArriveType] [tinyint]  NULL , 
		[NotifyMode] [varchar] (80) NULL , 
		[NotifyType] [varchar] (80) NULL , 
		[NotifyContent] [varchar] (300) NULL , 
		[TurnFlowId] [int]  NULL , 
		[TurnFlowRunId] [int]  NULL , 
		[Feedback] [varchar] (max) NULL , 
		[CreatorBoss] [varchar] (100) NULL , 
		[PositionDept] [varchar] (50) NULL , 
		[Creator] [int]  NULL  DEFAULT ('0'), 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_hyoa_flow_run_prcs] PRIMARY KEY NONCLUSTERED 
    ( 
       PrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcsHistory]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunPrcsHistory]( 
		[PrcsId] [int]  NOT NULL , 
		[RunId] [int]  NOT NULL , 
		[RunName] [varchar] (200) NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (500) NULL , 
		[NodeId] [int]  NOT NULL , 
		[PrcsName] [varchar] (200) NULL , 
		[UserId] [int]  NULL , 
		[UserName] [varchar] (100) NULL , 
		[DealIds] [varchar] (500) NULL , 
		[PrcsTime] [datetime]  NULL , 
		[DeliverTime] [datetime]  NULL , 
		[PrcsFlag] [int]  NOT NULL  DEFAULT ('1'), 
		[NextPrcsId] [int]  NULL , 
		[ParentId] [int]  NULL , 
		[FirstManFlag] [int]  NOT NULL  DEFAULT ('0'), 
		[Step] [int]  NULL , 
		[FirstStepFlag] [bit]  NULL  DEFAULT ('0'), 
		[PrcsStep] [int]  NULL , 
		[CreatorBoss] [varchar] (1000) NULL , 
		[PositionDept] [varchar] (50) NULL , 
		[Creator] [varchar] (50) NULL  DEFAULT ('0'), 
		[PrcsUsers] [varchar] (1000) NULL , 
		[PrcsRoles] [varchar] (1000) NULL , 
		[CreatorName] [varchar] (50) NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (500) NULL , 
		[TransactorS] [varchar] (max) NULL , 
		[WorkCreatorId] [int]  NULL , 
		[Pointx] [int]  NULL , 
		[Pointy] [int]  NULL , 
		[PrcsType] [varchar] (50) NULL , 
		[ApproveType] [int]  NULL , 
		[ToNextType] [int]  NULL , 
		[ArriveType] [int]  NULL , 
		[NotifyMode] [varchar] (80) NULL , 
		[NotifyType] [varchar] (80) NULL , 
		[NotifyContent] [varchar] (300) NULL , 
		[TurnFlowId] [int]  NULL , 
		[TurnFlowRunId] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_hyoa_flow_run_prcs_his] PRIMARY KEY CLUSTERED 
    ( 
       PrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcsPrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowRunPrcsPrivilege]( 
		[PrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[RunId] [int]  NOT NULL  DEFAULT ('-1'), 
		[PrcsId] [int]  NOT NULL  DEFAULT ('-1'), 
		[UserId] [int]  NOT NULL , 
		[IsMain] [bit]  NOT NULL , 
		[IsDeal] [bit]  NOT NULL    , 
    CONSTRAINT [PK_WF_FlowRunPrcsPrivilege] PRIMARY KEY NONCLUSTERED 
    ( 
       PrivilegeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowSort]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowSort]( 
		[SortId] [int] IdENTITY(1,1)  NOT NULL , 
		[SortNo] [int]  NOT NULL , 
		[SortName] [varchar] (200) NOT NULL , 
		[CreateTime] [datetime]  NULL , 
		[Creator] [varchar] (40) NULL , 
		[CreatorId] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_hyoa_flow_sort] PRIMARY KEY CLUSTERED 
    ( 
       SortId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowType]( 
		[FlowId] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowName] [varchar] (200) NOT NULL , 
		[FlowNo] [int]  NOT NULL , 
		[SortId] [int]  NOT NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (200) NULL , 
		[AutoName] [varchar] (200) NULL , 
		[ManageUsers] [varchar] (max) NULL , 
		[ManageNames] [varchar] (max) NULL , 
		[QueryUsers] [varchar] (max) NULL , 
		[QueryNames] [varchar] (max) NULL , 
		[CanQueryRoles] [varchar] (max) NULL , 
		[CanQueryRolesId] [varchar] (max) NULL , 
		[CanManageRoles] [varchar] (max) NULL , 
		[CanManageRolesId] [varchar] (max) NULL , 
		[CanStartUsers] [varchar] (max) NULL , 
		[CanStartNames] [varchar] (max) NULL , 
		[CanStartRoles] [varchar] (max) NULL , 
		[CanStartRolesId] [varchar] (max) NULL , 
		[AttachMaxSize] [int]  NULL , 
		[FlowAttach] [int]  NULL , 
		[IsPigeonhole] [bit]  NULL  DEFAULT ('0'), 
		[PigeonholedSQL] [varchar] (max) NULL , 
		[IsFreeFlow] [bit]  NULL , 
		[QueryItem] [varchar] (max) NULL , 
		[LaunchIsOpen] [bit]  NULL  DEFAULT ('0'), 
		[FormUrl] [varchar] (300) NULL , 
		[BrowseUrl] [varchar] (300) NULL , 
		[ListUrl] [varchar] (300) NULL , 
		[Detail] [varchar] (max) NULL , 
		[CreatorId] [int]  NULL  DEFAULT ('0'), 
		[Creator] [varchar] (50) NULL , 
		[CreateTime] [datetime]  NULL , 
		[EditTime] [datetime]  NULL , 
		[Editor] [varchar] (40) NULL , 
		[EditorId] [int]  NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_hyoa_flow_type] PRIMARY KEY CLUSTERED 
    ( 
       FlowId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowTypePrivilege]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FlowTypePrivilege]( 
		[PrivilegeId] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL  DEFAULT ('-1'), 
		[ObjectId] [int]  NOT NULL , 
		[CanQuery] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanStart] [bit]  NOT NULL  DEFAULT ('0'), 
		[CanDesign] [bit]  NOT NULL  DEFAULT ('0'), 
		[CaMonitor] [bit]  NOT NULL  DEFAULT ('0'), 
		[IdType] [tinyint]  NOT NULL  DEFAULT ('0'), 
		[ObjectName] [varchar] (50) NULL , 
		[AccountId] [int]  NOT NULL  DEFAULT ('1')   , 
    CONSTRAINT [PK_WF_FlowTypePrivilege] PRIMARY KEY NONCLUSTERED 
    ( 
       PrivilegeId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FormSort]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FormSort]( 
		[SortId] [int] IdENTITY(1,1)  NOT NULL , 
		[SortNo] [int]  NOT NULL , 
		[SortName] [varchar] (200) NOT NULL    , 
    CONSTRAINT [PK_hyoa_form_sort] PRIMARY KEY CLUSTERED 
    ( 
       SortId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_FormType]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_FormType]( 
		[FormId] [int] IdENTITY(1,1)  NOT NULL , 
		[ItemStr] [varchar] (5000) NULL , 
		[ItemType] [varchar] (5000) NULL , 
		[FormName] [varchar] (50) NULL , 
		[HtmlStr] [text]  NULL , 
		[CreateTime] [datetime]  NULL , 
		[SortId] [int]  NULL , 
		[SortName] [varchar] (100) NULL , 
		[FormNo] [int]  NULL , 
		[FormDetail] [varchar] (5000) NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (100) NULL    , 
    CONSTRAINT [PK_hyoa_form_type] PRIMARY KEY CLUSTERED 
    ( 
       FormId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_NodeCondition]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_NodeCondition]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[NodeId] [int]  NOT NULL , 
		[NodeName] [varchar] (100) NULL , 
		[FlowId] [int]  NOT NULL , 
		[FlowName] [varchar] (100) NULL , 
		[InOutType] [varchar] (100) NULL , 
		[FieldName] [varchar] (100) NULL , 
		[ConditionRelation] [varchar] (100) NULL , 
		[CompareType] [varchar] (100) NULL , 
		[DataType] [varchar] (100) NULL , 
		[CompareValue] [varchar] (500) NULL , 
		[SQLExpression] [varchar] (1000) NULL , 
		[PromptContent] [varchar] (max) NULL    , 
    CONSTRAINT [PK_FZET_Flow_NodeCondition] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_Rebut]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_Rebut]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NOT NULL , 
		[FlowName] [varchar] (200) NULL , 
		[RunId] [int]  NOT NULL , 
		[RunName] [varchar] (200) NULL , 
		[PrcsId] [int]  NULL , 
		[PrcsName] [varchar] (200) NULL , 
		[RebutToPrcsId] [int]  NULL , 
		[RebutToPrcsName] [varchar] (200) NULL , 
		[CreatorId] [int]  NULL , 
		[CreatorUserName] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL , 
		[Remark] [varchar] (max) NULL , 
		[NoteType] [tinyint]  NULL , 
		[NoteContent] [varchar] (max) NULL    , 
    CONSTRAINT [PK_WF_Rebut] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_TakeBackPrcs]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_TakeBackPrcs]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[FlowId] [int]  NULL , 
		[FlowName] [varchar] (200) NULL , 
		[RunId] [int]  NULL , 
		[RunName] [varchar] (200) NULL , 
		[PrcsId] [int]  NULL , 
		[PrcsName] [varchar] (200) NULL , 
		[CreatorId] [int]  NULL , 
		[CreateDate] [datetime]  NULL , 
		[Remark] [varchar] (max) NULL    , 
    CONSTRAINT [PK_WF_TakeBackPrcs] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_YiJian]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[WF_YiJian]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Text] [varchar] (100) NULL , 
		[Value] [varchar] (100) NULL , 
		[OrderNo] [int]  NULL    , 
    CONSTRAINT [PK_WF_YiJian] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_公司信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_公司信息]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[公司编号] [varchar] (50) NULL , 
		[公司名称] [varchar] (50) NULL , 
		[添加日期] [varchar] (50) NULL , 
		[录入人员] [varchar] (50) NULL , 
		[启用日期] [varchar] (50) NULL , 
		[会计期间] [int]  NULL , 
		[年份] [int]  NULL , 
		[是否会计期初] [bit]  NULL , 
		[录入期初日期] [varchar] (50) NULL    , 
    CONSTRAINT [PK_财务_公司信息] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_供应商汇总表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_供应商汇总表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[供应商编号] [varchar] (50) NULL , 
		[供应商名称] [varchar] (50) NULL , 
		[期初应付款] [money]  NULL , 
		[付款币种] [varchar] (50) NULL , 
		[应付款] [money]  NULL  DEFAULT ('0'), 
		[预付款] [money]  NULL  DEFAULT ('0'), 
		[已付款] [money]  NULL  DEFAULT ('0'), 
		[欠款余额] [money]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_供应商汇总表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_供应商资料]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_供应商资料]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[供应商编号] [varchar] (25) NULL , 
		[供应商名称] [varchar] (40) NULL , 
		[供应商简称] [varchar] (40) NULL , 
		[电话号码] [varchar] (40) NULL , 
		[联系人] [varchar] (25) NULL , 
		[联系人电话] [varchar] (40) NULL , 
		[传真] [varchar] (25) NULL , 
		[企业类型] [varchar] (40) NULL , 
		[地区名称] [varchar] (40) NULL , 
		[企业代码] [varchar] (25) NULL , 
		[法人代表] [varchar] (25) NULL , 
		[类型编号] [varchar] (50) NULL , 
		[增值税号] [varchar] (25) NULL , 
		[通讯地址] [varchar] (60) NULL , 
		[电子邮件] [varchar] (40) NULL , 
		[网址] [varchar] (40) NULL , 
		[开户银行] [varchar] (40) NULL , 
		[银行账号] [varchar] (25) NULL , 
		[付款币种] [varchar] (50) NULL , 
		[期初余额] [money]  NULL  DEFAULT ('0'), 
		[应付款] [money]  NULL  DEFAULT ('0'), 
		[预付款] [money]  NULL  DEFAULT ('0'), 
		[已付款] [money]  NULL  DEFAULT ('0'), 
		[欠款余额] [money]  NULL  DEFAULT ('0'), 
		[已启用] [bit]  NULL  DEFAULT ('0'), 
		[备注] [text]  NULL    , 
    CONSTRAINT [PK_供应商资料] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_货品类别表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_货品类别表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[类型名称] [varchar] (100) NULL , 
		[数据表名] [varchar] (100) NULL , 
		[查询语句] [text]  NULL , 
		[编号字段] [varchar] (100) NULL , 
		[名称字段] [varchar] (100) NULL , 
		[查询条件] [text]  NULL    , 
    CONSTRAINT [PK_财务_货品类别表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_结算方式]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_结算方式]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[编号] [varchar] (50) NOT NULL , 
		[结算方式] [varchar] (50) NOT NULL , 
		[内部账号名称] [varchar] (50) NULL , 
		[默认内部账号] [varchar] (50) NULL    , 
    CONSTRAINT [PK_结算方式] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_内部账户信息表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_内部账户信息表]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[科目代码] [varchar] (30) NOT NULL , 
		[科目名称] [varchar] (30) NULL , 
		[账号] [varchar] (30) NOT NULL , 
		[账户名称] [varchar] (30) NULL , 
		[账户类型] [varchar] (12) NULL , 
		[余额方向] [varchar] (4) NULL , 
		[币种] [varchar] (12) NULL , 
		[开户日期] [varchar] (12) NULL , 
		[开户员工编号] [varchar] (4) NULL , 
		[用途] [varchar] (40) NULL , 
		[有明细帐] [bit]  NULL  DEFAULT ('0'), 
		[备注] [text]  NULL , 
		[期初金额] [money]  NULL  DEFAULT ('0'), 
		[余额] [money]  NULL  DEFAULT ('0'), 
		[已启用] [bit]  NULL  DEFAULT ('0'), 
		[编号] [varchar] (10) NULL , 
		[银行账户名称] [varchar] (40) NULL    , 
    CONSTRAINT [PK_内部帐户信息表] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_企业类别]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_企业类别]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[类别编号] [varchar] (50) NOT NULL , 
		[类别名称] [varchar] (50) NULL    , 
    CONSTRAINT [PK_财务_企业类别] PRIMARY KEY CLUSTERED 
    ( 
       类别编号 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_往来单位资料]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_往来单位资料]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[所属分公司编号] [varchar] (50) NULL , 
		[所属分公司名称] [varchar] (50) NULL , 
		[编码] [varchar] (25) NULL , 
		[单位名称] [varchar] (40) NULL , 
		[全称] [varchar] (40) NULL , 
		[往来类型] [varchar] (50) NULL , 
		[地区] [varchar] (40) NULL , 
		[电话号码] [varchar] (40) NULL , 
		[联系人] [varchar] (25) NULL , 
		[手机] [varchar] (40) NULL , 
		[传真] [varchar] (25) NULL , 
		[地址] [varchar] (100) NULL , 
		[电子邮件] [varchar] (40) NULL , 
		[网址] [varchar] (40) NULL , 
		[法人代表] [varchar] (25) NULL , 
		[纳税登记号] [varchar] (25) NULL , 
		[开户银行] [varchar] (40) NULL , 
		[银行账号] [varchar] (25) NULL , 
		[信用额度] [varchar] (50) NULL , 
		[信用期] [varchar] (50) NULL , 
		[期初余额] [money]  NULL  DEFAULT ('0'), 
		[应付款] [money]  NULL  DEFAULT ('0'), 
		[预付款] [money]  NULL  DEFAULT ('0'), 
		[已付款] [money]  NULL  DEFAULT ('0'), 
		[欠款余额] [money]  NULL  DEFAULT ('0'), 
		[已启用] [bit]  NULL  DEFAULT ('0'), 
		[备注] [varchar] (max) NULL    , 
    CONSTRAINT [PK_往来单位资料] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_往来管理表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_往来管理表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[往来类型] [varchar] (100) NULL , 
		[数据表名] [varchar] (100) NULL , 
		[查询语句] [text]  NULL , 
		[编号字段] [varchar] (100) NULL , 
		[名称字段] [varchar] (100) NULL , 
		[查询条件] [text]  NULL    , 
    CONSTRAINT [PK_系统_往来管理表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_业务相关]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_业务相关]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NULL , 
		[业务名称] [varchar] (50) NULL , 
		[业务表名] [varchar] (50) NOT NULL , 
		[编号字段] [varchar] (50) NOT NULL , 
		[字段类型] [varchar] (50) NULL , 
		[业务类型] [varchar] (50) NULL , 
		[keyfield] [varchar] (50) NULL , 
		[往来单位编号字段] [varchar] (50) NULL , 
		[往来单位名称字段] [varchar] (50) NULL , 
		[往来单位类型] [varchar] (50) NULL , 
		[往来单位查询语句] [varchar] (5000) NULL , 
		[货品编号字段] [varchar] (50) NULL , 
		[货品名称字段] [varchar] (50) NULL , 
		[货品类型] [varchar] (50) NULL , 
		[货品查询语句] [varchar] (5000) NULL , 
		[业务编号查询语句] [varchar] (5000) NULL , 
		[业务子表名] [varchar] (50) NULL , 
		[子表货品编号字段] [varchar] (50) NULL , 
		[子表货品名称字段] [varchar] (50) NULL , 
		[子表数量字段] [varchar] (50) NULL , 
		[子表金额字段] [varchar] (50) NULL , 
		[子表单价字段] [varchar] (50) NULL , 
		[子表税额字段] [varchar] (50) NULL , 
		[子表折扣率字段] [varchar] (50) NULL    , 
    CONSTRAINT [PK_财务_业务相关] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_银行账户信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_银行账户信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[编号] [varchar] (4) NOT NULL , 
		[开户银行] [varchar] (40) NULL , 
		[银行账号] [varchar] (30) NOT NULL , 
		[内部账号] [varchar] (16) NULL , 
		[内部账户名称] [varchar] (40) NULL , 
		[私户标志] [bit]  NULL , 
		[账户用途] [varchar] (40) NULL , 
		[开户日期] [varchar] (40) NULL , 
		[销户日期] [varchar] (40) NULL , 
		[管理员Id] [varchar] (4) NULL , 
		[管理员] [varchar] (16) NULL , 
		[备注] [text]  NULL    , 
    CONSTRAINT [PK_银行账户信息] PRIMARY KEY CLUSTERED 
    ( 
       编号 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_账套信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_账套信息]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[启用日期] [varchar] (50) NULL , 
		[启用月份] [int]  NULL , 
		[当前月份] [int]  NULL , 
		[当前年份] [int]  NULL , 
		[当前会计期间] [int]  NULL , 
		[总账的账套名称] [varchar] (50) NULL , 
		[审核与制单同一人] [bit]  NULL , 
		[审核后自动记账] [bit]  NULL , 
		[保存凭证同时审核] [bit]  NULL , 
		[本位币别] [varchar] (50) NULL , 
		[会计科目级数] [int]  NULL , 
		[账套是否已经年结] [bit]  NULL , 
		[本期开始日期] [varchar] (50) NULL , 
		[本期过账日期] [varchar] (50) NULL , 
		[上期年份] [int]  NULL , 
		[上期会计期间] [int]  NULL    , 
    CONSTRAINT [PK_财务_账套信息] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_账务授权]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_账务授权]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[用户名] [varchar] (50) NULL , 
		[分公司名称] [varchar] (50) NULL , 
		[分公司编号] [varchar] (50) NULL    , 
    CONSTRAINT [PK_财务_账务授权] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[财务_账务中心]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[财务_账务中心]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[EntId] [int]  NULL , 
		[业务名称] [varchar] (50) NULL , 
		[交易编号] [varchar] (20) NULL , 
		[业务表名] [varchar] (50) NOT NULL , 
		[业务编号] [varchar] (50) NOT NULL , 
		[编号字段] [varchar] (50) NOT NULL , 
		[字段类型] [varchar] (50) NULL , 
		[业务人员编号] [varchar] (50) NOT NULL , 
		[业务人员姓名] [varchar] (50) NOT NULL , 
		[所在部门编号] [varchar] (50) NOT NULL , 
		[所在部门名称] [varchar] (50) NOT NULL , 
		[交易人编号] [varchar] (50) NULL , 
		[交易人姓名] [varchar] (50) NULL , 
		[业务类型] [varchar] (50) NULL , 
		[发生日期] [varchar] (20) NULL , 
		[已入账] [bit]  NULL  DEFAULT ('0'), 
		[已完结] [bit]  NULL  DEFAULT ('0'), 
		[已审核] [bit]  NULL  DEFAULT ('1'), 
		[摘要] [varchar] (50) NULL , 
		[可入账] [bit]  NULL  DEFAULT ('1'), 
		[keyfield] [varchar] (50) NULL , 
		[keyfieldvalue] [varchar] (50) NULL , 
		[往来单位类型] [varchar] (50) NULL , 
		[往来单位编号] [varchar] (50) NULL , 
		[往来单位名称] [varchar] (50) NULL , 
		[交易金额] [money]  NULL , 
		[货品编号] [varchar] (30) NULL , 
		[货品名称] [varchar] (50) NULL , 
		[货品类型] [varchar] (20) NULL , 
		[账务Id] [uniqueidentifier]  NULL   DEFAULT (newid())   , 
    CONSTRAINT [PK_中间链接表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[参数表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[参数表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[参数类型] [varchar] (50) NOT NULL , 
		[参数文本值] [varchar] (50) NOT NULL , 
		[参数隐藏值] [varchar] (50) NULL , 
		[上级Id] [int]  NULL , 
		[上级文本值] [varchar] (500) NULL , 
		[参数文本值2] [varchar] (500) NULL , 
		[参数文本值3] [varchar] (500) NULL , 
		[参数文本值4] [varchar] (500) NULL , 
		[参数文本值5] [varchar] (500) NULL    , 
    CONSTRAINT [PK_参数表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工资_部门权限]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工资_部门权限]( 
		[Id] [int]  NULL , 
		[部门编号] [varchar] (50) NULL , 
		[部门名称] [varchar] (50) NULL , 
		[username] [varchar] (50) NULL , 
		[userId] [varchar] (50) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工资_地区信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工资_地区信息]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[地区名称] [varchar] (50) NULL    , 
    CONSTRAINT [PK_工资_地区信息] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工资_调动记录]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工资_调动记录]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[调动日期] [varchar] (50) NULL , 
		[调动前部门] [varchar] (50) NULL , 
		[调动后部门] [varchar] (50) NULL , 
		[原岗位级别] [varchar] (50) NULL , 
		[现岗位级别] [varchar] (50) NULL , 
		[原基本工资] [money]  NULL , 
		[现基本工资] [money]  NULL , 
		[原考核工资] [money]  NULL , 
		[现考核工资] [money]  NULL , 
		[说明] [text]  NULL    , 
    CONSTRAINT [PK_工资_调动记录] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工资_调薪记录]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工资_调薪记录]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[所在部门] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[调薪前基本工资] [money]  NULL , 
		[调薪前考核工资] [money]  NULL , 
		[调薪后考核工资] [money]  NULL , 
		[调薪后基本工资] [money]  NULL , 
		[调薪日期] [varchar] (50) NULL , 
		[说明] [text]  NULL , 
		[调薪前岗位] [varchar] (50) NULL , 
		[调薪后岗位] [varchar] (50) NULL    , 
    CONSTRAINT [PK_工资_调薪记录] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工资_岗位级别]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工资_岗位级别]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[岗位级别] [float]  NULL , 
		[年薪总额] [money]  NULL , 
		[月基本工资] [money]  NULL , 
		[月考核工资] [money]  NULL , 
		[年薪差额] [money]  NULL    , 
    CONSTRAINT [PK_工资_岗位级别] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工资_员工档案]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工资_员工档案]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (50) NOT NULL , 
		[员工姓名] [varchar] (50) NOT NULL , 
		[UserName] [varchar] (20) NULL , 
		[性别] [varchar] (50) NOT NULL , 
		[身份证号] [varchar] (50) NOT NULL , 
		[出生日期] [varchar] (50) NULL , 
		[DeptId] [int]  NULL , 
		[年龄] [int]  NULL , 
		[民族] [varchar] (50) NULL , 
		[籍贯] [varchar] (50) NULL , 
		[婚姻状况] [varchar] (50) NULL , 
		[政治面貌] [varchar] (50) NULL , 
		[公司] [varchar] (50) NULL , 
		[公司编号] [varchar] (50) NULL , 
		[部门编号] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[角色] [varchar] (50) NULL , 
		[岗位级别] [varchar] (50) NOT NULL , 
		[员工岗位] [varchar] (50) NULL , 
		[员工状态] [varchar] (50) NOT NULL , 
		[电子邮箱] [varchar] (70) NULL , 
		[联系电话] [varchar] (50) NULL , 
		[入职日期] [varchar] (50) NULL , 
		[入职年限] [int]  NULL , 
		[转正日期] [varchar] (50) NULL , 
		[离职日期] [varchar] (50) NULL , 
		[基本工资] [money]  NOT NULL  DEFAULT ('0'), 
		[月考核工资] [money]  NULL , 
		[试用期工资] [money]  NULL  DEFAULT ('0'), 
		[试用期月考核工资] [money]  NULL  DEFAULT ('0'), 
		[是否电脑补贴] [bit]  NULL  DEFAULT ('0'), 
		[电脑补贴金额] [money]  NULL  DEFAULT ('0'), 
		[是否相机补贴] [bit]  NULL  DEFAULT ('0'), 
		[相机补贴金额] [money]  NULL  DEFAULT ('0'), 
		[是否购买社保] [bit]  NULL  DEFAULT ('0'), 
		[购买社保金额] [money]  NULL  DEFAULT ('0'), 
		[是否个人公积金] [bit]  NULL  DEFAULT ('0'), 
		[个人公积金金额] [money]  NULL  DEFAULT ('0'), 
		[是否公司公积金] [bit]  NULL  DEFAULT ('0'), 
		[公司公积金金额] [money]  NULL  DEFAULT ('0'), 
		[公司购买社保金额] [money]  NULL , 
		[地区差补贴] [money]  NULL , 
		[社保购买所在地] [varchar] (200) NULL , 
		[银行帐号] [varchar] (50) NULL , 
		[签订合同] [varchar] (50) NULL , 
		[签订日期] [varchar] (50) NULL , 
		[合同到期日] [varchar] (50) NULL , 
		[合同期限] [int]  NULL , 
		[学历] [varchar] (50) NULL , 
		[毕业院校] [varchar] (200) NULL , 
		[毕业时间] [varchar] (50) NULL , 
		[专业] [varchar] (50) NULL , 
		[专长] [varchar] (50) NULL , 
		[取得资格证书名称] [varchar] (50) NULL , 
		[职称] [varchar] (50) NULL , 
		[保险期限] [varchar] (50) NULL , 
		[保险截止日期] [varchar] (50) NULL , 
		[身份证上地址] [varchar] (200) NULL , 
		[密码] [nchar] (200) NULL  DEFAULT (N'A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'), 
		[备注] [text]  NULL , 
		[员工头像] [image]  NULL , 
		[QQ号码] [varchar] (50) NULL , 
		[资质] [varchar] (50) NULL , 
		[经验] [int]  NULL , 
		[市场] [int]  NULL , 
		[专业技能] [int]  NULL , 
		[综合管理能力] [int]  NULL , 
		[绩效值] [int]  NULL , 
		[考核月数] [int]  NULL  DEFAULT ('0'), 
		[头像图片] [varchar] (200) NULL    , 
    CONSTRAINT [PK_工资_员工档案] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[基本数据表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[基本数据表]( 
		[Id卡号] [char] (10) NOT NULL , 
		[职工编号] [char] (5) NULL , 
		[职工姓名] [nvarchar] (20) NULL , 
		[部门编号] [nvarchar] (20) NULL , 
		[部门名称] [nvarchar] (40) NULL , 
		[职位] [nvarchar] (20) NULL    , 
    CONSTRAINT [PK_基本数据表] PRIMARY KEY CLUSTERED 
    ( 
       Id卡号 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_会议室表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_会议室表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[会议室编号] [varchar] (50) NULL , 
		[会议室名称] [varchar] (50) NULL , 
		[容纳人数] [varchar] (50) NULL , 
		[会议室资源描述] [varchar] (500) NULL , 
		[说明] [varchar] (500) NULL    , 
    CONSTRAINT [PK_行政_会议室表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_个人调动申请表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_个人调动申请表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[申请调动人] [varchar] (50) NULL , 
		[申请调动时间] [datetime]  NULL , 
		[调动理由] [varchar] (1000) NULL , 
		[申请人姓名] [varchar] (50) NULL , 
		[性别] [varchar] (50) NULL , 
		[入职时间] [varchar] (50) NULL , 
		[原工作部门] [varchar] (50) NULL , 
		[原工作岗位] [varchar] (50) NULL , 
		[原工资级别] [decimal] (18,1) NULL , 
		[原基本工资] [money]  NULL , 
		[原考核工资] [money]  NULL , 
		[调动后的部门] [varchar] (50) NULL , 
		[调动后的岗位] [varchar] (50) NULL , 
		[调动后的工资级别] [decimal] (18,1) NULL , 
		[调动后的基本工资] [money]  NULL , 
		[调动后的考核工资] [money]  NULL , 
		[调出部门意见] [varchar] (1000) NULL , 
		[调入部门意见] [varchar] (1000) NULL , 
		[人事部意见] [varchar] (1000) NULL , 
		[总经理意见] [varchar] (1000) NULL , 
		[申请人编号] [varchar] (50) NULL    , 
    CONSTRAINT [PK_人事_个人调动申请表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_个人调动申请表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_个人调动申请表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[申请调动人] [varchar] (50) NULL , 
		[申请调动时间] [datetime]  NULL , 
		[调动理由] [varchar] (1000) NULL , 
		[申请人姓名] [varchar] (50) NULL , 
		[性别] [varchar] (50) NULL , 
		[入职时间] [varchar] (50) NULL , 
		[原工作部门] [varchar] (50) NULL , 
		[原工作岗位] [varchar] (50) NULL , 
		[原工资级别] [decimal] (18,1) NULL , 
		[原基本工资] [money]  NULL , 
		[原考核工资] [money]  NULL , 
		[调动后的部门] [varchar] (50) NULL , 
		[调动后的岗位] [varchar] (50) NULL , 
		[调动后的工资级别] [decimal] (18,1) NULL , 
		[调动后的基本工资] [money]  NULL , 
		[调动后的考核工资] [money]  NULL , 
		[调出部门意见] [varchar] (1000) NULL , 
		[调入部门意见] [varchar] (1000) NULL , 
		[人事部意见] [varchar] (1000) NULL , 
		[总经理意见] [varchar] (1000) NULL , 
		[申请人编号] [varchar] (50) NULL    , 
    CONSTRAINT [PK_人事_个人调动申请表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_请假表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_请假表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[结果有效] [bit]  NULL  DEFAULT ('0'), 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所属部门] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[请假类型] [varchar] (50) NULL , 
		[请假起始时间] [datetime]  NULL , 
		[请假结束时间] [datetime]  NULL , 
		[请假天数] [decimal] (18,1) NULL , 
		[请假原因] [varchar] (500) NULL , 
		[部门意见] [varchar] (200) NULL , 
		[分公司领导意见] [varchar] (200) NULL , 
		[公司领导意见] [varchar] (200) NULL    , 
    CONSTRAINT [PK_人事_请假表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_请假表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_请假表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[结果有效] [bit]  NULL  DEFAULT ('0'), 
		[WFRunId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所属部门] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[请假类型] [varchar] (50) NULL , 
		[请假起始时间] [datetime]  NULL , 
		[请假结束时间] [datetime]  NULL , 
		[请假天数] [decimal] (18,1) NULL , 
		[请假原因] [varchar] (500) NULL , 
		[部门意见] [varchar] (200) NULL , 
		[分公司领导意见] [varchar] (200) NULL , 
		[公司领导意见] [varchar] (200) NULL    , 
    CONSTRAINT [PK_人事_请假表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_人员调动表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_人员调动表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[调动编号] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[调入部门] [varchar] (50) NULL , 
		[调入分公司或项目部] [varchar] (50) NULL , 
		[调出部门] [varchar] (50) NULL , 
		[调出分公司或项目部] [varchar] (50) NULL , 
		[原岗位] [varchar] (50) NULL , 
		[新岗位] [varchar] (50) NULL , 
		[调动性质] [varchar] (50) NULL , 
		[计划调动时间] [varchar] (50) NULL , 
		[借调开始时间] [varchar] (50) NULL , 
		[借调结束时间] [varchar] (50) NULL , 
		[原工资级别] [varchar] (50) NULL , 
		[原基本工资] [varchar] (50) NULL , 
		[原月考核工资] [varchar] (50) NULL , 
		[原月工资合计] [varchar] (50) NULL , 
		[原年度考核工资] [varchar] (50) NULL , 
		[原年薪合计] [varchar] (50) NULL , 
		[原工龄工资] [varchar] (50) NULL , 
		[原电脑补贴] [varchar] (50) NULL , 
		[原地区差补贴] [varchar] (50) NULL , 
		[原电话费] [varchar] (50) NULL , 
		[原交通费] [varchar] (50) NULL , 
		[原社保] [varchar] (50) NULL , 
		[原意外保险] [varchar] (50) NULL , 
		[调后工资级别] [varchar] (50) NULL , 
		[调后基本工资] [varchar] (50) NULL , 
		[调后月考核工资] [varchar] (50) NULL , 
		[调后月工资合计] [varchar] (50) NULL , 
		[调后年度考核工资] [varchar] (50) NULL , 
		[调后年薪合计] [varchar] (50) NULL , 
		[调后工龄工资] [varchar] (50) NULL , 
		[调后电脑补贴] [varchar] (50) NULL , 
		[调后地区差补贴] [varchar] (50) NULL , 
		[调后电话费] [varchar] (50) NULL , 
		[调后交通费] [varchar] (50) NULL , 
		[调后社保] [varchar] (50) NULL , 
		[调后意外保险] [varchar] (50) NULL , 
		[调入部门意见] [varchar] (50) NULL , 
		[调出部门意见] [varchar] (50) NULL , 
		[调入分公司意见] [varchar] (50) NULL , 
		[调出分公司意见] [varchar] (50) NULL , 
		[生产管理部意见] [varchar] (50) NULL , 
		[董事长或总经理意见] [varchar] (50) NULL , 
		[登记时间] [varchar] (50) NULL    , 
    CONSTRAINT [PK_人事_人员调动表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_人员调动表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_人员调动表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[调动编号] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[调入部门] [varchar] (50) NULL , 
		[调入分公司或项目部] [varchar] (50) NULL , 
		[调出部门] [varchar] (50) NULL , 
		[调出分公司或项目部] [varchar] (50) NULL , 
		[原岗位] [varchar] (50) NULL , 
		[新岗位] [varchar] (50) NULL , 
		[调动性质] [varchar] (50) NULL , 
		[计划调动时间] [varchar] (50) NULL , 
		[借调开始时间] [varchar] (50) NULL , 
		[借调结束时间] [varchar] (50) NULL , 
		[原工资级别] [varchar] (50) NULL , 
		[原基本工资] [varchar] (50) NULL , 
		[原月考核工资] [varchar] (50) NULL , 
		[原月工资合计] [varchar] (50) NULL , 
		[原年度考核工资] [varchar] (50) NULL , 
		[原年薪合计] [varchar] (50) NULL , 
		[原工龄工资] [varchar] (50) NULL , 
		[原电脑补贴] [varchar] (50) NULL , 
		[原地区差补贴] [varchar] (50) NULL , 
		[原电话费] [varchar] (50) NULL , 
		[原交通费] [varchar] (50) NULL , 
		[原社保] [varchar] (50) NULL , 
		[原意外保险] [varchar] (50) NULL , 
		[调后工资级别] [varchar] (50) NULL , 
		[调后基本工资] [varchar] (50) NULL , 
		[调后月考核工资] [varchar] (50) NULL , 
		[调后月工资合计] [varchar] (50) NULL , 
		[调后年度考核工资] [varchar] (50) NULL , 
		[调后年薪合计] [varchar] (50) NULL , 
		[调后工龄工资] [varchar] (50) NULL , 
		[调后电脑补贴] [varchar] (50) NULL , 
		[调后地区差补贴] [varchar] (50) NULL , 
		[调后电话费] [varchar] (50) NULL , 
		[调后交通费] [varchar] (50) NULL , 
		[调后社保] [varchar] (50) NULL , 
		[调后意外保险] [varchar] (50) NULL , 
		[调入部门意见] [varchar] (50) NULL , 
		[调出部门意见] [varchar] (50) NULL , 
		[调入分公司意见] [varchar] (50) NULL , 
		[调出分公司意见] [varchar] (50) NULL , 
		[生产管理部意见] [varchar] (50) NULL , 
		[董事长或总经理意见] [varchar] (50) NULL , 
		[登记时间] [varchar] (50) NULL    , 
    CONSTRAINT [PK_人事_人员调动表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_试用期考核成绩表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_试用期考核成绩表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[转正编号] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[考核日期] [datetime]  NULL , 
		[考核得分] [numeric] (18,0) NULL , 
		[考核系数] [numeric] (18,0) NULL , 
		[评语] [varchar] (500) NULL    , 
    CONSTRAINT [PK_人事_试用期考核成绩表_1__66] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工调薪申请表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工调薪申请表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[性别] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[转正日期] [datetime]  NULL , 
		[调薪次数] [int]  NULL , 
		[调薪生效日期] [datetime]  NULL , 
		[申请类别] [varchar] (50) NULL , 
		[申请日期] [datetime]  NULL , 
		[调薪前的基本工资] [money]  NULL , 
		[调薪前的考核工资] [money]  NULL , 
		[调薪前的工资级别] [varchar] (50) NULL , 
		[调薪后的基本工资] [money]  NULL , 
		[调薪后的考核工资] [money]  NULL , 
		[调薪后的岗位] [varchar] (50) NULL , 
		[调薪后的工资级别] [varchar] (50) NULL , 
		[调薪理由] [varchar] (5000) NULL , 
		[直属部门意见] [varchar] (500) NULL , 
		[人力资源部意见] [varchar] (50) NULL , 
		[领导意见] [varchar] (50) NULL , 
		[办结意见] [varchar] (50) NULL    , 
    CONSTRAINT [PK_人事_员工调薪申请表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工调薪申请表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工调薪申请表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[性别] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[转正日期] [datetime]  NULL , 
		[调薪次数] [int]  NULL , 
		[调薪生效日期] [datetime]  NULL , 
		[申请类别] [varchar] (50) NULL , 
		[申请日期] [datetime]  NULL , 
		[调薪前的基本工资] [money]  NULL , 
		[调薪前的考核工资] [money]  NULL , 
		[调薪前的工资级别] [varchar] (50) NULL , 
		[调薪后的基本工资] [money]  NULL , 
		[调薪后的考核工资] [money]  NULL , 
		[调薪后的岗位] [varchar] (50) NULL , 
		[调薪后的工资级别] [varchar] (50) NULL , 
		[调薪理由] [varchar] (5000) NULL , 
		[直属部门意见] [varchar] (500) NULL , 
		[人力资源部意见] [varchar] (50) NULL , 
		[领导意见] [varchar] (50) NULL , 
		[办结意见] [varchar] (50) NULL    , 
    CONSTRAINT [PK_人事_员工调薪申请表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工加班申请表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工加班申请表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[申请日期] [datetime]  NULL , 
		[岗位] [varchar] (50) NULL , 
		[加班事由] [varchar] (2000) NULL , 
		[加班时间] [varchar] (max) NULL , 
		[直属上级审批] [varchar] (500) NULL , 
		[部门经理审批] [varchar] (500) NULL , 
		[人力资源经理审批] [varchar] (500) NULL , 
		[行政副总审批] [varchar] (500) NULL , 
		[加班总小时数] [int]  NULL    , 
    CONSTRAINT [PK_人事_员工加班申请表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工加班申请表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工加班申请表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[申请日期] [datetime]  NULL , 
		[岗位] [varchar] (50) NULL , 
		[加班事由] [varchar] (2000) NULL , 
		[加班时间] [varchar] (max) NULL , 
		[直属上级审批] [varchar] (500) NULL , 
		[部门经理审批] [varchar] (500) NULL , 
		[人力资源经理审批] [varchar] (500) NULL , 
		[行政副总审批] [varchar] (500) NULL , 
		[加班总小时数] [int]  NULL    , 
    CONSTRAINT [PK_人事_员工加班申请表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工晋升申请表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工晋升申请表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[申请人编号] [varchar] (50) NULL , 
		[申请人] [varchar] (50) NULL , 
		[现任部门] [varchar] (50) NULL , 
		[现任岗位] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[申请岗位] [varchar] (50) NULL , 
		[申请岗位所在公司] [varchar] (200) NULL , 
		[申请时间] [datetime]  NULL , 
		[生效时间] [datetime]  NULL , 
		[申请晋升原因] [varchar] (2000) NULL , 
		[对晋升岗位的理解] [varchar] (2000) NULL , 
		[对晋升岗位的胜任能力] [varchar] (2000) NULL , 
		[部门主管意见] [varchar] (200) NULL , 
		[部门经理意见] [varchar] (200) NULL , 
		[人事部意见] [varchar] (200) NULL , 
		[公司意见批复] [varchar] (200) NULL , 
		[备注] [varchar] (500) NULL    , 
    CONSTRAINT [PK_人事_员工晋升申请表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工晋升申请表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工晋升申请表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[申请人编号] [varchar] (50) NULL , 
		[申请人] [varchar] (50) NULL , 
		[现任部门] [varchar] (50) NULL , 
		[现任岗位] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[申请岗位] [varchar] (50) NULL , 
		[申请岗位所在公司] [varchar] (200) NULL , 
		[申请时间] [datetime]  NULL , 
		[生效时间] [datetime]  NULL , 
		[申请晋升原因] [varchar] (2000) NULL , 
		[对晋升岗位的理解] [varchar] (2000) NULL , 
		[对晋升岗位的胜任能力] [varchar] (2000) NULL , 
		[部门主管意见] [varchar] (200) NULL , 
		[部门经理意见] [varchar] (200) NULL , 
		[人事部意见] [varchar] (200) NULL , 
		[公司意见批复] [varchar] (200) NULL , 
		[备注] [varchar] (500) NULL    , 
    CONSTRAINT [PK_人事_员工晋升申请表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工离职申请表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工离职申请表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[合同起始日期] [datetime]  NULL , 
		[合同终止日期] [datetime]  NULL , 
		[拟离职日期] [datetime]  NULL , 
		[离职类型] [varchar] (200) NULL , 
		[离职原因] [varchar] (1000) NULL , 
		[申请日期] [datetime]  NULL , 
		[直属部门意见] [varchar] (1000) NULL , 
		[人力资源部意见] [varchar] (1000) NULL , 
		[领导意见] [varchar] (1000) NULL , 
		[办结意见] [varchar] (1000) NULL    , 
    CONSTRAINT [PK_人事_员工离职申请表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_员工离职申请表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_员工离职申请表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[合同起始日期] [datetime]  NULL , 
		[合同终止日期] [datetime]  NULL , 
		[拟离职日期] [datetime]  NULL , 
		[离职类型] [varchar] (200) NULL , 
		[离职原因] [varchar] (1000) NULL , 
		[申请日期] [datetime]  NULL , 
		[直属部门意见] [varchar] (1000) NULL , 
		[人力资源部意见] [varchar] (1000) NULL , 
		[领导意见] [varchar] (1000) NULL , 
		[办结意见] [varchar] (1000) NULL    , 
    CONSTRAINT [PK_人事_员工离职申请表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_转正申请表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_转正申请表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[转正编号] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[部门] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[上岗证种类及有效期] [varchar] (1000) NULL , 
		[员工自评] [varchar] (max) NULL , 
		[直接上级主管评语] [varchar] (1000) NULL , 
		[综合考核得分] [numeric] (18,0) NULL , 
		[综合考核系数] [numeric] (18,0) NULL , 
		[综合评定结果] [varchar] (200) NULL , 
		[试用期月基本工资] [money]  NULL , 
		[试用期月考核工资] [money]  NULL , 
		[试用期月工资合计] [money]  NULL , 
		[转正后工资等级] [numeric] (18,0) NULL , 
		[转正后月基本工资] [money]  NULL , 
		[转正后月考核工资] [money]  NULL , 
		[转正后月工资合计] [money]  NULL , 
		[转正后年度考核工资] [money]  NULL , 
		[转正后年薪合计] [money]  NULL , 
		[部门或项目部意见] [varchar] (1000) NULL , 
		[分公司意见] [varchar] (1000) NULL , 
		[生产管理部意见] [varchar] (1000) NULL , 
		[董事长或总经理意见] [varchar] (1000) NULL , 
		[申请转正日期] [datetime]  NULL    , 
    CONSTRAINT [PK_人事_转正申请表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[人事_转正申请表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[人事_转正申请表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[转正编号] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[部门] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[上岗证种类及有效期] [varchar] (1000) NULL , 
		[员工自评] [varchar] (max) NULL , 
		[直接上级主管评语] [varchar] (1000) NULL , 
		[综合考核得分] [numeric] (18,0) NULL , 
		[综合考核系数] [numeric] (18,0) NULL , 
		[综合评定结果] [varchar] (200) NULL , 
		[试用期月基本工资] [money]  NULL , 
		[试用期月考核工资] [money]  NULL , 
		[试用期月工资合计] [money]  NULL , 
		[转正后工资等级] [numeric] (18,0) NULL , 
		[转正后月基本工资] [money]  NULL , 
		[转正后月考核工资] [money]  NULL , 
		[转正后月工资合计] [money]  NULL , 
		[转正后年度考核工资] [money]  NULL , 
		[转正后年薪合计] [money]  NULL , 
		[部门或项目部意见] [varchar] (1000) NULL , 
		[分公司意见] [varchar] (1000) NULL , 
		[生产管理部意见] [varchar] (1000) NULL , 
		[董事长或总经理意见] [varchar] (1000) NULL    , 
    CONSTRAINT [PK_人事_转正申请表_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_差旅费报销单]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_差旅费报销单]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[出差编号] [varchar] (50) NULL , 
		[出差人] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[所在部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[出差地点] [varchar] (50) NULL , 
		[出差事由] [varchar] (max) NULL , 
		[出差起始日期] [datetime]  NULL , 
		[出差结束日期] [datetime]  NULL , 
		[总共天数] [int]  NULL , 
		[交通讯费] [money]  NULL , 
		[餐费] [money]  NULL , 
		[住宿费] [money]  NULL , 
		[通讯费] [money]  NULL , 
		[其他费] [money]  NULL , 
		[费用合计] [money]  NULL , 
		[报销日期] [datetime]  NULL , 
		[所在部门编号] [varchar] (50) NULL , 
		[部门审批意见] [varchar] (50) NULL , 
		[财务部审批意见] [varchar] (50) NULL , 
		[批准人] [varchar] (50) NULL , 
		[预支金额] [money]  NULL , 
		[应退或补金额] [money]  NULL , 
		[费用合计大写] [varchar] (100) NULL , 
		[预支金额大写] [varchar] (100) NULL , 
		[应退或补金额大写] [varchar] (100) NULL    , 
    CONSTRAINT [PK_行政_差旅费报销单] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_差旅费报销单_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_差旅费报销单_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[出差编号] [varchar] (50) NULL , 
		[出差人] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[所在部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[出差地点] [varchar] (50) NULL , 
		[出差事由] [varchar] (max) NULL , 
		[出差起始日期] [datetime]  NULL , 
		[出差结束日期] [datetime]  NULL , 
		[总共天数] [int]  NULL , 
		[交通讯费] [money]  NULL , 
		[餐费] [money]  NULL , 
		[住宿费] [money]  NULL , 
		[通讯费] [money]  NULL , 
		[其他费] [money]  NULL , 
		[费用合计] [money]  NULL , 
		[报销日期] [datetime]  NULL , 
		[所在部门编号] [varchar] (50) NULL , 
		[部门审批意见] [varchar] (50) NULL , 
		[财务部审批意见] [varchar] (50) NULL , 
		[批准人] [varchar] (50) NULL , 
		[预支金额] [money]  NULL , 
		[应退或补金额] [money]  NULL , 
		[费用合计大写] [varchar] (100) NULL , 
		[预支金额大写] [varchar] (100) NULL , 
		[应退或补金额大写] [varchar] (100) NULL    , 
    CONSTRAINT [PK_行政_差旅费报销单_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_出差申请单]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_出差申请单]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[出差编号] [varchar] (50) NULL , 
		[出差人] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[所在部门编号] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[申请日期] [datetime]  NULL , 
		[出差地点] [varchar] (50) NULL , 
		[出差期间工作代理人] [varchar] (50) NULL , 
		[出差事由] [varchar] (max) NULL , 
		[出差起始日期] [datetime]  NULL , 
		[出差结束日期] [datetime]  NULL , 
		[总共天数] [int]  NULL , 
		[交通工具安排] [varchar] (50) NULL , 
		[申请出差费用] [money]  NULL , 
		[部门主管签名] [varchar] (50) NULL , 
		[部门经理签名] [varchar] (50) NULL , 
		[综合办签名] [varchar] (50) NULL , 
		[总经理审批意见] [varchar] (500) NULL    , 
    CONSTRAINT [PK_行政_出差申请单] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_出差申请单_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_出差申请单_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[出差编号] [varchar] (50) NULL , 
		[出差人] [varchar] (50) NULL , 
		[员工编号] [varchar] (50) NULL , 
		[入职日期] [datetime]  NULL , 
		[所在部门编号] [varchar] (50) NULL , 
		[所在部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[申请日期] [datetime]  NULL , 
		[出差地点] [varchar] (50) NULL , 
		[出差期间工作代理人] [varchar] (50) NULL , 
		[出差事由] [varchar] (max) NULL , 
		[出差起始日期] [datetime]  NULL , 
		[出差结束日期] [datetime]  NULL , 
		[总共天数] [int]  NULL , 
		[交通工具安排] [varchar] (50) NULL , 
		[申请出差费用] [money]  NULL , 
		[部门主管签名] [varchar] (50) NULL , 
		[部门经理签名] [varchar] (50) NULL , 
		[综合办签名] [varchar] (50) NULL , 
		[总经理审批意见] [varchar] (500) NULL    , 
    CONSTRAINT [PK_行政_出差申请单_log] PRIMARY KEY CLUSTERED 
    ( 
       WFPrcsId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_工作请示表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_工作请示表]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFState] [varchar] (50) NULL , 
		[WFUserName] [varchar] (50) NULL , 
		[WFIsFinish] [bit]  NULL  DEFAULT ('0'), 
		[WFIsStart] [bit]  NULL  DEFAULT ('0'), 
		[WFAllUser] [varchar] (500) NULL , 
		[WFOpinion] [varchar] (max) NULL , 
		[WFRunId] [int]  NULL , 
		[WFFlowId] [int]  NULL , 
		[WFPrcsId] [int]  NULL , 
		[申请人] [varchar] (50) NULL , 
		[请示事项] [varchar] (50) NULL , 
		[申请部门] [varchar] (50) NULL , 
		[请示时间] [datetime]  NULL , 
		[预算金额] [money]  NULL , 
		[请示正文] [varchar] (max) NULL , 
		[部门意见] [varchar] (500) NULL , 
		[领导意见] [varchar] (500) NULL    , 
    CONSTRAINT [PK_行政_工作请示表] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[行政_工作请示表_log]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[行政_工作请示表_log]( 
		[LD_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[WFPrcsId] [int]  NOT NULL , 
		[WFRunId] [int]  NULL , 
		[申请人] [varchar] (50) NULL , 
		[请示事项] [varchar] (50) NULL , 
		[申请部门] [varchar] (50) NULL , 
		[请示时间] [datetime]  NULL , 
		[预算金额] [money]  NULL , 
		[请示正文] [varchar] (max) NULL , 
		[部门意见] [varchar] (500) NULL , 
		[领导意见] [varchar] (500) NULL    , 
    CONSTRAINT [PK_行政_工作请示表_log] PRIMARY KEY CLUSTERED 
    ( 
       LD_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntitySheet]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_EntitySheet]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Report_EntId] [int]  NULL , 
		[EntId] [int]  NULL , 
		[EntName] [varchar] (100) NULL , 
		[DBTableName] [varchar] (100) NULL , 
		[FieldName] [varchar] (100) NULL , 
		[ColumnByname] [varchar] (100) NULL , 
		[FieldDataType] [varchar] (100) NULL , 
		[FieldDataTypeId] [int]  NULL , 
		[TabId] [int]  NOT NULL  DEFAULT ('-1'), 
		[TotalUp] [bit]  NULL  DEFAULT ('0'), 
		[ColumnNO] [int]  NULL , 
		[ColumnType] [varchar] (100) NULL , 
		[ColumnTypeId] [int]  NOT NULL  DEFAULT ('-1'), 
		[IsMerge] [bit]  NULL  DEFAULT ('0'), 
		[EntUId] [uniqueidentifier]  NULL , 
		[CUId] [uniqueidentifier]  NULL   DEFAULT (newid()), 
		[ColumnWidth] [int]  NULL , 
		[ColumnHeight] [int]  NULL , 
		[TotalUpType] [varchar] (20) NULL , 
		[TotalUpUnit] [varchar] (20) NULL , 
		[FieldType] [varchar] (20) NULL , 
		[FieldTypeId] [int]  NULL  DEFAULT ('1'), 
		[LinkContent] [varchar] (300) NULL , 
		[IsGroupField] [bit]  NULL , 
		[GroupOrderNO] [int]  NULL , 
		[GroupTitleHtml] [varchar] (max) NULL , 
		[GroupTotalUpStr] [varchar] (max) NULL , 
		[IsOwnHead] [bit]  NULL , 
		[ColWidthType] [varchar] (10) NULL  DEFAULT ('px'), 
		[ColumnWidthStr] [varchar] (50) NULL , 
		[BeforeHtml] [varchar] (max) NULL , 
		[LastHtml] [varchar] (max) NULL , 
		[CellfrontHtml] [varchar] (max) NULL , 
		[CellbackHtml] [varchar] (max) NULL , 
		[SystemVariable] [varchar] (100) NULL , 
		[CalculateFormula] [varchar] (500) NULL    , 
    CONSTRAINT [PK_FZET_EntitySheet] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabAccountIndex]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabAccountIndex]( 
		[UserId] [numeric] (18,0)IdENTITY(1,1)  NOT NULL , 
		[UserName] [nvarchar] (40) NOT NULL , 
		[pwd] [nvarchar] (40) NOT NULL    , 
    CONSTRAINT [PK_TabUser] PRIMARY KEY CLUSTERED 
    ( 
       UserId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabAccountInfo]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabAccountInfo]( 
		[UserId] [numeric] (18,0) NOT NULL , 
		[SenderName] [nvarchar] (40) NOT NULL , 
		[CnName] [nvarchar] (40) NULL , 
		[EnName] [nvarchar] (40) NULL , 
		[EmailAddress] [nvarchar] (160) NULL , 
		[Descn] [nvarchar] (510) NULL    , 
    CONSTRAINT [PK_TabAccountInfo] PRIMARY KEY CLUSTERED 
    ( 
       UserId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabIntMailLog]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabIntMailLog]( 
		[LogId] [int]  NOT NULL , 
		[LogMsg] [nvarchar] (100) NULL , 
		[LogDate] [datetime]  NOT NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabMailAttachFiles]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabMailAttachFiles]( 
		[FileId] [int] IdENTITY(1,1)  NOT NULL , 
		[MailId] [int]  NOT NULL , 
		[FileName] [varchar] (255) NULL , 
		[FileSize] [int]  NULL , 
		[FileAttribute] [int]  NULL , 
		[FileVisualPath] [varchar] (255) NULL , 
		[FileAuthor] [varchar] (255) NULL , 
		[FileCatlog] [varchar] (255) NULL , 
		[FileAddedDate] [datetime]  NULL  DEFAULT (getdate())   , 
    CONSTRAINT [PK_TabMailAttachFiles] PRIMARY KEY CLUSTERED 
    ( 
       FileId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabMailGroup]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabMailGroup]( 
		[MailGroupId] [numeric] (18,0)IdENTITY(1,1)  NOT NULL , 
		[UserId] [numeric] (18,0) NOT NULL , 
		[MailGroupName] [nvarchar] (40) NOT NULL    , 
    CONSTRAINT [PK_TabMailGroup] PRIMARY KEY CLUSTERED 
    ( 
       MailGroupId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabMailGrpMemb]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabMailGrpMemb]( 
		[MailGroupId] [numeric] (18,0) NOT NULL , 
		[UserId] [numeric] (18,0) NOT NULL    , 
    CONSTRAINT [PK_TabMailGrpMemb] PRIMARY KEY CLUSTERED 
    ( 
       MailGroupId, UserId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabMailList]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabMailList]( 
		[MailId] [numeric] (18,0)IdENTITY(1,1)  NOT NULL , 
		[MailFolderType] [numeric] (18,0) NOT NULL , 
		[MailReceiverStr] [nvarchar] (600) NOT NULL , 
		[MailSendDate] [datetime]  NOT NULL  DEFAULT (getdate()), 
		[MailSendLevel] [smallint]  NOT NULL , 
		[MailReceiver] [nvarchar] (40) NULL , 
		[MailSender] [nvarchar] (40) NULL , 
		[MailSubject] [nvarchar] (100) NULL , 
		[MailBody] [text]  NULL , 
		[MailCcToAddr] [nvarchar] (600) NULL , 
		[MailBccToAddr] [nvarchar] (600) NULL , 
		[MailReadFlag] [bit]  NOT NULL  DEFAULT ('0'), 
		[MailTypeFlag] [bit]  NOT NULL , 
		[MailSize] [int]  NULL , 
		[ClassId] [int]  NOT NULL  DEFAULT ('0'), 
		[MailImportance] [int]  NOT NULL    , 
    CONSTRAINT [PK_TabReceiveMail] PRIMARY KEY CLUSTERED 
    ( 
       MailId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabSysMailFolder]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabSysMailFolder]( 
		[FolderId] [numeric] (18,0)IdENTITY(1,1)  NOT NULL , 
		[FolderName] [nvarchar] (20) NOT NULL    , 
    CONSTRAINT [PK_TabCommonMailFolder] PRIMARY KEY CLUSTERED 
    ( 
       FolderId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabUsrMailFolder]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TabUsrMailFolder]( 
		[FolderId] [numeric] (18,0)IdENTITY(1,1)  NOT NULL , 
		[UserId] [numeric] (18,0) NOT NULL , 
		[FolderName] [nvarchar] (40) NOT NULL , 
		[Attribute] [bit]  NOT NULL    , 
    CONSTRAINT [PK_TabUsrMailFolder] PRIMARY KEY CLUSTERED 
    ( 
       FolderId 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Task]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Task]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[ArrangedBy] [varchar] (50) NOT NULL , 
		[Subject] [varchar] (50) NULL , 
		[Detail] [text]  NULL , 
		[Address] [varchar] (300) NULL , 
		[ProjectId] [int]  NULL , 
		[StartTime] [datetime]  NULL , 
		[EndTime] [datetime]  NULL , 
		[Attribute] [bit]  NULL , 
		[Type] [int]  NULL , 
		[Status] [bit]  NULL , 
		[Tag] [int]  NULL , 
		[CooperatorList] [varchar] (300) NULL , 
		[IsAwake] [bit]  NULL , 
		[AwakeTime] [datetime]  NULL , 
		[ContractList] [varchar] (50) NULL , 
		[CreateDate] [datetime]  NULL  DEFAULT (getdate())   , 
    CONSTRAINT [PK_FZET_Assignment] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Task_Comment]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Task_Comment]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[TaskId] [int]  NULL , 
		[Username] [varchar] (50) NULL , 
		[Comment] [text]  NULL , 
		[SubmitTime] [datetime]  NULL  DEFAULT (getdate())   , 
    CONSTRAINT [PK_FZET_Task_Comment] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Team]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_Team]( 
		[Team_Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Super_Team_Id] [int]  NULL , 
		[Team_Name] [varchar] (255) NOT NULL , 
		[Team_Description] [text]  NULL    , 
    CONSTRAINT [PK_FZET_Team] PRIMARY KEY CLUSTERED 
    ( 
       Team_Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TeamInfo]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_TeamInfo]( 
		[TeamId] [int]  NULL , 
		[Scale] [numeric] (18,0) NULL , 
		[StartDate] [datetime]  NULL  DEFAULT (getdate()), 
		[EndDate] [datetime]  NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserTempMsg]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserTempMsg]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[Text1] [varchar] (max) NULL , 
		[Text2] [varchar] (max) NULL , 
		[Text3] [varchar] (max) NULL , 
		[Int1] [int]  NULL , 
		[Int2] [int]  NULL , 
		[Int3] [int]  NULL , 
		[Dtime] [datetime]  NULL    , 
    CONSTRAINT [PK_Dcx_UserTempMsg] PRIMARY KEY NONCLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserTryout]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[Dcx_UserTryout]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[Code] [int]  NOT NULL , 
		[UserId] [int]  NOT NULL , 
		[UserName] [varchar] (50) NOT NULL , 
		[RealName] [varchar] (50) NULL , 
		[Pwd] [varchar] (100) NOT NULL , 
		[CreateTime] [datetime]  NOT NULL  DEFAULT (getdate()), 
		[TryoutCount] [int]  NOT NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_Dcx_TryoutUser] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[公司信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[公司信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[公司编号] [varchar] (80) NOT NULL , 
		[成立日期] [varchar] (80) NULL , 
		[公司名称] [varchar] (80) NOT NULL , 
		[公司地址] [varchar] (80) NULL , 
		[邮编号码] [varchar] (80) NULL , 
		[内线电话] [varchar] (80) NULL , 
		[外线电话] [varchar] (80) NULL , 
		[区号] [varchar] (40) NULL , 
		[内部电子邮箱] [varchar] (80) NULL , 
		[外部电子邮箱] [varchar] (80) NULL , 
		[营业执照号码] [varchar] (80) NULL , 
		[营业执照年检有效期] [varchar] (80) NULL , 
		[组织机构代码证号码] [varchar] (80) NULL , 
		[组织机构代码证年检有效期] [varchar] (80) NULL , 
		[税务登记证国税号码] [varchar] (80) NULL , 
		[税务登记证国税年检有效期] [varchar] (80) NULL , 
		[税务登记证地税号码] [varchar] (80) NULL , 
		[税务登记证地税年检有效期] [varchar] (80) NULL , 
		[法定代表人] [varchar] (80) NULL , 
		[法定代表人身份证号码] [varchar] (80) NULL , 
		[基本开户许可证号码] [varchar] (80) NULL , 
		[其他证件] [varchar] (80) NULL , 
		[企业类别] [varchar] (80) NULL , 
		[开户银行] [varchar] (80) NULL , 
		[纳税账号] [varchar] (80) NULL , 
		[单位组织机构代码] [varchar] (80) NULL    , 
    CONSTRAINT [PK_公司信息] PRIMARY KEY CLUSTERED 
    ( 
       公司编号 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[公司制度]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[公司制度]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[制度编号] [varchar] (10) NULL , 
		[制度名称] [varchar] (200) NULL , 
		[制度类别] [varchar] (50) NULL , 
		[制度分类] [varchar] (50) NULL , 
		[发布部门] [varchar] (50) NULL , 
		[发布日期] [datetime]  NULL , 
		[附件1] [image]  NULL , 
		[附件2] [image]  NULL , 
		[附件3] [image]  NULL    , 
    CONSTRAINT [PK_公司制度] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[机构基本信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[机构基本信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[机构号] [varchar] (9) NOT NULL , 
		[成立日期] [varchar] (12) NOT NULL , 
		[机构名称] [varchar] (40) NOT NULL , 
		[机构地址] [varchar] (80) NOT NULL , 
		[邮编号码] [varchar] (6) NOT NULL , 
		[传真号码] [varchar] (80) NULL , 
		[内线电话号码] [varchar] (8) NULL , 
		[外线电话号码] [varchar] (4) NULL , 
		[区号] [varchar] (40) NULL , 
		[内部电子邮箱] [varchar] (40) NULL , 
		[外部电子邮箱] [varchar] (18) NULL , 
		[营业执照号码] [varchar] (18) NULL , 
		[营业执照年检有效期] [varchar] (12) NULL , 
		[组织机构代码证号码] [varchar] (18) NULL , 
		[组织机构代码证年检有效期] [varchar] (12) NULL , 
		[税务登记证国税号码] [varchar] (18) NULL , 
		[税务登记证国税年检有效期] [varchar] (12) NULL , 
		[税务登记证地税号码] [varchar] (18) NULL , 
		[税务登记证地税年检有效期] [varchar] (12) NULL , 
		[法定代表人] [varchar] (20) NULL , 
		[法定代表人身份证号码] [varchar] (20) NULL , 
		[基本开户许可证号码] [varchar] (18) NULL , 
		[其他证件] [varchar] (80) NULL , 
		[机构网址] [varchar] (100) NULL , 
		[联系人] [varchar] (100) NULL , 
		[银行开户帐号] [varchar] (100) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[集团通讯录]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[集团通讯录]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[公司] [varchar] (50) NULL , 
		[部门] [varchar] (50) NULL , 
		[姓名] [varchar] (50) NULL , 
		[直线电话] [varchar] (50) NULL , 
		[分机] [varchar] (50) NULL , 
		[手机] [varchar] (50) NULL , 
		[排序] [int]  NULL    , 
    CONSTRAINT [PK_集团通讯录] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[计划总结]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[计划总结]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[title] [varchar] (500) NULL , 
		[other] [text]  NULL , 
		[people1] [varchar] (500) NULL , 
		[people2] [varchar] (500) NULL , 
		[write_time] [smalldatetime]  NULL , 
		[com_time] [smalldatetime]  NULL , 
		[bumen] [varchar] (50) NULL    ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[系统_暂无图片]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[系统_暂无图片]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[noImage] [image]  NULL    , 
    CONSTRAINT [PK_系统_暂无图片] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[相片]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[相片]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[相片名称] [varchar] (20) NULL , 
		[附件] [image]  NULL , 
		[描述] [text]  NULL , 
		[备注] [text]  NOT NULL    , 
    CONSTRAINT [PK_相片] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[新闻公告]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[新闻公告]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[item] [varchar] (500) NOT NULL , 
		[itemurl] [varchar] (100) NULL , 
		[ordernum] [int]  NULL , 
		[onoff] [int]  NOT NULL  DEFAULT ('1'), 
		[ontime] [datetime]  NULL , 
		[offtime] [datetime]  NULL , 
		[infotype] [varchar] (20) NULL , 
		[body] [text]  NULL , 
		[sms] [bit]  NULL , 
		[smsed] [bit]  NULL , 
		[releasedate] [datetime]  NULL , 
		[releaseuser] [varchar] (30) NULL , 
		[releasedept] [varchar] (50) NULL , 
		[是否重要] [varchar] (50) NULL    , 
    CONSTRAINT [PK_新闻公告] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[ERP_总结计划]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[ERP_总结计划]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[主题] [varchar] (50) NULL , 
		[总结] [varchar] (max) NULL , 
		[计划] [varchar] (max) NULL , 
		[领导评阅] [varchar] (max) NULL , 
		[评阅人] [varchar] (50) NULL , 
		[已评阅] [bit]  NULL  DEFAULT ('0'), 
		[评阅时间] [varchar] (50) NULL , 
		[类别] [varchar] (50) NULL , 
		[创建人] [varchar] (50) NULL , 
		[创建时间] [varchar] (50) NULL , 
		[所属用户] [varchar] (50) NULL , 
		[所属部门] [varchar] (50) NULL    , 
    CONSTRAINT [PK_ERP_总结计划] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[个人通讯录]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[个人通讯录]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[姓名] [varchar] (10) NOT NULL , 
		[性别] [varchar] (50) NULL , 
		[部门] [varchar] (20) NULL , 
		[职务] [varchar] (100) NULL , 
		[办公电话] [varchar] (50) NULL , 
		[移动电话] [varchar] (20) NULL , 
		[家庭电话] [varchar] (20) NULL , 
		[电子邮件] [varchar] (20) NULL , 
		[地址] [varchar] (200) NULL , 
		[办公地址] [varchar] (200) NULL , 
		[传真号码] [varchar] (20) NULL , 
		[QQ号码] [varchar] (50) NULL , 
		[创建时间] [varchar] (50) NULL , 
		[所属用户] [varchar] (50) NULL    , 
    CONSTRAINT [PK_个人通讯录] PRIMARY KEY CLUSTERED 
    ( 
       姓名 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[工作日志]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[工作日志]( 
		[序号] [int] IdENTITY(1,1)  NOT NULL , 
		[姓名] [varchar] (10) NULL , 
		[部门] [varchar] (20) NULL , 
		[部门编号] [varchar] (20) NULL , 
		[日期] [varchar] (30) NOT NULL  DEFAULT ('getdate'), 
		[领导意见] [text]  NULL , 
		[本人意见] [varchar] (1000) NULL , 
		[填写人] [varchar] (20) NULL , 
		[工作内容1] [text]  NULL , 
		[工作内容] [text]  NULL , 
		[起止时间] [varchar] (20) NULL , 
		[内容输入] [varchar] (1000) NULL , 
		[write_date] [varchar] (20) NULL    , 
    CONSTRAINT [PK_工作日志] PRIMARY KEY CLUSTERED 
    ( 
       序号 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[名片夹]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[名片夹]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[编号] [varchar] (13) NULL , 
		[姓名] [varchar] (10) NULL , 
		[职位] [varchar] (10) NULL , 
		[办公电话] [varchar] (20) NULL , 
		[家庭电话] [varchar] (20) NULL , 
		[移动电话] [varchar] (20) NULL , 
		[传真号码] [varchar] (20) NULL , 
		[电子邮件] [varchar] (30) NULL , 
		[备注] [varchar] (200) NULL , 
		[分类] [varchar] (10) NULL , 
		[卡片所属] [varchar] (10) NULL , 
		[性别] [varchar] (10) NULL , 
		[创建时间] [datetime]  NULL    , 
    CONSTRAINT [PK_名片夹] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[内部交流表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[内部交流表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[主题] [varchar] (50) NULL , 
		[签收人] [varchar] (10) NULL , 
		[项目单位] [varchar] (50) NULL , 
		[内容] [text]  NULL , 
		[提交人] [varchar] (10) NULL , 
		[提交日期] [datetime]  NULL , 
		[附件] [image]  NULL , 
		[反馈信息] [varchar] (200) NULL , 
		[反馈日期] [datetime]  NULL    , 
    CONSTRAINT [PK_内部交流表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[年度]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[年度]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[年度] [varchar] (4) NULL    , 
    CONSTRAINT [PK_年度] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[业务通讯录]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[业务通讯录]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[姓名] [varchar] (10) NULL , 
		[姓别] [varchar] (50) NULL , 
		[单位] [varchar] (50) NULL , 
		[职务] [varchar] (20) NULL , 
		[电话] [varchar] (100) NULL , 
		[移动电话] [varchar] (50) NULL , 
		[传真] [varchar] (20) NULL , 
		[电子邮件] [varchar] (100) NULL , 
		[客户类型] [varchar] (20) NULL , 
		[填写人] [varchar] (10) NULL , 
		[部门] [varchar] (20) NULL , 
		[创建时间] [datetime]  NULL    , 
    CONSTRAINT [PK_员工通讯录] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[预期目标]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[预期目标]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[项目编号] [varchar] (15) NOT NULL , 
		[工作项目名称] [varchar] (50) NULL , 
		[责任人] [varchar] (10) NULL , 
		[填写人] [varchar] (10) NULL , 
		[填写日期] [datetime]  NULL , 
		[内容] [text]  NULL , 
		[附件] [image]  NULL    , 
    CONSTRAINT [PK_预期目标] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工调动信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工调动信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (4) NOT NULL , 
		[日期] [varchar] (15) NOT NULL , 
		[岗位名称] [varchar] (12) NOT NULL , 
		[职务] [varchar] (8) NOT NULL , 
		[主要岗位职责] [text]  NOT NULL , 
		[备注] [text]  NULL , 
		[公司] [varchar] (50) NULL , 
		[公司编号] [varchar] (50) NULL , 
		[部门] [varchar] (50) NULL , 
		[部门编号] [varchar] (50) NULL    , 
    CONSTRAINT [PK_员工调动信息] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工基本信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工基本信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (8) NOT NULL , 
		[姓名] [varchar] (20) NOT NULL , 
		[身份证号码] [varchar] (30) NOT NULL , 
		[出生日期] [varchar] (15) NOT NULL , 
		[性别] [varchar] (10) NOT NULL , 
		[民族] [varchar] (20) NOT NULL , 
		[籍贯] [varchar] (20) NOT NULL , 
		[学历] [varchar] (20) NOT NULL , 
		[婚姻状况] [varchar] (10) NOT NULL , 
		[政治面貌] [varchar] (20) NOT NULL , 
		[毕业院校] [varchar] (40) NULL , 
		[专业] [varchar] (40) NULL , 
		[专长] [varchar] (80) NULL , 
		[取得资格证书名称] [varchar] (40) NULL , 
		[职称] [varchar] (20) NULL , 
		[职务] [varchar] (50) NULL , 
		[岗位] [varchar] (50) NULL , 
		[手机号码] [varchar] (20) NOT NULL , 
		[家庭电话] [varchar] (20) NOT NULL , 
		[家庭住址] [varchar] (80) NOT NULL , 
		[家庭住址邮编] [varchar] (10) NOT NULL , 
		[配偶姓名] [varchar] (20) NULL , 
		[入本单位日期] [varchar] (15) NOT NULL , 
		[合同签订日期] [varchar] (15) NOT NULL , 
		[合同终止日期] [varchar] (15) NOT NULL , 
		[外语语种] [varchar] (20) NULL , 
		[外语水平] [varchar] (50) NULL , 
		[个人电子邮箱] [varchar] (50) NULL , 
		[公司] [varchar] (50) NULL , 
		[在职标志] [varchar] (10) NOT NULL , 
		[UserName] [varchar] (20) NULL , 
		[角色] [varchar] (50) NULL , 
		[密码] [nchar] (200) NULL  DEFAULT (N'A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'), 
		[公司编号] [varchar] (50) NULL , 
		[部门] [varchar] (50) NULL , 
		[部门编号] [varchar] (50) NULL , 
		[可登录系统] [bit]  NULL  DEFAULT ('0')   , 
    CONSTRAINT [PK_员工基本信息] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工假期表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工假期表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[年度] [nchar] (20) NOT NULL , 
		[姓名] [varchar] (50) NOT NULL , 
		[部门] [varchar] (50) NULL , 
		[职务] [varchar] (50) NULL , 
		[假期类型] [varchar] (10) NOT NULL , 
		[假期小时] [int]  NULL    , 
    CONSTRAINT [PK_员工假期表_1] PRIMARY KEY CLUSTERED 
    ( 
       年度, 姓名, 假期类型 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工奖惩信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工奖惩信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (4) NOT NULL , 
		[日期] [varchar] (15) NOT NULL , 
		[奖惩事项] [varchar] (16) NOT NULL , 
		[奖惩事由] [varchar] (50) NOT NULL , 
		[备注] [text]  NULL    , 
    CONSTRAINT [PK_员工奖惩信息] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工论坛]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工论坛]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[公告类别] [varchar] (50) NULL , 
		[公告标题] [varchar] (200) NULL , 
		[发布部门] [varchar] (50) NULL , 
		[发布人] [varchar] (10) NULL , 
		[发布日期] [datetime]  NULL , 
		[有效日期] [datetime]  NULL , 
		[附件] [image]  NULL    , 
    CONSTRAINT [PK_员工论坛] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工年休表]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工年休表]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (50) NULL , 
		[员工姓名] [varchar] (50) NULL , 
		[部门] [varchar] (50) NULL , 
		[所属分公司] [varchar] (50) NULL , 
		[工龄] [int]  NULL , 
		[年休天数] [int]  NULL , 
		[年休小时] [int]  NULL    , 
    CONSTRAINT [PK_员工年休表] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工培训信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工培训信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (4) NOT NULL , 
		[日期] [varchar] (15) NOT NULL , 
		[培训班名称] [varchar] (30) NOT NULL , 
		[培训内容] [varchar] (200) NOT NULL , 
		[开始日期] [varchar] (15) NOT NULL , 
		[结束日期] [datetime]  NOT NULL , 
		[备注] [text]  NULL    , 
    CONSTRAINT [PK_员工培训信息] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工社会关系]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工社会关系]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (4) NOT NULL , 
		[姓名] [varchar] (20) NOT NULL , 
		[关系类别] [varchar] (8) NOT NULL , 
		[工作单位] [varchar] (40) NULL , 
		[部门] [varchar] (20) NULL , 
		[职务] [varchar] (8) NULL , 
		[政治面貌] [varchar] (8) NULL , 
		[联系电话] [varchar] (20) NULL , 
		[备注] [text]  NULL    , 
    CONSTRAINT [PK_员工社会关系] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[员工薪酬信息]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[员工薪酬信息]( 
		[id] [int] IdENTITY(1,1)  NOT NULL , 
		[员工编号] [varchar] (4) NOT NULL , 
		[日期] [varchar] (15) NOT NULL , 
		[基本工资] [money]  NULL , 
		[绩效工资] [money]  NULL , 
		[节日补贴] [money]  NULL , 
		[加班工资] [money]  NULL , 
		[其他补贴] [money]  NULL , 
		[备注] [text]  NULL    , 
    CONSTRAINT [PK_员工薪酬信息] PRIMARY KEY CLUSTERED 
    ( 
       id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[月份]') AND type in (N'U')) 
BEGIN 
CREATE TABLE dbo.[月份]( 
		[Id] [int] IdENTITY(1,1)  NOT NULL , 
		[月份] [varchar] (2) NULL    , 
    CONSTRAINT [PK_月份] PRIMARY KEY CLUSTERED 
    ( 
       Id 
    )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
   
   ) ON [PRIMARY] 
   END 
----------------------------------------------------------------------------------------  上：数据表  ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------  下：索引  ----------------------------------------------------------------------------------
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Account]') AND name = N'IX_FZET_Account') 
   DROP index  IX_FZET_Account ON dbo.[Dcx_Account] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Account]') AND name = N'IX_FZET_Account') 
CREATE unique NONCLUSTERED INDEX [IX_FZET_Account] ON dbo.[Dcx_Account]  
( 
    Email 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_AjaxFormField_Run]') AND name = N'IX_FZET_AjaxFormField_Run') 
   DROP index  IX_FZET_AjaxFormField_Run ON dbo.[Dcx_AjaxFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_AjaxFormField_Run]') AND name = N'IX_FZET_AjaxFormField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_AjaxFormField_Run] ON dbo.[Dcx_AjaxFormField_Run]  
( 
    Form_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_AjaxFormField_Run]') AND name = N'IX_FZET_AjaxFormField_Run_1') 
   DROP index  IX_FZET_AjaxFormField_Run_1 ON dbo.[Dcx_AjaxFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_AjaxFormField_Run]') AND name = N'IX_FZET_AjaxFormField_Run_1') 
CREATE  NONCLUSTERED INDEX [IX_FZET_AjaxFormField_Run_1] ON dbo.[Dcx_AjaxFormField_Run]  
( 
    EntId, FldId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis]') AND name = N'IX_Dcx_Analysis') 
   DROP index  IX_Dcx_Analysis ON dbo.[Dcx_Analysis] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis]') AND name = N'IX_Dcx_Analysis') 
CREATE  CLUSTERED INDEX [IX_Dcx_Analysis] ON dbo.[Dcx_Analysis]  
( 
    TypeId, AnalysisId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Chart]') AND name = N'IX_Dcx_Analysis_Chart') 
   DROP index  IX_Dcx_Analysis_Chart ON dbo.[Dcx_Analysis_Chart] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Chart]') AND name = N'IX_Dcx_Analysis_Chart') 
CREATE  CLUSTERED INDEX [IX_Dcx_Analysis_Chart] ON dbo.[Dcx_Analysis_Chart]  
( 
    AnalysisId, Id 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Condition]') AND name = N'IX_Dcx_Analysis_Condition') 
   DROP index  IX_Dcx_Analysis_Condition ON dbo.[Dcx_Analysis_Condition] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Condition]') AND name = N'IX_Dcx_Analysis_Condition') 
CREATE  CLUSTERED INDEX [IX_Dcx_Analysis_Condition] ON dbo.[Dcx_Analysis_Condition]  
( 
    AnalysisId, Id 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Field]') AND name = N'IX_Dcx_Analysis_Field') 
   DROP index  IX_Dcx_Analysis_Field ON dbo.[Dcx_Analysis_Field] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Field]') AND name = N'IX_Dcx_Analysis_Field') 
CREATE  CLUSTERED INDEX [IX_Dcx_Analysis_Field] ON dbo.[Dcx_Analysis_Field]  
( 
    AnalysisId, Id 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BlockListField_Run]') AND name = N'IX_FZET_BlockListField_Run') 
   DROP index  IX_FZET_BlockListField_Run ON dbo.[Dcx_BlockListField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BlockListField_Run]') AND name = N'IX_FZET_BlockListField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_BlockListField_Run] ON dbo.[Dcx_BlockListField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BrowseReportField_Run]') AND name = N'IX_FZET_BrowseReportField_Run') 
   DROP index  IX_FZET_BrowseReportField_Run ON dbo.[Dcx_BrowseReportField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_BrowseReportField_Run]') AND name = N'IX_FZET_BrowseReportField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_BrowseReportField_Run] ON dbo.[Dcx_BrowseReportField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Company]') AND name = N'IX_FZET_Company_ComOrder') 
   DROP index  IX_FZET_Company_ComOrder ON dbo.[Dcx_Company] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Company]') AND name = N'IX_FZET_Company_ComOrder') 
CREATE  NONCLUSTERED INDEX [IX_FZET_Company_ComOrder] ON dbo.[Dcx_Company]  
( 
    ComOrder 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBConnect]') AND name = N'IX_FZET_DBConnect') 
   DROP index  IX_FZET_DBConnect ON dbo.[Dcx_DBConnect] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBConnect]') AND name = N'IX_FZET_DBConnect') 
CREATE  CLUSTERED INDEX [IX_FZET_DBConnect] ON dbo.[Dcx_DBConnect]  
( 
    DBConnectId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableExample]') AND name = N'IX_Dcx_DBTableExample') 
   DROP index  IX_Dcx_DBTableExample ON dbo.[Dcx_DBTableExample] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableExample]') AND name = N'IX_Dcx_DBTableExample') 
CREATE  CLUSTERED INDEX [IX_Dcx_DBTableExample] ON dbo.[Dcx_DBTableExample]  
( 
    TTypeId, DBTableName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableField_Run]') AND name = N'IX_FZET_DBTableField_Run') 
   DROP index  IX_FZET_DBTableField_Run ON dbo.[Dcx_DBTableField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableField_Run]') AND name = N'IX_FZET_DBTableField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_DBTableField_Run] ON dbo.[Dcx_DBTableField_Run]  
( 
    DBTableId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableLog]') AND name = N'IX_Dcx_DBTableLog') 
   DROP index  IX_Dcx_DBTableLog ON dbo.[Dcx_DBTableLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableLog]') AND name = N'IX_Dcx_DBTableLog') 
CREATE  CLUSTERED INDEX [IX_Dcx_DBTableLog] ON dbo.[Dcx_DBTableLog]  
( 
    UserId, Id DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableLog]') AND name = N'IX_Dcx_DBTableLog_1') 
   DROP index  IX_Dcx_DBTableLog_1 ON dbo.[Dcx_DBTableLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableLog]') AND name = N'IX_Dcx_DBTableLog_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_DBTableLog_1] ON dbo.[Dcx_DBTableLog]  
( 
    DBTableId, Id DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableType]') AND name = N'IX_Dcx_DBTableType') 
   DROP index  IX_Dcx_DBTableType ON dbo.[Dcx_DBTableType] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DBTableType]') AND name = N'IX_Dcx_DBTableType') 
CREATE  CLUSTERED INDEX [IX_Dcx_DBTableType] ON dbo.[Dcx_DBTableType]  
( 
    ParentId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultBrowseField_Run]') AND name = N'IX_FZET_DefaultBrowseField_Run') 
   DROP index  IX_FZET_DefaultBrowseField_Run ON dbo.[Dcx_DefaultBrowseField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultBrowseField_Run]') AND name = N'IX_FZET_DefaultBrowseField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_DefaultBrowseField_Run] ON dbo.[Dcx_DefaultBrowseField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultFormField_Run]') AND name = N'IX_FZET_DefaultFormField_Run') 
   DROP index  IX_FZET_DefaultFormField_Run ON dbo.[Dcx_DefaultFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultFormField_Run]') AND name = N'IX_FZET_DefaultFormField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_DefaultFormField_Run] ON dbo.[Dcx_DefaultFormField_Run]  
( 
    Form_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultFormField_Run]') AND name = N'IX_FZET_DefaultFormField_Run_1') 
   DROP index  IX_FZET_DefaultFormField_Run_1 ON dbo.[Dcx_DefaultFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DefaultFormField_Run]') AND name = N'IX_FZET_DefaultFormField_Run_1') 
CREATE  NONCLUSTERED INDEX [IX_FZET_DefaultFormField_Run_1] ON dbo.[Dcx_DefaultFormField_Run]  
( 
    EntId, FldId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_DeptCode') 
   DROP index  IX_FZET_Dept_DeptCode ON dbo.[Dcx_Dept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_DeptCode') 
CREATE unique NONCLUSTERED INDEX [IX_FZET_Dept_DeptCode] ON dbo.[Dcx_Dept]  
( 
    DeptCode 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_DeptName') 
   DROP index  IX_FZET_Dept_DeptName ON dbo.[Dcx_Dept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_DeptName') 
CREATE unique NONCLUSTERED INDEX [IX_FZET_Dept_DeptName] ON dbo.[Dcx_Dept]  
( 
    DeptName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_DeptOrder') 
   DROP index  IX_FZET_Dept_DeptOrder ON dbo.[Dcx_Dept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_DeptOrder') 
CREATE  NONCLUSTERED INDEX [IX_FZET_Dept_DeptOrder] ON dbo.[Dcx_Dept]  
( 
    DeptOrder 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_ParentId') 
   DROP index  IX_FZET_Dept_ParentId ON dbo.[Dcx_Dept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Dept]') AND name = N'IX_FZET_Dept_ParentId') 
CREATE  NONCLUSTERED INDEX [IX_FZET_Dept_ParentId] ON dbo.[Dcx_Dept]  
( 
    ParentId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]') AND name = N'IX_FZET_DeptPrivilege_DeptId') 
   DROP index  IX_FZET_DeptPrivilege_DeptId ON dbo.[Dcx_DeptPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]') AND name = N'IX_FZET_DeptPrivilege_DeptId') 
CREATE  NONCLUSTERED INDEX [IX_FZET_DeptPrivilege_DeptId] ON dbo.[Dcx_DeptPrivilege]  
( 
    DeptId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]') AND name = N'IX_FZET_DeptPrivilege_UserId') 
   DROP index  IX_FZET_DeptPrivilege_UserId ON dbo.[Dcx_DeptPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]') AND name = N'IX_FZET_DeptPrivilege_UserId') 
CREATE  CLUSTERED INDEX [IX_FZET_DeptPrivilege_UserId] ON dbo.[Dcx_DeptPrivilege]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DevelopDiary]') AND name = N'IX_Dcx_DevelopDiary') 
   DROP index  IX_Dcx_DevelopDiary ON dbo.[Dcx_DevelopDiary] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DevelopDiary]') AND name = N'IX_Dcx_DevelopDiary') 
CREATE  CLUSTERED INDEX [IX_Dcx_DevelopDiary] ON dbo.[Dcx_DevelopDiary]  
( 
    CreateTime 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Diary]') AND name = N'IX_Dcx_Diary') 
   DROP index  IX_Dcx_Diary ON dbo.[Dcx_Diary] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Diary]') AND name = N'IX_Dcx_Diary') 
CREATE unique CLUSTERED INDEX [IX_Dcx_Diary] ON dbo.[Dcx_Diary]  
( 
    CreatorId, CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Diary]') AND name = N'IX_Dcx_Diary_1') 
   DROP index  IX_Dcx_Diary_1 ON dbo.[Dcx_Diary] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Diary]') AND name = N'IX_Dcx_Diary_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_Diary_1] ON dbo.[Dcx_Diary]  
( 
    CreatorId, DyId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryPrivilege]') AND name = N'IX_Dcx_DiaryPrivilege') 
   DROP index  IX_Dcx_DiaryPrivilege ON dbo.[Dcx_DiaryPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryPrivilege]') AND name = N'IX_Dcx_DiaryPrivilege') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_DiaryPrivilege] ON dbo.[Dcx_DiaryPrivilege]  
( 
    DyId DESC, UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryReply]') AND name = N'IX_Dcx_DiaryReply') 
   DROP index  IX_Dcx_DiaryReply ON dbo.[Dcx_DiaryReply] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryReply]') AND name = N'IX_Dcx_DiaryReply') 
CREATE  CLUSTERED INDEX [IX_Dcx_DiaryReply] ON dbo.[Dcx_DiaryReply]  
( 
    DyId, CreateTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryTag]') AND name = N'IX_Dcx_DiaryTag') 
   DROP index  IX_Dcx_DiaryTag ON dbo.[Dcx_DiaryTag] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DiaryTag]') AND name = N'IX_Dcx_DiaryTag') 
CREATE  CLUSTERED INDEX [IX_Dcx_DiaryTag] ON dbo.[Dcx_DiaryTag]  
( 
    CreatorId, TagId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DocDownLoad]') AND name = N'IX_Dcx_DocDownLoad_1') 
   DROP index  IX_Dcx_DocDownLoad_1 ON dbo.[Dcx_DocDownLoad] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DocDownLoad]') AND name = N'IX_Dcx_DocDownLoad_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_DocDownLoad_1] ON dbo.[Dcx_DocDownLoad]  
( 
    FileId, CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DocDownLoad]') AND name = N'IX_Dcx_DocDownLoad_2') 
   DROP index  IX_Dcx_DocDownLoad_2 ON dbo.[Dcx_DocDownLoad] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DocDownLoad]') AND name = N'IX_Dcx_DocDownLoad_2') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_DocDownLoad_2] ON dbo.[Dcx_DocDownLoad]  
( 
    CreatorId, CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Document]') AND name = N'IX_Dcx_Document_1') 
   DROP index  IX_Dcx_Document_1 ON dbo.[Dcx_Document] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Document]') AND name = N'IX_Dcx_Document_1') 
CREATE  CLUSTERED INDEX [IX_Dcx_Document_1] ON dbo.[Dcx_Document]  
( 
    CreatorId, ParentId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Document]') AND name = N'IX_Dcx_Document_2') 
   DROP index  IX_Dcx_Document_2 ON dbo.[Dcx_Document] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Document]') AND name = N'IX_Dcx_Document_2') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_Document_2] ON dbo.[Dcx_Document]  
( 
    CreatorId, FileId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Employee]') AND name = N'IX_Dcx_Employee') 
   DROP index  IX_Dcx_Employee ON dbo.[Dcx_Employee] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Employee]') AND name = N'IX_Dcx_Employee') 
CREATE unique NONCLUSTERED INDEX [IX_Dcx_Employee] ON dbo.[Dcx_Employee]  
( 
    EmployeeCode 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Entity_Attachment]') AND name = N'IX_Dcx_Entity_Attachment') 
   DROP index  IX_Dcx_Entity_Attachment ON dbo.[Dcx_Entity_Attachment] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Entity_Attachment]') AND name = N'IX_Dcx_Entity_Attachment') 
CREATE  CLUSTERED INDEX [IX_Dcx_Entity_Attachment] ON dbo.[Dcx_Entity_Attachment]  
( 
    EntId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Entity_Run]') AND name = N'IX_FZET_Entity_Run') 
   DROP index  IX_FZET_Entity_Run ON dbo.[Dcx_Entity_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Entity_Run]') AND name = N'IX_FZET_Entity_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_Entity_Run] ON dbo.[Dcx_Entity_Run]  
( 
    MenuId, EntId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND name = N'IX_FZET_EntityPrivilege') 
   DROP index  IX_FZET_EntityPrivilege ON dbo.[Dcx_EntityPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND name = N'IX_FZET_EntityPrivilege') 
CREATE  CLUSTERED INDEX [IX_FZET_EntityPrivilege] ON dbo.[Dcx_EntityPrivilege]  
( 
    EntId, RoleId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND name = N'IX_FZET_EntityPrivilege_1') 
   DROP index  IX_FZET_EntityPrivilege_1 ON dbo.[Dcx_EntityPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND name = N'IX_FZET_EntityPrivilege_1') 
CREATE unique NONCLUSTERED INDEX [IX_FZET_EntityPrivilege_1] ON dbo.[Dcx_EntityPrivilege]  
( 
    EntityPrivilegeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND name = N'IX_FZET_EntityPrivilege_2') 
   DROP index  IX_FZET_EntityPrivilege_2 ON dbo.[Dcx_EntityPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]') AND name = N'IX_FZET_EntityPrivilege_2') 
CREATE  NONCLUSTERED INDEX [IX_FZET_EntityPrivilege_2] ON dbo.[Dcx_EntityPrivilege]  
( 
    MenuId, EntId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FilterViewCondition_Run]') AND name = N'IX_FZET_FilterViewCondition_Run') 
   DROP index  IX_FZET_FilterViewCondition_Run ON dbo.[Dcx_FilterViewCondition_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FilterViewCondition_Run]') AND name = N'IX_FZET_FilterViewCondition_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_FilterViewCondition_Run] ON dbo.[Dcx_FilterViewCondition_Run]  
( 
    EntId, ViewOptionId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Folder]') AND name = N'IX_hyoa_folder') 
   DROP index  IX_hyoa_folder ON dbo.[Dcx_Folder] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Folder]') AND name = N'IX_hyoa_folder') 
CREATE  NONCLUSTERED INDEX [IX_hyoa_folder] ON dbo.[Dcx_Folder]  
( 
    fatherId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FolderView]') AND name = N'IX_hyoa_folderView') 
   DROP index  IX_hyoa_folderView ON dbo.[Dcx_FolderView] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FolderView]') AND name = N'IX_hyoa_folderView') 
CREATE  NONCLUSTERED INDEX [IX_hyoa_folderView] ON dbo.[Dcx_FolderView]  
( 
    userId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FolderView]') AND name = N'IX_hyoa_folderView_1') 
   DROP index  IX_hyoa_folderView_1 ON dbo.[Dcx_FolderView] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FolderView]') AND name = N'IX_hyoa_folderView_1') 
CREATE  NONCLUSTERED INDEX [IX_hyoa_folderView_1] ON dbo.[Dcx_FolderView]  
( 
    folderId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FormDataSource_Run]') AND name = N'IX_FZET_FormDataSource_Run') 
   DROP index  IX_FZET_FormDataSource_Run ON dbo.[Dcx_FormDataSource_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_FormDataSource_Run]') AND name = N'IX_FZET_FormDataSource_Run') 
CREATE  NONCLUSTERED INDEX [IX_FZET_FormDataSource_Run] ON dbo.[Dcx_FormDataSource_Run]  
( 
    EntId, DsId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupInterfaceField_Run]') AND name = N'IX_FZET_GroupInterfaceField_Run') 
   DROP index  IX_FZET_GroupInterfaceField_Run ON dbo.[Dcx_GroupInterfaceField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupInterfaceField_Run]') AND name = N'IX_FZET_GroupInterfaceField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_GroupInterfaceField_Run] ON dbo.[Dcx_GroupInterfaceField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupReportField_Run]') AND name = N'IX_FZET_GroupReportField_Run') 
   DROP index  IX_FZET_GroupReportField_Run ON dbo.[Dcx_GroupReportField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GroupReportField_Run]') AND name = N'IX_FZET_GroupReportField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_GroupReportField_Run] ON dbo.[Dcx_GroupReportField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_HomePage]') AND name = N'IX_Dcx_HomePage') 
   DROP index  IX_Dcx_HomePage ON dbo.[Dcx_HomePage] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_HomePage]') AND name = N'IX_Dcx_HomePage') 
CREATE  CLUSTERED INDEX [IX_Dcx_HomePage] ON dbo.[Dcx_HomePage]  
( 
    UserId, SortOrder 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMail]') AND name = N'IX_Dcx_IMail') 
   DROP index  IX_Dcx_IMail ON dbo.[Dcx_IMail] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMail]') AND name = N'IX_Dcx_IMail') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMail] ON dbo.[Dcx_IMail]  
( 
    SenderUserId, SenderDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMail_Attachment]') AND name = N'IX_Dcx_IMail_Attachment') 
   DROP index  IX_Dcx_IMail_Attachment ON dbo.[Dcx_IMail_Attachment] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMail_Attachment]') AND name = N'IX_Dcx_IMail_Attachment') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMail_Attachment] ON dbo.[Dcx_IMail_Attachment]  
( 
    MailId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMailReceiver]') AND name = N'IX_Dcx_IMailReceiver') 
   DROP index  IX_Dcx_IMailReceiver ON dbo.[Dcx_IMailReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMailReceiver]') AND name = N'IX_Dcx_IMailReceiver') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMailReceiver] ON dbo.[Dcx_IMailReceiver]  
( 
    UserId, MailId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMailReceiver]') AND name = N'IX_Dcx_IMailReceiver_1') 
   DROP index  IX_Dcx_IMailReceiver_1 ON dbo.[Dcx_IMailReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMailReceiver]') AND name = N'IX_Dcx_IMailReceiver_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_IMailReceiver_1] ON dbo.[Dcx_IMailReceiver]  
( 
    MailId, UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMAttachment]') AND name = N'IX_Dcx_IMAttachment') 
   DROP index  IX_Dcx_IMAttachment ON dbo.[Dcx_IMAttachment] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMAttachment]') AND name = N'IX_Dcx_IMAttachment') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMAttachment] ON dbo.[Dcx_IMAttachment]  
( 
    MsgId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMessage]') AND name = N'IX_Dcx_IMessage') 
   DROP index  IX_Dcx_IMessage ON dbo.[Dcx_IMessage] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMessage]') AND name = N'IX_Dcx_IMessage') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMessage] ON dbo.[Dcx_IMessage]  
( 
    SentDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMessage]') AND name = N'IX_Dcx_IMessage_1') 
   DROP index  IX_Dcx_IMessage_1 ON dbo.[Dcx_IMessage] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMessage]') AND name = N'IX_Dcx_IMessage_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_IMessage_1] ON dbo.[Dcx_IMessage]  
( 
    ReceiverId, SenderId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ImgSummyListField_Run]') AND name = N'IX_FZET_ImgSummyListField_Run') 
   DROP index  IX_FZET_ImgSummyListField_Run ON dbo.[Dcx_ImgSummyListField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ImgSummyListField_Run]') AND name = N'IX_FZET_ImgSummyListField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_ImgSummyListField_Run] ON dbo.[Dcx_ImgSummyListField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRelationship]') AND name = N'IX_Dcx_IMRelationship') 
   DROP index  IX_Dcx_IMRelationship ON dbo.[Dcx_IMRelationship] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRelationship]') AND name = N'IX_Dcx_IMRelationship') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMRelationship] ON dbo.[Dcx_IMRelationship]  
( 
    HostUserId, LastTalkDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRelationship]') AND name = N'IX_Dcx_IMRelationship_1') 
   DROP index  IX_Dcx_IMRelationship_1 ON dbo.[Dcx_IMRelationship] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRelationship]') AND name = N'IX_Dcx_IMRelationship_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_IMRelationship_1] ON dbo.[Dcx_IMRelationship]  
( 
    GuestUserId, HostUserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoom]') AND name = N'IX_Dcx_IMGroup') 
   DROP index  IX_Dcx_IMGroup ON dbo.[Dcx_IMRoom] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoom]') AND name = N'IX_Dcx_IMGroup') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_IMGroup] ON dbo.[Dcx_IMRoom]  
( 
    CreatorId, RoomId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomLgr]') AND name = N'IX_Dcx_IMGroupLgr') 
   DROP index  IX_Dcx_IMGroupLgr ON dbo.[Dcx_IMRoomLgr] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomLgr]') AND name = N'IX_Dcx_IMGroupLgr') 
CREATE  CLUSTERED INDEX [IX_Dcx_IMGroupLgr] ON dbo.[Dcx_IMRoomLgr]  
( 
    RoomId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomLgr]') AND name = N'IX_Dcx_IMGroupLgr_1') 
   DROP index  IX_Dcx_IMGroupLgr_1 ON dbo.[Dcx_IMRoomLgr] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomLgr]') AND name = N'IX_Dcx_IMGroupLgr_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_IMGroupLgr_1] ON dbo.[Dcx_IMRoomLgr]  
( 
    RoomId, UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomMsg]') AND name = N'IX_DcxIMGroupMsg') 
   DROP index  IX_DcxIMGroupMsg ON dbo.[Dcx_IMRoomMsg] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomMsg]') AND name = N'IX_DcxIMGroupMsg') 
CREATE  CLUSTERED INDEX [IX_DcxIMGroupMsg] ON dbo.[Dcx_IMRoomMsg]  
( 
    RoomId, SentDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LinkMan]') AND name = N'IX_Dcx_LinkMan') 
   DROP index  IX_Dcx_LinkMan ON dbo.[Dcx_LinkMan] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LinkMan]') AND name = N'IX_Dcx_LinkMan') 
CREATE  CLUSTERED INDEX [IX_Dcx_LinkMan] ON dbo.[Dcx_LinkMan]  
( 
    CreatorId, GroupId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LinkManGroup]') AND name = N'IX_Dcx_LinkManGroup') 
   DROP index  IX_Dcx_LinkManGroup ON dbo.[Dcx_LinkManGroup] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_LinkManGroup]') AND name = N'IX_Dcx_LinkManGroup') 
CREATE  CLUSTERED INDEX [IX_Dcx_LinkManGroup] ON dbo.[Dcx_LinkManGroup]  
( 
    CreatorId, GroupId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListFormField_Run]') AND name = N'IX_FZET_ListFormField_Run') 
   DROP index  IX_FZET_ListFormField_Run ON dbo.[Dcx_ListFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListFormField_Run]') AND name = N'IX_FZET_ListFormField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_ListFormField_Run] ON dbo.[Dcx_ListFormField_Run]  
( 
    Form_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListReportField_Run]') AND name = N'IX_FZET_ListReportField_Run') 
   DROP index  IX_FZET_ListReportField_Run ON dbo.[Dcx_ListReportField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListReportField_Run]') AND name = N'IX_FZET_ListReportField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_ListReportField_Run] ON dbo.[Dcx_ListReportField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListReportField_Run]') AND name = N'IX_FZET_ListReportField_Run_1') 
   DROP index  IX_FZET_ListReportField_Run_1 ON dbo.[Dcx_ListReportField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_ListReportField_Run]') AND name = N'IX_FZET_ListReportField_Run_1') 
CREATE  NONCLUSTERED INDEX [IX_FZET_ListReportField_Run_1] ON dbo.[Dcx_ListReportField_Run]  
( 
    EntId, FldId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND name = N'IX_Dcx_MailReceiver') 
   DROP index  IX_Dcx_MailReceiver ON dbo.[Dcx_MailReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND name = N'IX_Dcx_MailReceiver') 
CREATE  CLUSTERED INDEX [IX_Dcx_MailReceiver] ON dbo.[Dcx_MailReceiver]  
( 
    UserId, MailId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND name = N'IX_Dcx_MailReceiver_1') 
   DROP index  IX_Dcx_MailReceiver_1 ON dbo.[Dcx_MailReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND name = N'IX_Dcx_MailReceiver_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_MailReceiver_1] ON dbo.[Dcx_MailReceiver]  
( 
    MailId, UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND name = N'IX_Dcx_MailReceiver_2') 
   DROP index  IX_Dcx_MailReceiver_2 ON dbo.[Dcx_MailReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]') AND name = N'IX_Dcx_MailReceiver_2') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_MailReceiver_2] ON dbo.[Dcx_MailReceiver]  
( 
    ToEmailAddr, MailId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuAppArea]') AND name = N'IX_FZET_MenuEntityModule') 
   DROP index  IX_FZET_MenuEntityModule ON dbo.[Dcx_MenuAppArea] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuAppArea]') AND name = N'IX_FZET_MenuEntityModule') 
CREATE  CLUSTERED INDEX [IX_FZET_MenuEntityModule] ON dbo.[Dcx_MenuAppArea]  
( 
    MenuId, EntId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuLog]') AND name = N'IX_Dcx_MenuLog') 
   DROP index  IX_Dcx_MenuLog ON dbo.[Dcx_MenuLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuLog]') AND name = N'IX_Dcx_MenuLog') 
CREATE  CLUSTERED INDEX [IX_Dcx_MenuLog] ON dbo.[Dcx_MenuLog]  
( 
    UserId, Id DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuLog]') AND name = N'IX_Dcx_MenuLog_1') 
   DROP index  IX_Dcx_MenuLog_1 ON dbo.[Dcx_MenuLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuLog]') AND name = N'IX_Dcx_MenuLog_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_MenuLog_1] ON dbo.[Dcx_MenuLog]  
( 
    MenuId, Id DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilege]') AND name = N'IX_FZET_MenuPrivilege_MenuId_RoleId') 
   DROP index  IX_FZET_MenuPrivilege_MenuId_RoleId ON dbo.[Dcx_MenuPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilege]') AND name = N'IX_FZET_MenuPrivilege_MenuId_RoleId') 
CREATE  CLUSTERED INDEX [IX_FZET_MenuPrivilege_MenuId_RoleId] ON dbo.[Dcx_MenuPrivilege]  
( 
    MenuId, RoleId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuRelated]') AND name = N'IX_Dcx_MenuRelated') 
   DROP index  IX_Dcx_MenuRelated ON dbo.[Dcx_MenuRelated] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuRelated]') AND name = N'IX_Dcx_MenuRelated') 
CREATE  CLUSTERED INDEX [IX_Dcx_MenuRelated] ON dbo.[Dcx_MenuRelated]  
( 
    TypeId, MenuId, OrderNo 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuType]') AND name = N'IX_Dcx_MenuType') 
   DROP index  IX_Dcx_MenuType ON dbo.[Dcx_MenuType] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuType]') AND name = N'IX_Dcx_MenuType') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_MenuType] ON dbo.[Dcx_MenuType]  
( 
    ParentId, SortOrder 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Message]') AND name = N'IX_Dcx_Message') 
   DROP index  IX_Dcx_Message ON dbo.[Dcx_Message] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Message]') AND name = N'IX_Dcx_Message') 
CREATE  CLUSTERED INDEX [IX_Dcx_Message] ON dbo.[Dcx_Message]  
( 
    SenderId, MsgId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageReceiver]') AND name = N'IX_Dcx_MessageReceiver_2') 
   DROP index  IX_Dcx_MessageReceiver_2 ON dbo.[Dcx_MessageReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageReceiver]') AND name = N'IX_Dcx_MessageReceiver_2') 
CREATE unique CLUSTERED INDEX [IX_Dcx_MessageReceiver_2] ON dbo.[Dcx_MessageReceiver]  
( 
    ReceiverId, MsgId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageReply]') AND name = N'IX_Dcx_MessageReply') 
   DROP index  IX_Dcx_MessageReply ON dbo.[Dcx_MessageReply] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageReply]') AND name = N'IX_Dcx_MessageReply') 
CREATE  CLUSTERED INDEX [IX_Dcx_MessageReply] ON dbo.[Dcx_MessageReply]  
( 
    SnederId, MsgId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageType]') AND name = N'IX_Dcx_INoteCenter') 
   DROP index  IX_Dcx_INoteCenter ON dbo.[Dcx_MessageType] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageType]') AND name = N'IX_Dcx_INoteCenter') 
CREATE  CLUSTERED INDEX [IX_Dcx_INoteCenter] ON dbo.[Dcx_MessageType]  
( 
    EntId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageTypeReceiver]') AND name = N'IX_Dcx_MessageReceiver') 
   DROP index  IX_Dcx_MessageReceiver ON dbo.[Dcx_MessageTypeReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageTypeReceiver]') AND name = N'IX_Dcx_MessageReceiver') 
CREATE  CLUSTERED INDEX [IX_Dcx_MessageReceiver] ON dbo.[Dcx_MessageTypeReceiver]  
( 
    EntId, Id 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageTypeReceiver]') AND name = N'IX_Dcx_MessageReceiver_1') 
   DROP index  IX_Dcx_MessageReceiver_1 ON dbo.[Dcx_MessageTypeReceiver] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MessageTypeReceiver]') AND name = N'IX_Dcx_MessageReceiver_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_MessageReceiver_1] ON dbo.[Dcx_MessageTypeReceiver]  
( 
    MsgTypeId, Id 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NavMenu]') AND name = N'IX_Dcx_NavMenu') 
   DROP index  IX_Dcx_NavMenu ON dbo.[Dcx_NavMenu] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NavMenu]') AND name = N'IX_Dcx_NavMenu') 
CREATE  CLUSTERED INDEX [IX_Dcx_NavMenu] ON dbo.[Dcx_NavMenu]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_News]') AND name = N'IX_Dcx_News') 
   DROP index  IX_Dcx_News ON dbo.[Dcx_News] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_News]') AND name = N'IX_Dcx_News') 
CREATE unique CLUSTERED INDEX [IX_Dcx_News] ON dbo.[Dcx_News]  
( 
    CreatorId, CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_News]') AND name = N'IX_Dcx_News_1') 
   DROP index  IX_Dcx_News_1 ON dbo.[Dcx_News] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_News]') AND name = N'IX_Dcx_News_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_News_1] ON dbo.[Dcx_News]  
( 
    CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsFile]') AND name = N'IX_Dcx_NewsFile') 
   DROP index  IX_Dcx_NewsFile ON dbo.[Dcx_NewsFile] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsFile]') AND name = N'IX_Dcx_NewsFile') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_NewsFile] ON dbo.[Dcx_NewsFile]  
( 
    CreatorId, CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsPrivilege]') AND name = N'IX_Dcx_NewsPrivilege') 
   DROP index  IX_Dcx_NewsPrivilege ON dbo.[Dcx_NewsPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_NewsPrivilege]') AND name = N'IX_Dcx_NewsPrivilege') 
CREATE  CLUSTERED INDEX [IX_Dcx_NewsPrivilege] ON dbo.[Dcx_NewsPrivilege]  
( 
    DeptId, NewsId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND name = N'IX_FZET_OnlineUser_IP') 
   DROP index  IX_FZET_OnlineUser_IP ON dbo.[Dcx_OnlineUser] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND name = N'IX_FZET_OnlineUser_IP') 
CREATE  NONCLUSTERED INDEX [IX_FZET_OnlineUser_IP] ON dbo.[Dcx_OnlineUser]  
( 
    IP 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND name = N'IX_FZET_OnlineUser_LoginTime') 
   DROP index  IX_FZET_OnlineUser_LoginTime ON dbo.[Dcx_OnlineUser] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND name = N'IX_FZET_OnlineUser_LoginTime') 
CREATE  NONCLUSTERED INDEX [IX_FZET_OnlineUser_LoginTime] ON dbo.[Dcx_OnlineUser]  
( 
    LoginTime 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND name = N'IX_FZET_OnlineUser_UserName') 
   DROP index  IX_FZET_OnlineUser_UserName ON dbo.[Dcx_OnlineUser] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUser]') AND name = N'IX_FZET_OnlineUser_UserName') 
CREATE  NONCLUSTERED INDEX [IX_FZET_OnlineUser_UserName] ON dbo.[Dcx_OnlineUser]  
( 
    UserName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OutPutField_Run]') AND name = N'IX_FZET_OutPutField_Run') 
   DROP index  IX_FZET_OutPutField_Run ON dbo.[Dcx_OutPutField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OutPutField_Run]') AND name = N'IX_FZET_OutPutField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_OutPutField_Run] ON dbo.[Dcx_OutPutField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish]') AND name = N'IX_Dcx_Publish') 
   DROP index  IX_Dcx_Publish ON dbo.[Dcx_Publish] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish]') AND name = N'IX_Dcx_Publish') 
CREATE  CLUSTERED INDEX [IX_Dcx_Publish] ON dbo.[Dcx_Publish]  
( 
    ReceiveTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Question]') AND name = N'IX_Dcx_Question') 
   DROP index  IX_Dcx_Question ON dbo.[Dcx_Question] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Question]') AND name = N'IX_Dcx_Question') 
CREATE unique CLUSTERED INDEX [IX_Dcx_Question] ON dbo.[Dcx_Question]  
( 
    CreateTime 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Question]') AND name = N'IX_Dcx_Question_1') 
   DROP index  IX_Dcx_Question_1 ON dbo.[Dcx_Question] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Question]') AND name = N'IX_Dcx_Question_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_Question_1] ON dbo.[Dcx_Question]  
( 
    CreatorId, QId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_QuestionAnwser]') AND name = N'IX_Dcx_QuestionAnwser') 
   DROP index  IX_Dcx_QuestionAnwser ON dbo.[Dcx_QuestionAnwser] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_QuestionAnwser]') AND name = N'IX_Dcx_QuestionAnwser') 
CREATE  CLUSTERED INDEX [IX_Dcx_QuestionAnwser] ON dbo.[Dcx_QuestionAnwser]  
( 
    QId, CreateTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Remind]') AND name = N'IX_Dcx_Remind') 
   DROP index  IX_Dcx_Remind ON dbo.[Dcx_Remind] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Remind]') AND name = N'IX_Dcx_Remind') 
CREATE  CLUSTERED INDEX [IX_Dcx_Remind] ON dbo.[Dcx_Remind]  
( 
    CreatorId, RemindDate 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Remind]') AND name = N'IX_Dcx_Remind_1') 
   DROP index  IX_Dcx_Remind_1 ON dbo.[Dcx_Remind] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Remind]') AND name = N'IX_Dcx_Remind_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_Remind_1] ON dbo.[Dcx_Remind]  
( 
    CreatorId, KeyFieldValue 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Role]') AND name = N'IX_EWorkRoles') 
   DROP index  IX_EWorkRoles ON dbo.[Dcx_Role] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Role]') AND name = N'IX_EWorkRoles') 
CREATE unique NONCLUSTERED INDEX [IX_EWorkRoles] ON dbo.[Dcx_Role]  
( 
    RoleName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Role]') AND name = N'IX_EWorkRoles_1') 
   DROP index  IX_EWorkRoles_1 ON dbo.[Dcx_Role] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Role]') AND name = N'IX_EWorkRoles_1') 
CREATE unique NONCLUSTERED INDEX [IX_EWorkRoles_1] ON dbo.[Dcx_Role]  
( 
    RoleId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Schedule]') AND name = N'IX_Dcx_Schedule') 
   DROP index  IX_Dcx_Schedule ON dbo.[Dcx_Schedule] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Schedule]') AND name = N'IX_Dcx_Schedule') 
CREATE  CLUSTERED INDEX [IX_Dcx_Schedule] ON dbo.[Dcx_Schedule]  
( 
    CreatorId, CreateTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchFormField_Run]') AND name = N'IX_FZET_SearchFormField_Run') 
   DROP index  IX_FZET_SearchFormField_Run ON dbo.[Dcx_SearchFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchFormField_Run]') AND name = N'IX_FZET_SearchFormField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_SearchFormField_Run] ON dbo.[Dcx_SearchFormField_Run]  
( 
    Form_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchFormField_Run]') AND name = N'IX_FZET_SearchFormField_Run_1') 
   DROP index  IX_FZET_SearchFormField_Run_1 ON dbo.[Dcx_SearchFormField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchFormField_Run]') AND name = N'IX_FZET_SearchFormField_Run_1') 
CREATE  NONCLUSTERED INDEX [IX_FZET_SearchFormField_Run_1] ON dbo.[Dcx_SearchFormField_Run]  
( 
    EntId, FldId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchItemInUser]') AND name = N'IX_Dcx_SearchItemInUser') 
   DROP index  IX_Dcx_SearchItemInUser ON dbo.[Dcx_SearchItemInUser] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SearchItemInUser]') AND name = N'IX_Dcx_SearchItemInUser') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_SearchItemInUser] ON dbo.[Dcx_SearchItemInUser]  
( 
    UserId, SortOrder 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SiteVisit]') AND name = N'IX_Dcx_SiteVisit') 
   DROP index  IX_Dcx_SiteVisit ON dbo.[Dcx_SiteVisit] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SiteVisit]') AND name = N'IX_Dcx_SiteVisit') 
CREATE unique CLUSTERED INDEX [IX_Dcx_SiteVisit] ON dbo.[Dcx_SiteVisit]  
( 
    PageId, Time DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SQLParameter_Run]') AND name = N'IX_FZET_SQLParameter_Run') 
   DROP index  IX_FZET_SQLParameter_Run ON dbo.[Dcx_SQLParameter_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SQLParameter_Run]') AND name = N'IX_FZET_SQLParameter_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_SQLParameter_Run] ON dbo.[Dcx_SQLParameter_Run]  
( 
    EntId, ModuleTypeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SummaryListField_Run]') AND name = N'IX_FZET_SummaryListField_Run') 
   DROP index  IX_FZET_SummaryListField_Run ON dbo.[Dcx_SummaryListField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SummaryListField_Run]') AND name = N'IX_FZET_SummaryListField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_SummaryListField_Run] ON dbo.[Dcx_SummaryListField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SysCtrl_Address]') AND name = N'IX_FZET_SysAddress') 
   DROP index  IX_FZET_SysAddress ON dbo.[Dcx_SysCtrl_Address] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SysCtrl_Address]') AND name = N'IX_FZET_SysAddress') 
CREATE  CLUSTERED INDEX [IX_FZET_SysAddress] ON dbo.[Dcx_SysCtrl_Address]  
( 
    ParentId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemLoginLog]') AND name = N'IX_FZET_SystemLoginLog_IP') 
   DROP index  IX_FZET_SystemLoginLog_IP ON dbo.[Dcx_SystemLoginLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemLoginLog]') AND name = N'IX_FZET_SystemLoginLog_IP') 
CREATE  NONCLUSTERED INDEX [IX_FZET_SystemLoginLog_IP] ON dbo.[Dcx_SystemLoginLog]  
( 
    IP 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemLoginLog]') AND name = N'IX_FZET_SystemLoginLog_LoginTime') 
   DROP index  IX_FZET_SystemLoginLog_LoginTime ON dbo.[Dcx_SystemLoginLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemLoginLog]') AND name = N'IX_FZET_SystemLoginLog_LoginTime') 
CREATE  CLUSTERED INDEX [IX_FZET_SystemLoginLog_LoginTime] ON dbo.[Dcx_SystemLoginLog]  
( 
    LoginTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND name = N'IX_FZET_SystemOperateLog') 
   DROP index  IX_FZET_SystemOperateLog ON dbo.[Dcx_SystemOperateLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND name = N'IX_FZET_SystemOperateLog') 
CREATE  NONCLUSTERED INDEX [IX_FZET_SystemOperateLog] ON dbo.[Dcx_SystemOperateLog]  
( 
    UserName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND name = N'IX_FZET_SystemOperateLog_1') 
   DROP index  IX_FZET_SystemOperateLog_1 ON dbo.[Dcx_SystemOperateLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND name = N'IX_FZET_SystemOperateLog_1') 
CREATE  NONCLUSTERED INDEX [IX_FZET_SystemOperateLog_1] ON dbo.[Dcx_SystemOperateLog]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND name = N'IX_FZET_SystemOperateLog_OperateTime') 
   DROP index  IX_FZET_SystemOperateLog_OperateTime ON dbo.[Dcx_SystemOperateLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemOperateLog]') AND name = N'IX_FZET_SystemOperateLog_OperateTime') 
CREATE  CLUSTERED INDEX [IX_FZET_SystemOperateLog_OperateTime] ON dbo.[Dcx_SystemOperateLog]  
( 
    OperateTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemParameter]') AND name = N'IX_FZET_SystemParameter') 
   DROP index  IX_FZET_SystemParameter ON dbo.[Dcx_SystemParameter] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemParameter]') AND name = N'IX_FZET_SystemParameter') 
CREATE  NONCLUSTERED INDEX [IX_FZET_SystemParameter] ON dbo.[Dcx_SystemParameter]  
( 
    GroupId, ParentId, Id 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TemplateArea_Run]') AND name = N'IX_FZET_TemplateArea_Run') 
   DROP index  IX_FZET_TemplateArea_Run ON dbo.[Dcx_TemplateArea_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TemplateArea_Run]') AND name = N'IX_FZET_TemplateArea_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_TemplateArea_Run] ON dbo.[Dcx_TemplateArea_Run]  
( 
    MenuId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TitleListField_Run]') AND name = N'IX_FZET_TitleListField_Run') 
   DROP index  IX_FZET_TitleListField_Run ON dbo.[Dcx_TitleListField_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TitleListField_Run]') AND name = N'IX_FZET_TitleListField_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_TitleListField_Run] ON dbo.[Dcx_TitleListField_Run]  
( 
    Report_EntId, FieldNO 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Trade]') AND name = N'IX_Dcx_Trade') 
   DROP index  IX_Dcx_Trade ON dbo.[Dcx_Trade] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Trade]') AND name = N'IX_Dcx_Trade') 
CREATE  CLUSTERED INDEX [IX_Dcx_Trade] ON dbo.[Dcx_Trade]  
( 
    SortOrder, TradeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Tree_Run]') AND name = N'IX_FZET_EntityTree') 
   DROP index  IX_FZET_EntityTree ON dbo.[Dcx_Tree_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Tree_Run]') AND name = N'IX_FZET_EntityTree') 
CREATE  NONCLUSTERED INDEX [IX_FZET_EntityTree] ON dbo.[Dcx_Tree_Run]  
( 
    EntId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TreeCell_Run]') AND name = N'IX_FZET_TreeCell_Run') 
   DROP index  IX_FZET_TreeCell_Run ON dbo.[Dcx_TreeCell_Run] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TreeCell_Run]') AND name = N'IX_FZET_TreeCell_Run') 
CREATE  CLUSTERED INDEX [IX_FZET_TreeCell_Run] ON dbo.[Dcx_TreeCell_Run]  
( 
    TreeId, CellNo 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND name = N'IX_FZET_User') 
   DROP index  IX_FZET_User ON dbo.[Dcx_User] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND name = N'IX_FZET_User') 
CREATE  NONCLUSTERED INDEX [IX_FZET_User] ON dbo.[Dcx_User]  
( 
    AccountId, UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND name = N'IX_FZET_User_1') 
   DROP index  IX_FZET_User_1 ON dbo.[Dcx_User] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND name = N'IX_FZET_User_1') 
CREATE unique NONCLUSTERED INDEX [IX_FZET_User_1] ON dbo.[Dcx_User]  
( 
    Email 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND name = N'IX_FZET_User_UserName') 
   DROP index  IX_FZET_User_UserName ON dbo.[Dcx_User] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User]') AND name = N'IX_FZET_User_UserName') 
CREATE unique NONCLUSTERED INDEX [IX_FZET_User_UserName] ON dbo.[Dcx_User]  
( 
    UserName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserApply]') AND name = N'IX_Dcx_UserApply') 
   DROP index  IX_Dcx_UserApply ON dbo.[Dcx_UserApply] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserApply]') AND name = N'IX_Dcx_UserApply') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_UserApply] ON dbo.[Dcx_UserApply]  
( 
    Email 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND name = N'IX_FZET_UserInDept_DeptId') 
   DROP index  IX_FZET_UserInDept_DeptId ON dbo.[Dcx_UserInDept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND name = N'IX_FZET_UserInDept_DeptId') 
CREATE  CLUSTERED INDEX [IX_FZET_UserInDept_DeptId] ON dbo.[Dcx_UserInDept]  
( 
    DeptId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND name = N'IX_FZET_UserInDept_EmployeeId') 
   DROP index  IX_FZET_UserInDept_EmployeeId ON dbo.[Dcx_UserInDept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND name = N'IX_FZET_UserInDept_EmployeeId') 
CREATE  NONCLUSTERED INDEX [IX_FZET_UserInDept_EmployeeId] ON dbo.[Dcx_UserInDept]  
( 
    EmployeeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND name = N'IX_FZET_UserInDept_UserId') 
   DROP index  IX_FZET_UserInDept_UserId ON dbo.[Dcx_UserInDept] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInDept]') AND name = N'IX_FZET_UserInDept_UserId') 
CREATE  NONCLUSTERED INDEX [IX_FZET_UserInDept_UserId] ON dbo.[Dcx_UserInDept]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInRole]') AND name = N'IX_FZET_UserInRole_UserId') 
   DROP index  IX_FZET_UserInRole_UserId ON dbo.[Dcx_UserInRole] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInRole]') AND name = N'IX_FZET_UserInRole_UserId') 
CREATE  CLUSTERED INDEX [IX_FZET_UserInRole_UserId] ON dbo.[Dcx_UserInRole]  
( 
    UserId, RoleId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInSystem]') AND name = N'IX_FZET_UserInSystem') 
   DROP index  IX_FZET_UserInSystem ON dbo.[Dcx_UserInSystem] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInSystem]') AND name = N'IX_FZET_UserInSystem') 
CREATE  CLUSTERED INDEX [IX_FZET_UserInSystem] ON dbo.[Dcx_UserInSystem]  
( 
    SystemId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInSystem]') AND name = N'IX_FZET_UserInSystem_1') 
   DROP index  IX_FZET_UserInSystem_1 ON dbo.[Dcx_UserInSystem] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInSystem]') AND name = N'IX_FZET_UserInSystem_1') 
CREATE  NONCLUSTERED INDEX [IX_FZET_UserInSystem_1] ON dbo.[Dcx_UserInSystem]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInvite]') AND name = N'IX_Dcx_UserInvite') 
   DROP index  IX_Dcx_UserInvite ON dbo.[Dcx_UserInvite] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInvite]') AND name = N'IX_Dcx_UserInvite') 
CREATE unique NONCLUSTERED INDEX [IX_Dcx_UserInvite] ON dbo.[Dcx_UserInvite]  
( 
    InviteCode 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInvite]') AND name = N'IX_Dcx_UserInvite_1') 
   DROP index  IX_Dcx_UserInvite_1 ON dbo.[Dcx_UserInvite] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserInvite]') AND name = N'IX_Dcx_UserInvite_1') 
CREATE unique NONCLUSTERED INDEX [IX_Dcx_UserInvite_1] ON dbo.[Dcx_UserInvite]  
( 
    Email 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Video]') AND name = N'IX_Dcx_Video') 
   DROP index  IX_Dcx_Video ON dbo.[Dcx_Video] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Video]') AND name = N'IX_Dcx_Video') 
CREATE  CLUSTERED INDEX [IX_Dcx_Video] ON dbo.[Dcx_Video]  
( 
    TopTypeId, IsTop DESC, IsPopular DESC, SortOrder, TypeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Video]') AND name = N'IX_Dcx_Video_1') 
   DROP index  IX_Dcx_Video_1 ON dbo.[Dcx_Video] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Video]') AND name = N'IX_Dcx_Video_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_Video_1] ON dbo.[Dcx_Video]  
( 
    VideoName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_VideoType]') AND name = N'IX_Dcx_VideoType') 
   DROP index  IX_Dcx_VideoType ON dbo.[Dcx_VideoType] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_VideoType]') AND name = N'IX_Dcx_VideoType') 
CREATE unique CLUSTERED INDEX [IX_Dcx_VideoType] ON dbo.[Dcx_VideoType]  
( 
    GroupId, ParentId, TypeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBo]') AND name = N'IX_Dcx_WeiBo') 
   DROP index  IX_Dcx_WeiBo ON dbo.[Dcx_WeiBo] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBo]') AND name = N'IX_Dcx_WeiBo') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_WeiBo] ON dbo.[Dcx_WeiBo]  
( 
    CreatorId, WId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBo]') AND name = N'IX_Dcx_WeiBo_1') 
   DROP index  IX_Dcx_WeiBo_1 ON dbo.[Dcx_WeiBo] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBo]') AND name = N'IX_Dcx_WeiBo_1') 
CREATE  CLUSTERED INDEX [IX_Dcx_WeiBo_1] ON dbo.[Dcx_WeiBo]  
( 
    CreateDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBoFile]') AND name = N'IX_Dcx_DocumentPublic') 
   DROP index  IX_Dcx_DocumentPublic ON dbo.[Dcx_WeiBoFile] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WeiBoFile]') AND name = N'IX_Dcx_DocumentPublic') 
CREATE  CLUSTERED INDEX [IX_Dcx_DocumentPublic] ON dbo.[Dcx_WeiBoFile]  
( 
    CreatorId, FileId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetter]') AND name = N'IX_Dcx_WLetter') 
   DROP index  IX_Dcx_WLetter ON dbo.[Dcx_WLetter] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetter]') AND name = N'IX_Dcx_WLetter') 
CREATE  CLUSTERED INDEX [IX_Dcx_WLetter] ON dbo.[Dcx_WLetter]  
( 
    SenderId, LId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetter]') AND name = N'IX_Dcx_WLetter_1') 
   DROP index  IX_Dcx_WLetter_1 ON dbo.[Dcx_WLetter] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetter]') AND name = N'IX_Dcx_WLetter_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_WLetter_1] ON dbo.[Dcx_WLetter]  
( 
    SenderId, SentDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterRcv]') AND name = N'IX_Dcx_WLetterRcv') 
   DROP index  IX_Dcx_WLetterRcv ON dbo.[Dcx_WLetterRcv] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterRcv]') AND name = N'IX_Dcx_WLetterRcv') 
CREATE unique CLUSTERED INDEX [IX_Dcx_WLetterRcv] ON dbo.[Dcx_WLetterRcv]  
( 
    ReceiverId, LId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterRcv]') AND name = N'IX_Dcx_WLetterRcv_1') 
   DROP index  IX_Dcx_WLetterRcv_1 ON dbo.[Dcx_WLetterRcv] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterRcv]') AND name = N'IX_Dcx_WLetterRcv_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_WLetterRcv_1] ON dbo.[Dcx_WLetterRcv]  
( 
    ReceiverId, SentDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterReply]') AND name = N'IX_Dcx_WLetterReply') 
   DROP index  IX_Dcx_WLetterReply ON dbo.[Dcx_WLetterReply] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WLetterReply]') AND name = N'IX_Dcx_WLetterReply') 
CREATE  CLUSTERED INDEX [IX_Dcx_WLetterReply] ON dbo.[Dcx_WLetterReply]  
( 
    SnederId, LId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMail]') AND name = N'IX_Dcx_WMail') 
   DROP index  IX_Dcx_WMail ON dbo.[Dcx_WMail] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMail]') AND name = N'IX_Dcx_WMail') 
CREATE  CLUSTERED INDEX [IX_Dcx_WMail] ON dbo.[Dcx_WMail]  
( 
    SenderId, SentDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMail]') AND name = N'IX_Dcx_WMail_1') 
   DROP index  IX_Dcx_WMail_1 ON dbo.[Dcx_WMail] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMail]') AND name = N'IX_Dcx_WMail_1') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_WMail_1] ON dbo.[Dcx_WMail]  
( 
    SenderId, MId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailRcv]') AND name = N'IX_Dcx_WMailRcv') 
   DROP index  IX_Dcx_WMailRcv ON dbo.[Dcx_WMailRcv] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailRcv]') AND name = N'IX_Dcx_WMailRcv') 
CREATE  NONCLUSTERED INDEX [IX_Dcx_WMailRcv] ON dbo.[Dcx_WMailRcv]  
( 
    ReceiverId, SentDate DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailRcv]') AND name = N'IX_Dcx_WMailRcv_1') 
   DROP index  IX_Dcx_WMailRcv_1 ON dbo.[Dcx_WMailRcv] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailRcv]') AND name = N'IX_Dcx_WMailRcv_1') 
CREATE unique CLUSTERED INDEX [IX_Dcx_WMailRcv_1] ON dbo.[Dcx_WMailRcv]  
( 
    ReceiverId, MId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailReply]') AND name = N'IX_Dcx_WMailReply') 
   DROP index  IX_Dcx_WMailReply ON dbo.[Dcx_WMailReply] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_WMailReply]') AND name = N'IX_Dcx_WMailReply') 
CREATE  CLUSTERED INDEX [IX_Dcx_WMailReply] ON dbo.[Dcx_WMailReply]  
( 
    SnederId, MId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_CanWriteField]') AND name = N'IX_WF_CanWriteField') 
   DROP index  IX_WF_CanWriteField ON dbo.[WF_CanWriteField] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_CanWriteField]') AND name = N'IX_WF_CanWriteField') 
CREATE  CLUSTERED INDEX [IX_WF_CanWriteField] ON dbo.[WF_CanWriteField]  
( 
    FlowId, NodeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_CanWriteField]') AND name = N'IX_WF_CanWriteField_1') 
   DROP index  IX_WF_CanWriteField_1 ON dbo.[WF_CanWriteField] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_CanWriteField]') AND name = N'IX_WF_CanWriteField_1') 
CREATE  NONCLUSTERED INDEX [IX_WF_CanWriteField_1] ON dbo.[WF_CanWriteField]  
( 
    NodeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_Depute]') AND name = N'IX_WF_Depute') 
   DROP index  IX_WF_Depute ON dbo.[WF_Depute] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_Depute]') AND name = N'IX_WF_Depute') 
CREATE  CLUSTERED INDEX [IX_WF_Depute] ON dbo.[WF_Depute]  
( 
    RunId, PrcsId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNode]') AND name = N'IX_WF_FlowNode') 
   DROP index  IX_WF_FlowNode ON dbo.[WF_FlowNode] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNode]') AND name = N'IX_WF_FlowNode') 
CREATE  CLUSTERED INDEX [IX_WF_FlowNode] ON dbo.[WF_FlowNode]  
( 
    FlowId, NodeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodePrivilege]') AND name = N'IX_WF_FlowNodePrivilege') 
   DROP index  IX_WF_FlowNodePrivilege ON dbo.[WF_FlowNodePrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodePrivilege]') AND name = N'IX_WF_FlowNodePrivilege') 
CREATE  CLUSTERED INDEX [IX_WF_FlowNodePrivilege] ON dbo.[WF_FlowNodePrivilege]  
( 
    FlowId, NodeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodePrivilege]') AND name = N'IX_WF_FlowNodePrivilege_1') 
   DROP index  IX_WF_FlowNodePrivilege_1 ON dbo.[WF_FlowNodePrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodePrivilege]') AND name = N'IX_WF_FlowNodePrivilege_1') 
CREATE  NONCLUSTERED INDEX [IX_WF_FlowNodePrivilege_1] ON dbo.[WF_FlowNodePrivilege]  
( 
    NodeId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND name = N'IX_WF_FlowOperateLog') 
   DROP index  IX_WF_FlowOperateLog ON dbo.[WF_FlowOperateLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND name = N'IX_WF_FlowOperateLog') 
CREATE  NONCLUSTERED INDEX [IX_WF_FlowOperateLog] ON dbo.[WF_FlowOperateLog]  
( 
    FlowId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND name = N'IX_WF_FlowOperateLog_1') 
   DROP index  IX_WF_FlowOperateLog_1 ON dbo.[WF_FlowOperateLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND name = N'IX_WF_FlowOperateLog_1') 
CREATE  NONCLUSTERED INDEX [IX_WF_FlowOperateLog_1] ON dbo.[WF_FlowOperateLog]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND name = N'IX_WF_FlowOperateLog_2') 
   DROP index  IX_WF_FlowOperateLog_2 ON dbo.[WF_FlowOperateLog] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowOperateLog]') AND name = N'IX_WF_FlowOperateLog_2') 
CREATE  CLUSTERED INDEX [IX_WF_FlowOperateLog_2] ON dbo.[WF_FlowOperateLog]  
( 
    OperateTime DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRun]') AND name = N'IX_WF_FlowRun') 
   DROP index  IX_WF_FlowRun ON dbo.[WF_FlowRun] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRun]') AND name = N'IX_WF_FlowRun') 
CREATE  CLUSTERED INDEX [IX_WF_FlowRun] ON dbo.[WF_FlowRun]  
( 
    FlowId, RunId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunAttention]') AND name = N'IX_WF_FlowAttention') 
   DROP index  IX_WF_FlowAttention ON dbo.[WF_FlowRunAttention] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunAttention]') AND name = N'IX_WF_FlowAttention') 
CREATE  CLUSTERED INDEX [IX_WF_FlowAttention] ON dbo.[WF_FlowRunAttention]  
( 
    UserId, RunId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunAttention]') AND name = N'IX_WF_FlowAttention_1') 
   DROP index  IX_WF_FlowAttention_1 ON dbo.[WF_FlowRunAttention] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunAttention]') AND name = N'IX_WF_FlowAttention_1') 
CREATE  NONCLUSTERED INDEX [IX_WF_FlowAttention_1] ON dbo.[WF_FlowRunAttention]  
( 
    RunId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunCollect]') AND name = N'IX_WF_FlowCollect') 
   DROP index  IX_WF_FlowCollect ON dbo.[WF_FlowRunCollect] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunCollect]') AND name = N'IX_WF_FlowCollect') 
CREATE  CLUSTERED INDEX [IX_WF_FlowCollect] ON dbo.[WF_FlowRunCollect]  
( 
    UserId, RunId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunCollect]') AND name = N'IX_WF_FlowCollect_1') 
   DROP index  IX_WF_FlowCollect_1 ON dbo.[WF_FlowRunCollect] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunCollect]') AND name = N'IX_WF_FlowCollect_1') 
CREATE  NONCLUSTERED INDEX [IX_WF_FlowCollect_1] ON dbo.[WF_FlowRunCollect]  
( 
    RunId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunFile]') AND name = N'IX_WF_FlowRunFile') 
   DROP index  IX_WF_FlowRunFile ON dbo.[WF_FlowRunFile] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunFile]') AND name = N'IX_WF_FlowRunFile') 
CREATE  CLUSTERED INDEX [IX_WF_FlowRunFile] ON dbo.[WF_FlowRunFile]  
( 
    FlowId, RunId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunHsty]') AND name = N'IX_WF_FlowRunHsty') 
   DROP index  IX_WF_FlowRunHsty ON dbo.[WF_FlowRunHsty] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunHsty]') AND name = N'IX_WF_FlowRunHsty') 
CREATE  CLUSTERED INDEX [IX_WF_FlowRunHsty] ON dbo.[WF_FlowRunHsty]  
( 
    FlowId, RunId DESC 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcs]') AND name = N'IX_WF_FlowRunPrcs') 
   DROP index  IX_WF_FlowRunPrcs ON dbo.[WF_FlowRunPrcs] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcs]') AND name = N'IX_WF_FlowRunPrcs') 
CREATE  CLUSTERED INDEX [IX_WF_FlowRunPrcs] ON dbo.[WF_FlowRunPrcs]  
( 
    RunId, PrcsId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcs]') AND name = N'IX_WF_FlowRunPrcs_1') 
   DROP index  IX_WF_FlowRunPrcs_1 ON dbo.[WF_FlowRunPrcs] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcs]') AND name = N'IX_WF_FlowRunPrcs_1') 
CREATE  NONCLUSTERED INDEX [IX_WF_FlowRunPrcs_1] ON dbo.[WF_FlowRunPrcs]  
( 
    FlowId, RunId, PrcsId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcsPrivilege]') AND name = N'IX_WF_FlowRunPrcsPrivilege') 
   DROP index  IX_WF_FlowRunPrcsPrivilege ON dbo.[WF_FlowRunPrcsPrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcsPrivilege]') AND name = N'IX_WF_FlowRunPrcsPrivilege') 
CREATE  CLUSTERED INDEX [IX_WF_FlowRunPrcsPrivilege] ON dbo.[WF_FlowRunPrcsPrivilege]  
( 
    RunId, PrcsId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowTypePrivilege]') AND name = N'IX_WF_FlowTypePrivilege') 
   DROP index  IX_WF_FlowTypePrivilege ON dbo.[WF_FlowTypePrivilege] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowTypePrivilege]') AND name = N'IX_WF_FlowTypePrivilege') 
CREATE  CLUSTERED INDEX [IX_WF_FlowTypePrivilege] ON dbo.[WF_FlowTypePrivilege]  
( 
    FlowId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_Rebut]') AND name = N'IX_WF_Rebut_1') 
   DROP index  IX_WF_Rebut_1 ON dbo.[WF_Rebut] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_Rebut]') AND name = N'IX_WF_Rebut_1') 
CREATE  CLUSTERED INDEX [IX_WF_Rebut_1] ON dbo.[WF_Rebut]  
( 
    FlowId, RunId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_TakeBackPrcs]') AND name = N'IX_WF_TakeBackPrcs') 
   DROP index  IX_WF_TakeBackPrcs ON dbo.[WF_TakeBackPrcs] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[WF_TakeBackPrcs]') AND name = N'IX_WF_TakeBackPrcs') 
CREATE  CLUSTERED INDEX [IX_WF_TakeBackPrcs] ON dbo.[WF_TakeBackPrcs]  
( 
    CreateDate 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabAccountIndex]') AND name = N'IX_TabUser') 
   DROP index  IX_TabUser ON dbo.[Dcx_TabAccountIndex] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_TabAccountIndex]') AND name = N'IX_TabUser') 
CREATE unique NONCLUSTERED INDEX [IX_TabUser] ON dbo.[Dcx_TabAccountIndex]  
( 
    UserName 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
IF EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserTempMsg]') AND name = N'IX_Dcx_UserTempMsg') 
   DROP index  IX_Dcx_UserTempMsg ON dbo.[Dcx_UserTempMsg] 
IF NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserTempMsg]') AND name = N'IX_Dcx_UserTempMsg') 
CREATE  CLUSTERED INDEX [IX_Dcx_UserTempMsg] ON dbo.[Dcx_UserTempMsg]  
( 
    UserId 
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY] 
----------------------------------------------------------------------------------------  上：索引  ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------  下：视图  ----------------------------------------------------------------------------------
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptCompanyView]')) 
   DROP VIEW  dbo.[Dcx_DeptCompanyView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptCompanyView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_DeptCompanyView]
AS
SELECT     dbo.Dcx_Dept.DeptId, dbo.Dcx_Dept.DeptCode, dbo.Dcx_Dept.DeptName, dbo.Dcx_Dept.CompanyId, dbo.Dcx_Dept.DeptOrder, 
                      dbo.Dcx_Dept.ParentId, dbo.Dcx_Dept.Telephone, dbo.Dcx_Dept.PostalCode, dbo.Dcx_Dept.Address, dbo.Dcx_Dept.Email, 
                      dbo.Dcx_Dept.URL, dbo.Dcx_Dept.Accounts, dbo.Dcx_Dept.Principal, dbo.Dcx_Dept.Remark, dbo.Dcx_Company.CompanyCode, 
                      dbo.Dcx_Company.CompanyName, dbo.Dcx_Company.Telephone AS CompanyTelephone, dbo.Dcx_Company.Address AS CompanyAddress, 
                      dbo.Dcx_Company.PostalCode AS CompanyPostalCode, dbo.Dcx_Company.Email AS CompanyEmail, dbo.Dcx_Company.URL AS CompanyURL, 
                      dbo.Dcx_Company.Accounts AS CompanyAccounts, dbo.Dcx_Company.Principal AS CompanyPrincipal, dbo.Dcx_Company.ComOrder, 
                      dbo.Dcx_Company.Remark AS CompanyRemark
FROM         dbo.Dcx_Dept LEFT OUTER JOIN
                      dbo.Dcx_Company ON dbo.Dcx_Dept.CompanyId = dbo.Dcx_Company.CompanyId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilegeUserView]')) 
   DROP VIEW  dbo.[Dcx_DeptPrivilegeUserView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilegeUserView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_DeptPrivilegeUserView]
AS
SELECT     dbo.Dcx_DeptPrivilege.DeptPrivilegeId, dbo.Dcx_DeptPrivilege.UserId, dbo.Dcx_DeptPrivilege.DeptId, dbo.Dcx_User.UserGuId, 
                      dbo.Dcx_User.UserName, dbo.Dcx_User.RealName, dbo.Dcx_Dept.DeptCode, dbo.Dcx_Dept.DeptName, dbo.Dcx_Dept.CompanyId, 
                      dbo.Dcx_User.EmployeeId, dbo.Dcx_User.PositionId, dbo.Dcx_User.SuperAdmin, dbo.Dcx_User.CanLogin, dbo.Dcx_User.VisitTime, 
                      dbo.Dcx_User.Online, dbo.Dcx_User.PWD, dbo.Dcx_User.LoginDate, dbo.Dcx_User.Sex, dbo.Dcx_User.Telephone AS UserTelephone, 
                      dbo.Dcx_User.Email AS UserEmail, dbo.Dcx_User.Status, dbo.Dcx_User.RegistedDate, dbo.Dcx_User.Phone, dbo.Dcx_User.Birthday, 
                      dbo.Dcx_User.Http, dbo.Dcx_Dept.ParentId, dbo.Dcx_Dept.Telephone AS DeptTelephone, dbo.Dcx_Dept.PostalCode AS DeptPostalCode, 
                      dbo.Dcx_Dept.Address AS DeptAddress, dbo.Dcx_Dept.Email, dbo.Dcx_Dept.URL AS DeptURL, dbo.Dcx_Dept.Accounts AS DeptAccounts, 
                      dbo.Dcx_Dept.Principal AS DeptPrincipal, dbo.Dcx_Dept.Remark, dbo.Dcx_DeptPrivilege.Remark AS PrivilegeRemark
FROM         dbo.Dcx_DeptPrivilege INNER JOIN
                      dbo.Dcx_Dept ON dbo.Dcx_DeptPrivilege.DeptId = dbo.Dcx_Dept.DeptId INNER JOIN
                      dbo.Dcx_User ON dbo.Dcx_DeptPrivilege.UserId = dbo.Dcx_User.UserId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilegeView]')) 
   DROP VIEW  dbo.[Dcx_DeptPrivilegeView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilegeView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_DeptPrivilegeView]
AS
SELECT     dbo.Dcx_DeptPrivilege.DeptPrivilegeId, dbo.Dcx_DeptPrivilege.UserId, dbo.Dcx_Dept.DeptId, dbo.Dcx_Dept.DeptCode, 
                      dbo.Dcx_Dept.DeptName, dbo.Dcx_Dept.CompanyId, dbo.Dcx_Dept.DeptOrder, dbo.Dcx_Dept.ParentId, dbo.Dcx_Dept.Telephone, 
                      dbo.Dcx_Dept.PostalCode, dbo.Dcx_Dept.Address, dbo.Dcx_Dept.Email, dbo.Dcx_Dept.URL, dbo.Dcx_Dept.Accounts, dbo.Dcx_Dept.Principal, 
                      dbo.Dcx_Dept.Remark, dbo.Dcx_DeptPrivilege.Remark AS PrivilegeRemark
FROM         dbo.Dcx_DeptPrivilege INNER JOIN
                      dbo.Dcx_Dept ON dbo.Dcx_DeptPrivilege.DeptId = dbo.Dcx_Dept.DeptId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilegeRoleView]')) 
   DROP VIEW  dbo.[Dcx_EntityPrivilegeRoleView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilegeRoleView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_EntityPrivilegeRoleView]
AS
SELECT     dbo.Dcx_EntityPrivilege.EntityPrivilegeId, dbo.Dcx_EntityPrivilege.MenuId, dbo.Dcx_EntityPrivilege.EntId, dbo.Dcx_EntityPrivilege.RoleId, 
                      dbo.Dcx_Role.RoleName, dbo.Dcx_EntityPrivilege.CanViewList, dbo.Dcx_EntityPrivilege.CanBrowse, dbo.Dcx_EntityPrivilege.CanInsert, 
                      dbo.Dcx_EntityPrivilege.CanDelete, dbo.Dcx_EntityPrivilege.CanUpdate, dbo.Dcx_EntityPrivilege.CanOutPut, dbo.Dcx_EntityPrivilege.CanInput, 
                      dbo.Dcx_EntityPrivilege.CanCopy, dbo.Dcx_EntityPrivilege.CanPrint, dbo.Dcx_EntityPrivilege.CanCheck, dbo.Dcx_EntityPrivilege.CanClean, 
                      dbo.Dcx_EntityPrivilege.CanRecycle, dbo.Dcx_EntityPrivilege.CanExecute, dbo.Dcx_EntityPrivilege.CanDesign
FROM         dbo.Dcx_EntityPrivilege INNER JOIN
                      dbo.Dcx_Role ON dbo.Dcx_EntityPrivilege.RoleId = dbo.Dcx_Role.RoleId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilegeView]')) 
   DROP VIEW  dbo.[Dcx_EntityPrivilegeView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilegeView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_EntityPrivilegeView]
AS
SELECT     dbo.Dcx_EntityPrivilege.EntityPrivilegeId, dbo.Dcx_EntityPrivilege.MenuId, dbo.Dcx_EntityPrivilege.EntId, dbo.Dcx_EntityPrivilege.RoleId, 
                      dbo.Dcx_EntityPrivilege.EntityPrivilegeId AS Expr1, dbo.Dcx_EntityPrivilege.CanViewList, dbo.Dcx_EntityPrivilege.CanBrowse, 
                      dbo.Dcx_EntityPrivilege.CanInsert, dbo.Dcx_EntityPrivilege.CanDelete, dbo.Dcx_EntityPrivilege.CanUpdate, dbo.Dcx_EntityPrivilege.CanOutPut, 
                      dbo.Dcx_EntityPrivilege.CanInput, dbo.Dcx_EntityPrivilege.CanCopy, dbo.Dcx_EntityPrivilege.CanPrint, dbo.Dcx_EntityPrivilege.CanCheck, 
                      dbo.Dcx_EntityPrivilege.CanClean, dbo.Dcx_EntityPrivilege.CanRecycle, dbo.Dcx_EntityPrivilege.CanExecute, 
                      dbo.Dcx_EntityPrivilege.CanDesign, dbo.Dcx_Entity_Run.MenuId AS Expr2, dbo.Dcx_Entity_Run.EntName, dbo.Dcx_Entity_Run.MEnt, 
                      dbo.Dcx_Entity_Run.DBConnectId, dbo.Dcx_Entity_Run.ParentId, dbo.Dcx_Entity_Run.OrderBy, dbo.Dcx_Entity_Run.CheckPower
FROM         dbo.Dcx_EntityPrivilege INNER JOIN
                      dbo.Dcx_Entity_Run ON dbo.Dcx_EntityPrivilege.EntId = dbo.Dcx_Entity_Run.EntId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityViewOptionView]')) 
   DROP VIEW  dbo.[Dcx_EntityViewOptionView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_EntityViewOptionView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_EntityViewOptionView]
AS
SELECT     TOP (100) PERCENT dbo.Dcx_EntityViewGroup.ViewGroupId, dbo.Dcx_EntityViewGroup.ViewGroupName, dbo.Dcx_EntityViewGroup.EntId, 
                      dbo.Dcx_EntityViewOption.ViewOptionId, dbo.Dcx_EntityViewOption.OptionName, dbo.Dcx_EntityViewGroup.ColumnCount, 
                      dbo.Dcx_EntityViewGroup.ParentId, dbo.Dcx_EntityViewGroup.OrderNO AS GroupOrderNO, dbo.Dcx_EntityViewOption.OrderNO AS OptionOrderNO, 
                      dbo.Dcx_EntityViewGroup.IsShare, dbo.Dcx_EntityViewGroup.IsSystem, dbo.Dcx_EntityViewGroup.Creator, dbo.Dcx_EntityViewGroup.CreateTime, 
                      dbo.Dcx_EntityViewGroup.LastMender, dbo.Dcx_EntityViewGroup.LastMenderTime
FROM         dbo.Dcx_EntityViewOption LEFT OUTER JOIN
                      dbo.Dcx_EntityViewGroup ON dbo.Dcx_EntityViewGroup.ViewGroupId = dbo.Dcx_EntityViewOption.ViewGroupId
ORDER BY dbo.Dcx_EntityViewGroup.EntId, GroupOrderNO, OptionOrderNO
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilegeRoleView]')) 
   DROP VIEW  dbo.[Dcx_MenuPrivilegeRoleView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilegeRoleView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_MenuPrivilegeRoleView]
AS
SELECT     dbo.Dcx_MenuPrivilege.MenuPrivilegeId, dbo.Dcx_MenuPrivilege.MenuId, dbo.Dcx_Role.RoleId, dbo.Dcx_Role.RoleName, 
                      dbo.Dcx_MenuPrivilege.CanViewList, dbo.Dcx_MenuPrivilege.CanBrowse, dbo.Dcx_MenuPrivilege.CanInsert, 
                      dbo.Dcx_MenuPrivilege.CanDelete, dbo.Dcx_MenuPrivilege.CanUpdate, dbo.Dcx_MenuPrivilege.CanOutPut, dbo.Dcx_MenuPrivilege.CanInput, 
                      dbo.Dcx_MenuPrivilege.CanCopy, dbo.Dcx_MenuPrivilege.CanPrint, dbo.Dcx_MenuPrivilege.CanCheck, dbo.Dcx_MenuPrivilege.CanClean
FROM         dbo.Dcx_MenuPrivilege INNER JOIN
                      dbo.Dcx_Role ON dbo.Dcx_MenuPrivilege.RoleId = dbo.Dcx_Role.RoleId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilegeView]')) 
   DROP VIEW  dbo.[Dcx_MenuPrivilegeView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilegeView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_MenuPrivilegeView]
AS
SELECT     dbo.Dcx_MenuPrivilege.MenuPrivilegeId, dbo.Dcx_MenuPrivilege.MenuId, dbo.Dcx_MenuPrivilege.RoleId, dbo.Dcx_MenuPrivilege.CanViewList, 
                      dbo.Dcx_MenuPrivilege.CanBrowse, dbo.Dcx_MenuPrivilege.CanInsert, dbo.Dcx_MenuPrivilege.CanDelete, dbo.Dcx_MenuPrivilege.CanUpdate, 
                      dbo.Dcx_MenuPrivilege.CanOutPut, dbo.Dcx_MenuPrivilege.CanInput, dbo.Dcx_MenuPrivilege.CanCopy, dbo.Dcx_MenuPrivilege.CanPrint, 
                      dbo.Dcx_MenuPrivilege.CanCheck, dbo.Dcx_MenuPrivilege.CanClean, dbo.Dcx_MenuPrivilege.CanRecycle, dbo.Dcx_MenuPrivilege.ExtendField1, 
                      dbo.Dcx_MenuPrivilege.ExtendField2, dbo.Dcx_MenuPrivilege.ExtendField3, dbo.Dcx_MenuPrivilege.ExtendField4, 
                      dbo.Dcx_MenuPrivilege.ExtendField5, dbo.Dcx_MenuPrivilege.ExtendField6, dbo.Dcx_MenuPrivilege.ExtendField7, 
                      dbo.Dcx_MenuPrivilege.ExtendField8, dbo.Dcx_MenuPrivilege.ExtendField9, dbo.Dcx_MenuPrivilege.ExtendField10, 
                      dbo.Dcx_MenuPrivilege.MenuId AS Expr1, dbo.Dcx_Menu_Run.MenuName, dbo.Dcx_Menu_Run.ParentId, dbo.Dcx_Menu_Run.ProPath, 
                      dbo.Dcx_Menu_Run.TemplateId, dbo.Dcx_Menu_Run.ImgPath, dbo.Dcx_Menu_Run.ExImgPath, dbo.Dcx_Menu_Run.OrderBy, 
                      dbo.Dcx_Menu_Run.Target, dbo.Dcx_Menu_Run.IsOpen, dbo.Dcx_Menu_Run.IsHidden
FROM         dbo.Dcx_MenuPrivilege INNER JOIN
                      dbo.Dcx_Menu_Run ON dbo.Dcx_MenuPrivilege.MenuId = dbo.Dcx_Menu_Run.MenuId
WHERE     (dbo.Dcx_Menu_Run.IsHidden = 0)
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUserView]')) 
   DROP VIEW  dbo.[Dcx_OnlineUserView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_OnlineUserView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_OnlineUserView]
AS
SELECT     dbo.Dcx_OnlineUser.OnLineId, dbo.Dcx_OnlineUser.UserId, dbo.Dcx_OnlineUser.UserGuId, dbo.Dcx_OnlineUser.UserName, 
                      dbo.Dcx_OnlineUser.RealName, dbo.Dcx_OnlineUser.LoginTime, dbo.Dcx_OnlineUser.ActiveTime, dbo.Dcx_OnlineUser.LastRefreshTime, 
                      dbo.Dcx_OnlineUser.RoleId, dbo.Dcx_OnlineUser.RoleName, dbo.Dcx_OnlineUser.RoleIds, dbo.Dcx_OnlineUser.RoleNames, 
                      dbo.Dcx_OnlineUser.DeptId, dbo.Dcx_OnlineUser.DeptName, dbo.Dcx_OnlineUser.EmployeeId, dbo.Dcx_OnlineUser.PositionId, 
                      dbo.Dcx_OnlineUser.PositionName, dbo.Dcx_OnlineUser.SuperAdmin, dbo.Dcx_OnlineUser.CanLogin, dbo.Dcx_OnlineUser.IP, 
                      dbo.Dcx_OnlineUser.RestrictIp, dbo.Dcx_OnlineUser.VisitTime, dbo.Dcx_OnlineUser.Online, dbo.Dcx_OnlineUser.PWD, 
                      dbo.Dcx_OnlineUser.UserOrder, dbo.Dcx_OnlineUser.Sex, dbo.Dcx_OnlineUser.Telephone, dbo.Dcx_OnlineUser.Email, 
                      dbo.Dcx_OnlineUser.Status, dbo.Dcx_OnlineUser.RegistedDate, dbo.Dcx_OnlineUser.Phone, dbo.Dcx_OnlineUser.Birthday, 
                      dbo.Dcx_OnlineUser.Style, dbo.Dcx_OnlineUser.IsNeedKey, dbo.Dcx_OnlineUser.Caste, dbo.Dcx_OnlineUser.Http, 
                      dbo.Dcx_OnlineUser.IconPath, dbo.Dcx_OnlineUser.Creator, dbo.Dcx_OnlineUser.CreateTime, dbo.Dcx_Dept.DeptName AS Expr1, 
                      dbo.Dcx_Dept.DeptCode, dbo.Dcx_Position.PositionCode, dbo.Dcx_Position.PositionName AS Expr2, dbo.Dcx_Role.RoleName AS Expr4
FROM         dbo.Dcx_OnlineUser LEFT OUTER JOIN
                      dbo.Dcx_Dept ON dbo.Dcx_OnlineUser.DeptId = dbo.Dcx_Dept.DeptId LEFT OUTER JOIN
                      dbo.Dcx_Position ON dbo.Dcx_OnlineUser.PositionId = dbo.Dcx_Position.PositionId LEFT OUTER JOIN
                      dbo.Dcx_Role ON dbo.Dcx_OnlineUser.RoleId = dbo.Dcx_Role.RoleId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserPositionView]')) 
   DROP VIEW  dbo.[Dcx_UserPositionView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserPositionView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_UserPositionView]
AS
SELECT     dbo.Dcx_User.UserId, dbo.Dcx_User.AccountId, dbo.Dcx_User.UserGuId, dbo.Dcx_User.UserName, dbo.Dcx_User.RealName, 
                      dbo.Dcx_User.DeptId, dbo.Dcx_User.CurSystemId, dbo.Dcx_User.EmployeeId, dbo.Dcx_User.PositionId, dbo.Dcx_User.SuperAdmin, 
                      dbo.Dcx_User.CanLogin, dbo.Dcx_User.IP, dbo.Dcx_User.RestrictIp, dbo.Dcx_User.VisitTime, dbo.Dcx_User.Online, dbo.Dcx_User.PWD, 
                      dbo.Dcx_User.LoginDate, dbo.Dcx_User.UserOrder, dbo.Dcx_User.Sex, dbo.Dcx_User.Telephone, dbo.Dcx_User.Email, dbo.Dcx_User.Status, 
                      dbo.Dcx_User.RegistedDate, dbo.Dcx_User.Phone, dbo.Dcx_User.Birthday, dbo.Dcx_User.Style, dbo.Dcx_User.IsNeedKey, 
                      dbo.Dcx_User.Caste, dbo.Dcx_User.Http, dbo.Dcx_User.IconPath, dbo.Dcx_User.Creator, dbo.Dcx_User.CreateTime, dbo.Dcx_User.Editor, 
                      dbo.Dcx_User.EditTime, dbo.Dcx_Position.PositionCode, dbo.Dcx_Position.PositionName, dbo.Dcx_Position.ParentId AS PositionParentId
FROM         dbo.Dcx_User LEFT OUTER JOIN
                      dbo.Dcx_Position ON dbo.Dcx_User.PositionId = dbo.Dcx_Position.PositionId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserRoleView]')) 
   DROP VIEW  dbo.[Dcx_UserRoleView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserRoleView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [Dcx_UserRoleView]
AS
SELECT     dbo.Dcx_UserInRole.UserRoleId, dbo.Dcx_User.UserId, dbo.Dcx_User.AccountId, dbo.Dcx_User.UserGuId, dbo.Dcx_User.UserName, 
                      dbo.Dcx_User.GroupId, dbo.Dcx_User.CurSystemId, dbo.Dcx_User.RealName, dbo.Dcx_User.DeptId, dbo.Dcx_User.EmployeeId, 
                      dbo.Dcx_User.PositionId, dbo.Dcx_User.SuperAdmin, dbo.Dcx_User.CanLogin, dbo.Dcx_User.IP, dbo.Dcx_User.RestrictIp, 
                      dbo.Dcx_User.VisitTime, dbo.Dcx_User.Online, dbo.Dcx_User.PWD, dbo.Dcx_User.LoginDate, dbo.Dcx_User.UserOrder, dbo.Dcx_User.Sex, 
                      dbo.Dcx_User.Telephone, dbo.Dcx_User.Email, dbo.Dcx_User.Status, dbo.Dcx_User.RegistedDate, dbo.Dcx_User.Phone, 
                      dbo.Dcx_User.Birthday, dbo.Dcx_User.Style, dbo.Dcx_User.IsNeedKey, dbo.Dcx_User.Caste, dbo.Dcx_User.Http, dbo.Dcx_User.IconPath, 
                      dbo.Dcx_User.Creator, dbo.Dcx_User.CreateTime, dbo.Dcx_User.Editor, dbo.Dcx_User.EditTime, dbo.Dcx_UserInRole.RoleId, 
                      dbo.Dcx_UserInRole.IsMainRole, dbo.Dcx_Role.RoleName
FROM         dbo.Dcx_UserInRole INNER JOIN
                      dbo.Dcx_User ON dbo.Dcx_UserInRole.UserId = dbo.Dcx_User.UserId INNER JOIN
                      dbo.Dcx_Role ON dbo.Dcx_UserInRole.RoleId = dbo.Dcx_Role.RoleId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserView]')) 
   DROP VIEW  dbo.[Dcx_UserView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW dbo.Dcx_UserView
AS
SELECT     dbo.Dcx_User.UserId, dbo.Dcx_User.AccountId, dbo.Dcx_User.UserGuId, dbo.Dcx_User.UserName, dbo.Dcx_User.GroupId, 
                      dbo.Dcx_User.CurSystemId, dbo.Dcx_User.RealName, dbo.Dcx_User.EmployeeId, (CASE WHEN EmployeeId IS NULL THEN NULL ELSE
                          (SELECT     TOP 1 EmployeeCode
                            FROM          dbo.Dcx_Employee
                            WHERE      (dbo.Dcx_Employee.EmployeeId = dbo.Dcx_User.EmployeeId)) END) AS EmployeeCode, dbo.Dcx_User.PositionId, 
                      dbo.Dcx_User.SuperAdmin, dbo.Dcx_User.CanLogin, dbo.Dcx_User.IP, dbo.Dcx_User.RestrictIp, dbo.Dcx_User.VisitTime, dbo.Dcx_User.Online, 
                      dbo.Dcx_User.PWD, dbo.Dcx_User.LoginDate, dbo.Dcx_User.UserOrder, dbo.Dcx_User.Sex, dbo.Dcx_User.Telephone, dbo.Dcx_User.Email, 
                      dbo.Dcx_User.Status, dbo.Dcx_User.RegistedDate, dbo.Dcx_User.Phone, dbo.Dcx_User.Birthday, dbo.Dcx_User.Style, dbo.Dcx_User.IsNeedKey, 
                      dbo.Dcx_User.Caste, dbo.Dcx_User.Http, dbo.Dcx_User.IconPath, dbo.Dcx_User.Creator, dbo.Dcx_User.CreateTime, dbo.Dcx_User.Editor, 
                      dbo.Dcx_User.EditTime, dbo.Dcx_Dept.DeptId, dbo.Dcx_Dept.DeptName, dbo.Dcx_Dept.DeptCode, dbo.Dcx_Position.PositionCode, 
                      dbo.Dcx_Position.PositionName, dbo.Dcx_UserInRole.RoleId, dbo.Dcx_Role.RoleName, dbo.Dcx_User.UpperName, dbo.Dcx_User.DcxUserName, 
                      dbo.Dcx_User.SelftHomePage, dbo.Dcx_User.SelftNavMenu, dbo.Dcx_User.SelftSearch, dbo.Dcx_User.StyleId, dbo.Dcx_User.AcceptStrangerIM, 
                      dbo.Dcx_User.Remark, dbo.Dcx_User.DiskSize, dbo.Dcx_User.InviteCode, dbo.Dcx_User.EditorId, dbo.Dcx_User.CreatorId, 
                      dbo.Dcx_User.IsAccountCreator, dbo.Dcx_User.Address, dbo.Dcx_User.TopMenuId
FROM         dbo.Dcx_User LEFT OUTER JOIN
                      dbo.Dcx_Dept ON dbo.Dcx_User.DeptId = dbo.Dcx_Dept.DeptId LEFT OUTER JOIN
                      dbo.Dcx_Position ON dbo.Dcx_User.PositionId = dbo.Dcx_Position.PositionId LEFT OUTER JOIN
                      dbo.Dcx_UserInRole ON dbo.Dcx_User.UserId = dbo.Dcx_UserInRole.UserId AND dbo.Dcx_UserInRole.IsMainRole = 1 LEFT OUTER JOIN
                      dbo.Dcx_Role ON dbo.Dcx_UserInRole.RoleId = dbo.Dcx_Role.RoleId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodeView]')) 
   DROP VIEW  dbo.[WF_FlowNodeView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[WF_FlowNodeView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [WF_FlowNodeView]
AS
SELECT     NodeId, FlowId, NodeName, Step, PrcsTo, TriggerBefore, TriggerAfter, CanReject, CanPigeonhole, PigeonholedSQL, NodeType, ApproveType, 
                      ToNextType, ArriveType, NotifyType, NotifyContent, EntId
FROM         dbo.WF_FlowNode
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[WF_WorkFlowView]')) 
   DROP VIEW  dbo.[WF_WorkFlowView]  
IF NOT EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_Id(N'dbo.[WF_WorkFlowView]')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE VIEW [WF_WorkFlowView]
AS
SELECT     dbo.WF_FlowSort.SortNo, dbo.WF_FlowSort.SortName, dbo.WF_FlowType.FlowId, dbo.WF_FlowType.FlowName, dbo.WF_FlowType.FlowNo, 
                      dbo.WF_FlowType.SortId, dbo.WF_FlowType.Detail, dbo.WF_FlowType.AutoName, dbo.WF_FlowType.ManageUsers, dbo.WF_FlowType.QueryUsers, 
                      dbo.WF_FlowType.QueryItem, dbo.WF_FlowType.AttachMaxSize, dbo.WF_FlowType.ManageNames, dbo.WF_FlowType.QueryNames, 
                      dbo.WF_FlowType.FlowAttach, dbo.WF_FlowType.CanStartUsers, dbo.WF_FlowType.CanStartRoles, dbo.WF_FlowType.CanStartRolesId, 
                      dbo.WF_FlowType.CanStartNames, dbo.WF_FlowType.EntId, dbo.WF_FlowType.EntName, dbo.WF_FlowType.IsPigeonhole, 
                      dbo.WF_FlowType.PigeonholedSQL, dbo.WF_FlowType.IsFreeFlow, ISNULL(dbo.WF_FlowType.Creator, '''') AS Creator, 
                      ISNULL(dbo.WF_FlowType.CreateTime, '''') AS CreateTime, dbo.WF_FlowType.LaunchIsOpen
FROM         dbo.WF_FlowType LEFT OUTER JOIN
                      dbo.WF_FlowSort ON dbo.WF_FlowType.SortId = dbo.WF_FlowSort.SortId
' 
END 
----------------------------------------------------------------------------------------  上：视图  ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------  下：外键  ----------------------------------------------------------------------------------
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_AjaxFormField_Run_FZET_AjaxForm_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_AjaxFormField_Run]')) 
   ALTER TABLE dbo.[Dcx_AjaxFormField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_AjaxFormField_Run_FZET_AjaxForm_Run] FOREIGN KEY(Form_EntId) 
REFERENCES dbo.Dcx_AjaxForm_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_Analysis_FZET_analysis_type]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_Analysis]')) 
   ALTER TABLE dbo.[Dcx_Analysis]  WITH CHECK ADD  CONSTRAINT [FK_FZET_Analysis_FZET_analysis_type] FOREIGN KEY(TypeId) 
REFERENCES dbo.Dcx_Analysis_Type (TypeId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_Analysis_Chart_Dcx_Analysis]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Chart]')) 
   ALTER TABLE dbo.[Dcx_Analysis_Chart]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_Analysis_Chart_Dcx_Analysis] FOREIGN KEY(AnalysisId) 
REFERENCES dbo.Dcx_Analysis (AnalysisId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_Analysis_Condition_Dcx_Analysis]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Condition]')) 
   ALTER TABLE dbo.[Dcx_Analysis_Condition]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_Analysis_Condition_Dcx_Analysis] FOREIGN KEY(AnalysisId) 
REFERENCES dbo.Dcx_Analysis (AnalysisId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_Analysis_Field_Dcx_Analysis]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_Analysis_Field]')) 
   ALTER TABLE dbo.[Dcx_Analysis_Field]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_Analysis_Field_Dcx_Analysis] FOREIGN KEY(AnalysisId) 
REFERENCES dbo.Dcx_Analysis (AnalysisId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_BlockListField_Run_FZET_BlockList_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_BlockListField_Run]')) 
   ALTER TABLE dbo.[Dcx_BlockListField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_BlockListField_Run_FZET_BlockList_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_BlockList_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_BrowseReportField_Run_FZET_BrowseReport_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_BrowseReportField_Run]')) 
   ALTER TABLE dbo.[Dcx_BrowseReportField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_BrowseReportField_Run_FZET_BrowseReport_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_BrowseReport_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_CrossReportField_Run_FZET_CrossReport_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_CrossReportField_Run]')) 
   ALTER TABLE dbo.[Dcx_CrossReportField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_CrossReportField_Run_FZET_CrossReport_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_CrossReport_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_DefaultBrowseField_Run_FZET_DefaultBrowse_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_DefaultBrowseField_Run]')) 
   ALTER TABLE dbo.[Dcx_DefaultBrowseField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_DefaultBrowseField_Run_FZET_DefaultBrowse_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_DefaultBrowse_Run (EntId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_DefaultFormField_Run_FZET_DefaultForm_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_DefaultFormField_Run]')) 
   ALTER TABLE dbo.[Dcx_DefaultFormField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_DefaultFormField_Run_FZET_DefaultForm_Run] FOREIGN KEY(Form_EntId) 
REFERENCES dbo.Dcx_DefaultForm_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_Dept_FZET_Company]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_Dept]')) 
   ALTER TABLE dbo.[Dcx_Dept]  WITH CHECK ADD  CONSTRAINT [FK_FZET_Dept_FZET_Company] FOREIGN KEY(CompanyId) 
REFERENCES dbo.Dcx_Company (CompanyId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_DeptPrivilege_FZET_User]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]')) 
   ALTER TABLE dbo.[Dcx_DeptPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_FZET_DeptPrivilege_FZET_User] FOREIGN KEY(UserId) 
REFERENCES dbo.Dcx_User (UserId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_DeptPrivilege_FZET_Dept]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_DeptPrivilege]')) 
   ALTER TABLE dbo.[Dcx_DeptPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_FZET_DeptPrivilege_FZET_Dept] FOREIGN KEY(DeptId) 
REFERENCES dbo.Dcx_Dept (DeptId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_DiaryPrivilege_Dcx_Diary]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_DiaryPrivilege]')) 
   ALTER TABLE dbo.[Dcx_DiaryPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_DiaryPrivilege_Dcx_Diary] FOREIGN KEY(DyId) 
REFERENCES dbo.Dcx_Diary (DyId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_DiaryReply_Dcx_Diary]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_DiaryReply]')) 
   ALTER TABLE dbo.[Dcx_DiaryReply]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_DiaryReply_Dcx_Diary] FOREIGN KEY(DyId) 
REFERENCES dbo.Dcx_Diary (DyId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_EntityPrivilege_FZET_Role]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_EntityPrivilege]')) 
   ALTER TABLE dbo.[Dcx_EntityPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_FZET_EntityPrivilege_FZET_Role] FOREIGN KEY(RoleId) 
REFERENCES dbo.Dcx_Role (RoleId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_FilterViewCondition_Run_FZET_FilterView_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_FilterViewCondition_Run]')) 
   ALTER TABLE dbo.[Dcx_FilterViewCondition_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_FilterViewCondition_Run_FZET_FilterView_Run] FOREIGN KEY(EntId) 
REFERENCES dbo.Dcx_FilterView_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_GroupInterfaceField_Run_FZET_GroupInterface_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_GroupInterfaceField_Run]')) 
   ALTER TABLE dbo.[Dcx_GroupInterfaceField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_GroupInterfaceField_Run_FZET_GroupInterface_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_GroupInterface_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_GroupReportField_Run_FZET_GroupReport_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_GroupReportField_Run]')) 
   ALTER TABLE dbo.[Dcx_GroupReportField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_GroupReportField_Run_FZET_GroupReport_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_GroupReport_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_IMail_Attachment_Dcx_IMail]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_IMail_Attachment]')) 
   ALTER TABLE dbo.[Dcx_IMail_Attachment]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_IMail_Attachment_Dcx_IMail] FOREIGN KEY(MailId) 
REFERENCES dbo.Dcx_IMail (MailId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_IMailReceiver_Dcx_IMail]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_IMailReceiver]')) 
   ALTER TABLE dbo.[Dcx_IMailReceiver]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_IMailReceiver_Dcx_IMail] FOREIGN KEY(MailId) 
REFERENCES dbo.Dcx_IMail (MailId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_ImgSummyListField_Run_FZET_ImgSummyList_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_ImgSummyListField_Run]')) 
   ALTER TABLE dbo.[Dcx_ImgSummyListField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_ImgSummyListField_Run_FZET_ImgSummyList_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_ImgSummyList_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_IMRoomLgr_Dcx_IMRoom]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_IMRoomLgr]')) 
   ALTER TABLE dbo.[Dcx_IMRoomLgr]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_IMRoomLgr_Dcx_IMRoom] FOREIGN KEY(RoomId) 
REFERENCES dbo.Dcx_IMRoom (RoomId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_LinkMan_Dcx_LinkManGroup]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_LinkMan]')) 
   ALTER TABLE dbo.[Dcx_LinkMan]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_LinkMan_Dcx_LinkManGroup] FOREIGN KEY(GroupId) 
REFERENCES dbo.Dcx_LinkManGroup (GroupId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_ListFormField_Run_FZET_ListForm_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_ListFormField_Run]')) 
   ALTER TABLE dbo.[Dcx_ListFormField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_ListFormField_Run_FZET_ListForm_Run] FOREIGN KEY(Form_EntId) 
REFERENCES dbo.Dcx_ListForm_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_ListReportField_Run_FZET_ListReport_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_ListReportField_Run]')) 
   ALTER TABLE dbo.[Dcx_ListReportField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_ListReportField_Run_FZET_ListReport_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_ListReport_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_MailReceiver_Dcx_Mail]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_MailReceiver]')) 
   ALTER TABLE dbo.[Dcx_MailReceiver]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_MailReceiver_Dcx_Mail] FOREIGN KEY(MailId) 
REFERENCES dbo.Dcx_Mail (MailId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_MenuAppArea_FZET_Menu]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_MenuAppArea]')) 
   ALTER TABLE dbo.[Dcx_MenuAppArea]  WITH CHECK ADD  CONSTRAINT [FK_FZET_MenuAppArea_FZET_Menu] FOREIGN KEY(MenuId) 
REFERENCES dbo.Dcx_Menu_Run (MenuId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_MenuPrivilege_FZET_Role]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilege]')) 
   ALTER TABLE dbo.[Dcx_MenuPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_FZET_MenuPrivilege_FZET_Role] FOREIGN KEY(RoleId) 
REFERENCES dbo.Dcx_Role (RoleId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_MenuPrivilege_FZET_Menu_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_MenuPrivilege]')) 
   ALTER TABLE dbo.[Dcx_MenuPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_FZET_MenuPrivilege_FZET_Menu_Run] FOREIGN KEY(MenuId) 
REFERENCES dbo.Dcx_Menu_Run (MenuId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_MessageReceiver_Dcx_MessageType]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_MessageTypeReceiver]')) 
   ALTER TABLE dbo.[Dcx_MessageTypeReceiver]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_MessageReceiver_Dcx_MessageType] FOREIGN KEY(EntId) 
REFERENCES dbo.Dcx_MessageType (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_Dcx_NewsPrivilege_Dcx_News]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_NewsPrivilege]')) 
   ALTER TABLE dbo.[Dcx_NewsPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_Dcx_NewsPrivilege_Dcx_News] FOREIGN KEY(NewsId) 
REFERENCES dbo.Dcx_News (NId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_OutPutField_Run_FZET_OutPut_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_OutPutField_Run]')) 
   ALTER TABLE dbo.[Dcx_OutPutField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_OutPutField_Run_FZET_OutPut_Run] FOREIGN KEY(EntId) 
REFERENCES dbo.Dcx_OutPut_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_SearchFormField_Run_FZET_SearchForm_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_SearchFormField_Run]')) 
   ALTER TABLE dbo.[Dcx_SearchFormField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_SearchFormField_Run_FZET_SearchForm_Run] FOREIGN KEY(Form_EntId) 
REFERENCES dbo.Dcx_SearchForm_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_SummaryListField_Run_FZET_SummaryList_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_SummaryListField_Run]')) 
   ALTER TABLE dbo.[Dcx_SummaryListField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_SummaryListField_Run_FZET_SummaryList_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_SummaryList_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_TitleListField_Run_FZET_TitleList_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TitleListField_Run]')) 
   ALTER TABLE dbo.[Dcx_TitleListField_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_TitleListField_Run_FZET_TitleList_Run] FOREIGN KEY(Report_EntId) 
REFERENCES dbo.Dcx_TitleList_Run (EntId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_Tree_Cell_Run_FZET_Tree_Run]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TreeCell_Run]')) 
   ALTER TABLE dbo.[Dcx_TreeCell_Run]  WITH CHECK ADD  CONSTRAINT [FK_FZET_Tree_Cell_Run_FZET_Tree_Run] FOREIGN KEY(TreeId) 
REFERENCES dbo.Dcx_Tree_Run (TreeId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_User_FZET_Account]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_User]')) 
   ALTER TABLE dbo.[Dcx_User]  WITH CHECK ADD  CONSTRAINT [FK_FZET_User_FZET_Account] FOREIGN KEY(AccountId) 
REFERENCES dbo.Dcx_Account (AccountId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_UserInRole_FZET_User]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_UserInRole]')) 
   ALTER TABLE dbo.[Dcx_UserInRole]  WITH CHECK ADD  CONSTRAINT [FK_FZET_UserInRole_FZET_User] FOREIGN KEY(UserId) 
REFERENCES dbo.Dcx_User (UserId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_UserInRole_FZET_Role]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_UserInRole]')) 
   ALTER TABLE dbo.[Dcx_UserInRole]  WITH CHECK ADD  CONSTRAINT [FK_FZET_UserInRole_FZET_Role] FOREIGN KEY(RoleId) 
REFERENCES dbo.Dcx_Role (RoleId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_WF_CanWriteField_WF_FlowNode]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_CanWriteField]')) 
   ALTER TABLE dbo.[WF_CanWriteField]  WITH CHECK ADD  CONSTRAINT [FK_WF_CanWriteField_WF_FlowNode] FOREIGN KEY(NodeId) 
REFERENCES dbo.WF_FlowNode (NodeId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_WF_Depute_WF_FlowRunPrcs]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_Depute]')) 
   ALTER TABLE dbo.[WF_Depute]  WITH CHECK ADD  CONSTRAINT [FK_WF_Depute_WF_FlowRunPrcs] FOREIGN KEY(PrcsId) 
REFERENCES dbo.WF_FlowRunPrcs (PrcsId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_WF_FlowNode_WF_FlowType]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_FlowNode]')) 
   ALTER TABLE dbo.[WF_FlowNode]  WITH CHECK ADD  CONSTRAINT [FK_WF_FlowNode_WF_FlowType] FOREIGN KEY(FlowId) 
REFERENCES dbo.WF_FlowType (FlowId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_WF_FlowNodePrivilege_WF_FlowNode]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_FlowNodePrivilege]')) 
   ALTER TABLE dbo.[WF_FlowNodePrivilege]  WITH CHECK ADD  CONSTRAINT [FK_WF_FlowNodePrivilege_WF_FlowNode] FOREIGN KEY(NodeId) 
REFERENCES dbo.WF_FlowNode (NodeId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_hyoa_flow_run_hyoa_flow_type]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_FlowRun]')) 
   ALTER TABLE dbo.[WF_FlowRun]  WITH CHECK ADD  CONSTRAINT [FK_hyoa_flow_run_hyoa_flow_type] FOREIGN KEY(FlowId) 
REFERENCES dbo.WF_FlowType (FlowId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_hyoa_flow_run_file_hyoa_flow_run]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_FlowRunFile]')) 
   ALTER TABLE dbo.[WF_FlowRunFile]  WITH CHECK ADD  CONSTRAINT [FK_hyoa_flow_run_file_hyoa_flow_run] FOREIGN KEY(RunId) 
REFERENCES dbo.WF_FlowRun (RunId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_hyoa_flow_run_prcs_hyoa_flow_run]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcs]')) 
   ALTER TABLE dbo.[WF_FlowRunPrcs]  WITH CHECK ADD  CONSTRAINT [FK_hyoa_flow_run_prcs_hyoa_flow_run] FOREIGN KEY(RunId) 
REFERENCES dbo.WF_FlowRun (RunId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_WF_FlowRunPrcsPrivilege_WF_FlowRunPrcs]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_FlowRunPrcsPrivilege]')) 
   ALTER TABLE dbo.[WF_FlowRunPrcsPrivilege]  WITH CHECK ADD  CONSTRAINT [FK_WF_FlowRunPrcsPrivilege_WF_FlowRunPrcs] FOREIGN KEY(PrcsId) 
REFERENCES dbo.WF_FlowRunPrcs (PrcsId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_Flow_NodeCondition_hyoa_flow_process]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_NodeCondition]')) 
   ALTER TABLE dbo.[WF_NodeCondition]  WITH CHECK ADD  CONSTRAINT [FK_FZET_Flow_NodeCondition_hyoa_flow_process] FOREIGN KEY(NodeId) 
REFERENCES dbo.WF_FlowNode (NodeId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_WF_Rebut_WF_Rebut]') AND parent_object_id = OBJECT_Id(N'dbo.[WF_Rebut]')) 
   ALTER TABLE dbo.[WF_Rebut]  WITH CHECK ADD  CONSTRAINT [FK_WF_Rebut_WF_Rebut] FOREIGN KEY(RunId) 
REFERENCES dbo.WF_FlowRun (RunId) 
ON DELETE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_TabAccountInfo_TabAccountIndex]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TabAccountInfo]')) 
   ALTER TABLE dbo.[Dcx_TabAccountInfo]  WITH CHECK ADD  CONSTRAINT [FK_TabAccountInfo_TabAccountIndex] FOREIGN KEY(UserId) 
REFERENCES dbo.Dcx_TabAccountIndex (UserId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_TabMailGroup_TabAccountIndex]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TabMailGroup]')) 
   ALTER TABLE dbo.[Dcx_TabMailGroup]  WITH CHECK ADD  CONSTRAINT [FK_TabMailGroup_TabAccountIndex] FOREIGN KEY(UserId) 
REFERENCES dbo.Dcx_TabAccountIndex (UserId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_TabMailGroupMember_TabAccountIndex]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TabMailGrpMemb]')) 
   ALTER TABLE dbo.[Dcx_TabMailGrpMemb]  WITH CHECK ADD  CONSTRAINT [FK_TabMailGroupMember_TabAccountIndex] FOREIGN KEY(UserId) 
REFERENCES dbo.Dcx_TabAccountIndex (UserId) 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_TabMailGroupMember_TabMailGroup]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TabMailGrpMemb]')) 
   ALTER TABLE dbo.[Dcx_TabMailGrpMemb]  WITH CHECK ADD  CONSTRAINT [FK_TabMailGroupMember_TabMailGroup] FOREIGN KEY(MailGroupId) 
REFERENCES dbo.Dcx_TabMailGroup (MailGroupId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_TabUsrMailFolder_TabAccountIndex1]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_TabUsrMailFolder]')) 
   ALTER TABLE dbo.[Dcx_TabUsrMailFolder]  WITH CHECK ADD  CONSTRAINT [FK_TabUsrMailFolder_TabAccountIndex1] FOREIGN KEY(UserId) 
REFERENCES dbo.Dcx_TabAccountIndex (UserId) 
ON DELETE Cascade 
ON  UPDATE Cascade 
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_Id(N'dbo.[FK_FZET_Team_FZET_Team]') AND parent_object_id = OBJECT_Id(N'dbo.[Dcx_Team]')) 
   ALTER TABLE dbo.[Dcx_Team]  WITH CHECK ADD  CONSTRAINT [FK_FZET_Team_FZET_Team] FOREIGN KEY(Super_Team_Id) 
REFERENCES dbo.Dcx_Team (Team_Id) 
----------------------------------------------------------------------------------------  上：外键  ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------  下：存储过程  ----------------------------------------------------------------------------------
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_AddField]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_AddField]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_AddField]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--新增表字段
CREATE PROCEDURE [dbo].[Dcx_DB_AddField]
(
@TableName varchar(100),
@FieldName varchar(100),
@FieldExplain varchar(200),--字段说明
@DataType varchar(100),--数据类型
--@ConnectTableName varchar(100),
@FieldLength int
)
as
declare @NewsId int  --成功或失败
begin transaction mytran --开始事务
declare @errorSum int
if not exists (SELECT * FROM syscolumns    where id=object_id(@TableName)   AND name=@FieldName) 
begin
	declare @sql varchar(8000)
	set @TableName=replace(@TableName,'' '','''')
	--生成SQL语句
	if(@DataType=''decimal'') 
		set @sql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType +''('' +Convert(varchar,@FieldLength)+'',2''+'')''
	else if(@DataType=''varchar'')
		set @sql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType +''('' +Convert(varchar,@FieldLength)+'')''
	else
		set @sql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType
	exec(@sql) --添加字段
	--字段描述
	EXECUTE sp_addextendedproperty   N''MS_Description'', @FieldExplain,   N''user'',  N''dbo'',  N''Table'', @TableName, N''column'' , @FieldName;
	set @errorSum=@errorSum+@@error
	set @NewsId=0;
end
else
	set @NewsId=1;
if(@errorSum>0)
begin --出错
	rollback tran
end
else 
begin --成功
   commit tran mytran
end
select @NewsId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_AddFiled]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_AddFiled]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_AddFiled]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--新增表字段
CREATE PROCEDURE [dbo].[Dcx_DB_AddFiled]
(
@TableName varchar(100),
@FieldName varchar(100),
@FieldExplain varchar(200),
@DataType varchar(100),
@ConnectTableName varchar(100),
@FieldLength int,
@NewsId int output
)
as
begin transaction mytran
declare @errorSum int
if not exists (SELECT * FROM syscolumns    where id=object_id(@TableName)   AND name=@FieldName) 
begin
insert tb_TableField 
(
TableName,
FieldName,
FieldExplain,
DataType,
ConnectTableName,
FieldLength,
UserSetSign
)
values
(
@TableName,
@FieldName,
@FieldExplain,
@DataType,
@ConnectTableName,
@FieldLength,
''1''
)
declare @sql varchar(8000)
--判断类型
if(@DataType=''decimal'')
begin
set @sql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType +''('' +Convert(varchar,@FieldLength)+'',2''+'')''
end
else if(@DataType=''varchar'')
begin
set @sql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType +''('' +Convert(varchar,@FieldLength)+'')''
end
else
begin
set @sql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType
end
exec(@sql)
EXECUTE sp_addextendedproperty   N''MS_Description'', @FieldExplain,   N''user'',  N''dbo'',  N''Table'', @TableName, N''column'' , @FieldName;
 set @errorSum=@errorSum+@@error
 set @NewsId=0;
end
else
begin
set @NewsId=1;
end
if(@errorSum>0)
begin
 rollback tran
end
else
begin
   commit tran mytran
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_DBTableIsExists]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_DBTableIsExists]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_DBTableIsExists]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_DB_DBTableIsExists] 
@DBTableName varchar(100)
AS
BEGIN
--declare @DBTableName varchar(50)
--set @DBTableName=''Dcx_DBTableField_Run''
select count(*) from sysobjects o where (o.xtype = ''U'' or o.xtype = ''V'' ) and o.name=@DBTableName
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetAllTableName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_GetAllTableName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetAllTableName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_DB_GetAllTableName] 
--@Rowcount int OUTPUT
AS
BEGIN
select   name   from   sysobjects where xtype=''U'' order by name
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetDBDataTableMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_GetDBDataTableMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetDBDataTableMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_DB_GetDBDataTableMsg] 
@TableName varchar(100)
AS
BEGIN
 SELECT    
[name]       =a.name,   
[datatype]   =b.name,   
[Identity]   =case   when   COLUMNPROPERTY(   a.id,a.name,''IsIdentity'')=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
[key]        =case   when   exists(SELECT 1 FROM sysobjects where xtype=''PK'' and name in (SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then cast(1 as bit) else cast(0 as bit) end,   
[encodedname]=a.name,   
[nulls]      =case   when   a.isnullable=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
[size]       =a.length,   
[precision]  =COLUMNPROPERTY(a.id,a.name,''PRECISION''),   
[scale]      =isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0),   
[default]    =isnull(e.text,''''),   
[字段说明]   =isnull(g.[value],''''), 
[id]         =case   when   a.colorder=1   then   cast(1 as bit)    else   cast(0 as bit) end,
[表名]       =case   when   a.colorder=1   then   d.name   else   ''''   end,
[表说明]     =case   when   a.colorder=1   then   isnull(f.value,'''')   else   ''''   end,
[字段序号]   =a.colorder
FROM   syscolumns   a   
left   join   systypes   b   on   a.xtype=b.xusertype   
inner   join   sysobjects   d   on   a.id=d.id     and   d.xtype=''U''   and     d.name<>''dtproperties''   
left   join   syscomments   e   on   a.cdefault=e.id   
left   join   sys.extended_properties   g   on   a.id=g.major_id   and   a.colid=g.minor_id       
left   join   sys.extended_properties   f   on   d.id=f.major_id   and   f.minor_id=0  
--left join  sys.sp_addextendedproperty dd  on   a.name=dd.name  
where   d.name=@TableName  order   by   a.colorder  
--            SELECT 
--            	   (case when a.colorder=1 then d.name else d.name end)表名,
--                   a.colorder 字段序号,
--                   a.name 字段名,
--                   (case when COLUMNPROPERTY( a.id,a.name,''IsIdentity'')=1 then ''√''else '''' end) 标识,
--                   (case when (SELECT count(*)
--                   FROM sysobjects
--                   WHERE (name in
--                             (SELECT name
--                            FROM sysindexes
--                            WHERE (id = a.id) AND (indid in
--                                      (SELECT indid
--                                     FROM sysindexkeys
--                                     WHERE (id = a.id) AND (colid in
--                                               (SELECT colid
--                                              FROM syscolumns
--                                              WHERE (id = a.id) AND (name = a.name))))))) AND
--                          (xtype = ''PK''))>0 then ''√'' else '''' end) 主键,
--                   b.name 类型,
--                   a.length 占用字节数,
--                   COLUMNPROPERTY(a.id,a.name,''PRECISION'') as 长度,
--                   isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0) as 小数位数,
--                   (case when a.isnullable=1 then ''√'' else '''' end) 允许空,
--                   isnull(e.text,'''') 默认值,
--                   isnull(g.[value],'''') AS 字段说明    
--            FROM syscolumns a left join systypes b 
--             on a.xtype=b.xusertype 
--             inner join sysobjects d 
--             on a.id=d.id and  (d.xtype=''U'' or d.xtype=''V'')  and d.name<>''dtproperties'' 
--             left join syscomments e 
--             on a.cdefault=e.id 
--             left join sys.extended_properties g 
--             on a.id=g.major_id AND a.colid = g.minor_id  
--             where d.name=@table_name
--             order by a.id,a.colorder
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetFieldList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_GetFieldList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetFieldList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_DB_GetFieldList] 
@DBTableName varchar(100)
AS
BEGIN
SELECT     
[FieldName]       =a.name,   
[FieldDataType]   =b.name,   
[IsIdentity]   =case   when   COLUMNPROPERTY(   a.id,a.name,''IsIdentity'')=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
[IsKey]        =case   when   exists(SELECT 1 FROM sysobjects where xtype=''PK'' and name in (SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then cast(1 as bit) else cast(0 as bit) end,   
[IsNullAble]      =case   when   a.isnullable=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
[Length]       =a.length,   
[precision]  =COLUMNPROPERTY(a.id,a.name,''PRECISION''),   
[Scale]      =isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0),   
[DefaultValue]    =isnull(e.text,'''')   ,
[DefaultConstraint]    =(case when a.cdefault>0 then (Select k.Name From sysobjects k Where k.xType = ''D'' and k.id=a.cdefault  ) else '''' end)
FROM   syscolumns   a   
left   join   systypes   b   on   a.xtype=b.xusertype   
inner   join   sysobjects   d   on   a.id=d.id     and   d.xtype=''U''   and     d.name<>''dtproperties''   
left   join   syscomments   e   on   a.cdefault=e.id   
where   d.name=@DBTableName  order   by   a.colorder 
--SELECT     
--[name]       =a.name,   
--[datatype]   =b.name,   
--[Identity]   =case   when   COLUMNPROPERTY(   a.id,a.name,''IsIdentity'')=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
--[key]        =case   when   exists(SELECT 1 FROM sysobjects where xtype=''PK'' and name in (SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then cast(1 as bit) else cast(0 as bit) end,   
--[encodedname]=a.name,   
--[nulls]      =case   when   a.isnullable=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
--[size]       =a.length,   
--[precision]  =COLUMNPROPERTY(a.id,a.name,''PRECISION''),   
--[scale]      =isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0),   
--[default]    =isnull(e.text,''''),   
--[字段说明]   =isnull(g.[value],''''), 
--[id]         =case   when   a.colorder=1   then   cast(1 as bit)    else   cast(0 as bit) end,
--[表名]       =case   when   a.colorder=1   then   d.name   else   ''''   end,
--[表说明]     =case   when   a.colorder=1   then   isnull(f.value,'''')   else   ''''   end,
--[字段序号]   =a.colorder
--FROM   syscolumns   a   
--left   join   systypes   b   on   a.xtype=b.xusertype   
--inner   join   sysobjects   d   on   a.id=d.id     and   d.xtype=''U''   and     d.name<>''dtproperties''   
--left   join   syscomments   e   on   a.cdefault=e.id   
--left   join   sys.extended_properties   g   on   a.id=g.major_id   and   a.colid=g.minor_id       
--left   join   sys.extended_properties   f   on   d.id=f.major_id   and   f.minor_id=0   
--where   d.name=@DBTableName  order   by   a.colorder 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetFieldName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_GetFieldName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetFieldName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_DB_GetFieldName] 
@table_name varchar(50)
--@Rowcount int OUTPUT
AS
BEGIN
select   name   from   syscolumns   where   id=object_id(  @table_name ) 
and name!=''FD_Id '' and name!=''feedback'' and name!=''form_id'' and name!=''run_id'' 
and name!=''Run_pid''
and name!=''User_id '' and name!=''Zc_flag''  and name!=''LD_Id '' and name!=''flow_lsh'' 
--order by name asc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetTableMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_GetTableMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_GetTableMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[Dcx_DB_GetTableMsg]
@table_name varchar(50)
--@Rowcount int OUTPUT
AS
BEGIN
select   a.name as name        --字段名   
        , a.length  as length,
        c.name  as datatype      --数据类型   
  from   syscolumns   a,   
            sysobjects   b,   
            systypes   c     
  where   a.id=b.id   and   a.xtype=c.xtype   
  and   b.name=@table_name  
  and a.name!=''FD_Id '' and a.name!=''feedback'' and a.name!=''form_id'' 
  and a.name!=''run_id'' 
and a.name!=''Run_pid''
and a.name!=''User_id '' and a.name!=''Zc_flag''-- order by name asc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_UpdateField]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DB_UpdateField]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DB_UpdateField]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--修改表字段
CREATE PROCEDURE [dbo].[Dcx_DB_UpdateField]
(
@TableName varchar(100),
@FieldName varchar(100),
@FieldExplain varchar(200),
@DataType varchar(100),
@ConnectTableName varchar(100),
@FieldLength int,
@PaySystemField varchar (100),
@Id int,
@NewsId int output
)
as
begin transaction mytran
begin try
	declare @fname varchar(100)
	declare @filetype varchar(20)
	declare @tsql varchar(1000)
	---先取出表中以前的字段名称
	select  @fname=FieldName,@filetype=DataType from  tb_TableField where Id=@Id
	declare @pstid int
	declare @sql varchar(8000)
	--再根据字段名称取出tb_PaySystemToLocation中对应的Id
	select  @pstid=Id from  tb_PaySystemToLocation where LocationField=@fname
	if(@filetype!=@DataType)--如果字段类型修改了
	begin
		if(@DataType=''decimal'')
			set @tsql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType +''('' +Convert(varchar,@FieldLength)+'',2''+'')''
		else if(@DataType=''varchar'')
			set @tsql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType +''('' +Convert(varchar,@FieldLength)+'')''
		else
			set @tsql = ''alter table '' + @TableName +'' add '' + @FieldName +'' '' + @DataType 
		declare @delsql varchar(1000)
		set @delsql=''ALTER TABLE '' +@TableName+ '' DROP COLUMN ''+ @fname
		exec(@delsql)--先删除旧字段 再添加新字段
		exec(@tsql)
		EXECUTE sp_addextendedproperty   N''MS_Description'', @FieldExplain,   N''user'',  N''dbo'',  N''Table'', @TableName, N''column'' , @FieldName;
	end
	if(@fname!=@FieldName) 
	begin 
		set @sql = ''sp_rename ''+CHAR(39)+@TableName+''.[''+@fname+'']''+CHAR(39)+'','' +char(39)+@FieldName+char(39)+'','' +  char(39)+''COLUMN'' +CHAR(39)
		exec(@sql)
	end
--	update tb_TableField set TableName=@TableName,FieldName=@FieldName,
--	 FieldExplain=@FieldExplain, DataType=@DataType,ConnectTableName=@ConnectTableName,FieldLength=@FieldLength where Id=@Id
	--修改字段说明
	EXECUTE sp_updateextendedproperty   N''MS_Description'', @FieldExplain,   N''user'',  N''dbo'',  N''Table'', @TableName, N''column'' , @FieldName;
	update tb_PaySystemToLocation set PaySystemField=@PaySystemField,LocationField=@FieldName,TableName=@TableName where Id=@pstid
	set @NewsId=0
	commit tran mytran
end try
begin catch 
	insert into tb_error (Message)values(ERROR_MESSAGE())
	set @NewsId=1
	if(@@TRANCOUNT >0)
		rollback transaction mytran
end catch
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeleteOnlineUserByUserIdorIP]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_DeleteOnlineUserByUserIdorIP]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_DeleteOnlineUserByUserIdorIP]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_DeleteOnlineUserByUserIdorIP]
@UserId int,
@Ip char(20)
AS
delete FROM [Dcx_OnlineUser] WHERE [UserId]=@UserId or [IP]=@Ip
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GetOnlineUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_GetOnlineUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GetOnlineUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_GetOnlineUser]
@UserId int,
@Password char(32)
AS
SELECT TOP 1 * FROM [Dcx_OnlineUser] WHERE [UserId]=@UserId AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GetOnlineUserByIP]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_GetOnlineUserByIP]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_GetOnlineUserByIP]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_GetOnlineUserByIP]
@UserId int,
@Ip char(30)
AS
SELECT TOP 1 * FROM [Dcx_OnlineUser] WHERE [UserId]=@UserId AND [IP]=@Ip
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Module_GetTemplateModule]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_Module_GetTemplateModule]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Module_GetTemplateModule]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_Module_GetTemplateModule] --获取模板的模块信息
@TemplateId int 
AS
BEGIN
SELECT TemplateId,Dcx_Module. [ModuleId]
      ,[ModuleName]
      ,[Dcx_Module].[ModuleTypeId]
      ,[ModuleOrder]
      ,[JsCss_Link]
      ,'''' as [ModuleHtml]
      ,[ModuleUrl]
      ,[ImageUrl]
      ,[ExampleImgUrl]
      ,[StyleId]
 FROM Dcx_TemplateArea   inner join 
[Dcx_Module] on Dcx_TemplateArea.[ModuleId]=[Dcx_Module].[ModuleId]
where TemplateId = @TemplateId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish_Deal]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_Publish_Deal]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish_Deal]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_Publish_Deal] --发布成功后，更新
@Id int, 
@UserName varchar(50) ,
@UserId int 
AS
BEGIN 
UPDATE [Dcx_Publish] SET [IsPublish] =1 ,[EditTime] =getdate(),[Editor] =@UserName WHERE  [Id]=@Id and [CreatorId]=@UserId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish_DeleteUnPublish]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_Publish_DeleteUnPublish]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Publish_DeleteUnPublish]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_Publish_DeleteUnPublish] --新的发布到来时，把久的未处理的发布删掉
@PublishId varchar(50) ,
@EntId int ,
@ModuleTypeId int 
AS
BEGIN 
delete from [Dcx_Publish]  WHERE  [IsPublish] =0 and [PublishId]=@PublishId and [ModuleTypeId]=@ModuleTypeId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_StaffSearch]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_StaffSearch]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_StaffSearch]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 





CREATE PROC [dbo].[Dcx_StaffSearch]
@Name varchar(200),
@Mobile varchar(100),
@Email varchar(100),
@Gender varchar(100),
@PositionId int,
@SearchBound varchar(50)
/*--------------------------------------
功能：查询人员
参数：
	@Name	人员姓名
	@Mobile	手机号码
	@Email	email
	@Gender	性别
	@PositionId	职位id
	@SearchBound	查询范围
---------------------------------------*/
AS
DECLARE @SQL VARCHAR(500)
DECLARE @HAVECONDITION BIT
IF @PositionId=0
	SET @SQL = ''SELECT Dcx_Position.Position_Name,Dcx_staff.*,Case Sex When 1 Then ''''男'''' Else ''''女'''' End AS SexName FROM Dcx_STAFF Left OUTER JOIN Dcx_Staff_In_Position ON Dcx_STAFF.userId=Dcx_Staff_In_Position.[UserId] INNER JOIN Dcx_Position ON Dcx_Staff_In_Position.Position_Id=Dcx_Position.Position_Id''
ELSE
	SET @SQL = ''SELECT Dcx_Position.Position_Name,Dcx_staff.*,Case Sex When 1 Then ''''男'''' Else ''''女'''' End AS SexName FROM Dcx_STAFF INNER JOIN Dcx_Staff_In_Position ON Dcx_STAFF.userId=Dcx_Staff_In_Position.[UserId] INNER JOIN Dcx_Position ON Dcx_Staff_In_Position.Position_Id=Dcx_Position.Position_Id ''
SET @HAVECONDITION = 0
	IF (@Name<>'''')
	BEGIN
		SET @SQL = @SQL + '' WHERE (UserName LIKE ''''%''+@Name+''%'''' OR RealName LIKE ''''%''+@Name+''%'''')''
		SET @HAVECONDITION = 1
	END
	IF (@Mobile<>'''')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Mobile LIKE ''''%''+@Mobile+''%'''')''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Mobile LIKE ''''%''+@Mobile+''%'''')''
	END
	IF (@Email<>'''')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Email LIKE ''''%''+@Email+''%'''')''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Email LIKE ''''%''+@Email+''%'''')''
	END
	IF (@Gender<>'''')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			IF @Gender=''male''
			BEGIN
				SET @SQL = @SQL + '' WHERE (Sex=1)''
				SET @HAVECONDITION = 1
			END	
			ELSE
			BEGIN
				SET @SQL = @SQL + '' WHERE (Sex=0)''
				SET @HAVECONDITION = 1
			END
		END
		ELSE
			IF @Gender=''male''
			BEGIN
				SET @SQL = @SQL + '' AND (Sex=1)''
			END
			ELSE
			BEGIN
				SET @SQL = @SQL + '' AND (Sex=0)''
			END
	END
	IF (@PositionId<>0)
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Dcx_Position.Position_Id=''+Convert(varchar(5),@PositionId)+'')''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Dcx_Position.Position_Id=''+Convert(varchar(5),@PositionId)+'')''
	END
	IF (@SearchBound=''on'')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Dcx_User.Dimission=0)''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Dcx_User.Dimission=0)''
	END
	IF (@SearchBound=''off'')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Dcx_User.Dimission=1)''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Dcx_User.Dimission=1)''
	END
	PRINT @SQL
	EXECUTE  (@SQL)
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemPublish_GetListByTypeId_Page]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_SystemPublish_GetListByTypeId_Page]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemPublish_GetListByTypeId_Page]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_SystemPublish_GetListByTypeId_Page]
@TradeId int,
@TypeId int,
@PageSize int,
@PageIndex int
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @PageSize is null or @PageSize<1
	set @PageSize=20
if @PageIndex is null or @PageIndex<1
	set @PageIndex=1
SET @startRow = (@PageIndex - 1) * @PageSize +1
SET @endRow = @startRow + @PageSize -1 
if @TypeId>0 and  @TradeId<1 
	select *  from (select row_number() over( order by [IsTop] desc,[IsPopular] desc,[PublishDate] desc)as dcx_rowid, 
	[PublishId],[SystemId],[SystemName],[Tags],[HomePage],[SystemImg],convert(char(10),[PublishDate],120) as [PublishDate],[TradeId],[TypeId],[Scale],[DownloadTimes],[IsPopular],[IsTop]
	from [Dcx_SystemPublish]     where [TypeId]=@TypeId ) AS MyTable  
	where  dcx_rowid between @startRow and @endRow
else if  @TradeId>0 and  @TypeId<1
	select *  from (select row_number() over( order by [IsTop] desc,[IsPopular] desc,[PublishDate] desc)as dcx_rowid, 
	[PublishId],[SystemId],[SystemName],[Tags],[HomePage],[SystemImg],convert(char(10),[PublishDate],120) as [PublishDate],[TradeId],[TypeId],[Scale],[DownloadTimes],[IsPopular],[IsTop]
	from [Dcx_SystemPublish]     where [TradeId]=@TradeId ) AS MyTable
	where  dcx_rowid between @startRow and @endRow
else  if  @TradeId=0 and  @TypeId=0
	select *  from (select row_number() over( order by [IsTop] desc,[IsPopular] desc,[PublishDate] desc)as dcx_rowid, 
	[PublishId],[SystemId],[SystemName],[Tags],[HomePage],[SystemImg],convert(char(10),[PublishDate],120) as [PublishDate],[TradeId],[TypeId],[Scale],[DownloadTimes],[IsPopular],[IsTop]
	from [Dcx_SystemPublish] ) AS MyTable
	where  dcx_rowid between @startRow and @endRow
else
	select *  from (select row_number() over( order by [IsTop] desc,[IsPopular] desc,[PublishDate] desc)as dcx_rowid, 
	[PublishId],[SystemId],[SystemName],[Tags],[HomePage],[SystemImg],convert(char(10),[PublishDate],120) as [PublishDate],[TradeId],[TypeId],[Scale],[DownloadTimes],[IsPopular],[IsTop]
	from [Dcx_SystemPublish]     where [TypeId]=@TypeId and [TradeId]=@TradeId) AS MyTable
	where  dcx_rowid between @startRow and @endRow
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemPublish_GetModel]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_SystemPublish_GetModel]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemPublish_GetModel]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_SystemPublish_GetModel]
@PublishId int
AS
begin
	select 	[PublishId],[SystemId],[SystemName],[Tags],[HomePage],[SystemImg],convert(char(10),[PublishDate],120) as [PublishDate],[TradeId],[TypeId],[Scale],[DownloadTimes],[IsPopular],[IsTop]
	from [Dcx_SystemPublish]     where [PublishId]=@PublishId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemPublish_GetNewSystem]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_SystemPublish_GetNewSystem]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_SystemPublish_GetNewSystem]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_SystemPublish_GetNewSystem]
@count int
AS
begin
	select top 15
	[PublishId],[SystemId],[SystemName],[Tags],[HomePage],[SystemImg],[PublishDate],[TradeId],[TypeId],[Scale],[DownloadTimes],[IsPopular],[IsTop]
	from [Dcx_SystemPublish]    order by [IsTop] desc,[IsPopular] desc,[PublishDate] desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Test_ReplaceFormString]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_Test_ReplaceFormString]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Test_ReplaceFormString]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--替换表单中指定字符（不对外发布）
 CREATE PROCEDURE [dbo].[Dcx_Test_ReplaceFormString]
@sStr varchar(3000) ,
@dStr varchar(3000) 
AS
BEGIN
UPDATE [Dcx_AjaxForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_DefaultForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_ListForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_SearchForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_AjaxFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),
[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_DefaultFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_ListFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_SearchFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_ModuleUICell] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml]=replace([LastHtml],@sStr,@dStr)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Test_ReplaceFormString2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_Test_ReplaceFormString2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_Test_ReplaceFormString2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
----替换表单中指定字符（不对外发布）
 CREATE PROCEDURE [dbo].[Dcx_Test_ReplaceFormString2]
@sStr varchar(3000) ,
@dStr varchar(3000) 
AS
BEGIN
UPDATE [Dcx_AjaxForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_DefaultForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_ListForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_SearchForm_Design] SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_BrowseReport_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_DefaultBrowse_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_SummaryList_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_ImgSummyList_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_BlockList_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_TitleList_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE Dcx_ListReport_Design SET [DesignHtml] =replace([DesignHtml],@sStr,@dStr)
UPDATE [Dcx_AjaxForm_Run] SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE [Dcx_AjaxFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),
[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_DefaultForm_Run] SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE [Dcx_DefaultFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_ListForm_Run] SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE [Dcx_ListFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_SearchForm_Run] SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE [Dcx_SearchFormField_Run] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[CtrlBeforeHtml] = replace([CtrlBeforeHtml],@sStr,@dStr)
,[CtrlfrontHtml] =replace([CtrlfrontHtml],@sStr,@dStr)
,[CtrlbackHtml] = replace([CtrlbackHtml],@sStr,@dStr)
,[CtrlLastHtml] =replace([CtrlLastHtml],@sStr,@dStr),
[LastHtml]=replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_BrowseReport_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_BrowseReportField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_DefaultBrowse_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_DefaultBrowseField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_SummaryList_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_SummaryListField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_ImgSummyList_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_ImgSummyListField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_BlockList_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_BlockListField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_TitleList_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_TitleListField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE Dcx_ListReport_Run SET AutoInitJs =replace(AutoInitJs,@sStr,@dStr),AutoOtherJS =replace(AutoOtherJS,@sStr,@dStr)
UPDATE Dcx_ListReportField_Run SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml] =replace([LastHtml],@sStr,@dStr)
UPDATE [Dcx_ModuleUICell] SET [BeforeHtml] =replace([BeforeHtml],@sStr,@dStr),[LastHtml]=replace([LastHtml],@sStr,@dStr)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckEmail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckEmail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckEmail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckEmail] 
@Email Char(50)
AS
BEGIN
if ltrim(rtrim(@Email))=''''
begin 
select 1
return
end
else
SELECT top 1 1 FROM [Dcx_User]  where [Email]=@Email
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckEmail2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckEmail2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckEmail2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckEmail2] 
@UserId int,
@Email varchar(50)
AS
BEGIN
if ltrim(rtrim(@Email))=''''
begin 
select 1
return
end
else
SELECT top 1 1 FROM [Dcx_User]  where [UserId]!=@UserId and [Email]=@Email 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByEmail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckPasswordByEmail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByEmail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckPasswordByEmail]
@AccountId int ,
@UserId int,
@Email varchar(100),
@Password varchar(100)
AS
SELECT TOP 1 1 FROM [Dcx_User] WHERE [AccountId]=@AccountId and [UserId]=@UserId AND [Email]=@Email AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByEmail2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckPasswordByEmail2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByEmail2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[Dcx_User_CheckPasswordByEmail2]
@Email varchar(100),
@Password varchar(100)
AS
SELECT TOP 1 1 FROM [Dcx_User] WHERE [Email]=@Email AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckPasswordByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckPasswordByUserId]
@UserId int,
@Password varchar(100)
AS
SELECT TOP 1 * FROM [Dcx_User] WHERE [UserId]=@UserId AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByUserId2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckPasswordByUserId2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByUserId2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckPasswordByUserId2]
@AccountId int ,
@UserId int,
@Password varchar(100)
AS
SELECT TOP 1 * FROM [Dcx_User] WHERE [AccountId]=@AccountId and [UserId]=@UserId AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckPasswordByUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckPasswordByUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckPasswordByUserName]
@UserName varchar(20),
@Password varchar(100)
AS
SELECT TOP 1 * FROM [Dcx_User] WHERE [UserName]=@UserName AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CheckUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CheckUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CheckUserName] 
@UserName Char(16)
AS
BEGIN
if ltrim(rtrim(@UserName))=''''
begin 
select 1
return
end
else
SELECT top 1 1 FROM [Dcx_User]  where [UserName]=@UserName
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CreateUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_CreateUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_CreateUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_CreateUser]
@AccountId int,
@UserName varchar(20),
@RealName varchar(20),
@Email varchar(50),
@Password varchar(100),
@GroupId int
AS
BEGIN
--declare @AccountId int 
declare @UserId int 
set @UserId=-1
--注册用户
INSERT INTO [Dcx_User]
([UserName],[UpperName],[RealName],[Email],[GroupId],[AccountId],[IsAccountCreator],[PWD],[RegistedDate],[Creator],[CreateTime],[Editor],[EditTime])
VALUES
(@UserName,upper(@UserName),@RealName,@Email,@GroupId,@AccountId,0,@Password,getdate(),@UserName,getdate(),@UserName,getdate())
set @UserId=@@IdENTITY 
set @UserId=isnull(@UserId,0)
select isnull(@UserId,0)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_DeleteInviteUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_DeleteInviteUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_DeleteInviteUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[Dcx_User_DeleteInviteUser]
@UserId int
AS
BEGIN
delete from [Dcx_User] where [UserId]=@UserId and [UserName]!=''admin'' and [GroupId]=14
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetCountByAccountId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetCountByAccountId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetCountByAccountId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetCountByAccountId]
@AccountId int
AS 
begin
select count(*)  from  [Dcx_User]     where [AccountId]=@AccountId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetCurSystemId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetCurSystemId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetCurSystemId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetCurSystemId]
@AccountId int ,
@UserId int
AS
select  isnull([CurSystemId],0) from [Dcx_User] WHERE [AccountId]=@AccountId and [UserId]=@UserId 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetEmailList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetEmailList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetEmailList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetEmailList] --获取用户的邮箱
@UserIds varchar(6000) 
AS
BEGIN
declare @sql varchar(6000)
set @sql=''SELECT [Email],[UserName],[UserId] FROM [Dcx_User]  where [UserId] in(''+@UserIds+'')''
exec sp_executesql @sql
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetIp]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetIp]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetIp]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetIp]
@AccountId int ,
@UserId int
AS
select  isnull([IP],'''')+(case when [RestrictIp]=1 then ''&&1'' else ''&&0'' end) as [IP] from [Dcx_User] WHERE [AccountId]=@AccountId and [UserId]=@UserId 
--[RestrictIp], 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetListByAccountId_Page]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetListByAccountId_Page]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetListByAccountId_Page]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetListByAccountId_Page]
@AccountId int,
@PageSize int,
@PageIndex int
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @PageSize is null or @PageSize<1
	set @PageSize=20
if @PageIndex is null or @PageIndex<1
	set @PageIndex=1
SET @startRow = (@PageIndex - 1) * @PageSize +1
SET @endRow = @startRow + @PageSize -1 
select *  from (
select row_number() over( order by [UserId] asc)as dcx_rowid,
[UserName],[RealName],[Email],[Phone]
,[VisitTime],[UserId] 
from [Dcx_User]     where [AccountId]=@AccountId ) AS MyTable  
 where  dcx_rowid between @startRow and @endRow
select count(*) from [Dcx_User]     where [AccountId]=@AccountId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserByAccountId_Simple]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetUserByAccountId_Simple]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserByAccountId_Simple]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetUserByAccountId_Simple]--获取帐号下的全部用户
@AccountId int 
AS
BEGIN
SELECT [UserName],[UserId] ,[RealName] FROM [Dcx_User] where [AccountId]=@AccountId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetUserById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetUserById] --获取用户信息
@AccountId int ,
@UserId int 
AS
BEGIN
SELECT * FROM [Dcx_User]  where [AccountId]=@AccountId  and  [UserId]=@UserId  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserByUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetUserByUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserByUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetUserByUserName]
@UserName varchar(50) 
AS
if @UserName is null or @UserName='''' or len(@UserName)>40
begin
select -1
end
select top 1 [UserId]
      ,[UserName],[RealName]
      ,[AccountId]
      ,[IsAccountCreator]
      ,[CurSystemId],[GroupId]
       from [Dcx_User]   WHERE [UserName]=@UserName  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_GetUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_GetUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_GetUserName]
@AccountId int ,
@UserId int
AS
select [UserName] from [Dcx_User]   WHERE [AccountId]=@AccountId and [UserId]=@UserId  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateCurSystemId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdateCurSystemId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateCurSystemId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdateCurSystemId]
@AccountId int ,
@SystemId int ,
@UserId int 
AS
BEGIN
UPDATE [Dcx_User] SET [CurSystemId] = @SystemId  
WHERE [AccountId]=@AccountId  and [UserId]=@UserId
UPDATE [Dcx_OnlineUser] SET [SystemId] = @SystemId  
WHERE [AccountId]=@AccountId  and [UserId]=@UserId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateCurSystemId2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdateCurSystemId2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateCurSystemId2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdateCurSystemId2]  --用户第一次创建web系统时调用
@AccountId int ,
@CurSystemId int 
--@UserId int 
AS
BEGIN
update [Dcx_User]  set CurSystemId=@CurSystemId where [AccountId]=@AccountId and [CurSystemId]<1
UPDATE [Dcx_OnlineUser] SET [SystemId] = @CurSystemId  WHERE [AccountId]=@AccountId  and [SystemId]<1
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateEmail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdateEmail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateEmail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdateEmail]
@AccountId int ,
@UserId int,
@Email varchar(100)
AS
update [Dcx_User] set [Email]=@Email WHERE [AccountId]=@AccountId and [UserId]=@UserId  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateEmail2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdateEmail2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateEmail2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdateEmail2]--还没激活时
@AccountId int ,
@UserId int,
@Email varchar(100)
AS
if @AccountId<1 or  @UserId<1  or  ltrim(rtrim(@Email))=''''
	return
update [Dcx_Account]  set [Email]=@Email WHERE [AccountId]=@AccountId and [GroupId]=3
update [Dcx_User] set [Email]=@Email WHERE [AccountId]=@AccountId and [UserId]=@UserId and [GroupId]=3
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateIp]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdateIp]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdateIp]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdateIp]
@AccountId int ,
@UserId int,
@RestrictIp bit,
@Ips varchar(500)
AS
if  @Ips is null or ltrim(rtrim(@Ips))='''' 
	set @RestrictIp=0
update [Dcx_User] set [RestrictIp]=@RestrictIp, [IP]=@Ips WHERE [AccountId]=@AccountId and [UserId]=@UserId  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdatePassword]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdatePassword]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdatePassword]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdatePassword]
@UserId int,
@Password varchar(100)
AS
update [Dcx_User] set [PWD]=@Password WHERE [UserId]=@UserId  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdatePassword2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdatePassword2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdatePassword2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdatePassword2]
@AccountId int ,
@UserId int,
@Password varchar(100)
AS
update [Dcx_User] set [PWD]=@Password WHERE [AccountId]=@AccountId and [UserId]=@UserId  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdatePwdByEmail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_User_UpdatePwdByEmail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_User_UpdatePwdByEmail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Dcx_User_UpdatePwdByEmail]
@email varchar(100),
@pwd varchar(100)
AS
BEGIN
if @pwd is null or ltrim(rtrim(@pwd))='''' or len(@pwd)<6
	return
if @email is null or ltrim(rtrim(@email))='''' or len(@email)<6
	return
UPDATE [Dcx_User] SET [PWD] =@pwd where [Email]=@email 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserSearch]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Dcx_UserSearch]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Dcx_UserSearch]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 





CREATE PROC [dbo].[Dcx_UserSearch]
@Name varchar(200),
@Mobile varchar(100),
@Email varchar(100),
@Gender varchar(100),
@PositionId int,
@SearchBound varchar(50)
/*--------------------------------------
功能：查询人员
参数：
	@Name	人员姓名
	@Mobile	手机号码
	@Email	email
	@Gender	性别
	@PositionId	职位id
	@SearchBound	查询范围
---------------------------------------*/
AS
DECLARE @SQL VARCHAR(500)
DECLARE @HAVECONDITION BIT
IF @PositionId=0
	SET @SQL = ''SELECT Dcx_Position.Position_Name,Dcx_User.*,Case Sex When 1 Then ''''男'''' Else ''''女'''' End AS SexName FROM Dcx_User Left OUTER JOIN Dcx_User_In_Position ON Dcx_User.STAFF_Id=Dcx_User_In_Position.Staff_Id INNER JOIN Dcx_Position ON Dcx_User_In_Position.Position_Id=Dcx_Position.Position_Id''
ELSE
	SET @SQL = ''SELECT Dcx_Position.Position_Name,Dcx_User.*,Case Sex When 1 Then ''''男'''' Else ''''女'''' End AS SexName FROM Dcx_User INNER JOIN Dcx_User_In_Position ON Dcx_User.STAFF_Id=Dcx_User_In_Position.Staff_Id INNER JOIN Dcx_Position ON Dcx_User_In_Position.Position_Id=Dcx_Position.Position_Id ''
SET @HAVECONDITION = 0
	IF (@Name<>'''')
	BEGIN
		SET @SQL = @SQL + '' WHERE (Staff_Name LIKE ''''%''+@Name+''%'''' OR RealName LIKE ''''%''+@Name+''%'''')''
		SET @HAVECONDITION = 1
	END
	IF (@Mobile<>'''')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Mobile LIKE ''''%''+@Mobile+''%'''')''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Mobile LIKE ''''%''+@Mobile+''%'''')''
	END
	IF (@Email<>'''')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Email LIKE ''''%''+@Email+''%'''')''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Email LIKE ''''%''+@Email+''%'''')''
	END
	IF (@Gender<>'''')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			IF @Gender=''male''
			BEGIN
				SET @SQL = @SQL + '' WHERE (Sex=1)''
				SET @HAVECONDITION = 1
			END	
			ELSE
			BEGIN
				SET @SQL = @SQL + '' WHERE (Sex=0)''
				SET @HAVECONDITION = 1
			END
		END
		ELSE
			IF @Gender=''male''
			BEGIN
				SET @SQL = @SQL + '' AND (Sex=1)''
			END
			ELSE
			BEGIN
				SET @SQL = @SQL + '' AND (Sex=0)''
			END
	END
	IF (@PositionId<>0)
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Dcx_Position.Position_Id=''+Convert(varchar(5),@PositionId)+'')''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Dcx_Position.Position_Id=''+Convert(varchar(5),@PositionId)+'')''
	END
	IF (@SearchBound=''on'')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Dcx_User.Dimission=0)''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Dcx_User.Dimission=0)''
	END
	IF (@SearchBound=''off'')
	BEGIN
		IF(@HAVECONDITION=0)
		BEGIN
			SET @SQL = @SQL + '' WHERE (Dcx_User.Dimission=1)''
			SET @HAVECONDITION = 1
		END
		ELSE
			SET @SQL = @SQL + '' AND (Dcx_User.Dimission=1)''
	END
	PRINT @SQL
	EXECUTE  (@SQL)
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxEntityTask_UpdateAreaId_byTaskId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxEntityTask_UpdateAreaId_byTaskId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxEntityTask_UpdateAreaId_byTaskId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxEntityTask_UpdateAreaId_byTaskId] 
@TaskId int ,
@AccountId int ,
@AreaId int 
AS
BEGIN
if @TaskId<1 or @AccountId<1
return
if @AreaId=0
update [Dcx_EntityTask] set [AreaId]=@AreaId where [CreatorAccountId]=@AccountId and [TaskId]=@TaskId   and [AreaId]>0 
else
update [Dcx_EntityTask] set [AreaId]=@AreaId where [CreatorAccountId]=@AccountId and [TaskId]=@TaskId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetFieldList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_DB_GetFieldList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetFieldList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_DB_GetFieldList] 
@TableName varchar(100)
AS
BEGIN
if ltrim(rtrim(isnull(@TableName,'''')))=''''
begin
select   ''请选择数据表''   
return
end
select   name   from   syscolumns   where   id=object_id(  @TableName ) 
and name!=''FD_Id '' and name!=''feedback'' and name!=''form_id'' and name!=''run_id'' 
and name!=''Run_pid''
and name!=''User_id '' and name!=''Zc_flag''  and name!=''LD_Id '' and name!=''flow_lsh'' 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableAndViewList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_DB_GetTableAndViewList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableAndViewList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_DB_GetTableAndViewList] 
AS
BEGIN
select   name   from   sysobjects where xtype=''U'' or xtype=''V'' order by name
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableAndViewList2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_DB_GetTableAndViewList2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableAndViewList2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_DB_GetTableAndViewList2] 
AS
BEGIN
select ''请选择数据表'' as name union select   name   from   sysobjects where xtype=''U'' or xtype=''V'' order by name
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_DB_GetTableList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_DB_GetTableList] 
AS
BEGIN
select   name   from   sysobjects where xtype=''U'' order by name
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableList2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_DB_GetTableList2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_GetTableList2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_DB_GetTableList2] 
AS
BEGIN
select ''请选择数据表'' as name union select   name   from   sysobjects where xtype=''U'' order by name
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_KillSpid]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_DB_KillSpid]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_DB_KillSpid]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--还原数据库时数据库正在使用导致数据库无会还原，此存储过存在msater数据库下创建。exec killspid ''dbname'' 结束此数据库的进程，这样才能还原数据库
CREATE PROC [dbo].[DcxRun_DB_KillSpid] (@dbname varchar(20))     
as     
begin     
declare @sql   nvarchar(500)     
declare @spid  int     
set @sql=''declare getspid cursor for select spid from sysprocesses where dbid=db_id(''''''+@dbname+'''''')''     
exec (@sql)     
open getspid     
fetch next from getspid into @spid     
while @@fetch_status <> -1     
begin     
exec(''kill ''+@spid)     
fetch next from getspid into @spid     
end     
close getspid     
deallocate getspid     
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Diary_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_Diary_Delete](@userId int, @dyId int)
as
begin
--set nocount on
		delete from [Dcx_Diary] WHERE [CreatorId]=@userId  and [DyId]=@dyId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Diary_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Diary_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate 
							and [CreateDate]<@toDate and [CreatorId]=@userId   and [IsTop]=0
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId  and [IsTop]=0
				end
				else 
				begin
							select count(1)  from [Dcx_Diary]  where  [CreateDate]<@toDate and [CreatorId]=@userId  and [IsTop]=0
				end
		end
		else
		begin
				select count(1)  from [Dcx_Diary]  where  [CreatorId]=@userId  and [IsTop]=0
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate 
							and [CreateDate]<@toDate and [CreatorId]=@userId   and [IsTop]=0 and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_Diary]  where  [CreateDate]<@toDate and [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_Diary]  where  [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Diary_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_Diary_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_Diary_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_Diary_GetTopDiary]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_Diary_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Diary_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Diary_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate 
	--							and [CreateDate]<@toDate and [CreatorId]=@userId   and [IsTop]=0
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate  and [CreatorId]=@userId  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId  and [IsTop]=0
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]<@toDate and [CreatorId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_Diary]  where  [CreateDate]<@toDate and [CreatorId]=@userId  and [IsTop]=0
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
						where [CreatorId]=@userId  and [IsTop]=0
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--					if @pageIndex<=1
	--						select count(1)  from [Dcx_Diary]  where   [CreatorId]=@userId  and [IsTop]=0
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId
					end
					else if @toDate is  null 
					begin
								select   top 200 [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate  and [CreatorId]=@userId
					end
					else 
					begin
								select   top 200 [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]<@toDate and [CreatorId]=@userId
					end
			end
			else
			begin
								select  top 200  [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreatorId]=@userId  and [IsTop]=0
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate 
	--							and [CreateDate]<@toDate and [CreatorId]=@userId   and [IsTop]=0 and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate  and [CreatorId]=@userId  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_Diary]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]<@toDate and [CreatorId]=@userId and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_Diary]  where  [CreateDate]<@toDate and [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [CreateDate] desc)as dcx_rowid, [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
						where [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--					if @pageIndex<=1
	--						select count(1)  from [Dcx_Diary]  where   [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]>@fromDate  and [CreatorId]=@userId  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreateDate]<@toDate and [CreatorId]=@userId  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  [DyId],[DyContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[IsTop],[IsRead],[ReadTime],[ColorId],[TagId],[TagName],[FileJson]  FROM [Dcx_Diary]  
								where [CreatorId]=@userId  and [IsTop]=0 and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetTopDiary]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Diary_GetTopDiary]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Diary_GetTopDiary]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_Diary_GetTopDiary]
@tagId int,
@userId int
AS
BEGIN 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_Diary where [CreatorId]=@userId  and [IsTop]=1 
else
	 select 1 as dcx_rowid,*  from Dcx_Diary where [CreatorId]=@userId  and [IsTop]=1 and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Document_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_Document_Delete](@userId int, @fileId int)
as
begin
--set nocount on
		delete from [Dcx_Document] WHERE [CreatorId]=@userId  and [FileId]=@fileId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Document_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Document_GetCount]
(
@groupId int,
@userId int,
@fromDate datetime,
@toDate datetime,
	@parentId int
)
AS
begin
if @parentId>-1
begin
		if @groupId<1
		begin
				if @fromDate is not null  or @toDate is not null 
				begin
						if @fromDate is not null  and @toDate is not null 
						begin
									select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
									and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId    
						end
						else if @toDate is  null 
						begin
									select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId   
						end
						else 
						begin
									select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId   
						end
				end
				else
				begin
						select count(1)  from [Dcx_Document]  where  [CreatorId]=@userId and [ParentId]=@parentId   
				 end
		end
		else 
		begin
				if @fromDate is not null  or @toDate is not null 
				begin
						if @fromDate is not null  and @toDate is not null 
						begin
									select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
									and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId     and [GroupId]=@groupId
						end
						else if @toDate is  null 
						begin
									select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId    and [GroupId]=@groupId
						end
						else 
						begin
									select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId    and [GroupId]=@groupId
						end
				end
				else
				begin
						select count(1)  from [Dcx_Document]  where  [CreatorId]=@userId and [ParentId]=@parentId    and [GroupId]=@groupId
				 end
		end
end
else
begin
	if @groupId<1
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
								and [CreateDate]<@toDate and [CreatorId]=@userId     
					end
					else if @toDate is  null 
					begin
								select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId    
					end
					else 
					begin
								select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId    
					end
			end
			else
			begin
					select count(1)  from [Dcx_Document]  where  [CreatorId]=@userId    
			 end
	end
	else 
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
								and [CreateDate]<@toDate and [CreatorId]=@userId      and [GroupId]=@groupId
					end
					else if @toDate is  null 
					begin
								select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId     and [GroupId]=@groupId
					end
					else 
					begin
								select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId     and [GroupId]=@groupId
					end
			end
			else
			begin
					select count(1)  from [Dcx_Document]  where  [CreatorId]=@userId     and [GroupId]=@groupId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Document_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_Document_GetForFirstTime]
@groupId2 int,
@userId2 int,
@pageSize2 int,
@parentId2 int
AS
BEGIN 
EXEC	[DcxRun_Document_GetList]
@groupId = @groupId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null,@parentId = @parentId2
EXEC	[DcxRun_Document_GetTopDocument]
		@groupId = @groupId2,@userId = @userId2
EXEC	[DcxRun_Document_GetCount]
		@groupId = @groupId2,@userId = @userId2,@fromDate = null,@toDate = null,@parentId = @parentId2
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Document_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Document_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@groupId int,
	@fromDate datetime,
	@toDate datetime,
	@parentId int
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @parentId>-1
begin
		if @groupId<1
		begin
			if @pageSize>0 or @pageIndex>0
			begin
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId 
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
			--							and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId   
							end
							else if @toDate is  null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId  
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId  
							end
							else 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId 
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId  
							end
					end
					else
					begin
							  select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
								where [CreatorId]=@userId and [ParentId]=@parentId  
							  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--					if @pageIndex<=1
			--						select count(1)  from [Dcx_Document]  where   [CreatorId]=@userId and [ParentId]=@parentId  
					 end
			end
			else
			begin  
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId
							end
							else if @toDate is  null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId
							end
							else 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId
							end
					end
					else
					begin
										select  top 200  [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreatorId]=@userId and [ParentId]=@parentId  
					 end
			end
		end
		else 
		begin
			if @pageSize>0 or @pageIndex>0
			begin
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId   and [GroupId]=@groupId
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
			--							and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId    and [GroupId]=@groupId
							end
							else if @toDate is  null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId  and [GroupId]=@groupId
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId   and [GroupId]=@groupId
							end
							else 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId and [GroupId]=@groupId
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId   and [GroupId]=@groupId
							end
					end
					else
					begin
							  select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
								where [CreatorId]=@userId and [ParentId]=@parentId   and [GroupId]=@groupId
							  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--					if @pageIndex<=1
			--						select count(1)  from [Dcx_Document]  where   [CreatorId]=@userId and [ParentId]=@parentId   and [GroupId]=@groupId
					 end
			end
			else
			begin  
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId  and [GroupId]=@groupId
							end
							else if @toDate is  null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId and [ParentId]=@parentId  and [GroupId]=@groupId and [GroupId]=@groupId
							end
							else 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId and [ParentId]=@parentId  and [GroupId]=@groupId
							end
					end
					else
					begin
										select  top 200  [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreatorId]=@userId and [ParentId]=@parentId   and [GroupId]=@groupId
					 end
			end
		end
end
else
begin
		if @groupId<1
		begin
			if @pageSize>0 or @pageIndex>0
			begin
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId  
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
			--							and [CreateDate]<@toDate and [CreatorId]=@userId    
							end
							else if @toDate is  null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId   
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId   
							end
							else 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId  
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId   
							end
					end
					else
					begin
							  select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
								where [CreatorId]=@userId   
							  ) AS MyTable  where dcx_rowid between @startRow and @endRow 
			--					if @pageIndex<=1
			--						select count(1)  from [Dcx_Document]  where   [CreatorId]=@userId   
					 end
			end
			else
			begin  
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId
							end
							else if @toDate is  null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId
							end
							else 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId
							end
					end
					else
					begin
										select  top 200  [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreatorId]=@userId   
					 end
			end
		end
		else 
		begin
			if @pageSize>0 or @pageIndex>0
			begin
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId    and [GroupId]=@groupId
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate 
			--							and [CreateDate]<@toDate and [CreatorId]=@userId     and [GroupId]=@groupId
							end
							else if @toDate is  null 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId   and [GroupId]=@groupId
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]>@fromDate  and [CreatorId]=@userId    and [GroupId]=@groupId
							end
							else 
							begin
									select *  from (
										select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId  and [GroupId]=@groupId
									) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--						if @pageIndex<=1
			--							select count(1)  from [Dcx_Document]  where  [CreateDate]<@toDate and [CreatorId]=@userId    and [GroupId]=@groupId
							end
					end
					else
					begin
							  select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
								where [CreatorId]=@userId    and [GroupId]=@groupId
							  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			--					if @pageIndex<=1
			--						select count(1)  from [Dcx_Document]  where   [CreatorId]=@userId    and [GroupId]=@groupId
					 end
			end
			else
			begin  
					if @fromDate is not null  or @toDate is not null 
					begin
							if @fromDate is not null  and @toDate is not null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate and [CreateDate]<@toDate and [CreatorId]=@userId   and [GroupId]=@groupId
							end
							else if @toDate is  null 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]>@fromDate  and [CreatorId]=@userId   and [GroupId]=@groupId and [GroupId]=@groupId
							end
							else 
							begin
										select   top 200 [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreateDate]<@toDate and [CreatorId]=@userId   and [GroupId]=@groupId
							end
					end
					else
					begin
										select  top 200  [FileId],[FilePath],[FileName],[FileTypeId],[FileSize],[ParentId],[IsCollect],[CreatorId],[CreatorName],[CreateDate],[GroupId],[FileSource],[LinkDataJson]  FROM [Dcx_Document]  
										where [CreatorId]=@userId    and [GroupId]=@groupId
					 end
			end
		end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetTopDocument]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Document_GetTopDocument]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Document_GetTopDocument]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_Document_GetTopDocument]
@groupId int,
@userId int
AS
BEGIN 
if @userId is null or @userId<1
	return 
 if @groupId<1
	 select 1 as dcx_rowid,*  from Dcx_Document where [CreatorId]=@userId     and [ParentId]=0
else
	 select 1 as dcx_rowid,*  from Dcx_Document where [CreatorId]=@userId   and [GroupId]=@groupId  and [ParentId]=0
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_EMail_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_EMail_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_EMail_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_EMail_GetList]
(
@userid varchar(6),
@ordertype VarChar(10),
@pagesize int,
@pageindex int,
@dotype int)
as
set nocount on
if(@dotype=1)
select count(mailid) from ew_newmail where [r_usersid] like ''%,'' + @userid + '',%'' and isnull([deluserid],'''') not like ''%,'' + @userid + '',%'' and isnull([deleteuserid],'''') not like ''%,'' + @userid + '',%''
else if(@dotype=2)
select count(mailid) from ew_newmail where [r_usersid] like ''%,'' + @userid + '',%'' and isnull([deluserid],'''') not like ''%,'' + @userid + '',%'' and isnull([deleteuserid],'''') not like ''%,'' + @userid + '',%'' and isnull([read_usersid],'''') not like ''%,'' + @userid + '',%''
else
begin
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
create table #pageindex(id int identity(1,1) not null,nid int)
set rowcount @PageUpperBound
exec(''insert into #pageindex(nid)
select mailid from ew_newmail where [r_usersid] like ''''%,'' + @userid + '',%'''' 
and isnull([deluserid],'''''''') not like ''''%,'' + @userid + '',%'''' 
and isnull([deleteuserid],'''''''') not like ''''%,'' + @userid + '',%'''' order by "''+@ordertype+''" desc'')
select O.mailid,O.s_userid,O.s_username,O.title,O.rq,o.read_usersid
from ew_newmail O,#pageindex p
where O.mailid=p.nid and p.id>@PageLowerBound and p.id<=@PageUpperBound order by p.id
end
set nocount off
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_EMail_GetList2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_EMail_GetList2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_EMail_GetList2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_EMail_GetList2]
(
@userid int,
@query varchar(200),
@ordertype VarChar(10),
@PageLowerBound int,
@PageUpperBound int,
@dotype int)
as
set nocount on
declare @userid2 varchar(20)
set @userid2=cast(@userid as varchar(20))
if(@dotype=1)
select count(MailId) from Dcx_IMail where [ReceiverUserIds] like ''%,'' + @userid2 + '',%'' and isnull([DelUserIds],'''') not like ''%,'' + @userid2 + '',%'' and isnull([DeleteUseIds],'''') not like ''%,'' + @userid2 + '',%''
else if(@dotype=2)
select count(MailId) from Dcx_IMail where [ReceiverUserIds] like ''%,'' + @userid2 + '',%'' and isnull([DelUserIds],'''') not like ''%,'' + @userid2 + '',%'' and isnull([DeleteUseIds],'''') not like ''%,'' + @userid2 + '',%'' and isnull([ReadUserIds],'''') not like ''%,'' + @userid2 + '',%''
else
begin
set @PageLowerBound=@PageLowerBound-1 
set @PageUpperBound=@PageUpperBound-1 
create table #pageindex(id int identity(1,1) not null,nid int)
set rowcount @PageUpperBound
exec(''insert into #pageindex(nid)
select MailId from Dcx_IMail where ''+@query+ '' and [ReceiverUserIds] like ''''%,'' + @userid2 + '',%'''' 
and isnull([DelUserIds],'''''''') not like ''''%,'' + @userid2 + '',%'''' 
and isnull([DeleteUseIds],'''''''') not like ''''%,'' + @userid2 + '',%'''' order by "''+@ordertype+''" desc'')
select O.MailId,O.SenderUserId,O.SenderUserName,O.Title,O.SenderDate,o.ReadUserIds,(case when charindex('','' + @userid2 + '','',o.ReadUserIds,1)>0 then 1 else 0 end) as IsReaded 
from Dcx_IMail O,#pageindex p
where O.MailId=p.nid and p.id>@PageLowerBound and p.id<=@PageUpperBound order by p.id
end
set nocount off
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_EMail_GetYfMail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_EMail_GetYfMail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_EMail_GetYfMail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_EMail_GetYfMail]
(@userid varchar(6),
@ordertype VarChar(10),
@pagesize int,
@pageindex int,
@dotype int)
as
set nocount on
if(@dotype=1)
select count(mailid) from ew_newmail where [s_userid]= @userid  and del is null
else
begin
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
create table #pageindex(id int identity(1,1) not null,nid int)
set rowcount @PageUpperBound
exec(''insert into #pageindex(nid)
select mailid from ew_newmail where [s_userid]=''+@userid+'' and del is null order by "''+@ordertype+''" desc'')
select O.mailid,O.s_userid,O.s_username,O.title,O.rq,o.read_usersid
from ew_newmail O,#pageindex p
where O.mailid=p.nid and p.id>@PageLowerBound and p.id<=@PageUpperBound order by p.id
end
set nocount off
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Entity_GetAllEntityBySEntId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Entity_GetAllEntityBySEntId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Entity_GetAllEntityBySEntId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Entity_GetAllEntityBySEntId]
@SEntId int
AS
declare @ParentId int   
declare @EntId int   
 select @ParentId=[ParentId],@EntId=[EntId] from [Dcx_Entity_Run] where [SEntId]=@SEntId or  [EntId]=@SEntId 
if @ParentId is null 
return
if @ParentId>0
 select * from [Dcx_Entity_Run] where ([EntId]=@ParentId or [ParentId]=@ParentId ) order by [ParentId]
else 
 select * from [Dcx_Entity_Run] where  ([EntId]=@EntId or [ParentId]=@EntId ) order by [ParentId]
--declare @MenuId int   
--select @MenuId=[MenuId] from [Dcx_Entity_Run] where [SEntId]=@SEntId 
----if @MenuId is not null
--select * from [Dcx_Entity_Run] where [MenuId]=@MenuId 
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Entity_GetEntityAndChildren]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Entity_GetEntityAndChildren]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Entity_GetEntityAndChildren]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Entity_GetEntityAndChildren]
@EntId int
AS
declare @ParentId int   
 select @ParentId=[ParentId] from [Dcx_Entity_Run] where [EntId]=@EntId 
if @ParentId>0
 select * from [Dcx_Entity_Run] where ([EntId]=@ParentId or [ParentId]=@ParentId )
else
 select * from [Dcx_Entity_Run] where  ([EntId]=@EntId or [ParentId]=@EntId )
--declare @MenuId int   
--select @MenuId=[MenuId] from [Dcx_Entity_Run] where [EntId]=@EntId 
--select * from [Dcx_Entity_Run] where [MenuId]=@MenuId 
--declare @MenuId int   
--declare @EntName varchar(100)   
--declare @SEntId int   
--declare @ParentId int   
--declare @SMenuId int   
--declare @SystemId int   
--declare @IsDesigning int   
--declare @table table([EntId] int,[EntName] varchar(100),MenuId int,ParentId int,[SEntId] int,SystemId int,IsDesigning bit) 
--set  @ParentId= -1
--select @MenuId=[MenuId],@SystemId=[SystemId],@EntName=[EntName],@EntId=[EntId], @MenuId= [MenuId]  ,@SEntId= [SEntId]  ,@ParentId=[ParentId],@IsDesigning=[IsDesigning] from [Dcx_Entity_Run]  where [EntId] = @EntId  
--set @ParentId=isnull(@ParentId,-1)
--insert into @table ([EntId] ,[EntName] ,MenuId ,ParentId ,[SEntId] ,SystemId ,[IsDesigning]) 
--values(@EntId,@EntName,@MenuId ,@ParentId ,@SEntId ,@SystemId,@IsDesigning) 
--if @ParentId>0
--begin
--	insert into @table ([EntId] ,[EntName] ,MenuId ,ParentId ,[SEntId] ,SystemId,[IsDesigning] ) 
--	select[EntId] ,[EntName] ,MenuId ,ParentId ,[SEntId] ,SystemId,[IsDesigning]    from [Dcx_Entity_Run] 
--	where [ParentId] = @ParentId  
--end   
--
--select * from @table
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Entity_UpdateCopyedEntity]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Entity_UpdateCopyedEntity]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Entity_UpdateCopyedEntity]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Entity_UpdateCopyedEntity]  
@SystemId int,
@EntId int,
@OldEntId int ,
@UserId int,
@UserName varchar(40)
AS
begin
UPDATE [Dcx_Entity_Run] SET 
 [SSystemId] =@SystemId
,[SEntId] = @EntId
,[IsDesigning]=1
,[AddDcxTime]=getdate()
,[AddDcxUserName]=@UserName
,[AddDcxUserId]=@UserId
WHERE [EntId]=@OldEntId and ([IsDesigning] is null or [IsDesigning]=0)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_HomePage_Loading]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_HomePage_Loading]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_HomePage_Loading]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC  [dbo].[DcxRun_HomePage_Loading] (
@UserId int,
@DeptId int
--,@TopMenuId int
) 
AS 
--待办事务个数
declare @WorkCount int
declare @t1 as varchar(20)
set @t1=''%,''+cast(@UserId as varchar)+'',%''
select @WorkCount=count(*) FROM [WF_FlowRunPrcs]  where  (  PrcsFlag=1 or PrcsFlag=2)  and (UserId=@UserId or DealIds like @t1) 
set @WorkCount=isnull(@WorkCount,0)
select @WorkCount
--Email个数
declare @EmailCount int
--SELECT @EmailCount=count(1) FROM [Dcx_MessageReceiver] where [ReceiverId]=@UserId and [IsRead]=0  and [EntId]=2071
SELECT @EmailCount=count(1) FROM Dcx_WMailRcv where [ReceiverId]=@UserId and [IsRead]=0  
set @EmailCount=isnull(@EmailCount,0)
select @EmailCount
--短信个数
declare @NoteCount int
--SELECT @NoteCount=count(1) FROM [Dcx_MessageReceiver] where [ReceiverId]=@UserId and [IsRead]=0  and [EntId]=2076
SELECT @NoteCount=count(1) FROM Dcx_WLetterRcv where [ReceiverId]=@UserId and [IsRead]=0  
set @NoteCount=isnull(@NoteCount,0)
select @NoteCount
----在线人员
--SELECT top 10 * FROM [Dcx_OnlineUser] where Online=1 order by LoginTime desc
--在线人员
SELECT 1
----顶部菜单
--EXEC	[dbo].[Dcx_Menu_Run_GetChild_Privilege]
--		@ParentId = @TopMenuId,
--		@UserId = @UserId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddFriend]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_AddFriend]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddFriend]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
 
CREATE PROC [dbo].[DcxRun_IM_AddFriend](
@groupId int,
@userId int, @userName nvarchar(256),
@friendId int, @friendName nvarchar(256)
)
as
begin 
if (select count(1) from [Dcx_LinkMan] where [CreatorId]=@userId and [UserId]=@friendId)<1
	INSERT INTO [Dcx_LinkMan]([CreatorId] ,[GroupId],[UserId],[UserName],[LinkTime],[CreateDate])
	values(@userId,@groupId,@friendId,@friendName,0,getdate())
else
	UPDATE [Dcx_LinkMan] SET [GroupId] =@groupId WHERE  [CreatorId]=@userId and [UserId]=@friendId
declare @rId1 int
declare @rId2 int
set @rId1=0
set @rId2=0
if (select count(1) from [Dcx_IMRelationship] where HostUserId=@userId and [GuestUserId]=@friendId and [RoomId]=0)<1
begin
	insert into [Dcx_IMRelationship] (GroupId,[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
	values( @groupId,@userId,@friendId,@friendName,0,getdate())
	set @rId1=@@identity
end
else
begin
	UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsTemp]=0,[IsDeleted]=0 WHERE [HostUserId]=@userId and [GuestUserId]=@friendId  and [RoomId]=0
end
if (select count(1) from [Dcx_IMRelationship] where HostUserId=@friendId and [GuestUserId]=@userId and [RoomId]=0)<1
begin 
	insert into [Dcx_IMRelationship] (GroupId,[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime,[IsTemp])
	values( @groupId,@friendId,@userId,@userName,0,getdate(),1)
	set @rId2=@@identity
end
--else
--begin
--	UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsDeleted]=0 WHERE [HostUserId]=@friendId and [GuestUserId]=@userId  and [RoomId]=0
----	UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsTemp]=0,[IsDeleted]=0 WHERE [HostUserId]=@friendId and [GuestUserId]=@userId  and [RoomId]=0
--end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddFriend2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_AddFriend2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddFriend2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROC [dbo].[DcxRun_IM_AddFriend2](
@accountId int,
@groupId int,
@userId int, @userName nvarchar(256),
@friendId int, @friendName nvarchar(256)
)
as
begin 
if (select count(1) from [Dcx_LinkMan] where [CreatorId]=@userId and [UserId]=@friendId)<1
	INSERT INTO [Dcx_LinkMan]([AccountId] ,[CreatorId] ,[GroupId],[UserId],[UserName],[LinkTime],[CreateDate])
	values(@accountId,@userId,@groupId,@friendId,@friendName,0,getdate())
else
	UPDATE [Dcx_LinkMan] SET [GroupId] =@groupId WHERE  [CreatorId]=@userId and [UserId]=@friendId
declare @rId1 int
declare @rId2 int
set @rId1=0
set @rId2=0
if (select count(1) from [Dcx_IMRelationship] where HostUserId=@userId and [GuestUserId]=@friendId and [RoomId]=0)<1
begin
	insert into [Dcx_IMRelationship] ([AccountId] ,GroupId,[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
	values( @accountId,@groupId,@userId,@friendId,@friendName,0,getdate())
	set @rId1=@@identity
end
else
begin
	UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsTemp]=0,[IsDeleted]=0 WHERE [HostUserId]=@userId and [GuestUserId]=@friendId  and [RoomId]=0
end
if (select count(1) from [Dcx_IMRelationship] where HostUserId=@friendId and [GuestUserId]=@userId and [RoomId]=0)<1
begin 
	insert into [Dcx_IMRelationship] ([AccountId] ,GroupId,[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime,[IsTemp])
	values( @accountId,@groupId,@friendId,@userId,@userName,0,getdate(),1)
	set @rId2=@@identity
end
--else
--begin
--	UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsDeleted]=0 WHERE [HostUserId]=@friendId and [GuestUserId]=@userId  and [RoomId]=0
----	UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsTemp]=0,[IsDeleted]=0 WHERE [HostUserId]=@friendId and [GuestUserId]=@userId  and [RoomId]=0
--end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddRoomLgr]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_AddRoomLgr]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddRoomLgr]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_AddRoomLgr](
@accountId int,
@isController bit,
@roomId int, @roomUserName nvarchar(256),
@friendId int, @friendName nvarchar(256)
)
as
begin
INSERT INTO [Dcx_IMRoomLgr]([AccountId],[RoomId],[UserId],[UserName],[IsController],[CreateDate])
VALUES (@accountId,@roomId,@friendId,@friendName,@isController ,getdate())
declare @Relationship int
set @Relationship=0
if @isController=1
	set @Relationship=2
if (select count(*) from [Dcx_IMRelationship] where HostUserId=@roomId and  [GuestUserId]=@friendId and RoomId=@roomId)<1
begin
	insert into [Dcx_IMRelationship] ([AccountId],GroupId,RoomId,[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
	values(@accountId,0, @roomId,@roomId,@friendId,@friendName,@Relationship,getdate())
end
else
begin
	UPDATE [Dcx_IMRelationship] SET [RoomId] =@roomId,[IsTemp]=0,[IsDeleted]=0 WHERE [HostUserId]=@roomId and [GuestUserId]=@friendId  and  RoomId=@roomId 
end
if (select count(*) from [Dcx_IMRelationship] where HostUserId=@friendId and  RoomId=@roomId and  [GuestUserId]=@roomId )<1
begin 
	insert into [Dcx_IMRelationship] ([AccountId],GroupId,RoomId,[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
	values(@accountId, 0,@roomId,@friendId,@roomId,@roomUserName,@Relationship,getdate())
end 
else
begin
	UPDATE [Dcx_IMRelationship] SET [RoomId] =@roomId,[IsTemp]=0,[IsDeleted]=0 WHERE [HostUserId]=@friendId and [GuestUserId]=@roomId  and  RoomId=@roomId 
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddTempFriend]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_AddTempFriend]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_AddTempFriend]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--添加临时好友
CREATE PROC [dbo].[DcxRun_IM_AddTempFriend](
@accountId int,@userId int, @userName nvarchar(256),
@friendId int, @friendName nvarchar(256)
)
as
begin
if (select count(*) from [Dcx_IMRelationship] where HostUserId=@userId and [RoomId]=0)<1
begin
	insert into [Dcx_IMRelationship] ([AccountId] ,[IsTemp],[GroupId],[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
	values( @accountId,1,0,@userId,@friendId,@friendName,0,getdate())
end
if (select count(*) from [Dcx_IMRelationship] where [HostUserId]=@friendId and [RoomId]=0)<1
begin 
	insert into [Dcx_IMRelationship] ([AccountId] ,[IsTemp],[GroupId],[HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
	values( @accountId,1,0,@friendId,@userId,@userName,0,getdate())
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_CreateGroup]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_CreateGroup]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_CreateGroup]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_CreateGroup](@creatorName nvarchar(256), @userName nvarchar(256), @realName nvarchar(256), @inviteCode nvarchar(256))
as
begin
	select [UserId] from Dcx_User where UserName=UPPER(@userName)
	if(@@rowcount>0)
	begin
		raiserror(N''群"%s"已存在'', 16, 1, @userName)
		return
	end
--添加用户
	insert into Dcx_User (UserName,UpperName,PWD,RealName,Email,InviteCode,GroupId,RegistedDate) 
	values (@userName,UPPER(@userName),'''',@realName,'''',@inviteCode,0,getdate())
	declare @UserId int
	set @UserId = @@identity
--添加角色成员
	insert into Dcx_UserInRole (UserId,RoleId)
	select [UserId] as UserId,2 as RoleId from Dcx_User where [UserId]=@UserId
--和创建者成为好友
	insert into Dcx_IMRelationship (RenewTime,HostUserId,GuestUserId,Relationship)
	select getdate() as RenewTime,(select [UserId] from Dcx_User where UserName=UPPER(@creatorName)) as HostUserId,(select [UserId] from Dcx_User where [UserId]=@UserId) as GuestUserId,3 as Relationship
--和创建者成为好友
	insert into Dcx_IMRelationship (RenewTime,HostUserId,GuestUserId,Relationship)
	select getdate() as RenewTime,(select [UserId] from Dcx_User where [UserId]=@UserId) as GuestUserId,(select [UserId] from Dcx_User where UserName=UPPER(@creatorName)) as HostUserId,3 as Relationship
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_CreateTempUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_CreateTempUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_CreateTempUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_CreateTempUser](@userName nvarchar(256), @realName nvarchar(256))
as
begin
	select [UserId] from Dcx_User where UserName=UPPER(@userName)
	if(@@rowcount>0)
	begin
		raiserror(N''用户"%s"已存在'', 16 ,1, @userName)
		return
	end
--添加用户
	insert into Dcx_User (UserName,UpperName,PWD,RealName,Email,InviteCode,GroupId,RegistedDate) 
	values (@userName,UPPER(@userName),N'''',@realName,N'''',N'''',0,getdate())
	declare @UserId int
	set @UserId = @@identity
--添加角色成员
	insert into Dcx_UserInRole (UserId,RoleId)
	select [UserId] as UserId,2 as RoleId from Dcx_User where [UserId]=@UserId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_CreateUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_CreateUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_CreateUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_CreateUser](@userName nvarchar(256), @realName nvarchar(256), @pwd nvarchar(256), @email nvarchar(256), @inviteCode nvarchar(256))
as
begin
	select [UserId] from Dcx_User where UserName=UPPER(@userName)
	if(@@rowcount>0)
	begin
		raiserror(N''用户"%s"已存在'', 16 ,1, @userName)
		return
	end
--增加用户
	insert into Dcx_User (UserName,[UpperName],PWD,RealName,Email,InviteCode,RegistedDate) 
	values (@userName,UPPER(@userName),@pwd,@realName,@email,@inviteCode,getdate())
	declare @UserId int
	set @UserId = @@identity
--增加角色成员
	insert into Dcx_UserInRole (UserId,RoleId)
	select [UserId] as UserId,2 as RoleId from Dcx_User where [UserId]=@UserId
--增加好友关系
	insert into Dcx_IMRelationship(HostUserId, GuestUserId,Relationship,RenewTime)
	select u1.[UserId], u2.[UserId], 0, getdate() as RenewTime
	from Dcx_User u1, Dcx_User u2 
	where u1.UserName=''PUBLIC'' and u2.[UserId]=@UserId
--增加好友关系
	insert into Dcx_IMRelationship(HostUserId, GuestUserId,Relationship,RenewTime)
	select u2.[UserId], u1.[UserId], 0, getdate() as RenewTime
	from Dcx_User u1, Dcx_User u2 
	where u1.UserName=''PUBLIC'' and u2.[UserId]=@UserId
--增加好友关系
	insert into Dcx_IMRelationship(HostUserId, GuestUserId,Relationship,RenewTime)
	select u1.[UserId], u2.[UserId], 0, getdate() as RenewTime
	from Dcx_User u1, Dcx_User u2 
	where u1.UserName=''ADMIN'' and u2.[UserId]=@UserId
--增加好友关系
	insert into Dcx_IMRelationship(HostUserId, GuestUserId,Relationship,RenewTime)
	select u2.[UserId], u1.[UserId], 0, getdate() as RenewTime
	from Dcx_User u1, Dcx_User u2 
	where u1.UserName=''ADMIN'' and u2.[UserId]=@UserId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteAllMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteAllMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteAllMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条消息
CREATE PROC [dbo].[DcxRun_IM_DeleteAllMsg](@userId int,@friendId int)
as
begin
set nocount on
update  [Dcx_IMessage] set SenderDelete=1 WHERE [SenderId]=@userId and [ReceiverId]=@friendId
update  [Dcx_IMessage] set ReceiverDelete=1 WHERE [SenderId]=@friendId and [ReceiverId]=@userId
delete from [Dcx_IMessage] WHERE (([SenderId]=@userId and [ReceiverId]=@friendId) or ([SenderId]=@friendId and [ReceiverId]=@userId) )
and SenderDelete=1 and ReceiverDelete=1
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteAllRoomMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteAllRoomMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteAllRoomMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条消息
CREATE PROC [dbo].[DcxRun_IM_DeleteAllRoomMsg](@roomId int,@userId int)
as
begin
set nocount on
if @userId=(select top 1 CreatorId from [Dcx_IMRoom] where [RoomId]=@roomId)
	delete from [Dcx_IMRoomMsg] WHERE  [RoomId]=@roomId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteFriend]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteFriend]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteFriend]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_DeleteFriend](@roomId int, @userId int, @friendId int)
as
begin
set nocount on
if @roomId is null
	set @roomId=0
if @roomId>0
begin
	delete from [Dcx_IMRoomLgr] WHERE [RoomId]=@roomId and [UserId]=@friendId 
	delete from [Dcx_IMRelationship] where ([HostUserId]=@friendId or [GuestUserId]=@friendId) and  [RoomId]=@roomId 
end
else
begin
	delete from [Dcx_LinkMan] WHERE [CreatorId]=@userId and [UserId]=@friendId 
	delete from [Dcx_IMRelationship] where [HostUserId]=@userId and [GuestUserId]=@friendId and  [RoomId]=@roomId 
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteGroup]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteGroup]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteGroup]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_DeleteGroup](@userId int, @groupId int)
as
begin
if(select count(1) from [Dcx_LinkMan] WHERE [CreatorId]=@userId and [GroupId]=@groupId )<1 
begin
	delete from [Dcx_LinkManGroup] WHERE [CreatorId]=@userId and [GroupId]=@groupId 
	select 1
end
else
	select 0
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条消息
CREATE PROC [dbo].[DcxRun_IM_DeleteMsg](@userId int,@senderId int,@receiverId int, @msgId int)
as
begin
set nocount on
if @userId=@senderId
begin
	if (select [ReceiverDelete] from [Dcx_IMessage] WHERE [SenderId]=@senderId and [ReceiverId]=@receiverId and [MsgId]=@msgId)=1
		delete from [Dcx_IMessage] WHERE [SenderId]=@senderId and [ReceiverId]=@receiverId and [MsgId]=@msgId
	else
		update  [Dcx_IMessage] set SenderDelete=1 WHERE [SenderId]=@senderId and [ReceiverId]=@receiverId and [MsgId]=@msgId
end
else
begin
	if (select [SenderDelete] from [Dcx_IMessage] WHERE [SenderId]=@senderId and [ReceiverId]=@receiverId and [MsgId]=@msgId)=1
		delete from [Dcx_IMessage] WHERE [SenderId]=@senderId and [ReceiverId]=@receiverId and [MsgId]=@msgId
	else
	update  [Dcx_IMessage] set ReceiverDelete=1 WHERE [SenderId]=@senderId and [ReceiverId]=@receiverId and [MsgId]=@msgId
end
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteMsgBySendDate]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteMsgBySendDate]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteMsgBySendDate]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除在一定时间段之内我和一位朋友的对话消息
CREATE PROC [dbo].[DcxRun_IM_DeleteMsgBySendDate](@userId int,@friendId int,@fromDate datetime)
as
begin
	set nocount on 
	if @fromDate is null
	begin
		update  [Dcx_IMessage] set SenderDelete=1 WHERE [SenderId]=@userId and [ReceiverId]=@friendId 
		update  [Dcx_IMessage] set ReceiverDelete=1 WHERE [SenderId]=@friendId and [ReceiverId]=@userId
	end
	else
	begin
		update  [Dcx_IMessage] set SenderDelete=1 WHERE [SenderId]=@userId and [ReceiverId]=@friendId  and [SentDate]>=@fromDate 
		update  [Dcx_IMessage] set ReceiverDelete=1 WHERE [SenderId]=@friendId and [ReceiverId]=@userId and [SentDate]>=@fromDate 
	end
	delete from [Dcx_IMessage] WHERE (([SenderId]=@userId and [ReceiverId]=@friendId) or ([SenderId]=@friendId and [ReceiverId]=@userId) ) and SenderDelete=1 and ReceiverDelete=1
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteRoom]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteRoom]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteRoom]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_DeleteRoom](@roomId int, @userId int)
as
begin
	delete from [Dcx_IMRoom] WHERE [CreatorId]=@userId and [RoomId]=@roomId 
	delete from [Dcx_IMRoomLgr] WHERE [RoomId]=@roomId 
	delete from [Dcx_IMRelationship] WHERE [RoomId]=@roomId and ([HostUserId]=@roomId or [GuestUserId]=@roomId )
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteRoomMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteRoomMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteRoomMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条消息
CREATE PROC [dbo].[DcxRun_IM_DeleteRoomMsg](@roomId int,@userId int,@msgId int)
as
begin
set nocount on
if @userId=(select top 1 CreatorId from [Dcx_IMRoom] where [RoomId]=@roomId)
	delete from [Dcx_IMRoomMsg] WHERE  [RoomId]=@roomId and  [MsgId]=@msgId
else
	delete from [Dcx_IMRoomMsg] WHERE  [RoomId]=@roomId and  [MsgId]=@msgId and  [SenderId]=@userId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteRoomMsgBySendDate]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteRoomMsgBySendDate]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteRoomMsgBySendDate]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除在一定时间段之内我和一位朋友的对话消息
CREATE PROC [dbo].[DcxRun_IM_DeleteRoomMsgBySendDate](@roomId int,@userId int,@fromDate datetime)
as
begin
set nocount on 
	if @userId=(select top 1 CreatorId from [Dcx_IMRoom] where [RoomId]=@roomId)
	begin
		if @fromDate is null
			delete from [Dcx_IMRoomMsg] WHERE  [RoomId]=@roomId  
		else
			delete from [Dcx_IMRoomMsg] WHERE  [RoomId]=@roomId and [SentDate]>=@fromDate 
	end
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_DeleteUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_DeleteUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_DeleteUser](@UserId int)
as
begin
	delete from Dcx_IMRelationship where RoomId=0 and (HostUserId = @UserId or GuestUserId = @UserId)
	delete from Dcx_UserInRole where UserId = @UserId
	delete from Dcx_User where [UserId] = @UserId;
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_FindHistory]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_FindHistory]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_FindHistory]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_FindHistory](@userId int, @peerId int, @fromDate datetime, @toDate datetime)
as
begin
	select top 30 temp.[MsgId], temp.[ReceiverId], temp.[SenderId], temp.[MsgContent], temp.[SentDate] 
	from (
--1。@peerId发给我的。
		select [MsgId], [ReceiverId], [SenderId], [MsgContent], [SentDate] 
		from [Dcx_IMessage] 
		where [ReceiverId] = @userId and [SenderId] = @peerId and [SentDate] >= @fromDate and [SentDate] <= @toDate
		union all
--2。我发给@peerId的。
		select [MsgId], [ReceiverId], [SenderId], [MsgContent], [SentDate] 
		from [Dcx_IMessage] 
		where [ReceiverId] = @peerId and [SenderId] = @userId and [SentDate] >= @fromDate and [SentDate] <= @toDate
		union all
--3。聊天室
		select 
			m.[MsgId], m.[ReceiverId], m.[SenderId], m.[MsgContent], m.[SentDate] 
		from 
			[Dcx_IMessage] m, [Dcx_IMRelationship] ur, Dcx_User u, Dcx_User s
		where 
			ur.[HostUserId] = @userId and m.[ReceiverId] = @peerId 
			and ur.[GuestUserId] = u.[UserId] and u.[GroupId] = 1 and ur.[GuestUserId] = m.[ReceiverId] 
			and [SentDate] >= @fromDate and [SentDate] <= @toDate
			and m.[SenderId] = s.[UserId] and s.UserName <> ''ADMINISTRATOR'' and m.[SentDate] > ur.RenewTime
	) temp
	order by [SentDate] desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_FindMessages]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_FindMessages]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_FindMessages]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取@fromDate之后的100条信息，@receiverId：接收者；@peerId：发送者
--如果@peerId>0，返回指定发送者发给我的信息；
--否则，用户是游客，返回公共聊天室的信息。
CREATE PROC [dbo].[DcxRun_IM_FindMessages](@receiverId int, @peerId int, @fromDate datetime)
as
begin
	if(@peerId > 0)
	begin
		select top 100 [MsgId],ReceiverId,SenderId,MsgContent,SentDate
		from Dcx_IMessage 
		where ReceiverId = @receiverId and SenderId = @peerId and SentDate > @fromDate
		order by SentDate desc
	end
	else
	begin
		select top 100 temp.[MsgId], temp.ReceiverId, temp.SenderId, temp.MsgContent, temp.SentDate 
		from (
			select [MsgId], ReceiverId, SenderId, MsgContent, SentDate 
			from Dcx_IMessage 
			where ReceiverId = @receiverId and SentDate > @fromDate
			union all
			select m.[MsgId], m.ReceiverId, m.SenderId, m.MsgContent, m.SentDate 
			from Dcx_IMessage m inner join [Dcx_IMRelationship] ur on 
ur.HostUserId = @receiverId and  ur.GuestUserId = m.ReceiverId 
  inner join [Dcx_User] u   on   ur.GuestUserId = u.[UserId]
			where u.GroupId = 1 and  m.SentDate > @fromDate and m.SentDate > ur.RenewTime
		) temp  --这个“ur.GuestUserId = u.[MsgId] and u.Type = 1 ”就表明了要获取的就是公共聊天室，专门有一个帐号做为公共聊天室来使用的，即GuestUserId
		order by SentDate desc
	end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAccountInfoByName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetAccountInfoByName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAccountInfoByName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetAccountInfoByName](@userName nvarchar(256))
as
begin
	select * from [Dcx_User] where [UpperName] = UPPER(@userName)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAllGroups]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetAllGroups]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAllGroups]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetAllGroups]
as
begin
	select u.[UserId], u.[UserName], u.RealName, u.Email, u.RegistedDate, c.[UserId] Creator
	from [Dcx_User] u, [Dcx_User] c, [Dcx_IMRelationship] ur 
	where u.[GroupId] = 1 and u.[UserId] = ur.[HostUserId] and c.[UserId] = ur.[GuestUserId] and ur.Relationship = 3
	order by u.RegistedDate desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAllUnreadMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetAllUnreadMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAllUnreadMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_IM_GetAllUnreadMsg]
(
	@userId int,
	@fromDate datetime
)
AS
begin
EXEC	[DcxRun_IM_GetReceiveMsg]
		@PageSize = 0,
		@PageIndex = 0,
		@userId = @userId,
		@friendId = 0,
		@fromDate = @fromDate,
		@toDate = null
EXEC	[DcxRun_IM_GetRoomMsg]
		@PageSize = 0,
		@PageIndex = 0,
		@userId = @userId,
		@roomId = 0,
		@fromDate = @fromDate,
		@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAllUsers]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetAllUsers]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetAllUsers]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetAllUsers]
as
begin
	select [UserId], [UserName], RealName, Email, RegistedDate 
	from [Dcx_User] u 
	where u.[GroupId] = 0
	order by RegistedDate desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetFriends]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetFriends]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetFriends]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetFriends](@userName nvarchar(256))
as
begin
	select 
		guest.[UserName] as [UserName],
		guest.GroupId as UserType,
		r.RenewTime as RenewTime,
		r.Relationship as Relationship
	from 
		[Dcx_IMRelationship] r,
		[Dcx_User] host,
		[Dcx_User] guest
	where 
		r.[HostUserId]=host.[UserId] and
		r.[GuestUserId]=guest.[UserId] and
		host.[UserName]=upper(@userName)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetFriendsByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetFriendsByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetFriendsByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetFriendsByUserId](
@userId int,
@roomId int
)
as
begin 
if @roomId<1
SELECT [RId] 
      ,[GuestUserId] as UserId
      ,[GuestUserName] as UserName
      ,[Relationship]
      ,[RenewTime]
      ,[GroupId]
      ,[GroupName]
      ,[RoomId]
      ,[LastTalkDate],LastMsg,[IsTemp],[IsDeleted],0 as UserType
  FROM [Dcx_IMRelationship] where [HostUserId]=@userId  and ([RoomId]=0 or [GuestUserId]=[RoomId]) order by [LastTalkDate] desc
else
SELECT [RId] 
      ,[GuestUserId] as UserId
      ,[GuestUserName] as UserName
      ,[Relationship]
      ,[RenewTime]
      ,[GroupId]
      ,[GroupName]
      ,[RoomId]
      ,[LastTalkDate],LastMsg,[IsTemp],[IsDeleted],0 as UserType
  FROM [Dcx_IMRelationship] where [HostUserId]=@roomId  and [RoomId]=@roomId order by LastTalkDate desc 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetGroupManagers]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetGroupManagers]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetGroupManagers]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetGroupManagers](@userName nvarchar(256))
as
begin
	select 
		guest.[UserName] 
	from 
		[Dcx_IMRelationship] r,
		[Dcx_User] host,
		[Dcx_User] guest
	where 
		r.Relationship=2 and
		r.[HostUserId]=host.[UserId] and
		r.[GuestUserId]=guest.[UserId] and
		host.[UserName]=UPPER(@userName)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetMaxMsgId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetMaxMsgId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetMaxMsgId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetMaxMsgId]
as
begin
declare @id1 int
declare @id2 int
declare @t1 datetime
declare @t2 datetime
select @id1=max([MsgId]), @t1=max(SentDate) from Dcx_IMessage
select @id2=max([MsgId]), @t2=max(SentDate) from Dcx_IMRoomMsg
set @id1=isnull(@id1,0)
set @id2=isnull(@id2,0)
if @id1<@id2
set @id1=@id2
if @t1<@t2
set @t1=@t2
select @id1 as MaxMsgId, @t1 as MaxCreatedTime
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_IM_GetMsg]
(
	@PageSize int,
	@PageIndex int,
	@userId int,
	@friendId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @PageSize>0 or @PageIndex>0
begin
	DECLARE @startRow int
	DECLARE @endRow   int
	if @PageSize is null or @PageSize<1
		set @PageSize=20
	if @PageIndex is null or @PageIndex<1
		set @PageIndex=1
	SET @startRow = (@PageIndex - 1) * @PageSize +1
	SET @endRow = @startRow + @PageSize -1 
	if @friendId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else if @toDate is  null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
		end
		else
		begin
				  select *  from (
					select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
					where ([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
					   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1)
				  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
		 end
	end
	else 
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and (([SenderId]=@userId  and [SenderDelete]!=1) 
							   or ([ReceiverId]=@userId and [ReceiverDelete]!=1))
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else if @toDate is  null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and (([SenderId]=@userId  and [SenderDelete]!=1) 
							   or ( [ReceiverId]=@userId and [ReceiverDelete]!=1))
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and (([SenderId]=@userId and [SenderDelete]!=1) 
							   or ( [ReceiverId]=@userId and [ReceiverDelete]!=1))
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
		end
		else
		begin
				select *  from (
					select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
					where ([SenderId]=@userId and  [SenderDelete]!=1) 
					   or ([ReceiverId]=@userId and [ReceiverDelete]!=1)
				) AS MyTable  where  dcx_rowid between @startRow and @endRow 
		end
	end
end
else
begin  
	if @friendId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else if @toDate is  null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
		end
		else
		begin
							select  top 200  [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where ([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1)
		 end
	end
	else 
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and (([SenderId]=@userId  and [SenderDelete]!=1) 
							   or ([ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else if @toDate is  null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and (([SenderId]=@userId  and [SenderDelete]!=1) 
							   or ( [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and (([SenderId]=@userId and [SenderDelete]!=1) 
							   or ( [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
		end
		else
		begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where ([SenderId]=@userId and  [SenderDelete]!=1) 
							   or ([ReceiverId]=@userId and [ReceiverDelete]!=1)
		end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetMsgCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetMsgCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetMsgCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_IM_GetMsgCount]
(
	@userId int,
	@friendId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
	if @friendId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1) FROM [Dcx_IMessage] where [SentDate]>@fromDate and [SentDate]<@toDate and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else if @toDate is  null 
				begin
							select count(1) FROM [Dcx_IMessage] where [SentDate]>@fromDate  and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else 
				begin
							select count(1) FROM [Dcx_IMessage] where [SentDate]<@toDate and (([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
							   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
		end
		else
		begin
						select count(1) FROM [Dcx_IMessage] where ([SenderId]=@userId and [ReceiverId]=@friendId and [SenderDelete]!=1) 
					   or ([SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1)
		 end
	end
	else 
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1) FROM [Dcx_IMessage] where [SentDate]>@fromDate and [SentDate]<@toDate and (([SenderId]=@userId  and [SenderDelete]!=1) 
							   or ([ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else if @toDate is  null 
				begin
							select count(1) FROM [Dcx_IMessage] where [SentDate]>@fromDate  and (([SenderId]=@userId  and [SenderDelete]!=1) 
							   or ( [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
				else 
				begin
							select count(1) FROM [Dcx_IMessage] where [SentDate]<@toDate and (([SenderId]=@userId and [SenderDelete]!=1) 
							   or ( [ReceiverId]=@userId and [ReceiverDelete]!=1))
				end
		end
		else
		begin
					select count(1) FROM [Dcx_IMessage] where ([SenderId]=@userId and  [SenderDelete]!=1) 
					   or ([ReceiverId]=@userId and [ReceiverDelete]!=1)
		end
	end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetReceiveMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetReceiveMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetReceiveMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取@friendId发送给@userId的信息
CREATE PROCEDURE [dbo].[DcxRun_IM_GetReceiveMsg]
(
	@PageSize int,
	@PageIndex int,
	@userId int,
	@friendId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @PageSize>0 or @PageIndex>0
begin
	DECLARE @startRow int
	DECLARE @endRow   int
	if @PageSize is null or @PageSize<1
		set @PageSize=20
	if @PageIndex is null or @PageIndex<1
		set @PageIndex=1
	SET @startRow = (@PageIndex - 1) * @PageSize +1
	SET @endRow = @startRow + @PageSize -1 
	if @friendId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and  [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else if @toDate is  null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
		end
		else
		begin
				  select *  from (
					select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
					where  [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
				  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
		 end
	end
	else 
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId and [ReceiverDelete]!=1 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else if @toDate is  null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and  [ReceiverId]=@userId and [ReceiverDelete]!=1 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and [ReceiverId]=@userId and [ReceiverDelete]!=1
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
		end
		else
		begin
				select *  from (
					select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
					where [ReceiverId]=@userId and [ReceiverDelete]!=1
				) AS MyTable  where  dcx_rowid between @startRow and @endRow 
		end
	end
end
else
begin  
	if @friendId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and  [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
				end
				else if @toDate is  null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and  [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
				end
				else 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and  [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
				end
		end
		else
		begin
							select  top 200  [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where  [SenderId]=@friendId and [ReceiverId]=@userId and [ReceiverDelete]!=1 
		 end
	end
	else 
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and  [ReceiverId]=@userId and [ReceiverDelete]!=1 
				end
				else if @toDate is  null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]>@fromDate  and  [ReceiverId]=@userId and [ReceiverDelete]!=1 
				end
				else 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where [SentDate]<@toDate and [ReceiverId]=@userId and [ReceiverDelete]!=1 
				end
		end
		else
		begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[ReadFlag],[FileJson]  FROM [Dcx_IMessage]  
							where  [ReceiverId]=@userId and [ReceiverDelete]!=1 
		end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetRelationship]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetRelationship]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetRelationship]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetRelationship](@userName1 nvarchar(256), @userName2 nvarchar(256))
as
begin
	select *
	from [Dcx_User] host,[Dcx_User] guest,[Dcx_IMRelationship] r
	where host.[UserName]=upper(@userName1) and guest.[UserName]=upper(@userName2) and r.[HostUserId]=host.[UserId] and r.[GuestUserId]=guest.[UserId]
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetRoomMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetRoomMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetRoomMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_IM_GetRoomMsg]
(
	@PageSize int,
	@PageIndex int,
	@userId int,
	@roomId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
declare @rooms table([RoomId] int)
if @PageSize>0 or @PageIndex>0
begin
	DECLARE @startRow int
	DECLARE @endRow   int
--	set @PageSize=20
	if @PageSize is null or @PageSize<1
		set @PageSize=20
	if @PageIndex is null or @PageIndex<1
		set @PageIndex=1
	SET @startRow = (@PageIndex - 1) * @PageSize +1
	SET @endRow = @startRow + @PageSize -1 
	if @roomId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and [RoomId]=@roomId
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else if @toDate is  null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
							where [SentDate]>@fromDate  and [RoomId]=@roomId
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
							where [SentDate]<@toDate and [RoomId]=@roomId
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
		end
		else
		begin
				  select *  from (
					select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
					where [RoomId]=@roomId
				  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
		 end
	end
	else 
	begin
		insert into @rooms([RoomId]) select RoomId from Dcx_IMRoomLgr where UserId=@userId
		if (select count(1) from @rooms)<1
		begin
			select   -1,-1,null,null,null,null
			return
		end
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
							where [SentDate]>@fromDate and [SentDate]<@toDate 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else if @toDate is  null 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]   FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
							where [SentDate]>@fromDate  
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
				else 
				begin
						select *  from (
							select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]   FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
							where [SentDate]<@toDate 
						) AS MyTable  where  dcx_rowid between @startRow and @endRow 
				end
		end
		else
		begin
				select *  from (
					select row_number() over( order by [SentDate] desc)as dcx_rowid, [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]    FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
				) AS MyTable  where  dcx_rowid between @startRow and @endRow 
		end
	end
end
else
begin 
	if @roomId>0
	begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select  top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
							where [SentDate]>@fromDate and [SentDate]<@toDate and [RoomId]=@roomId
				end
				else if @toDate is  null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
							where [SentDate]>@fromDate  and [RoomId]=@roomId
				end
				else 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
							where [SentDate]<@toDate and [RoomId]=@roomId
				end
		end
		else
		begin
					select  [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM [Dcx_IMRoomMsg]  
					where [RoomId]=@roomId
		 end
	end
	else 
	begin
		insert into @rooms([RoomId]) select RoomId from Dcx_IMRoomLgr where UserId=@userId
		if (select count(1) from @rooms)<1
		begin
			select   -1 as [MsgId],-1 as SenderId,null as SenderName,null as [MsgContent],null as [SentDate],null as [FileJson],0 as [RoomId]
			return
		end
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]  FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
							where [SentDate]>@fromDate and [SentDate]<@toDate 
				end
				else if @toDate is  null 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]   FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
							where [SentDate]>@fromDate  
				end
				else 
				begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]   FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
							where [SentDate]<@toDate 
				end
		end
		else
		begin
							select   top 200 [MsgId],SenderId,SenderName,[MsgContent],[SentDate],[FileJson],[Dcx_IMRoomMsg].[RoomId]    FROM @rooms as Room inner join [Dcx_IMRoomMsg]  on Room.[RoomId]=[Dcx_IMRoomMsg].[RoomId]
		end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetRoomMsgCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetRoomMsgCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetRoomMsgCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_IM_GetRoomMsgCount]
(
	@roomId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin 
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1) FROM [Dcx_IMRoomMsg] where [SentDate]>@fromDate and [SentDate]<@toDate and  [RoomId]=@roomId
				end
				else if @toDate is  null 
				begin
							select count(1) FROM [Dcx_IMRoomMsg] where [SentDate]>@fromDate  and  [RoomId]=@roomId
				end
				else 
				begin
							select count(1) FROM [Dcx_IMRoomMsg] where [SentDate]<@toDate and    [RoomId]=@roomId
				end
		end
		else
		begin
						select count(1) FROM [Dcx_IMRoomMsg] where     [RoomId]=@roomId
		 end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetUserById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetUserById](@UserId int)
as
begin
	select top 1 * from [Dcx_User] where [UserId] = @UserId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserByName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetUserByName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserByName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetUserByName](@userName nvarchar(256))
as
begin
	select * from [Dcx_User] where [UserName] = UPPER(@userName)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRoles]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetUserRoles]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRoles]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetUserRoles](@userName nvarchar(256))
as
begin
	select r.[RoleName] as RoleName 
	from Dcx_User u,Dcx_UserInRole ur,Dcx_Role r 
	where u.UserName=upper(@userName) and u.[UserId]=ur.[UserId] and ur.[RoleId]=r.[RoleId]
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRolesById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetUserRolesById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRolesById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetUserRolesById](@userId int)
as
begin
select r.[RoleName] ,r.RoleId from 
[Dcx_UserInRole] ur inner join [Dcx_Role] r on  ur.[RoleId]=r.[RoleId] where ur.[UserId]=@userId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRolesByName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetUserRolesByName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRolesByName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetUserRolesByName](@userName varchar(50))
as
begin
select r.[RoleName] ,r.RoleId from 
[Dcx_UserInRole] ur inner join [Dcx_Role] r on  ur.[RoleId]=r.[RoleId] where ur.[UserName]=@userName 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRolesByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_GetUserRolesByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_GetUserRolesByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_GetUserRolesByUserId](@userId int)
as
begin
SELECT distinct ur.[RoleId]
      ,[RoleName]
      ,[SystemRoleType]
      ,[ParentId]
      ,[RoleOrder]
      ,[RoleTypeId]
      ,[Remark]
	from Dcx_UserInRole ur,Dcx_Role r 
	where ur.[UserId]=@userId and ur.[RoleId]=r.[RoleId] order by [RoleOrder]
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateFriendGroup]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_UpdateFriendGroup]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateFriendGroup]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_UpdateFriendGroup](
@groupId int,
@userId int, 
@friendId int
)
as
begin 
if @groupId>0
begin
UPDATE [Dcx_LinkMan] SET [GroupId] =@groupId WHERE [CreatorId]=@userId and [UserId]=@friendId 
UPDATE [Dcx_IMRelationship] SET [GroupId] =@groupId,[IsTemp]=0 WHERE [HostUserId]=@userId and [GuestUserId]=@friendId 
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateFriendRelation]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_UpdateFriendRelation]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateFriendRelation]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_UpdateFriendRelation](
@RoomId int,
@HostUserId int,
@GuestUserId int, 
@LastTalkDate datetime,
@LastMsg varchar(3000)
)
as
begin 
set nocount on
if @RoomId<1
set  @RoomId=0
UPDATE [Dcx_IMRelationship] SET [LastTalkDate] =@LastTalkDate,[LastMsg] =@LastMsg
 WHERE  [RoomId]=@RoomId and (([HostUserId]=@HostUserId and [GuestUserId]=@GuestUserId  ) or 
([HostUserId]=@GuestUserId and [GuestUserId]=@HostUserId))
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateGroupName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_UpdateGroupName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateGroupName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_UpdateGroupName](@userId int, @groupId int, @groupName varchar(100) )
as
begin
update [Dcx_LinkManGroup] set [GroupName]=@groupName WHERE [CreatorId]=@userId and [GroupId]=@groupId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateLastTalk]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_UpdateLastTalk]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateLastTalk]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_UpdateLastTalk](
@senderId int,
@receiverId int,
@talkDate datetime
)
as
begin 
update [Dcx_IMRelationship] set [LastTalkDate]=@talkDate 
where  ([HostUserId]=@senderId and [GuestUserId]=@receiverId ) or ([GuestUserId]=@senderId and [HostUserId]=@receiverId )  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateRoomLgrCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_UpdateRoomLgrCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateRoomLgrCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_UpdateRoomLgrCount](
@roomId int
)
as
begin
declare @c int
set @c=(select count(1) from [Dcx_IMRoomLgr] as r WHERE  r.[RoomId]=@roomId  )
UPDATE [Dcx_IMRoom] SET [LgrCount] =@c WHERE  [RoomId]=@roomId  
select @c
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateRoomName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_UpdateRoomName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_UpdateRoomName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_UpdateRoomName](
@roomId int,
@roomName varchar(200)
)
as
begin
UPDATE [Dcx_IMRoom] SET [RoomName] =@roomName WHERE  [RoomId]=@roomId  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_Validate]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_IM_Validate]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_IM_Validate]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_IM_Validate](@userName nvarchar(256), @pwd nvarchar(256))
as
begin
	select top 1 * from [Dcx_User] where [UserName]=upper(@userName) and [PWD]=@pwd
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_DelAllReceived]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_DelAllReceived]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_DelAllReceived]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[DcxRun_INote_DelAllReceived]
@receiver_id int
AS
BEGIN
update fzoa_inner_note set receiver_del=1 where receiver_id=@receiver_id and receiver_del=0
delete from fzoa_inner_note where receiver_del=1 and sender_del=1
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_DelAllsent]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_DelAllsent]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_DelAllsent]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[DcxRun_INote_DelAllsent]
@sender_id int
AS
BEGIN
update fzoa_inner_note set sender_del=1 where sender_id=@sender_id and sender_del=0
delete from fzoa_inner_note where receiver_del=1 and sender_del=1
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_delete_true]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_delete_true]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_delete_true]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_INote_delete_true]
@user_id int
AS
BEGIN
delete from fzoa_inner_note where receiver_del=1 and sender_del=1
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_deleteReceived]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_deleteReceived]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_deleteReceived]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_INote_deleteReceived]
@innerNoteId varchar(8000)
AS
BEGIN
DECLARE @up_sql VARCHAR(200)
set @up_sql=''update  fzoa_inner_note set receiver_id=1 where inner_note_id in (''+@innerNoteId+'') and receiver_id=0 ''
EXECUTE(@up_sql)
delete from fzoa_inner_note where receiver_del=1 and sender_del=1
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_deleteSent]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_deleteSent]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_deleteSent]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_INote_deleteSent]
@innerNoteId varchar(8000)
AS
BEGIN
DECLARE @up_sql VARCHAR(200)
set @up_sql=''update  fzoa_inner_note set sender_del=1 where inner_note_id in (''+@innerNoteId+'') and sender_del=0 ''
EXECUTE(@up_sql)
delete from fzoa_inner_note where receiver_del=1 and sender_del=1
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_ALLInnernote]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_Get_ALLInnernote]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_ALLInnernote]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_Get_ALLInnernote]
@receiver_id int,
@Rowcount int OUTPUT
AS
BEGIN
select inner_note_id,sender_id,sender_name,sent_date,note_content,read_flag from fzoa_inner_note where receiver_id=@receiver_id order by sent_date desc
SET  @Rowcount=@@ROWCOUNT
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_ReceivedInnerNoteByCondition]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_Get_ReceivedInnerNoteByCondition]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_ReceivedInnerNoteByCondition]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_INote_Get_ReceivedInnerNoteByCondition]
@condition varchar(1000)
AS
BEGIN
DECLARE @select_sql VARCHAR(5000)
set @select_sql=''select inner_note_id,sender_id,sender_name,sent_date,note_content,read_flag from fzoa_inner_note where receiver_del=0 and ''+@condition+'' order by sent_date desc''
EXECUTE(@select_sql)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_SentInnerNote]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_Get_SentInnerNote]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_SentInnerNote]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_Get_SentInnerNote]
@user_id int
AS
BEGIN
select inner_note_id,realname as real_name,sent_date,note_content,read_flag,receiver_id from fzoa_inner_note,Dcx_USER where sender_id=@user_id and sender_del=0 and receiver_id=Dcx_USER.[UserId] order by sent_date desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_SentInnerNoteByCondition]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_Get_SentInnerNoteByCondition]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_SentInnerNoteByCondition]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_INote_Get_SentInnerNoteByCondition]
@condition varchar(1000)
AS
BEGIN
DECLARE @select_sql VARCHAR(5000)
set @select_sql=''select inner_note_id,receiver_id,realname as real_name,sent_date,note_content,read_flag from fzoa_inner_note,Dcx_USER  where  sender_del=0 and  receiver_id=Dcx_USER.userid and ''+@condition+'' order by sent_date desc''
EXECUTE(@select_sql)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_unnote_innernote]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_Get_unnote_innernote]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_unnote_innernote]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[DcxRun_INote_Get_unnote_innernote]
@receiver_id int,
@Rowcount int OUTPUT
AS
BEGIN
select inner_note_id,sender_id,sender_name,sent_date,note_content from fzoa_inner_note where receiver_id=@receiver_id and note_flag=0 and receiver_del=0 order by sent_date desc
SET  @Rowcount=@@ROWCOUNT
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_unread_innernote]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_Get_unread_innernote]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_Get_unread_innernote]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_Get_unread_innernote]
@receiver_id int,
@Rowcount int OUTPUT
AS
BEGIN
select inner_note_id,sender_id,sender_name,sent_date,note_content from fzoa_inner_note where receiver_id=@receiver_id and read_flag=0 and receiver_del=0 order by sent_date desc
SET  @Rowcount=@@ROWCOUNT
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetALLReceived]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_GetALLReceived]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetALLReceived]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_GetALLReceived]
@user_id int,
@Rowcount int OUTPUT
AS
BEGIN
select * from fzoa_inner_note where receiver_id=@user_id  and receiver_del=0 order by sent_date desc
SET  @Rowcount=@@ROWCOUNT
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetALLSent]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_GetALLSent]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetALLSent]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_GetALLSent]
@user_id int,
@Rowcount int OUTPUT
AS
BEGIN
select * from fzoa_inner_note where sender_id=@user_id and sender_del=0 order by sent_date desc
SET  @Rowcount=@@ROWCOUNT
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetAttachFilePathByRunId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_GetAttachFilePathByRunId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetAttachFilePathByRunId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_GetAttachFilePathByRunId] 
@run_id int
AS
select file_path from fzoa_flow_attach where run_id=@run_id
	/* SET NOCOUNT ON */ 
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetCreator]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_GetCreator]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_GetCreator]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_GetCreator]--获取流程创建者 
@run_id int
AS
select creator_id,creator_name from hyoa_flow_run where run_id=@run_id
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_NoteAll]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_NoteAll]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_NoteAll]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_NoteAll]
@user_id int
AS
BEGIN
update fzoa_inner_note set note_flag=1  where receiver_id=@user_id and note_flag=0 and receiver_del=0
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_NoteRead]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_NoteRead]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_NoteRead]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_NoteRead]
@InnerNoteId int
AS
BEGIN
update fzoa_inner_note set note_flag=1,read_flag=1 where inner_note_id=@InnerNoteId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_readAll]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_readAll]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_readAll]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_readAll]
@user_id int
AS
BEGIN
update fzoa_inner_note set read_flag=1  where receiver_id=@user_id and read_flag=0 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_readOne]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_readOne]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_readOne]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_readOne]
@innerNoteId int
AS
BEGIN
update fzoa_inner_note set  note_flag=1,read_flag=1 where inner_note_id=@innerNoteId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_UnreadCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_INote_UnreadCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_INote_UnreadCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_INote_UnreadCount]
@user_id int
AS
BEGIN
select count(inner_note_id) from fzoa_inner_note where receiver_id=@user_id and read_flag=0 and receiver_del=0
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetAllChild_Privilege]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_GetAllChild_Privilege]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetAllChild_Privilege]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--2012-10-14
--dcx
CREATE PROCEDURE [dbo].[DcxRun_Menu_GetAllChild_Privilege] --获取全部子菜单，和子菜单的子子菜单，考虑权限
@ParentId int ,
@UserId int 
AS
BEGIN
if @ParentId <1
	SELECT top 1 @ParentId=isnull([TopMenuId],0) FROM [Dcx_RuningSysParam]
if @ParentId<1
begin
	SELECT top 1 @ParentId=isnull([MenuId],0) from [Dcx_Menu_Run] where [ParentId]=0
	if @ParentId>0
		update [Dcx_RuningSysParam] set [TopMenuId]=@ParentId
end
if @ParentId<1
begin
	return 
end
declare @t table(
			[MenuId] int,
			[ParentId] int,
			[MenuName] varchar(100)   ,
			[ProPath] varchar(200)  ,
			[ImgPath] varchar(50)  ,
			[ExImgPath] varchar(50)  ,
			[OrderBy] int  ,
			[Target] varchar(50)  ,
			Level int
		)  
declare @Role table(RoleId int ) 
insert into @Role SELECT distinct [RoleId] FROM [Dcx_UserInRole] where [UserId]=@UserId
declare @i int   
set @i = 1    
declare @tmp int  
set @tmp=0 
--插入父菜单下的子菜单
while @i=1 or @tmp>0
begin   
	if @i=1
		 insert into @t SELECT a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.Target,@i  
		 from [Dcx_Menu_Run] a inner join [Dcx_MenuPrivilege] b on 
		 a.[MenuId]=b.[MenuId] and  b.[RoleId] in(select [RoleId] from @Role)  
		 where a.[ParentId] = @ParentId    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId] 
	else
		insert into @t SELECT a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.Target,@i  
		from  @t c   inner join [Dcx_Menu_Run] a on  c.Level = @i-1  and c.[MenuId]=a.[ParentId]  
		inner join  [Dcx_MenuPrivilege] b on a.[MenuId]=b.[MenuId]  and  b.[RoleId] in(select [RoleId] from @Role)  
		where ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId] 
	set @tmp=@@rowcount 
	set @i = @i + 1
end   
select * from @t
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetAllParentMenu_Simple]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_GetAllParentMenu_Simple]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetAllParentMenu_Simple]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Menu_GetAllParentMenu_Simple]
@MenuId int
AS
declare @ParentId int   
declare @SMenuId int   
declare @SystemId int   
declare @SSystemId int   
declare @table table(MenuId int,ParentId int,SMenuId int,SSystemId int,SystemId int)    
set  @ParentId= -1
select @SMenuId=[SMenuId],@SystemId=[SystemId],@SSystemId=[SSystemId],  @MenuId= [MenuId]  ,@ParentId=[ParentId] from [Dcx_Menu_Run]  where [MenuId] = @MenuId  
set @ParentId=isnull(@ParentId,-1)
while @ParentId>-1
begin 
	insert into @table (MenuId ,ParentId ,SMenuId ,SystemId  ,[SSystemId]) values(@MenuId ,@ParentId ,@SMenuId ,@SystemId,@SSystemId) 
	set  @MenuId=@ParentId
	set @ParentId=-1
	select @SMenuId=[SMenuId],@SystemId=[SystemId],@SSystemId=[SSystemId], @MenuId= [MenuId]  ,@ParentId=[ParentId] from [Dcx_Menu_Run]  where [MenuId] = @MenuId  
	set @ParentId=isnull(@ParentId,-1)
end   
select * from @table
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetChild_Privilege]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_GetChild_Privilege]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetChild_Privilege]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--2012-10-14
--2013-11-23
CREATE PROCEDURE [dbo].[DcxRun_Menu_GetChild_Privilege] --获取仅下一级的子菜单，考虑权限
@AccountId int ,
@ParentId int ,
@UserId int 
AS
BEGIN
--以下正确，暂时去掉，正式运行时恢复
--if @ParentId <1
--	SELECT top 1 @ParentId=isnull([TopMenuId],0) FROM [Dcx_RuningSysParam]
--if @ParentId<1
--begin
--	SELECT top 1 @ParentId=isnull([MenuId],0) from [Dcx_Menu_Run] where [ParentId]=0
--	if @ParentId>0
--		update [Dcx_RuningSysParam] set [TopMenuId]=@ParentId
--end
--if @ParentId<1
--begin
--	return 
--end
declare @Role table(RoleId int ) 
insert into @Role SELECT distinct [RoleId] FROM [Dcx_UserInRole] where [UserId]=@UserId
SELECT distinct a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.Target  
 from [Dcx_Menu_Run] a inner join [Dcx_MenuPrivilege] b on 
a.[MenuId]=b.[MenuId] and  b.[RoleId] in(select [RoleId] from @Role)  
 where a.[ParentId] = @ParentId    and (a.[AccountId]=@AccountId or a.[AccountId]=1) and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId] 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetTopMenu]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_GetTopMenu]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetTopMenu]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--2012-10-15
--2013-10-19
--dcx
CREATE PROCEDURE [dbo].[DcxRun_Menu_GetTopMenu] --设置顶级菜单Id
AS
BEGIN
declare @TopMenuId int 
declare @tmp int 
select top 1 @TopMenuId=[TopMenuId] from [Dcx_RuningSysParam]
if @TopMenuId is not null and @TopMenuId>-1
begin
	select @TopMenuId
	return
end
if @TopMenuId is null
INSERT INTO [Dcx_RuningSysParam]
           ([DefautStyleId]
           ,[SystemId]
           ,[TopMenuId]
           ,[SystemName]
           ,[HomePageMenuId])
     VALUES(1,1,-1,''系统名称'',-1)
--if @TopMenuId<1 or @TopMenuId is null
--begin
	if (SELECT count(1) from [Dcx_Menu_Run] where [ParentId]=0)>1
	begin
		set @TopMenuId=0
		update [Dcx_RuningSysParam] set [TopMenuId]=@TopMenuId
	end
	else
	begin
		SELECT top 1 @TopMenuId=[MenuId] from [Dcx_Menu_Run] where [ParentId]=0
		if @TopMenuId is  null or @TopMenuId<1
			SELECT top 1 @TopMenuId=A.[MenuId] from [Dcx_Menu_Run] as A where A.[ParentId] not in (SELECT distinct B.[MenuId] from [Dcx_Menu_Run] as B )
		update [Dcx_RuningSysParam] set [TopMenuId]=@TopMenuId
	end
	select isnull(@TopMenuId,-1)
--end
------select top 1 isnull([TopMenuId],-1)  from [Dcx_RuningSysParam]
----return 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetTopMenuIdByMenuId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_GetTopMenuIdByMenuId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetTopMenuIdByMenuId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--2013-4-23
--2013-10-19
--dcx
CREATE PROCEDURE [dbo].[DcxRun_Menu_GetTopMenuIdByMenuId] --设置顶级菜单Id
@MenuId int 
AS
BEGIN
declare @TopMenuId int 
declare @ParentId int 
declare @tmp int 
select top 1 @ParentId=[ParentId] from Dcx_Menu_Run where MenuId=@MenuId
--@MenuId不存在
if  @ParentId is  null
begin
	EXEC	 [dbo].[DcxRun_Menu_GetTopMenu]
return
end
set @tmp=@MenuId
declare @tmp2 int 
set @tmp2=0
while @ParentId is not null and @ParentId>0  and @tmp2<10
begin
if @MenuId=@ParentId 
	break
	set @MenuId=@ParentId
 set @tmp2=@tmp2+1
	set @ParentId=-1
	select top 1 @ParentId=[ParentId] from Dcx_Menu_Run where MenuId=@MenuId
end
--if  @ParentId is  null
--select @MenuId 
--else 
select @MenuId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetUnDesignedParentMenu]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_GetUnDesignedParentMenu]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_GetUnDesignedParentMenu]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Menu_GetUnDesignedParentMenu]
@MenuId int
AS
declare @ParentId int   
declare @SMenuId int   
declare @SSystemId int   
declare @SystemId int   
declare @IsDesigning int   
declare @table table(MenuId int,ParentId int,SMenuId int,SystemId int,SSystemId int,IsDesigning bit)    
set  @ParentId= -1 
select @SMenuId=[SMenuId],@SystemId=[SystemId],@SSystemId=[SSystemId], @MenuId= [MenuId]  ,@ParentId=[ParentId],@IsDesigning=[IsDesigning] from [Dcx_Menu_Run]  where [MenuId] = @MenuId  
set @ParentId=isnull(@ParentId,-1)
while @ParentId>-1  --and @SMenuId=@MenuId
begin 
	insert into @table (MenuId ,ParentId ,SMenuId ,SystemId,[IsDesigning] ,[SSystemId]) values(@MenuId ,@ParentId ,@SMenuId ,@SystemId,@IsDesigning,@SSystemId) 
	set  @MenuId=@ParentId
	set @ParentId=-1
	select @SMenuId=[SMenuId],@SystemId=[SystemId],@SSystemId=[SSystemId], @MenuId= [MenuId]  ,@ParentId=[ParentId],@IsDesigning=IsDesigning from [Dcx_Menu_Run]  where [MenuId] = @MenuId  
	set @ParentId=isnull(@ParentId,-1)
end   
select * from @table
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_SetTopMenu]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_SetTopMenu]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_SetTopMenu]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--2012-10-15
--dcx
CREATE PROCEDURE [dbo].[DcxRun_Menu_SetTopMenu] --设置顶级菜单Id
@ParentId int 
AS
BEGIN
declare @TopMenuId int 
declare @tmp int 
SELECT top 1 @tmp=count(*) FROM [Dcx_RuningSysParam]
if @tmp=0
INSERT INTO [Dcx_RuningSysParam]
           ([DefautStyleId]
           ,[SystemId]
           ,[TopMenuId]
           ,[SystemName]
           ,[HomePageMenuId])
     VALUES(1,1,-1,''系统名称'',-1)
if @ParentId<1
	SELECT top 1 @ParentId=isnull([MenuId],0) from [Dcx_Menu_Run] where [ParentId]=0
if @ParentId is  null or @ParentId<1
	SELECT top 1 @ParentId=A.[MenuId] from [Dcx_Menu_Run] as A where A.[ParentId] not in (SELECT distinct B.[MenuId] from [Dcx_Menu_Run] as B )
if @ParentId>0
	update [Dcx_RuningSysParam] set [TopMenuId]=@ParentId
select top 1 isnull([TopMenuId],-1)  from [Dcx_RuningSysParam]
return 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_UpdateCopyedApps]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_UpdateCopyedApps]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_UpdateCopyedApps]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Menu_UpdateCopyedApps]  --创建菜单，创建应用
@SystemId int,
@MenuId int,
@OldMenuId int ,
@UserId int,
@UserName varchar(40)
AS
begin
UPDATE [Dcx_Menu_Run] SET 
 [SSystemId] =@SystemId
,[SMenuId] = @MenuId
,[IsDesigning]=1
,[AddDcxTime]=getdate()
,[AddDcxUserName]=@UserName
,[AddDcxUserId]=@UserId
WHERE [MenuId]=@OldMenuId and ([IsDesigning] is null or [IsDesigning]=0)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_UpdateCopyedMenu]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_UpdateCopyedMenu]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_UpdateCopyedMenu]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Menu_UpdateCopyedMenu]  --创建菜单，创建应用
@SystemId int,
@MenuId int,
@OldMenuId int ,
@UserId int,
@UserName varchar(40)
AS
begin
UPDATE [Dcx_Menu_Run] SET 
 [SSystemId] =@SystemId
,[SMenuId] = @MenuId
,[IsDesigning]=1
,[AddDcxTime]=getdate()
,[AddDcxUserName]=@UserName
,[AddDcxUserId]=@UserId
WHERE [MenuId]=@OldMenuId and ([IsDesigning] is null or [IsDesigning]=0)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_UpdateCopyedMenus]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Menu_UpdateCopyedMenus]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Menu_UpdateCopyedMenus]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Menu_UpdateCopyedMenus]  --创建菜单，创建应用
@SystemId int,
@MenuId int,
@OldMenuId int ,
@UserId int,
@UserName varchar(40)
AS
begin
UPDATE [Dcx_Menu_Run] SET 
 [SSystemId] =@SystemId
,[SMenuId] = @MenuId
,[IsDesigning]=1
,[AddDcxTime]=getdate()
,[AddDcxUserName]=@UserName
,[AddDcxUserId]=@UserId
WHERE [MenuId]=@OldMenuId and ([IsDesigning] is null or [IsDesigning]=0)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_MessageR_GetList]
@IsFlow bit,
@IsOther bit,
@UserId int,
@EntId int,
@PageIndex int,
@PageSize int
--,@minRcvId int
AS
BEGIN 
		if @UserId is null or @UserId<1
			return 
		if @PageSize is null or @PageSize<1
			set @PageSize=10
		if @PageIndex is null or @PageIndex<1
			set @PageIndex=1
		declare @S int
		declare @E int
		set @S=(@PageIndex-1)*@PageSize
		set @E=(@PageIndex)*@PageSize
--		if @EntId is null or @EntId<1 
--		begin
--			if @IsFlow=1
--				 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [IsFlow]=1   and [IsTop]=0) AS MyTable where  dcx_rowid between @S and @E
--				 union 
--				 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=0 and [IsPublic]=1  and [IsFlow]=1   and [IsTop]=0) AS MyTable where  dcx_rowid between @S and @E
--			else if @IsOther=1 
--				 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [IsFlow]!=1   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--				 union 
--				 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=0 and [IsPublic]=1   and [IsFlow]!=1   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--			else 
--				 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--				 union 
--				 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=0 and [IsPublic]=1 and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--		end
--		else
--		begin
--			 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--			 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and  [EntId]=@EntId   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--			 union
--			 select *  from (select row_number() over( order by ReceiverId asc,[MsgId] desc)as dcx_rowid,*
--			 from Dcx_MessageReceiver  where [ReceiverId]=0 and [IsPublic]=1 and  [EntId]=@EntId   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--		end
 		if @EntId is null or @EntId<1 
		begin
			if @IsFlow=1
				 select *  from (select row_number() over( order by [MsgId] desc)as dcx_rowid,*
				 from Dcx_MessageReceiver  where ([ReceiverId]=@UserId or ([ReceiverId]=0 and [IsPublic]=1 )) and [IsFlow]=1   and [IsTop]=0) AS MyTable where  dcx_rowid between @S and @E 
			union 
				 select *  from (select row_number() over( order by [MsgId] desc)as dcx_rowid,*
				 from Dcx_MessageReceiver  where ([ReceiverId]=@UserId or ([ReceiverId]=0 and [IsPublic]=1 )) and [IsFlow]=1   and [IsTop]=0) AS MyTable where  dcx_rowid between @S and @E 
			else if @IsOther=1 
				 select *  from (select row_number() over( order by [MsgId] desc)as dcx_rowid,*
				 from Dcx_MessageReceiver  where ([ReceiverId]=@UserId or ([ReceiverId]=0 and [IsPublic]=1 ))  and [IsFlow]!=1   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
			else 
				 select *  from (select row_number() over( order by [MsgId] desc)as dcx_rowid,*
				 from Dcx_MessageReceiver  where ([ReceiverId]=@UserId or ([ReceiverId]=0 and [IsPublic]=1 ))   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
		end
		else
		begin
			 select *  from (select row_number() over( order by [MsgId] desc)as dcx_rowid,*
			 from Dcx_MessageReceiver  where ([ReceiverId]=@UserId or ([ReceiverId]=0 and [IsPublic]=1 )) and  [EntId]=@EntId   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
		end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetMsgCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_GetMsgCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetMsgCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_MessageR_GetMsgCount]
@IsFlow bit,
@IsOther bit,
@UserId int,
@EntId int
AS
BEGIN 
--如果是第一分页，获取总记录数
	if @EntId is null or @EntId<1 
	begin
		if @IsFlow=1
			 select count(1)  from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [IsFlow]=1   
		else if @IsOther=1 
			 select count(1)
			 from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [IsFlow]!=1   
		else 
			 select count(1)
			 from Dcx_MessageReceiver  where [ReceiverId]=@UserId 
	end
	else
	begin
		 select count(1)
		 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and  [EntId]=@EntId 
	end
--if @UserId is null or @UserId<1
--return 
--if @PageSize is null or @PageSize<1
--set @PageSize=10
--if @PageIndex is null or @PageIndex<1
--set @PageIndex=1
--declare @S int
--declare @E int
--set @S=(@PageIndex-1)*@PageSize
--set @E=(@PageIndex)*@PageSize
----if @minRcvId is null or @minRcvId<1 
----begin
--		if @EntId is null or @EntId<1 
--		begin
--			if @IsFlow=1
--				 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [IsFlow]=1   and [IsTop]=0) AS MyTable where  dcx_rowid between @S and @E
--			else if @IsOther=1 
--				 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [IsFlow]!=1   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--			else 
--				 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
--				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--		end
--		else
--		begin
--			 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
--			 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and  [EntId]=@EntId   and [IsTop]=0 ) AS MyTable where  dcx_rowid between @S and @E
--		end
----end
----else 
----begin
----		if @EntId is null or @EntId<1 
----		begin
----			if @IsFlow=1
----				 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
----				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [RcvId]>@minRcvId and [IsFlow]=1 ) AS MyTable where  dcx_rowid between @S and @E
----			else if @IsOther=1 
----				 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
----				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [RcvId]>@minRcvId and [IsFlow]!=1  ) AS MyTable where  dcx_rowid between @S and @E
----			else 
----				 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
----				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [RcvId]>@minRcvId ) AS MyTable where  dcx_rowid between @S and @E
----		end
----		else
----		begin
----			 select *  from (select row_number() over( order by ReceiverId asc,RcvId desc)as dcx_rowid,*
----			 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and  [EntId]=@EntId and [RcvId]>@minRcvId  ) AS MyTable where  dcx_rowid between @S and @E
----		end
----end
------如果是第一分页，获取总记录数
----if @PageIndex<2
----begin
----		if @EntId is null or @EntId<1 
----		begin
----			if @IsFlow=1
----				 select count(1)  from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [IsFlow]=1   
----			else if @IsOther=1 
----				 select count(1)
----				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [IsFlow]!=1   
----			else 
----				 select count(1)
----				 from Dcx_MessageReceiver  where [ReceiverId]=@UserId 
----		end
----		else
----		begin
----			 select count(1)
----			 from Dcx_MessageReceiver  where [ReceiverId]=@UserId and  [EntId]=@EntId 
----		end
----end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetMsgForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_GetMsgForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetMsgForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--当加载任何一个消息类别时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_MessageR_GetMsgForFirstTime]
@IsFlow2 bit,
@IsOther2 bit,
@UserId2 int,
@EntId2 int,
@PageIndex2 int,
@PageSize2 int
AS
BEGIN 
EXEC	[DcxRun_MessageR_GetList]
		@IsFlow = @IsFlow2,@IsOther = @IsOther2,@UserId = @UserId2,@EntId = @EntId2,
@PageIndex = @PageIndex2,@PageSize = @PageSize2
EXEC	[DcxRun_MessageR_GetTopMsg]
		@IsFlow = @IsFlow2,@IsOther = @IsOther2,@UserId = @UserId2,@EntId = @EntId2
EXEC	[DcxRun_MessageR_GetMsgCount]
		@IsFlow = @IsFlow2,@IsOther = @IsOther2,@UserId = @UserId2,@EntId = @EntId2
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetNewCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_GetNewCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetNewCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_MessageR_GetNewCount]
@IsFlow bit,
@IsOther bit,
@UserId int,
@EntId int,
@MinMsgId int --最底的一个消息
AS
BEGIN 
if @UserId is null or @UserId<1
return 
if @MinMsgId is null 
set @MinMsgId=0 
if @MinMsgId is null or @MinMsgId<1 
begin
		if @EntId is null or @EntId<1 
		begin
			if @IsFlow=1
				 select count(1) from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [IsFlow]=1 and [IsTop]=0
			else if @IsOther=1 
				 select count(1) from Dcx_MessageReceiver  where [ReceiverId]=@UserId  and [IsFlow]!=1 and [IsTop]=0
			else 
				 select count(1) from Dcx_MessageReceiver  where [ReceiverId]=@UserId and [IsTop]=0
		end
		else
		begin
			 select count(1) from Dcx_MessageReceiver  where [ReceiverId]=@UserId and  [EntId]=@EntId   and [IsTop]=0
		end
end
else 
begin
		if @EntId is null or @EntId<1 
		begin
			if @IsFlow=1
				 select count(1) from Dcx_MessageReceiver  where  [ReceiverId]=@UserId and [MsgId]>@MinMsgId and [IsFlow]=1 and [IsTop]=0
			else if @IsOther=1 
				 select count(1) from Dcx_MessageReceiver  where   [ReceiverId]=@UserId  and [MsgId]>@MinMsgId and [IsFlow]!=1  and [IsTop]=0
			else 
				 select count(1) from Dcx_MessageReceiver  where   [ReceiverId]=@UserId  and [MsgId]>@MinMsgId   and [IsTop]=0
		end
		else
		begin
			 select count(1) from Dcx_MessageReceiver  where   [ReceiverId]=@UserId and  [EntId]=@EntId and [MsgId]>@MinMsgId   and [IsTop]=0
		end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetObjBrowse]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_GetObjBrowse]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetObjBrowse]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取和消息相关的数据
CREATE PROCEDURE [dbo].[DcxRun_MessageR_GetObjBrowse]
(
@entId int,
@userId int,
@msgId int,
@keyId int
)
AS
begin
if @entId=2071
begin
	SELECT [RcvId],[MId] as [MsgId],[Title],[MsgContent],[FileJson],[TagId] FROM [Dcx_WMailRcv] 
	where [ReceiverId]=@userId and  [MId]=@keyId 
	update [Dcx_WMailRcv] set [IsRead]=1,ReadTime=getdate() where [ReceiverId]=@userId and  [MId]=@keyId 
end
else if @entId=2076
begin
	SELECT [RcvId],[LId] as [MsgId],'''' as [Title],[MsgContent],[FileJson],[TagId] FROM [Dcx_WLetterRcv] 
	where [ReceiverId]=@userId and  [LId]=@keyId 
	update [Dcx_WLetterRcv] set [IsRead]=1,ReadTime=getdate() where [ReceiverId]=@userId and  [LId]=@keyId 
end
else if @entId=1
begin
	SELECT 0 as [RcvId],[WId] as [MsgId],'''' as [Title],[MsgContent],[FileJson],[TagId] FROM [Dcx_WeiBo] 
	where [CreatorId]=@userId and  [WId]=@keyId 
--	update [Dcx_WeiBo] set [IsRead]=1,ReadTime=getdate() where [CreatorId]=@userId and  [WId]=@keyId 
end
else if @entId=2 --通知公告
begin
	SELECT 0 as [RcvId],[NId] as [MsgId],'''' as [Title],[NewsContent] as [MsgContent],[FileJson],[TagId] FROM [Dcx_News] 
	where [CreatorId]=@userId and  [NId]=@keyId 
--	update [Dcx_News] set [IsRead]=1,ReadTime=getdate() where [CreatorId]=@userId and  [NId]=@keyId 
end
	update [Dcx_MessageReceiver] set [IsRead]=1,ReadTime=getdate() where [ReceiverId]=@userId and  [MsgId]=@msgId 
end' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetTopMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_GetTopMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_GetTopMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_MessageR_GetTopMsg]
@IsFlow bit,
@IsOther bit,
@UserId int,
@EntId int
AS
BEGIN 
if @UserId is null or @UserId<1
return 
if @EntId is null or @EntId<1 
begin
	if @IsFlow=1
		 select 1 as dcx_rowid,*  from Dcx_MessageReceiver where [ReceiverId]=@UserId and [IsFlow]=1   and [IsTop]=1
	else if @IsOther=1 
		 select 1 as dcx_rowid,*  from Dcx_MessageReceiver where [ReceiverId]=@UserId and [IsFlow]!=1  and [IsTop]=1
	else 
		 select 1 as dcx_rowid,*  from Dcx_MessageReceiver where [ReceiverId]=@UserId  and [IsTop]=1
end
else
begin
		 select 1 as dcx_rowid,*  from Dcx_MessageReceiver where [ReceiverId]=@UserId and  [EntId]=@EntId  and [IsTop]=1
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_SetProcessed]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_SetProcessed]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_SetProcessed]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_MessageR_SetProcessed]
 @UserId int,
@MsgId int --最底的一个消息
AS
BEGIN 
set nocount on
if @UserId is null or @UserId<1
return 
if @MsgId is null or @MsgId<1
return 
UPDATE[Dcx_MessageReceiver] SET [ProcessTime] =getdate(), [IsProcessed]=1
 WHERE [ReceiverId]=@UserId and [MsgId]=@MsgId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_SetProcessedByPrcsId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_MessageR_SetProcessedByPrcsId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_MessageR_SetProcessedByPrcsId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_MessageR_SetProcessedByPrcsId]
 @UserId int,
@PrcsId int --最底的一个消息
AS
BEGIN 
set nocount on
if @UserId is null or @UserId<1
return 
if @PrcsId is null or @PrcsId<1
return 
UPDATE[Dcx_MessageReceiver] SET [ProcessTime] =getdate(), [IsProcessed]=1
 WHERE [ReceiverId]=@UserId and [PrcsId]=@PrcsId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_News_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_News_Delete](@userId int, @nId int)
as
begin
--set nocount on
		delete from [Dcx_News] WHERE 12=12  and [NId]=@nId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_News_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_News_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate 
							and [CreateDate]<@toDate and 12=12   
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate  and 12=12  
				end
				else 
				begin
							select count(1)  from [Dcx_News]  where  [CreateDate]<@toDate and 12=12  
				end
		end
		else
		begin
				select count(1)  from [Dcx_News]  where  12=12  
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate 
							and [CreateDate]<@toDate and 12=12    and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate  and 12=12   and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_News]  where  [CreateDate]<@toDate and 12=12   and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_News]  where  12=12   and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_News_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_News_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_News_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_News_GetTopNews]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_News_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_News_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_News_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate 
	--							and [CreateDate]<@toDate and 12=12   
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate  and 12=12  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate  and 12=12  
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]<@toDate and 12=12 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_News]  where  [CreateDate]<@toDate and 12=12  
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
--						where 12=12  
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--					if @pageIndex<=1
	--						select count(1)  from [Dcx_News]  where   12=12  
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12
					end
					else if @toDate is  null 
					begin
								select   top 200 [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate  and 12=12
					end
					else 
					begin
								select   top 200 [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]<@toDate and 12=12
					end
			end
			else
			begin
								select  top 200  [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
--								where 12=12  
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate 
	--							and [CreateDate]<@toDate and 12=12    and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate  and 12=12  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_News]  where  [CreateDate]>@fromDate  and 12=12   and [TagId]=@tagId
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]<@toDate and 12=12 and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_News]  where  [CreateDate]<@toDate and 12=12   and [TagId]=@tagId
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [CreateDate] desc)as dcx_rowid, [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
						where 12=12   and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--					if @pageIndex<=1
	--						select count(1)  from [Dcx_News]  where   12=12   and [TagId]=@tagId
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]>@fromDate  and 12=12  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where [CreateDate]<@toDate and 12=12  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  [NId],[Title],[TypeId],[TagId],[TagName],[NewsContent],[IsPublic],[CreateDate],[CreatorName],[CreatorId],[FileJson],[ReadTimes]  FROM [Dcx_News]  
								where 12=12   and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetTopNews]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_News_GetTopNews]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_News_GetTopNews]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_News_GetTopNews]
@tagId int,
@userId int
AS
BEGIN 
select -1
	return 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_News where 12=12   
else
	 select 1 as dcx_rowid,*  from Dcx_News where 12=12   and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Remind_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Remind_Delete]
( 
	@rmId int,
	@userId int
)
AS
begin
 delete FROM  [Dcx_Remind] where  [CreatorId]=@userId and [RmId]=@rmId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_DeleteAll]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Remind_DeleteAll]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_DeleteAll]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Remind_DeleteAll]
( 
	@userId int
)
AS
begin
 delete FROM  [Dcx_Remind] where  [CreatorId]=@userId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_GetById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Remind_GetById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_GetById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--根据提醒Id查找我的提醒信息
CREATE PROCEDURE [dbo].[DcxRun_Remind_GetById]
@rmId int, 
@userId int
AS
SELECT  * FROM  [Dcx_Remind] where 	
 [RmId]=@rmId and [CreatorId]=@userId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_GetByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Remind_GetByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_GetByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[DcxRun_Remind_GetByUserId]
@RemindDate DateTime,
@StaffId varchar(16)
 AS
   SELECT oa_Remind.Subject, oa_Remind.SchId,oa_Remind.RemindDate
   FROM oa_schedMsg INNER JOIN
   oa_Remind ON oa_schedMsg.SchId = oa_Remind.SchId
   where
/*
预约他人
*/
--不重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 0 and 
oa_Remind.RemindDate  between  @RemindDate  and  DATEADD (day,1,@RemindDate))
or
--每日重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 0 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate)
or
--每周重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 1 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and (convert(int,@RemindDate - oa_Remind.RemindDate))%7=0)
or
--每月重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 2 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and DAY(@RemindDate) = DAY(oa_Remind.RemindDate))
or
--每年重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 3 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and DAY(@RemindDate) = DAY(oa_Remind.RemindDate) and MONTH(@RemindDate) = MONTH(oa_Remind.RemindDate))
or
--隔周重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 4 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate  and  (convert(int,@RemindDate - oa_Remind.RemindDate))%14=0)
or
--隔月重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 5 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and DAY(@RemindDate) = DAY(oa_Remind.RemindDate) and (MONTH(@RemindDate) - MONTH(oa_Remind.RemindDate))%2=0)
union
/*
提醒信息
*/
select oa_Remind.Subject,oa_Remind.SchId,oa_Remind.RemindDate
from 
oa_Remind
where
--不重复显示
(oa_Remind.StaffId=@StaffId  and oa_Remind.RepeatFlag = 0 and 
oa_Remind.RemindDate between  @RemindDate  and  DATEADD (day,1,@RemindDate) and oa_Remind.RemindDate <>DATEADD(day,1,@RemindDate))
or
--每日重复显示
(oa_Remind.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 0 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate)
or
--每周重复显示
(oa_Remind.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 1 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and (convert(int,@RemindDate - oa_Remind.RemindDate))%7=0)
or
--每月重复显示
(oa_Remind.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 2 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and DAY(@RemindDate) = DAY(oa_Remind.RemindDate))
or
--每年重复显示
(oa_Remind.StaffId=@StaffId   and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 3 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and DAY(@RemindDate) = DAY(oa_Remind.RemindDate) and MONTH(@RemindDate) = MONTH(oa_Remind.RemindDate))
or
--隔周重复显示
(oa_Remind.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 4 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate  and  (convert(int,@RemindDate - oa_Remind.RemindDate))%14=0)
or
--隔月重复显示
(oa_Remind.StaffId=@StaffId  and oa_Remind.RepeatFlag = 1 and oa_Remind.RequenCate = 5 and
@RemindDate  between oa_Remind.RemindDate  and  oa_Remind.UpToDate and DAY(@RemindDate) = DAY(oa_Remind.RemindDate) and (MONTH(@RemindDate) - MONTH(oa_Remind.RemindDate))%2=0)
order by oa_Remind.RemindDate
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Remind_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Remind_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--按月，周，日三个模式查询提醒
CREATE PROCEDURE [dbo].[DcxRun_Remind_GetList]
( 
	@userId int, 
	@fromDate datetime,
	@toDate datetime, 
	@modeType int
)
AS
begin
				declare @week int
				declare @isWorkDay bit
				declare @beginDay int
				declare @beginMonth int
				declare @endDay int
				declare @endMonth int
				set datefirst 1
				set @week=datepart(weekday,@fromDate)
				if @week<6
					set @isWorkDay=1
				else
					set @isWorkDay=0
				set @beginDay=day(@fromDate)
				set @beginMonth=month(@fromDate)
				set @endDay=day(@toDate)
				set @endMonth=month(@toDate)
				if  @modeType=1 --月   --0，不重复；1，每天；2，每个工作日；4，每周；5，每月；6，每年。
				begin
						SELECT  top 200 [RmId] ,[RmContent],[TypeId],[RepeatType],[RemindDate]  FROM  [Dcx_Remind] 
						where [CreatorId]=@userId and   [RemindDate]<=@toDate and(RepeatType!=0 or [RemindDate]>=@fromDate)
				end
				else if @modeType=2 --周
				begin
						declare @isSameMonth bit --是否同一月
						if @beginMonth!=@endMonth 
							set @isSameMonth=0
						else
							set @isSameMonth=1
						--0，不重复；1，每天；2，每个工作日；4，每周；5，每月；6，每年。
						SELECT  top 200 [RmId] ,[RmContent],[TypeId],[RepeatType],[RemindDate]  FROM  [Dcx_Remind] 
						where  [CreatorId]=@userId and   [RemindDate]<=@toDate and
						(  (RepeatType=0 and [RemindDate]>=@fromDate ) 
						or (RepeatType=1 or RepeatType=2 or RepeatType=4)
						or (RepeatType=5 and ((@isSameMonth=1 and  @beginDay<=day([RemindDate]) and @endDay>=day([RemindDate])) or 
											  (@isSameMonth=0 and (@beginDay>=day([RemindDate]) or  @endDay>=day([RemindDate])))))
						or (RepeatType=6 and 
						(((day([RemindDate])>=@beginDay and  month([RemindDate])=@beginMonth ) or  month([RemindDate])>@beginMonth) and 
						((day([RemindDate])<=@endDay and  month([RemindDate])=@endMonth ) or  month([RemindDate])<@endMonth))))
				end
				else --日
				begin
						--0，不重复；1，每天；2，每个工作日；4，每周；5，每月；6，每年。
						SELECT  top 200 [RmId] ,[RmContent],[TypeId],[RepeatType],[RemindDate]  FROM  [Dcx_Remind] 
						where  [CreatorId]=@userId  and [RemindDate]<=@toDate and
						(  (RepeatType=0 and [RemindDate]>=@fromDate) 
						or (RepeatType=1)
						or (RepeatType=2 and @isWorkDay=1)
						or (RepeatType=4 and @week=datepart(weekday,@fromDate))
						or (RepeatType=5 and day([RemindDate])=@beginDay)
						or (RepeatType=6 and day([RemindDate])=@beginDay and  month([RemindDate])=@beginMonth ))
		end 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_RuningSysParam_SetSystemKey]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_RuningSysParam_SetSystemKey]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_RuningSysParam_SetSystemKey]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_RuningSysParam_SetSystemKey] --设置系统密钥
@SystemKey varchar(50)
AS
BEGIN
if (select count(*) from Dcx_RuningSysParam )<1 
begin
	declare @TopMenuId int 
	SELECT top 1 @TopMenuId=[MenuId] from [Dcx_Menu_Run] where [ParentId]=0
	if @TopMenuId is  null or @TopMenuId<1
		SELECT top 1 @TopMenuId=A.[MenuId] from [Dcx_Menu_Run] as A where A.[ParentId] not in (SELECT distinct B.[MenuId] from [Dcx_Menu_Run] as B )
	set @TopMenuId=isnull(@TopMenuId,-1)
	INSERT INTO [Dcx_RuningSysParam]
			   ([DefautStyleId]
			   ,[SystemId]
			   ,[TopMenuId]
			   ,[SystemName]
			   ,[HomePageMenuId],[SystemKey])
	VALUES(1,1,@TopMenuId,''系统名称'',-1,@SystemKey)
end
else
	update [Dcx_RuningSysParam] set [SystemKey]=@SystemKey  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Schedule_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Schedule_Delete]
( 
	@sId int,
	@userId int
)
AS
begin
 delete FROM  [Dcx_Schedule] where  [CreatorId]=@userId and [SId]=@sId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_DeleteAll]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Schedule_DeleteAll]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_DeleteAll]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_Schedule_DeleteAll]
( 
	@userId int
)
AS
begin
 delete FROM  [Dcx_Schedule] where  [CreatorId]=@userId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_GetById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Schedule_GetById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_GetById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--根据日程Id查找我的日程信息
CREATE PROCEDURE [dbo].[DcxRun_Schedule_GetById]
@sId int, 
@userId int
AS
SELECT  * FROM  [Dcx_Schedule] where 	
 [SId]=@sId and [CreatorId]=@userId
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_GetByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Schedule_GetByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_GetByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[DcxRun_Schedule_GetByUserId]
@StartTime DateTime,
@StaffId varchar(16)
 AS
   SELECT oa_schedule.Subject, oa_schedule.SchId,oa_schedule.StartTime
   FROM oa_schedMsg INNER JOIN
   oa_schedule ON oa_schedMsg.SchId = oa_schedule.SchId
   where
/*
预约他人
*/
--不重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 0 and 
oa_schedule.StartTime  between  @StartTime  and  DATEADD (day,1,@StartTime))
or
--每日重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 0 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate)
or
--每周重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 1 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and (convert(int,@StartTime - oa_schedule.StartTime))%7=0)
or
--每月重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 2 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and DAY(@StartTime) = DAY(oa_schedule.StartTime))
or
--每年重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 3 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and DAY(@StartTime) = DAY(oa_schedule.StartTime) and MONTH(@StartTime) = MONTH(oa_schedule.StartTime))
or
--隔周重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 4 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate  and  (convert(int,@StartTime - oa_schedule.StartTime))%14=0)
or
--隔月重复显示
(oa_schedMsg.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 5 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and DAY(@StartTime) = DAY(oa_schedule.StartTime) and (MONTH(@StartTime) - MONTH(oa_schedule.StartTime))%2=0)
union
/*
日程信息
*/
select oa_schedule.Subject,oa_schedule.SchId,oa_schedule.StartTime
from 
oa_schedule
where
--不重复显示
(oa_schedule.StaffId=@StaffId  and oa_schedule.RepeatFlag = 0 and 
oa_schedule.StartTime between  @StartTime  and  DATEADD (day,1,@StartTime) and oa_schedule.StartTime <>DATEADD(day,1,@StartTime))
or
--每日重复显示
(oa_schedule.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 0 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate)
or
--每周重复显示
(oa_schedule.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 1 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and (convert(int,@StartTime - oa_schedule.StartTime))%7=0)
or
--每月重复显示
(oa_schedule.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 2 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and DAY(@StartTime) = DAY(oa_schedule.StartTime))
or
--每年重复显示
(oa_schedule.StaffId=@StaffId   and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 3 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and DAY(@StartTime) = DAY(oa_schedule.StartTime) and MONTH(@StartTime) = MONTH(oa_schedule.StartTime))
or
--隔周重复显示
(oa_schedule.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 4 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate  and  (convert(int,@StartTime - oa_schedule.StartTime))%14=0)
or
--隔月重复显示
(oa_schedule.StaffId=@StaffId  and oa_schedule.RepeatFlag = 1 and oa_schedule.RequenCate = 5 and
@StartTime  between oa_schedule.StartTime  and  oa_schedule.UpToDate and DAY(@StartTime) = DAY(oa_schedule.StartTime) and (MONTH(@StartTime) - MONTH(oa_schedule.StartTime))%2=0)
order by oa_schedule.StartTime
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Schedule_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--按月，周，日三个模式查询日程
CREATE PROCEDURE [dbo].[DcxRun_Schedule_GetList]
( 
	@userId int, 
	@fromDate datetime,
	@toDate datetime, 
	@modeType int
)
AS
begin
				declare @week int
				declare @isWorkDay bit
				declare @beginDay int
				declare @beginMonth int
				declare @endDay int
				declare @endMonth int
				set datefirst 1
				set @week=datepart(weekday,@fromDate)
				if @week<6
					set @isWorkDay=1
				else
					set @isWorkDay=0
				set @beginDay=day(@fromDate)
				set @beginMonth=month(@fromDate)
				set @endDay=day(@toDate)
				set @endMonth=month(@toDate)
				if  @modeType=1 --月   --0，不重复；1，每天；2，每个工作日；4，每周；5，每月；6，每年。
				begin
						SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
						where [CreatorId]=@userId and   [StartTime]<=@toDate and(RepeatType!=0 or [StartTime]>=@fromDate)
				end
				else if @modeType=2 --周
				begin
						declare @isSameMonth bit --是否同一月
						if @beginMonth!=@endMonth 
							set @isSameMonth=0
						else
							set @isSameMonth=1
						--0，不重复；1，每天；2，每个工作日；4，每周；5，每月；6，每年。
						SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
						where  [CreatorId]=@userId and   [StartTime]<=@toDate and
						(  (RepeatType=0 and [StartTime]>=@fromDate ) 
						or (RepeatType=1 or RepeatType=2 or RepeatType=4)
						or (RepeatType=5 and ((@isSameMonth=1 and  @beginDay<=day([StartTime]) and @endDay>=day([StartTime])) or 
											  (@isSameMonth=0 and (@beginDay>=day([StartTime]) or  @endDay>=day([StartTime])))))
						or (RepeatType=6 and 
						(((day([StartTime])>=@beginDay and  month([StartTime])=@beginMonth ) or  month([StartTime])>@beginMonth) and 
						((day([StartTime])<=@endDay and  month([StartTime])=@endMonth ) or  month([StartTime])<@endMonth))))
				end
				else --日
				begin
						--0，不重复；1，每天；2，每个工作日；4，每周；5，每月；6，每年。
--						SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
--						where (RepeatType!=0 or ([StartTime]>=@fromDate and [StartTime]<=@toDate )) and [CreatorId]=@userId
						SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
						where  [CreatorId]=@userId  and [StartTime]<=@toDate and
						(  (RepeatType=0 and [StartTime]>=@fromDate) 
						or (RepeatType=1)
						or (RepeatType=2 and @isWorkDay=1)
						or (RepeatType=4 and @week=datepart(weekday,@fromDate))
						or (RepeatType=5 and day([StartTime])=@beginDay)
						or (RepeatType=6 and day([StartTime])=@beginDay and  month([StartTime])=@beginMonth ))
		end 
--		if @fromDate is not null  or @toDate is not null 
--		begin
--				if @fromDate is not null  and @toDate is not null 
--				begin
--						
--							SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
--							where ([StartTime]>=@fromDate and [StartTime]<=@toDate ) and [CreatorId]=@userId
--						
--				end
--				else if @toDate is  null 
--				begin
--						
--							SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
--							where [StartTime]>@fromDate  and [CreatorId]=@userId
--							  
--						
--				end
--				else 
--				begin
--						
--							SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule]  
--							where [StartTime]<@toDate and  [CreatorId]=@userId
--						
--				end
--		end
--		else
--		begin
--				  
--							SELECT  top 200 [SId] ,[Title],[TypeId],[RepeatType],[StartTime],[EndTime],[Address] ,[IsAllDay] FROM  [Dcx_Schedule] 
--							where [CreatorId]=@userId
--				  
--		 end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_Update]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_Schedule_Update]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_Schedule_Update]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--更新日程安排信息
CREATE PROCEDURE [dbo].[DcxRun_Schedule_Update]
	@schid int,
	@staffid varchar(16),
    @creatorid varchar(16),
	@subject varchar(64),
	@schType varchar(20),
	@place varchar(20),
	@content text,
	@privflag bit,
	@repeatflag bit,
	@requencate smallint,
	@uptodate datetime,
	@remindflag bit,
	@remindday smallint,
	@startdate datetime,
	@enddate datetime
 AS
--	update oa_schedule set Subject=@subject,SchType=@schtype,Place=@place,
--		Content=@content,PrivFlag=@privflag,RepeatFlag=@repeatflag,RequenCate=@requencate,
--		UpToDate=@uptodate,RemindFlag=@remindflag,RemindDay=@remindday,StartTime=@startdate,EndTime=@enddate
--	where schid=@schid
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_SetRuningSysParam]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_SetRuningSysParam]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_SetRuningSysParam]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_SetRuningSysParam] --设置系统密钥
@SystemName varchar(150),
@CompanyName varchar(150),
@DcxUserName varchar(150),
@SystemKey varchar(150),
@RegisterCode varchar(500)
AS
BEGIN
if (select count(*) from Dcx_RuningSysParam )<1 
begin
	declare @TopMenuId int 
	SELECT top 1 @TopMenuId=[MenuId] from [Dcx_Menu_Run] where [ParentId]=0
	if @TopMenuId is  null or @TopMenuId<1
		SELECT top 1 @TopMenuId=A.[MenuId] from [Dcx_Menu_Run] as A where A.[ParentId] not in (SELECT distinct B.[MenuId] from [Dcx_Menu_Run] as B )
	set @TopMenuId=isnull(@TopMenuId,-1)
	INSERT INTO [Dcx_RuningSysParam]
			   ([DefautStyleId]
			   ,[SystemId]
			   ,[TopMenuId]
			   ,[SystemName]
			   ,[HomePageMenuId],[SystemKey],[CompanyName],[DcxUserName],[RegisterCode],EditTime,
InstallDate)
	VALUES(1,1,@TopMenuId,@SystemName,-1,@SystemKey,@CompanyName,@DcxUserName,@RegisterCode
,getdate(),getdate())
end 
else
	update [Dcx_RuningSysParam] set [SystemName]=@SystemName,[CompanyName]=@CompanyName,
[DcxUserName]=@DcxUserName,[SystemKey]=@SystemKey,[RegisterCode]=@RegisterCode  ,
EditTime=getdate() ,
InstallDate=getdate()
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_GetDcxUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_User_GetDcxUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_GetDcxUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_User_GetDcxUserName] --获取用户在dcxCreator上的用户名
@UserId int 
AS
BEGIN
SELECT top 1 DcxUserName FROM [Dcx_User]  where  [UserId]=@UserId  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_GetUserMainMsgById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_User_GetUserMainMsgById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_GetUserMainMsgById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--根据类别和Id，获取用户
CREATE PROCEDURE [dbo].[DcxRun_User_GetUserMainMsgById] 
@accountId int,
@id int,
@qType int  --1，按用户；2，按部门；3，按职位；4，按角色；5，全部用户
AS
BEGIN
if @qType=2 --按部门
SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User] where ([Dcx_User].[AccountId]=@accountId) and [DeptId]=@id
else if @qType=3 --按职位
SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User] where  ([Dcx_User].[AccountId]=@accountId) and [PositionId]=@id
else if @qType=4 --按角色
SELECT distinct [Dcx_User].[UserId],[Dcx_User].[UserName],0 as [DeptId],[RealName] FROM [Dcx_User] inner join 
 [Dcx_UserInRole] on [Dcx_UserInRole].[UserId]=[Dcx_UserInRole].[UserId] where  ([Dcx_User].[AccountId]=@accountId) and [Dcx_UserInRole].[RoleId]=@id
else if @qType=5
SELECT [UserId],[UserName],[UserName] as [RealName],0 as [DeptId],0 as [PositionId],0 as [SuperAdmin] FROM [Dcx_LinkMan] where  GroupId=@id order by [UserName] --[CreatorId]=3 and 1=1 and
--else if @qType=6 --菜单
--SELECT [UserId],[UserName],[UserName] as [RealName],0 as [DeptId],0 as [PositionId],0 as [SuperAdmin] FROM [Dcx_LinkMan] where  GroupId=@id order by [UserName] --[CreatorId]=3 and 1=1 and
else
SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User]   where  [Dcx_User].[AccountId]=@accountId
--if @qType=2 --按部门
--SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User] where ([Dcx_User].[AccountId]=@accountId   or    [Dcx_User].[AccountId]=1) and [DeptId]=@id
--else if @qType=3 --按职位
--SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User] where  ([Dcx_User].[AccountId]=@accountId   or    [Dcx_User].[AccountId]=1) and [PositionId]=@id
--else if @qType=4 --按角色
--SELECT distinct [Dcx_User].[UserId],[Dcx_User].[UserName],0 as [DeptId],[RealName] FROM [Dcx_User] inner join 
-- [Dcx_UserInRole] on [Dcx_UserInRole].[UserId]=[Dcx_UserInRole].[UserId] where  ([Dcx_User].[AccountId]=@accountId   or    [Dcx_User].[AccountId]=1) and [Dcx_UserInRole].[RoleId]=@id
--else if @qType=5
--SELECT [UserId],[UserName],[UserName] as [RealName],0 as [DeptId],0 as [PositionId],0 as [SuperAdmin] FROM [Dcx_LinkMan] where  ([Dcx_LinkMan].[AccountId]=@accountId   or    [Dcx_LinkMan].[AccountId]=1) and  GroupId=@id order by [UserName] --[CreatorId]=3 and 1=1 and
----else if @qType=6 --菜单
----SELECT [UserId],[UserName],[UserName] as [RealName],0 as [DeptId],0 as [PositionId],0 as [SuperAdmin] FROM [Dcx_LinkMan] where  GroupId=@id order by [UserName] --[CreatorId]=3 and 1=1 and
--else
--SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User]   where  ([Dcx_User].[AccountId]=@accountId   or    [Dcx_User].[AccountId]=1)
--
--if @qType=2 --按部门
--SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User] where [DeptId]=@id
--else if @qType=3 --按职位
--SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User] where [PositionId]=@id
--else if @qType=4 --按角色
--SELECT distinct [Dcx_User].[UserId],[Dcx_User].[UserName],0 as [DeptId],[RealName] FROM [Dcx_User] inner join 
-- [Dcx_UserInRole] on [Dcx_UserInRole].[UserId]=[Dcx_UserInRole].[UserId] where [Dcx_UserInRole].[RoleId]=@id
--else if @qType=5
--SELECT [UserId],[UserName],[UserName] as [RealName],0 as [DeptId],0 as [PositionId],0 as [SuperAdmin] FROM [Dcx_LinkMan] where  GroupId=@id order by [UserName] --[CreatorId]=3 and 1=1 and
----else if @qType=6 --菜单
----SELECT [UserId],[UserName],[UserName] as [RealName],0 as [DeptId],0 as [PositionId],0 as [SuperAdmin] FROM [Dcx_LinkMan] where  GroupId=@id order by [UserName] --[CreatorId]=3 and 1=1 and
--else
--SELECT [UserId],[UserName],[RealName],[Email],[DeptId],[PositionId],[SuperAdmin] FROM [Dcx_User]  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_GetUserRolesById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_User_GetUserRolesById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_GetUserRolesById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC [dbo].[DcxRun_User_GetUserRolesById](@userId int)
as
begin
select r.[RoleName] ,r.RoleId,r.SystemRoleType,r.RoleTypeId from 
[Dcx_UserInRole] ur inner join [Dcx_Role] r on  ur.[RoleId]=r.[RoleId] where ur.[UserId]=@userId 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_SetDcxUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_User_SetDcxUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_User_SetDcxUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_User_SetDcxUserName] --设置用户在dcxCreator上的用户名
@UserId int ,
@DcxUserName varchar(30)
AS
BEGIN
update [Dcx_User] set [DcxUserName]=@DcxUserName    where  [UserId]=@UserId  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_UserView_CheckPasswordByEmail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_UserView_CheckPasswordByEmail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_UserView_CheckPasswordByEmail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[DcxRun_UserView_CheckPasswordByEmail]
@Email nchar(20),
@Password char(100)
AS
SELECT TOP 1 * FROM [Dcx_UserView] WHERE [Email]=@Email AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_UserView_CheckPasswordByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_UserView_CheckPasswordByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_UserView_CheckPasswordByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[DcxRun_UserView_CheckPasswordByUserId]
@UserId int,
@Password char(100)
AS
SELECT TOP 1 * FROM [Dcx_UserView] WHERE [UserId]=@UserId AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_UserView_CheckPasswordByUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_UserView_CheckPasswordByUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_UserView_CheckPasswordByUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[DcxRun_UserView_CheckPasswordByUserName]
@UserName nchar(20),
@Password char(100)
AS
SELECT TOP 1 * FROM [Dcx_UserView] WHERE [UserName]=@UserName AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WeiBo_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_WeiBo_Delete](@userId int, @wId int)
as
begin
--set nocount on
		delete from [Dcx_WeiBo] WHERE 12=12  and [WId]=@wId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WeiBo_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WeiBo_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate 
							and [CreateDate]<@toDate and 12=12   
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate  and 12=12  
				end
				else 
				begin
							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]<@toDate and 12=12  
				end
		end
		else
		begin
				select count(1)  from [Dcx_WeiBo]  where  12=12  
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate 
							and [CreateDate]<@toDate and 12=12    and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate  and 12=12   and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]<@toDate and 12=12   and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_WeiBo]  where  12=12   and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WeiBo_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_WeiBo_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_WeiBo_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_WeiBo_GetTopWeiBo]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_WeiBo_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WeiBo_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WeiBo_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate 
	--							and [CreateDate]<@toDate and 12=12   
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate  and 12=12  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate  and 12=12  
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]<@toDate and 12=12 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]<@toDate and 12=12  
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
--						where 12=12  
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--					if @pageIndex<=1
	--						select count(1)  from [Dcx_WeiBo]  where   12=12  
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12
					end
					else if @toDate is  null 
					begin
								select   top 200 [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate  and 12=12
					end
					else 
					begin
								select   top 200 [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]<@toDate and 12=12
					end
			end
			else
			begin
								select  top 200  [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
--								where 12=12  
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate 
	--							and [CreateDate]<@toDate and 12=12    and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate  and 12=12  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]>@fromDate  and 12=12   and [TagId]=@tagId
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]<@toDate and 12=12 and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--						if @pageIndex<=1
	--							select count(1)  from [Dcx_WeiBo]  where  [CreateDate]<@toDate and 12=12   and [TagId]=@tagId
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [CreateDate] desc)as dcx_rowid, [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
						where 12=12   and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
	--					if @pageIndex<=1
	--						select count(1)  from [Dcx_WeiBo]  where   12=12   and [TagId]=@tagId
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate and [CreateDate]<@toDate and 12=12  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]>@fromDate  and 12=12  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where [CreateDate]<@toDate and 12=12  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  [WId],[MsgContent],[CreatorId],[CreatorName],[CreateDate],[IsPublic],[TypeId],[TagId],[TagName],[HasFile],[FileJson]  FROM [Dcx_WeiBo]  
								where 12=12   and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetTopWeiBo]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WeiBo_GetTopWeiBo]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WeiBo_GetTopWeiBo]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_WeiBo_GetTopWeiBo]
@tagId int,
@userId int
AS
BEGIN 
select -1
	return 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_WeiBo where 12=12   
else
	 select 1 as dcx_rowid,*  from Dcx_WeiBo where 12=12   and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_CanWriteField_Insert]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_CanWriteField_Insert]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_CanWriteField_Insert]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC  [dbo].[DcxRun_WF_CanWriteField_Insert] (
@FlowId int,
@NodeId int,
@PrcsItem varchar(max),
@PrcsItem2 varchar(max)
) 
AS 
declare @EntId int 
declare @EntName varchar(500)
declare @FlowName varchar(500)
select @EntId=[EntId],@FlowName=[FlowName] from [WF_FlowType] where [FlowId]=@FlowId
set @EntId=isnull(@EntId,0)
if @EntId<1
return
select @EntName=[EntName] from [Dcx_Entity_Run] where [EntId]=@EntId
declare @IsDefaultForm int 
set @IsDefaultForm=0
SELECT top 1 @IsDefaultForm=1 FROM [Dcx_DefaultForm_Run] where [EntId]=@EntId
delete from [WF_CanWriteField] where [FlowId]=@FlowId and [NodeId ]=@NodeId 
declare @re bit
set @re=1
declare @ObjectId int 
declare @temp varchar(100)
declare @str varchar(max)
declare @Len int 
declare @split char(1)  --分割符
set @split='',''
declare @StartIndex int --起始序号
set @StartIndex=1
declare @EndIndex int  --结束序号
declare @ContainSplit bit --是否含有分割符
declare @FieldName varchar(500)
declare @CtrlByName varchar(500)
-----------初始化变量-----------------------
set @str=@PrcsItem
set @Len=len(@str)
set @ContainSplit=0
set @EndIndex=CharIndex(@split,@str,@StartIndex)
if @EndIndex<1
	set @EndIndex=@Len
else
	set @ContainSplit=1
while (@EndIndex>0 and @EndIndex <= @Len and @StartIndex <= @Len) --开始循环
begin
--------------------------------------开始  -----------------------------------------
	if @ContainSplit=0
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex+1)))
	else 
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex)))
	if @temp='''' or @temp is null
		break
 	set @ObjectId=cast(ltrim(rtrim(@temp)) as int)
	if @ObjectId<1
		break
if @IsDefaultForm=1
	SELECT @FieldName=[FieldName] FROM [Dcx_DefaultFormField_Run] where [FldId]=@ObjectId and EntId=@EntId
else 
	SELECT @FieldName=[FieldName] FROM [Dcx_AjaxFormField_Run] where [FldId]=@ObjectId and EntId=@EntId
set @CtrlByName=@FieldName
INSERT INTO [WF_CanWriteField]
           ([EntId]
           ,[EntName]
           ,[NodeId]
           ,[FldId]
           ,[FieldName]
           ,[CtrlByName]
           ,[FlowId]
           ,[FlowName]
           ,[TypeId])
     VALUES
           (@EntId
           ,@EntName
           ,@NodeId
           ,@ObjectId
           ,@FieldName
           ,@CtrlByName
           ,@FlowId
           ,@FlowName
           ,1)
	if @EndIndex>=@Len
		break
	set @StartIndex =@EndIndex+1
	set @EndIndex=CharIndex(@split,@str,@StartIndex)
	set @ContainSplit=0
	if @EndIndex<1
		set @EndIndex=@Len
	else
		set @ContainSplit=1
end 
-----------初始化变量-----------------------
set @str=@PrcsItem2
set @Len=len(@str)
set @ContainSplit=0
set @EndIndex=CharIndex(@split,@str,@StartIndex)
if @EndIndex<1
	set @EndIndex=@Len
else
	set @ContainSplit=1
while (@EndIndex>0 and @EndIndex <= @Len and @StartIndex <= @Len) --开始循环
begin
--------------------------------------开始  -----------------------------------------
	if @ContainSplit=0
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex+1)))
	else 
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex)))
	if @temp='''' or @temp is null
		break
 	set @ObjectId=cast(ltrim(rtrim(@temp)) as int)
	if @ObjectId<1
		break
SELECT @FieldName=[EntName] FROM [Dcx_Entity_Run] where [EntId]=@ObjectId 
set @CtrlByName=@FieldName
INSERT INTO [WF_CanWriteField]
           ([EntId]
           ,[EntName]
           ,[NodeId]
           ,[FldId]
           ,[FieldName]
           ,[CtrlByName]
           ,[FlowId]
           ,[FlowName]
           ,[TypeId])
     VALUES
           (@EntId
           ,@EntName
           ,@NodeId
           ,@ObjectId
           ,@FieldName
           ,@CtrlByName
           ,@FlowId
           ,@FlowName
           ,2)
	if @EndIndex>=@Len
		break
	set @StartIndex =@EndIndex+1
	set @EndIndex=CharIndex(@split,@str,@StartIndex)
	set @ContainSplit=0
	if @EndIndex<1
		set @EndIndex=@Len
	else
		set @ContainSplit=1
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_CanDeal]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_CanDeal]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_CanDeal]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_CanDeal]
@NodeId int, 
@UserId int, 
@DeptId int
AS
select [dbo].WF_CanDealFlowNode(@NodeId,@UserId,@DeptId)
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_DeleteStep]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_DeleteStep]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_DeleteStep]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_DeleteStep] 
@flowId int,
@nodeId int
AS
delete from WF_FlowNode where [FlowId]=@flowId and  NodeId=@nodeId
declare @nodeId2   int
declare @prcsTo   varchar(500)
declare @nodeId3   varchar(11)
declare @prcsTo2   varchar(600)
set @nodeId3='',''+cast(@nodeId as varchar(11))+'',''
--创建游标
declare myCursor cursor for SELECT [NodeId] ,[PrcsTo]   FROM  WF_FlowNode where [FlowId]=@flowId
--打开游标 任务
open myCursor 
fetch next  from myCursor into  	@nodeId2,@prcsTo
while (@@fetch_status=0)
begin 
--------------------------------------开始  循环-----------------------------------------
if @prcsTo is not null and ltrim(rtrim(@prcsTo))!=''''
begin
set @prcsTo2=@prcsTo 
if substring(@prcsTo2,1,1)!='','' 
	set @prcsTo2='',''+@prcsTo2 
if substring(@prcsTo2,len(@prcsTo2),1)!='','' 
	set @prcsTo2=@prcsTo2 +'',''
set @prcsTo2=replace(@prcsTo2,@nodeId3,'','')
if len(@prcsTo2)<=2
	set @prcsTo2=''''
else
	set @prcsTo2=substring(@prcsTo2,2,len(@prcsTo2)-2)
update [WF_FlowNode]  set [PrcsTo]=@prcsTo2  where [FlowId]=@flowId and  NodeId=@nodeId2
end
--下一条记录
fetch next  from myCursor into @nodeId2,@prcsTo
--------------------------------------结束  循环-----------------------------------------
end
close myCursor --关闭 任务
deallocate myCursor 
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetAllDealMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetAllDealMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetAllDealMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetAllDealMsg]--从WF_FlowNode中获取经办人设置
@NodeId int
AS
select PrcsUsers,PrcsRoles,'''' as Creator,'''' as CreatorBoss,PositionDept from WF_FlowNode 
where NodeId=@NodeId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetAllNode]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetAllNode]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetAllNode]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetAllNode] 
@FlowId int
AS
	select NodeId,NodeName,Step,PrcsTo,Pointx,Pointy,NodeType from WF_FlowNode where FlowId=@FlowId order by Step asc
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetCanDealUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetCanDealUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetCanDealUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetCanDealUser]--获取节点的可办理人
@FlowId int ,
@RunId int ,
@NodeId int ,
@IdType int,--1，UserId；2，RoleId；3，DeptId；4，Position；0，全部
@UserId int
AS
--SELECT [ObjectName],[ObjectId] FROM [WF_FlowNodePrivilege] 
--where [NodeId]={@NodeId} and [IdType]={@DealUserType}
--EXEC	[dbo].[DcxRun_WF_GetNodeUserList]
--	@NodeId = {@NodeId},
--	@IdType = {@DealUserType}
if @IdType=1 
begin
	declare @UserList table([UserName]  varchar(100)   ,[UserId] int )
	declare @AllowLastNodeBoss int
	declare @AllowWorkCreator int
	declare @CreatorId int
	declare @CreatorName varchar(100)
	SELECT @AllowLastNodeBoss=[AllowLastNodeBoss],@AllowWorkCreator=[AllowWorkCreator] FROM [WF_FlowNode] where [NodeId]=@NodeId and [FlowId]=@FlowId
	if @AllowWorkCreator=1 
	begin
		select @CreatorId=[CreatorId],@CreatorName=[CreatorName] from [WF_FlowRun] where [RunId]=@RunId
		insert into @UserList ([UserName],[UserId]) values(@CreatorName,@CreatorId)--select [UserName],[UserId] from [Dcx_User] where [UserId]=@CreatorId
	end
	if @AllowLastNodeBoss=1 
	begin
		declare @PositionId int
		declare @PositionParentId int
		select @PositionId=[PositionId] from [Dcx_User] where [UserId]=@UserId
		select @PositionParentId=[ParentId] from [Dcx_Position] where [PositionId]=@PositionId
		if @PositionParentId>0
		begin
			insert into @UserList ([UserName],[UserId]) select [UserName],[UserId] from [Dcx_User] where [PositionId]=@PositionParentId
		end
	end
	insert into @UserList ([UserName],[UserId]) SELECT [ObjectName] as [UserName],[ObjectId] as [UserId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=@IdType
	select * from @UserList
 end
else if @IdType=2 
begin
	select (select top 1 B.[UserName] from [Dcx_User] as B where B.[UserId]=A.[UserId] ) as [UserName],A.[UserId] from  [Dcx_UserInRole] as A where A.[RoleId] in(SELECT [ObjectId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=@IdType)
end
else if @IdType=3 
begin
	select [UserName],[UserId] from [Dcx_User] where [DeptId] in(SELECT [ObjectId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=@IdType)
end
else if @IdType=4 
begin
	select [UserName],[UserId] from [Dcx_User] where [PositionId] in(SELECT [ObjectId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=@IdType)
end
else if @IdType=0 --获取全部 
begin
SELECT [ObjectName] as [UserName],[ObjectId] as [UserId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=1
 union 
select (select top 1 B.[UserName] from [Dcx_User] as B where B.[UserId]=A.[UserId] ) as [UserName],A.[UserId] from  [Dcx_UserInRole] as A where A.[RoleId] in(SELECT [ObjectId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=2)
 union 
select [UserName],[UserId] from [Dcx_User] where [DeptId] in(SELECT [ObjectId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=3)
 union 
select [UserName],[UserId] from [Dcx_User] where [PositionId] in(SELECT [ObjectId] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId and [IdType]=4)
end
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetDealUserMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetDealUserMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetDealUserMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetDealUserMsg]--从表WF_FlowNode查询经办人
@NodeId int 
AS
if @NodeId=-1
return
declare @PrcsUsers as  varchar(2000)
set @PrcsUsers=''''
select @PrcsUsers=PrcsUserNames from WF_FlowNode where NodeId=@NodeId
if @PrcsUsers=''''
return 
declare @sel_sql as varchar(5000)
select [UserId] as UserId,[RealName] as real_name from [Dcx_User] 
where   @PrcsUsers like ''%,''+ltrim(rtrim([Dcx_User].[UserName]))+'',%''
--execute(@sel_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetFirstStep]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetFirstStep]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetFirstStep]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetFirstStep] 
@FlowId int
AS
begin
declare @NodeId as int
select @NodeId=NodeId from WF_FlowNode where FlowId=@FlowId and PrcsTo like ''%-1%''
if @NodeId is not null
begin
	select top 1 *  from WF_FlowNode where FlowId=@FlowId  order by  NodeId
end
else
begin
		select top 1 *  from WF_FlowNode where FlowId=-1
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetFirstStepMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetFirstStepMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetFirstStepMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetFirstStepMsg] 
@FlowId int
AS
begin
declare @NodeId as int
select @NodeId=NodeId from WF_FlowNode where FlowId=@FlowId
 and PrcsTo like ''%-1%''
if @NodeId is not null
begin
select top 1 NodeId,NodeName from WF_FlowNode where FlowId=@FlowId  order by NodeId asc
--select min(NodeId),NodeName as NodeId from WF_FlowNode where FlowId=@FlowId 
end
else
begin
select NodeId,NodeName from WF_FlowNode where Step=-123
end
--select *from WF_FlowNode where FlowId=@FlowId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetFirstStepPrcsId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetFirstStepPrcsId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetFirstStepPrcsId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetFirstStepPrcsId] 
@FlowId int
AS
begin
declare @NodeId as int
select @NodeId=NodeId from WF_FlowNode where FlowId=@FlowId
 and PrcsTo like ''%-1%''
if @NodeId is not null
begin
select top 1 NodeId,NodeName from WF_FlowNode where FlowId=@FlowId  order by NodeId asc
end
else
begin
select NodeId,NodeName from WF_FlowNode where Step=-123
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetNextStep]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetNextStep]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetNextStep]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetNextStep]
@NodeId int,
@FlowId int
AS
--	select PrcsTo,NextNames from WF_FlowNode where NodeId=@NodeId and PrcsTo!=''-1''
declare @sel_sql as varchar(500)
declare @next_step as varchar (500)
select @next_step=PrcsTo from WF_FlowNode where NodeId=@NodeId
if @next_step='''' or @next_step is null
begin
set @sel_sql=''select NodeId,Step,cast(Step as varchar)+''''.''''+NodeName as NodeName from WF_FlowNode where NodeId=-1''
end
else
begin
set @sel_sql=''select NodeId,Step,cast(Step as varchar)+''''.''''+NodeName as NodeName,''+@next_step+'' as next_step from WF_FlowNode where FlowId=''+cast(@FlowId as varchar)+'' and NodeId in(''+@next_step+'')''
end
execute(@sel_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetStepMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetStepMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetStepMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetStepMsg] 
@NodeId int
AS
select * from WF_FlowNode where NodeId=@NodeId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetStepNameAndId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_GetStepNameAndId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_GetStepNameAndId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取指定流程的指定节点Id之内或者之外的节点信息
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_GetStepNameAndId] 
@prcs_ids varchar(500),--多个节点Id字符串，格式：id,id,id....
@type int ,--等于1时，查询的是@prcs_ids参数中指定的节点Id的节点详细信息；等于2时，查询的是除了@prcs_ids参数中指定的节点之外的其他所有节点的详细信息
@FlowId int
AS
--begin
--	declare @sel_sql as varchar(1000)
--if @type=1 --选择是其下一步的 
--begin
--  if @prcs_ids ='''' or @prcs_ids is null
--	select PrcsTo,NodeId,NodeName as prcs_name2,Step,FlowId from WF_FlowNode where NodeId=-1
--	else
--select NodeName as prcs_name2,PrcsTo,Step,FlowId,NodeId,''第''+cast(Step as varchar)+''步:''+NodeName as NodeName from WF_FlowNode where FlowId=cast(@FlowId as varchar) and NodeId in(@prcs_ids)
--end
--else
--begin
--    if @prcs_ids ='''' or @prcs_ids is null
--select NodeName as prcs_name2,PrcsTo,NodeId,''第''+cast(Step as varchar)+''步:''+NodeName as NodeName,Step,FlowId from WF_FlowNode where FlowId=cast(@FlowId as varchar)
--	else
--select NodeName as prcs_name2,PrcsTo,Step,FlowId,NodeId,''第''+cast(Step as varchar)+''步:''+NodeName as NodeName from WF_FlowNode where  FlowId=cast(@FlowId as varchar) and NodeId not in(@prcs_ids)
--end
--
--	end
begin
	declare @sel_sql as varchar(1000)
if @type=1 --选择是其下一步的 
begin
  if @prcs_ids ='''' or @prcs_ids is null
	begin
	set @sel_sql=''select PrcsTo,NodeId,NodeName as prcs_name2,Step,FlowId from WF_FlowNode where NodeId=-1''
	end
	else
	begin
	set @sel_sql=''select NodeName as prcs_name2,PrcsTo,Step,FlowId,NodeId,''''第''''+cast(Step as varchar)+''''步:''''+NodeName as NodeName from WF_FlowNode where FlowId=''+cast(@FlowId as varchar)+'' and NodeId in(''+@prcs_ids+'')''
	end
end
else
begin
    if @prcs_ids ='''' or @prcs_ids is null
    begin
	set @sel_sql=''select NodeName as prcs_name2,PrcsTo,NodeId,''''第''''+cast(Step as varchar)+''''步:''''+NodeName as NodeName,Step,FlowId from WF_FlowNode where FlowId=''+cast(@FlowId as varchar)
	end
	else
	begin
	set @sel_sql=''select NodeName as prcs_name2,PrcsTo,Step,FlowId,NodeId,''''第''''+cast(Step as varchar)+''''步:''''+NodeName as NodeName from WF_FlowNode where  FlowId=''+cast(@FlowId as varchar)+'' and NodeId not in(''+@prcs_ids+'')''
	end
end
	execute(@sel_sql)
	end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_SetPower]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_SetPower]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_SetPower]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC  [dbo].[DcxRun_WF_FlowNode_SetPower] (
@FlowId int,
@NodeId int,
@str varchar(max),
@IdType int--1，UserId；2，RoleId；3，DeptId；3，Position；
) 
AS 
if @str=null or @str=''''
	return
declare @re bit
set @re=1
declare @ObjectId int 
declare @ObjectName varchar(500)
declare @temp varchar(100)
declare @Len int 
declare @split char(1)  --分割符
set @split='',''
declare @StartIndex int --起始序号
set @StartIndex=1
declare @EndIndex int  --结束序号
declare @ContainSplit bit --是否含有分割符
declare @CanQuery bit
declare @CanStart bit
declare @CanDesign bit
declare @CaMonitor bit
set @CanQuery=0
set @CanStart=0
set @CanDesign=0
set @CaMonitor=0
-----------初始化变量-----------------------
set @Len=len(@str)
set @ContainSplit=0
set @EndIndex=CharIndex(@split,@str,@StartIndex)
if @EndIndex<1
	set @EndIndex=@Len
else
	set @ContainSplit=1
while (@EndIndex>0 and @EndIndex <= @Len and @StartIndex <= @Len) --开始循环
begin
--------------------------------------开始  -----------------------------------------
	if @ContainSplit=0
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex+1)))
	else 
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex)))
	if @temp='''' or @temp is null
		break
 	set @ObjectId=cast(ltrim(rtrim(@temp)) as int)
	if @ObjectId<1
		break
--if (select count(*) from [WF_FlowNodePrivilege]  WHERE  [NodeId]=@NodeId and  [ObjectId]=@ObjectId and [IdType]=@IdType)<1
set @ObjectName=null
if @ObjectId=1
set @ObjectName=(select top 1 [UserName] from Dcx_User where [UserId]=@ObjectId)
else if @ObjectId=2
set @ObjectName=(select top 1 [RoleName] from Dcx_Role where [RoleId]=@ObjectId)
else if @ObjectId=3
set @ObjectName=(select top 1 DeptName from Dcx_Dept where [DeptId]=@ObjectId)
else if @ObjectId=4
set @ObjectName=(select top 1 PositionName from Dcx_Position where PositionId=@ObjectId)
	INSERT INTO [WF_FlowNodePrivilege]([NodeId],[ObjectId],[FlowId],[IdType],[ObjectName])
	VALUES (@NodeId,@ObjectId,@FlowId,@IdType,@ObjectName)
	if @EndIndex>=@Len
		break
	set @StartIndex =@EndIndex+1
	set @EndIndex=CharIndex(@split,@str,@StartIndex)
	set @ContainSplit=0
	if @EndIndex<1
		set @EndIndex=@Len
	else
		set @ContainSplit=1
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_UpdateDealPower]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowNode_UpdateDealPower]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowNode_UpdateDealPower]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowNode_UpdateDealPower] 
@NodeId int,
@Creator int,
@CreatorBoss int,
@PositionDept varchar(30),
@PrcsRoles varchar(100),
@PrcsUsers varchar(1000)
AS
	update WF_FlowNode set PositionDept=@PositionDept,
	PrcsRoles=@PrcsRoles,PrcsUsers=@PrcsUsers where NodeId=@NodeId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_DeleteWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_DeleteWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_DeleteWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_DeleteWork] 
@RunId int
AS
--declare @table_name as varchar(200)
--declare @FlowId as int
--declare @FormId as int
--if @RunId='''' or @RunId<1
--return
--set @FlowId=-1
--set @FormId=-1
--set @table_name=''''
--select @FlowId=FlowId from WF_FlowRun where RunId=@RunId
--if @FlowId=-1
--return
--
--select @FormId=EntId from WF_FlowType where FlowId=@FlowId
--if @FormId=-1
--return
--select @table_name=table_name from fzoa_form_bindtable where FormId=@FormId
--if @table_name=''''
--return
--
--delete from WF_FlowRunPrcs where RunId=@RunId
--delete from WF_FlowRun where RunId=@RunId
--declare @del_sql as varchar(200)
--set @del_sql=''delete from ''+@table_name+'' where RunId=''+cast(@RunId as varchar)
--	execute(@del_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_DeleteWork2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_DeleteWork2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_DeleteWork2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[DcxRun_WF_FlowRun_DeleteWork2] 
@RunId int
AS
declare @dbTableName as varchar(200)
declare @FlowId as int
declare @EntId as int
if @RunId='''' or @RunId<1
return
set @FlowId=-1
set @EntId=-1
set @dbTableName=''''
select @FlowId=FlowId from WF_FlowRun where RunId=@RunId
if @FlowId=-1
return
select @EntId=EntId from WF_FlowType where FlowId=@FlowId
if @EntId=-1
return
select @dbTableName=DBTableName from Dcx_Entity where [EntId]=@EntId
delete from WF_FlowRunPrcs where RunId=@RunId
delete from WF_FlowRun where RunId=@RunId
if @dbTableName=''''
	return
declare @del_sql as varchar(400)
set @del_sql=''delete from ''+@dbTableName+'' where WFRunId=''+cast(@RunId as varchar(20))
execute(@del_sql)
set @del_sql=''delete from ''+@dbTableName+''_log where WFRunId=''+cast(@RunId as varchar(20))
execute(@del_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetBoss]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetBoss]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetBoss]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetBoss]--获取所有上司 
@RunId int 
AS
if @RunId<1 
return 
declare @CreatorBoss as varchar(5000)
set @CreatorBoss=''''
select @CreatorBoss=CreatorBoss from WF_FlowRun where RunId=@RunId
if @CreatorBoss='''' or @CreatorBoss is null
return
declare @sel_sql as varchar(5000)
set @sel_sql=''select [UserId] as UserId,[RealName] as real_name from [Dcx_User] where [UserId] in(''+@CreatorBoss+'')''
execute(@sel_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetCreator]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetCreator]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetCreator]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetCreator]--获取流程创建者 
@RunId int
AS
select CreatorId as UserId,CreatorName as real_name from WF_FlowRun where RunId=@RunId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetDealedUsers]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetDealedUsers]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetDealedUsers]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetDealedUsers]
@flowId int,
@runId int
AS
BEGIN
	select distinct [CreatorId],[CreatorName] from [WF_FlowRunHsty] where 
	@flowId=FlowId and @runId=[RunId]  
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetDoneWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetDoneWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetDoneWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetDoneWork]--获取经办工作
@UserId int, 
@FlowId int,
@pagesize int, 
@pageindex int, 
@docount int
AS
begin
if @docount=1 and @FlowId=0
begin 
--获取所有已办工作的数量
select count(*) from 
WF_FlowRunPrcs where UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 )
--select count(*) from 
--WF_FlowRunPrcs as rp 
--inner join  
--WF_FlowNode as p 
--on rp.UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) and  rp.NodeId=p.NodeId
-- inner join WF_FlowRun as r 
--on rp.RunId=r.RunId
--inner join  WF_FlowType as t on t.FlowId=r.FlowId
return 
end
else if  @docount=1 and @FlowId!=0
begin
--获取指定工作流的已办工作的数量。1：表示没有接收；2：表示已经查阅过；3：表示已办理过；4：表示已结束。
select count(*) from 
WF_FlowRunPrcs  where UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) and FlowId=@FlowId
--select count(*) from 
--WF_FlowRunPrcs as rp 
--inner join  
--WF_FlowNode as p 
--on  rp.UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) and rp.NodeId=p.NodeId
--inner join 
--WF_FlowRun as r 
--on rp.RunId=r.RunId 
--inner join 
--WF_FlowType as t 
--on t.FlowId=@FlowId and t.FlowId=r.FlowId 
return 
end
--分页
declare @indextable table(id int identity(1,1),nid int) 
declare @PageLowerBound int 
declare @PageUpperBound int 
set @PageLowerBound=(@pageindex-1)*@pagesize 
set @PageUpperBound=@PageLowerBound+@pagesize 
set rowcount @PageUpperBound 
if @FlowId=0 
begin
insert into @indextable(nid)
select PrcsId from 
WF_FlowRunPrcs  where UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) order by PrcsId desc 
end
else
begin
insert into @indextable(nid)
select PrcsId  from WF_FlowRunPrcs  
where UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) and FlowId=FlowId  order by PrcsId desc 
end
--分页
if @FlowId=0 
begin
select RunId,RunName,FlowId,PrcsId,Step,''第''+cast(Step as varchar)+''步：''+PrcsName as p_step,PrcsName,FlowName,
CreatorName,PrcsTime,PrcsFlag,EntId,WorkCreatorId as CreatorId ,DeliverTime,NodeId
 from 
WF_FlowRunPrcs  /*分页*/ inner join  @indextable as it 
on PrcsId=it.nid and it.id>@PageLowerBound and it.id<=@PageUpperBound   /*分页*/
 where UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) order by PrcsId desc
 end
else
begin
select RunId,RunName,FlowId,PrcsId,Step,''第''+cast(Step as varchar)+''步：''+PrcsName as p_step,PrcsName,FlowName,
CreatorName,PrcsTime,PrcsFlag,EntId,WorkCreatorId as CreatorId ,DeliverTime,NodeId
 from 
WF_FlowRunPrcs  /*分页*/ inner join  @indextable as it 
on PrcsId=it.nid and it.id>@PageLowerBound and it.id<=@PageUpperBound   /*分页*/
where UserId=@UserId  and (PrcsFlag=3 or PrcsFlag=4 ) and FlowId=FlowId  order by PrcsId desc 
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetDraftWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetDraftWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetDraftWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetDraftWork]--获取经办工作,此存储过程增加了分分页的功能
@UserId int, 
@FlowId int,
@pagesize int, 
@pageindex int, 
@docount int
AS
begin
declare @t1 as varchar(20)--用户Id like
declare @t2 as varchar(20)--角色Id like
declare @RoleId as int
declare @pos_id as int
declare @dept_id as int
declare @p_d as varchar(20)
--获取用户的角色Id
select top 1 @RoleId=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
--获取用户的职位Id，部门Id
select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
----获取用户的部门Id
--select top 1  @dept_id=dept_id from hyoa_dept_leaguer where UserId=@UserId
set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
--用户Id like
set @t1=''%,''+cast(@UserId as varchar)+'',%''
--角色Id like
set @t2=''%,''+cast(@RoleId as varchar)+'',%''
--获取所有的未办工作数量
if @docount=1 and @FlowId=0
begin
select count(*) from WF_FlowRunPrcs  where 
PrcsFlag=2 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1)))) 
return 
end
else if  @docount=1 and @FlowId!=0
begin
select count(*) from WF_FlowRunPrcs  where FlowId=@FlowId and 
PrcsFlag=2 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1)))) 
--获取指定工作流程的所有未办工作数量
return 
end
--分页获取指定所有未办工作数量
--分页
declare @indextable table(id int identity(1,1),nid int) 
declare @PageLowerBound int 
declare @PageUpperBound int 
set @PageLowerBound=(@pageindex-1)*@pagesize 
set @PageUpperBound=@PageLowerBound+@pagesize 
set rowcount @PageUpperBound 
if @FlowId=0 
begin
insert into @indextable(nid) 
select PrcsId from WF_FlowRunPrcs  where 
PrcsFlag=2 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1))))   order by PrcsId desc 
end
else
begin
insert into @indextable(nid) 
select PrcsId from WF_FlowRunPrcs  where FlowId=@FlowId and 
PrcsFlag=2 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1))))  order by PrcsId desc 
end
--分页
if @FlowId=0 
begin 
select RunId,RunName,FlowId,PrcsId,''第''+cast(Step as varchar)+''步：''+PrcsName as p_step,FlowName,
CreatorName,DeliverTime,PrcsFlag,EntId,UserId as deal_type
,Creator as CreatorId ,NodeId,PrcsName as NodeName,EntName as EntName,ParentId  from WF_FlowRunPrcs 
  /*分页*/ inner join  @indextable as it 
on PrcsId=it.nid and it.id>@PageLowerBound and it.id<=@PageUpperBound  /*分页*/
 where PrcsFlag=2 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1))))   order by PrcsId desc  
end
else
begin
select RunId,RunName,FlowId,PrcsId,''第''+cast(Step as varchar)+''步：''+PrcsName as p_step,FlowName,
CreatorName,DeliverTime,PrcsFlag,EntId,UserId as deal_type
,Creator as CreatorId ,NodeId,PrcsName as NodeName,EntName as EntName,ParentId  
 from WF_FlowRunPrcs  inner join 
 /*分页*/ @indextable as it 
on PrcsId=it.nid and it.id>@PageLowerBound and it.id<=@PageUpperBound    /*分页*/
 where   FlowId=@FlowId and  PrcsFlag=2 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1))))   order by PrcsId desc  
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_Getlsh]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_Getlsh]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_Getlsh]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
-------------------开始------------------------------
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_Getlsh]
@RunId int---参数，其实也是变量；只是我们可以通过他，在使用这个存储过程的时候，传些数据进来运行
AS
--------------------内容开始--------------------------
	select FlowLsh from WF_FlowRun where RunId=@RunId
--------------------内容结束--------------------------
	RETURN
--------------------结束--------------------------
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetRunName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetRunName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetRunName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE  [dbo].[DcxRun_WF_FlowRun_GetRunName]
@PrcsId int
AS
declare @RunId as int
select @RunId=RunId from WF_FlowRunPrcs where PrcsId=@PrcsId
select RunName from WF_FlowRun where RunId=@RunId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetUndoWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetUndoWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetUndoWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetUndoWork]--获取经办工作,此存储过程增加了分分页的功能
@UserId int, 
@FlowId int,
@pagesize int, 
@pageindex int, 
@docount int
AS
begin
declare @t1 as varchar(20)--用户Id like
declare @t2 as varchar(20)--角色Id like
declare @role_id as int
declare @pos_id as int
declare @dept_id as int
declare @p_d as varchar(20)
--获取用户的角色Id
select top 1 @role_id=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
 --获取用户的职位Id，部门Id
select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
--用户Id like
set @t1=''%,''+cast(@UserId as varchar)+'',%''
--角色Id like
set @t2=''%,''+cast(@role_id as varchar)+'',%''
--获取所有的未办工作数量
if @docount=1 and @FlowId=0
begin
select count(*) from WF_FlowRunPrcs  where 
PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or UserId=@UserId  or 
(CreatorBoss like @t1)))) 
return 
end
else if  @docount=1 and @FlowId!=0
begin
select count(*) from WF_FlowRunPrcs  where FlowId=@FlowId and 
PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
(CreatorBoss like @t1)))) 
--获取指定工作流程的所有未办工作数量
return 
end
--分页获取指定所有未办工作数量
--分页
declare @indextable table(id int identity(1,1),nid int) 
declare @PageLowerBound int 
declare @PageUpperBound int 
set @PageLowerBound=(@pageindex-1)*@pagesize 
set @PageUpperBound=@PageLowerBound+@pagesize 
set rowcount @PageUpperBound 
if @FlowId=0 
begin
insert into @indextable(nid) 
select PrcsId from WF_FlowRunPrcs  where 
PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles
like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
(CreatorBoss like @t1))))   order by PrcsId desc 
end
else
begin
insert into @indextable(nid) 
select PrcsId from WF_FlowRunPrcs  where FlowId=@FlowId and 
PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
(CreatorBoss like @t1))))  order by PrcsId desc 
end
--分页
if @FlowId=0 
begin 
select RunId,RunName,FlowId,PrcsId,''第''+cast(Step as varchar)+''步：''+PrcsName as p_step,FlowName,
CreatorName,DeliverTime,PrcsFlag,EntId,UserId as deal_type
,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName as EntName,ParentId  from WF_FlowRunPrcs 
  /*分页*/ inner join  @indextable as it 
on PrcsId=it.nid and it.id>@PageLowerBound and it.id<=@PageUpperBound  /*分页*/
 where PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
(CreatorBoss like @t1))))   order by PrcsId desc  
end
else
begin
select RunId,RunName,FlowId,PrcsId,''第''+cast(Step as varchar)+''步：''+PrcsName as p_step,FlowName,
CreatorName,DeliverTime,PrcsFlag,EntId,UserId as deal_type
,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName as EntName,ParentId  
 from WF_FlowRunPrcs  inner join 
 /*分页*/ @indextable as it 
on PrcsId=it.nid and it.id>@PageLowerBound and it.id<=@PageUpperBound    /*分页*/
 where   FlowId=@FlowId and  PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
(CreatorBoss like @t1))))   order by PrcsId desc  
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetWorkForQuery]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetWorkForQuery]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetWorkForQuery]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetWorkForQuery] 
@query varchar(2000),
@PageLowerBound int, 
@PageUpperBound int,
--@pagesize int, 
--@currentpage int,
@getcount int
AS
begin
declare @sel_sql as varchar(4000)
--获取行数
if @getcount=1 
begin
declare @s as varchar(max)
set @s=''
select count(*) from 
WF_FlowRun  inner join WF_FlowType
on ''+@query+ ''  and WF_FlowRun.FlowId=WF_FlowType.FlowId
inner join WF_FlowRunPrcs 
on WF_FlowRun.RunId =WF_FlowRunPrcs.RunId
and (WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 or NextPrcsId=-1) 
inner join WF_FlowNode
on WF_FlowRunPrcs.NodeId=WF_FlowNode.NodeId 
''
	execute(@s) 
return 
end
		if object_id(''tempdb..#MyWorkFlow'') is not null
		Begin     drop table #MyWorkFlow End 
	create table #MyWorkFlow  --创建临时表#Tmp
	(
[Id] [int] IdENTITY(1,1) NOT NULL,
RowIndex int NOT NULL,
[RunId] int NOT NULL,
[RunName] varchar(200)   NOT NULL,
[FlowId] int NOT NULL,
[FlowName] varchar(200)   NULL,
[CreateTime] datetime NOT NULL,
[CreatorId] int NOT NULL,
[FlowLsh] varchar(500)   NULL,
[CreatorBoss] varchar(1000)   NULL,
[CreatorName] varchar(50)   NULL,
[FinishFlag] int NULL  ,
[KeyField] varchar(500)   NULL,
[KeyFieldValue] varchar(100)   NULL,
[EntId] int ,
[EntName] varchar(500)   NULL,
[PrcsId] int   ,
[NodeId] int  ,
[NodeName] varchar(200)   ,
[UserId] int ,
[UserName] varchar(100)   ,
[DealIds] varchar(500)   ,
[PrcsTime] datetime ,
[DeliverTime] datetime ,
[PrcsFlag] int   ,
[NextPrcsId] int ,
[ParentId] int ,
[FirstManFlag] int     ,
[Step] int ,
[PrcsStep] int ,
[FirstStepFlag] bit    ,
[PositionDept] varchar(50)   ,
[PrcsUsers] varchar(1000)   ,
[PrcsRoles] varchar(1000)   ,
CurrentStep varchar(1000)  
	) 
--构造SQL语句,使用了行字段来实现了分页读取
 set @sel_sql=''INSERT INTO #MyWorkFlow(   RowIndex, [RunId],[RunName],[FlowId],[FlowName],[CreateTime],[CreatorId],[FlowLsh],[CreatorBoss],[CreatorName],[FinishFlag],[KeyField],[KeyFieldValue],[EntId],[EntName])  
select   * from (SELECT 
RANK() OVER (ORDER BY  .WF_FlowRun.[RunId] desc) AS RowIndex, [RunId],[RunName],[FlowId],[FlowName],[CreateTime],[CreatorId],[FlowLsh],[CreatorBoss],[CreatorName],[FinishFlag],[KeyField],[KeyFieldValue],[EntId],[EntName]
  FROM  WF_FlowRun  where ''+@query+'') as A  where RowIndex>''+cast(@PageLowerBound as varchar)+''  and RowIndex<=''+cast(@PageUpperBound as varchar) 
--将流程查询结果写入临时表
execute(@sel_sql)
--定义循环变量
declare @RunId   int
declare @FlowId   int
declare @id   int 
declare @FinishFlag   int 
--定义游标
	declare mycursor cursor for SELECT Id,RunId,FlowId,FinishFlag FROM #MyWorkFlow
	open mycursor
	fetch next from mycursor into @id,@RunId,@FlowId,@FinishFlag
	while (@@fetch_status=0)
		begin 
--定义需要更新的字段
		declare @EntId int   
	declare @EntName  varchar(200)   
select   @EntId=EntId,@EntName=EntName from WF_FlowType where FlowId=@FlowId
declare @PrcsId int   
	declare @NodeId int  
	declare @PrcsName varchar(200)   
	declare @NodeName varchar(200)   
	declare @UserId int 
	declare @UserName varchar(100)   
	declare @DealIds varchar(500)   
	declare @PrcsTime datetime 
	declare @DeliverTime datetime 
	declare @PrcsFlag int   
	declare @NextPrcsId int 
	declare @ParentId int 
	declare @FirstManFlag int     
	declare @Step int 
	declare @FirstStepFlag bit    
	declare @PrcsStep int 
	declare @CreatorBoss varchar(1000)   
	declare @PositionDept varchar(50)   
	declare @PrcsUsers varchar(1000)   
	declare @PrcsRoles varchar(1000)   
	declare @CurrentStep varchar(1000) 
--查询最后一个步骤
select  	top 1 @PrcsId=PrcsId,
	@NodeId=NodeId,
	@PrcsName=PrcsName,
	@UserId=UserId,
	@UserName=UserName,
	@DealIds=DealIds,
	@PrcsTime=PrcsTime,
	@DeliverTime=DeliverTime,
	@PrcsFlag=PrcsFlag,
	@NextPrcsId=NextPrcsId,
	@ParentId=ParentId,
	@FirstManFlag=FirstManFlag,
	@Step=Step,
	@FirstStepFlag=FirstStepFlag,
	@PrcsStep=PrcsStep,
	@CreatorBoss=CreatorBoss,
	@PositionDept=PositionDept,
	@PrcsUsers=PrcsUsers,
	@PrcsRoles=PrcsRoles,
	@CurrentStep=(case when @FinishFlag=1 then ''已完成'' else ''第''+cast(WF_FlowRunPrcs.Step as varchar)+''步：''+isnull(WF_FlowRunPrcs.PrcsName,'''') end )
from WF_FlowRunPrcs where RunId=@RunId order by PrcsId desc 
--将查询结束更新到临时表相应行中
update  #MyWorkFlow set EntId=@EntId,EntName=@EntName,PrcsId=@PrcsId,
	NodeId=@NodeId,
--	PrcsName=@PrcsName,
	UserId=@UserId,
	UserName=@UserName,
	DealIds=@DealIds,
	PrcsTime=@PrcsTime,
	DeliverTime=@DeliverTime,
	PrcsFlag=@PrcsFlag,
	NextPrcsId=@NextPrcsId,
	ParentId=@ParentId,
	FirstManFlag=@FirstManFlag,
	Step=@Step,
	FirstStepFlag=@FirstStepFlag,
	PrcsStep=@PrcsStep,
	PositionDept=@PositionDept,
	PrcsUsers=@PrcsUsers,
	PrcsRoles=@PrcsRoles,
	CurrentStep=@CurrentStep where id=@id
fetch next from mycursor into  @id,@RunId,@FlowId,@FinishFlag
		end
	close mycursor
	deallocate mycursor
--返回查询结果
select * from #MyWorkFlow
end
--if @currentpage=1 --如果是第一页
--begin
-- set @sel_sql=''select top ''+cast(@pagesize as varchar)+'' WF_FlowRun.RunId,WF_FlowRun.RunName,
-- WF_FlowRun.FlowId,
-- WF_FlowRun.CreatorName,
-- FinishFlag,
-- WF_FlowRun.CreatorId,
-- WF_FlowRun.CreateTime,
-- WF_FlowRunPrcs.DealIds,
--	WF_FlowRunPrcs.PrcsId,
--	''''第''''+cast(WF_FlowNode.Step as varchar)+''''步：''''+WF_FlowNode.NodeName as CurrentStep,
--	WF_FlowType.FlowName,
--	WF_FlowType.EntId,
--	NextPrcsId,
--	WF_FlowRunPrcs.UserId,
--	WF_FlowType.ManageUsers
--	,WF_FlowRunPrcs.NodeId
--	from  WF_FlowRun 
--  inner join WF_FlowType
--	  on ''+@query+'' and WF_FlowRun.FlowId=WF_FlowType.FlowId
--	  inner join WF_FlowRunPrcs 
--	 on WF_FlowRun.RunId =WF_FlowRunPrcs.RunId
--	and (WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 or NextPrcsId=-1) 
--	inner join WF_FlowNode
--	on WF_FlowRunPrcs.NodeId=WF_FlowNode.NodeId order by WF_FlowRun.RunId desc''
--	
--end
--else --非第一页
--begin
--
-- set @sel_sql=''select top ''+cast(@pagesize as varchar)+'' WF_FlowRun.RunId,WF_FlowRun.RunName,
-- WF_FlowRun.FlowId,
-- WF_FlowRun.CreatorName,
-- WF_FlowRun.FinishFlag,
-- WF_FlowRun.CreatorId,
-- CreateTime,
-- WF_FlowRunPrcs.DealIds,
--	WF_FlowRunPrcs.PrcsId,''''第''''+cast(WF_FlowNode.Step as varchar)+''''步：''''+WF_FlowNode.NodeName as CurrentStep,
--	WF_FlowType.FlowName,
--	WF_FlowType.EntId,
--	NextPrcsId	,
--	WF_FlowRunPrcs.UserId,
--	WF_FlowType.ManageUsers
--	,WF_FlowRunPrcs.NodeId
--	from 
--	 WF_FlowRun 	
--	  inner join WF_FlowType
--	  on ''+@query+'' and WF_FlowRun.FlowId=WF_FlowType.FlowId
--	  inner join WF_FlowRunPrcs 
--	 on WF_FlowRun.RunId =WF_FlowRunPrcs.RunId
--	and (WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 or NextPrcsId=-1) 
--	inner join WF_FlowNode
--	on WF_FlowRunPrcs.NodeId=WF_FlowNode.NodeId
--	  where
--	 WF_FlowRun.RunId<(select min(RunId)  from (select top ''+cast(@PageLowerBound as varchar)+'' WF_FlowRun.RunId
--	  from 
--	   WF_FlowRun 	
--	  inner join WF_FlowType
--	  on ''+@query+'' and WF_FlowRun.FlowId=WF_FlowType.FlowId
--	  inner join WF_FlowRunPrcs 
--	 on WF_FlowRun.RunId =WF_FlowRunPrcs.RunId
--	and (WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 or NextPrcsId=-1) 
--	inner join WF_FlowNode
--	on WF_FlowRunPrcs.NodeId=WF_FlowNode.NodeId
--	 order by WF_FlowRun.RunId desc) as temp) order by WF_FlowRun.RunId desc''
--	 end
--	print @sel_sql
--	  execute(@sel_sql)
--	  end
/*
select * from(
    select WF_FlowRun.RunId,WF_FlowRun.RunName,WF_FlowRun.FlowId,CreatorName,FinishFlag,
	WF_FlowRunPrcs.PrcsId,''''第''''+cast(WF_FlowNode.Step as varchar)+''''步：''''+WF_FlowNode.NodeName as CurrentStep,
	WF_FlowType.FlowName,WF_FlowType.EntId,''''已经结束'''' as work_state 
	from  WF_FlowRun inner join WF_FlowRunPrcs on''+ @query+'' and WF_FlowRunPrcs.RunId=WF_FlowRun.RunId 
	and ((WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 ) and NextPrcsId!=-1) inner join WF_FlowNode
	on WF_FlowRun.FlowId=WF_FlowNode.FlowId inner join WF_FlowType on WF_FlowType.FlowId =WF_FlowRun.FlowId
	   union 
	select WF_FlowRun.RunId,WF_FlowRun.RunName,WF_FlowRun.FlowId,CreatorName,FinishFlag,
	WF_FlowRunPrcs.PrcsId,''''第''''+cast(WF_FlowNode.Step as varchar)+''''步：''''+WF_FlowNode.NodeName as CurrentStep,
	WF_FlowType.FlowName,WF_FlowType.EntId,''''正在执行'''' as work_state 
	from  WF_FlowRun inner join WF_FlowRunPrcs on''+ @query+'' and WF_FlowRunPrcs.RunId=WF_FlowRun.RunId 
	and  NextPrcsId=-1 inner join WF_FlowNode
	on WF_FlowRun.FlowId=WF_FlowNode.FlowId inner join WF_FlowType on WF_FlowType.FlowId =WF_FlowRun.FlowId
	) as hyoa_flow_work order by CreateTime decs''
	*/
--不合并重复
--问题：在查询工作时，有些工作，不是任何人都可以查询的，所以，在设计工作流程时指定的

--查询人员，就是指这些可以查询此工作流的人员，其他人便无权查看这些流程
--但此存储过程并没有考虑此情况，以后再改一下
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetWorkHistory]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_GetWorkHistory]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_GetWorkHistory]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_GetWorkHistory] 
@RunId int
AS
select PrcsId,''第''+cast(WF_FlowNode.Step as varchar)+''步：''+WF_FlowNode.NodeName as p_step,
      Dcx_User.[RealName] as real_name,DeliverTime,(case when PrcsFlag!=4 then ''正在办理'' else  ''已办理'' end) as state,WF_FlowType.EntId,
       WF_FlowType.FlowName,WF_FlowRun.RunName,WF_FlowRun.RunId,WF_FlowNode.NodeName
        from WF_FlowRun inner join WF_FlowRunPrcs 
        on WF_FlowRun.RunId=@RunId and WF_FlowRun.RunId=WF_FlowRunPrcs.RunId
       inner join WF_FlowNode 
       on  WF_FlowRunPrcs.NodeId=WF_FlowNode .NodeId 
      inner join WF_FlowType on WF_FlowType.FlowId=WF_FlowNode.FlowId
       left outer join Dcx_User on Dcx_User.[UserId]=WF_FlowRunPrcs.UserId
        order by PrcsId asc
	RETURN
set ANSI_NULLS ON
set QUOTED_IdENTIFIER ON
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_SetWorkFinished]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_SetWorkFinished]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_SetWorkFinished]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_SetWorkFinished] 
@RunId int
AS
	update WF_FlowRun set FinishFlag=1 where RunId=@RunId
		update WF_FlowRunPrcs set PrcsFlag=4 where RunId=@RunId and  PrcsFlag=3 
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_TakeBack]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_TakeBack]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_TakeBack]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_TakeBack] 
@PrcsId int
AS
declare @flag as int
declare @to as int
declare @next_run_pid as int
if @PrcsId='''' or @PrcsId<1
return
select @to=NextPrcsId from WF_FlowRunPrcs where PrcsId=@PrcsId
if @to!=-1 and @to is not null and @to>0
begin
select @flag=PrcsFlag,@next_run_pid=PrcsId from WF_FlowRunPrcs where NodeId=@to and ParentId=@PrcsId
if @flag=1 
begin
delete from WF_FlowRunPrcs where PrcsId=@next_run_pid
update WF_FlowRunPrcs set PrcsFlag=2 where PrcsId=@PrcsId
end
end
else
begin
update WF_FlowRunPrcs set PrcsFlag=2 where PrcsId=@PrcsId
end
	RETURN 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_Update]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowRun_Update]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowRun_Update]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowRun_Update]
@FlowId int, 
@RunId int, 
@EntId int, 
@UserId int, 
@KeyFieldName varchar(100), 
@KeyFieldValue varchar(100), 
@DbTableName varchar(100), 
@Feedback varchar(1000)
AS
UPDATE [WF_FlowRun]
   SET [DbTableName] = @DbTableName
      ,[KeyField] = @KeyFieldName
      ,[KeyFieldValue] = @KeyFieldValue
      ,[Feedback] = isnull([Feedback],'''')+isnull(@Feedback,'''')
      ,[EditorId] =@UserId
      ,[EditTime] =getdate()
 WHERE  [FlowId]=@FlowId and [RunId]=@RunId
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CaMonitor]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_CaMonitor]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CaMonitor]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowType_CaMonitor]
@FlowId int, 
@UserId int, 
@DeptId int
AS
select [dbo].WF_CaMonitorFlow(@FlowId,@UserId,@DeptId)
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CanDesign]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_CanDesign]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CanDesign]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowType_CanDesign]
@FlowId int, 
@UserId int, 
@DeptId int
AS
select [dbo].WF_CanDesignFlow(@FlowId,@UserId,@DeptId)
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CanQuery]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_CanQuery]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CanQuery]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowType_CanQuery]
@FlowId int, 
@UserId int, 
@DeptId int
AS
select [dbo].WF_CanQueryFlow(@FlowId,@UserId,@DeptId)
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CanStart]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_CanStart]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_CanStart]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowType_CanStart]
@FlowId int, 
@UserId int, 
@DeptId int
AS
select [dbo].WF_CanStartFlow(@FlowId,@UserId,@DeptId)
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_GetAllFlow]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_GetAllFlow]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_GetAllFlow]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowType_GetAllFlow] 
AS
select FlowId,FlowName from WF_FlowType order by SortId asc
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_GetFlowName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_GetFlowName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_GetFlowName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_FlowType_GetFlowName]
@flow_id int
AS
select FlowName from WF_FlowType where [FlowId]=@flow_id
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_SetPower]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_FlowType_SetPower]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_FlowType_SetPower]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROC  [dbo].[DcxRun_WF_FlowType_SetPower] (
@FlowId int,
@str varchar(max),
@IdType int,--1，UserId；2，RoleId；3，DeptId；
@PowerTypeId int--权限类别，1：CanQuery；2：CanStart；3：CanDesign；4：CaMonitor；
) 
AS 
declare @re bit
set @re=1
--declare @IdType int 
--declare @PowerTypeId int 
declare @ObjectId int 
declare @temp varchar(100)
declare @Len int 
declare @split char(1)  --分割符
set @split='',''
declare @StartIndex int --起始序号
set @StartIndex=1
declare @EndIndex int  --结束序号
declare @ContainSplit bit --是否含有分割符
--declare @str varchar(max)
--declare @IdType int 
--declare @PowerTypeId int 
declare @CanQuery bit
declare @CanStart bit
declare @CanDesign bit
declare @CaMonitor bit
set @CanQuery=0
set @CanStart=0
set @CanDesign=0
set @CaMonitor=0
-----------初始化变量-----------------------
--set @PowerTypeId=4
--set @IdType=1
--set @str=@ManageUsers
set @Len=len(@str)
set @ContainSplit=0
set @EndIndex=CharIndex(@split,@str,@StartIndex)
if @EndIndex<1
	set @EndIndex=@Len
else
	set @ContainSplit=1
while (@EndIndex>0 and @EndIndex <= @Len and @StartIndex <= @Len) --开始循环
begin
--------------------------------------开始  -----------------------------------------
	if @ContainSplit=0
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex+1)))
	else 
		set @temp=ltrim(rtrim(SUBSTRING(@str,@StartIndex,@EndIndex-@StartIndex)))
	if @temp='''' or @temp is null
		break
	--1，UserId；2，RoleId；3，DeptId；
	if ISNUMERIC(@temp)=0 
	begin
	set @ObjectId=-1 
	if @IdType=1
		select @ObjectId=[UserId] from [Dcx_User] where [UserName]=@temp 
	else if @IdType=2
		select @ObjectId=[RoleId] from [Dcx_Role] where [RoleName]=@temp 
	else if @IdType=3
		select @ObjectId=[DeptId] from [Dcx_Dept] where [DeptName]=@temp 
	end
	else		
 		set @ObjectId=cast(ltrim(rtrim(@temp)) as int)
	if   @ObjectId is not null and @ObjectId>0
	begin 
		if @PowerTypeId=1
			set @CanQuery=1
		else if @PowerTypeId=2
			set @CanStart=1
		else if @PowerTypeId=3
			set @CanDesign=1
		else if @PowerTypeId=4
			set @CaMonitor=1
		if (select count(*) from [WF_FlowTypePrivilege]  WHERE  [FlowId]=@FlowId and  [ObjectId]=@ObjectId and [IdType]=@IdType)<1
		begin
			INSERT INTO [WF_FlowTypePrivilege]
			([FlowId],[ObjectId],[CanQuery],[CanStart],[CanDesign],[CaMonitor],[IdType],[ObjectName])
			VALUES (@FlowId,@ObjectId,@CanQuery,@CanStart,@CanDesign,@CaMonitor,@IdType,null)
		end
		else
		begin
			if @PowerTypeId=1
				update [WF_FlowTypePrivilege] set [CanQuery]=1   WHERE  [FlowId]=@FlowId and  [ObjectId]=@ObjectId and [IdType]=@IdType
			else if @PowerTypeId=2
				update [WF_FlowTypePrivilege] set [CanStart]=1   WHERE  [FlowId]=@FlowId and  [ObjectId]=@ObjectId and [IdType]=@IdType
			else if @PowerTypeId=3
				update [WF_FlowTypePrivilege] set [CanDesign]=1   WHERE  [FlowId]=@FlowId and  [ObjectId]=@ObjectId and [IdType]=@IdType
			else if @PowerTypeId=4
				update [WF_FlowTypePrivilege] set [CaMonitor]=1   WHERE  [FlowId]=@FlowId and  [ObjectId]=@ObjectId and [IdType]=@IdType
		end
	end
	if @EndIndex>=@Len
		break
	set @StartIndex =@EndIndex+1
	set @EndIndex=CharIndex(@split,@str,@StartIndex)
	set @ContainSplit=0
	if @EndIndex<1
		set @EndIndex=@Len
	else
		set @ContainSplit=1
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetFieldList_ByFlowId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetFieldList_ByFlowId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetFieldList_ByFlowId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetFieldList_ByFlowId] 
@FlowId int
AS
BEGIN
declare @TableName varchar(100)
declare @EntId int
declare @DBTableId int
select @EntId=[EntId] from [WF_FlowType] where [FlowId]=@FlowId
set @EntId=isnull(@EntId,0)
if @EntId<1
begin
select   ''未绑定应用''   
return
end
select @DBTableId=[DBTableId] from [Dcx_Entity_Run] where  [EntId]=@EntId
set @DBTableId=isnull(@DBTableId,0)
if @DBTableId<1
begin
select   ''未绑定应用''   
return
end 
select @TableName=[DBTableName] from [Dcx_DBTable_Run] where  [DBTableId]=@DBTableId
set @TableName=isnull(@TableName,'''')
if ltrim(rtrim(isnull(@TableName,'''')))=''''
begin
select   ''请选择数据表''   
return
end
select   name   from   syscolumns   where   id=object_id(  @TableName ) 
and name!=''FD_Id '' and name!=''feedback'' and name!=''form_id'' and name!=''run_id'' 
and name!=''Run_pid''
and name!=''User_id '' and name!=''Zc_flag''  and name!=''LD_Id '' and name!=''flow_lsh'' 
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetFlowField]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetFlowField]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetFlowField]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetFlowField]
@FlowId int 
AS
declare @EntId int 
select @EntId=[EntId] from [WF_FlowType] where [FlowId]=@FlowId
set @EntId=isnull(@EntId,0)
if @EntId<1
return
declare @c int 
set @c=0
 (SELECT top 1 @c=1 FROM [Dcx_DefaultForm_Run] where [EntId]=@EntId) 
if @c=1
SELECT [FieldName],[FldId] FROM [Dcx_DefaultFormField_Run] where [EntId]=@EntId order by [FldId]
else 
SELECT [FieldName],[FldId] FROM [Dcx_AjaxFormField_Run] where [EntId]=@EntId order by [FldId]
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetFlowField_ByEntId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetFlowField_ByEntId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetFlowField_ByEntId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetFlowField_ByEntId]
@EntId int 
AS
set @EntId=isnull(@EntId,0)
if @EntId<1
return
declare @c int 
set @c=0
 (SELECT top 1 @c=1 FROM [Dcx_DefaultForm_Run] where [EntId]=@EntId) 
if @c=1
SELECT [FieldName],[FldId] FROM [Dcx_DefaultFormField_Run] where [EntId]=@EntId order by [FldId]
else 
SELECT [FieldName],[FldId] FROM [Dcx_AjaxFormField_Run] where [EntId]=@EntId order by [FldId]
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyDraftWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetMyDraftWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyDraftWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetMyDraftWork] --获取我草稿箱的工作
@SearchArea varchar(2000),
@StartIndex int, 
@EndIndex int,
@UserId int,
@DeptId int,
@getcount int
AS
begin
declare @sel_sql as varchar(4000)
--declare @IsMainDealer bit
declare @t1 as varchar(20)--用户Id like
--用户Id like
set @t1=''%,''+cast(@UserId as varchar)+'',%''
if @getcount<1
begin 
set @sel_sql=''select *  from (select row_number() over(order by PrcsId desc)as dcx_rowid, 
 RunId,RunName,FlowId,PrcsId,''''第''''+cast(isnull(Step,'''''''') as varchar)+''''步：''''+isnull(PrcsName,'''''''') as CurrentStep,FlowName,
 CreatorName,DeliverTime,PrcsFlag,EntId,UserId,UserName
,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName,ParentId ,(case when UserId=''+ cast(@UserId as varchar(12))+'' then 1 else 0 end) as IsMainDealer
FROM [WF_FlowRunPrcs]  where  ''+@SearchArea+'' and (  PrcsFlag=2) and (UserId=''+cast(@UserId as varchar(12))+'' or DealIds like ''''''+@t1+'''''')     ) AS MyTable 
where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
 end
else 
begin
	 set @sel_sql=''select count(*) FROM [WF_FlowRunPrcs]  where  ''+@SearchArea+''  and (  PrcsFlag=2)  and (UserId=''+cast(@UserId as varchar(12))+'' or DealIds like ''''''+@t1+'''''') ''
 end 
	execute(@sel_sql)
--<$2056$>
----获取待办工作
--declare @t1 as varchar(20)--用户Id like
--declare @t2 as varchar(20)--角色Id like
--declare @RoleId as int
--declare @pos_id as int
--declare @dept_id as int
--declare @p_d as varchar(20)
--declare @UserId as int
--set @UserId={$userid}
----获取用户的角色Id
--select top 1 @RoleId=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
-- --获取用户的职位Id，部门Id
--select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
--set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
----用户Id like
--set @t1=''%,''+cast(@UserId as varchar)+'',%''
----角色Id like
--set @t2=''%,''+cast(@RoleId as varchar)+'',%''
--
-- select *  from (select  row_number() over( order by DeliverTime desc)as dcx_rowid,
-- RunId,RunName,FlowId,PrcsId,''第''+cast(isnull(Step,'''') as varchar)+''步：''+isnull(PrcsName,'''') as CurrentStep,FlowName,
--CreatorName,DeliverTime,PrcsFlag,EntId,UserId as deal_type
--,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName as EntName,ParentId  
-- from WF_FlowRunPrcs  
--
-- where   {$SearchArea} and  PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
--
--(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
--
--like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
--
--(CreatorBoss like @t1))))   ) AS MyTable  where  dcx_rowid between {$startRow} and {$endRow}
-- order by PrcsId desc  
--
-- </$2056$>
--
--
--<$2056:Count$>
----获取待办工作的数量
--declare @t1 as varchar(20)--用户Id like
--declare @t2 as varchar(20)--角色Id like
--declare @RoleId as int
--declare @pos_id as int
--declare @dept_id as int
--declare @p_d as varchar(20)
--declare @UserId as int
--set @UserId={$userid}
----获取用户的角色Id
--select top 1 @RoleId=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
-- --获取用户的职位Id，部门Id
--select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
--set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
----用户Id like
--set @t1=''%,''+cast(@UserId as varchar)+'',%''
----角色Id like
--set @t2=''%,''+cast(@RoleId as varchar)+'',%''
-- 
--select count(*) from WF_FlowRunPrcs  where {$SearchArea} and 
--
--PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
--
--(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
--
--like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
--
--(CreatorBoss like @t1)))) 
--</$2056:Count$>
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyMonitorWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetMyMonitorWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyMonitorWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetMyMonitorWork] --获取我可监控的工作
@SearchArea varchar(2000),
@StartIndex int, 
@EndIndex int,
@UserId int,
@DeptId int,
@getcount int
AS
begin
declare @sel_sql as varchar(4000)
--declare @IsMainDealer bit
if @getcount<1
begin 
set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, 
 RunId,RunName,FlowId,PrcsId,''''第''''+cast(isnull(Step,'''''''') as varchar)+''''步：''''+isnull(PrcsName,'''''''') as CurrentStep,FlowName,
 CreatorName,DeliverTime,PrcsFlag,EntId,UserId,UserName
,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName,ParentId ,(case when UserId=''+ cast(@UserId as varchar(12))+'' then 1 else 0 end) as IsMainDealer
FROM [WF_FlowRunPrcs]  where  ''+@SearchArea+'' and (  PrcsFlag=1 or PrcsFlag=2) and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1     ) AS MyTable 
where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
 end
else 
begin
	 set @sel_sql=''select count(*) FROM [WF_FlowRunPrcs]  where  ''+@SearchArea+''  and (  PrcsFlag=1 or PrcsFlag=2) and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1 ''
 end 
	execute(@sel_sql)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyUndoWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetMyUndoWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyUndoWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetMyUndoWork] --获取我未办理的工作
@SearchArea varchar(2000),
@StartIndex int, 
@EndIndex int,
@UserId int,
@DeptId int,
@getcount int
AS
begin
declare @sel_sql as varchar(4000)
--declare @IsMainDealer bit
declare @t1 as varchar(20)--用户Id like
--用户Id like
set @t1=''%,''+cast(@UserId as varchar)+'',%''
if @getcount<1
begin 
set @sel_sql=''select *  from (select row_number() over(order by PrcsId desc)as dcx_rowid, 
 RunId,RunName,FlowId,PrcsId,''''第''''+cast(isnull(Step,'''''''') as varchar)+''''步：''''+isnull(PrcsName,'''''''') as CurrentStep,FlowName,
 CreatorName,DeliverTime,PrcsFlag,EntId,UserId,UserName
,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName,ParentId ,(case when [UserId]=''+ cast(@UserId as varchar(12))+'' then 1 else 0 end) as IsMainDealer
FROM [WF_FlowRunPrcs]  where  ''+@SearchArea+'' and (  PrcsFlag=1 or PrcsFlag=2) and ([UserId]=''+cast(@UserId as varchar(12))+'' or DealIds like ''''''+@t1+'''''')     ) AS MyTable 
where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
 end
else 
begin
	 set @sel_sql=''select count(*) FROM [WF_FlowRunPrcs]  where  ''+@SearchArea+''  and (  PrcsFlag=1 or PrcsFlag=2)  and (UserId=''+cast(@UserId as varchar(12))+'' or DealIds like ''''''+@t1+'''''') ''
 end 
	execute(@sel_sql)
--<$2056$>
----获取待办工作
--declare @t1 as varchar(20)--用户Id like
--declare @t2 as varchar(20)--角色Id like
--declare @RoleId as int
--declare @pos_id as int
--declare @dept_id as int
--declare @p_d as varchar(20)
--declare @UserId as int
--set @UserId={$userid}
----获取用户的角色Id
--select top 1 @RoleId=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
-- --获取用户的职位Id，部门Id
--select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
--set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
----用户Id like
--set @t1=''%,''+cast(@UserId as varchar)+'',%''
----角色Id like
--set @t2=''%,''+cast(@RoleId as varchar)+'',%''
--
-- select *  from (select  row_number() over( order by DeliverTime desc)as dcx_rowid,
-- RunId,RunName,FlowId,PrcsId,''第''+cast(isnull(Step,'''') as varchar)+''步：''+isnull(PrcsName,'''') as CurrentStep,FlowName,
--CreatorName,DeliverTime,PrcsFlag,EntId,UserId as deal_type
--,WorkCreatorId as CreatorId ,NodeId,PrcsName as NodeName,EntName as EntName,ParentId  
-- from WF_FlowRunPrcs  
--
-- where   {$SearchArea} and  PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
--
--(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
--
--like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
--
--(CreatorBoss like @t1))))   ) AS MyTable  where  dcx_rowid between {$startRow} and {$endRow}
-- order by PrcsId desc  
--
-- </$2056$>
--
--
--<$2056:Count$>
----获取待办工作的数量
--declare @t1 as varchar(20)--用户Id like
--declare @t2 as varchar(20)--角色Id like
--declare @RoleId as int
--declare @pos_id as int
--declare @dept_id as int
--declare @p_d as varchar(20)
--declare @UserId as int
--set @UserId={$userid}
----获取用户的角色Id
--select top 1 @RoleId=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
-- --获取用户的职位Id，部门Id
--select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
--set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
----用户Id like
--set @t1=''%,''+cast(@UserId as varchar)+'',%''
----角色Id like
--set @t2=''%,''+cast(@RoleId as varchar)+'',%''
-- 
--select count(*) from WF_FlowRunPrcs  where {$SearchArea} and 
--
--PrcsFlag!=3 and PrcsFlag!=4 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
--
--(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
--
--like @t2 or PositionDept=@p_d or (Creator=@UserId)  or UserId=@UserId or 
--
--(CreatorBoss like @t1)))) 
--</$2056:Count$>
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyWorkForQuery]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetMyWorkForQuery]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetMyWorkForQuery]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetMyWorkForQuery]  --思路：1，先获取分页后的WF_FlowRun，之后，再通过游标，获取每个工作的最后一步，最后，把工作返回
@query varchar(2000),
@PageLowerBound int, 
@PageUpperBound int,
@getcount int
AS
begin
declare @sel_sql as varchar(4000)
--获取行数
if @getcount=1 
begin
	declare @s as varchar(max)
	set @s=''
	select count(*) from 
	WF_FlowRun  inner join WF_FlowType
	on ''+@query+ ''  and WF_FlowRun.FlowId=WF_FlowType.FlowId
	inner join WF_FlowRunPrcs 
	on WF_FlowRun.RunId =WF_FlowRunPrcs.RunId
	and (WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 ) 
	inner join WF_FlowNode
	on WF_FlowRunPrcs.NodeId=WF_FlowNode.NodeId 
	''
--	set @s=''
--	select count(*) from 
--	WF_FlowRun  inner join WF_FlowType
--	on ''+@query+ ''  and WF_FlowRun.FlowId=WF_FlowType.FlowId
--	inner join WF_FlowRunPrcs 
--	on WF_FlowRun.RunId =WF_FlowRunPrcs.RunId
--	and (WF_FlowRunPrcs.PrcsFlag=1 or WF_FlowRunPrcs.PrcsFlag=2 or NextPrcsId=-1) 
--	inner join WF_FlowNode
--	on WF_FlowRunPrcs.NodeId=WF_FlowNode.NodeId 
--	''
	execute(@s) 
	return 
end
if object_id(''tempdb..#MyWorkFlow'') is not null
Begin     drop table #MyWorkFlow End 
	create table #MyWorkFlow  --创建临时表#Tmp
	(
		[Id] [int] IdENTITY(1,1) NOT NULL,
		RowIndex int NOT NULL,
		[RunId] int NOT NULL,
		[RunName] varchar(200)   NOT NULL,
		[FlowId] int NOT NULL,
		[FlowName] varchar(200)   NULL,
		[CreateTime] datetime NOT NULL,
		[CreatorId] int NOT NULL,
		[FlowLsh] varchar(500)   NULL,
		[CreatorBoss] varchar(1000)   NULL,
		[CreatorName] varchar(50)   NULL,
		[FinishFlag] int NULL  ,
		[KeyField] varchar(500)   NULL,
		[KeyFieldValue] varchar(100)   NULL,
		[EntId] int ,
		[EntName] varchar(500)   NULL,
		[PrcsId] int   ,
		[NodeId] int  ,
		[NodeName] varchar(200)   ,
		[UserId] int ,
		[UserName] varchar(100)   ,
		[DealIds] varchar(500)   ,
		[PrcsTime] datetime ,
		[DeliverTime] datetime ,
		[PrcsFlag] int   ,
		[NextPrcsId] int ,
		[ParentId] int ,
		[FirstManFlag] int     ,
		[Step] int ,
		[PrcsStep] int ,
		[FirstStepFlag] bit    ,
		[PositionDept] varchar(50)   ,
		[PrcsUsers] varchar(1000)   ,
		[PrcsRoles] varchar(1000)   ,
		CurrentStep varchar(1000)  
	) 
--构造SQL语句,使用了行字段来实现了分页读取
 set @sel_sql=''INSERT INTO #MyWorkFlow(   RowIndex, [RunId],[RunName],[FlowId],[FlowName],[CreateTime],[CreatorId],[FlowLsh],[CreatorBoss],[CreatorName],[FinishFlag],[KeyField],[KeyFieldValue],[EntId],[EntName])  
select   * from (SELECT 
RANK() OVER (ORDER BY  .WF_FlowRun.[RunId] desc) AS RowIndex, [RunId],[RunName],[FlowId],[FlowName],[CreateTime],[CreatorId],[FlowLsh],[CreatorBoss],[CreatorName],[FinishFlag],[KeyField],[KeyFieldValue],[EntId],[EntName]
  FROM  WF_FlowRun  where ''+@query+'') as A  where RowIndex>''+cast(@PageLowerBound as varchar)+''  and RowIndex<=''+cast(@PageUpperBound as varchar) 
--将流程查询结果写入临时表
execute(@sel_sql)
--定义循环变量
declare @RunId   int
declare @FlowId   int
declare @id   int 
declare @FinishFlag   int 
--定义游标
	declare mycursor cursor for SELECT Id,RunId,FlowId,FinishFlag FROM #MyWorkFlow
	open mycursor
	fetch next from mycursor into @id,@RunId,@FlowId,@FinishFlag
	while (@@fetch_status=0)
		begin 
--定义需要更新的字段
		declare @EntId int   
	declare @EntName  varchar(200)   
select   @EntId=EntId,@EntName=EntName from WF_FlowType where FlowId=@FlowId
declare @PrcsId int   
	declare @NodeId int  
	declare @PrcsName varchar(200)   
	declare @NodeName varchar(200)   
	declare @UserId int 
	declare @UserName varchar(100)   
	declare @DealIds varchar(500)   
	declare @PrcsTime datetime 
	declare @DeliverTime datetime 
	declare @PrcsFlag int   
	declare @NextPrcsId int 
	declare @ParentId int 
	declare @FirstManFlag int     
	declare @Step int 
	declare @FirstStepFlag bit    
	declare @PrcsStep int 
	declare @CreatorBoss varchar(1000)   
	declare @PositionDept varchar(50)   
	declare @PrcsUsers varchar(1000)   
	declare @PrcsRoles varchar(1000)   
	declare @CurrentStep varchar(1000) 
--查询最后一个步骤
select  	top 1 @PrcsId=PrcsId,
	@NodeId=NodeId,
	@PrcsName=PrcsName,
	@UserId=UserId,
	@UserName=UserName,
	@DealIds=DealIds,
	@PrcsTime=PrcsTime,
	@DeliverTime=DeliverTime,
	@PrcsFlag=PrcsFlag,
	@NextPrcsId=NextPrcsId,
	@ParentId=ParentId,
	@FirstManFlag=FirstManFlag,
	@Step=Step,
	@FirstStepFlag=FirstStepFlag,
	@PrcsStep=PrcsStep,
	@CreatorBoss=CreatorBoss,
	@PositionDept=PositionDept,
	@PrcsUsers=PrcsUsers,
	@PrcsRoles=PrcsRoles,
	@CurrentStep=(case when @FinishFlag=1 then ''已完成'' else ''第''+cast(WF_FlowRunPrcs.Step as varchar)+''步：''+isnull(WF_FlowRunPrcs.PrcsName,'''') end )
from WF_FlowRunPrcs where RunId=@RunId order by PrcsId desc 
--将查询结束更新到临时表相应行中
update  #MyWorkFlow set EntId=@EntId,EntName=@EntName,PrcsId=@PrcsId,
	NodeId=@NodeId,
--	PrcsName=@PrcsName,
	UserId=@UserId,
	UserName=@UserName,
	DealIds=@DealIds,
	PrcsTime=@PrcsTime,
	DeliverTime=@DeliverTime,
	PrcsFlag=@PrcsFlag,
	NextPrcsId=@NextPrcsId,
	ParentId=@ParentId,
	FirstManFlag=@FirstManFlag,
	Step=@Step,
	FirstStepFlag=@FirstStepFlag,
	PrcsStep=@PrcsStep,
	PositionDept=@PositionDept,
	PrcsUsers=@PrcsUsers,
	PrcsRoles=@PrcsRoles,
	CurrentStep=@CurrentStep where id=@id
fetch next from mycursor into  @id,@RunId,@FlowId,@FinishFlag
		end
	close mycursor
	deallocate mycursor
--返回查询结果
select * from #MyWorkFlow
end
--不合并重复
--问题：在查询工作时，有些工作，不是任何人都可以查询的，所以，在设计工作流程时指定的

--查询人员，就是指这些可以查询此工作流的人员，其他人便无权查看这些流程
--但此存储过程并没有考虑此情况，以后再改一下
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetNextNodes]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_GetNextNodes]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_GetNextNodes]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_GetNextNodes]
@FlowId int,
@NodeId int
AS
declare @sel_sql as varchar(500)
declare @next_step as varchar (500)
select @next_step=PrcsTo from WF_FlowNode where [FlowId]=@FlowId and [NodeId]=@NodeId
if @next_step is null or ltrim(rtrim(@next_step))='''' 
begin
	select ''结束'',-1,1
end
else
begin
if PATINDEX(''%-1%'',@next_step)<1
	set @sel_sql=''select ''''第''''+cast(Step as varchar)+''''步.''''+NodeName as NodeName,NodeId,1 from WF_FlowNode where FlowId=''+cast(@FlowId as varchar)+'' and NodeId in(''+@next_step+'') order by Step''
else 
	set @sel_sql=''select NodeName,NodeId,ss from (select ''''结束'''' as NodeName,-1 as NodeId,1 as ss,9999 as Step union select ''''第''''+cast(Step as varchar)+''''步.''''+NodeName as NodeName,NodeId,1 as ss,Step from WF_FlowNode where FlowId=''+cast(@FlowId as varchar)+'' and NodeId in(''+@next_step+'')) as A order by Step''
execute(@sel_sql)
end
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_QueryWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_QueryWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_QueryWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_QueryWork] 
@SearchArea varchar(2000),
@StartIndex int, 
@EndIndex int,
@UserId int,
@DeptId int,
@RangeTypeId int,
@StartUserId int,
@getcount int
AS
begin
declare @sel_sql as varchar(4000)
if @getcount<1
begin
	if @RangeTypeId=0 --所有范围
		set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, *  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and  ( [CreatorId]=''+cast(@UserId as varchar(12))+'' or [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1 or EXISTS (SELECT  [UserId] FROM [WF_FlowRunPrcs] as B where B.RunId=[WF_FlowRun].RunId and UserId=''+cast(@UserId as varchar(12))+''))    ) AS MyTable 
		where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
	else if @RangeTypeId=1 --我发起的 
		set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, *  FROM [WF_FlowRun]  where  ''+@SearchArea+''  and [CreatorId]=''+cast(@UserId as varchar(12))+''   ) AS MyTable 
		where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
	else if @RangeTypeId=2 --我办理过的 
		set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, *  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and EXISTS (SELECT  [UserId] FROM [WF_FlowRunPrcs] as B where B.RunId=[WF_FlowRun].RunId and UserId=''+cast(@UserId as varchar(12))+'')  ) AS MyTable 
		where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
	else if @RangeTypeId=3 --我管理的 
		set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, *  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1     ) AS MyTable 
		where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
	else if @RangeTypeId=4 --指定发起人 
	begin
		if @StartUserId >0 
			set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, *  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1 and [CreatorId]=''+cast(@StartUserId as varchar(12))+''   ) AS MyTable 
			where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
		else 
			set @sel_sql=''select *  from (select row_number() over(order by [RunId] desc)as dcx_rowid, *  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1    ) AS MyTable 
			where  dcx_rowid between ''+cast(@StartIndex as varchar(12))+'' and ''+cast(@EndIndex as varchar(12))+''''
	end
end
else 
begin
	if @RangeTypeId=0 --所有范围
		set @sel_sql=''select count(*) FROM [WF_FlowRun]  where  ''+@SearchArea+'' and ( [CreatorId]=''+cast(@UserId as varchar(12))+'' or [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1 or EXISTS (SELECT  [UserId] FROM [WF_FlowRunPrcs] as B where B.RunId=[WF_FlowRun].RunId and UserId=''+cast(@UserId as varchar(12))+''))''
	else if @RangeTypeId=1 --我发起的 
		set @sel_sql=''select count(*)  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [CreatorId]=''+cast(@UserId as varchar(12))+'' ''
	else if @RangeTypeId=2 --我办理过的 
		set @sel_sql=''select count(*)  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and EXISTS (SELECT  [UserId] FROM [WF_FlowRunPrcs] as B where B.RunId=[WF_FlowRun].RunId and UserId=''+cast(@UserId as varchar(12))+'') ''
	else if @RangeTypeId=3 --我管理的 
		set @sel_sql=''select count(*) FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1 ''
	else if @RangeTypeId=4 --指定发起人 
	begin
		if @StartUserId >0 
			set @sel_sql=''select count(*)  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1 and [CreatorId]=''+cast(@StartUserId as varchar(12))+'' ''
		else 
			set @sel_sql=''select count(*)  FROM [WF_FlowRun]  where  ''+@SearchArea+'' and [dbo].WF_CaMonitorFlow([FlowId],''+cast(@UserId as varchar(12))+'',''+cast(@DeptId as varchar(12))+'')=1  ''
	end
end 
--if @sel_sql is not null and @sel_sql!=''''
	execute(@sel_sql)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunFile_DeleteAttach]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunFile_DeleteAttach]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunFile_DeleteAttach]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunFile_DeleteAttach] 
@AttachmentIds varchar (500)
AS
begin
if @AttachmentIds='''' or @AttachmentIds is null
return
declare @sel_sql as varchar (400)
set @sel_sql=''delete from WF_FlowRunFile where FileId in(''+@AttachmentIds+'')''
 execute(@sel_sql)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunFile_GetAttFilePath]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunFile_GetAttFilePath]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunFile_GetAttFilePath]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunFile_GetAttFilePath]
@AttachmentIds varchar(500)
AS
BEGIN
declare @sel_sql as varchar (400)
if @AttachmentIds='''' or @AttachmentIds is null
begin
select FilePath from WF_FlowRunFile where FileId=-1
return
end
else
begin
set @sel_sql=''select FilePath from WF_FlowRunFile where FileId in(''+@AttachmentIds+'')''
execute(@sel_sql)
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_Depute]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_Depute]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_Depute]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--委托 
Create PROCEDURE [dbo].[DcxRun_WF_RunPrcs_Depute]
@FlowId int,
@RunId int,
@PrcsId int,
@MainUserId int,
@UserId int,
@UserName varchar(100),
@DealIds varchar(4000)
AS
update [WF_FlowRunPrcs] set [MainUserId]=@MainUserId,[UserId]=@UserId,[UserName]=@UserName,
[PrcsFlag]=1,[DealIds]=@DealIds where  [FlowId]=@FlowId and  [RunId]=@RunId and [PrcsId]=@PrcsId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetCurrentPrcsMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetCurrentPrcsMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetCurrentPrcsMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetCurrentPrcsMsg]--获取经办工作,此存储过程增加了分分页的功能
@FlowId int,
@EntId int,
@KeyFieldValue as varchar(50)
AS
begin
declare @RunId int 
SELECT @RunId=[RunId] FROM [WF_FlowRun] where [FlowId]=@FlowId and [EntId]=@EntId  and [KeyFieldValue]=@KeyFieldValue  
SELECT top 1 [PrcsId]
      ,[RunId]
      ,[RunName]
      ,[FlowId]
      ,[FlowName]
      ,[NodeId]
      ,[UserId]
      ,[UserName]
  FROM [WF_FlowRunPrcs] where RunId=@RunId and ( [PrcsFlag]=1 or [PrcsFlag]=2)  order by [PrcsId] desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetDealManByPAndD]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetDealManByPAndD]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetDealManByPAndD]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetDealManByPAndD] --获取按职位，部门而定的经办人
@position_id varchar(50),
@dept_id  varchar(50)
AS
if @dept_id!=''-1''--/当部门Id不为空时
select Dcx_User.[UserId] as UserId,Dcx_User.[RealName] as real_name from 
Dcx_User  where Dcx_User.[PositionId]=@position_id  or Dcx_User.[DeptId]=@dept_id  
else--当部门Id为空时
 select Dcx_User.[UserId] as UserId,Dcx_User.[RealName] as real_name from 
Dcx_User  where Dcx_User.[PositionId]=@position_id  
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetFlowStepIds]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetFlowStepIds]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetFlowStepIds]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetFlowStepIds]
@PrcsId int
AS
select WF_FlowRunPrcs.RunId,WF_FlowRunPrcs.NodeId,UserId,WF_FlowRun.FlowId,WF_FlowType.EntId,WF_FlowRun.HtmlStr
,WF_FlowType.FlowName,WF_FlowNode.PrcsItem,WF_FlowRunPrcs.ParentId,PrcsFlag from WF_FlowRunPrcs  inner join WF_FlowRun on 
WF_FlowRunPrcs.PrcsId=@PrcsId and
 WF_FlowRunPrcs.RunId=WF_FlowRun.RunId  inner join WF_FlowType 
 on WF_FlowRun.FlowId=WF_FlowType.FlowId inner join WF_FlowNode on WF_FlowNode.NodeId=WF_FlowRunPrcs.NodeId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetManForConsign]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetManForConsign]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetManForConsign]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetManForConsign]--获取人员，用于托使用
@PrcsId int
AS
declare @user_ids as varchar(1000)
/*这部分代码还没完善，还没有考虑当用户设置为谁接到谁做的情况，以后再加*/
--declare @flag as int
--declare @NodeId as int
--select @flag=FirstManFlag,@NodeId=NodeId from WF_FlowRunPrcs where PrcsId=@PrcsId
--if @flag=0 
--begin
select @user_ids=DealIds from WF_FlowRunPrcs where PrcsId=@PrcsId
if @user_ids<>'''' and @user_ids<>null 
begin 
set @user_ids=''0''+@user_ids+''0''
declare @sel_sql as varchar(1000)
set @sel_sql=''select [Dcx_User].[RealName] as real_name,[Dcx_User].[UserId] as UserId from [Dcx_User] where [Dcx_User].[UserId] in(''+@user_ids+'')''
execute(@sel_sql)
end
else
begin
select [Dcx_User].[RealName] as real_name,[Dcx_User].[UserId] as UserId from [Dcx_User] where [Dcx_User].[UserId]=-1
end
/*
end
else
begin
*/
--select @user_ids=PrcsUsers
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetMyOneUndoWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetMyOneUndoWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetMyOneUndoWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetMyOneUndoWork]--获取经办工作,此存储过程增加了分分页的功能
@UserId int, 
@FlowId int,
@EntId int,
@KeyFieldValue as varchar(50)
AS
begin
declare @t1 as varchar(20)--用户Id like
declare @t2 as varchar(20)--角色Id like
declare @role_id as int
declare @pos_id as int
declare @dept_id as int
declare @p_d as varchar(20)
--获取用户的角色Id
select top 1 @role_id=[RoleId] from [Dcx_UserInRole] where [UserId]=@UserId and [IsMainRole]=1
 --获取用户的职位Id，部门Id
select  top 1 @pos_id=[PositionId],@dept_id=[DeptId] from [Dcx_User] where [UserId]=@UserId
set @p_d=cast(@pos_id as varchar)+'',''+cast(@dept_id as varchar)
--用户Id like
set @t1=''%,''+cast(@UserId as varchar)+'',%''
--角色Id like
set @t2=''%,''+cast(@role_id as varchar)+'',%''
declare @RunId int 
SELECT @RunId=[RunId] FROM [WF_FlowRun] where [FlowId]=@FlowId and [EntId]=@EntId and [FinishFlag]=0 and [KeyFieldValue]=@KeyFieldValue  
SELECT top 1 [PrcsId]
      ,[RunId]
      ,[RunName]
      ,[FlowId]
      ,[FlowName]
      ,[NodeId]
      ,[PrcsName]
      ,[UserId]
,(case when [UserId]=@UserId and [UserId] is not null then 0 else 1 end) as IsSign
      ,[UserName]
      ,[DealIds]
      ,[PrcsTime]
      ,[DeliverTime]
      ,[PrcsFlag]
      ,[NextPrcsId]
      ,[ParentId]
      ,[FirstManFlag]
      ,[Step]
      ,[FirstStepFlag]
      ,[Step]
      ,[CreatorBoss]
      ,[PositionDept]
      ,[Creator]
      ,[PrcsUsers]
      ,[PrcsRoles]
      ,[CreatorName]
      ,[EntId]
      ,[EntName]
      ,[TransactorS]
  FROM [WF_FlowRunPrcs] where RunId=@RunId and ( [PrcsFlag]=1 or [PrcsFlag]=2) 
 and ( (FirstManFlag=0 and (UserId=@UserId or DealIds like @t1)) or 
(FirstManFlag=1 and (PrcsUsers like @t1 or PrcsRoles 
like @t2 or PositionDept=@p_d or (Creator=@UserId) or 
(CreatorBoss like @t1)))) order by [PrcsId] desc
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetNodeId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetNodeId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetNodeId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetNodeId]
@FlowId int,
@RunId int,
@PrcsId int
AS
select  NodeId from  WF_FlowRunPrcs  where 
[FlowId]=@FlowId and RunId=@RunId and PrcsId=@PrcsId   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetPrcsFlag]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetPrcsFlag]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetPrcsFlag]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetPrcsFlag] 
@PrcsId int
AS
	select PrcsFlag from WF_FlowRunPrcs where PrcsId=@PrcsId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetPrcsMsg1]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetPrcsMsg1]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetPrcsMsg1]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetPrcsMsg1]
@FlowId int,
@RunId int,
@PrcsId int
AS
select  [UserId], [WorkCreatorId],NodeId from  WF_FlowRunPrcs  where 
[FlowId]=@FlowId and RunId=@RunId and PrcsId=@PrcsId   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetPrcsUsers]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetPrcsUsers]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetPrcsUsers]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetPrcsUsers] 
@RunId int,
@NodeId int
AS
BEGIN
declare @CreatorBoss as varchar(1000) 
declare @CreatorName as varchar(50) 
declare @CreatorId int
SELECT @CreatorId=[CreatorId],@CreatorName=[CreatorName] from [WF_FlowRun]  where [RunId]=@RunId
set @CreatorId=isnull(@CreatorId,'''')
set @CreatorName=isnull(@CreatorName,'''')
SELECT PositionDept
,'''' as [CreatorBoss],@CreatorId as [CreatorId]
,PrcsUsers,PrcsRoles,Step, @CreatorName as CreatorName
FROM WF_FlowNode  where NodeId=@NodeId
--,(case when AllowWorkCreator>0 then @CreatorId else '''' end) as [CreatorId]
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetRoleMan]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetRoleMan]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetRoleMan]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetRoleMan]--获取角色人员 
@NodeId int 
AS
declare @PrcsRoles as varchar(300)
set @PrcsRoles=''''
select @PrcsRoles=PrcsRoleNames from WF_FlowNode where NodeId=@NodeId
if @PrcsRoles='''' or @PrcsRoles is null
return 
set @PrcsRoles=@PrcsRoles
--declare @sel_sql as varchar(5000)
select [Dcx_UserRoleView].[UserId] as UserId,[Dcx_UserRoleView].[RealName] as real_name from [Dcx_UserRoleView]
where     @PrcsRoles  like ''%,''+ltrim(rtrim([Dcx_UserRoleView].[RoleName]))+'',%'' 
--execute(@sel_sql)
--旧版本
--declare @PrcsRoles as varchar(300)
--set @PrcsRoles=''''
--select @PrcsRoles=PrcsRoles from WF_FlowNode where NodeId=@NodeId
--if @PrcsRoles='''' or @PrcsRoles is null
--return 
--set @PrcsRoles=''0''+@PrcsRoles+''0''
--declare @sel_sql as varchar(5000)
--set @sel_sql=''select hyoa_role_leaguer.UserId,hyoa_user.real_name from hyoa_role_leaguer  inner join  hyoa_user
-- on  role_id in (''+@PrcsRoles+'') and hyoa_role_leaguer.UserId=hyoa_user.UserId ''
--execute(@sel_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetSelectDealMan]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_GetSelectDealMan]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_GetSelectDealMan]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_GetSelectDealMan] 
@RunId int,
@NodeId int
AS
declare @DealIds as varchar(1000)
select @DealIds=DealIds from WF_FlowRunPrcs where RunId=@RunId and NodeId=@NodeId
if @DealIds='''' or @DealIds is null
return
set @DealIds=''0''+@DealIds+''0''
declare @sel_sql as varchar(1000)
set @sel_sql=''select [UserId] as UserId,[RealName] as real_name from [Dcx_User] where [UserId] in(''+@DealIds+'')''
execute(@sel_sql)
 	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_SetStepFinish]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_SetStepFinish]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_SetStepFinish]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_SetStepFinish]
@PrcsId int 
	/*
	(
	@parameter1 int = 5,
	@parameter2 datatype OUTPUT
	)
	*/
AS
update WF_FlowRunPrcs set PrcsFlag=4 where PrcsId=@PrcsId
	/* SET NOCOUNT ON */ 
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_SetWorkDealing]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_SetWorkDealing]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_SetWorkDealing]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_SetWorkDealing] --将一个步骤设置为正在办理，即值为2
@PrcsId int
AS
	update WF_FlowRunPrcs set PrcsFlag=2 where PrcsId=@PrcsId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateDealedState]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_UpdateDealedState]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateDealedState]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_UpdateDealedState] 
@FlowId int ,
@RunId int ,
@PrcsId int ,
@PrcsFlag int,
@NextPrcsId int,
@UserId int,
--@FormOpType int,--表单操作类别。1，添加；2，编辑；3，删除
@KeyFieldValue varchar(50)
AS
begin
--update WF_FlowRunPrcs set PrcsTime=getdate(),PrcsFlag=@PrcsFlag,
--NextPrcsId=@NextPrcsId,UserId=@UserId,FirstManFlag=0 where [RunId]=@RunId and PrcsId=@PrcsId
update WF_FlowRunPrcs set PrcsTime=getdate(),PrcsFlag=@PrcsFlag,
NextPrcsId=@NextPrcsId,UserId=@UserId,FirstManFlag=0 where [RunId]=@RunId and PrcsId=@PrcsId
if @NextPrcsId<1 and (@PrcsFlag=3 or @PrcsFlag=4) --结束流程
begin
	if @KeyFieldValue is not null and ltrim(rtrim(@KeyFieldValue))!=''''
	 update WF_FlowRun set [KeyFieldValue]=@KeyFieldValue,[FinishFlag]=1 where FlowId=@FlowId and RunId=@RunId
	else
	 update WF_FlowRun set [FinishFlag]=1 where FlowId=@FlowId and RunId=@RunId
	 update WF_FlowRunPrcs set PrcsFlag=4 where RunId=@RunId and  PrcsFlag=3 
end
else  if @KeyFieldValue is not null and ltrim(rtrim(@KeyFieldValue))!=''''
	 update WF_FlowRun set [KeyFieldValue]=@KeyFieldValue where FlowId=@FlowId and RunId=@RunId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateDealedState2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_UpdateDealedState2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateDealedState2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_UpdateDealedState2] 
@FlowId int ,
@RunId int ,
@PrcsId int ,
@PrcsFlag int,
@NextPrcsId int,
@UserId int,
@IsRebut int
AS
begin
update WF_FlowRunPrcs set PrcsTime=getdate(),PrcsFlag=@PrcsFlag,[IsRebut] = @IsRebut,
NextPrcsId=@NextPrcsId,UserId=@UserId,FirstManFlag=0 where [RunId]=@RunId and PrcsId=@PrcsId
if @NextPrcsId<1 and (@PrcsFlag=3 or @PrcsFlag=4) --结束流程
begin
 update WF_FlowRun set FinishFlag=1 where FlowId=@FlowId and RunId=@RunId
 update WF_FlowRunPrcs set PrcsFlag=4 where RunId=@RunId and  PrcsFlag=3 
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateFeedback]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_UpdateFeedback]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateFeedback]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_UpdateFeedback] 
@Feedback varchar(8000),
@PrcsId int,
@form_id int 
AS
declare @up_sql as varchar(100)
declare @table_name as  varchar(8000)
select distinct @table_name=[DBTableName] from [Dcx_Entity_Run] where [EntId]=@form_id
set @up_sql=''update ''+@table_name +'' set [WFOpinion]=''''''+@Feedback+'''''' where
 PrcsId=''+cast(@PrcsId as varchar)
 execute(@up_sql)
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateFrontForMan]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_UpdateFrontForMan]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateFrontForMan]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_UpdateFrontForMan]--修改主办人 
@UserId int,
@PrcsId int
AS
update WF_FlowRunPrcs set UserId=@UserId where PrcsId=@PrcsId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateMainMan]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_UpdateMainMan]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdateMainMan]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_UpdateMainMan] 
@UserId int,
@RunId int,
@NodeId int
AS
	update WF_FlowRunPrcs set UserId=@UserId where RunId=@RunId and NodeId=@NodeId
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdatePrcsIsFinish]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_RunPrcs_UpdatePrcsIsFinish]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_RunPrcs_UpdatePrcsIsFinish]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_RunPrcs_UpdatePrcsIsFinish] 
@PrcsId int ,
@PrcsTime datetime,
@PrcsFlag int,
@NextPrcsId int,
@UserId int,
@ParentId int
AS
begin
--update WF_FlowRunPrcs set PrcsTime=@PrcsTime,PrcsFlag=@PrcsFlag,
--NextPrcsId=@NextPrcsId,UserId=@UserId,FirstManFlag=0 where PrcsId=@PrcsId
update WF_FlowRunPrcs set PrcsTime=@PrcsTime,PrcsFlag=4,
NextPrcsId=@NextPrcsId,UserId=@UserId,FirstManFlag=0 where PrcsId=@PrcsId
--update WF_FlowRunPrcs set PrcsFlag=4 where PrcsId=@ParentId
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetNodePlace]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_SetNodePlace]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetNodePlace]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_SetNodePlace]
@FlowId int ,
@NodeId int ,
@Pointx int ,
@Pointy int 
AS
UPDATE [WF_FlowNode] SET [Pointx] =@Pointx ,[Pointy] = @Pointy WHERE [FlowId]=@FlowId and NodeId=@NodeId
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetNodeVld]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_SetNodeVld]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetNodeVld]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_SetNodeVld]
@strVld varchar(max) ,
@FlowId int ,
@NodeId int 
AS
update WF_FlowNode set Json_Validate=@strVld where [FlowId]=@FlowId and NodeId=@NodeId
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetPrcsFlagTo2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_SetPrcsFlagTo2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetPrcsFlagTo2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_SetPrcsFlagTo2]
@FlowId int,
@RunId int,
@PrcsId int,
@UserId int
AS
UPDATE [WF_FlowRunPrcs] SET  [PrcsFlag] = 2,AcceptTime=getdate()
 WHERE [RunId]=@RunId and PrcsId=@PrcsId and [PrcsFlag]=1
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetPrcsFlagTo2_2]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_SetPrcsFlagTo2_2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_SetPrcsFlagTo2_2]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_SetPrcsFlagTo2_2]
@FlowId int,
@RunId int,
@PrcsId int,
@UserId int,
@IsRebut int
AS
UPDATE [WF_FlowRunPrcs] SET  [PrcsFlag] = 2,[IsRebut] = @IsRebut,AcceptTime=getdate()
 WHERE [RunId]=@RunId and PrcsId=@PrcsId and [PrcsFlag]=1
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_TakeBackWork]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WF_TakeBackWork]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WF_TakeBackWork]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WF_TakeBackWork]  --收回工作
@FlowId int,
@RunId int,
@PrcsId int,  --我已办理过的任何
@UserId int
AS
declare @PrcsFlag  int
--declare @to  int
declare @NextPrcsId  int
if  @PrcsId<1 or @RunId<1
	return
set @NextPrcsId=-13
set @PrcsFlag=-15
select @NextPrcsId=[NextPrcsId],@PrcsFlag=[PrcsFlag] from WF_FlowRunPrcs where [RunId]=@RunId and [PrcsId]=@PrcsId and [UserId]=@UserId
if @PrcsFlag is null or @PrcsFlag=-15 or @NextPrcsId=-13 or @NextPrcsId is null
begin
	select -1 --工作无法找到，获取已被删除
	return
end
if @PrcsFlag=1 or @PrcsFlag=2 
begin
	select -2 --要收回的工作，还没办理
	return
end
if @NextPrcsId=-1 or @NextPrcsId=0
begin
	select -3 --流程已结束
	return
end
if @NextPrcsId is null
begin
	select -4 --无下一节点，无需收回
	return
end
if @NextPrcsId!=-1 and @NextPrcsId is not null and @NextPrcsId>0  --下一工作节点被找到
begin
	set @PrcsFlag=-15
	select @PrcsFlag=PrcsFlag,@NextPrcsId=PrcsId from WF_FlowRunPrcs where  [RunId]=@RunId and PrcsId=@NextPrcsId and ParentId=@PrcsId
	if @PrcsFlag=1 --下一工作没被接收
	begin
		delete from WF_FlowRunPrcs where  [RunId]=@RunId and PrcsId=@NextPrcsId
		update WF_FlowRunPrcs set PrcsFlag=2 where  [RunId]=@RunId and PrcsId=@PrcsId
	end
	else 
	begin
		select -5 --下一节点的工作已被接收，无法收回
		return
	end
end
else  --下一工作节点无法找到，即更新自己的节点，令进入未提交状态的可办理状态
begin
	update WF_FlowRunPrcs set PrcsFlag=2 where  [RunId]=@RunId and PrcsId=@PrcsId
end
	select 1
RETURN 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetter_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_WLetter_Delete](@userId int, @lId int)
as
begin
--set nocount on
		delete from [Dcx_WLetter] WHERE [SenderId]=@userId  and [LId]=@lId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetter_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WLetter_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WLetter]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [SenderId]=@userId   
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WLetter]  where  [SentDate]>@fromDate  and [SenderId]=@userId  
				end
				else 
				begin
							select count(1)  from [Dcx_WLetter]  where  [SentDate]<@toDate and [SenderId]=@userId  
				end
		end
		else
		begin
				select count(1)  from [Dcx_WLetter]  where  [SenderId]=@userId  
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WLetter]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [SenderId]=@userId    and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WLetter]  where  [SentDate]>@fromDate  and [SenderId]=@userId   and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_WLetter]  where  [SentDate]<@toDate and [SenderId]=@userId   and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_WLetter]  where  [SenderId]=@userId   and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetter_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_WLetter_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_WLetter_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_WLetter_GetTopWLetter]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_WLetter_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetter_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WLetter_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId=3
set @tagId=0
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow   
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate  and [SenderId]=@userId  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]<@toDate and [SenderId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
						where [SenderId]=@userId  
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId
					end
					else if @toDate is  null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate  and [SenderId]=@userId
					end
					else 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]<@toDate and [SenderId]=@userId
					end
			end
			else
			begin
								select  top 200  0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SenderId]=@userId  
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate  and [SenderId]=@userId  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]<@toDate and [SenderId]=@userId and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
						where [SenderId]=@userId   and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]>@fromDate  and [SenderId]=@userId  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SentDate]<@toDate and [SenderId]=@userId  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  0 as [RcvId],0 as [IsPublic],[IsTop],[LId],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetter]  
								where [SenderId]=@userId   and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetTopWLetter]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetter_GetTopWLetter]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetter_GetTopWLetter]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_WLetter_GetTopWLetter]
@tagId int,
@userId int
AS
BEGIN 
select -1
	return 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_WLetter where [SenderId]=@userId   
else
	 select 1 as dcx_rowid,*  from Dcx_WLetter where [SenderId]=@userId   and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetterRcv_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_WLetterRcv_Delete](@userId int, @lId int)
as
begin
--set nocount on
		delete from [Dcx_WLetterRcv] WHERE [ReceiverId]=@userId  and [LId]=@lId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetterRcv_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WLetterRcv_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WLetterRcv]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [ReceiverId]=@userId   
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WLetterRcv]  where  [SentDate]>@fromDate  and [ReceiverId]=@userId  
				end
				else 
				begin
							select count(1)  from [Dcx_WLetterRcv]  where  [SentDate]<@toDate and [ReceiverId]=@userId  
				end
		end
		else
		begin
				select count(1)  from [Dcx_WLetterRcv]  where  [ReceiverId]=@userId  
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WLetterRcv]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [ReceiverId]=@userId    and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WLetterRcv]  where  [SentDate]>@fromDate  and [ReceiverId]=@userId   and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_WLetterRcv]  where  [SentDate]<@toDate and [ReceiverId]=@userId   and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_WLetterRcv]  where  [ReceiverId]=@userId   and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetterRcv_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_WLetterRcv_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_WLetterRcv_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_WLetterRcv_GetTopWLetterRcv]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_WLetterRcv_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetterRcv_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WLetterRcv_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow   
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
						where [ReceiverId]=@userId  
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId
					end
					else if @toDate is  null 
					begin
								select   top 200 [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId
					end
					else 
					begin
								select   top 200 [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId
					end
			end
			else
			begin
								select  top 200  [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [ReceiverId]=@userId  
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
						where [ReceiverId]=@userId   and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  [RcvId],[LId],[MsgContent],[ReadTime],[IsPublic],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WLetterRcv]  
								where [ReceiverId]=@userId   and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetTopWLetterRcv]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WLetterRcv_GetTopWLetterRcv]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WLetterRcv_GetTopWLetterRcv]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_WLetterRcv_GetTopWLetterRcv]
@tagId int,
@userId int
AS
BEGIN 
select -1
	return 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_WLetterRcv where [ReceiverId]=@userId   
else
	 select 1 as dcx_rowid,*  from Dcx_WLetterRcv where [ReceiverId]=@userId   and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMail_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_WMail_Delete](@userId int, @mId int)
as
begin
--set nocount on
		delete from [Dcx_WMail] WHERE [SenderId]=@userId  and [MId]=@mId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMail_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WMail_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WMail]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [SenderId]=@userId   
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WMail]  where  [SentDate]>@fromDate  and [SenderId]=@userId  
				end
				else 
				begin
							select count(1)  from [Dcx_WMail]  where  [SentDate]<@toDate and [SenderId]=@userId  
				end
		end
		else
		begin
				select count(1)  from [Dcx_WMail]  where  [SenderId]=@userId  
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WMail]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [SenderId]=@userId    and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WMail]  where  [SentDate]>@fromDate  and [SenderId]=@userId   and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_WMail]  where  [SentDate]<@toDate and [SenderId]=@userId   and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_WMail]  where  [SenderId]=@userId   and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMail_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_WMail_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_WMail_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_WMail_GetTopWMail]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_WMail_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMail_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WMail_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId=3
set @tagId=0
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow   
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
								where [SentDate]>@fromDate  and [SenderId]=@userId  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
								where [SentDate]<@toDate and [SenderId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
						where [SenderId]=@userId  
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId
					end
					else if @toDate is  null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SentDate]>@fromDate  and [SenderId]=@userId
					end
					else 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SentDate]<@toDate and [SenderId]=@userId
					end
			end
			else
			begin
								select  top 200  0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SenderId]=@userId  
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
								where [SentDate]>@fromDate  and [SenderId]=@userId  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
								where [SentDate]<@toDate and [SenderId]=@userId and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail]  
						where [SenderId]=@userId   and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SentDate]>@fromDate and [SentDate]<@toDate and [SenderId]=@userId  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SentDate]>@fromDate  and [SenderId]=@userId  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SentDate]<@toDate and [SenderId]=@userId  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  0 as [RcvId],0 as [IsPublic],[IsTop],[MId],[Title],[MsgContent],[SenderId],[SenderName],[SentDate],[SenderDelete],[ColorId],[ReceiverUserIds],[ReceiverUserNames],[MeetReceipt],[HaveAttachment],[FileJson],[TagId]  FROM [Dcx_WMail] 								where [SenderId]=@userId   and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetTopWMail]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMail_GetTopWMail]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMail_GetTopWMail]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_WMail_GetTopWMail]
@tagId int,
@userId int
AS
BEGIN 
select -1
	return 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_WMail where [SenderId]=@userId   
else
	 select 1 as dcx_rowid,*  from Dcx_WMail where [SenderId]=@userId   and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMailRcv_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--删除一条
CREATE PROC [dbo].[DcxRun_WMailRcv_Delete](@userId int, @mId int)
as
begin
--set nocount on
		delete from [Dcx_WMailRcv] WHERE [ReceiverId]=@userId  and [MId]=@mId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMailRcv_GetCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WMailRcv_GetCount]
(
@tagId int,
	@userId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
if @tagId<1
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WMailRcv]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [ReceiverId]=@userId   
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WMailRcv]  where  [SentDate]>@fromDate  and [ReceiverId]=@userId  
				end
				else 
				begin
							select count(1)  from [Dcx_WMailRcv]  where  [SentDate]<@toDate and [ReceiverId]=@userId  
				end
		end
		else
		begin
				select count(1)  from [Dcx_WMailRcv]  where  [ReceiverId]=@userId  
		 end
end
else 
begin
		if @fromDate is not null  or @toDate is not null 
		begin
				if @fromDate is not null  and @toDate is not null 
				begin
							select count(1)  from [Dcx_WMailRcv]  where  [SentDate]>@fromDate 
							and [SentDate]<@toDate and [ReceiverId]=@userId    and [TagId]=@tagId
				end
				else if @toDate is  null 
				begin
							select count(1)  from [Dcx_WMailRcv]  where  [SentDate]>@fromDate  and [ReceiverId]=@userId   and [TagId]=@tagId
				end
				else 
				begin
							select count(1)  from [Dcx_WMailRcv]  where  [SentDate]<@toDate and [ReceiverId]=@userId   and [TagId]=@tagId
				end
		end
		else
		begin
				select count(1)  from [Dcx_WMailRcv]  where  [ReceiverId]=@userId   and [TagId]=@tagId
		 end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetForFirstTime]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMailRcv_GetForFirstTime]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetForFirstTime]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--加载时，第一次调用
CREATE PROCEDURE [dbo].[DcxRun_WMailRcv_GetForFirstTime]
@tagId2 int,
@userId2 int,
@pageSize2 int
AS
BEGIN 
EXEC	[DcxRun_WMailRcv_GetList]
@tagId = @tagId2,@pageIndex = 1,@pageSize = @pageSize2,@userId = @userId2,@fromDate = null,@toDate = null
EXEC	[DcxRun_WMailRcv_GetTopWMailRcv]
		@tagId = @tagId2,@userId = @userId2
EXEC	[DcxRun_WMailRcv_GetCount]
		@tagId = @tagId2,@userId = @userId2,@fromDate = null,@toDate = null
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMailRcv_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[DcxRun_WMailRcv_GetList]
(
	@pageSize int,
	@pageIndex int,
	@userId int,
	@tagId int,
	@fromDate datetime,
	@toDate datetime
)
AS
begin
DECLARE @startRow int
DECLARE @endRow   int
if @pageSize is null or @pageSize<1
	set @pageSize=20
if @pageIndex is null or @pageIndex<1
	set @pageIndex=1
SET @startRow = (@pageIndex - 1) * @pageSize +1
SET @endRow = @startRow + @pageSize -1 
if @tagId<1
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow   
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId  
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId 
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
						where [ReceiverId]=@userId  
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId
					end
					else if @toDate is  null 
					begin
								select   top 200 [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId
					end
					else 
					begin
								select   top 200 [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId
					end
			end
			else
			begin
								select  top 200  [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [ReceiverId]=@userId  
			 end
	end
end
else 
begin
	if @pageSize>0 or @pageIndex>0
	begin
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId   and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else if @toDate is  null 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId  and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
					else 
					begin
							select *  from (
								select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId and [TagId]=@tagId
							) AS MyTable  where  dcx_rowid between @startRow and @endRow 
					end
			end
			else
			begin
					  select *  from (
						select row_number() over( order by [SentDate] desc)as dcx_rowid, [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
						where [ReceiverId]=@userId   and [TagId]=@tagId
					  ) AS MyTable  where  dcx_rowid between @startRow and @endRow 
			 end
	end
	else
	begin  
			if @fromDate is not null  or @toDate is not null 
			begin
					if @fromDate is not null  and @toDate is not null 
					begin
								select   top 200 [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate and [SentDate]<@toDate and [ReceiverId]=@userId  and [TagId]=@tagId
					end
					else if @toDate is  null 
					begin
								select   top 200 [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]>@fromDate  and [ReceiverId]=@userId  and [TagId]=@tagId and [TagId]=@tagId
					end
					else 
					begin
								select   top 200 [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [SentDate]<@toDate and [ReceiverId]=@userId  and [TagId]=@tagId
					end
			end
			else
			begin
								select  top 200  [RcvId],[MId],[Title],[MsgContent],[ReadTime],[IsPublic],[IsCollect],[IsTop],[IsRead],[SenderId],[SenderName],[SentDate],[ColorId],[FileJson],[TagId]  FROM [Dcx_WMailRcv]  
								where [ReceiverId]=@userId   and [TagId]=@tagId
			 end
	end
end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetTopWMailRcv]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[DcxRun_WMailRcv_GetTopWMailRcv]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[DcxRun_WMailRcv_GetTopWMailRcv]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取置顶消息
CREATE PROCEDURE [dbo].[DcxRun_WMailRcv_GetTopWMailRcv]
@tagId int,
@userId int
AS
BEGIN 
select -1
	return 
if @userId is null or @userId<1
	return 
 if @tagId<1
	 select 1 as dcx_rowid,*  from Dcx_WMailRcv where [ReceiverId]=@userId   
else
	 select 1 as dcx_rowid,*  from Dcx_WMailRcv where [ReceiverId]=@userId   and [TagId]=@tagId
 end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[dms_getTotalDataCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[dms_getTotalDataCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[dms_getTotalDataCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取某个表的符合某个条件的数据个数
CREATE PROCEDURE [dbo].[dms_getTotalDataCount]
@Tables VARCHAR(1000), --表的名称
@Where  VARCHAR(1000)=''''  --条件
AS
SET NOCOUNT ON
  DECLARE @SQL VARCHAR(3000)
  IF @Where IS NOT NULL AND LEN(LTRIM(RTRIM(@Where)))!=0 BEGIN
      SET @SQL = '' SELECT COUNT(*) AS Total FROM [''+@Tables +'']WHERE ''+@Where
  END
  ELSE BEGIN
     SET @SQL = '' SELECT COUNT(*) AS Total From[''+@Tables+'']''
  END
  EXEC(@SQL)
SET NOCOUNT OFF
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[dms_pager]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[dms_pager]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[dms_pager]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
---分页存储过程（该存储过程用在除了主表数据和申请外的所有表格)
CREATE PROCEDURE [dbo].[dms_pager]
@Tables VARCHAR(1000), --表名，视图
@PrimaryKey VARCHAR(100),--主关键字
@Sort       VARCHAR(200) = NULL,--排序语句，不带Order By 比如：NewsId Desc,OrderRows Asc
@CurrentPage INT = 1,--当前页码
@PageSize  INT = 10,--分页尺寸
@Fields    VARCHAR(1000)=''*'',--选取的字段
@Filter VARCHAR(1000)=NULL, --过滤语句，不带Where 
@Group  VARCHAR(1000)=NULL --Group语句,不带Group By
AS
SET NOCOUNT ON
    declare @strTmp varchar(110)
    declare @strOrder varchar(400)
    declare @strSQL   varchar(5000)
   if @Sort is not null and len(ltrim(rtrim(@Sort)))!= 0 begin
      set @Sort = ''  , ''+@Sort
  end
    set @strTmp = ''<(select min''
    set @strOrder='' order by [''+@PrimaryKey+''] desc''
    if @CurrentPage = 1 begin
         if @Filter is not null and len(ltrim(rtrim(@Filter)))!=0 
              set @strSQL = '' select top ''+CAST(@PageSize as varchar)+'' ''+@Fields+'' FROM [''+@Tables+''] where ''+@Filter+'' ''+@strOrder+@Sort
          else
              set @strSQL = '' select top ''+CAST(@PageSize as varchar)+'' ''+@Fields+'' FROM [''+@Tables+'']''+@strOrder+@Sort
     end
     else begin
       set @strSQL = '' select top ''+CAST(@PageSize as varchar) + '' ''+@Fields+ '' from [''+@Tables+''] where [''+@PrimaryKey+'']''+
                     @strTmp+''([''+@PrimaryKey+'']) from (select top ''+CAST((@CurrentPage-1)*@PageSize as varchar)+'' [''+@PrimaryKey+''] from [''+@Tables+
                     '']''+ @strOrder+@Sort+'') as tblTmp)''+@strOrder+@Sort
       if @Filter is not null and len(ltrim(rtrim(@Filter)))!=0 
          set @strSQL = '' select top ''+CAST(@PageSize AS VARCHAR)+'' ''+@Fields+'' from[''+@Tables+''] where [''+@PrimaryKey+'']''+@strTmp+
                        ''([''+@PrimaryKey+'']) from(select top ''+CAST((@CurrentPage-1)*@PageSize as varchar)+'' [''+@PrimaryKey+''] from[''+
                        @Tables+'']where ''+@Filter+'' ''+@strOrder+@Sort+'')as tblTmp)and ''+@Filter+'' ''+@strOrder+@Sort
     end
     exec(@strSQL)
SET NOCOUNT OFF
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_DeleteOnlineUserByUserIdorIP]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[FZET_DeleteOnlineUserByUserIdorIP]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_DeleteOnlineUserByUserIdorIP]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[FZET_DeleteOnlineUserByUserIdorIP]
@UserId int,
@Ip char(20)
AS
delete FROM [Dcx_OnlineUser] WHERE [UserId]=@UserId or [IP]=@Ip
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_GetDBDataTableMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[FZET_GetDBDataTableMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_GetDBDataTableMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[FZET_GetDBDataTableMsg] 
@TableName varchar(100)
AS
BEGIN
 SELECT    
[name]       =a.name,   
[datatype]   =b.name,   
[Identity]   =case   when   COLUMNPROPERTY(   a.id,a.name,''IsIdentity'')=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
[key]        =case   when   exists(SELECT 1 FROM sysobjects where xtype=''PK'' and name in (SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then cast(1 as bit) else cast(0 as bit) end,   
[encodedname]=a.name,   
[nulls]      =case   when   a.isnullable=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
[size]       =a.length,   
[precision]  =COLUMNPROPERTY(a.id,a.name,''PRECISION''),   
[scale]      =isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0),   
[default]    =isnull(e.text,''''),   
[字段说明]   =isnull(g.[value],''''), 
[id]         =case   when   a.colorder=1   then   cast(1 as bit)    else   cast(0 as bit) end,
[表名]       =case   when   a.colorder=1   then   d.name   else   ''''   end,
[表说明]     =case   when   a.colorder=1   then   isnull(f.value,'''')   else   ''''   end,
[字段序号]   =a.colorder
FROM   syscolumns   a   
left   join   systypes   b   on   a.xtype=b.xusertype   
inner   join   sysobjects   d   on   a.id=d.id     and   d.xtype=''U''   and     d.name<>''dtproperties''   
left   join   syscomments   e   on   a.cdefault=e.id   
left   join   sys.extended_properties   g   on   a.id=g.major_id   and   a.colid=g.minor_id       
left   join   sys.extended_properties   f   on   d.id=f.major_id   and   f.minor_id=0  
--left join  sys.sp_addextendedproperty dd  on   a.name=dd.name  
where   d.name=@TableName  order   by   a.colorder  
--            SELECT 
--            	   (case when a.colorder=1 then d.name else d.name end)表名,
--                   a.colorder 字段序号,
--                   a.name 字段名,
--                   (case when COLUMNPROPERTY( a.id,a.name,''IsIdentity'')=1 then ''√''else '''' end) 标识,
--                   (case when (SELECT count(*)
--                   FROM sysobjects
--                   WHERE (name in
--                             (SELECT name
--                            FROM sysindexes
--                            WHERE (id = a.id) AND (indid in
--                                      (SELECT indid
--                                     FROM sysindexkeys
--                                     WHERE (id = a.id) AND (colid in
--                                               (SELECT colid
--                                              FROM syscolumns
--                                              WHERE (id = a.id) AND (name = a.name))))))) AND
--                          (xtype = ''PK''))>0 then ''√'' else '''' end) 主键,
--                   b.name 类型,
--                   a.length 占用字节数,
--                   COLUMNPROPERTY(a.id,a.name,''PRECISION'') as 长度,
--                   isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0) as 小数位数,
--                   (case when a.isnullable=1 then ''√'' else '''' end) 允许空,
--                   isnull(e.text,'''') 默认值,
--                   isnull(g.[value],'''') AS 字段说明    
--            FROM syscolumns a left join systypes b 
--             on a.xtype=b.xusertype 
--             inner join sysobjects d 
--             on a.id=d.id and  (d.xtype=''U'' or d.xtype=''V'')  and d.name<>''dtproperties'' 
--             left join syscomments e 
--             on a.cdefault=e.id 
--             left join sys.extended_properties g 
--             on a.id=g.major_id AND a.colid = g.minor_id  
--             where d.name=@table_name
--             order by a.id,a.colorder
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_GetOnlineUser]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[FZET_GetOnlineUser]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_GetOnlineUser]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[FZET_GetOnlineUser]
@userid int,
@password char(32)
AS
SELECT TOP 1 * FROM [Dcx_OnlineUser] WHERE [UserId]=@userid AND [PWD]=@password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_GetOnlineUserByIP]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[FZET_GetOnlineUserByIP]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[FZET_GetOnlineUserByIP]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[FZET_GetOnlineUserByIP]
@userid int,
@Ip char(30)
AS
SELECT TOP 1 * FROM [Dcx_OnlineUser] WHERE [UserId]=@userid AND [IP]=@Ip
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fzoa_archive_getLendMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[fzoa_archive_getLendMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fzoa_archive_getLendMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[fzoa_archive_getLendMsg]
@apply_id int
AS
	select u1.real_name as applicant_name,
	u2.real_name as approver_name,
	hyoa_file.file_code,
	hyoa_file.file_title,
	reason,
	approve_time,
	apply_time,
	deadline,
	return_time,
	checkup,
	aa.file_id
	from 
	 hyoa_archive_apply as aa inner join hyoa_user as u1 
	on apply_id=@apply_id and u1.user_id=aa.applicant_id
	inner join hyoa_file
	on aa.file_id=hyoa_file.file_id
	left outer join hyoa_user as u2
	on u2.user_id=aa.approver_id
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fzoa_item_deleteAll]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[fzoa_item_deleteAll]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fzoa_item_deleteAll]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[fzoa_item_deleteAll]  AS
begin
delete from fzoa_item
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fzoa_培训_个人培训卡]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[fzoa_培训_个人培训卡]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fzoa_培训_个人培训卡]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[fzoa_培训_个人培训卡]--获取经办工作,此存储过程增加了分分页的功能
@员工编号 varchar(100)
AS
begin
		if object_id(''tempdb..#培训明细'') is not null
		Begin     drop table #培训明细 End 
	create table #培训明细  --创建临时表#Tmp
	(
[id] [int] IdENTITY(1,1) NOT NULL,
	培训编号 varchar(50) ,
	[部门编号] varchar(50) ,
	[所在部门] varchar(50),
	[员工编号] varchar(50),
	[姓名] varchar(50),
	[考核记录] varchar(5000),
	[是否通过考核] varchar(50),
	[个人培训费用] money NULL,
	[课程编号] varchar(50),
    [课程名称] varchar(50),
	[培训时间] varchar(50),
    [培训课时] varchar(50),
	[人均培训费用] money NULL,
    [培训机构] varchar(50),
    [培训类别] varchar(50)
	) 
INSERT INTO #培训明细  SELECT A.培训编号,[部门编号]  ,
	[所在部门] ,
	[员工编号] ,
	[姓名] ,
	[考核记录] ,
	[是否通过考核] ,
	[个人培训费用]  ,
	[课程编号] ,
    [课程名称] ,
	[开始时间] ,
    [培训课时] ,
	[人均培训费用]  ,
    [培训机构] ,
    [培训类别] 
  FROM  [Dcx_培训_参加培训人员] as A inner join [Dcx_培训_培训记录表] as B on  A.[培训编号]=B.[培训编号] and ltrim(rtrim(B.[是否记录个人培训卡中]))=''是''
 where [员工编号]=''00014''   order by [开始时间] 
	if object_id(''tempdb..#个人培训卡'') is not null
		Begin     drop table #个人培训卡 End 
	create table #个人培训卡  --创建临时表#Tmp
	(
专业类别 varchar(100) ,
课程编号 varchar(100) ,
课程名称 varchar(100) ,
学习频率 varchar(100) , 
理论培训1_培训时间 varchar(100) ,
理论培训1_课时 varchar(100) ,
理论培训1_考核结果 varchar(100) ,
理论培训2_培训时间 varchar(100) ,
理论培训2_课时 varchar(100) ,
理论培训2_考核结果 varchar(100) ,
现场培训1_培训时间 varchar(100) ,
现场培训1_课时 varchar(100) ,
现场培训1_考核结果 varchar(100) ,
现场培训2_培训时间 varchar(100) ,
现场培训2_课时 varchar(100) ,
现场培训2_考核结果 varchar(100) ,
专家签名 varchar(100) ,
认证时间 varchar(100) ,
培训费用 money NULL
	) 
INSERT INTO #个人培训卡(专业类别,课程编号,课程名称,学习频率)    SELECT A.专业类别,A.课程编号,A.课程名称,
(SELECT top 1 学习频率 from Dcx_培训_岗位培训表 as B where  A.课程编号=B.课程编号) as 学习频率
  FROM  Dcx_培训_课程表 as A  where ltrim(rtrim(课程编号)) in( SELECT ltrim(rtrim(课程编号))  FROM  #培训明细)
declare @培训费用  money
declare @课程编号   varchar(50)  
set @培训费用=0 
	declare mycursor cursor for SELECT ltrim(rtrim(课程编号)) FROM #个人培训卡
	open mycursor
	fetch next from mycursor into @课程编号
	while (@@fetch_status=0)
		begin 
declare @id  int 
declare @是否通过考核   varchar(100) 
declare @个人培训费用   varchar(100) 
declare @培训时间   varchar(100) 
declare @培训课时   varchar(100) 
select top 1 @id=id,
@是否通过考核=是否通过考核 ,
	@个人培训费用=个人培训费用  ,
	@培训时间=培训时间 ,
    @培训课时=培训课时 from #培训明细  where ltrim(rtrim(课程编号))=@课程编号 and [培训类别]=''理论'' or [培训类别] like ''%理论%'' order by id
if @id is not null 
begin
update #个人培训卡 set 理论培训1_培训时间=@培训时间,理论培训1_课时=@培训课时,理论培训1_考核结果=@是否通过考核 
where  ltrim(rtrim(课程编号))=@课程编号 
set @培训费用=isnull(@培训费用,0)+isnull(@个人培训费用,0)
end
select top 1 @id=id,
@是否通过考核=是否通过考核 ,
	@个人培训费用=个人培训费用  ,
	@培训时间=培训时间 ,
    @培训课时=培训课时 from #培训明细  where id!=@id and ltrim(rtrim(课程编号))=@课程编号 and [培训类别]=''理论'' or [培训类别] like ''%理论%'' order by id
if @id is not null 
begin
update #个人培训卡 set 理论培训2_培训时间=@培训时间,理论培训2_课时=@培训课时,理论培训2_考核结果=@是否通过考核 
where  ltrim(rtrim(课程编号))=@课程编号 
set @培训费用=isnull(@培训费用,0)+isnull(@个人培训费用,0)
end 
select top 1 @id=id,
@是否通过考核=是否通过考核 ,
	@个人培训费用=个人培训费用  ,
	@培训时间=培训时间 ,
    @培训课时=培训课时 from #培训明细  where id!=@id and ltrim(rtrim(课程编号))=@课程编号 and [培训类别]=''现场'' or [培训类别] like ''%现场%'' order by id
if @id is not null 
begin
update #个人培训卡 set 现场培训1_培训时间=@培训时间,现场培训1_课时=@培训课时,现场培训1_考核结果=@是否通过考核 
where  ltrim(rtrim(课程编号))=@课程编号 
set @培训费用=isnull(@培训费用,0)+isnull(@个人培训费用,0)
end
select top 1 @id=id,
@是否通过考核=是否通过考核 ,
	@个人培训费用=个人培训费用  ,
	@培训时间=培训时间 ,
    @培训课时=培训课时 from #培训明细  where id!=@id and ltrim(rtrim(课程编号))=@课程编号 and [培训类别]=''现场'' or [培训类别] like ''%现场%'' order by id
if @id is not null 
begin
update #个人培训卡 set 现场培训2_培训时间=@培训时间,现场培训2_课时=@培训课时,现场培训2_考核结果=@是否通过考核 
where  ltrim(rtrim(课程编号))=@课程编号 
set @培训费用=isnull(@培训费用,0)+isnull(@个人培训费用,0)
end 
update #个人培训卡 set 培训费用=@培训费用
where  ltrim(rtrim(课程编号))=@课程编号 
fetch next from mycursor into @课程编号
		end
	close mycursor
	deallocate mycursor
select 
专业类别  ,
课程编号  ,
课程名称  ,
学习频率  , 
理论培训1_培训时间  ,
理论培训1_课时  ,
理论培训1_考核结果  ,
理论培训2_培训时间  ,
理论培训2_课时  ,
理论培训2_考核结果  ,
现场培训1_培训时间  ,
现场培训1_课时  ,
现场培训1_考核结果  ,
现场培训2_培训时间  ,
现场培训2_课时  ,
现场培训2_考核结果  ,
专家签名  ,
认证时间  ,
培训费用 
from #个人培训卡
end
--end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getljmaillist]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[getljmaillist]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getljmaillist]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[getljmaillist]
(@userid varchar(6),
@ordertype VarChar(10),
@pagesize int,
@pageindex int,
@dotype int)
as
set nocount on
if(@dotype=1)
select count(mailid) from ew_newmail where [r_usersid] like ''%,'' + @userid + '',%'' and isnull([deluserid],'''') like ''%,'' + @userid + '',%'' and isnull([deleteuserid],'''') not like ''%,'' + @userid + '',%''
else
begin
declare @PageLowerBound int
declare @PageUpperBound int
set @PageLowerBound=(@pageindex-1)*@pagesize
set @PageUpperBound=@PageLowerBound+@pagesize
create table #pageindex(id int identity(1,1) not null,nid int)
set rowcount @PageUpperBound
exec(''insert into #pageindex(nid)
select mailid from ew_newmail where [r_usersid] like ''''%,'' + @userid + '',%'''' 
and isnull([deluserid],'''''''') like ''''%,'' + @userid + '',%'''' 
and isnull([deleteuserid],'''''''') not like ''''%,'' + @userid + '',%'''' order by "''+@ordertype+''" desc'')
select O.mailid,O.s_userid,O.s_username,O.title,O.rq,o.read_usersid
from ew_newmail O,#pageindex p
where O.mailid=p.nid and p.id>@PageLowerBound and p.id<=@PageUpperBound order by p.id
end
set nocount off
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Insert_DA_ecm_ework]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Insert_DA_ecm_ework]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Insert_DA_ecm_ework]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Insert_DA_ecm_ework]
     @Id1 int
AS 
BEGIN
  declare @year char(4)   --ecm 的年度
  DECLARE @fint_Id INT --收文、发文的Id
----删除档案库中的数据
  delete [eWorkDA].[dbo].[Foa_DA]
  delete [eWorkDA].[dbo].[Foa_wj]
  select @year=年度 from eworkdadoecm.dbo.案卷 where id=@Id1
  ----从案卷表插入到档案库中的foa_DA表中,如果(档案号=f_GDH)一样就不重复插入到foa_DA库中
  INSERT INTO [eWorkDA].[dbo].[Foa_DA]
		(f_AJSXH,f_ND,f_BGQX,f_TM,f_GDH,f_BZDW,f_CFDD,f_BZRQ,f_JNWJQSRQ,f_JNWJZZRQ,f_DLDH)
		select 案卷号, 年度, 保管期限, 案卷标题, 档案号, 编制单位, 存放地点, 编制日期, 起始日期, 结束日期, 档案分类 from eworkdadoecm.dbo.案卷 --where 年度=@year
    --从收文表插入到档案库中的foa_WJ表中，如果(文号=f_WJBH)一样就不重复插入到foa_WJ库中
    --从收文表插入到档案库中的foa_WJ表中
    DECLARE authors_cursor CURSOR FOR
       select Id from eworkdadoecm.dbo.收文 WHERE flag=0 --@year=convert(char(4),year(文件日期))
    OPEN authors_cursor
     FETCH NEXT FROM authors_cursor into @fint_Id
     WHILE @@FETCH_STATUS = 0
     BEGIN
        if((select CHARINDEX(''['',文号) from 收文 WHERE Id=@fint_Id)=0 OR (select CHARINDEX('']'',文号) from 收文 WHERE Id=@fint_Id)=0 or (select CHARINDEX(''号'',文号) from 收文 WHERE Id=@fint_Id)=0)
           INSERT INTO [eWorkDA].[dbo].[Foa_WJ]
		(f_WJLX,f_GDH,f_BM,f_TM,f_ZTC,f_WJBH,f_WSH,f_YS,f_FS,f_MJ,f_BGQX,f_LWDW,f_CWRQ,f_DJRQ,f_CLQK,f_WJLX2)
		select 文件类型, 档案号, 部门, 文件题名, 主题词, 文号,文件自编号, 页数, 份数, 密级, 保管期限, 责任者, 文件日期, 登记日期, 领导批示, 文件子类  from eworkdadoecm.dbo.收文 WHERE  Id=@fint_Id
        else
            INSERT INTO [eWorkDA].[dbo].[Foa_WJ]
		(f_WJLX,f_GDH,f_BM,f_TM,f_ZTC,f_WJBH,f_WJZ,f_ND,f_WJH,f_WSH,f_YS,f_FS,f_MJ,f_BGQX,f_LWDW,f_CWRQ,f_DJRQ,f_CLQK,f_WJLX2)
		select 文件类型, 档案号, 部门, 文件题名, 主题词, 文号,left(文号,CHARINDEX(''['',文号)-1),substring(文号,CHARINDEX(''['',文号)+1,4),substring(文号,CHARINDEX('']'',文号)+1,len(文号)-CHARINDEX('']'',文号)-1),文件自编号, 页数, 份数, 密级, 保管期限, 责任者, 文件日期, 登记日期, 领导批示, 文件子类  from eworkdadoecm.dbo.收文 WHERE  Id=@fint_Id
        FETCH NEXT FROM authors_cursor into  @fint_Id
    END
    CLOSE authors_cursor
    DEALLOCATE authors_cursor 
    --从发文表插入到档案库中的foa_WJ表中，如果(文号=f_WJBH)一样就不重复插入到foa_WJ库中
    DECLARE fawen_cursor CURSOR FOR
       select Id from eworkdadoecm.dbo.发文 WHERE  flag=0--@year=convert(char(4),year(文件日期))
    OPEN fawen_cursor
     FETCH NEXT FROM fawen_cursor into @fint_Id
     WHILE @@FETCH_STATUS = 0
     BEGIN
        if((select CHARINDEX(''['',文号) from 发文 WHERE Id=@fint_Id)=0 OR (select CHARINDEX('']'',文号) from 发文 WHERE Id=@fint_Id)=0 or (select CHARINDEX(''号'',文号) from 发文 WHERE Id=@fint_Id)=0)
           INSERT INTO [eWorkDA].[dbo].[Foa_WJ]
		(f_WJLX,f_GDH,f_BM,f_TM,f_ZTC,f_WJBH,f_WSH,f_ZS,f_CS,f_LG,f_XD,f_HQ,f_CLQK,f_FS,f_MJ,f_LWDW,f_BZ,f_CWRQ,f_DJRQ,f_WJLX2)
		select 文件类型, 档案号, 发文部门, 文件题名, 主题词, 文号,卷内顺序号, 主送, 抄送, 拟稿人, 校对人, 会签意见, 审批意见, 份数, 密级, 责任者, 备注, 文件日期, 发文日期, 文件分类 from eworkdadoecm.dbo.发文 WHERE  Id=@fint_Id
        else
           INSERT INTO [eWorkDA].[dbo].[Foa_WJ]
		(f_WJLX,f_GDH,f_BM,f_TM,f_ZTC,f_WJBH,f_WJZ,f_ND,f_WJH,f_WSH,f_ZS,f_CS,f_LG,f_XD,f_HQ,f_CLQK,f_FS,f_MJ,f_LWDW,f_BZ,f_CWRQ,f_DJRQ,f_WJLX2)
		select 文件类型, 档案号, 发文部门, 文件题名, 主题词, 文号,left(文号,CHARINDEX(''['',文号)-1),substring(文号,CHARINDEX(''['',文号)+1,4),substring(文号,CHARINDEX('']'',文号)+1,len(文号)-CHARINDEX('']'',文号)-1), 卷内顺序号, 主送, 抄送, 拟稿人, 校对人, 会签意见, 审批意见, 份数, 密级, 责任者, 备注, 文件日期, 发文日期, 文件分类 from eworkdadoecm.dbo.发文 WHERE  Id=@fint_Id
        FETCH NEXT FROM fawen_cursor into  @fint_Id
    END
    CLOSE fawen_cursor
    DEALLOCATE fawen_cursor
/*
 --从收文表插入到档案库中的foa_WJ表中，如果(文号=f_WJBH)一样就不重复插入到foa_WJ库中
        --从收文表插入到档案库中的foa_WJ表中
  INSERT INTO [eWorkDA].[dbo].[Foa_WJ]
		(f_WJLX,f_GDH,f_BM,f_TM,f_ZTC,f_WJBH,f_WJZ,f_ND,f_WJH,f_WSH,f_YS,f_FS,f_MJ,f_BGQX,f_LWDW,f_CWRQ,f_DJRQ,f_CLQK,f_WJLX2)
		select 文件类型, 档案号, 部门, 文件题名, 主题词, 文号,left(文号,CHARINDEX(''['',文号)-1),substring(文号,CHARINDEX(''['',文号)+1,4),substring(文号,CHARINDEX('']'',文号)+1,len(文号)-CHARINDEX('']'',文号)-1),文件自编号, 页数, 份数, 密级, 保管期限, 责任者, 文件日期, 登记日期, 领导批示, 文件子类  from eworkdadoecm.dbo.收文 WHERE  @year=convert(char(4),year(文件日期))
 --从发文表插入到档案库中的foa_WJ表中，如果(文号=f_WJBH)一样就不重复插入到foa_WJ库中
  INSERT INTO [eWorkDA].[dbo].[Foa_WJ]
		(f_WJLX,f_GDH,f_BM,f_TM,f_ZTC,f_WJBH,f_WJZ,f_ND,f_WJH,f_WSH,f_ZS,f_CS,f_LG,f_XD,f_HQ,f_CLQK,f_FS,f_MJ,f_LWDW,f_BZ,f_CWRQ,f_DJRQ,f_WJLX2)
		select 文件类型, 档案号, 发文部门, 文件题名, 主题词, 文号,left(文号,CHARINDEX(''['',文号)-1),substring(文号,CHARINDEX(''['',文号)+1,4),substring(文号,CHARINDEX('']'',文号)+1,len(文号)-CHARINDEX('']'',文号)-1), 文件自编号, 主送, 抄送, 拟稿人, 校对人, 会签意见, 审批意见, 份数, 密级, 责任者, 备注, 文件日期, 发文日期, 文件分类 from eworkdadoecm.dbo.发文 WHERE  @year=convert(char(4),year(文件日期))
*/
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Pr_UpdateItemVoteCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Pr_UpdateItemVoteCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Pr_UpdateItemVoteCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Pr_UpdateItemVoteCount]
(
	@ItemId int
)
AS
UPDATE 
	Dcx_TP_Items
SET
	VoteCount = isnull(VoteCount,0) + 1
WHERE
	ItemId = @ItemId 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Pr_UpdateTopicCurrent]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Pr_UpdateTopicCurrent]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Pr_UpdateTopicCurrent]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Pr_UpdateTopicCurrent]
(
	@TopicId int
)
AS
BEGIN TRAN
UPDATE
	Dcx_TP_Topics
SET
	IsCurrent = 1
WHERE
	TopicId = @TopicId
UPDATE
	Dcx_TP_Topics
SET
	IsCurrent = 0
WHERE
	TopicId <> @TopicId
COMMIT TRAN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Update_Car_Apply]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Update_Car_Apply]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Update_Car_Apply]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Update_Car_Apply]
AS
BEGIN
    declare @fstr_CarNum varchar(30) --车牌号码
    Update 车辆使用情况 set 使用状态=''空闲''
    DECLARE authors_cursor CURSOR FOR
       select 车牌号码 from 车辆申请 where (getdate() between 起始日期 and 结束日期) and 批示=''同意''
    OPEN authors_cursor
     FETCH NEXT FROM authors_cursor into @fstr_CarNum
     WHILE @@FETCH_STATUS = 0
     BEGIN
        Update 车辆使用情况 set 使用状态=''正在使用'' where 车牌号码=@fstr_CarNum
        FETCH NEXT FROM authors_cursor into  @fstr_CarNum
    END
    CLOSE authors_cursor
    DEALLOCATE authors_cursor  
End
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Update_Meeting_Room_Apply]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[Update_Meeting_Room_Apply]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Update_Meeting_Room_Apply]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[Update_Meeting_Room_Apply]
AS
BEGIN
    declare @fstr_meeting_room varchar(30) --会议室名称
    Update 会议室情况 set 会议室状况=''空闲''
    DECLARE authors_cursor CURSOR FOR
       select 会议室名称 from 会议室申请 where (getdate() between 开会日期 and 结束日期) and 批示=''同意''
    OPEN authors_cursor
     FETCH NEXT FROM authors_cursor into @fstr_meeting_room
     WHILE @@FETCH_STATUS = 0
     BEGIN
        Update 会议室情况 set 会议室状况=''正在使用'' where 会议室名称=@fstr_meeting_room
        FETCH NEXT FROM authors_cursor into  @fstr_meeting_room
    END
    CLOSE authors_cursor
    DEALLOCATE authors_cursor  
End
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[userGetNameById]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[userGetNameById]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[userGetNameById]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[userGetNameById]
(
	@userId int
)
AS
	SET NOCOUNT ON 
	SELECT 员工姓名 FROM 工资_员工档案 where [UserName] in(select [UserName] from Dcx_user where userid=@userId)
	SET NOCOUNT OFF 
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_CheckIsExist]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_CheckIsExist]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_CheckIsExist]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_CheckIsExist]
@sv_TableName varchar(200),
@sv_FieldName varchar(200),
@sv_FieldValue varchar(200),
@sv_OperateType varchar(200),
@sv_KeyField varchar(200),
@sv_KeyFieldValue  varchar(200)
AS
DECLARE @SelSQL   nvarchar(max) 
set @sv_TableName=ltrim(rtrim(isnull(@sv_TableName,'''')))
set @sv_FieldName=ltrim(rtrim(isnull(@sv_FieldName,'''')))
set @sv_FieldValue=ltrim(rtrim(isnull(@sv_FieldValue,'''')))
set @sv_OperateType=ltrim(rtrim(isnull(@sv_OperateType,'''')))
set @sv_KeyField=ltrim(rtrim(isnull(@sv_KeyField,'''')))
set @sv_KeyFieldValue=ltrim(rtrim(isnull(@sv_KeyFieldValue,'''')))
if @sv_TableName ='''' or @sv_FieldName ='''' or @sv_FieldValue ='''' or @sv_OperateType ='''' or @sv_KeyField =''''
begin
select -1
return 
end
else
begin
if @sv_OperateType = ''edit'' or @sv_OperateType = ''copy''
  set   @SelSQL = ''select count(*) from '' + @sv_TableName + '' where '' + @sv_FieldName + ''='' +@sv_FieldValue + '' and '' + @sv_KeyField + ''!='' + @sv_KeyFieldValue
else
  set   @SelSQL = ''select count(*) from '' + @sv_TableName + '' where '' + @sv_FieldName + ''='' +@sv_FieldValue 
exec sp_executesql @SelSQL
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_Add]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_FailedLogins_Add]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_Add]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_FailedLogins_Add] 
@ip char(18)
AS
INSERT INTO [Dcx_FailedLogins] ([ip], [errcount], [lastupdate]) VALUES(@ip, 1, GETDATE())
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_Delete]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_FailedLogins_Delete]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_Delete]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_FailedLogins_Delete] 
@ip char(18)
AS
DELETE FROM [Dcx_FailedLogins] WHERE [ip]=@ip OR DATEDIFF(n,[lastupdate], GETDATE()) > 15
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_GetFailedMsgByIP]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_FailedLogins_GetFailedMsgByIP]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_GetFailedMsgByIP]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_FailedLogins_GetFailedMsgByIP] 
@ip char(18)
AS
select top 1 [errcount],[lastupdate] from Dcx_FailedLogins where ip=@ip
	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_ReSet]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_FailedLogins_ReSet]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_ReSet]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_FailedLogins_ReSet] 
@ip char(18)
AS
update [Dcx_FailedLogins] set  [errcount]=0,[lastupdate]=getdate()   where [ip]=@ip
RETURN
--
--
--USE [VL_ETSYSv3]
--GO
--/****** 对象:  StoredProcedure [dbo].[fzoa_getCreator]    脚本日期: 07/13/2012 11:33:06 ******/
--SET ANSI_NULLS ON
--GO
--SET QUOTED_IdENTIFIER ON
--GO
--alter PROCEDURE [dbo].[VL_FailedLogins_GetFailedMsgByIP] 
--@ip char(18)
--AS
--select top 1 [errcount],[lastupdate] from Dcx_FailedLogins where ip=@ip
--
--	RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_UpdateErrCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_FailedLogins_UpdateErrCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_FailedLogins_UpdateErrCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_FailedLogins_UpdateErrCount] 
@ip char(18)
AS
update [Dcx_FailedLogins] set  [errcount]=isnull([errcount],0)+1, [lastupdate]=GETDATE()  WHERE [ip]=@ip
RETURN
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetData]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetData]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetData]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetData] --分页读取数据
@PageSize int output,--每页记录数
@PageIndex int output,--当前页码
@KeyField varchar(200),--主键字段名称
@SQLFields varchar(max),--字段串
@SQLTables varchar(max),
@SQLCondition varchar(max),
@SQLOrderby varchar(max),
@PageCount int output, --总共显示多少页
@RecCount int output--总共记录
AS
DECLARE @startRow int
DECLARE @endRow   int
DECLARE @SelSQL   nvarchar(max) 
--
if @PageSize is null or @PageSize<1
set @PageSize=20
if @PageIndex is null or @PageIndex<1
set @PageIndex=1
set @KeyField=ltrim(rtrim(isnull(@KeyField,'''')))
set @SQLFields=ltrim(rtrim(isnull(@SQLFields,'''')))
set @SQLTables=ltrim(rtrim(isnull(@SQLTables,'''')))
set @SQLCondition=ltrim(rtrim(isnull(@SQLCondition,'''')))
set @SQLOrderby=ltrim(rtrim(isnull(@SQLOrderby,'''')))
if @KeyField='''' or  @SQLFields=''''
 return 
set @SQLFields=@SQLFields
if @SQLTables!=''''
set @SQLTables='' FROM ''+@SQLTables
 if @SQLCondition!=''''
set @SQLCondition='' WHERE ''+@SQLCondition
 if @SQLOrderby=''''
set @SQLOrderby=@KeyField
DECLARE @IntVariable INT
DECLARE @SQLString NVARCHAR(500)
DECLARE @ParmDefinition NVARCHAR(500)
SET @SQLString = N'' select @c=count(*) ''+''  ''+@SQLTables+ ''  ''+@SQLCondition
--select @SQLString
SET @ParmDefinition = N''@c int output''
set @RecCount=0
set @PageCount=0
EXECUTE sp_executesql @SQLString, @ParmDefinition, @c = @RecCount output
if(@RecCount%@PageSize<>0)
begin
   set @PageCount=@RecCount/@PageSize+1
end 
else
begin
   set @PageCount=@RecCount/@PageSize
end
set @RecCount=isnull(@RecCount,0)
set @PageCount=isnull(@PageCount,0)
if @PageIndex>@PageCount
set @PageIndex=@PageCount
SET @startRow = (@PageIndex - 1) * @PageSize +1
SET @endRow = @startRow + @PageSize -1 
if @PageIndex = 1 begin
   set @SelSQL = '' select top ''+CAST(@PageSize as varchar)+'' ''+@SQLFields+ '' ''+@SQLTables+ ''  ''+@SQLCondition+'' ORDER BY ''+@SQLOrderby
end
else begin
set @SelSQL=''SELECT *  FROM (SELECT ROW_NUMBER() OVER(ORDER BY ''+@SQLOrderby+'')AS VL_ROWId,''+@SQLFields 
+''  ''+@SQLTables+ ''  ''+@SQLCondition+''  ) AS MyTable  WHERE  VL_ROWId BETWEEN ''+cast(@startRow as varchar(50))+'' AND ''+cast(@endRow as varchar(50)) --+''  ''+@SQLOrderby
end
exec sp_executesql @SelSQL
--实例 ，直接运行即可测试
--DECLARE	@return_value int,
--		@PageCount int,
--		@RecCount int
--
--SELECT	@PageCount = -1
--SELECT	@RecCount = -1
--
--EXEC	@return_value = [dbo].[VL_GetData]
--		@PageSize = 2,
--		@PageIndex = 5,
--		@KeyField = N''TemplateModuleId'',
--		@SQLFields = N''*'',
--		@SQLTables = N''Dcx_TemplateModuleView'',
--		@SQLCondition = N'' ModuleId In(1)'',
--		@SQLOrderby = N'''',
--		@PageCount = @PageCount OUTPUT,
--		@RecCount = @RecCount OUTPUT
--
--SELECT	@PageCount as N''@PageCount'',
--		@RecCount as N''@RecCount''
--
--SELECT	''Return Value'' = @return_value
--
--GO
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetDBTableColumnMsg]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetDBTableColumnMsg]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetDBTableColumnMsg]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetDBTableColumnMsg] 
@TableName varchar(100)
AS
BEGIN
--select top 100 * from Dcx_Entity
SELECT  
/*字段名称*/ [FieldName]=a.name  ,  
/*字段类型*/ [DataType]=b.name,   
/*标识*/ [IsIdentity]=case   when   COLUMNPROPERTY( a.id,a.name,''IsIdentity'')=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
/*主键*/ [IsKey]=case   when   exists(SELECT 1 FROM sysobjects where xtype=''PK'' and name in (SELECT name FROM sysindexes WHERE indid in(SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then cast(1 as bit) else cast(0 as bit) end,    
/*是否可空*/ [IsNullAble]=case   when   a.isnullable=1   then    cast(1 as bit)  else    cast(0 as bit)    end,   
/*占用字节数*/ [Length]=a.length,
/*精确度*/[Precision]=COLUMNPROPERTY(a.id,a.name,''PRECISION''),
/*小数位数*/[Scale]=isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0),
/*默认值*/[DefaultValue]=isnull(e.text,''''),
--/*字段说明*/[FieldRemark]=isnull(g.[value],''''),
--/*表示是第一个字段*/[IsFirstColumn]=case   when   a.colorder=1   then   cast(1 as bit)    else   cast(0 as bit) end,
/*所属表名*/[DBTableName]=case   when   a.colorder=1   then   d.name   else   ''''   end,
--/*表说明*/[DBTableNameRemark]=case   when   a.colorder=1   then   isnull(f.value,'''')   else   ''''   end,
/*字段序号*/[FieldNO]=a.colorder
FROM   syscolumns   a   
left   join   systypes   b   on   a.xtype=b.xusertype   
inner   join   sysobjects   d   on   a.id=d.id     and   d.xtype=''U''   and     d.name<>''dtproperties''   
left   join   syscomments   e   on   a.cdefault=e.id   
--left   join   sys.extended_properties   g   on   a.id=g.major_id   and   a.colid=g.minor_id       
--left   join   sys.extended_properties   f   on   d.id=f.major_id   and   f.minor_id=0   
where   d.name=@TableName  order   by   a.colorder  
--            SELECT 
--            	   (case when a.colorder=1 then d.name else d.name end)表名,
--                   a.colorder 字段序号,
--                   a.name 字段名,
--                   (case when COLUMNPROPERTY( a.id,a.name,''IsIdentity'')=1 then ''√''else '''' end) 标识,
--                   (case when (SELECT count(*)
--                   FROM sysobjects
--                   WHERE (name in
--                             (SELECT name
--                            FROM sysindexes
--                            WHERE (id = a.id) AND (indid in
--                                      (SELECT indid
--                                     FROM sysindexkeys
--                                     WHERE (id = a.id) AND (colid in
--                                               (SELECT colid
--                                              FROM syscolumns
--                                              WHERE (id = a.id) AND (name = a.name))))))) AND
--                          (xtype = ''PK''))>0 then ''√'' else '''' end) 主键,
--                   b.name 类型,
--                   a.length 占用字节数,
--                   COLUMNPROPERTY(a.id,a.name,''PRECISION'') as 长度,
--                   isnull(COLUMNPROPERTY(a.id,a.name,''Scale''),0) as 小数位数,
--                   (case when a.isnullable=1 then ''√'' else '''' end) 允许空,
--                   isnull(e.text,'''') 默认值,
--                   isnull(g.[value],'''') AS 字段说明    
--            FROM syscolumns a left join systypes b 
--             on a.xtype=b.xusertype 
--             inner join sysobjects d 
--             on a.id=d.id and  (d.xtype=''U'' or d.xtype=''V'')  and d.name<>''dtproperties'' 
--             left join syscomments e 
--             on a.cdefault=e.id 
--             left join sys.extended_properties g 
--             on a.id=g.major_id AND a.colid = g.minor_id  
--             where d.name=@table_name
--             order by a.id,a.colorder
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetList]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetList]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetList]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetList]
@pagesize int,
@pageindex int,
@KeyField varchar(200),
@SQLFields varchar(max),
@SQLTables varchar(max),
@SQLCondition varchar(max),
@SQLOrderby varchar(max)
AS
DECLARE @startRow int
DECLARE @endRow   int
DECLARE @SelSQL   nvarchar(max) 
if @pagesize is null or @pagesize<1
set @pagesize=20
if @pageindex is null or @pageindex<1
set @pageindex=1
SET @startRow = (@pageindex - 1) * @pagesize +1
SET @endRow = @startRow + @pagesize -1 
set @KeyField=ltrim(rtrim(isnull(@KeyField,'''')))
set @SQLFields=ltrim(rtrim(isnull(@SQLFields,'''')))
set @SQLTables=ltrim(rtrim(isnull(@SQLTables,'''')))
set @SQLCondition=ltrim(rtrim(isnull(@SQLCondition,'''')))
set @SQLOrderby=ltrim(rtrim(isnull(@SQLOrderby,'''')))
--if @KeyField='''' or  @SQLFields=''''
-- return 
--
--set @SQLFields='',''+@SQLFields
-- 
--
--if @SQLTables!=''''
--set @SQLTables='' FROM ''+@SQLTables
-- 
-- if @SQLCondition!=''''
--set @SQLCondition='' WHERE ''+@SQLCondition
-- if @SQLOrderby!=''''
--set @SQLOrderby='' ORDER BY ''+@SQLOrderby
--
--
--set @SelSQL=''SELECT *  FROM (SELECT ROW_NUMBER() OVER(ORDER BY ''+@KeyField+'')AS VL_ROWId''+@SQLFields 
--+''  ''+@SQLTables+ ''  ''+@SQLCondition+''  ) AS MyTable  WHERE  VL_ROWId BETWEEN ''+cast(@startRow as varchar(50))+'' AND ''+cast(@endRow as varchar(50))+''  ''+@SQLOrderby
--exec sp_executesql @SelSQL
if @KeyField='''' or  @SQLFields=''''
 return 
set @SQLFields='',''+@SQLFields
if @SQLTables!=''''
set @SQLTables='' FROM ''+@SQLTables
 if @SQLCondition!=''''
set @SQLCondition='' WHERE ''+@SQLCondition
 if @SQLOrderby=''''
set @SQLOrderby=@KeyField
-- if @SQLOrderby!=''''
--set @SQLOrderby='' ORDER BY ''+@SQLOrderby
set @SelSQL=''SELECT *  FROM (SELECT ROW_NUMBER() OVER(ORDER BY ''+@SQLOrderby+'')AS VL_ROWId''+@SQLFields 
+''  ''+@SQLTables+ ''  ''+@SQLCondition+''  ) AS MyTable  WHERE  VL_ROWId BETWEEN ''+cast(@startRow as varchar(50))+'' AND ''+cast(@endRow as varchar(50)) --+''  ''+@SQLOrderby
exec sp_executesql @SelSQL
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetList_NoPage]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetList_NoPage]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetList_NoPage]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetList_NoPage]
@SQLFields varchar(max),
@SQLTables varchar(max),
@SQLCondition varchar(max),
@SQLOrderby varchar(max)
AS
DECLARE @SelSQL   nvarchar(max) 
set @SQLFields=ltrim(rtrim(isnull(@SQLFields,'''')))
set @SQLTables=ltrim(rtrim(isnull(@SQLTables,'''')))
set @SQLCondition=ltrim(rtrim(isnull(@SQLCondition,'''')))
set @SQLOrderby=ltrim(rtrim(isnull(@SQLOrderby,'''')))
if @SQLTables!=''''
set @SQLTables='' FROM ''+@SQLTables
 if @SQLCondition!=''''
set @SQLCondition='' WHERE ''+@SQLCondition
 if @SQLOrderby!=''''
set @SQLOrderby='' ORDER BY ''+@SQLOrderby
set @SelSQL=''SELECT ''+@SQLFields +''  ''+@SQLTables+ ''  ''+@SQLCondition +@SQLOrderby
exec sp_executesql @SelSQL
--exec(@SelSQL) 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListBySQL]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetListBySQL]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListBySQL]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetListBySQL]
@pagesize int,
@pageindex int,
--@KeyField varchar(200),
@SQL nvarchar(max)
--@SearchArea varchar(max),
--@DBTableName varchar(max)
AS
 --说明：@pageindex，@pagesize，@keyField，@SearchArea，@DBTableName是本系统的程序层面的变量
 --变量说明：
 --@pageindex：当前分页序号
 --@pagesize：分页大小
 --@keyField：主键字段名
 --@DBTableName：本实体的数据表名
 --@SearchArea：由搜索条件连接起来的条件字符串（如果为空，即为：1=1），一定得保留，不然搜索不起使用
--分页查询
DECLARE @startRow int
DECLARE @endRow   int
SET @startRow = (@pageindex - 1) * @pagesize +1
SET @endRow   = @startRow + @pagesize -1 
set @SQL=replace(@SQL,''{{@startRow}}'',@startRow)
set @SQL=replace(@SQL,''{{@endRow}}'',@endRow)
--set @SQL=replace(@SQL,''@SearchArea'',@SearchArea)
--set @SQL=replace(@SQL,''@keyField'',@keyField)
--set @SQL=replace(@SQL,''@DBTableName'',@DBTableName)
--exec(@SQL) 
exec sp_executesql @SQL
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListBySQL_NoPage]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetListBySQL_NoPage]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListBySQL_NoPage]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetListBySQL_NoPage]
@SQL nvarchar(max)
AS
set @SQL=replace(@SQL,''{{@startRow}}'',''0'')
set @SQL=replace(@SQL,''{{@endRow}}'',''99999999'')
-- exec(@SQL) 
exec sp_executesql @SQL
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListCount]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetListCount]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListCount]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetListCount]
@SQLTables varchar(2000),
@SQLCondition varchar(2000)
AS
DECLARE @SelSQL   nvarchar(2000) 
if @SQLTables!=''''
set @SQLTables='' FROM ''+@SQLTables
-- else 
--begin
--select 0
--end 
 if @SQLCondition!=''''
set @SQLCondition='' WHERE ''+@SQLCondition
set @SelSQL=''SELECT count(*) ''+@SQLTables+ ''  ''+@SQLCondition  
--select count(*) from 工资_考勤记录
--exec(@SelSQL) 
exec sp_executesql @SelSQL
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListCountBySQL]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_GetListCountBySQL]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_GetListCountBySQL]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_GetListCountBySQL]
@SQL nvarchar(max)
AS
 --说明：@PageIndex，@pageSize，@keyField，@SearchArea，@DBTableName是本系统的程序层面的变量
 --变量说明：
 --@PageIndex：当前分页序号
 --@pageSize：分页大小
 --@keyField：主键字段名
 --@DBTableName：本实体的数据表名
 --@SearchArea：由搜索条件连接起来的条件字符串（如果为空，即为：1=1），一定得保留，不然搜索不起使用
--分页查询
--set @SQL=replace(@SQL,''@SearchArea'',@SearchArea)
--set @SQL=replace(@SQL,''@keyField'',@keyField)
--set @SQL=replace(@SQL,''@DBTableName'',@DBTableName)
set @SQL=replace(@SQL,''{{@startRow}}'',''0'')
set @SQL=replace(@SQL,''{{@endRow}}'',''999999999'')
exec sp_executesql @SQL
--exec(@SQL) 
--declare @num int, 
--@sqls nvarchar(4000) 
--set @sqls=cast(@SQL as nvarchar(max))
--set @sqls=’select @a=count(*) from tableName ’ 
--exec sp_executesql @sqls,N''@a int output'',@num output 
--select @num 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_UserView_CheckPasswordByUserId]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_UserView_CheckPasswordByUserId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_UserView_CheckPasswordByUserId]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_UserView_CheckPasswordByUserId]
@UserId int,
@Password char(100)
AS
SELECT TOP 1 * FROM [Dcx_UserView] WHERE [UserId]=@UserId AND [PWD]=@Password
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_UserView_CheckPasswordByUserName]')  AND type in (N'P', N'PC')) 
   DROP procedure  dbo.[VL_UserView_CheckPasswordByUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[VL_UserView_CheckPasswordByUserName]')  AND type in (N'P', N'PC')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE PROCEDURE [dbo].[VL_UserView_CheckPasswordByUserName]
@UserName nchar(20),
@Password char(100)
AS
SELECT TOP 1 * FROM [Dcx_UserView] WHERE [UserName]=@UserName AND [PWD]=@Password
' 
END 
----------------------------------------------------------------------------------------  上：存储过程  ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------  下：触发器  ----------------------------------------------------------------------------------
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='delete_IMRelationship') 
 drop trigger  delete_IMRelationship 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='delete_IMRelationship') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [delete_IMRelationship] on [dbo].[Dcx_LinkMan] for delete
as
begin
declare @userId   int
declare @CreatorId   int
select  @CreatorId= CreatorId from  deleted
delete from Dcx_IMRelationship 
where ([HostUserId]=@userId and [GuestUserId]=@CreatorId) or ([HostUserId]=@CreatorId and [GuestUserId]=@userId)
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='add_IMRelationship') 
 drop trigger  add_IMRelationship 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='add_IMRelationship') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [add_IMRelationship] on [dbo].[Dcx_LinkMan] for insert
as
begin
declare @UserId   int
--declare @CreatorId   int
--declare @userName varchar(100)   
--select  @CreatorId= CreatorId,@UserId= UserId from  inserted
--if (select count(*) from [Dcx_IMRelationship] where HostUserId=@CreatorId)<1
--begin
--
--	select top 1 @userName=username from dcx_user where userid=@UserId
--	insert into [Dcx_IMRelationship] ([HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
--	values( @CreatorId,@UserId,@userName,0,getdate())
--end
--if (select count(*) from [Dcx_IMRelationship] where HostUserId=@UserId)<1
--begin
--	select top 1 @userName=username from dcx_user where userid=@UserId
--	insert into [Dcx_IMRelationship] ([HostUserId],[GuestUserId],[GuestUserName],Relationship,RenewTime)
--	values( @UserId,@CreatorId,@userName,0,getdate())
--end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='ListFormField_Update_FieldTypeId') 
 drop trigger  ListFormField_Update_FieldTypeId 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='ListFormField_Update_FieldTypeId') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [ListFormField_Update_FieldTypeId]
ON  dbo.Dcx_ListFormField_Run for insert
AS
BEGIN
SET NOCOUNT ON;
--declare @FldId int
--declare @FieldType varchar(100)
--select  @FldId=FldId,@FieldType=ltrim(rtrim(FieldType))  from   inserted 
--
--
--declare @FieldTypeId int
--select  @FieldTypeId=FieldTypeId  from   Dcx_ReportFieldType where   lower(ltrim(rtrim(FieldTypeValue)))=lower(@FieldType)
--set @FieldTypeId=isnull(@FieldTypeId,1)
--
--update Dcx_ListFormField_Run set FieldTypeId=@FieldTypeId where FldId=@FldId
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='TitleListField_Update_FieldTypeId') 
 drop trigger  TitleListField_Update_FieldTypeId 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='TitleListField_Update_FieldTypeId') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 


CREATE TRIGGER [TitleListField_Update_FieldTypeId]
ON  [dbo].Dcx_TitleListField for insert
AS
BEGIN

SET NOCOUNT ON;

declare @REFId int
declare @FieldType varchar(100)
select  @REFId=REFId,@FieldType=ltrim(rtrim(FieldType))  from   inserted 


declare @FieldTypeId int
select  @FieldTypeId=FieldTypeId  from   Dcx_ReportFieldType where   lower(ltrim(rtrim(FieldTypeValue)))=lower(@FieldType)
set @FieldTypeId=isnull(@FieldTypeId,1)

update Dcx_TitleListField set FieldTypeId=@FieldTypeId where REFId=@REFId
END


' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Update_peopleMsg') 
 drop trigger  Update_peopleMsg 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Update_peopleMsg') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [Update_peopleMsg]
ON  dbo.Dcx_User for delete
AS
BEGIN
SET NOCOUNT ON;
declare @Id int
declare @UserName varchar(100)
declare @StaffNO varchar(100)
declare @Role varchar(100)
--select  @UserName=UserName,@StaffNO=ltrim(rtrim(StaffNO)),@Role=ltrim(rtrim(Role))  from   deleted
-----------------------------------------------------------------------------------
--if @UserName is not null and @UserName!='''' and @Role=''Public''
--begin
--update 工资_员工档案 set UserName=null  where 员工编号=@StaffNO
--update 工资_员工档案 set UserName=null  where UserName=@UserName
--
--delete from   Dcx_User  where ltrim(rtrim(UserName))=@UserName
--end
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Insert_UpdateSystemMsg') 
 drop trigger  Insert_UpdateSystemMsg 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Insert_UpdateSystemMsg') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [Insert_UpdateSystemMsg]
ON  [dbo].[Dcx_User] for insert
AS
BEGIN
SET NOCOUNT ON;
declare @AccountId int
declare @UserName varchar(20)
declare @UserId int
declare @CreatorId int
declare @CurSystemId int
declare @IsAccountCreator bit
select  @UserId=[UserId],@AccountId=[AccountId],@UserName=[UserName],@CurSystemId=[CurSystemId]
,@CreatorId=[CreatorId],@IsAccountCreator=[IsAccountCreator] from  inserted 
if @UserId is not null and @UserId>0
begin
if (@CreatorId is null or @CreatorId<1) and  @IsAccountCreator=1
begin
	update [Dcx_User] set [Creator]=@UserName,[CreatorId]=@CreatorId where [AccountId]=@AccountId and [UserId]=@UserId
end
else if @CurSystemId is not null and @CurSystemId>0
begin
	IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N''dbo.[Dcx_AccountSystem]'') AND type in (N''U''))
		set @UserId=1 
--update [Dcx_AccountSystem] set [UserCount]=isnull([UserCount],0)+1 where [AccountId]=@AccountId and [SystemId]=@CurSystemId
end
end
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='UpdateVideoType') 
 drop trigger  UpdateVideoType 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='UpdateVideoType') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 




CREATE TRIGGER [UpdateVideoType]
ON  [dbo].[Dcx_VideoTypeGroup] for update
AS
BEGIN

SET NOCOUNT ON;
declare @GroupName varchar(100)
declare @GroupId int
declare @Old_GroupId int
select  @GroupId=[GroupId],@GroupName=GroupName from  inserted 
select  @Old_GroupId=[GroupId] from  deleted
if @GroupId!=@Old_GroupId and @GroupId is not null and @Old_GroupId is not null
begin
update Dcx_VideoType set GroupId=@GroupId,GroupName=@GroupName where GroupId=@Old_GroupId
end
else
update Dcx_VideoType set GroupName=@GroupName where GroupId=@Old_GroupId
END





' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetPY_ForInsert') 
 drop trigger  SetPY_ForInsert 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetPY_ForInsert') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 


CREATE TRIGGER [SetPY_ForInsert]
ON  [dbo].ERP_客户资料 for insert
AS
BEGIN

SET NOCOUNT ON;
declare @客户编号 varchar(100)
declare @客户名称 varchar(100)
declare @助记码 varchar(40)

select  @客户名称=客户名称,@客户编号=客户编号 from  inserted 
set @助记码=dbo.fun_getPY(@客户名称)
update ERP_客户资料 set 客户名称助记码=@助记码 where 客户编号=@客户编号


END


' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetPY_ForUpdate') 
 drop trigger  SetPY_ForUpdate 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetPY_ForUpdate') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 



CREATE TRIGGER [SetPY_ForUpdate]
ON  [dbo].[ERP_客户资料] for update
AS
BEGIN

SET NOCOUNT ON;
declare @助记码 varchar(40)

declare @客户编号 varchar(100)
declare @客户名称 varchar(100)

select  @客户名称=客户名称,@客户编号=客户编号 from  inserted 
set @助记码=dbo.fun_getPY(@客户名称)
update ERP_客户资料 set 客户名称助记码=@助记码 where 客户编号=@客户编号


END



' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowRunPrcs_ForInsert') 
 drop trigger  SetFlowRunPrcs_ForInsert 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowRunPrcs_ForInsert') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [SetFlowRunPrcs_ForInsert] on dbo.WF_Depute for insert
as
begin
declare @FlowId   int
declare @RunId   int
declare @PrcsId   int
declare @CreatorId   int
declare @UserId   int
declare @UserName   varchar(50)
--select    @FlowId=[FlowId],@RunId=[RunId],@PrcsId=[PrcsId],@CreatorId=[CreatorId],@UserName=[UserName],@UserId=[UserId] from  inserted 
--declare @PrcsFlag   int
--declare @UserId2   int
--declare @MainUserId   int
--declare @DealIds   varchar(max)
--
--select    @PrcsFlag=[PrcsFlag],@DealIds=[DealIds],@MainUserId=[MainUserId],@UserId2=[UserId] from  WF_FlowRunPrcs where  [RunId]=@RunId and [PrcsId]=@PrcsId
--declare @tmp   varchar(50)
--declare @Index   int
--set @Index=0
--if @DealIds is not null and len(@DealIds)>0
--begin
--	set @tmp='',''+cast(@CreatorId as varchar(20))+'',''
--	set @DealIds='',''+isnull(@DealIds,'''')+'',''
--	set @Index=CharIndex(@tmp,@DealIds,0)
--end
--if (@PrcsFlag=1 or @PrcsFlag=2) and (@CreatorId=@UserId2 or  @Index>0)   and @UserId is not null and @CreatorId is not null
--begin
--	if @CreatorId=@UserId2
--		update [WF_FlowRunPrcs] set [UserId]=@UserId,[UserName]=@UserName where  [RunId]=@RunId and [PrcsId]=@PrcsId
--	else  if @Index>0
--	begin
--		declare @tmp2   varchar(50)
--		set @tmp2='',''+cast(@UserId as varchar(20))+'',''
--		set @DealIds=replace(@DealIds,@tmp,@tmp2)
--		set @DealIds=ltrim(rtrim(substring(@DealIds,1,len(@DealIds)-2)))
--		update [WF_FlowRunPrcs] set [DealIds]=@DealIds where  [RunId]=@RunId and [PrcsId]=@PrcsId
--	end
--end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowRunPrcs_Forupdate') 
 drop trigger  SetFlowRunPrcs_Forupdate 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowRunPrcs_Forupdate') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [SetFlowRunPrcs_Forupdate] on dbo.WF_Depute for update
as
begin
declare @FlowId   int
declare @RunId   int
declare @PrcsId   int
declare @CreatorId   int
declare @UserId   int
declare @UserName   varchar(50)
--select    @FlowId=[FlowId],@RunId=[RunId],@PrcsId=[PrcsId],
--@CreatorId=[CreatorId],@UserName=[UserName],@UserId=[UserId] from  inserted 
--declare @PrcsFlag   int
--declare @UserId2   int
--declare @MainUserId   int
--declare @DealIds   varchar(max)
--
--select    @PrcsFlag=[PrcsFlag],@DealIds=[DealIds],@MainUserId=[MainUserId],@UserId2=[UserId] from  WF_FlowRunPrcs
--where  [RunId]=@RunId and [PrcsId]=@PrcsId
--
--declare @tmp   varchar(50)
--declare @Index   int
--set @Index=0
--if @DealIds is not null and len(@DealIds)>0
--begin
--set @tmp='',''+cast(@CreatorId as varchar(20))+'',''
--set @DealIds='',''+isnull(@DealIds,'''')+'',''
--set @Index=CharIndex(@tmp,@DealIds,0)
--end
--if (@PrcsFlag=1 or @PrcsFlag=2) and (@CreatorId=@UserId2 or  @Index>0)   and @UserId is not null and @CreatorId is not null
--begin
--if @CreatorId=@UserId2
--update [WF_FlowRunPrcs] set [UserId]=@UserId,[UserName]=@UserName where  [RunId]=@RunId and [PrcsId]=@PrcsId
--else  if @Index>0
--begin
--declare @tmp2   varchar(50)
--set @tmp2='',''+cast(@UserId as varchar(20))+'',''
--set @DealIds=replace(@DealIds,@tmp,@tmp2)
--set @DealIds=ltrim(rtrim(substring(@DealIds,1,len(@DealIds)-2)))
--update [WF_FlowRunPrcs] set [DealIds]=@DealIds where  [RunId]=@RunId and [PrcsId]=@PrcsId
--end
--
--end
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetNodePrivilege_ForInsert') 
 drop trigger  SetNodePrivilege_ForInsert 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetNodePrivilege_ForInsert') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [SetNodePrivilege_ForInsert] on [dbo].[WF_FlowNode] for insert
as
begin
declare @FlowId   int
declare @NodeId   int
declare @PrcsUsers varchar(max)
declare @PrcsDepts varchar(max)
declare @CanQueryRolesId varchar(max)
declare @CanManageRolesId varchar(max)
declare @PrcsRoles varchar(max)
declare @PositionDept varchar(max)
declare @AllowLastNodeBoss   int
declare @AllowWorkCreator   int
declare @CreatorId   int

select    @AllowLastNodeBoss=[AllowLastNodeBoss],@AllowWorkCreator=[AllowWorkCreator],@FlowId=[FlowId],@NodeId=[NodeId],@PrcsUsers=[PrcsUsers],@PrcsDepts=[PrcsDepts],
@PrcsRoles=[PrcsRoles],@PositionDept=[PositionDept] from  inserted 

set @PrcsUsers=''''+isnull(@PrcsUsers,'''')+''''
set @PrcsDepts=''''+isnull(@PrcsDepts,'''')+''''
set @PrcsRoles=''''+isnull(@PrcsRoles,'''')+''''
set @PositionDept=''''+isnull(@PositionDept,'''')+''''

DELETE from  [WF_FlowNodePrivilege]  WHERE  [NodeId]=@NodeId
EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
@FlowId = @FlowId,@NodeId = @NodeId,@str = @PrcsUsers,@IdType = 1

EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
@FlowId = @FlowId,@NodeId = @NodeId,@str = @PrcsRoles,@IdType = 2

EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
@FlowId = @FlowId,@NodeId = @NodeId,@str = @PrcsDepts,@IdType = 3

EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
@FlowId = @FlowId,@NodeId = @NodeId,@str = @PositionDept,@IdType = 4


end

' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetNodePrivilege_ForUpdate') 
 drop trigger  SetNodePrivilege_ForUpdate 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetNodePrivilege_ForUpdate') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [SetNodePrivilege_ForUpdate] on [dbo].[WF_FlowNode] for update
as
begin
--set nocount on 
declare @FlowId   int
declare @EntId int
declare @NodeId   int
declare @PrcsUsers varchar(max)
declare @PrcsDepts varchar(max)
declare @CanQueryRolesId varchar(max)
declare @CanManageRolesId varchar(max)
declare @PrcsRoles varchar(max)
declare @PositionDept varchar(max)
declare @AllowLastNodeBoss   int
declare @AllowWorkCreator   int
declare @CreatorId   int
declare @Old_PrcsItem varchar(max)
declare @Old_PrcsItem2 varchar(max)
declare @PrcsItem varchar(max)
declare @PrcsItem2 varchar(max)

declare myCursor cursor for SELECT [FlowId],[NodeId],[PrcsItem],[PrcsItem2] FROM deleted
--打开游标 应用
open myCursor 
fetch next  from myCursor into @FlowId,@NodeId,@Old_PrcsItem,@Old_PrcsItem2
while (@@fetch_status=0)
begin 

	--select    @FlowId=[FlowId],@NodeId=[NodeId],@Old_PrcsItem=[PrcsItem],@Old_PrcsItem2=[PrcsItem2] from  deleted
	select    @PrcsItem=[PrcsItem],@PrcsItem2=[PrcsItem2],@AllowLastNodeBoss=[AllowLastNodeBoss],@AllowWorkCreator=[AllowWorkCreator],@PrcsUsers=[PrcsUsers],@PrcsDepts=[PrcsDepts],
	@PrcsRoles=[PrcsRoles],@PositionDept=[PositionDept] from  inserted  where NodeId=@NodeId

	set @PrcsUsers=''''+isnull(@PrcsUsers,'''')+''''
	set @PrcsDepts=''''+isnull(@PrcsDepts,'''')+''''
	set @PrcsRoles=''''+isnull(@PrcsRoles,'''')+''''
	set @PositionDept=''''+isnull(@PositionDept,'''')+''''

	DELETE from  [WF_FlowNodePrivilege]  WHERE  [NodeId]=@NodeId
	 
	EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
	@FlowId = @FlowId,@NodeId = @NodeId,@str = @PrcsUsers,@IdType = 1

	EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
	@FlowId = @FlowId,@NodeId = @NodeId,@str = @PrcsRoles,@IdType = 2

	EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
	@FlowId = @FlowId,@NodeId = @NodeId,@str = @PrcsDepts,@IdType = 3

	EXEC	[dbo].[DcxRun_WF_FlowNode_SetPower]
	@FlowId = @FlowId,@NodeId = @NodeId,@str = @PositionDept,@IdType = 4

	fetch next  from myCursor into @FlowId,@NodeId,@Old_PrcsItem,@Old_PrcsItem2
end
close myCursor --关闭
deallocate myCursor 

--if isnull(ltrim(rtrim(@PrcsItem)),'''')!=isnull(ltrim(rtrim(@Old_PrcsItem)),'''') or  isnull(ltrim(rtrim(@PrcsItem2)),'''')!=isnull(ltrim(rtrim(@Old_PrcsItem2)),'''')
--begin
--	select  @EntId=[EntId] from  [WF_FlowRun] where [FlowId]=@FlowId
--	set @EntId=isnull(@EntId,0)
--	if @EntId<1
--	return
--	declare @c int
--	set @c=0
--	 (select  top 1 @c=1 from  [Dcx_DefaultForm_Run] where [EntId]=@EntId)
--	if @c=1
--		select  [FieldName],[FldId] from  [Dcx_DefaultFormField_Run] where [EntId]=@EntId order by [FldId]
--	else
--		select  [FieldName],[FldId] from  [Dcx_AjaxFormField_Run] where [EntId]=@EntId order by [FldId]
--end

end

' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowPrivilege_ForInsert') 
 drop trigger  SetFlowPrivilege_ForInsert 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowPrivilege_ForInsert') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [SetFlowPrivilege_ForInsert] on dbo.WF_FlowType for insert
as
begin
declare @FlowId   int
declare @ManageUsers varchar(max)
declare @QueryUsers varchar(max)
declare @CanQueryRolesId varchar(max)
declare @CanManageRolesId varchar(max)
declare @CanStartUsers varchar(max)
declare @CanStartRolesId varchar(max)
declare @EntId   int
select    @EntId=[EntId],@FlowId=FlowId,@ManageUsers=[ManageUsers],@QueryUsers=[QueryUsers],@CanStartUsers=[CanStartUsers],@CanStartRolesId=[CanStartRolesId] from  inserted 
if @EntId is not null and @EntId>0
begin
	UPDATE [Dcx_Entity_Run]  SET [IsFlow] =1 ,[FlowId]= @FlowId WHERE  EntId=@EntId
	declare @ListUrl varchar(400)
	declare @FormUrl varchar(400)
	declare @BrowseUrl varchar(400)
	SELECT @ListUrl=[AreaUrl] FROM [Dcx_MenuAppArea] where   EntId=@EntId and [ModuleTypeId] in (1,8,9,10,11,12)
	SELECT @FormUrl=[AreaUrl] FROM [Dcx_MenuAppArea] where   EntId=@EntId and [ModuleTypeId] in (3,18)
	SELECT @BrowseUrl=[AreaUrl] FROM [Dcx_MenuAppArea] where   EntId=@EntId and [ModuleTypeId] in (16,19)
	set @ListUrl=isnull(@ListUrl,''/Template/Default/ListReport/ListReport001.aspx'')
	set @FormUrl=isnull(@FormUrl,''/Template/Default/Form/AjaxForm/AjaxForm008.aspx'')
	set @BrowseUrl=isnull(@BrowseUrl,''/Template/Default/Browse/Browse008.aspx'')
	UPDATE [WF_FlowType] SET [ListUrl] =@ListUrl ,[FormUrl]= @FormUrl ,[BrowseUrl]=@BrowseUrl WHERE  [FlowId]=@FlowId
end
set @ManageUsers=''''+isnull(@ManageUsers,'''')+''''
set @QueryUsers=''''+isnull(@QueryUsers,'''')+''''
set @CanStartUsers=''''+isnull(@CanStartUsers,'''')+''''
set @CanStartRolesId=''''+isnull(@CanStartRolesId,'''')+''''
DELETE from  [WF_FlowTypePrivilege]  WHERE  FlowId=@FlowId
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @ManageUsers,@IdType = 1,@PowerTypeId = 4
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @QueryUsers,@IdType = 1,@PowerTypeId = 1
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @CanStartUsers,@IdType = 1,@PowerTypeId = 2
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @CanStartRolesId,@IdType = 2,@PowerTypeId = 2
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowPrivilege_ForUpdate') 
 drop trigger  SetFlowPrivilege_ForUpdate 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='SetFlowPrivilege_ForUpdate') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE trigger [SetFlowPrivilege_ForUpdate] on dbo.WF_FlowType for Update
as
begin
declare @FlowId   int
declare @EntId_old   int
declare @EntId_new   int
select   @FlowId=FlowId,@EntId_new= EntId from  inserted 
select   @EntId_old= EntId from  deleted
set @EntId_new=isnull(@EntId_new,-1)
set @EntId_old=isnull(@EntId_old,-1)
if @EntId_new!=@EntId_old
begin
DELETE from  [WF_CanWriteField]  WHERE  FlowId=@FlowId
DELETE from  [WF_NodeCondition]  WHERE  FlowId=@FlowId
if @EntId_old is not null and @EntId_old>0
begin
	UPDATE [Dcx_Entity_Run]  SET [IsFlow] =0 ,[FlowId]= 0 WHERE  EntId=@EntId_old
end
if @EntId_new is not null and @EntId_new>0
begin
	declare @EntId   int
	set @EntId=@EntId_new
	UPDATE [Dcx_Entity_Run]  SET [IsFlow] =1 ,[FlowId]= @FlowId WHERE  EntId=@EntId
	declare @ListUrl varchar(400)
	declare @FormUrl varchar(400)
	declare @BrowseUrl varchar(400)
	SELECT @ListUrl=[AreaUrl] FROM [Dcx_MenuAppArea] where   EntId=@EntId and [ModuleTypeId] in (1,8,9,10,11,12)
	SELECT @FormUrl=[AreaUrl] FROM [Dcx_MenuAppArea] where   EntId=@EntId and [ModuleTypeId] in (3,18)
	SELECT @BrowseUrl=[AreaUrl] FROM [Dcx_MenuAppArea] where   EntId=@EntId and [ModuleTypeId] in (16,19)
	set @ListUrl=isnull(@ListUrl,''/Template/Default/ListReport/ListReport001.aspx'')
	set @FormUrl=isnull(@FormUrl,''/Template/Default/Form/AjaxForm/AjaxForm008.aspx'')
	set @BrowseUrl=isnull(@BrowseUrl,''/Template/Default/Browse/Browse008.aspx'')
	UPDATE [WF_FlowType] SET [ListUrl] =@ListUrl ,[FormUrl]= @FormUrl ,[BrowseUrl]=@BrowseUrl WHERE  [FlowId]=@FlowId
end
end
declare @ManageUsers varchar(max)
declare @QueryUsers varchar(max)
declare @CanQueryRolesId varchar(max)
declare @CanManageRolesId varchar(max)
declare @CanStartUsers varchar(max)
declare @CanStartRolesId varchar(max)
select   @ManageUsers=[ManageUsers],@QueryUsers=[QueryUsers],@CanStartUsers=[CanStartUsers],@CanStartRolesId=[CanStartRolesId] from  inserted 
set @ManageUsers=''''+isnull(@ManageUsers,'''')+''''
set @QueryUsers=''''+isnull(@QueryUsers,'''')+''''
set @CanStartUsers=''''+isnull(@CanStartUsers,'''')+''''
set @CanStartRolesId=''''+isnull(@CanStartRolesId,'''')+''''
DELETE from  [WF_FlowTypePrivilege]  WHERE  FlowId=@FlowId
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @ManageUsers,@IdType = 1,@PowerTypeId = 4
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @QueryUsers,@IdType = 1,@PowerTypeId = 1
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @CanStartUsers,@IdType = 1,@PowerTypeId = 2
EXEC	[dbo].[DcxRun_WF_FlowType_SetPower]
@FlowId = @FlowId,@str = @CanStartRolesId,@IdType = 2,@PowerTypeId = 2
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_dept_for_add') 
 drop trigger  update_dept_for_add 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_dept_for_add') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [dbo].[update_dept_for_add]
ON  dbo.工资_调动记录 for insert
AS
BEGIN

SET NOCOUNT ON;

declare @员工编号 varchar(40)
declare @员工姓名 varchar(40)
declare @调动后部门 varchar(40)
declare @现岗位级别 varchar(40)
declare @现基本工资  money
declare @现考核工资  money
select  @员工编号=员工编号,@员工姓名=员工姓名,@调动后部门=调动后部门,@现基本工资=现基本工资,@现考核工资=现考核工资,@现岗位级别=现岗位级别 from  inserted 
update 工资_员工档案 set 所在部门=@调动后部门,岗位级别=@现岗位级别,基本工资=@现基本工资,月考核工资=@现考核工资 where 员工编号=@员工编号


END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_money_for_add') 
 drop trigger  update_money_for_add 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_money_for_add') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 

CREATE TRIGGER [update_money_for_add]
ON  [dbo].[工资_调薪记录] for insert
AS
BEGIN

SET NOCOUNT ON;

declare @员工编号 varchar(40)
declare @调薪后岗位 varchar(40)

declare @员工姓名 varchar(40)
declare @调薪后考核工资 money
declare @调薪后基本工资 money
select  @调薪后岗位=调薪后岗位,@员工编号=员工编号,@员工姓名=员工姓名,@调薪后考核工资=调薪后考核工资,@调薪后基本工资=调薪后基本工资 from  inserted 
update 工资_员工档案 set 员工岗位=@调薪后岗位,基本工资=@调薪后基本工资,月考核工资=@调薪后考核工资 where 员工编号=@员工编号


END

' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_用户所在部门') 
 drop trigger  update_用户所在部门 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_用户所在部门') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [update_用户所在部门]
ON  dbo.工资_员工档案 for update
AS
BEGIN

SET NOCOUNT ON;
--declare @所在部门 varchar(100)
--declare @部门编号 varchar(100)
--declare @员工编号 varchar(100)
--declare @old_员工编号 varchar(100)
--declare @公司名称 varchar(100)
--declare @公司编号 varchar(100)
--
--declare @Id int
--declare @出生日期 varchar(100)
--declare @入职日期 varchar(100)
--declare @签订日期 varchar(100)
--declare @合同到期日 varchar(100)
--select  @old_员工编号=ltrim(rtrim(员工编号)) from   deleted
--
--select  @所在部门=ltrim(rtrim(所在部门)),@员工编号=员工编号,@Id=Id, @出生日期=出生日期,
--@入职日期=入职日期,@签订日期=签订日期,@合同到期日=合同到期日 from   inserted 
--select  @部门编号=[部门编号],@公司名称=ltrim(rtrim(company_name)),@公司编号=ltrim(rtrim(company_code))
-- from  [工资_部门信息] where [部门名称]=@所在部门
--
--update Dcx_User set DeptName=@所在部门,DeptNO=@部门编号,StaffNO=@员工编号 where ltrim(rtrim(ROLE))=''Public'' and StaffNO=@old_员工编号
--
--update 工资_员工档案 set 公司=@公司名称,公司编号=@公司编号,[部门编号]=@部门编号,年龄=(case when [出生日期]='''' or [出生日期] is null then null else year(getdate())-year([出生日期])  end),
-- 入职年限=(case when 入职日期='''' or 入职日期 is null then null else  year(getdate())-year(入职日期)  end),
-- 合同期限=(case when 合同到期日='''' or 合同到期日 is null or  签订日期='''' or 签订日期 is null then null else  year(合同到期日)-year(签订日期)  end)
-- where id=@Id
-----------------------------------------------------------------------------------


END

set ANSI_NULLS ON
set QUOTED_IdENTIFIER ON
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_年入期') 
 drop trigger  update_年入期 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_年入期') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [update_年入期]
ON  dbo.工资_员工档案 for insert
AS
BEGIN

SET NOCOUNT ON;

--declare @Id int
--declare @公司名称 varchar(100)
--declare @公司编号 varchar(100)
--
--declare @所在部门 varchar(100)
--declare @部门编号 varchar(100)
--
--select  @Id=Id,@所在部门=ltrim(rtrim(所在部门)) from   inserted 
--select  @部门编号=[部门编号],@公司名称=ltrim(rtrim(company_name)),@公司编号=ltrim(rtrim(company_code)) from  [工资_部门信息] where [部门名称]=@所在部门
--
--update 工资_员工档案 set  公司=@公司名称,公司编号=@公司编号,部门编号=@部门编号,年龄=(case when [出生日期]='''' or [出生日期] is null then null else year(getdate())-year([出生日期])  end),
-- 入职年限=(case when 入职日期='''' or 入职日期 is null then null else  year(getdate())-year(入职日期)  end),
-- 合同期限=(case when 合同到期日='''' or 合同到期日 is null or  签订日期='''' or 签订日期 is null then null else  year(合同到期日)-year(签订日期)  end)
-- where id=@Id
-----------------------------------------------------------------------------------


END

set ANSI_NULLS ON
set QUOTED_IdENTIFIER ON
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='EntitySheet_Update_FieldTypeId') 
 drop trigger  EntitySheet_Update_FieldTypeId 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='EntitySheet_Update_FieldTypeId') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [EntitySheet_Update_FieldTypeId]
ON  dbo.Dcx_EntitySheet for insert
AS
BEGIN

SET NOCOUNT ON;

declare @Id int
declare @FieldType varchar(100)
select  @Id=Id,@FieldType=ltrim(rtrim(FieldType))  from   inserted 


declare @FieldTypeId int
select  @FieldTypeId=FieldTypeId  from   Dcx_ReportFieldType where   lower(ltrim(rtrim(FieldTypeValue)))=lower(@FieldType)
set @FieldTypeId=isnull(@FieldTypeId,1)

update Dcx_EntitySheet set FieldTypeId=@FieldTypeId where Id=@Id
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Update_dept_ForUpdate') 
 drop trigger  Update_dept_ForUpdate 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Update_dept_ForUpdate') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [Update_dept_ForUpdate] 
   ON  [dbo].[公司信息] for update
AS 
BEGIN
	SET NOCOUNT ON;
declare @公司名称 varchar(100) 
declare @公司编号 varchar(40) 
select @公司名称=ltrim(rtrim(公司名称)),@公司编号=ltrim(rtrim(公司编号)) from inserted
--update 部门信息 set company_name=@公司名称 where ltrim(rtrim(company_code))=@公司编号
update 财务_公司信息 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_账务授权 set 分公司名称=@公司名称 where ltrim(rtrim(分公司编号))=@公司编号
update 财务_科目余额表 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_科目余额历史表 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_凭证表 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_凭证历史表 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_明细分类帐 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_明细分类帐历史表 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_总分类帐历史表 set 公司名称=@公司名称 where ltrim(rtrim(公司编号))=@公司编号
update 财务_往来单位资料 set 所属分公司名称=@公司名称 where ltrim(rtrim(所属分公司编号))=@公司编号
-----------------------------------------------------------------------------------
--insert into hj_users(username,roles,bm,f_hp,员工编号,realname,部门编号) values(@username,''Public'',@部门名称,''A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'',@worker_NO,@姓名,@部门编号)
--if @role<>''Public'' begin
--insert into hj_users(username,roles,f_hp,员工编号) values(@username,@role,''A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'',@worker_NO)
--return 
--end
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Update_dept_ForInsert') 
 drop trigger  Update_dept_ForInsert 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Update_dept_ForInsert') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [Update_dept_ForInsert] 
   ON  [dbo].[公司信息] for insert
AS 
BEGIN
	SET NOCOUNT ON;
declare @公司名称 varchar(100) 
declare @公司编号 varchar(40) 
select @公司名称=ltrim(rtrim(公司名称)),@公司编号=ltrim(rtrim(公司编号)) from inserted
--update 部门信息 set company_name=@公司名称 where ltrim(rtrim(company_code))=@公司编号
-----------------------------------------------------------------------------------
--insert into hj_users(username,roles,bm,f_hp,员工编号,realname,部门编号) values(@username,''Public'',@部门名称,''A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'',@worker_NO,@姓名,@部门编号)
--if @role<>''Public'' begin
--insert into hj_users(username,roles,f_hp,员工编号) values(@username,@role,''A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'',@worker_NO)
--return 
--end
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='jihua_dele') 
 drop trigger  jihua_dele 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='jihua_dele') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER jihua_dele ON dbo.计划总结
FOR  UPDATE
AS
declare @id int
declare @p1 varchar(500)
select  @p1=people1 from  inserted 
if @p1=''''
begin
select  @id=id from  inserted 
delete from  计划总结 where id=@id
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='delnewfujisn') 
 drop trigger  delnewfujisn 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='delnewfujisn') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
-- =============================================
-- Author:		<Author,,Name>
-- alter date: <alter Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE TRIGGER delnewfujisn
ON  dbo.新闻公告
AFTER DELETE
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from 
-- interfering with select  statements.
SET NOCOUNT ON;
declare @keyid int
select  @keyid=id from  deleted
delete from  dbo.新闻公告_附件 where [newid]=@keyid
-- Insert statements for trigger here

END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='工作日志_no_update') 
 drop trigger  工作日志_no_update 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='工作日志_no_update') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 

CREATE TRIGGER [工作日志_no_update] ON [dbo].[工作日志]
FOR update
AS
begin
declare @序号  int
select  @序号=序号 from  inserted 
if (select  本人意见 from  工作日志 WHERE 序号=@序号) is not  null and  (select  rtrim(本人意见) from  工作日志 WHERE 序号=@序号)<>''''
begin
DECLARE @ptrvall binary(16)
select  @ptrvall = TEXTPTR(领导意见) from  工作日志 WHERE 序号=@序号
DECLARE @textl varchar(1000)
select  @textl=''<p>''+本人意见+''( ''+isnull(填写人,'''')+'' 填写时间 ''+convert(varchar(20),getdate(),20)+'')</p>''  from  工作日志 WHERE 序号=@序号
declare @DATALENGTHl int
select   @DATALENGTHl=DATALENGTH(领导意见)  from  工作日志 WHERE  序号=@序号
UPDATETEXT 工作日志.领导意见 @ptrvall  @DATALENGTHl 0 @textl
end
update 工作日志 set 本人意见=''''  where 序号=@序号
if (select  内容输入 from  工作日志 WHERE 序号=@序号) is not  null and  (select  rtrim(内容输入) from  工作日志 WHERE 序号=@序号)<>''''
begin
DECLARE @ptrvall1 binary(16)
select  @ptrvall1 = TEXTPTR(工作内容) from  工作日志 WHERE 序号=@序号
DECLARE @textl1 varchar(1000)
select  @textl1=''<br><p><font color=#008000><b>工作时段:</b></font> ''+起止时间+'' (<font color=#008000><b>填写时间</b></font> ''+convert(varchar(20),getdate(),20)+'')<br>&nbsp;&nbsp;'' +内容输入+''</p>''  from  工作日志 WHERE 序号=@序号
declare @DATALENGTHl1 int
select   @DATALENGTHl1=DATALENGTH(工作内容)  from  工作日志 WHERE  序号=@序号
UPDATETEXT 工作日志.工作内容 @ptrvall1 @DATALENGTHl1 0 @textl1
DECLARE @ptrvall2 binary(16)
select  @ptrvall2 = TEXTPTR(工作内容1) from  工作日志 WHERE 序号=@序号
DECLARE @textl2 varchar(1000)
select  @textl2=''<br><p><font color=#008000><b>工作时段:</b></font> ''+起止时间+'' (<font color=#008000><b>填写时间</b></font> ''+convert(varchar(20),getdate(),20)+'')<br>&nbsp;&nbsp;'' +left(内容输入+space(20),20)+''......''+''</p>''  from  工作日志 WHERE 序号=@序号
declare @DATALENGTHl2 int
select   @DATALENGTHl2=DATALENGTH(工作内容1)  from  工作日志 WHERE  序号=@序号
UPDATETEXT 工作日志.工作内容1 @ptrvall2 @DATALENGTHl2 0 @textl2
end
update 工作日志 set 内容输入=''''  where 序号=@序号
end

' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='工作日志_INSERT') 
 drop trigger  工作日志_INSERT 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='工作日志_INSERT') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 


CREATE TRIGGER [工作日志_INSERT] ON [dbo].[工作日志]
FOR INSERT
AS
begin
declare @序号  int
select  @序号=序号 from  inserted 
if (select  内容输入 from  工作日志 WHERE 序号=@序号) is not  null and  (select  rtrim(内容输入) from  工作日志 WHERE 序号=@序号)<>''''
begin
DECLARE @ptrvall1 binary(16)
select  @ptrvall1 = TEXTPTR(工作内容) from  工作日志 WHERE 序号=@序号
DECLARE @textl1 varchar(1000)
select  @textl1=''<p><font color=#008000><b>工作时段:</b></font>''+起止时间+'' (<font color=#008000><b>填写时间</b></font> ''+convert(varchar(20),getdate(),20)+'')<br>&nbsp;&nbsp;'' +内容输入+''</p>''  from  工作日志 WHERE 序号=@序号
declare @DATALENGTHl1 int
select   @DATALENGTHl1=DATALENGTH(工作内容)  from  工作日志 WHERE  序号=@序号
UPDATETEXT 工作日志.工作内容 @ptrvall1 @DATALENGTHl1 0 @textl1
DECLARE @ptrvall2 binary(16)
select  @ptrvall2 = TEXTPTR(工作内容1) from  工作日志 WHERE 序号=@序号
DECLARE @textl2 varchar(1000)
select  @textl2=''<p><font color=#008000><b>工作时段:</b></font>''+起止时间+'' (<font color=#008000><b>填写时间</b></font> ''+convert(varchar(20),getdate(),20)+'')<br>&nbsp;&nbsp;'' +left(内容输入+space(20),20)+''......''+''</p>''  from  工作日志 WHERE 序号=@序号
declare @DATALENGTHl2 int
select   @DATALENGTHl2=DATALENGTH(工作内容1)  from  工作日志 WHERE  序号=@序号
UPDATETEXT 工作日志.工作内容1  @ptrvall2  @DATALENGTHl2 0 @textl2
end
update 工作日志 set 内容输入='''',write_date= convert(varchar(10),getdate(),120)  where 序号=@序号
end


' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_comAndDeptForInsert') 
 drop trigger  update_comAndDeptForInsert 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_comAndDeptForInsert') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 






CREATE TRIGGER [update_comAndDeptForInsert]
ON  [dbo].员工调动信息 for insert
AS
BEGIN

SET NOCOUNT ON;

declare @worker_NO varchar(40)
--修改公司名称和部门名称
declare @公司编号 varchar(40)
declare @部门编号 varchar(40)
declare @公司名称 varchar(40)
declare @部门名称 varchar(40)
select  @worker_NO=[员工编号],@公司编号=公司编号,@部门编号=部门编号 from  inserted 
select  top 1 @公司名称=公司名称 from  公司信息 where 公司编号=@公司编号
select  top 1 @部门名称=dept_name from  部门信息 where dept_code=@部门编号
update 员工调动信息 set 公司=@公司名称, 部门=@部门名称 where 员工编号=@worker_NO
return
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_comAndDeptForUpdate') 
 drop trigger  update_comAndDeptForUpdate 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_comAndDeptForUpdate') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 






CREATE TRIGGER [update_comAndDeptForUpdate]
ON  [dbo].员工调动信息 for update
AS
BEGIN

SET NOCOUNT ON;

declare @worker_NO varchar(40)
--修改公司名称和部门名称
declare @公司编号 varchar(40)
declare @部门编号 varchar(40)
declare @公司名称 varchar(40)
declare @部门名称 varchar(40)
select  @worker_NO=[员工编号],@公司编号=公司编号,@部门编号=部门编号 from  inserted 
select  top 1 @公司名称=公司名称 from  公司信息 where 公司编号=@公司编号
select  top 1 @部门名称=dept_name from  部门信息 where dept_code=@部门编号
update 员工调动信息 set 公司=@公司名称, 部门=@部门名称 where 员工编号=@worker_NO
return
end
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_peopleNO') 
 drop trigger  update_peopleNO 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='update_peopleNO') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [update_peopleNO]
ON  dbo.员工基本信息 for update
AS
BEGIN

SET NOCOUNT ON;

declare @old_NO varchar(4) --流水号
declare @new_NO varchar(8)
declare @公司编号 varchar(40)
declare @部门编号 varchar(40)
declare @公司名称 varchar(40)
declare @部门名称 varchar(40)

select  @old_NO=[员工编号] from  deleted
select  @new_NO=[员工编号],@公司编号=公司编号,@部门编号=部门编号 from  inserted 
update [员工调动信息] set [员工编号]=@new_NO where [员工编号]=@old_NO
update [员工奖惩信息] set [员工编号]=@new_NO where [员工编号]=@old_NO
update [员工社会关系] set [员工编号]=@new_NO where [员工编号]=@old_NO
update [员工培训信息] set [员工编号]=@new_NO where [员工编号]=@old_NO
update [员工调动信息] set [员工编号]=@new_NO where [员工编号]=@old_NO
update [员工薪酬信息] set [员工编号]=@new_NO where [员工编号]=@old_NO
update [hj_users] set [员工编号]=@new_NO where [员工编号]=@old_NO
--修改公司名称和部门名称

select  top 1 @公司名称=公司名称 from  公司信息 where 公司编号=@公司编号
select  top 1 @部门名称=dept_name from  部门信息 where dept_code=@部门编号
update 员工基本信息 set 公司=@公司名称, 部门=@部门名称 where 员工编号=@new_NO
update HJ_USERS set bm=@部门名称,部门编号=@部门编号,员工编号=@new_NO where 员工编号=@old_NO
-----------------------------------------------------------------------------------
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='delete_childTable') 
 drop trigger  delete_childTable 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='delete_childTable') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE TRIGGER [dbo].[delete_childTable]
ON  dbo.员工基本信息 for delete
AS
BEGIN

SET NOCOUNT ON;

declare @old_NO varchar(4) --流水号


select  @old_NO=[员工编号] from  deleted
delete from   [员工调动信息] where [员工编号]=@old_NO
delete from  [员工奖惩信息]  where [员工编号]=@old_NO
delete from  [员工社会关系]  where [员工编号]=@old_NO
delete from  [员工培训信息]  where [员工编号]=@old_NO
delete from  [员工调动信息]  where [员工编号]=@old_NO
delete from  [员工薪酬信息]  where [员工编号]=@old_NO

END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF  EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Add_user') 
 drop trigger  Add_user 
IF NOT EXISTS (SELECT name FROM sys.sysobjects WHERE  xtype='TR' and name ='Add_user') 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 

CREATE TRIGGER [Add_user]
ON  [dbo].[员工基本信息] for insert
AS
BEGIN

SET NOCOUNT ON;

declare @username varchar(40)
declare @姓名 varchar(40)
declare @role varchar(40)
declare @worker_NO varchar(40)
--修改公司名称和部门名称
declare @公司编号 varchar(40)
declare @部门编号 varchar(40)
declare @公司名称 varchar(40)
declare @部门名称 varchar(40)
select  @role=[角色],@worker_NO=[员工编号],@公司编号=公司编号,@部门编号=部门编号,@姓名=姓名 from  inserted 
select  top 1 @公司名称=公司名称 from  公司信息 where 公司编号=@公司编号
select  top 1 @部门名称=dept_name from  部门信息 where dept_code=@部门编号
update 员工基本信息 set 公司=@公司名称, 部门=@部门名称 where 员工编号=@worker_NO
-----------------------------------------------------------------------------------

--insert into hj_users(username,roles,bm,f_hp,员工编号,realname,部门编号) values(@username,''Public'',@部门名称,''A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'',@worker_NO,@姓名,@部门编号)
--if @role<>''Public'' begin
--insert into hj_users(username,roles,f_hp,员工编号) values(@username,@role,''A3-C3-71-6C-43-81-86-5D-33-1A-DF-38-B9-FD-F7-F8'',@worker_NO)
--return
--end
END


' 
END 
----------------------------------------------------------------------------------------  上：触发器  ----------------------------------------------------------------------------------
----------------------------------------------------------------------------------------  下：函数  ----------------------------------------------------------------------------------
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fn_diagramobjects]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[fn_diagramobjects]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fn_diagramobjects]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
	CREATE FUNCTION dbo.fn_diagramobjects() 
	RETURNS int
	WITH EXECUTE AS N''dbo''
	AS
	BEGIN
		declare @id_upgraddiagrams		int
		declare @id_sysdiagrams			int
		declare @id_helpdiagrams		int
		declare @id_helpdiagramdefinition	int
		declare @id_creatediagram	int
		declare @id_renamediagram	int
		declare @id_alterdiagram 	int 
		declare @id_dropdiagram		int
		declare @InstalledObjects	int
		select @InstalledObjects = 0
		select 	@id_upgraddiagrams = object_id(N''dbo.sp_upgraddiagrams''),
			@id_sysdiagrams = object_id(N''dbo.sysdiagrams''),
			@id_helpdiagrams = object_id(N''dbo.sp_helpdiagrams''),
			@id_helpdiagramdefinition = object_id(N''dbo.sp_helpdiagramdefinition''),
			@id_creatediagram = object_id(N''dbo.sp_creatediagram''),
			@id_renamediagram = object_id(N''dbo.sp_renamediagram''),
			@id_alterdiagram = object_id(N''dbo.sp_alterdiagram''), 
			@id_dropdiagram = object_id(N''dbo.sp_dropdiagram'')
		if @id_upgraddiagrams is not null
			select @InstalledObjects = @InstalledObjects + 1
		if @id_sysdiagrams is not null
			select @InstalledObjects = @InstalledObjects + 2
		if @id_helpdiagrams is not null
			select @InstalledObjects = @InstalledObjects + 4
		if @id_helpdiagramdefinition is not null
			select @InstalledObjects = @InstalledObjects + 8
		if @id_creatediagram is not null
			select @InstalledObjects = @InstalledObjects + 16
		if @id_renamediagram is not null
			select @InstalledObjects = @InstalledObjects + 32
		if @id_alterdiagram  is not null
			select @InstalledObjects = @InstalledObjects + 64
		if @id_dropdiagram is not null
			select @InstalledObjects = @InstalledObjects + 128
		return @InstalledObjects 
	END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fun_getPY]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[fun_getPY]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[fun_getPY]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function    [dbo].[fun_getPY](@str   nvarchar(4000))   
  returns   nvarchar(4000)   
  as   
  begin   
  declare   @word   nchar(1),@PY   nvarchar(4000)   
  set   @PY=''''   
  while   len(@str)>0   
  begin   
  set   @word=left(@str,1)   
  --如果非汉字字符，返回原字符   
  set   @PY=@PY+(case   when   unicode(@word)   between   19968   and   19968+20901   
  then   (select   top   1   PY   from   (   
  select   ''A''   as   PY,N''骜''   as   word   
  union   all   select   ''B'',N''簿''   
  union   all   select   ''C'',N''错''   
  union   all   select   ''D'',N''鵽''   
  union   all   select   ''E'',N''樲''   
  union   all   select   ''F'',N''鳆''   
  union   all   select   ''G'',N''腂''   
  union   all   select   ''H'',N''夻''   
  union   all   select   ''J'',N''攈''   
  union   all   select   ''K'',N''穒''   
  union   all   select   ''L'',N''鱳''   
  union   all   select   ''M'',N''旀''   
  union   all   select   ''N'',N''桛''   
  union   all   select   ''O'',N''沤''   
  union   all   select   ''P'',N''曝''   
  union   all   select   ''Q'',N''囕''   
  union   all   select   ''R'',N''鶸''   
  union   all   select   ''S'',N''蜶''   
  union   all   select   ''T'',N''箨''   
  union   all   select   ''W'',N''鹜''   
  union   all   select   ''X'',N''鑂''   
  union   all   select   ''Y'',N''韵''   
  union   all   select   ''Z'',N''咗''   
  )   T     
  where   word>=@word   collate   Chinese_PRC_CS_AS_KS_WS     
  order   by   PY   ASC)   else   @word   end)   
  set   @str=right(@str,len(@str)-1)   
  end   
  return   @PY   
  end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_DAH]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[Get_DAH]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_DAH]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[Get_DAH] (@TypeDH varchar(50))  --返回归档号
RETURNS varchar (50) AS  
BEGIN 
	Declare @档案号  varchar(40)
	Declare @len  int
	Select @len=len(@TypeDH)
	/* 生成归档号 */
	If (SELECT Count(档案号) FROM dbo.DA_档案著录 Where @TypeDH+''-''=LEFT(档案号,@len+1))>0 
		SELECT @档案号=@TypeDH+''-''+right(str(max(convert(int,substring(档案号,@len+2,5))+1)+100000),5)
		FROM dbo.DA_档案著录 WHERE @TypeDH+''-'' = LEFT(档案号,@len+1)
	Else
		SELECT @档案号=@TypeDH + ''-00001''
	RETURN @档案号
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_RoleNameStr]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[Get_RoleNameStr]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_RoleNameStr]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[Get_RoleNameStr] --获取指定用户的角色名称串：系统管理员,普通员工
( 
@UserId int
) 
returns varchar(1000)  
as 
begin 
declare @RoleNames varchar(1000) 
set @RoleNames=''''
select @RoleNames=@RoleNames+isnull([RoleName],'''')+'','' from [Dcx_Role] where [RoleId] in (select A.[RoleId] From [Dcx_UserInRole] as A where A.[UserId]=@UserId)
return @RoleNames 
--调用示例：select dbo.Get_RoleNameStr(1) 
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_RoleNameStr_ByUserName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[Get_RoleNameStr_ByUserName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_RoleNameStr_ByUserName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[Get_RoleNameStr_ByUserName] --获取指定用户的角色名称串：系统管理员,普通员工
( 
@UserName varchar(30) 
) 
returns varchar(1000) 
as 
begin 
declare @RoleNames varchar(1000) 
set @RoleNames=''''
select @RoleNames=@RoleNames+isnull([RoleName],'''')+'','' from [Dcx_Role] where [RoleId] in (select A.[RoleId] From [Dcx_UserInRole] as A where A.[UserId]=
(select top 1 B.[UserId] from Dcx_User as B where B.UserName=@UserName))
return @RoleNames 
--调用示例：select dbo.Get_RoleNameStr(1) 
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_StrArrayLength]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[Get_StrArrayLength]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_StrArrayLength]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[Get_StrArrayLength] --按指定符号分割字符串，返回分割后的元素个数
( 
@str varchar(1024), --要分割的字符串 
@split varchar(10) --分隔符号 
) 
returns int 
as 
begin 
declare @location int --当前分隔符的位置
declare @start int --进行下一次查找的开始位置
declare @length int --元素个数
declare @seed int --分隔符的长度
set @split=isnull(ltrim(rtrim(@split)),'','')
set @str=isnull(ltrim(rtrim(@str)),'''')
set @seed=len(ltrim(rtrim(@split)))
set @location=charindex(@split,@str) 
set @length=1 
while @location<>0 
begin 
set @start=@location+@seed 
set @location=charindex(@split,@str,@start) 
set @length=@length+1 
end 
return @length 
--调用示例：select dbo.Get_StrArrayLength(''78,1,2,3'','','') 
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_StrArrayStrOfIndex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[Get_StrArrayStrOfIndex]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_StrArrayStrOfIndex]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[Get_StrArrayStrOfIndex] --按指定符号分割字符串，返回分割后指定索引的第几个元素，象数组一样方便
( 
@str varchar(1024), --要分割的字符串 
@split varchar(10), --分隔符号 
@index int --取第几个元素 
) 
returns varchar(1024) 
as 
begin 
declare @location int --当前分隔符的位置
declare @start int --进行下一次查找的开始位置
declare @next int --下一个的位置
declare @seed int --分隔符的长度
set @split=isnull(ltrim(rtrim(@split)),'','')
set @str=isnull(ltrim(rtrim(@str)),'''')
set @str=ltrim(rtrim(@str)) 
set @start=1 
set @next=1 
set @seed=len(@split) 
set @location=charindex(@split,@str) 
while @location<>0 and @index>@next 
begin 
set @start=@location+@seed 
set @location=charindex(@split,@str,@start) 
set @next=@next+1 
end 
if @location =0 select @location =len(@str)+1 
--这儿存在两种情况：1、字符串不存在分隔符号 2、字符串中存在分隔符号，跳出while循环后，@location为0，那默认为字符串后边有一个分隔符号. 
return substring(@str,@start,@location-@start) 
--调用示例：select dbo.Get_StrArrayStrOfIndex(''8,9,4'','','',2) 
--返回值：9
--应用示例：
--declare @str varchar(50) 
--declare @arrlen int
--set @arrlen=dbo.Get_StrArrayLength(@str,'','') 
--set @str=''1,2,3,4,5'' 
--declare @next int 
--set @next=1 
--while @next<=@arrlen
--begin 
--print dbo.Get_StrArrayStrOfIndex(@str,'','',@next) 
--set @next=@next+1 
--end
end 
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_workday]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[Get_workday]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[Get_workday]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[Get_workday] (@begindate datetime,@enddate datetime) 
RETURNS int AS  
BEGIN 
  declare  @days   int   
  set   @days=0   
  while   @begindate<=@enddate   
  begin   
  if   (datepart(DW,@begindate)!=1)   and   (datepart(DW,@begindate)!=7)   
  set   @days=@days+1     
  set   @begindate=@begindate+1  
  end 
if @days>22
-- 薪酬体系规定是22天 23天也当成22天
set  @days=22
	RETURN @days
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetChildMenuNode]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--从Dcx_Menu获取  所有的子级菜单   
CREATE function [dbo].[GetChildMenuNode](@menuId int)    
returns @t table(MenuId int,ParentId int,Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
    insert into @t select @menuId,@menuId,0 --当前级，本级，如果不要的话可以注释掉或再加个参数来选择操作    
    insert into @t select MenuId,ParentId,@i from Dcx_Menu where ParentId = @menuId    
    while @@rowcount<>0    
    begin   
        set @i = @i + 1    
        insert into @t    
        select   
            a.MenuId,a.ParentId,@i    
        from   
            Dcx_Menu a,@t b    
        where   
            a.ParentId=b.MenuId and b.Level = @i-1    
    end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNode_System]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetChildMenuNode_System]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNode_System]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--从Dcx_Menu和Dcx_SystemMenu获取  所有的子级菜单   
CREATE function [dbo].[GetChildMenuNode_System](@menuId int,@systemId int)    
returns @t table(MenuId int,ParentId int,Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
    insert into @t select @menuId,@menuId,0 --当前级，本级，如果不要的话可以注释掉或再加个参数来选择操作    
    insert into @t select MenuId,ParentId,@i from Dcx_Menu where ParentId = @menuId    
    while @@rowcount<>0    
    begin   
        set @i = @i + 1    
        insert into @t    
        select   
            a.MenuId,a.ParentId,@i    
        from   
            Dcx_Menu a,@t b    
        where   
            a.ParentId=b.MenuId and b.Level = @i-1    
    end   
if @systemId>0
    insert into @t select MenuId,(select top 1 A.ParentId from Dcx_Menu as A where 
	A.MenuId=B.MenuId),0 from Dcx_SystemMenu as B where B.SystemId = @systemId    
--    insert into @t select MenuId,(case when B.ParentId<1 then (select top 1 A.ParentId from Dcx_Menu as A where 
--	A.MenuId=B.MenuId) else B.ParentId end),0 from Dcx_SystemMenu as B where B.SystemId = @systemId    
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetChildMenuNodes]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--从Dcx_Menu获取  所有的子级菜单   
CREATE function [dbo].[GetChildMenuNodes](@menuId int)    
returns @t 
table(
menuId int,
ParentId int,
	menuName varchar(100)   ,
	ProPath varchar(200)  ,
	ImgPath varchar(50)  ,
	ExImgPath varchar(50)  ,
--	userNames varchar(max),
--	roles varchar(max),
	OrderBy int  ,
	IsHidden bit ,
Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
 insert into @t 
SELECT [MenuId]
      ,a.ParentId
      ,a.[MenuName]
      ,a.[ProPath]
      ,a.[ImgPath]
      ,a.[ExImgPath]
--      ,a.[userNames]
--      ,a.[roles]
      ,a.[OrderBy]
      ,a.[IsHidden],@i   from Dcx_Menu  as a where a.ParentId = @menuId    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.OrderBy,a.MenuId 
    while @@rowcount<>0    
    begin   
        set @i = @i + 1  
        insert into @t    
      SELECT a.[MenuId]
      ,a.[ParentId]
      ,a.[MenuName]
      ,a.[ProPath]
      ,a.[ImgPath]
      ,a.[ExImgPath]
--      ,a.[userNames]
--      ,a.[roles]
      ,a.[OrderBy]
      ,a.[IsHidden]
,@i 
        FROM    Dcx_Menu a,@t b    
        where   
            a.ParentId=b.menuId and b.Level = @i-1    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.OrderBy,a.MenuId   
    end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes_Run]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetChildMenuNodes_Run]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes_Run]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--从[Dcx_Menu_Run]获取所有的子孙级菜单，含它本身 
--@IsHidden：隐藏的菜单，是否显示
CREATE function [dbo].[GetChildMenuNodes_Run](@menuId int,@IsHidden int)    
returns @t table(
			[MenuId] int,
			[ParentId] int,
			[MenuName] varchar(100)   ,
			[ProPath] varchar(200)  ,
			[ImgPath] varchar(50)  ,
			[ExImgPath] varchar(50)  ,
			[OrderBy] int  ,
			[IsHidden] bit ,
			[Target] varchar(50)  ,
			Level int
		)  
as   
begin   
declare @i int   
set @i = 1    
--1。插入顶级菜单
if @IsHidden=1 or @IsHidden is null 
begin 
	insert into @t SELECT [MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.[IsHidden],a.Target,@i   from [Dcx_Menu_Run]  as a where a.[ParentId] = @menuId    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId] 
end
else 
begin 
	insert into @t SELECT [MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.[IsHidden],a.Target,@i   from [Dcx_Menu_Run]  as a where a.[ParentId] = @menuId   ORDER BY a.[OrderBy],a.[MenuId] 
end   
--2。插入父菜单下的子菜单
while @@rowcount<>0    
begin   
	set @i = @i + 1
	if @IsHidden=1 or @IsHidden is null 
	begin 
		insert into @t SELECT a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.[IsHidden],a.Target,@i   FROM    @t b inner join [Dcx_Menu_Run] a on 
		  b.Level = @i-1  and b.[MenuId]=a.[ParentId]    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId]   
	end   
	else 
	begin 
		insert into @t SELECT a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.[IsHidden],a.Target,@i   FROM    @t b inner join [Dcx_Menu_Run] a on 
		  b.Level = @i-1  and b.[MenuId]=a.[ParentId]  ORDER BY a.[OrderBy],a.[MenuId]   
	end   
end   
return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes_Run_NoTopMenu]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetChildMenuNodes_Run_NoTopMenu]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes_Run_NoTopMenu]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--从[Dcx_Menu_Run]获取所有的子孙级菜单，不含它本身 
CREATE function [dbo].[GetChildMenuNodes_Run_NoTopMenu](@ParentId int)
returns @t table(
			[MenuId] int,
			[ParentId] int,
			[MenuName] varchar(100)   ,
			[ProPath] varchar(200)  ,
			[ImgPath] varchar(50)  ,
			[ExImgPath] varchar(50)  ,
			[OrderBy] int  ,
			[IsHidden] bit ,
			[Target] varchar(50)  ,
			Level int
		)  
as   
begin   
declare @i int   
set @i = 1    
--插入父菜单下的子菜单
while @i=1 or @@rowcount<>0    
begin   
	if @i=1
			insert into @t SELECT a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.[IsHidden],a.Target,@i   FROM     [Dcx_Menu_Run] a where  a.[ParentId]=@ParentId    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId]   
	else
			insert into @t SELECT a.[MenuId],a.[ParentId],a.[MenuName],a.[ProPath],a.[ImgPath],a.[ExImgPath],a.[OrderBy],a.[IsHidden],a.Target,@i   FROM    @t b inner join [Dcx_Menu_Run] a on 
			  b.Level = @i-1  and b.[MenuId]=a.[ParentId]    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.[OrderBy],a.[MenuId]   
	set @i = @i + 1
end   
return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes2]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetChildMenuNodes2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetChildMenuNodes2]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--从Dcx_Menu获取  所有的子级菜单   
CREATE function [dbo].[GetChildMenuNodes2](@menuId int,@IsHidden int)    
returns @t 
table(
menuId int,
ParentId int,
	menuName varchar(100)   ,
	ProPath varchar(200)  ,
	ImgPath varchar(50)  ,
	ExImgPath varchar(50)  ,
--	userNames varchar(max),
--	roles varchar(max),
	OrderBy int  ,
	IsHidden bit ,
Target varchar(50)  ,
Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
if @IsHidden=1 or @IsHidden is null 
begin 
	insert into @t 
	SELECT [MenuId]
		  ,a.ParentId
		  ,a.[MenuName]
		  ,a.[ProPath]
		  ,a.[ImgPath]
		  ,a.[ExImgPath]
	--      ,a.[userNames]
	--      ,a.[roles]
		  ,a.[OrderBy]
		  ,a.[IsHidden],a.Target,@i   from Dcx_Menu  as a where a.ParentId = @menuId    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.OrderBy,a.MenuId 
 end
 else 
begin 
	insert into @t 
	SELECT [MenuId]
		  ,a.ParentId
		  ,a.[MenuName]
		  ,a.[ProPath]
		  ,a.[ImgPath]
		  ,a.[ExImgPath]
	--      ,a.[userNames]
	--      ,a.[roles]
		  ,a.[OrderBy]
		  ,a.[IsHidden],a.Target,@i   from Dcx_Menu  as a where a.ParentId = @menuId   ORDER BY a.OrderBy,a.MenuId 
end   
while @@rowcount<>0    
begin   
     set @i = @i + 1  
     if @IsHidden=1 or @IsHidden is null 
	 begin 
	 insert into @t    
		  SELECT a.[MenuId]
		  ,a.ParentId
		  ,a.[MenuName]
		  ,a.[ProPath]
		  ,a.[ImgPath]
		  ,a.[ExImgPath]
	--      ,a.[userNames]
	--      ,a.[roles]
		  ,a.[OrderBy]
		  ,a.[IsHidden],a.Target
	,@i 
			FROM    Dcx_Menu a,@t b    
			where   
				a.ParentId=b.menuId and b.Level = @i-1    and  ( a.IsHidden=0 or  a.IsHidden is null ) ORDER BY a.OrderBy,a.MenuId   
		end   
	 else 
	   begin 
	 insert into @t    
		  SELECT a.[MenuId]
		  ,a.ParentId
		  ,a.[MenuName]
		  ,a.[ProPath]
		  ,a.[ImgPath]
		  ,a.[ExImgPath]
	--      ,a.[userNames]
	--      ,a.[roles]
		  ,a.[OrderBy]
		  ,a.[IsHidden],a.Target
	,@i 
			FROM    Dcx_Menu a,@t b    
			where   
				a.ParentId=b.menuId and b.Level = @i-1  ORDER BY a.OrderBy,a.MenuId   
 end   
 end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetDeptAndChildsByDeptId]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetDeptAndChildsByDeptId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetDeptAndChildsByDeptId]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--说明：获取指定所有的子级部门；
--@getself=1，同时获取他本身，@getself=0，只获取下级
CREATE function [dbo].[GetDeptAndChildsByDeptId](@DeptId int,  @getself int)    
returns @t table(DeptId int,DeptName varchar(200),ParentId int,Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
    declare @DeptName varchar(200)   
select @DeptName=[DeptName] from [Dcx_Dept] where [DeptId]=@DeptId
 if @getself=1
   insert into @t select @DeptId,@DeptName,@DeptId,0 --当前级，本级，如果不要的话可以注释掉或再加个参数来选择操作    
    insert into @t select [DeptId],[DeptName],[ParentId],@i from [Dcx_Dept] where [ParentId] = @DeptId    
    while @@rowcount<>0    
    begin   
        set @i = @i + 1    
insert into @t 
select  a.[DeptId],a.[DeptName],a.[ParentId],@i  from  [Dcx_Dept] a,@t b where  a.[ParentId]=b.DeptId and b.Level = @i-1 
    end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetDeptCodeString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetDeptCodeString]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetDeptCodeString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[GetDeptCodeString](
@deptCode varchar(1000)
)
 Returns varchar(max)
As
Begin
declare @deptCodes varchar(max) 
set @deptCodes=''''
select @deptCodes=@deptCodes+'',''+Id from GetDeptChildNode(@deptCode)
if len(@deptCodes)>0 
set @deptCodes=substring(@deptCodes,2,len(@deptCodes)-1)
Return @deptCodes
End  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetDeptNameString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetDeptNameString]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetDeptNameString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[GetDeptNameString](
@deptName varchar(1000)
)
 Returns varchar(max)
As
Begin
declare @deptCode varchar(100) 
select @deptCode=部门编号 from 工资_部门信息 where 部门名称=@deptName
declare @deptnames varchar(max) 
set @deptnames=''''
select @deptnames=@deptnames+'',''+dept_name from GetDeptChildNode(@deptCode)
if len(@deptnames)>0 
set @deptnames=substring(@deptnames,2,len(@deptnames)-1)
Return @deptnames
End  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetGoodsTypeChildNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetGoodsTypeChildNode]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetGoodsTypeChildNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取所有的子级货品类别（含它本身）    
CREATE function [dbo].[GetGoodsTypeChildNode](@Id varchar(100))    
returns @t table(Id varchar(100),ParentId varchar(100),Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
    insert into @t select @Id,@Id,0 --当前级，本级，如果不要的话可以注释掉或再加个参数来选择操作    
    insert into @t select 类别编号,父级类别编号,@i from ERP_货品类别表 where 父级类别编号 = @Id    
    while @@rowcount<>0    
    begin   
        set @i = @i + 1    
        insert into @t    
        select   
            a.类别编号,a.父级类别编号,@i    
        from   
            ERP_货品类别表 a,@t b    
        where   
            a.父级类别编号=b.Id and b.Level = @i-1    
    end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getGridName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[getGridName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getGridName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[getGridName](@str varchar(50)) 
RETURNS varchar (50) AS  
BEGIN
    Declare @Id1  varchar(40)
	Select @Id1=SubString(@str,1,CHARINDEX(''-('',@str)-1)
    return LOWER(@Id1)
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getkeyid]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[getkeyid]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getkeyid]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[getkeyid](@str varchar(50)) 
RETURNS int AS
BEGIN
if len(@str)>9 begin
return 0
end
    Declare @Id1  int
	Select @Id1=Convert(int,SubString(@str,CHARINDEX('' -'',@str,3)+2,Len(@str)-CHARINDEX('' -'',@str,3)-2))
    return @Id1
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getlsh]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[getlsh]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getlsh]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[getlsh](@type varchar(20)) 
RETURNS varchar (4) AS  
BEGIN
    --0120070428004
	declare @nyear varchar(4)
	declare @oyear varchar(4)
	declare @maxlsh varchar(15)
	declare @lastnum varchar(4)
	Declare @lsh  varchar(15)
	declare @num int
	if @type = ''发文''
		select @maxlsh=max(流水号) from dbo.EW_fawen		
	else if @type = ''收文''
		select @maxlsh=max(流水号) from dbo.EW_shuowen		
	else if @type = ''签报''
		select @maxlsh=max(流水号) from dbo.ew_qshb	
else if @type = ''贷款申请''
		select @maxlsh=max(流水号) from dbo.贷款信息		
else if @type = ''贷款续贷申请''
		select @maxlsh=max(流水号) from dbo.贷款续贷信息	
else if @type = ''还款''
		select @maxlsh=max(流水号) from dbo.贷款还款		
	else if @type = ''工程联系单''
		select @maxlsh=max(流水号) from dbo.ew_gclxd
else if @type = ''办公用品申购''
		select @maxlsh=max(流水号) from dbo.办公用品申购流程表	
else if @type = ''办公用品采购''
		select @maxlsh=max(流水号) from dbo.办公用品采购流程表			
	else if @type = ''支付申请''
	begin 
		select @maxlsh=max(流水号) from dbo.ew_reqpay	
	end	
	if @maxlsh is null
		set @lsh = ''0001''	
	else 
		begin
			set @oyear=Substring(@maxlsh,3,4) 
			set @nyear=convert(varchar(4), year(getdate()))
			if @oyear <> @nyear
				set @lsh = ''0001''	
			ELSE
				begin
				set @lastnum=Substring(@maxlsh,11,4) 
				set @num = convert(int, @lastnum)+ 10001
				set @lsh=Substring(Convert(varchar(10),@num),2,4)	
				end
		end
	return @lsh
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getlsh2]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[getlsh2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getlsh2]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[getlsh2]() 
RETURNS varchar (4) AS  
BEGIN
    --0120070428004
	declare @nyear varchar(4)
	declare @oyear varchar(4)
	declare @maxlsh varchar(15)
	declare @lastnum varchar(4)
	Declare @lsh  varchar(15)
	declare @num int
		select @maxlsh=max(flow_lsh) from dbo.hyoa_flow_run		
	if @maxlsh is null
		set @lsh = ''0001''	
	else 
		begin
			set @oyear=Substring(@maxlsh,3,4) 
			set @nyear=convert(varchar(4), year(getdate()))
			if @oyear <> @nyear
				set @lsh = ''0001''	
			else
				set @lastnum=Substring(@maxlsh,11,4) 
				set @num = (convert(int, @lastnum)+ 10001)
				set @lsh=Substring(Convert(varchar(10),@num),2,4)			
			end
	return @lsh
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetParentId]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetParentId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetParentId]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 

CREATE function [dbo].[GetParentId] (@Id int)
returns int
as
Begin
Declare @pid int
set @pid =0
select @pid = classparentid from Dcx_class where classid = @Id
return @pid
End
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetParentMenuId]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetParentMenuId]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetParentMenuId]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取指定菜单的所有父级菜单的MenuId    
CREATE function [dbo].[GetParentMenuId](@menuId int)    
returns @t table(MenuId int)    
as   
begin   
    declare @parentId int   
    declare @menuid2 int   
select @parentId=ParentId from Dcx_Menu  where MenuId = @menuId  
set @parentId=isnull(@parentId,0)
while @parentId<>0
begin 
    insert into @t (MenuId) values(@parentId) 
set  @menuid2=@parentId
select @parentId=ParentId from Dcx_Menu  where MenuId = @menuid2  
    end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getstring]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[getstring]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[getstring]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[getstring](
@string varchar(10)
,@date datetime)
 Returns varchar(30)
As
Begin
declare @get varchar(30) 
declare @ym varchar(6) 
declare @fh varchar(2)
if @string=''收文''
set @fh=''S''
else 
set @fh=''F'' 
select @ym=CONVERT(varchar(4), YEAR(@date))+Right(CONVERT(varchar(4), month(@date)+100),2) 
if (select count(*) from EW_文件管理 where right(left(登记号,5),4)=convert(varchar(4),year(@date)) and 文件状态=@string)>0
Begin
	select @get=@fh+@ym+right(convert(int,right(max(登记号),4))+1+10000,4) from EW_文件管理 where right(left(登记号,5),4)=convert(varchar(4),year(@date)) and 文件状态=@string
End
Else
Begin
	select @get=@fh+@ym+''0001''
End 
Return @get
End  
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetSubjectChildNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetSubjectChildNode]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetSubjectChildNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
--获取所有的子级会计科科目（含它本身）    
CREATE function [dbo].[GetSubjectChildNode](@Id varchar(100))    
returns @t table(Id varchar(100),ParentId varchar(100),Level int)    
as   
begin   
    declare @i int   
    set @i = 1    
    insert into @t select @Id,@Id,0 --当前级，本级，如果不要的话可以注释掉或再加个参数来选择操作    
    insert into @t select 科目代码,父级科目,@i from 财务_会计科目 where 父级科目 = @Id    
    while @@rowcount<>0    
    begin   
        set @i = @i + 1    
        insert into @t    
        select   
            a.科目代码,a.父级科目,@i    
        from   
            财务_会计科目 a,@t b    
        where   
            a.父级科目=b.Id and b.Level = @i-1    
    end   
    return   
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetSystemAllDbTableName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[GetSystemAllDbTableName]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[GetSystemAllDbTableName]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
create function [dbo].[GetSystemAllDbTableName](@topMenuId int)    
returns @t table(DBTableName varchar(200))    
as   
begin   
insert into @t select DBTableName from Dcx_DBTable where DBTableId in (select A.DBTableId from Dcx_Entity as A 
where A.MenuId in(select B.MenuId from dbo.GetChildMenuNode(@topMenuId) as B ))
return 
end   
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[isReallyNumeric]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[isReallyNumeric]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[isReallyNumeric]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function [dbo].[isReallyNumeric]
(
  @num VARCHAR(128)
)
RETURNS BIT
BEGIN
  set @num = LTRIM(RTRIM(@num))
  IF LEFT(@num, 1) = ''-''
  SET @num = SUBSTRING(@num, 2, LEN(@num))
  DECLARE @pos int
  SET @pos = 1 + LEN(@num) - CHARINDEX(''.'', REVERSE(@num))
  RETURN CASE
  WHEN PATINDEX(''%[^0-9.-]%'', @num) = 0
  AND @num NOT IN (''.'', ''-'', ''+'', ''^'')
  AND LEN(@num)>0
  AND @num NOT LIKE ''%-%''
  AND
  (
  ((@pos = LEN(@num)+1)
  OR @pos = CHARINDEX(''.'', @num))
  )
  THEN
  1
  ELSE
  0
  END
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CaMonitorFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[WF_CaMonitorFlow]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CaMonitorFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[WF_CaMonitorFlow] (
@FlowId int,
@UserId int,
@DeptId int) 
RETURNS bit AS  
BEGIN 
declare @ObjectId int
declare @IdType int
declare @IsCan bit
set @IsCan=0
declare @IsGetRole bit
set @IsGetRole=0
declare @myRole table(RoleId int ) 
if @UserId<1 or @FlowId<1
	return 0
declare myCursor cursor for SELECT [ObjectId],[IdType] FROM [WF_FlowTypePrivilege] where [FlowId]=@FlowId and [CaMonitor]=1
--打开游标 应用
open myCursor 
fetch next  from myCursor into @ObjectId,@IdType
while (@@fetch_status=0)
begin 
	if @IdType=1 
	begin
		if @ObjectId=@UserId 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=2 
	begin
		if @IsGetRole=0
		begin
			insert into @myRole([RoleId]) select [RoleId] from [Dcx_UserInRole] where [UserId]=@UserId
			set @IsGetRole=1
		end 
		if (select count([RoleId]) from @myRole where [RoleId]=@ObjectId)>0 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=3 
	begin
		if @DeptId<1 
			select @DeptId=isnull([DeptId],-1) from [Dcx_User] where [UserId]=@UserId
		if @ObjectId=@DeptId 
		begin
			set @IsCan=1
			break
		end
	end 
fetch next  from myCursor into @ObjectId,@IdType
end
close myCursor --关闭
deallocate myCursor 
RETURN @IsCan
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CaMonitorFlow2]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[WF_CaMonitorFlow2]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CaMonitorFlow2]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[WF_CaMonitorFlow2] (
@FlowId int,
@UserId int,
@DeptId int,
@myRoles varchar(300)) 
RETURNS bit AS  
BEGIN 
declare @ObjectId int
declare @IdType int
declare @IsCan bit
set @IsCan=0
declare @IsGetRole bit
set @IsGetRole=0
declare @myRole table(RoleId int ) 
if @UserId<1 or @FlowId<1
	return 0
declare myCursor cursor for SELECT [ObjectId],[IdType] FROM [WF_FlowTypePrivilege] where [FlowId]=@FlowId and [CaMonitor]=1
--打开游标 应用
open myCursor 
fetch next  from myCursor into @ObjectId,@IdType
while (@@fetch_status=0)
begin 
	if @IdType=1 
	begin
		if @ObjectId=@UserId 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=2 
	begin
		if @IsGetRole=0
		begin
			insert into @myRole([RoleId]) select [RoleId] from [Dcx_UserInRole] where [UserId]=@UserId
			set @IsGetRole=1
		end 
		if (select count([RoleId]) from @myRole where [RoleId]=@ObjectId)>0 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=3 
	begin
		if @DeptId<1 
			select @DeptId=isnull([DeptId],-1) from [Dcx_User] where [UserId]=@UserId
		if @ObjectId=@DeptId 
		begin
			set @IsCan=1
			break
		end
	end 
fetch next  from myCursor into @ObjectId,@IdType
end
close myCursor --关闭
deallocate myCursor 
RETURN @IsCan
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanDealFlowNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[WF_CanDealFlowNode]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanDealFlowNode]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[WF_CanDealFlowNode] (
@NodeId int,
@UserId int,
@DeptId int) 
RETURNS bit AS  
BEGIN 
declare @ObjectId int
declare @IdType int
declare @IsCan bit
set @IsCan=0
declare @IsGetRole bit
set @IsGetRole=0
declare @myRole table(RoleId int ) 
if @UserId<1 or @NodeId<1
	return 0
declare myCursor cursor for SELECT [ObjectId],[IdType] FROM [WF_FlowNodePrivilege] where [NodeId]=@NodeId
--打开游标 应用
open myCursor 
fetch next  from myCursor into @ObjectId,@IdType
while (@@fetch_status=0)
begin 
	if @IdType=1 
	begin
		if @ObjectId=@UserId 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=2 
	begin
		if @IsGetRole=0
		begin
			insert into @myRole([RoleId]) select [RoleId] from [Dcx_UserInRole] where [UserId]=@UserId
			set @IsGetRole=1
		end 
		if (select count([RoleId]) from @myRole where [RoleId]=@ObjectId)>0 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=3 
	begin
		if @DeptId<1 
			select @DeptId=isnull([DeptId],-1) from [Dcx_User] where [UserId]=@UserId
		if @ObjectId=@DeptId 
		begin
			set @IsCan=1
			break
		end
	end 
fetch next  from myCursor into @ObjectId,@IdType
end
close myCursor --关闭
deallocate myCursor 
RETURN @IsCan
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanDesignFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[WF_CanDesignFlow]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanDesignFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[WF_CanDesignFlow] (
@FlowId int,
@UserId int,
@DeptId int) 
RETURNS bit AS  
BEGIN 
declare @ObjectId int
declare @IdType int
declare @IsCan bit
set @IsCan=0
declare @IsGetRole bit
set @IsGetRole=0
declare @myRole table(RoleId int ) 
if @UserId<1 or @FlowId<1
	return 0
declare myCursor cursor for SELECT [ObjectId],[IdType] FROM [WF_FlowTypePrivilege] where [FlowId]=@FlowId and [CanDesign]=1
--打开游标 应用
open myCursor 
fetch next  from myCursor into @ObjectId,@IdType
while (@@fetch_status=0)
begin 
	if @IdType=1 
	begin
		if @ObjectId=@UserId 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=2 
	begin
		if @IsGetRole=0
		begin
			insert into @myRole([RoleId]) select [RoleId] from [Dcx_UserInRole] where [UserId]=@UserId
			set @IsGetRole=1
		end 
		if (select count([RoleId]) from @myRole where [RoleId]=@ObjectId)>0 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=3 
	begin
		if @DeptId<1 
			select @DeptId=isnull([DeptId],-1) from [Dcx_User] where [UserId]=@UserId
		if @ObjectId=@DeptId 
		begin
			set @IsCan=1
			break
		end
	end 
fetch next  from myCursor into @ObjectId,@IdType
end
close myCursor --关闭
deallocate myCursor 
RETURN @IsCan
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanQueryFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[WF_CanQueryFlow]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanQueryFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[WF_CanQueryFlow] (
@FlowId int,
@UserId int,
@DeptId int) 
RETURNS bit AS  
BEGIN 
declare @ObjectId int
declare @IdType int
declare @IsCan bit
set @IsCan=0
declare @IsGetRole bit
set @IsGetRole=0
declare @myRole table(RoleId int ) 
if @UserId<1 or @FlowId<1
	return 0
declare myCursor cursor for SELECT [ObjectId],[IdType] FROM [WF_FlowTypePrivilege] where [FlowId]=@FlowId and [CanQuery]=1
--打开游标 应用
open myCursor 
fetch next  from myCursor into @ObjectId,@IdType
while (@@fetch_status=0)
begin 
	if @IdType=1 
	begin
		if @ObjectId=@UserId 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=2 
	begin
		if @IsGetRole=0
		begin
			insert into @myRole([RoleId]) select [RoleId] from [Dcx_UserInRole] where [UserId]=@UserId
			set @IsGetRole=1
		end 
		if (select count([RoleId]) from @myRole where [RoleId]=@ObjectId)>0 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=3 
	begin
		if @DeptId<1 
			select @DeptId=isnull([DeptId],-1) from [Dcx_User] where [UserId]=@UserId
		if @ObjectId=@DeptId 
		begin
			set @IsCan=1
			break
		end
	end 
fetch next  from myCursor into @ObjectId,@IdType
end
close myCursor --关闭
deallocate myCursor 
RETURN @IsCan
END
' 
END 
SET ANSI_NULLS ON 
SET QUOTED_IdENTIFIER ON 
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanStartFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
   DROP FUNCTION  dbo.[WF_CanStartFlow]  
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_Id(N'dbo.[WF_CanStartFlow]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT')) 
BEGIN 
EXEC dbo.sp_executesql @statement = N' 
CREATE function  [dbo].[WF_CanStartFlow] (
@FlowId int,
@UserId int,
@DeptId int) 
RETURNS bit AS  
BEGIN 
declare @ObjectId int
declare @IdType int
declare @IsCan bit
set @IsCan=0
declare @IsGetRole bit
set @IsGetRole=0
declare @myRole table(RoleId int ) 
if @UserId<1 or @FlowId<1
	return 0
declare myCursor cursor for SELECT [ObjectId],[IdType] FROM [WF_FlowTypePrivilege] where [FlowId]=@FlowId and CanStart=1
--打开游标 应用
open myCursor 
fetch next  from myCursor into @ObjectId,@IdType
while (@@fetch_status=0)
begin 
	if @IdType=1 
	begin
		if @ObjectId=@UserId 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=2 
	begin
		if @IsGetRole=0
		begin
			insert into @myRole([RoleId]) select [RoleId] from [Dcx_UserInRole] where [UserId]=@UserId
			set @IsGetRole=1
		end 
		if (select count([RoleId]) from @myRole where [RoleId]=@ObjectId)>0 
		begin
			set @IsCan=1
			break
		end
	end 
	else if @IdType=3 
	begin
		if @DeptId<1 
			select @DeptId=isnull([DeptId],-1) from [Dcx_User] where [UserId]=@UserId
		if @ObjectId=@DeptId 
		begin
			set @IsCan=1
			break
		end
	end 
fetch next  from myCursor into @ObjectId,@IdType
end
close myCursor --关闭
deallocate myCursor 
RETURN @IsCan
END
' 
END 
----------------------------------------------------------------------------------------  上：函数  ----------------------------------------------------------------------------------
