//注销商品类别 private void btnDeleteCategory_Click(object sender, EventArgs e) { if (dgvCategory.SelectedRows.Count <= 0) { md.MsgDivShow("请选择要注销的商品类别"); return; } if (MessageBox.Show("确定删除该类别吗", "删除商品类别", MessageBoxButtons.OKCancel) == System.Windows.Forms.DialogResult.OK) { //获取类别ID int cId = ((CategoryInfo)dgvCategory.SelectedRows[0].DataBoundItem).CId; ProductInfoBll proBll = new ProductInfoBll(); if (proBll.GetProductInfoCountByCId(cId) > 0) { md.MsgDivShow("抱歉,该类别下有产品,不能删除"); return; } CategoryInfoBll cBll = new CategoryInfoBll(); md.MsgDivShow(cBll.SoftDeleteCategoryByCId(cId) ? "操作成功" : "操作失败", 1); LoadAllCategoryInfoByDelFlag(0); return; } md.MsgDivShow("取消了", 1); }
private void btnOk_Click_1(object sender, EventArgs e) { if (CheckEmpty())//判断所有的文本框不为空 { CategoryInfoBll cBll = new CategoryInfoBll(); CategoryInfo c = new CategoryInfo(); c.CName = txtCName.Text;//名字 c.CNum = txtCNum.Text;//编号 c.CRemark = txtCRemark.Text;//备注 //判断是新增还是修改 if (Temp == 1)//新增 { c.DelFlag = 0; c.SubBy = 1; c.SubTime = System.DateTime.Now;//提交时间 }//修改 else if (Temp == 2) { c.CId = Convert.ToInt32(labId.Text);//id类别 } string msg = cBll.AddOrUpdateCategoryInfo(c, Temp) ? "操作成功" : "操作失败"; md.MsgDivShow(msg, 1, Bind); // md.MsgDivShow(msg, 1); } }
//显示类别信息的方法 private void LoadAllCategoryInfoByDelFlag(int p) { CategoryInfoBll cBll = new CategoryInfoBll(); dgvCategory.AutoGenerateColumns = false;//禁止自动生成列 dgvCategory.DataSource = cBll.GetAllCategoryInfoByDelFlag(p); dgvCategory.ClearSelection(); }
//绑定下拉框的类别数据 private void LoadCategoryInfoByDelFlag(int p) { CategoryInfoBll cBll = new CategoryInfoBll(); List<CategoryInfo> list = cBll.GetAllCategoryInfoByDelFlag(p); list.Insert(0, new CategoryInfo() { CName = "请选择", CId = -1 }); cmbCategory.DataSource = list; cmbCategory.DisplayMember = "CName"; cmbCategory.ValueMember = "CId"; }
//节点树绑定数据 private void LoadTvCategoryByDelFlag(int p) { CategoryInfoBll cbll = new CategoryInfoBll(); List<CategoryInfo> list = cbll.GetAllCategoryInfoByDelFlag(p); for (int i = 0; i < list.Count; i++) { TreeNode tn = tvCategory.Nodes.Add(list[i].CName); //根据商品类别id查找该类别下的所有产品 LoadProductInfoByCId(tn.Nodes, list[i].CId); } }