コード例 #1
0
ファイル: Service1.svc.cs プロジェクト: riad9808/poc
        public bool InscrireAttente(ListeAttente l)
        {
            MySqlConnection     connexion = new MySqlConnection("database=bibliotheque; server=localhost; user id=root; pwd=1898;");
            bool                res       = false;
            int                 priorite  = 0;
            List <ListeAttente> test      = ListAttente();

            for (int i = 0; i < test.Count; i++)
            {
                if (test[i].CodeBarre.Equals(l.CodeBarre))
                {
                    if (test[i].Priorite >= priorite)
                    {
                        priorite = test[i].Priorite + 1;
                    }
                }
            }
            l.Priorite = priorite;
            try
            {
                connexion.Open();
                MySqlCommand    sql1 = new MySqlCommand("insert into listeattente values('" + l.CodeBarre + "','" + l.Id + "'," + l.Priorite + ")", connexion);
                MySqlDataReader rd1;
                rd1 = sql1.ExecuteReader();
                connexion.Close();
                res = true;
            }
            catch
            {
                Console.WriteLine("erreuer");
            }
            return(res);
        }
コード例 #2
0
ファイル: Service1.svc.cs プロジェクト: riad9808/poc
        public List <ListeAttente> ListAttente()
        {
            List <ListeAttente> attente   = new List <ListeAttente>();
            MySqlConnection     connexion = new MySqlConnection("database=bibliotheque; server=localhost; user id=root; pwd=1898;");

            try
            {
                connexion.Open();
                MySqlCommand    sqlet = new MySqlCommand("select * from listeattente ", connexion);
                MySqlDataReader rd;
                rd = sqlet.ExecuteReader();
                while (rd.Read())
                {
                    ListeAttente la = new ListeAttente();
                    la.CodeBarre = int.Parse(rd["codebare"].ToString());
                    la.Id        = rd["id"].ToString();
                    la.Priorite  = int.Parse(rd["priorite"].ToString());

                    attente.Add(la);
                }
                connexion.Close();
            }
            catch (MySqlException e)
            {
            }
            return(attente);
        }
コード例 #3
0
ファイル: Service1.svc.cs プロジェクト: riad9808/poc
        public void sanctionner()
        {
            MySqlConnection connexion = new MySqlConnection("database=bibliotheque; server=localhost; user id=root; pwd=1898;");

            List <OuvrageEmprent> ouvemp    = ListOuvrageEmprent();
            List <Etudiant>       etudiant  = ListEtudiant();
            List <Ensignant>      ensignant = ListEnsignant();
            List <ListeAttente>   attente   = ListAttente();
            DateTimeOffset        d         = DateTimeOffset.Now;

            for (int i = 0; i < ouvemp.Count; i++)
            {
                if (ouvemp[i].Etat == false)
                {
                    TimeSpan t = d - ouvemp[i].DateEmprent;
                    if (t.Days > 1)
                    {
                        for (int j = 0; j < etudiant.Count; j++)
                        {
                            if (ouvemp[i].Id.Equals(etudiant[j].NumCarte))
                            {
                                if (etudiant[j].NbNonReserve == 2)
                                {
                                    d = d.AddDays(30);
                                    try
                                    {
                                        connexion.Open();
                                        MySqlCommand    sql1 = new MySqlCommand("update emprenteur set etatsanction=1,sanction='" + d.Year + "-" + d.Month + "-" + d.Day + "' where matricule='" + etudiant[j].NumCarte + "'  ", connexion);
                                        MySqlDataReader rd1;
                                        rd1 = sql1.ExecuteReader();
                                        connexion.Close();
                                    }
                                    catch
                                    {
                                        Console.WriteLine("erreuer");
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        connexion.Open();
                                        MySqlCommand    sql1 = new MySqlCommand("update emprenteur set nonConfirme=" + etudiant[j].NbNonReserve + 1 + " where matricule='" + etudiant[j].NumCarte + "'  ", connexion);
                                        MySqlDataReader rd1;
                                        rd1 = sql1.ExecuteReader();
                                        connexion.Close();
                                    }
                                    catch
                                    {
                                        Console.WriteLine("erreuer");
                                    }
                                }
                            }
                        }


                        for (int h = 0; h < ensignant.Count; h++)
                        {
                            if (ouvemp[i].Id.Equals(ensignant[h].Matricule))
                            {
                                if (ensignant[h].NbNonReserve == 2)
                                {
                                    d = d.AddDays(30);
                                    try
                                    {
                                        connexion.Open();
                                        MySqlCommand    sql1 = new MySqlCommand("update emprenteur set nonConfirme=0,etatsanction=1,sanction='" + d.Year + "-" + d.Month + "-" + d.Day + "' where matricule='" + ensignant[h].Matricule + "'  ", connexion);
                                        MySqlDataReader rd1;
                                        rd1 = sql1.ExecuteReader();
                                        connexion.Close();
                                    }
                                    catch
                                    {
                                        Console.WriteLine("erreuer");
                                    }
                                }
                                else
                                {
                                    try
                                    {
                                        connexion.Open();
                                        MySqlCommand    sql1 = new MySqlCommand("update emprenteur set nonConfirme=" + ensignant[h].NbNonReserve + 1 + " where matricule='" + ensignant[h].Matricule + "'  ", connexion);
                                        MySqlDataReader rd1;
                                        rd1 = sql1.ExecuteReader();
                                        connexion.Close();
                                    }
                                    catch
                                    {
                                        Console.WriteLine("erreuer");
                                    }
                                }
                            }
                        }

                        int vartest = 0;
                        for (int m = 0; m < attente.Count; m++)
                        {
                            if (attente[m].CodeBarre.Equals(ouvemp[i].CodeBarre) && vartest == 0)
                            {
                                ListeAttente aajouter = attente[m];
                                for (int n = 0; n < attente.Count; n++)
                                {
                                    if (aajouter.CodeBarre.Equals(attente[n].CodeBarre) && aajouter.Priorite < attente[n].Priorite)
                                    {
                                        aajouter = attente[n];
                                    }
                                }
                                vartest = 1;
                                OuvrageEmprent e = new OuvrageEmprent();
                                e.CodeBarre = aajouter.CodeBarre;
                                e.Id        = aajouter.Id;
                                Reserver(e);
                                try
                                {
                                    connexion.Open();
                                    MySqlCommand    sql1 = new MySqlCommand("delete from listeattente where codebare=" + aajouter.CodeBarre + "and priorite=" + aajouter.Priorite + " ", connexion);
                                    MySqlDataReader rd1;
                                    rd1 = sql1.ExecuteReader();
                                    connexion.Close();
                                }
                                catch
                                {
                                    Console.WriteLine("erreuer");
                                }
                            }
                        }
                        if (vartest == 0)
                        {
                            try
                            {
                                connexion.Open();
                                MySqlCommand    sql1 = new MySqlCommand("update ouvrage set etat=0 where codebarre=" + ouvemp[i].CodeBarre + " ", connexion);
                                MySqlDataReader rd1;
                                rd1 = sql1.ExecuteReader();
                                connexion.Close();
                            }
                            catch
                            {
                                Console.WriteLine("erreuer");
                            }
                        }
                        try
                        {
                            connexion.Open();
                            MySqlCommand    sql1 = new MySqlCommand("delete from ouvrageemprent where numemprent=" + ouvemp[i].Numemprent + " ", connexion);
                            MySqlDataReader rd1;
                            rd1 = sql1.ExecuteReader();
                            connexion.Close();
                        }
                        catch
                        {
                            Console.WriteLine("erreuer");
                        }
                    }
                }
            }
        }
コード例 #4
0
ファイル: Service1.svc.cs プロジェクト: riad9808/poc
        public bool Reserver(OuvrageEmprent o)
        {
            MySqlConnection connexion = new MySqlConnection("database=bibliotheque; server=localhost; user id=root; pwd=1898;");

            bool             res     = false;
            List <Ouvrage>   ouvrage = ListOuvrage();
            List <Etudiant>  etudian = ListEtudiant();
            List <Ensignant> ens     = ListEnsignant();

            for (int i = 0; i < etudian.Count; i++)
            {
                if (etudian[i].NumCarte.Equals(o.Id))
                {
                    if ((etudian[i].EtatCompte == false) || (etudian[i].EtatSanction == true))
                    {
                        return(false);
                    }
                }
            }
            for (int i = 0; i < ens.Count; i++)
            {
                if (ens[i].Matricule.Equals(o.Id))
                {
                    if ((ens[i].EtatCompte == false) || (ens[i].EtatSanction == true))
                    {
                        return(false);
                    }
                }
            }
            for (int i = 0; i < ouvrage.Count; i++)
            {
                if (ouvrage[i].CodeBarre.Equals(o.CodeBarre))
                {
                    if (ouvrage[i].Etat == true)
                    {
                        ListeAttente l = new ListeAttente();
                        l.CodeBarre = o.CodeBarre;
                        l.Id        = o.Id;
                        InscrireAttente(l);
                        return(false);
                    }
                }
            }
            try
            {
                connexion.Open();
                DateTime        d    = DateTime.Now;
                MySqlCommand    sql1 = new MySqlCommand("insert into ouvrageemprent (codebare,id,date) values('" + o.CodeBarre + "','" + o.Id + "','" + d.Year + "-" + d.Month + "-" + d.Day + "')", connexion);
                MySqlDataReader rd1;
                rd1 = sql1.ExecuteReader();
                connexion.Close();
                res = true;
            }
            catch
            {
                Console.WriteLine("erreuer");
            }
            try
            {
                connexion.Open();
                MySqlCommand    sql1 = new MySqlCommand("update ouvrage set etat=1 where codebare='" + o.CodeBarre + "'", connexion);
                MySqlDataReader rd1;
                rd1 = sql1.ExecuteReader();
                connexion.Close();
                res = true;
            }
            catch
            {
                Console.WriteLine("erreuer");
            }
            return(res);
        }