Пример #1
0
        private void importButton_Click(object sender, EventArgs e)
        {
            Cursor priorCursor = null;

            RFID_Explorer.mainForm.CommonDialogSupport dlg = new mainForm.CommonDialogSupport(mainForm.CommonDialogSupport.DialogType.OpenChannel);

            if (dlg.ShowDialog( ) == DialogResult.OK)
            {
                try
                {
                    this.Capture   = true;
                    priorCursor    = Cursor.Current;
                    Cursor.Current = Cursors.WaitCursor;
                    try
                    {
                        this.bindingSource.DataSource = this.channelList =
                            RFID_Explorer.ExcelExport.ImportRFChannelConfig(this.reader, dlg.FileName);


                        rfid.Constants.Result result =
                            this.channelList.store(LakeChabotReader.MANAGED_ACCESS, this.reader.ReaderHandle);

                        if (rfid.Constants.Result.OK != result)
                        {
                            throw new Exception(result.ToString( ));
                        }

                        this.view.Refresh( );
                    }
                    catch (Exception e2)
                    {
                        MessageBox.Show(String.Format("Error importing RF channel settings.\n\n{0}", e2.Message), "Invalid import file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                finally
                {
                    if (priorCursor != null)
                    {
                        Cursor.Current = priorCursor;
                    }
                    this.Capture = false;
                }
            }
        }
        public override object ConvertFrom(
           System.ComponentModel.ITypeDescriptorContext context,
           System.Globalization.CultureInfo             culture,
           Object                                       value
       )
        {
            Source_FrequencyBandList channelList = new Source_FrequencyBandList( );

            if ( String.IsNullOrEmpty( value as string ) )
            {
                return channelList;
            }

            String[ ] channelStrings = ( value as String ).Split( new Char[ ] { ';' } );

            if ( null == channelStrings )
            {
                return channelList;
            }

            foreach ( String s in channelStrings )
            {
                Object obj = TypeDescriptor.GetConverter( typeof( Source_FrequencyBand ) ).ConvertFromString( s );

                if ( null == obj )
                {
                    // TODO : supply err msg || rely on Source_FrequencyBand converter for msg
                }
                else
                {
                    channelList.Add( obj as Source_FrequencyBand );
                }
            }

            return channelList;
        }