예제 #1
0
        public override dynamic Restaurar()
        {
            Estoc estocDessat = new Estoc();

            try
            {
                BaseDeDades.Desconecta();
                BaseDeDades.Conecta();
                Recepta[]        receptes  = Recepta.ReceptesDessades(BaseDeDades);
                Producte[]       productes = Producte.ProductesDessats(BaseDeDades, receptes);
                UnitatProducte[] unitats   = UnitatProducte.UnitatsDessades(BaseDeDades, receptes, productes);
                estocDessat.Afegir(productes);
                //poso els objectes en el control!
                Afegir(receptes);
                for (int i = 0; i < receptes.Length; i++)
                {
                    foreach (Ingredient ingredient in receptes[i])
                    {
                        Afegir(ingredient);
                    }
                }
                Afegir(productes);
                Afegir(unitats);
            }
            catch { }
            return(estocDessat);
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            UnitatProducte unitat = obj as UnitatProducte;
            bool           iguals = unitat != null;

            if (iguals)
            {
                iguals = unitat.DataCaducitat.Equals(DataCaducitat) && unitat.DataQueEsVaObrir.Equals(DataQueEsVaObrir) && unitat.IdRecepta == IdRecepta && unitat.Obert.Equals(Obert) && unitat.Producte.PrimaryKey.Equals(Producte.PrimaryKey) && unitat.Quantitat == Quantitat && unitat.Recepta.Equals(Recepta) && unitat.Taula == Taula;
            }
            return(iguals);
        }
예제 #3
0
        public void FabricaProducteAmbReceptaOriginal()
        {
            Producte pa = new Producte("Pa");
            Producte formatge = new Producte("Formatge");
            Recepta receptaBocata = new Recepta("BocataFormatge");
            Producte bocataFormatge = new Producte("Bocata de Formatge");
            UnitatProducte unitatPa = new UnitatProducte(pa, 10);
            UnitatProducte unitatFormatge = new UnitatProducte(formatge, 15);
            UnitatProducte unitatBocata;
            Estoc.Estoc estoc = new Estoc.Estoc();
            bocataFormatge.ReceptaOriginal = receptaBocata;
            receptaBocata.Afegir(new Ingredient(pa, 1));
            receptaBocata.Afegir(new Ingredient(formatge, 4));
            estoc.Afegir(new Producte[] { pa, formatge, bocataFormatge });
            unitatBocata = Producte.Fabrica(bocataFormatge, estoc);
            Assert.AreNotEqual(null, unitatBocata);


        }
예제 #4
0
		static void Main(string[] args)
		{
			BaseDeDadesMySQL bd = new BaseDeDadesMySQL();
			bd.Conecta();
			ControlObjectesSql control = new Control(bd);
			
			var estoc = control.Restaurar();
			Estoc.Estoc estocAct = new Estoc.Estoc();
			control.Reset();
			Producte producte = new Producte("ProvaIDProducte", "ProvaCategoria", "ProvaUnitat", new TimeSpan(4, 3, 2, 1), new TimeSpan(1, 0, 0, 0), new TimeSpan(1, 2, 3, 4), new Recepta(), 5, 100);
			UnitatProducte unitat = new UnitatProducte(producte);
			UnitatProducte unitat2 = new UnitatProducte(producte);
			unitat2.Recepta = new Recepta("Altre");
			control.Afegir((ObjecteSql)unitat2.Recepta);
			unitat2.Recepta.Afegir(new Ingredient(producte, 100M));
			control.Afegir((IEnumerable<Ingredient>)unitat2.Recepta);
			unitat2.Quantitat = 12.3M;
			unitat.Quantitat = 10;
			control.Afegir((ObjecteSql)producte.ReceptaOriginal);
			control.Afegir((ObjecteSql)producte);
			control.Afegir(unitat);
			control.Afegir(unitat2);
			control.ComprovaActualitzacions();
			estocAct.Afegir(producte);
			if (estocAct.Equals(estoc))
				Console.WriteLine("Funciona");//si esta bien!!
			else
				Console.WriteLine("No funciona");

			
			estoc = control.Restaurar();
			if (estocAct.Equals(estoc))
				Console.WriteLine("Funciona");//si esta bien!!
			else
				Console.WriteLine("No funciona");
			//Console.WriteLine(unitat2);
			//Console.WriteLine(unitat2.Recepta);
			//Console.WriteLine(producte);
			//Console.WriteLine(estoc);
			//Console.WriteLine(control);
			Console.ReadKey();
			
		}
예제 #5
0
 public void ActualitzarDadesUnitatProducte()
 {
     UnitatProducte unitat = new UnitatProducte(new Producte("ProvaUnitatProducte2"));
     control.Afegir((ObjecteSql)unitat.Producte.ReceptaOriginal);
     control.Afegir((ObjecteSql)unitat.Producte);
     control.Afegir(unitat);
     unitat.Quantitat = 223;
     control.ComprovaActualitzacions(unitat);
     UnitatProducte unitatDessada = null;
     SortedList<string, UnitatProducte> indexProductes = new SortedList<string, UnitatProducte>();
     foreach (UnitatProducte producteD in UnitatProducte.UnitatsDessades(bdProves))
         indexProductes.Add(producteD.PrimaryKey, producteD);
     try
     {
         unitatDessada = indexProductes[unitat.PrimaryKey];
     }
     catch {unitatDessada=new UnitatProducte(new Producte("ProvaUnitatProducte2")); }
     Assert.AreEqual(unitat.Quantitat, unitatDessada.Quantitat);//si esta bien!!
 }
예제 #6
0
 public void DonarDeBaixaUnitatProducte()
 {
     UnitatProducte unitat = new UnitatProducte(new Producte("ProvaUnitatProducte2"));
     control.Afegir((ObjecteSql)unitat.Producte.ReceptaOriginal);
     control.Afegir((ObjecteSql)unitat.Producte);
     control.Afegir(unitat);
     unitat.OnBaixa();
     Assert.AreEqual(false, bdProves.CompruebaSiFunciona(unitat.StringConsultaSql()));
 }
예제 #7
0
 public void DonarDeBaixaUnitatDonantDeBaixaElProducte()
 {
     UnitatProducte unitat = new UnitatProducte(new Producte("ProvaUnitatProducte2"));
     control.Afegir((ObjecteSql)unitat.Producte.ReceptaOriginal);
     control.Afegir((ObjecteSql)unitat.Producte);
     control.Afegir(unitat);
     unitat.Producte.OnBaixa();//tiene que dar de baja todas sus unidades 
     Assert.AreEqual(false, bdProves.CompruebaSiFunciona(unitat.StringConsultaSql()));
 }
예제 #8
0
 public void DonarDeAltaUnitatProducte()
 {
     UnitatProducte unitat = new UnitatProducte(new Producte("ProvaUnitatProducte"));
     control.Afegir((ObjecteSql)unitat.Producte.ReceptaOriginal);
     control.Afegir((ObjecteSql)unitat.Producte);//doy de alta el producto
     control.Afegir(unitat);//doy de alta la unidad
     Assert.AreEqual(true, bdProves.CompruebaSiFunciona(unitat.StringConsultaSql()));
 }
예제 #9
0
        public void ErrorFabricaProductesFaltants()
        {
            Producte pa = new Producte("Pa");
            Producte formatge = new Producte("Formatge");
            Recepta receptaBocata = new Recepta("BocataFormatge");
            Producte bocataFormatge = new Producte("Bocata de Formatge");
            Producte oli = new Producte("Oli");
            UnitatProducte unitatOli = new UnitatProducte(oli, 100);
            UnitatProducte unitatPa = new UnitatProducte(pa, 10);
            UnitatProducte unitatFormatge = new UnitatProducte(formatge, 15);
            UnitatProducte unitatBocata;
            Estoc.Estoc estoc = new Estoc.Estoc();
            receptaBocata.Afegir(new Ingredient(pa, 1.5M));
            receptaBocata.Afegir(new Ingredient(formatge, 50));
            receptaBocata.Afegir(new Ingredient(oli,10));
            estoc.Afegir(new Producte[] { pa, formatge, bocataFormatge,oli });
            unitatBocata = Producte.Fabrica(bocataFormatge, receptaBocata, new Producte[] { pa, formatge });//por cambiar...se tiene que hacer...
            Assert.AreEqual(null, unitatBocata);


        }
예제 #10
0
        public void FabricaElMaximDeProducteAmbProductesDeEstoc()
        {
            Producte pa = new Producte("Pa");
            Producte formatge = new Producte("Formatge");
            Recepta receptaBocata = new Recepta("BocataFormatge");
            Producte bocataFormatge = new Producte("Bocata de Formatge");
            UnitatProducte unitatPa = new UnitatProducte(pa, 10);
            UnitatProducte unitatFormatge = new UnitatProducte(formatge, 15);
            UnitatProducte[] unitatsBocata;
            Estoc.Estoc estoc = new Estoc.Estoc();
            receptaBocata.Afegir(new Ingredient(pa, 1.5M));
            receptaBocata.Afegir(new Ingredient(formatge, 6));
            estoc.Afegir(new Producte[] { pa, formatge, bocataFormatge });
            unitatsBocata = Producte.FabricaElMax(bocataFormatge, estoc,receptaBocata);
            Assert.AreNotEqual(new UnitatProducte[]{}, unitatsBocata);


        }