/// <summary> /// 检查批量删除的输入的有效性 /// </summary> /// <returns>允许批量删除</returns> private bool CheckInputBatchDelete() { bool returnValue = false; int selectedCount = 0; BaseItemsEntity itemsEntity = new BaseItemsEntity(); foreach (DataGridViewRow dgvRow in grdItems_.Rows) { DataRow dataRow = (dgvRow.DataBoundItem as DataRowView).Row; if (dataRow.RowState != DataRowState.Deleted) { if ((System.Boolean)(dgvRow.Cells["colSelected"].Value??false)) { // 是否允许删除 itemsEntity.GetFrom(dataRow); if (itemsEntity.AllowDelete == 0) { returnValue = false; MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, itemsEntity.FullName), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); // 这里需要直接返回了,不再进行输入交验了。 return returnValue; } else { selectedCount++; } } } } //foreach (DataRowView dataRowView in this.DTItems.DefaultView) //{ // DataRow dataRow = dataRowView.Row; // if (dataRow.RowState != DataRowState.Deleted) // { // if (dataRow["colSelected"].ToString() == true.ToString()) // { // // 是否允许删除 // itemsEntity.GetFrom(dataRow); // if (itemsEntity.AllowDelete == 0) // { // returnValue = false; // MessageBox.Show(AppMessage.Format(AppMessage.MSG0018, itemsEntity.FullName), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); // // 这里需要直接返回了,不再进行输入交验了。 // return returnValue; // } // else // { // selectedCount++; // } // } // } //} // 有记录被选中了 returnValue = selectedCount > 0; if (!returnValue) { MessageBox.Show(AppMessage.MSG0024, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information); } return returnValue; }
private void grdItems_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) { // 当前记录是否允许被删除 BaseItemsEntity ItemsEntity = new BaseItemsEntity(); DataRow dataRow = BaseBusinessLogic.GetDataRow(this.DTItems, this.EntityId); ItemsEntity.GetFrom(dataRow); // 判断是否允许删除 if (ItemsEntity.AllowDelete == 0) { MessageBox.Show(AppMessage.MSG0017, AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Question); e.Cancel = true; } else { if (MessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel) { e.Cancel = true; } else { // 删除数据 DotNetService.Instance.ItemsService.Delete(UserInfo, this.TargetTableName, this.EntityId); } } }
/// <summary> /// 批量进行保存 /// </summary> /// <param name="dataTable">数据表</param> /// <returns>影响行数</returns> public override int BatchSave(DataTable dataTable) { int returnValue = 0; BaseItemsEntity itemsEntity = new BaseItemsEntity(); foreach (DataRow dataRow in dataTable.Rows) { // 删除状态 if (dataRow.RowState == DataRowState.Deleted) { string id = dataRow[BaseItemsEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { if (itemsEntity.AllowDelete == 1) { returnValue += this.Delete(id); } } } // 被修改过 if (dataRow.RowState == DataRowState.Modified) { string id = dataRow[BaseItemsEntity.FieldId, DataRowVersion.Original].ToString(); if (id.Length > 0) { itemsEntity.GetFrom(dataRow); // 判断是否允许编辑 if (itemsEntity.AllowEdit == 1) { returnValue += this.UpdateEntity(itemsEntity); } else { // 不允许编辑,但是排序还是允许的 returnValue += this.SetProperty(itemsEntity.Id, new KeyValuePair<string, object>(BaseItemsEntity.FieldSortCode, itemsEntity.SortCode)); } } } // 添加状态 if (dataRow.RowState == DataRowState.Added) { itemsEntity.GetFrom(dataRow); returnValue += this.AddEntity(itemsEntity).Length > 0 ? 1 : 0; } if (dataRow.RowState == DataRowState.Unchanged) { continue; } if (dataRow.RowState == DataRowState.Detached) { continue; } } return returnValue; }