--V1.2版本 所作的升级
if exists( Select OptValue from tSysOpt where OptName='DBEdition')
begin
  Declare @DBVer varchar(10)
  Select @DBVer=OptValue from tSysOpt where OptName='DBEdition'
  Set @DBVer=Substring(@DBVer,1,4)+'-'+Substring(@DBVer,6,2)+'-'+Substring(@DBVer,9,2)
  if @DBVer>='2006-10-08'
    Return
end
--2006-09-18 工资模块升级
if not Exists(Select * from SysColumns where name='Type' and id=Object_ID('bi_t_payitem_info'))
begin
Alter table bi_t_payitem_info add [Type] char(1) Null
Exec ('update bi_t_payitem_info  Set Type=''1'' ')
end
if not Exists(Select * from SysColumns where name='Type' and id=Object_ID('Gz_t_payitem_info'))
begin
Alter table Gz_t_payitem_info add [Type] char(1) Null 
Exec ('update Gz_t_payitem_info  Set Type=''1'' ')
end
if not Exists(Select * from SysColumns where name='Formula' and id=Object_ID('bi_t_payitem_info'))
begin
Alter table bi_t_payitem_info add [Formula] Varchar(255) Null 
Exec ('update bi_t_payitem_info  Set Formula='''' ')
end
if not Exists(Select * from SysColumns where name='Formula' and id=Object_ID('Gz_t_payitem_info'))
begin
Alter table Gz_t_payitem_info add [Formula] Varchar(255) Null 
Exec ('update Gz_t_payitem_info  Set Formula='''' ')
end
--2006-09-19 纸长自动适应
if not Exists(Select * from SysColumns where name='AutoLength' and id=Object_ID('ReportSet'))
begin
Alter table ReportSet add [AutoLength] bit Null
ALTER TABLE [dbo].[ReportSet] WITH NOCHECK ADD 
	CONSTRAINT [DF_ReportSet_AutoLength] DEFAULT (0) FOR [AutoLength]
Exec ('update ReportSet  Set AutoLength=0 ')
end

--2006-10-14 删除tAutoOrder表
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tAutoOrder]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
begin
drop table [dbo].[tAutoOrder]

CREATE TABLE [dbo].[tAutoOrder] (
	[ProdCode] [char] (18) NOT NULL ,
	[ProdName] [char] (40) NULL ,
	[BarCode] [char] (18) NOT NULL ,
	[Spec] [char] (20) NULL ,
	[DepCode] [char] (12) NULL ,
	[SupCode] [char] (12) NULL ,
	[ColorCode] [char] (3) NULL ,
	[SizeCode] [char] (3) NULL ,
	[AvgXSCount] [money] NULL ,
	[OTax] [tinyint] NULL ,
	[Hlimit] [int] NULL ,
	[Llimit] [int] NULL ,
	[HOPrice] [decimal](19, 10) NULL ,
	[LOPrice] [decimal](19, 10) NULL ,
	[COPrice] [decimal](19, 10) NULL ,
	[SaleCYC] [int] NULL ,
	[OrderCYC] [int] NULL ,
	[OrderParam] [money] NULL ,
	[OrderCount] [money] NULL ,
	[OrderPrice] [decimal](19, 10) NULL ,
	[OutOrdPrice] [decimal](19, 10) NULL ,
	[OrderCost] [money] NULL ,
	[OutOrdCost] [money] NULL ,
	[OrderTotal] [money] NULL ,
	[MbarFlag] [char] (1) NULL ,
	[Price] [money] NULL ,
	[Amount] [money] NULL ,
	[Unit] [char] (20) NULL ,
	[PUnit] [char] (20) NULL ,
	[PunitAmt] [money] NULL ,
	[CountP] [money] NULL ,
	[CountM] [money] NULL 
) ON [PRIMARY]

ALTER TABLE [dbo].[tAutoOrder] WITH NOCHECK ADD 
	CONSTRAINT [DF_tAutoOrder_AvgXSCount] DEFAULT (0) FOR [AvgXSCount],
	CONSTRAINT [DF_tAutoOrder_OTax] DEFAULT (0) FOR [OTax],
	CONSTRAINT [DF_tAutoOrder_Hlimit] DEFAULT (0) FOR [Hlimit],
	CONSTRAINT [DF_tAutoOrder_Llimit] DEFAULT (0) FOR [Llimit],
	CONSTRAINT [DF_tAutoOrder_HOPrice] DEFAULT (0) FOR [HOPrice],
	CONSTRAINT [DF_tAutoOrder_LOPrice] DEFAULT (0) FOR [LOPrice],
	CONSTRAINT [DF_tAutoOrder_COPrice] DEFAULT (0) FOR [COPrice],
	CONSTRAINT [DF_tAutoOrder_SaleCYC] DEFAULT (0) FOR [SaleCYC],
	CONSTRAINT [DF_tAutoOrder_OrderCYC] DEFAULT (0) FOR [OrderCYC],
	CONSTRAINT [DF_tAutoOrder_OrderParam] DEFAULT (0) FOR [OrderParam],
	CONSTRAINT [DF_tAutoOrder_OrderCount] DEFAULT (0) FOR [OrderCount],
	CONSTRAINT [DF_tAutoOrder_OrderPrice] DEFAULT (0) FOR [OrderPrice],
	CONSTRAINT [DF_tAutoOrder_OutOrdPrice] DEFAULT (0) FOR [OutOrdPrice],
	CONSTRAINT [DF_tAutoOrder_OrderCost] DEFAULT (0) FOR [OrderCost],
	CONSTRAINT [DF_tAutoOrder_OutOrdCost] DEFAULT (0) FOR [OutOrdCost],
	CONSTRAINT [DF_tAutoOrder_OrderTotal] DEFAULT (0) FOR [OrderTotal],
	CONSTRAINT [DF_tAutoOrder_Price] DEFAULT (0) FOR [Price],
	CONSTRAINT [DF_tAutoOrder_Amount] DEFAULT (0) FOR [Amount],
	CONSTRAINT [DF_tAutoOrder_PunitAmt] DEFAULT (1) FOR [PunitAmt],
	CONSTRAINT [DF_tAutoOrder_CountP] DEFAULT (0) FOR [CountP],
	CONSTRAINT [DF_tAutoOrder_CountM] DEFAULT (0) FOR [CountM],
	CONSTRAINT [PK_tAutoOrder] PRIMARY KEY  CLUSTERED 
	(
		[ProdCode],
		[BarCode]
	)  ON [PRIMARY] 
end

--2006-10-13 首页打印表头，打印列标题
if not Exists(Select * from SysColumns where name='PgeHdOnFirst' and id=Object_ID('ReportSet'))
begin
Alter table ReportSet add [PgeHdOnFirst] bit Null
ALTER TABLE [dbo].[ReportSet] WITH NOCHECK ADD 
	CONSTRAINT [DF_ReportSet_PgeHdOnFirst] DEFAULT (0) FOR [PgeHdOnFirst]
Exec ('update ReportSet  Set PgeHdOnFirst=0 ')
end
if not Exists(Select * from SysColumns where name='ColHdOnFirst' and id=Object_ID('ReportSet'))
begin
Alter table ReportSet add [ColHdOnFirst] bit Null
ALTER TABLE [dbo].[ReportSet] WITH NOCHECK ADD 
	CONSTRAINT [DF_ReportSet_ColHdOnFirst] DEFAULT (0) FOR [ColHdOnFirst]
Exec ('update ReportSet  Set ColHdOnFirst=0 ')
end

--2006-11-03 批发销货单中增加货号字段
if not Exists(Select * from SysColumns where name='CargoNo' and id=Object_ID('FWXHB'))
begin
Alter table FWXHB add [CargoNo] Varchar(15) Null
end