Bonjour je suis débutante en C#, et je fais un code pour que la personne dès qu'elle appuie sur un bouton, une fenêtre s'ouvre, pour cérifier si elle a les droits, et enregistrer l'action, Le truc c'est que si elle n'a pas les droits, comment faire pour stopper l'action vue que la demande vient d'une autre fenêtre ?
Voici mon code d'appel de cette fenêtre :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
 
int id_action = 3;
            action_histo childForm = new action_histo(id_action);
            childForm.MdiParent = this;
            childForm.WindowState = FormWindowState.Maximized;
            childForm.Show();
et voici le action_histo :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
 
namespace Planning
{
    public partial class action_histo : Form
    {
        public action_histo(int id_action)
        {
            InitializeComponent();
            Variables.VerifPath();
 
            Tools.DBManager db = new Tools.DBManager(Variables.Stock, 1);
            if (db.open())
            {
                if (db.executeSQL("SELECT Nom FROM Utilis"))
                {
                    while (db.read())
                    {
                        string nom = "";
                        if (!db.getString("Nom", ref nom))
                            Console.WriteLine("Error: " + db.LastError);
                        else
                            cbx_utilisateur.Items.Add(nom);
                    }
                }
                else
                    Console.WriteLine("Error: " + db.LastError);
                db.endRead();
                db.close();
            }
            this.Refresh();
            InitializeComponent();
        }
 
        private void button1_Click(object sender, EventArgs e)
        {
            //DateTime datetime;
            int droit_utilis = 0;
            string id_utilis = "";
            int droit_actiondispo = 0;
            //string string_action = "";
            //string cb_action;
            string cb_utilis;
            //cb_action = cbx_action.Text;
            cb_utilis = cbx_utilisateur.Text;
            Variables.VerifPath();
            Tools.DBManager db = new Tools.DBManager(Variables.Spires, 1);
            if (db.open())
            {
                if (db.executeSQL("SELECT * FROM Utilis WHERE NOM_CLIENT = '" + cb_utilis + "'"))
                {
                    while (db.read())
                    {
                        if (!db.getInt("ID_DROITS", ref droit_utilis))
                            Console.WriteLine("Error: " + db.LastError);
                        if (!db.getString("ID_UTILIS", ref id_utilis))
                            Console.WriteLine("Error: " + db.LastError);
                    }
                }
                else
                    Console.WriteLine("Error: " + db.LastError);
                db.endRead();
                db.close();
            }
             db = new Tools.DBManager(Variables.Planning, 0);
            if (db.open())
            {
                if (db.executeSQL("SELECT * FROM Action_Dispo WHERE Action = '" + id_action + "'"))
                {
                    while (db.read())
                    {
                        if (!db.getInt("Droits", ref droit_actiondispo))
                            Console.WriteLine("Error: " + db.LastError);
                    }
                }
                else
                   Console.WriteLine("Error: " + db.LastError);
 
                db.endRead();
                db.close();
            }
            if (droit_utilis >= droit_actiondispo) 
            {
                db = new Tools.DBManager(Variables.Planning, 0);
                if (db.open())
                {
                    if (db.executeSQL("Insert into HistoPlanning (Id_operateur, DateTime, Id_action) VALUES (" + id_utilis + ",  "  + DateTime.Now + ", " + id_action + ")"))
                    {
                        while (db.read())
                        {
                            //if (!db.getString("Droits", ref droit_actiondispo))
                            //Console.WriteLine("Error: " + db.LastError);
                        }
                    }
                    else
                        Console.WriteLine("Error: " + db.LastError);
                    db.endRead();
                    db.close();
                }
            }
            else
            {
                  MessageBox.Show("Vous n'avez pas les droits pour effectuer cette action");
            }
        }
    }
}
Si quelqu'un pouvait m'aider merci beaucoup