public static Boolean IsInherited(FzSchemeEntity scheme, List<FzRelationEntity> relations) { if (scheme.Attributes.Count > 0) { return FzSchemeDAL.IsInherited(scheme, relations); } return false; }
public static Boolean IsInherited(FzSchemeEntity scheme, List<FzRelationEntity> relations) { try { foreach (FzRelationEntity relation in relations) { if (scheme.Equals(relation.Scheme)) { return true; //break; } } } catch { } return false; }
public bool OpenFuzzyDatabase(FdbEntity fdb) { try { SqliteConnection connection = new SqliteConnection(fdb.ConnString); DataSet ds = new DataSet(); ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemScheme", "system_scheme"));//Table [0] ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemRelation", "system_relation"));//Table [1] ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemAttribute", "system_attribute"));//Table [2] ds.Tables.Add(connection.GetDataTable("SELECT * FROM SystemQuery", "system_query"));//Table [3] ///Load Schemes//////////////////////////////////////////////////////////////////////////////////////// foreach (DataRow row in ds.Tables["system_scheme"].Rows) { String schemeName = row[1].ToString(); FzSchemeEntity tmpScheme = new FzSchemeEntity(schemeName); DataTable tmpDt = new DataTable(); tmpDt = connection.GetDataTable("SELECT * FROM SystemAttribute Where SchemeID=" + Convert.ToInt16(row[0])); if (tmpDt != null) { foreach (DataRow item in tmpDt.Rows) { Boolean primaryKey = Convert.ToBoolean(item[1]); String attributeName = Convert.ToString(item[2]); String typeName = Convert.ToString(item[3]); String domain = Convert.ToString(item[4]); String description = Convert.ToString(item[5]); FzDataTypeEntity tmpDataType = new FzDataTypeEntity(typeName, domain); FzAttributeEntity tmpAttribute = new FzAttributeEntity(primaryKey, attributeName, tmpDataType, description); tmpScheme.Attributes.Add(tmpAttribute); } fdb.Schemes.Add(tmpScheme); } } ///Load Relations////////////////////////////////////////////////////////////////////////////////////////// foreach (DataRow row in ds.Tables["system_relation"].Rows) { String relationName = row[1].ToString(); int schemeID = Convert.ToInt16(row[2]);//To get scheme is referenced String schemeName = connection.GetValueField("SELECT SchemeName FROM SystemScheme WHERE ID=" + schemeID).ToString(); DataTable tmpDt = new DataTable(); tmpDt = connection.GetDataTable("SELECT * FROM " + relationName); FzRelationEntity tmpRelation = new FzRelationEntity(relationName);//Relation only content relation name, but scheme referenced and list tuples is null tmpRelation.Scheme = FzSchemeDAL.GetSchemeByName(schemeName, fdb);//Assign scheme referenced to relation, but tuples is null int nColumns = tmpRelation.Scheme.Attributes.Count;//Get number columns of per row if (tmpDt != null)// { foreach (DataRow tupleRow in tmpDt.Rows) { List<Object> objs = new List<object>(); for (int i = 0; i < nColumns; i++)//Add values on per row from tupleRow[i] { //values += tupleRow[i].ToString(); objs.Add(tupleRow[i]); } FzTupleEntity tmpTuple = new FzTupleEntity() { ValuesOnPerRow = objs }; tmpRelation.Tuples.Add(tmpTuple); } } fdb.Relations.Add(tmpRelation); } ///Load Queries//////////////////////////////////////////////////////////////////////////////////////////// foreach (DataRow row in ds.Tables["system_query"].Rows) { FzQueryEntity tmpQuery = new FzQueryEntity(row[1].ToString(), row[2].ToString()); fdb.Queries.Add(tmpQuery); } return true; } catch (SQLiteException ex) { throw new Exception("ERROR:\n" + ex.Message); //return false; } }
public FzRelationEntity(FzRelationEntity old) { this._relationName = old._relationName; this._scheme = old._scheme; this._tuples = old._tuples; }
public FzRelationEntity(String relationName) { this._relationName = relationName; this._scheme = new FzSchemeEntity(); this._tuples = new List<FzTupleEntity>(); }
private List<FzTupleEntity> _tuples; //List of tuples #endregion Fields #region Constructors public FzRelationEntity() { this._relationName = String.Empty; this._scheme = new FzSchemeEntity(); this._tuples = new List<FzTupleEntity>(); }
private void OpenScheme(FzSchemeEntity currentScheme) { //is not contented any attributes, need to add some attributes if (currentScheme.Attributes.Count == 0) { AddRowDefault(); MessageBox.Show("There are no attribute in this scheme, let create some attributes!"); xtraTabDatabase.TabPages[0].Text = "Create Attribute to Scheme " + currentScheme.SchemeName; xtraTabDatabase.SelectedTabPage = xtraTabDatabase.TabPages[0]; UnsetReadOnlyGridView(); } else//is contented, show text and attributes { xtraTabDatabase.TabPages[0].Text = "Scheme " + currentScheme.SchemeName; xtraTabDatabase.SelectedTabPage = xtraTabDatabase.TabPages[0]; if (FzSchemeBLL.IsInherited(currentScheme, fdbEntity.Relations)) { SetReadOnlyGridView();//To prevent add attributes to current scheme } else UnsetReadOnlyGridView(); ///Finally, show list attributes ShowAttribute(); } }
private void SaveScheme() { try { if (!CheckSchemeData()) return; ///Current scheme is null that mean you dont open any schemes (the GridView is empty) ///Save new scheme OR save attributes to an existed scheme ///Save new scheme: Save scheme name and list attributes ///Save to an existed scheme: Update list attributes (if it is not inherited) if (AllowSavingNewScheme()) { DBValues.schemesName = FzSchemeBLL.GetListSchemeName(fdbEntity); frmSaveScheme frm = new frmSaveScheme(); frm.ShowDialog(); if (frm.SchemeName != String.Empty) { newScheme = FzSchemeBLL.GetSchemeByName(frm.SchemeName, fdbEntity); if (newScheme == null)///Mean the scheme doesn't exist in the database. Saving scheme name { AddSchemeNode(frm.SchemeName);//Add scheme name to tree node and database } currentScheme = newScheme; SaveCurrentScheme(frm.SchemeName);///Clear all attributes and update } } ///This is exact "currentScheme" ///Save current scheme opened on GridView ///Check the inheritance (checked in SaveCurrentScheme()) else { String schemeName = currentScheme.SchemeName; SaveCurrentScheme(schemeName); } } catch (Exception ex) { MessageBox.Show("ERROR:\n" + ex.Message); } }
private void AddSchemeNode(String schemeName) { newScheme = new FzSchemeEntity(schemeName); fdbEntity.Schemes.Add(newScheme); TreeNode tempNode = new TreeNode(); tempNode.Name = schemeName; tempNode.Text = schemeName; tempNode.ToolTipText = "Scheme " + schemeName; tempNode.ContextMenuStrip = ContextMenu_SchemaNode; tempNode.ImageIndex = schemeImageTree.selectedState; tempNode.SelectedImageIndex = schemeImageTree.unselectedState; childSchemeNode.Nodes.Add(tempNode); }
public void ResetObject() { fdbEntity = null; currentScheme = newScheme = null; //currentRelation = NewRelation = RenamedRelation = null; //CurrentQuery = NewQuery = RenamedQuery = null; parentFdbNode = childSchemeNode = childRelationNode = childQueryNode = childCurrentNode = childNewNode = null; }
/// <summary> /// Delete tree node on treeList and also delete Object in db /// </summary> private void DeleteTreeNode(String deleteNodeName, FzSchemeEntity schemeEntity, FzRelationEntity relationEntity, FzQueryEntity queryEntity) { if (schemeEntity != null) { TreeNode deletedNode = childSchemeNode.Nodes[deleteNodeName]; deletedNode.Remove(); fdbEntity.Schemes.Remove(schemeEntity); schemeEntity = null; if (childSchemeNode.Nodes.Count == 0) { childSchemeNode.ImageIndex = childSchemeNode.SelectedImageIndex = 2; } } if (relationEntity != null) { TreeNode deletedNode = childRelationNode.Nodes[deleteNodeName]; deletedNode.Remove(); fdbEntity.Relations.Remove(relationEntity); relationEntity = null; if (childRelationNode.Nodes.Count == 0) { childRelationNode.ImageIndex = childRelationNode.SelectedImageIndex = 2; } } if (queryEntity != null) { TreeNode deletedNode = childQueryNode.Nodes[deleteNodeName]; deletedNode.Remove(); fdbEntity.Queries.Remove(queryEntity); queryEntity = null; if (childQueryNode.Nodes.Count == 0) { childQueryNode.ImageIndex = childQueryNode.SelectedImageIndex = 2;//folder close } } }
private void DeleteScheme(FzSchemeEntity delScheme) { if (FzSchemeBLL.IsInherited(delScheme, fdbEntity.Relations)) { MessageBox.Show("Scheme is being inherited!"); } else { DialogResult result = new DialogResult(); result = MessageBox.Show("Delete this scheme ?", "Delete scheme " + delScheme.SchemeName, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { if (currentScheme != null && delScheme.Equals(currentScheme)) { //CloseCurrentScheme(); AddRowDefault(); } DeleteTreeNode(delScheme.SchemeName, delScheme, null, null); } } }
private void deleteAllSchemesToolStripMenuItem_Click(object sender, EventArgs e) { try { if (!FzSchemeBLL.IsInherited(fdbEntity)) { MessageBox.Show("Some scheme is being inherited\n Can not delete all schemes"); return; } DBValues.schemesName = FzSchemeBLL.GetListSchemeName(fdbEntity); foreach (var item in DBValues.schemesName) { FzSchemeEntity tmp = new FzSchemeEntity(); tmp = FzSchemeBLL.GetSchemeByName(item, fdbEntity); DeleteTreeNode(item, tmp, null, null); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }