1. 程式人生 > 實用技巧 >條碼系統工單匯入到K3產品入庫

條碼系統工單匯入到K3產品入庫

好久沒有在網站上寫的東西了,今天早上正好有這個空閒時間

公司的條碼系統已經運行了快一年了,這套系統也是我剛剛進入公司,開始實施開發並匯入使用的,這裡我的目的不是討論該套系統,

今天主要目的還是想說明下,條碼系統匯入K3所實現的過程,

K3中所相關的也是最主要的是3張表,即:ICStockBill,ICStockBillEntry,icmaxnum

尤其是表:icmaxnum,第一次匯入是隻是匯入了前2張,後來發現數據是匯入進去了,過一段時間就消失了,後來查明原因

才知道問題在於 表:icmaxnum,這個表的功能是實現最大單據號(最大序號,這裡的序號其實我已經通過函式獲得),

但獲得後還必須將當前的序號寫入到這個表中,這點很重要,


以下是匯入工具的,主儲存過程,裡面有相關的函式、子儲存過程的(這些程式碼如果需要可以聯絡我,包括每天匯入資料併發送郵件的工具

該工具是VS 2008開發的,語言:C#)




///////////////////////////////////////////////////////////////////////////////////////////

USE [AIS20150326095508]

GO

/****** Object: StoredProcedure [dbo].[Luke_Insert_ICStockBill] Script Date: 04/14/2015 08:47:24 ******/

SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

-- =============================================

-- Author:

Luke.Lu

-- Create date: 2015-3-31

-- Description:增加表ICStockBill,ICStockBillEntry記錄

-- =============================================

ALTER PROCEDURE [dbo].[Luke_Insert_ICStockBill]

AS

begin transaction

declare @FInterID nvarchar(10)

declare @FDate datetime

declare @FTranType int

declare @FBrNo nvarchar(10)

declare @FBillNo nvarchar(50)

declare @FBillerID int --制單人

declare @FDeptID nvarchar(10) --部門

declare @FFManagerID int --驗收人

declare @FSManagerID int --保管人

declare @FROB nvarchar(10)

declare @FEntryID nvarchar(10)

declare @FItemID nvarchar(10)

declare @FQty int

declare @FPrice int

declare @FUnitID nvarchar(10)

declare @FAuxQty int

declare @FDCStockID nvarchar(20) --存放倉庫

declare @Icount int

declare @i int

declare @FItem nvarchar(50)

set @FPrice=0

set @FUnitID=dbo.Luke_GetUnit('Set')

set @FQty=0 --應收入庫數量,需要經常變動*,K3基本收貨數量數字上等於@FAuxQty

-- SET @FAuxQty=1-----實際入庫數量,需要經常變動*

-- set @FItemID=dbo.Luke_GetFitemID('TEST') --料號,需要經常變動*

set @FEntryID=0 --序號,需要經常變動*

set @FROB=1 --藍字

set @FBillerID=dbo.Luke_GetEmpID_FBillerID('Administrator')

set @FDeptID=dbo.Luke_GetFSCStockID('電鍍車間')

set @FFManagerID=dbo.Luke_GetEmpID('SYSADMIN')

set @FSManagerID=dbo.Luke_GetEmpID('SYSADMIN')

set @FInterID=dbo.Luke_GetICStockBill_FInterID()

--set @FDate=getdate()

set @FTranType=dbo.Luke_GetFTranType('KCZH') --傳輸標識

set @FBrNo=0

set @FBillNo=dbo.Luke_GetMaxFBillNo()

set @FDCStockID=dbo.Luke_GetStockID('一次電鍍良品次數')

SET NOCOUNT ON

--條件包括日期

select @Icount=count(*) from AIS20110901110631.dbo.CT_B_JOB_COMP_SUM_FORK3I_VIEW where Comp_date=CONVERT (varchar(10), getdate()-1, 120)

if (@Icount is not null or @Icount<>0)

print @Icount

--條件包括日期

DECLARE cur CURSOR FOR select itemcode,comp_date,sumQty from AIS20110901110631.dbo.CT_B_JOB_COMP_SUM_FORK3I_VIEW where Comp_date=CONVERT (varchar(10), getdate()-1, 120) order by itemcode desc

open cur

--FETCH from cur into @FItem,@FDate,@FAuxQty

--BEGIN TRANSACTION

while @@FETCH_STATUS=0

begin

FETCH next from cur into @FItem,@FDate,@FAuxQty

set @FItemID=dbo.Luke_GetFitemID(@FItem)

set @[email protected] + 1

print @FEntryID

print @FItem

print @FDate

print @FAuxQty

if @FEntryID<[email protected]

begin

--插入到表ICStockBill

--BEGIN transaction

--插入ICStockBill

if @FEntryID=1

begin

insert into ICStockBill(FBrNo,FInterID,FTranType,FDate,FBillNo,FDeptID,FFManagerID,FSManagerID,FBillerID,FROB)values (@FBrNo,@FInterID,@FTranType,@FDate,@FBillNo,@FDeptID,@FFManagerID,@FSManagerID,@FBillerID,@FROB)

end

--插入ICStockBillEntry

if (@FItemID is not null or len(@FItemID)<1)

begin

insert into ICStockBillEntry(FBrNo,FInterID,FItemID,FQty,FUnitID,FEntryID,FAuxQty,FDCStockID)values(@FBrNo,@FInterID,@FItemID,@FAuxQty,@FUnitID,@FEntryID,@FAuxQty,@FDCStockID)

--更新單據最大號表中記錄

Update icmaxnum set Fmaxnum=(select max(FInterID) from ICStockBillEntry) where Ftablename='ICStockBill'

end

else

begin

--BEGIN transaction

EXEC dbo.Luke_CreateItem @FItem,@FAuxQty,@FDate

-- if @@error>0

--begin

-- rollback transaction

-- retrun

-- end

-- else

-- begin

-- commit transaction

-- end

end

--select @@fetch_status

--FETCH from cur into @FItem,@FDate,@FAuxQty

if @@error>0

begin

rollback transaction

retrun

end

--else

-- begin

-- Update icmaxnum set Fmaxnum=(select max(FInterID) from ICStockBillEntry) where Ftablename='ICStockBill'

-- end

--else

-- commit transaction

end

end

commit transaction

--FETCH next from cur into @FItem,@FDate,@FAuxQty



--else

--begin



close cur

DEALLOCATE cur

SET NOCOUNT OFF

-- begin

-- -- --插入ICStockBill

-- insert into ICStockBill(FBrNo,FInterID,FTranType,FDate,FBillNo,FDeptID,FFManagerID,FSManagerID,FBillerID,FROB)

-- --values (@FBrNo,@FInterID,@FTranType,@FDate,@FBillNo,@FDeptID,@FFManagerID,@FSManagerID,@FBillerID,@FROB)

-- select

-- @FBrNo,

-- @FInterID,

-- @FTranType,

-- comp_date,

-- @FBillNo,

-- @FDeptID,

-- @FFManagerID,

-- @FSManagerID,

-- @FBillerID,

-- @FROB

-- from AIS20110901110631.dbo.CT_B_JOB_COMP_SUM_FORK3I_VIEW where Comp_date=CONVERT (varchar(10), getdate()-1, 120)

-- end

-- begin

-- -- --插入ICStockBillEntry

----insert into ICStockBillEntry(FBrNo,FInterID,FItemID,FQty,FUnitID,FEntryID,FAuxQty,FDCStockID)

---- --values(@FBrNo,@FInterID,@FItemID,@FQty,@FUnitID,@FEntryID,@FAuxQty,@FDCStockID)

---- select

---- @FBrNo,

---- @FInterID,

---- dbo.Luke_GetFitemID(itemcode),

---- @FQty,

---- @FUnitID,

---- --IDENTITY(INT,1,1) as id,

---- 1,

---- sumQty,

---- @FDCStockID

---- from AIS20110901110631.dbo.CT_B_JOB_COMP_SUM_FORK3I_VIEW where Comp_date=CONVERT (varchar(10), getdate()-1, 120)

-- end

-- if @@error>0

--begin

--rollback transaction

--return

--end

-- commit transaction

///////////////////////////////////////////////////////////////////////////////////////////

---本資訊來至於ACCESS技巧網Http://www.mdbtip.com


http://www.mdbtip.com/Html/?865.html


wKioL1UsaJGTx5NKAAIfK3ZSfZk659.jpg


轉載於:https://blog.51cto.com/officevba/1632092