public struct bill
{
public int id;
public DateTime docdate;
public ArrayList billDetails;//this will point the billitems structure
};
public struct billItems
{
public int id;
public int item;
public int quantity;
public string name;
public double price;
public ArrayList tax;
public double discount;
};
public ArrayList ReadBill(MySqlConnection connection)
{
ArrayList billList = new ArrayList( );
ArrayList billdetailsList = new ArrayList();
ArrayList details = new ArrayList();
bill bills = new bill();
DataTable dt = new DataTable();
MySqlCommand cmd = new MySqlCommand("SELECT id,DATE_FORMAT(DATE, \"%d-%m-%Y\")docdate,contents FROM bills WHERE progress='Paid'; ", connection);
dt.Load(cmd.ExecuteReader());
for (int i = 0; i < dt.Rows.Count; i++)
{
bills.id = Convert.ToInt32(dt.Rows[i]["id"].ToString());
bills.docdate =Convert.ToDateTime(dt.Rows[i]["docdate"].ToString());
bills.billDetails = new ArrayList();
bills.billDetails = JsonConversion(dt.Rows[i]["contents"].ToString());//function to get deserialization of json string
string str = "";
foreach (var items in bills.billDetails)
{
str= items.ToString();
string replacement = Regex.Replace(str, @"\t|\n|\r", "");//removing the spaces
replacement = Regex.Replace(replacement, " ", "");
details.Add(replacement); //adding to arraylist
}
bills.billDetails = details;// mapping arraylist to structure variable arraylist
//i want to assign this arralist to a structure which contains the details of billitems.
}
private ArrayList JsonConversion(string v)
{
int len;
ArrayList testarray = new ArrayList();
ArrayList resultarraylist = new ArrayList();
testarray= JsonConvert.DeserializeObject<ArrayList>(v);
string array = "";
char[] splitter_securityIDs = { ',' };
foreach (var items in testarray)
{
array = items.ToString();
array = array.Remove(0, 1);
len = array.Length;
array = array.Remove(len - 1, 1);
resultarraylist.AddRange(array.Split(splitter_securityIDs));
return resultarraylist;
}
return null;
}
**i have two structure bill and billitems. bill have billdetails arraylist which will point to billitems. i got a json string from the mysql db using the select query. i got the json string Like below for a recod.
[{"id":46,"item":1,"quantity":10,"name":"GARLIC CHEESE ROLL ","price":"50.000","tax":{"name":null,"price":50,"quantity":10,"percent":0,"amount":0,"contents":[]},"discount":0},{"id":47,"item":85,"quantity":1,"name":"PISTA SCOOPS","price":"70.000","tax":{"name":null,"price":70,"quantity":1,"percent":0,"amount":0,"contents":[]},"discount":0}]
enter image description here **this is the datatable i get after select query.
now i want to split this details ("id":46,"item":1,"quantity":10,"name":"GARLIC CHEESE ROLL ","price":"50.000","tax":{"name":null,"price":50,"quantity":10,"percent":0,"amount":0,"contents":[]},"discount":0) to the structure called billitems.
Plz help me in this. thanks in advance.