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; }
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; }
internal static void Insert(ProbQuery probQuery) { if (probQuery.IDQuery == -1) { probQuery.IDQuery = new DataBase().GetMaxIdInTable("SystemQuery"); } DataBase db = new DataBase(); string SQL = ""; if (probQuery.QueryString == "") { probQuery.QueryString = "Empty"; } SQL += "INSERT INTO SystemQuery VALUES ("; SQL += probQuery.IDQuery + ","; SQL += "'" + probQuery.QueryName + "'" + ","; SQL += "'" + probQuery.QueryString + "'"; SQL += " );"; if (!db.Update(SQL)) { throw new Exception(db.errorMessage); } }
internal static List <BLL.ProbQuery> getAllQuery() { List <ProbQuery> probQuerys = new List <ProbQuery>(); DataBase db = new DataBase(); DataSet dts = dts = new DataSet(); dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemQuery", "system_query")); foreach (DataRow queryRow in dts.Tables["system_query"].Rows) { ProbQuery NewQuery = new ProbQuery(); NewQuery.IDQuery = Convert.ToInt16(queryRow[0].ToString()); NewQuery.QueryName = queryRow[1].ToString(); if (queryRow[2].ToString() != "Empty") { NewQuery.GetQueryString(queryRow[2].ToString()); } else { NewQuery.GetQueryString(""); } probQuerys.Add(NewQuery); } return(probQuerys); }
private void btnSave_Click(object sender, EventArgs e) { errorProvider.SetError(txtNewName, null); if (txtNewName.Text.Trim().Length <= 0) { errorProvider.SetError(txtNewName, "You did not enter a query name"); return; } foreach (string item in this.listNameQuery) { if (item == txtNewName.Text.Trim().ToLower() && txtNewName.Text.Trim() != this.listNameQuery[cbo_QueryName.SelectedIndex]) { errorProvider.SetError(txtNewName, "This query name has already existed in the database"); return; } } ProbQuery query = this.probDatabase.Queries.SingleOrDefault(c => c.QueryName == this.listNameQuery[cbo_QueryName.SelectedIndex]); QueryNameRename = query.QueryName; query.QueryName = txtNewName.Text.Trim().ToLower(); query.Update(); queryName = query.QueryName; MessageBox.Show("Rename query successfully", "Notification", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); }
private void btnSave_Click(object sender, EventArgs e) { errorProvider.SetError(txtQueryName, null); if (txtQueryName.Text.Trim().Length < 0) { errorProvider.SetError(txtQueryName, "You must enter a query name, please try again !"); return; } foreach (string item in this.probDatabase.ListOfQueryNameToLower()) { if (item == txtQueryName.Text.ToLower()) { errorProvider.SetError(txtQueryName, "The query name has already existed in the database, please try again !"); return; } } this.queryName = txtQueryName.Text.Trim().ToLower(); ProbQuery query = new ProbQuery(this.queryName); query.Insert(); query = query.getQueryByName(); this.probDatabase.Queries.Add(query); MessageBox.Show("Add successfully.", "Message"); txtQueryName.Text = ""; txtQueryName.Focus(); this.Close(); }
internal static void DeleteById(ProbQuery probQuery) { DataBase db = new DataBase(); if (!db.Update("DELETE FROM SystemQuery where ID = " + probQuery.IDQuery)) { throw new Exception(db.errorMessage); } }
internal static void Update(ProbQuery probQuery) { string SQL = ""; SQL += "Update SystemQuery SET "; SQL += " QueryName = '" + probQuery.QueryName + "'"; SQL += " , QueryString = '" + probQuery.QueryString.Replace("'", "''") + "'"; SQL += " Where ID = " + probQuery.IDQuery; new DataBase().Update(SQL); }
private void btnOk_Click(object sender, EventArgs e) { DialogResult result = new DialogResult(); result = MessageBox.Show("Are you sure want to delete this query ?", "Delete Queries", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { string selectName = cbo_QueryName.Properties.Items[cbo_QueryName.SelectedIndex].ToString(); ProbQuery query = this.probDatabase.Queries.SingleOrDefault(c => c.QueryName.ToLower() == selectName); query.DeleteById(); QueryNameRemove = query.QueryName; this.probDatabase.Queries.Remove(query); MessageBox.Show(" Delete successfully !", "Infomation ", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } }
internal static ProbQuery getQueryByName(ProbQuery probQuery) { DataBase db = new DataBase(); DataSet dts = dts = new DataSet(); dts.Tables.Add(db.GetDataTable("SELECT * FROM SystemQuery where QueryName = '" + probQuery.QueryName + "'", "system_query")); ProbQuery NewQuery = new ProbQuery(); foreach (DataRow queryRow in dts.Tables["system_query"].Rows) { NewQuery = new ProbQuery(); NewQuery.IDQuery = Convert.ToInt16(queryRow[0].ToString()); NewQuery.QueryName = queryRow[1].ToString(); NewQuery.GetQueryString(queryRow[2].ToString()); } return(NewQuery); }
private void btnSave_Click(object sender, EventArgs e) { errorProvider.SetError(txtQueryName, null); if (txtQueryName.Text.Trim().Length < 0) { errorProvider.SetError(txtQueryName, "You must enter a query name, please try again !"); return; } foreach (string item in this.probDatabase.ListOfQueryNameToLower()) { if (item == txtQueryName.Text.ToLower()) { errorProvider.SetError(txtQueryName, "The query name has already existed in the database, please try again !"); return; } } this.queryName = txtQueryName.Text.Trim().ToLower(); ProbQuery query = new ProbQuery(this.queryName); query.Insert(); query = query.getQueryByName(); this.probDatabase.Queries.Add(query); if (MessageBox.Show("Add successfully. Do you want add a new query name ?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { txtQueryName.Text = ""; txtQueryName.Focus(); } else { this.Close(); } }