Exemple #1
0
        private void cmdBackup_Click(object sender, EventArgs e)
        {
            bool   Success      = false;
            bool   FoundError   = false;
            string DatabaseName = string.Empty;
            string ObjectName   = string.Empty;
            string ObjectText   = string.Empty;
            int    SuccessCount = 0;
            int    FailCount    = 0;
            int    RowCount     = 0;
            string ProjectName  = string.Empty;
            int    ProjectID    = 0;
            int    SetID        = 0;
            bool   SetDone      = false;

            foreach (DataGridViewRow row in dgvMain.Rows)
            {
                FoundError   = false;
                DatabaseName = "";
                ObjectName   = "";
                ObjectText   = "";
                ProjectName  = "";

                try
                {
                    DatabaseName = Convert.ToString(row.Cells["DatabaseName"].Value);
                    ObjectName   = Convert.ToString(row.Cells["DBObjectName"].Value);
                    ObjectText   = Convert.ToString(row.Cells["ObjectText"].Value);
                    ProjectName  = cbProject.Text;

                    if (!SetDone)
                    {
                        using (DataStuff sn = new DataStuff())
                        {
                            DataTable dt = sn.SaveProjectBackupSet(ProjectName);

                            if (dt != null)
                            {
                                if (dt.Rows.Count > 0)
                                {
                                    int.TryParse(dt.Rows[0]["ProjectID"].ToString(), out ProjectID);
                                    int.TryParse(dt.Rows[0]["ProjectSetID"].ToString(), out SetID);
                                }
                            }
                        }

                        SetDone = true;
                    }

                    if ((ObjectText.Trim() != "") && (ProjectID > 0) && (SetID > 0))
                    {
                        using (DataStuff sn = new DataStuff())
                        {
                            Success = sn.DoProjectBackup(SetID, ProjectID, ObjectName, DatabaseName, ObjectText);
                        }
                    }
                    else
                    {
                        Success = false;
                    }

                    RowCount++;

                    if (Success)
                    {
                        SuccessCount++;
                    }
                    else
                    {
                        FoundError = true;
                        FailCount++;
                    }

                    if (FoundError)
                    {
                        MessageBox.Show("There was an error backing up object " + ObjectName + ".", "Project Backup", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                catch
                {
                }

                Application.DoEvents();
            }

            if ((SuccessCount > 0) && (FailCount == 0))
            {
                MessageBox.Show(SuccessCount.ToString() + " objects successfully backed-up.", "Project Backup", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show(SuccessCount.ToString() + " objects successfully backed-up, " + FailCount.ToString() + " objects failed to back-up.", "Project Backup", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }