private int AddAndUpdate(ProductInfo pro, string sql, int temp)
 {
     List<SQLiteParameter> list = new List<SQLiteParameter>();
     SQLiteParameter[] ps = {
                                new SQLiteParameter("@CatId",pro.CatId),
                                new SQLiteParameter("@ProName",pro.ProName),
                                new SQLiteParameter("@ProCost",pro.ProCost),
                                new SQLiteParameter("@ProSpell",pro.ProSpell),
                                new SQLiteParameter("@ProPrice",pro.ProPrice),
                                new SQLiteParameter("@ProUnit",pro.ProUnit),
                                new SQLiteParameter("@Remark",pro.Remark),
                                new SQLiteParameter("@ProStock",pro.ProStock),
                                new SQLiteParameter("@ProNum",pro.ProNum)
                            };
     list.AddRange(ps);
     if(temp == 3)
     {
         list.Add(new SQLiteParameter("@DelFlag", pro.DelFlag));
         list.Add(new SQLiteParameter("@SubTime", pro.SubTime));
         list.Add(new SQLiteParameter("@SubBy", pro.SubBy));
     }
     else if(temp == 4)
     {
         list.Add(new SQLiteParameter("@ProId", pro.ProId));
     }
     return SqliteHelper.ExecuteNonQuery(sql, list.ToArray());
 }
 public bool SaverProduct(ProductInfo pro, int temp)
 {
     int r = -1;
     if(temp == 3)
     {
         dal.AddProductInfo(pro);
     }
     else if(temp == 4)
     {
         dal.UpdateProductInfo(pro);
     }
     return r > 0;
 }
        /// <summary>
        /// 根据id查询对象
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        private ProductInfo RowToProductInfo(DataRow dr)
        {
            ProductInfo pi = new ProductInfo();
            pi.ProId = Convert.ToInt32(dr["ProId"]);
            pi.ProName = dr["ProName"].ToString();
            pi.ProCost = Convert.ToDecimal(dr["ProCost"]);
            pi.ProSpell = dr["ProSpell"].ToString();
            pi.ProUnit = dr["ProUnit"].ToString();
            pi.Remark = dr["Remark"].ToString();
            pi.ProStock = Convert.ToInt32(dr["ProStock"]);
            pi.ProNum = dr["ProNum"].ToString();
            pi.ProPrice = Convert.ToDecimal(dr["ProPrice"]);
            pi.CatId = Convert.ToInt32(dr["CatId"]);
            return pi;

        }
 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();
     }
 }
 public int UpdateProductInfo(ProductInfo pro)
 {
     string sql = "update ProductInfo set CatId=@CatId,ProName=@ProName,ProCost=@ProCost,ProSpell=@ProSpell,ProPrice=@ProPrice,ProUnit=@ProUnit,Remark=@Remark,ProStock=@ProStock,ProNum=@ProNum where ProId=@ProId";
     return AddAndUpdate(pro, sql, 4);
 }
 public int AddProductInfo(ProductInfo pro)
 {
     string sql = "insert into ProductInfo(CatId,ProName,ProCost,ProSpell,ProPrice,ProUnit,Remark,DelFlag,SubTime,ProStock,ProNum,SubBy) Values(@CatId,@ProName,@ProCost,@ProSpell,@ProPrice,@ProUnit,@Remark,@DelFlag,@SubTime,@ProStock,@ProNum,@SubBy)";
     return AddAndUpdate(pro, sql, 3);
 }