Пример #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.");
            }
        }
Пример #2
0
        public Dictionary<string, int> getTotalProduct(NodeUser user, NodePrice price)
        {
            Dictionary<string, int> result = new Dictionary<string, int>();

            for (int n = 0; n < price.NbProduct(); n++)
            {
                // XmlNode
                //nodePrice.getProduct(n)
            }
            return result;
        }
Пример #3
0
 private void FillGuiPrice(NodePrice n)
 {
 }
Пример #4
0
        private void fillTree()
        {
            try
            {
                nodeCategory = new NodesCategory();
            }
            catch (Exception e) { MessageBox.Show("Error Category " + e.Message); }

            try {
            nodeCustomer = new NodesUser();
            } catch(Exception e1) { MessageBox.Show("Error User " + e1.Message); }
                try
                {
            nodephotographer = new NodesPhotographer();
                }catch(Exception e2) { MessageBox.Show("Error PhotoGrapher " + e2.Message); }
                try
                {
            nodeInfo = new NodesInfo();
                }catch(Exception e3) { MessageBox.Show("Error Info " + e3.Message); }
                try
                {
            nodeConfig = new NodeConfig();
                }
                    catch(Exception e4) { MessageBox.Show("Error Config " + e4.Message); }
                try
                {
            nodePrice = new NodePrice();
                }
                        catch(Exception e5) { MessageBox.Show("Error Config " + e5.Message); }

            treeView1.Nodes.Add(nodeConfig);
            treeView1.Nodes.Add(nodeCategory);
            treeView1.Nodes.Add(nodeCustomer);
            treeView1.Nodes.Add(nodephotographer);
            treeView1.Nodes.Add(nodeInfo);
            treeView1.Nodes.Add(nodePrice);

            for (int n = 0; n < nodePrice.NbProduct(); n++)
            {
                flowLayoutPanelProduct.Controls.Add((Control)new ProductControl(nodePrice.getProduct(n)));
            }
            photoPromotionEntry1.setXmlNode(nodePrice.getPromotion(0));
            photoPromotionEntry2.setXmlNode(nodePrice.getPromotion(1));
            photoPromotionEntry3.setXmlNode(nodePrice.getPromotion(2));
            photoPromotionEntry4.setXmlNode(nodePrice.getPromotion(3));
            photoPromotionEntry5.setXmlNode(nodePrice.getPromotion(4));
            photoPromotionEntry6.setXmlNode(nodePrice.getPromotion(5));
        }
        public static void CommandLogger(NodeUser user,NodePrice price)
        {
            if (Directory.Exists("COMMAND") == false)
            {
                Directory.CreateDirectory("COMMAND");
            }

            string filename = "COMMAND\\command_"+DateTime.Now.Month.ToString()+ "_"+ DateTime.Now.Year.ToString()+".log";
            StreamWriter sw = new StreamWriter(filename,true);

            int nbphoto = user.NbPhoto();

            for (int n = 0; n < nbphoto; n++)
            {
                string photographe = getPhotographe(user.FilenamePhoto(n));

                XmlNode img = user.GetPhoto(n);

                string strOuput = DateTime.Now.ToShortDateString() + ";" + user.chamberNumber + ";" + user.FilenamePhoto(n) + ";" + photographe + ";" + user.FormatPhoto(n) + ";";
                for (int i = 0; i < price.NbProduct(); i++)
                {
                    XmlNode nPrice = price.getProduct(i);
                    // parcourir la commande utilisateur pour déterminer les quantités !!
                    // pour chaque photo commandée par l'utilisateur
                    String currentFormatName = XMLTools.GetAttributeStringValue(nPrice, "name");
                    String strOrderedQuantity = XMLTools.GetAttributeIntValue(img, currentFormatName).ToString();
                    strOuput += currentFormatName + ";" + strOrderedQuantity + ";";
                }

                String strImageOnCD = XMLTools.GetAttributeStringValue(img, "imageoncd");

                if (strImageOnCD.ToLower() == "true")
                {
                    strOuput += "imageoncd;true;";
                }
                else
                {
                    strOuput += "imageoncd;false;";
                }
                String strImageOnBook = XMLTools.GetAttributeStringValue(img, "imageonbook");

                if (strImageOnBook.ToLower() == "true")
                {
                    strOuput += "imageonbook;true;";
                }
                else
                {
                    strOuput += "imageonbook;false;";
                }

                sw.WriteLine(strOuput);

                LogOnNet("log.php",strOuput);
            }
            sw.Close();

            try
            {
                for (int n = 0; n < nbphoto; n++)
                {
                    List<String> data = new List<string>();
                    string photographe = getPhotographe(user.FilenamePhoto(n));
                    data.Add(DateTime.Now.ToShortDateString());
                    data.Add(user.FilenamePhoto(n));
                    data.Add(photographe);
                    data.Add(user.FormatPhoto(n));
                 //   data.Add(user.orderCD.ToString());
                 //   data.Add(user.chamberNumber);
                 //   Insert(1, data);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show("Error " + e.Message);
            }
        }