Ejemplo n.º 1
0
        private void addRowButton_Click(object sender, EventArgs e)
        {
            DBRow new_row = table.InputRow();

            table.AddRow(new_row);
            RefreshRowsDataGridView();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns true if all items in a row have the same content
 /// </summary>
 public override bool Equals(object obj)
 {
     //Check for null and compare run-time types.
     if ((obj == null) || !this.GetType().Equals(obj.GetType()))
     {
         return(false);
     }
     else
     {
         DBRow other  = (DBRow)obj;
         var   ritems = other.GetElements();
         if (items.Count != ritems.Count)
         {
             return(false);
         }
         // Check that all element have the same values
         for (int i = 0; i < items.Count; i++)
         {
             if (!items[i].Equals(ritems[i]))
             {
                 return(false);
             }
         }
         // All checks passed, rows are equal
         return(true);
     }
 }
Ejemplo n.º 3
0
        private void editRowButton_Click(object sender, EventArgs e)
        {
            DBRow new_row            = table.InputRow();
            int   selected_row_index = rowsDataGridView.SelectedRows[0].Index;

            table.ReplaceRow(new_row, selected_row_index);
            RefreshRowsDataGridView();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Prompts user to enter all elements to form a DBRow. Returns this DBRow
        /// </summary>
        public DBRow InputRow()
        {
            DBRow new_row = new DBRow();

            foreach (DBField field in fields)
            {
                new_row.InputElement(field);
            }
            return(new_row);
        }
Ejemplo n.º 5
0
 public void ReplaceRow(DBRow row, int index)
 {
     rows[index] = row;
 }
Ejemplo n.º 6
0
 public void AddRow(DBRow row)
 {
     rows.Add(row);
 }
Ejemplo n.º 7
0
        public void JoinTables(DBTable leftTable, int leftFieldIndex,
                               DBTable rightTable, int rightFieldIndex)
        {
            string joinedTableName = String.Format("{0}-{1}-Join",
                                                   leftTable.GetName(),
                                                   rightTable.GetName());
            DBTable joinedTable = new DBTable(joinedTableName);

            // Build a joined table
            foreach (DBRow lrow in leftTable.GetRows())
            {
                // For each row in leftTable, get value in key field
                Element keyValue = lrow.GetElement(leftFieldIndex);
                // find rows in rightTable that have the same value in key field
                List <DBRow> rightRows = new List <DBRow>();
                foreach (DBRow rrow in rightTable.GetRows())
                {
                    Element rvalue = rrow.GetElement(rightFieldIndex);
                    // Attention! Compare types by their string representation
                    if (keyValue.ToString().Equals(rvalue.ToString()))
                    {
                        rightRows.Add(rrow);
                    }
                }
                // concatenate leftRow with all rightRows
                foreach (DBRow rrow in rightRows)
                {
                    DBRow conc_row = new DBRow();
                    // Add all fields from left table
                    foreach (Element el in lrow.GetElements())
                    {
                        conc_row.AddElement(el.Clone());
                    }
                    // Add all fields from right table, except key field
                    for (int i = 0; i < rrow.GetElements().Count; i++)
                    {
                        if (i != rightFieldIndex)
                        {
                            conc_row.AddElement(rrow.GetElement(i).Clone());
                        }
                    }
                    joinedTable.AddRow(conc_row);
                }
            }
            // Concatenate fields
            foreach (DBField field in leftTable.GetFields())
            {
                joinedTable.AddField(field.Clone()); // left table
            }
            List <DBField> rfields = rightTable.GetFields();

            for (int i = 0; i < rfields.Count; i++)
            {
                if (i != rightFieldIndex)
                {
                    joinedTable.AddField(rfields[i].Clone());
                }
            }
            // Add new table to database
            tables.Add(joinedTable);
        }