private void dgvGoodsList_CellContentClick(object sender, DataGridViewCellEventArgs e) { Action act = () => { if (e.RowIndex >= 0) { var curCell = dgvGoodsList.Rows[e.RowIndex].Cells[e.ColumnIndex]; ViewGoodsInfoModel goodsInfo = dgvGoodsList.Rows[e.RowIndex].DataBoundItem as ViewGoodsInfoModel; string cellVal = curCell.FormattedValue.ToString(); switch (cellVal) { case "修改": ShowGoodsInfoPage(2, goodsInfo.GoodsId); break; case "删除": DeleteGoodsInfo(1, goodsInfo); break; case "恢复": DeleteGoodsInfo(0, goodsInfo); break; case "移除": DeleteGoodsInfo(2, goodsInfo); break; } } }; act.TryCatch("操作商品信息数据异常!"); }
/// <summary> /// 详情响应 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnInfo_Click(object sender, EventArgs e) { if (dgvGoodsList.CurrentRow != null) { ViewGoodsInfoModel goodsInfo = dgvGoodsList.CurrentRow.DataBoundItem as ViewGoodsInfoModel; if (goodsInfo != null) { ShowGoodsInfoPage(4, goodsInfo.GoodsId); } } else { MsgBoxHelper.MsgErrorShow("请选择要查看的商品信息!"); return; } }
/// <summary> /// 删除商品信息处理(删除、恢复、移除) /// </summary> /// <param name="isDeleted"></param> /// <param name="goodsInfo"></param> private void DeleteGoodsInfo(int isDeleted, ViewGoodsInfoModel goodsInfo) { string delTypeName = FormUtility.GetDeleteTypeName(isDeleted); string msgTitle = $"商品信息{delTypeName}"; if (MsgBoxHelper.MsgBoxConfirm(msgTitle, $"您确定要{delTypeName}该商品信息?") == DialogResult.Yes) { bool bl = false; switch (isDeleted) { case 1: //删除 //如果商品在使用中,不允许删除 bool IsGoodsUse = RequestStar.CheckIsGoodsUse(goodsInfo.GoodsId); if (!IsGoodsUse) { bl = RequestStar.DeleteGoodsInfo(goodsInfo.GoodsId); } else { MsgBoxHelper.MsgErrorShow($"该商品:{goodsInfo.GoodsName}在使用中,不能删除!"); return; } break; case 0: //恢复 bl = RequestStar.RecoverGoodsInfo(goodsInfo.GoodsId, uName); break; case 2: //移除 bl = RequestStar.RemoveGoodsInfo(goodsInfo.GoodsId); break; } string sucType = bl ? "成功" : "失败"; string delMsg = $"商品信息:{goodsInfo.GoodsName} {delTypeName} {sucType}"; if (bl) { MsgBoxHelper.MsgBoxShow(msgTitle, delMsg); LoadGoodsList(); } else { MsgBoxHelper.MsgErrorShow(delMsg); return; } } }
/// <summary> /// 批量删除 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnDelete_Click(object sender, EventArgs e) { Action act = () => { //SelectedRows 选定行的集合(MultiSelect True ) 多个行 if (dgvGoodsList.SelectedRows.Count == 0) { MsgBoxHelper.MsgErrorShow("请选择要删除的商品信息"); return; } string title = "删除商品信息"; if (MsgBoxHelper.MsgBoxConfirm(title, "您确定要删除选择的这些商品信息吗?") == DialogResult.Yes) { List <int> goodsIds = new List <int>(); string IsUseGoodsNames = ""; foreach (DataGridViewRow row in dgvGoodsList.SelectedRows) { ViewGoodsInfoModel gInfo = row.DataBoundItem as ViewGoodsInfoModel; //如果该类别添加了商品,不允许删除 bool isGoodsUse = RequestStar.CheckIsGoodsUse(gInfo.GoodsId); if (!isGoodsUse) { goodsIds.Add(gInfo.GoodsId); } else { if (IsUseGoodsNames.Length > 0) { IsUseGoodsNames += ","; } IsUseGoodsNames += gInfo.GoodsName; } } if (goodsIds.Count > 0) { bool bl = RequestStar.DeleteGoodsInfos(goodsIds);//执行批量删除 string sucMsg = bl ? "成功" : "失败"; string msg = $"选择的商品信息中符合删除要求的信息 删除 {sucMsg}!"; if (bl) { if (!string.IsNullOrEmpty(IsUseGoodsNames)) { msg += $" {IsUseGoodsNames} 已经使用,不能删除!"; } MsgBoxHelper.MsgBoxShow(title, msg); LoadGoodsList(); } else { MsgBoxHelper.MsgErrorShow(msg); } } else { MsgBoxHelper.MsgErrorShow("没有符合删除要求的商品信息!"); } } }; act.TryCatch("批量删除商品信息异常!"); }