Friday 27 June 2008

Updating a customer's delivery address

This is quite a simple piece of code, but it was asked for by one of our development community. Basically how to update a customer's delivery address from code, so here it is:

Private Sub btnUpdateDeliveryAddress_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdateDeliveryAddress.Click
Dim SalesRecord As SageDataObject50.SalesRecord = DirectCast(ws50.CreateObject("SalesRecord"), SageDataObject50.SalesRecord)
SalesRecord.MoveFirst()
SalesRecord.Edit()
SalesRecord.Fields.Item("DEL_ADDRESS_1").Value = "10 William Drive"
SalesRecord.Fields.Item("DEL_ADDRESS_2").Value = "Wallaceville"
SalesRecord.Fields.Item("DEL_ADDRESS_3").Value = "co. Durham"
SalesRecord.Fields.Item("DEL_ADDRESS_4").Value = "England"
SalesRecord.Fields.Item("DEL_ADDRESS_5").Value = "NT48 9LH"
SalesRecord.Update()
End Sub

Wednesday 4 June 2008

Displaying the IFields Collection

This handy utility was submitted by one of our users, to display the list of fields available within an InvoiceItem. The code could easily be adapted for any of the objects within Sage.

// This class is only to display the field information in a DataGrid or GridView
private class FieldNameInfo
{
private string _name;
private string _desc;
private string _typ;
private string _len;
public FieldNameInfo(string Name, string Desc, string Typ, string Len)
{
_name = Name;
_desc = Desc;
_typ = Typ;
_len = Len;
}
public string Name
{
get { return _name; }
}
public string Description
{
get { return _desc; }
}
public string Lenth
{
get { return _len; }
}
public string Typ
{
get { return _typ; }
}
}
private void checkFields()
{
lblTable.Text = "Invoice Item";
ArrayList listFields = new ArrayList();
sdo120= new SageDataObject120.SageDataObjects();
ws120 = sdo120.GetWorkSpace();
try
{
if ( ws120.Connect(ConfigurationSettings.AppSettings["SagePath"], ConfigurationSettings.AppSettings["SageUser"], ConfigurationSettings.AppSettings["SagePassword"], "ChkFields") )
{
SageDataObject120.SopItem myRec = (SageDataObject120.SopItem)ws120.CreateObject("InvoiceItem");
myRec.MoveFirst();
SageDataObject120.IFields myFields = myRec.Fields;
foreach (SageDataObject120.IField myFld in myFields)
{
FieldNameInfo fni = new FieldNameInfo(myFld.Name.ToString(), myFld.Description.ToString(), myFld.Type.ToString(), myFld.Length.ToString());
listFields.Add(fni);

}
}
}
catch(Exception ex)
{
}
finally
{
ws120.Disconnect();
}
listFieldsId.DataSource = listFields;
listFieldsId.DataBind();
}