Пример #1
0
        private void startTagSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Vertex <ReadingTag> startTag = (Vertex <ReadingTag>)beginningTag.SelectedItem;
                //mainGraph.TagFinder(startTag);
                //createTagGraph(startTag.tagId);
                List <WeightedEdge <ReadingTag> > list = mainGraph.TagFinder(startTag, new List <WeightedEdge <ReadingTag> >(), new List <Vertex <ReadingTag> >(), new List <Vertex <ReadingTag> >(), new List <WeightedEdge <ReadingTag> >());
                Console.WriteLine(list.Count());
                Console.WriteLine(list);
                List <Reading> suggestedReadings = new List <Reading>();
                string         str = DatabaseInterface.databaseConnectionStr;

                using (SqlConnection con = new SqlConnection(str))
                {
                    foreach (WeightedEdge <ReadingTag> edge in list)
                    {
                        Console.WriteLine(edge.ToString());
                        foreach (int id in edge.ReadingIds)
                        {
                            Reading r = DatabaseInterface.getReadings(project.projectId, con, false, id).First();
                            if (r != null && suggestedReadings.Find(x => x.readingId == id) == null)
                            {
                                suggestedReadings.Add(r);
                            }
                        }
                    }
                }
                suggestedReadingsList.DataSource    = suggestedReadings;
                suggestedReadingsList.DisplayMember = "title";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Пример #2
0
        private WeightedGraph <ReadingTag> createTagGraph()
        {
            string str = DatabaseInterface.databaseConnectionStr;
            WeightedGraph <ReadingTag> graph;

            using (SqlConnection con = new SqlConnection(str))
            {
                // Vertex<ReadingTag> startTag = null;
                List <Vertex <ReadingTag> >       vertices = new List <Vertex <ReadingTag> >();
                List <WeightedEdge <ReadingTag> > edges    = new List <WeightedEdge <ReadingTag> >();
                List <ReadingTag> tags = DatabaseInterface.getReadingTags(null, con, false);
                tags = DatabaseInterface.getHighlight_ReadingTags(tags, null, con, false);
                int            numTags  = tags.Count();
                List <TagLink> tagLinks = DatabaseInterface.getReadingLinks(con, false);
                tagLinks.AddRange(DatabaseInterface.getHighlightLinks(con, false));
                //List<List<List<int>>> table = new List<List<List<int>>>();
                List <int>[,] table = new List <int> [numTags, numTags];

                foreach (TagLink l in tagLinks)
                {
                    if (table[l.t1, l.t2] == null)
                    {
                        table[l.t1, l.t2] = new List <int>();
                    }
                    table[l.t1, l.t2].Add(l.rId);
                }

                Dictionary <string, Vertex <ReadingTag> > dict = new Dictionary <string, Vertex <ReadingTag> >();

                foreach (ReadingTag t in tags)
                {
                    Vertex <ReadingTag> v = new Vertex <ReadingTag>(t);
                    if (!dict.ContainsKey(t.tagId.ToString()))
                    {
                        dict.Add(t.tagId.ToString(), v);
                        vertices.Add(v);
                    }
                }

                for (int i = 0; i < tags.Count(); i++)
                {
                    for (int j = 0; j < tags.Count(); j++)
                    {
                        if (table[i, j] != null && table[i, j].Count() > 0)
                        {
                            //TODO: might have error here with readingIds array
                            WeightedEdge <ReadingTag> edge  = new WeightedEdge <ReadingTag>(dict[i.ToString()], dict[j.ToString()], table[i, j].Count());
                            WeightedEdge <ReadingTag> edge2 = new WeightedEdge <ReadingTag>(dict[j.ToString()], dict[i.ToString()], table[i, j].Count());
                            edge.ReadingIds  = table[i, j];
                            edge2.ReadingIds = table[i, j];
                            edges.Add(edge2);
                            edges.Add(edge);
                            dict[i.ToString()].AddEdge(edge);
                            dict[j.ToString()].AddEdge(edge2);
                        }
                    }
                }


                graph = new WeightedGraph <ReadingTag>(vertices, edges);
                beginningTag.DataSource    = graph.vertices;
                beginningTag.DisplayMember = "Value";

                return(graph);
            }
        }
Пример #3
0
 private void newProjectButton_Click(object sender, EventArgs e)
 {
     selectedProject = DatabaseInterface.createProject(newProjectNameTextBox.Text);
     openNewProjectPage();
 }
Пример #4
0
 public override void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     writing.text = writingDoc.Text;
     DatabaseInterface.updateProject(project);
 }
Пример #5
0
 public override void saveProjectToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DatabaseInterface.updateProject(project);
 }