2013-07-01 37 views
0

我需要你的帮助。如何防止多次选择组合框值?

我有这样的方法:

protected void btnDocumentType_Click(object sender, EventArgs e) 
     { 

      DocumentApplicationCategoryManager DACM = new DocumentApplicationCategoryManager(); 
      IkubInfo.NE.Domain.DocumentApplicationCategory DAC = new Domain.DocumentApplicationCategory(); 

      DAC.DocumentType = new DocumentTypeManager().GetById(new Guid(cboDocumentType.SelectedValue)); 
      DAC.ApplicationCategory = Entity; 

      Entity.DocumentApplicationCategory.Add(DAC); 

      DACM.Save(DAC); 
      DACM.Session.CommitChanges(); 
      SetUIValues(); 
     } 

这是ADD按钮,它允许用户在网格添加一个值的方法。 我需要检查用户试图添加的值是否保存一次,它不能被保存两次。我需要验证它并向用户显示错误消息,但我不知道如何执行此操作。 我想我有这条线之前,把一个“如果”条件:

DAC.DocumentType = new DocumentTypeManager().GetById(new Guid(cboDocumentType.SelectedValue)); 

任何想法? 您的帮助,将不胜感激。 在此先感谢:)

回答

0
protected void btnDocumentType_Click(object sender, EventArgs e) 
     { 

      DocumentApplicationCategoryManager DACM = new DocumentApplicationCategoryManager(); 
      IkubInfo.NE.Domain.DocumentApplicationCategory DAC = new Domain.DocumentApplicationCategory(); 

      DAC.DocumentType = new DocumentTypeManager().GetById(new Guid(cboDocumentType.SelectedValue)); 
      DAC.ApplicationCategory = Entity; 

//Check here from DocumentApplicationCategory, Whether DAC.DocumentType and Entity Exists or not, if does not exists then allow to come in 
     if(CHECK_HERE) 
     { 
       Entity.DocumentApplicationCategory.Add(DAC); 

       DACM.Save(DAC); 
       DACM.Session.CommitChanges(); 
     } 
      SetUIValues(); 
     } 

请参考评论:在CHECK_HERE的地方,把你的条件确认你试图插入的数据已经存在与否。

+0

谢谢@Bhaarat,你能告诉我到底该怎么写CHECK_HERE,因为这是我正在寻找:)谢谢。 – Marin

+0

我已经在代码中提到过这件事。这里是:从DocumentApplicationCategory检查这里,是否DAC.DocumentType和实体是否存在,如果不存在,则允许进入 – Bhaarat

0

您需要做的是检查组合框中的每个值是否存在或不存在。为此,您需要创建一个带有HasNext或IsNull类型条件的循环,并且在循环内部,您将使用您的If语句来比较ID(从我的代码中了解的内容)的值。

+0

谢谢你的回答:) – Marin