2011-03-25 6 views
1

나는 CRM 시스템을 위해 사용자 정의 된 추가 기능을 구축 중입니다. 최종 사용자가 특정 조건을 충족하면 메시지 상자를 한 번만 팝업하고 싶습니다. 다음 클래스에서한 번만 메시지 보이기

public class MyWorkspaceAddIn : Panel, IWorkspaceComponent2 
    { 

     private bool _readOnly; 
     private IRecordContext _recordContext; 
     private IGlobalContext _globalContext; 
     private bool _triggerPopup = true; 

팝업 코드 :

void _incident_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
     {//check property and/or i.Prod and then show the popup 

      // MessageBox.Show(e.PropertyName); //Check what property name is 

      if (_incident.ProductID == 182 && _triggerPopup) //If product ID is 183 in incident 
      { 
       MessageBox.Show("The GO Classic will soon be end of life, make sure you propose the customer to buy a new device and offer maximum 20% discount to reward his/her loyalty (NOTE: refurbished devices are not included in this offer)."); 
       _triggerPopup = false; //Do not pop up 
      } 

I I 글로벌 스코프의 트리거 변수를 선언

: 본인은 다음과 구현에서 제대로 할 수 있는지 확실하지 않다 메시지 상자가 한 번만 나타나기를 바랍니다.

전체 코드 :

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.AddIn; 
using RightNow.AddIns.AddInViews; 
using RightNow.AddIns.Common; 
using System.Windows.Forms; 

//////////////////////////////////////////////////////////////////////////////// 
// 
// File: MyWorkspaceAddIn.cs 
// 
// Comments: 
// 
// Notes: 
// 
// Pre-Conditions: 
// 
//////////////////////////////////////////////////////////////////////////////// 
namespace TriggerAddIn 
{ 
    [AddIn("My VAS AddIn", Version = "1.1.0.2")] 
    public class MyWorkspaceAddIn : Panel, IWorkspaceComponent2 
    { 

     private bool _readOnly; 
     private IRecordContext _recordContext; 
     private IGlobalContext _globalContext; 
     private bool _triggerPopup = true; 

     IIncident _incident; //Define IIncident outside dataLoaded event; 
     //Get reference when the incident open in workspace. 
     public MyWorkspaceAddIn(bool inDesignMode, IRecordContext recContext, IGlobalContext globalContext) 
     { 
      /*MessageBox.Show("AddIns Load My workspace plugin");*/ 

      _recordContext = recContext; 
      _globalContext = globalContext; 
      //Check wheather users 
      if (!inDesignMode &&_recordContext != null) 
      { //Add our custom event 
       _recordContext.DataLoaded += new EventHandler(_recordContext_DataLoaded); 
      } 
     } 
     //Custom Event handler 
     void _recordContext_DataLoaded(object sender, EventArgs e) 
     { 
      _incident = _recordContext.GetWorkspaceRecord(WorkspaceRecordType.Incident) as IIncident; 

      if (_incident != null) 
      { 
       _incident.PropertyChanged -= _incident_PropertyChanged; 
       _incident.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(_incident_PropertyChanged); 
      } 
     } 
     void _incident_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) 
     {//check property and/or i.Prod and then show the popup 

      // MessageBox.Show(e.PropertyName); //Check what property name is 

      if (_incident.ProductID == 182 && _triggerPopup) //If product ID is 183 in incident 
      { 
       MessageBox.Show("The GO Classic will soon be end of life, make sure you propose the customer to buy a new device and offer maximum 20% discount to reward his/her loyalty (NOTE: refurbished devices are not included in this offer)."); 
       _triggerPopup = false; //Do not pop up 
      } 
      /* 
      if (_incident.CategoryID == 2353) 
      { 
       Form1 myForm = new Form1(); 
       myForm.ShowDialog(); 
      }*/ 
     } 
     #region IAddInControl Members 

     public Control GetControl() 
     { 
      return this; 
     } 

     #endregion 

     #region IWorkspaceComponent2 Members 

     public bool ReadOnly 
     { 
      get 
      { 
       return _readOnly; 
      } 
      set 
      { 
       _readOnly = value; 
      } 
     } 

     public void RuleActionInvoked(string actionName) 
     { 

     } 

     public string RuleConditionInvoked(string conditionName) 
     { 
      return ""; 
     } 

     #endregion 
    } 

    [AddIn("My VAS Factory AddIn", Version = "1.1.0.2")] 
    public class MyWorkspaceAddInFactory : IWorkspaceComponentFactory2 
    { 

     private IGlobalContext _globalContext; 

     #region IWorkspaceComponentFactory2 Members 

     IWorkspaceComponent2 IWorkspaceComponentFactory2.CreateControl(bool inDesignMode, IRecordContext context) 
     { 
      return new MyWorkspaceAddIn(inDesignMode, context, _globalContext); 
     } 

     #endregion 

     #region IFactoryBase Members 

     public System.Drawing.Image Image16 
     { 
      get { return Properties.Resources.AddIn16; } 
     } 

     public string Text 
     { 
      get { return "Trigger add in for VAS"; } 
     } 

     public string Tooltip 
     { 
      get { return "Trigger add in for VAS Tooltip"; } 
     } 

     #endregion 

     #region IAddInBase Members 

     public bool Initialize(IGlobalContext context) 
     { 
      _globalContext = context; 

      return true; 
     } 

     #endregion 

    } 
} 
+2

이렇게 해 보았습니다. 어떻게 된 거예요? –

+1

무엇이 문제입니까? 코드를 해봤습니까? 작동합니까? –

답변

2

이것은 좋아 보이지만 한 번만 실행되는 PropertyChanged에 나만의 이벤트를 구현하는 것입니다. PropertyFirstChanged 추가 코드 호출을 피할 수 있습니다.

+0

추가 코드 호출을 어떻게 피할 수 있습니까? 필요한 이벤트를 결정할 때도 검사를해야합니다. –

+0

이벤트는 한 번만 실행되므로 메서드 호출을 수행하지 않습니다. 물론 상승 이벤트를 결정할 필요가 있지만 레벨 업 책임으로 이동하기 때문에 이벤트가 필요없는 경우 해고되지 않습니다. –

+0

안녕 Pawel과 Cody, 빠른 답장을 보내 주셔서 감사합니다. 이벤트는 한 번로드되기 때문에 PropertyChanged를 사용자 정의하는 것은 어렵다고 생각합니다. 내 원본 게시물에있는 모든 코드를 공유합니다. – QLiu

0

당신의 코드가 나에게 올바른 것, 특정 질문은 코드가 맞다면 여기에 다른 다음이?

당신에게 MyWorkspaceAddIn의 모든 인스턴스에 대한 팝업이 표시됩니다. 팝업을 응용 프로그램 수명 동안 한 번만 표시하려면 다른 클래스의 정적 변수를 호출해야합니다.