anthony peiris
11th December 2010, 22:10
Attempting to print order acknowledgement with the following code.
BaaN throws "Can't read session or object (tdsls44010002)"
The object BaaN is complaining about really do not exist.. I guess it is inferring this from request submitted.
also note the code is throwing 'Process is gone'
When I run the code I get this debugger output
1: SetEnum
141527: Putfield orno.f
000: Putfield comp.f
999: Putfield comp.t
141527: Putfield orno.t
2: SetEnum prnt.discount
2: Putfield prnt.sellpr
1: Putfield printed
1: Putfield quant.to.print
2: Putfield prnt.options
1: Putfield num.copies
InsertSession(tdsls4401m000):1
FindSession(tdsls4401m000), Found=ok.Found
CountinueProces(tdsls4401m000):Process is gone
#region button1 click
private void button1_Click(object sender, EventArgs e)
{
// Reference myBW is tlibimp from Baan 4 bw type lib
// 2010 Dec 3rd a.p
// myBw.IDispatchBaan4 b = new myBw.Baan4();
b.Timeout = 1;
string qry = "select tiitm001.citg from tiitm001 group by tiitm001.citg order by tiitm001.citg";
string sf = string.Format("olesql_parse(\"{0}\")", qry);
int i = b.ParseExecFunction("ottdllsql_query", sf);
Debug.WriteLine(sf);
Debug.WriteLine(i);
int handle = int.Parse(b.ReturnValue);
string s2 = "";
sf = string.Format("olesql_fetch({0})", handle); b.ParseExecFunction("ottdllsql_query", sf);// fetch the first one
while (b.ReturnValue != "110")
{
s2 = string.Format("olesql_getstring(\"tiitm001.citg\",\" \")"); i = b.ParseExecFunction("ottdllsql_query", s2); // Get string
Debug.WriteLine("funccall={0} rv={1} Error={2}", b.FunctionCall.Remove(b.FunctionCall.IndexOfAny(new char[] { '\0' }), 1), b.ReturnValue, b.Error);
i = b.ParseExecFunction("ottdllsql_query", sf); // fetch nexyt
}
Debug.WriteLine("wait...");
Debug.WriteLine(b.Error);
Debug.WriteLine(b.ReturnValue);
b.Quit();
Debug.WriteLine("hello");
b = null;
}
#endregion
public string PutField(string session, KeyValuePair<string, Object> kvp)
{
string sParams = string.Format("stpapi.put.field(\"{0}\",\"{1}\",\"{2}\")", session, kvp.Key, kvp.Value);
b.DllName = "ottstpapihand";
b.ParseExecFunction("ottstpapihand", sParams);
string[] rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return rv[3];
}
public string GetField(string session, KeyValuePair<string, object> kvp)
{
string sParams = string.Format("stpapi.get.field(\"{0}\",\"{1}\",\"{2}\")", session, kvp.Key, kvp.Value);
b.ParseExecFunction("ottstpapihand", sParams);
string rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries)[3];
return rv;
}
public string SetEnum(string session, KeyValuePair<string, object> kvp)
{
string sParams = string.Format("stpapi.enum.answer(\"{0}\",\"{1}\",{2})", session, kvp.Key, kvp.Value);
b.ParseExecFunction("ottstpapihand", sParams);
string rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"', ')' }, StringSplitOptions.RemoveEmptyEntries)[3];
return rv;
}
public string InsertSession(string s)
{
string err = " ";
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.insert(\"{0}\",1,\"{1}\")", s, err));
string[] x = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return x[2];
}
public string ContinueProcess(string session)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.continue.process(\"{0}\",\"{1}\")", session, " "));
string[] x = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return x[2];
}
public string Find(string session)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.find(\"{0}\",\"{1}\")", session, ""));
return b.ReturnValue;
}
public void PrintReport(string session)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.print.report(\"{0}\", \"{1}\")", session, " "));
}
public void SetReport(string session, string reportName, string device)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.set.report(\"{0}\",\"{1}\",\"{2}\" , \"{3}\" )", session, reportName, device, " "));
}
public string GetMessageCode(string session)
{
string x = " ";
string sParams = string.Format("stpapi.get.mess.code(\"{0}\",\"{1}\")", session, x);
b.ParseExecFunction("ottstpapihand", sParams);
string[] rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return rv[2];
}
#region btnExecDll click
private void btnExecDll_Click(object sender, EventArgs e)
{
#region kill running bw.exe processes
Process[] p = Process.GetProcessesByName("bw");
foreach (Process x in p)
{
Debug.WriteLine(x.CloseMainWindow());
x.Kill();
}
#endregion
b = new myBw.Baan4();
string sSession = "tdsls4401m000";
Debug.WriteLine("SetEnum", SetEnum(sSession, new KeyValuePair<string, object>("selection", 1)));
Debug.WriteLine("Putfield orno.f", PutField(sSession, new KeyValuePair<string, object>("orno.f", "141527")));
Debug.WriteLine("Putfield comp.f", PutField(sSession, new KeyValuePair<string, object>("comp.f", "000")));
Debug.WriteLine("Putfield comp.t", PutField(sSession, new KeyValuePair<string, object>("comp.t", "999")));
Debug.WriteLine("Putfield orno.t", PutField(sSession, new KeyValuePair<string, object>("orno.t", "141527")));
Debug.WriteLine("SetEnum prnt.discount", SetEnum(sSession, new KeyValuePair<string, object>("prnt.discount", 2)));
Debug.WriteLine("Putfield prnt.sellpr", PutField(sSession, new KeyValuePair<string, object>("prnt.sellpr", 2)));
Debug.WriteLine("Putfield printed", PutField(sSession, new KeyValuePair<string, object>("printed", 1)));
Debug.WriteLine("Putfield quant.to.print", PutField(sSession, new KeyValuePair<string, object>("quan.to.print", 1)));
Debug.WriteLine("Putfield prnt.options", PutField(sSession, new KeyValuePair<string, object>("prnt.options", 2)));
//Debug.WriteLine("SetEnum prnt.spellr", SetEnum(sSession, new KeyValuePair<string, object>("prnt.sellpr", 2)));
//Debug.WriteLine("SetEnum printed", SetEnum(sSession, new KeyValuePair<string, object>("printed", 1)));
//Debug.WriteLine("SetEnum quan.to.prin", SetEnum(sSession, new KeyValuePair<string, object>("quan.to.print", 1)));
//Debug.WriteLine("SetEnum prnt.options", SetEnum(sSession, new KeyValuePair<string, object>("prnt.options", 2)));
Debug.WriteLine("Putfield num.copies", PutField(sSession, new KeyValuePair<string, object>("num.copies", 1)));
SetReport(sSession, "tdsls440101000", "D66");
Debug.WriteLine(String.Format("InsertSession({0}):{1}",sSession, InsertSession(sSession)));
// PrintReport(sSession);
Debug.WriteLine(String.Format("FindSession({0}), Found={1}", sSession, Find(sSession) == "1" ? "ok.Found" : "***Error notfound***"));
Debug.WriteLine(String.Format("CountinueProces({0}):{1}",sSession, ContinueProcess(sSession)));
b.Quit(); b = null;
}
#endregion
}
}
Any help appreciated
Anthony
BaaN throws "Can't read session or object (tdsls44010002)"
The object BaaN is complaining about really do not exist.. I guess it is inferring this from request submitted.
also note the code is throwing 'Process is gone'
When I run the code I get this debugger output
1: SetEnum
141527: Putfield orno.f
000: Putfield comp.f
999: Putfield comp.t
141527: Putfield orno.t
2: SetEnum prnt.discount
2: Putfield prnt.sellpr
1: Putfield printed
1: Putfield quant.to.print
2: Putfield prnt.options
1: Putfield num.copies
InsertSession(tdsls4401m000):1
FindSession(tdsls4401m000), Found=ok.Found
CountinueProces(tdsls4401m000):Process is gone
#region button1 click
private void button1_Click(object sender, EventArgs e)
{
// Reference myBW is tlibimp from Baan 4 bw type lib
// 2010 Dec 3rd a.p
// myBw.IDispatchBaan4 b = new myBw.Baan4();
b.Timeout = 1;
string qry = "select tiitm001.citg from tiitm001 group by tiitm001.citg order by tiitm001.citg";
string sf = string.Format("olesql_parse(\"{0}\")", qry);
int i = b.ParseExecFunction("ottdllsql_query", sf);
Debug.WriteLine(sf);
Debug.WriteLine(i);
int handle = int.Parse(b.ReturnValue);
string s2 = "";
sf = string.Format("olesql_fetch({0})", handle); b.ParseExecFunction("ottdllsql_query", sf);// fetch the first one
while (b.ReturnValue != "110")
{
s2 = string.Format("olesql_getstring(\"tiitm001.citg\",\" \")"); i = b.ParseExecFunction("ottdllsql_query", s2); // Get string
Debug.WriteLine("funccall={0} rv={1} Error={2}", b.FunctionCall.Remove(b.FunctionCall.IndexOfAny(new char[] { '\0' }), 1), b.ReturnValue, b.Error);
i = b.ParseExecFunction("ottdllsql_query", sf); // fetch nexyt
}
Debug.WriteLine("wait...");
Debug.WriteLine(b.Error);
Debug.WriteLine(b.ReturnValue);
b.Quit();
Debug.WriteLine("hello");
b = null;
}
#endregion
public string PutField(string session, KeyValuePair<string, Object> kvp)
{
string sParams = string.Format("stpapi.put.field(\"{0}\",\"{1}\",\"{2}\")", session, kvp.Key, kvp.Value);
b.DllName = "ottstpapihand";
b.ParseExecFunction("ottstpapihand", sParams);
string[] rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return rv[3];
}
public string GetField(string session, KeyValuePair<string, object> kvp)
{
string sParams = string.Format("stpapi.get.field(\"{0}\",\"{1}\",\"{2}\")", session, kvp.Key, kvp.Value);
b.ParseExecFunction("ottstpapihand", sParams);
string rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries)[3];
return rv;
}
public string SetEnum(string session, KeyValuePair<string, object> kvp)
{
string sParams = string.Format("stpapi.enum.answer(\"{0}\",\"{1}\",{2})", session, kvp.Key, kvp.Value);
b.ParseExecFunction("ottstpapihand", sParams);
string rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"', ')' }, StringSplitOptions.RemoveEmptyEntries)[3];
return rv;
}
public string InsertSession(string s)
{
string err = " ";
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.insert(\"{0}\",1,\"{1}\")", s, err));
string[] x = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return x[2];
}
public string ContinueProcess(string session)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.continue.process(\"{0}\",\"{1}\")", session, " "));
string[] x = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return x[2];
}
public string Find(string session)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.find(\"{0}\",\"{1}\")", session, ""));
return b.ReturnValue;
}
public void PrintReport(string session)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.print.report(\"{0}\", \"{1}\")", session, " "));
}
public void SetReport(string session, string reportName, string device)
{
b.ParseExecFunction("ottstpapihand", String.Format("stpapi.set.report(\"{0}\",\"{1}\",\"{2}\" , \"{3}\" )", session, reportName, device, " "));
}
public string GetMessageCode(string session)
{
string x = " ";
string sParams = string.Format("stpapi.get.mess.code(\"{0}\",\"{1}\")", session, x);
b.ParseExecFunction("ottstpapihand", sParams);
string[] rv = b.FunctionCall.Split(new char[] { ',', '\0', '\"' }, StringSplitOptions.RemoveEmptyEntries);
return rv[2];
}
#region btnExecDll click
private void btnExecDll_Click(object sender, EventArgs e)
{
#region kill running bw.exe processes
Process[] p = Process.GetProcessesByName("bw");
foreach (Process x in p)
{
Debug.WriteLine(x.CloseMainWindow());
x.Kill();
}
#endregion
b = new myBw.Baan4();
string sSession = "tdsls4401m000";
Debug.WriteLine("SetEnum", SetEnum(sSession, new KeyValuePair<string, object>("selection", 1)));
Debug.WriteLine("Putfield orno.f", PutField(sSession, new KeyValuePair<string, object>("orno.f", "141527")));
Debug.WriteLine("Putfield comp.f", PutField(sSession, new KeyValuePair<string, object>("comp.f", "000")));
Debug.WriteLine("Putfield comp.t", PutField(sSession, new KeyValuePair<string, object>("comp.t", "999")));
Debug.WriteLine("Putfield orno.t", PutField(sSession, new KeyValuePair<string, object>("orno.t", "141527")));
Debug.WriteLine("SetEnum prnt.discount", SetEnum(sSession, new KeyValuePair<string, object>("prnt.discount", 2)));
Debug.WriteLine("Putfield prnt.sellpr", PutField(sSession, new KeyValuePair<string, object>("prnt.sellpr", 2)));
Debug.WriteLine("Putfield printed", PutField(sSession, new KeyValuePair<string, object>("printed", 1)));
Debug.WriteLine("Putfield quant.to.print", PutField(sSession, new KeyValuePair<string, object>("quan.to.print", 1)));
Debug.WriteLine("Putfield prnt.options", PutField(sSession, new KeyValuePair<string, object>("prnt.options", 2)));
//Debug.WriteLine("SetEnum prnt.spellr", SetEnum(sSession, new KeyValuePair<string, object>("prnt.sellpr", 2)));
//Debug.WriteLine("SetEnum printed", SetEnum(sSession, new KeyValuePair<string, object>("printed", 1)));
//Debug.WriteLine("SetEnum quan.to.prin", SetEnum(sSession, new KeyValuePair<string, object>("quan.to.print", 1)));
//Debug.WriteLine("SetEnum prnt.options", SetEnum(sSession, new KeyValuePair<string, object>("prnt.options", 2)));
Debug.WriteLine("Putfield num.copies", PutField(sSession, new KeyValuePair<string, object>("num.copies", 1)));
SetReport(sSession, "tdsls440101000", "D66");
Debug.WriteLine(String.Format("InsertSession({0}):{1}",sSession, InsertSession(sSession)));
// PrintReport(sSession);
Debug.WriteLine(String.Format("FindSession({0}), Found={1}", sSession, Find(sSession) == "1" ? "ok.Found" : "***Error notfound***"));
Debug.WriteLine(String.Format("CountinueProces({0}):{1}",sSession, ContinueProcess(sSession)));
b.Quit(); b = null;
}
#endregion
}
}
Any help appreciated
Anthony