Ejemplo n.º 1
0
        private void Delete_Module(object sender, EventArgs e)
        {
            if (MessageBox.Show(GetLabel("Quest.0003"), GetLabel("Quest"), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == System.Windows.Forms.DialogResult.Yes)
            {
                SynapseModule _module = (SynapseModule)olvModules.SelectedObject;
                IList <SynapseProfile_Control> _profileControl = SynapseProfile_Control.LoadFromQuery("SELECT dbo.[Synapse_Security_Profile Control].* FROM dbo.[Synapse_Security_Profile Control] INNER JOIN dbo.Synapse_Security_Profile ON dbo.[Synapse_Security_Profile Control].FK_PROFILEID = dbo.Synapse_Security_Profile.ID INNER JOIN dbo.Synapse_Module ON dbo.Synapse_Security_Profile.FK_MODULEID = dbo.Synapse_Module.ID WHERE (dbo.Synapse_Module.ID = " + _module.ID + ")");
                IList <SynapseUser_Profile>    _userProfile    = SynapseUser_Profile.LoadFromQuery("SELECT dbo.[Synapse_Security_User Profile].* FROM dbo.[Synapse_Security_User Profile] INNER JOIN dbo.Synapse_Security_Profile ON dbo.[Synapse_Security_User Profile].FK_SECURITY_PROFILE = dbo.Synapse_Security_Profile.ID INNER JOIN dbo.Synapse_Module ON dbo.Synapse_Security_Profile.FK_MODULEID = dbo.Synapse_Module.ID WHERE (dbo.Synapse_Module.ID = " + _module.ID + ")");
                IList <SynapseProfile>         _profile        = SynapseProfile.LoadFromQuery("SELECT dbo.Synapse_Security_Profile.* FROM dbo.Synapse_Security_Profile INNER JOIN dbo.Synapse_Module ON dbo.Synapse_Security_Profile.FK_MODULEID = dbo.Synapse_Module.ID WHERE (dbo.Synapse_Module.ID = " + _module.ID + ")");
                IList <SynapseControl>         _control        = SynapseControl.Load("WHERE FK_MODULE_ID=" + _module.ID);

                SynapseCore.Database.DBFunction.StartTransaction();
                try
                {
                    foreach (SynapseProfile_Control obj in _profileControl)
                    {
                        obj.delete();
                    }
                    foreach (SynapseUser_Profile obj in _userProfile)
                    {
                        obj.delete();
                    }
                    foreach (SynapseProfile obj in _profile)
                    {
                        obj.delete();
                    }
                    foreach (SynapseControl obj in _control)
                    {
                        obj.delete();
                    }
                    foreach (SynapseLabel obj in ((SynapseModule)olvModules.SelectedObject).FriendlyName.Labels)
                    {
                        obj.delete();
                    }
                    foreach (SynapseLabel obj in ((SynapseModule)olvModules.SelectedObject).Description.Labels)
                    {
                        obj.delete();
                    }

                    _module.delete();

                    SynapseCore.Database.DBFunction.CommitTransaction();

                    listModule();
                }
                catch (Exception ex)
                {
                    SynapseCore.Database.DBFunction.RollbackTransaction();
                    MessageBox.Show("Data not deleted from Database:" + ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }