예제 #1
0
    public void Add(Commercial commercial)
    {
        COMMERCIAL entity = new COMMERCIAL();

        entity.PERSONNEL_ID     = commercial.Id;
        entity.PERSONNEL_NOM    = commercial.Nom;
        entity.PERSONNEL_PRENOM = commercial.Prenom;
        entity.SECTEUR          = commercial.Secteur;
        entity.NUMERO_MOBILE    = commercial.NumeroMobile;
        entity.PERSONNEL_LOGIN  = commercial.Login;
        entity.PERSONNEL_MDP    = commercial.Mdp;
        entity.PERSONNEL_TOKEN  = commercial.Token;

        using (var db = new maderaEntities())
        {
            db.COMMERCIAL.Add(entity);
            db.SaveChanges();
        }
    }
        public ActionResult Edit([Bind(Include = "ID,Lastname,Firstname,Mail,Password")] Commercial commercial)
        {
            ModelState.Remove("Mail");
            ModelState.Remove("Password");
            ModelState.Remove("ConfirmedPassword");
            var old = db.Commercials.Find(commercial.ID);

            commercial.Mail              = old.Mail;
            commercial.Password          = old.Password;
            commercial.ConfirmedPassword = old.Password.HashMD5();
            db.Entry(old).State          = EntityState.Detached;
            if (ModelState.IsValid)
            {
                db.Entry(commercial).State             = EntityState.Modified;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(commercial));
        }
예제 #3
0
        public ActionResult Create([Bind(Include = "Login,MotDePasse,MotDePasseVerification,Civilite,Nom,Prenom,Adresse,Telephone,DateNaissance")] Commercial commercial)
        {
            //commerciale.Login = commerciale.Nom.Substring(0, 2) + commerciale.Prenom.Substring(0, 2) + commerciale.ID.ToString();
            if (ModelState.IsValid)
            {
                commercial.MotDePasse             = commercial.MotDePasse.HashMD5();
                commercial.MotDePasseVerification = commercial.MotDePasseVerification.HashMD5();

                db.Configuration.ValidateOnSaveEnabled = false;
                db.Commercials.Add(commercial);
                db.SaveChanges();

                db.Configuration.ValidateOnSaveEnabled = true;
                Display("Commercial enregistré");

                return(RedirectToAction("index", "TableauDeBord"));
            }

            return(View(commercial));
        }
예제 #4
0
        // GET: Commercials/Create
        public async Task <IActionResult> Create(Guid productId, Guid clientId, Guid policyId)
        {
            Commercial commercial = new Commercial
            {
                StartDate = DateTime.Now,
                EndDate   = DateTime.Now
            };

            CommercialViewModel viewModel = new CommercialViewModel
            {
                ProductID     = productId,
                ClientID      = clientId,
                PolicyID      = policyId,
                Commercial    = commercial,
                ComponentList = new SelectList(await _context.Components.ToListAsync(),
                                               "ID", "Name", await _context.Components.FirstOrDefaultAsync())
            };

            return(View(viewModel));
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            //Residential Customer energy bill Calculation when residental customer radio button is selected
            if (rdResidential.Checked == true)
            {
                if (Validator.IsProvided(txtKwh, "Energy Usage") && Validator.IsNonNegativeInt(txtKwh, "Energy usage") && Validator.IsNonNegativeDbl(txtKwh, "usage"))
                {
                    Customer c            = new Residential(null, 0, '0'); //passing null and 0 in the constructors as  we don't want to save the object in the list yet
                    int      input        = Convert.ToInt32(txtKwh.Text);  //converting user input into integer
                    double   restotalBill = c.calculateBill(input);        //calling the function which calculates residential bill
                    txtChargeAmt.Text = restotalBill.ToString("c");        //displaying result with $ currancy
                }
            }
            //Commercial customer energy bill calculation when commercial customer radio button is selected
            if (rdCommercial.Checked == true)
            {
                if (Validator.IsProvided(txtKwh, "Energy Usage") && Validator.IsNonNegativeInt(txtKwh, "Energy usage") && Validator.IsNonNegativeDbl(txtKwh, "usage"))
                {
                    Customer c            = new Commercial(null, 0, '0'); //passing null and 0 in the constructors as  we don't want to save the object in the list yet
                    int      input        = Convert.ToInt32(txtKwh.Text); //converting user input into integer
                    double   comtotalBill = c.calculateBill(input);       //calling the function which calculates commercial bill
                    txtChargeAmt.Text = comtotalBill.ToString("c");       //displaying result with $ currancy
                }
            }


            //Industrial  customer energy bill calculation when indutrial customer radio button is selected
            if (rdIndustrial.Checked == true)
            {
                if (Validator.IsProvided(txtOnPeak, "Energy Usage") && Validator.IsNonNegativeInt(txtOnPeak, "Energy usage") && Validator.IsNonNegativeDbl(txtOnPeak, "Energy usage") &&
                    Validator.IsProvided(txtOffPeak, "Energy Usage") && Validator.IsNonNegativeInt(txtOffPeak, "Energy usage") && Validator.IsNonNegativeDbl(txtOffPeak, "Energy usage"))

                {
                    Customer c            = new Industrial(null, 0, '0');     //passing null and 0 in the constructors as  we don't want to save the object in the list yet
                    int      onpeak       = Convert.ToInt32(txtOnPeak.Text);  //converting user input into integer
                    int      offpeak      = Convert.ToInt32(txtOffPeak.Text); //converting user input into integer
                    double   indTotalBill = c.calculateBill(onpeak, offpeak); //calling the function which calculates industrial bill
                    txtChargeAmt.Text = indTotalBill.ToString("c");           //displaying result with $ currancy
                }
            }
        }
        public async Task <ActionResult> EditCommercial(Commercial model)
        {
            if (ModelState.IsValid)
            {
                var Db   = new ApplicationDbContext();
                var user = Db.Users.First(u => u.Email == model.Email);
                // Update the user data:

                user.Nom             = model.Nom;
                user.Prenom          = model.Prenom;
                user.BirthDate       = model.BirthDate;
                user.TelPerso        = model.TelPerso;
                user.Adresse         = model.Adresse;
                Db.Entry(user).State = System.Data.Entity.EntityState.Modified;
                await Db.SaveChangesAsync();

                return(RedirectToAction("CommercialsList"));
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        /// <summary>
        /// For a specific commercial swap this method calculates what the affect on
        /// the total rating will be, so we can determine if it's better than other
        /// available swaps
        /// </summary>
        /// <param name="sourceBreakCommercials">Source break/commercials instance</param>
        /// <param name="sourceCommercial">Source commercial</param>
        /// <param name="targetBreakCommercials">Target break/commercials instance</param>
        /// <param name="targetCommercial">Target commercial</param>
        /// <returns>The rating change</returns>
        private int GetRatingChangeForSwap(
            BreakCommercials sourceBreakCommercials,
            Commercial sourceCommercial,
            BreakCommercials targetBreakCommercials,
            Commercial targetCommercial)
        {
            var ratingTotalAfterSwap = 0;

            if (sourceBreakCommercials != null)
            {
                ratingTotalAfterSwap += sourceBreakCommercials.Break.BreakDemographics
                                        .Where(value => value.Demographic.Id == targetCommercial.Demographic.Id)
                                        .Select(value => value.Rating).FirstOrDefault();
            }

            if (targetBreakCommercials != null)
            {
                ratingTotalAfterSwap += targetBreakCommercials.Break.BreakDemographics
                                        .Where(value => value.Demographic.Id == sourceCommercial.Demographic.Id)
                                        .Select(value => value.Rating).FirstOrDefault();
            }

            var ratingTotalBeforeSwap = 0;

            if (sourceBreakCommercials != null)
            {
                ratingTotalBeforeSwap += sourceBreakCommercials.Break.BreakDemographics
                                         .Where(value => value.Demographic.Id == sourceCommercial.Demographic.Id)
                                         .Select(value => value.Rating).FirstOrDefault();
            }

            if (targetBreakCommercials != null)
            {
                ratingTotalBeforeSwap += targetBreakCommercials.Break.BreakDemographics
                                         .Where(value => value.Demographic.Id == targetCommercial.Demographic.Id)
                                         .Select(value => value.Rating).FirstOrDefault();
            }

            return(ratingTotalAfterSwap - ratingTotalBeforeSwap);
        }
예제 #8
0
        public void Setup()
        {
            l = new Location();
            //System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Civic).TypeHandle);
            //System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Residential).TypeHandle);
            //System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(typeof(Commercial).TypeHandle);
            validDummy.Add(new Tuple <String, String>("Type:DummyLocation,ID:1", "Standard dummy location is valid"));
            invalidDummy.Add(new Tuple <String, String>("Type:DummyLocation", "Should be at least 2 components"));
            invalidDummy.Add(new Tuple <String, String>("Type:DummyLocation,ID:1,Connections", "At most 2 components"));
            invalidDummy.Add(new Tuple <String, String>("Type:DummyLocation,blah:1", "Components should be valid"));
            invalidDummy.Add(new Tuple <String, String>("Type:sadas,ID:", "Type should be DummyLocaiton"));
            invalidDummy.Add(new Tuple <String, String>("Type:DummyLocation,ID:sadass", "ID should be an int"));
            invalidDummy.Add(new Tuple <String, String>("Type:DummyLocation,ID:-1", "ID should be positive"));

            Residential res = new Residential(1, 3, 5);
            Commercial  com = new Commercial(2, 4, 7);
            Civic       civ = new Civic(3, 6, 3);

            validLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations,CurrentSublocation", "Standard location is valid"));
            validLoc.Add(new Tuple <String, String>("Type:Location,ID:2,Visited:True,Sublocations:" + res.ParseToString() + ":" + com.ParseToString() + ",CurrentSublocation:1", "Standard location is valid"));
            //invalidLoc.Add(new Tuple<String, String>("Type:Location,ID:1,Connections:2:3,Visited:False,Sublocations,CurrentSublocation", "Standard location is valid"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations", "Should be at least 6 components"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations,CurrentSublocation,CurrentSublocation", "Should be at most 6 components"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Invalid,CurrentSublocation", "Components should be valid"));
            invalidLoc.Add(new Tuple <String, String>("Type:BlaLocation,ID:1,Visited:False,Sublocations,CurrentSublocation", "Type should be Location"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:megh,Visited:False,Sublocations,CurrentSublocation", "ID should be an int"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:-1,Visited:False,Sublocations,CurrentSublocation", "ID should be positive"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited,Sublocations,CurrentSublocation", "Visited should have a value"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:True:False,Sublocations,CurrentSublocation", "Visited should a single value"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:4,Sublocations,CurrentSublocation", "Visited should be a bool"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:blah,Sublocations,CurrentSublocation", "Visited should be a bool"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations:,CurrentSublocation", "If there are sublocations there should be at least one"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations:Residential:1:False:2:blah:temp,CurrentSublocation", "Sublocation should be valid"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations:Residential:1:False,CurrentSublocation", "Sublocation should be complete"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations:Residential:1:False:2:3:temp:Civic:1:False:2:3:temp,CurrentSublocation", "Sublocations can not share IDs"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations,CurrentSublocation:", "if there is a Current Sublocation it should have a value"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations:Residential:1:False:2:3:temp,CurrentSublocation:one", "Current Sublocation should be an int"));
            invalidLoc.Add(new Tuple <String, String>("Type:Location,ID:1,Visited:False,Sublocations:Residential:1:False:2:3:temp,CurrentSublocation:2", "Current Sublocation should be defined in sublocations"));
        }
예제 #9
0
 public void Setup()
 {
     stdSubLoc = ":1:False:2:3:temp";
     invalid.Add(new Tuple <String, String>(":1:False:2:3", "String should have exactly 6 items"));
     invalid.Add(new Tuple <String, String>(":1:False:2:3:temp:7", "String should have exactly 6 items"));
     invalid.Add(new Tuple <String, String>(":dasdas:False:2:3", "ID should be an int"));
     invalid.Add(new Tuple <String, String>(":1:blah:2:3:temp", "Scavenged should be a bool"));
     invalid.Add(new Tuple <String, String>(":1:False:sada:3:temp", "Max Items should be an int"));
     invalid.Add(new Tuple <String, String>(":1:False:2:blah:temp", "Max Amount should be an int"));
     invalid.Add(new Tuple <String, String>("::False:2:3:temp", "ID should have a value"));
     invalid.Add(new Tuple <String, String>(":1::2:3:temp", "Scav should have a value"));
     invalid.Add(new Tuple <String, String>(":1:False::3:temp", "Max Items should have a value"));
     invalid.Add(new Tuple <String, String>(":1:False:2::temp", "Max Amount should have a value"));
     res = new Residential(1, 3, 5);
     com = new Commercial(2, 4, 7);
     civ = new Civic(3, 6, 3);
     for (int i = 1; i < 21; i++)
     {
         Item tmp = new Item(StringMaker.makeItemStr(i));
         items.Add(tmp);
     }
 }
예제 #10
0
        /// <summary>
        /// Méthode pour sélectionner la liste de tous les commerciaux existants
        /// </summary>
        public void listAllCommerciaux()
        {
            // Nom du/des champs mis directement dans la requête pour éviter d'avoir à passer par QSqlRecord
            SQLQuery = "SELECT refCommercial, nom, prenom, email, motDePasse FROM commercial";
            //SQLQuery = "SELECT * FROM commercial;

            // Ouverture de la connexion
            conn.LiteCo.Open();
            using (SQLiteCommand command = new SQLiteCommand(SQLQuery, conn.LiteCo))
            {
                Trace.WriteLine(SQLQuery);
                try
                {
                    // Execute le lecteur de donnée
                    using (SQLiteDataReader reader = command.ExecuteReader())
                    {
                        Trace.WriteLine("#### GET COMMERCIAUX DATA ####");
                        while (reader.Read())
                        {
                            Commercial com = new Commercial
                                             (
                                reader.GetString(0),
                                reader.GetString(1),
                                reader.GetString(2),
                                reader.GetString(3),
                                reader.GetString(4)
                                             );
                            commerciaux.Add(com);
                        }
                    }
                    Trace.WriteLine("#### GET COMMERCIAUX DATA SUCCESS ####");
                }
                catch (SQLiteException ex)
                {
                    Trace.WriteLine(" \n ################################################# ERREUR RECUPERATION COMMERCIAUX ################################################# \n" + ex.ToString() + "\n");
                }
            }
            conn.LiteCo.Close();
        }
예제 #11
0
        static void Login()
        {
            OutilsConsole.Visual("Normal");

            bool sortir = false;

            OutilsConsole.PrintMenu("BoVoyage", "Add");
            string LoginUser;
            string MotDePasseUser;

            GererFichier.RecupererFichier(commercial);
            while (!sortir)
            {
                LoginUser = OutilsConsole.SaisirChaineObligatoire("\nLogin(valeur - yann)", "Champs Obligatoire!");
                Console.WriteLine("\nMot de passe(valeur - abc)");
                MotDePasseUser = OutilsConsole.MaskPassword();
                foreach (Commercial c in commercial)
                {
                    if (c.Login == LoginUser && c.MotDePasse == MotDePasseUser)
                    {
                        CommercialUser = c;
                        OutilsConsole.Visual("Lister");
                        Console.WriteLine("\nLogin Validé!");
                        OutilsConsole.Visual("Normal");
                        Console.ReadKey();
                        sortir = true;
                    }
                }
                if (!sortir)
                {
                    OutilsConsole.Visual("Danger");
                    Console.WriteLine("\nLogin ou Mot de passe Invalide!");
                    OutilsConsole.Visual("Normal");
                    Console.ReadKey();
                    Console.Clear();
                    OutilsConsole.PrintMenu("BoVoyage", "Add");
                }
            }
        }
예제 #12
0
        private void AjouterSalarie()

        {
            salarie = new Salarie();

            salarie.Matricule     = textBoxMatricule.Text;
            salarie.Nom           = textBoxNom.Text;
            salarie.Prenom        = textBoxPrenom.Text;
            salarie.DateNaissance = DateTime.Parse(textBoxDatedeNaissance.Text);
            salarie.SalaireBrut   = decimal.Parse(textBoxSalaireBrut.Text);
            salarie.TauxCS        = decimal.Parse(textBoxTauxCS.Text.Replace(".", ","));

            Commercial commercial = salarie as Commercial;

            if (commercial != null)
            {
                commercial.ChiffreAffaire = Decimal.Parse(textBoxChiffreAffaire.Text);
                commercial.Commission     = Decimal.Parse(textBoxCommission.Text);
            }

            salaries.Add(salarie);
            salaries.Save(MonApplication.DispositifSauvegarde, Settings.Default.AppData);
        }
예제 #13
0
        private void ChargerValeursSalarie()
        {
            textBoxMatricule.Text       = salarie.Matricule;
            textBoxNom.Text             = salarie.Nom;
            textBoxPrenom.Text          = salarie.Prenom;
            textBoxSalaireBrut.Text     = salarie.SalaireBrut.ToString();
            textBoxDatedeNaissance.Text = salarie.DateNaissance.ToString();
            textBoxTauxCS.Text          = salarie.TauxCS.ToString();
            Commercial commercial = salarie as Commercial;

            if (commercial != null)
            {
                textBoxChiffreAffaire.Text    = commercial.ChiffreAffaire.ToString();
                textBoxCommission.Text        = commercial.Commission.ToString();
                textBoxChiffreAffaire.Visible = true;
                textBoxCommission.Visible     = true;
            }
            else
            {
                textBoxChiffreAffaire.Visible = false;
                textBoxCommission.Visible     = false;
            }
        }
예제 #14
0
        public static ArrayList CreerListeHeteroclite()
        {
            ArrayList bjets = new ArrayList();

            bjets.Add(1.3m);
            bjets.Add("chou");
            bjets.Add(9);
            Salarie salarie = new Salarie();

            salarie.Nom = "Jaques";
            bjets.Add(salarie);
            Salarie salarie2 = new Salarie();

            salarie2.Nom = "Henri";
            bjets.Add(salarie2);
            Commercial com1 = (new Commercial());

            com1.Nom = "tata yoyo";
            bjets.Add(com1);


            return(bjets);
        }
예제 #15
0
 //set data to an object base on classification
 private Classification SetClass(string classStr)
 {
     if (classStr == "residential")
     {
         Residential res = new Residential();
         res.prev       = Double.Parse(tbPrev.Text);
         res.pres       = Double.Parse(tbPres.Text);
         res.days       = Int32.Parse(tbRdays.Text);
         res.addedPrice = Int32.Parse(tbRadded.Text);
         res.price      = Int32.Parse(tbRprice.Text);
         return(res);
     }
     else
     {
         Commercial com = new Commercial();
         com.prev       = Double.Parse(tbPrev.Text);
         com.pres       = Double.Parse(tbPres.Text);
         com.days       = Int32.Parse(tbCdays.Text);
         com.addedPrice = Int32.Parse(tbCadded.Text);
         com.price      = Int32.Parse(tbCprice.Text);
         return(com);
     }
 }
        public ActionResult Edit([Bind(Include = "ID,Email,CiviliteID,Nom,Prenom,Adresse,Telephone,DateNaissance")] Commercial commercial)
        {
            ModelState.Remove("Password");
            ModelState.Remove("PasswordConfirmation");
            ModelState.Remove("Email");
            var old = db.Commerciaux.SingleOrDefault(x => x.ID == commercial.ID);

            commercial.Password             = old.Password;
            commercial.PasswordConfirmation = old.Password;
            commercial.Email    = old.Email;
            db.Entry(old).State = EntityState.Detached;
            if (ModelState.IsValid)
            {
                db.Entry(commercial).State             = EntityState.Modified;
                db.Configuration.ValidateOnSaveEnabled = false;
                db.SaveChanges();
                DisplayMessage($"Les données du commercial {commercial.Nom} {commercial.Prenom} ont été modifiéés.", MessageType.SUCCESS);
                return(RedirectToAction("Index"));
            }
            ViewBag.Civilites = db.Civilites.ToList();
            DisplayMessage("Une erreur est apparue", MessageType.ERROR);
            return(View(commercial));
        }
        public void nbNotesFraisNonRembourseesTest()
        {
            Commercial        c, c1;
            ServiceCommercial sc;

            sc = new ServiceCommercial();
            c  = new Commercial("Jean", "Dupond", 25, 'A');
            c1 = new Commercial("Paul", "Duval", 10, 'B');
            sc.ajouterCommercial(c);
            sc.ajouterCommercial(c1);

            NoteFrais f, f1, f2, f3, f4;

            f  = new NoteFrais(new DateTime(2013, 11, 12), c);
            f1 = new NoteFrais(new DateTime(2013, 11, 15), c);
            f1.setFraisRembourser();
            f2 = new NoteFrais(new DateTime(2013, 11, 18), c1);
            f3 = new NoteFrais(new DateTime(2013, 11, 22), c1);
            f3.setFraisRembourser();
            f4 = new NoteFrais(new DateTime(2013, 11, 25), c1);
            f4.setFraisRembourser();
            Assert.AreEqual(2, sc.nbFraisNonRembourses());
        }
예제 #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="breakIntern"></param>
        /// <param name="currComm"></param>
        /// <returns></returns>
        public Break GetBestBreak(List <Break> breakIntern, Commercial currComm)
        {
            Break bestBr = null;

            foreach (var br in breakIntern)
            {
                if (!IsTypeAllowedInBrake(br, currComm))
                {
                    continue;
                }
                if (bestBr == null)
                {
                    bestBr = br; continue;
                }
                var newScore     = br.Ratings?.FirstOrDefault(p => p.DemoType == currComm.TargetDemo)?.Score;
                var currentScore = bestBr.Ratings?.FirstOrDefault(p => p.DemoType == currComm.TargetDemo)?.Score;
                if (newScore > currentScore)
                {
                    bestBr = br;
                }
            }
            return(bestBr);
        }
예제 #19
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            bool isRowSelected = this.gvCommercials.SelectedRows.Count > 0;

            if (isRowSelected)
            {
                Commercial com = this.gvCommercials.SelectedRows[0].Cells[CLMNAME_COMMERCIAL_OBJ].Value as Commercial;
                if (this._prodcut.Commercials.Contains(com))
                {
                    this._prodcut.Commercials.Remove(com);
                    this.BindGridView();
                    MessageBox.Show("הפרסומת הוסרה");
                }
                else
                {
                    MessageBox.Show("הפרסומת אינה משויכת למוצר");
                }
            }
            else
            {
                MessageBox.Show("Please select a row for seleting");
            }
        }
예제 #20
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Multiselect = true;

            if (ofd.ShowDialog(this) == DialogResult.OK)
            {
                List <Image> images      = new List <Image>();
                int          countFailed = 0;
                foreach (string fileName in ofd.FileNames)
                {
                    try
                    {
                        Image img = Image.FromFile(fileName);
                        images.Add(img);
                    }
                    catch (Exception)
                    {
                        countFailed++;
                    }
                }
                if (countFailed > 0)
                {
                    MessageBox.Show(String.Format("Failed to add {0} files", countFailed));
                }

                foreach (Image img in images)
                {
                    Commercial commercial = new Commercial();
                    commercial.SetImage(img);
                    this._prodcut.Commercials.Add(commercial);
                }

                this.BindGridView();
            }
        }
예제 #21
0
        public void calculCommissionTest()
        {
            Commercial[] jeuxDEssai    = TableauCommerciaux();
            Commercial   unCommercial1 = jeuxDEssai[2];
            Commercial   unCommercial2 = jeuxDEssai[3];
            Commercial   unCommercial3 = jeuxDEssai[4];
            Commercial   unCommercial4 = jeuxDEssai[4];

            unCommercial1.setCA(2, 100000);
            unCommercial2.setCA(3, 300000);
            unCommercial3.setCA(4, 450000);
            unCommercial4.setCA(5, 1000000);

            double ca_du_mois_commercial1 = unCommercial1.donneCaMois(2);
            double ca_du_mois_commercial2 = unCommercial2.donneCaMois(3);
            double ca_du_mois_commercial3 = unCommercial3.donneCaMois(4);
            double ca_du_mois_commercial4 = unCommercial4.donneCaMois(5);


            double commission_Attendue_Commercial1 = 2000;
            double commission_commercial1          = Exercice4_Parametres_CalculRemu.Commercial.calculCommission(ref ca_du_mois_commercial1);

            double commission_Attendue_Commercial2 = 7000;
            double commission_commercial2          = Exercice4_Parametres_CalculRemu.Commercial.calculCommission(ref ca_du_mois_commercial2);

            double commission_Attendue_Commercial3 = 12000;
            double commission_commercial3          = Exercice4_Parametres_CalculRemu.Commercial.calculCommission(ref ca_du_mois_commercial3);

            double commission_Attendue_Commercial4 = 44000;
            double commission_commercial4          = Exercice4_Parametres_CalculRemu.Commercial.calculCommission(ref ca_du_mois_commercial4);

            Assert.AreEqual(commission_Attendue_Commercial1, commission_commercial1);
            Assert.AreEqual(commission_Attendue_Commercial2, commission_commercial2);
            Assert.AreEqual(commission_Attendue_Commercial3, commission_commercial3);
            Assert.AreEqual(commission_Attendue_Commercial4, commission_commercial4);
        }
        /// <summary>
        /// Checks if the commercial can be moved to the break based on commercial type
        /// restrictions.
        /// </summary>
        /// <param name="breakCommercials">The Break/commercials instance</param>
        /// <param name="commercial">The commercial to add</param>
        /// <returns>True if the commercial can be added to the break</returns>
        private bool IsCommercialValidForBreak(
            BreakCommercials breakCommercials,
            Commercial commercial)
        {
            //Is the source commercial valid for the target break?
            if (breakCommercials.Break.InvalidCommercialTypes != null &&
                breakCommercials.Break.InvalidCommercialTypes.Contains(commercial.CommercialType))
            {
                //Commercial type is invalid for this break
                return(false);
            }

            var targetCountAlreadyInBreak =
                breakCommercials.Commercials.Count(
                    value => value.CommercialType == commercial.CommercialType);

            if (targetCountAlreadyInBreak + 1 > MaxBreakCapacityForCommercialType(breakCommercials.Break))
            {
                //Adding this type to the break will mean there's too many of the type
                return(false);
            }

            return(true);
        }
        public int UpdateCommercial([FromBody] Commercial commercial)
        {
            var repository = new StandCommercialRepository();

            return(repository.UpdateCommercial(commercial));
        }
예제 #24
0
        public void Setup()
        {
            // PC Model
            List <Item> items = new List <Item>();

            itemCatalogue = ItemCatalogue.TAG;
            inventory     = Inventory.TAG;
            pc            = PlayerCharacter.HEALTH + ":80:1," + PlayerCharacter.HUNGER + ":50:1,"
                            + PlayerCharacter.THIRST + ":60:1," + PlayerCharacter.SANITY + ":70:1";
            for (int i = 1; i < 21; i++)
            {
                Item tmp = new Item(StringMaker.makeItemStr(i));
                items.Add(tmp);
                itemCatalogue += ";" + tmp.ParseToString();
            }

            inventory += "#" + items[0].ParseToString() + "#" + items[3].ParseToString() + "#" + items[2].ParseToString() + "#" + items[5].ParseToString() + "#" + items[7].ParseToString();

            pcm = new PCModel(pc, inventory, itemCatalogue);

            // Event Model
            String validPREE    = PREventEffect.PR_EFFECT_TAG + ":" + PlayerCharacter.HEALTH + ":10:20:Test Result";
            String validIEE     = ItemEventEffect.ITEM_EFFECT_TAG + "#" + items[1].ParseToString() + "#Test Result";
            String validOption1 = Option.TAG + ";" + "1;TestText1;TestResult;EventEffects|" + validPREE + "|" + validIEE;
            String validOption2 = Option.TAG + ";" + "2;TestText2;TestResult;EventEffects|" + validPREE + "|" + validIEE;
            String validOption3 = Option.TAG + ";" + "3;TestText3;TestResult;EventEffects|" + validPREE + "|" + validIEE;
            String validOption4 = Option.TAG + ";" + "4;TestText4;TestResult;EventEffects|" + validPREE + "|" + validIEE;

            List <Event> events = new List <Event>();

            eventCatalogue = EventCatalogue.TAG;
            for (int i = 1; i < 21; i++)
            {
                String evt = Event.TAG + "$" + i + "$Type$Test text$EventOptions*" + validOption1 + "*" + validOption2 + "*" + validOption3 + "*" + validOption4;
                if (!Event.IsValidEvent(evt))
                {
                    String wrong = evt;
                    Event.IsValidEvent(wrong);
                }

                Event temp = new Event(evt);
                events.Add(temp);
                eventCatalogue += "^" + evt;
            }

            usedEvents   = EventModel.USED_TAG + ":1:2:6";
            currentEvent = events[7].ParseToString();
            em           = new EventModel(usedEvents, eventCatalogue, currentEvent);

            // Location Model
            Residential res = new Residential(1, 3, 5);
            Commercial  com = new Commercial(2, 4, 7);
            Civic       civ = new Civic(3, 6, 3);

            List <Location>      locations      = new List <Location>();
            List <DummyLocation> dummyLocations = new List <DummyLocation>();

            visitedLocs   = "VisitedLocations";
            unvisitedLocs = "UnvisitedLocations";

            for (int i = 1; i < 21; i++)
            {
                int    j = i + 20;
                String loc;
                String dloc;
                if (i + 1 < 21)
                {
                    if (i - 1 > 0)
                    {
                        loc  = "Type:Location,ID:" + i + ",Visited:True,Sublocations:" + res.ParseToString() + ":" + com.ParseToString() + ",CurrentSublocation:1";
                        dloc = "Type:DummyLocation,ID:" + j;
                    }
                    else
                    {
                        loc  = "Type:Location,ID:" + i + ",Visited:True,Sublocations:" + res.ParseToString() + ":" + com.ParseToString() + ",CurrentSublocation:1";
                        dloc = "Type:DummyLocation,ID:" + j;
                    }
                }
                else
                {
                    loc  = "Type:Location,ID:" + i + ",Visited:True,Sublocations:" + res.ParseToString() + ":" + com.ParseToString() + ",CurrentSublocation:1";
                    dloc = "Type:DummyLocation,ID:" + j;
                }

                Location      temp  = new Location(loc);
                DummyLocation dTemp = new DummyLocation(dloc);
                locations.Add(temp);
                dummyLocations.Add(dTemp);

                visitedLocs   += "#" + loc;
                unvisitedLocs += "#" + dloc;
            }

            currLoc  = "4";
            currSLoc = "1";
            lm       = new LocationModel(visitedLocs, unvisitedLocs, currLoc, currSLoc);


            // Discovery Model

            List <Discovery> discoveries = new List <Discovery>();

            discoveryCatalogue = DiscoveryCatalogue.TAG;
            for (int i = 1; i < 21; i++)
            {
                String    disc = Discovery.TAG + ":" + i + ":Text:" + i;
                Discovery temp = new Discovery(disc);
                discoveries.Add(temp);
                discoveryCatalogue += "#" + disc;
            }

            discovered = DiscoveryModel.DISCOVERED_TAG + ":1:2:7:8";

            dm = new DiscoveryModel(discovered, discoveryCatalogue);

            // Game State
            //gs = new GameState(pc, inventory, itemCatalogue,
            //    usedEvents, currentEvent, eventCatalogue,
            //    discovered, discoveryCatalogue,
            //    visitedLocs, unvisitedLocs, currLoc, currSLoc);
        }
예제 #25
0
 public void CopyFrom(Commercial o)
 {
     CopyFromBase(o);
     Offices = o.Offices;
 }
예제 #26
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="baseLoc"></param>
 /// <param name="cm"></param>
 /// <returns></returns>
 public override bool CanBeBuilt(Location baseLoc, ControlMode cm)
 {
     return(Commercial.canBeBuilt(baseLoc, Size, cm));
 }
예제 #27
0
 /// <summary>
 /// retrieves the score a brake has for a particular commercial
 /// </summary>
 /// <param name="br"></param>
 /// <param name="comm"></param>
 /// <returns></returns>
 private int GetScore(Break br, Commercial comm)
 {
     return(br?.Ratings?.FirstOrDefault(p => p.DemoType == comm.TargetDemo)?.Score ?? 0);
 }
예제 #28
0
 /// <summary>
 /// checks if a commercial can be added to the brake
 /// </summary>
 /// <param name="bestBr"></param>
 /// <param name="currComm"></param>
 /// <returns></returns>
 private bool IsTypeAllowedInBrake(Break bestBr, Commercial currComm)
 {
     return(bestBr.DisallowedCommTypes == null || bestBr.DisallowedCommTypes.All(d => d != currComm.CommercialType));
 }
예제 #29
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="bestBr"></param>
 /// <param name="currComm"></param>
 /// <param name="index"></param>
 private void AddCommercialAtIndex(Break bestBr, Commercial currComm, int index)
 {
     currComm.CurrentRating = bestBr.Ratings.FirstOrDefault(p => p.DemoType == currComm.TargetDemo);
     bestBr.Commercials.Insert(index, currComm);
 }
예제 #30
0
        /// <summary>
        /// recursively iterates over the given collection of breaks and finds the best allocation
        /// for a given commercial respecting given restrictions
        /// </summary>
        /// <param name="breaks"></param>
        /// <param name="currComm"></param>
        /// <param name="start"></param>
        private void ProcessRecursively(List <Break> breaks, Commercial currComm, int start)
        {
            if (start == breaks.Count)
            {
                return;
            }

            var breakIntern = breaks.Skip(start).ToList();
            var bestBr      = GetBestBreak(breakIntern, currComm);

            if (bestBr == null)
            {
                return;
            }
            if (bestBr.Commercials == null || !bestBr.Commercials.Any())
            {
                bestBr.Commercials = new List <Commercial>();
                AddCommercialAtIndex(bestBr, currComm, 0);
            }
            else if (bestBr.Commercials.Count < MaxNumberOfCommercialsPerBrake)
            {
                var newScore = GetScore(bestBr, currComm);
                if (bestBr.Commercials.Count(p => p.CommercialType == currComm.CommercialType) < MaxNumberOfCommercialsPerBrakeWithSameType)
                {
                    AddCommercialAtIndex(bestBr, currComm, bestBr.Commercials.Count);
                }
                else
                {
                    var toBeMoved = bestBr.Commercials.FirstOrDefault(d => d.CommercialType == currComm.CommercialType && d.CurrentRating.Score < newScore);
                    if (toBeMoved != null)
                    {
                        AddCommercialAtIndex(bestBr, currComm, bestBr.Commercials.IndexOf(toBeMoved));
                        bestBr.Commercials.Remove(toBeMoved);
                        MoveItem(breaks.IndexOf(bestBr), start, breaks);
                        ProcessRecursively(breaks, toBeMoved, ++start);
                    }
                    else
                    {
                        MoveItem(breaks.IndexOf(bestBr), start, breaks);
                        ProcessRecursively(breaks, currComm, ++start);
                    }
                }
            }
            else
            {
                if (ShouldBeInserted(currComm, bestBr))
                {
                    var newScore = GetScore(bestBr, currComm);
                    bestBr.Commercials = bestBr.Commercials.OrderByDescending(d => d.CurrentRating.Score).ToList();

                    var toBeMoved = bestBr.Commercials.FirstOrDefault(d => d.CurrentRating.Score < newScore);
                    AddCommercialAtIndex(bestBr, currComm, bestBr.Commercials.IndexOf(toBeMoved));

                    var detachedCom = bestBr.Commercials.Last();
                    bestBr.Commercials.Remove(detachedCom);

                    MoveItem(breaks.IndexOf(bestBr), start, breaks);
                    ProcessRecursively(breaks, detachedCom, ++start);
                }
                else
                {
                    MoveItem(breaks.IndexOf(bestBr), start, breaks);
                    ProcessRecursively(breaks, currComm, ++start);
                }
            }
        }