I have been trying to do that for the last hour and still can get it to work.
I'm trying to create a multi depth array. Let me explain myslef.
Boss
Manager
Employee
Employee
Employee
Manager
Employee
Employee
Employee
Boss
Manager
Employee
Employee
Employee
Manager
Employee
Employee
Employee
Boss
Manager
Employee
Employee
Employee
Manager
Employee
Employee
Employee
and they must have a label, here it would be Boss, Manager or Employee's name.
Is there any way to do this ?
Thanks
Might be better just to have a class that represent a hierarchy of a person with a list of people underneath them. Personally, a multidepth array can be a bit complicated especially for the person that is going to maintain the code.
Sub Main()
Dim bosses As New List(Of Hierarchy)
bosses.Add(New Hierarchy)
bosses(0).Person = New Person
bosses(0).Person.Name = "Boss"
bosses(0).Childs.Add(New Hierarchy)
bosses(0).Childs(0).Person = New Person
bosses(0).Childs(0).Person.Name = "Manager"
bosses(0).Childs(0).Childs.Add(New Hierarchy)
bosses(0).Childs(0).Childs(0).Person = New Person
bosses(0).Childs(0).Childs(0).Person.Name = "Employee"
bosses(0).Childs(0).Childs.Add(New Hierarchy)
bosses(0).Childs(0).Childs(1).Person = New Person
bosses(0).Childs(0).Childs(1).Person.Name = "Employee"
For Each boss In bosses
Console.WriteLine(boss.Person.Name)
For Each manager In boss.Childs
Console.WriteLine(" " & manager.Person.Name)
For Each employee In manager.Childs
Console.WriteLine(" " & employee.Person.Name)
Next
Next
Next
End Sub
Class Hierarchy
Public Person As Person
Public Childs As New List(Of Hierarchy)
End Class
Class Person
Public Name As String
End Class
Here is how I managed to do this:
Public Class sousdir
Public name As String
Public services As New List(Of String)
End Class
Public Class direction
Public name As String
Public sousdirs As New List(Of sousdir)
End Class
Dim directions As New List(Of direction)
directions.Add(New direction)
directions(0).name = "Direction 1"
directions(0).sousdirs.Add(New sousdir)
directions(0).sousdirs(0).name = "Sous Direction 1"
directions(0).sousdirs(0).services.Add("Service 1")
directions(0).sousdirs(0).services.Add("Service 2")
directions(0).sousdirs(0).services.Add("Service 3")
directions(0).sousdirs.Add(New sousdir)
directions(0).sousdirs(1).name = "Sous Direction 2"
directions(0).sousdirs(1).services.Add("Service 1")
directions(0).sousdirs(1).services.Add("Service 2")
...
With result formatting
How this will help some people
Related
I am new to the salesforce flows. Here I am trying to show the list of student data in salesforce flow. The return type of getStudentList is an Aggregate student list which is List of List. I am getting StudentWrapper data but not able to print Aggregate student list. Please help me.
public class DemoWrapperLists{
#InvocableMethod
public List<AggStudentList> class getStudentList(List<String> studentIds){
List<Student__c> stuListObj = [SELECT Id, Name, status from Student__c where Id in: studentIds];
List<StudentWrapper> stuWrapee = new List<StudentWrapper>();
List<AggStudentList> aggList = new List<AggStudentList>();
for(Student__c s: stuListObj){
Student stu = new Student();
stu.Id = s.Id;
stu.Name = s.Name;
stu.Status = s.Status;
stuWrapee.add(stu);
aggList.addAll(stuWrapee);
}
}
// this is for list of students
public class AggStudentList{
#InvocableVariable List<StudentWrapper> studentDetails;
}
public class StudentWrapper {
#InvocableVariable String Id
#InvocableVariable String Name
#InvocableVariable String Status
}
}
I have forgotten how to make an array or whatever out of 8 fields. It looks something like Array.Subcategory[x] afterwards but i've forgotten what its called and how to do it.
It needs to be 1 array with multiple entries but each entry have 8 sub entries.
So for a group of people
1 array entry will contain:
Name
Eye colour
Haircolour
Age
Balls
Smell
???
One array will contain all this data for each array entry.
cheers
You could define a class in VB.NET like this:
public class Entry
public Name as String
public EyeColour as String
public Haircolour as String
public Age as Integer
public Balls as Integer
public Smell as String
end class
Then create a List or Array holding entries like this:
public ListOfEntries as List(of Entry) = new List(of Entry)
public ArrayOfEntries(10) as Entry
Use it like this:
dim e as Entry = new Entry
e.Name = "Test"
e.EyeColour = "Blue"
' add new object to list
ListOfEntries.Add(e)
' add new object at position 0
ArrayOfEntries(0) = e
Another possibility would be to use a Structure (used-defined data type):
' a record of data
public structure Entry
public Name as String
public EyeColour as Integer
'...
end structure
' array of entries
public Entries(10) as Entry
' usage like in the class example
dim e = new Entry
e.Name = "Test"
e.EyeColour = 5
Entries(0) = e
You can do it with types also, which avoids some of the initialization hassels with classes in arrays:
Type foo
Name as String
EyeColour as Integer
...
End Type
Dim bar() As foo
I need to get all of the subdocuments array from the Courses Class where the User.UserId = whatever and Courses.Status=active
Public Class User
Public Property UserId As String 'this is unique so i would like to index this, unless you think otherwise
Public Property CourseData() As List(Of Courses) '
Public Property Groups As List(Of String)
Public Property BU As List(Of String)
End Class
Public Class Courses
Public Property id As String 'this can be dynamic
Public Property description As String
Public Property CompletionDate As String
Public Property Hours As String
Public Property Status As String
End Class
Using vb.net , I tried a few ways, I only want the courses returned that have a Status="Active" to be dumped into Ienumberable
I tried (_users is a collection of User) (_uid is a variable passed into it)
Return _users.FindAs(Of User)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid))))
Return _users.FindAs(Of User)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid)))).SetFields("Courses", "1")
Return _users.FindAs(Of Courses)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid))))
Return _users.FindAs(Of Courses)(Query.And(query.EQ("LearningHours.Status", "Active"), (Query.EQ("UserId", _uid)))).SetFields("Courses", "1")
None seem to work, they usually come back with the fields from Class User or both Class User and Class Course, but the Course fields are blank
I even am trying linq.. this works - but only returns 1 row result
Dim uc = From _u In _users.AsQueryable(Of User)()
Where _u.userid = _userid _
Select _
CourseID = _u.Courses.Where(Function(c) c.State = "Submitted").Select(Function(c) c.CourseId)(0), _
CourseDescription = _u.Courses.Where(Function(c) c.State = "Submitted").Select(Function(c) c.CourseDescription)(0)
Seems easy enough to do, just cant get it
Got It, I think I was over thinking it
Once I declare an instance of the class, I can iterate through the subdocument
Dim _u as new User
For Each c In _user.Courses.Where(Function(cs) cs.Status= "Active").Select(Function(cs) cs)
console.writeline(c.id & c.description & "so on...")
Next
I can't seem to find documentation or examples for my problem (been searching a while now). I think my problem is pretty straightforward, so here goes.
I have two tables. My primary table is called Persons and the secondary table is PersonEntries. For each person in Person table, i can have 0 or more entries in the PersonEntries table. Like this.
Table: Person
Id
Name
Table: PersonEntry
PersonId
CheckinTime
CheckoutTime
I have two objects like this
public class Person {
public string Name;
public List<PersonEntry> PersonEntries;
}
public class PersonEntry {
public DateTime CheckinTime;
public DateTime CheckoutTime;
}
If i was to get it from the database into my c# classes how would i do it? I can map a single table into my c# class and do it for each table, but then i'm left to match what entries maps to what person.
I've seen several examples of mapping ONE PersonEntry to ONE Person, the problem here is that i have a zero-to-many relation. My Person have a LIST of PersonEntry items.
You can do something like this (see https://www.tritac.com/blog/dappernet-by-example):
public class Shop {
public int? Id {get;set;}
public string Name {get;set;}
public string Url {get;set;}
public IList<Account> Accounts {get;set;}
}
public class Account {
public int? Id {get;set;}
public string Name {get;set;}
public string Address {get;set;}
public string Country {get;set;}
public int ShopId {get;set;}
}
var lookup = new Dictionary<int, Shop>()
conn.Query<Shop, Account, Shop>(#"
SELECT s.*, a.*
FROM Shop s
INNER JOIN Account a ON s.ShopId = a.ShopId
", (s, a) => {
Shop shop;
if (!lookup.TryGetValue(s.Id, out shop)) {
lookup.Add(s.Id, shop = s);
}
if (shop.Accounts == null)
shop.Accounts = new List<Account>();
shop.Accounts.Add(a);
return shop;
}
).AsQueryable();
var resultList = lookup.Values;
I had made a class in C# Windows form to represent my database.
It has a master/detail using List<>
A record with Employee profile with Trainings(master) and TrainingDetails(detail)
Now, how can I display this into 2 datagridview that whenever I select a "Training" from the first datagridview it will display the details on the 2nd datagridview.
Its easy to change the datasource of the 2nd datagridview whenever the user select a new item from the first datagridview. But im wondering how it is done professionally.
Also saving is a pain, Im thingking to iterate through the datarow and save it but It mean I have to know what are the data has been update, inserted and deleted.
Please help me. Im a newbie.
BindingSources take care of this for you.
For example say I have two classes, Teachers and Students:
public class Teacher
{
private List<Student> _students = new List<Student>();
public string Name { get; set; }
public string Class { get; set; }
public List<Student> Students { get { return _students; } }
}
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
}
You can then create a list of Teachers which represents the Master/Detail situation:
List<Teacher> teachers = new List<Teacher>();
Teacher t = new Teacher();
t.Name = "Mr. Smith";
t.Class = "A1";
teachers.Add(t);
Student s = new Student();
s.Name = "Jimmy Jones";
s.Age = 6;
t.Students.Add(s);
s = new Student();
s.Name = "Jane Doe";
s.Age = 5;
t.Students.Add(s);
t = new Teacher();
t.Name = "Ms. Allen";
t.Class = "B3";
teachers.Add(t);
s = new Student();
s.Name = "Sally Student";
s.Age = 7;
t.Students.Add(s);
On my form I have two DataGridViews, teachersDataGridView and studentsDataGridView and two binding sources teachersBindingSource and studentsBindingSource.
I wire everything up like so:
teachersBindingSource.DataSource = teachers;
studentsBindingSource.DataSource = teachersBindingSource;
studentsBindingSource.DataMember = "Students";
teachersDataGridView.DataSource = teachersBindingSource;
studentsDataGridView.DataSource = studentsBindingSource;
And as if by magic when running up on the form selecting an item from the teachers grid changes students grid.
For managing inserts, updates and deletes you will need to implement some sort of change tracking yourself (or use an ORM such as Entity Framework or nHibernate). It is a topic that deserves its own question so read up on those technologies (and look at the blog post I like below) and come back when you have some specific problems.
For this answer I borrowed heavily from this excellent post - the example I've given is complete and avoids a lot of the complexity in that authors example's, but eventually you will probably want to at least know about everything he discusses. Download his demos and have a look.