如何终止用户并更新剩余当前用户的标签?

时间:2015-11-04 09:51:05

标签: c# asp.net linq-to-sql terminate

我创建了成员并将它们存储到数据库中。我有一个标签,用于统计数据库中存储的所有用户,每次保存的数字都会增加。我还有一个终止按钮,它按照保单编号终止,所以这就是我想要的。终止成员时,它还必须从标签更新当前成员。 E.g总成员数= 10,当您终止用户时,总成员标签也必须更新为9.我该怎么做?

这就是我到目前为止所做的......

  1. 加载总成员

    protected void Page_Load(object sender, EventArgs e)
    {
        lblTotal.Text = "Total Members Captured : " + CountMembersCaptured();
    } 
    
  2. 总会员的方法

    protected int CountMembersCaptured()
    {
        List<SP_COUNTPOLICYMEMBERSResult> _MemberCountList = _dc.SP_COUNTPOLICYMEMBERS().ToList();
        return _MemberCountList.Count();
    }
    
  3. 获取总会员的程序

       ALTER PROCEDURE [dbo].[SP_COUNTPOLICYMEMBERS]
       AS
       BEGIN        
       SELECT  [DateID]
      ,[PolicyNumber]
      ,[Name]
      ,[PolicyName]
      ,[InceptionDate]
      ,[Active]   
      FROM [dbo].[tblPolicy]
      END
    
  4. 终止按钮

    protected void btnTerminate_Click(object sender, EventArgs e)
    {
    
        if (Session["DateID"] != null)
        {
            List<tblPolicy> _PolicyMemberList = _dc.tblPolicies.Where(a => a.DateID == int.Parse(Session["DateID"].ToString())).ToList();
    
            if (_PolicyMemberList != null)
            {
                if (_PolicyMemberList.Count() > 0)
                {
                    foreach (tblPolicy _PolicyMember in _PolicyMemberList)
                    {
                        _PolicyMember.Active = false;
                    }
    
                    _dc.SubmitChanges();
                    lblresults.Text = "Confirmation: Member has been terminated/deleted successfully.!";
                }
            }
        }
    }
    

2 个答案:

答案 0 :(得分:0)

将Where子句添加到选择查询。

 ALTER PROCEDURE [dbo].[SP_COUNTPOLICYMEMBERS]
   AS
   BEGIN        
   SELECT  [DateID]
  ,[PolicyNumber]
  ,[Name]
  ,[PolicyName]
  ,[InceptionDate]
  ,[Active]   
  FROM [dbo].[tblPolicy] where Active=1
  END

希望这会有所帮助......

答案 1 :(得分:0)

ALTER PROCEDURE [dbo].[SP_COUNTPOLICYMEMBERS]
AS
BEGIN        
SELECT  [DateID]
,[PolicyNumber]
,[Name]
,[PolicyName]
,[InceptionDate]
,[Active]   
FROM [dbo].[tblPolicy] WHERE [Active]=1
END

protected void btnTerminate_Click(object sender, EventArgs e)
{

if (Session["DateID"] != null)
{
    List<tblPolicy> _PolicyMemberList = _dc.tblPolicies.Where(a => a.DateID == int.Parse(Session["DateID"].ToString())).ToList();

    if (_PolicyMemberList != null)
    {
        if (_PolicyMemberList.Count() > 0)
        {
            foreach (tblPolicy _PolicyMember in _PolicyMemberList)
            {
                _PolicyMember.Active = false;
            }

            _dc.SubmitChanges();
            lblresults.Text = "Confirmation: Member has been terminated/deleted successfully.!";
            lblTotal.Text = "Total Members Captured : " + CountMembersCaptured();
        }
    }
}
}