Esempio n. 1
0
        // 准备 dpTable Rows 事项。但不急于填充
        static int PrepareRows(RelationControl control,
            List<ResultItem> items,
            out List<DpRow> rows,
            out string strError)
        {
            strError = "";
            rows = new List<DpRow>();

            ControlInfo info = (ControlInfo)control.Tag;

            // List<ResultItem> items = info.ResultItems;
            if (items == null || items.Count == 0)
                return 0;

            string strControlKey = control.SourceText;

            foreach (ResultItem item in items)
            {
                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(item.Xml);
                }
                catch (Exception ex)
                {
                    strError = "XML 装入 DOM 时出错: " + ex.Message;
                    return -1;
                }

                XmlElement node = dom.DocumentElement.SelectSingleNode("key") as XmlElement;

                string strKey = node.GetAttribute("name");
                // string strKeyCaption = DomUtil.GetCaption(this.Lang, node);

                if (info.Relation.DbName.StartsWith("DDC") == true)
                    strKey = strKey.Replace("/", "");

                XmlNodeList nodes = dom.DocumentElement.SelectNodes("rel");
                foreach (XmlElement rel_node in nodes)
                {
                    string strRel = rel_node.GetAttribute("name");
                    // string strRelCaption = DomUtil.GetCaption(this.Lang, rel_node);
                    string strWeight = rel_node.GetAttribute("weight");

                    DpRow row = new DpRow();
                    // key
                    {
                        DpCell cell = new DpCell();
                        cell.Text = strKey;
                        cell.OwnerDraw = true;
                        row.Add(cell);
                    }
                    // rel
                    {
                        DpCell cell = new DpCell();
                        cell.Text = strRel;
                        row.Add(cell);
                    }
                    // weight
                    {
                        DpCell cell = new DpCell();
                        cell.Text = strWeight;
                        row.Add(cell);
                    }
                    // level
                    {
                        DpCell cell = new DpCell();
                        int nLevel = GetLevel(strControlKey, strKey);
                        Debug.Assert(nLevel <= strControlKey.Length && nLevel <= strKey.Length, "");
                        cell.Text = nLevel.ToString();
                        row.Add(cell);
                    }

                    rows.Add(row);
                }
            }

            rows.Sort(CompareEntrys);

            // 如果 control 还没有初始化过 hitcounts,则初始化一次
            if (control.HitCounts.Count == 0)
                control.HitCounts = BuildHitCountList(rows, strControlKey);

#if NO
            // 选定特定行
            if (info.SelectedLines != null && info.SelectedLines.Count > 0)
            {
                foreach (string line in info.SelectedLines)
                {
                    SelectRowByKey(line);
                }
            }
#endif
            return 0;
        }
Esempio n. 2
0
        void control_Click(object sender, EventArgs e)
        {
#if NO
            RelationControl control = (RelationControl)sender;
            if (control == _currentControl)
                return;

            _currentControl = control;

            // 填充事项列表
            FillEntryList(control);
#endif
            SelectControl((RelationControl)sender);
        }
Esempio n. 3
0
        // 填充关系列表
        int FillRelationList(out string strError)
        {
            strError = "";

            ClearRelationList();

            foreach(Relation relation in this._relationCollection)
            {
                foreach (string key in relation.Keys)
                {
                    ControlInfo info = new ControlInfo();
                    info.Relation = relation;

                    string strKey = key;
                    if (relation.DbName.StartsWith("DDC") == true)
                        strKey = strKey.Replace("/", "");
                    else if (relation.DbName.StartsWith("LCC") == true)
                    {
                        //string strSave = strKey;
                        strKey = CanonicalizeLCC(strKey);
                        //if (strSave != strKey)
                        //    MessageBox.Show(this, "old=" + strSave + ",new=" + strKey);
                    }

                    RelationControl control = new RelationControl();
                    control.Tag = info;
                    control.TitleText = relation.DbName;
                    if (string.IsNullOrEmpty(relation.Color) == false)
                        control.TitleBackColor = ColorUtil.String2Color(relation.Color);
                    control.SourceTextOrigin = strKey;
                    control.SourceText = strKey;
                    control.BackColor = SystemColors.Window;
                    AddEvents(control, true);

                    this.flowLayoutPanel_relationList.Controls.Add(control);
                }
            }

            return 0;
        }
Esempio n. 4
0
 void AddEvents(RelationControl control, bool bAdd)
 {
     if (bAdd)
     {
         control.Click += control_Click;
     }
     else
     {
         control.Click -= control_Click;
     }
 }
Esempio n. 5
0
        void SelectControl(RelationControl control)
        {
            if (control == this._currentControl)
                return;

            if (this._currentControl != null)
                this._currentControl.Selected = false;
            if (control != null)
                control.Selected = true;
            this._currentControl = control;

            // 填充事项列表
            FillEntryList(control);
        }
Esempio n. 6
0
 // 在 dpTable 中选择一行,然后返回这行的信息。或者去掉对一行的选择
 SelectedItem SelectItem(RelationControl control,
     int index,
     bool bSelect)
 {
     DpRow row = this.dpTable1.Rows[index];
     if (bSelect == false)
     {
         row.Selected = false;
         return null;
     }
     SelectedItem item = new SelectedItem();
     item.Control = control;
     item.Index = index;
     item.Key = row[COLUMN_KEY].Text;
     item.Rel = row[COLUMN_REL].Text;
     item.Level = Int32.Parse(row[COLUMN_LEVEL].Text);
     item.Weight = Int32.Parse(row[COLUMN_WEIGHT].Text);
     row.Selected = true;
     return item;
 }
Esempio n. 7
0
        void FillEntryList(RelationControl control)
        {
            string strError = "";

            _disableSelectionChanged++; // 防止 control 的 TargetText 被清掉
            this.dpTable1.Rows.Clear();
            _disableSelectionChanged--;

            ControlInfo info = (ControlInfo)control.Tag;

            List<ResultItem> items = info.ResultItems;
            if (items == null || items.Count == 0)
                return;

            string strControlKey = control.SourceText;

            foreach (ResultItem item in items)
            {
                XmlDocument dom = new XmlDocument();
                try
                {
                    dom.LoadXml(item.Xml);
                }
                catch (Exception ex)
                {
                    strError = "XML 装入 DOM 时出错: " + ex.Message;
                    goto ERROR1;
                }

                XmlElement node = dom.DocumentElement.SelectSingleNode("key") as XmlElement;

                string strKey = node.GetAttribute("name");
                // string strKeyCaption = DomUtil.GetCaption(this.Lang, node);

                XmlNodeList nodes = dom.DocumentElement.SelectNodes("rel");
                foreach (XmlElement rel_node in nodes)
                {
                    string strRel = rel_node.GetAttribute("name");
                    // string strRelCaption = DomUtil.GetCaption(this.Lang, rel_node);
                    string strWeight = rel_node.GetAttribute("weight");

                    DpRow row = new DpRow();
                    // key
                    {
                        DpCell cell = new DpCell();
                        cell.Text = strKey;
                        cell.OwnerDraw = true;
                        row.Add(cell);
                    }
                    // rel
                    {
                        DpCell cell = new DpCell();
                        cell.Text = strRel;
                        row.Add(cell);
                    }
                    // weight
                    {
                        DpCell cell = new DpCell();
                        cell.Text = strWeight;
                        row.Add(cell);
                    }
                    // level
                    {
                        DpCell cell = new DpCell();
                        int nLevel = GetLevel(strControlKey, strKey);
                        Debug.Assert(nLevel <= strControlKey.Length && nLevel <= strKey.Length, "");
                        cell.Text = nLevel.ToString();
                        row.Add(cell);
                    }

                    this.dpTable1.Rows.Add(row);
                }
            }

            this.dpTable1.Rows.Sort(CompareEntrys);

            // 如果 control 还没有初始化过 hitcounts,则初始化一次
            if (control.HitCounts.Count == 0)
                control.HitCounts = BuildHitCountList(strControlKey);

            // 选定特定行
            if (info.SelectedLines != null && info.SelectedLines.Count > 0)
            {
                foreach (string line in info.SelectedLines)
                {
                    SelectRowByKey(line);
                }
            }

            return;
        ERROR1:
            MessageBox.Show(this, strError);
        }
Esempio n. 8
0
        // 为当前选定的 RelationControl 填充 dpTable Rows 事项
        void FillEntryList(RelationControl control)
        {
            // string strError = "";

            _disableSelectionChanged++; // 防止 control 的 TargetText 被清掉
            this.dpTable1.Rows.Clear();
            _disableSelectionChanged--;

            ControlInfo info = (ControlInfo)control.Tag;

            List<DpRow> rows = info.Rows;
            if (rows == null || rows.Count == 0)
                return;

            foreach(DpRow row in rows)
            {
                this.dpTable1.Rows.Add(row);
            }
        }