public void loadDatabaseTable(EIBPanel panelControl) { this.panelControl = panelControl; foreach (Control control in panelControl.Controls) { //Give Handle to XML Node to new Frame Element so it can write its own child string eibCOntrolInterfaceName = (typeof(IEIBControl)).Name; if (control.GetType().GetInterface(eibCOntrolInterfaceName) != null) { if (control is EIBTable) { EIBTable eibTable = (EIBTable)control; DataTable dataTable = eibTable.TableData; if (dataTable != null) { this.eibRelation1.firstTableName.Items.Add(dataTable.TableName); this.eibRelation1.secondTableName.Items.Add(dataTable.TableName); } else { dataTable = databaseDataSet.Tables[eibTable.tableName.Text]; if (dataTable != null) { this.eibRelation1.firstTableName.Items.Add(dataTable.TableName); this.eibRelation1.secondTableName.Items.Add(dataTable.TableName); } } } } } }
//Retrieves a Line object having a mark private Line getLineByMark(EIBTable m) { foreach (Line l in ((BaseWindow)this.baseFrame.Parent).Lines) { if (l.mark1 == m || l.mark2 == m) { return(l); } }//Never happens :D throw new System.Exception("No line found"); }
private void Mark_MouseMove(object sender, MouseEventArgs e) { if (isSelected) { EIBTable mc1 = (EIBTable)sender; Line l = getLineByMark(mc1); Point p = new Point(e.X - _X + mc1.Left, e.Y - _Y + mc1.Top); mc1.Location = p; Redraw(l, p); } }
internal static DataTable CreateSchema(DataSet DataSetNew, string tableName, EIBTable eibTable) { // Create a Schema DataColumn DataColumnNew; string strName, strType; Type dataType; DataTable DataTableNew = new DataTable(tableName); foreach (ListViewItem lvItem in eibTable.lvDatabase.Items) { strName = lvItem.Text; strType = lvItem.SubItems[1].Text; //Append System. to make them .net types dataType = Type.GetType("System." + strType); DataColumnNew = new DataColumn(strName, dataType); DataColumnNew.AutoIncrement = (lvItem.SubItems[2].Text == "Yes"); DataTableNew.Columns.Add(DataColumnNew); } DataSetNew.Tables.Add(DataTableNew); return(DataTableNew); }
public static object CreateControl(string ctrlName, string partialName) { try { Control ctrl = null; //ToolStripMenuItem menu; //ToolStripButton menuItem; switch (ctrlName) { case "EIBButton": ctrl = new EIBButton(); break; case "EIBApplet": ctrl = new EIBApplet(); break; case "EIBLattice": ctrl = new EIBLattice(); break; case "EIBSchedular": ctrl = new EIBSchedular(); break; case "EIBDatePicker": ctrl = new EIBDatePicker(); break; case "EIBTime": ctrl = new EIBTime(); break; case "EIBCheckbox": ctrl = new EIBCheckbox(); break; case "EIBCombobox": ctrl = new EIBCombobox(); break; case "EIBLabel": ctrl = new EIBLabel(); break; case "EIBLine": ctrl = new EIBLine(); break; case "EIBPanel": ctrl = new EIBPanel(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBJasper": ctrl = new EIBJasper(); break; case "EIBRadioGroup": ctrl = new EIBRadioGroup(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBPicture": ctrl = new EIBPicture(); break; case "EIBRadioButton": ctrl = new EIBRadioButton(); break; case "EIBTabControl": ctrl = new EIBTabControl(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBTabPage": ctrl = new EIBTabPage(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBSearch": ctrl = new EIBSearch(); break; case "EIBListbox": ctrl = new EIBListbox(); break; case "EIBGrid": ctrl = new EIBGrid(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBTable": ctrl = new EIBTable(); break; case "EIBRelation": ctrl = new EIBRelation(); break; case "EIBTextBox": ctrl = new EIBTextBox(); break; case "EIBTreeView": ctrl = new EIBTreeView(); break; case "EIBMenuBar": ctrl = new EIBMenuBar(false); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBNode": ctrl = new EIBNode(); break; case "EIBNodeRelation": ctrl = new EIBNodeRelation(); break; case "EIBColumn": ctrl = new EIBColumn(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBScrollableRow": ctrl = new EIBScrollableRow(); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBBrowse": ctrl = new EIBBrowse(); break; case "EIBVMenuBar": ctrl = new EIBVMenuBar(false); DragDropHandler.RegisterControl(ctrl, true, true); break; case "EIBMenu": return(new EIBMenu()); case "EIBMenuItem": return(new EIBMenuItem()); /* * case "EIBTreeNode": * ctrl = new EIBTreeNode(); * break; */ default: Assembly controlAsm = Assembly.LoadWithPartialName(partialName); Type controlType = controlAsm.GetType(partialName + "." + ctrlName); ctrl = (Control)Activator.CreateInstance(controlType); break; } return(ctrl); } catch (Exception ex) { System.Diagnostics.Trace.WriteLine("create control failed:" + ex.Message); return(new Control()); } }
//Deserialize individual base windows and there child control public static void DeserializeWindowXML(string fileName, Control baseFrame, XmlNode parentXMLNode) { DataSet dataset = new DataSet(); int nextTop = 0, nextLeft = 0; int maxHeight = 0, maxWidth = 0; int ParentWidth; Dictionary <string, EIBTable> listTable = new Dictionary <string, EIBTable>(); try { ParentWidth = baseFrame.Width; // disabling re-drawing of treeview till all nodes are added baseFrame.SuspendLayout(); fileName = fileName + ".xml"; string datasetName = System.IO.Path.GetFileNameWithoutExtension(fileName); List <string> M2MList = new List <string>(); dataset = DatabaseXMLServices.ReadSchema(datasetName, fileName, M2MList); //dataset.ReadXml(fileName); baseFrame.Controls.Clear(); ((BaseWindow)baseFrame.Parent).DatabaseDataSet = dataset; foreach (DataTable table in dataset.Tables) { EIBTable.counter++; EIBTable newNode = new EIBTable(); newNode.TableData = table; newNode.Height = 160; newNode.Width = 200; newNode.DatabaseDataSet = dataset; newNode.Name = table.TableName; listTable.Add(newNode.Name, newNode); newNode.ControlName = table.TableName; newNode.tableName.Text = table.TableName; if (M2MList.Contains(table.TableName)) { newNode.M2M = true; } else { newNode.M2M = false; } newNode.Top = nextTop; newNode.Left = nextLeft; UpdateControlProperties(newNode); newNode.AutoSize = false; baseFrame.Controls.Add(newNode); if (newNode.Height > maxHeight) { maxHeight = newNode.Height; } if (newNode.Width > maxWidth) { maxWidth = newNode.Width; } if ((nextLeft + newNode.Width + maxWidth) >= ParentWidth) { nextTop += maxHeight; nextLeft = 0; } else { nextLeft += newNode.Width; } foreach (DataColumn column in table.Columns) { ListViewItem lvItem = new ListViewItem(column.ColumnName); if (column.DataType.Name == typeof(string).Name) { int iCap; bool isVarChar = Int32.TryParse(column.Caption, out iCap); if (isVarChar) { lvItem.SubItems.Add(column.DataType.Name); } else { lvItem.SubItems.Add(Designer.Database.DatabaseConstants.LongTextType); } } else { lvItem.SubItems.Add(column.DataType.Name); } string autoIncrement = null; if (column.AutoIncrement) { autoIncrement = "Yes"; } else { autoIncrement = "No"; } lvItem.SubItems.Add(autoIncrement); string uniqueKey = null; if (column.Unique) { uniqueKey = "Yes"; } else { uniqueKey = "No"; } lvItem.SubItems.Add(uniqueKey); int iCaption; if (column.Caption != null && (!column.Caption.Trim().Equals("")) && Int32.TryParse(column.Caption, out iCaption)) { lvItem.SubItems.Add(column.Caption); } else { lvItem.SubItems.Add(""); } if (column.Unique) { lvItem.SubItems.Add("Not Null"); } else { lvItem.SubItems.Add((column.AllowDBNull ? "Null" : "Not Null")); } newNode.lvDatabase.Items.Add(lvItem); } } foreach (DataRelation relation in dataset.Relations) { EIBTableConnector tableConnector = new EIBTableConnector(); tableConnector.InitiateSettings((EIBPanel)baseFrame); tableConnector.Mark1 = (EIBTable)listTable[relation.ParentTable.TableName]; tableConnector.Mark2 = (EIBTable)listTable[relation.ChildTable.TableName]; tableConnector.createLine(); baseFrame.Controls.Add(tableConnector); } } catch (FileNotFoundException) { MessageBox.Show("Basewindow.xml not Found"); } catch (XmlException) { MessageBox.Show("DataPattern xml is changed."); } finally { // enabling redrawing of treeview after all nodes are added baseFrame.ResumeLayout(); baseFrame.Invalidate(); } }
private void deletebutton_Click(object sender, EventArgs e) { bool isAnySelected = false; try { errorLabel.Text = ""; if (currentBaseWindow != null) { if (currentBaseWindow.TypeOfWindow.Equals(FormDesignerConstants.DataPattern)) { if (currentBaseWindow.CurrentControl != null) { if (currentBaseWindow.CurrentControl[0] is EIBTable && currentBaseWindow.CurrentControl.Count == 1) { currentDataSet = currentBaseWindow.DatabaseDataSet; EIBTable eibTable = (EIBTable)currentBaseWindow.CurrentControl[0]; DataTable currentTable = currentDataSet.Tables[eibTable.tableName.Text]; if (foreignKeyList.SelectedItem != null) { isAnySelected = true; if (!foreignKeyList.SelectedItem.ToString().Trim().Equals("")) { string PkeyTable = ((ForeignKeyConstraint)currentTable.Constraints[foreignKeyList.SelectedItem.ToString()]).RelatedTable.TableName; //currentTable.Constraints[foreignKeyList.SelectedItem.ToString()].Table currentTable.Constraints.Remove(foreignKeyList.SelectedItem.ToString().Trim()); currentTable.ParentRelations.Remove(foreignKeyList.SelectedItem.ToString()); if (parentRelations.SelectedItem != null) { parentRelations.SelectedIndex = 0; } EIBTableConnectorBase connectorDel = null; foreach (EIBTableConnectorBase connectorBase in eibTable.tableConnectorList) { Control connectorControl = ((BaseWindow)currentBaseWindow).baseFrame.Controls[connectorBase.ControlName]; EIBTableConnector tableConnector = (EIBTableConnector)connectorControl; if (tableConnector != null && connectorBase.Mark1.tableName.Text == PkeyTable && connectorBase.Mark2.tableName.Text == currentTable.TableName) { connectorDel = connectorBase; //tableConnector.Redraw(-1 ); EIBFormDesigner.Database.Table.Line line = tableConnector.line; line.isDeleted = true; if (((BaseWindow)currentBaseWindow).Lines.Contains(line)) { ((BaseWindow)currentBaseWindow).Lines.Remove(line); } tableConnector.EraseLine(line); ((BaseWindow)currentBaseWindow).baseFrame.Controls.Remove(connectorControl); } } if (connectorDel != null) { eibTable.tableConnectorList.Remove(connectorDel); connectorDel.mark1.tableConnectorList.Remove(connectorDel); } } } if (uniqueKeyList.SelectedItem != null) { isAnySelected = true; if (!uniqueKeyList.SelectedItem.ToString().Trim().Equals("")) { currentTable.Constraints.Remove(uniqueKeyList.SelectedItem.ToString().Trim()); } } if (parentRelations.SelectedItem != null && isAnySelected == false) { isAnySelected = true; if (!parentRelations.SelectedItem.ToString().Trim().Equals("")) { if (currentTable.ParentRelations.Contains(parentRelations.SelectedItem.ToString().Trim())) { string PkeyTable = currentTable.ParentRelations[parentRelations.SelectedItem.ToString()].ParentTable.TableName; currentTable.ParentRelations.Remove(parentRelations.SelectedItem.ToString().Trim()); if (currentTable.Constraints.Contains(parentRelations.SelectedItem.ToString())) { currentTable.Constraints.Remove(parentRelations.SelectedItem.ToString()); } EIBTableConnectorBase connectorDel = null; foreach (EIBTableConnectorBase connectorBase in eibTable.tableConnectorList) { Control connectorControl = ((BaseWindow)currentBaseWindow).baseFrame.Controls[connectorBase.ControlName]; EIBTableConnector tableConnector = (EIBTableConnector)connectorControl; if (tableConnector != null && connectorBase.Mark1.tableName.Text == PkeyTable && connectorBase.Mark2.tableName.Text == currentTable.TableName) { //tableConnector.Redraw(-1 ); connectorDel = connectorBase; EIBFormDesigner.Database.Table.Line line = tableConnector.line; line.isDeleted = true; if (((BaseWindow)currentBaseWindow).Lines.Contains(line)) { ((BaseWindow)currentBaseWindow).Lines.Remove(line); } tableConnector.EraseLine(line); ((BaseWindow)currentBaseWindow).baseFrame.Controls.Remove(connectorControl); } } if (connectorDel != null) { eibTable.tableConnectorList.Remove(connectorDel); connectorDel.mark1.tableConnectorList.Remove(connectorDel); } } } } if (childRelations.SelectedItem != null) { isAnySelected = true; if (!childRelations.SelectedItem.ToString().Trim().Equals("")) { string CKeyTableName = currentTable.ChildRelations[childRelations.SelectedItem.ToString()].ChildTable.TableName; currentTable.ChildRelations[childRelations.SelectedItem.ToString()].ChildTable.Constraints.Remove(childRelations.SelectedItem.ToString()); currentTable.ChildRelations.Remove(childRelations.SelectedItem.ToString().Trim()); EIBTableConnectorBase connectorDel = null; foreach (EIBTableConnectorBase connectorBase in eibTable.tableConnectorList) { Control connectorControl = ((BaseWindow)currentBaseWindow).baseFrame.Controls[connectorBase.ControlName]; EIBTableConnector tableConnector = (EIBTableConnector)connectorControl; if (tableConnector != null && CKeyTableName == connectorBase.Mark2.tableName.Text && currentTable.TableName == connectorBase.Mark1.tableName.Text) { //tableConnector.Redraw(-1 ); connectorDel = connectorBase; EIBFormDesigner.Database.Table.Line line = tableConnector.line; line.isDeleted = true; if (((BaseWindow)currentBaseWindow).Lines.Contains(line)) { ((BaseWindow)currentBaseWindow).Lines.Remove(line); } tableConnector.EraseLine(line); ((BaseWindow)currentBaseWindow).baseFrame.Controls.Remove(connectorControl); } } if (connectorDel != null) { eibTable.tableConnectorList.Remove(connectorDel); connectorDel.mark2.tableConnectorList.Remove(connectorDel); } } } } } } } } catch (Exception ex) { errorLabel.Text = ex.Message; } finally { TableSettings_Load(null, null); if (!isAnySelected) { errorLabel.Text += "\n" + "Please select a Constraint or relation to delete."; } //this.Close(); } }
private void TableSettings_Load(object sender, EventArgs e) { try { if (currentBaseWindow != null) { if (currentBaseWindow.TypeOfWindow.Equals(FormDesignerConstants.DataPattern)) { if (currentBaseWindow.CurrentControl != null && currentBaseWindow.CurrentControl.Count == 1) { if (currentBaseWindow.CurrentControl[0] is EIBTable) { childRelations.Items.Clear(); parentRelations.Items.Clear(); uniqueKeyList.Items.Clear(); foreignKeyList.Items.Clear(); childRelations.Text = ""; parentRelations.Text = ""; uniqueKeyList.Text = ""; foreignKeyList.Text = ""; currentDataSet = currentBaseWindow.DatabaseDataSet; EIBTable eibTable = (EIBTable)currentBaseWindow.CurrentControl[0]; DataTable currentTable = currentDataSet.Tables[eibTable.tableName.Text]; ConstraintCollection consRelation = currentTable.Constraints; foreach (Constraint constraint in consRelation) { //remove constraint if (constraint is ForeignKeyConstraint) { ForeignKeyConstraint uniqueCS = (ForeignKeyConstraint)constraint; foreignKeyList.Items.Add(uniqueCS.ConstraintName); } } consRelation = currentTable.Constraints; foreach (Constraint constraint in consRelation) { //remove constraint if (constraint is UniqueConstraint) { UniqueConstraint uniqueCS = (UniqueConstraint)constraint; // Get the Columns as an array. uniqueKeyList.Items.Add(uniqueCS.ConstraintName); } } DataRelationCollection relationCOllection = null; relationCOllection = currentTable.ParentRelations; foreach (DataRelation relation in relationCOllection) { parentRelations.Items.Add(relation.RelationName); } relationCOllection = currentTable.ChildRelations; foreach (DataRelation relation in relationCOllection) { childRelations.Items.Add(relation.RelationName); } this.tableName.Text = currentTable.TableName; } } } } } catch (Exception ex) { errorLabel.Text = ex.Message; } }
public void AssociateMarkUpandDown(EIBTable table) { table.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Mark_MouseUp); table.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Mark_MouseDown); }