Nadawanie sygnatur dla dokumentów

< Cofnij

NOWY MECHANIZM (AKTUALNY):

Mechanizm nadawania sygnatury znajduje się w aplikacji. Służy do tego encja Sygnatura (znajdziemy ją w Ustawienia\Konfiguracje dokumentów).

W przypadku nieokreślenia sygnatury dla danego typu dokumentu, sygnatura nie zostanie nadana!

 

Informacje dla programistów:

 

Domyślnie klasa IEDBaseObject implementuje interfejs IDocSygnature tak więc wszystkie inne klasy dziedziczące po IEDBaseObject będą obsługiwane przez mechanizm nadawania sygnatur.<

W przypadku chęci użycia sygnatur dla innych typów ( które nie dziedziczą po IEDBaseObject ) należy dodać dziedziczenie po IDocSygnature.

 

W standardowych sytuacjach, czyli podczas zapisywania dokumentu za pomocą przycisku SAVE uruchamiany jest kontroler, który nadaje sygnaturę dla dokumentu:

public partial class DocSygnatureController : ViewController
    {
        public DocSygnatureController()
        {
            InitializeComponent();
            // Target required Views (via the TargetXXX properties) and create their Actions.
            TargetObjectType = typeof(IDocSygnature);
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
            View.ObjectSpace.ObjectSaving += ObjectSpace_ObjectSaving;
        }

        private void ObjectSpace_ObjectSaving(object sender, ObjectManipulatingEventArgs e)
        {
            if (View != null && ObjectSpace != null)
                DocSygnature.NadajSygnature(Application, ObjectSpace, View.CurrentObject);
        }

        protected override void OnDeactivated()
        {
            // Unsubscribe from previously subscribed events and release other references and resources.
            View.ObjectSpace.ObjectSaving -= ObjectSpace_ObjectSaving;
            base.OnDeactivated();
        }
    }

W sytuacjach, kiedy tworzymy nasz obiekt w kodzie mechanizm nadawania sygnatury nie zostanie uruchomiony. Aby sygnatura została nadana należy użyć w tym celu metody statycznej NadajSygnature , która znajduje się w statycznej klasie DocSygnature przed zapisaniem nowego obiektu:

DocSygnature.NadajSygnature(XafApplication Application, IObjectSpace ObjectSpace,object obj);

 

STARY MECHANIZM ( NIEAKTUALNY ):

Powodem zrezygnowania z tego mechanizmu to fakt, że pluginy/usługi nie widzą modelu aplikacji a co za tym idzie nie są w stanie pobrać formatu sygnatury dla dokumentu.

Mechanizm nadawania sygnatury został przeniesiony z aplikacji do modelu.

Od teraz w gałęzi BOModel w klasie, która dziedziczy po interfejsie IDocSygnature będzie dostępna właściwość SygnatureFormat.

Domyślnie klasa IEDBaseObject implementuje interfejs IDocSygnature tak więc wszystkie inne klasy dziedziczące po IEDBaseObject będą miały dostępną właściwość SygnatureFormat.

 

W przypadku gdy SygnatureFormat nie zostanie nadana w modelu, po zapisaniu obiektu Sygnatura nie zostanie nadana!

 

Informacje dla programistów:

 

W celu generowania sygnatury dla określonego typu należy w klasie dziedziczyć po interfejsie IDocSygnature (znajduje się w BaseModule) a następnie go zaimplementować:

[ModelDefault("AllowEdit", "False")]
[NonCloneable]
public string Sygnatura
{
get;
set;
}

[Browsable(false)]
public Dzial Dzial
{
get
{
return Dzial;
}
}

[Browsable(false)]
public SeriaDokumentu Seria
{
get
{
return SeriaDokumentu;
}
}

 

Mechanizm nadawania Sygnatury obsługuje Controller DocSygnatureController (znajduje się w BaseModule)

 

public partial class DocSygnatureController : ViewController
    {
        public DocSygnatureController()
        {
            InitializeComponent();
            // Target required Views (via the TargetXXX properties) and create their Actions.
            TargetObjectType = typeof(IDocSygnature);
        }
        protected override void OnActivated()
        {
            base.OnActivated();
            // Perform various tasks depending on the target View.
        }
        protected override void OnViewControlsCreated()
        {
            base.OnViewControlsCreated();
            // Access and customize the target View control.
            View.ObjectSpace.ObjectSaving += ObjectSpace_ObjectSaving;
        }

        private void ObjectSpace_ObjectSaving(object sender, ObjectManipulatingEventArgs e)
        {
            if(View.CurrentObject != null)
            {
                IDocSygnature doc = View.CurrentObject as IDocSygnature;
                
                if (doc != null)
                {
                    if (string.IsNullOrEmpty(doc.Sygnatura))
                    {
                        var model = Application.Model.BOModel.FirstOrDefault(x=>x.TypeInfo.Type == View.CurrentObject.GetType());
                        if (model != null)
                        {
                            int wielkoscNumer = 5;
                            string resultString = Regex.Match((model as IModelDocSygnature).SygnatureFormat, @"\d+").Value;
                            if (!string.IsNullOrEmpty(resultString))
                                wielkoscNumer = Convert.ToInt32(resultString);

                            string sygnaturaFormat = (model as IModelDocSygnature).SygnatureFormat.
                                            Replace($"{{numer: {wielkoscNumer}}}", "1".PadLeft(wielkoscNumer, '0')).
                                            Replace($"{{NUMER: {wielkoscNumer}}}", "1".PadLeft(wielkoscNumer, '0')).
                                            Replace($"{{numer:{wielkoscNumer}}}", "1".PadLeft(wielkoscNumer, '0')).
                                            Replace($"{{NUMER:{wielkoscNumer}}}", "1".PadLeft(wielkoscNumer, '0')).
                                            Replace("{dzial}", doc.Dzial != null ? doc.Dzial.SymbolDzialu : string.Empty).
                                            Replace("{DZIAL}", doc.Dzial != null ? doc.Dzial.SymbolDzialu : string.Empty).
                                            Replace("{seria}", doc.Seria != null ? doc.Seria.Kod : string.Empty).
                                            Replace("{SERIA}", doc.Seria != null ? doc.Seria.Kod : string.Empty).
                                            Replace("{rr}", DateTime.Now.Year.ToString().Substring(DateTime.Now.Year.ToString().Length - 2)).
                                            Replace("{RR}", DateTime.Now.Year.ToString().Substring(DateTime.Now.Year.ToString().Length - 2)).
                                            Replace("{rrrr}", DateTime.Now.Year.ToString()).
                                            Replace("{RRRR}", DateTime.Now.Year.ToString()).
                                            Replace("{MM}", DateTime.Now.Month.ToString().PadLeft(2, '0')).
                                            Replace("{mm}", DateTime.Now.Month.ToString().PadLeft(2, '0')).
                                            Replace("{DD}", DateTime.Now.Day.ToString().PadLeft(2, '0')).
                                            Replace("{dd}", DateTime.Now.Day.ToString().PadLeft(2, '0'));

                            int nextSequence = DistributedIdGeneratorHelper.Generate(((XPObjectSpace)ObjectSpace).Session.DataLayer, View.CurrentObject.GetType().FullName + "_" + sygnaturaFormat, "MyServerPrefix");

                            string sygnatura = (model as IModelDocSygnature).SygnatureFormat.
                                            Replace($"{{numer: {wielkoscNumer}}}", nextSequence.ToString().PadLeft(wielkoscNumer, '0')).
                                            Replace($"{{NUMER: {wielkoscNumer}}}", nextSequence.ToString().PadLeft(wielkoscNumer, '0')).
                                            Replace($"{{numer:{wielkoscNumer}}}", nextSequence.ToString().PadLeft(wielkoscNumer, '0')).
                                            Replace($"{{NUMER:{wielkoscNumer}}}", nextSequence.ToString().PadLeft(wielkoscNumer, '0')).
                                            Replace("{dzial}", doc.Dzial != null ? doc.Dzial.SymbolDzialu : string.Empty).
                                            Replace("{DZIAL}", doc.Dzial != null ? doc.Dzial.SymbolDzialu : string.Empty).
                                            Replace("{seria}", doc.Seria != null ? doc.Seria.Kod : string.Empty).
                                            Replace("{SERIA}", doc.Seria != null ? doc.Seria.Kod : string.Empty).
                                            Replace("{rr}", DateTime.Now.Year.ToString().Substring(DateTime.Now.Year.ToString().Length - 2)).
                                            Replace("{RR}", DateTime.Now.Year.ToString().Substring(DateTime.Now.Year.ToString().Length - 2)).
                                            Replace("{rrrr}", DateTime.Now.Year.ToString()).
                                            Replace("{RRRR}", DateTime.Now.Year.ToString()).
                                            Replace("{MM}", DateTime.Now.Month.ToString().PadLeft(2, '0')).
                                            Replace("{mm}", DateTime.Now.Month.ToString().PadLeft(2, '0')).
                                            Replace("{DD}", DateTime.Now.Day.ToString().PadLeft(2, '0')).
                                            Replace("{dd}", DateTime.Now.Day.ToString().PadLeft(2, '0'));


                            doc.Sygnatura = sygnatura;
                        }

                        
                    }
                }
            }          
        }

        protected override void OnDeactivated()
        {
            // Unsubscribe from previously subscribed events and release other references and resources.
            View.ObjectSpace.ObjectSaving -= ObjectSpace_ObjectSaving;
            base.OnDeactivated();
        }
    }
 

Dalej >