//删除操作 protected void List_RowDeleting(object sender, GridViewDeleteEventArgs e) { int itemId = Int32.Parse(List.DataKeys[e.RowIndex].Value.ToString()); int regionId = Int32.Parse(((HiddenField)List.Rows[e.RowIndex].FindControl("RegionIDHid")).Value); HiddenField itemTypeIdHid = (HiddenField)List.Rows[e.RowIndex].FindControl("ItemTypeIDHid"); HiddenField itemPriceHid = (HiddenField)List.Rows[e.RowIndex].FindControl("ItemPriceHid"); int monthRegion = 1; bool success = false; if (regionId > 0) { DataTable dt = ItemAccess.GetItemListByRegionId(userId, regionId); monthRegion = dt.Rows.Count; foreach (DataRow dr in dt.Rows) { itemId = Int32.Parse(dr["ItemID"].ToString()); success = ItemAccess.DeleteItem(itemId, userId); } } else { success = ItemAccess.DeleteItem(itemId, userId); } if (success) { List.EditIndex = -1; BindGrid(); } else { Utility.Alert(this, "删除失败!"); } }
//更新操作 protected void List_RowUpdating(object sender, GridViewUpdateEventArgs e) { int itemId = Int32.Parse(List.DataKeys[e.RowIndex].Value.ToString()); string itemName = ((TextBox)List.Rows[e.RowIndex].FindControl("ItemNameBox")).Text.Trim(); if (itemName == "") { Utility.Alert(this, "商品名称未填写!"); return; } string itemType = ((DropDownList)List.Rows[e.RowIndex].FindControl("ItemTypeDropDown")).SelectedValue.ToString(); HiddenField itemTypeIdHid = (HiddenField)List.Rows[e.RowIndex].FindControl("ItemTypeIDHid"); int catTypeId = Int32.Parse(((DropDownList)List.Rows[e.RowIndex].FindControl("CatTypeDropDown")).SelectedValue.ToString()); string itemPrice = ((TextBox)List.Rows[e.RowIndex].FindControl("ItemPriceBox")).Text.Trim(); HiddenField itemPriceHid = (HiddenField)List.Rows[e.RowIndex].FindControl("ItemPriceHid"); DateTime itemBuyDate = DateTime.Parse(((TextBox)List.Rows[e.RowIndex].FindControl("ItemBuyDateBox")).Text.Trim() + " " + DateTime.Now.ToString("HH:mm:ss")); int recommend = Int32.Parse(((HiddenField)List.Rows[e.RowIndex].FindControl("RecommendHid")).Value); int itemAppId = Int32.Parse(((HiddenField)List.Rows[e.RowIndex].FindControl("ItemAppIDHid")).Value); int regionId = Int32.Parse(((HiddenField)List.Rows[e.RowIndex].FindControl("RegionIDHid")).Value); string regionType = ((HiddenField)List.Rows[e.RowIndex].FindControl("RegionTypeHid")).Value; int cardId = Int32.Parse(((DropDownList)List.Rows[e.RowIndex].FindControl("CardDropDown")).SelectedValue.ToString()); ItemEntity item = ItemAccess.GetItemListById(itemId); item.ItemID = itemId; item.ItemType = itemType; item.ItemName = itemName; item.CategoryTypeID = catTypeId; item.ItemPrice = Double.Parse(itemPrice); item.ItemBuyDate = itemBuyDate; item.Synchronize = 1; item.CardID = cardId; int monthRegion = 1; bool success = false; if (regionId > 0) { DataTable dt = ItemAccess.GetItemListByRegionId(userId, regionId); monthRegion = dt.Rows.Count; foreach (DataRow dr in dt.Rows) { itemId = Int32.Parse(dr["ItemID"].ToString()); itemAppId = Int32.Parse(dr["ItemAppID"].ToString()); itemBuyDate = DateTime.Parse(dr["ItemBuyDate"].ToString()); recommend = Int32.Parse(dr["Recommend"].ToString()); item.ItemID = itemId; item.ItemAppID = itemAppId; item.ItemBuyDate = itemBuyDate; item.Recommend = recommend; success = ItemAccess.UpdateItem(item, 1); } } else { success = ItemAccess.UpdateItem(item, 1); } if (success) { List.EditIndex = -1; BindGrid(); } }