Example for C# and BRIZ
(GUI GP_TERM.LIB)
This sample created only for explanation how to create connection, read the items and work with array of items.For more details see COM Example and other examples . Download solution.
For this example it is nessesary:
1 Start BRIZ
2 Login into account with GP_TERM.LIB
3 Start any program based on GP_TERM.LIB (PE, SPE, PEHELP, ADM.PRG, Funprg, Test.vb,
example_com ...)
4 Start example or dedug example from VS2005
Every xxx_Click:
1 create object
2 Retrive data from server
3 Release object
In real, project creates object once.
private void button_lf_Click(object sender, EventArgs e)
{
String str1 = "BRIZ";
GP_Term.Connector gpConn1 = new GP_Term.Connector();
GP_Term.Document gpDoc1;
object obj1 = null;
gpDoc1 = (GP_Term.Document)gpConn1.GetTerminal(ref str1);
gpConn1 = null;
if (gpDoc1 != null)
{
gpDoc1.ExecTCL("select md");
while (gpDoc1.GetTCLResult(ref obj1) < 0) ;
gpDoc1.GetActiveList(ref obj1) ;
gpDoc1 = null;
}
if (obj1 != null)
{
int i;
object[] obj2 = (object[])obj1;
listBox_lf.Items.Clear();
for (i = 0; i < obj2.GetLength(0); i++) listBox_lf.Items.Add(obj2[i]);
}
}
private void button_lmd_Click(object sender, EventArgs e)
{
String strConnect = "BRIZ";
GP_Term.Connector gpConn = new GP_Term.Connector();
GP_Term.Document gpDoc;
char[] arrDelims = char.ConvertFromUtf32(1).ToCharArray();
object objKeys = null, objRecs = null;
int i, iFileHandle;
object[] arrRecs, arrKeys, arrRec;
ListViewItem lviTmp;
gpDoc = (GP_Term.Document)gpConn.GetTerminal(ref strConnect);
gpConn = null;
if (gpDoc != null)
{
iFileHandle = gpDoc.OpenPICKFile("md");
if (iFileHandle >= 0)
{
gpDoc.ReadKFromPICKEx(iFileHandle, -1, ref objRecs, ref objKeys);
arrRecs = (object[])objRecs; arrKeys = (object[])objKeys;
for (i = 0; i < arrRecs.GetLength(0); i++)
{
lviTmp = listView_md.Items.Add(arrKeys[i].ToString());
arrRec = arrRecs[i].ToString().Split(arrDelims);
lviTmp.SubItems.Add(arrRec[0].ToString());
if (arrRec.GetLength(0) > 1) lviTmp.SubItems.Add(arrRec[1].ToString());
if (arrRec.GetLength(0) > 2) lviTmp.SubItems.Add(arrRec[2].ToString());
if (arrRec.GetLength(0) > 3) lviTmp.SubItems.Add(arrRec[3].ToString());
}
gpDoc.ClosePICKFile(iFileHandle);
}
gpDoc = null;
}
}
String str1 = "BRIZ";
// default registration name. You should use unique name
(for example ApplicationName:PortNumber)
GP_Term.Connector gpConn1 = new
GP_Term.Connector();
// declare and create Connector object
GP_Term.Document gpDoc1;
// declare Provider object
object obj1 = null;
// declare object for array of items
gpDoc1 = (GP_Term.Document)gpConn1.GetTerminal(ref
str1);
// Initialize provider object
gpConn1 = null;
// release connector object
if (gpDoc1 != null)
// validate Provider object
{
..................................
..................................
}
gpDoc1 = null;
1 Button "List files" (Actually, read items Id of entire md )
gpDoc1.ExecTCL("select md");
// Execute TCL command
while (gpDoc1.GetActiveList(ref
obj1) < 0) ;
// Waiting the result of TCL command
object[] obj2 = (object[])obj1;
// Declare and initialize array of items receved
into obj1
listBox_lf.Items.Clear();
for (i = 0; i < obj2.GetLength(0);
i++) listBox_lf.Items.Add(obj2[i]);
// Fill ListBox
2 Button "list MD" (Actually, only Item ID and Attr. 1,2,3)
iFileHandle = gpDoc.OpenPICKFile("md");
// Open server file "MD"
if (iFileHandle >= 0)
// Check result
{
gpDoc.ReadKFromPICKEx(iFileHandle,
-1, ref objRecs, ref objKeys);
//Read entire file (Items and keys). The best way
is read file by items groups
arrRecs
= (object[])objRecs; arrKeys = (object[])objKeys;
// Declare and initialize array of items and keys
// It is possible convert array to araay of arrays
for (i = 0;
i < arrRecs.GetLength(0); i++)
{
lviTmp = listView_md.Items.Add(arrKeys[i].ToString());
arrRec = arrRecs[i].ToString().Split(arrDelims);
lviTmp.SubItems.Add(arrRec[0].ToString());
if (arrRec.GetLength(0) > 1) lviTmp.SubItems.Add(arrRec[1].ToString());
if (arrRec.GetLength(0) > 2) lviTmp.SubItems.Add(arrRec[2].ToString());
if (arrRec.GetLength(0) > 3) lviTmp.SubItems.Add(arrRec[3].ToString());
}
gpDoc.ClosePICKFile(iFileHandle);
// Close server file
}
See also: COM in BRIZ.CHM documentation.
Actually, it is very easy.
All remarks and offers direct to support service support@infotools.ru .