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
}
}
}
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
}
}
}