/// <summary>
 /// get sum and count based on orderId
 /// </summary>
 /// <param name="orderId"></param>
 /// <returns></returns>
 public R_OrderInfo_Product GetMoneyAndUnitCount(int orderId)
 {
     string sql = "select count(*), sum(ProPrice*UnitCount) from R_OrderInfo_Product inner join ProductInfo on ProductInfo.ProId=R_OrderInfo_Product.ProId where R_OrderInfo_Product.DelFlag=0 and OrderId=" + orderId;
     R_OrderInfo_Product rop = null;
     using(SQLiteDataReader reader = SqliteHelper.ExecuteReader(sql))
     {
         if(reader.HasRows)
         {
             while(reader.Read())
             {
                 rop = new R_OrderInfo_Product();
                 rop.CT = Convert.ToInt32(reader[0]);
                 //avoid null
                 if(DBNull.Value == reader[1])
                 {
                     rop.MONEY = 0;
                 }
                 else
                 {
                     rop.MONEY = Convert.ToDecimal(reader[1]);
                 }
             }
         }
     }
     return rop;
 }
        /// <summary>
        /// Add order in product
        /// </summary>
        /// <param name="rop"></param>
        /// <returns></returns>
        public int AddROrderInfoProduct(R_OrderInfo_Product rop)
        {
            string sql = "insert into R_OrderInfo_Product(OrderId,ProId,DelFlag,SubTime,State,UnitCount) values(@OrderId,@ProId,@DelFlag,@SubTime,@State,@UnitCount)";

            SQLiteParameter[] ps = {
               new SQLiteParameter("@OrderId",rop.OrderId),  
                new SQLiteParameter("@ProId",rop.ProId), 
                 new SQLiteParameter("@DelFlag",rop.DelFlag), 
                  new SQLiteParameter("@SubTime",rop.SubTime), 
                   new SQLiteParameter("@State",rop.State), 
                    new SQLiteParameter("@UnitCount",rop.UnitCount), 
                                   };
            return SqliteHelper.ExecuteNonQuery(sql, ps);
        }
 private R_OrderInfo_Product RowToROrderInfoProduct(DataRow dr)
 {
     R_OrderInfo_Product rop = new R_OrderInfo_Product();
     rop.CatName = dr["CatName"].ToString();
     rop.ProName = dr["ProName"].ToString();
     rop.ProPrice = Convert.ToDecimal(dr["ProPrice"]);
     rop.ProUnit = dr["ProUnit"].ToString();
     rop.ROrderProId = Convert.ToInt32(dr["ROrderProId"]);
     rop.SubTime = Convert.ToDateTime(dr["SubTime"]);
     rop.UnitCount = Convert.ToDecimal(dr["UnitCount"]);
     rop.ProMoney = rop.UnitCount * rop.ProPrice;
     return rop;
 }
 //start order with cell double click event
 private void dgvProduct_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
 {
     
         int proId = Convert.ToInt32(dgvProduct.SelectedRows[0].Cells[0].Value.ToString());
         R_OrderInfo_Product rop = new R_OrderInfo_Product();
         rop.OrderId = Convert.ToInt32(labOrderId.Text);
         rop.ProId = proId;
         rop.DelFlag = 0;
         rop.SubTime = System.DateTime.Now;
         rop.State = 0;
         if(string.IsNullOrEmpty(txtCount.Text) || txtCount.Text=="0" || txtCount.Text=="1")
         {
             rop.UnitCount = 1;
         }
         else
         {
             rop.UnitCount = Convert.ToInt32(txtCount.Text);
         }
         R_OrderInfo_ProductBLL bll = new R_OrderInfo_ProductBLL();
         string msg = bll.AddROrderInfoProduct(rop) ? "成功" : "失败";
         LoadROrderInfoProductByOrderId(Convert.ToInt32(rop.OrderId));
  }
 /// <summary>
 /// Add order in product
 /// </summary>
 /// <param name="rop"></param>
 /// <returns></returns>
 /// 
 public bool AddROrderInfoProduct(R_OrderInfo_Product rop)
 {
     return dal.AddROrderInfoProduct(rop) > 0;
 }