public static List<AccountInfo> getAllAccount() { string conn_str = "Data Source=" + path + pwd_str; List<AccountInfo> infolist = new List<AccountInfo>(); SQLiteConnection conn = new SQLiteConnection(conn_str); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); //查询表 String sql = "Select id,BlogUrl,Provider,BlogName,AccountName,Password from " + tablename; cmd.CommandText = sql; cmd.Connection = conn; SQLiteDataReader datareader = cmd.ExecuteReader(); while (datareader.Read()) { AccountInfo info = new AccountInfo(); info.url = datareader.GetString(datareader.GetOrdinal("BlogUrl")); info.username = datareader.GetString(datareader.GetOrdinal("AccountName")); info.password = datareader.GetString(datareader.GetOrdinal("Password")); info.provider = datareader.GetString(datareader.GetOrdinal("Provider")); info.account_id = datareader.GetInt32(datareader.GetOrdinal("id")) + ""; info.blogname = datareader.GetString(datareader.GetOrdinal("BlogName")); infolist.Add(info); } conn.Close(); return infolist; }
public static AccountInfo getAccountById(string account_id) { string conn_str = "Data Source=" + path + pwd_str; SQLiteConnection conn = new SQLiteConnection(conn_str); conn.Open(); SQLiteCommand cmd = new SQLiteCommand(); String sql = "Select Provider,BlogName,AccountName,Password from " + tablename +" where id="+account_id; cmd.CommandText = sql; cmd.Connection = conn; SQLiteDataReader datareader = cmd.ExecuteReader(); AccountInfo account = new AccountInfo(); while (datareader.Read()) { account.provider = datareader.GetString(datareader.GetOrdinal("Provider")); account.username = datareader.GetString(datareader.GetOrdinal("AccountName")); account.password = datareader.GetString(datareader.GetOrdinal("Password")); account.blogname = datareader.GetString(datareader.GetOrdinal("BlogName")); account.account_id = account_id; } return account; }
public void changeAccount(String id) { curinfo = DataMgr.getAccountById(id); if (curinfo.provider != "") { blog = BlogFactory.createBlogger(curinfo.provider); blog.authenticate(curinfo.username, curinfo.password); titlelabel.Text = curinfo.blogname; } else MessageBox.Show("切换账户出错!\r\n"); }
private void okbtn_Click(object sender, EventArgs e) { String key = contentlist.SelectedItems[0].Name; if (catagorylist.SelectedItems[0].Index >= 2) { //设置当前的Catagory catagory = OpenCatagory.Blog; String key1 = catagorylist.SelectedItems[0].Name; int idx1 = int.Parse(key1.Trim()); //设置当前的Account curinfo = infolist[idx1]; int idx = int.Parse(key.Trim()); postinfo = new PostInfo(); postinfo.title = posts.ElementAt(idx).Title; JoeBlogs.Post p = blog.getPostById(posts.ElementAt(idx).PostID ); postinfo.text = p.Body; postinfo.postid = posts.ElementAt(idx).PostID; postinfo.status = BlogStatus.Old; } else if (catagorylist.SelectedItems[0].Index == 1) { catagory = OpenCatagory.Recently; int idx = int.Parse(key.Trim()); RecentInfo recent = recentlist[idx]; //设置account curinfo = DataMgr.getAccountById(recent.accountid); //设置当前的PostInfo postinfo = new PostInfo(); postinfo.title = recent.title; blog = BlogFactory.createBlogger(curinfo.provider); JoeBlogs.Post p = blog.getPostById(recent.postid); postinfo.text = p.Body; postinfo.postid = recent.postid; postinfo.status = BlogStatus.Old; } else { catagory = OpenCatagory.Draft; int idx = int.Parse(key.Trim()); DraftInfo draft = draftlist[idx]; postinfo = new PostInfo(); postinfo.title = draft.title; postinfo.text = draft.text; postinfo.status = BlogStatus.New; curinfo = DataMgr.getAccountById(draft.accountid); } this.DialogResult = DialogResult.OK; this.Close(); }
private void openbtn_Click(object sender, EventArgs e) { List<AccountInfo> infolist = DataMgr.getAllAccount(); List<DraftInfo> draftlist = DataMgr.getAllDraft(); List<RecentInfo> recentlist = DataMgr.getAllRecent(); if ((infolist == null) || (infolist.Count == 0)) MessageBox.Show("请先在博客设置中添加博客账户"); else { OpenBlogDlg openDlg = new OpenBlogDlg(infolist, draftlist, recentlist); if (openDlg.ShowDialog() == DialogResult.OK) { if (openDlg.Catagory == OpenCatagory.Blog) { //修改当前的IBlog 和 账户 blog = openDlg.Blog; curinfo = openDlg.Account; titlelabel.Text = curinfo.blogname; postinfo = openDlg.Post; titlebox.Text = postinfo.title; editor.HtmlText = postinfo.text; status = postinfo.status; } } } }