[一籃飯特稀原創,轉載請註明出自http://www.cnblogs.com/wanghafan/p/4754769.html] html
JsonWriter使用:json
前臺post
1 $.post("Ajax_EstimatedIncome.aspx/GetEstimatedIncomePlus", { ProjectID: m_EstimatedIncomeTEN.ProjectID }, function (json) { 2 var m = eval('(' + json + ')'); 3 var m_ProjectTEN = eval('(' + m.ProjectTEN + ')'); 4 var m_ProjectPlugTEN = eval('(' + m.ProjectPlugTEN + ')'); 5 var m_CustomersTEN = eval('(' + m.CustomersTEN + ')'); 6 $('#form1 input[name="Stock"]').val(m.Stock); 7 $('#form1 input[name="EstimatedID"]').val(m_EstimatedIncomeTEN.EstimatedID); 8 $('#form1 input[name="BluntMonney"]').val(m_EstimatedIncomeTEN.BluntMonney); 9 $('#form1 input[name="BluntMonneyA"]').val(m_EstimatedIncomeTEN.BluntMonneyA); 10 $('#form1 input[name="CreateDate"]').val(CreateDate.getFullYear() + "-" + (CreateDate.getMonth() + 1) + "-" + CreateDate.getDate()); 11 $('#form1 input[name="CustomersName"]').val(m_CustomersTEN.ShortName); 12 $('#form1 input[name="DesignFee"]').val(m_ProjectTEN.DesignFee); 13 $('#form1 input[name="EstimatedCost"]').val(m_EstimatedIncomeTEN.EstimatedCost); 14 $('#form1 input[name="EstimatedDate"]').val(EstimatedDate.getFullYear() + "-" + (EstimatedDate.getMonth() + 1)); 15 $('#form1 input[name="EstimatedMonney"]').val(m_EstimatedIncomeTEN.EstimatedMonney); 16 $('#form1 input[name="EstimatedMonneyA"]').val(m_EstimatedIncomeTEN.EstimatedMonneyA); 17 $('#form1 input[name="EstimatedRatio"]').val(m_EstimatedIncomeTEN.EstimatedRatio); 18 $('#form1 input[name="MyProjectNo"]').val(m_ProjectTEN.MyProjectNo); 19 $('#form1 input[name="ProjectName"]').val(m_ProjectTEN.ProjectName); 20 $('#form1 input[name="ProjectNum"]').val(m_ProjectTEN.ProjectNum); 21 $('#form1 input[name="BluntDate"]').val(EstimatedDate.getFullYear() + "-" + (EstimatedDate.getMonth() + 1)); 22 $('#form1 input[name="Remark"]').val(m_EstimatedIncomeTEN.Remark); 23 $('#form1 input[name="EstimatedRatio"]').val(m_EstimatedIncomeTEN.EstimatedRatio); 24 $('#form1 input[name="UserName"]').val(m_EstimatedIncomeTEN.UserName); 25 $('#form1 input[name="CreaterID"]').val(m_EstimatedIncomeTEN.UserID); 26 if (m_ProjectPlugTEN.ProjectRange == 0) 27 $('#form1 input[name=ProjectRange]').val('自營'); 28 else if (m_ProjectPlugTEN.ProjectRange == 1) 29 $('#form1 input[name=ProjectRange]').val('分包'); 30 else if (m_ProjectPlugTEN.ProjectRange == 2) 31 $('#form1 input[name=ProjectRange]').val('代理'); 32 $('#form1 input[name="ProjectID"]').val(m_EstimatedIncomeTEN.ProjectID); 33 });
後臺ui
1 [WebMethod(EnableSession = true)] 2 public string GetEstimatedIncomePlus() 3 { 4 string ProjectID = Request.Params["ProjectID"] == null ? "0" : Request.Params["ProjectID"].ToString(); 5 try 6 { 7 m_ProjectTEN = bll_ProjectTEO.GetModel(long.Parse(ProjectID)); 8 m_ProjectPlugTEN = bll_ProjectPlugTEO.GetModel(m_ProjectTEN.ProjectPlugID); 9 m_CustomersTEN = bll_CustomersTEO.GetModel(m_ProjectPlugTEN.CustomersID.Value); 10 string Stock = "0"; 11 DataTable dt_ProjectSum = bll_ProjectSumTEO.GetList_Detail("ProjectID=" + ProjectID); 12 if (dt_ProjectSum != null && dt_ProjectSum.Rows.Count > 0) 13 Stock = dt_ProjectSum.Rows[0]["Stock"].ToString(); 14 else 15 Stock = Global.Precision; 16 string UserName = string.Empty; 17 if (ND.Webs.Outsourcing.PlatBase.Business.PlatBaseUserTBO.LoginInfo != null) 18 UserName = ND.Webs.Outsourcing.PlatBase.Business.PlatBaseUserTBO.LoginInfo.UserName; 19 int UserID = 0; 20 if (ND.Webs.Outsourcing.PlatBase.Business.PlatBaseUserTBO.LoginInfo != null) 21 UserID=ND.Webs.Outsourcing.PlatBase.Business.PlatBaseUserTBO.LoginInfo.UserID; 22 StringWriter sw = new StringWriter(); 23 using (JsonWriter writer = new JsonTextWriter(sw)) 24 { 25 writer.Formatting = Formatting.Indented; 26 writer.WriteStartObject(); 27 writer.WritePropertyName("ProjectTEN"); 28 writer.WriteValue(JsonConvert.SerializeObject(m_ProjectTEN)); 29 writer.WritePropertyName("ProjectPlugTEN"); 30 writer.WriteValue(JsonConvert.SerializeObject(m_ProjectPlugTEN)); 31 writer.WritePropertyName("CustomersTEN"); 32 writer.WriteValue(JsonConvert.SerializeObject(m_CustomersTEN)); 33 writer.WritePropertyName("Stock"); 34 writer.WriteValue(Stock); 35 writer.WritePropertyName("UserName"); 36 writer.WriteValue(UserName); 37 writer.WritePropertyName("UserID"); 38 writer.WriteValue(UserID); 39 writer.WriteEndObject(); 40 writer.Flush(); 41 } 42 sw.Close(); 43 return sw.GetStringBuilder().ToString(); 44 } 45 catch (Exception ex) 46 { 47 return "Error"; 48 } 49 }