예제 #1
0
        public void ReadFromXmlNode(IXmlCodeReader reader, XmlNode node)
        {
            TableName = XmlUtil.GetNameAttribute(node);
            XmlNodeList ns = node.SelectNodes(string.Format(CultureInfo.InvariantCulture,
                                                            "{0}/{1}", XML_Columns, WebPageDataSet.XML_Item));

            Columns = new WebDataColumn[ns.Count];
            for (int i = 0; i < ns.Count; i++)
            {
                Columns[i] = new WebDataColumn();
                Columns[i].ReadFromXmlNode(ns[i]);
            }
            Rows = new Dictionary <string, WebPageDataRow[]>();
            XmlNodeList ndrcs = node.SelectNodes(string.Format(CultureInfo.InvariantCulture,
                                                               "{0}/{1}", XML_Rows, XML_RowsC));

            foreach (XmlNode ndc in ndrcs)
            {
                string           culture = XmlUtil.GetAttribute(ndc, XMLATTR_culture);
                XmlNodeList      nrs     = ndc.SelectNodes(WebPageDataSet.XML_Item);
                WebPageDataRow[] rs      = new WebPageDataRow[nrs.Count];
                for (int i = 0; i < nrs.Count; i++)
                {
                    rs[i] = new WebPageDataRow();
                    rs[i].ReadFromXmlNode(reader, nrs[i]);
                }
                Rows.Add(culture, rs);
            }
        }
예제 #2
0
        public PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            WebPageDataRow[] rows = GetCurrentRows();
            if (rows == null || rows.Length == 0)
            {
                rows    = new WebPageDataRow[1];
                rows[0] = new WebPageDataRow();
                if (this.Rows == null)
                {
                    this.Rows = new Dictionary <string, WebPageDataRow[]>();
                }
                if (CurrentCulture == null)
                {
                    CurrentCulture = string.Empty;
                }
                if (this.Rows.ContainsKey(CurrentCulture))
                {
                    this.Rows[CurrentCulture] = rows;
                }
                else
                {
                    this.Rows.Add(CurrentCulture, rows);
                }
            }
            WebPageDataRow r = rows[0];

            if (r == null)
            {
                r       = new WebPageDataRow();
                rows[0] = r;
            }

            if (Columns == null)
            {
                Columns = new WebDataColumn[] { };
            }
            if (r.ItemArray == null)
            {
                r.ItemArray = new object[Columns.Length];
            }
            else
            {
                if (r.ItemArray.Length < Columns.Length)
                {
                    object[] vs = new object[Columns.Length];
                    for (int i = 0; i < r.ItemArray.Length; i++)
                    {
                        vs[i] = r.ItemArray[i];
                    }
                    r.ItemArray = vs;
                }
            }
            PropertyDescriptor[] ps = new PropertyDescriptor[Columns.Length];
            for (int i = 0; i < Columns.Length; i++)
            {
                ps[i] = new PropertyDescriptorRowValue(r, i, Columns[i].SystemType, Columns[i].ColumnName, attributes);
            }
            return(new PropertyDescriptorCollection(ps));
        }
예제 #3
0
        public WebDataColumn Clone()
        {
            WebDataColumn c = new WebDataColumn();

            c.ColumnName = ColumnName;
            c.ReadOnly   = ReadOnly;
            c.Type       = Type;
            return(c);
        }
        private void btOK_Click(object sender, EventArgs e)
        {
            StringCollection ns = new StringCollection();

            RetColumns = new WebDataColumn[_table.Rows.Count];
            for (int i = 0; i < _table.Rows.Count; i++)
            {
                RetColumns[i]            = new WebDataColumn();
                RetColumns[i].Type       = _table.Rows[i][1] as string;
                RetColumns[i].ColumnName = _table.Rows[i][0] as string;
                if (RetColumns[i].ColumnName != null)
                {
                    RetColumns[i].ColumnName = RetColumns[i].ColumnName.Trim();
                }
                if (string.IsNullOrEmpty(RetColumns[i].ColumnName))
                {
                    MessageBox.Show(this, "Data column name cannot be empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                if (RetColumns[i].Type != null)
                {
                    RetColumns[i].Type = RetColumns[i].Type.Trim();
                }
                if (string.IsNullOrEmpty(RetColumns[i].Type))
                {
                    MessageBox.Show(this, "Data column type cannot be empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                string snc = RetColumns[i].ColumnName.ToLowerInvariant();
                if (ns.Contains(snc))
                {
                    MessageBox.Show(this, "Data column name [{0}] is used more than once.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                ns.Add(snc);
            }
            this.DialogResult = DialogResult.OK;
        }
예제 #5
0
 public void UpdateColumns(WebDataColumn[] tableColumns)
 {
     if (tableColumns == null)
     {
         tableColumns = new WebDataColumn[] { };
     }
     if (Columns == null || Columns.Length == 0)
     {
         Columns = tableColumns;
     }
     else
     {
         bool changed = true;
         if (Columns.Length == tableColumns.Length)
         {
             changed = false;
             for (int i = 0; i < Columns.Length; i++)
             {
                 if (string.Compare(Columns[i].ColumnName, tableColumns[i].ColumnName, StringComparison.OrdinalIgnoreCase) != 0)
                 {
                     changed = true;
                 }
             }
         }
         if (changed)
         {
             bool  hasData = false;
             int[] map     = new int[tableColumns.Length];
             for (int i = 0; i < tableColumns.Length; i++)
             {
                 map[i] = -1;
                 for (int j = 0; j < Columns.Length; j++)
                 {
                     if (string.Compare(tableColumns[i].ColumnName, Columns[j].ColumnName, StringComparison.OrdinalIgnoreCase) == 0)
                     {
                         map[i]  = j;
                         hasData = true;
                         break;
                     }
                 }
             }
             if (hasData)
             {
                 if (Rows != null)
                 {
                     Dictionary <string, WebPageDataRow[]> newRows = new Dictionary <string, WebPageDataRow[]>();
                     foreach (KeyValuePair <string, WebPageDataRow[]> kv in Rows)
                     {
                         WebPageDataRow[] rs;
                         if (kv.Value == null)
                         {
                             rs = new WebPageDataRow[] { };
                         }
                         else
                         {
                             rs = new WebPageDataRow[kv.Value.Length];
                             for (int i = 0; i < rs.Length; i++)
                             {
                                 rs[i]           = new WebPageDataRow();
                                 rs[i].ItemArray = new object[tableColumns.Length];
                                 for (int j = 0; j < tableColumns.Length; j++)
                                 {
                                     if (map[j] < 0)
                                     {
                                         rs[i].ItemArray[j] = null;
                                     }
                                     else
                                     {
                                         rs[i].ItemArray[j] = kv.Value[i].ItemArray[map[j]];
                                     }
                                 }
                             }
                         }
                         newRows.Add(kv.Key, rs);
                     }
                     Rows = newRows;
                 }
             }
             else
             {
                 Rows = null;
             }
             Columns = tableColumns;
         }
     }
 }