C#将列表转换为可观察的集合 [英] C# Convert List to Observable Collection

查看:503
本文介绍了C#将列表转换为可观察的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我有一个C#(我是新来的)类,它返回List.我想将其转换为一个Observable集合,以便可以使用INotify ...事件.我没有使用实体框架.只是一个标准类,它调用存储过程.

I have a C# (which I am new to) Class which returns a List . I would like to convert this to an Observable Collection, so that I may use the INotify... event. I am not using Entity Framework. Just a standard class which calls a stored procedure.

有人可以指导我如何轻松地将我的列表转换为可观察的集合吗?

Can someone please direct me on how to easily convert my List to an Observable Collection ?

这是我的代码:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations; // ►►► Provides the support for defining metadata (Key, Required, etc.)
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.ObjectModel;


namespace CorporateHR.Web
{
  public class PatientStatus
  {
    [Key]
    // These Properties correspond to Patient Status columns in the Stored Procedure
    public int   PatIdS3 { get; set; }
    public double  PatIdEssentris { get; set; }
    //[Required(ErrorMessage = "PatIdEssentris is required.")]
    public string  PatIdShort { get; set; }
    //[Required(ErrorMessage = "Patient Key is required.")]
    public string  DuplicateShortId { get; set; }
    public string  EssentrisPatientName { get; set; }
    public string  S3PatientName { get; set; }
    public int   MaxStatusOR { get; set; }
    public string  StatusDescription { get; set; }
    public string  AdmitDateStr { get; set; }
    public string  BDate { get; set; }
    public int   StatusRx { get; set; }
    public int   Room { get; set; }
    public int   Case { get; set; }
    public string  PatientName { get; set; }
    public string  Procedure { get; set; }

    public string  Surgeon { get; set; }
    public string  Anesthesiologist { get; set; }
    public bool   HideRow { get; set; }
    public string  Remarks { get; set; }
    public string  RxDescription { get; set; }
    public bool   Isolation { get; set; }
    public string  OREnterTime { get; set; }
    public string  InductCompleteTime { get; set; }
    public string  TimeOutCompleted { get; set; }
    public string  TimeBegin { get; set; }
    public string  TimeEnd { get; set; }
    public string  ORExitTime { get; set; }
   
    public string  DOBS3 { get; set; }
    public string  SexS3 { get; set; }

   
    public static List<PatientStatus> GetPatientStatusRowsAll()
    {
      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["RefConnectionString"].ConnectionString);
      SqlCommand cmd = new SqlCommand("usptblPatientStatusSelect", con);
      cmd.CommandType = System.Data.CommandType.StoredProcedure;

      
      List<PatientStatus> PatientStatuses = new List<PatientStatus>();
      con.Open();
      SqlDataReader dr = cmd.ExecuteReader(behavior: CommandBehavior.CloseConnection);
      while (dr.Read())
      {
        PatientStatus ps = new PatientStatus();
        ps.Room = Convert.ToInt16(dr["Room"].ToString());
        ps.Case = Convert.ToInt16(dr["Case"].ToString());
        ps.PatIdS3 = Convert.ToInt32(dr["PatIdS3"].ToString());
        ps.PatIdEssentris = Convert.ToDouble(dr["PatIdEssentris"].ToString());
        ps.PatIdShort = dr["PatIdShort"].ToString();
        ps.DuplicateShortId = dr["DuplicateShortId"].ToString();
        ps.S3PatientName = dr["S3PatientName"].ToString();
        ps.EssentrisPatientName = dr["EssentrisPatientName"].ToString();
        ps.MaxStatusOR = Convert.ToInt16(dr["MaxStatusOR"].ToString());
        ps.StatusDescription = dr["StatusDescription"].ToString();
    
        ps.StatusRx = Convert.ToInt16(dr["StatusRx"].ToString());
        ps.RxDescription = dr["RxDescription"].ToString();
       
        ps.Procedure = dr["Procedure"].ToString();
        ps.Surgeon = dr["Surgeon"].ToString();
        ps.Anesthesiologist = dr["Anesthesiologist"].ToString();
        ps.HideRow = Convert.ToBoolean(dr["HideRow"].ToString());
        ps.Remarks = dr["Remarks"].ToString();
        ps.Isolation = Convert.ToBoolean(dr["Isolation"].ToString());
        ps.AdmitDateStr = dr["AdmitDateStr"].ToString();
        ps.BDate = dr["BDate"].ToString();
        
        
        ps.OREnterTime = dr["OREnterTime"].ToString();
        ps.InductCompleteTime = dr["InductCompleteTime"].ToString();
        ps.TimeOutCompleted = dr["TimeOutCompleted"].ToString();
        ps.TimeBegin = dr["TimeBegin"].ToString();
        ps.TimeEnd = dr["TimeEnd"].ToString();
        ps.ORExitTime = dr["ORExitTime"].ToString();
// Need to Include: S3Rank, S3DOB, and S3Sex
        ps.DOBS3 = dr["DOBS3"].ToString();
        ps.SexS3 = dr["SexS3"].ToString();

        PatientStatuses.Add(ps);
      }
      return PatientStatuses;
    }

    
  }

  

}



推荐答案

http://msdn.microsoft.com/en-us/library/ms653202.aspx

阅读.

致谢


这篇关于C#将列表转换为可观察的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆