private void comboBox_SchemeName_SelectedIndexChanged(object sender, EventArgs e) { currentSchemeName = comboBox_SchemeName.Properties.Items[comboBox_SchemeName.SelectedIndex].ToString(); txtSchemeName.Text = currentSchemeName; currentScheme = this.probDatabase.Schemes.SingleOrDefault(c => c.SchemeName.ToLower() == currentSchemeName); // check inherited if (new ProbScheme(currentSchemeName).isInherited(this.probDatabase.Relations) == true) { lblInfomation.Visible = true; lblCurrentName.Enabled = false; GridViewDesign.ReadOnly = true; btnSave.Enabled = false; txtSchemeName.Enabled = false; Btn_Design_ClearData.Enabled = false; Btn_Design_DeleteRow.Enabled = false; } else { lblInfomation.Visible = false; lblCurrentName.Enabled = true; GridViewDesign.ReadOnly = false; btnSave.Enabled = true; txtSchemeName.Enabled = true; Btn_Design_ClearData.Enabled = true; Btn_Design_DeleteRow.Enabled = true; } //add attribute into GridViewDesign GridViewDesign.Rows.Clear(); int i = 0; CheckBox chkbox; foreach (ProbAttribute attr in currentScheme.Attributes) { GridViewDesign.Rows.Add(); chkbox = new CheckBox(); chkbox.Checked = attr.PrimaryKey; GridViewDesign.Rows[i].Cells[0].Value = chkbox.CheckState; GridViewDesign.Rows[i].Cells[1].Value = attr.AttributeName; GridViewDesign.Rows[i].Cells[2].Value = attr.Type.TypeName; GridViewDesign.Rows[i].Cells[3].Value = attr.Type.DomainString; GridViewDesign.Rows[i].Cells[4].Value = (attr.Description != null ? attr.Description : null); i++; } GridViewDesign.CurrentCell = GridViewDesign.Rows[i].Cells[0]; if (GridViewDesign.CurrentRow != null) { lblDesignRowNumberIndicator.Text = (GridViewDesign.CurrentRow.Index + 1).ToString() + " / " + GridViewDesign.Rows.Count.ToString(); } else { lblDesignRowNumberIndicator.Text = "1 / " + GridViewDesign.Rows.Count.ToString(); } }
internal static ProbDatabase OpenExistingDatabase(ProbDatabase probDatabase) { ProbDatabase newProbDatabase = new ProbDatabase(probDatabase); try { List<ProbScheme> Schemes = new List<ProbScheme>(); Schemes = new ProbScheme().getAllScheme(); newProbDatabase.Schemes = Schemes; List<ProbRelation> relations = new List<ProbRelation>(); relations = new ProbRelation().getAllRelation(); newProbDatabase.Relations = relations; List<ProbQuery> querys = new List<ProbQuery>(); querys = new ProbQuery().getAllQuery(); newProbDatabase.Queries = querys; } catch (Exception) { return null; } return newProbDatabase; }
private static bool DropDatabaseData() { try { List<ProbRelation> relations = new List<ProbRelation>(); relations = new ProbRelation().getAllRelation(); foreach (ProbRelation item in relations) { item.DropTableByTableName(); } ProbScheme probScheme = new ProbScheme(); probScheme.DeleteAllScheme(); ProbRelation probRelation = new ProbRelation(); probRelation.DeleteAllRelation(); ProbAttribute probAttribute = new ProbAttribute(); probAttribute.DeleteAllAttribute(); ProbQuery probQuery = new ProbQuery(); probQuery.DeleteAllQuery(); } catch (Exception EX) { MessageBox.Show(EX.Message); return false; } return true; }
private void btnSave_Click(object sender, EventArgs e) { errorProvider.SetError(txtSchemeName, null); if (txtSchemeName.Text.Trim().Length <= 0) { errorProvider.SetError(txtSchemeName, "You must enter a schema name, please try again!"); return; } errorProvider.SetError(txtSchemeName, null); if (txtSchemeName.Text.ToLower() == "select" || txtSchemeName.Text.ToLower() == "from" || txtSchemeName.Text.ToLower() == "where") { errorProvider.SetError(txtSchemeName, "Schema name is not valid ( not match with keyword 'select', 'from', 'where') "); return; } foreach (var item in this.probDatabase.ListOfSchemeNameToLower()) { if (item.Equals(txtSchemeName.Text.ToLower())) { errorProvider.SetError(txtSchemeName, "This schema name has already existed in the database, please try again !"); return; } } errorProvider.SetError(txtSchemeName, null); if (CheckValidatedDataGridView(this.GridViewDesign) == false) { return; } //insert scheme ProbScheme scheme = new ProbScheme(txtSchemeName.Text); scheme.IDScheme = scheme.getMaxIdinTable(); scheme.Insert(); scheme.Attributes = getAllAttributeFromDataGridView(GridViewDesign); //insert attribute int attributeID = new ProbAttribute().getMaxIdinTable(); foreach (ProbAttribute attr in scheme.Attributes) { attr.probScheme = scheme; attr.IDAttribute = attributeID; attr.Insert(); attributeID++; } /// add scheme this.listProbScheme.Add(scheme); MessageBox.Show("Add successfully.", "Message"); txtSchemeName.Text = ""; GridViewDesign.Rows.Clear(); txtSchemeName.Focus(); this.Close(); }
internal static void Update(ProbScheme probScheme) { string SQL = ""; SQL += "Update SystemScheme SET "; SQL += " SchemeName = " + probScheme.SchemeName; SQL += " Where ID = " + probScheme.IDScheme; new DataBase().Update(SQL); }
private void btnSave_Click(object sender, EventArgs e) { try { errorProvider.SetError(txtRelationName, null); if (txtRelationName.Text.Trim().Length <= 0) { errorProvider.SetError(txtRelationName, "You must enter a relation name, please try again !"); return; } if (txtRelationName.Text.ToLower() == "select" || txtRelationName.Text.ToLower() == "from" || txtRelationName.Text.ToLower() == "where") { errorProvider.SetError(txtRelationName, "Relation name is not valid ( not match with keyword 'select', 'from', 'where') "); return; } foreach (var item in this.probDatabase.ListOfRelationNameToLower()) { if (item.Equals(txtRelationName.Text.ToLower(), StringComparison.OrdinalIgnoreCase)) { errorProvider.SetError(txtRelationName, "This relation name has already existed in the database, please try again !"); return; } } ProbScheme scheme = this.probDatabase.Schemes.SingleOrDefault(c => c.SchemeName.ToLower() == cbo_SchemeName.Properties.Items[cbo_SchemeName.SelectedIndex].ToString()); ProbRelation relation = new ProbRelation(); relation.RelationName = txtRelationName.Text.ToLower(); relation.Scheme = scheme; relation.InsertSystemRelation(); relation.CreateTableRelation(); this.probDatabase.Relations.Add(relation); if (MessageBox.Show("Add successfully.Do you want add a new relation name ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { txtRelationName.Focus(); txtRelationName.Text = null; this.frm__new_relation_Load(sender, e); } else { this.Close(); } } catch (Exception EX) { MessageBox.Show(EX.Message); } }
internal static void Insert(ProbScheme probScheme) { DataBase db = new DataBase(); string SQL = ""; SQL += "INSERT INTO SystemScheme VALUES ("; SQL += probScheme.IDScheme + ","; SQL += "'" + probScheme.SchemeName + "'"; SQL += " );"; if (!db.Update(SQL)) { throw new Exception(db.errorMessage); } }
internal static void DeleteSchemeById(ProbScheme probScheme) { foreach (ProbAttribute attr in probScheme.Attributes) { attr.probScheme = probScheme; attr.DeleteAllAttributeByIdScheme(); } DataBase db = new DataBase(); if (!db.Update("DELETE FROM SystemScheme Where ID = " + probScheme.IDScheme)) { throw new Exception(db.errorMessage); } }
internal static ProbScheme getSchemeById(ProbScheme probScheme) { ProbScheme newSchemes = new ProbScheme(); DataBase db = new DataBase(); DataSet dts = new DataSet(); dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemScheme where ID = " + probScheme.IDScheme, "system_scheme")); foreach (DataRow row in dts.Tables["system_scheme"].Rows) { List <ProbAttribute> attributes = new ProbAttribute().getListAttributeByIDScheme(Convert.ToInt16(row[0])); newSchemes = new ProbScheme(Convert.ToInt16(row[0]), row[1].ToString(), attributes); } return(newSchemes); }
internal static List <BLL.ProbRelation> getAllRelation() { //"SELECT * FROM SystemRelation", "system_relation") List <ProbRelation> relations = new List <ProbRelation>(); DataBase db = new DataBase(); DataSet dts = new DataSet(); dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemRelation", "system_relation")); foreach (DataRow row in dts.Tables["system_relation"].Rows) { string relationname = row[1].ToString(); int schemeID = Convert.ToInt16(row[2]); ProbScheme schemeName = new ProbScheme(schemeID).getSchemeById(); List <ProbTuple> probTuples = new List <ProbTuple>(); int nTriples = schemeName.Attributes.Count; probTuples = new ProbTuple().getAllTypleByRelationName(relationname, nTriples); ProbRelation relation = new ProbRelation(Convert.ToInt16(row[0]), relationname, probTuples, schemeName); relations.Add(relation); } return(relations); }
private void btnOK_Click(object sender, EventArgs e) { if (cbo_schemeName.SelectedIndex != -1) { ProbScheme currentScheme = this.probDatabase.Schemes.SingleOrDefault(c => c.SchemeName.ToLower() == cbo_schemeName.Properties.Items[cbo_schemeName.SelectedIndex].ToString()); if (currentScheme.isInherited(this.probDatabase.Relations)) { MessageBox.Show(" Cannot delete this schema because it is inherited by some relations, please try again !", "Infomation ", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (MessageBox.Show(" Are you sure delete this schema ?", "Delete Schema " + currentScheme.SchemeName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { this.probDatabase.Schemes.Remove(currentScheme); currentScheme.DeleteSchemeById(); MessageBox.Show(" Delete successfully !", "Infomation ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } } else { this.Close(); } }