ArcFM Desktop Developer Guide
C# Code Sample

Resource Center Home

In the event that you want to bypass the standard ArcFM login and connect to a predefined ArcFM system database, you can utilize the default login object to write your custom login solution.

This code sample creates an ArcFM login dialog that lets the user log into an Oracle or SQL Server database. This sample does not support login for personal geodatabases.

Product Availability: ArcFM Engine, ArcFM Viewer for ArcGIS Engine, ArcFM Desktop

References: Miner.Controls, Miner.Interop.Geodatabase, Miner.Interop.System, Miner.mmSystem

  1. Login objects require a using directive to the mmSystem library and Miner.Interop.

  2. IMMChangeDefaultVersion accesses the default connection properties in MMDefaultLoginObject.

  3. The Login method sets up the connection properties and logs in using the default login object.

  4. Reuse the default login object’s implementation of GetFullTableName.

  5. Cancels the login and closes the login form.

  6. Validates and sets the user name and password, sets the connection properties, and executes the login.

  7. Code the IsValidLogin property so that it will return whether a call to Login() was successful.

  8. The UserName property should return the username that was used to login to the system database.

  9. The LoginWorkspace property should return the login workspace.

  10. Validates the values input by the user on the login form.

  11. Sets the active control to the user name text box when the form loads.

C# Sample
Copy Code
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;

using Miner.Interop;
//1
using Miner.mmSystem;

using Esri.ArcGIS.Geodatabase;
using Esri.ArcGIS.esriSystem;


namespace Miner.DeveloperSamples.Engine
{
  /// <summary>
  /// The ArcFM Engine Login sample enables the user to log into 
  /// an Oracle or SQL Server database.
  /// Currently, there is no support for personal geodatabases.
  /// </summary>
 /// 
 public class EngineLoginObject : System.Windows.Forms.Form, IMMLoginObject, IMMChangeDefaultVersion
 {

  private MMDefaultLoginObjectClass _defaultLoginObject;
  private bool _initialLogin;
  private bool _loginChanged;
  private IPropertySet propertySet;
  
  //ViewerLoginObject Form Variables//

   /// <summary>
   /// Required designer variable.
   /// </summary>
  private System.ComponentModel.Container components = null;

  public EngineLoginObject()
  { 
   
  //Windows Generated Code//

//2
  #region IMMChangeDefaultVersion Members

  public void ChangeDefaultVersion(IVersion pVersion)
  {
   _defaultLoginObject.ChangeDefaultVersion(pVersion);
  }

  #endregion

//3
  #region IMMLoginObject Members

  public bool Login(bool vbInitialLogin)
  {
   _initialLogin = vbInitialLogin;
   this.ShowDialog();
   return _loginChanged;
  }

  public string GetFullTableName(string bstrBaseTableName)
  {
//4
   return _defaultLoginObject.GetFullTableName(bstrBaseTableName);
  }

//5
  private void cmdCancel_Click(object sender, System.EventArgs e)
  {
   if(_defaultLoginObject.IsValidLogin)
   {
    this.Close();
   }
   else
   {
    Process.GetCurrentProcess().Kill();
   }

  }

  private void cmdOK_Click(object sender, System.EventArgs e)
  {
   propertySet = new PropertySetClass();
   System.Windows.Forms.Cursor.Current = Cursors.WaitCursor;

    //Check for valid user name and password
//6
   string userName = txtUser.Text.Trim();
   string password = txtPassword.Text.Trim();
   string server = txtServer.Text.Trim();
   string instance = txtInstance.Text.Trim();
   string database = txtDatabase.Text.Trim();

   if(!ValidateUserPassword(userName, password, server)) 
    return;
   
    //Set server, instance, database
   propertySet.SetProperty("SERVER", server);
   propertySet.SetProperty("INSTANCE", instance);
   propertySet.SetProperty("DATABASE", database);
   propertySet.SetProperty("VERSION", "SDE.DEFAULT");

    //Set user and password
   propertySet.SetProperty("USER", userName);
   propertySet.SetProperty("PASSWORD", password);

    //Try to login using ArcFM's default login object
   _defaultLoginObject.SetConnectionProperties(propertySet);
   _defaultLoginObject.ShowDialog = false;
   _loginChanged = _defaultLoginObject.Login(_initialLogin);

   this.Close();
   
   System.Windows.Forms.Cursor.Current = Cursors.Default;
  }
//7
  public bool IsValidLogin
  {
   get
   {
    return _defaultLoginObject.IsValidLogin;
   }
  }
//8
  public string UserName
  {
   get
   {
    return _defaultLoginObject.UserName;
   }
  }
//9
  public IWorkspace LoginWorkspace
  {
   get
   {
    return _defaultLoginObject.LoginWorkspace;
   }
  }

  #endregion
//10
  private bool ValidateUserPassword(string userName, string password, string server)
  {
   if (userName.Length == 0)
   {
    MessageBox.Show("Enter User Name", "GeneralCaption");
    txtUser.Focus();
    return false;
   }

   if (userName.IndexOf("'") > 0 || userName.IndexOf(" ") > 0 || userName.IndexOf(@"""") > 0)
   {
    MessageBox.Show("Cannot Contain Special Characters", "Dev: ArcFM Engine Login");
    txtUser.Focus();
    return false;
   }

   if (password.Length == 0 && server != "")
   {
    MessageBox.Show("Please Enter Password", "Dev: ArcFM Engine Login");
    txtPassword.Focus();
    return false;
   }

   return true;
  }
//11
  private void ViewerLoginObject_Load(object sender, System.EventArgs e)
  {
   try
   {
    if (txtUser.Text == "")
    {
     this.ActiveControl = txtUser;
    }
    else
    {
     this.ActiveControl = txtPassword;
    }
   }
   catch (Exception exc)
   {
    MessageBox.Show("Error creating login object. " + exc.ToString());
    Process.GetCurrentProcess().Kill();
   }
  }
 }
}

 

Return to Login Objects

 

 


Send Comment to ArcFMdocumentation@schneider-electric.com