コード例 #1
0
ファイル: DALProbDatabase.cs プロジェクト: AnhTran30/KLTN
        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;

        }
コード例 #2
0
ファイル: DALProbDatabase.cs プロジェクト: AnhTran30/KLTN
        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;
        }
コード例 #3
0
ファイル: DALProbRelation.cs プロジェクト: AnhTran30/KLTN
        internal static void DropTableByTableName(ProbRelation probRelation)
        {
            DataBase db = new DataBase();

            if (!db.DropTable(probRelation.RelationName))
            {
                throw new Exception(db.errorMessage);
            }
        }
コード例 #4
0
ファイル: DALProbRelation.cs プロジェクト: AnhTran30/KLTN
        internal static void DeleteRelationById(ProbRelation probRelation)
        {
            DataBase db = new DataBase();

            if (!db.Update("DELETE FROM SystemRelation where ID = " + probRelation.IDRelation))
            {
                throw new Exception(db.errorMessage);
            }
        }
コード例 #5
0
ファイル: frm_ new_relation.cs プロジェクト: Ngothihong/PRDP
        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);
            }
        }
コード例 #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            errorProvider.SetError(txtNewNameRelation, null);
            if (txtNewNameRelation.Text.Trim().Length <= 0)
            {
                errorProvider.SetError(txtNewNameRelation, "You did not enter a relation name");
                return;
            }

            if (txtNewNameRelation.Text.ToLower() == "select" || txtNewNameRelation.Text.ToLower() == "from" || txtNewNameRelation.Text.ToLower() == "where")
            {
                errorProvider.SetError(txtNewNameRelation, "Relation name is not valid ( not match with keyword 'select', 'from', 'where')  ");
                return;
            }


            if (this.CurrentNameRelation == txtNewNameRelation.Text.Trim().ToLower())
            {
                return;
            }


            if (this.CurrentNameRelation != txtNewNameRelation.Text.Trim().ToLower())
            {
                foreach (var item in this.probDatabase.ListOfRelationNameToLower())
                {
                    if (item.Equals(txtNewNameRelation.Text.ToLower()))
                    {
                        errorProvider.SetError(txtNewNameRelation, "This relation name has already existed in the database ");
                        return;
                    }
                }
            }

            ProbRelation relation = this.probDatabase.Relations.SingleOrDefault(c => c.RelationName.ToLower() == CurrentNameRelation);

            this.probDatabase.Relations.Remove(relation);
            relation.DropTableByTableName();
            relation.DeleteRelationById();
            relation.RelationName = txtNewNameRelation.Text.Trim();
            relation.InsertSystemRelation();
            relation.CreateTableRelation();
            relation.InsertTupleIntoTableRelation();
            this.probDatabase.Relations.Add(relation);
            MessageBox.Show("Rename relation successful", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
コード例 #7
0
ファイル: DALProbRelation.cs プロジェクト: AnhTran30/KLTN
        internal static void CreateTableRelation(ProbRelation probRelation)
        {
            if (probRelation.Scheme.Attributes.Count > 0)
            {
                DataBase db  = new DataBase();
                string   SQL = "";
                SQL += "CREATE TABLE " + probRelation.RelationName + " ( ";
                foreach (ProbAttribute attribute in probRelation.Scheme.Attributes)
                {
                    SQL += attribute.AttributeName + " " + "TEXT" + ", ";
                }
                SQL  = SQL.Remove(SQL.LastIndexOf(','), 1);
                SQL += " ); ";

                if (!db.CreateTable(SQL))
                {
                    throw new Exception(db.errorMessage);
                }
            }
        }
コード例 #8
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            if (cbo_RelationName.SelectedIndex != -1)
            {
                ProbRelation relation = this.probDatabase.Relations.SingleOrDefault(c => c.RelationName.ToLower() == cbo_RelationName.Properties.Items[cbo_RelationName.SelectedIndex].ToString());

                if (MessageBox.Show(" Are you sure delete this relation  ?", "Delete Relation " + relation.RelationName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    this.probDatabase.Relations.Remove(relation);
                    relation.DropTableByTableName();
                    relation.DeleteRelationById();
                    relationNameRemove = relation.RelationName;
                    MessageBox.Show(" Delete successfully !", "Infomation ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            else
            {
                this.Close();
            }
        }
コード例 #9
0
ファイル: DALProbRelation.cs プロジェクト: AnhTran30/KLTN
        internal static void InsertSystemRelation(ProbRelation probRelation)
        {
            if (probRelation.IDRelation == -1)
            {
                probRelation.IDRelation = new DataBase().GetMaxIdInTable("SystemRelation");
            }


            DataBase db  = new DataBase();
            string   SQL = "";

            SQL  = "";
            SQL += "INSERT INTO SystemRelation VALUES ( ";
            SQL += probRelation.IDRelation + ",";
            SQL += "'" + probRelation.RelationName + "'" + ",";
            SQL += probRelation.Scheme.IDScheme;
            SQL += " );";
            if (!db.Update(SQL))
            {
                throw new Exception(db.errorMessage);
            }
        }
コード例 #10
0
ファイル: DALProbRelation.cs プロジェクト: AnhTran30/KLTN
        internal static void InsertTupleIntoTableRelation(ProbRelation probRelation)
        {
            DataBase db = new DataBase();

            if (probRelation.tuples.Count > 0)
            {
                foreach (ProbTuple tuple in probRelation.tuples)
                {
                    string SQL = "";
                    SQL += "INSERT INTO " + probRelation.RelationName + " VALUES (";
                    foreach (ProbTriple triple in tuple.Triples)
                    {
                        SQL += "'" + triple.GetStrValue() + "'" + ",";
                    }
                    SQL  = SQL.Remove(SQL.LastIndexOf(','), 1);
                    SQL += " );  ";

                    if (!db.Update(SQL))
                    {
                        throw new Exception(db.errorMessage);
                    }
                }
            }
        }
コード例 #11
0
ファイル: DALProbRelation.cs プロジェクト: AnhTran30/KLTN
        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);
        }