示例#1
0
文件: TestForm.cs 项目: wshanshan/DDD
        private void button1_Click(object sender, EventArgs e)
        {
            ModifiableAttributePair att = new ModifiableAttributePair();
            att.Attribute = textBoxAttributeName.Text;
            att.Value = textBoxAttributeValue.Text;
            att.Modifiable = checkBoxModify.Checked;

            modifiableAttributePanel1.AddAttribute(att);

            textBoxAttributeName.Text = string.Empty;
            textBoxAttributeValue.Text = string.Empty;
            checkBoxModify.Checked = false;
        }
示例#2
0
        public bool AddAttribute(ModifiableAttributePair att)
        {
            if (att.Attribute.Length == 0)
            {
                return(false);
            }
            if (!InvokeRequired)
            {
                try
                {
                    if (_attributeList.ContainsKey(att.Attribute)) //Update Existing attribute
                    {
                        int row = _attributeGridMapping[att.Attribute];

                        if (_attributeList[att.Attribute].Modifiable != att.Modifiable) //Modify previous control type
                        {
                            /*
                             * //Trying to replace existing labels with textboxes is proving difficult, and not really req'd
                             * Control con = null;
                             * bool stop = false;
                             * try
                             * {
                             *   con = tableLayoutPanelMain.Controls.Find(String.Format("_val_{0}", att.Attribute), true)[0];
                             *
                             * }
                             * catch (Exception e)
                             * {
                             *  stop = true;
                             * }
                             * if (!stop)
                             * {
                             *  int indexOfCon = tableLayoutPanelMain.Controls.IndexOf(con);
                             *  int rowInd = 0;
                             *  int columnInd = 1;
                             *  if (att.Modifiable) //Make this attribute modifiable
                             *  {
                             *      tableLayoutPanelMain.Controls.RemoveAt(indexOfCon);
                             *      tableLayoutPanelMain.Controls.Add(CreateControl(GetControlName(att.Attribute, true), att.Value, true, false));
                             *      SetGridToPage(_currentPage);
                             *  }
                             *  else //make this attribute not-modifiable
                             *  {
                             *      //tableLayoutPanelMain.Controls[indexOfCon] = CreateControl(GetControlName(att.Attribute, true), att.Value, false, false);
                             *  }
                             * }
                             */
                        }
                        if (_attributeList[att.Attribute].Value != att.Value) //Modify previous value
                        {
                            try
                            {
                                Control c = tableLayoutPanelMain.Controls.Find(GetControlName(att.Attribute, true), true)[0];
                                c.Text = att.Value;
                            }
                            catch (Exception e)
                            {
                                if (e is IndexOutOfRangeException)
                                {
                                    Console.WriteLine("Error in ModifiableAttributePanel.AddAttribute.  Attempting to add value '{0}' to attribute '{1}', resulted in error: {2}.", att.Value, att.Attribute, e.Message);
                                }
                                else
                                {
                                    throw e;
                                }
                            }
                        }
                        _attributeList[att.Attribute] = att;
                    }
                    else //Add New Attribute
                    {
                        int row = _attributeList.Count; //works for 0-based index

                        _attributeList.Add(att.Attribute, att);

                        int tableRow  = row % _pageSize;
                        int tablePage = row / _pageSize + 1;

                        if (tablePage == _currentPage)
                        {
                            //create attribute name label
                            tableLayoutPanelMain.Controls.Add(CreateControl(GetControlName(att.Attribute, false), att.Attribute, false, true), 0, tableRow);
                            //create attribute value label
                            tableLayoutPanelMain.Controls.Add(CreateControl(GetControlName(att.Attribute, true), att.Value, att.Modifiable, false), 1, tableRow);
                        }
                        _attributeGridMapping.Add(att.Attribute, row);
                        _gridAttributeMapping.Add(row, att.Attribute);
                        SetGridButtons();
                    }
                }
                catch (Exception exc)
                {
                    throw new Exception(exc.Message);
                }
            }
            else
            {
                BeginInvoke(new AddAttributeDelegate(AddAttribute), att);
            }



            return(true);
        }
示例#3
0
        public bool AddAttribute(ModifiableAttributePair att)
        {
            if (att.Attribute.Length == 0)
                return false;
            if (!InvokeRequired)
            {
                try
                {
                    if (_attributeList.ContainsKey(att.Attribute)) //Update Existing attribute
                    {
                        int row = _attributeGridMapping[att.Attribute];

                        if (_attributeList[att.Attribute].Modifiable != att.Modifiable) //Modify previous control type
                        {
                            /*
                             * //Trying to replace existing labels with textboxes is proving difficult, and not really req'd
                            Control con = null;
                            bool stop = false;
                            try
                            {
                                 con = tableLayoutPanelMain.Controls.Find(String.Format("_val_{0}", att.Attribute), true)[0];
                       
                            }
                            catch (Exception e)
                            {
                                stop = true;
                            }
                            if (!stop)
                            {
                                int indexOfCon = tableLayoutPanelMain.Controls.IndexOf(con);
                                int rowInd = 0;
                                int columnInd = 1;
                                if (att.Modifiable) //Make this attribute modifiable
                                {
                                    tableLayoutPanelMain.Controls.RemoveAt(indexOfCon);
                                    tableLayoutPanelMain.Controls.Add(CreateControl(GetControlName(att.Attribute, true), att.Value, true, false));
                                    SetGridToPage(_currentPage);
                                }
                                else //make this attribute not-modifiable
                                {
                                    //tableLayoutPanelMain.Controls[indexOfCon] = CreateControl(GetControlName(att.Attribute, true), att.Value, false, false);
                                }
                            }
                             */

                        }
                        if (_attributeList[att.Attribute].Value != att.Value) //Modify previous value
                        {
                            try
                            {
                                Control c = tableLayoutPanelMain.Controls.Find(GetControlName(att.Attribute, true), true)[0];
                                c.Text = att.Value;
                            }
                            catch (Exception e)
                            {
                                if (e is IndexOutOfRangeException)
                                {
                                    Console.WriteLine("Error in ModifiableAttributePanel.AddAttribute.  Attempting to add value '{0}' to attribute '{1}', resulted in error: {2}.", att.Value, att.Attribute, e.Message);
                                }
                                else
                                {
                                    throw e;
                                }
                            }
                        }
                        _attributeList[att.Attribute] = att;
                    }
                    else //Add New Attribute
                    {
                        int row = _attributeList.Count; //works for 0-based index

                        _attributeList.Add(att.Attribute, att);

                        int tableRow = row % _pageSize;
                        int tablePage = row / _pageSize + 1;

                        if (tablePage == _currentPage)
                        {
                            //create attribute name label
                            tableLayoutPanelMain.Controls.Add(CreateControl(GetControlName(att.Attribute, false), att.Attribute, false, true), 0, tableRow);
                            //create attribute value label
                            tableLayoutPanelMain.Controls.Add(CreateControl(GetControlName(att.Attribute, true), att.Value, att.Modifiable, false), 1, tableRow);
                        }
                        _attributeGridMapping.Add(att.Attribute, row);
                        _gridAttributeMapping.Add(row, att.Attribute);
                        SetGridButtons();
                    }
                }
                catch (Exception exc)
                {
                    throw new Exception(exc.Message);
                }
            }
            else
            {
                BeginInvoke(new AddAttributeDelegate(AddAttribute), att);
            }

            

            return true;
        }