使用选中的下拉列表在数据表视图/网格视图中显示记录

时间:2019-03-28 06:59:46

标签: c# sql-server entity-framework

我有一个Status列,在我的网格/记录视图中有5个可能的值(NEW,PAID,PENDING,PROCESS,FAULT)。如果从下拉列表中选择“新建/已付款/待处理/过程/故障”,则网格仅显示该选定值的记录,即“新建/已付款/待处理/过程/故障”

我试图编写一个存储过程来过滤数据,但是无法在我的控制器,模型和视图中实现它。

如果您还有其他方法,请告诉我

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE sp_GetFilterbyStatus
    @Filter VARCHAR(50)
AS
BEGIN
    SET NOCOUNT ON; 

    IF @Filter = 'PAID'
       SELECT [PlateNumber] as 'Plate Number',
              [ReceiptNumber] as ' Receipt Number', 
              [VehicleType] as ' Vehicle Type', 
              [CustomerName] as 'Customer Name', 
              concat([PeriodStartDate], '-', [PeriodEndDate]) as 'Insurance Period',
              [UserName] as 'Agent Name',
              [BranchName] as 'Agent Branch',
              [TotalPremiumPrice] as 'Agent Branch',
              [InvoiceNumber] as 'Invoice Number',
              [InsuranceStatus] as 'Status'
       FROM [CouponManagement].[dbo].[Insurance]
       WHERE [InsuranceStatus] = 'PAID'

     ELSE IF @Filter = 'PENDING'
      SELECT [PlateNumber] as 'Plate Number',
              [ReceiptNumber] as ' Receipt Number', 
              [VehicleType] as ' Vehicle Type', 
              [CustomerName] as 'Customer Name', 
              concat([PeriodStartDate], '-', [PeriodEndDate]) as 'Insurance Period',
              [UserName] as 'Agent Name',
              [BranchName] as 'Agent Branch',
              [TotalPremiumPrice] as 'Agent Branch',
              [InvoiceNumber] as 'Invoice Number',
              [InsuranceStatus] as 'Status'
     FROM [CouponManagement].[dbo].[Insurance]
     WHERE [InsuranceStatus] = 'PENDING'

     ELSE IF @Filter = 'PROCESS'

            SELECT [PlateNumber] as 'Plate Number',
              [ReceiptNumber] as ' Receipt Number', 
              [VehicleType] as ' Vehicle Type', 
              [CustomerName] as 'Customer Name', 
              concat([PeriodStartDate], '-', [PeriodEndDate]) as 'Insurance Period',
              [UserName] as 'Agent Name',
              [BranchName] as 'Agent Branch',
              [TotalPremiumPrice] as 'Agent Branch',
              [InvoiceNumber] as 'Invoice Number',
              [InsuranceStatus] as 'Status'
     FROM [CouponManagement].[dbo].[Insurance]
     WHERE [InsuranceStatus] = 'PROCESS'

     ELSE IF @Filter = 'FAULT'

           SELECT [PlateNumber] as 'Plate Number',
              [ReceiptNumber] as ' Receipt Number', 
              [VehicleType] as ' Vehicle Type', 
              [CustomerName] as 'Customer Name', 
              concat([PeriodStartDate], '-', [PeriodEndDate]) as 'Insurance Period',
              [UserName] as 'Agent Name',
              [BranchName] as 'Agent Branch',
              [TotalPremiumPrice] as 'Agent Branch',
              [InvoiceNumber] as 'Invoice Number',
              [InsuranceStatus] as 'Status'
     FROM [CouponManagement].[dbo].[Insurance]
     WHERE [InsuranceStatus] = 'FAULT'

     ELSE IF @Filter = 'NEW'
      SELECT [PlateNumber] as 'Plate Number',
              [ReceiptNumber] as ' Receipt Number', 
              [VehicleType] as ' Vehicle Type', 
              [CustomerName] as 'Customer Name', 
              concat([PeriodStartDate], '-', [PeriodEndDate]) as 'Insurance Period',
              [UserName] as 'Agent Name',
              [BranchName] as 'Agent Branch',
              [TotalPremiumPrice] as 'Agent Branch',
              [InvoiceNumber] as 'Invoice Number',
              [InsuranceStatus] as 'Status'
     FROM [CouponManagement].[dbo].[Insurance]
      WHERE [InsuranceStatus] = 'NEW'

      ELSE

          SELECT [PlateNumber] as 'Plate Number',
              [ReceiptNumber] as ' Receipt Number', 
              [VehicleType] as ' Vehicle Type', 
              [CustomerName] as 'Customer Name', 
              concat([PeriodStartDate], '-', [PeriodEndDate]) as 'Insurance Period',
              [UserName] as 'Agent Name',
              [BranchName] as 'Agent Branch',
              [TotalPremiumPrice] as 'Agent Branch',
              [InvoiceNumber] as 'Invoice Number',
              [InsuranceStatus] as 'Status'
     FROM [CouponManagement].[dbo].[Insurance] 
     where [InsuranceStatus] =@Filter
END
GO

enter code here

0 个答案:

没有答案