Exemple #1
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();
        }
Exemple #2
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();
            }
        }