public SongFormatter(DS.SongsRow row) { InitializeComponent(); currentRow = row; // accept changes if not new if (row.RowState == DataRowState.Detached) { this.Text = "Add a new song"; this.btnSave.Text = "Add"; } else { this.btnSave.Text = "Save"; row.AcceptChanges(); } dt = new EmpowerPresenter.DS.SongVersesDataTable(); // load song verses using (FBirdTask t = new FBirdTask()) { t.CommandText = "SELECT \"AutoNumber\", \"IsChorus\", \"Verse\", \"OrderNum\" " + "FROM \"SongVerses\" " + "WHERE \"AutoNumber\" = @AutoNumber " + "ORDER BY \"OrderNum\""; t.Parameters.Add("@AutoNumber", FbDbType.Integer); t.Parameters["@AutoNumber"].Value = row.AutoNumber; DS.SongVersesRow r; t.ExecuteReader(); while (t.DR.Read()) { r = dt.NewSongVersesRow(); r.AutoNumber = t.DR.GetInt32(0); r.IsChorus = t.DR.GetInt16(1) == 1 ? true : false; r.Verse = t.DR.GetString(2); r.OrderNum = t.DR.GetInt32(3); dt.AddSongVersesRow(r); } dt.AcceptChanges(); } dataView1.BeginInit(); dataView1.Table = dt; dataView1.EndInit(); // disect song SongNumber = currentRow.Number.ToString(); txtTitle.Text = currentRow.Title; txtChorus.Text = currentRow.Chorus; currentImage = new PhotoInfo(); currentImage.ImageId = currentRow.Image; button1_Click(null, null); gdbVerses.Model.Refresh(); }
private void LoadSongNote(int songNumber) { dt = new PresenterDataset.SongNotesDataTable(); SNdataView = new DataView(); this.Controls.Add(SndataGrid); BindingSource source = new BindingSource(); source.DataSource = SNdataView; SndataGrid.DataSource = SNdataView; int SongId = 5; using (FBirdTask t = new FBirdTask()) { t.CommandText = "SELECT [SongNotes].[Number], [SongNotes].[Note], [SongNotes].[IdSong] FROM [SongNotes]" + " where [SongNotes].[IdSong]=" + songNumber; t.ExecuteReader(); if (t.DR != null) { int rowNumber = 1; while (t.DR.Read()) { sRow = dt.NewSongNotesRow(); sRow.Number = t.GetInt32(0); // rowNumber; sRow.Note = t.GetString(1); // sRow.SongNumber= t.GetInt32(2); dt.AddSongNotesRow(sRow); rowNumber++; } t.DR.Close(); SNdataView.BeginInit(); SNdataView.Table = dt; SNdataView.EndInit(); } else { sRow = dt.NewSongNotesRow(); sRow.Note = ""; dt.AddSongNotesRow(sRow); } rowCount = dt.Rows.Count; } }
private void InternalLoadSongFromDB(PresenterDataset.SongsRow row, bool isNew) { dt = new PresenterDataset.SongVersesDataTable(); dt.Columns["AutoNumber"].DefaultValue = row.AutoNumber; if (!isNew) { using (FBirdTask t = new FBirdTask()) { t.CommandText = "SELECT [AutoNumber], [IsChorus], [Verse], [OrderNum] " + "FROM [SongVerses] " + "WHERE [AutoNumber] = @AutoNumber " + "ORDER BY [OrderNum]"; t.Parameters.Add("@AutoNumber", FbDbType.Integer); t.Parameters["@AutoNumber"].Value = row.AutoNumber; PresenterDataset.SongVersesRow r; t.ExecuteReader(); while (t.DR.Read()) { r = dt.NewSongVersesRow(); r.AutoNumber = t.GetInt32(0); r.IsChorus = t.GetInt32(1) == 1 ? true : false; r.Verse = t.GetString(2).Replace("\r\n", "\n").Replace("\n", "\r\n"); r.OrderNum = t.GetInt32(3); dt.AddSongVersesRow(r); } } } dt.AcceptChanges(); if (dt.Count == 0) { btnSave.Enabled = false; } dataView1.BeginInit(); dataView1.Table = dt; dataView1.EndInit(); dataGrid1.TableStyles[0].MappingName = dt.TableName; }
public void BeginInit2 () { DataTable table = new DataTable ("table"); DataView dv = new DataView (); DataColumn col1 = new DataColumn ("col1"); DataColumn col2 = new DataColumn ("col2"); dvInitialized = false; dv.Initialized += new EventHandler (OnDataViewInitialized); dv.BeginInit (); table.BeginInit (); table.Columns.AddRange (new DataColumn[] {col1,col2}); dv.Table = table; AssertNull ("#1", dv.Table); dv.EndInit (); AssertNull ("#2", dv.Table); AssertEquals ("#3", 0, table.Columns.Count); table.EndInit (); dv.Initialized -= new EventHandler (OnDataViewInitialized); // this should not be unregistered before table.EndInit(). AssertEquals ("#4", 2, table.Columns.Count); AssertEquals ("#6", table, dv.Table); AssertEquals ("DataViewInitialized #5", true, dvInitialized); }
public void BeginInit () { DataTable table = new DataTable ("table"); DataView dv = new DataView (); DataColumn col1 = new DataColumn ("col1"); DataColumn col2 = new DataColumn ("col2"); dv.BeginInit (); table.BeginInit (); table.Columns.AddRange (new DataColumn[] {col1,col2}); dv.Table = table; AssertNull ("#1", dv.Table); dv.EndInit (); AssertNull ("#2", dv.Table); // still. AssertEquals ("#3", 0, table.Columns.Count); table.EndInit (); AssertEquals ("#5", table, dv.Table); AssertEquals ("#4", 2, table.Columns.Count); }
public void BeginInit () { DataTable table = new DataTable ("table"); DataView dv = new DataView (); DataColumn col1 = new DataColumn ("col1"); DataColumn col2 = new DataColumn ("col2"); dv.BeginInit (); table.BeginInit (); table.Columns.AddRange (new DataColumn[] {col1,col2}); dv.Table = table; Assert.IsNull (dv.Table, "#1"); dv.EndInit (); Assert.IsNull (dv.Table, "#2"); // still. Assert.AreEqual (0, table.Columns.Count, "#3"); table.EndInit (); Assert.AreEqual (table, dv.Table, "#4"); Assert.AreEqual (2, table.Columns.Count, "#5"); }