Пример #1
0
        /// Fonction pour effectué la copie des fichiers et inscrire la note dans les document Autofab
        private void transfertImages_Click(object sender, RoutedEventArgs e) 
        {
            string noProdval = "CO-" + noProd.Text;

            try
            {
                var ordredocument = (from d in db.DOCUMENTs
                                     where d.DOSEQ_REFERENCE == sequenceCommande && d.DONOM_TABLE == "COMMANDE"
                                     orderby d.DOORDRE descending
                                     select new { d.DOORDRE }).FirstOrDefault();

                newOrdreDocNo = ordredocument.DOORDRE + 1;
            }
            catch (Exception)
            {
                newOrdreDocNo = 1; // aucun document dans commande Ordre = 1
            }

            if (cPhoto.Count > 0 && sequenceCommande != 0)
            {
                bool copyValid = false;

                foreach (var item in cPhoto)
                {
                    
                    string subPath = @"\\cabanons00013\documentsautofab6\documents\COMMANDE\" + year + @"\" + noProdval + @"\"; // \\cabanons00013\documentsautofab6\documents\COMMANDE\2015\CO-000024
                    Directory.CreateDirectory(subPath);

                    try
                    {
                        File.Copy(item.Photo, subPath + System.IO.Path.GetFileName(item.Name));

                        DOCUMENT docNew = new DOCUMENT();

                        docNew.DONOM_TABLE = "COMMANDE";
                        docNew.DOSEQ_REFERENCE = sequenceCommande;
                        docNew.DOFICHIER = subPath + System.IO.Path.GetFileName(item.Name);
                        docNew.DOORDRE = newOrdreDocNo;
                        docNew.DODESC_P = "PHOTO INSTALLATION";
                        docNew.DODESC_S = "PHOTO INSTALLATION";
                        docNew.DONOTE = "";
                        docNew.DODATE = DateTime.Now;
                        docNew.DOUSAGER = "PHOTO IMPORTER";

                        db.DOCUMENTs.InsertOnSubmit(docNew);
                        db.SubmitChanges();

                        newOrdreDocNo += 1; //Incrémente le compteur
                        copyValid = true;
                    }
                    catch (Exception)
                    {
                        MessageBox.Show(System.IO.Path.GetFileName(item.Name) + " Fichier déja existant dans le repertoire AutoFAB Image non transféré");
                        copyValid = false;
                    }
                }

                if (copyValid)
                {
                    MessageBox.Show("Image Transféré a AutoFAB6");
                    // Vide la selection apres le transfert
                    cPhoto.Clear();
                    noProd.Text = "";
                    labelNomClient.Content = null;
                    addl1.Content = null;
                    addl2.Content = null;
                    addl3.Content = null;
                    installateur.Items.Clear();
                    updateEcran();
                }
            }
            else 
            {
                MessageBox.Show("Aucune image transféré");
            }
        }
 partial void UpdateDOCUMENT(DOCUMENT instance);
 partial void DeleteDOCUMENT(DOCUMENT instance);
 partial void InsertDOCUMENT(DOCUMENT instance);