private static void WriteCartList(StringBuilder sb, DataRow row, string cid) { sb.Append("{"); foreach (DataColumn column in row.Table.Columns) { sb.AppendFormat("\"{0}\":", column.ColumnName); WriteValue(sb, row[column]); sb.Append(","); } string cartid = string.Join("','", cid.Split(' ')); string sql = "select distinct id, proId, title, img, originPrice, price, count FROM V_Cart where id IN('" + cartid + "')"; DataTable table = CSql.CreateDataSet(sql, "CartData").Tables[0]; WriteSubDataTable(sb, table); sb.Append("}"); }
private static void WriteShop(StringBuilder sb, DataRow row, string sid) { sb.Append("{"); foreach (DataColumn column in row.Table.Columns) { sb.AppendFormat("\"{0}\":", column.ColumnName); WriteValue(sb, row[column]); sb.Append(","); } string sql = "select distinct id, proId, title, originPrice, price, count FROM V_Cart where isPay='0' AND shopID='" + sid + "'"; DataTable table = CSql.CreateDataSet(sql, "CartData").Tables[0]; WriteSubDataTable(sb, table); // Remove the trailing comma. //if (row.Table.Columns.Count > 0) //{ // --sb.Length; //} sb.Append("}"); }
// {orderList: [ // {shop: ..., CartData: [{},...] }}, // {} //]} public static string GetOrderListJSon(string uid, string ispay) { StringBuilder sb = new StringBuilder(); string sql = "SELECT id, uid, sid, shopName, shopIcon, payway, isPay, cartIdList, originPrice, discount, deliveryFee, remark FROM V_Order WHERE isPay LIKE'" + ispay + "' and uid='" + uid + "'"; DataTable table = CSql.CreateDataSet(sql, "OrderList").Tables[0]; string name = table.TableName; sb.Append("{\"" + name + "\":["); foreach (DataRow row in table.Rows) { string cid = row["cartIdList"].ToString(); WriteCartList(sb, row, cid); sb.Append(","); } // Remove the trailing comma. if (table.Rows.Count > 0) { --sb.Length; } sb.Append("]}"); return(sb.ToString()); }
public static string GetCartJSon(string uid) { StringBuilder sb = new StringBuilder(); string sql = "select distinct shopID, shopName, shopIcon FROM V_Cart where isPay='0' AND uid='" + uid + "'"; DataTable table = CSql.CreateDataSet(sql, "Shops").Tables[0]; string name = table.TableName; sb.Append("{\"" + name + "\":["); foreach (DataRow row in table.Rows) { string sid = row["shopID"].ToString(); WriteShop(sb, row, sid); sb.Append(","); } // Remove the trailing comma. if (table.Rows.Count > 0) { --sb.Length; } sb.Append("]}"); return(sb.ToString()); }