public void SaveStylesForUser(StyleObj styles, string username) { var sql = "delete from UserStyles where Username=@user"; var sql2 = @"insert into UserStyles (Username, BackgroundColor, FontFamily, TitleColor, MainLinksColor, TopFrameColor, TopFrameBorderColor, TableHeaderRowBackground, TableRowBackground, TableRowAlternateBackground, TableCellBorder, TablePadding, FontSize) values (@user, @bgcolor, @font, @title, @mainlinks, @topframebkgd, @topframeborder, @tableheader, @tablerow, @tablealternaterow, @cellborder, @tablepadding, @fontsize) " ; using (var conn = new SqlConnection(mainDb)) { conn.Open(); using (var cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@user", username); cmd.ExecuteNonQuery(); } using (var cmd = new SqlCommand(sql2, conn)) { cmd.Parameters.AddWithValue("@user", username); if (String.IsNullOrEmpty(styles.BackgroundColor)) { cmd.Parameters.AddWithValue("@bgcolor", DBNull.Value); } else { cmd.Parameters.AddWithValue("@bgcolor", styles.BackgroundColor); } if (String.IsNullOrEmpty(styles.FontFamily)) { cmd.Parameters.AddWithValue("@font", DBNull.Value); } else { cmd.Parameters.AddWithValue("@font", styles.FontFamily); } if (String.IsNullOrEmpty(styles.TitleColor)) { cmd.Parameters.AddWithValue("@title", DBNull.Value); } else { cmd.Parameters.AddWithValue("@title", styles.TitleColor); } if (String.IsNullOrEmpty(styles.MainLinksColor)) { cmd.Parameters.AddWithValue("@mainlinks", DBNull.Value); } else { cmd.Parameters.AddWithValue("@mainlinks", styles.MainLinksColor); } if (String.IsNullOrEmpty(styles.TopFrameColor)) { cmd.Parameters.AddWithValue("@topframebkgd", DBNull.Value); } else { cmd.Parameters.AddWithValue("@topframebkgd", styles.TopFrameColor); } if (String.IsNullOrEmpty(styles.TopFrameBorderColor)) { cmd.Parameters.AddWithValue("@topframeborder", DBNull.Value); } else { cmd.Parameters.AddWithValue("@topframeborder", styles.TopFrameBorderColor); } if (String.IsNullOrEmpty(styles.TableHeaderRowBackground)) { cmd.Parameters.AddWithValue("@tableheader", DBNull.Value); } else { cmd.Parameters.AddWithValue("@tableheader", styles.TableHeaderRowBackground); } if (String.IsNullOrEmpty(styles.TableRowBackground)) { cmd.Parameters.AddWithValue("@tablerow", DBNull.Value); } else { cmd.Parameters.AddWithValue("@tablerow", styles.TableRowBackground); } if (String.IsNullOrEmpty(styles.TableRowAlternateBackground)) { cmd.Parameters.AddWithValue("@tablealternaterow", DBNull.Value); } else { cmd.Parameters.AddWithValue("@tablealternaterow", styles.TableRowAlternateBackground); } if (String.IsNullOrEmpty(styles.TableRowBackground)) { cmd.Parameters.AddWithValue("@cellborder", DBNull.Value); } else { cmd.Parameters.AddWithValue("@cellborder", styles.TableCellBorder); } if (String.IsNullOrEmpty(styles.TablePadding)) { cmd.Parameters.AddWithValue("@tablepadding", DBNull.Value); } else { cmd.Parameters.AddWithValue("@tablepadding", styles.TablePadding); } if (String.IsNullOrEmpty(styles.FontSize)) { cmd.Parameters.AddWithValue("@fontsize", DBNull.Value); } else { cmd.Parameters.AddWithValue("@fontsize", styles.FontSize); } cmd.ExecuteNonQuery(); } } }
public StyleObj GetStylesForUser(string username, bool loadDefaultIfNoUser = false) { var styles = new StyleObj() { ContainsCustomStyles = false }; var sql = @"select * from UserStyles where Username=@user"; var sql2 = @"select * from UserStyles where Username='******'"; using (var conn = new SqlConnection(mainDb)) { conn.Open(); using (var cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddWithValue("@user", username); using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { styles.ContainsCustomStyles = true; styles.BackgroundColor = GetVal(rdr["BackgroundColor"]); styles.TableRowBackground = GetVal(rdr["TableRowBackground"]); styles.TableRowAlternateBackground = GetVal(rdr["TableRowAlternateBackground"]); styles.TableCellBorder = GetVal(rdr["TableCellBorder"]); styles.TableHeaderRowBackground = GetVal(rdr["TableHeaderRowBackground"]); styles.FontFamily = GetVal(rdr["FontFamily"]); styles.MainLinksColor = GetVal(rdr["MainLinksColor"]); styles.TitleColor = GetVal(rdr["TitleColor"]); styles.TopFrameBorderColor = GetVal(rdr["TopFrameBorderColor"]); styles.TopFrameColor = GetVal(rdr["TopFrameColor"]); styles.TablePadding = GetVal(rdr["TablePadding"]); styles.FontSize = GetVal(rdr["FontSize"]); } } } if (!styles.ContainsCustomStyles && loadDefaultIfNoUser) { using (var cmd = new SqlCommand(sql2, conn)) { using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { styles.ContainsCustomStyles = true; styles.BackgroundColor = GetVal(rdr["BackgroundColor"]); styles.TableRowBackground = GetVal(rdr["TableRowBackground"]); styles.TableCellBorder = GetVal(rdr["TableCellBorder"]); styles.TableHeaderRowBackground = GetVal(rdr["TableHeaderRowBackground"]); styles.FontFamily = GetVal(rdr["FontFamily"]); styles.MainLinksColor = GetVal(rdr["MainLinksColor"]); styles.TitleColor = GetVal(rdr["TitleColor"]); styles.TopFrameBorderColor = GetVal(rdr["TopFrameBorderColor"]); styles.TopFrameColor = GetVal(rdr["TopFrameColor"]); styles.TablePadding = GetVal(rdr["TablePadding"]); styles.FontSize = GetVal(rdr["FontSize"]); } } } } } return(styles); }
private string BuildCustomStyleSheet(StyleObj styles) { var newStyle = @" body { background:inherit; background-color: @bgcolor; font-family: @fontfamily; font-size: @fontsizepx; } body { padding-bottom: 20px; } /*Background Color of table header row*/ .hoverTable th { background: @tableheaderbkgd; } /*Background Color of table row*/ .hoverTable tr { background: @tablerowbkgd; } /*Background Color of alternate table row*/ .hoverTable tr:nth-child(even) { background: @tablealternaterowbkgd; } /*Border color of each table cell*/ .hoverTable td { border: @tablecellborder 1px solid; } /*Color of thead main LiveScores logo in top-left*/ .navbar-inverse .navbar-brand { color: @titlecolor; } /*Color of main links across the top frame*/ .navbar-inverse .navbar-nav > li > a { color: @mainlinkscolor; } /*Background color of the top frame*/ .navbar-inverse { background-color: @topframecolor; border-color: @topframebordercolor; } .body-content { padding-top: 15px; padding-left: 15px; padding-right: 15px; } .table > tbody > tr > td { padding: @tablepaddingpx; } " ; newStyle = ReplaceText(newStyle, "@bgcolor", styles.BackgroundColor, "#334750"); newStyle = ReplaceText(newStyle, "@tableheaderbkgd", styles.TableHeaderRowBackground, "#6FA8D9"); newStyle = ReplaceText(newStyle, "@tablerowbkgd", styles.TableRowBackground, "#EDEEEF"); newStyle = ReplaceText(newStyle, "@tablealternaterowbkgd", styles.TableRowAlternateBackground, "#FFFFFF"); newStyle = ReplaceText(newStyle, "@tablecellborder", styles.TableCellBorder, "#4E95F4"); newStyle = ReplaceText(newStyle, "@fontfamily", styles.FontFamily, "'Open Sans', sans-serif"); newStyle = ReplaceText(newStyle, "@topframebordercolor", styles.TopFrameBorderColor, "#101010"); newStyle = ReplaceText(newStyle, "@topframecolor", styles.TopFrameColor, "#333333"); newStyle = ReplaceText(newStyle, "@mainlinkscolor", styles.MainLinksColor, "#9d9d9d"); newStyle = ReplaceText(newStyle, "@titlecolor", styles.TitleColor, "Orange"); newStyle = ReplaceText(newStyle, "@tablepadding", styles.TablePadding, "8"); newStyle = ReplaceText(newStyle, "@fontsize", styles.FontSize, "14"); return(newStyle); }