private void button1_Click(object sender, EventArgs e) { string tagNameString = textBox1.Text.ToString(); if (tagNameString != null && tagNameString.Trim().Length > 0) { Tags tags = new Tags(); tags.tagName = tagNameString; tags.tagItemCount = 0; tags.tagFatherId = 0; tags.tagCreateTime = DateTime.Now; tags.UserId = InfoSource.curuser.UserId; InfoSource.AddTags(tags); //更新tag标签分类的TreeView; DataOperation insertTag = new DataOperation(); int flag = insertTag.InsertNewTags(tags); if(flag == 0) MessageBox.Show("该标签已经存在!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); else if(flag == -1) MessageBox.Show("插入标签失败!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); else { tags.tagId = flag; MessageBox.Show("创建标签成功!", "", MessageBoxButtons.OK, MessageBoxIcon.Information); InfoSource.AddTags(tags); } } else { MessageBox.Show("标签不能为空格或空字符.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
//���ӱ�ǩ public static void AddTags(Tags tag) { _TagsList.Add(tag); }
public ArrayList GetTagListByItemId(int itemid) { ArrayList tagslist = new ArrayList(); string sql = "SELECT Tags.tag_id, Tags.tag_name,Tags.tag_fatherid,Tags.tag_createtime, Tags.tag_itemcount,Tags.acc_id" + "FROM Tags, Item_Tags WHERE Tags.tag_id = Item_Tags.tag_id AND Item_Tags.ite_id =" + itemid.ToString(); using (DbTransaction transaction = connection.BeginTransaction()) { try { using (SQLiteDataReader reader = dataop.ExecuteReader(sql, null)) { if (reader.HasRows) { while (reader.Read()) { Tags newtags = new Tags(); newtags.tagId = reader.GetInt32(0); newtags.tagName = reader.GetString(1); newtags.tagFatherId = reader.GetInt32(2); newtags.tagCreateTime = reader.GetDateTime(3); newtags.tagItemCount = reader.GetInt32(4); newtags.UserId = reader.GetInt32(5); tagslist.Add(newtags); } } } transaction.Commit(); } catch { transaction.Rollback(); throw; } return tagslist; } }
public int InsertNewTags(Tags newtags) { int flag = 0; if (TagIsExistByName(newtags.tagName) != 0) return flag; string sql = "INSERT INTO Tags(tag_name,tag_fatherid,tag_createtime,tag_itemcount,acc_id)" + "values(@tagname,@tagfatherid,@tagcreatetime,@tagitemcount,@userid)"; using (DbTransaction transaction = connection.BeginTransaction()) { try { SQLiteParameter[] parameters = new SQLiteParameter[]{ new SQLiteParameter("@tagname", newtags.tagName), new SQLiteParameter("@tagfatherid", newtags.tagFatherId), new SQLiteParameter("@tagcreatetime",newtags.tagCreateTime), new SQLiteParameter("@tagitemcount", newtags.tagItemCount), new SQLiteParameter("@userid", newtags.UserId) }; dataop.ExecuteNonQuery(sql, parameters); transaction.Commit(); flag = TagIsExistByName(newtags.tagName); } catch { flag = -1; transaction.Rollback(); throw; } return flag; } }
public ArrayList GetAllTagsByUserid(int userid) { ArrayList tagslist = new ArrayList(); string sql = "SELECT * FROM Tags WHERE acc_id=" + userid.ToString(); using (DbTransaction transaction = connection.BeginTransaction()) { try { using (SQLiteDataReader reader = dataop.ExecuteReader(sql, null)) { if (reader.HasRows) { while (reader.Read()) { Tags newtags = new Tags(); newtags.tagId = reader.GetInt32(0); newtags.tagName = reader.GetString(1); newtags.tagFatherId = reader.GetInt32(2); newtags.tagCreateTime = reader.GetDateTime(3); newtags.tagItemCount = reader.GetInt32(4); newtags.UserId = reader.GetInt32(5); tagslist.Add(newtags); } } } transaction.Commit(); } catch { transaction.Rollback(); throw; } return tagslist; } }