Пример #1
0
        private void ModelDiagramManager_Load(object sender, EventArgs e)
        {
            var errorMessage = String.Empty;

            try
            {
                GetModels();
            }
            catch (Exception exc)
            {
                this.lblError.Text = exc.Message;
                return;
            }
            List <string> conStrings = MDSModelling.GetConnectionStrings(Application.ExecutablePath);

            if (conStrings.Count > 0)
            {
                // txtSingleConString.Text = conStrings.First();

                foreach (string conStr in conStrings)
                {
                    string[] separator = new string[1] {
                        ";"
                    };
                    int num = 0;
                    foreach (string ConStringElement in conStr.Split(separator, (StringSplitOptions)num))
                    {
                        if (ConStringElement.ToLower().Contains("source"))
                        {
                            string substr = ConStringElement.Substring(ConStringElement.IndexOf('=') + 1);
                            if (!this.cbDataSource.Items.Contains((object)substr))
                            {
                                this.cbDataSource.Items.Add((object)substr);
                            }
                        }
                        else
                        if (ConStringElement.ToLower().Contains("catalog"))
                        {
                            string substr = ConStringElement.Substring(ConStringElement.IndexOf('=') + 1);
                            if (!this.cbInitialCatalog.Items.Contains((object)substr))
                            {
                                this.cbInitialCatalog.Items.Add((object)substr);
                            }
                        }
                        else
                        if (ConStringElement.ToLower().Contains("attachdbfilename"))
                        {
                            this.txtAttachDbFilename.Text = ConStringElement.Substring(ConStringElement.IndexOf('=') + 1);
                        }
                    }
                }
            }
        }
Пример #2
0
        private void btExportDiagram_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            try
            {
                System.Data.SqlClient.SqlConnectionStringBuilder builder = null;
                if (rbUseSingleConString.Checked && !string.IsNullOrWhiteSpace(txtSingleConString.Text))
                {
                    builder = new System.Data.SqlClient.SqlConnectionStringBuilder(txtSingleConString.Text);


                    this.cbDataSource.Text        = builder.DataSource;
                    this.cbInitialCatalog.Text    = builder.InitialCatalog;
                    this.txtAttachDbFilename.Text = builder.AttachDBFilename;
                }
                else
                if (rbUseConStringElements.Checked)
                {
                    builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
                    builder.AttachDBFilename = txtAttachDbFilename.Text;
                    builder.DataSource       = cbDataSource.Text;
                    builder.InitialCatalog   = cbInitialCatalog.Text;

                    this.txtSingleConString.Text = builder.ConnectionString;
                }

                if (!string.IsNullOrEmpty(this.cbDataSource.Text) && !string.IsNullOrEmpty(this.txtModellingDb.Text))
                {
                    if (this.cbModel.SelectedItem != null)
                    {
                        this.txtDefaultSchema.Text = string.IsNullOrEmpty(this.txtDefaultSchema.Text) ? "dbo" : this.txtDefaultSchema.Text;
                        if (this.chkDropExistingDB.Checked)
                        {
                            try
                            {
                                MDSModelling.DropExistingDb(txtSingleConString.Text, txtModellingDb.Text);
                            }
                            catch (Exception ex)
                            {
                                this.lblError.Text = ex.Message + ";" + ex.InnerException != null ? ex.InnerException.Message : "";
                            }
                        }
                        if (this.ckCreateDb.Checked)
                        {
                            try
                            {
                                MDSModelling.CreateNewDb(txtSingleConString.Text, txtModellingDb.Text);
                            }
                            catch (Exception ex)
                            {
                                this.lblError.Text = ex.Message + ";" + ex.InnerException != null ? ex.InnerException.Message : "";
                            }
                        }
                        foreach (CustomEntity customEntity in this.ucManageEntities1.lstEntities.Items)
                        {
                            MDSModelling.CreateTable(txtSingleConString.Text, customEntity.Name, txtAttachDbFilename.Text, txtModellingDb.Text, this.txtDefaultSchema.Text);
                        }

                        foreach (CustomEntity customEntity in this.ucManageEntities1.lstEntities.Items)
                        {
                            OperationResult or       = new OperationResult();
                            Metadata        metaData = MDSWrapper.GetMetaData(new International(), ref or, (Identifier)this.cbModel.SelectedItem, ((CustomVersion)this.cbVersion.SelectedItem).Identifier, (Identifier)customEntity.entityId, MDAction.AttributesOnly);
                            if (metaData != null)
                            {
                                foreach (MetadataAttribute att in metaData.Attributes)
                                {
                                    AttributeType?attributeType = att.AttributeType;
                                    if ((attributeType.GetValueOrDefault() != AttributeType.Domain ? 0 : (attributeType.HasValue ? 1 : 0)) != 0)
                                    {
                                        MDSModelling.CreateRelationShips(this.cbDataSource.Text, this.cbInitialCatalog.Text, this.txtModellingDb.Text, att.DomainEntityId.Name, att.Identifier.EntityId.Name);
                                    }
                                    else
                                    {
                                        MDSModelling.AddColumn(txtSingleConString.Text, this.txtModellingDb.Text, customEntity.Name, att);
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.lblError.Text = "You must select a model first!";
                    }
                }
                else
                {
                    this.lblError.Text = "You must enter a data source, an initial catalog and a modelling database name or a connection string!";
                }
            }
            catch (Exception ex)
            {
                this.lblError.Text = ex.Message;
            }
            finally
            {
                Cursor.Current = Cursors.Default;
            }
        }