将字符串值作为参数传递给存储过程

时间:2016-08-03 06:58:08

标签: c# sql-server crystal-reports-2008

我使用crystal report生成报告。现在我想在用户生成报告时在PrintHistory表中保存打印详细信息。我使用令牌获取用户和系统详细信息的详细信息。我想将令牌值传递给我的存储过程而不在报告中使用它。

以下是我生成报告的代码,

case "OutletToOutletInventryTransferService":

                        object transferCode = Request.Form["transferId"];
                        object issuedBy = Request.Form["curentUser"];
                        object tockenNum = Request.Form["tocken"];

                       string transferId = Convert.ToString(transferCode);
                       string curentUser = Convert.ToString(issuedBy);
                       string tocken = Convert.ToString(tockenNum);

                        myReport.Load(Server.MapPath("~/Report/MIS/OutletToOutletInventryTransferService/OutletToOutletTransfer.rpt"));
                        reportTytle = "Outlet To Outlet Inventory Transfer";
                        myReport.SetParameterValue("@TransferCode", transferId);
                        myReport.SetParameterValue("@UserName", curentUser);
                        //myReport.SetParameterValue("@Tocken", tocken);

                        break;

这是我的存储过程,

    ALTER PROCEDURE [dbo].[PrintOutlettoOutletTransfer]  --exec PrintOutlettoOutletTransfer 'INTRANSYS000044'
    @TransferCode varchar(20),
    @token varchar(100)

    AS
    BEGIN

DECLARE @Isprint AS int
DECLARE @user AS VARCHAR(50)
DECLARE @PcIp AS VARCHAR(50)
DECLARE @PcName AS VARCHAR(50)
DECLARE @AditUserName AS VARCHAR(100)
DECLARE @outlet AS VARCHAR(100)
DECLARE @ServerName AS VARCHAR(200)

SET @user = ''


-- Retrive data from user login history from Tocken
SELECT 
@user = UserLogInHistory.UserId,
@PcIp = LogInIp, 
@outlet=OutletCode,
@ServerName = ServerId,
@AditUserName = Users.UserFullName
from UserLogInHistory
inner join Users on Users.UserId = UserLogInHistory.UserId
where UserTokenId = @token;

    SELECT
    ISNULL(InventoryTransferHeader.TransferCode,'') AS 'TransferId',
    ISNULL(InventoryTransferHeader.TransferDate,'') AS 'TransferDate',
    ISNULL(InventoryTransferLine.ItemCode,'') AS 'ItemCode',
    ISNULL(InventoryTransferLine.ItemDescription,'') AS 'ItemDescription',
    ISNULL(InventoryTransferLine.Qty,'') AS 'Qty',

    STUFF((SELECT  InventoryTransferSerials.SerialNo +' / ' 
           FROM InventoryTransferSerials
           WHERE InventoryTransferSerials.ItemCode = InventoryTransferLine.ItemCode
           AND InventoryTransferSerials.TransferCode = InventoryTransferHeader.TransferCode 
           FOR XML PATH('')),1,1,'') AS 'SN',

    ISNULL(InventoryStatus.Description,'') AS 'InventoryStatus',
    ISNULL(InventoryTransferHeader.FromOutlet,'') AS 'outletFrom' ,
    ISNULL(F.OutletDesc,'') AS 'Outlets',
    ISNULL(InventoryTransferHeader.TOOutlet,'') AS 'outletTO' ,
    ISNULL(T.OutletDesc,'') AS 'Outlets' 

    FROM    InventoryTransferHeader
    INNER JOIN
    Outlets F ON InventoryTransferHeader.FromOutlet = F.OutletCode
    INNER JOIN
    Outlets T ON InventoryTransferHeader.ToOutlet = T.OutletCode 
    LEFT OUTER JOIN
    InventoryStatus on InventoryStatus.StatusCode = InventoryTransferHeader.InventoryStatus
    LEFT OUTER JOIN
    InventoryTransferLine ON InventoryTransferLine.TransferCode = InventoryTransferHeader.TransferCode 
    --LEFT OUTER JOIN
    --InventoryTransferSerials ON InventoryTransferSerials.TransferCode = InventoryTransferLine.TransferCode 
    --AND InventoryTransferSerials.ItemCode = InventoryTransferLine.ItemCode


    WHERE (InventoryTransferHeader.TransferCode = @TransferCode OR @TransferCode = '') AND (InventoryStatus.StatusCode = 1 OR InventoryStatus.StatusCode = 2)

    --- Insert Values to Audit table
INSERT INTO PrintHistory
([DocType],[Reference],[AuditOutlet],[AuditUser],[AuditDate],[AuditType],[AuditIp],[AuditPc],[AuditUserName])
values
('OutletToOutletInventryTransfer',@TransferCode,@outlet,@user,GETDATE(),'1',@PcIp,@ServerName,@AditUserName);


      UPDATE InventoryTransferHeader
      SET   InventoryTransferHeader.[Print] = 1,
            InventoryTransferHeader.[PrintUser] = @user,
            InventoryTransferHeader.[PrintDate] = GETDATE()
      WHERE InventoryTransferHeader.TransferCode = @TransferCode AND InventoryTransferHeader.[Print] = 0;
    END

如何将令牌值传递给存储过程?

0 个答案:

没有答案