private void LoadProductInfoByDelFlag(int p)
 {
     ProductInfoBLL bll = new ProductInfoBLL();
     dgvProduct.AutoGenerateColumns = false;
     dgvProduct.DataSource = bll.GetProductInfoByDelFlag(p);
     dgvProduct.SelectedRows[0].Selected = false;
 }
 private void LoadProductInfoByCatId(int p, TreeNodeCollection tnc)
 {
     ProductInfoBLL bll = new ProductInfoBLL();
     List<ProductInfo> list = bll.GetProductInfoByCatId(p);
     for(int i=0; i<list.Count; i++)
     {
         tnc.Add(list[i].ProName + "====="+list[i].ProPrice+"元");
     }
 }
 private void btnOk_Click(object sender, EventArgs e)
 {
     if(CheckEmpty())
     {
         ProductInfo pro = new ProductInfo();
         pro.CatId = Convert.ToInt32(cmbCategory.SelectedValue);
         pro.ProCost = Convert.ToDecimal(txtCost.Text);
         pro.ProName = txtName.Text;
         pro.ProNum = txtNum.Text;
         pro.ProPrice = Convert.ToDecimal(txtPrice.Text);
         pro.ProSpell = txtSpell.Text;
         pro.ProUnit = txtUnit.Text;
         pro.Remark = txtRemark.Text;
         
         if(this.Tp == 3)
         {
             pro.DelFlag = 0;
             pro.SubBy = 1;
             pro.SubTime = System.DateTime.Now;
         }
         
         else if(this.Tp == 4)
         {
             pro.ProId = Convert.ToInt32(labId.Text);
         }
         ProductInfoBLL bll = new ProductInfoBLL();
         if(bll.SaverProduct(pro,this.Tp))
         {
             MessageBox.Show("操作失败");
         }
         else
         {
             MessageBox.Show("操作成功");
         }
         this.Close();
     }
 }
 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);
     }
     
 }
 //search for id and alphaet
 private void txtSearch_TextChanged(object sender, EventArgs e)
 {
     if(string.IsNullOrEmpty(txtSearch.Text))
     {
         LoadProductInfoByDelFlag(0);
         return;
     }
     int n = 0;
     if(char.IsLetter(txtSearch.Text[0]))
     {
         //the first text is alphaet
         n = 1;
     }
     else
     {
         //the first is number
         n = 2;
     }
     ProductInfoBLL bll = new ProductInfoBLL();
     dgvProduct.AutoGenerateColumns = false;
     dgvProduct.DataSource = bll.GetProductInfoBySpellOrNum(txtSearch.Text, n);
     if(dgvProduct.SelectedRows.Count > 0)
     {
         dgvProduct.SelectedRows[0].Selected = false;
     }
 }
 private void txtSearch_TextChanged(object sender, EventArgs e)
 {
     //获取文本框的内容
     string txt = txtSearch.Text;
     //传到bll层
     ProductInfoBLL bll = new ProductInfoBLL();
    List<ProductInfo> list = bll.GetProductInfoByProNum(txt);
     //集合绑定到dgv上
    dgvProductInfo.AutoGenerateColumns = false;
    dgvProductInfo.DataSource = list;
     if(dgvProductInfo.SelectedRows.Count>0)
     {
         dgvProductInfo.SelectedRows[0].Selected = false;
     }
  }
 private void cmbCategory_SelectedIndexChanged(object sender, EventArgs e)
 {
     if(cmbCategory.SelectedIndex !=0)
     {
         int id = Convert.ToInt32(cmbCategory.SelectedValue);
         ProductInfoBLL bll = new ProductInfoBLL();
         dgvProductInfo.AutoGenerateColumns = false;
         dgvProductInfo.DataSource = bll.GetProductInfoByCatId(id);
         if(dgvProductInfo.SelectedRows.Count>0)
         {
             dgvProductInfo.SelectedRows[0].Selected = false;
         }
         
     }
     else
     {
         LoadProductInfoByDelFlag(0);
     }
 }
 //Update Product
 private void btnUpdatePro_Click(object sender, EventArgs e)
 {
     if(dgvProductInfo.SelectedRows.Count>0)
     {
         int id = Convert.ToInt32(dgvProductInfo.SelectedRows[0].Cells[0].Value.ToString());
         ProductInfoBLL bll = new ProductInfoBLL();
         ProductInfo pro = bll.GetProductInfoById(id);
         if(pro!=null)
         {
             meaFcp.Obj = pro;
             InsertOrUpdate(4);
         }
     }
     else
     {
         MessageBox.Show("请选中Product");
     }
     
 }
 private void btnDeletePro_Click(object sender, EventArgs e)
 {
     if(dgvProductInfo.SelectedRows.Count>0)
     {
         //提示
         if(DialogResult.OK == MessageBox.Show("真的要删除吗","删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question))
         {
             int id = Convert.ToInt32(dgvProductInfo.SelectedRows[0].Cells[0].Value.ToString());
             ProductInfoBLL bll = new ProductInfoBLL();
             if(bll.DeleteProductInfoByProId(id))
             {
                 MessageBox.Show("操作成功");
             }
             else
             {
                 MessageBox.Show("操作失败");
             }
             LoadProductInfoByDelFlag(0);
             
         }
     }
     else
     {
         MessageBox.Show("请选择要删除的行");
     }
 }