private void InitSelectClass() { var classAlist = new BLL.ClassAModelBLL().GetAll(); List <Models.ClassBModel> classBlist = new BLL.ClassBModelBLL().GetAll(); //控件列表 List <Controls.MainClassPanel> classCtrlList = new List <Controls.MainClassPanel>(); foreach (var classA in classAlist) //循环主类 { List <Models.ClassBModel> ClassBList = classBlist.FindAll(s => s.ClassA == classA.ClassName); //选择某一子类 List <RadioButton> roomControl = new List <RadioButton>(); var floorPanel = new Controls.MainClassPanel { ClassAname = classA.ClassName, Dock = DockStyle.Top, AutoSize = true }; floorPanel.comboBox1.DataSource = ClassBList; floorPanel.comboBox1.DisplayMember = "classB"; floorPanel.comboBox1.ValueMember = "classB"; classCtrlList.Add(floorPanel); } if (this.InvokeRequired) { this.BeginInvoke(new MethodInvoker(delegate { panelRoomList.Controls.AddRange(classCtrlList.ToArray()); })); } else { panelRoomList.Controls.AddRange(classCtrlList.ToArray()); } }
private void btnDel_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("确认要删除所选内容吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); if (result == DialogResult.OK) { var r = new BLL.ClassBModelBLL().DeleteById(Convert.ToInt16(lbID.Text)); if (r > 0) { MessageBox.Show("删除成功!"); BindData(); } } }
private void saveClassB(string classA, string classB) { var canInsert = new BLL.ClassBModelBLL().GetByClassName(classA, classB); if (canInsert == null) { Models.ClassBModel info = new ClassBModel() { ClassA = classA, ClassB = classB, CreateTime = DateTime.Now }; new BLL.ClassBModelBLL().Add(info); } }
private void btnAdd_Click(object sender, EventArgs e) { string errMsg = ""; if (cbAddClassA.SelectedValue == null) { errMsg += "请选择一个主分类!\r\n"; } if (tbClassNameAdd.Text == "") { errMsg += "子类名称不能为空!\r\n"; } if (errMsg != "") { MessageBox.Show(errMsg); return; } var canInsert = new BLL.ClassBModelBLL().GetByClassName(cbAddClassA.SelectedValue.ToString(), tbClassNameAdd.Text); if (canInsert != null) { MessageBox.Show("不能添加重复的类别名称!"); return; } var info = new Models.ClassBModel { ClassA = cbAddClassA.SelectedValue.ToString(), ClassB = tbClassNameAdd.Text, ClassNote = tbClassNoteAdd.Text, CreateTime = DateTime.Now }; int result = new BLL.ClassBModelBLL().Add(info); if (result > 0) { MessageBox.Show("添加成功"); BindData(); } }
private void btnEdit_Click(object sender, EventArgs e) { string errMsg = ""; if (cbEditClassA.SelectedValue == null) { errMsg += "请选择一个主分类!\r\n"; } if (tbClassNameEdit.Text == "") { errMsg += "子类名称不能为空!\r\n"; } if (errMsg != "") { MessageBox.Show(errMsg); return; } var info = new Models.ClassBModel { Id = Convert.ToInt32(lbID.Text), ClassA = cbEditClassA.SelectedValue.ToString(), ClassB = tbClassNameEdit.Text, ClassNote = tbClassNoteEdit.Text, CreateTime = DateTime.Now }; int result = new BLL.ClassBModelBLL().Update(info); if (result > 0) { MessageBox.Show("更新成功!"); BindData(); } }