private void deleteToolStripMenuItem_Click(object sender, EventArgs e) { int index; index = SndataGrid.CurrentCell.RowNumber; int rNumber = sRow.Number; using (FBirdTask t = new FBirdTask()) { t.CommandText = "DELETE FROM [SongNotes] WHERE [Number] = @NNumber"; t.AddParameter("@Number", rNumber); t.ExecuteNonQuery(); } SNdataView.Delete(index); }
public static void SaveFontToDatabase(int id, PresenterFont font) { using (FBirdTask t = new FBirdTask()) { // check is font saved t.CommandText = "SELECT COUNT(*) FROM [PPTFONT] WHERE [AUTONUMBER] = @AUTONUMBER"; t.AddParameter("@AUTONUMBER", id); if ((int)t.ExecuteScalar() == 0) { // insert t.CommandText = "INSERT INTO [PPTFONT] ([AUTONUMBER], [FONTNAME], [SIZEINPOINTS], [COLOR], [VERTICALALIGNMENT], [HORIZONTALALIGNMENT], [OUTLINE], [SHADOW], [OUTLINECOLOR], [SHADOWCOLOR], [ITALIC], [BOLD], [DOUBLESPACE]) " + "VALUES (@AUTONUMBER, @FONTNAME, @SIZEINPOINTS, @COLOR, @VERTICALALIGNMENT, @HORIZONTALALIGNMENT, @OUTLINE, @SHADOW, @OUTLINECOLOR, @SHADOWCOLOR, @ITALIC, @BOLD, @DOUBLESPACE)"; } else { // update t.CommandText = "UPDATE [PPTFONT] SET " + "[FONTNAME] = @FONTNAME, " + "[SIZEINPOINTS] = @SIZEINPOINTS," + "[COLOR] = @COLOR," + "[VERTICALALIGNMENT] = @VERTICALALIGNMENT," + "[HORIZONTALALIGNMENT] = @HORIZONTALALIGNMENT," + "[OUTLINE] = @OUTLINE," + "[SHADOW] = @SHADOW," + "[ITALIC] = @ITALIC," + "[BOLD] = @BOLD, " + "[OUTLINECOLOR] = @OUTLINECOLOR, " + "[SHADOWCOLOR] = @SHADOWCOLOR, " + "[DOUBLESPACE] = @DOUBLESPACE " + "WHERE [AUTONUMBER] = @AUTONUMBER"; } // add parameters t.AddParameter("@FONTNAME", 512, font.FontName); t.AddParameter("@SIZEINPOINTS", font.SizeInPoints); t.AddParameter("@COLOR", font.Color.ToArgb()); t.AddParameter("@VERTICALALIGNMENT", (int)font.VerticalAlignment); t.AddParameter("@HORIZONTALALIGNMENT", (int)font.HorizontalAlignment); t.AddParameter("@OUTLINE", font.Outline); t.AddParameter("@SHADOW", font.Shadow); t.AddParameter("@ITALIC", font.Italic); t.AddParameter("@BOLD", font.Bold); t.AddParameter("@OUTLINECOLOR", font.OutlineColor.ToArgb()); t.AddParameter("@SHADOWCOLOR", font.ShadowColor.ToArgb()); t.AddParameter("@DOUBLESPACE", font.DoubleSpace); // save to db t.ExecuteNonQuery(); } }
// Database support public static PresenterFont GetFontFromDatabase(int id) { PresenterFont font = new PresenterFont(); using (FBirdTask t = new FBirdTask()) { t.CommandText = "SELECT [FONTNAME], [SIZEINPOINTS], [COLOR], [VERTICALALIGNMENT], [HORIZONTALALIGNMENT], [OUTLINE], [SHADOW], [OUTLINECOLOR], [SHADOWCOLOR], [ITALIC], [BOLD], [DOUBLESPACE] " + "FROM [PPTFONT] " + "WHERE [AUTONUMBER] = @AUTONUMBER"; t.AddParameter("@AUTONUMBER", id); t.ExecuteReader(); if (t.DR.Read()) { font.FontName = t.GetString(0); font.SizeInPoints = t.GetInt32(1); font.Color = t.GetColor(2, Color.Black); switch (t.GetInt32(3)) { case 0: font.VerticalAlignment = VerticalAlignment.Top; break; case 1: font.VerticalAlignment = VerticalAlignment.Middle; break; case 2: font.VerticalAlignment = VerticalAlignment.Bottom; break; default: break; } switch (t.GetInt32(4)) { case 0: font.HorizontalAlignment = HorizontalAlignment.Left; break; case 2: font.HorizontalAlignment = HorizontalAlignment.Center; break; case 1: font.HorizontalAlignment = HorizontalAlignment.Right; break; default: break; } font.Outline = t.GetBoolean(5); font.Shadow = t.GetBoolean(6); font.OutlineColor = t.GetColor(7, Color.White); font.ShadowColor = t.GetColor(8, Color.Gray); font.Italic = t.GetBoolean(9); font.Bold = t.GetBoolean(10); font.DoubleSpace = t.GetBoolean(11); } return(font); } }