I am populating a treeview from an arrayList and I am not able to populate the grandchildren of the second child.
I was going for something like this
parent
- child1
- gc1
- gc2
- child2
- gc1
- gc2
But I am stuck with only just populating the child2 as I am having exceptions (ArgumentOutOfRangeException) when trying to populate the grandchildren of the second child
string currentDatabaseParent = "";
string currentSchemaParent = "";
string currentTableParent = "";
int databasecount = 0;
int schemacount = 0;
int tablecount = 0;
foreach (var schema in schemaArr)
{
int order = Array.IndexOf(schemaArr, schema);
if ((schema.column_name != "Number") && (schema.schema_name != "INFORMATION_SCHEMA") && (schema.database_name != "SAMPLE_DATA"))
{
if ((currentDatabaseParent == "") || (currentDatabaseParent != schema.database_name))
{
treeViewSchemaList.Nodes.Add(schema.database_name);
sb.AppendLine(schema.database_name);
currentDatabaseParent = schema.database_name;
}
else if (currentDatabaseParent != schema.database_name)
{
treeViewSchemaList.Nodes.Add(schema.database_name);
sb.AppendLine(schema.database_name);
currentDatabaseParent = schema.database_name;
databasecount = databasecount + 1;
schemacount = 0;
tablecount = 0;
}
if ((currentSchemaParent == ""))
{
treeViewSchemaList.Nodes[schemacount].Nodes.Add(schema.schema_name);
sb.AppendLine(" - " + schema.schema_name);
currentSchemaParent = schema.schema_name;
}
else if (currentSchemaParent != schema.schema_name)
{
treeViewSchemaList.Nodes[schemacount].Nodes.Add(schema.schema_name);
sb.AppendLine(" - " + schema.schema_name);
currentSchemaParent = schema.schema_name;
schemacount = schemacount + 1;
}
if (currentTableParent == "")
{
treeViewSchemaList.Nodes[schemacount].Nodes[tablecount].Nodes.Add(schema.table_name);
sb.AppendLine(" - " + schema.table_name);
currentTableParent = schema.table_name;
}
else if (currentTableParent != schema.table_name)
{
treeViewSchemaList.Nodes[schemacount].Nodes[tablecount].Nodes.Add(schema.table_name);
sb.AppendLine(" - " + schema.table_name);
currentTableParent = schema.table_name;
tablecount = tablecount + 1;
}
//DataType dataType = new DataType();
//dataType = JsonConvert.DeserializeObject<DataType>(schema.data_type);
//sb.AppendLine(" - " + schema.column_name + "(" + dataType.Type + ")");
//treeViewSchemaList.Nodes[databasecount].Nodes[schemacount].Nodes[tablecount].Nodes.Add(schema.column_name + "(" + schema.data_type + ")");
}
}
The code stucks to this when viewed from the StringBuilder
parent
- child1
- gc1
- gc2
- child2
I have already tried modifying some code by manipulating the count variables but still can't get to work
Related
Library Version:
1.2.9
NuGet Package Url:
https://www.nuget.org/packages/PrestaSharp/1.2.9
Prestashop version:
1.7.7.0
Describe the Bug:
PrestaSharp GetByFilter with pagination always return same entity list
Since ProductFactory's GetByFilter method returns null if there are more than 5000 products that match the filter. I decide to get them by pagination like this
_productFactory.GetIdsByFilter(filter, null, "[" + startingIndex.ToString() + "," + count.ToString() + "]");
but even if startingIndex(because of a loop) changes the result is the same
Full code:
filter.Add("date_upd", "[" + dFrom + "," + dTo + "]");
int i = 0;
List<long> AllProducts = new List<long>();
List<long> products;
while (true) // this loop never breaks
{
int startingIndex = i++ * count;
products = _productFactory.GetIdsByFilter(filter, null, "[" + startingIndex.ToString() + "," + (count).ToString() + "]"); // returns same products in every iteration
if (products?.Any() == true) // to check the list is not empty
{
AllProducts.AddRange(products);
if (products.Count < count)
{
break;
}
}
else
break;
}
You just have to remove the brackets from the 'limit' parameter. It is an error in the Github documentation when they give the example with brackets. Here's an own implementation where I send multiple requests in parallel to speed up the processing, regards.
public async Task<List<PS_Entity>> GetElements(int pageSize = 100) {
try {
var numberOfElements = factory.GetIds().Count;
var numberOfParallelTasks = numberOfElements >= pageSize ? numberOfElements / pageSize : 1;
var loadElementsTasks = Enumerable.Range(0, numberOfParallelTasks).Select(taskNumber => factory.GetByFilterAsync(null, "id_ASC", $"{taskNumber * pageSize},{pageSize}")).ToList();
if (numberOfElements % pageSize != 0) {
var skiped = numberOfParallelTasks * pageSize;
loadElementsTasks.Add(factory.GetByFilterAsync(null, "id_ASC", $"{skiped},{numberOfElements - skiped}"));
}
var elements = (await Task.WhenAll(loadElementsTasks)).SelectMany(elements => elements).ToList();
return elements;
} catch (PrestaSharpException e) {
if ((int)e.ResponseHttpStatusCode == 404)
Console.WriteLine($"No existen {RemoveFactoryFromName(factory)}'s.");
return new List<PS_Entity>();
}
}
The problem with the following code is :
even if I only have 10 locations to deliver and one depot set at location 0 , in this example, vehicles 1,2,3,4 seem to have they're depot at locations 10,11,12,13. Those locations don't exists. The 10 that I have are numbered from 0-9.
On the other hand the business logic seems to be OK :
as I isolated the cost of leaving the depot and the one of going back to it ( value 10 ) I get the expected result : 104. There are only 4 trips between cities that don't include the depot.
Is this a bug in Google or-tools ?
public static void Main(string[] args)
{
new CVRP().Solve(10);
}
private class RandomManhattan : NodeEvaluator2
{
public override long Run(int first_index, int second_index)
{
if (first_index == 0 || second_index == 0)
return 10;
return 1;
}
};
private class Demand : NodeEvaluator2
{
public override long Run(int first_index, int second_index)
{
return 1;
}
};
private void Solve(int locations)
{
var nr_vehicle = 5;
var routing = new RoutingModel(locations, nr_vehicle, new[] {0, 0, 0, 0, 0}, new[] {0, 0, 0, 0, 0});
Console.WriteLine("Depot : " + routing.GetDepot());
NodeEvaluator2 demandCallback = new Demand();
routing.AddDimension(demandCallback, 0, 3, true, "capacity");
var distances = new RandomManhattan();
routing.SetCost(distances);
var searchParameters =
RoutingModel.DefaultSearchParameters();
searchParameters.FirstSolutionStrategy =
FirstSolutionStrategy.Types.Value.PathCheapestArc;
var solution = routing.SolveWithParameters(searchParameters);
if (solution != null)
{
var output = "Total cost: " + solution.ObjectiveValue() + "\n";
// Dropped orders
var dropped = "";
for (var order = 0; order < locations; ++order)
{
if (solution.Value(routing.NextVar(order)) == order)
{
dropped += " " + order;
}
}
if (dropped.Length > 0)
{
output += "Dropped orders:" + dropped + "\n";
}
// Routes
for (var vehicle = 0; vehicle < nr_vehicle; ++vehicle)
{
var route = "Vehicle " + vehicle + ": ";
var order = routing.Start(vehicle);
if (routing.IsEnd(solution.Value(routing.NextVar(order))))
{
route += "Empty";
}
else
{
for (; !routing.IsEnd(order); order = solution.Value(routing.NextVar(order)))
{
var local_load = routing.CumulVar(order, "capacity");
route += order + " Load(" + solution.Value(local_load) + ") -> ";
}
if (route.Length > 0)
route = route + "0";
}
output += route + "\n";
}
Console.WriteLine(output);
}
}
You have to wrap order in
route += order + " Load(" + solution.Value(local_load) + ") -> ";
inside model.IndexToNode(order), like this
route += model.IndexToNode(order) + " Load(" + solution.Value(local_load) + ") -> ";
I cant seem to pull the custom field values of a transaction search using Web Services.
searchTransaction.savedSearchId = "2017";
SearchResult result = netsuite.search(searchTransaction);
if(result.status.isSuccess)
{
SearchRow[] searchRows = result.searchRowList;
if(searchRows != null && searchRows.Length >= 1)
{
for (int i = 0; i < searchRows.Length; i++)
{
TransactionSearchRow transactionRow = (TransactionSearchRow)searchRows[i];
var iid = transactionRow.basic.internalId[0].searchValue;
double amount = transactionRow.basic.amount[0].searchValue;
string custfild = transactionRow.basic.customFieldList[0].scriptId;
Console.WriteLine("\n Transaction ID: " + iid.internalId);
Console.WriteLine("\n Amount: " + amount.ToString());
Console.WriteLine("\n customfield: " + custfield.ToString());
}
}
}
I know that the field is being returned because I can see it in the xml response. And custfield.ToString() does return the internal ID of the custom field.
I just cant seem to get the actual value.
Figured it out, posting in case anyone else has the same question:
searchTransaction.savedSearchId = "2017";
SearchResult result = netsuite.search(searchTransaction);
if(result.status.isSuccess)
{
SearchRow[] searchRows = result.searchRowList;
if(searchRows != null && searchRows.Length >= 1)
{
for (int i = 0; i < searchRows.Length; i++)
{
TransactionSearchRow transactionRow = (TransactionSearchRow)searchRows[i];
var iid = transactionRow.basic.internalId[0].searchValue;
double amount = transactionRow.basic.amount[0].searchValue;
string custfild = transactionRow.basic.customFieldList[0].scriptId;
SearchColumnStringCustomField custfild = (SearchColumnStringCustomField)transactionRow.basic.customFieldList[0];
Console.WriteLine("\n Transaction ID: " + iid.internalId);
Console.WriteLine("\n Amount: " + amount.ToString());
Console.WriteLine("\n custfild: " + custfild.searchValue);
}
}
}
i have a class that starts with a variable of type TreeNode in System.Windows.Forms. The class's functions job is to add some nodes to this variable .. but the problem is when i try to add some nodes to it the debugger freeze up and doesn't show any response .. I searched over the internet but i didn't find such a problem .This is one of those functions
NOTE : the line that produce issue is commented
public Node Factor()
{
Node result = new Node();
if (count < tokens.Count && tokens[count] == TokenType.LeftParentheses)
{
this.Match(TokenType.LeftParentheses);
result = this.Expression();
if (!this.Match(TokenType.RightParentheses))
return null;
result.viewnode.Text = "Expression";
}
else if (tokens[count] == TokenType.Num)
{
if (!this.Match(TokenType.Num))
return null;
NumberNode nnode = new NumberNode(lexemes[count - 1]);
nnode.childs = "NumberNode : Value " + nnode.value + '\n';
nnode.viewnode = new TreeNode("Number - Value = " + nnode.value);
result = nnode;
result.viewnode = nnode.viewnode;
result.viewnode.Nodes.Add(nnode.viewnode);
}
else
{
if (!this.Match(TokenType.ID))
return null;
IdNode inode = new IdNode(lexemes[count - 1], "0");
inode.childs = "IdNode - Value : " + inode.name + '\n';
inode.viewnode = new TreeNode("Id - " + inode.name);
result = inode;
result.viewnode = inode.viewnode;
//the program freezes at this line
inode.viewnode.Nodes.Add(inode.viewnode);
}
return result;
}
You are adding the node to itself.
should be result.viewnode ...
How to get the Radio button values from PDF form using PDFbox (C#)
In Java :
doc = PDDocument.load("C:\\Users\\347702\\Desktop\\sample_form.pdf");
List pages = doc.getDocumentCatalog().getAllPages();
PDAcroForm form = doc.getDocumentCatalog().getAcroForm();
List FieldTypes = form.getFields();
PDField pdfFields;
for (int i = 0; i < FieldTypes.size(); i++) {
pdfFields = (PDField) ((List) FieldTypes).get(i);
if (pdfFields instanceof PDRadioCollection)
{
String iAsString = Integer.toString(k);
System.out.println(iAsString);
type = "RadioButton";
System.out.println("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
List kids = pdfFields.getKids();
for (Object kid : kids) {
if (kid instanceof PDCheckbox) {
PDCheckbox checkbox = (PDCheckbox) kid;
String Name = checkbox.getOnValue();
System.out.println(Name);
}
}
The above java code has been successfully working (successfully returns the children of Radiobuttons) but when the same logic is been implemented in c# its not running as expected
below is my c# code :
else if (pdfFields is PDRadioCollection)
{
System.Console.WriteLine("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
List kids = pdfFields.getKids();
System.Console.WriteLine(kids);
for (int w = 0; w < kids.size(); w++)
{
kids.get(w);
System.Console.WriteLine(kids.get(w)); ---- > Return null
System.Console.WriteLine(kids.get(w).ToString()); -- > Return null
}
}
Can any help out in this please
Thanks
At last got it work : here it is ::
C# : Need to type case with IEnumerable :
else if (pdfFields is PDRadioCollection)
{
System.Console.WriteLine("Radio Button" + " "
+ pdfFields.getFullyQualifiedName() + " ");
System.Collections.IEnumerable kids = (System.Collections.IEnumerable)pdfFields.getKids();
System.Console.WriteLine(kids);
foreach (object kid in kids)
{
PDCheckbox checkbox = (PDCheckbox)kid;
checkbox.check();
}