Exemple #1
0
        private void tsbViewObject_Click(object sender, EventArgs e)
        {
            ObjectViewer ov                = new ObjectViewer();
            string       ObjectText        = string.Empty;
            string       ObjectDescription = string.Empty;

            try
            {
                using (DataStuff sn = new DataStuff())
                {
                    DataTable dt = sn.GetDatabaseObjectText(ConnectionString, DatabaseName, ObjectName);

                    if (dt.Rows.Count > 1)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            ObjectText        = row["FullDefinition"].ToString();
                            ObjectDescription = row["ROUTINE_NAME"].ToString() + ": " + row["ROUTINE_TYPE"].ToString();
                        }
                    }
                    else
                    {
                        ObjectText        = LoadHelpText(ConnectionString, DatabaseName, ObjectName);
                        ObjectDescription = ObjectName;

                        if (ObjectText.Trim() == "")
                        {
                            dt = sn.GetTableHelpText(ConnectionString, DatabaseName, ObjectName);

                            foreach (DataRow row in dt.Rows)
                            {
                                ObjectText = row[0].ToString();
                            }

                            ObjectText = ObjectText.Replace("~", Environment.NewLine);
                        }
                    }
                }

                ov.ObjectDescription = ObjectDescription;
                ov.ObjectText        = ObjectText;
                ov.ConnectionString  = ConnectionString;
                ov.DatabaseName      = DatabaseName;
                ov.ObjectName        = ObjectName;
                ov.AliasName         = ServerAlias;

                ov.Show();
            }

            catch
            {
            }
        }
        private string GetObjectText(string CnnString, string DBName, string ObjName)
        {
            string ObjectText        = string.Empty;
            string ObjectDescription = string.Empty;

            try
            {
                using (DataStuff sn = new DataStuff())
                {
                    DataTable dt = sn.GetDatabaseObjectText(CnnString, DBName, ObjName);

                    if (dt.Rows.Count > 1)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            ObjectText        = row["FullDefinition"].ToString();
                            ObjectDescription = row["ROUTINE_NAME"].ToString() + ": " + row["ROUTINE_TYPE"].ToString();
                        }
                    }
                    else
                    {
                        ObjectText = LoadHelpText(CnnString, DBName, ObjName);

                        if (ObjectText.Trim() == "")
                        {
                            dt = sn.GetTableHelpText(CnnString, DBName, ObjName);

                            foreach (DataRow row in dt.Rows)
                            {
                                ObjectText = row[0].ToString();
                            }

                            ObjectText = ObjectText.Replace("~", Environment.NewLine);
                        }
                    }

                    return(ObjectText);
                }
            }

            catch
            {
                return("");
            }
        }
Exemple #3
0
        private bool BackupReleaseToServerObject(string ReleaseToServer, string DatabaseName, string ObjectName, string ProjectName)
        {
            string ObjectText        = string.Empty;
            string ObjectDescription = string.Empty;
            string ConnectionStr     = string.Empty;
            bool   Result            = false;

            ConnectionStr = GetServerConnectionString(ReleaseToServer);

            try
            {
                using (DataStuff sn = new DataStuff())
                {
                    DataTable dt = sn.GetDatabaseObjectText(ConnectionStr, DatabaseName, ObjectName);

                    if (dt.Rows.Count > 1)
                    {
                        foreach (DataRow row in dt.Rows)
                        {
                            ObjectText        = row["FullDefinition"].ToString();
                            ObjectDescription = row["ROUTINE_NAME"].ToString() + ": " + row["ROUTINE_TYPE"].ToString();
                        }
                    }
                }
            }

            catch
            {
                DialogResult result = MessageBox.Show("An error occurred getting the object text for server " + ReleaseToServer + ". Release anyway?", "Backup Object", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                if (result == DialogResult.No)
                {
                    return(false);
                }
                else
                {
                    IsNewObject = true;
                    return(true);
                }
            }

            if (ObjectText.Trim() == "")
            {
                try
                {
                    using (DataStuff sn = new DataStuff())
                    {
                        DataTable dt = sn.GetObjectHelpText(ConnectionStr, DatabaseName, ObjectName);

                        if (dt.Rows.Count > 0)
                        {
                            foreach (DataRow row in dt.Rows)
                            {
                                ObjectText = ObjectText + row[0].ToString();
                            }
                        }
                    }
                }

                catch
                {
                    DialogResult result = MessageBox.Show("An error occurred getting the object text for server " + ReleaseToServer + ". Release anyway?", "Backup Object", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                    if (result == DialogResult.No)
                    {
                        return(false);
                    }
                    else
                    {
                        IsNewObject = true;
                        return(true);
                    }
                }
            }

            try
            {
                if (ObjectText.Trim() == "")
                {
                    DialogResult result = MessageBox.Show("An error occurred getting the object text for server " + ReleaseToServer + ". Release anyway?", "Backup Object", MessageBoxButtons.YesNo, MessageBoxIcon.Error);

                    if (result == DialogResult.No)
                    {
                        return(false);
                    }
                    else
                    {
                        IsNewObject = true;
                        return(true);
                    }
                }

                string BackupComment;

                BackupComment = UserName + " - " + "Backup before restore from project backup";

                using (DataStuff sn = new DataStuff())
                {
                    Result = sn.BackupObject(ReleaseToServer, "Backup", UserName, ObjectName, DatabaseName, ObjectText, BackupComment, ProjectName, "", "", "N", "N");

                    if (!Result)
                    {
                        MessageBox.Show("There was an error creating a backup for this object. Please ensure that your servers have been set up correctly.", "Change Status", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }

                    lStatus.Text = "Creating backup of " + ReleaseToServer + " - " + DatabaseName + ": " + ObjectName + "...";
                }
            }

            catch
            {
                MessageBox.Show("An error occurred while creating the backup record.", "Backup Object", MessageBoxButtons.OK, MessageBoxIcon.Error);
                lStatus.Text = "Error creating backup of " + ReleaseToServer + " - " + DatabaseName + ": " + ObjectName + ".";
                return(false);
            }

            return(true);
        }