Thursday, November 30, 2023

c# - How to call custom event

1) Custom event without parameters:
public Action OnBeforeEvaluationEvent;
...
if ( OnBeforeEvaluationEvent != null ) OnBeforeEvaluationEvent();
2) Custom event with parameter(s):
public delegate void OnAfterEvaluatingDelegate( CodeConditionGroup _conditionGroup );    
public event OnAfterEvaluatingDelegate OnAfterEvaluationgEvent;

if ( OnAfterEvaluationgEvent != null ) OnAfterEvaluationgEvent( condition );

Friday, November 24, 2023

c#, devexpress - How to make master-detail relation on non-DB objects (List generic )

List<TmpParent> list = new List<TmpParent>();

List<TmpChild> listChildExternal = new List<TmpChild>();
Initial data filling:
var p = new TmpParent( "A", "A", true );
p.listInner.Add( new TmpChild() );
list.Add( p );
list.Add( new TmpParent( "B", "B", false, TypeEnum.OPERATOR ) );
list.Add( new TmpParent( "C", "C", true ) );
list.Add( new TmpParent( "D", "D", false ) );

listChildExternal.Add( new TmpChild() { str1="C", str2 = "child1" } );
listChildExternal.Add( new TmpChild() { str1="C", str2 = "child1.1" } );
listChildExternal.Add( new TmpChild() { str1="B", str2 = "child1.2" } );

gridParent.DataSource = list;	// master
Find and show detail data:
  • First detail list for inner list.
  • Second detail list for external list connected with relation.
private void gridViewParent_FocusedRowChanged( object sender, 
  DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e ) {
   
  if ( e.FocusedRowHandle >= 0 ) {        
    TmpParent master = gridView1.GetRow( e.FocusedRowHandle ) as TmpParent;
    if ( master != null ) {          
      /* A] try to find in inner list */
      gridDetail.DataSource = master.listInner;

      /* B] try to find in external list */           
      gridChildExternal.DataSource = 
        listChildExternal.Where( x => x.str1 == master.str1 ).ToList();
    }
  }
}
First grid=master, second grid=detail internal list, third grid=detail external list.

Tuesday, November 14, 2023

c#, devexpress - How to use attributes in GridControl (devexpress)

The attributes in the class can be used as metadata for generated GridControl (devexpress) columns. 

Class for rows:
public enum TypeEnum {
   [Display(Name = "Type is expression.")]  
   EXPRESSION = 0,
   [Display(Name = "Type is operator.")]  
   OPERATOR = 1
}    

public class TmpParent
{            
   [Display(
     ShortName = "Company", 
     Name = "Company Name", 
     Description = "The amount of currently available product", 
     AutoGenerateFilter = false)
   ]
  public string str1 { get; set; }
  [DataType(DataType.Text), StringLength(20, MinimumLength = 3)]
  public string str2 { get; set; }
  public bool bool1 { get; set; }
  public TypeEnum enum1 { get; set; }
  [DisplayFormat(DataFormatString = "MMMM/yyyy")]
  public DateTime date1 { get; set; }
  [DisplayFormat(DataFormatString = "p", ApplyFormatInEditMode = true)]
  public float value1 {  get; set; }
  [DataType(DataType.Currency), Range(200, 5000), Required]    
  public float value2 { get; set; }
        
   public TmpParent( string _s1, string _s2, bool _b, TypeEnum _enum = TypeEnum.EXPRESSION )
   {
     str1 = _s1;
     str2 = _s2;
     bool1 = _b;
     enum1 = _enum;
     date1 = DateTime.Now;
     value1 = 100.1f;
     value2 = 300.5f;
   }
}
Grid fillings:
var p = new TmpParent( "A", "A", true );
list.Add( p );
list.Add( new TmpParent( "B", "B", false, TypeEnum.OPERATOR ) );
list.Add( new TmpParent( "C", "C", true ) );
list.Add( new TmpParent( "D", "D", false ) );

gridParent.DataSource = list;
Output:

Monday, October 23, 2023

delphi - How to work with generic TArray

Using generic TArray with String type.
procedure TFDrawingRelease.doReading;
var
  f : TextFile;
  sRow : string;
  aSplitted: TArray<string>;
begin
  { -- delete all rows }

  if QData.Active then
    begin
      QData.Close;
      QData.Open;
    end;

  { -- open file and read data (two columns divided by ";") }

  AssignFile( f, EFileName.Text );
  try
    Screen.Cursor := crHourGlass;
    QData.DisableControls;

    reset( f );  
    
    while not eof( f ) do
      begin
        readln( f, sRow );

        aSplitted := sRow.Split( [';'], 2 );

        QData.Insert;
        { ..and return to first char _ }
        QDataItemid.AsString := aSplitted[0].Split( [ '_' ], 1 )[0];
        QDataName.AsString := aSplitted[1];
        QData.Post;
      end;
  finally
    closeFile( f );

    QData.EnableControls;
    Screen.Cursor := crDefault;
  end;

  SetButtons;
end;

Wednesday, September 6, 2023

ax - How to call new form and modify its grid filter

Args    args;
FormRun formRun;
Query query;
My_VM_Resources table;
FormDataSource formDataSource = new FormDataSource();

super();

// call the new form 
args = new Args();
formRun = new menufunction( menuItemDisplayStr( WrkCtrCapRes ), 
                            MenuItemType::Display ).create( args );

formRun.init();
formDataSource = formRun.dataSource();
formRun.run();

table = My_VM_Resources_ds.cursor();
formDataSource.filter( fieldNum(WrkCtrCapRes, WrkCtrId), /*"5210*"*/table.my_resource_mask );
formRun.detach();

formRun.wait();

Wednesday, July 12, 2023

Monday, May 22, 2023

oracle - How to alter sequence next number

DROP SEQUENCE MENU_SEQ;

create sequence MENU_SEQ
minvalue 1
maxvalue 999999999999999999999
start with 18456
increment by 1
cache 20;

Friday, April 21, 2023

ax - How to find plan version by name

if ( this.RefType == WrkCtrCapRefType::PlannedOrder ) {
        
  reqPO = ReqPO::find( 
    ReqPlanVersion::findReqPlanId( "MAIN", "company", NoYes::Yes, false ).RecId,  
    this.refId, false );
        
  if ( reqPO ) return reqPO.ItemId;
}

Friday, April 14, 2023

c# - How to solve problem on TEST project with error on referenced project

The problem with the referenced project error can be solved with this change: 

 Set "Target OS" from "None" to something else.

Monday, January 30, 2023

c# - How to save List into text file

public List CodeLogOnlyList = new();
...
await System.IO.File.WriteAllLinesAsync( _filename, this.CodeLogOnlyList );

Friday, January 20, 2023

Wednesday, January 11, 2023