Пример #1
0
        /// <summary>
        /// Builds the Key and Value set for the parcel.
        /// </summary>
        public void ParcelDictionaryBuild()
        {
            ///Iterate through each data store
            foreach (string PTable in ParcelTables)
            {

                ///Store table name in local variable
                string TableName = document.GetElementbyId(PTable).Id;

                try
                {

                    List<HtmlNode> x = document.GetElementbyId(PTable).Elements("tr").ToList();

                    ///New data store is triggered when names change.
                    string TableNameCheck = "Set First Name Unique XZY!@#";

                    ///Datatable builder through loops
                    ///The table is stored with a string table name and then the datatable.
                    var DataTableStore = new Dictionary<string, DataTable>();

                    int count = 0;
                    foreach (HtmlNode node in x)
                    {

                        List<HtmlNode> s = node.Elements("td").ToList();
                        //MessageBox.Show(TableName);

                        ///If Html node has 2 elements, then store information as a parcel dictionary key value.
                        if (s.Count == 2)
                        {
                            string ElementKey = s[0].InnerText.Trim();
                            string ElementValue = s[1].InnerText.Trim();

                            ParcelDictionaryKeyValue PDE = new ParcelDictionaryKeyValue(TableName.Replace("kingcounty_gov_cphContent_", "PDE_"), ElementKey, ElementValue);
                            PD.AddKVElement(PDE);
                        }

                        ///If Html node has other than 2 elements, then store information as a table.
                        else
                        {
                            ///Replaces table name prefix with a shorter alternative.
                            string TempName = TableName.Replace("kingcounty_gov_cphContent_", "PDT_");

                            ///Iterator that stores the table names when a new name is encountered.
                            if (String.Equals(TableName, TableNameCheck) != true)
                            {
                                DataTableStore.Add(TempName, new DataTable());
                            }

                            ///Iterate through sub elements in each table.
                            List<HtmlNode> h = node.Elements("th").ToList();

                            foreach (HtmlNode item in h)
                            {

                                DataTableStore[TempName].Columns.Add(item.InnerText.Trim(), typeof(string));
                            }

                            if (count != 0)
                            {
                                StringBuilder ValueListLine = new StringBuilder();

                                List<string> dataElements = new List<string>();
                                foreach (HtmlNode item2 in s)
                                {
                                    ///Trim unused formatting characters from string.
                                    dataElements.Add(item2.InnerText.Trim().Replace("&nbsp;", ""));
                                }

                                DataTableStore[TempName].Rows.Add(dataElements.ToArray());

                            }

                            count = count + 1;
                        }
                        TableNameCheck = TableName;
                    }

                    ///Iterate through the key/value pairs of datatables to transfer data store to the parcel dictionary.
                    foreach (var DT in DataTableStore)
                    {

                        DataTable Temp = new DataTable();

                        ///The key is transferred to the datatable name property.
                        Temp.TableName = DT.Key;
                        ///The value is transferred to the datatable itself.
                        Temp = DT.Value;
                        ///Add the element to the parcel dictionary.
                        PD.AddTBElement(Temp);

                        ///Test to preview parcel table data in datagridview.
                        //Form TempForm = new Form();
                        //DataGridView dataGridView1 = new DataGridView();

                        //dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
                        //dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
                        //dataGridView1.Location = new System.Drawing.Point(0, 0);
                        //dataGridView1.Name = "dataGridView1";
                        //dataGridView1.Size = new System.Drawing.Size(997, 690);
                        //dataGridView1.TabIndex = 0;

                        //TempForm.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                        //TempForm.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                        //TempForm.ClientSize = new System.Drawing.Size(997, 690);
                        //TempForm.Controls.Add(dataGridView1);
                        //TempForm.Name = Temp.TableName;
                        //TempForm.Text = Temp.TableName;

                        //dataGridView1.DataSource = DT.Value;
                        //TempForm.ShowDialog();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Add key/value pair to list and name to hash list.
 /// </summary>
 /// <param name="PDKV"></param>
 public void AddKVElement(ParcelDictionaryKeyValue PDKV)
 {
     ParcelKeyValues.Add(PDKV);
     ParcelKVNames.Add(PDKV.ElementTableId);
 }