public ErrorEventDlg(DeviceErrorEventArgs d, PosCommon co) { // // Required for Windows Form Designer support // InitializeComponent(); deviceErrorArgs = d; ErrorText.Text = "An ErrorEvent occurred with the following parameters:\r\n" + "\tError Code: " + d.ErrorCode.ToString() + "\r\n" + "\tExtended Error Code: " + d.ErrorCodeExtended.ToString() + "\r\n" + "\tError Locus: " + d.ErrorLocus.ToString() + "\r\n" + "\tError Response: " + d.ErrorResponse.ToString(); if (co is PosPrinter) { string s; s = "\r\n\r\nErrorLevel: " + ((PosPrinter)co).ErrorLevel.ToString() + "\r\n"; s += "ErrorStation: " + ((PosPrinter)co).ErrorStation.ToString() + "\r\n"; s += "ErrorString: " + ((PosPrinter)co).ErrorString.ToString(); ErrorText.Text += s; } RetryradioButton.Checked = (d.ErrorResponse == ErrorResponse.Retry); ClearradioButton.Checked = (d.ErrorResponse == ErrorResponse.Clear); ContinueInputradioButton.Checked = (d.ErrorResponse == ErrorResponse.ContinueInput); }
/// <summary> /// How to use "PosExplorer" sample1. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExample1_Click(object sender, System.EventArgs e) { //Use a Logical Device Name which has been set on the SetupPOS. try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; //Get DeviceInfo use devicecategory and logicalname. deviceInfo = posExplorer.GetDevice(DeviceType.PosPrinter, m_strLogicalName); m_PosCommon = (PosCommon)posExplorer.CreateInstance(deviceInfo); //Open the device m_PosCommon.Open(); //Get the exclusive control right for the opened device. //Then the device is disable from other application. m_PosCommon.Claim(1000); //Enable the device. m_PosCommon.DeviceEnabled = true; //CheckHealth. m_PosCommon.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive); //Close device m_PosCommon.Close(); } catch (Exception) { } }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } co = null; } base.Dispose( disposing ); }
/// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose(bool disposing) { if (disposing) { if (components != null) { components.Dispose(); } co = null; } base.Dispose(disposing); }
public StatisticsForm(PosCommon co) { // // Required for Windows Form Designer support // InitializeComponent(); UpdateState(); this.co = co; RetrieveStatistics(new string[] { "" }); }
private void DrawStatus() { try { // This will redraw the status bar in the correct place if it isn't already if (statusBar1.Bottom != ClientSize.Height) { PerformLayout(); } PosCommon so = wr.Target as PosCommon; if (so != null && so.State != ControlState.Closed) { string text = so.State.ToString() + ", "; if (so.Claimed) { text += "Claimed, "; } else { text += "Unclaimed, "; } if (so.DeviceEnabled) { text += "Enabled"; } else { text += "Disabled"; } sbpState.Text = text; if (piDataEventEnabled != null) { sbpDataEventsEnabled.Text = "DataEventsEnabled: " + piDataEventEnabled.GetValue(so, null).ToString(); } if (piDataCount != null) { sbpDataCount.Text = "DataCount: " + piDataCount.GetValue(so, null).ToString(); } } } catch { // eat exceptions } }
private void SetDataEventEnabledPosCommon(ref PosCommon posCommon, bool isEnabled) { try { PropertyInfo dataEventEnabled = posCommon.GetType().GetProperty("DataEventEnabled"); if (dataEventEnabled != null) { dataEventEnabled.SetValue(posCommon, isEnabled, null); } } catch (Exception ex) { sMessengeError = ex.Message; } }
public static DeviceScreenBase CreateDeviceScreen(PosCommon posCommon, string soName, MainForm mainForm) { DeviceScreenBase screen =null; if (posCommon is Msr) screen = new MsrScreen(); else if (posCommon is Scanner) screen = new ScannerScreen(); else if (posCommon is CheckScanner) screen = new CheckScannerScreen(); else if (posCommon is PosPrinter) screen = new PosPrinterScreen(); else if (posCommon is Scale) screen = new ScaleScreen(); else if (posCommon is Micr) screen = new MicrScreen(); else if (posCommon is LineDisplay) screen = new LineDisplayScreen(); else if (posCommon is PinPad) screen = new PinPadScreen(); else if (posCommon is CashDrawer) screen = new CashDrawerScreen(); else if (posCommon is PosKeyboard) screen = new PosKeyboardScreen(); else if (posCommon is CoinDispenser) screen = new CoinDispenserScreen(); else if (posCommon is Keylock) screen = new KeylockScreen(); else if (posCommon is SignatureCapture) screen = new SignatureCaptureScreen(); else if (posCommon is SmartCardRW) screen = new SmartCardRWScreen(); else if (posCommon is BumpBar) screen = new BumpBarScreen(); else if (posCommon is Biometrics) screen = new BiometricsScreen(); else if (posCommon is RFIDScanner) screen = new RFIDScannerScreen(); if (screen != null) { screen._mainForm = mainForm; screen._posCommon = posCommon; screen._soName = soName; } return screen; }
private void HookUpEvents(PosCommon pc, bool attach) { EventInfo dataEvent = pc.GetType().GetEvent("DataEvent"); if (dataEvent != null) { if (attach) { dataEvent.AddEventHandler(pc, new DataEventHandler(co_OnDataEvent)); } else { dataEvent.RemoveEventHandler(pc, new DataEventHandler(co_OnDataEvent)); } } }
public SimulatorBase(PosCommon serviceObject) { HandleCreated += new EventHandler(SimulatorBase_HandleCreated); wr = new WeakReference(serviceObject); WindowVisible = new ManualResetEvent(false); UIThread = new Thread(new ThreadStart(UIThreadMethod)); UIThread.IsBackground = true; UIThread.Start(); WindowVisible.WaitOne(); WindowVisible.Close(); WindowVisible = null; closed = false; stateTimer.Tick += new EventHandler(stateTimer_Tick); stateTimer.Interval = 200; stateTimer.Start(); }
public SimulatorBase(PosCommon serviceObject) { HandleCreated += new EventHandler(SimulatorBase_HandleCreated); wr = new WeakReference(serviceObject); WindowVisible = new ManualResetEvent(false); UIThread = new Thread(new ThreadStart(UIThreadMethod)); UIThread.IsBackground = true; UIThread.Start(); WindowVisible.WaitOne(); WindowVisible.Close(); WindowVisible = null; closed = false; stateTimer.Tick +=new EventHandler(stateTimer_Tick); stateTimer.Interval = 200; stateTimer.Start(); }
private void OpenDevice(ref PosCommon posCommon, string strDeviceName, string strDeviceLevel) { if (string.IsNullOrEmpty(strDeviceLevel) || string.IsNullOrEmpty(strDeviceName)) { return; } DeviceCollection devices = _posExplorer.GetDevices((DeviceCompatibilities)Enum.Parse(typeof(DeviceCompatibilities), strDeviceLevel, false)); DeviceInfo drv = devices.Cast <DeviceInfo>().Where(x => x.ServiceObjectName.Equals(strDeviceName)).FirstOrDefault(); try { posCommon = (PosCommon)_posExplorer.CreateInstance(drv); posCommon.Open(); SetDataEventEnabledPosCommon(ref posCommon, true); HookUpEvents(posCommon, true); } catch (Exception ex) { //sMessengeError = ex.Message; throw ex; } }
public void UIThreadMethod() { InitializeComponent(); PosCommon so = wr.Target as PosCommon; if (so != null) { this.Text = so.DeviceName; // create status bar panels sbpState = new StatusBarPanel(); sbpState.BorderStyle = StatusBarPanelBorderStyle.Sunken; sbpState.AutoSize = StatusBarPanelAutoSize.Spring; statusBar1.Panels.Add(sbpState); piDataCount = so.GetType().GetProperty("DataCount"); if (piDataCount != null) { sbpDataCount = new StatusBarPanel(); sbpDataCount.BorderStyle = StatusBarPanelBorderStyle.Sunken; sbpDataCount.AutoSize = StatusBarPanelAutoSize.Spring; statusBar1.Panels.Add(sbpDataCount); } piDataEventEnabled = so.GetType().GetProperty("DataEventEnabled"); if (piDataEventEnabled != null) { sbpDataEventsEnabled = new StatusBarPanel(); sbpDataEventsEnabled.BorderStyle = StatusBarPanelBorderStyle.Sunken; sbpDataEventsEnabled.AutoSize = StatusBarPanelAutoSize.Spring; statusBar1.Panels.Add(sbpDataEventsEnabled); } } so = null; Application.Run(this); }
private static void CloseDevice(PosCommon device) { if (device == null) { return; } try { if (device.Claimed) { device.Release(); } } catch { } try { device.Close(); } catch { } }
bool ImplementsMethod(PosCommon pc, string methodName) { if (pc != null) return (pc.GetType().GetMethod(methodName) != null); return false; }
public DirectIOForm(PosCommon posCommon) { poscommon = posCommon; InitializeComponent(); }
public static DeviceScreenBase CreateDeviceScreen(PosCommon posCommon, string soName, MainForm mainForm) { DeviceScreenBase screen = null; if (posCommon is Msr) { screen = new MsrScreen(); } else if (posCommon is Scanner) { screen = new ScannerScreen(); } else if (posCommon is CheckScanner) { screen = new CheckScannerScreen(); } else if (posCommon is PosPrinter) { screen = new PosPrinterScreen(); } else if (posCommon is Scale) { screen = new ScaleScreen(); } else if (posCommon is Micr) { screen = new MicrScreen(); } else if (posCommon is LineDisplay) { screen = new LineDisplayScreen(); } else if (posCommon is PinPad) { screen = new PinPadScreen(); } else if (posCommon is CashDrawer) { screen = new CashDrawerScreen(); } else if (posCommon is PosKeyboard) { screen = new PosKeyboardScreen(); } else if (posCommon is CoinDispenser) { screen = new CoinDispenserScreen(); } else if (posCommon is Keylock) { screen = new KeylockScreen(); } else if (posCommon is SignatureCapture) { screen = new SignatureCaptureScreen(); } else if (posCommon is SmartCardRW) { screen = new SmartCardRWScreen(); } else if (posCommon is BumpBar) { screen = new BumpBarScreen(); } else if (posCommon is Biometrics) { screen = new BiometricsScreen(); } else if (posCommon is RFIDScanner) { screen = new RFIDScannerScreen(); } if (screen != null) { screen._mainForm = mainForm; screen._posCommon = posCommon; screen._soName = soName; } return(screen); }
private void co_OnDataEvent(object sender, DataEventArgs e) { PosCommon posCommon = sender as PosCommon; SetDataEventEnabledPosCommon(ref posCommon, true); }
public void Initialize() { #region Original pos initialization code /* Original code * // Create a new Pos Explorer * posExplorer = new PosExplorer(); * devices = new ArrayList(); * * customerDisplayDevice ="TMLineDisplay"; // EclipsePosSettings.CustomerDisplay; * printerDevice = "TMPrinter"; //EclipsePosSettings.Printer; * cashDrawerDevice = null; //EclipsePosSettings.CashDrawer; * keyboardDevice = "PREHKeyboard"; * //keyboardDevice = null; //"PCKeyboard"; //EclipsePosSettings.KeyBoard; * msrDevice = "Msr"; //EclipsePosSettings.MSR; * custIdle1 = null; //EclipsePosSettings.LineDisplayIdle1; * custIdle2 = null; //EclipsePosSettings.LineDisplayIdle2; * // operatorDevice = EclipsePosSettings.(string) ConfigurationManager.GetConfiguration("Operator"); * * // Add device support * if (printerDevice != null ) * { * posPrinter = new PosPrinterWrapper(printerDevice, posExplorer); * posPrinter.Open(); * if (posPrinter.CheckHealth()) * { * DeviceInfo device = posExplorer.GetDevice("PosPrinter", "TMPrinter"); * PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus( HardwareStatusPanelId.Printer, device.ServiceObjectName); * } * posPrinter.Close(); * devices.Add(posPrinter); * * } * * if (customerDisplayDevice != null ) * { * lineDisplay = new LineDisplayWrapper(customerDisplayDevice, posExplorer); * // lineDisplay.Open(); * // if (lineDisplay.CheckHealth()) * // {using System.Text; * * DeviceInfo device = posExplorer.GetDevice(DeviceType.LineDisplay, customerDisplayDevice); * PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus( HardwareStatusPanelId.LineDisplay, device.ServiceObjectName); * // } * // lineDisplay.Close(); * devices.Add(lineDisplay); * } * * if ( keyboardDevice != null ) * { * keyboard = new PosKeyboardWrapper(keyboardDevice, posExplorer); * devices.Add(keyboard); * if (keyboard.CheckHealth()) * { * DeviceInfo device = posExplorer.GetDevice(DeviceType.PosKeyboard, keyboardDevice); * PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus( HardwareStatusPanelId.PosKeyboard, device.ServiceObjectName); * } * * } * * if ( msrDevice != null ) * { * msr = new MsrWrapper(msrDevice, posExplorer); * devices.Add(msr); * if (msr.CheckHealth()) * { * DeviceInfo device = posExplorer.GetDevice(DeviceType.Msr, msrDevice); //, keyboardDevice); * // string deviceText = msr.DeviceText(); * PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus( HardwareStatusPanelId.Msr, device.ServiceObjectName); * } * * } * */ #endregion // deviceCollection = new ArrayList(); // deviceCollection.Clear(); //posExplorer = new PosExplorer(PosContext.Instance.CurrentPosDisplay as Form); //posExplorer.DeviceAddedEvent += new DeviceChangedEventHandler(DeviceAdded); //posExplorer.DeviceRemovedEvent += new DeviceChangedEventHandler(DeviceRemoved); DeviceCollection devices = PosContext.Instance.PosExplorer.GetDevices(); foreach (DeviceInfo device in devices) { if (device.LogicalNames.Length == 0) { continue; } try { PosCommon posCommon = PosContext.Instance.PosExplorer.CreateInstance(device) as PosCommon; //Printer if (posCommon is PosPrinter) { if (posPrinter == null) { posPrinter = new PosPrinterWrapper(posCommon as PosPrinter); //printerDevice, posExplorer); //Register the pos printer to device status display if (PosContext.Instance.PosHardwareStatusDevice1 != null) { posPrinter.StatusEvent += new PosPrinterWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice1.Status); } if (PosContext.Instance.PosHardwareStatusDevice2 != null) { posPrinter.StatusEvent += new PosPrinterWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice2.Status); } posPrinter.Open(); if (posPrinter.CheckHealth()) { // MessageBox.Show(device.ServiceObjectName); deviceCollection.Add(posPrinter); } else { posPrinter.Close(); posPrinter = null; } } } //LineDisplay if (posCommon is Microsoft.PointOfService.LineDisplay) { if (lineDisplay == null) { lineDisplay = new LineDisplayWrapper(posCommon as LineDisplay); //Register the Line Display to device status display if (PosContext.Instance.PosHardwareStatusDevice1 != null) { lineDisplay.StatusEvent += new LineDisplayWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice1.Status); } if (PosContext.Instance.PosHardwareStatusDevice2 != null) { lineDisplay.StatusEvent += new LineDisplayWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice2.Status); } lineDisplay.Open(); if (lineDisplay.CheckHealth()) { deviceCollection.Add(lineDisplay); PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus(HardwareStatusPanelId.LineDisplay, device.ServiceObjectName); } else { lineDisplay.Close(); lineDisplay = null; } } } //Msr if (posCommon is Microsoft.PointOfService.Msr) { if (msr == null) { msr = new MsrWrapper(posCommon as Msr); //Register the MSR to device status display if (PosContext.Instance.PosHardwareStatusDevice1 != null) { msr.StatusEvent += new MsrWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice1.Status); } if (PosContext.Instance.PosHardwareStatusDevice2 != null) { msr.StatusEvent += new MsrWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice2.Status); } msr.Open(); if (msr.CheckHealth()) { deviceCollection.Add(msr); PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus(HardwareStatusPanelId.Msr, device.ServiceObjectName); } else { msr.Close(); msr = null; } } } //Keyboard if (posCommon is Microsoft.PointOfService.PosKeyboard) { if (keyboard == null) { keyboard = new PosKeyboardWrapper(posCommon as PosKeyboard); keyboard.Open(); if (keyboard.CheckHealth()) { deviceCollection.Add(keyboard); PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus(HardwareStatusPanelId.PosKeyboard, device.ServiceObjectName); } else { keyboard.Close(); keyboard = null; } } } // Scanner if (posCommon is Microsoft.PointOfService.Scanner) { if (scanner == null) { scanner = new ScannerWrapper(posCommon as Scanner); //Register the Scanner to device status display if (PosContext.Instance.PosHardwareStatusDevice1 != null) { scanner.StatusEvent += new ScannerWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice1.Status); } if (PosContext.Instance.PosHardwareStatusDevice2 != null) { scanner.StatusEvent += new ScannerWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice2.Status); } scanner.Open(); if (scanner.CheckHealth()) { deviceCollection.Add(scanner); PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus(HardwareStatusPanelId.Scanner, device.ServiceObjectName); } else { scanner.Close(); scanner = null; } } } //Scale if (posCommon is Microsoft.PointOfService.Scale) { } // Cash Drawer if (posCommon is Microsoft.PointOfService.CashDrawer) { if (drawer == null) { drawer = new CashDrawerWrapper(posCommon as CashDrawer); //Register the Cash drawer to device status display if (PosContext.Instance.PosHardwareStatusDevice1 != null) { drawer.StatusEvent += new CashDrawerWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice1.Status); } if (PosContext.Instance.PosHardwareStatusDevice2 != null) { drawer.StatusEvent += new CashDrawerWrapper.StausChangedEventHandler(PosContext.Instance.PosHardwareStatusDevice2.Status); } drawer.Open(); if (drawer.CheckHealth()) { deviceCollection.Add(drawer); // PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus(HardwareStatusPanelId.Scanner, device.ServiceObjectName); } else { drawer.Close(); drawer = null; } } } //Pin Pad if (posCommon is Microsoft.PointOfService.PinPad) { } } catch (Exception e) { Logger.Error("PosHardware.cs", e.ToString()); } } /* * posExplorer = new PosExplorer(PosContext.Instance.CurrentPosDisplay as Form); * DeviceCollection devices = posExplorer.GetDevices(); * foreach( DeviceInfo device in devices ) * { * MessageBox.Show(device.ServiceObjectName); * PosCommon posCommon = posExplorer.CreateInstance(device) as PosCommon; * if (posCommon is PosPrinter) * { * posPrinter = new PosPrinterWrapper(printerDevice, posExplorer); * posPrinter.Open(); * MessageBox.Show(device.HardwareDescription); * if (posPrinter.CheckHealth()) * { * //DeviceInfo device = posExplorer.GetDevice("PosPrinter", "TMPrinter"); * //PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus( HardwareStatusPanelId.Printer, device.ServiceObjectName); * } * posPrinter.Close(); * deviceCollection.Add(posPrinter); * } * } */ //if there aren't any Pos keyboard, start the Keyboard hook /*if ( keyboard == null && PosSettings.Default.PCKeyBoard ) * { * // MessageBox.Show("Deleted code"); * * PCKeyboard pcKeyboard = new PCKeyboard(); * pcKeyboard.Open(); * if( pcKeyboard.CheckHealth()) * { * deviceCollection.Add(pcKeyboard); * PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus( HardwareStatusPanelId.PosKeyboard, "PCKeyboard"); * } * else * { * pcKeyboard.Close(); * pcKeyboard = null; * } * * } */ /* * if ( msr == null && PosSettings.Default.HidMsr) * { * try * { * * HidMsr msr1 = new HidMsr(); * msr1.Open(); * // Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.ApplicationIdle, new MsrRead( msr1.Open ) ); * if (msr1.CheckHealth()) * { * deviceCollection.Add(msr1); * PosContext.Instance.CurrentPosDisplay.DisplayHardwareStatus(HardwareStatusPanelId.Msr, "Msr"); * } * else * { * msr1.Close(); * msr1 = null; * } * * } * catch(Exception e) * { * MessageBox.Show(e.ToString()); * } * * } * */ }
/// <summary> /// How to use "PosExplorer" sample2. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnExample2_Click(object sender, System.EventArgs e) { try { //Create PosExplorer PosExplorer posExplorer = new PosExplorer(); DeviceInfo deviceInfo = null; DeviceCollection deviceCollection; //Get DeviceCollection use device categoly deviceCollection = posExplorer.GetDevices(DeviceType.PosPrinter); string[] astrLogicalNames; Hashtable hashDevice = new Hashtable(0); foreach (DeviceInfo devInfo in deviceCollection) { //if the device name is registered. if (devInfo.LogicalNames.Length > 0) { astrLogicalNames = devInfo.LogicalNames; for (int i = 0; i < astrLogicalNames.Length; i++) { if (!hashDevice.ContainsKey(astrLogicalNames[i])) { m_PosCommon = (PosCommon)posExplorer.CreateInstance(devInfo); //Use Legacy Opos //if(m_PosCommon.Compatibility.Equals(DeviceCompatibilities.Opos)) //Use Opos for .Net if (m_PosCommon.Compatibility.Equals (DeviceCompatibilities.CompatibilityLevel1)) { try { //Register hashtable key:LogicalName,Value:DeviceInfo hashDevice.Add(astrLogicalNames[i], devInfo); } catch (Exception) { } } } } } } deviceInfo = (DeviceInfo)hashDevice[m_strLogicalName]; m_PosCommon = (PosCommon)posExplorer.CreateInstance(deviceInfo); //Open the device m_PosCommon.Open(); //Get the exclusive control right for the opened device. //Then the device is disable from other application. m_PosCommon.Claim(1000); //Enable the device. m_PosCommon.DeviceEnabled = true; //CheckHealth. m_PosCommon.CheckHealth(Microsoft.PointOfService.HealthCheckLevel.Interactive); //Close device m_PosCommon.Close(); } catch (Exception) { } }
bool ImplementsProperty(PosCommon pc, string PropertyName) { if (pc != null) return (pc.GetType().GetProperty(PropertyName) != null); return false; }
void HookUpEvents(PosCommon pc, bool attach) { if (pc == null) return; if (attach) { pc.StatusUpdateEvent += new StatusUpdateEventHandler(co_OnStatusUpdateEvent); pc.DirectIOEvent += new DirectIOEventHandler(co_OnDirectIOEvent); } else { pc.StatusUpdateEvent -= new StatusUpdateEventHandler(co_OnStatusUpdateEvent); pc.DirectIOEvent -= new DirectIOEventHandler(co_OnDirectIOEvent); } EventInfo dataEvent = pc.GetType().GetEvent("DataEvent"); if (dataEvent != null) { if (attach) dataEvent.AddEventHandler(pc, new DataEventHandler(co_OnDataEvent)); else dataEvent.RemoveEventHandler(pc, new DataEventHandler(co_OnDataEvent)); } EventInfo errorEvent = pc.GetType().GetEvent("ErrorEvent"); if (errorEvent != null) { if (attach) errorEvent.AddEventHandler(pc, new DeviceErrorEventHandler(co_OnErrorEvent)); else errorEvent.RemoveEventHandler(pc, new DeviceErrorEventHandler(co_OnErrorEvent)); } EventInfo outputCompleteEvent = pc.GetType().GetEvent("OutputCompleteEvent"); if (outputCompleteEvent != null) { if (attach) outputCompleteEvent.AddEventHandler(pc, new OutputCompleteEventHandler(co_OnOutputCompleteEvent)); else outputCompleteEvent.RemoveEventHandler(pc, new OutputCompleteEventHandler(co_OnOutputCompleteEvent)); } }
void SetCheckState(PosCommon pc, CheckBox cb, string propertyName) { cb.Tag = cb; // Mark the tag so that we event handler is disabled try { if (pc == null) { cb.Enabled = cb.Checked = false; } else { PropertyInfo pi = pc.GetType().GetProperty(propertyName); if (pi != null) { cb.Enabled = true; if (pc.State != ControlState.Closed) { try { if (propertyName == "PowerNotify") cb.Checked = ((PowerNotification)pi.GetValue(pc, null)) == PowerNotification.Enabled; else cb.Checked = (bool)pi.GetValue(pc, null); } catch (Exception) { cb.Checked = false; } } else cb.Checked = false; } else cb.Enabled = cb.Checked = false; } } finally { cb.Tag = null; } }
public PropertiesForm(PosCommon posCommon) : this() { propertyGrid1.SelectedObject = posCommon; }