How to use SDK's PriGrelha in edit mode?
The SDK is a library of business standards and controls for the PRIMAVERA environment, that offers a set of components in order to offer the third-party applications the same level of features and user experience as the ERP. When developing business applications, grids are often used to insert data that. Depending on the use context, can require the implementation of several features' existent in the ERP, such as, drilldown, printing, column configuration, etc. In these cases, it is recommended to use the grid provided in the SDK, considering that it allows to refrain the development teams from the referred implementations and allow them to focus on the client's business. In the next steps, we describe how to configure the grit in the data insertion context. Step 1 - Initializations First, it is necessary to initialize the SDK context. For more information, please see the article "How to use the PRIMAVERA ERP SDK controls?." To use the PriGrelha in consultation mode, for example in an exploration, we suggest viewing the article "How to use the PRIGRELHA from the PRIMAVERA ERP SDK?" The initialization process in edit mode is similar and the differences between the PriGrelha in edit and consultation mode will be explained later. Step 2 - Column and properties definition When started in consultation mode, the grid does not present the same behavior as in the editing mode, so you should consider a few properties when defining the columns. Similarly, you should pay additional attention to the definition of the column type, considering that there is a dependency relation between the column type and the data inserted in the cells. You should also consider a few grid properties, namely, the property that defines the editing mode. Columns properties Column Types Grid properties Cells of the ComboBox Type The cells of the ComboBox require a special handling because they need to load the items to be shown in the combo. Thus, when defining the columns in the AddColKey you should indicate the items through the ComboValores argument. The following example shows how to load the items "Cliente" (Client), "Fornecedor" (Supplier) and "Outro Terceiro" (Other Third-Party) for the combo, in the column you wish the user to choose the entity type from: To read the selected item value, you should use a normal cell value reading method, and the read value correspond to the selection index. The following example shows the reading of the value and its conversion to the known entity type: To assign a value to a cell of this type, you should use the native grid method, and this value should be from the combobox item itself: Step 3 - Reading and writing values Method to read the value in a cell: Method to write a value in a cell: Step 4 - Invoke the lists in the rows using F4 The following example shows how the item list is presented when you wish to select a specific item. You should invoke a list from the KeyDown event from the grid. When a list is invoked, the AbreLista receives the form, a grid, column and current row as an argument. Thus, when invoking the list using F4 key, the system records the item selected by the user in the previous window field. The value in inserted in the grid and, if it exists, the method F4RowFileds is automatically invoked. In this method, you should insert the necessary code to execute when a list item is selected. Step 5 - EditMode Event The EditMode event is activated when the user is in edit mode in a cell, as well as when he finishes it. You should execute the same procedure as F4, that is, validate the inserted value, fill in other related data, etc. Step 6 - Other methods and grid events to consider Methods Events In here you can find a complete example of how to use the PriGrelha in edit mode.Configure grids
Bloqueada Indicates if the cells are locked for editing. ValorMinimo Minimum value each column cell can assume (applicable to numeric cells). ValorMaximo Maximum value each column cell can assume (applicable to numeric cells). CasasDecimais No. of decimal places. EditLen Cell writing size (applicable to text cells). ComboValores Values for the items of the cell type "combobox" (explained later). CellTypeDate For cells that accepted values referring to dates. CellTypeEdit For cells that accepted free text. CellTypeStaticText For cells that show free, but non-editable text. CellTypeInteger For cells that accepted integer numeric values. CellTypeFloat For cells that accept decimal numeric values. CellTypeComboBox Cells formatted with combobox. CellTypeCheckBox Cells formatted with checkbox. PermiteEdicao Indicates if the grid is in editing mode (true). PermiteAgrupamentosUser In editing mode, there are no groupings (false). PermiteDataFill In editing mode, the grid loading is never performed by DataBind (false). PermiteFiltros In editing mode, the filters are also not active (false). priGrelha1.AddColKey(colTipoEntidade, FpCellType.CellTypeComboBox, "Tipo Ent.", 8, strComboValores: DaValoresComboTipoEntidade());
private string DaValoresComboTipoEntidade()
{
return
"Clientet" +
"Fornecedort" +
"Outro Terceiro";
}
private string GetTipoEntidadeFromGrid(int row)
{
string result = "C";
switch (PSO.Utils.FInt(priGrelha1.GetGRID_GetValorCelula(row, colTipoEntidade)))
{
case 1:
result = "F";
break;
case 2:
result = "O";
break;
default:
break;
}
return result;
}
private void SetValorComboboxGrelha(string col, int row, string value)
{
//Updates the combo value in the grid.
priGrelha1.Grelha.SetText(priGrelha1.Cols.GetEdita(col).Number, row, value);
}
priGrelha1.GetGRID_GetValorCelula(row, colNomeColuna);
priGrelha1.SetGRID_SetValorCelula(row, colNomeColuna, "Valor");
private void priGrelha1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
try
{
if (e.KeyCode == Keys.F4 && !e.Control && !e.Shift)
{
TrataF4Linhas(priGrelha1.Grelha.ActiveCol, priGrelha1.Grelha.ActiveRow);
}
return;
}
catch (Exception ex)
{
PSO.Dialogos.MostraErroSimples("Erro ao executar a operação!", StdPlatBS100.StdBSTipos.IconId.PRI_Critico, ex.Message);
}
}
private void TrataF4Linhas(int col, int row)
{
// Items
if (col == priGrelha1.Cols.GetEdita(colArtigo).Number)
{
PSO.AbreLista(1, ConstantesPrimavera100.Categorias.Artigo, "Artigo", this, priGrelha1.Grelha, "mnuTabArtigo", row, col, false, "(ArtigoAnulado = 0)");
}
}
public void F4RowFields(string Categoria, string NomeCampo, dynamic Valor)
{
try
{
if (Categoria == ConstantesPrimavera100.Categorias.Artigo)
{
TrataColuna_Artigo(priGrelha1.Grelha.ActiveRow);
}
}
catch (Exception ex)
{
PSO.Dialogos.MostraErro("Erro ao carregar o registo.", StdPlatBS100.StdBSTipos.IconId.PRI_Exclama, ex.Message, ex);
}
}
private void TrataColuna_Artigo(int row)
{
try
{
string artigo = PSO.Utils.FStr(priGrelha1.GetGRID_GetValorCelula(row, colArtigo));
if (!string.IsNullOrWhiteSpace(artigo))
{
if (BSO.Base.Artigos.Existe(artigo))
{
BasBEArtigo beArtigo = BSO.Base.Artigos.Consulta(artigo);
priGrelha1.SetGRID_SetValorCelula(row, colArtigo, beArtigo.Artigo.ToUpper());
priGrelha1.SetGRID_SetValorCelula(row, colDescArtigo, beArtigo.Descricao.ToUpper());
}
else
{
throw new Exception("Artigo inexistente!");
}
}
}
catch (Exception ex)
{
priGrelha1.SetGRID_SetValorCelula(row, priGrelha1.Cols.GetEdita(colArtigo).ColKey, string.Empty);
priGrelha1.SetGRID_SetValorCelula(row, priGrelha1.Cols.GetEdita(colDescArtigo).ColKey, string.Empty);
throw ex;
}
}
private void priGrelha1_EditMode(object Sender, PriGrelha.EditModeEventArgs e)
{
try
{
if ((e.Mode == 0) && (e.ChangeMade))
{
TrataColuna(e.Col, e.Row);
}
}
catch (Exception ex)
{
PSO.Dialogos.MostraErroSimples("Erro ao executar a operação!", StdPlatBS100.StdBSTipos.IconId.PRI_Critico, ex.Message);
}
}
private void TrataColuna(int col, int row)
{
if ((row > priGrelha1.Grelha.DataRowCnt) || row == 0)
{
return;
}
if (col == priGrelha1.Cols.GetEdita(colArtigo).Number)
{
TrataColuna_Artigo(row);
}
}
InsereLinhas Inserts n rows from the specified position. RemoveLinhas Removes n rows from the specified position. AdicionaLinhasBrancoGrelhaEdicao Adds 50 rows to the existent rows so that they are editable. FormataLinhaEdicao Formats all one row columns for editing. GRID_InsereLinhaEdicao Inserts a row for editing. GRID_RemoveLinhaEdicao Removes a row for editing. Grid_BloqueiaColuna Locks/unlocks one or more cells. Grid_BloqueiaLinha Locks/unlocks the cells for one or more rows. Grid_CelulaBloqueada Indicates if the cell is locked. Grid_EscondeLinha Hides/shows one or more rows. Grid_LimpaParteDaGrelha Clears one or more cells. Grid_SetActiveCell Positions the mouse cursor on a grid cell. PosicionaCelulaAnterior Positions the mouse cursor in the previous cell. PosicionaCelulaSeguinte Positions the mouse cursor in the following cell. AntesInserirLinha Occurs before GRID_InsereLinhaEdicao() AntesRemoverLinha Occurs before GRID_RemoveLinhaEdicao() LinhaInserida Occurs after GRID_InsereLinhaEdicao() LinhaRemovida Occurs after GRID_RemoveLinhaEdicao()
login para deixar a sua opinião.