Esempio n. 1
0
        // POST: api/Devis
        public HttpResponseMessage Post(object genObjec_d) // DEVRA CREER UN DEVIS
        {                                                  // recup informations envoyer PUIIIS fabrique WORD et met son emplacement dans la bd
          //try
          //{
            //JObject job = JObject.Parse(genObjec_d);

            var           escouilles   = genObjec_d.ToString();
            GeneralObject newGenObject = JsonConvert.DeserializeObject <GeneralObject>(escouilles);

            foreach (Projet p in newGenObject.projets)
            {
                p.découpageStories.Add("B", new List <MasterStories>());
                p.découpageStories.Add("PR", new List <MasterStories>());
                p.découpageStories.Add("PNR", new List <MasterStories>());
                foreach (MasterStories s in p.Stories)
                {
                    if ((bool)s.Bonus)
                    {
                        p.découpageStories["B"].Add(s);
                    }
                    else if (s.nonEffetue)
                    {
                        p.découpageStories["PNR"].Add(s);
                    }
                    else
                    {
                        p.découpageStories["PR"].Add(s);
                    }
                }
            }
            //GeneralObject genTest = CreateATestingContext();
            Calculator devisCalculator          = new Calculator(newGenObject);
            SumManager resultFromcallCalculator = devisCalculator.CalculateFactu();
            Devis      devis  = new Devis();
            FileFiller filler = new FileFiller(devis, false, resultFromcallCalculator, newGenObject);

            newGenObject.SaveToDb(false, devis);
            return(new HttpResponseMessage(HttpStatusCode.Accepted));
            //}
            //catch (Exception e)
            //{
            //    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)); //lance exception si y'a eu un problème
            //}
        }
Esempio n. 2
0
        // POST: api/Facturation
        public void Post(object genObjec_f)
        {
            var           stringed     = genObjec_f.ToString();
            GeneralObject newGenObject = JsonConvert.DeserializeObject <GeneralObject>(stringed);

            foreach (Projet p in newGenObject.projets)
            {
                p.découpageStories.Add("B", new List <MasterStories>());
                p.découpageStories.Add("PR", new List <MasterStories>());
                p.découpageStories.Add("PNR", new List <MasterStories>());
                foreach (MasterStories s in p.Stories)
                {
                    if ((bool)s.Bonus)
                    {
                        p.découpageStories["B"].Add(s);
                    }
                    else if (s.nonEffetue)
                    {
                        p.découpageStories["PNR"].Add(s);
                    }
                    else
                    {
                        p.découpageStories["PR"].Add(s);
                    }
                }
            }
            Calculator devisCalculator = new Calculator(newGenObject);
            //DevisCalculator devisCalculator = new DevisCalculator(genObjec_d);
            SumManager  resultFromcallCalculator = devisCalculator.CalculateFactu();
            Facturation facturation = new Facturation();
            FileFiller  filler      = new FileFiller(facturation, true, resultFromcallCalculator, newGenObject);

            //StreamWriter logFile = new StreamWriter(System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\test.txt");
            //logFile.WriteLine("je suis juste un petit fichier de test qui va me permettre de savoir si j'arriva a renvoyer des fichiers au clients");
            //logFile.Close();
            //  DateTime longDate = DateTime.Now;
            //var path = System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\" + "Etat_des_lieux_VS_Devis_initial_All_NS_Reneco_" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + ".docx";
            //HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
            //var stream = new FileStream(path, FileMode.Open);
            //result.Content = new StreamContent(stream);
            //result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
            //result.Content.Headers.ContentDisposition.FileName = Path.GetFileName(path);
            //result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
            //result.Content.Headers.ContentLength = stream.Length;

            // string strdocPath;
            //strdocPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\Calcul" + ".txt";
            // strdocPath = System.AppDomain.CurrentDomain.BaseDirectory + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\" + "Etat_des_lieux_VS_Devis_initial_All_NS_Reneco_" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + ".docx";

            //FileStream objfilestream = new FileStream(strdocPath, FileMode.Open, FileAccess.Read);
            //int len = (int)objfilestream.Length;
            // Byte[] documentcontents = File.ReadAllBytes(strdocPath);
            // objfilestream.Read(documentcontents, 0, len);
            // objfilestream.Close();

            //string stringFile = Convert.ToBase64String(documentcontents);

            //HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, "value");
            //response.Content = new StringContent(stringFile, Encoding.UTF8);
            //response.Content = new StringContent(stringFile);
            //response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.openxmlformats-officedocument.wordprocessingml.document");

            //return response;
            newGenObject.SaveToDb(true, facturation);
            //return new HttpResponseMessage(HttpStatusCode.Accepted);
            //}
            //catch (Exception e)
            //{
            //    throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, e.Message)); //lance exception si un attribut dans l'objet est nulle
            //}
        }
Esempio n. 3
0
        //public WordFileGenerator(FactuConstante obj, bool isFactu = false)
        //{
        //    DateTime longDate = DateTime.Now;
        //    this.isFactu = isFactu;
        //    this.basePath = System.AppDomain.CurrentDomain.BaseDirectory;
        //    this.tableSubTotal = 0;
        //    this.tableSubTotalBonus = 0;
        //    if (isFactu)
        //    {
        //        this.fileName = "Etat_des_lieux_VS_Devis_initial_All_NS_Reneco_" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + ".docx";
        //    }
        //    else
        //    {

        //        this.fileName = "Devis_All_NS_Reneco_" + longDate.Year.ToString() + "_" + longDate.AddMonths(1).Month + ".docx";
        //    }
        //    obj.chefProjet.updateValue();
        //    obj.directeur.updateValue();
        //    this.final = loadTemplate();
        //    setValue("dateCreation", longDate.ToShortDateString());
        //    //     manageDevisTable(obj.projet);
        //    insertElementsInFiles(obj.chefProjet.sum, obj.directeur.sum);
        //    //Save template to a new name same location
        //    //TODO : convenir d'une convention de nommage
        //    this.final.SaveAs(this.basePath + @"\Content\" + this.fileName);
        //    this.encoded = File.ReadAllBytes(this.basePath + @"\Content\" + this.fileName);
        //}

        public WordFileGenerator(GeneralObject obj, SumManager sumManager, dynamic fichier, bool isFactu = false)
        {
            DevisFacturationEntities db = new DevisFacturationEntities();
            DateTime longDate           = DateTime.Now;

            this.isFactu            = isFactu;
            this.basePath           = System.AppDomain.CurrentDomain.BaseDirectory;
            this.tableSubTotal      = 0;
            this.tableSubTotalBonus = 0;
            if (isFactu)
            {
                List <Facturation> lesFactures = db.Facturation.Where(devisVerif => devisVerif.Commande.Trim().ToLower() == obj.epic.Trim().ToLower()).ToList();
                if (lesFactures.Count() > 0)
                {
                    fichier          = (Facturation)lesFactures[0];
                    fichier.Commande = obj.epic;
                    fichier.Mois     = DateTime.Now.ToString("MMMM");
                    this.isAnUpdate  = true;
                }
                else
                {
                    fichier          = (Facturation)fichier;
                    fichier.Commande = obj.epic;
                    fichier.Mois     = DateTime.Now.ToString("MMMM");
                    Devis devisSameCommande = db.Devis.Where(dev => dev.Commande.Trim().ToLower() == obj.epic.Trim().ToLower()).FirstOrDefault();
                    fichier.FK_Devis = devisSameCommande.ID;
                    this.isAnUpdate  = false;
                }
                this.fileName = "Etat_des_lieux_VS_Devis_initial_All_NS_Reneco_" + obj.epic.Trim() + ".docx";
            }
            else
            {
                List <Devis> lesDevis = db.Devis.Where(devisVerif => devisVerif.Commande.Trim().ToLower() == obj.epic.Trim().ToLower()).ToList();
                if (lesDevis.Count() > 0)
                {
                    fichier          = (Devis)lesDevis[0];
                    fichier.Commande = obj.epic;
                    fichier.Mois     = DateTime.Now.ToString("MMMM");
                    this.isAnUpdate  = true;
                }
                else
                {
                    fichier          = (Devis)fichier;
                    fichier.Commande = obj.epic;
                    fichier.Mois     = DateTime.Now.ToString("MMMM");
                    this.isAnUpdate  = false;
                }

                this.fileName = "Devis_All_NS_Reneco_" + obj.epic.Trim() + ".docx";
            }
            this.final = loadTemplate();
            setValue("dateCreation", longDate.ToShortDateString());
            manageDevisTable(obj, sumManager);
            if (isFactu)
            {
                insertElementsInFiles(fichier, obj.getJourCdp(), obj.getJourDT());
            }
            else
            {
                insertElementsInFiles(fichier);
            }
            this.final.SaveAs(this.basePath + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\" + this.fileName);
            this.encoded     = File.ReadAllBytes(this.basePath + @"\Content\Devis" + longDate.Year.ToString() + "_" + longDate.AddMonths(-1).Month + @"\" + this.fileName);
            fichier.Filename = this.fileName;
            fichier.Date     = DateTime.Now;
            //fichier.
            if (this.isFactu)
            {
                if (this.isAnUpdate)
                {
                    db.Facturation.Attach(fichier);
                    db.SaveChanges();
                }
                else
                {
                    db.Facturation.Add(fichier);
                    db.SaveChanges();
                }
            }
            else
            {
                if (this.isAnUpdate)
                {
                    db.Devis.Attach(fichier);
                    db.SaveChanges();
                }
                else
                {
                    db.Devis.Add(fichier);
                    db.SaveChanges();
                }
            }
        }
Esempio n. 4
0
        private void manageDevisTable(GeneralObject obj, SumManager sumManager)
        {
            Table tab = this.final.Tables[2];

            Row templateToCopy = tab.Rows[1];

            foreach (Projet projet in obj.projets)
            {
                if (projet.Stories != null && projet.Stories.Count > 0 && projet.découpageStories["PR"].Count > 0)
                {
                    Row toAdd = tab.InsertRow(tab.RowCount - 2);
                    //project
                    toAdd.Cells[0].InsertParagraph(projet.Nom);
                    List bulletedList = null;
                    //stories
                    if (projet.découpageStories.Count > 0)
                    {
                        foreach (MasterStories story in projet.découpageStories["PR"])
                        {
                            if (bulletedList == null)
                            {
                                bulletedList = this.final.AddList(story.Description, 0, ListItemType.Bulleted, 1);
                            }
                            else
                            {
                                this.final.AddListItem(bulletedList, story.Description);
                            }
                        }
                        if (bulletedList != null)
                        {
                            toAdd.Cells[1].InsertList(bulletedList);
                            //Cout
                            FactuStoriesTabs total = (FactuStoriesTabs)sumManager.getProjectCost(projet.Nom, true);
                            toAdd.Cells[2].InsertParagraph(total.getPR().ToString("G29") + "€");
                        }
                    }
                }
                FactuStoriesTabs totalCost    = (FactuStoriesTabs)sumManager.getProjectCost(projet.Nom, true);
                string           totalCostStr = totalCost.getPR().ToString("G29");
                this.tableSubTotal += decimal.Parse(totalCostStr);
            }
            tab.Rows[tab.RowCount - 1].Cells[1].ReplaceText("[totalTable]", this.tableSubTotal.ToString());

            if (this.isFactu)
            {
                Table tabBonus      = this.final.Tables[3];
                Table tabUnfinished = this.final.Tables[4];
                Row   ToCopy        = tab.Rows[1];
                foreach (Projet insert in obj.projets)
                {
                    if (insert.découpageStories["B"] != null && insert.découpageStories["B"].Count > 0)
                    {
                        Row toAdd = tabBonus.InsertRow(tabBonus.RowCount - 2);
                        //project
                        toAdd.Cells[0].InsertParagraph(insert.Nom);
                        List bulletedList = null;
                        //stories
                        foreach (MasterStories story in insert.découpageStories["B"])
                        {
                            if (bulletedList == null)
                            {
                                bulletedList = this.final.AddList(story.Description, 0, ListItemType.Bulleted, 1);
                            }
                            else
                            {
                                this.final.AddListItem(bulletedList, story.Description);
                            }
                        }
                        toAdd.Cells[1].InsertList(bulletedList);
                        //Cout
                        FactuStoriesTabs total = (FactuStoriesTabs)sumManager.getProjectCost(insert.Nom, true);
                        toAdd.Cells[2].InsertParagraph(total.getB().ToString("G29") + "€");
                        string totalBstr = total.getB().ToString("G29");
                        this.tableSubTotalBonus += decimal.Parse(totalBstr);
                    }

                    if (insert.découpageStories["PNR"] != null && insert.découpageStories["PNR"].Count > 0)
                    {
                        Row toAdd = tabUnfinished.InsertRow(tabUnfinished.RowCount - 1);
                        //project
                        toAdd.Cells[0].InsertParagraph(insert.Nom);
                        List bulletedList = null;
                        //stories
                        foreach (MasterStories story in insert.découpageStories["PNR"])
                        {
                            if (bulletedList == null)
                            {
                                bulletedList = this.final.AddList(story.Description, 0, ListItemType.Bulleted, 1);
                            }
                            else
                            {
                                this.final.AddListItem(bulletedList, story.Description);
                            }
                        }
                        toAdd.Cells[1].InsertList(bulletedList);
                    }
                }
                tabBonus.Rows[tabBonus.RowCount - 1].Cells[1].ReplaceText("[totalTableBonus]", this.tableSubTotalBonus.ToString());
            }
        }
 private void Awake()
 {
     ins = this;
 }