private void updateFormBasedOnMachine(PawnSecVO.ClientPawnSecMachineVO machine) { if (machine != null) { this.ipAddressTextBox.Enabled = true; this.macAddressTextBox.Enabled = true; this.isAllowedCheckBox.Enabled = true; this.terminalNumberNumericUpDown.Enabled = true; this.logLevelComboBox.Enabled = true; this.traceLevelNumericUpDown.Enabled = true; this.adobeOverrideCheckBox.Enabled = true; this.ghostScriptOverrideCheckBox.Enabled = true; this.removeButton.Enabled = true; this.printingAllowedCheckBox.Enabled = true; if (!string.IsNullOrEmpty(machine.Machine.IPAddress)) { this.ipAddressTextBox.Text = machine.Machine.IPAddress; } if (!string.IsNullOrEmpty(machine.Machine.MACAddress)) { this.macAddressTextBox.Text = machine.Machine.MACAddress; } this.isAllowedCheckBox.Checked = machine.Machine.IsAllowed; this.printingAllowedCheckBox.Checked = machine.StoreMachine.PrintEnabled; this.traceLevelNumericUpDown.Value = machine.StoreMachine.TraceLevel; this.terminalNumberNumericUpDown.Value = machine.StoreMachine.TerminalNumber; int fndIdx = -1, idx = 0; foreach (var it in this.logLevelComboBox.Items) { if (it.Equals(machine.StoreMachine.LogLevel)) { fndIdx = idx; break; } idx++; } if (fndIdx != -1) { this.logLevelComboBox.SelectedIndex = fndIdx; } else { this.logLevelComboBox.SelectedText = LogLevel.DEBUG.ToString(); } if (!string.IsNullOrEmpty(machine.Machine.AdobeOverride)) { this.adobeOverrideCheckBox.Checked = true; this.adobeReaderOverrideTextBox.Text = machine.Machine.AdobeOverride; } if (!string.IsNullOrEmpty(machine.Machine.GhostOverride)) { this.ghostScriptOverrideCheckBox.Checked = true; this.ghostScriptOverrideTextBox.Text = machine.Machine.GhostOverride; } } }
private void addMachineButton_Click(object sender, EventArgs e) { string macName = this.machineNameComboBox.Text; if (!string.IsNullOrEmpty(macName) && macName.ToLowerInvariant().Contains(CASHAM_DOMAIN)) { macName = macName.Trim(); var res = MessageBox.Show("Are you sure you want to add " + macName + " to PAWNSEC™ ?", PawnStoreSetupForm.SETUPALERT_TXT, MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res == DialogResult.No) { return; } //Ensure that this machine does not exist in pawn sec already for this store or //any other store var fndMachine = false; var pgFm = new InProgressForm("* VERIFYING UNIQUENESS OF MACHINE *"); if (CollectionUtilities.isNotEmpty(this.storeData.PawnSecData.ClientMachines)) { var fndMac = this.storeData.PawnSecData.ClientMachines.Find( x => x.Machine.MachineName.Equals(macName, StringComparison.OrdinalIgnoreCase)); if (fndMac != null) { fndMachine = true; } if (fndMachine == false && !string.IsNullOrEmpty(ipAddressTextBox.Text)) { var trimIp = ipAddressTextBox.Text.Trim(); if (!string.IsNullOrEmpty(trimIp)) { //See if IP address is used, and if so, ensure uniqueness var fndIp = this.storeData.PawnSecData.ClientMachines.Find( x => x.Machine.IPAddress.Equals(trimIp)); if (fndIp != null) { fndMachine = true; } } } if (fndMachine == false && !string.IsNullOrEmpty(macAddressTextBox.Text)) { var trimMac = macAddressTextBox.Text.Trim(); if (!string.IsNullOrEmpty(trimMac)) { var fndMacAddr = this.storeData.PawnSecData.ClientMachines.Find( x => x.Machine.MACAddress.Equals(trimMac, StringComparison.OrdinalIgnoreCase)); if (fndMacAddr != null) { fndMachine = true; } } } } //Now check globally against all entries if (!fndMachine) { var whereClause = "machinename = '" + macName + "'"; if (!string.IsNullOrEmpty(ipAddressTextBox.Text)) { var trimIp = ipAddressTextBox.Text.Trim(); if (!string.IsNullOrEmpty(trimIp)) { whereClause += " or ipaddress = '" + trimIp + "'"; } } if (!string.IsNullOrEmpty(macAddressTextBox.Text)) { var trimMac = macAddressTextBox.Text.Trim(); if (!string.IsNullOrEmpty(trimMac)) { whereClause += " or macaddress = '" + trimMac + "'"; } } DataReturnSet dS; if (DataAccessService.ExecuteQuery(false, string.Format( "select machinename from clientregistry where {0}", whereClause), "clientregistry", PawnStoreSetupForm.PAWNSEC, out dS, ref this.dAPawnSec)) { if (dS != null && dS.NumberRows > 0) { fndMachine = true; } } pgFm.HideMessage(); } if (fndMachine) { pgFm.Dispose(); MessageBox.Show( "This machine already exists in the pawn security database. " + Environment.NewLine + " If this machine has moved to a different store, please " + Environment.NewLine + "remove it from that store's security database first.", PawnStoreSetupForm.SETUPALERT_TXT); return; } pgFm.Dispose(); this.addMachineButton.Enabled = false; this.removeButton.Enabled = false; this.machineNameComboBox.Enabled = false; var newMac = new PawnSecVO.ClientPawnSecMachineVO(); var newMapping = new PawnSecVO.ClientStoreMapVO(); newMac.Machine.MachineName = macName; int perIdx = macName.IndexOf("."); if (perIdx != -1) { newMac.Machine.WorkstationName = macName.Substring(0, perIdx); } //Set terminal number if (CollectionUtilities.isNotEmpty(this.storeData.PawnSecData.ClientMachines)) { newMac.StoreMachine.TerminalNumber = this.storeData.PawnSecData.ClientMachines.Max( x => x.StoreMachine.TerminalNumber) + 1; } else { newMac.StoreMachine.TerminalNumber = 1; } //Set store client config id //ulong storeMachineId = 0; //this.storeData.PawnSecData.NextIdSet.GetNextIds(PawnSecVO.PawnSecNextIdVO.SELECTOR.STOCLICFG_ID, ref storeMachineId); newMac.StoreMachine.Id = 0;//storeMachineId; //Set client id //ulong clientRegId = 0; //this.storeData.PawnSecData.NextIdSet.GetNextIds(PawnSecVO.PawnSecNextIdVO.SELECTOR.CLIREG_ID, ref clientRegId); newMac.Machine.ClientId = 0; //Set mapping id //ulong newMappingId = 1; //this.storeData.PawnSecData.NextIdSet.GetNextIds(PawnSecVO.PawnSecNextIdVO.SELECTOR.CLISTOMAP_ID, ref newMappingId); newMapping.Id = 0; newMapping.ClientRegistryId = newMac.Machine.ClientId; //Set store config id newMapping.StoreClientConfigId = newMac.StoreMachine.Id; var curSto = this.getStoreInformation(); if (curSto == null) { MessageBox.Show("Cannot find store to add this client to for mapping purposes", PawnStoreSetupForm.SETUPALERT_TXT); return; } newMapping.StoreSiteId = curSto.StoreSiteId; newMapping.StoreConfigId = curSto.StoreConfiguration.Id; newMapping.StoreNumber = this.storeNumber; this.storeData.PawnSecData.ClientMachines.Add(newMac); this.storeData.PawnSecData.ClientStoreMapList.Add(newMapping); this.storeData.PawnSecData.GenerateMaps(); } else { MessageBox.Show( "Please enter a valid machine name. It must contain the full domain name: " + CASHAM_DOMAIN, PawnStoreSetupForm.SETUPALERT_TXT); } }