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 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(); }