• C# easyui json类


    using System;
    using System.Data;
    using System.Text;
    namespace Common
    {
    	public class JsonHelp
    	{
    		private StringBuilder result = new StringBuilder();
    		private StringBuilder sb = new StringBuilder();
    		public string CreateComboboxJson(DataTable dt, int type)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			if (dt != null && dt.Rows.Count > 0)
    			{
    				StringBuilder stringBuilder2 = new StringBuilder();
    				stringBuilder2.Append("[");
    				if (type != 2)
    				{
    					stringBuilder2.Append("{ ");
    					stringBuilder2.Append(""id": ");
    					stringBuilder2.Append(-1 + ",");
    					stringBuilder2.Append(""text": ");
    					if (type == 1 || type == 3)
    					{
    						stringBuilder2.Append(""请选择"");
    					}
    					else
    					{
    						stringBuilder2.Append(""全部"");
    					}
    					DataRow[] array = dt.Select("IsDefault=1");
    					if ((type == 0 || array.Length == 0) && type != 3)
    					{
    						stringBuilder2.Append(","selected": ");
    						stringBuilder2.Append("true");
    					}
    					stringBuilder2.Append("},");
    				}
    				stringBuilder.Append(stringBuilder2.ToString());
    				for (int i = 0; i < dt.Rows.Count; i++)
    				{
    					if (i < dt.Rows.Count - 1)
    					{
    						stringBuilder.Append("{ ");
    						stringBuilder.Append(""id": ");
    						stringBuilder.Append(dt.Rows[i]["ID"] + ",");
    						stringBuilder.Append(""text": ");
    						stringBuilder.Append(""" + this.JsonCharFilter(dt.Rows[i]["name"].ToString()) + """);
    						if (dt.Rows[i]["IsDefault"].ToString() == "1" && type == 1)
    						{
    							stringBuilder.Append(","selected": ");
    							stringBuilder.Append("true");
    						}
    						stringBuilder.Append("},");
    					}
    					if (i == dt.Rows.Count - 1)
    					{
    						stringBuilder.Append("{ ");
    						stringBuilder.Append(""id": ");
    						stringBuilder.Append(dt.Rows[i]["ID"] + ",");
    						stringBuilder.Append(""text": ");
    						stringBuilder.Append(""" + this.JsonCharFilter(dt.Rows[i]["name"].ToString()) + """);
    						if (dt.Rows[i]["IsDefault"].ToString() == "1" && type == 1)
    						{
    							stringBuilder.Append(","selected": ");
    							stringBuilder.Append("true");
    						}
    						stringBuilder.Append("}");
    					}
    				}
    				stringBuilder.Append("]");
    				return stringBuilder.ToString();
    			}
    			stringBuilder.Append("[");
    			stringBuilder.Append("{ ");
    			stringBuilder.Append(""id": ");
    			stringBuilder.Append(-1 + ",");
    			stringBuilder.Append(""text": ");
    			stringBuilder.Append(""请选择"");
    			stringBuilder.Append("}");
    			stringBuilder.Append("]");
    			return stringBuilder.ToString();
    		}
    		public string ComboboxJson(DataTable dt, int warehouseid, int type)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			if (dt != null && dt.Rows.Count > 0)
    			{
    				StringBuilder stringBuilder2 = new StringBuilder();
    				stringBuilder2.Append("[");
    				stringBuilder.Append(stringBuilder2.ToString());
    				for (int i = 0; i < dt.Rows.Count; i++)
    				{
    					if (i < dt.Rows.Count - 1)
    					{
    						stringBuilder.Append("{ ");
    						stringBuilder.Append(""id": ");
    						stringBuilder.Append(dt.Rows[i]["ID"] + ",");
    						stringBuilder.Append(""text": ");
    						stringBuilder.Append(""" + this.JsonCharFilter(dt.Rows[i]["name"].ToString()) + """);
    						if ((dt.Rows[i]["name"].ToString() == "人民币" || dt.Rows[i]["ID"].ToString() == "3") && warehouseid == 1 && type == 1)
    						{
    							stringBuilder.Append(","selected": ");
    							stringBuilder.Append("true");
    						}
    						if ((dt.Rows[i]["name"].ToString() == "港币" || dt.Rows[i]["ID"].ToString() == "2") && warehouseid == 2 && type == 1)
    						{
    							stringBuilder.Append(","selected": ");
    							stringBuilder.Append("true");
    						}
    						stringBuilder.Append("},");
    					}
    					if (i == dt.Rows.Count - 1)
    					{
    						stringBuilder.Append("{ ");
    						stringBuilder.Append(""id": ");
    						stringBuilder.Append(dt.Rows[i]["ID"] + ",");
    						stringBuilder.Append(""text": ");
    						stringBuilder.Append(""" + this.JsonCharFilter(dt.Rows[i]["name"].ToString()) + """);
    						if ((dt.Rows[i]["name"].ToString() == "人民币" || dt.Rows[i]["ID"].ToString() == "3") && warehouseid == 1 && type == 1)
    						{
    							stringBuilder.Append(","selected": ");
    							stringBuilder.Append("true");
    						}
    						if ((dt.Rows[i]["name"].ToString() == "港币" || dt.Rows[i]["ID"].ToString() == "2") && warehouseid == 2 && type == 1)
    						{
    							stringBuilder.Append(","selected": ");
    							stringBuilder.Append("true");
    						}
    						stringBuilder.Append("}");
    					}
    				}
    				stringBuilder.Append("]");
    				return stringBuilder.ToString();
    			}
    			stringBuilder.Append("[");
    			stringBuilder.Append("{ ");
    			stringBuilder.Append(""id": ");
    			stringBuilder.Append(-1 + ",");
    			stringBuilder.Append(""text": ");
    			stringBuilder.Append(""请选择"");
    			stringBuilder.Append("}");
    			stringBuilder.Append("]");
    			return stringBuilder.ToString();
    		}
    		public string CreateComboboxJson(DataTable dt)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			if (dt != null && dt.Rows.Count > 0)
    			{
    				stringBuilder.Append("[ ");
    				for (int i = 0; i < dt.Rows.Count; i++)
    				{
    					if (i < dt.Rows.Count - 1)
    					{
    						stringBuilder.Append("{ ");
    						stringBuilder.Append(""id": ");
    						stringBuilder.Append(dt.Rows[i]["ID"] + ",");
    						stringBuilder.Append(""name": ");
    						stringBuilder.Append(""" + this.JsonCharFilter(dt.Rows[i]["name"].ToString()) + """);
    						stringBuilder.Append("},");
    					}
    					if (i == dt.Rows.Count - 1)
    					{
    						stringBuilder.Append("{ ");
    						stringBuilder.Append(""id": ");
    						stringBuilder.Append(dt.Rows[i]["ID"] + ",");
    						stringBuilder.Append(""name": ");
    						stringBuilder.Append(""" + this.JsonCharFilter(dt.Rows[i]["name"].ToString()) + """);
    						stringBuilder.Append("}");
    					}
    				}
    				stringBuilder.Append("]");
    				return stringBuilder.ToString();
    			}
    			stringBuilder.Append("[");
    			stringBuilder.Append("{ ");
    			stringBuilder.Append(""id": ");
    			stringBuilder.Append(-1 + ",");
    			stringBuilder.Append(""text": ");
    			stringBuilder.Append(""请选择"");
    			stringBuilder.Append("}");
    			stringBuilder.Append("]");
    			return stringBuilder.ToString();
    		}
    		public string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string rela, object pId, int type)
    		{
    			if (tabel.Rows.Count > 0)
    			{
    				this.sb.Append("[");
    				if (pId.ToString() == "0" && type == 1)
    				{
    					this.sb.Append("{"id":"0","text":"根目录","state":"open"");
    					this.sb.Append("},");
    				}
    				string filterExpression = string.Format("{0}='{1}'", rela, pId);
    				DataRow[] array = tabel.Select(filterExpression);
    				if (array.Length > 0)
    				{
    					DataRow[] array2 = array;
    					for (int i = 0; i < array2.Length; i++)
    					{
    						DataRow dataRow = array2[i];
    						this.sb.Append(string.Concat(new object[]
    						{
    							"{"id":"",
    							dataRow[idCol],
    							"","text":"",
    							dataRow[txtCol],
    							"","state":"open""
    						}));
    						if (tabel.Select(string.Format("{0}='{1}'", rela, dataRow[idCol])).Length > 0)
    						{
    							this.sb.Append(","children":");
    							this.GetTreeJsonByTable(tabel, idCol, txtCol, rela, dataRow[idCol], type);
    							this.result.Append(this.sb.ToString());
    						}
    						this.result.Append(this.sb.ToString());
    						this.sb.Append("},");
    					}
    					this.sb = this.sb.Remove(this.sb.Length - 1, 1);
    				}
    				this.sb.Append("]");
    				this.result.Append(this.sb.ToString());
    			}
    			return this.sb.ToString();
    		}
    		public string GetAdvancedRuleTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string rela, object pId)
    		{
    			if (tabel.Rows.Count > 0)
    			{
    				this.sb.Append("[");
    				if (pId.ToString() == "0")
    				{
    					this.sb.Append("{"id":"0","text":"最高权限","state":"open"");
    					this.sb.Append("},");
    				}
    				string filterExpression = string.Format("{0}='{1}'", rela, pId);
    				DataRow[] array = tabel.Select(filterExpression);
    				if (array.Length > 0)
    				{
    					DataRow[] array2 = array;
    					for (int i = 0; i < array2.Length; i++)
    					{
    						DataRow dataRow = array2[i];
    						this.sb.Append(string.Concat(new object[]
    						{
    							"{"id":"",
    							dataRow[idCol],
    							"","text":"",
    							dataRow[txtCol],
    							"","state":"open""
    						}));
    						if (tabel.Select(string.Format("{0}='{1}'", rela, dataRow[idCol])).Length > 0)
    						{
    							this.sb.Append(","children":");
    							this.GetAdvancedRuleTreeJsonByTable(tabel, idCol, txtCol, rela, dataRow[idCol]);
    							this.result.Append(this.sb.ToString());
    						}
    						this.result.Append(this.sb.ToString());
    						this.sb.Append("},");
    					}
    					this.sb = this.sb.Remove(this.sb.Length - 1, 1);
    				}
    				this.sb.Append("]");
    				this.result.Append(this.sb.ToString());
    			}
    			else
    			{
    				if (pId.ToString() == "0")
    				{
    					this.sb.Append("[");
    					this.sb.Append("{"id":"0","text":"最高权限","state":"open"");
    					this.sb.Append("}");
    					this.sb.Append("]");
    				}
    			}
    			return this.sb.ToString();
    		}
    		public string GetJsonTreeByTable(DataTable dt, string where)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			if (dt.Rows.Count > 0)
    			{
    				DataRow[] array = dt.Select(where, " Sequence asc");
    				stringBuilder.Append("[");
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["id"].ToString());
    					string text = array[i]["URL"].ToString();
    					if (!string.IsNullOrEmpty(text) && text.IndexOf('?') != -1)
    					{
    						text = text + "&pagesid=" + num;
    					}
    					else
    					{
    						if (!string.IsNullOrEmpty(text) && text.IndexOf('?') == -1)
    						{
    							text = text + "?&pagesid=" + num;
    						}
    					}
    					stringBuilder.Append(""attributes": {");
    					stringBuilder.Append(""url": "" + text + "",");
    					stringBuilder.Append(""isreloadid":"" + array[i]["isreloadid"].ToString() + """);
    					stringBuilder.Append("},");
    					stringBuilder.Append(""checked": false, ");
    					stringBuilder.Append(""iconCls": "ext-icon-medal_gold_3" ,");
    					if (array[i]["fatherid"].ToString() == "0")
    					{
    						stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					}
    					else
    					{
    						stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    						stringBuilder.Append(""pid": "" + array[i]["fatherid"].ToString() + "" ,");
    					}
    					stringBuilder.Append(""state": "open", ");
    					stringBuilder.Append(""text": "" + array[i]["Name"].ToString().Replace(""", "\"") + "" ");
    					if (i == array.Length - 1)
    					{
    						stringBuilder.Append("}");
    					}
    					else
    					{
    						stringBuilder.Append("},");
    					}
    				}
    				stringBuilder.Append("]");
    			}
    			else
    			{
    				stringBuilder.Append("[]");
    			}
    			return stringBuilder.ToString();
    		}
    		public string GetFatherNameByFatherID(DataTable dt, string fatherid)
    		{
    			DataRow[] array = dt.Select("id=" + fatherid);
    			if (array.Length > 0)
    			{
    				return array[0]["name"].ToString();
    			}
    			return "";
    		}
    		public string GetTreeList(DataTable dt)
    		{
    			DataRow[] array = dt.Select(" fatherid=0");
    			StringBuilder stringBuilder = new StringBuilder();
    			stringBuilder.Append("{"total":" + dt.Rows.Count + ","rows":");
    			stringBuilder.Append("[ ");
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["fatherid"].ToString());
    					int num2 = Convert.ToInt32(array[i]["pagetypeid"].ToString());
    					int num3 = Convert.ToInt32(array[i]["isreloadid"].ToString());
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""name": "" + array[i]["Name"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""seq": "" + array[i]["Sequence"].ToString() + "", ");
    					stringBuilder.Append(""url": "" + array[i]["url"].ToString().Replace(""", "\"") + "" ,");
    					stringBuilder.Append(""buttonid": "" + array[i]["buttonid"].ToString() + "" ,");
    					stringBuilder.Append(""fatherid": "" + num + "" ,");
    					stringBuilder.Append(""iconCls": "icon-ok" ,");
    					stringBuilder.Append(""pagetypename": "" + array[i]["pagetypename"].ToString().Replace(""", "\"") + "" ,");
    					stringBuilder.Append(""pagetypeid": "" + num2 + "" ,");
    					if (num3 == 1)
    					{
    						stringBuilder.Append(""isreloadid": "否" ,");
    					}
    					else
    					{
    						stringBuilder.Append(""isreloadid": "是" ,");
    					}
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.SetMenu(array[i]["ID"].ToString(), dt));
    				}
    			}
    			stringBuilder.Remove(stringBuilder.Length - 1, 1);
    			stringBuilder.Append("]}");
    			return stringBuilder.ToString();
    		}
    		public string GetAdvancedTreeList(DataTable dt)
    		{
    			DataRow[] array = dt.Select(" fatherid=0");
    			StringBuilder stringBuilder = new StringBuilder();
    			stringBuilder.Append("{"total":" + dt.Rows.Count + ","rows":");
    			stringBuilder.Append("[ ");
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["fatherid"].ToString());
    					int num2 = Convert.ToInt32(array[i]["userid"].ToString());
    					string str = array[i]["name"].ToString();
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""fatherid": "" + num + "" ,");
    					stringBuilder.Append(""userid": "" + num2 + "" ,");
    					stringBuilder.Append(""name": "" + str + "" ,");
    					stringBuilder.Append(""departmentname": "" + array[i]["departmentname"].ToString() + "" ,");
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.SetAdvancedMenu(array[i]["ID"].ToString(), dt));
    				}
    			}
    			stringBuilder.Remove(stringBuilder.Length - 1, 1);
    			stringBuilder.Append("]}");
    			return stringBuilder.ToString();
    		}
    		public string SetAdvancedMenu(string parentid, DataTable dt)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			DataRow[] array = dt.Select(" fatherid=" + parentid);
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["userid"].ToString());
    					string str = array[i]["name"].ToString();
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(string.Format(""_parentId": "{0}" ,", parentid));
    					stringBuilder.Append(""fatherid": "" + parentid + "" ,");
    					stringBuilder.Append(""userid": "" + num + "" ,");
    					stringBuilder.Append(""name": "" + str + "" ,");
    					stringBuilder.Append(""departmentname": "" + array[i]["departmentname"].ToString() + "" ,");
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.SetAdvancedMenu(array[i]["ID"].ToString(), dt));
    				}
    			}
    			return stringBuilder.ToString();
    		}
    		public string SetMenu(string parentid, DataTable dt)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			DataRow[] array = dt.Select(" fatherid=" + parentid);
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["pagetypeid"].ToString());
    					int num2 = Convert.ToInt32(array[i]["isreloadid"].ToString());
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""name": "" + array[i]["Name"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""seq": "" + array[i]["Sequence"].ToString() + "", ");
    					stringBuilder.Append(""url": "" + array[i]["url"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""buttonid": "" + array[i]["buttonid"].ToString().Replace(""", "\"") + "" ,");
    					stringBuilder.Append(string.Format(""_parentId": "{0}" ,", parentid));
    					stringBuilder.Append(""fatherid": "" + parentid + "" ,");
    					stringBuilder.Append(""pagetypename": "" + array[i]["pagetypename"].ToString().Replace(""", "\"") + "" ,");
    					stringBuilder.Append(""pagetypeid": "" + num + "" ,");
    					if (num2 == 1)
    					{
    						stringBuilder.Append(""isreloadid": "否" ,");
    					}
    					else
    					{
    						stringBuilder.Append(""isreloadid": "是" ,");
    					}
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.SetMenu(array[i]["ID"].ToString(), dt));
    				}
    			}
    			return stringBuilder.ToString();
    		}
    		public string GetJsonFromDataTable(DataTable dt, int total, bool isshowtotal = true)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			if (dt.Rows.Count == 0)
    			{
    				stringBuilder.Append("{ ");
    				stringBuilder.Append(""rows":[ ");
    				stringBuilder.Append("]");
    				if (isshowtotal)
    				{
    					stringBuilder.Append(",");
    					stringBuilder.Append(""total":");
    					stringBuilder.Append(total);
    				}
    				stringBuilder.Append("}");
    				return stringBuilder.ToString();
    			}
    			stringBuilder.Append("{ ");
    			stringBuilder.Append(""rows":[ ");
    			for (int i = 0; i < dt.Rows.Count; i++)
    			{
    				stringBuilder.Append("{ ");
    				for (int j = 0; j < dt.Columns.Count; j++)
    				{
    					if (j < dt.Columns.Count - 1)
    					{
    						stringBuilder.Append(string.Concat(new string[]
    						{
    							""",
    							dt.Columns[j].ColumnName.ToString().ToLower(),
    							"":"",
    							this.JsonCharFilter(dt.Rows[i][j].ToString()),
    							"","
    						}));
    					}
    					else
    					{
    						if (j == dt.Columns.Count - 1)
    						{
    							stringBuilder.Append(string.Concat(new string[]
    							{
    								""",
    								dt.Columns[j].ColumnName.ToString().ToLower(),
    								"":"",
    								this.JsonCharFilter(dt.Rows[i][j].ToString()),
    								"""
    							}));
    						}
    					}
    				}
    				if (i == dt.Rows.Count - 1)
    				{
    					stringBuilder.Append("} ");
    				}
    				else
    				{
    					stringBuilder.Append("}, ");
    				}
    			}
    			stringBuilder.Append("]");
    			if (isshowtotal)
    			{
    				stringBuilder.Append(",");
    				stringBuilder.Append(""total":");
    				stringBuilder.Append(total);
    			}
    			stringBuilder.Append("}");
    			return stringBuilder.ToString();
    		}
    		public string JsonCharFilter(string sourceStr)
    		{
    			sourceStr = sourceStr.Replace("\", "\\");
    			sourceStr = sourceStr.Replace(""", "\"");
    			sourceStr = sourceStr.Replace("", "\b");
    			sourceStr = sourceStr.Replace("	", "\t");
    			sourceStr = sourceStr.Replace("
    ", "\n");
    			sourceStr = sourceStr.Replace("f", "\f");
    			sourceStr = sourceStr.Replace("
    ", "\r");
    			return sourceStr;
    		}
    		public string DataTableToFomater(DataTable dt)
    		{
    			this.sb.Clear();
    			this.sb.Append("[{");
    			if (dt.Rows.Count > 0)
    			{
    				string text = dt.Rows[0][0].ToString();
    				if (text.IndexOf("成功") != -1)
    				{
    					this.sb.Append(""success":");
    					this.sb.Append("true,");
    				}
    				else
    				{
    					this.sb.Append(""success":");
    					this.sb.Append("false,");
    				}
    				this.sb.Append(""msg":");
    				this.sb.Append(""" + text + """);
    			}
    			this.sb.Append("}]");
    			return this.sb.ToString();
    		}
    		public string CheckLogin()
    		{
    			this.sb.Append("[{");
    			this.sb.Append(""success":");
    			this.sb.Append("false,");
    			this.sb.Append(""reload":");
    			this.sb.Append("true,");
    			this.sb.Append(""url":");
    			this.sb.Append(""/login.html",");
    			this.sb.Append(""msg":");
    			this.sb.Append(""非法操作,请重新登录"");
    			this.sb.Append("}]");
    			return this.sb.ToString();
    		}
    		public string GetJsonFromDataTable(DataTable dt, int total, bool ShowFooter, string fields, string inputfiled, string ShowMessage = "合计:", string filter = "")
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			if (dt.Rows.Count == 0)
    			{
    				stringBuilder.Append("{ ");
    				stringBuilder.Append(""rows":[ ");
    				stringBuilder.Append("]");
    				stringBuilder.Append(",");
    				stringBuilder.Append(""total":");
    				stringBuilder.Append(total);
    				stringBuilder.Append(","footer":[");
    				stringBuilder.Append("]");
    				stringBuilder.Append("}");
    				return stringBuilder.ToString();
    			}
    			stringBuilder.Append("{ ");
    			stringBuilder.Append(""rows":[ ");
    			for (int i = 0; i < dt.Rows.Count; i++)
    			{
    				stringBuilder.Append("{ ");
    				for (int j = 0; j < dt.Columns.Count; j++)
    				{
    					if (j < dt.Columns.Count - 1)
    					{
    						stringBuilder.Append(string.Concat(new string[]
    						{
    							""",
    							dt.Columns[j].ColumnName.ToString().ToLower(),
    							"":"",
    							this.JsonCharFilter(dt.Rows[i][j].ToString()),
    							"","
    						}));
    					}
    					else
    					{
    						if (j == dt.Columns.Count - 1)
    						{
    							stringBuilder.Append(string.Concat(new string[]
    							{
    								""",
    								dt.Columns[j].ColumnName.ToString().ToLower(),
    								"":"",
    								this.JsonCharFilter(dt.Rows[i][j].ToString()),
    								"""
    							}));
    						}
    					}
    				}
    				if (i == dt.Rows.Count - 1)
    				{
    					stringBuilder.Append("} ");
    				}
    				else
    				{
    					stringBuilder.Append("}, ");
    				}
    			}
    			stringBuilder.Append("]");
    			stringBuilder.Append(",");
    			stringBuilder.Append(""total":");
    			stringBuilder.Append(total);
    			if (ShowFooter && fields.Length > 0 && inputfiled.Length > 0)
    			{
    				stringBuilder.Append(","footer":[{");
    				stringBuilder.Append(string.Concat(new string[]
    				{
    					""",
    					inputfiled,
    					"":"<span style='color:red;  font-weight:bold'>",
    					ShowMessage,
    					"</span>","
    				}));
    				string[] array = fields.Split(new char[]
    				{
    					','
    				});
    				for (int k = 0; k < array.Length; k++)
    				{
    					if (k < array.Length - 1)
    					{
    						stringBuilder.Append(string.Concat(new object[]
    						{
    							""",
    							array[k],
    							"":"",
    							dt.Compute("sum(" + array[k] + ")", filter),
    							"","
    						}));
    					}
    					else
    					{
    						stringBuilder.Append(string.Concat(new object[]
    						{
    							""",
    							array[k],
    							"":"",
    							dt.Compute("sum(" + array[k] + ")", filter),
    							"""
    						}));
    					}
    				}
    				stringBuilder.Append("}]");
    			}
    			stringBuilder.Append("}");
    			return stringBuilder.ToString();
    		}
    		public string GetJsonFromDataTable()
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			stringBuilder.Append("{ ");
    			stringBuilder.Append(""rows":[ ");
    			stringBuilder.Append("]");
    			stringBuilder.Append(",");
    			stringBuilder.Append(""total":");
    			stringBuilder.Append(0);
    			stringBuilder.Append(","footer":[");
    			stringBuilder.Append("]");
    			stringBuilder.Append("}");
    			return stringBuilder.ToString();
    		}
    		public string ComBoxProductTree(DataTable tables)
    		{
    			DataRow[] array = tables.Select(" FatherID=0");
    			StringBuilder stringBuilder = new StringBuilder();
    			stringBuilder.Append("{"total":" + tables.Rows.Count + ","rows":");
    			stringBuilder.Append("[ ");
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["FatherID"].ToString());
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""productid": "" + array[i]["ProductID"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""productcode": "" + array[i]["ProductCode"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""productname": "" + array[i]["ProductName"].ToString().Replace(""", "\"") + "" ,");
    					stringBuilder.Append(""fatherid": "" + num + "" ,");
    					stringBuilder.Append(""qty": "" + array[i]["Quantity"].ToString() + "" ,");
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.GetComBoxProductTreeByFatherid(array[i]["ID"].ToString(), tables));
    				}
    			}
    			stringBuilder.Remove(stringBuilder.Length - 1, 1);
    			stringBuilder.Append("]}");
    			return stringBuilder.ToString();
    		}
    		public string GetComBoxProductTreeByFatherid(string fatherid, DataTable dt)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			DataRow[] array = dt.Select(" FatherID=" + fatherid);
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""productid": "" + array[i]["ProductID"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""productcode": "" + array[i]["ProductCode"].ToString().Replace(""", "\"") + "", ");
    					stringBuilder.Append(""productname": "" + array[i]["ProductName"].ToString().Replace(""", "\"") + "" ,");
    					stringBuilder.Append(""fatherid": "" + fatherid + "" ,");
    					stringBuilder.Append(""qty": "" + array[i]["Quantity"].ToString() + "" ,");
    					stringBuilder.Append(string.Format(""_parentId": "{0}" ,", fatherid));
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.GetComBoxProductTreeByFatherid(array[i]["ID"].ToString(), dt));
    				}
    			}
    			return stringBuilder.ToString();
    		}
    		public string GetProjectCostTreeList(DataTable dt)
    		{
    			DataRow[] array = dt.Select(" fatherid=0");
    			StringBuilder stringBuilder = new StringBuilder();
    			stringBuilder.Append("{"total":" + dt.Rows.Count + ","rows":");
    			stringBuilder.Append("[ ");
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["fatherid"].ToString());
    					int num2 = Convert.ToInt32(array[i]["projectid"].ToString());
    					string str = this.JsonCharFilter(array[i]["title"].ToString());
    					string str2 = this.JsonCharFilter(array[i]["costtypename"].ToString());
    					decimal num3 = Convert.ToDecimal(array[i]["price"].ToString());
    					int num4 = Convert.ToInt32(array[i]["costtypeid"].ToString());
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""fatherid": "" + num + "" ,");
    					stringBuilder.Append(""projectid": "" + num2 + "" ,");
    					stringBuilder.Append(""code": "" + array[i]["code"].ToString() + "" ,");
    					stringBuilder.Append(""title": "" + str + "" ,");
    					stringBuilder.Append(""costtypeid": "" + num4 + "" ,");
    					stringBuilder.Append(""costtypename": "" + str2 + "" ,");
    					stringBuilder.Append(""price": "" + num3 + "" ,");
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.SetProjectMenu(array[i]["ID"].ToString(), dt));
    				}
    			}
    			stringBuilder.Remove(stringBuilder.Length - 1, 1);
    			stringBuilder.Append("]}");
    			return stringBuilder.ToString();
    		}
    		public string SetProjectMenu(string parentid, DataTable dt)
    		{
    			StringBuilder stringBuilder = new StringBuilder();
    			DataRow[] array = dt.Select(" fatherid=" + parentid);
    			if (array.Length > 0)
    			{
    				for (int i = 0; i < array.Length; i++)
    				{
    					stringBuilder.Append("{ ");
    					int num = Convert.ToInt32(array[i]["fatherid"].ToString());
    					int num2 = Convert.ToInt32(array[i]["projectid"].ToString());
    					string str = this.JsonCharFilter(array[i]["title"].ToString());
    					string str2 = this.JsonCharFilter(array[i]["costtypename"].ToString());
    					decimal num3 = Convert.ToDecimal(array[i]["price"].ToString());
    					int num4 = Convert.ToInt32(array[i]["costtypeid"].ToString());
    					stringBuilder.Append(""id": "" + array[i]["ID"].ToString() + "" ,");
    					stringBuilder.Append(""fatherid": "" + num + "" ,");
    					stringBuilder.Append(""projectid": "" + num2 + "" ,");
    					stringBuilder.Append(""code": "" + array[i]["code"].ToString() + "" ,");
    					stringBuilder.Append(""title": "" + str + "" ,");
    					stringBuilder.Append(""costtypeid": "" + num4 + "" ,");
    					stringBuilder.Append(""costtypename": "" + str2 + "" ,");
    					stringBuilder.Append(""price": "" + num3 + "" ,");
    					stringBuilder.Append(string.Format(""_parentId": "{0}" ,", parentid));
    					stringBuilder.Append(""state": "closed" ");
    					stringBuilder.Append("},");
    					stringBuilder.Append(this.SetAdvancedMenu(array[i]["ID"].ToString(), dt));
    				}
    			}
    			return stringBuilder.ToString();
    		}
    		public DataTable CreateDataTable()
    		{
    			DataTable dataTable = new DataTable();
    			dataTable.Columns.Add("abc", typeof(string));
    			DataRow dataRow = dataTable.NewRow();
    			object[] itemArray = new object[]
    			{
    				"操作失败"
    			};
    			dataRow.ItemArray = itemArray;
    			dataTable.Rows.Add(dataRow);
    			return dataTable;
    		}
    	}
    }
    

      

  • 相关阅读:
    C语言 strcat
    C语言 strncpy
    C语言 strcpy
    C语言 main
    可显示Android设备选择列表,并进入指定Android设备Console的Shell脚本
    Android系统如何录制屏幕(录制成mp4格式)
    据说有99%的人都会做错的面试题
    一道淘汰85%面试者的百度开发者面试题
    用Android模拟器也可以开发和测试NFC应用
    一道腾讯面试题的思考:到底谁会赢?
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/3471157.html
Copyright © 2020-2023  润新知