/// <summary> /// 加载datatable /// </summary> public void dataLoad() { this.dataGridView1.DataSource = ""; NewFolder1.PropertyClass propertyClass = new NewFolder1.PropertyClass(); propertyClass.dataLoad(); this.dataGridView1.DataSource = propertyClass.dataLoad(); }
/// <summary> /// 动态添加listview项 /// </summary> public void ClassifyView() { this.listClassify.Items.Clear(); NewFolder1.PropertyClass propertyClass = new NewFolder1.PropertyClass(); DataTable dt = propertyClass.SelectListByWhere(""); foreach (DataRow table in dt.Rows) { ListViewItem item = new ListViewItem(table["CalssName"].ToString()); item.SubItems.Add(table["ClassID"].ToString()); this.listClassify.Items.Add(item); } }
/// <summary> /// 单击节点事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void listNode_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { this.dataGridView1.DataSource = ""; NewFolder1.PropertyClass propertyClass = new NewFolder1.PropertyClass(); this.dataGridView1.DataSource = propertyClass.SetPro(e.Node.Text); if (this.txtF_proID.Text == "") { this.btn.Text = "添加"; } else { this.btn.Text = "修改"; } }
/// <summary> /// 确定保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnKeep_Click(object sender, EventArgs e) { NewFolder1.PropertyClass propertyClass = new NewFolder1.PropertyClass(); switch (ascertain) { case "无": MessageBox.Show("请选择添加,修改或删除!!!"); break; case "添加": propertyClass.ClassID = this.txtClassID.Text; propertyClass.ClassNAme = this.txtClassName.Text; if (propertyClass.Add()) { MessageBox.Show("添加成功!"); this.txtClassID.Text = ""; this.txtClassName.Text = ""; this.txtClassID.ReadOnly = true; ClassifyView(); } else { MessageBox.Show("添加失败!"); } break; case "修改": if (this.txtClassID.Text == "") { MessageBox.Show("请选择你要修改的项!"); } else { if (this.txtClassName.Text == "") { MessageBox.Show("类型名不能为空!"); } else { propertyClass.ClassID = this.txtClassID.Text; propertyClass.ClassNAme = this.txtClassName.Text; if (propertyClass.Update()) { MessageBox.Show("修改成功!"); this.txtClassID.Text = ""; this.txtClassName.Text = ""; ClassifyView(); } else { MessageBox.Show("修改失败!"); } } } break; case "删除": if (this.txtClassID.Text == "") { MessageBox.Show("请选择你要删除的项!"); } else { if (propertyClass.Delete(this.txtClassID.Text)) { MessageBox.Show("删除成功!"); this.txtClassID.Text = ""; this.txtClassName.Text = ""; ClassifyView(); } else { MessageBox.Show("删除失败!"); } } break; } }