public void ChangeEventSelection() { if (EventBox.SelectedIndex != -1) { this.Cursor = Cursors.WaitCursor; FunctionBox.Items.Clear(); selectedevent = events.ElementAt(EventBox.SelectedIndex).eventid; DataSet ds = common.readSQL("SELECT * FROM statel_functions s WHERE event_id=" + selectedevent + " AND statel_id=" + selectedstatel + " ORDER BY functionid, event_id ASC"); DataTable dt = ds.Tables[0]; functions.Clear(); args.Clear(); ArgumentBox.Items.Clear(); reqs.Clear(); RequirementBox.Items.Clear(); foreach (DataRow r in dt.Rows) { StatelFunction f = new StatelFunction(); f.functionid = (Int32)r[0]; f.functionnum = (Int32)r[3]; f.target = (Int32)r[4]; f.tickcount = (Int32)r[5]; f.tickinterval = (Int32)r[6]; functions.Add(f); FunctionBox.Items.Add(f.ToString()); } if (FunctionBox.Items.Count > 0) { FunctionBox.SelectedIndex = 0; } this.Cursor = Cursors.Default; } }
private void but_RemoveFunction_Click(object sender, EventArgs e) { if (FunctionBox.SelectedIndex == -1) { return; } if (MessageBox.Show("Delete this function and all of its arguments/requirements?", "Delete function?", MessageBoxButtons.YesNo) == DialogResult.Yes) { StatelFunction sf = functions.ElementAt(FunctionBox.SelectedIndex); common.execSQL("DELETE FROM statel_function_reqs WHERE function_id=" + sf.functionid); common.execSQL("DELETE FROM statel_function_arguments WHERE function_id=" + sf.functionid); common.execSQL("DELETE FROM statel_functions WHERE functionid=" + sf.functionid); ChangeEventSelection(); } }
private void FunctionBox_MouseDoubleClick(object sender, MouseEventArgs e) { if (FunctionBox.SelectedIndex != -1) { StatelFunction oldfunc = functions.ElementAt(FunctionBox.SelectedIndex); SelectFunction sf = new SelectFunction(); sf.getdata(oldfunc); sf.ShowDialog(); if (sf.DialogResult == DialogResult.OK) { common.execSQL("REPLACE INTO statel_functions VALUES (" + oldfunc.functionid + "," + selectedevent + "," + selectedstatel + "," + sf.functionnum + "," + sf.target + "," + sf.tickcount + "," + sf.tickinterval + ")"); int oldindex = FunctionBox.SelectedIndex; StatelBox_SelectedIndexChanged(null, null); FunctionBox.SelectedIndex = oldindex; if (sf.functionnum != oldfunc.functionnum) { common.execSQL("DELETE FROM statel_function_arguments WHERE function_id=" + oldfunc.functionid + " AND event_id=" + selectedevent + " AND statel_id=" + selectedstatel); ArgumentBox_MouseDoubleClick(null, null); } } } }
public void getdata(StatelFunction sf) { for (int c = 0; c < Functions.Items.Count; c++) { if (MainWindow.strBefore(MainWindow.strAfter(Functions.Items[c].ToString(), "("), ")") == sf.functionnum.ToString()) { Functions.SelectedIndex = c; break; } } tickcountbox.Text = sf.tickcount.ToString(); tickintervalbox.Text = sf.tickinterval.ToString(); for (int c = 0; c < Targets.Items.Count; c++) { if (MainWindow.strBefore(MainWindow.strAfter(Targets.Items[c].ToString(), "("), ")") == sf.target.ToString()) { Targets.SelectedIndex = c; break; } } }