Vous consultez une page technique concernant le logiciel de gestion Mercator. Celle-ci contient des informations spécifiques destinées aux professionnels de Mercator. Souhaitez-vous être redirigés vers des informations plus générales ?


   Ne plus poser cette question

Edition d'un mémo dans les lignes d'un document de gestion commerciale

0000002247     -      10/11/2023

Il peut être mis en place sans programmation :

  • ajouter la colonne tel qu'indiqué ci-dessous,
  • dans les Columns du LinesEditor, ajouter une colonne dont la source est MEMO,
  • dans les ColumnsRules du LinesEditor, ajouter une règle dont Name = MEMO et Editor = Memo ou Html.

 

Le développement documenté ci-dessous est obsolète.


Cet exemple montre comment gérer un mémo dans les lignes d'un document de vente ou d'achat de la gestion commerciale. Il se fait par l'ajout d'une colonne de boutons dans le LinesEditor. Le texte de ce bouton sera :

  • Mémo si le mémo n'est pas vide
  • mémo si le mémo est vide

memo_lines


La colonne MEMO doit être créée dans la base de données :
Pour les ventes :

alter table LIGNES_V add MEMO varchar(MAX) not null default ''

Pour les achats :

alter table LIGNES_A add MEMO varchar(MAX) not null default ''

Cette programmation est construite sur base d'un customizer Billing qui implémente les interface suivantes :

Le code s'établit comme suit :

Zoom
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Windows.Forms;
using MercatorApi;
using MercatorUi;

namespace Billing
{
    public class Customizer : MercatorUi.ICustomizers.IBillingEngineCreated, MercatorUi.ICustomizers.IBillingEngineClosed
    {
        public void BillingEngineCreated(MercatorUi.Engine.Gescom.BillingEngine BillingEngine)
        {
            BillingEngine.BillingFormLoaded += BillingEngine_BillingFormLoaded;
        }

        public void BillingEngineClosed(MercatorUi.Engine.Gescom.BillingEngine BillingEngine)
        {
            BillingEngine.BillingFormLoaded -= BillingEngine_BillingFormLoaded;
        }

        void BillingEngine_BillingFormLoaded(object sender, EventArgs e)
        {
            MercatorUi.Engine.Gescom.BillingEngine billingEngine = (MercatorUi.Engine.Gescom.BillingEngine)sender;
            if (billingEngine.BillingForm.LinesEditor != null)
            {
                MercatorUi.GridPro.DataGridViewHidableButtonXColumn colButtonMemo = new MercatorUi.GridPro.DataGridViewHidableButtonXColumn();
                colButtonMemo.Name = "ButtonMemo";
                colButtonMemo.HeaderText = "";
                colButtonMemo.Width = 50;
                colButtonMemo.BeforeCellPaint += new EventHandler<DevComponents.DotNetBar.Controls.BeforeCellPaintEventArgs>(colButtonMemo_BeforeCellPaint);
                billingEngine.BillingForm.LinesEditor.Grid.Columns.Add(colButtonMemo);
                billingEngine.BillingForm.LinesEditor.Grid.CellSuperClick += new MercatorUi.GridPro.CellSuperClickHandler(Grid_CellSuperClick);
            }
        }

        void colButtonMemo_BeforeCellPaint(object sender, DevComponents.DotNetBar.Controls.BeforeCellPaintEventArgs e)
        {
            if ((e.ColumnIndex > -1) && (e.RowIndex > -1))
            {
                MercatorUi.GridPro.DataGridViewHidableButtonXColumn colButtonMemo = (MercatorUi.GridPro.DataGridViewHidableButtonXColumn)sender;
                DataTable dt = (DataTable)colButtonMemo.DataGridView.DataSource;
                if (dt.Rows[Api.DataGridViewRowToDataTableRowIndex(colButtonMemo.DataGridView.Rows[e.RowIndex])]["memo"].ToString() != "")
                    colButtonMemo.DataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Api.Iif_langue(Globals.Langue, "Merkz.", "Memo", "Memo", "Mémo");
                else
                    colButtonMemo.DataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = Api.Iif_langue(Globals.Langue, "merkz.", "memo", "memo", "mémo");
            }
        }

        void Grid_CellSuperClick(object sender, DataGridViewCellEventArgs e)
        {
            MercatorUi.GridPro.DataGridViewXPro grid = (MercatorUi.GridPro.DataGridViewXPro)sender;
            if ((e.ColumnIndex < 0 || e.RowIndex < 0) || (grid.Columns[e.ColumnIndex].Name != "ButtonMemo"))
                return;

            DataTable dt = (DataTable)grid.DataSource;
            DataRow currentRow = dt.Rows[Api.DataGridViewRowToDataTableRowIndex(grid.Rows[e.RowIndex])];

            string memo = Dialogs.AskMemo(string.Format("Memo ligne {0} ?", e.RowIndex + 1), currentRow["memo"].ToString(), grid.FindForm());
            if (!dt.Columns["memo"].ReadOnly && (memo != null)) // on n'a pas cliqué sur "Annuler"
                currentRow["memo"] = memo.Trim();
        }
    }
}

Si on souhaite effectuer la saisie d'un contenu HTML plutôt qu'un simple mémo, il suffit de remplacer cette ligne

Zoom
string memo = Dialogs.AskMemo(string.Format("Memo ligne {0} ?", e.RowIndex + 1), dt.Rows[e.RowIndex]["memo"].ToString(), grid.FindForm());

par

Zoom
string memo = Dialogs.AskHtml(string.Format("Memo ligne {0} ?", e.RowIndex + 1), dt.Rows[e.RowIndex]["memo"].ToString(), grid.FindForm());