private void btnAllocateEquipment_Click(object sender, EventArgs e) { DataRow serviceTypeRow = DM.dtServiceType.Rows[cmServiceType.Position]; DataRow equipmentRow = DM.dtEquipment.Rows[cmEquipment.Position]; DataRow[] serviceTypeEquipment = DM.dtServiceTypeEquipment.Select("ServiceTypeID = " + serviceTypeRow["ServiceTypeID"].ToString() + "and EquipmentID = " + equipmentRow["EquipmentID"].ToString()); if (serviceTypeEquipment.Length == 0) { DataRow newServiceTypeEquipment = DM.dtServiceTypeEquipment.NewRow(); newServiceTypeEquipment["ServiceTypeID"] = dgvServiceType["ServiceTypeID", cmServiceType.Position].Value; newServiceTypeEquipment["EquipmentID"] = dgvEquipment["EquipmentID", cmEquipment.Position].Value; DM.dsGreens.Tables["ServiceTypeEquipment"].Rows.Add(newServiceTypeEquipment); DM.UpdateServiceTypeEquipment(); //update database MessageBox.Show("Item of equipment allocated successfully", "Success"); return; } else { MessageBox.Show("This item of equipment has already been allocated to this service type", "Error"); return; } }
private void btnAllocate_Click(object sender, EventArgs e) { try { if (DM.dtService.Rows[cmServiceType.Position]["Status"].ToString() == "Pending") { DataRow newServiceTypeEquipment = DM.dtServiceTypeEquipment.NewRow(); newServiceTypeEquipment["EquipmentID"] = dgvEquipment["EquipmentID", cmEquipment.Position].Value; newServiceTypeEquipment["ServiceTypeID"] = dgvServiceType["ServiceTypeID", cmServiceType.Position].Value; DM.DSGreen.Tables["ServiceTypeEquipment"].Rows.Add(newServiceTypeEquipment); //add a new row to dataset DM.UpdateServiceTypeEquipment(); //update database //Give the user a success message MessageBox.Show("Item of equipment allocated successfully."); } else { MessageBox.Show("Cannot allocate equipment to paid service.", "Error"); } } catch (ConstraintException) { MessageBox.Show("This item of equipment has already been allocated to this service type.", "Error"); } }