private void comboBoxListSchema_SelectedIndexChanged(object sender, EventArgs e)
 {
     gridViewEditSchema.CloseEditor();
     currentSchemeName  = comboBoxListSchema.Properties.Items[comboBoxListSchema.SelectedIndex].ToString();
     txtSchemeName.Text = currentSchemeName;
     currentScheme      = this.probDatabase.FproSchemas.SingleOrDefault(c => c.SchemaName.ToLower() == currentSchemeName);
     // check inherited
     if (new FProbSchemaBLL(currentSchemeName).isInherited(this.probDatabase.FproRelations) == true)
     {
         lblInfomation.Visible         = true;
         lblCurrentName.Enabled        = false;
         btSaveEditSchema.Enabled      = false;
         txtSchemeName.Enabled         = false;
         gridControlEditSchema.Enabled = false;
         gridViewEditSchema.OptionsBehavior.ReadOnly = true;
     }
     else
     {
         lblInfomation.Visible         = false;
         lblCurrentName.Enabled        = true;
         btSaveEditSchema.Enabled      = true;
         txtSchemeName.Enabled         = true;
         gridControlEditSchema.Enabled = true;
         gridViewEditSchema.OptionsBehavior.ReadOnly = false;
     }
     ResetGridView(currentScheme.FproAttributes);
 }
        internal static List <FProbRelationBLL> getAllRelation()
        {
            //"SELECT * FROM SystemRelation", "system_relation")

            List <FProbRelationBLL> relations = new List <FProbRelationBLL>();
            DataBase db  = new DataBase();
            DataSet  dts = new DataSet();

            dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemRelation", "system_relation"));
            try
            {
                foreach (DataRow row in dts.Tables["system_relation"].Rows)
                {
                    string               relationname = row[1].ToString();
                    int                  schemeID     = Convert.ToInt16(row[2]);
                    FProbSchemaBLL       schemeName   = new FProbSchemaBLL(schemeID).getSchemeById();
                    List <FProbTupleBLL> probTuples   = new List <FProbTupleBLL>();
                    int                  nTriples     = schemeName.FproAttributes.Count;
                    probTuples = new FProbTupleBLL().getAllTypleByRelationName(relationname, nTriples);
                    FProbRelationBLL relation = new FProbRelationBLL(Convert.ToInt16(row[0]), relationname, probTuples, schemeName);
                    relations.Add(relation);
                }
                return(relations);
            }
            catch
            {
                return(null);
            }
        }
        private static bool DropDatabaseData()
        {
            try
            {
                List <FProbRelationBLL> relations = new List <FProbRelationBLL>();
                relations = new FProbRelationBLL().getAllRelation();

                foreach (FProbRelationBLL item in relations)
                {
                    item.DropTableByTableName();
                }

                FProbSchemaBLL probScheme = new FProbSchemaBLL();
                probScheme.DeleteAllScheme();

                FProbRelationBLL probRelation = new FProbRelationBLL();
                probRelation.DeleteAllRelation();

                FProbAttributeBLL probAttribute = new FProbAttributeBLL();
                probAttribute.DeleteAllAttribute();

                FProbQueryBLL probQuery = new FProbQueryBLL();
                probQuery.DeleteAllQuery();
            }
            catch (Exception EX)
            {
                MessageBox.Show(EX.Message);
                return(false);
            }
            return(true);
        }
Example #4
0
        internal static void Update(FProbSchemaBLL probScheme)
        {
            string SQL = "";

            SQL += "Update SystemScheme  SET ";
            SQL += " SchemeName  = " + probScheme.SchemaName;
            SQL += " Where  ID = " + probScheme.IdSchema;
            new DataBase().Update(SQL);
        }
Example #5
0
        internal static void DeleteSchemeById(FProbSchemaBLL probScheme)
        {
            foreach (FProbAttributeBLL attr in probScheme.FproAttributes)
            {
                attr.FproSchema = probScheme;
                attr.DeleteAllAttributeByIdScheme();
            }
            DataBase db = new DataBase();

            if (!db.Update("DELETE FROM SystemScheme Where ID = " + probScheme.IdSchema))
            {
                throw new Exception(db.errorMessage);
            }
        }
Example #6
0
        internal static void Insert(FProbSchemaBLL probScheme)
        {
            DataBase db  = new DataBase();
            string   SQL = "";

            SQL += "INSERT INTO SystemScheme VALUES (";
            SQL += probScheme.IdSchema + ",";
            SQL += "'" + probScheme.SchemaName + "'";
            SQL += " );";
            if (!db.Update(SQL))
            {
                throw new Exception(db.errorMessage);
            }
        }
Example #7
0
        internal static FProbSchemaBLL getSchemeById(FProbSchemaBLL probScheme)
        {
            FProbSchemaBLL newSchemes = new FProbSchemaBLL();
            DataBase       db         = new DataBase();
            DataSet        dts        = new DataSet();

            dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemScheme where ID = " + probScheme.IdSchema, "system_scheme"));

            foreach (DataRow row in dts.Tables["system_scheme"].Rows)
            {
                List <FProbAttributeBLL> attributes = new FProbAttributeBLL().getListAttributeByIDScheme(Convert.ToInt16(row[0]));
                newSchemes = new FProbSchemaBLL(Convert.ToInt16(row[0]), row[1].ToString(), attributes);
            }
            return(newSchemes);
        }
Example #8
0
        private void btSaveCreateNewRel_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;
                    }
                }

                if (XtraMessageBox.Show("Do you want save?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    FProbSchemaBLL   scheme   = this.probDatabase.FproSchemas.SingleOrDefault(c => c.SchemaName.ToLower() == ComboBox_RelationName.Properties.Items[ComboBox_RelationName.SelectedIndex].ToString());
                    FProbRelationBLL relation = new FProbRelationBLL();
                    relation.RelationName = txtRelationName.Text;
                    relation.FproSchema   = scheme;
                    relation.InsertSystemRelation();
                    relation.CreateTableRelation();
                    this.probDatabase.FproRelations.Add(relation);
                    XtraMessageBox.Show("Add successfully");
                    this.Close();
                }
            }
            catch (Exception EX)
            {
                XtraMessageBox.Show(EX.Message);
            }
        }
        internal static FProbDatabaseBLL OpenExistingDatabase(FProbDatabaseBLL probDatabase)
        {
            FProbDatabaseBLL newProbDatabase = new FProbDatabaseBLL(probDatabase);

            try
            {
                List <FProbSchemaBLL> Schemes = new List <FProbSchemaBLL>();
                Schemes = new FProbSchemaBLL().getAllScheme();
                newProbDatabase.FproSchemas = Schemes;

                List <FProbRelationBLL> relations = new List <FProbRelationBLL>();
                relations = new FProbRelationBLL().getAllRelation();
                newProbDatabase.FproRelations = relations;

                List <FProbQueryBLL> querys = new List <FProbQueryBLL>();
                querys = new FProbQueryBLL().getAllQuery();
                newProbDatabase.FproQueries = querys;
            }
            catch (Exception)
            {
                return(null);
            }
            return(newProbDatabase);
        }
Example #10
0
        private void btOkDelSchema_Click(object sender, EventArgs e)
        {
            if (comboBoxDelSchema.SelectedIndex != -1)
            {
                FProbSchemaBLL currentScheme = this.probDatabase.FproSchemas.SingleOrDefault(c => c.SchemaName.ToLower() == comboBoxDelSchema.Properties.Items[comboBoxDelSchema.SelectedIndex].ToString());

                if (currentScheme.isInherited(this.probDatabase.FproRelations))
                {
                    XtraMessageBox.Show("Cannot delete this schema because it is inherited by some relations, please try again !", "Infomation ", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                if (XtraMessageBox.Show("Are you sure delete this schema?", "Delete Schema " + currentScheme.SchemaName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    this.probDatabase.FproSchemas.Remove(currentScheme);
                    currentScheme.DeleteSchemeById();
                    XtraMessageBox.Show("Delete successfully!", "Infomation ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            else
            {
                this.Close();
            }
        }
Example #11
0
        private void btSaveNewSchema_Click(object sender, EventArgs e)
        {
            dxErrorProviderNewSchema.SetError(txtSchemeName, null);

            if (txtSchemeName.Text.Trim().Length <= 0)
            {
                dxErrorProviderNewSchema.SetError(txtSchemeName, "You must enter a schema name, please try again!");
                return;
            }

            dxErrorProviderNewSchema.SetError(txtSchemeName, null);

            if (txtSchemeName.Text.ToLower() == "select" || txtSchemeName.Text.ToLower() == "from" || txtSchemeName.Text.ToLower() == "where")
            {
                dxErrorProviderNewSchema.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()))
                {
                    dxErrorProviderNewSchema.SetError(txtSchemeName, "This schema name has already existed in the database, please try again !");
                    return;
                }
            }

            dxErrorProviderNewSchema.SetError(txtSchemeName, null);
            if (gridViewNewSchema.DataRowCount < 1)
            {
                XtraMessageBox.Show("Error: Unable to create Schema. Schema attribute is required !", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //insert scheme
            FProbSchemaBLL scheme = new FProbSchemaBLL(txtSchemeName.Text);

            scheme.IdSchema = scheme.getMaxIdinTable();
            scheme.Insert();
            scheme.FproAttributes = getAllAttributeFromDataGridView(gridViewNewSchema);

            //insert attribute
            int attributeID = new FProbAttributeBLL().getMaxIdinTable();

            foreach (FProbAttributeBLL attr in scheme.FproAttributes)
            {
                attr.FproSchema  = scheme;
                attr.IdAttribute = attributeID;
                attr.Insert();
                attributeID++;
            }
            /// add scheme
            this.listProbScheme.Add(scheme);
            FProbRelationBLL relation = new FProbRelationBLL();

            relation.RelationName = txtSchemeName.Text;
            relation.FproSchema   = scheme;
            relation.InsertSystemRelation();
            relation.CreateTableRelation();
            this.probDatabase.FproRelations.Add(relation);
            XtraMessageBox.Show("Add successfully");
            this.Close();
        }