silverlight应用:使用SilverLight构建插件式应用程序( 6)

  留言板插件开发-插件留言显示:

  留言板是整个系统第个可以和用户交互插件插件实现了登录用户留言系统从数据库获取功能

使用SilverLight构建插件式应用<img src='/icons/14443chengxu.gif' />( 6)

  首先看服务器提供数据功能:

/// <summary>
  /// 获取留言总条数
  /// </summary>
  /// <s>留言条数</s>
  [OperationContract]
  public GetNotesCount
  {
    NotesBLL bll = NotesBLL;
     bll.GetNotesCount;
  } 
  /// <summary>
  /// 获取指定页码和大小留言
  /// </summary>
  /// <param name="pageNumber">页码</param>
  /// <param name="pageSize">大小</param>
  /// <s>留言</s>
  [OperationContract]
  public List<NotesInfo> GetNotesByPage( pageNumber, pageSize)
  {
    NotesBLL bll = NotesBLL;
     bll.GetNotesByPage(pageNumber,pageSize);
  }


  下面看看客户端代码:

  整个客户单和显示有关有3个对象;

  NotesItem:显示留言项;

  留言项基本就是个XAML界面每条留言需要显示内容

  NotesPage:显示留言页;

  容纳留言项界面没有更多代码

  NotesMain.xaml:显示留言主界面;

  这是整个插件核心部分实现了读取数据生成数据项显示翻页等等功能

  1:实现IPlugIn接口这个是每个插件都要实现功能;

  2:获取整个留言页数为分页显示最准备下面是代码:

private void DataCount
    {
      Uri uri = .Windows.Browser.HtmlPage.Document.DocumentUri;
       host = uri.AbsoluteUri;
      host = host.Sub(0, host.Length - uri.LocalPath.Length);
       servicePath = "/Services/WSNotes.svc";
       serviceUri = host + servicePath;
      //
      WSNotesClient ws = WSNotesClient( .ServiceModel.BasicHttpBinding, .ServiceModel.EndpoAddress(serviceUri));
      ws.GetNotesCountCompleted (o, ev) =>
      {
         (ev.Error null)
        {
           tmpCount = ev.Result / PageSize;
           (tmpCount * PageSize ev.Result)
          {
            PageCount = tmpCount;
          }
          
          {
            PageCount = tmpCount + 1;
          }
          this.txtPageCount.Text = "/" + PageCount;
          //
          DataLoad(1);
        }
      };
      ws.GetNotesCountAsync;
    }


  3:显示指定页码内容:

//
      Uri uri = .Windows.Browser.HtmlPage.Document.DocumentUri;
       host = uri.AbsoluteUri;
      host = host.Sub(0, host.Length - uri.LocalPath.Length);
       servicePath = "/Services/WSNotes.svc";
       serviceUri = host + servicePath;
      //
      WSNotesClient ws = WSNotesClient( .ServiceModel.BasicHttpBinding, .ServiceModel.EndpoAddress(serviceUri));
      ws.GetNotesByPageCompleted (o, e) =>
        {
           (e.Error null)
          {
            ObservableCollection<NotesInfo> notesInfo = e.Result;
             itemCount = notesInfo.Count;
  
            NotesPage page = NotesPage;
            for ( iItem = 0; iItem < itemCount; iItem)
            {
              NotesItem item = NotesItem;
  
              Thickness thicknessi = Thickness;
              thicknessi.Top = 5;
              thicknessi.Bottom = 5;
              item.Margin = thicknessi;
              item.notesTitle.Text = notesInfo[iItem].Title;
              item.notesText.Text = notesInfo[iItem].Content;
              item.AuthorName.Text = notesInfo[iItem].UserName;
              item.AuthorImage.Source = ResourceHelper.GetBitmap("Resources/Images/self.png", this.GetType.Namespace);
              page.panelPageItem.Children.Add(item);
            }
  
            Thickness thickness = Thickness;
            thickness.Top = 10;
            thickness.Bottom = 10;
            page.Margin = thickness;
            page.PageFooter.Text = pageNumber.;
  
            this.txtPageNumber.Text = pageNumber.;
  
            this.panelPages.Children.Clear;
            this.panelPages.Children.Add(page);
  
          }
          //如果在xaml界面直接使用这两个属性运行就会报错
          //在这个地方设定没有
          ScrollPages.SetValue(Grid.RowProperty, 1);
          ScrollPages.SetValue(Grid.ColumnProperty, 1);
        };
      ws.GetNotesByPageAsync(pageNumber,PageSize);




  4:控制翻页状态

tag = ((Button)sender).Tag.;
       (tag "First")
      {
        PageNumber = 1;
      }
       (tag "Prview")
      {
        PageNumber = PageNumber - 1; ;
      }
       (tag "Next")
      {
        PageNumber = PageNumber + 1; ;
      }
       (tag "Last")
      {
        PageNumber = PageCount;
      }
       (tag "Goto")
      {
         tmp=PageNumber;
         (.TryParse(this.txtPageNumber.Text, out tmp))
        {
          PageNumber = tmp;
        }
        
        {
          MessageBox.Show("你输入页码不是整数请重新输入","提示",MessageBoxButton.OK);
        }
  
      }
      DataLoad(PageNumber);


  至此整个留言显示完成,如果用户需要留言请先注册登陆个Blog写如何填写留言

  演示地址:www.cuface.cn



Tags:  silverlight.2.0 silverlight是什么 silverlight silverlight应用

延伸阅读

最新评论

发表评论