Dear All, I need your advise
I am working with
GP10 and SP4
Developer toolkit SP3
eConnect Sp3
I want to tell you the how I am structuring my code using Developer tool kit.
I create new Project “Dynamic GP Add-in”
GPAddIn Class “IDexterityAddIn” File Created for me by default
I want to make some customizations specific screen “ItemTransferEntry” then I create a new normal Class.
Inside my class I wrote all the events for “ItemTransferEntry” and then write my code inside these events, for ex.
Validate some data entered by the user
Adding new serial
Validate that the user is allowed to use the selected site
Please find below example of GPAddIn Class
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;
using System.Data;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.IO;
using System.EnterpriseServices;
using System.Reflection;
namespace DynamicsGPAddin1
{
public class GPAddIn : IDexterityAddIn
{
public void Initialize()
{
ItemTransferEntry itemTransferEntry = new ItemTransferEntry();
}
}
}
Please find below example of “ItemTransferEntry” Class
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Dexterity.Bridge;
using Microsoft.Dexterity.Applications;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.SqlClient;
using System.Data.Common;
using System.Data;
using System.Windows.Forms;
using SharedClasses;
namespace DynamicsGPAddin1
{
class ItemTransferEntry
{
SiteSecurity.SiteSecurityAbb FromResult;
SiteSecurity.SiteSecurityAbb TOResult;
SiteSecurity.SiteSecurityAbb Result;
SiteSecurity.SiteSecurityAbb TrxFromSiteResult;
SiteSecurity.SiteSecurityAbb TrxTOSiteResult;
public ItemTransferEntry()
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.ValidateBeforeOriginal +=new System.ComponentModel.CancelEventHandler(IvDocumentNumber_ValidateBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.EnterBeforeOriginal += new System.ComponentModel.CancelEventHandler(IvDocumentNumber_EnterBeforeOriginal);
//Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.LeaveBeforeOriginal+=new System.ComponentModel.CancelEventHandler(IvDocumentNumber_LeaveBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.ValidateBeforeOriginal += new System.ComponentModel.CancelEventHandler(LocalFromDefaultSite_ValidateBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.ValidateBeforeOriginal += new System.ComponentModel.CancelEventHandler(LocalToDefaultSite_ValidateBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.LeaveAfterOriginal += new EventHandler(LocalToDefaultSite_LeaveAfterOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.LeaveAfterOriginal += new EventHandler(LocalFromDefaultSite_LeaveAfterOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.ValidateBeforeOriginal += new System.ComponentModel.CancelEventHandler(TrxLocation_ValidateBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.ValidateBeforeOriginal += new System.ComponentModel.CancelEventHandler(TransferToLocation_ValidateBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.SaveButton.ClickAfterOriginal += new EventHandler(SaveButton_ClickAfterOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.DeleteButton.ClickAfterOriginal += new EventHandler(DeleteButton_ClickAfterOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.CloseAfterOriginal += new EventHandler(IvTransferEntry_CloseAfterOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.PrintBeforeOriginal += new System.ComponentModel.CancelEventHandler(IvTransferEntry_PrintBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.SaveButton.ClickBeforeOriginal+=new System.ComponentModel.CancelEventHandler(SaveButton_ClickBeforeOriginal);
//Dynamics.Forms.IvTransferEntry.IvTransferEntry.ActivateAfterOriginal += new EventHandler(IvTransferEntry_ActivateAfterOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LookupButton3.ClickBeforeOriginal += new System.ComponentModel.CancelEventHandler(LookupButton3_ClickBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LookupButton4.ClickBeforeOriginal += new System.ComponentModel.CancelEventHandler(LookupButton4_ClickBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LookupButton7.ClickBeforeOriginal += new System.ComponentModel.CancelEventHandler(LookupButton7_ClickBeforeOriginal);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LookupButton8.ClickBeforeOriginal += new System.ComponentModel.CancelEventHandler(LookupButton8_ClickBeforeOriginal);
//Dynamics.Forms.IvTransferEntry.IvTransferEntry.SaveRecord.ValidateBeforeOriginal += new System.ComponentModel.CancelEventHandler(SaveRecord_ValidateBeforeOriginal);
}
void LookupButton8_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
SitesLookUP sitesLookUP = new SitesLookUP();
sitesLookUP._ScreenName = SitesLookUP.Screens.ItemTransferEntry;
sitesLookUP._SiteSource = SitesLookUP.SiteSource.LineToSite;
sitesLookUP.Show();
e.Cancel = true;
}
catch (Exception ex)
{
throw new Exception("LookupButton4_ClickBeforeOriginal" + ex.Message);
}
}
void LookupButton7_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
SitesLookUP sitesLookUP = new SitesLookUP();
sitesLookUP._ScreenName = SitesLookUP.Screens.ItemTransferEntry;
sitesLookUP._SiteSource = SitesLookUP.SiteSource.LineFromSite;
sitesLookUP.Show();
e.Cancel = true;
}
catch (Exception ex)
{
throw new Exception("LookupButton4_ClickBeforeOriginal" + ex.Message);
}
}
void LookupButton4_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
SitesLookUP sitesLookUP = new SitesLookUP();
sitesLookUP._ScreenName = SitesLookUP.Screens.ItemTransferEntry;
sitesLookUP._SiteSource = SitesLookUP.SiteSource.ToSite;
sitesLookUP.Show();
e.Cancel = true;
}
catch (Exception ex)
{
throw new Exception("LookupButton4_ClickBeforeOriginal" + ex.Message);
}
}
void LookupButton3_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
SitesLookUP sitesLookUP = new SitesLookUP();
sitesLookUP._ScreenName = SitesLookUP.Screens.ItemTransferEntry;
sitesLookUP._SiteSource = SitesLookUP.SiteSource.FromSite;
sitesLookUP.Show();
e.Cancel = true;
}
catch (Exception ex)
{
throw new Exception("LookupButton3_ClickBeforeOriginal" + ex.Message);
}
}
void IvTransferEntry_ActivateAfterOriginal(object sender, EventArgs e)
{
try
{
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value != "")
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Disable();
}
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite != "")
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Disable();
}
}
catch(Exception ex)
{
throw new Exception("IvTransferEntry_ActivateAfterOriginal" + ex.Message);
}
}
void SaveButton_ClickBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
int nAbbStatus;
AbbStatus abbStatus = new AbbStatus();
string strDocNumber = Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value;
if (strDocNumber.Length > 6)
{
nAbbStatus = abbStatus.GetAbbStatus(strDocNumber.Substring(3, 3));
}
else
{
nAbbStatus = 0;
}
if (nAbbStatus == 0)
{
MessageBox.Show("You Are Not Allowed To Use This Serial.", "Auto Serial", MessageBoxButtons.OK, MessageBoxIcon.Stop);
e.Cancel = true;
}
}
catch (Exception ex)
{
throw new Exception("SaveButton_ClickBeforeOriginal" + ex.Message);
}
}
void IvTransferEntry_PrintBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
EditaTrustReceipt editaTrustReceipt = new EditaTrustReceipt();
editaTrustReceipt._PrintType = EditaTrustReceipt.PrintType.ItemTransferEntry;
editaTrustReceipt.Show();
e.Cancel = true;
}
catch(Exception ex)
{
throw new Exception("IvTransferEntry_PrintBeforeOriginal" + ex.Message);
}
}
void IvTransferEntry_CloseAfterOriginal(object sender, EventArgs e)
{
try
{
ItemTransferLotNumberEntry._strBin = "";
}
catch(Exception ex)
{
throw new Exception("IvTransferEntry_CloseAfterOriginal" + ex.Message);
}
}
void DeleteButton_ClickAfterOriginal(object sender, EventArgs e)
{
try
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value = "";
ItemTransferLotNumberEntry._strBin = "";
}
catch(Exception ex)
{
throw new Exception("DeleteButton_ClickAfterOriginal" + ex.Message);
}
}
void SaveButton_ClickAfterOriginal(object sender, EventArgs e)
{
try
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value = "";
ItemTransferLotNumberEntry._strBin = "";
}
catch(Exception ex)
{
throw new Exception("SaveButton_ClickAfterOriginal" + ex.Message);
}
}
void IvDocumentNumber_EnterBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
//Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value = "00000000000000001";//System.Guid.NewGuid().ToString().Substring(0, 16);//"00000000000000001";
GetDocumentSerialNumberNewValue getDocumentSerialNumberNewValue = new GetDocumentSerialNumberNewValue();
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value =
getDocumentSerialNumberNewValue.DocumentGetNewSerial(GetDocumentSerialNumberNewValue.TransType.OPN,
"OPN");
}
catch(Exception ex)
{
throw new Exception("IvDocumentNumber_EnterBeforeOriginal" + ex.Message);
}
}
void TransferToLocation_ValidateBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Value != "")
{
try
{
if (TOResult == SiteSecurity.SiteSecurityAbb.HeaderDetailAreTheSame)
{
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Value.Trim() != Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value.Trim())
{
MessageBox.Show("Header and Detail Site Should be The Same", "Site Security", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Focus();
}
}
else
{
try
{
SiteSecurity siteSecurity = new SiteSecurity();
TrxTOSiteResult = siteSecurity.TOSiteValidation(Dynamics.Globals.UserId, Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Value.Trim());
if ((TrxTOSiteResult == SiteSecurity.SiteSecurityAbb.SiteDoesNotBelongToUser) || (TrxTOSiteResult == SiteSecurity.SiteSecurityAbb.UserISNotAllowedForPosting) || (TrxTOSiteResult == SiteSecurity.SiteSecurityAbb.AbbandCityAreWrong))
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TransferToLocation.Focus();
}
}
catch (Exception ex)
{
throw new Exception("TransferToLocation_ValidateBeforeOriginal" + ex.Message);
}
}
}
catch (Exception ex)
{
throw new Exception("TransferToLocation_ValidateBeforeOriginal" + ex.Message);
}
}
}
void TrxLocation_ValidateBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Value != "")
{
try
{
if (FromResult == SiteSecurity.SiteSecurityAbb.HeaderDetailAreTheSame)
{
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Value.Trim() != Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Value.Trim())
{
MessageBox.Show("Header and Detail Site Should be The Same", "Site Security", MessageBoxButtons.OK, MessageBoxIcon.Warning);
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Focus();
}
}
else
{
try
{
string strSubString;
SiteSecurity siteSecurity = new SiteSecurity();
strSubString = siteSecurity.DocumentCheck(Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value);
TrxFromSiteResult = siteSecurity.FromSiteValidation(Dynamics.Globals.UserId, Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Value.Trim(), strSubString);
if ((TrxFromSiteResult == SiteSecurity.SiteSecurityAbb.SiteDoesNotBelongToUser) || (TrxFromSiteResult == SiteSecurity.SiteSecurityAbb.UserISNotAllowedForPosting) || (TrxFromSiteResult == SiteSecurity.SiteSecurityAbb.AbbandCityAreWrong))
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvTransferScroll.TrxLocation.Focus();
}
}
catch (Exception ex)
{
throw new Exception("TrxLocation_ValidateBeforeOriginal" + ex.Message);
}
}
}
catch (Exception ex)
{
throw new Exception("TrxLocation_ValidateBeforeOriginal" + ex.Message);
}
}
}
void LocalFromDefaultSite_LeaveAfterOriginal(object sender, EventArgs e)
{
if(Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Value != "")
{
try
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Disable();
}
catch(Exception ex)
{
throw new Exception("LocalFromDefaultSite_LeaveAfterOriginal" + ex.Message);
}
}
}
void LocalToDefaultSite_LeaveAfterOriginal(object sender, EventArgs e)
{
if (Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value != "")
{
try
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Disable();
}
catch (Exception ex)
{
throw new Exception("LocalToDefaultSite_LeaveAfterOriginal" + ex.Message);
}
}
}
void LocalToDefaultSite_ValidateBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
SiteSecurity siteSecurity = new SiteSecurity();
TOResult = siteSecurity.TOSiteValidation(Dynamics.Globals.UserId, Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value.Trim());
if ((TOResult == SiteSecurity.SiteSecurityAbb.SiteDoesNotBelongToUser) || (TOResult == SiteSecurity.SiteSecurityAbb.UserISNotAllowedForPosting) || (TOResult == SiteSecurity.SiteSecurityAbb.AbbandCityAreWrong))
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalToDefaultSite.Focus();
}
}
catch (Exception ex)
{
throw new Exception("LocalToDefaultSite_ValidateBeforeOriginal" + ex.Message);
}
}
void LocalFromDefaultSite_ValidateBeforeOriginal(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
string strSubString = "";
SiteSecurity siteSecurity = new SiteSecurity();
strSubString = siteSecurity.DocumentCheck(Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value);
FromResult = siteSecurity.FromSiteValidation(Dynamics.Globals.UserId, Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Value.Trim(), strSubString);
if ((FromResult == SiteSecurity.SiteSecurityAbb.SiteDoesNotBelongToUser) || (FromResult == SiteSecurity.SiteSecurityAbb.UserISNotAllowedForPosting) || (FromResult == SiteSecurity.SiteSecurityAbb.AbbandCityAreWrong))
{
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Value = "";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.LocalFromDefaultSite.Focus();
}
}
catch (Exception ex)
{
throw new Exception("LocalFromDefaultSite_ValidateBeforeOriginal" + ex.Message);
}
}
void IvDocumentNumber_ValidateBeforeOriginal(object sender, EventArgs e)
{
try
{
string strOldSerial = Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value;
GetDocumentSerialNumberNewValue getDocumentSerialNumberNewValue = new GetDocumentSerialNumberNewValue();
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value =
getDocumentSerialNumberNewValue.DocumentGetNewSerial(GetDocumentSerialNumberNewValue.TransType.TRX,
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value);
string strNewSerial = Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value;
///////////////////
if (strOldSerial == strNewSerial)
{
SiteSecurity siteSecurity = new SiteSecurity();
Result = siteSecurity.DocumentAuthorization(Dynamics.Globals.UserId, GetDocumentSerialNumberNewValue.TransType.TRX, Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value);
if (Result == SiteSecurity.SiteSecurityAbb.DocumentDoesNotBelongTOThisUser)//"DocumentDoesNotBelongTOThisUser")
{
//Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value = "00000000000000001";//System.Guid.NewGuid().ToString().Substring(0, 16);//"00000000000000001";
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Value =
getDocumentSerialNumberNewValue.DocumentGetNewSerial(GetDocumentSerialNumberNewValue.TransType.OPN,
"OPN");
Dynamics.Forms.IvTransferEntry.IvTransferEntry.IvDocumentNumber.Focus();
((System.ComponentModel.CancelEventArgs)(e)).Cancel = true;
}
}
}
catch (Exception ex)
{
throw new Exception("IvDocumentNumber_ValidateBeforeOriginal" + ex.Message);
}
}
}
}
*This post is locked for comments