Esempio n. 1
0
        public void addProjToUser(ConectionData data, ScaffoldedModel models)
        {
            Model.Context context = new Model.Context();
            Model.User    user    = context.User.Where(c => c.LoginName == User.Identity.Name).FirstOrDefault();

            Model.Projects project = new Model.Projects();
            project.Owner            = user;
            project.OwnerId          = user.Id;
            project.ProjectName      = data.ProjName;
            project.ContextName      = data.ContextName;
            project.ConnectionString = data.ConnectionString;
            context.Add(project);
            foreach (var file in models.AdditionalFiles)
            {
                Model.Model model = new Model.Model();
                model.Project   = project;
                model.Projectid = project.Id;
                model.Model1    = file.Code;
                model.Filename  = Path.GetFileName(file.Path);
                context.Add(model);
            }
            Model.Model ContextModel = new Model.Model();
            ContextModel.Project   = project;
            ContextModel.Projectid = project.Id;
            ContextModel.Model1    = models.ContextFile.Code;
            ContextModel.Filename  = Path.GetFileName(models.ContextFile.Path);
            context.Add(ContextModel);
            context.SaveChanges();
            context.Dispose();
        }
Esempio n. 2
0
 // Function to save the result of simulation
 public void saveSimulation(Model.Simulation simulation)
 {
     if (this.View.isSimulate == true)
     {
         using (var context = new Model.Context())
         {
             Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
             context.Database.Initialize(force: false);  // connect to db
             context.Simulations.Add(simulation);
             try
             {
                 context.SaveChanges();  // save change
                 VMMain.UIMainForm.genMsgBox("Simulation saved!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             catch (Exception e)
             {
                 VMMain.HandleException(e, this.VMMain.UIMainForm);
                 VMMain.UIMainForm.genMsgBox("Fail to save the simulation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 Cursor.Current = Cursors.Arrow;             // get back to normal cursor
             }
         }
     }
     else
     {
         VMMain.UIMainForm.genMsgBox("You haven't simulated yet.", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 3
0
        // Function  to delect a result of simulation
        public void delectSimulaion(Simulation Sim)
        {
            using (var context = new Model.Context())
            {
                int SimId = Sim.Id;


                Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
                                                            //context.Database.Initialize(force: true);   // connect to db, it takes time
                context.Database.Initialize(force: true);   // connect to db, it takes time
                Model.Simulation SimToRemove = context.Simulations.Where(u => u.Id == SimId).First();
                if (SimToRemove != null)
                {
                    context.Simulations.Attach(SimToRemove);
                    context.Simulations.Remove(SimToRemove);
                    context.SaveChanges();
                    VMMain.UIMainForm.genMsgBox("Simulation deleted.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }


                Cursor.Current = Cursors.Arrow;             // get back to normal cursor

                SimulationForBinding = new List <Simulation>(Simulations);
                blSimulation         = new BindingList <Simulation>(SimulationForBinding);
                this.View.getLboxSim().DataSource    = blSimulation;
                this.View.getLboxSim().DisplayMember = "LbInformation";
            }
        }
 private void SaveScript(Model.Script script)
 {
     using (var context = new Model.Context())
     {
         context.Scripts.Add(script);
         context.SaveChanges();
     }
 }
Esempio n. 5
0
 public IActionResult EditModel([FromBody] EditModel tempproj)
 {
     Model.Context context = new Model.Context();
     Model.Model   model   = context.Model.Where(c => c.Projectid == tempproj.Id).Where(c => c.Filename == tempproj.Filename).FirstOrDefault();
     model.Model1 = tempproj.Model;
     context.SaveChanges();
     return(Ok());
 }
Esempio n. 6
0
        /**
         * Sell the selected product
         */
        public void SellProduct()
        {
            if (View.getLBoxClient().SelectedValue != null)
            {
                if (View.getLBoxProduct().SelectedValue != null)
                {
                    Client              selectedClt  = (Client)View.getLBoxClient().SelectedValue;
                    BoughtProduct       selectedPdt  = (BoughtProduct)View.getLBoxProduct().SelectedValue;
                    List <TimeInterest> TimeInterest = selectedPdt.Product.TimeInterests;
                    int     periode         = (int)(DateTime.Today.Date - selectedPdt.StartDate).TotalDays / 30;
                    Decimal TimeInterestPdt = Utils.FindTimeInterestSection(selectedPdt.StartDate, DateTime.Today, selectedPdt.Product.TimeInterests).Interest;
                    Decimal SillInterestPdt = Utils.FindSillInterestSection(selectedPdt.Price, selectedPdt.Product.SillInterests).Interest;
                    Decimal InterestRate    = 0;
                    Decimal InterestPdt     = 0;
                    if (TimeInterestPdt != 0)
                    {
                        InterestRate = (TimeInterestPdt + 100) * (SillInterestPdt + 100) / 100 - 100;
                        InterestPdt  = InterestRate / 100 * selectedPdt.Price;
                    }

                    DialogResult d = MessageBox.Show("You will have an interest rate : " + InterestRate.ToString("0.##") + " % and amount : " + InterestPdt.ToString("0.##") + ", are you sure to sell them now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (d == DialogResult.Yes)
                    {
                        selectedClt.BoughtProductList.Remove(selectedPdt);
                        selectedClt.AccountList[0].Balance = selectedClt.AccountList[0].Balance + InterestPdt;
                        using (var context = new Model.Context())
                        {
                            Cursor.Current = Cursors.WaitCursor;                 // waiting animation cursor
                            context.Database.Initialize(force: false);           // connect to db
                            List <Client> clients = context.Clients
                                                    .Include(c => c.AccountList) // get related entities
                                                    .Include(bpl => bpl.BoughtProductList)
                                                    .Include("BoughtProductList.Product")
                                                    .ToList();
                            Client clientInDb = clients.Where(c => c.Id == selectedClt.Id).SingleOrDefault();

                            BoughtProduct productS = context.BoughtProducts.Where(c => c.Id == selectedPdt.Id).SingleOrDefault();
                            context.BoughtProducts.Remove(productS);
                            clientInDb.BoughtProductList.Remove(selectedPdt);
                            clientInDb.AccountList[0].Balance = clientInDb.AccountList[0].Balance + InterestPdt;
                            //Console.Write(context.Clients.Find(VMMain.Client.Id).FirstName);
                            context.SaveChanges();
                        }
                        this.loadClientDetail(selectedClt);
                    }
                }
                else
                {
                    this.VMMain.UIMainForm.genMsgBox("You haven't chosen a product yet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                this.VMMain.UIMainForm.genMsgBox("You haven't chosen a client yet.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Model.T_REPARATUR currentReparatur = this.gridReparaturDaten.DataContext as Model.T_REPARATUR;

            List<Model.TZ_ARBEITLISTE> al = this.dataGridArbeit.DataContext as List<Model.TZ_ARBEITLISTE>;

            if (currentReparatur != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.T_REPARATUR reparaturToSave;

                    if (!currentReparatur.isNew)
                    {
                        reparaturToSave = context.T_REPARATUR.Where(q => q.REP_ID == currentReparatur.REP_ID).FirstOrDefault();

                        if (reparaturToSave != null)
                        {
                            foreach (Model.TZ_ARBEITLISTE arbl in al)
                            {
                                if (arbl.ABL_ID > 0)
                                {
                                    context.ApplyCurrentValues<Model.TZ_ARBEITLISTE>("TZ_ARBEITLISTE", arbl);
                                }
                                else
                                {
                                    context.AddToTZ_ARBEITLISTE(arbl);
                                }
                            }
                            context.ApplyCurrentValues<Model.T_REPARATUR>("T_REPARATUR", currentReparatur);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        context.AddToT_REPARATUR(currentReparatur);
                        context.SaveChanges();
                    }
                }
                this.dataGridReparaturDaten.DataContext = getReparaturen();
            }
        }
Esempio n. 8
0
        /**
         * Functions for 3 buttons, add, modify and choose client
         */
        public bool addClient(string firstName, string lastName, string idCardNumber)
        {
            bool isSuccess = true;

            if (firstName == "" || lastName == "" || idCardNumber == "")
            {
                VMMain.UIMainForm.genMsgBox("Please enter all 3 textboxes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (firstName.Length > 20 || lastName.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("First name and last name should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (idCardNumber.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("ID card number should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else
            {
                // creaete a client by input
                Client clt = new Client(firstName, lastName, idCardNumber);

                // create a default account
                Account acc = new Account();
                acc.Client      = clt;
                acc.Number      = DateTime.Now.ToString("yyyyMMddHHmmssf"); // use time of now , a unique number
                acc.status      = 1;
                acc.Balance     = 0M;
                clt.AccountList = new List <Account>();
                clt.AccountList.Add(acc);


                using (var context = new Model.Context())
                {
                    Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
                    context.Database.Initialize(force: false);  // connect to db
                    context.Clients.Add(clt);
                    try
                    {
                        context.SaveChanges();  // save change
                        getDataFromDb();        // refresh the list
                    }
                    catch (Exception e)
                    {
                        VMMain.HandleException(e, this.VMMain.UIMainForm);
                        isSuccess = false;
                    }
                    Cursor.Current = Cursors.Arrow;             // get back to normal cursor
                }
            }
            return(isSuccess);
        }
Esempio n. 9
0
        public Tempproj GenerateTempProject(ConectionData data, string ending, ScaffoldedModel models)
        {
            DiplomWork.Model.Context context     = new Model.Context();
            Model.TempProjects       tempProject = new Model.TempProjects();
            tempProject.ConnectionString = data.ConnectionString;
            tempProject.ContextName      = data.ContextName;
            tempProject.ProjectName      = data.ProjName;
            Tempproj tempproj = new Tempproj();

            context.Add(tempProject);
            tempproj.Models    = new List <string>();
            tempproj.FileNames = new List <string>();
            foreach (var file in models.AdditionalFiles)
            {
                DiplomWork.Model.Model model = new DiplomWork.Model.Model();
                model.Tempproject           = tempProject.Id;
                model.Model1                = file.Code;
                model.Filename              = Path.GetFileName(file.Path);
                model.TempprojectNavigation = tempProject;
                context.Add(model);
                context.SaveChanges();
                tempproj.FileNames.Add(Path.GetFileName(file.Path));
                tempproj.Models.Add(file.Code);
            }
            tempproj.FileNames.Add(Path.GetFileName(models.ContextFile.Path));
            tempproj.Models.Add(models.ContextFile.Code);
            DiplomWork.Model.Model Contextmodel = new DiplomWork.Model.Model();
            Contextmodel.Tempproject = tempProject.Id;
            Contextmodel.Model1      = models.ContextFile.Code;
            Contextmodel.Filename    = Path.GetFileName(models.ContextFile.Path);
            context.Add(Contextmodel);

            context.SaveChanges();
            tempproj.Id           = tempProject.Id;
            tempproj.RandomEnding = ending;
            tempproj.Data         = data;
            context.Dispose();
            return(tempproj);
        }
Esempio n. 10
0
        public IActionResult Newproject(Project project)
        {
            var context    = new Model.Context();
            var newproject = new Model.Projects();

            newproject.ConnectionString = project.ConnectionString;
            newproject.ContextName      = project.Context;
            newproject.ProjectName      = project.Name;
            newproject.OwnerId          = context.User.Where(c => c.LoginName == User.Identity.Name).FirstOrDefault().Id;

            context.Add(newproject);

            context.SaveChanges();
            return(Ok());
        }
Esempio n. 11
0
 // Agregar una palabra a la lista
 // params: objeto de la clase AccesoDatos.Model.Palabra
 public void AgregarPalabra(Palabra palabra)
 {
     using (var db = new Model.Context())
     {
         try
         {
             db.PalabraSet.Add(palabra);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido agregar la palabra ", e);
         }
     }
 }
Esempio n. 12
0
 // Agregar una etiqueta a la lista
 // params: objeto de la clase AccesoDatos.Model.Etiqueta
 public void AgregarEtiqueta(Model.Etiqueta etiqueta)
 {
     using (var db = new Model.Context())
     {
         try
         {
             db.EtiquetaSet.Add(etiqueta);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido agregar la etiqueta ", e);
         }
     }
 }
Esempio n. 13
0
 // Agregar un documento a la lista
 // params: objeto de la clase AccesoDatos.Model.Documento
 public void AgregarDocumento(Documento documento)
 {
     using (var db = new Model.Context())
     {
         try
         {
             db.DocumentoSet.Add(documento);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido agregar el documento", e);
         }
     }
 }
Esempio n. 14
0
 // Agregar un proyecto a la lista
 // params: objeto de la clase AccesoDatos.Model.Proyecto
 public void AgregarProyecto(Proyecto proyecto)
 {
     using (var db = new Model.Context())
     {
         try
         {
             db.ProyectoSet.Add(proyecto);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido agregar el proyecto ", e);
         }
     }
 }
Esempio n. 15
0
 // Elimina un documento de la lista
 // params: objeto de la clase AccesoDatos.Model.Documento
 public void EliminarDocumento(Documento documento)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var doc = db.DocumentoSet.FirstOrDefault(x => x.Id == documento.Id);
             db.DocumentoSet.Remove(doc);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido eliminar el documento ", e);
         }
     }
 }
Esempio n. 16
0
 // Elimina un proyecto de la lista
 // params: objeto de la clase AccesoDatos.Model.Proyecto
 public void EliminarProyecto(Proyecto proyecto)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var proy = db.ProyectoSet.FirstOrDefault(x => x.Id == proyecto.Id);
             db.ProyectoSet.Remove(proy);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido eliminar el proyecto ", e);
         }
     }
 }
Esempio n. 17
0
 // Elimina una cita de la lista
 // params: objeto de la clase AccesoDatos.Model.Cita
 public void EliminarCita(Model.Cita cita)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var citaTmp = db.CitaSet.FirstOrDefault(x => x.Id == cita.Id);
             db.CitaSet.Remove(citaTmp);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido eliminar la cita ", e);
         }
     }
 }
Esempio n. 18
0
 // Elimina una palabra de la lista
 // params: objeto de la clase AccesoDatos.Model.Palabra
 public void EliminarPalabra(Palabra palabra)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var pal = db.PalabraSet.FirstOrDefault(x => x.Id == palabra.Id);
             db.PalabraSet.Remove(pal);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido eliminar la palabra ", e);
         }
     }
 }
Esempio n. 19
0
 // Elimina un etiqueta de la lista
 // params: objeto de la clase AccesoDatos.Model.Etiqueta
 public void EliminarEtiqueta(Model.Etiqueta etiqueta)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var etiq = db.EtiquetaSet.FirstOrDefault(x => x.Id == etiqueta.Id);
             db.EtiquetaSet.Remove(etiq);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido eliminar la etiqueta ", e);
         }
     }
 }
Esempio n. 20
0
        // Agregar una nube a la lista 
        // params: objeto de la clase AccesoDatos.Model.Nube
        public void AgregarNube(Model.Nube nube)
        {
            using (var db = new Model.Context())
            {
                try
                {
                    db.NubeSet.Add(nube);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception("No se ha podido agregar la nube ", e);
                }
            }

        }
Esempio n. 21
0
 // Actualiza un proyecto de la lista
 // params: objeto de la clase AccesoDatos.Model.Proyecto con los datos actualizados
 public void ActualizarProyecto(Proyecto proyecto)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var proy = db.ProyectoSet.FirstOrDefault(x => x.Id == proyecto.Id);
             db.Entry(proy).State = EntityState.Modified;
             db.Entry(proy).CurrentValues.SetValues(proyecto);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido actualizar el proyecto ", e);
         }
     }
 }
Esempio n. 22
0
        // Elimina una nube de la lista 
        // params: objeto de la clase AccesoDatos.Model.nube 
        public void EliminarNube(Model.Nube nube)
        {
            using (var db = new Model.Context())
            {
                try
                {
                    var nubeTmp = db.NubeSet.FirstOrDefault(x => x.Id == nube.Id);
                    db.NubeSet.Remove(nubeTmp);
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    throw new Exception("No se ha podido eliminar la nube ", e);

                }
            }
        }
Esempio n. 23
0
 // Actualiza un documento de la lista
 // params: objeto de la clase AccesoDatos.Model.Documento con los datos actualizados
 public void ActualizarDocumento(Documento documento)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var doc = db.DocumentoSet.FirstOrDefault(x => x.Id == documento.Id);
             db.Entry(doc).State = EntityState.Modified;
             db.Entry(doc).CurrentValues.SetValues(documento);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido actualizar el documento ", e);
         }
     }
 }
Esempio n. 24
0
 // Actualiza una nube de la lista 
 // params: objeto de la clase AccesoDatos.Model.nube con los datos actualizados
 public void ActualizarNube(Model.Nube nube)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var nubeTmp = db.NubeSet.FirstOrDefault(x => x.Id == nube.Id);
             db.Entry(nubeTmp).State = EntityState.Modified;
             db.Entry(nubeTmp).CurrentValues.SetValues(nube);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido actualizar la nube ", e);
         }
     }
 }
Esempio n. 25
0
 // Actualiza una palabra de la lista
 // params: objeto de la clase AccesoDatos.Model.Palabra con los datos actualizados
 public void ActualizarPalabra(Palabra palabra)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var pal = db.PalabraSet.FirstOrDefault(x => x.Id == palabra.Id);
             db.Entry(pal).State = EntityState.Modified;
             db.Entry(pal).CurrentValues.SetValues(palabra);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido actualizar la palabra ", e);
         }
     }
 }
Esempio n. 26
0
 // Actualiza una etiqueta de la lista
 // params: objeto de la clase AccesoDatos.Model.Etiqueta con los datos actualizados
 public void ActualizarEtiqueta(Model.Etiqueta etiqueta)
 {
     using (var db = new Model.Context())
     {
         try
         {
             var etiq = db.EtiquetaSet.FirstOrDefault(x => x.Id == etiqueta.Id);
             db.Entry(etiq).State = EntityState.Modified;
             db.Entry(etiq).CurrentValues.SetValues(etiqueta);
             db.SaveChanges();
         }
         catch (Exception e)
         {
             throw new Exception("No se ha podido actualizar la etiqueta ", e);
         }
     }
 }
Esempio n. 27
0
        public bool modifyClient(Client clt, string firstName, string lastName, string idCardNumber)
        {
            bool isSuccess = true;

            if (firstName == "" || lastName == "" || idCardNumber == "")
            {
                VMMain.UIMainForm.genMsgBox("Please enter all 3 textboxes.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (firstName.Length > 20 || lastName.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("First name and last name should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else if (idCardNumber.Length > 20)
            {
                VMMain.UIMainForm.genMsgBox("ID card number should less than 20 characters", "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
                isSuccess = false;
            }
            else
            {
                using (var context = new Model.Context())
                {
                    Cursor.Current = Cursors.WaitCursor;        // waiting animation cursor
                    context.Database.Initialize(force: false);  // connect to db
                    Client oldClt = context.Clients.Find(clt.Id);
                    oldClt.FirstName    = firstName;
                    oldClt.LastName     = lastName;
                    oldClt.IdCardNumber = idCardNumber;
                    try
                    {
                        context.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        VMMain.HandleException(e, this.VMMain.UIMainForm);
                        isSuccess = false;
                    }
                    Cursor.Current = Cursors.Arrow;             // get back to normal cursor
                }
            }

            return(isSuccess);
        }
Esempio n. 28
0
        /// <summary>
        /// Löscht einen Nutzer aus dem Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            Model.T_NUTZER currentNutzer = this.gridNutzerDaten.DataContext as Model.T_NUTZER;

            if (currentNutzer != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.T_NUTZER nutzerToDelete = context.T_NUTZER.Where(q => q.NUT_ID == currentNutzer.NUT_ID).First();

                    if (nutzerToDelete != null)
                    {
                        context.T_NUTZER.DeleteObject(context.T_NUTZER.Where(q => q.NUT_ID == nutzerToDelete.NUT_ID).First());
                        context.SaveChanges();
                    }
                }
                this.gridNutzerDaten.DataContext = new Model.T_NUTZER();
                this.dataGridNutzerDaten.DataContext = getNutzer();
            }
        }
Esempio n. 29
0
        /// <summary>
        /// Löscht ein Material aus dem Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            Model.TR_MATERIAL currentMaterial = this.gridMaterialDaten.DataContext as Model.TR_MATERIAL;

            if (currentMaterial != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.TR_MATERIAL materialToDelete = context.TR_MATERIAL.Where(q => q.MAT_ID == currentMaterial.MAT_ID).First();

                    if (materialToDelete != null)
                    {
                        context.TR_MATERIAL.DeleteObject(context.TR_MATERIAL.Where(q => q.MAT_ID == materialToDelete.MAT_ID).First());
                        context.SaveChanges();
                    }
                }
                this.gridMaterialDaten.DataContext = new Model.TR_MATERIAL();
                this.dataGridMaterialDaten.DataContext = getMaterial();
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Löscht eine Tätigkeit aus dem Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            Model.TR_ARBEIT currentArbeit = this.gridArbeitsDaten.DataContext as Model.TR_ARBEIT;

            if (currentArbeit != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.TR_ARBEIT arbeitToDelete = context.TR_ARBEIT.Where(q => q.ARB_ID == currentArbeit.ARB_ID).First();

                    if (arbeitToDelete != null)
                    {
                        context.TR_ARBEIT.DeleteObject(context.TR_ARBEIT.Where(q => q.ARB_ID == arbeitToDelete.ARB_ID).First());
                        context.SaveChanges();
                    }
                }
                this.gridArbeitsDaten.DataContext = new Model.TR_MATERIAL();
                this.dataGridArbeitsDaten.DataContext = getArbeit();
            }
        }
Esempio n. 31
0
        /// <summary>
        /// Löscht ein Fahrzeug aus dem Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            Model.T_FAHRZEUG currentFahrzeug = this.gridFahrzeug.DataContext as Model.T_FAHRZEUG;

            if (currentFahrzeug != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.T_FAHRZEUG fahrzeugToDelete = context.T_FAHRZEUG.Where(q => q.FZG_ID == currentFahrzeug.FZG_ID).FirstOrDefault();

                    if (fahrzeugToDelete != null)
                    {
                        context.T_FAHRZEUG.DeleteObject(context.T_FAHRZEUG.Where(q => q.FZG_ID == fahrzeugToDelete.FZG_ID).FirstOrDefault());
                        context.SaveChanges();
                    }
                }
                this.gridFahrzeug.DataContext = new Model.T_FAHRZEUG();
                this.datagridFahrzeugDaten.DataContext = getFahrzeuge();
            }
        }
Esempio n. 32
0
        public IActionResult RemoveProject([FromBody] int projectID)
        {
            var context         = new Model.Context();
            var project         = context.Projects.Where(c => c.Id == projectID).FirstOrDefault();
            var models          = context.Model.Where(c => c.Projectid == projectID);
            var compiledContext = context.CompiledContext.Where(c => c.ProjectId == projectID).FirstOrDefault();

            if (compiledContext != null)
            {
                context.Remove(compiledContext);
            }
            if (models != null)
            {
                context.RemoveRange(models.AsEnumerable());
            }
            if (project != null)
            {
                context.Remove(project);
            }
            context.SaveChanges();
            context.Dispose();
            return(Ok());
        }
Esempio n. 33
0
        // Function to execute a simulation and save into the bdd
        public void ExecuteSimulation(Model.Simulation Sim)
        {
            if (this.VMMain.Client.AccountList[0].Balance >= Sim.Price)
            {
                Model.BoughtProduct boughtP = new Model.BoughtProduct();
                //Enter infomations of simulation
                boughtP.BoughtStatus = 1;
                boughtP.Price        = Sim.Price;

                //boughtP.Product = Sim.Product;
                boughtP.ProductId = Sim.ProductId;

                boughtP.SettlementPrice = Sim.SettlementPrice;

                boughtP.StartDate  = Sim.StartDate;
                boughtP.EndDate    = Sim.EndDate;
                boughtP.BuyingDate = DateTime.Today.Date;

                //boughtP.Client = this.VMMain.Client;
                boughtP.ClientId = this.VMMain.Client.Id;

                boughtP.FinalInterest = Sim.SettlementPrice - Sim.Price;

                //Save bought product
                using (var context = new Model.Context())
                {
                    Cursor.Current = Cursors.WaitCursor;                 // waiting animation cursor
                    context.Database.Initialize(force: false);           // connect to db
                    List <Client> clients = context.Clients
                                            .Include(c => c.AccountList) // get related entities
                                            .Include(bpl => bpl.BoughtProductList)
                                            .Include("BoughtProductList.Product")
                                            .Include("BoughtProductList.Product.TimeInterests")
                                            .Include("BoughtProductList.Product.SillInterests")
                                            .ToList();
                    Client clientSim = clients.Where(c => c.Id == VMMain.Client.Id).SingleOrDefault();
                    //context.BoughtProducts.Add(boughtP);
                    clientSim.BoughtProductList.Add(boughtP);
                    clientSim.AccountList[0].Balance = clientSim.AccountList[0].Balance - Sim.Price;
                    //Console.Write(context.Clients.Find(VMMain.Client.Id).FirstName);

                    VMMain.Client.BoughtProductList.Add(boughtP);

                    try
                    {
                        context.SaveChanges();  // save change
                        VMMain.UIMainForm.genMsgBox("Simulation executed!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.VMMain.Client.AccountList[0].Balance = this.VMMain.Client.AccountList[0].Balance - Sim.Price;
                        this.VMMain.VMClient.loadClientDetail(VMMain.Client);
                        printBalance();
                    }
                    catch (Exception e)
                    {
                        VMMain.HandleException(e, this.VMMain.UIMainForm);
                        VMMain.UIMainForm.genMsgBox("Fail to execute the simulation", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Cursor.Current = Cursors.Arrow;             // get back to normal cursor
                    }
                    //context.SaveChanges();
                }
            }
            else
            {
                VMMain.UIMainForm.genMsgBox("Balance not enough!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 34
0
        /// <summary>
        ///  Speichert ein neues Material im Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Model.TR_MATERIAL currentMaterial = this.gridMaterialDaten.DataContext as Model.TR_MATERIAL;

            if (currentMaterial != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.TR_MATERIAL materialToSave;

                    if (!currentMaterial.isNew)
                    {
                        materialToSave = context.TR_MATERIAL.Where(q => q.MAT_ID == currentMaterial.MAT_ID).First();

                        if (materialToSave != null)
                        {
                            context.ApplyCurrentValues<Model.TR_MATERIAL>("TR_MATERIAL", currentMaterial);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        context.AddToTR_MATERIAL(currentMaterial);
                        context.SaveChanges();
                    }
                }

                this.dataGridMaterialDaten.DataContext = getMaterial();
            }
        }
Esempio n. 35
0
        /**
         * Save product in database. Call by UISunProduct
         */
        public bool saveProduct()
        {
            bool isSuccess            = true;   // if false, will not save modification
            bool isAnyFieldNotFilled  = false;  // if true, will show a message
            bool isAnyFieldNotCorrect = false;  // if true, will show a message

            Product pdt = new Product();

            if (View.sub.pdtId != 0)
            {
                pdt.Id = View.sub.pdtId;
            }

            pdt.Name          = View.sub.getTbName().Text;
            pdt.Description   = View.sub.getTbDescription().Text;
            pdt.ProductStatus = 1;   // set 1 as default

            int sillInterestCount = View.sub.sillInterestCount;
            int timeInterestCount = View.sub.timeInterestCount;



            // extract all filled pairs of sill-interest
            for (int i = 1; i <= sillInterestCount; i++)
            {
                bool    isTwoTbFilled = true;
                decimal tempSill      = 0;
                decimal tempInterest  = 0;

                // find all tb of sill, validate the text and copy it to tempSill
                TextBox tbSill = (TextBox)View.sub.getFlpSI().Controls.Find("sill" + i.ToString(), false).First();
                string  sill   = tbSill.Text;
                // if field is not filled, allow but show a message
                if (string.IsNullOrEmpty(sill))
                {
                    isTwoTbFilled       = false; // if false, will not save this pair of Sill-Interest
                    isAnyFieldNotFilled = true;  // if true, will show a message
                }
                // if is not numeric, not allow, change text color to red and show a message
                else if (!decimal.TryParse(sill, out tempSill))
                {
                    isTwoTbFilled        = false;
                    isAnyFieldNotCorrect = true;    // if true, will show a message
                    isSuccess            = false;   // if false, will not save modification
                    tbSill.ForeColor     = System.Drawing.Color.Red;
                }
                // if is numeric, change back to black color
                else
                {
                    tbSill.ForeColor = System.Drawing.Color.Black;
                }

                // find all tb of interest, validate the text and copy it to tempSill
                TextBox tbInterest = (TextBox)View.sub.getFlpSI().Controls.Find("interest" + i.ToString(), false).First();
                string  interest   = tbInterest.Text;
                if (string.IsNullOrEmpty(interest))
                {
                    isTwoTbFilled       = false;
                    isAnyFieldNotFilled = true;
                }
                else if (!decimal.TryParse(interest, out tempInterest))
                {
                    isTwoTbFilled        = false;
                    isAnyFieldNotCorrect = true;
                    isSuccess            = false;
                    tbInterest.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    tbInterest.ForeColor = System.Drawing.Color.Black;
                }

                // if two tb are filled and the text inside is numeric, save them in the list
                if (isTwoTbFilled)
                {
                    SillInterest si = new SillInterest();
                    si.Sill     = tempSill;
                    si.Interest = tempInterest;
                    pdt.SillInterests.Add(si);
                }
            }


            // find all filled pairs of time-interest textboxes
            for (int i = 1; i <= timeInterestCount; i++)
            {
                bool    isTwoTbFilled = true;
                int     tempTime      = 0;
                decimal tempInterest  = 0;

                TextBox tbSill = (TextBox)View.sub.getFlpTI().Controls.Find("sill" + i.ToString(), false).First();
                string  sill   = tbSill.Text;
                if (string.IsNullOrEmpty(sill))
                {
                    isTwoTbFilled       = false;
                    isAnyFieldNotFilled = true;
                }
                else if (!int.TryParse(sill, out tempTime))
                {
                    isTwoTbFilled        = false;
                    isAnyFieldNotCorrect = true;
                    isSuccess            = false;
                    tbSill.ForeColor     = System.Drawing.Color.Red;
                }
                else
                {
                    tbSill.ForeColor = System.Drawing.Color.Black;
                }

                TextBox tbInterest = (TextBox)View.sub.getFlpTI().Controls.Find("interest" + i.ToString(), false).First();
                string  interest   = tbInterest.Text;
                if (string.IsNullOrEmpty(interest))
                {
                    isTwoTbFilled       = false;
                    isAnyFieldNotFilled = true;
                }
                else if (!decimal.TryParse(interest, out tempInterest))
                {
                    isTwoTbFilled        = false;
                    isAnyFieldNotCorrect = true;
                    isSuccess            = false;
                    tbInterest.ForeColor = System.Drawing.Color.Red;
                }
                else
                {
                    tbInterest.ForeColor = System.Drawing.Color.Black;
                }

                // convert to SillInterest, and add to list
                if (isTwoTbFilled)
                {
                    TimeInterest ti = new TimeInterest();
                    ti.Time     = tempTime;
                    ti.Interest = tempInterest;
                    pdt.TimeInterests.Add(ti);
                }
            }


            // sort list by sill/time
            pdt.SillInterests = pdt.SillInterests.OrderBy(si => si.Sill).ToList();
            pdt.TimeInterests = pdt.TimeInterests.OrderBy(ti => ti.Time).ToList();


            // show messages
            if (isAnyFieldNotCorrect)
            {
                VMMain.UIMainForm.genMsgBox("Input incorrect!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (isAnyFieldNotFilled)
            {
                VMMain.UIMainForm.genMsgBox("All not filled fields will be ignore", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }


            // connect to db
            using (var context = new Model.Context())
            {
                Cursor.Current = Cursors.WaitCursor;       // waiting animation cursor
                context.Database.Initialize(force: false); // connect to db

                if (View.sub.pdtId != 0)                   // if modified a product
                {
                    var pdts = context.Products.Where(p => p.Id == pdt.Id);
                    // there should be only one product in the list
                    Product pdtOld = pdts.First();
                    // modify product
                    pdtOld.Name        = pdt.Name;
                    pdtOld.Description = pdt.Description;
                    // clear old SI and TI list, then copy new SI and TI
                    pdtOld.SillInterests.Clear();
                    pdtOld.SillInterests = new List <SillInterest>(pdt.SillInterests);
                    pdtOld.TimeInterests.Clear();
                    pdtOld.TimeInterests = new List <TimeInterest>(pdt.TimeInterests);
                    // set productID for SI and TI
                    foreach (SillInterest si in pdtOld.SillInterests)
                    {
                        si.ProductID = pdtOld.Id;
                    }
                    foreach (TimeInterest ti in pdtOld.TimeInterests)
                    {
                        ti.ProductID = pdtOld.Id;
                    }
                }
                else // if add a new product
                {
                    // add product
                    context.Products.Add(pdt);
                }
                try
                {
                    context.SaveChanges();
                    // modify product will set product's SI and TI rows's productID to null,
                    // and insert new rows of SI and TI, so delete all rows with null productID
                    context.SillInterests.RemoveRange(context.SillInterests.Where(si => si.ProductID == null));
                    context.TimeInterests.RemoveRange(context.TimeInterests.Where(ti => ti.ProductID == null));
                    context.SaveChanges();
                }
                catch (DbEntityValidationException dbEx)    // catch DbEntityValidationException and print it out
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}",
                                                   validationError.PropertyName,
                                                   validationError.ErrorMessage);
                        }
                    }
                    isSuccess = false;
                }
                catch (Exception e)     // get other exception
                {
                    VMMain.UIMainForm.genMsgBox(e.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                Cursor.Current = Cursors.Arrow;             // get back to normal cursor
            }

            return(isSuccess);
        }
Esempio n. 36
0
        /// <summary>
        /// Speichert Änderungen eines Fahrzeugdatensatzes im Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Model.T_FAHRZEUG currentFahrzeug = this.gridFahrzeug.DataContext as Model.T_FAHRZEUG;

            if (currentFahrzeug != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.T_FAHRZEUG fahrzeugToSave;

                    if (!currentFahrzeug.isNew)
                    {
                        fahrzeugToSave = context.T_FAHRZEUG.Where(q => q.FZG_ID == currentFahrzeug.FZG_ID).FirstOrDefault();

                        if (fahrzeugToSave != null)
                        {
                            context.ApplyCurrentValues<Model.T_FAHRZEUG>("T_FAHRZEUG", currentFahrzeug);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        context.AddToT_FAHRZEUG(currentFahrzeug);
                        context.SaveChanges();
                    }
                }

                this.datagridFahrzeugDaten.DataContext = getFahrzeuge();
            }
        }
Esempio n. 37
0
        /// <summary>
        ///  Speichert eine neue Tätigkeit im Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Model.TR_ARBEIT currentArbeit = this.gridArbeitsDaten.DataContext as Model.TR_ARBEIT;

            if (currentArbeit != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.TR_ARBEIT arbeitToSave;

                    if (!currentArbeit.isNew)
                    {
                        arbeitToSave = context.TR_ARBEIT.Where(q => q.ARB_ID == currentArbeit.ARB_ID).First();

                        if (arbeitToSave != null)
                        {
                            context.ApplyCurrentValues<Model.TR_ARBEIT>("TR_ARBEIT", currentArbeit);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        context.AddToTR_ARBEIT(currentArbeit);
                        context.SaveChanges();
                    }
                }

                this.dataGridArbeitsDaten.DataContext = getArbeit();
            }
        }
Esempio n. 38
0
        /// <summary>
        /// Speichert Änderungen eines Nutzerdatensatzes im Model
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            Model.T_NUTZER currentNutzer = this.gridNutzerDaten.DataContext as Model.T_NUTZER;

            if (currentNutzer != null)
            {
                using (Model.Context context = new Model.Context())
                {
                    Model.T_NUTZER nutzerToSave;

                    if (!currentNutzer.isNew)
                    {
                        nutzerToSave = context.T_NUTZER.Where(q => q.NUT_ID == currentNutzer.NUT_ID).First();

                        if (nutzerToSave != null)
                        {
                            context.ApplyCurrentValues<Model.T_NUTZER>("T_NUTZER", currentNutzer);
                            context.SaveChanges();
                        }
                    }
                    else
                    {
                        context.AddToT_NUTZER(currentNutzer);
                        context.SaveChanges();
                    }
                }

                this.dataGridNutzerDaten.DataContext = getNutzer();
            }
        }