private void btnCancel_Click(object sender, EventArgs e) { DataGridViewRow selectedRow = null; foreach (DataGridViewRow row in dgvMaster.Rows) { if (Convert.ToBoolean(row.Cells[0].Value)) { selectedRow = row; break; } } if (selectedRow != null) { if (selectedRow.Cells["STATENAME"].Value.ToString() == "执行中") { string billID = selectedRow.Cells["BILLMASTERID"].Value.ToString(); DataTable table = billDal.FindBillDetail(billID); if (table.Select("ConfirmState = 3").Length == 0 && table.Select("ConfirmState = 2").Length > 0) { billDal.SaveMasterState("4", billID); taskDal.GetTaskTypeDeleteTask(billID); taskDal.CancelRetailTask(billID); if (new ConfigUtil().GetConfig("DeviceType")["Device"] != "0") { new SendUDP().Send(); } dgvMaster.DataSource = billDal.GetRetailMaster(); } else { MessageBox.Show("不能进行取消操作,已有子项开始仓库作业。", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("单据状态不为‘执行中’,请重新选择单据。", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show("请选择需要取消仓库作业的单据。", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); } }