Пример #1
0
        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;
        }
Пример #2
0
        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();
        }
Пример #3
0
        internal static void DeleteAllAttributeByIdScheme(ProbAttribute probAttribute)
        {
            DataBase db = new DataBase();

            if (!db.Update("DELETE FROM SystemAttribute Where SchemeID = " + probAttribute.probScheme.IDScheme))
            {
                throw new Exception(db.errorMessage);
            }
        }
Пример #4
0
        internal static List <ProbScheme> getAllScheme()
        {
            List <ProbScheme> newSchemes = new List <ProbScheme>();
            DataBase          db         = new DataBase();
            DataSet           dts        = new DataSet();

            dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemScheme", "system_scheme"));
            foreach (DataRow row in dts.Tables["system_scheme"].Rows)
            {
                List <ProbAttribute> attributes = new ProbAttribute().getListAttributeByIDScheme(Convert.ToInt16(row[0]));
                newSchemes.Add(new ProbScheme(Convert.ToInt16(row[0]), row[1].ToString(), attributes));
            }
            return(newSchemes);
        }
Пример #5
0
        public List <ProbAttribute> getAllAttributeFromDataGridView(DataGridView gridViewDesign)
        {
            List <ProbAttribute> probAttributes = new List <ProbAttribute>();

            int nRow = gridViewDesign.Rows.Count - 1;

            for (int i = 0; i < nRow; i++)
            {
                ProbAttribute attribute = new ProbAttribute();
                attribute.PrimaryKey    = Convert.ToBoolean(gridViewDesign.Rows[i].Cells[0].Value);
                attribute.AttributeName = gridViewDesign.Rows[i].Cells[1].Value.ToString();
                attribute.Type.TypeName = gridViewDesign.Rows[i].Cells[2].Value.ToString();
                attribute.Type.GetDomain(gridViewDesign.Rows[i].Cells[3].Value.ToString());
                attribute.Description = (gridViewDesign.Rows[i].Cells[4].Value == null ? "" : gridViewDesign.Rows[i].Cells[4].Value.ToString());
                attribute.Type.GetDataType();
                probAttributes.Add(attribute);
            }
            return(probAttributes);
        }
Пример #6
0
        internal static void Insert(ProbAttribute probAttribute)
        {
            DataBase db  = new DataBase();
            string   SQL = "";

            SQL += "INSERT INTO SystemAttribute VALUES ( ";
            SQL += probAttribute.IDAttribute + ",";
            SQL += "'" + probAttribute.PrimaryKey + "'" + ",";
            SQL += "'" + probAttribute.AttributeName + "'" + ",";
            SQL += "'" + probAttribute.Type.TypeName + "'" + ",";
            SQL += "'" + probAttribute.Type.DomainString + "'" + ",";
            SQL += "'" + probAttribute.Description + "'" + ",";
            SQL += probAttribute.probScheme.IDScheme;
            SQL += " );";

            if (!db.Update(SQL))
            {
                throw new Exception(db.errorMessage);
            }
        }
Пример #7
0
        internal static List <BLL.ProbAttribute> getListAttributeByIDScheme(int IDScheme)
        {
            List <ProbAttribute> probAttributes = new List <ProbAttribute>();
            DataBase             db             = new DataBase();
            DataTable            dtb            = db.GetDataTable("SELECT * FROM SystemAttribute Where SchemeID=" + IDScheme);

            if (dtb != null)
            {
                foreach (DataRow attrRow in dtb.Rows)
                {
                    ProbAttribute NewAttr = new ProbAttribute();
                    NewAttr.PrimaryKey    = Convert.ToBoolean(attrRow[1]);
                    NewAttr.AttributeName = Convert.ToString(attrRow[2]);
                    NewAttr.Type.TypeName = Convert.ToString(attrRow[3]);
                    NewAttr.Type.GetDomain(Convert.ToString(attrRow[4]));
                    NewAttr.Type.GetDataType();
                    NewAttr.Description = Convert.ToString(attrRow[5]);
                    probAttributes.Add(NewAttr);
                }
            }


            return(probAttributes);
        }
Пример #8
0
        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;
            }



            if (this.currentSchemeName != txtSchemeName.Text.Trim().ToLower())
            {
                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 (new frm_new_scheme().CheckValidatedDataGridView(this.GridViewDesign) == false)
            {
                return;
            }

            currentScheme.SchemeName = txtSchemeName.Text;
            currentScheme.Update();



            foreach (ProbAttribute attr in currentScheme.Attributes)
            {
                attr.probScheme = currentScheme;
                attr.DeleteAllAttributeByIdScheme();
            }

            currentScheme.Attributes.Clear();

            currentScheme.Attributes = new frm_new_scheme().getAllAttributeFromDataGridView(this.GridViewDesign);

            int ID = new ProbAttribute().getMaxIdinTable();

            foreach (ProbAttribute attr in currentScheme.Attributes)
            {
                attr.IDAttribute = ID;
                attr.probScheme  = currentScheme;
                attr.Insert();
                ID++;
            }



            if (MessageBox.Show("Edit successfully, Do you want edit another schema  ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                comboBox_SchemeName.Focus();
                this.scheme = currentScheme.SchemeName;
                frm_edit_scheme_Load(sender, e);
            }
            else
            {
                this.Close();
            }
        }