public virtual void TemplateCategoryDelete(TemplateCategory entity)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     m_DataContext.BeginNestedTran();
     try
     {
       m_DataContext.ndihdTemplateCategoryDelete(entity.TemplateRef,
                                             entity.ProgramCategoryRef);
       m_DataContext.CommitNested();
     }
     catch
     {
       m_DataContext.RollbackNested();
       throw;
     }
     TraceCallReturnEvent.Raise();
     return;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }
        // -------------------------------------------------------------------------------------
        /// <summary>
        /// Insert a new Template record to the database
        /// </summary>
        // -------------------------------------------------------------------------------------
        private void InsertData()
        {
            try
              {
            ITemplateService srv = ServiceFactory.GetTemplateService();
            m_Template.Name = txtName.Text;
            m_Template.IsActive = cbxActivate.Checked;
            m_Template.PublicityLevel = Convert.ToInt32(cmbPublicityLevel.SelectedValue);

            // set categories:
            if (rbtCategoryOrganisation.Checked)
            {
              TemplateCategory catOrg = new TemplateCategory(m_Template.ID, "ORG");
              m_Template.Categories.Insert(catOrg);
            }
            if (rbtCategoryProgram.Checked)
            {
              if (cbxCategoryOther.Checked)
              {
            TemplateCategory catOth = new TemplateCategory(m_Template.ID, "OTH");
            m_Template.Categories.Insert(catOth);
              }
              if (cbxCategoryPrevention.Checked)
              {
            TemplateCategory catPre = new TemplateCategory(m_Template.ID, "PRE");
            m_Template.Categories.Insert(catPre);
              }
              if (cbxCategoryResearch.Checked)
              {
            TemplateCategory catRes = new TemplateCategory(m_Template.ID, "RES");
            m_Template.Categories.Insert(catRes);
              }
              if (cbxCategoryTreatment.Checked)
              {
            TemplateCategory catTre = new TemplateCategory(m_Template.ID, "TRE");
            m_Template.Categories.Insert(catTre);
              }
            }

            srv.TemplateInsert(m_Template);
              }
              catch (Exception ex)
              {
            throw ex;
              }
        }
 // -------------------------------------------------------------------------------------
 /// <summary>
 /// Copy constructor.
 /// </summary>
 /// <param name="origInstance">Original document data to copy.</param>
 // -------------------------------------------------------------------------------------
 public TemplateCategory(TemplateCategory origInstance)
     : base(origInstance)
 {
 }
 public virtual TemplateCategory TemplateCategorySelect(DBGuid TemplateRefVal,
                                                    DBString ProgramCategoryRefVal)
 {
     TraceCallEnterEvent.Raise();
       try
       {
     TemplateCategory result = null;
     DataSet entitySet = m_DataContext.ndihdTemplateCategorySelect(TemplateRefVal,
                                                               ProgramCategoryRefVal);
     if (entitySet.Tables[0].Rows.Count != 0)
     {
       result = new TemplateCategory(entitySet);
     }
     TraceCallReturnEvent.Raise();
     return result;
       }
       catch (Exception ex)
       {
     ExceptionManager.Publish(ex);
     TraceCallReturnEvent.Raise(false);
     throw;
       }
 }