Esempio n. 1
0
        public ActionResult <string> delete([FromForm] InsertedNode parameter)
        {
            ElementDAO elementDAO = new ElementDAO();

            String parent = (parameter.parentid.Equals(Element.getRoot().getId()) ? "" : parameter.parentid + ".");

            using (var conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=nasca;Encoding=UTF-8;User Id=postgres;Password=nomura;"))
            {
                conn.Open();

                using (var tran = conn.BeginTransaction())
                {
                    //更新対象とその子エレメントを取得します。
                    Element        target   = elementDAO.selectByID(parent + parameter.id);
                    List <Element> children = target.getChild();

                    //子エレメントとその依存を更新します。
                    foreach (Element child in children)
                    {
                        this.deleteDependency(conn, tran, child.getId());

                        //子エレメントの更新
                        elementDAO.delete(conn, tran, child.getId());
                    }

                    this.deleteDependency(conn, tran, parent + parameter.id);

                    elementDAO.delete(conn, tran, parent + parameter.id);

                    tran.Commit();
                }
            }

            return(JsonConvert.SerializeObject(new { }));
        }
Esempio n. 2
0
 private async Task Update()
 {
     try
     {
         await ElementDAO.UpdateFromAPI(new Progress <int>(percent =>
         {
             if (percent == -1)
             {
                 UpdateProgressBar.IsIndeterminate = true;
                 LabelStatus.Text = "Checking API status";
             }
             else
             {
                 UpdateProgressBar.IsIndeterminate = false;
                 LabelStatus.Text = "Updating cache";
                 UpdateProgressBar.Value = percent;
             }
         }));
     }
     catch (WebException)
     {
         await new ContentDialog
         {
             Title           = "Periodic Table",
             Content         = "Unable to get information from server! Using from cached.",
             CloseButtonText = "Ok"
         }.ShowAsync();
     }
 }
Esempio n. 3
0
        public ActionResult <string> insert([FromForm] InsertedNode parameter)
        {
            ElementDAO elementDAO = new ElementDAO();

            String parent = (parameter.parentid.Equals(Element.getRoot().getId()) ? "" : parameter.parentid + ".");

            using (var conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=nasca;Encoding=UTF-8;User Id=postgres;Password=nomura;"))
            {
                conn.Open();

                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        elementDAO.insert(
                            conn,
                            tran,
                            parent + parameter.id,
                            parameter.name,
                            parameter.type,
                            parameter.remark
                            );

                        this.updateDependencyID(conn, tran, parameter.parentid, parent + parameter.id);
                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                    }
                }
            }

            return(JsonConvert.SerializeObject(new { }));
        }
Esempio n. 4
0
 private async Task Update()
 {
     try
     {
         await ElementDAO.UpdateFromAPI(new Progress <int>(percent =>
         {
             if (percent == -1)
             {
                 UpdateProgressBar.IsIndeterminate = true;
                 LabelStatus.Content = "Checking API status";
             }
             else
             {
                 UpdateProgressBar.IsIndeterminate = false;
                 LabelStatus.Content = "Updating cache";
                 UpdateProgressBar.Value = percent;
             }
         }));
     }
     catch (WebException)
     {
         Modscleo4.WPFUI.MessageBox.Show("Unable to get information from server! Using from cached.", "Periodic Table", MessageBoxButton.OK, MessageBoxImage.Exclamation);
     }
     finally
     {
         new MainWindow().Show();
         Close();
     }
 }
Esempio n. 5
0
        public void Load()
        {
            DataConnector dataConnector = new DataConnector();

            dataConnector.OpenConnection("mySql");

            WorkflowDAO workflowDAO = new WorkflowDAO(dataConnector.MySqlConnection);
            ElementDAO  elementDAO  = new ElementDAO(dataConnector.MySqlConnection);
            RelationDAO relationDAO = new RelationDAO(dataConnector.MySqlConnection);

            dataConnector.CloseConnection();
        }
Esempio n. 6
0
 private async Task Update()
 {
     try
     {
         await ElementDAO.UpdateFromAPI();
     }
     catch (WebException)
     {
         await DisplayAlert("Periodic Table", "Unable to get information from server! Using from cached.", "Ok");
     }
     finally
     {
         Application.Current.MainPage = new MainPage();
     }
 }
Esempio n. 7
0
        private void checkBusinessRulesOnUpdate(Element e)
        {
            Notification notification = new Notification();
            ElementDAO   elementDAO   = DAOFactoryFactory.DAOFactory.GetElementDAO();

            if (e.Sprava != oldSprava || e.Naziv != oldNaziv)
            {
                if (e.Naziv != "" && elementDAO.postojiElement(e.Sprava, e.Naziv))
                {
                    notification.RegisterMessage("Naziv", "Element sa datim nazivom vec postoji.");
                    throw new BusinessException(notification);
                }
            }
            if (e.Sprava != oldSprava || e.EngleskiNaziv != oldEngleskiNaziv)
            {
                if (e.EngleskiNaziv != "" &&
                    elementDAO.postojiElementEng(e.Sprava, e.EngleskiNaziv))
                {
                    notification.RegisterMessage("EngleskiNaziv", "Element sa datim engleskim nazivom vec postoji.");
                    throw new BusinessException(notification);
                }
            }
            if (e.Sprava != oldSprava || e.NazivPoGimnasticaru != oldNazivPoGimnasticaru)
            {
                if (e.NazivPoGimnasticaru != "" &&
                    elementDAO.postojiElementGim(e.Sprava, e.NazivPoGimnasticaru))
                {
                    notification.RegisterMessage("NazivPoGimnasticaru", "Element sa datim nazivom po gimnasticaru vec postoji.");
                    throw new BusinessException(notification);
                }
            }
            if (e.IsTablicniElement)
            {
                if (e.Sprava != oldSprava ||
                    e.Grupa != oldGrupa ||
                    e.Tezina != oldTezina ||
                    e.Broj != oldBroj ||
                    e.PodBroj != oldPodBroj)
                {
                    if (elementDAO.postojiElement(e.Sprava, e.Grupa,
                                                  e.Broj, e.PodBroj))
                    {
                        notification.RegisterMessage("Grupa", "Vec postoji element sa datim brojem za datu spravu i grupu.");
                        throw new BusinessException(notification);
                    }
                }
            }
        }
Esempio n. 8
0
        public void Store()
        {
            DataConnector dataConnector = new DataConnector();

            dataConnector.OpenConnection("mySql");

            WorkflowDAO workflowDAO = new WorkflowDAO(dataConnector.MySqlConnection);
            ElementDAO  elementDAO  = new ElementDAO(dataConnector.MySqlConnection);
            RelationDAO relationDAO = new RelationDAO(dataConnector.MySqlConnection);

            WorkflowDTO workflowDTO = new WorkflowDTO();

            workflowDTO.id   = this.id;
            workflowDTO.name = this.name;
            if (this.startElement != null)
            {
                workflowDTO.startElement = this.startElement.id;
            }
            if (this.finishElement != null)
            {
                workflowDTO.finishElement = this.finishElement.id;
            }
            this.id = (int)workflowDAO.StoreWorkflow(workflowDTO);

            foreach (FlowElement element in elements)
            {
                ElementDTO elementDTO = new ElementDTO();
                elementDTO.id          = element.id;
                elementDTO.owner       = this.id;
                elementDTO.name        = element.name;
                elementDTO.enabled     = element.enabled;
                elementDTO.elementType = element.elementType;

                elementDAO.StoreElement(elementDTO);
            }

            foreach (Relation relation in relations)
            {
                RelationDTO relationDTO = new RelationDTO();
                relationDTO.origin      = relation.origin.id;
                relationDTO.destinarion = relation.destination.id;

                relationDAO.StoreRelation(relationDTO);
            }

            dataConnector.CloseConnection();
        }
Esempio n. 9
0
        /// <summary>
        /// Electronic distribution via API
        /// </summary>
        /// <param name="numberOfElectrons">The number of electrons (or the number of protons)</param>
        /// <returns>Returns the electronic distribution</returns>
        public static List <string> APIElectronicDistribution(uint numberOfElectrons)
        {
            var ret = new List <string>();
            var electronicConfiguration = ElementDAO.Select((int)numberOfElectrons).ElectronicConfiguration;

            while (Regex.Match(electronicConfiguration, @"\[.*\]").Success)
            {
                var e = ElementDAO.Select(Regex.Replace(electronicConfiguration, @"^.*\[(.*)\].*$", @"$1"));
                electronicConfiguration = Regex.Replace(electronicConfiguration, @"(\[(.*)\])", e.ElectronicConfiguration);
            }

            foreach (var s in electronicConfiguration.Split(' '))
            {
                ret.Add(s);
            }

            return(ret);
        }
Esempio n. 10
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            var elements = await ElementDAO.SelectAsync();

            foreach (var element in elements)
            {
                var gridElement = new GridElement
                {
                    AtomicNumber = element.AtomicNumber.ToString(),
                    Symbol       = element.Symbol,
                    BorderBrush  = new SolidColorBrush(Color.FromArgb(element.GroupBlock.Color.A, element.GroupBlock.Color.R, element.GroupBlock.Color.G, element.GroupBlock.Color.B))
                };

                var column = PeriodicTableUtils.GetGroup(element.AtomicNumber);
                var row    = PeriodicTableUtils.GetPeriod(element.AtomicNumber);

                if ((row == 1 && column >= 2) ||
                    (row <= 5 && column > 2))
                {
                    column += rowLock - PeriodicTableUtils.GetPeriodMaxE(row);
                }
                else if (column > 2)
                {
                    if (column < rowLock)
                    {
                        // Lanthanoid/actinoid are at row 8
                        row += 3;
                        column++;
                    }
                    else
                    {
                        // Bring the elements 14 columns back (removed all the lanthanoid/actinoid)
                        column -= 14;
                    }
                }

                Grid.SetRow(gridElement, (int)row - 1);
                Grid.SetColumn(gridElement, (int)column - 1);

                ElementsGrid.Children.Add(gridElement);
            }
        }
Esempio n. 11
0
        protected override async void OnAppearing()
        {
            base.OnAppearing();

            var elements = await ElementDAO.SelectAsync();

            foreach (var element in elements)
            {
                var gridElement = new GridElement()
                {
                    Symbol      = element.Symbol,
                    BorderColor = Color.FromRgba(element.GroupBlock.Color.R, element.GroupBlock.Color.G, element.GroupBlock.Color.B, element.GroupBlock.Color.A)
                };

                var column = PeriodicTableUtils.GetGroup(element.AtomicNumber);
                var row    = PeriodicTableUtils.GetPeriod(element.AtomicNumber);

                if ((row == 1 && column >= 2) || (row <= 5 && column > 2))
                {
                    column += rowLock - PeriodicTableUtils.GetPeriodMaxE(row);
                }
                else if (column > 2)
                {
                    if (column < rowLock)
                    {
                        // Lanthanoid/actinoid are at row 8
                        row += 3;
                        column++;
                    }
                    else
                    {
                        // Bring the elements 14 columns back (removed all the lanthanoid/actinoid)
                        column -= 14;
                    }
                }

                ElementsGrid.Children.Add(gridElement, (int)column - 1, (int)row - 1);
            }
        }
Esempio n. 12
0
        public ActionResult <string> NodeList()
        {
            ElementDAO     dao      = new ElementDAO();
            List <Element> elements = dao.selectAll();

            var nodes = new List <Node>();

            var root = new Node
            {
                id            = Element.getRoot().getId(),
                parent        = "#",
                text          = Element.getRoot().getName(),
                type          = Element.getRoot().getType(),
                remark        = "",
                hasDependency = false
            };

            nodes.Add(root);

            elements.ForEach(element =>
            {
                var node = new Node
                {
                    parent        = element.getParent().getId(),
                    parentText    = element.getParent().getName(),
                    id            = element.getId(),
                    text          = element.getName(),
                    type          = element.getType(),
                    remark        = element.getRemark(),
                    icon          = "./images/" + element.getSvgFile() + ".png",
                    hasDependency = (element.getDependency().Count == 0 && element.getDependencyDependOnMe().Count == 0 ? false : true)
                };

                nodes.Add(node);
            });

            return(JsonConvert.SerializeObject(nodes));
        }
Esempio n. 13
0
        private void checkBusinessRulesOnAdd(Element e)
        {
            // TODO: Nek bude moguce da dva tablicna elementa iste sprave, grupe,
            // tezine i broja, a razlicitog podbroja imaju isti naziv (promeni ovo i
            // kod checkUpdate)

            Notification notification = new Notification();
            ElementDAO   elementDAO   = DAOFactoryFactory.DAOFactory.GetElementDAO();

            if (e.Naziv != "" &&
                elementDAO.postojiElement(e.Sprava, e.Naziv))
            {
                notification.RegisterMessage("Naziv", "Element sa datim nazivom vec postoji.");
                throw new BusinessException(notification);
            }
            if (e.EngleskiNaziv != "" &&
                elementDAO.postojiElementEng(e.Sprava, e.EngleskiNaziv))
            {
                notification.RegisterMessage("EngleskiNaziv", "Element sa datim engleskim nazivom vec postoji.");
                throw new BusinessException(notification);
            }
            if (e.NazivPoGimnasticaru != "" &&
                elementDAO.postojiElementGim(e.Sprava, e.NazivPoGimnasticaru))
            {
                notification.RegisterMessage("NazivPoGimnasticaru", "Element sa datim nazivom po gimnasticaru vec postoji.");
                throw new BusinessException(notification);
            }
            if (e.IsTablicniElement)
            {
                if (elementDAO.postojiElement(e.Sprava, e.Grupa,
                                              e.Broj, e.PodBroj))
                {
                    notification.RegisterMessage("Grupa", "Vec postoji element sa datim brojem za datu spravu i grupu.");
                    throw new BusinessException(notification);
                }
            }
        }
Esempio n. 14
0
        public ActionResult <string> update([FromForm] InsertedNode parameter)
        {
            ElementDAO elementDAO = new ElementDAO();

            String parent = (parameter.parentid.Equals(Element.getRoot().getId()) ? "" : parameter.parentid + ".");

            using (var conn = new NpgsqlConnection("Server=127.0.0.1;Port=5432;Database=nasca;Encoding=UTF-8;User Id=postgres;Password=nomura;"))
            {
                conn.Open();

                using (var tran = conn.BeginTransaction())
                {
                    try
                    {
                        //更新対象とその子エレメントを取得します。
                        Element        target   = elementDAO.selectByID(parameter.originalid);
                        List <Element> children = target.getChild();

                        //ID変更の場合
                        if (parameter.originalid != parent + parameter.id)
                        {
                            var re = new Regex(parameter.originalid);

                            //子エレメントとその依存を更新します。
                            foreach (Element child in children)
                            {
                                this.updateDependencyID(conn, tran, child.getId(), re.Replace(child.getId(), parent + parameter.id, 1));

                                //子エレメントの更新
                                elementDAO.update(
                                    conn,
                                    tran,
                                    child.getId(),
                                    re.Replace(child.getId(), parent + parameter.id, 1),
                                    child.getName(),
                                    child.getType(),
                                    child.getRemark());
                            }
                        }

                        this.updateDependencyID(conn, tran, parameter.originalid, parent + parameter.id);

                        elementDAO.update(
                            conn,
                            tran,
                            parameter.originalid,
                            parent + parameter.id,
                            parameter.name,
                            parameter.type,
                            parameter.remark
                            );

                        tran.Commit();
                    }
                    catch
                    {
                        tran.Rollback();
                    }
                }
            }

            return(JsonConvert.SerializeObject(new { }));
        }
Esempio n. 15
0
        private void LoadElement(string symbol)
        {
            var element = ElementDAO.Select(symbol);

            LoadElementInfo(element);
        }
Esempio n. 16
0
        private void LoadElement(int atomicNumber)
        {
            var element = ElementDAO.Select(atomicNumber);

            LoadElementInfo(element);
        }