20. Oktober 2006 16:01
20. Oktober 2006 19:00
20. Oktober 2006 19:50
21. Oktober 2006 10:08
int TableRef = 0;
int Record = 0;
int Field_No = 0;
object PEBE_OBJ;
int TableNo = _cf.TableNo("PEBE Import Lines");
bool TabOpen = _cf.OpenTable(ref TableRef, TableNo);
_cf.AllowRecordNotFound();
_cf.BWT();//Beginn Transaktion
Record = _cf.AllocRec(TableRef);
_cf.InitRec(TableRef, Record);
// 1 Journal Template Name Code 10 Fix "MUSTER"
Field_No = _cf.FieldNo(TableRef, "Journal Template Name");
string Line_No = "MUSTER";
PEBE_OBJ = Line_No.Trim();
_cf.AssignField(TableRef, Record, Field_No, ref PEBE_OBJ);
// DIESER Befehl stürzt ab!!
//
bool insert = _cf.InsertRec(TableRef, Record);
if (!insert)
{
throw (new Exception("Fehler beim Einfügen " + _cf.LastError().ToString()));
}
// Finale
_cf.EWT(); // End of Transaktion
_cf.FreeRec(Record);
_cf.CloseTable(TableRef);
22. Oktober 2006 12:01
NavisionCode navCode = NavisionCode.Parse("MUSTER");
_cf.AssignField(TableRef, Record, Field_No, ref navCode); // Variante 1
_cf.AssignField(TableRef, Record, Field_No, ref navCode.GetBytes()); // Variante 2
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Navision.CFront;
namespace NavCfrontTest
{
class Program
{
static void Main(string[] args)
{
CFrontDotNet cfront;
string serverName;
string databaseName;
string companyName;
serverName = "Server";
databaseName = "Database";
companyName = "Company";
cfront = new CFrontDotNet(NavisionDriverType.Sql);
// Verbinden mit Standardeinstellungen: 32MB cache, NT auth
cfront.ConnectServerAndOpenDatabase(
serverName, NavisionNetType.SqlDefault, databaseName,
32786, true, true, "", "");
cfront.OpenCompany(companyName);
// RecordNotFound sollte keine Exception werfen, tut er aber doch...
cfront.Allow(NavisionAllowedError.RecordNotFound);
int pictureTableNo = cfront.TableNo("Picture");
int pictureTableRef = cfront.OpenTable(pictureTableNo);
int pictureRecordRef = cfront.AllocRecord(pictureTableRef);
int noFieldNo = cfront.FieldNo(pictureTableRef, "No.");
bool recordFound = false;
// Filtern und Datensatz suchen
try
{
cfront.SetFilter(pictureTableRef, noFieldNo, "TESCHT");
recordFound = cfront.FindFirstRecord(pictureTableRef, pictureRecordRef);
}
catch (CFrontException cfrontEx)
{
recordFound = false;
}
bool transactionSuccessful = false;
cfront.BeginWriteTransaction();
// Loeschen wenn gefunden, Insert wenn nicht
if (recordFound == true)
{
transactionSuccessful = cfront.DeleteRecord(pictureTableRef, pictureRecordRef);
}
else
{
int descriptionFieldNo = cfront.FieldNo(pictureTableRef, "Description");
cfront.InitRecord(pictureTableRef, pictureRecordRef);
cfront.StringToField(pictureTableRef, pictureRecordRef, noFieldNo, "TESCHT");
cfront.StringToField(pictureTableRef, pictureRecordRef, descriptionFieldNo, "Tescht Beschreibung");
transactionSuccessful = cfront.InsertRecord(pictureTableRef, pictureRecordRef);
}
// Je nachdem ob alles glatt lief oder nicht, die Transaktion beenden oder abbrechen
if (transactionSuccessful == false)
{
cfront.AbortWriteTransaction();
}
else
{
cfront.EndWriteTransaction();
}
// Aufraeumen
cfront.FreeRecord(pictureRecordRef);
cfront.CloseTable(pictureTableRef);
cfront.CloseCompany();
cfront.CloseDatabase();
cfront.DisconnectServer();
}
}
}