首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web Service >

Silverlight 中 控件DataGrid 怎么绑定 WebService 中 DataSet的值

2012-01-07 
Silverlight中 控件DataGrid如何绑定WebService中DataSet的值Silverlight中 控件DataGrid如何绑定WebServi

Silverlight 中 控件DataGrid 如何绑定 WebService 中 DataSet的值
Silverlight 中 控件DataGrid 如何绑定 WebService 中 DataSet的值

实体类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace Apparel_Models
{
  [Serializable]
  [XmlRoot("UserDaily")] 
  public class UserDaily
  {
  private int id;

  public int Id
  {
  get { return id; }
  set { id = value; }
  }
  private string eQPQTYName;

  public string EQPQTYName
  {
  get { return eQPQTYName; }
  set { eQPQTYName = value; }
  }

  private decimal charge;

  public decimal Charge
  {
  get { return charge; }
  set { charge = value; }
  }

  private decimal noCharge;

  public decimal NoCharge
  {
  get { return noCharge; }
  set { noCharge = value; }
  }


  private decimal sETUP;

  public decimal SETUP
  {
  get { return sETUP; }
  set { sETUP = value; }
  }

  private decimal iDLE;

  public decimal IDLE
  {
  get { return iDLE; }
  set { iDLE = value; }
  }

  private decimal eNGR;

  public decimal ENGR
  {
  get { return eNGR; }
  set { eNGR = value; }
  }

  private decimal pM;

  public decimal PM
  {
  get { return pM; }
  set { pM = value; }
  }

  private decimal dOWN;

  public decimal DOWN
  {
  get { return dOWN; }
  set { dOWN = value; }
  }

  private decimal cOEETarget;

  public decimal COEETarget
  {
  get { return cOEETarget; }
  set { cOEETarget = value; }
  }

  private decimal cOEE;

  public decimal COEE
  {
  get { return cOEE; }
  set { cOEE = value; }
  }

  private decimal cOEETargetIDLE;

  public decimal COEETargetIDLE
  {
  get { return cOEETargetIDLE; }
  set { cOEETargetIDLE = value; }
  }

  private decimal cOEEIDLE;

  public decimal COEEIDLE
  {
  get { return cOEEIDLE; }
  set { cOEEIDLE = value; }
  }

  public UserDaily()
  { }

   

  }
}


---Dal层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apparel_Models;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using Apparel_DBUtility;


namespace Apparel_DAL
{
  public class UserDailyService
  {
  /// <summary>
  /// 获取所有的信息,测试表。测试Silverlight
  /// </summary>


  /// <returns></returns>
  public IList<UserDaily> GetAllUserDaily()
  {
  IList<UserDaily> userDailys = new List<UserDaily>();
  string sql = "SELECT * FROM [Demo].[dbo].[DemoText]";
  using(SqlDataReader sdr=SQLHelper.ExecuteReader(SQLHelper.ConnectionStringLocalTransaction,CommandType.Text,sql,null ))
  {
  while (sdr.Read())
  {
  //ID, EQPQTYName, Charge, NoCharge, SETUP, IDLE, ENGR, PM,
  // DOWN, COEETarget, COEE, COEETargetIDLE, COEEIDLE
  UserDaily ud = new UserDaily();
  ud.Id = Convert.ToInt32(sdr["ID"].ToString());
  ud.EQPQTYName = Convert.ToString(sdr["EQPQTYName"].ToString());
  ud.Charge = Convert.ToDecimal(sdr["Charge"].ToString());
  ud.NoCharge = Convert.ToDecimal(sdr["NoCharge"].ToString());
  ud.SETUP = Convert.ToDecimal(sdr["SETUP"].ToString());
  ud.IDLE = Convert.ToDecimal(sdr["IDLE"].ToString());
  ud.ENGR = Convert.ToDecimal(sdr["ENGR"].ToString());
  ud.PM = Convert.ToDecimal(sdr["PM"].ToString());
  ud.DOWN = Convert.ToDecimal(sdr["DOWN"].ToString());
  ud.COEETarget = Convert.ToDecimal(sdr["COEETarget"].ToString());
  ud.COEE = Convert.ToDecimal(sdr["COEE"].ToString());
  ud.COEETargetIDLE = Convert.ToDecimal(sdr["COEETargetIDLE"].ToString());
  ud.COEEIDLE = Convert.ToDecimal(sdr["COEEIDLE"].ToString());
  userDailys.Add(ud);

  }
  }


  return userDailys;
  }

  /// <summary>
  /// 获取所有的信息,测试表。测试Silverlight。DataSet
  /// </summary>
  /// <returns></returns>
  public DataSet GetAllUserDailys()
  {
  DataSet ds = new DataSet();
  string sql = "SELECT * FROM [Demo].[dbo].[DemoText]";
  SqlDataAdapter sda = new SqlDataAdapter(sql,SQLHelper.ConnectionStringLocalTransaction);
  DataTable tb = new DataTable();
  sda.Fill(tb);
  ds.Tables.Add(tb);
  return ds;
  }

  }
}
---BLL层
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Apparel_DAL;
using Apparel_Models;
using System.Data;
using System.Data.SqlClient;


namespace Apparel_BLL
{
  public class UserDailyManger
  {
  UserDailyService uss = new UserDailyService();

  /// <summary>
  /// 获取所有的信息,测试表。测试Silverlight
  /// </summary>
  /// <returns></returns>
  public IList<UserDaily> GetAllUserDaily()
  {
  return uss.GetAllUserDaily();
  }



  /// <summary>
  /// 获取所有的信息,测试表。测试Silverlight。DataSet
  /// </summary>
  /// <returns></returns>
  public DataSet GetAllUserDailys()
  {
  return uss.GetAllUserDailys();
  }


  }
}


---WebService  

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Apparel_BLL;
using Apparel_Models;
using System.Xml.Serialization;
using System.Data;
using System.Data.SqlClient;


namespace ApparelSilverlightPro.Web
{

  [XmlInclude(typeof(UserDaily))]
  /// <summary>
  /// ApparelWebService 的摘要说明
  /// </summary>
  [WebService(Namespace = "http://tempuri.org/")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
  [System.ComponentModel.ToolboxItem(false)]
  // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
  // [System.Web.Script.Services.ScriptService]
  public class ApparelWebService : System.Web.Services.WebService
  {

   
  UserDailyManger umm = new UserDailyManger();


  [WebMethod]
  public string HelloWorld()
  {
  return "Hello World";
  }

  /// <summary>
  /// 获取所有的信息,测试表。测试Silverlight
  /// </summary>
  /// <returns></returns>
  //[WebMethod]
  //public IList<UserDaily> GetAllUserDaily()
  //{
  // return umm.GetAllUserDaily();
  //}


   
  ///// <summary>
  ///// 获取所有的信息,测试表。测试Silverlight。DataSet
  ///// </summary>
  ///// <returns></returns>
  [WebMethod]
  public DataSet GetAllUserDailys()
  {
  return umm.GetAllUserDailys();
  }
  }
}



----

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ApparelSilverlightPro.ApparelServiceReference;
using System.Xml;
using System.Xml.Schema;
using System.Configuration;


namespace ApparelSilverlightPro
{
  public partial class MainPage : UserControl
  {
  ApparelWebServiceSoapClient wbap = new ApparelWebServiceSoapClient();
  public MainPage()
  {
  InitializeComponent(); 


  --问题在这里,我怎么把值付给,dataGrid  
  }

   



  }
}


[解决办法]
异步

没有DataSet概念。

DataCmdClient webclient = new DataCmdClient();
webclient.GetRoad_PathInfoCompleted += new EventHandler<DBServiceClient.GetRoad_PathInfoCompletedEventArgs>(webclient_GetRoad_PathInfoCompleted);
webclient.GetRoad_PathInfoAsync();

热点排行