CFRONTDOTNET Navision 2009 R2

albertassaad@hotmail.com
Member Posts: 13
Hello,
I am trying to connect via .net C# program to Nav server(SQL) getting the last transaction for a specific POS and then trying to connect to that POS (Native) by changing the CFRONT driver type, sometimes it's working and sometimes not I think cause I don't have 2 instance of the CFront object (the same Object is switching the driver type from SQL to native) hereby my function would you please help?
public void connectandcheck()
{
if (PosLocations == null || HoLocation == null)
{
throw new NullReferenceException();
}else{
NavisionValue HOData = new NavisionValue();
NavisionValue POSData = new NavisionValue();
foreach (Location l in PosLocations)
{
int tablehandle=0;
int recordHandle=0;
CFrontDotNet.NavisionPath = "C:\\Program Files (x86)\\LS Retail\\Data Director 3\\cfront\\602\\";
try
{
NavisionNetType HonetType = NavisionNetType.SqlDefault;
CFrontDotNet.DriverType = NavisionDriverType.Sql;
CFrontDotNet.Instance.ConnectServerAndOpenDatabase(HoLocation.getServerName(), HonetType, HoLocation.getDatabase(),
65000, false, false, HoLocation.getUsername(), HoLocation.getPassword());
CFrontDotNet.Instance.OpenCompany(HoLocation.getCompany());
tablehandle = CFrontDotNet.Instance.OpenTable(99001473);
recordHandle = CFrontDotNet.Instance.AllocRecord(tablehandle);
CFrontDotNet.Instance.SetFilter(tablehandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Store No."), "=" + l.getLocationName());
CFrontDotNet.Instance.FindLastRecord(tablehandle, recordHandle);
HOData = CFrontDotNet.Instance.GetFieldData(tablehandle, recordHandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Transaction
No."));
CFrontDotNet.Instance.CloseTable(99001473);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
}
catch (CFrontException ex)
{
messagetosend = messagetosend + "\r\n" + "Cannot Connect to HO while checking POS No." + l.getLocationName();
LogMessage.LogTheEvent("Error cannot Login to HO "+ ex.Message.ToString());
CFrontDotNet.Instance.CloseTable(tablehandle);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
continue;
}
try
{
NavisionNetType Posnettype = NavisionNetType.NativeTcp;
CFrontDotNet.DriverType = NavisionDriverType.Native;
CFrontDotNet.Instance.ConnectServerAndOpenDatabase(l.getServerName(), Posnettype, l.getCompany(), 65000, false, false,
l.getUsername(), l.getPassword());
CFrontDotNet.Instance.OpenCompany(l.getCompany());
tablehandle = CFrontDotNet.Instance.OpenTable(99001473);
recordHandle = CFrontDotNet.Instance.AllocRecord(tablehandle);
CFrontDotNet.Instance.SetFilter(tablehandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Store No."), "=" + l.getLocationName());
CFrontDotNet.Instance.FindLastRecord(tablehandle, recordHandle);
POSData = CFrontDotNet.Instance.GetFieldData(tablehandle, recordHandle, CFrontDotNet.Instance.FieldNo(tablehandle,
"Transaction No."));
CFrontDotNet.Instance.CloseTable(99001473);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
if (HOData.ToString() != POSData.ToString())
{
int honumber = Int32.Parse(HOData.ToString());
int posnumber = Int32.Parse(POSData.ToString());
int difference = posnumber - honumber;
messagetosend = messagetosend + "\r\n" + "You have " + difference + " transactions difference between HO and POS No. on" +
l.getLocationName();
}
}
catch (CFrontException ex)
{
messagetosend = messagetosend + "\r\n" + "Cannot Connect to POS No. " + l.getLocationName()+ "Last Ho Transaction No.
"+HOData.ToString();
LogMessage.LogTheEvent("Error cannot Login to POS "+l.getLocationName()+" " + ex.Message.ToString());
CFrontDotNet.Instance.CloseTable(tablehandle);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
continue;
}
}
I am trying to connect via .net C# program to Nav server(SQL) getting the last transaction for a specific POS and then trying to connect to that POS (Native) by changing the CFRONT driver type, sometimes it's working and sometimes not I think cause I don't have 2 instance of the CFront object (the same Object is switching the driver type from SQL to native) hereby my function would you please help?
public void connectandcheck()
{
if (PosLocations == null || HoLocation == null)
{
throw new NullReferenceException();
}else{
NavisionValue HOData = new NavisionValue();
NavisionValue POSData = new NavisionValue();
foreach (Location l in PosLocations)
{
int tablehandle=0;
int recordHandle=0;
CFrontDotNet.NavisionPath = "C:\\Program Files (x86)\\LS Retail\\Data Director 3\\cfront\\602\\";
try
{
NavisionNetType HonetType = NavisionNetType.SqlDefault;
CFrontDotNet.DriverType = NavisionDriverType.Sql;
CFrontDotNet.Instance.ConnectServerAndOpenDatabase(HoLocation.getServerName(), HonetType, HoLocation.getDatabase(),
65000, false, false, HoLocation.getUsername(), HoLocation.getPassword());
CFrontDotNet.Instance.OpenCompany(HoLocation.getCompany());
tablehandle = CFrontDotNet.Instance.OpenTable(99001473);
recordHandle = CFrontDotNet.Instance.AllocRecord(tablehandle);
CFrontDotNet.Instance.SetFilter(tablehandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Store No."), "=" + l.getLocationName());
CFrontDotNet.Instance.FindLastRecord(tablehandle, recordHandle);
HOData = CFrontDotNet.Instance.GetFieldData(tablehandle, recordHandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Transaction
No."));
CFrontDotNet.Instance.CloseTable(99001473);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
}
catch (CFrontException ex)
{
messagetosend = messagetosend + "\r\n" + "Cannot Connect to HO while checking POS No." + l.getLocationName();
LogMessage.LogTheEvent("Error cannot Login to HO "+ ex.Message.ToString());
CFrontDotNet.Instance.CloseTable(tablehandle);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
continue;
}
try
{
NavisionNetType Posnettype = NavisionNetType.NativeTcp;
CFrontDotNet.DriverType = NavisionDriverType.Native;
CFrontDotNet.Instance.ConnectServerAndOpenDatabase(l.getServerName(), Posnettype, l.getCompany(), 65000, false, false,
l.getUsername(), l.getPassword());
CFrontDotNet.Instance.OpenCompany(l.getCompany());
tablehandle = CFrontDotNet.Instance.OpenTable(99001473);
recordHandle = CFrontDotNet.Instance.AllocRecord(tablehandle);
CFrontDotNet.Instance.SetFilter(tablehandle, CFrontDotNet.Instance.FieldNo(tablehandle, "Store No."), "=" + l.getLocationName());
CFrontDotNet.Instance.FindLastRecord(tablehandle, recordHandle);
POSData = CFrontDotNet.Instance.GetFieldData(tablehandle, recordHandle, CFrontDotNet.Instance.FieldNo(tablehandle,
"Transaction No."));
CFrontDotNet.Instance.CloseTable(99001473);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
if (HOData.ToString() != POSData.ToString())
{
int honumber = Int32.Parse(HOData.ToString());
int posnumber = Int32.Parse(POSData.ToString());
int difference = posnumber - honumber;
messagetosend = messagetosend + "\r\n" + "You have " + difference + " transactions difference between HO and POS No. on" +
l.getLocationName();
}
}
catch (CFrontException ex)
{
messagetosend = messagetosend + "\r\n" + "Cannot Connect to POS No. " + l.getLocationName()+ "Last Ho Transaction No.
"+HOData.ToString();
LogMessage.LogTheEvent("Error cannot Login to POS "+l.getLocationName()+" " + ex.Message.ToString());
CFrontDotNet.Instance.CloseTable(tablehandle);
CFrontDotNet.Instance.CloseCompany();
CFrontDotNet.Instance.CloseDatabase();
continue;
}
}
0
Answers
-
[Topic moved from 'NAV Tips & Tricks' forum to 'NAV/Navision Classic Client' forum]
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions