Question How to Generate json string for function FillGrids ?

ahmedsalah

Active member
Joined
Sep 26, 2018
Messages
32
Programming Experience
3-5
I have windows form functions FillGrids and i need to convert to json format string
private static void FillGrids(Control.ControlCollection Controls, xForm frm)
{

foreach (Control co in Controls)
{
if (co is xDataGrid && (!String.IsNullOrEmpty(((xDataGrid)co).TableName) || !String.IsNullOrEmpty(((xDataGrid)co).SelectQuery)))
{
Binder.DataToGrid(frm.Controls, frm, (xDataGrid)co);
}
else
{

}
if (co.Controls.Count > 0 && co.Name != "pnlGridPanel" && co.Name != "pnlMasterDetailsGrid")
{
FillGrids(co.Controls, frm);
}
}

}
public static void DataToGrid(Control.ControlCollection Controls, xForm frm, xDataGrid Grid)
{

string SQL = "";

string Criteria = "";
DataTable Relations = new DataTable();

if (Grid.SelectQuery != "")

SQL = Grid.SelectQuery;
else xExceptions.DataGirdTableNameOrSelectQueryIsMissing();

Relations = DataAccess.ExecuteDataTable(SqlFactory.Queries.Tables_GetRelations(frm.TableName, Grid.TableName));

if (Grid.SelectQuery.IndexOf(" WHERE ", StringComparison.OrdinalIgnoreCase) == -1)
{
Criteria = SqlFactory.Queries.GetGlobalCriteriaForGrid(frm, Grid.TableName, Relations);
SQL += " WHERE ";
SQL += Criteria != "" ? Criteria : " 1 = 1 ";
}
else
{

Criteria = SqlFactory.Queries.GetGlobalCriteriaForGrid(frm, Grid.TableName, Relations, false);
if (Criteria != "") SQL += " AND " + Criteria;
}

if (!String.IsNullOrEmpty(Grid.Filter) && !SQL.Contains(" 1 = 1 ")) SQL += " AND " + Grid.Filter;

DataTable dt = DataAccess.ExecuteDataTable(SQL);


if (frm.IsSaveAndCopy)
{
Grid.ChangeAllRowsState(RowStates.Inserted); //Because of F6
}
else
{
Grid.DataBinding(dt);

}

}
this function FillGrids give me sql select statement result as following :
select FooterTable.ItemCode,FooterTable.Quantity,FooterTable.UniPrice from

MasterTable inner join FooterTable on MasterTable.Serial=FooterTable.Serial,MasterTable.BranchCode=FooterTable.BranchCode,MasterTable.Year=FooterTable.Year

where MasterTable.Serial=10 AND MasterTable.Year=2019 AND MasterTable.BranchCode=1

wht i try to do is

{
"Details":{
"table":[
"MasterTable",
"FooterTable"
],
"fields":{
"ItemCode":"string",
"Quantity":"int",
"Price":"decimal"

},
"keys":{
"BranchCode":1,
"Year":2019,
"Serial":2
}
}
}
 
Original formulation of this question by the OP over at Dream In Code.
 
How was this not helpful to you? Serializing and Deserializing JSON

Please show us where you tried to implement this?

I am also a bit perplexed how you can determine logically whether an inner join is required when you have not even experienced the output of your json file through your code to determine if inner join will be necessary. Do you even know what inner join does? :unsure:

- Begging : Screenshot is really detestable. Instead, take some time to reflect on what you were given on this topic. How To Generate Json File For Select Statement For Following Format ? - C# | Dream.In.Code

I also believe your spearhead approach has led to your latest topic here Question - Cannot modify function GetSelectStatement to generate select statement from string json?, which I will let a moderator decide to merge, since It's kinda the same problem, except you're going about it the wrong way. And disregarding the advice on the other forum which is not going to lead to a silver bullet to progress with your project. I think that topic should be merged with this.
 
Back
Top Bottom