private void simpleButton1_Click(object sender, EventArgs e) { if (textBox2.Text == "") { MessageBox.Show("新组名不能为空!"); return; } SQLiteConnection conn = new SQLiteConnection(DataPath.DBPath); string sql = string.Format("update Item set GroupName='{0}' where CategoryID='{1}' and GroupID='{2}'", textBox2.Text.Trim(), ID, GroupID); SQLiteCommand comm = new SQLiteCommand(sql, conn); try { conn.Open(); comm.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { conn.Close(); MessageBox.Show(ex.Message); return; } //更新主界面 MainBody form = (MainBody)this.Owner; form.SearchItem(); this.Close(); }
private void btnSave_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("编号和名称不得为空!"); return; } if (alter == true) { success = Alter(); } else { success = Add(); } //更新主界面 if (success) { MainBody form = (MainBody)this.Owner; form.SearchCategory(); this.Close(); } }
private void simpleButton1_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "") { MessageBox.Show("不得为空!"); return; } //查找该组名 string sql1 = string.Format("select GroupName from Item where CategoryID='{0}' and GroupID='{1}'", textBox1.Text, textBox2.Text); SQLiteCommand comm = new SQLiteCommand(sql1, conn); try { conn.Open(); SQLiteDataReader reader = comm.ExecuteReader(); if (reader.HasRows) { reader.Read(); newGroupName = reader.GetString(0); } else { reader.Close(); conn.Close(); MessageBox.Show("没有这个组!"); return; } reader.Close();//不加这句就会造成database is locked conn.Close(); } catch (Exception ex) { conn.Close(); MessageBox.Show(ex.Message); return; } string sql2 = string.Format("update Item set CategoryID='{0}',GroupID='{1}',ItemID='{2}',GroupName='{3}' where CategoryID='{4}' and GroupID='{5}' and ItemID='{6}' and ItemName='{7}'", textBox1.Text.Trim(), textBox2.Text.Trim(), textBox3.Text.Trim(), newGroupName, ID, GroupID, ItemID, ItemName); SQLiteCommand comm1 = new SQLiteCommand(sql2, conn); try { conn.Open(); comm1.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { conn.Close(); MessageBox.Show(ex.Message); return; } //写回主界面 MainBody form = (MainBody)this.Owner; form.SearchItem(); this.Close(); }
private void simpleButton2_Click(object sender, EventArgs e) { if (textBox1.Text == "" || richTextBox1.Text == "" || textBox3.Text == "") { MessageBox.Show("组名、标题和内容不得为空!"); return; } //写数据库 string sql = ""; if (addNew == true) { sql = string.Format("insert into Item(CategoryID,GroupID,GroupName,ItemID,ItemName,ItemSolution,Time) values ('{0}','{1}','{2}','{3}','{4}',@ItemSolution,'{5}')", CategoryID, GroupID, textBox1.Text.Trim(), ItemID, textBox3.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm")); } else if (addNewGroup == true) { sql = string.Format("insert into Item(CategoryID,GroupID,GroupName,ItemID,ItemName,ItemSolution,Time) values ('{0}','{1}','{2}','{3}','{4}',@ItemSolution,'{5}')", CategoryID, GroupID, GroupName, ItemID, textBox3.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm")); } else if (alter == true) { sql = string.Format("update Item set ItemName='{0}',Time='{1}',ItemSolution=@ItemSolution where CategoryID='{2}' and GroupID='{3}' and ItemID='{4}';", textBox3.Text, DateTime.Now.ToString("yyyy-MM-dd HH:mm"), CategoryID, GroupID, ItemID) + "VACUUM;"; } byte[] bWrite = null; byte[] bWrite1 = null; using (MemoryStream ms = new MemoryStream()) { richTextBox1.SaveFile(ms, RichTextBoxStreamType.RichText); bWrite = ms.ToArray(); } using (MemoryStream ms = new MemoryStream()) { using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress)) { zip.Write(bWrite, 0, bWrite.Length); } bWrite1 = ms.ToArray(); } try { conn.Open(); SQLiteCommand comm = new SQLiteCommand(sql, conn); comm.Parameters.Add("@ItemSolution", DbType.Binary).Value = bWrite1; comm.ExecuteNonQuery(); conn.Close(); } catch (Exception ex) { conn.Close(); MessageBox.Show(ex.Message); return; } //写回主界面 MainBody form = (MainBody)this.Owner; form.SearchItem(); this.Close(); }