简体   繁体   中英

How to create rdlc report with stored procedure?

I have problem with this stored procedure and i can not create RDLC report fromthat please help me. thanks.

USE [ASSevenAzhitechs]
GO
/****** Object:  StoredProcedure [dbo].[Sp_RepReceptionServicesParts]    Script Date: 04/13/2016 11:16:15 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO




ALTER procedure [dbo].[Sp_RepReceptionServicesParts]
    (
     @UserType as char(1),
     @UserCode as varchar(5),
     @DateFrom as varchar(10),
     @DateTo as Varchar(10) ,
     @DealerNo as varchar(5),
     @DealerNoCombo as varchar(5),
     @VehicleCode as varchar(5) ,
     @ChassisNo as varchar(30),
     @ReceptionCode as varchar(10),
     @FactorNo as varchar(10),
     @ServiceUserCode as varchar(30),
     @PartNo as varchar(30) ,
     @CostCenter as char(1) ,
     @PartOrService as char(1),
     @ReceptionType as char(1),
     @VehicleType as char(1)
    )
as
begin

declare @strParts as varchar(max)
declare @strServices as varchar(max)
declare @strFinal as varchar(max)
set @DateFrom = '''' + @DateFrom + ''''  
set @DateTo = '''' + @DateTo + ''''  
set @strParts =  '
                select ReceptionCode,RecDate,FactorNo,rp.DeliverDate FactorDate,VehicleFarsiName VehicleName, case when s.Imported = 1 then ''notok'' else ''ok'' end as VehicleType ,RecKilometer ReceptionKilometer, ''Parts'' as Type,
                        PartFarsiName as Name,''-'' as ServerName,PartNo as Code, Warranty=case HasWarranty when 1 then ''Yes'' when 0 then ''No'' end,
                        max(UnitPrice) UnitPrice,sum(Number) Qty,Sum(ExtraPrice) ExtraPrice,Sum(SpecialDiscount) Discount, Sum((UnitPrice*Number)+ExtraPrice - SpecialDiscount ) as Price ,ChassisNo,MotorNo,s.ActualDeliveryDate ''date start''
                from V_RecParts rp 
                        left join 
                        V_LastSubscribers s 
                        on rp.SubScriberCode = s.SubScriberCode
                where RecDate  between ' + @DateFrom + ' and ' + @DateTo + ' --DealerNoRMN --VehicleCodeRMN --ChassisNoRMN --ReceptionCodeRMN --FactorNoRMN
                        --PartNoRMN --CostCenterRMN --ReceptionTypeRMN --VehicleTypeRMN
                group  by ReceptionCode,RecDate,FactorNo,rp.DeliverDate,VehicleFarsiName,RecKilometer,HasWarranty,PartFarsiName,PartNo,ChassisNo,MotorNo,s.ActualDeliveryDate, s.imported '

                    set @strServices = '
                select ReceptionCode,RecDate,FactorNo,rs.DeliverDate FactorDate,VehicleFarsiName VehicleName, case when s.Imported = 1 then ''notok'' else ''ok'' end as VehicleType,RecKilometer ReceptionKilometer, ''Services'' as Type,
                        FarsiName as Name,ServerName,ServiceUserCode as Code, Warranty=case HasWarranty when 1 then ''Yes'' when 0 then ''No'' end,
                        max(UnitPrice) UnitPrice,sum(Number) Qty,Sum(ExteraPrice) ExtraPrice,Sum(SpecialDiscount) Discount, Sum((UnitPrice*Number)+ExteraPrice - SpecialDiscount ) as Price ,ChassisNo,MotorNo,s.ActualDeliveryDate ''date start''
                from V_RecServices rs 
                        left join 
                        V_LastSubscribers s 
                        on rs.SubScriberCode = s.SubScriberCode
                where RecDate  between ' + @DateFrom + ' and ' + @DateTo + ' --DealerNoRMN --VehicleCodeRMN --ChassisNoRMN --ReceptionCodeRMN --FactorNoRMN
                        --ServiceUserCodeRMN --CostCenterRMN --ReceptionTypeRMN --VehicleTypeRMN
                group  by  ReceptionCode,RecDate,FactorNo,rs.DeliverDate,VehicleFarsiName ,RecKilometer ,HasWarranty,FarsiName,ServerName,ServiceUserCode,ChassisNo,MotorNo,s.ActualDeliveryDate,s.imported '   
if @PartOrService = 'P' -- output is just Parts
    set @strFinal = @strParts
else
    if @PartOrService = 'S' -- output is just Services
        set @strFinal = @strServices
    else
        set @strFinal = '( '+ @strParts + ') union ( ' + @strServices + ' ) '

set @strFinal = @strFinal + ' order by ReceptionCode '

if @UserType <> 'A' 
    set @strFinal = replace(@strFinal ,'--DealerNoRMN', ' and ReceptionCode / 100000 = ' + @DealerNo )
else
    if @DealerNoCombo <> -1
        set @strFinal = replace(@strFinal ,'--DealerNoRMN', ' and ReceptionCode / 100000 = ' + @DealerNoCombo )
    else
        set @strFinal = replace(@strFinal ,'--DealerNoRMN', '' )

if len(@vehicleCode) > 0 
    set @strFinal = replace(@strFinal ,'--VehicleCodeRMN', ' and VehicleCode = ' + @vehicleCode )
else
    set @strFinal = replace(@strFinal ,'--VehicleCodeRMN', '' )

if len(@ChassisNo) > 0 
    set @strFinal = replace(@strFinal ,'--ChassisNoRMN', ' and ChassisNo like ''%' + @ChassisNo + '%''' )
else
    set @strFinal = replace(@strFinal ,'--ChassisNoRMN', '' )

if len(@ReceptionCode) > 0 
    set @strFinal = replace(@strFinal ,'--ReceptionCodeRMN', ' and ReceptionCode = ' + @ReceptionCode )
else
    set @strFinal = replace(@strFinal ,'--ReceptionCodeRMN', '' )

if len(@FactorNo) > 0 
    set @strFinal = replace(@strFinal ,'--FactorNoRMN', ' and FactorNo = ' + @FactorNo )
else
    set @strFinal = replace(@strFinal ,'--FactorNoRMN', '' )

if len(@PartNo) > 0 
    set @strFinal = replace(@strFinal ,'--PartNoRMN', ' and PartNo like ''%' + @PartNo + '%''' )
else
    set @strFinal = replace(@strFinal ,'--PartNoRMN', '' )

if len(@ServiceUserCode) > 0 
    set @strFinal = replace(@strFinal ,'--ServiceUserCodeRMN', ' and ServiceUserCode like ''%' + @ServiceUserCode + '%''' )
else
    set @strFinal = replace(@strFinal ,'--ServiceUserCodeRMN', '' )

if @CostCenter = 'G'      -- output is just guaranty
    set @strFinal = replace(@strFinal ,'--CostCenterRMN', ' and HasWarranty = 1' )
else
    if @CostCenter = 'C'  -- output is just Customer
        set @strFinal = replace(@strFinal ,'--CostCenterRMN', ' and HasWarranty = 0' )
    else              -- 'B' output is Customer and guaranty
        set @strFinal = replace(@strFinal ,'--CostCenterRMN', '' )

if @ReceptionType = 'C'  -- output is just Closed Reception
    set @strFinal = replace(@strFinal ,'--ReceptionTypeRMN', ' and QCFlag = 1 and FactorNo is not Null' )
else
    if @ReceptionType = 'O'  -- output is just Open Reception
        set @strFinal = replace(@strFinal ,'--ReceptionTypeRMN', ' and (QCFlag = 0 or FactorNo is Null)' )
    else
        set @strFinal = replace(@strFinal ,'--ReceptionTypeRMN', '' )

if @VehicleType = 'F'  
    set @strFinal = replace(@strFinal ,'--VehicleTypeRMN', ' and s.Imported = 0 ' )  -- Imported = 0 --> Factory
else
    if @VehicleType = 'N'  
        set @strFinal = replace(@strFinal ,'--VehicleTypeRMN', ' and s.Imported = 1 ' ) -- Imported = 1 --> Not Factory
    else
        set @strFinal = replace(@strFinal ,'--VehicleTypeRMN', '' )

--print @strFinal
exec (@strFinal)

end

i can show data in to datagridview by this code:

public DataTable MySelect(string UserType,string UserCode,string DateFrom,string DateTo, string DealerNo,string DealerNoCombo,string VehicleCode,string ChassisNo,string ReceptionCode, string FactorNo,string ServiceUserCode,string PartNo,string CostCenter,string PartOrService, string ReceptionType, string VehicleType, string HasWarranty) {

        if (openConnection() == true)
        {
            Cmd = new SqlCommand("Sp_MyFullShowing", Con2);
            //Cmd.CommandText = "Sp_MyFullShowing";
            Cmd.Parameters.AddWithValue("@UserType", UserType);
            Cmd.Parameters.AddWithValue("@UserCode", UserCode);
            Cmd.Parameters.AddWithValue("@DateFrom", DateFrom);
            Cmd.Parameters.AddWithValue("@DateTo", DateTo);
            Cmd.Parameters.AddWithValue("@DealerNo", DealerNo);
            Cmd.Parameters.AddWithValue("@DealerNoCombo", DealerNoCombo);
            Cmd.Parameters.AddWithValue("@VehicleCode", VehicleCode);
            Cmd.Parameters.AddWithValue("@ChassisNo", ChassisNo);
            Cmd.Parameters.AddWithValue("@ReceptionCode", ReceptionCode);
            Cmd.Parameters.AddWithValue("@FactorNo", FactorNo);
            Cmd.Parameters.AddWithValue("@ServiceUserCode", ServiceUserCode);
            Cmd.Parameters.AddWithValue("@PartNo", PartNo);
            Cmd.Parameters.AddWithValue("@CostCenter", CostCenter);
            Cmd.Parameters.AddWithValue("@PartOrService", PartOrService);
            Cmd.Parameters.AddWithValue("@ReceptionType", ReceptionType);
            Cmd.Parameters.AddWithValue("@VehicleType", VehicleType);
            Cmd.Parameters.AddWithValue("@HasWarranty", HasWarranty);


            Cmd.CommandType = CommandType.StoredProcedure;

            DT = new DataTable();
            Adapter = new SqlDataAdapter(Cmd);
            Adapter.Fill(DT);
            closeConnection();
        }
        return DT;

}

and in button click this code:

dt = sql.MySelect("", "", lbl1.Text, lbl2.Text, "", "", "", "", txtPaziresh.Text, "", "", "", "", "", "", "", cmbGarant.Text); elDataGridView3.DataSource = dt.DefaultView;

but i can not create rdlc report from that. anyone can not helppppppp????

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM