zoukankan      html  css  js  c++  java
  • 关于dataGrid查询按钮的实现

    纠结了好久的数据查询,今天终于有点进展,虽然还没有能够做出登陆程序,但是我觉得已经非常接近了。

    domain server.cs这个类,里面的成员,你会发现,里面有查询,修改,删除,更新这些功能

     public IQueryable<contents> GetContents()
            {
                return this.ObjectContext.contents;
            }
    

     这是查询的功能,返回的是一个contents实体,如果你要修改,返回你想指定的实体,那么你要这样修改

     public IQueryable<contents> GetContentsByType(string type) {
                return this.ObjectContext.contents.Where(c=>c.name==type);
            }
    

     上面返回的是经过查询的实体,调用的时候,你只需要调用这么方法

    插入:

    public void InsertContents(contents contents)
            {
                if ((contents.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(contents, EntityState.Added);
                }
                else
                {
                    this.ObjectContext.contents.AddObject(contents);
                }
            }
    

     更新:

    public void UpdateContents(contents currentcontents)
            {
                this.ObjectContext.contents.AttachAsModified(currentcontents, this.ChangeSet.GetOriginal(currentcontents));
            }
    

     删除:

    public void DeleteContents(contents contents)
            {
                if ((contents.EntityState != EntityState.Detached))
                {
                    this.ObjectContext.ObjectStateManager.ChangeObjectState(contents, EntityState.Deleted);
                }
                else
                {
                    this.ObjectContext.contents.Attach(contents);
                    this.ObjectContext.contents.DeleteObject(contents);
                }
            }
    

     用datagrid作例子:代码页很简单

    namespace testBox
    {
        public partial class MainPage : UserControl
        {
            testBoxDomainService1 test;
            public MainPage()
            {
                test = new testBoxDomainService1();
                InitializeComponent();
                binddata();
              
            }
            private void binddata() {
                dataGrid2.ItemsSource = test.contents;
                test.Load(test.GetContentsQuery());
                
            
            }
    
            private void chaxun_click(object sender, RoutedEventArgs e)
            {
                testBoxDomainService1 test2 = new testBoxDomainService1();
                string s =textBox1.Text;
                dataGrid1.ItemsSource = test2.contents;
                test2.Load(test2.GetContentsByTypeQuery(s));
            }
        }
    }
    

     前台只需要把autogeneratecolumn设置为true,让其自动生成

    就可以实现这样的功能:

  • 相关阅读:
    C++类型转换(字符串)
    GDI+ 中Image::FromStream ,用流的方式显示图像
    mfc对话框序列化实例
    配置android开发环境eclipse获取ADT获取不到(转)
    vs开发错误总结
    MFC获取文件操作
    Android系统架构剖析(转)
    OpenCV 图像采样 插值 几何变换
    C++ char*,char[],string,CString转换
    Simscape Multibody 教程 —— 入门学习
  • 原文地址:https://www.cnblogs.com/lihaozhou/p/2608365.html
Copyright © 2011-2022 走看看