コード例 #1
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);
            }
        }
コード例 #2
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();
        }