Esempio n. 1
0
        public void ExcelCustomer(NodeUser user, NodePrice price)
        {
            // On va générer une facture excel à partir des données de l'utilisateur (sa commande)
            // et des données référence des prix (NodePrice)

            ConfigManager cm = ConfigManager.getSingleton();

            if (File.Exists(cm.getExcelTemplateFile()))
            {
                using (ExcelPackage p = new ExcelPackage(new FileInfo(cm.getExcelTemplateFile()), true))
                {
                    //Set up the headers
                    ExcelWorksheet ws = p.Workbook.Worksheets[1];

                    int nbphoto = user.NbPhoto();
                    idFacture = nbIDFacture();

                    // Identification de la facture
                    ws.Cells["B1"].Value = String.Format("FACTURE N° {0}", idFacture.ToString().PadLeft(6, '0'));
                    ws.Cells["B2"].Value = DateTime.Today.ToString("yyyy-MM-dd");

                    // Identification du client
                    ws.Cells["C6"].Value = user.chamberNumber.ToString();
                    ws.Cells["C4"].Value = user.name;
                    ws.Cells["C5"].Value = user.firstname;
                    ws.Cells["C7"].Value = user.LeavingDate;

                    #region Ici, on va générer tous les tableaux de données qui seront utilisés pour la suite de la construction du fichier excel

                    List<OrderedItem> listForfaitsDivers = new List<OrderedItem>();

                    for (int i = 0; i < price.NbForfaits(); i++)
                    {
                        XmlNode n = price.getForfait(i);

                        OrderedItem item = new OrderedItem();
                        item.Name = XMLTools.GetAttributeStringValue(n, "name");

                        listForfaitsDivers.Add(item);
                    }

                    Int32 TotalPhotoCD = 0;
                    Int32 TotalPhotoTirage = 0;

                    List<OrderedItem> listFormatPhotos = new List<OrderedItem>();
                    List<OrderedItem> listMerchandising = new List<OrderedItem>();
                    List<OrderedItem> listImageOnBook = new List<OrderedItem>();

                    for (int i = 0; i < price.NbProduct(); i++)
                    {
                        XmlNode n = price.getProduct(i);

                        String formatPhoto = XMLTools.GetAttributeStringValue(n, "formatphoto");

                        if (formatPhoto.ToLower() == "true")
                        {
                            OrderedItem item = new OrderedItem();
                            String currentFormatName = XMLTools.GetAttributeStringValue(n, "name");
                            item.Name = GetFormatDisplayName(currentFormatName);
                            item.UnitPrice = XMLTools.GetAttributePriceValue(n, "price");

                            // parcourir la commande utilisateur pour déterminer les quantités !!
                            // pour chaque photo commandée par l'utilisateur
                            for (int j = 0; j < user.NbPhoto(); j++)
                            {
                                XmlNode img = user.GetPhoto(j);

                                // on regarde si le format actuel a été commandé et si oui, en combien d'exemplaires
                                String strOrderedQuantity = XMLTools.GetAttributeStringValue(img, currentFormatName);

                                // Le format a été commandé, on va récupérer le chiffre et l'ajouter à la quantité de photos commandées
                                if (!String.IsNullOrEmpty(strOrderedQuantity))
                                {
                                    Int32 qty = 0;
                                    Int32.TryParse(strOrderedQuantity, out qty);

                                    item.Quantity += qty;
                                    TotalPhotoTirage += qty;
                                }
                            }

                            listFormatPhotos.Add(item);
                        }
                        else
                        {
                            OrderedItem item = new OrderedItem();

                            String currentFormatName = XMLTools.GetAttributeStringValue(n, "name");

                            item.Name = XMLTools.GetAttributeStringValue(n, "description");
                            if (item.Name == String.Empty)
                                item.Name = currentFormatName;
                            item.UnitPrice = XMLTools.GetAttributePriceValue(n, "price");

                            // parcourir la commande utilisateur pour déterminer les quantités !!
                            // pour chaque photo commandée par l'utilisateur
                            for (int j = 0; j < user.NbPhoto(); j++)
                            {
                                XmlNode img = user.GetPhoto(j);

                                // on regarde si le format actuel a été commandé et si oui, en combien d'exemplaires
                                String strOrderedQuantity = XMLTools.GetAttributeStringValue(img, currentFormatName);

                                // Le format a été commandé, on va récupérer le chiffre et l'ajouter à la quantité de photos commandées
                                if (!String.IsNullOrEmpty(strOrderedQuantity))
                                {
                                    Int32 qty = 0;
                                    Int32.TryParse(strOrderedQuantity, out qty);

                                    item.Quantity += qty;
                                }
                            }
                            listMerchandising.Add(item);
                        }
                    }

                    // avant de finir, on reparcours encore la commande utilisateur pour calculer le nombre d'images commandées sur CD (minimum 10 normalement, mais ça c'est censé etre checké en amont)
                    for (int j = 0; j < user.NbPhoto(); j++)
                    {
                        // On en profite également pour regarder si la photo a été commandée sur CD
                        // Dans ce cas, on incrément le compteur. cela nous permettra de calculer le prix de revient du CD
                        if (user.isPhotoOnCD(j))
                        {
                            TotalPhotoCD++;
                        }

                    }

                    // avant de finir, on reparcours encore la commande utilisateur pour calculer le nombre d'images commandées sur CD (minimum 10 normalement, mais ça c'est censé etre checké en amont)
                    for (int j = 0; j < user.NbPhoto(); j++)
                    {
                        XmlNode img = user.GetPhoto(j);
                        // On en profite également pour regarder si la photo a été commandée sur CD
                        // Dans ce cas, on incrément le compteur. cela nous permettra de calculer le prix de revient du CD

                    }

                    // Maintenant on détermine les remises auxquelles l'utilisateur a le droit
                    String strPromoList = String.Empty;
                    Int32 pourcentageRemise = 0;
                    for (int i = 0; i < price.NbPromotion(); i++)
                    {
                        XmlNode n = price.getPromotion(i);

                        if (!String.IsNullOrEmpty(strPromoList))
                            strPromoList += " / ";

                        Int32 nbPhotos = XMLTools.GetAttributeIntValue(n, "nbphoto");
                        Int32 montantReduction = XMLTools.GetAttributeIntValue(n, "promotion");

                        strPromoList += String.Format("{0} P={1}%", nbPhotos.ToString(), montantReduction.ToString());

                        if (TotalPhotoTirage >= nbPhotos && pourcentageRemise < montantReduction)
                        {
                            pourcentageRemise = montantReduction;
                        }
                    }

                    #endregion

                    // On va itérer sur chaque format de photo disponible
                    int row = STARTING_ROW;

                    createCategoryRows(ref ws, row, listFormatPhotos);
                    row += listFormatPhotos.Count - 1;

                    createSubTotalRow(ref ws, ++row);
                    createRemiseRow(ref ws, ++row, 0.0, pourcentageRemise); // remise à calculer
                    createTotalRow(ref ws, ++row);

                    //createPromotionListRow(ref ws, ++row, strPromoList);

                    // Formules photos
                    List<OrderedItem> listFormulesPhotos = new List<OrderedItem>();

                    if (user.withoutprinting )
                    {
                        if (user.NbPhoto() == 12)
                        {
                            listFormulesPhotos.Add(new OrderedItem() { Name = "Forfait 50 Images sur CD", Quantity = 1, UnitPrice = price.getforfait50CD() });
                        }
                        else
                        {
                            listFormulesPhotos.Add(new OrderedItem() { Name = "Forfait 100 Images sur CD", Quantity = 1, UnitPrice = price.getforfait100CD() });

                        }
                    }
                    else
                    {
                        listFormulesPhotos.Add(new OrderedItem() { Name = "Fichiers numériques sur CD", Quantity = TotalPhotoCD, UnitPrice = price.PrixFichierNumerique() });
                    }

                    createCategoryRows(ref ws, ++row, listFormulesPhotos);
                    row += listFormulesPhotos.Count - 1;
                    createInterCategoryRow(ref ws, ++row);

                    // merchandising
                    createCategoryRows(ref ws, ++row, listMerchandising);
                    row += listMerchandising.Count - 1;
                    createInterCategoryRow(ref ws, ++row);

                    // Nombre de page sur le livre.
                    // 20 pages a 300 euros soit 12000 Mur
                    // 500 mur la page supplémentaire , fonctionnant par 2 pages

                    if (user.orderBook == true)
                    {
                        int nbPageOnBook = user.getNbPageOnBook;
                        int nbPageSupplementaire = nbPageOnBook -20;
                        row += createPhotoOnBook(ref ws, ++row, nbPageSupplementaire, price.getPrixFortaitBookPrestige(), price.getprixPageBookMore());

                        createInterCategoryRow(ref ws, ++row);

                    }

                    // forfaits divers
                    createCategoryRows(ref ws, ++row, listForfaitsDivers, false);
                    row += listForfaitsDivers.Count - 1;

                    // FINALLY
                    // LE GRAND TOTAL
                    createMainTotalQuantiteRow(ref ws, ++row, listFormatPhotos);
                    createMainTotalTtcRow(ref ws, ++row, listFormatPhotos);
                    createMainTVARow(ref ws, ++row);

                    Byte[] bin = p.GetAsByteArray();

                    string file = String.Format("{0}\\{1}-{2}.{3}.{4}-{5}.xlsx", user.getDirectory(), idFacture.ToString().PadLeft(5, '0'), user.name, user.firstname, user.chamberNumber, DateTime.Now.ToString("yyyyMMdd"));
                    try
                    {
                        File.WriteAllBytes(file, bin);
                        ShellExecute se = new ShellExecute();
                        //se.Verb = ShellExecute.PrintFile;
                        se.Path = file;
                        se.Execute();
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Error Exporting Excel " + e.Message);
                    }
                }
            }
            else
            {
                MessageBox.Show("Unable to open template file located at : \"" + cm.getExcelTemplateFile() + "\". Please check the file and try again.");
            }
        }
Esempio n. 2
0
        private void pdfFileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            _pdfOfd.Filter = Resources.PdfFileFilter;
            _pdfOfd.FileName = Settings.Default.PdfPath;
            if (_pdfOfd.ShowDialog(this) == DialogResult.OK)
            {
                Settings.Default.PdfPath = _pdfOfd.FileName;
                Settings.Default.Save();

                var execute = new ShellExecute { Verb = ShellExecute.OpenFile, Path = _pdfOfd.FileName };
                execute.Execute();
            }
        }
Esempio n. 3
0
 private void buttonOpenDir_Click(object sender, EventArgs e)
 {
     if (treeView1.SelectedNode.GetType().Name == "NodeCategory")
     {
         NodeCategory nodeCat = (NodeCategory)treeView1.SelectedNode;
         ShellExecute se = new ShellExecute();
         se.Path = nodeCat.getDirectory();
         se.Execute();
     }
 }
Esempio n. 4
0
 private void openGoogleSearchToolStripMenuItem_Click(object sender, EventArgs e)
 {
     var execute = new ShellExecute { Path = "http://google.com/search?q=" + _currentWord, Verb = ShellExecute.OpenFile };
     execute.Execute();
 }
 public static void Open(string path)
 {
     var execute = new ShellExecute
     {
         Verb = ShellExecute.OpenFile,
         Path = path
     };
     execute.Execute();
 }