/// <summary> /// /// </summary> /// <param name="p"></param> /// <param name="pers"></param> /// <param name="hasId"></param> /// <returns></returns> private int getPeripheralIndex(PeripheralVO p, List <PairType <string, PeripheralVO> > pers, out bool hasId) { hasId = false; if (p == null || CollectionUtilities.isEmpty(pers)) { return(-1); } int fndIdIdx = pers.FindIndex(x => x.Right.Id.Equals(p.Id, StringComparison.OrdinalIgnoreCase)); //int fndIpIdx = (!string.IsNullOrEmpty(p.IPAddress)) // ? pers.FindIndex(x => x.Right.IPAddress.Equals(p.IPAddress)) // : -1; int fndNmIdx = (!string.IsNullOrEmpty(p.Name)) ? pers.FindIndex(x => x.Right.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase)) : -1; int fndTypeIdx = pers.FindIndex( x => x.Right.PeriphType.PeripheralTypeId.Equals( p.PeriphType.PeripheralTypeId, StringComparison.OrdinalIgnoreCase)); if (fndIdIdx != -1 && fndTypeIdx != -1) { hasId = true; return(fndIdIdx); } return(-1); }
private bool isPeripheralValid(PeripheralVO pVo, out string errMsg) { errMsg = string.Empty; //Verify the peripheral being added prior to adding it bool fndErrors = false; var errMsgSB = new StringBuilder(); if (pVo == null) { errMsgSB.AppendLine("Peripheral object must be valid"); fndErrors = true; } else { if (string.IsNullOrEmpty(pVo.Name) || pVo.Name.Trim().Length == 0) { errMsgSB.AppendLine("Peripheral Name is empty or null"); fndErrors = true; } if (pVo.LogicalType == PeripheralVO.PeripheralType.UNKNOWN) { errMsgSB.AppendLine("Peripheral logical type must be specified"); fndErrors = true; } if (pVo.LogicalType != PeripheralVO.PeripheralType.INTERMEC) { if (!StringUtilities.ISIPv4Address(pVo.IPAddress)) { errMsgSB.AppendLine("Peripheral IP Address must be valid"); fndErrors = true; } int ptNum; if (string.IsNullOrEmpty(pVo.Port) || !Int32.TryParse(pVo.Port, out ptNum)) { errMsgSB.AppendLine("Peripheral Port number must be valid"); fndErrors = true; } } } if (fndErrors) { errMsg = errMsgSB.ToString(); } return(!fndErrors); }
private void processPendingChange(bool changeSelection) { if (!this.pendingChanges) { return; } DialogResult res = DialogResult.Yes; if (changeSelection) { res = MessageBox.Show( "You have changes which will be lost. " + System.Environment.NewLine + "Do you want to save your changes?", PawnStoreSetupForm.SETUPALERT_TXT, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); } //If mode is edit or add, submit changes if (res == DialogResult.Yes) { PeripheralVO perVo = (this.mode == PeripheralMgmtMode.ADD) ? this.AddPeripheral : this.EditPeripheral; bool hasId; int idx = getPeripheralIndex(perVo, this.storeData.AllPeripherals, out hasId); if (idx == -1) { //Add this.storeData.AllPeripherals.Add(perVo); //this.storeData.PeripheralsInserts.Add(perVo); } else { //Edit this.storeData.AllPeripherals[idx] = perVo; //this.storeData.PeripheralsUpdates.Add(perVo); } } this.pendingChanges = false; }
private void deMapButton_Click(object sender, EventArgs e) { var wkst = this.SelectedWorkstation; if (wkst != null && !string.IsNullOrEmpty(wkst.Name) && CollectionUtilities.isNotEmptyContainsKey( this.storeData.PawnWorkstationPeripheralMap, wkst.Name)) { //Create mapping entry data table var wkName = wkst.Name; var mapEntDt = new DataTable(); mapEntDt.Columns.Add("Workstation Name"); mapEntDt.Columns.Add("Peripheral Name"); mapEntDt.Columns.Add("Peripheral Type"); var perList = this.storeData.PawnWorkstationPeripheralMap[wkName]; if (CollectionUtilities.isNotEmpty(perList)) { var wksName = wkName; foreach (var per in perList) { if (per == null) { continue; } var dR = mapEntDt.NewRow(); dR["Workstation Name"] = wksName; dR["Peripheral Name"] = per.Right.Name; dR["Peripheral Type"] = per.Right.PeriphType.PeripheralTypeName; mapEntDt.Rows.Add(dR); } } if (mapEntDt.Rows.Count > 0) { var rowCount = mapEntDt.Rows.Count; var sumFm = new SummaryForm(mapEntDt, "Please remove incorrect mappings (NOTE: Use the Delete key):", false); sumFm.ShowDialog(this); //Resolve any changes made if (sumFm.SummaryData.Rows.Count < rowCount) { var sumDt = sumFm.SummaryData; if (sumDt.Rows.Count > 0) { var removePeripherals = new List <PeripheralVO>(); foreach (var per in perList) { if (per == null) { continue; } bool fndPer = false; foreach (DataRow dR in sumDt.Rows) { string perName = Utilities.GetStringValue(dR["Peripheral Name"]); if (perName.Equals(per.Right.Name, StringComparison.OrdinalIgnoreCase)) { fndPer = true; break; } } if (!fndPer) { removePeripherals.Add(per.Right); } } if (CollectionUtilities.isNotEmpty(removePeripherals)) { foreach (var remPer in removePeripherals) { PeripheralVO per = remPer; perList.RemoveAll(x => x.Right.Name.Equals(per.Name, StringComparison.OrdinalIgnoreCase)); } } } else { perList.Clear(); } } //Update it back to the peripheral map this.pendingChanges = false; //Resync workstations this.syncWorkstations(); } } }
private void mapButton_Click(object sender, EventArgs e) { //Check if a peripheral is selected if (this.peripheralSelectedIndex != -1 && this.SelectedWorkstation != null && !this.pendingChanges && (this.mode == PeripheralMgmtMode.INITIAL || this.mode == PeripheralMgmtMode.VIEW || this.mode == PeripheralMgmtMode.EDIT)) { List <PairType <string, PeripheralVO> > mappedPers; bool exists = false; string wkName = this.SelectedWorkstation.Name; if (CollectionUtilities.isNotEmptyContainsKey( this.storeData.PawnWorkstationPeripheralMap, wkName)) { mappedPers = this.storeData.PawnWorkstationPeripheralMap[wkName]; exists = true; } else { mappedPers = new List <PairType <string, PeripheralVO> >(); } PeripheralVO selPer = this.findSelectedPeripheral(); if (selPer != null) { bool hasId; int perIdx = getPeripheralIndex(selPer, mappedPers, out hasId); if (perIdx == -1) { mappedPers.Add(new PairType <string, PeripheralVO>("0", selPer)); } else { MessageBox.Show( "That peripheral <=> workstation mapping already exists.", PawnStoreSetupForm.SETUPALERT_TXT); return; } } else { MessageBox.Show("Cannot locate the selected peripheral.", PawnStoreSetupForm.SETUPALERT_TXT); return; } if (exists) { this.storeData.PawnWorkstationPeripheralMap[wkName] = mappedPers; } else { this.storeData.PawnWorkstationPeripheralMap.Add(wkName, mappedPers); } this.pendingChanges = false; //Resync workstations this.syncWorkstations(); } }