Abhishek Singh

Abhishek Singh

  • NA
  • 103
  • 769

Json Object inside a Json Array

Feb 10 2022 10:24 AM
public List<Itm> GetInvItm(string CustGST,string CustInvNo,string CustInvDt)
{
    List<Itm> ItmD = new List<Itm>();
    var k = GetInvItmDtl(CustGST, CustInvNo, CustInvDt);
    DataTable dt = GetData("SELECT SUM(BILL_FREIGHT)BILL_AMNT,SUM(CGST_RATE+SGST_RATE+IGST_RATE)GST_RATE,SUM(CGST)CGST,SUM(SGST)SGST,SUM(IGST)IGST,SUM(NET_AMNT)  FROM INVOICE_SUMMARY_VW WHERE  " +
                           "BRANCH_GSTIN='" + ddlGSTINNo.SelectedValue + "' AND CUST_GSTIN='" + CustGST + "' AND BILL_MONTH='" + drpMonth.SelectedValue + "' " +
                           "AND BILL_NO='" + CustInvNo + "' AND TO_CHAR(BILL_DATE,'DD-MM-RRRR')='" + CustInvDt.Trim() + "'  ");
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        ItmD.Add(new Itm
        {
            num = 1201,
            itm_det = null,[How to map item detail]
        });
    }
    return ItmD;
}
public List<ItmDet> GetInvItmDtl(string CustGST, string CustInvNo, string CustInvDt)
{
    List<ItmDet> ItmDtl = new List<ItmDet>();
    DataTable dt = GetData("SELECT SUM(BILL_FREIGHT)BILL_AMNT,SUM(CGST_RATE+SGST_RATE+IGST_RATE)GST_RATE,SUM(CGST)CGST,SUM(SGST)SGST,SUM(IGST)IGST  FROM INVOICE_SUMMARY_VW WHERE  " +
                           "BRANCH_GSTIN='" + ddlGSTINNo.SelectedValue + "' AND CUST_GSTIN='" + CustGST + "' AND BILL_MONTH='" + drpMonth.SelectedValue + "' " +
                           "AND BILL_NO='" + CustInvNo + "' AND TO_CHAR(BILL_DATE,'DD-MM-RRRR')='" + CustInvDt.Trim() + "' ");
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        ItmDtl.Add(new ItmDet
        {
            txval = Convert.ToDouble(dt.Rows[i]["BILL_AMNT"]),
            rt = Convert.ToDouble(dt.Rows[i]["GST_RATE"]),
            camt = Convert.ToDouble(dt.Rows[i]["CGST"]),
            samt = Convert.ToDouble(dt.Rows[i]["SGST"]),
            csamt = Convert.ToDouble(dt.Rows[i]["IGST"])
        });
    }
    return ItmDtl;
}
public class Itm
{
    public int num { get; set; }
    public ItmDet itm_det { get; set; }
}
public class ItmDet
{
    public double txval { get; set; }
    public double rt { get; set; }
    public double camt { get; set; }
    public double samt { get; set; }
    public double csamt { get; set; }
}

OUTPUT 

"itms":[
   {
      "num":1,
      "itm_det":{
         "txval":23475.00,
         "rt":12,
         "camt":1408.50,
         "samt":1408.50,
         "csamt":0.00
      }
   }
],

 


Answers (7)