Loading data in Matrix

Jose Ribeiro

Hi


 


I am struggling to get a matrix to load data. I have tried using the SystemDatasource as well as Datatable. Any help will be appreciated!


 


Sample code:


 


var frm = Form.CreateNewForm("TESTFORM", "TESTFORM" + SwissAddonFramework.Utils.UniqueStringGenerator.Next());

            frm.Visible = false;

 

            frm.Value = "Form title";

            frm.Width = 500;

            frm.Height = 500;

            frm.Left = 500;

            frm.Top = 150;

            

            var exDS = SystemDatasource.CreateNew();

            exDS.UniqueID = "OCRD";

            frm.AddSystemDatasource(exDS);

            

            //var myDt = DataTable.CreateNew("OCRD");

            //myDt.ExecuteQuery("SELECT CardCode, CardName FROM OCRD");

            //frm.AddDataTable(myDt);

 

            Matrix mtx = Matrix.CreateNew("mtx");

            mtx.Width = 350;

            mtx.Height = 350;

 

            MatrixColumn mtxHeaderCol;

            mtxHeaderCol = MatrixColumn.CreateNew("#");

            mtxHeaderCol.Type = MatrixColumn.MatrixItemType.TextEdit;

            mtxHeaderCol.Width = 40;

            mtxHeaderCol.Value = "#";

            mtx.Columns.Add(mtxHeaderCol);

 

            MatrixColumn mtxCodeCol;

            mtxCodeCol = MatrixColumn.CreateNew("CodeCol");

            mtxCodeCol.Type = MatrixColumn.MatrixItemType.TextEdit;

            mtxCodeCol.Width = 100;

            mtxCodeCol.Value = "Code";

            mtxCodeCol.Editable = true;

            mtxCodeCol.DataBind.SetBind(true, "CardCode", "OCRD");

            mtx.Columns.Add(mtxCodeCol);

 

            MatrixColumn mtxNameCol;

            mtxNameCol = MatrixColumn.CreateNew("NameCol");

            mtxNameCol.Type = MatrixColumn.MatrixItemType.TextEdit;

            mtxNameCol.Width = 150;

            mtxNameCol.Value = "Name";

            mtxNameCol.DataBind.SetBind(true, "CardName", "OCRD");

            mtx.Columns.Add(mtxNameCol);

            

            frm.AddItem(mtx);

 

            var btnOk = Button.CreateNew("1");

            btnOk.Top = frm.Height - (btnOk.Height * 3 + 5);

            btnOk.Left = 5;

            btnOk.Value = "OK";

            frm.AddItem(btnOk);

 

            var btnCancel = Button.CreateNew("2");

            btnCancel.Top = frm.Height - (btnCancel.Height * 3 + 5);

            btnCancel.Left = btnOk.Width + 10;

            btnCancel.Value = "Cancel";

            frm.AddItem(btnCancel);

 

            frm.DefButton = "1"; //OK button

            frm.Load();

            

            frm.Visible = true;

            mtx.LoadFromDataSource();

Jose Ribeiro

Can anyone post a sample using a matrix to load data?? I am in need of urgent assistance...


 


I believe the problem is with the SystemDataSource.


 


If I debug and setup over after the frm.Load() the SystemDataSource has 310 fields, however the Size (Rows) is 1, however the OCRD table has 20 rows. I just cannot get the SystemDataSource to get the data.


Paolo Manfrin

Hi,


by experience we suggest always to use a Grid instead of a Matrix.


In case you would reconsider the Grid as an option for your project I suggest you to use the following code:


 


You can test it creating a new menu rule.



try
{
Form f = Form.CreateNewForm("WK_OPENQ", SwissAddonFramework.Utils.UniqueStringGenerator.Next());
f.Value = "Sales Quotation Selection";
f.Top = f.Height = 600;

Grid g = Grid.CreateNew("G1");
g.Top = 20;
g.Left = 5;
g.Width = 400;
g.Height = 400;

Button btn = Button.CreateNew("BTN1");
btn.Top = g.Top + g.Height + 10;
btn.Left = 5;
btn.Width = 100;
btn.Value = "Generate PDF";

f.AddItem(g);
f.AddItem(btn);

f.Load();
g.ExecuteQuery(@"SELECT 'N' AS [Generate PDF], DocEntry, DocNum, DocDate, CardCode, CardName, DocTotal, DocCur FROM OQUT WHERE DocStatus = 'O'
ORDER BY DocDate DESC");

g.Columns["Generate PDF"].Type = SwissAddonFramework.UI.Components.GridColumn.Types.CheckBox;


SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressedEventHandler buttonPressEvent = null;
buttonPressEvent = delegate(SwissAddonFramework.UI.EventHandling.ItemEvents.ItemPressed btnPress)
{
try
{
for (int rowIndex = 0; rowIndex < g.Rows.Count; rowIndex++)
{

string generatePDF = g.GetValue("Generate PDF", rowIndex);
/*
if (generatePDF == "Y")
{
string docNum = g.GetValue("DocNum", rowIndex);
StatusBar.WriteSucess("Generating PDF for Offer nr. " + docNum);
string pdfPath = ExtCode_GeneratePdf(docNum);

// generate an activity for the generated PDF
SAPbobsCOM.CompanyService oCmpSrv = SwissAddonFramework.B1Connector.GetB1Connector().Company.GetCompanyService();
SAPbobsCOM.ActivitiesService oActSrv = (SAPbobsCOM.ActivitiesService) oCmpSrv.GetBusinessService(SAPbobsCOM.ServiceTypes.ActivitiesService);
SAPbobsCOM.Activity oAct = (SAPbobsCOM.Activity) oActSrv.GetDataInterface(SAPbobsCOM.ActivitiesServiceDataInterfaces.asActivity);

//SAPbobsCOM.ActivityParams oParam = null;
oAct.CardCode = g.GetValue("CardCode", rowIndex);
oAct.ActivityDate = DateTime.Now;
oAct.Activity = SAPbobsCOM.BoActivities.cn_Other;
oAct.Notes = "Quotation ";// +pdfPath;
oAct.DocEntry = g.GetValue("DocEntry", rowIndex);
oAct.DocType = "23"; // 23 -> Sales Quotation
oActSrv.AddActivity(oAct);
//long actCode = oParam.ActivityCode;
}*/
}

}
catch (Exception innerException)
{
StatusBar.WriteError(innerException.Message);
}
};

btn.AddHandler_ItemPressed(SwissAddonFramework.UI.Components.ModeComponent.FormModes.ALL, null, buttonPressEvent);

g.Columns["DocEntry"].Editable = false;
g.Columns["DocNum"].Editable = false;
g.Columns["DocDate"].Editable = false;
g.Columns["CardCode"].Editable = false;
g.Columns["CardName"].Editable = false;
g.Columns["DocTotal"].Editable = false;
g.Columns["DocCur"].Editable = false;
((TextEditGridColumn) g.Columns["DocEntry"].SpecificGridColumn).LinkObjectType = "23";
}
catch (Exception ex)
{
StatusBar.WriteError(pVal.RuleInfo.RuleName + " : " + ex.Message);
}
************

hth


paolo


dhaval

Hi Paolo,


 


I was facing the same issue, as per suggestion, I have used grid instead of matrix, have load data from one table successfully,


Which are the way to save modifications done by user on the screen/grid to final database table?


 


Best Regards,


Dhaval


Anders Olsson

Hi Dhaval,

 

You would use the DI objects to save the data, in your case the BusinessPartners object.

If you don't have many rows, iterate through the grid. For each row get the object, set properties according to grid data and update.

In case you have a lot of rows the fastest method is to attach a handler to the Validate event of the grid and keep note of changed rows.

Then when the user presses update you simply process those rows.

 

Example of using the BusinessPartners object:



SAPbobsCOM.Company company = SwissAddonFramework.B1Connector.GetB1Connector().Company;
SAPbobsCOM.BusinessPartners bp = (SAPbobsCOM.BusinessPartners)company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
bp.GetByKey("cardcode");
bp.UserFields.Fields.Item("U_UDF").Value = "test";
int err = bp.Update();


Regards,

Anders
0

Comments

0 comments

Please sign in to leave a comment.

Didn't find what you were looking for?

New post