//················利用timer触发事件········· private void timer1_Tick(object sender, EventArgs e) { TXL_Cats myObj = new TXL_Cats(); tvCats.Nodes.Clear(); _userID = loginfrm.UserID; myObj.UserID = UserID; OleDbDataReader myReader = myObj.GetAllTXLCatsDR(); while (myReader.Read()) { //先清除原先加载的,防止重复加载 TreeNode myNode = new TreeNode(myReader["CatName"].ToString(), 1, 2); TXL_Cats myCat = new TXL_Cats(); myCat.CatId = (int)myReader["CatId"]; myCat.CatName = myReader["CatName"].ToString(); myNode.Tag = myCat; tvCats.Nodes.Add(myNode); } myReader.Close(); //注意修改状态!! this.timer1.Enabled = false; }
//右击事件判断 private void lvPerson_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { TXL_Cats myObj = new TXL_Cats(); myObj.UserID = loginfrm.UserID; if (lvPerson.SelectedIndices != null && lvPerson.SelectedIndices.Count > 0) { //listview添加右键菜单 lvPerson.ContextMenuStrip = contextMenuStrip1; ListView.SelectedIndexCollection c = lvPerson.SelectedIndices; myObj.Name = lvPerson.Items[c[0]].Text; //myObj.Name = lvPerson.Items[(int)lvPerson.SelectedIndices[1]].Text; //myObj.Tel = lvPerson.Items[(int)lvPerson.SelectedIndices[0]].SubItems[1].Text; //myObj.QQ = lvPerson.Items[(int)lvPerson.SelectedIndices[0]].SubItems[2].Text; myObj.CatId = CatID; } OleDbDataReader myReader = myObj.GetPersonID(); while (myReader.Read()) { //此段目的是获得PersonID!! _personID = (int)myReader["PersonID"]; } myReader.Close(); } }
//删除分组 private void DeleteCats_Click(object sender, EventArgs e) { System.Windows.Forms.DialogResult dr; dr = MessageBox.Show(this, "删除分组会将分组内的联系人删除!确定要删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); switch (dr) { case System.Windows.Forms.DialogResult.Yes: TXL_Cats myObj = new TXL_Cats(); _catName = this.tvCats.SelectedNode.Text; _userID = loginfrm.UserID; myObj.UserID = UserID; myObj.CatName = CatName; myObj.Delete(); _catID = myObj.GetCatID(); TXL_Persons myPerson = new TXL_Persons(); myPerson.CatId = CatID; myPerson.UserID = UserID; MessageBox.Show("删除成功"); this.tvCats.SelectedNode.Remove(); break; } }
private void AddPersons_Load(object sender, EventArgs e) { //加载分类 TXL_Cats myCats = new TXL_Cats(); _userID = loginfrm.UserID; myCats.UserID = UserID; CatsText.DisplayMember = "CatName"; CatsText.ValueMember = "CatId"; CatsText.DataSource = myCats.GetAllTXLCatsDS().Tables[0]; if (whichBtn == true) { SuerBtn.Text = "添加联系人"; this.Text = "添加联系人"; } else { this.Text = "修改联系人"; SuerBtn.Text = "修改联系人"; //在文本框中赋值 TXL_Persons myPerson = new TXL_Persons(); _personId = mainfrm.PersonID; myPerson.PersonId = PersonId; OleDbDataReader myReader = myPerson.GetAllPerson(); while (myReader.Read()) { _personName = myReader["PersonName"].ToString(); _catId = int.Parse(myReader["CatId"].ToString()); _personTel = myReader["PersonTel"].ToString(); _personCel = myReader["PersonCel"].ToString(); _personQQ = myReader["PersonQQ"].ToString(); _personAddress = myReader["PersonAddress"].ToString(); _remark = myReader["Remark"].ToString(); myPerson.CatId = CatId; _cats = myPerson.GetCatName(); UserNameText.Text = PersonName; CatsText.Text = Cats; QQText.Text = PersonQQ; PersonTelText.Text = PersonTel; PersonCellText.Text = PersonCel; AddressText.Text = PersonAddress; RemarkText.Text = Remark; } } }
////添加和修改不能重复! //public bool Check() //{ //} //添加分组 private void AddCatsBtn_Click(object sender, EventArgs e) { TXL_Cats myObj = new TXL_Cats(); _userID = loginfrm.UserID; myObj.UserID = UserID; myObj.CatName = CatNameText.Text; if (whichBtn == true) { myObj.Add(); MessageBox.Show("添加成功!"); } else { _catID = mainfrm.CatID; myObj.CatId = CatID; myObj.Update(); MessageBox.Show("更改成功!"); } }
//删除联系人 private void DeletePerson_Click(object sender, EventArgs e) { System.Windows.Forms.DialogResult dr; dr = MessageBox.Show(this, "确定要删除吗?", "删除", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); switch (dr) { case System.Windows.Forms.DialogResult.Yes: TXL_Cats myObj = new TXL_Cats(); myObj.PersonID = PersonID; myObj.DeletePerson(); MessageBox.Show("删除成功"); //加上判断防止出现InvalidArgument=“0”的值对于“index”无效错误 if (lvPerson.SelectedIndices != null && lvPerson.SelectedIndices.Count > 0) { lvPerson.Items.Remove(lvPerson.Items[Row]); } break; } }
//鼠标单击树节点发生 private void tvCats_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { TXL_Cats myObj = (TXL_Cats)e.Node.Tag; lvPerson.Items.Clear(); TXL_Persons myPerson = new TXL_Persons(); OleDbDataReader myReader = myPerson.GetAllTXLCatsDR(myObj.CatId); //得到catID _catID = (int)myObj.CatId; while (myReader.Read()) { ListViewItem myItem = new ListViewItem(); myItem.Text = myReader["PersonName"].ToString(); myItem.ImageIndex = 0; myItem.SubItems.Add(myReader["PersonTel"].ToString()); myItem.SubItems.Add(myReader["PersonQQ"].ToString()); lvPerson.Items.Add(myItem); } myReader.Close(); }
//treeview判断右键 打开窗口修改分组名 private void tvCats_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { if (tvCats.SelectedNode == null) { tvCats.ContextMenuStrip = null; //return; } else { //treeview添加右键菜单 tvCats.ContextMenuStrip = contextMenuStrip2; _catName = this.tvCats.SelectedNode.Text; _userID = loginfrm.UserID; TXL_Cats myObj = new TXL_Cats(); myObj.UserID = UserID; myObj.CatName = CatName; _catID = myObj.CatIds(); } } }
private void SuerBtn_Click(object sender, EventArgs e) { if (whichBtn == true) { //获取CatID号 int _catId = (int)CatsText.SelectedValue; TXL_Persons myObj = new TXL_Persons(); _personName = UserNameText.Text; _personTel = PersonTelText.Text; _personQQ = QQText.Text; _personAddress = AddressText.Text; myObj.UserID = UserID; myObj.Name = PersonName; myObj.Tel = PersonTel; myObj.QQ = PersonQQ; myObj.Address = PersonAddress; myObj.CatId = _catId; myObj.AddPersons(); MessageBox.Show("添加成功"); } else { TXL_Cats myCats = new TXL_Cats(); _cats = CatsText.Text; _userID = loginfrm.UserID; myCats.CatName = Cats; myCats.UserID = UserID; _catId = myCats.CatIds(); TXL_Persons myPerson = new TXL_Persons(); _personId = mainfrm.PersonID; _personName = UserNameText.Text; _personQQ = QQText.Text; _personTel = PersonTelText.Text; _personCel = PersonCellText.Text; _personAddress = AddressText.Text; _remark = RemarkText.Text; myPerson.PersonId = PersonId; myPerson.CatId = CatId; myPerson.PersonName = PersonName; myPerson.QQ = PersonQQ; myPerson.Tel = PersonTel; myPerson.PersonCel = PersonCel; myPerson.Address = PersonAddress; myPerson.Remark = Remark; myPerson.ChangPerson(); MessageBox.Show("修改成功!"); } }
private void AddPersons_Load(object sender, EventArgs e) { //加载分类 TXL_Cats myCats = new TXL_Cats(); _userID = loginfrm.UserID; myCats.UserID = UserID; CatsText.DisplayMember = "CatName"; CatsText.ValueMember = "CatId"; CatsText.DataSource=myCats.GetAllTXLCatsDS().Tables[0]; if (whichBtn == true) { SuerBtn.Text = "添加联系人"; this.Text = "添加联系人"; } else { this.Text = "修改联系人"; SuerBtn.Text = "修改联系人"; //在文本框中赋值 TXL_Persons myPerson = new TXL_Persons(); _personId = mainfrm.PersonID; myPerson.PersonId = PersonId; OleDbDataReader myReader = myPerson.GetAllPerson(); while (myReader.Read()) { _personName = myReader["PersonName"].ToString(); _catId = int.Parse(myReader["CatId"].ToString()); _personTel=myReader["PersonTel"].ToString(); _personCel=myReader["PersonCel"].ToString(); _personQQ=myReader["PersonQQ"].ToString(); _personAddress=myReader["PersonAddress"].ToString(); _remark = myReader["Remark"].ToString(); myPerson.CatId = CatId; _cats = myPerson.GetCatName(); UserNameText.Text = PersonName; CatsText.Text = Cats; QQText.Text = PersonQQ; PersonTelText.Text = PersonTel; PersonCellText.Text = PersonCel; AddressText.Text = PersonAddress; RemarkText.Text = Remark; } } }