private void DgvAdd() { if (goodsPreSize == goodsCurSize) { return; } for (int i = goodsPreSize; i < goodsCurSize; i++) { EtGood etGood = Goods[i].Good; DgvGoodIncome.Rows.Add(new object[] { i + 1, etGood.Category.CategoryName, etGood.Category.ParentCategoryName, etGood.Category.Unit, etGood.Category.Firm, etGood.ProductionDate, Goods[i].Count, etGood.Cost, etGood.Price, etGood.State }); } DgvGoodIncome.RowsDefaultCellStyle.BackColor = Color.LightCyan; DgvGoodIncome.AlternatingRowsDefaultCellStyle.BackColor = Color.White; }
public static int UpdateGood(EtGood good) { List <EtGood> goods = QueryByGoodID(good.GoodID); if (goods.Count == 0) { return(-1); } DBHelper helper = new DBHelper(); string sql = "UPDATE good SET categoryID = @CategoryID, " + "productionDate = @ProductionDate, purchaseDate = @PurchaseDate, cost = @Cost, " + "price = @price, state = @state WHERE goodID = @goodID"; MySqlParameter[] prams = { new MySqlParameter("@categoryID", good.Category.CategoryID), new MySqlParameter("@productionDate", good.ProductionDate ?? (object)DBNull.Value), new MySqlParameter("@purchaseDate", good.PurchaseDate ?? (object)DBNull.Value), new MySqlParameter("@cost", good.Cost), new MySqlParameter("@price", good.Price), new MySqlParameter("@state", good.State), new MySqlParameter("@goodID", good.GoodID) }; return(helper.RunNonQuerySQL(sql, prams)); }
private bool Save() { EtPurchase purchase; if (-1 == CmbOperator.SelectedIndex) { MsgBoxUtil.ErrMsgBox("经办人不能为空!"); return(false); } int staffId = StaffDao.QueryByStaffName(CmbOperator.SelectedItem.ToString())[0].StaffID; int res = 0; foreach (ClsGood good in Goods) { purchase = new EtPurchase { PurchaseID = int.Parse(LblPurchaseID.Text), Category = good.Good.Category, PurchaseDate = DtpPurchaseDate.Value.ToString("yyyyMMdd"), Quantity = good.Count, Cost = good.Good.Cost, StaffID = staffId }; res += PurchaseDao.InsertPurchase(purchase); EtGood g = new EtGood { Category = good.Good.Category, ProductionDate = good.Good.ProductionDate, PurchaseDate = purchase.PurchaseDate, Cost = good.Good.Cost, Price = good.Good.Price, State = good.Good.State }; for (int i = 0; i < good.Count; i++) { GoodDao.InsertGood(g); } } if (res == Goods.Count) { return(true); } else { return(false); } }
public static int InsertGood(EtGood good) { List <EtGood> goods = QueryByGoodID(good.GoodID); if (goods.Count > 0) { return(-1); } DBHelper helper = new DBHelper(); string sql = "INSERT INTO " + "good(categoryID,productionDate,purchaseDate,cost,price,state) " + "VALUE(@categoryID,@productionDate,@purchaseDate,@cost,@price,@state)"; MySqlParameter[] prams = { new MySqlParameter("@categoryID", good.Category.CategoryID), new MySqlParameter("@productionDate", good.ProductionDate ?? (object)DBNull.Value), new MySqlParameter("@purchaseDate", good.PurchaseDate ?? (object)DBNull.Value), new MySqlParameter("@cost", good.Cost), new MySqlParameter("@price", good.Price), new MySqlParameter("@state", good.State) }; return(helper.RunNonQuerySQL(sql, prams));; }
private static List <EtGood> GetListByDataReader(MySqlDataReader dr) { List <EtGood> goods = new List <EtGood>(); try { while (dr.Read()) { EtGood good = new EtGood { GoodID = dr.GetInt32("goodID"), Category = new EtCategory { CategoryID = dr.GetInt32("categoryID"), CategoryName = dr["categoryName"] is DBNull ? null : dr.GetString("categoryName"), ParentCategoryID = dr["parentCategoryID"] is DBNull ? ECategory.未定义 : (ECategory)dr.GetInt16("parentCategoryID"), ParentCategoryName = dr["parentCategoryName"] is DBNull ? null : dr.GetString("parentCategoryName"), Unit = dr["unit"] is DBNull ? null : dr.GetString("unit"), Color = dr["color"] is DBNull ? null : dr.GetString("color"), Firm = dr["firm"] is DBNull ? null : dr.GetString("firm"), MinStock = dr["minStock"] is DBNull ? 0 : dr.GetInt32("minStock"), MaxStock = dr["maxStock"] is DBNull ? 0 : dr.GetInt32("maxStock"), ExpirationDate = dr["expirationDate"] is DBNull ? 0 : dr.GetInt32("expirationDate"), IsValid = dr["isValid"] is DBNull ? EValid.已删除 : (EValid)dr.GetInt16("isValid") }, ProductionDate = dr["productionDate"] is DBNull ? null : dr.GetString("productionDate"), PurchaseDate = dr["purchaseDate"] is DBNull ? null : dr.GetString("purchaseDate"), Cost = dr["cost"] is DBNull ? 0 : dr.GetDouble("cost"), Price = dr["price"] is DBNull ? 0 : dr.GetDouble("price"), State = (EState)(dr["state"] is DBNull ? 0 : dr.GetInt32("state")) }; goods.Add(good); } } catch (Exception e) { Console.WriteLine(e.ToString()); } return(goods); }