private void RunScript() { object temp = new object(); sql = Script.Text; if (sql.IndexOf("*/") > 0) { sql = sql.Remove(0, sql.IndexOf("*/") + 2); } sql = HapusLineEnding(sql); temp = DatabaseScript.SQLscriptExecute(sql); if (temp != null) { DatabaseScript.data.DataView.DataSource = temp; } else { Script.Text = deletecommnet(Script.Text); Script.Text = addcomment(Script.Text); Script.AppendText(" "); } }
public static void EditData() // Edit Data From Database { DialogResult result = MessageBox.Show("Data will be deleted first. Do you want to process?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == System.Windows.Forms.DialogResult.Yes) { int rows = data.DataView.SelectedRows.Count; int PrimaryKey = 0; bool FoundPK = false; for (int i = 0; i < data.DataView.ColumnCount; i++) { if (data.DataView.Columns[i].Name == "Npm") { PrimaryKey = i; FoundPK = true; } } if (rows > 0 && FoundPK == true) { data.ClearData.PerformClick(); string script = "select *from beasiswa where "; bool Can = true; foreach (DataGridViewRow Current in data.DataView.SelectedRows) { string NPM = data.DataView[0, Current.Index].Value.ToString(); if (Can) { script += " NPM = '" + NPM + "' "; Can = false; } else { script += "or NPM = '" + NPM + "' "; } } script += ";"; DataTable dt = DatabaseScript.SQLscriptExecute(script); DataTableReader read = dt.CreateDataReader(); data.InputData.Rows.Add(rows); int i = 0; while (read.Read()) { for (int j = 0; j < 8; j++) { data.InputData[j, i].Value = read.GetValue(j).ToString(); } DatabaseScript.SQLscriptExecute("DELETE FROM `db_ai`.`beasiswa` WHERE `Npm`='" + data.InputData[0, i].Value.ToString() + "';"); i++; } } data.Refresh.PerformClick(); } }
private void ExecuteSQL_Click(object sender, EventArgs e) // Menjalankan SQL Script { object temp = DatabaseScript.SQLscriptExecute(sqlScript.Text); if (temp != null) { DataView.DataSource = temp; } }
public static void Delete() // Delete Data from Database { DialogResult result = MessageBox.Show("Are you sure want to delete?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { if (data.DataView.SelectedRows.Count > 0) { foreach (DataGridViewRow Current in data.DataView.SelectedRows) { string NPM = data.DataView[0, Current.Index].Value.ToString(); DatabaseScript.SQLscriptExecute("DELETE FROM `db_ai`.`beasiswa` WHERE `Npm`='" + NPM + "';"); } } data.Refresh.PerformClick(); data.ValueView(); } }
private void Data_Load(object sender, EventArgs e) // Action / Trigger { DataView.DataSource = DatabaseScript.SQLscriptExecute("select *from beasiswa;"); Algoritm.SelectedItem = Algoritm.Items[0]; ValueView(); }
private void Refresh_Click(object sender, EventArgs e) // Refresh Table Beasiswa { DataView.DataSource = DatabaseScript.SQLscriptExecute("select *from beasiswa;"); }