Esempio n. 1
0
        /// <summary>
        /// 按设定的条件执行搜索。
        /// </summary>
        /// <param name="pageNum">搜索指定页的分类。如果要搜索第2页及其之后页的数据,则应先设置 PageSize 属性。</param>
        /// <param name="isReverse">是否对排序信息 OrderInfos 中设定的排序条件执行倒序,如果该参数为 true 将导致整个搜索结果的先后顺序发生逆转,通常情况下应使用 false。</param>
        /// <param name="keepSource">是否保留所有分类至该搜索结果集合源的引用。当需要对分类进行进一步的数据查询操作,保留源引用可以提升查询性能。</param>
        /// <param name="reload">对于应用程序框架缓存的分类,是否重新载入分类属性。如果应用程序框架对分类进行了缓存用以保持引用分类的一致性,该参数为 true 时可以强制刷新分类档案,例如桌面应用程序通常需要对分类对象进行缓存;但是对于 WEB 应用程序通常不做分类对象缓存,所以将该参数设为 false。</param>
        /// <returns>符合条件的分类集合。</returns>
        public ClassifyCollection Search(int pageNum, bool isReverse, bool keepSource, bool reload)
        {
            base.PageNum = pageNum;

            ClassifyCollection classifys = new ClassifyCollection(keepSource);

            try
            {
                System.Data.IDataReader dr = base.GetDataReader(isReverse);
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        int intClassifyId = Function.ToInt(dr[Tables.Classify.ClassifyId]);

                        Classify classify = base.Application.GetClassifyInstance(intClassifyId);
                        if (classify != null)
                        {
                            if (reload)
                            {
                                classify.SetDataReader(dr);
                            }

                            if (this.Found != null)
                            {
                                if (keepSource)
                                {
                                    if (isReverse)
                                    {
                                        classifys.Insert(0, classify);
                                    }
                                    else
                                    {
                                        classifys.Add(classify);
                                    }
                                }
                                this.Found(classify);
                            }
                            else
                            {
                                if (isReverse)
                                {
                                    classifys.Insert(0, classify);
                                }
                                else
                                {
                                    classifys.Add(classify);
                                }
                            }
                        }
                        else
                        {
                            ClassifyType classifyType = base.Application.ClassifyTypes.GetClassifyType(Function.ToString(dr[Tables.Classify.ClassifyType]));
                            if (classifyType != null)
                            {
                                classify = classifyType.CreateClassify();
                                classify.SetApplication(base.Application);
                                classify.SetDataReader(dr);

                                if (classifyType.NeedCache)
                                {
                                    base.Application.SetClassifyInstance(classify);
                                }

                                if (this.Found != null)
                                {
                                    if (keepSource)
                                    {
                                        if (isReverse)
                                        {
                                            classifys.Insert(0, classify);
                                        }
                                        else
                                        {
                                            classifys.Add(classify);
                                        }
                                    }
                                    this.Found(classify);
                                }
                                else
                                {
                                    if (isReverse)
                                    {
                                        classifys.Insert(0, classify);
                                    }
                                    else
                                    {
                                        classifys.Add(classify);
                                    }
                                }
                            }
                            else
                            {
                                throw new Exception("未发现类型为 " + Function.ToString(dr[Tables.Classify.ClassifyType]) + " 的分类。");
                            }
                        }
                    }
                    dr.Close();
                }
            }
            finally
            {
                base.DbConnection.Close();
            }

            return(classifys);
        }
Esempio n. 2
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            if (this.cmbClassifyType.SelectedItem == null || (this.cmbClassifyType.SelectedItem is ClassifyType) == false)
            {
                MessageBox.Show("必须选择机构类型。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (this.txtName.Text.Length == 0)
            {
                MessageBox.Show("请输入根节点名称。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (this.m_Organization == null)
            {
                if (MessageBox.Show("确定创建名为“" + this.txtName.Text + "”类型是“" + this.cmbClassifyType.SelectedItem + "”的根节点机构吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                {
                    ClassifyType _ClassifyType = this.cmbClassifyType.SelectedItem as ClassifyType;
                    Organization _Organization = _ClassifyType.CreateClassify() as Organization;
                    _Organization.Name = this.txtName.Text;
                    _Organization.Save();
                    this.m_Organization = _Organization;

                    MessageBox.Show("根节点机构“" + _Organization.Name + "”已创建。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                if (this.m_Organization.ClassifyType.Equals(this.cmbClassifyType.SelectedItem))
                {
                    if (this.m_Organization.Name.Equals(this.txtName.Text) == false)
                    {
                        if (MessageBox.Show("确定要将“" + this.m_Organization.Name + "”修改为“" + this.txtName.Text + "”吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                        {
                            this.m_Organization.Name = this.txtName.Text;
                            this.m_Organization.Save();
                            MessageBox.Show("根节点机构“" + this.m_Organization.Name + "”已改名。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            f.Close();
                        }
                    }
                }
                else
                {
                    if (MessageBox.Show("确定要将类型是“" + this.m_Organization.ClassifyType.Name + "”的根节点机构更改为“" + this.cmbClassifyType.SelectedItem + "”类型吗?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
                    {
                        if (MessageBox.Show("变更根节点机构的类型将删除现有机构数据及机构与设备的对应关系,是否继续?", this.Text, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK)
                        {
                            this.m_Organization.Delete();
                            this.m_Organization = null;

                            ClassifyType _ClassifyType = this.cmbClassifyType.SelectedItem as ClassifyType;
                            Organization _Organization = _ClassifyType.CreateClassify() as Organization;
                            _Organization.Name = this.txtName.Text;
                            _Organization.Save();
                            this.m_Organization = _Organization;
                            MessageBox.Show("根节点机构“" + _Organization.Name + "”已重新创建。", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);

                            f.Close();
                        }
                    }
                }
            }
        }