Inheritance: INotifyPropertyChanging, INotifyPropertyChanged
Exemple #1
0
 partial void DeleteSubChange(SubChange instance);
Exemple #2
0
 partial void UpdateSubChange(SubChange instance);
Exemple #3
0
 partial void InsertSubChange(SubChange instance);
Exemple #4
0
 private void detach_SubChanges(SubChange entity)
 {
     this.SendPropertyChanging();
     entity.LawChange = null;
 }
Exemple #5
0
 private void attach_SubChanges(SubChange entity)
 {
     this.SendPropertyChanging();
     entity.LawChange = this;
 }
        public static void DoNonChangeLawTexts(string lawtext, LawStage stage, Law law, DBDataContext db)
        {
            var doc = GetDoc(lawtext).DocumentNode;

            var ps = doc.SelectNodes("//p").OfType<HtmlNode>();
            var gps = ps.Where(p => p.Attributes["class"] != null &&
                (
                    p.Attributes["class"].Value == "Paragraf" ||
                    p.Attributes["class"].Value == "CentreretParagraf" ||
                    p.Attributes["class"].Value == "Stk2" ||
                    p.Attributes["class"].Value == "AendringMedNummer" ||
                    p.Attributes["class"].Value == "KapitelOverskrift2"
                ));

            Paragraph currpar = null;
            int currsectionsnr = 1;
            int chaptercounter = 1;
            LawChange currchange = null;
            LawChapter currchap = null;
            foreach (var p in gps)
            {
                if (p.Attributes["class"].Value == "Paragraf" ||
                    p.Attributes["class"].Value == "CentreretParagraf")
                {
                    string numbertext;
                    if (p.Attributes["class"].Value == "Paragraf")
                    {
                        var node = p.SelectSingleNode("./span");
                        if (node != null)
                        {
                            numbertext = node.InnerText;
                        }
                        else
                        {
                            // TODO, bug in this one
                            // http://www.ft.dk/dokumenter/tingdok.aspx?/samling/20072/lovforslag/L20/som_fremsat.htm
                            continue;
                        }
                    }
                    else
                    {
                        numbertext = p.InnerText;
                    }

                    if (numbertext.StartsWith("»"))
                    {
                        // this is actually a quoted paragraph, make it the first subchange
                        // TODO, do the above
                        continue;
                    }

                    numbertext = TrimPar(numbertext);
                    int num;
                    string letter = null;
                    bool succ = int.TryParse(numbertext, out num);
                    if (!succ)
                    {
                        bool succ2 = int.TryParse(numbertext.Split(new char[] { ' ' })[0], out num);
                        if (succ2)
                        {
                            letter = numbertext.Split(new char[] { ' ' })[1];
                        }
                        else
                        {
                            // TODO, big missing feature in here
                            continue;
                            // ok, this is a borky change paragraph
                            // like this one http://ft.dk/Samling/20072/lovforslag/L20/som_fremsat.htm
                            // create a change and stick it on above par
                            //currsectionsnr = 1;
                            //lawchange c = new lawchange()
                            //{

                            //};
                            //currchange = c;
                        }
                    }
                    Paragraph par =
                        new Paragraph()
                        {
                            Law = law,
                            Number = num,
                            Stage = (LawStage)stage,
                            LawChapter = currchap,
                            Letter = letter
                        };

                    if (p.NextSibling != null &&
                        p.NextSibling.NextSibling != null &&
                        (
                            (p.NextSibling.NextSibling.Attributes["class"] != null &&
                            p.NextSibling.NextSibling.Attributes["class"].Value == "AendringMedNummer")
                        ||
                            (p.NextSibling.NextSibling.NextSibling != null &&
                            p.NextSibling.NextSibling.NextSibling.NextSibling != null &&
                            p.NextSibling.NextSibling.NextSibling.NextSibling.Attributes["class"] != null &&
                            p.NextSibling.NextSibling.NextSibling.NextSibling.Attributes["class"].Value == "AendringMedNummer")
                        )
                        )
                    {
                        // go into changemode
                        par.IsChange = true;
                        // this text is in the paragraph, instead of the first stk
                        if (p.ChildNodes.Count < 3)
                        {
                            par.ChangeText = p.NextSibling.NextSibling.InnerText.Kapow();
                        }
                        else
                        {
                            par.ChangeText = p.ChildNodes[2].InnerText.Trim().Kapow();
                        }
                    }
                    else
                    {
                        par.IsChange = false;
                        currchange = null; // reset the f****r
                        // the paragraph also contains the text of stk 1

                        string sectiontxt = null;
                        if (p.ChildNodes.Count < 2)
                        {
                            // this suggest a paragraph with no initial unnumbered section
                            // we set sectionnr to zero to get the right numbers
                            // there's an example in paragraf 9 here
                            // http://ft.dk/Samling/20072/lovforslag/L175/som_fremsat.htm
                            currsectionsnr = 0;
                            currpar = par;
                            db.Paragraphs.InsertOnSubmit(par);
                            continue;
                            //sectiontxt = p.ChildNodes[1].InnerText.Trim();
                        }
                        else if (p.ChildNodes.Count < 3)
                        {
                            sectiontxt = p.ChildNodes[1].InnerText.Trim();
                        }
                        else
                        {
                            sectiontxt = p.ChildNodes[2].InnerText.Trim(); // to get the pure text
                        }
                        currsectionsnr = 1;

                        if (par == null)
                            throw new ArgumentException();

                        Section s = new Section()
                        {
                            Paragraph = par,
                            Number = currsectionsnr,
                            Text = sectiontxt.Kapow()
                        };

                        CheckforList(p, s);
                        db.Sections.InsertOnSubmit(s);
                    }
                    currpar = par;
                    db.Paragraphs.InsertOnSubmit(par);

                }
                // check that we are not in change mode
                else if (p.Attributes["class"].Value == "Stk2")
                {
                    //string numbertext = p.SelectSingleNode("./span").InnerText;
                    //numbertext = numbertext.Trim(new char[] { 'S', 't', 'k', '.', ' ' }).Trim();
                    //int num = int.Parse(numbertext);

                    string sectiontxt = GetSectionText(p);

                    if (currchange != null)
                    {
                        currsectionsnr++;
                        var sub = new SubChange()
                        {
                            Number = currsectionsnr,
                            Text = sectiontxt.Kapow(),
                            LawChange = currchange
                        };

                        db.SubChanges.InsertOnSubmit(sub);
                    }
                    else
                    {
                        currsectionsnr++;

                        if (currpar == null)
                            throw new ArgumentException();

                        var s = new Section()
                        {
                            Text = sectiontxt.Kapow(),
                            Number = currsectionsnr,
                            Paragraph = currpar
                        };

                        db.Sections.InsertOnSubmit(s);
                    }
                }
                else if (p.Attributes["class"].Value == "AendringMedNummer")
                {
                    string numbertext = p.SelectSingleNode("./span").InnerText;
                    numbertext = numbertext.Trim(new char[] { '.' }).Trim();
                    int num;
                    var succ = int.TryParse(numbertext, out num);
                    if (succ)
                    {
                        if (currpar == null)
                            throw new ArgumentException();

                        var change = new LawChange()
                        {
                            // interesting formatting in here
                            //ChangeText = p.InnerHtml,
                            Number = num,
                            Paragraph = currpar,
                            NoformChangeText = p.InnerText.Kapow()
                        };

                        db.LawChanges.InsertOnSubmit(change);
                        currchange = change;
                    }
                }
                else if (p.Attributes["class"].Value == "KapitelOverskrift2")
                {
                    var chap = new LawChapter()
                    {
                        //Law = l,
                        Number = chaptercounter++,
                        Titel = p.InnerText,
                        Stage = (byte)stage

                    };
                    db.LawChapters.InsertOnSubmit(chap);
                    currchap = chap;
                }
                else
                {
                    // unrelated paragraph, do nothing
                }
            }
            //}
        }