예제 #1
0
        public static bool updatePhotoUsers(Users f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string path = "";
                if (!(f.Photo == null || f.Photo.Trim().Equals("")))
                {
                    path    = f.Photo;
                    f.Photo = Utils.milliseconds() + Path.GetExtension(path);
                }

                string        delete = "update users set photo = '" + f.Photo + "' where id = " + f.Id;
                NpgsqlCommand cmd    = new NpgsqlCommand(delete, con);
                cmd.ExecuteNonQuery();

                if (!(path == null || path.Trim().Equals("")))
                {
                    string chemin = Chemins.getCheminUsers(f.Id.ToString()) + f.Photo;
                    System.IO.File.Copy(path, chemin, true);
                }

                return(true);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(false);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }
예제 #2
0
 private void btn_connecter_Click(object sender, EventArgs e)
 {
     try
     {
         if (ConnectLog())
         {
             timer1.Stop();
             timer2.Stop();
             this.Close();
             Form_Parent f_parent = new Form_Parent();
             if (Constantes.f_parent == null)
             {
                 f_parent.Show();
                 Constantes.f_parent = f_parent;
             }
             else
             {
                 Constantes.f_parent.InitializeComponent();
                 Constantes.f_parent.Show();
             }
             if (Constantes.users != null)
             {
                 Acces.LoadAcces(Constantes.users.Niveau);
                 Constantes.f_parent.txt_users.Text = Constantes.users.Prenom + " " + Constantes.users.Nom;
                 if (!(Constantes.users.Photo == null || Constantes.users.Photo.Trim().Equals("")))
                 {
                     string chemin = Chemins.getCheminUsers(Constantes.users.Id.ToString());
                     if (System.IO.File.Exists(chemin + Constantes.users.Photo))
                     {
                         Constantes.f_parent.box_users.Image = Image.FromFile(chemin + Constantes.users.Photo);
                         return;
                     }
                 }
             }
             Constantes.f_parent.box_users.Image.Dispose();
             Constantes.f_parent.box_users.Image = global::CATALOGUE_ARTICLE.Properties.Resources.contact;
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }
예제 #3
0
        private void box_photo_DoubleClick(object sender, EventArgs e)
        {
            bool add = (bool)(((PictureBox)sender).Tag);

            if (!add)
            {
                OpenFileDialog file = new OpenFileDialog();
                file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                file.Filter           = "Fichiers jpg (*.jpg)|*.jpg|Fichiers png (*.png)|*.png|Fichiers bmp (*.bmp)|*.bmp|Tous les images (*.*)|*.jpg;*.png;*.bmp";
                if (file.ShowDialog(this) == DialogResult.OK)
                {
                    string path = file.FileName;
                    if (path != null ? !path.Trim().Equals("") : false)
                    {
                        current.Photo = path;
                        if (current != null ? current.Id > 0 : false)
                        {
                            if (DialogResult.Yes == Messages.Confirmation(Mots.Enregistrer))
                            {
                                if (UsersBLL.UpdatePhoto(current))
                                {
                                    var t = current.Photo;
                                    box_photo.Image      = Image.FromFile(Chemins.getCheminUsers(current.Id.ToString()) + current.Photo);
                                    box_photo.Tag        = true;
                                    lk_box_photo.Visible = true;
                                    Messages.Succes();
                                }
                            }
                        }
                        else
                        {
                            box_photo.Image = Image.FromFile(current.Photo);
                        }
                    }
                }
            }
            else
            {
                Messages.Information(Mots.Msg_Photo_exist);
            }
        }
예제 #4
0
 private void LoadPhoto(Users u)
 {
     if (u != null ? u.Id > 0 : false)
     {
         if (!(u.Photo == null || u.Photo.Trim().Equals("")))
         {
             string chemin = Chemins.getCheminUsers(u.Id.ToString());
             if (System.IO.File.Exists(chemin + u.Photo))
             {
                 box_photo.Image      = Image.FromFile(chemin + u.Photo);
                 box_photo.Tag        = true;
                 lk_box_photo.Visible = true;
                 return;
             }
         }
     }
     box_photo.Image.Dispose();
     box_photo.Image      = global::CATALOGUE_ARTICLE.Properties.Resources.ajouter;
     box_photo.Tag        = false;
     lk_box_photo.Visible = false;
 }
예제 #5
0
        public static Users saveUsers(Users f)
        {
            NpgsqlConnection con = Connexion.Connection();

            try
            {
                string path = "";
                if (!(f.Photo == null || f.Photo.Trim().Equals("")))
                {
                    path    = f.Photo;
                    f.Photo = Utils.milliseconds() + Path.GetExtension(path);
                }
                string insert = "insert into users (nom, prenom, identifiant, mot_passe, photo, actif, niveau) values " +
                                "('" + f.Nom + "','" + f.Prenom + "','" + f.Identifiant + "','" + f.Password + "','" + f.Photo + "','" + f.Actif + "'," + f.Niveau.Id + ")";
                NpgsqlCommand cmd = new NpgsqlCommand(insert, con);
                cmd.ExecuteNonQuery();
                f.Id = currentUsers(f);

                if (!(path == null || path.Trim().Equals("")))
                {
                    string chemin = Chemins.getCheminUsers(f.Id.ToString()) + f.Photo;
                    System.IO.File.Copy(path, chemin, true);
                }

                return(f);
            }
            catch (NpgsqlException e)
            {
                Messages.Exception(e);
                return(null);
            }
            finally
            {
                Connexion.Deconnection(con);
            }
        }