public Sequence_t LoadSequence(string name) { m_cmd.CommandText = "SELECT SA.type, SA.value, SA.duration, SA.keybind FROM Sequences S JOIN SequenceAction SA ON SA.sequence = S.id WHERE S.name=@name"; m_cmd.Parameters.AddWithValue("@name", name); m_cmd.Prepare(); SQLiteDataReader rdr = m_cmd.ExecuteReader(); List <Action_t> actions = new List <Action_t>(); while (rdr.Read()) { Action_t act = new Action_t(rdr.GetString(0), rdr.GetString(1), rdr.GetInt32(2)); try { int keybind = rdr.GetInt32(3); Keybind_t kb = LoadKeyBind(keybind); kb.readable = rdr.GetString(1); act.keybind = kb; } catch (InvalidCastException) { } actions.Add(act); } rdr.Close(); Sequence_t seqs = new Sequence_t(actions); return(seqs); }
private void save_selected(object sender, EventArgs e) { ToolStripItem item = sender as ToolStripItem; Sequence_t seq = m_db.LoadSequence(item.Text); dataGridView1.Rows.Clear(); foreach (var act in seq.actions) { if (act.keybind == null) { dataGridView1.Rows.Add(act.type, act.value, act.duration); if (act.type == "Delay") { DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count - 2]; row.Cells[1].Style.BackColor = Color.LightGray; row.Cells[1].ReadOnly = true; } else if (act.type == "Stop") { DataGridViewRow row = dataGridView1.Rows[dataGridView1.Rows.Count - 2]; row.Cells[1].Style.BackColor = Color.LightGray; row.Cells[1].ReadOnly = true; row.Cells[2].Style.BackColor = Color.LightGray; row.Cells[2].ReadOnly = false; row.Cells[2].Value = ""; } } else { dataGridView1.Rows.Add(act.type, act.keybind, act.duration); } } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { saveForm form = new saveForm(this.TopMost); form.ShowDialog(); string save_name = form.save_name; if (save_name.Length <= 0) { return; } List <Action_t> actions = new List <Action_t>(); foreach (DataGridViewRow row in dataGridView1.Rows) { if (row == null) { continue; } if (row.Cells[0] == null || row.Cells[2] == null) { continue; } if (row.Cells[0].Value == null || row.Cells[2].Value == null) { continue; } decimal duration; bool ret = Decimal.TryParse(row.Cells[2].Value.ToString(), out duration); if (!ret) { duration = 0; } Action_t act; try { act = new Action_t((string)row.Cells[0].Value, (string)row.Cells[1].Value, decimal.ToInt32(duration)); act.keybind = null; } catch (InvalidCastException) { act = new Action_t((string)row.Cells[0].Value, row.Cells[1].Value.ToString(), decimal.ToInt32(duration)); act.keybind = (Keybind_t)row.Cells[1].Value; } actions.Add(act); } Sequence_t seq = new Sequence_t(actions); m_db.SaveSequence(save_name, seq); UpdateSavesList(); }
public void SaveSequence(string name, Sequence_t seq) { m_cmd.CommandText = "DELETE FROM Sequences WHERE name=@name"; m_cmd.Parameters.AddWithValue("@name", name); m_cmd.Prepare(); m_cmd.ExecuteNonQuery(); m_cmd.CommandText = "INSERT INTO Sequences (name) VALUES (@name)"; m_cmd.Prepare(); m_cmd.ExecuteNonQuery(); m_cmd.CommandText = "SELECT id FROM Sequences WHERE name=@name"; m_cmd.Prepare(); int id = Convert.ToInt32(m_cmd.ExecuteScalar().ToString()); m_cmd.CommandText = "INSERT INTO SequenceAction (sequence, type, value, duration, keybind) VALUES (@sequence, @type, @value, @duration, @keybind)"; m_cmd.Parameters.AddWithValue("@sequence", id); foreach (var act in seq.actions) { if (act.keybind != null) { int keybind = SaveKeyBind(act.keybind); m_cmd.Parameters.AddWithValue("@keybind", keybind); } else { m_cmd.Parameters.AddWithValue("@keybind", null); } m_cmd.Parameters.AddWithValue("@type", act.type); m_cmd.Parameters.AddWithValue("@value", act.value); m_cmd.Parameters.AddWithValue("@duration", act.duration); m_cmd.Prepare(); m_cmd.ExecuteNonQuery(); } }