コード例 #1
0
ファイル: StudentForm.cs プロジェクト: zirax007/WindowsForms
        private void addStudent_Click(object sender, EventArgs e)
        {
            string sex = female.Text;

            if (male.Checked)
            {
                sex = male.Text;
            }
            if (!checkEmptyAttributes())
            {
                Request request = new Request(RequestType.AddStudent, new Student(0, (Branch)branchStudent.SelectedItem, cneStudent.Text, studentName.Text, studenLastName.Text, sex, address.Text, dateTimePicker1.Value, phone.Text));
                byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                socket.Send(buffer);
                buffer = new byte[1024];
                int size = socket.Receive(buffer);
                Array.Resize(ref buffer, size);
                bool answer = (bool)SerializeDeserializeObject.Deserialize(buffer);
                if (answer)
                {
                    new MessageBx("L'ajout a réussi", "L'ajout").Show();
                }
                else
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }
                resetAllAttributes();
                refreshDataGrid();
            }
            else
            {
                new MessageBx("Veuillez remplir tous les champs", "Attention").Show();
            }
        }
コード例 #2
0
ファイル: BranchForm.cs プロジェクト: zirax007/WindowsForms
 private void addBranch_Click(object sender, EventArgs e)
 {
     if (BranchName.Text != "")
     {
         try
         {
             Request request = new Request(RequestType.AddBranch, new Branch(0, BranchName.Text));
             byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
             socket.Send(buffer);
             buffer = new byte[1024];
             int size = socket.Receive(buffer);
             Array.Resize(ref buffer, size);
             bool answer = (bool)SerializeDeserializeObject.Deserialize(buffer);
             if (answer)
             {
                 new MessageBx("L'ajout a réussi", "L'ajout").Show();
                 BranchName.Text = "";
                 actualiserLeTableau();
             }
             else
             {
                 new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
             }
         }
         catch (Exception)
         {
             new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").ShowDialog();
         }
     }
     else
     {
         new MessageBx("Veuillez remplir le champ", "Attention").ShowDialog();
     }
 }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: zirax007/WindowsForms
        private void validate_Click(object sender, EventArgs e)
        {
            if (currrentPass.Text == "" || newPassword.Text == "")
            {
                new MessageBx("Veuillez remplir tous les champs", "Attention").Show();
            }
            else
            {
                Request request = new Request(RequestType.UpdateUser, new User(idUser, username.Text, newPassword.Text));
                byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                socket.Send(buffer);
                buffer = new byte[1024];
                int size = socket.Receive(buffer);
                Array.Resize(ref buffer, size);
                bool answer = (bool)SerializeDeserializeObject.Deserialize(buffer);
                Console.WriteLine(idUser + "");
                Console.WriteLine(answer);
                if (answer)
                {
                    new MessageBx("La modification a réussi", "Modification").Show();
                    user.Text = username.Text;
                }
                else
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }

                param.Visible = false;
            }
        }
コード例 #4
0
ファイル: Graphic.cs プロジェクト: zirax007/WindowsForms
        public Graphic(Socket sock)
        {
            InitializeComponent();
            socket = sock;
            Request request = new Request(RequestType.GetStatics, null);

            byte[] buffer = SerializeDeserializeObject.Serialize(request);
            socket.Send(buffer);
            buffer = new byte[1024 * 1024];
            int size = socket.Receive(buffer);

            Array.Resize(ref buffer, size);
            int total = 0;
            Dictionary <string, int> answer = (Dictionary <string, int>)SerializeDeserializeObject.Deserialize(buffer);

            foreach (var item in answer)
            {
                total += item.Value;
            }
            int position = 0;

            foreach (var item in answer)
            {
                string percentage = Math.Round(((double)(item.Value * 100) / total), 2) + "%";
                setGraph(item.Value, item.Key, percentage, position);
                position += 1;
                //Console.WriteLine(percentage + "  " + position);
            }
        }
コード例 #5
0
ファイル: BranchForm.cs プロジェクト: zirax007/WindowsForms
        private void updateBranch_Click(object sender, EventArgs e)
        {
            Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);

            if (selectedRowCount > 0)
            {
                //int lignes = 0;
                for (int i = 0; i < selectedRowCount; i++)
                {
                    int    id = Int32.Parse(dataGridView1.SelectedRows[i].Cells["Id_Filière"].Value.ToString());
                    string branchNameTable = dataGridView1.SelectedRows[i].Cells["Nom_Filière"].Value.ToString();
                    try
                    {
                        MessageUpdate msg = new MessageUpdate();
                        msg.UpdateNamebranch.Text = branchNameTable;
                        msg.ShowDialog();
                        Request request = new Request(RequestType.UpdateBranch, new Branch(id, msg.UpdateNamebranch.Text));
                        byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                        socket.Send(buffer);
                        buffer = new byte[1024];
                        int size = socket.Receive(buffer);
                        Array.Resize(ref buffer, size);
                        bool answer = (bool)SerializeDeserializeObject.Deserialize(buffer);
                        if (answer)
                        {
                            new MessageBx("La modification a réussi", "Modification").ShowDialog();
                            actualiserLeTableau();
                        }
                        else
                        {
                            new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").ShowDialog();
                        }
                    }
                    catch (Exception)
                    {
                        new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").ShowDialog();
                    }
                }
            }
            else
            {
                new MessageBx("Veuillez sélectionner une ligne", "Attention").ShowDialog();
            }
        }
コード例 #6
0
ファイル: StudentForm.cs プロジェクト: zirax007/WindowsForms
        private void deleteStudent_Click(object sender, EventArgs e)
        {
            Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);

            if (selectedRowCount > 0)
            {
                for (int i = 0; i < selectedRowCount; i++)
                {
                    // get the data
                    try
                    {
                        string  cne     = dataGridView1.SelectedRows[i].Cells["CNE"].Value.ToString();
                        Request request = new Request(RequestType.DeleteStudent, cne);
                        byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                        socket.Send(buffer);
                        buffer = new byte[1024];
                        int size = socket.Receive(buffer);
                        Array.Resize(ref buffer, size);
                        bool answer = (bool)SerializeDeserializeObject.Deserialize(buffer);
                        if (answer)
                        {
                            new MessageBx("La suppression a réussi", "Suppression").Show();
                            refreshDataGrid();
                        }
                        else
                        {
                            new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                        }
                    }
                    catch (Exception)
                    {
                        new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                    }
                }
            }
            else
            {
                new MessageBx("Veuillez sélectionner une ligne", "Attention").Show();
            }
        }
コード例 #7
0
ファイル: StudentForm.cs プロジェクト: zirax007/WindowsForms
 private void getAllBranches()
 {
     try
     {
         Request request = new Request(RequestType.GetAllBranches, null);
         byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
         socket.Send(buffer);
         buffer = new byte[1024];
         int size = socket.Receive(buffer);
         Array.Resize(ref buffer, size);
         dataGridView1.Rows.Clear();
         List <Branch> branches = (List <Branch>)SerializeDeserializeObject.Deserialize(buffer);
         foreach (Branch branch in branches)
         {
             branchStudent.Items.Add(branch);
         }
     }
     catch (SocketException ex)
     {
         new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show(); Console.WriteLine(ex.Message);
     }
 }
コード例 #8
0
ファイル: StudentForm.cs プロジェクト: zirax007/WindowsForms
 private void refreshDataGrid()
 {
     try
     {
         Request request = new Request(RequestType.GetAllStudnets, null);
         byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
         socket.Send(buffer);
         buffer = new byte[1024 * 1024];
         int size = socket.Receive(buffer);
         Array.Resize(ref buffer, size);
         dataGridView1.Rows.Clear();
         List <Student> students = (List <Student>)SerializeDeserializeObject.Deserialize(buffer);
         foreach (var student in students)
         {
             dataGridView1.Rows.Add(student.CNE, student.Nom, student.Prenom, student.Sex, student.DateNessance, student.Adresse, student.Telephone, student.Branch.Nom, student.Id);
         }
     }
     catch (SocketException)
     {
         new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
     }
 }
コード例 #9
0
ファイル: StudentForm.cs プロジェクト: zirax007/WindowsForms
        private void getStudentByCNE(object sender, EventArgs e)
        {
            if (cneSearch.Text != "")
            {
                try
                {
                    Request request = new Request(RequestType.GetOneStudnet, cneSearch.Text);
                    byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                    socket.Send(buffer);
                    buffer = new byte[1024 * 1024];
                    int size = socket.Receive(buffer);
                    Array.Resize(ref buffer, size);
                    Dictionary <bool, Student> answer = SerializeDeserializeObject.Deserialize(buffer) as Dictionary <bool, Student>;

                    foreach (var item in answer)
                    {
                        if (item.Key)
                        {
                            dataGridView1.Rows.Clear();
                            dataGridView1.Rows.Add(item.Value.CNE, item.Value.Nom, item.Value.Prenom, item.Value.Sex, item.Value.DateNessance, item.Value.Adresse, item.Value.Telephone, item.Value.Branch.Nom, item.Value.Id);
                            cneSearch.Text = "";
                        }
                        else
                        {
                            new MessageBx("Veuillez vérifier le CNE", "Attention").Show();
                        }
                    }
                }
                catch (SocketException)
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }
            }
            else
            {
                new MessageBx("Veuillez remplir le champ", "Attention").Show();
            }
        }
コード例 #10
0
        private void iconButton2_Click(object sender, EventArgs e)
        {
            if (cneStudent.Text != "")
            {
                try
                {
                    //get the student by his cne from the server.
                    Request request = new Request(RequestType.GetOneStudnet, cneStudent.Text);
                    byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                    socket.Send(buffer);
                    buffer = new byte[2048];
                    int size = socket.Receive(buffer);
                    Array.Resize(ref buffer, size);
                    Dictionary <bool, Student> answer = SerializeDeserializeObject.Deserialize(buffer) as Dictionary <bool, Student>;

                    /*                    FolderBrowserDialog folder = new FolderBrowserDialog();
                     *                  if (folder.ShowDialog() == DialogResult.OK)
                     *                  {*/
                    if (answer.Keys.First())
                    {
                        new oneStudentReportViewerForm(answer.Values.First()).Show();
                        cneStudent.Text = "";
                    }
                    else
                    {
                        new MessageBx("Veuillez vérifier le CNE", "Attention").Show();
                    }
                }
                catch (SocketException)
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }
            }
            else
            {
                new MessageBx("Veuillez remplir le champs", "Attention").Show();
            }
        }
コード例 #11
0
ファイル: BranchForm.cs プロジェクト: zirax007/WindowsForms
 private void actualiserLeTableau()
 {
     try
     {
         //Création de l'objet request à comme paramètre la demande de type avoir toutes les filières.
         Request request = new Request(RequestType.GetAllBranches, null);
         // la sérialisation de l'objet requeqt.
         byte[] buffer = SerializeDeserializeObject.Serialize(request);
         socket.Send(buffer);                                                                    // Envoyer l'objet.
         buffer = new byte[1024];                                                                // réinitialiser le buffer.
         int size = socket.Receive(buffer);                                                      // Recevoir la réponse du serveur.
         Array.Resize(ref buffer, size);                                                         // redimensionner le buffer
         List <Branch> filieres = (List <Branch>)SerializeDeserializeObject.Deserialize(buffer); // la sérialisation de la réponse.
         dataGridView1.Rows.Clear();
         foreach (Branch filiere in filieres)
         {
             dataGridView1.Rows.Add(filiere.Id, filiere.Nom);
         }
     }
     catch (SocketException)
     {
         new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").ShowDialog();
     }
 }
コード例 #12
0
ファイル: Login.cs プロジェクト: zirax007/WindowsForms
        private void signIn_Click(object sender, EventArgs e)
        {
            User user;

            try
            {
                string serverIp = ConfigurationManager.AppSettings["serverIpAddress"];
                int    port     = Int32.Parse(ConfigurationManager.AppSettings["communicationPort"]);
                socket        = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                localEndPoint = new IPEndPoint(IPAddress.Parse(serverIp), port);
                socket.Connect(localEndPoint);
                user = new User(0, username.Text, password.Text);
                Request request = new Request(RequestType.CheckUser, user);
                byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                socket.Send(buffer);
                buffer = new byte[2048];
                int size = socket.Receive(buffer);
                Array.Resize(ref buffer, size);
                Dictionary <bool, int> answer = (Dictionary <bool, int>)SerializeDeserializeObject.Deserialize(buffer);

                if (answer.Keys.First())
                {
                    new MainForm(answer.Values.First(), username.Text, socket, this).Show();
                    Hide();
                }
                else
                {
                    new MessageBx("Le mot de passe ou le nom d'utilisateur\nest incorrect", "Attention").ShowDialog();
                }
            }
            catch (SocketException)
            {
                socket.Close();
                new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").ShowDialog();
            }
        }
コード例 #13
0
        public override void run()
        {
            int size = 1024;

            byte[] buffer = new byte[size];
            while (true)
            {
                try
                {
                    buffer = new byte[1024];
                    size   = socket.Receive(buffer);
                    Console.WriteLine(size);
                    Array.Resize(ref buffer, size);
                    Request request = (Request)SerializeDeserializeObject.Deserialize(buffer);

                    Object answer         = null;
                    int    nbRowsAffected = 0;
                    string CNE;
                    Branch branch;
                    switch (request.Type)
                    {
                    case RequestType.AddStudent:
                        Student student = (Student)request.Data;
                        Console.WriteLine("Adding student ...");
                        nbRowsAffected = connection.addStudent(student);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;

                    case RequestType.UpdateStudent:
                        Student data = (Student)request.Data;
                        Console.WriteLine("Updating student ...");
                        nbRowsAffected = connection.updateStudent(data);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;

                    case RequestType.GetOneStudnet:
                        Console.WriteLine("getting one Student");
                        CNE    = (string)request.Data;
                        answer = connection.getStudent(CNE);
                        break;

                    case RequestType.GetAllStudnets:
                        Console.WriteLine("getting all students");
                        answer = connection.getAllStudents();
                        break;

                    case RequestType.GetStudentByBranch:
                        Console.WriteLine("getting all students grouping by branch");
                        answer = connection.getStudentsByBranch();
                        break;

                    case RequestType.DeleteStudent:
                        Console.WriteLine("Deleting the student");
                        CNE            = (string)request.Data;
                        nbRowsAffected = connection.deleteStudent(CNE);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;

                    case RequestType.AddBranch:
                        Console.WriteLine("Adding a branch");
                        branch         = (Branch)request.Data;
                        nbRowsAffected = connection.addBranch(branch);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;

                    case RequestType.UpdateBranch:
                        Console.WriteLine("Updating a branch");
                        branch         = (Branch)request.Data;
                        nbRowsAffected = connection.updateBranch(branch);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;

                    case RequestType.GetAllBranches:
                        Console.WriteLine("Getting all branches");
                        answer = connection.getAllBranchs();
                        break;

                    case RequestType.DeleteBranch:
                        Console.WriteLine("Deleting the branch");
                        int ID = (int)request.Data;
                        nbRowsAffected = connection.deleteBranch(ID);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;

                    case RequestType.GetStatics:
                        Console.WriteLine("Getting the statistics");
                        answer = connection.getStatistics();
                        break;

                    case RequestType.CheckUser:
                        Console.WriteLine("Getting the user");
                        User user = request.Data as User;
                        answer = connection.CheckUser(user);

                        break;

                    case RequestType.UpdateUser:
                        Console.WriteLine("Updating the user");
                        User userUpadte = request.Data as User;
                        nbRowsAffected = connection.UpdateUser(userUpadte);
                        if (nbRowsAffected > 0)
                        {
                            answer = true;
                        }
                        else
                        {
                            answer = false;
                        }
                        break;
                    }

                    byte[] bufferAnswer = SerializeDeserializeObject.Serialize(answer);

                    socket.Send(bufferAnswer);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);

                    /*socket.Close();
                     * socket.Dispose();*/
                    break;
                }
            }
        }
コード例 #14
0
        private void iconButton5_Click(object sender, EventArgs e)
        {
            Dictionary <string, int> branches = new Dictionary <string, int>();

            foreach (Branch item in branchStudent.Items)
            {
                branches.Add(item.Nom, item.Id);
            }
            var filePath = string.Empty;

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.InitialDirectory = "c:\\";
                openFileDialog.Filter           = "Excel files (*.xls)|*.xls";
                openFileDialog.FilterIndex      = 2;
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Get the path of specified file
                    filePath = openFileDialog.FileName;
                }
            }

            //if the user selected a file
            if (!filePath.Equals(""))
            {
                List <Student> students = null;
                try
                {
                    ExcelReader excelReader = new ExcelReader(socket);
                    students = excelReader.ReadFromExcel(filePath);
                    ExcelViewer excelViewer = new ExcelViewer(students);
                    excelViewer.ShowDialog();
                    //if the user confirmed his uploading
                    if (excelViewer.answer)
                    {
                        foreach (var student in students)
                        {
                            Request request = new Request(RequestType.AddStudent, student);
                            byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                            socket.Send(buffer);
                            buffer = new byte[1024];
                            int size = socket.Receive(buffer);
                            Array.Resize(ref buffer, size);
                            bool answer = (bool)SerializeDeserializeObject.Deserialize(buffer);
                            if (!answer)
                            {
                                MessageBx warning = new MessageBx("Probléme", "Probléme");
                                warning.ShowDialog();
                            }
                            else
                            {
                                Console.WriteLine("Student " + student.Nom + " " + student.Prenom + " addedsuccesfully");
                            }
                        }
                        if (ExcelReader.errorMessages.Count > 0)
                        {
                            foreach (var msg in ExcelReader.errorMessages)
                            {
                                MessageBx warning = new MessageBx(msg, "Probléme");
                                warning.ShowDialog();
                            }
                        }
                    }

                    refreshDataGrid();
                }
                catch (SocketException)
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }
                catch (Exception)
                {
                    new MessageBx("Nous avons rencontré un problème dans la lecture du fichier!\nVeulliez correcter votre fichier et réessayer plus tard.", "Problème du fichier Excel").Show();
                }
            }
        }
コード例 #15
0
ファイル: ExcelReader.cs プロジェクト: zirax007/WindowsForms
        public List <Student> ReadFromExcel(String filePath)
        {
            errorMessages = new List <string>();
            List <Student> students = new List <Student>();

            //getting all existed branches as a Dictionary of <name, id>
            Dictionary <string, int> branches = new Dictionary <string, int>();
            Request request = new Request(RequestType.GetAllBranches, null);

            byte[] buffer = SerializeDeserializeObject.Serialize(request);
            socket.Send(buffer);
            buffer = new byte[1024];
            int size = socket.Receive(buffer);

            Array.Resize(ref buffer, size);

            foreach (var item in (List <Branch>)SerializeDeserializeObject.Deserialize(buffer))
            {
                branches.Add(item.Nom, item.Id);
            }

            string con = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";"
                         + @"Extended Properties='Excel 8.0;HDR=Yes;'";

            using (OleDbConnection connection = new OleDbConnection(con))
            {
                try
                {
                    connection.Open();
                    OleDbCommand command = new OleDbCommand("select * from [Sheet1$]", connection);
                    using (OleDbDataReader dr = command.ExecuteReader())
                    {
                        var columns = new {
                            CNE               = dr.GetOrdinal("CNE"),
                            nom               = dr.GetOrdinal("Nom"),
                            prenom            = dr.GetOrdinal("Prenom"),
                            sex               = dr.GetOrdinal("Sex"),
                            address           = dr.GetOrdinal("Address"),
                            date_de_naissance = dr.GetOrdinal("date de naissance"),
                            telephone         = dr.GetOrdinal("Telephone"),
                            nom_filiere       = dr.GetOrdinal("Filiere")
                        };

                        //checking if the branch existed



                        while (dr.Read())
                        {
                            string branchName = dr.GetString(columns.nom_filiere);
                            if (branches.ContainsKey(branchName))
                            {
                                students.Add(new Student(0, new Branch(branches[branchName], branchName), dr.GetString(columns.CNE), dr.GetString(columns.nom), dr.GetString(columns.prenom), dr.GetString(columns.sex), dr.GetString(columns.address), dr.GetDateTime(columns.date_de_naissance), dr.GetDouble(columns.telephone).ToString()));
                            }
                            else
                            {
                                errorMessages.Add("Impossible d'ajouter l'etudiant " + dr.GetString(columns.nom) + " " + dr.GetString(columns.prenom) //message
                                                  + "\nCause: filiere " + dr.GetString(columns.nom_filiere) + " n'existe pas");
                            }
                        }
                    }
                }
                catch (SocketException ex)
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    connection.Close();
                    throw ex;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine(e.StackTrace);
                    connection.Close();
                    throw e;
                }
                finally
                {
                    connection.Close();
                }
            }
            return(students);
        }
コード例 #16
0
        private void iconButton2_Click(object sender, EventArgs e)
        {
            MessageBoxYesNo messageBoxYesNo = new MessageBoxYesNo("Vous voulez Télécharger le Reporting ?", "Télécharger le Reporting");

            messageBoxYesNo.ShowDialog();
            if (messageBoxYesNo.Answer)
            {
                try
                {
                    Request request = new Request(RequestType.GetStudentByBranch, null);
                    byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                    socket.Send(buffer);
                    buffer = new byte[1024 * 1024];
                    int size = socket.Receive(buffer);
                    Array.Resize(ref buffer, size);
                    Dictionary <string, List <Student> > StudentsByBranch = (Dictionary <string, List <Student> >)SerializeDeserializeObject.Deserialize(buffer);

                    //select the path of the folder where we will store the pdf file
                    FolderBrowserDialog folder = new FolderBrowserDialog();
                    if (folder.ShowDialog() == DialogResult.OK)
                    {
                        // Create the pdf
                        Document document = new Document();
                        PdfWriter.GetInstance(document, new FileStream(folder.SelectedPath + "\\Reporting.pdf", FileMode.Create));
                        document.Open();
                        // ENSAS Logo
                        iTextSharp.text.Image ensasLogo = iTextSharp.text.Image.GetInstance(@".\Resources\logo.png");
                        ensasLogo.ScalePercent(50);
                        ensasLogo.SetAbsolutePosition(document.PageSize.Width - 120f, document.PageSize.Height - 100f);
                        document.Add(ensasLogo);
                        // UCA Logo
                        iTextSharp.text.Image ucaLogo = iTextSharp.text.Image.GetInstance(@".\Resources\ucaLogo.jpg");
                        ucaLogo.ScalePercent(50);
                        ucaLogo.SetAbsolutePosition(15f, document.PageSize.Height - 100f);
                        document.Add(ucaLogo);

                        // Title
                        Paragraph paragraph = new Paragraph(new Phrase("Ecole Nationale des Sciences Appliquées de", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 13f, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLUE)));
                        paragraph.IndentationLeft = 95f;
                        document.Add(paragraph);
                        Paragraph paragraph_2 = new Paragraph(new Phrase("SAFI", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 13f, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLUE)));
                        paragraph_2.IndentationLeft = 250f;
                        document.Add(paragraph_2);

                        //New Lines
                        document.Add(new Paragraph("\n\n\n\n\n"));
                        // Set the data of all students by branch:
                        foreach (var item in StudentsByBranch)
                        {
                            // Create a table
                            PdfPTable table = new PdfPTable(5);
                            table.TotalWidth  = 545f;
                            table.LockedWidth = true;
                            float[] widths = new float[] { 90f, 115f, 140f, 110f, 90f };
                            table.SetWidths(widths);
                            PdfPCell cell = new PdfPCell(new Phrase(item.Key, new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.WHITE)));
                            cell.BackgroundColor = new iTextSharp.text.BaseColor(43, 78, 132);

                            // Added some padding into the headercell
                            cell.PaddingTop          = 10;
                            cell.PaddingBottom       = 10;
                            cell.Colspan             = 5;
                            cell.HorizontalAlignment = 1;
                            table.AddCell(cell);

                            // First Row :
                            PdfPCell cell1 = new PdfPCell(new Phrase("CNE", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE)));
                            MakePaddingAndColor(cell1);
                            table.AddCell(cell1);
                            PdfPCell cell2 = new PdfPCell(new Phrase("Nom et prénom", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE)));
                            MakePaddingAndColor(cell2);
                            table.AddCell(cell2);
                            PdfPCell cell3 = new PdfPCell(new Phrase("Date de naissance", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE)));
                            MakePaddingAndColor(cell3);
                            table.AddCell(cell3);
                            PdfPCell cell4 = new PdfPCell(new Phrase("Adresse", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE)));
                            MakePaddingAndColor(cell4);
                            table.AddCell(cell4);
                            PdfPCell cell5 = new PdfPCell(new Phrase("Téléphone", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLUE)));
                            MakePaddingAndColor(cell5);
                            table.AddCell(cell5);


                            // the rest of each table:
                            foreach (var student in item.Value)
                            {
                                table.AddCell(MakePadding(new PdfPCell(new Phrase(student.CNE))));
                                table.AddCell(MakePadding(new PdfPCell(new Phrase(student.Nom.ToUpper() + " " + student.Prenom))));
                                table.AddCell(MakePadding(new PdfPCell(new Phrase(student.DateNessance.ToShortDateString()))));
                                table.AddCell(MakePadding(new PdfPCell(new Phrase(student.Adresse))));
                                table.AddCell(MakePadding(new PdfPCell(new Phrase(student.Telephone))));
                            }

                            // add the table
                            document.Add(table);
                            document.Add(new Paragraph("\n\n"));
                        }

                        document.Close();
                        new MessageBx("Le téléchargement est terminé", "Le téléchargement").Show();
                    }
                }
                catch (SocketException)
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }
            }
        }
コード例 #17
0
        public allStudentsReportViewerForm(Socket socket)
        {
            this.socket = socket;

            branches = new List <AllStudentsReportAdapter>();
            Request request = new Request(RequestType.GetStudentByBranch, null);

            byte[] buffer = SerializeDeserializeObject.Serialize(request);
            socket.Send(buffer);
            buffer = new byte[1024 * 1024];
            int size = socket.Receive(buffer);

            Array.Resize(ref buffer, size);
            Dictionary <string, List <Student> > StudentsByBranch = (Dictionary <string, List <Student> >)SerializeDeserializeObject.Deserialize(buffer);


            students = new Dictionary <string, List <OneStudentReportAdapter> >();
            foreach (var item in StudentsByBranch)
            {
                List <OneStudentReportAdapter> studentAdapters = new List <OneStudentReportAdapter>();
                foreach (var student in item.Value)
                {
                    studentAdapters.Add(new OneStudentReportAdapter(student));
                }
                students.Add(item.Key, studentAdapters);
            }


            foreach (var item in students.Keys)
            {
                branches.Add(new AllStudentsReportAdapter(item, null));
            }
            InitializeComponent();
        }
コード例 #18
0
        private void download_Click(object sender, EventArgs e)
        {
            if (cneStudent.Text != "")
            {
                try
                {
                    //get the student by his cne from the server.
                    Request request = new Request(RequestType.GetOneStudnet, cneStudent.Text);
                    byte[]  buffer  = SerializeDeserializeObject.Serialize(request);
                    socket.Send(buffer);
                    buffer = new byte[2048];
                    int size = socket.Receive(buffer);
                    Array.Resize(ref buffer, size);
                    Dictionary <bool, Student> answer = SerializeDeserializeObject.Deserialize(buffer) as Dictionary <bool, Student>;

                    /*                    FolderBrowserDialog folder = new FolderBrowserDialog();
                     *                  if (folder.ShowDialog() == DialogResult.OK)
                     *                  {*/
                    if (answer.Keys.First())
                    {
                        // Get the folder path
                        string path = string.Empty;
                        FolderBrowserDialog folder = new FolderBrowserDialog();
                        if (folder.ShowDialog() == DialogResult.OK)
                        {
                            path = folder.SelectedPath;

                            Document document = new Document();
                            PdfWriter.GetInstance(document, new FileStream(path + "\\" + answer.Values.First().CNE + ".pdf", FileMode.Create));
                            document.Open();
                            // ENSAS Logo
                            iTextSharp.text.Image ensasLogo = iTextSharp.text.Image.GetInstance(@".\Resources\logo.png");
                            ensasLogo.ScalePercent(50);
                            ensasLogo.SetAbsolutePosition(document.PageSize.Width - 120f, document.PageSize.Height - 100f);
                            document.Add(ensasLogo);
                            // UCA Logo
                            iTextSharp.text.Image ucaLogo = iTextSharp.text.Image.GetInstance(@".\Resources\ucaLogo.jpg");
                            ucaLogo.ScalePercent(50);
                            ucaLogo.SetAbsolutePosition(15f, document.PageSize.Height - 100f);
                            document.Add(ucaLogo);
                            // Title
                            Paragraph paragraph = new Paragraph(new Phrase("Ecole Nationale des Sciences Appliquées de", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 13f, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLUE)));
                            paragraph.IndentationLeft = 95f;
                            document.Add(paragraph);
                            Paragraph paragraph_2 = new Paragraph(new Phrase("SAFI", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 13f, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLUE)));
                            paragraph_2.IndentationLeft = 250f;
                            document.Add(paragraph_2);
                            //New Lines
                            document.Add(new Paragraph("\n\n\n\n\n\n\n\n"));

                            // added name of the student
                            Paragraph title = new Paragraph(new Phrase("Information de L'Etudiant(e): " + answer.Values.First().Nom + " " + answer.Values.First().Prenom, new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 14f, iTextSharp.text.Font.BOLDITALIC, iTextSharp.text.BaseColor.BLACK)));
                            title.IndentationLeft = 80f;
                            document.Add(title);

                            //New Lines
                            document.Add(new Paragraph("\n\n\n\n\n"));

                            //  set cne of the setudent
                            Phrase cne = new Phrase("CNE:          ", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 14f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK));
                            document.Add(cne);
                            document.Add(new Phrase(answer.Values.First().CNE + "\n\n", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 13f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE)));
                            //  set branch name of the setudent
                            Phrase branch = new Phrase("Nom filière:  ", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 14f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.BLACK));
                            document.Add(branch);
                            document.Add(new Phrase(answer.Values.First().Branch.ToString() + "\n\n\n\n\n\n", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 13f, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLUE)));

                            // set the other information:
                            PdfPTable table = new PdfPTable(4);
                            table.TotalWidth  = 520f;
                            table.LockedWidth = true;
                            float[] widths = new float[] { 150f, 150f, 110f, 110f };
                            table.SetWidths(widths);

                            // First  row in the table
                            // First Row :
                            PdfPCell cell1 = new PdfPCell(new Phrase("Date de Naissance", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.WHITE)));
                            MakePaddingAndColor(cell1);
                            table.AddCell(cell1);
                            PdfPCell cell2 = new PdfPCell(new Phrase("Adresse", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.WHITE)));
                            MakePaddingAndColor(cell2);
                            table.AddCell(cell2);
                            PdfPCell cell3 = new PdfPCell(new Phrase("Téléphone", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.WHITE)));
                            MakePaddingAndColor(cell3);
                            table.AddCell(cell3);
                            PdfPCell cell4 = new PdfPCell(new Phrase("Sexe", new iTextSharp.text.Font(iTextSharp.text.Font.NORMAL, 12f, iTextSharp.text.Font.BOLD, iTextSharp.text.BaseColor.WHITE)));
                            MakePaddingAndColor(cell4);
                            table.AddCell(cell4);


                            // Second  row in the table

                            table.AddCell(MakePadding(new PdfPCell(new Phrase(answer.Values.First().DateNessance.ToShortDateString()))));
                            table.AddCell(MakePadding(new PdfPCell(new Phrase(answer.Values.First().Adresse))));
                            table.AddCell(MakePadding(new PdfPCell(new Phrase(answer.Values.First().Telephone))));
                            table.AddCell(MakePadding(new PdfPCell(new Phrase(answer.Values.First().Sex))));
                            document.Add(table);

                            document.Add(new Paragraph("\n\n\n\n\n\n\n\n\n\n"));
                            document.Add(new Paragraph("Date du jour: " + DateTime.Today.ToShortDateString() +
                                                       "                                                                                 " + "Signature"));
                            document.Close();

                            new MessageBx("Le téléchargement est terminé", "Le téléchargement").Show();
                            cneStudent.Text = "";
                        }
                    }
                    else
                    {
                        new MessageBx("Veuillez vérifier le CNE", "Attention").Show();
                    }
                }
                catch (SocketException)
                {
                    new MessageBx("Nous avons rencontré un problème!\nRéessayer plus tard.", "Problème de serveur").Show();
                }
            }
            else
            {
                new MessageBx("Veuillez remplir le champs", "Attention").Show();
            }
        }