Ejemplo n.º 1
0
        private void newDataSourceToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (treeView1.Nodes[0].Nodes.Count > 0)
                return;

            ConnectionWizard cwz = new ConnectionWizard();
            DialogResult cwzResult = cwz.ShowDialog();

            if (cwzResult == DialogResult.OK)
            {
                DataSet ds = cwz.GetDataSet();
                MainForm mf = (MainForm) FindForm().ParentForm;
                ModelForm frmModel = new ModelForm();
                frmModel.SqlSchema = cwz.SqlSchema;
                frmModel.Closed += new EventHandler(frmModel_Closed);

                EditWorkingTables ewt = new EditWorkingTables(ds, new List<string>());
                DialogResult result = ewt.ShowDialog();
                if (result == DialogResult.OK)
                {
                    treeView1.Nodes[0].Nodes.Add(ds.DataSetName);
                    treeView1.Nodes[0].Expand();
                    frmModel.Show(mf.DockPanel);

                    frmModel.SetZoom(75);
                    frmModel.SetVisibleTables(ewt.VisibleTables);
                    frmModel.LoadDataSet(ewt.WorkDataSet);
                }
            }
        }
Ejemplo n.º 2
0
        private void writeProjectStatus(string fileName, ModelForm frmModel)
        {
            //string xmlExtension = ".xml";

            Stream fileStream = new FileStream(fileName, FileMode.Create);
            StreamWriter stw = new StreamWriter(fileStream, System.Text.Encoding.UTF8);
            XmlTextWriter xmlWriter = new XmlTextWriter(stw);
            xmlWriter.Formatting = Formatting.Indented;

            //xml doc
            xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
            xmlWriter.WriteStartElement("ProjectStatus");

            //ProjectName
            xmlWriter.WriteElementString("ProjectName", projectName);

            //ConnectionSettings
            xmlWriter.WriteStartElement("ConnectionSettings");
            writeConnectionSettings(xmlWriter, frmModel);
            xmlWriter.WriteEndElement(); // /ConnectionSettings

            //DataSetFileName
            String dsFileName = projectDirectory + Path.GetFileNameWithoutExtension(fileName) + "_" + frmModel.DataSet.DataSetName + projectExtension;
            dsFileName.Replace("&", "&amp;");
            dsFileName.Replace("'", "&apos;");
            xmlWriter.WriteElementString("DataSetFileName", dsFileName);
            //writing dataset
            frmModel.DataSet.WriteXml(dsFileName, System.Data.XmlWriteMode.WriteSchema);

            //WorkingTables
            xmlWriter.WriteStartElement("WorkingTables");
            writeWorkingTables(xmlWriter, frmModel);
            xmlWriter.WriteEndElement(); // /WorkingTables

            //EntitiesSuggestion
            xmlWriter.WriteStartElement("EntitiesSuggestion");

            writeEntityTypes(xmlWriter, frmModel);
            writeMinimalEntities(xmlWriter, frmModel);
            writeMaximalEntities(xmlWriter, frmModel);
            writeMaximalHierarchies(xmlWriter, frmModel);

            xmlWriter.WriteEndElement(); // /EntitiesSuggestion

            xmlWriter.WriteEndElement(); // /ProjectStatus

            // finalization
            xmlWriter.Close();
            stw.Close();
        }
Ejemplo n.º 3
0
 private void writeWorkingTables(XmlTextWriter xmlWriter, ModelForm frmModel)
 {
     IEnumerator vtIterator = frmModel.VisibleTables.GetEnumerator();
     while (vtIterator.MoveNext())
     {
         string vTable = (string)vtIterator.Current;
         xmlWriter.WriteElementString("TableName", vTable);
     }
 }
Ejemplo n.º 4
0
 private void writeMinimalEntities(XmlTextWriter xmlWriter, ModelForm frmModel)
 {
     IEnumerator minIt = frmModel.MinimalEntities.GetEnumerator();
     xmlWriter.WriteStartElement("MinimalEntities");
     while (minIt.MoveNext())
     {
         int minElem = (int)minIt.Current;
         xmlWriter.WriteElementString("TableName", minElem.ToString());
     }
     xmlWriter.WriteEndElement(); // /MinimalEntities
 }
Ejemplo n.º 5
0
 private void writeMaximalHierarchies(XmlTextWriter xmlWriter, ModelForm frmModel)
 {
     IEnumerator maxHIt = frmModel.MaximalHierarchies.GetEnumerator();
     xmlWriter.WriteStartElement("MaximalHierarchies");
     if (frmModel.MaximalHierarchies.Count != 0)
     {
         xmlWriter.WriteStartElement("Vector");
         while (maxHIt.MoveNext())
         {
             List<int> tmpList = (List<int>)maxHIt.Current;
             IEnumerator listIt = tmpList.GetEnumerator();
             xmlWriter.WriteStartElement("List");
             while (listIt.MoveNext())
             {
                 int elem = (int)listIt.Current;
                 xmlWriter.WriteElementString("Elem", elem.ToString());
             }
             xmlWriter.WriteEndElement(); // /List
         }
         xmlWriter.WriteEndElement(); // /Vector
     }
     xmlWriter.WriteEndElement(); // /MaximalHierarchies
 }
Ejemplo n.º 6
0
 private void writeEntityTypes(XmlTextWriter xmlWriter, ModelForm frmModel)
 {
     IEnumerator dicIt = frmModel.EntityTypesDic.GetEnumerator();
     xmlWriter.WriteStartElement("EntityTypes");
     while (dicIt.MoveNext())
     {
         KeyValuePair<string, EntityTypes> dicElem;
         dicElem = (KeyValuePair<string, EntityTypes>)dicIt.Current;
         string dicString = dicElem.Key;
         int eTypes = (int)dicElem.Value;
         xmlWriter.WriteStartElement("EntityType");
         xmlWriter.WriteElementString("TableName", dicString);
         xmlWriter.WriteElementString("TableType", eTypes.ToString());
         xmlWriter.WriteEndElement(); // /EntityType
     }
     xmlWriter.WriteEndElement(); // /EntityTypes
 }
Ejemplo n.º 7
0
        private void writeConnectionSettings(XmlTextWriter xmlWriter, ModelForm frmModel)
        {
            //WindowsAuthorization
            xmlWriter.WriteElementString("WindowsAuthorization", frmModel.SqlSchema.WindowsAuthorization.ToString().ToLower());

            //Server
            xmlWriter.WriteElementString("Server", frmModel.SqlSchema.Server.ToString());

            //UserName
            xmlWriter.WriteElementString("UserName", frmModel.SqlSchema.Username.ToString());

            //Password
            xmlWriter.WriteElementString("Password", frmModel.SqlSchema.Password.ToString());
        }
Ejemplo n.º 8
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ModelForm frmModel = (ModelForm)dockPanel1.ActiveDocument;
            if (frmModel == null)
            {
                frmModel = new ModelForm();
                frmModel.Closed += new EventHandler(frmModel_Closed);
            }

            frmModel.SqlSchema = new SqlSchema();

            OpenFileDialog fDialog;
            fDialog = new OpenFileDialog();
            fDialog.Filter = "BDDW Project Files|*" + projectExtension;
            fDialog.Multiselect = false;
            fDialog.CheckFileExists = false;
            fDialog.AddExtension = false;
            fDialog.CheckFileExists = true;
            FileInfo file;
            if (fDialog.ShowDialog() == DialogResult.OK)
            {
                file = new FileInfo(fDialog.FileName.ToString());
                projectDirectory = file.Directory.ToString() + "\\";
                projectName = file.Name.ToString();

                XmlDocument xdoc = new XmlDocument();
                xdoc.Load(fDialog.FileName.ToString());

                xdoc.Schemas.Add(null, Application.StartupPath + @"\currentState.xsd");
                ValidationEventHandler eventHandler = new ValidationEventHandler(MyValidationEventHandler);
                xdoc.Validate(eventHandler);

                if (!validSchema)
                {
                    validSchema = true;
                    return;
                }

                //root : ProjectStatus
                XmlNode projectStatusNode = xdoc.SelectSingleNode("/ProjectStatus");

                //ProjectName
                XmlNode pnNode = projectStatusNode.SelectSingleNode("ProjectName");
                this.projectName = pnNode.InnerText;

                //ConnectionSettings
                XmlNode csNode = projectStatusNode.SelectSingleNode("ConnectionSettings");
                XmlNode waNode, sNode, unNode, pNode;

                //WindowsAuthorization
                waNode = csNode.SelectSingleNode("WindowsAuthorization");
                bool wa = false;
                string waString = waNode.InnerText;
                if (waString.Equals("true"))
                    wa = true;
                frmModel.SqlSchema.WindowsAuthorization = wa;

                //Server
                sNode = csNode.SelectSingleNode("Server");
                frmModel.SqlSchema.Server = sNode.InnerText;

                //UserName
                unNode = csNode.SelectSingleNode("UserName");
                frmModel.SqlSchema.Username = unNode.InnerText;

                //Password
                pNode = csNode.SelectSingleNode("Password");
                frmModel.SqlSchema.Password = pNode.InnerText;

                //DataSetFileName
                XmlNode dsf = projectStatusNode.SelectSingleNode("DataSetFileName");
                string dataSetFileName = dsf.InnerText;
                frmModel.DataSet = new DataSet();
                //dataset load
                if (!dataSetFileName.Equals(string.Empty))
                {
                    frmModel.DataSet.ReadXml(dataSetFileName);
                }

                //WorkingTables
                frmModel.VisibleTables = new List<string>();
                XmlNode wtNode = projectStatusNode.SelectSingleNode("WorkingTables");
                foreach (XmlNode elem in wtNode)
                {
                    XmlNode tmp = elem.SelectSingleNode("TableName");
                    frmModel.VisibleTables.Add(elem.InnerText.ToString());
                }
                //MessageBox.Show(frmModel.VisibleTables.Count.ToString ());

                //EntitiesSuggestion
                XmlNode esNode = projectStatusNode.SelectSingleNode("EntitiesSuggestion");

                //EntityTypes
                XmlNode etNode = esNode.SelectSingleNode("EntityTypes");

                frmModel.EntityTypesDic = new Dictionary<string, EntityTypes>();

                foreach (XmlNode elem in etNode)
                {
                    string tableName;
                    int tableType;
                    XmlNode tableNode = elem.SelectSingleNode("TableName");
                    tableName = tableNode.InnerText;
                    XmlNode typeNode = elem.SelectSingleNode("TableType");
                    tableType = System.Convert.ToInt32(typeNode.InnerText.ToString());
                    EntityTypes eType = EntityTypes.Unclassified;
                    switch (tableType)
                    {
                        case -1:
                            eType = EntityTypes.Unclassified;
                            break;
                        case 0:
                            eType = EntityTypes.ClassificationEntity;
                            break;
                        case 1:
                            eType = EntityTypes.ComponentEntity;
                            break;
                        case 2:
                            eType = EntityTypes.TransactionEntity;
                            break;
                    }
                    frmModel.EntityTypesDic.Add(tableName, eType);
                }
                //MessageBox.Show(frmModel.EntityTypesDic.Count.ToString());

                //MinimalEntities
                frmModel.MinimalEntities = new List<int>();
                XmlNodeList minNode = esNode.SelectNodes("MinimalEntities/TableName");
                foreach (XmlNode elem in minNode)
                {
                    frmModel.MinimalEntities.Add(System.Convert.ToInt32(elem.InnerText.ToString()));
                }

                //MaximalEntities
                frmModel.MaximalEntities = new List<int>();
                XmlNodeList maxNode = esNode.SelectNodes("MaximalEntities/TableName");
                foreach (XmlNode elem in maxNode)
                {
                    frmModel.MaximalEntities.Add(System.Convert.ToInt32(elem.InnerText.ToString()));
                }

                //MaximalHierarchies
                frmModel.MaximalHierarchies = new List<List<int>>();
                XmlNodeList listNode = esNode.SelectNodes("MaximalHierarchies/Vector/List");
                foreach (XmlNode list in listNode)
                {
                    List<int> toAdd = new List<int>();
                    XmlNodeList elemList = list.SelectNodes("Elem");
                    foreach (XmlNode elem in elemList)
                    {
                        toAdd.Add(System.Convert.ToInt32(elem.InnerText.ToString()));
                    }
                    frmModel.MaximalHierarchies.Add(toAdd);
                }

                prjExplorer.TreeView.Nodes[0].Nodes.Clear();
                prjExplorer.TreeView.Nodes[0].Nodes.Add(frmModel.DataSet.DataSetName);
                prjExplorer.TreeView.Nodes[0].Expand();
                frmModel.Show(DockPanel);

                frmModel.SetZoom(75);
                frmModel.LoadDataSet(frmModel.DataSet);
            }
        }