Exemplo n.º 1
0
        /// <summary>
        /// 読込ボタン
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter      = "edmx files (*.edmx)|*.edmx|All files (*.*)|*.*";
            dlg.FilterIndex = 0;
            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            _filename = dlg.FileName;
            _doc      = new EXDocument();
            _doc.Load(_filename);

            _tables = new List <TableMapping>();
            var els = _doc * "edmx:Mappings" * "EntitySetMapping";

            foreach (var el in els)
            {
                TableMapping tm = new TableMapping();
                _tables.Add(tm);
                tm.EntityName    = el / "EntityTypeMapping" % "TypeName";
                tm.EntityName    = tm.EntityName.Substring(tm.EntityName.IndexOf('.') + 1);
                tm.EntitySetName = el % "Name";
                tm.StoreName     = el / "EntityTypeMapping" / "MappingFragment" % "StoreEntitySet";
            }
            listBox1.DataSource = _tables;

            EXElement el2  = _doc * "EntitySet";
            string    name = el2 % "EntityType";

            _modelName = name.Substring(0, name.IndexOf('.'));
        }
Exemplo n.º 2
0
        /// <summary>
        /// テーブル名を更新
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonTableUpdate_Click(object sender, EventArgs e)
        {
            int       idx           = listBox1.SelectedIndex;
            string    entityNameOld = _tables[idx].EntityName;
            string    entityTypeOld = _modelName + "." + entityNameOld;
            string    entityNameNew = textTableName.Text;
            string    entityTypeNew = _modelName + "." + entityNameNew;
            EXElement el            = _doc * "edmx:ConceptualModels" * "EntitySet" % "EntityType" == entityTypeOld;

            el["Name"]       = entityNameNew;
            el["EntityType"] = entityTypeNew;


            el               = _doc * "edmx:ConceptualModels" * "EntitySet" % "EntityType" == entityTypeOld;
            el["Name"]       = entityNameNew;
            el["EntityType"] = entityTypeNew;
            el               = _doc * "edmx:ConceptualModels" * "EntityType" % "Name" == entityNameOld;
            el["Name"]       = entityNameNew;

            el                = _doc * "edmx:Mappings" * "EntityTypeMapping" % "TypeName" == entityTypeOld;
            el["TypeName"]    = entityTypeNew;
            el.Parent["Name"] = entityNameNew;



            el = _doc * "Diagrams" * "EntityTypeShape" % "EntityType" == entityTypeOld;
            el["EntityType"] = entityTypeNew;

            _tables[idx].EntityName    = entityNameNew;
            _tables[idx].EntitySetName = entityNameNew;

            listBox1.DataSource    = null;
            listBox1.DataSource    = _tables;
            listBox1.SelectedIndex = idx;
        }
Exemplo n.º 3
0
        /// <summary>
        /// リスト選択
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listBox1.SelectedIndex == -1)
            {
                return;
            }
            TableMapping tm    = (TableMapping)listBox1.SelectedItem;
            string       name  = tm.EntityName;
            EXElement    el    = _doc * "MappingFragment" % "StoreEntitySet" == tm.StoreName;
            var          items = from t in el / "ScalarProperty"
                                 select new ScalarProperty
            {
                Name       = t % "Name",
                ColumnName = t % "ColumnName"
            };

            _columns = items.ToList();
            dataGridView1.DataSource = _columns;

            textTableName.Text = name;
        }
Exemplo n.º 4
0
        /// <summary>
        /// カラム名を変更
        /// </summary>
        /// <param name="oldName"></param>
        /// <param name="newName"></param>
        private void ChangeScalarProp(string oldName, string newName)
        {
            string    entityName = _tables[listBox1.SelectedIndex].EntityName;
            EXElement el         = _doc * "edmx:ConceptualModels" * "EntityType" % "Name" == entityName;

            EXElement elref = el * "PropertyRef" % "Name" == oldName;

            if (EXDocument.IsEmpty(elref) == false)
            {
                elref["Name"] = newName;
            }
            EXElement elprop = el * "Property" % "Name" == oldName;

            elprop["Name"] = newName;

            string storeName = _tables[listBox1.SelectedIndex].StoreName;

            el             = _doc * "edmx:Mappings" * "MappingFragment" % "StoreEntitySet" == storeName;
            elprop         = el / "ScalarProperty" % "Name" == oldName;
            elprop["Name"] = newName;
        }
Exemplo n.º 5
0
 /// <summary>
 /// 要素を作成する
 /// </summary>
 /// <returns></returns>
 public EXElement CreateElement()
 {
     EXElement el = new EXElement(this);
     return el;
 }
Exemplo n.º 6
0
 /// <summary>
 /// コンストラクタ
 /// </summary>
 public EXDocument()
 {
     _emptyElement = new EXElement(this);
     _emptyAttr = new EXAttr(_emptyElement, "");
     _emptyAttr.Value = "";
 }
Exemplo n.º 7
0
 /// <summary>
 /// 補助関数
 /// </summary>
 /// <param name="reader"></param>
 /// <param name="pa"></param>
 protected void LoadXML(XmlReader reader, EXElement pa)
 {
     EXElement el = null;
     while (reader.Read())
     {
         switch (reader.NodeType)
         {
             case XmlNodeType.Element:
                 el = new EXElement(pa.Document);
                 el.Name = reader.Name;
                 pa.ChildNodes.Add(el);
                 el.Parent = pa;
                 if (reader.HasAttributes)
                 {
                     if (reader.HasAttributes)
                     {
                         for (int i = 0; i < reader.AttributeCount; i++)
                         {
                             reader.MoveToAttribute(i);
                             EXAttr attr = new EXAttr(el, reader.Name);
                             attr.Value = reader.Value;
                             el.Attributes.Add(attr.Name, attr);
                         }
                     }
                     reader.MoveToElement();
                 }
                 LoadXML(reader, el);
                 break;
             case XmlNodeType.EndElement:
                 return;
             case XmlNodeType.Text:
                 pa.Value = reader.Value;
                 break;
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// 文字列からドキュメントを作成する
 /// </summary>
 /// <param name="xml"></param>
 public void LoadXML(string xml)
 {
     using (XmlReader reader = XmlReader.Create(new StringReader(xml)))
     {
         // ルート要素までジャンプ
         while (reader.Read())
         {
             if (reader.NodeType == XmlNodeType.Element)
             {
                 EXElement root = new EXElement(this);
                 this.DocumentElement = root;
                 root.Name = reader.Name;
                 root.Value = "";
                 root.Parent = EXDocument._emptyElement;
                 LoadXML(reader, root);
             }
         }
     }
 }