Skip to content

Commit

Permalink
--SQLiteHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjohnsan committed Nov 22, 2015
1 parent 14b6274 commit fc59f37
Show file tree
Hide file tree
Showing 24 changed files with 1,962 additions and 1,945 deletions.
Binary file modified YQSQLite.suo
Binary file not shown.
Binary file modified YQSQLite/Data/YQ.db
Binary file not shown.
22 changes: 12 additions & 10 deletions YQSQLite/MainFrm.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Microsoft.Win32;
Expand All @@ -13,7 +9,6 @@
using System.Runtime.Serialization;
using System.Net;
using System.Threading;
using System.Transactions;
using System.Data.SQLite;


Expand Down Expand Up @@ -532,7 +527,9 @@ public void SaveToDB(DataTable dt)
/* todo:sqlite没有提供批量插入的机制,需要通过事务处理 更新所有数据
* http://www.cnblogs.com/hbjohnsan/p/4169612.html
* Eorr 数据库加了锁,执行不了自己的代码。
*
*/

string connStr = @"data source=E:\YQSQLite\YQSQLite\Data\YQ.db";
using (SQLiteConnection conn = new SQLiteConnection(connStr))
{
Expand All @@ -546,10 +543,14 @@ public void SaveToDB(DataTable dt)
{
foreach (DataRow dr in dt.Rows)
{
cmd.CommandText = @"insert or ignore into RssItem values ('"+Int32.Parse(dr[0].ToString()) +"','"
+dr[1].ToString()+"','"+dr[2].ToString()+"','"
+dr[3].ToString()+"','"+Convert.ToDateTime(dr[4].ToString())+"','"
+dr[5].ToString()+"','"+dr[6].ToString()+"')";
cmd.CommandText = @"insert or ignore into RssItem values (" + Int32.Parse(dr[0].ToString()) + ",'"
+ dr[1].ToString() + "','" + dr[2].ToString() + "','"
+ dr[3].ToString() + "','" + dr[4].ToString() + "','"
+ dr[5].ToString() + "','" + dr[6].ToString() + "')";

//改进一下,减少两个字段 没有了主键,将都会插入
//cmd.CommandText = @"insert or ignore into RssItem(ChannelCode,Title,Link,PubDate,IsRead) values ('"+dr[1].ToString()+"','"+dr[2].ToString()+"','"
// + dr[3].ToString() + "','" + dr[4].ToString().Trim() + "','"+dr[5].ToString()+"')";
cmd.ExecuteNonQuery();

}
Expand All @@ -564,11 +565,12 @@ public void SaveToDB(DataTable dt)
}
}
}




}
//该字符串未被识别为有效的 DateTime。 把数据库的datatime类型改为varchar类型,在程序中依然是DataTime类型

private void MainFrm_FormClosing(object sender, FormClosingEventArgs e)
{
Expand Down
8 changes: 4 additions & 4 deletions YQSQLite/NavFrm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ where p.ChannelCode.StartsWith(navurl.Code)
// rsit.Site = item.Site;
rsit.Title = item.Title;
rsit.Link = item.Link;
rsit.PubDate = item.PubDate;
rsit.PubDate =Convert.ToDateTime(item.PubDate);
rsit.IsRead = item.IsRead;
rsit.Content = item.Content;
ListViewItem lv = new ListViewItem(new string[] { rsit.Title, rsit.PubDate.ToString("MM-dd HH:mm:ss"), rsit.ChannelCode });
ListViewItem lv = new ListViewItem(new string[] { rsit.Title, rsit.PubDate.ToString("yyyy-MM-dd HH:mm:ss"), rsit.ChannelCode });
lv.Tag = rsit;
mf.SelectFrmListViewReload(lv);
}
Expand Down Expand Up @@ -185,11 +185,11 @@ private void Nomal_GetRssXml(NavUrl navurl)
{
RssItem it = new RssItem(maxId, navurl.Code, result.Title.Trim(), result.Link, Convert.ToDateTime(result.PubDate), "F", "");

ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("MM-dd HH:mm:ss"), navurl.Code });
ListViewItem lv = new ListViewItem(new string[] { it.Title, it.PubDate.ToString("yyyy-MM-dd HH:mm:ss"), navurl.Code });
lv.Tag = it;
mf.SelectFrmListViewReload(lv);
//方法二:在DataSet中添加行,然后一次提交到库
mf.DS.RssItem.AddRssItemRow(it.RssItemID, it.ChannelCode, it.Title, it.Link, it.PubDate, it.IsRead, it.Content);
mf.DS.RssItem.AddRssItemRow(it.RssItemID, it.ChannelCode, it.Title, it.Link, it.PubDate.ToString(), it.IsRead, it.Content);
}
}
}
Expand Down
16 changes: 3 additions & 13 deletions YQSQLite/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 1 addition & 9 deletions YQSQLite/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="YQSQLite.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="yqConnectionString" Type="(Connection string)" Scope="Application">
<Setting Name="YQConnectionString" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;data source=E:\YQSQLite\YQSQLite\Data\YQ.db&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.SQLite&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">data source=E:\YQSQLite\YQSQLite\Data\YQ.db</Value>
</Setting>
<Setting Name="YQConnectionString1" Type="(Connection string)" Scope="Application">
<DesignTimeValue Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;SerializableConnectionString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;ConnectionString&gt;data source=E:\YQSQLite\YQSQLite\Data\YQ.db&lt;/ConnectionString&gt;
&lt;ProviderName&gt;System.Data.SQLite.EF6&lt;/ProviderName&gt;
&lt;/SerializableConnectionString&gt;</DesignTimeValue>
<Value Profile="(Default)">data source=E:\YQSQLite\YQSQLite\Data\YQ.db</Value>
</Setting>
Expand Down
4 changes: 2 additions & 2 deletions YQSQLite/WaitEdit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void ReLoad()
RssItem rssit = new RssItem();
rssit.Title = it.Title;
// rssit.Site = it.Site;
rssit.PubDate = it.PubDate;
rssit.PubDate =Convert.ToDateTime(it.PubDate);
rssit.Link = it.Link;
rssit.Content = it.Content;
rssit.IsRead = it.IsRead;
Expand All @@ -56,7 +56,7 @@ public void AddRssItem(int itemID)
RssItem rsit = new RssItem();
// rsit.Site = row.Site;
rsit.Title = row.Title;
rsit.PubDate = row.PubDate;
rsit.PubDate =Convert.ToDateTime(row.PubDate);
rsit.Link = row.Link;
rsit.IsRead = row.Link;
rsit.Content = row.Content;
Expand Down
Loading

0 comments on commit fc59f37

Please sign in to comment.