1、附件主表结构
CREATE TABLE [dbo].[Stm_Attach_Hd](
[AttachmentKey] [INT] IDENTITY(1,1) NOT NULL,
[AttachmentCode] [VARCHAR](200) NULL,
[AttachmentName] [VARCHAR](200) NULL,
CONSTRAINT [PK_Stm_Attachment] PRIMARY KEY CLUSTERED
(
[AttachmentKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
2、附件明细表结构
CREATE TABLE [dbo].[Stm_Attach_Dt](
[AttachKey] [INT] IDENTITY(1,1) NOT NULL,
[AttachmentKey] [INT] NULL,
[ContentLength] [INT] NULL,
[ContentType] [VARCHAR](500) NULL,
[SourceFileName] [VARCHAR](500) NULL,
[SourcePathName] [VARCHAR](500) NULL,
[NewFileName] [VARCHAR](500) NULL,
[NewPathName] [VARCHAR](500) NULL,
[UserHostAddress] [VARCHAR](500) NULL,
[UserHostName] [VARCHAR](500) NULL,
[CreateTime] [DATETIME] NULL,
CONSTRAINT [PK_Stm_Attach_Dt] PRIMARY KEY CLUSTERED
(
[AttachKey] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
3、附件上传时存储过程处理
USE [Hello]
GO
/****** Object: StoredProcedure [dbo].[P_CreateAttachment] Script Date: 07/11/2015 18:06:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[P_CreateAttachment](
@AttachmentKey INT,
@ContentLength int,
@ContentType varchar(20),
@SourceFileName varchar(500),
@SourcePathName varchar(500),
@NewFileName varchar(500),
@NewPathName varchar(500),
@UserHostAddress varchar(500),
@UserHostName varchar(500)
)
AS
BEGIN
DECLARE @AttachmentCode VARCHAR(200);
DECLARE @AttachmentName VARCHAR(200);
IF @AttachmentKey<=0
BEGIN
SET @AttachmentCode=CONVERT(varchar(100), GETDATE(), 21);
SET @AttachmentName=CONVERT(varchar(100), GETDATE(), 21);
INSERT INTO dbo.Stm_Attach_Hd
( AttachmentCode, AttachmentName )
VALUES ( @AttachmentCode, @AttachmentName) SET @AttachmentKey=@@IDENTITY;
END;
DECLARE @AttachKey INT;
INSERT INTO dbo.Stm_Attach_Dt
( AttachmentKey ,
ContentLength ,
ContentType ,
SourceFileName ,
SourcePathName ,
NewFileName ,
NewPathName ,
UserHostAddress ,
UserHostName ,
CreateTime
)
VALUES (
@AttachmentKey ,
@ContentLength,
@ContentType,
@SourceFileName,
@SourcePathName,
@NewFileName,
@NewPathName,
@UserHostAddress,
@UserHostName,
GETDATE()
) SET @AttachKey=@@IDENTITY;
IF @AttachKey>0
RETURN @AttachmentKey;
ELSE
RETURN 0;
END
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content=&