protected override void OnCreate(Bundle bundle) { try { base.OnCreate(bundle); //展示页面 SetContentView(Resource.Layout.Main); CommonFunction.mode = "NFC"; //数据填充 Spinner TargetSpinner = FindViewById <Spinner>(Resource.Id.mSystemType); ArrayAdapter adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.SystemType, Android.Resource.Layout.SimpleSpinnerItem); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); TargetSpinner.Adapter = adapter; TargetSpinner.Prompt = "请选择"; TargetSpinner.ItemSelected += TargetSpinner_ItemSelected; //数据库操作 string documents = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); db = Path.Combine(documents, DataBaseName); bool exists = File.Exists(db); //判断文件中是否存在 数据表db 如果存在 获取数据,如果不存在 重置系统创建数据表 if (!exists) { InitSqlDB(db); } else { #region 获取数据 IsExistsSqlDB = true; var conn = new SqliteConnection("Data Source=" + db); var cmd = new SqliteCommand("select * from LoginTB limit 1", conn); cmd.CommandType = System.Data.CommandType.Text; try { conn.Open(); if (conn.State == System.Data.ConnectionState.Open) { SqliteDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { int id = 0; Spinner SystemSpinner = FindViewById <Spinner>(Resource.Id.mSystemType); for (int i = 0; i < SystemSpinner.Count; i++) { if (SystemSpinner.GetItemAtPosition(i).ToString() == sdr["SystemType"].ToString()) { id = i; break; } } SystemSpinner.SetSelection(id, true); sdr.Close(); } } else { CommonFunction.ShowMessage("数据库打开失败!", this, true); } } catch (Exception ex) { CommonFunction.ShowMessage("数据库创建失败!", this, true); } finally { if (conn.State != System.Data.ConnectionState.Closed) { conn.Clone(); } conn.Dispose(); } #endregion } // 按钮事件 Button bLogin = FindViewById <Button>(Resource.Id.bLogin); bLogin.Click += bLogin_Click; TextView txt_Exit = FindViewById <TextView>(Resource.Id.textView4); txt_Exit.Click += textExit; TextView txt_Init = FindViewById <TextView>(Resource.Id.textView5); txt_Init.Click += textInit; #region try { IntentFilter ndef = new IntentFilter(NfcAdapter.ActionTagDiscovered); m_nfcAdapter = NfcAdapter.GetDefaultAdapter(this); m_nfcAdapter.SetNdefPushMessage(CreateNdefMessageCallback(), this, this); } catch (NullReferenceException nullex) { CommonFunction.ShowMessage(nullex.Message, this, true); } #endregion } catch (Exception ex) { CommonFunction.ShowMessage(ex.ToString(), this, true); } }