码迷,mamicode.com
首页 > 其他好文 > 详细

浅谈DevExpress<二>:设计一个完整界面(2)

时间:2014-05-31 12:39:30      阅读:284      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

  下面来把剩下的工作做完,换肤功能昨天已近讨论过,今天就不重复了。首先建立三个全局变量,一个存放文件路径,一个存放数据,一个存放过滤条件。

        string DBFileName;
        DataView dataView;
        string[] filter = new string[3];

  取得数据并绑定到表格中:

bubuko.com,布布扣
 DBFileName = DevExpress.Utils.FilesHelper.FindingFileName(Application.StartupPath, "Products.xml");

            if (!string.IsNullOrEmpty(DBFileName))
            {
                DataSet dt = new DataSet();
                dt.ReadXml(DBFileName);
                gridControl1.DataSource = dataView = dt.Tables[0].DefaultView;
            }
bubuko.com,布布扣

  给imageList添加一些图标(随便找的):

bubuko.com,布布扣

  将工具栏中的种类项与图标和表格关联起来:

bubuko.com,布布扣
 string[] s = new string[] { "Beverages","Condiments","Confections","Dairy Products",
                                        "Grains/Cereals","Meat/Poultry","Produce","Seafood"};
            for (int i = 0; i < s.Length; i++)
                repositoryItemImageComboBox1.Items.Add(new ImageComboBoxItem(s[i], i + 1, i));
            RepositoryItem ri = repositoryItemImageComboBox1.Clone() as RepositoryItem;
            colCategoryID.ColumnEdit = ri;
bubuko.com,布布扣

  修改种类项的属性:

this.repositoryItemImageComboBox1.SmallImages = this.imageList1;

  此时运行后界面应该是这样的:

bubuko.com,布布扣

  下面添加条件筛选的功能,首先定义一个设置筛选的方法:

bubuko.com,布布扣
 private void SetFilter()
        {
            string f = "";
            foreach (string s in filter)
            {
                if (f != "" && (!string.IsNullOrEmpty(s)))
                {
                    f += " And";
                }
                if (!string.IsNullOrEmpty(s))
                {
                    f += s;
                }

                dataView.RowFilter = (f == "") ? "No Filter" : "Filter: " + f;
                iRecords.Caption = "Records: " + dataView.Count.ToString();
            }
        }
bubuko.com,布布扣

  然后定义3种点击事件,一个是筛选checkBox,一个是小于所选日期,一个选择种类:

bubuko.com,布布扣
 private void discontinued_EditValueChanged(object sender, EventArgs e)
        {
            if (discontinued.EditValue == null)
                filter[0] = "";
            else
                filter[0] = string.Format("[Discontinued] = {0}", discontinued.EditValue.ToString());
            SetFilter();
        }

        private void lastOrder_EditValueChanged(object sender, EventArgs e)
        {
            if (lastOrder.EditValue == null)
            {
                filter[1] = "";
            }
            else
            {
                filter[1] = string.Format("[LastOrder] < #{0}#", StringDataToFormat(lastOrder.EditValue.ToString()));
            }
            SetFilter();
        }

        private static string StringDataToFormat(string s)
        {
            try
            {
                DateTime dt = DateTime.Parse(s);
                return string.Format("{0}/{1}/{2}", dt.Month.ToString(), dt.Day.ToString(), dt.Year.ToString());
            }
            catch
            {
                return s;
            }
        }

        private void categories_EditValueChanged(object sender, EventArgs e)
        {
            if (categories.EditValue == null)
                filter[2] = "";
            else
                filter[2] = string.Format("[CategoryID] = {0}",categories.EditValue.ToString());
            SetFilter();
        }
bubuko.com,布布扣

  此时效果如下:

bubuko.com,布布扣

  此时界面基本完成,剩下的就是加上一些边边角角的东西,比如设置清除筛选条件按钮:

bubuko.com,布布扣
        private void iClearFilter_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            discontinued.EditValue = null;
            lastOrder.EditValue = null;
            categories.EditValue = null;
        }
bubuko.com,布布扣

  然后总体效果图就出来了

bubuko.com,布布扣

 

 

浅谈DevExpress<二>:设计一个完整界面(2),布布扣,bubuko.com

浅谈DevExpress<二>:设计一个完整界面(2)

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/xuekai-to-sharp/p/3761161.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!