private void LoadCategoryInfoByDelFlag(int p)
 {
     CategoryInfoBLL bll = new CategoryInfoBLL();
     List<CategoryInfo> list = new List<CategoryInfo>();
     list = bll.GetCategoryInfoByDelFlag(p);
     list.Insert(0, new CategoryInfo() { CatName = "请选择", CatId = -1 });
     cmbCategory.DataSource = list;
     cmbCategory.DisplayMember = "CatName";
     cmbCategory.ValueMember = "CatId";
 }
 private void LoadCategoryInfoByDelFlag(int p)
 {
     CategoryInfoBLL bll = new CategoryInfoBLL();
     List<CategoryInfo> list = bll.GetCategoryInfoByDelFlag(p);
     for(int i=0; i < list.Count; i++)
     {
         TreeNode tn = tvCategory.Nodes.Add(list[i].CatName);
         LoadProductInfoByCatId(list[i].CatId, tn.Nodes);
     }
 }
        private void LoadCategoryInfoByDelFlag(int p)
        {

            CategoryInfoBLL bal = new CategoryInfoBLL();
            dgvCategoryInfo.AutoGenerateColumns = false;
            dgvCategoryInfo.DataSource = bal.GetCategoryInfoByDelFlag(p);
            dgvCategoryInfo.SelectedRows[0].Selected = false;

            
        }
 private void LoadCategoryInfoByDelFlagToCmb(int p)
 {
     CategoryInfoBLL bal = new CategoryInfoBLL();
     dgvCategoryInfo.AutoGenerateColumns = false;
     List<CategoryInfo> list = bal.GetCategoryInfoByDelFlag(p);
     list.Insert(0, new CategoryInfo() { CatId = -1, CatName = "请选择" });
     cmbCategory.DataSource = list;
     cmbCategory.DisplayMember = "CatName";
     cmbCategory.ValueMember = "CatId";
 }
 private void benDeleteCategory_Click(object sender, EventArgs e)
 {
     if(dgvCategoryInfo.SelectedRows.Count<=0)
     {
         MessageBox.Show("请选择要删除的行");
         return;
     }
     if(DialogResult.OK == MessageBox.Show("删除类别","Are you sure?",MessageBoxButtons.OKCancel,MessageBoxIcon.Question))
     {
         int id = Convert.ToInt32(dgvCategoryInfo.SelectedRows[0].Cells[0].Value.ToString());
         ProductInfoBLL bll = new ProductInfoBLL();
         int r = bll.GetProductInfoCountByCatId(id);
         if(r > 0)
         {
             MessageBox.Show("该类别有产品,不能删除");
             return;
         }
         CategoryInfoBLL cbll = new CategoryInfoBLL();
         string msg = cbll.SoftDeleteCategoryInfoByCatId(id) ? "操作成功" : "操作失败";
         MessageBox.Show(msg);
         LoadCategoryInfoByDelFlag(0);
     }
     
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     if(CheckEmpty())
     {
         CategoryInfo ct = new CategoryInfo();
         ct.CatName = txtCName.Text;
         ct.CatNum = Convert.ToInt32(txtCNum.Text);
         ct.Remark = txtCRemark.Text;
         if(this.Tp == 1)
         {
             ct.DelFlag = 0;
             ct.SubBy = 1;
             ct.SubTime = DateTime.Now;
         }
         else if(this.Tp == 2)
         {
             ct.CatId = Convert.ToInt32(labId.Text);
         }
         CategoryInfoBLL bll = new CategoryInfoBLL();
         string msg = bll.SaveCategoryInfo(ct, this.Tp) ? "操作成功" : "操作失败";
         MessageBox.Show(msg);
         this.Close();
     }
 }
 //UpdateProductCategory
 private void btnUpdateCategory_Click(object sender, EventArgs e)
 {
     if(dgvCategoryInfo.SelectedRows.Count>0)
     {
         //选中行后获取id
         //根据id获取该对象
         int id = Convert.ToInt32(dgvCategoryInfo.SelectedRows[0].Cells[0].Value.ToString());
         //根据id去数据库查询
         CategoryInfoBLL bll = new CategoryInfoBLL();
         CategoryInfo ct = bll.GetCategoryInfoById(id);
         if(ct !=null)
         {
             mea.Obj = ct;
             LoadFrmChangeCategoryInfo(2);
         }
     }
     else
     {
         MessageBox.Show("please select!!");
     }
     
 }