public static void Create(string uuid, string ip) { // IPエラー var ipCount = Convert.ToInt32(MySqlite.GetOne( "select count(1) from users " + "where ip = ? ", new object[] { ip } )); if (ipCount >= 1) { throw new Exception(); } MySqlite.Execute( "insert into users " + "(uuid, ip, created_at) values " + "(?, ?, ?) ", new object[] { uuid, ip, Utility.GetDatetime() } ); // 匿名ネームに変える int id = MySqlite.LastInsertedId(); MySqlite.Execute( "update users " + "set name = ? " + "where id = ? ", new object[] { "匿名" + id.ToString(), id } ); }
/// <summary> /// 从本地数据库获取章节 /// </summary> void GetChapters(int sourceID, string novel) { chapters = new List <Chapter>(); chapterItems = new List <ListViewItem>(); Chapter chapter; ListViewItem item; //根据小说名和网站查找 string sql = "select * from chapters where novel=@novel and webIndex=@index"; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("index", sourceID)); parameters.Add(new SQLiteParameter("novel", novel)); DataTable table = MySqlite.GetData(sql, parameters); for (int i = 0; i < table.Rows.Count; i++) { chapter = new Chapter(); chapter.novel = table.Rows[i][0].ToString(); chapter.chapter = table.Rows[i][1].ToString(); chapter.web = Convert.ToInt32(table.Rows[i][2].ToString()); chapter.site = table.Rows[i][3].ToString(); chapters.Add(chapter); string[] ss = { chapter.chapter, chapter.site }; item = new ListViewItem(ss); chapterItems.Add(item); } Invoke(new Action(delegate { AddChaptersList(); })); }
//右键--屏蔽 private void 屏蔽选中词语ToolStripMenuItem_Click(object sender, EventArgs e) { string txt = richTextBox1.SelectedText.Trim(); txt = txt.Replace("'", "''"); //单引号转义 string type = "词语"; //添加到数据库 string sql = "insert into blackWords values(@word,'',@type,@date)"; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("word", txt)); parameters.Add(new SQLiteParameter("type", type)); parameters.Add(new SQLiteParameter("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); MySqlite.ExecSql(sql, parameters); string s = richTextBox1.Text; s = s.Replace(txt, ""); richTextBox1.Text = s.TrimEnd(); BlackWord word = new BlackWord(); word.word = txt; word.type = type; word.instead = ""; blackWords.Add(word); }
private void button_ok_Click(object sender, EventArgs e) { string s1 = textBox_source.Text.Trim(); //原屏蔽词 string s2 = textBox_des.Text.Trim(); //新屏蔽词 string s4 = textBox_desinstead.Text.Trim(); //新替换词 if (s1 == s2) { return; } s1 = s1.Replace("'", "''");//单引号转义 s2 = s2.Replace("'", "''"); s4 = s4.Replace("'", "''"); string sql = "select * from blackWords where words=@word"; //查重 List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("word", s2)); DataTable table = MySqlite.GetData(sql, parameters); if (table.Rows.Count > 0) { MessageBox.Show("已存在相同项"); return; } sql = "update blackWords set words=@word,@instead=instead,date=@date where words=@oldword"; parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("word", s2)); parameters.Add(new SQLiteParameter("instead", s4)); parameters.Add(new SQLiteParameter("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); parameters.Add(new SQLiteParameter("oldword", s1)); MySqlite.ExecSql(sql, parameters); Close(); }
public static bool IsExist(string title, string artist) { return(Convert.ToInt32(MySqlite.GetOne( "select count(1) from subjects " + "where title = ? and artist = ? ", new object[] { title, artist } )) >= 1); }
public static List <Dictionary <string, object> > GetAll() { return(MySqlite.GetAll( "select id, user_id, title, artist, url, comment, created_at from subjects " + "where is_disabled = 0 " + "order by id asc " )); }
public static Dictionary <string, object> GetUser(string uuid) { return(MySqlite.GetLine( "select * from users " + "where uuid = ? ", new object[] { uuid } )); }
private static string Get(string key) { return(MySqlite.GetOne( "select value from infos " + "where key = ? ", new object[] { key } )); }
public static List <Dictionary <string, object> > GetMine(int?userId) { return(MySqlite.GetAll( "select id, user_id, title, artist, url, comment, created_at from subjects " + "where user_id = ? and is_disabled = 0 " + "order by id asc ", new object[] { userId } )); }
void DeleteRecord(int index) { string novel = chapters[index].novel; string sql = "delete from bookshelf where novel=@novel"; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("novel", novel)); MySqlite.ExecSql(sql, parameters); GetData(); }
private void button_clr_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("将会清空所有要屏蔽的词语,确认吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { string sql = "delete from blackWords"; MySqlite.ExecSql(sql); listView1.Items.Clear(); } }
public void Statistic() { Movies = new List <Movie>(); string name = Path.GetFileNameWithoutExtension(Properties.Settings.Default.DataBasePath).ToLower(); name = "DataBase\\" + name; MySqlite db = new MySqlite(name); Movies = db.SelectMoviesBySql("SELECT * FROM movie"); db.CloseDB(); }
public static bool Replace(int SubjectId, int UserId, int Point, string Comment) { return(MySqlite.Execute( "insert or replace into subject_votes " + "(user_id, subject_id, point, comment, updated_at) values " + "(?,?,?,?,?)", new object[] { UserId, SubjectId, Point, Comment, Utility.GetDatetime() } ) >= 1); }
public bool SaveModel(string ID = "") { string table = ((Main)GetWindowByName("Main")).GetCurrentList(); if (ID == "" && DetailMovie != null && DetailMovie.id.ToUpper() == id.ToUpper()) { InsertMovie(table); return(true); } id = ID; if (DetailMovie != null) { if (DetailMovie.id.ToUpper() != id.ToUpper()) { //修改了原来的识别码 if (string.IsNullOrEmpty(table)) { if (DataBase.SelectMovieByID(ID) != null) { return(false); } DataBase.DeleteByField("movie", "id", DetailMovie.id); DetailMovie.id = id; DataBase.InsertFullMovie(DetailMovie); } else { //修改了清单中的识别码 using (MySqlite mySqlite = new MySqlite("mylist")) { if (mySqlite.SelectMovieBySql($"select * from {table} where id='{ID}'") != null) { return(false); } mySqlite.DeleteByField(table, "id", DetailMovie.id); DetailMovie.id = id; mySqlite.InsertFullMovie(DetailMovie, table); } } } else { InsertMovie(table); } return(true); } return(false); }
public static List <Dictionary <string, object> > GetAllWithMyVote(int?userId) { return(MySqlite.GetAll( "select subjects.id as subject_id, subjects.user_id as user_id, " + "title, artist, url, subjects.comment as subject_comment, " + "subject_votes.comment as vote_comment, point, subject_votes.id as vote_id " + "from subjects " + "left join subject_votes on " + "subject_votes.subject_id = subjects.id " + "where subject_votes.user_id = ? or subject_votes.user_id is null ", new object[] { userId } )); }
/// <summary> /// 查询所有屏蔽关键词 /// </summary> void GetData() { listView1.Items.Clear(); string sql = "select * from blackWords order by date desc"; DataTable table = MySqlite.GetData(sql); ListViewItem[] items = new ListViewItem[table.Rows.Count]; for (int i = 0; i < items.Length; i++) { string[] ss = { table.Rows[i][0].ToString(), table.Rows[i][1].ToString(), table.Rows[i][2].ToString(), table.Rows[i][3].ToString() }; items[i] = new ListViewItem(ss); } listView1.Items.AddRange(items); }
private void button_clear_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("确定清空所有章节记录吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { //书架上面的不删 string sql = "delete from chapters where novel not in (select distinct novel from bookshelf) or webindex not in(select distinct webindex from bookshelf) "; MySqlite.ExecSql(sql); listView1.Items.Clear(); //不是虚拟模式,直接clear就好 listView2.VirtualListSize = 0; //虚拟模式下,需要设置size才能清空 GetChapterCount(); //重新获取 } }
public static bool Create(int?userId, string title, string artist, string url, string comment) { if (IsExist(title, artist)) { return(false); } return(MySqlite.Execute( "insert into subjects " + "(user_id, title, artist, url, comment, created_at) values " + "(?, ?, ?, ?, ?, ?) ", new object[] { userId, title, artist, url, comment, Utility.GetDatetime() } ) >= 1); }
private void InsertMovie(string table) { if (string.IsNullOrEmpty(table)) { DataBase.InsertFullMovie(DetailMovie); } else { using (MySqlite mySqlite = new MySqlite("mylist")) { mySqlite.InsertFullMovie(DetailMovie, table); } } }
public Search() { InitializeComponent(); Width = listView2.Left; comboBox_Source.SelectedIndex = 0; MySqlite.InitDB(); if (!File.Exists(MySqlite.path)) { Tools.CreateTable(); //不存在数据库,创建新表 } UIColors.SetControlColors(this); webTools = new Tools(); //网络请求结束的事件 webTools.HTMLGetCompleted += Tools_HTMLGetCompleted; }
private static void CreateVideoData(string name) { if (!name.EndsWith(".sqlite")) { name += ".sqlite"; } string path = Path.Combine(GlobalVariable.VideoDataPath, name); MySqlite db = new MySqlite(path); db.CreateTable(DataBase.SQLITETABLE_MOVIE); db.CreateTable(DataBase.SQLITETABLE_ACTRESS); db.CreateTable(DataBase.SQLITETABLE_LIBRARY); db.CreateTable(DataBase.SQLITETABLE_JAVDB); db.CloseDB(); }
public void SaveLove() { string table = GetCurrentListFromMain(); if (!string.IsNullOrEmpty(table)) { using (MySqlite mySqlite = new MySqlite("mylist")) { mySqlite.ExecuteSql($"update {table} set favorites={ DetailMovie.favorites} where id='{DetailMovie.id}'"); } } else { DataBase.UpdateMovieByID(DetailMovie.id, "favorites", DetailMovie.favorites, "string"); } }
/// <summary> /// 获得每个小说、每个来源的章节数目统计 /// </summary> void GetChapterCount() { string sql; DataTable table; if (!all) //只显示当前小说 { sql = "select webIndex,count(*) from chapters where novel=@novel GROUP BY webIndex"; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("novel", novel)); table = MySqlite.GetData(sql, parameters); } else //显示所有小说 { sql = "select webIndex,count(*),novel from chapters GROUP BY webIndex,novel ORDER BY novel,webIndex"; table = MySqlite.GetData(sql); if (listView1.Columns.Count == 2) { ColumnHeader header = new ColumnHeader(); header.Text = "小说名"; header.Width = 100; listView1.Columns.Insert(0, header); } } itemsLv1 = new List <ListViewItem>(); sourceIndex = new List <int>(); listView1.Items.Clear(); for (int i = 0; i < table.Rows.Count; i++) { int index = Convert.ToInt32(table.Rows[i][0]); string website = Tools.InitSource(index, false); string[] ss = new string[] { website, table.Rows[i][1].ToString() }; if (all) { ss = new string[] { table.Rows[i][2].ToString(), website, table.Rows[i][1].ToString() } } ; ListViewItem item = new ListViewItem(ss); itemsLv1.Add(item); sourceIndex.Add(index); } listView1.Items.AddRange(itemsLv1.ToArray()); } List <Chapter> chapters; List <ListViewItem> chapterItems; string chapterKeyword = "";
public void Statistic() { Movies = new List <Movie>(); string name = Properties.Settings.Default.DataBasePath.Split('\\').Last().Split('.').First().ToLower(); if (name != "info") { name = "DataBase\\" + name; } MySqlite db = new MySqlite(name); Movies = db.SelectMoviesBySql("SELECT * FROM movie"); db.CloseDB(); AllCount = Movies.Count; UncensoredCount = Movies.Where(arg => arg.vediotype == 1).Count(); CensoredCount = Movies.Where(arg => arg.vediotype == 2).Count(); EuropeCount = Movies.Where(arg => arg.vediotype == 3).Count(); CensoredCountPercent = (int)(100 * CensoredCount / (AllCount == 0 ? 1 : AllCount)); UncensoredCountPercent = (int)(100 * UncensoredCount / (AllCount == 0 ? 1 : AllCount)); EuropeCountPercent = (int)(100 * EuropeCount / (AllCount == 0 ? 1 : AllCount)); ChartValuesCensoredCount = new ChartValues <double>() { CensoredCount }; ChartValuesUnCensoredCount = new ChartValues <double>() { UncensoredCount }; ChartValuesEuropeCount = new ChartValues <double>() { EuropeCount }; PointLabel = chartPoint => string.Format("{0} ({1:P})", chartPoint.Y, chartPoint.Participation); //按识别码显示 LoadID(); LoadGenre(); LoadTag(); LoadActor(); Formatter = value => value.ToString("N"); }
private void button_del_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { string word = listView1.SelectedItems[0].SubItems[0].Text; word = word.Replace("'", "''"); //单引号转义 string date = listView1.SelectedItems[0].SubItems[3].Text; string sql = "delete from blackWords where words=@word and date=@date"; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("word", word)); parameters.Add(new SQLiteParameter("date", date)); MySqlite.ExecSql(sql, parameters); listView1_SelectedIndexChanged(null, null); GetData(); } }
private void button_delete_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("确定删除吗?", "提示", MessageBoxButtons.OKCancel); if (dr == DialogResult.OK) { int index = listView1.SelectedIndices[0]; string sql = "delete from chapters where novel=@novel and webIndex=@web and novel not in (select distinct novel from bookshelf) or webindex not in(select distinct webindex from bookshelf) "; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("novel", novel)); parameters.Add(new SQLiteParameter("web", sourceIndex[index])); MySqlite.ExecSql(sql, parameters); label_novel.Text = "章节管理"; label_novel.Left = (Width - label_novel.Width) / 2; listView1_SelectedIndexChanged(null, null); GetChapterCount(); } }
void GetData() { string sql = "select * from bookshelf order by date desc"; DataTable table = MySqlite.GetData(sql); chapters = new List <Chapter>(); for (int i = 0; i < table.Rows.Count; i++) { Chapter chapter = new Chapter(); chapter.novel = table.Rows[i][0].ToString(); chapter.chapter = table.Rows[i][1].ToString(); chapter.web = Convert.ToInt32(table.Rows[i][2].ToString()); chapter.site = table.Rows[i][3].ToString(); chapter.lastDate = table.Rows[i][4].ToString(); chapters.Add(chapter); } AddList(); }
/// <summary> /// 阅读记录存入数据库,在书架页面会查询 /// </summary> /// <param name="chapter"></param> void UpdateData(Chapter chapter) { //删除原有的 string sql = "delete from bookshelf where novel=@novel"; List <SQLiteParameter> parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("novel", novelName)); MySqlite.ExecSql(sql, parameters); //添加新的记录 sql = "insert into bookshelf values(@novel,@chapter,@webIndex,@site,@date)"; parameters = new List <SQLiteParameter>(); parameters.Add(new SQLiteParameter("novel", chapter.novel)); parameters.Add(new SQLiteParameter("chapter", chapter.chapter)); parameters.Add(new SQLiteParameter("webIndex", Tools.source.ID)); parameters.Add(new SQLiteParameter("site", chapter.site)); parameters.Add(new SQLiteParameter("date", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); MySqlite.ExecSql(sql, parameters); }
public void Create() { int max = number; string savepath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "database", $"sample_{max}.sqlite"); MySqlite db = new MySqlite(savepath, true); db.CreateTable(DataBase.SQLITETABLE_MOVIE); db.CreateTable(DataBase.SQLITETABLE_ACTRESS); db.CreateTable(DataBase.SQLITETABLE_LIBRARY); db.CreateTable(DataBase.SQLITETABLE_JAVDB); db.CloseDB(); List <string> ID = GetID(max); using (MySqlite mySqlite = new MySqlite(savepath, true)) { for (int i = 0; i < max; i++) { Movie movie = new Movie() { id = ID[i], favorites = new Random(Guid.NewGuid().GetHashCode()).Next(0, 6), visits = new Random(Guid.NewGuid().GetHashCode()).Next(0, 100), title = GetSomeText(30, i), runtime = new Random(Guid.NewGuid().GetHashCode()).Next(0, 300), rating = (float)(new Random(Guid.NewGuid().GetHashCode()).Next(0, 100)) / 10, filesize = Math.Abs(5 * 1024 * new Random(Guid.NewGuid().GetHashCode()).Next(0, 1024 * 1024)), subsection = i % 100 == 0 ? "path1;path2" : "", scandate = DateTime.Now.AddDays(-new Random(Guid.NewGuid().GetHashCode()).Next(-500, 500)).ToString("yyyy-MM-dd HH:mm:ss"), otherinfo = DateTime.Now.AddDays(-new Random(Guid.NewGuid().GetHashCode()).Next(-500, 500)).ToString("yyyy-MM-dd HH:mm:ss"), releasedate = DateTime.Now.AddDays(-new Random(Guid.NewGuid().GetHashCode()).Next(-500, 500)).ToString("yyyy-MM-dd"), vediotype = new Random(Guid.NewGuid().GetHashCode()).Next(1, 4), tag = "系列" + new Random(Guid.NewGuid().GetHashCode()).Next(defaultmax), director = "导演" + new Random(Guid.NewGuid().GetHashCode()).Next(defaultmax), studio = "发行商" + new Random(Guid.NewGuid().GetHashCode()).Next(defaultmax) }; movie.genre = GetGenre(movie); movie.actor = GetActor(max); movie.label = GetLabel(max); mySqlite.InsertFullMovie(movie, "movie"); Console.WriteLine(i); } } }
/// <summary> /// 查询屏蔽词语 /// </summary> void GetBlackWords() { blackWords = new List <BlackWord>(); string sql = "select words,insteadWords,type from blackWords order by length(words) desc"; DataTable table = MySqlite.GetData(sql); BlackWord word1; for (int i = 0; i < table.Rows.Count; i++) { word1 = new BlackWord(); string word = table.Rows[i][0].ToString().Trim(); string instead = table.Rows[i][1].ToString().Trim(); string type = table.Rows[i][2].ToString().Trim(); word1.word = word; word1.type = type; word1.instead = instead; blackWords.Add(word1); } }