/* * public string getJSONRow(DataRow rw) * { * DataTable res = rw.Table; * string s = "{"; * for (int j = 0; j < res.Columns.Count; j++) * { * string fs = @"""" + res.Columns[j].ColumnName + @""":"; * string val = DBClient.strEscape(rw[j].ToString()); * * if (rw[j] != DBNull.Value) * { * if (res.Columns[j].DataType == typeof(System.Double)) * * val = ((Double)rw[j]).ToString("#,##0.00"); * * if (res.Columns[j].DataType == typeof(System.DateTime)) * val = ((DateTime)rw[j]).ToString("dd.MM.yyyy HH:mm"); * } * * * fs = fs + @"""" + val + @""""; * * * if (j == res.Columns.Count - 1) * s = s + fs + "}"; * else * s = s + fs + ","; * } * return s; * } */ public string getJSONRow(DataRow rw, Dictionary <string, string> formats) { if (formats == null) { formats = new Dictionary <string, string>(); } DataTable res = rw.Table; string s = "{"; for (int j = 0; j < res.Columns.Count; j++) { string fs = @"""" + res.Columns[j].ColumnName + @""":"; string val = DBClient.strEscape(rw[j].ToString()); //01.08.2016 картинка if (res.Columns[j].ColumnName == "image_bmp" & !String.IsNullOrEmpty(val)) { val = @"<img src='data:image/gif;base64," + val + @"'/>"; } //05.10.2016 if (res.Columns[j].ColumnName == "Color") { if (rw[j] != DBNull.Value) { Color cl = Color.FromArgb((int)rw[j]); val = "#" + ((int)cl.R).ToString("X") + ((int)cl.G).ToString("X") + ((int)cl.B).ToString("X"); } else { val = "#FFFFFF"; } } if (rw[j] != DBNull.Value) { if (res.Columns[j].DataType == typeof(System.Double)) { if (formats.ContainsKey(res.Columns[j].ColumnName)) { val = ((Double)rw[j]).ToString(formats[res.Columns[j].ColumnName]); } else { val = ((Double)rw[j]).ToString("#,##0.00"); } } if (res.Columns[j].DataType == typeof(System.DateTime)) { if (formats.ContainsKey(res.Columns[j].ColumnName)) { val = ((DateTime)rw[j]).ToString(formats[res.Columns[j].ColumnName]); } else { val = ((DateTime)rw[j]).ToString("dd.MM.yyyy"); } } } fs = fs + @"""" + val + @""""; if (j == res.Columns.Count - 1) { s = s + fs + "}"; } else { s = s + fs + ","; } } return(s); }