protected override void OnListItemClick(ListView l, View v, int position, long id)
 {
     ActivityInfo info = (ActivityInfo) l.GetItemAtPosition(position);
     Intent intent = new Intent();
     intent.SetComponent(new ComponentName(this, info.Name));
     StartActivity(intent);
 }
		/// <summary>
		/// Will register for the remote control client commands in audio manager
		/// </summary>
		private void RegisterRemoteClient()
		{
			try{

				if(remoteControlClient == null)
				{
					audioManager.RegisterMediaButtonEventReceiver(remoteComponentName);
					//Create a new pending intent that we want triggered by remote control client
					var mediaButtonIntent = new Intent(Intent.ActionMediaButton);
					mediaButtonIntent.SetComponent(remoteComponentName);
					// Create new pending intent for the intent
					var mediaPendingIntent = PendingIntent.GetBroadcast(this, 0, mediaButtonIntent, 0);
					// Create and register the remote control client
					remoteControlClient = new RemoteControlClient(mediaPendingIntent);
					audioManager.RegisterRemoteControlClient(remoteControlClient);
				}


				//add transport control flags we can to handle
				remoteControlClient.SetTransportControlFlags(RemoteControlFlags.Play | 
					RemoteControlFlags.Pause |
					RemoteControlFlags.PlayPause |
					RemoteControlFlags.Stop | 
					RemoteControlFlags.Previous |
					RemoteControlFlags.Next);


			}catch(Exception ex){
				Console.WriteLine (ex);
			}
		}
Example #3
0
        public override void OnReceive (Context context, Intent intent)
        {
            var comp = new ComponentName (context,
                           Java.Lang.Class.FromType (typeof(GcmService)));
            StartWakefulService (context, (intent.SetComponent (comp)));

            ResultCode = Result.Ok;
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            Button btnStartTargetLauncher = FindViewById<Button> (Resource.Id.btnStartTargetLauncher);
            Button btnStartExplicit = FindViewById<Button> (Resource.Id.btnStartExplicit);
            Button btnStartExplicitWithResult = FindViewById<Button> (Resource.Id.btnStartExplicitWithResult);
            Button btnStartImplicit = FindViewById<Button> (Resource.Id.btnStartImplicit);

            // Start target app's the main launcher activity. This works "out of the box" if we know the package name.
            btnStartTargetLauncher.Click += (sender, e) => {
                var intent = PackageManager.GetLaunchIntentForPackage("net.csharx.targetapp");
                this.StartActivity(intent);
            };

            // Start any non-main activity of the target app.
            // Preconditions:
            // - We know the package name
            // - We know the full qualified name of the activity
            // - The activity to be started must be exported by the target app
            // - The activity to be started must explicitly set its (full qualified) name
            btnStartExplicit.Click += (sender, e) => {
                var intent = new Intent();
                intent.SetComponent(new ComponentName("net.csharx.targetapp", "net.csharx.targetapp.ExplicitActivityInTargetApp"));
                this.StartActivity(intent);
            };

            btnStartExplicitWithResult.Click += (sender, e) => {
                var intent = new Intent();
                intent.SetComponent(new ComponentName("net.csharx.targetapp", "net.csharx.targetapp.ExplicitActivityInTargetApp"));
                this.StartActivityForResult(intent, 100);
            };

            // Start a target activity via an implicit intent. Best way to do this is to set a custom (unique) action filter on the target.
            btnStartImplicit.Click += (sender, e) => {
                var intent = new Intent();
                intent.SetAction("net.csharx.targetapp.SOME_ACTION");
                this.StartActivity(intent);
            };
        }
Example #5
0
        public void OnFacebook(Action<bool> OnFacebookNotFound, string data)
        {
            String fullUrl = "https://m.facebook.com/sharer.php?u=..";

            if (!IsAvailable("com.facebook.android"))
            {
                if (OnFacebookNotFound != null)
                    OnFacebookNotFound(true);
                return;
            }
            #region Code

            try
            {
                Intent shareIntent = new Intent(global::Android.Content.Intent.ActionSend);
                shareIntent.SetType("text/plain");
                shareIntent.PutExtra(Intent.ExtraText, data);
                PackageManager pm = Forms.Context.PackageManager;
                IList<ResolveInfo> activityList = pm.QueryIntentActivities(shareIntent, PackageInfoFlags.Activities);
                foreach (ResolveInfo app in activityList)
                {
                    if ((app.ActivityInfo.Name).Contains("facebook"))
                    {
                        ActivityInfo activity = app.ActivityInfo;
                        ComponentName name = new ComponentName(activity.ApplicationInfo.PackageName, activity.Name);
                        shareIntent.AddCategory(Intent.CategoryLauncher);
                        shareIntent.SetFlags(ActivityFlags.NewTask | ActivityFlags.ResetTaskIfNeeded);
                        shareIntent.SetComponent(name);
                        Forms.Context.StartActivity(shareIntent);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Intent i = new Intent(Intent.ActionView);
                i.SetData(global::Android.Net.Uri.Parse(fullUrl));
                Forms.Context.StartActivity(i);
            }

            #endregion
        }
        public void Notify(string title, string message)
        {
            using (var intent = new Intent())
            {
                intent.SetComponent(new ComponentName(_activity, "dart.androidapp.ContactsActivity"));
                using (var pendingIntent = PendingIntent.GetActivity(_activity, 0, intent, 0))
                using (var builder = new NotificationCompat.Builder(_activity))
                {
                    var notification = builder.SetContentIntent(pendingIntent)
                        .SetContentTitle(title)
                        .SetContentText(message)
                        .SetSound(RingtoneManager.GetDefaultUri(RingtoneType.Notification))
                        .SetSmallIcon(Resource.Drawable.Icon)
                        .SetAutoCancel(true)
                        .Build();

                    using (notification)
                    using (var nMgr = (NotificationManager)_activity.GetSystemService(Context.NotificationService))
                        nMgr.Notify(_msgId++, notification);
                }
            }
        }
Example #7
0
        static List<AppInfo> FetchApps(Context context, bool addSettings = false, List<string> ignoredPackageNames = null, Dictionary<string, string> renameMappings = null)
        {
            if (renameMappings == null)
                renameMappings = new Dictionary<string, string> ();
            if (ignoredPackageNames == null)
                ignoredPackageNames = new List<string> ();

            var results = new List<AppInfo> ();
            var apps = context.PackageManager.GetInstalledApplications (PackageInfoFlags.Activities);

            foreach (var app in apps) {

                var launchIntent = context.PackageManager.GetLaunchIntentForPackage (app.PackageName);

                if (launchIntent != null) {

                    if (ignoredPackageNames.Contains (app.PackageName))
                        continue;

                    var label = app.LoadLabel (context.PackageManager);
                    if (renameMappings.ContainsKey (app.PackageName))
                        label = renameMappings [app.PackageName];

                    results.Add (new AppInfo {
                        LaunchIntent = launchIntent,
                        Name = label,
                        App = app,
                        PackageName = app.PackageName
                    });
                }
            }

            if (!ignoredPackageNames.Contains (Android.Provider.Settings.ActionSettings) && addSettings) {

                // FROM Logcat, we can see settings calls this intent:
                // {act=android.intent.action.VIEW cat=[com.amazon.device.intent.category.LAUNCHER_MENU] flg=0x14000000 cmp=com.amazon.tv.launcher/.ui.SettingsActivity (has extras)} from pid 11366
                // So let's construct that same one to use
                var settingsIntent = new Intent ("android.intent.action.VIEW");
                settingsIntent.AddCategory ("com.amazon.device.intent.category.LAUNCHER_MENU");
                settingsIntent.SetComponent (new ComponentName ("com.amazon.tv.launcher", "com.amazon.tv.launcher.ui.SettingsActivity"));

                results.Add (new AppInfo {
                    LaunchIntent = settingsIntent,
                    Name = "Settings",
                    App = null,
                    PackageName = Android.Provider.Settings.ActionSettings
                });
            }

            return results.OrderBy(x => x.Name).ToList ();
        }
Example #8
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            Reset.Run();
            //this.SetTheme(Android.Resource.Style.ThemeNoTitleBarFullScreen);//全屏
            if (SysVisitor.firstOpenIndex == 0)//防止多次启动
            {
                Shopping.goodslist = new System.Collections.Generic.List<Goods> { };
                Shopping.goodslistgive = new System.Collections.Generic.List<Goods> { };
                Shopping.Clear();
                Shopping.Clear(true);
                new StarThread(this);
            }
            else
                SysVisitor.firstOpenIndex++;
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Index);
            TextView gname = FindViewById<TextView>(Resource.Id.Index_Gname);
            TextView Contact = FindViewById<TextView>(Resource.Id.Index_Contact);
            gname.Text = baseclass.MyConfig.of_GetMySysSet("COMPANY", "CompanyName") + "     登陆人:" + SysVisitor.UserName; ;
            Contact.Text = "广州国宇软件技术服务有限公司\n联系电话:020-61131488 85557207\n软件版本 " + SysVisitor.getVersionCode(this);
            Contact.LongClick += delegate { Contact.Visibility = ViewStates.Gone; };
            //本地功能
            string[] list_loacl = { "录入补货", "新品订货", "本地订单", "录入回款", "本地回款", "查看销价" };
            //需联网功能
            string[] list_server = { "库存查询", "订单查询", "出货单查询", "客户对账", "回款查询", "消息通知" };
            //
            string[] list_setting = { "系统设置" };
            GridView gridView_local = FindViewById<GridView>(Resource.Id.Index_gridView);
            IndexAdapter listItemAdapter_local = new IndexAdapter(this, list_loacl);
            gridView_local.Adapter = listItemAdapter_local;

            GridView gridView_server = FindViewById<GridView>(Resource.Id.Index_gridView_server);
            IndexAdapter listItemAdapter_server = new IndexAdapter(this, list_server);
            gridView_server.Adapter = listItemAdapter_server;

            GridView gridView_setting = FindViewById<GridView>(Resource.Id.Index_gridView_Setting);
            IndexAdapter listItemAdapter_setting = new IndexAdapter(this, list_setting);
            gridView_setting.Adapter = listItemAdapter_setting;
            //快速点击5次打开开发人员查看页
            Contact.Click += delegate
            {
                if (as_date == null)
                    ai_clickNum++;
                else
                {
                    if (SysVisitor.DateDiff(as_date, SysVisitor.timeSpan.Milliseconds) < 300)
                    {
                        if (ai_clickNum == 3)
                        {
                            SysVisitor.GetVibrator(this);
                            StartActivity(typeof(TelePhoneManager));
                            Finish();
                        }
                        ai_clickNum++;
                    }
                    else
                    {
                        ai_clickNum = 0;
                    }
                }
                as_date = DateTime.Now;
            };
            System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ThreadStart(of_netType));
            thr.Start();
            ImageButton netType_del = FindViewById<ImageButton>(Resource.Id.Index_netType_del);
            LinearLayout netType_view = FindViewById<LinearLayout>(Resource.Id.Index_netType_LinearLayout);
            TextView netType = FindViewById<TextView>(Resource.Id.Index_netType_text);
            netType_del.Click += delegate { netType_view.Visibility = ViewStates.Gone; ab_shouNetType = true; };
            netType.Click += delegate
            {
                Intent intent = null;
                if (int.Parse(Android.OS.Build.VERSION.Sdk) > 10)
                    intent = new Intent(Android.Provider.Settings.ActionWirelessSettings);
                else
                {
                    intent = new Intent();
                    ComponentName component = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
                    intent.SetComponent(component);
                    intent.SetAction("android.intent.action.VIEW");
                }
                StartActivity(intent);
            };
            System.Threading.Thread thr_msg = new System.Threading.Thread(MsgPush);
            thr_msg.Start();
        }
Example #9
0
 private void SendNotification(string message)
 {
     var nMgr = (NotificationManager)this.GetSystemService(NotificationService);
     var notification = new Notification(Resource.Drawable.Icon, "Kotys Message");
     var intent = new Intent();
     intent.SetComponent(new ComponentName(this, "dart.androidapp.ContactsActivity"));
     var pendingIntent = PendingIntent.GetActivity(this, 0, intent, 0);
     notification.SetLatestEventInfo(this, message, message, pendingIntent);
     nMgr.Notify(0, notification);
 }
Example #10
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Index);

            TextView gname = FindViewById<TextView>(Resource.Id.Index_Gname);
            TextView Contact = FindViewById<TextView>(Resource.Id.Index_Contact);
            gname.Text = _publicfuns.of_GetMySysSet("COMPANY", "CompanyName");

            Contact.Text = "广州国宇软件技术服务有限公司\n联系电话:020-61131488 85557207\n软件版本" + SysVisitor.getVersionName(this);

            string[] list = {
                "会员查询",
                "新增会员",
                "快速收银",
                "系统设置"
                };
            GridView gridView = FindViewById<GridView>(Resource.Id.Index_gridView);
            IndexAdapter listItemAdapter = new IndexAdapter(this, list);
            gridView.Adapter = listItemAdapter;

            System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ThreadStart(of_netType));
            thr.Start();
            ImageButton netType_del = FindViewById<ImageButton>(Resource.Id.Index_netType_del);
            LinearLayout netType_view = FindViewById<LinearLayout>(Resource.Id.Index_netType_LinearLayout);
            TextView netType = FindViewById<TextView>(Resource.Id.Index_netType_text);
            netType_del.Click += delegate { netType_view.Visibility = ViewStates.Gone; ab_shouNetType = true; };
            netType.Click += delegate
            {
                Intent intent = null;
                if (int.Parse(Android.OS.Build.VERSION.Sdk) > 10)
                {
                    intent = new Intent(Android.Provider.Settings.ActionWirelessSettings);
                }
                else
                {
                    intent = new Intent();
                    ComponentName component = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
                    intent.SetComponent(component);
                    intent.SetAction("android.intent.action.VIEW");
                }
                StartActivity(intent);
            };
            System.Threading.Thread thr_msg = new System.Threading.Thread(MsgPush);
            thr_msg.Start();
        }
Example #11
0
 private void LaunchTtsSettings()
 {
     //Open Android Text-To-Speech Settings
     if (((int)Android.OS.Build.VERSION.SdkInt) >= 14)
     {
         Intent intent = new Intent();
         intent.SetAction("com.android.settings.TTS_SETTINGS");
         intent.SetFlags(ActivityFlags.NewTask);
         context.StartActivity(intent);
     }
     else
     {
         Intent intent = new Intent();
         intent.AddCategory(Intent.CategoryLauncher);
         intent.SetComponent(new ComponentName("com.android.settings", "com.android.settings.TextToSpeechSettings"));
         intent.SetFlags(ActivityFlags.NewTask);
         context.StartActivity(intent);
     }
 }
Example #12
0
        bool ab_shouNetType;//是否手动禁止显示未联网状态显示
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Main);
            if (string.IsNullOrEmpty(baseclass.MyConfig.of_GetMySysSet("COMPANY", "CompanyName")))
            {
                Core.SysVisitor.CreateServerDB();
                string ls_sql = "select Itemvalue from mysysset where ItemType='COMPANY' and itemName='CompanyName'";
                string ls_CompanyName = SqlHelper.ExecuteScalar(ls_sql);
                if (!string.IsNullOrEmpty(ls_CompanyName))
                {
                    baseclass.MyConfig.of_SetMySysSet("COMPANY", "CompanyName", ls_CompanyName);
                }
            }
            if (string.IsNullOrEmpty(MyConfig.of_GetMySysSet("printer", "memo")))
            {

            }
            GyERP.CompanyName = baseclass.MyConfig.of_GetMySysSet("COMPANY", "CompanyName");
            if (SysVisitor.getVersionCode(this) != -1)
                MyConfig.of_SetMySysSet("app", "vercode", SysVisitor.getVersionCode(this).ToString());
            if (SysVisitor.getVersionName(this) != "")
                MyConfig.of_SetMySysSet("app", "vername", SysVisitor.getVersionName(this));
            MyConfig.of_SetMySysSet("phone", "meid", SysVisitor.MEID(this));
            #region 自动登录
            if (MyConfig.of_GetMySysSet("Login", "Login") == "Y")
            {
                string ls_user = MyConfig.of_GetMySysSet("Login", "username");
                string ls_pwd = MyConfig.of_GetMySysSet("Login", "password");
                string ls_logindate = MyConfig.of_GetMySysSet("Login", "logindate");
                if (!string.IsNullOrEmpty(ls_user) && !string.IsNullOrEmpty(ls_pwd))
                {
                    DateTime time;
                    try
                    {
                        time = Convert.ToDateTime(ls_logindate);
                    }
                    catch
                    {
                        time = DateTime.Now.AddDays(-100);
                    }
                    if (SysVisitor.DateDiff(time.ToString(), SysVisitor.timeSpan.Days) <= 7)
                    {
                        GyERP.UserName = ls_user;
                        Intent it = new Intent();
                        Bundle bu = new Bundle();
                        bu.PutString("name", "data");
                        bu.PutString("update", "");
                        it.PutExtras(bu);
                        it.SetClass(this.ApplicationContext, typeof(Index));
                        StartActivity(it);
                        Finish();
                        return;
                    }
                }
            }
            #endregion
            string ls_DeviceId = SysVisitor.MEID(this);

            Spinner sp_comname = FindViewById<Spinner>(Resource.Id.login_company);
            Spinner sp_mygroup = FindViewById<Spinner>(Resource.Id.login_group);
            Spinner username = FindViewById<Spinner>(Resource.Id.login_username);
            Button btn_cancel = FindViewById<Button>(Resource.Id.login_cancel);
            Button btn_login = FindViewById<Button>(Resource.Id.login_submit);
            TextView Refresh = FindViewById<TextView>(Resource.Id.login_Refresh);
            EditText password = FindViewById<EditText>(Resource.Id.login_pass);
            CheckBox chk_showpwd = FindViewById<CheckBox>(Resource.Id.login_showpwd);//显示密码
            CheckBox chk_login = FindViewById<CheckBox>(Resource.Id.login_checklogin);//自动登录
            TextView txt_msg = FindViewById<TextView>(Resource.Id.login_text);//底部说明文字
            Button btn_login_b = FindViewById<Button>(Resource.Id.login_Btn_LoginB);

            password.Click += delegate
            {
                //AlertDialog.Builder builder = new AlertDialog.Builder(this);
                //var et_search = new EditText(this);
                //et_search.InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationPassword;
                //builder.SetTitle("提示:");
                //builder.SetMessage("请输入密码:");
                //builder.SetView(et_search);
                //builder.SetNegativeButton("确定", delegate
                //{
                //    if (et_search.Text != "")
                //        password.Text = et_search.Text;
                //});
                //builder.SetPositiveButton("确定并登陆", delegate
                //{
                //    if (et_search.Text != "")
                //        password.Text = et_search.Text;
                //    btn_login.PerformClick();
                //});
                //builder.Show();
                if (password.Text != "")
                    password.SetSelectAllOnFocus(true);
            };
            btn_login_b.Click += delegate
            {
                btn_login.PerformClick();
            };

            string ls_comname = LocalYW.of_GetMySysSet("comname", "defaultcomname");    //取到上次登录comname
            string ls_defaultusername = LocalYW.of_GetMySysSet("comname", "defaultusername");   //取到上次登录人

            //int li_row = MyConfig.ExecuteScalarNum("select count(*) from customer");
            if (string.IsNullOrEmpty(ls_comname))
            {
                txt_msg.Text = "首次登陆时需要从服务器获取大量数据\n可能需要几分钟甚至更长时间\n建议在网络条件较好的环境下操作\n获取数据过程中请不要关闭程序";
            }
            //bool lb_db = SqliteHelper.of_ExistDataBase();
            new CreateTable();

            string ls_CompanyListSQL = @"select itemvalue from mysysset where itemtype=@itemtype order by itemname";
            DataTable ldt_comanyList = MyConfig.ExecuteDataTable(GyERP.ConfigPath + "config.db", CommandType.Text, ls_CompanyListSQL, "@itemtype=YWcompanylist");

            #region 为控件绑定数据
            int li_comnameRow = 0;
            var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            for (int i = 0; i < ldt_comanyList.Rows.Count; i++)
            {
                if (ls_comname == ldt_comanyList.Rows[i][0].ToString())
                    li_comnameRow = i;
                adapter.Add(ldt_comanyList.Rows[i][0].ToString());
            }
            sp_comname.Adapter = adapter;
            sp_comname.SetSelection(li_comnameRow, true);//默认选中项

            adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            DataTable ldt = new DataTable();
            ldt = MyConfig.ExecuteDataTable("select groupname from mygroup");
            for (int i = 0; i < ldt.Rows.Count; i++)
            {
                adapter.Add(ldt.Rows[i]["groupname"].ToString());
            }
            sp_mygroup.Adapter = adapter;

            adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            ldt = new DataTable();
            string ls_gid = "";
            ls_gid = MyConfig.ExecuteScalar("select gid from mygroup");
            ldt = MyConfig.ExecuteDataTable("select username from myuser where gid='" + ls_gid + "'");
            for (int i = 0; i < ldt.Rows.Count; i++)
            {
                adapter.Add(ldt.Rows[i]["username"].ToString());
            }
            username.Adapter = adapter;
            #endregion
            sp_comname.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(sp_comname_ItemSelected);
            sp_mygroup.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(sp_group_ItemSelected);
             
            chk_showpwd.CheckedChange += delegate
            {
                if (chk_showpwd.Checked)
                {
                    password.InputType = Android.Text.InputTypes.TextVariationWebEditText;
                }
                else
                {
                    password.InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationPassword;
                }
                password.SetSelection(password.Text.Length);
            };

            btn_cancel.Click += delegate
            {
                SysVisitor.EXIT(this);
            };

            //登陆
            btn_login.Click += delegate
            {
                string local_user = MyConfig.of_GetMySysSet("Login", "username");
                string local_pwd = MyConfig.of_GetMySysSet("Login", "password");
                string local_logindate = MyConfig.of_GetMySysSet("Login", "logindate");

                string ls_username = username.SelectedItem.ToString();
                string ls_password = password.Text;

                string ls_Login = "";
                DateTime time = baseclass.GyConvert.of_ToDatetime(local_logindate);
                #region 本地登陆


                ls_Login = GyERP.of_SetUserInfo(GyERP.ComName, ls_username, ls_password);
                if (baseclass.GYstring.of_LeftStr(ls_Login, 2) != "OK")
                {
                    Toast.MakeText(this, "用户名或密码错误,请重新输入", ToastLength.Short).Show();
                    return;
                }
                if (SysVisitor.DateDiff(time.ToString(), SysVisitor.timeSpan.Days) <= 7)
                {
                    if (!string.IsNullOrEmpty(local_user) && !string.IsNullOrEmpty(local_pwd))
                    {
                        if (local_user == ls_username && local_pwd == baseclass.DES.of_EncryStr_64(ls_password, "loginpasskey"))
                        {
                            ls_Login = "******";//本地账号密码校验成功
                                            //测试时关闭本地校验
                        }
                    }
                }
                if (string.IsNullOrEmpty(ls_Login))//未完成本地登陆
                {
                }
                #endregion
                if (string.IsNullOrEmpty(ls_username) || string.IsNullOrEmpty(ls_password))
                {
                    Toast.MakeText(this, "用户名或密码不能为空", ToastLength.Short).Show();
                    return;
                }
                #region 登陆成功
                if (ls_Login == "OK")
                {
                    MyConfig.of_SetMySysSet("Login", "username", ls_username);
                    MyConfig.of_SetMySysSet("Login", "password", baseclass.DES.of_EncryStr_64(ls_password, "loginpasskey"));
                    //_publicfuns.of_SetMySysSet("Login", "password-"++GyERP.DriverNO, baseclass.DES.of_EncryStr_64(ls_password, "loginpasskey"));
                    MyConfig.of_SetMySysSet("Login", "logindate", DateTime.Now.ToString());
                    if (chk_login.Checked)//下次自动登录
                    {
                        MyConfig.of_SetMySysSet("Login", "Login", "Y");
                    }
                    else
                    {
                        MyConfig.of_SetMySysSet("Login", "Login", "N");
                    }
                    //登陆成功
                    int li_rowcount = MyConfig.ExecuteScalarNum("select count(*) from customer limit 1");

                    Toast.MakeText(this, "登陆成功", ToastLength.Short).Show();
                    Intent it = new Intent();
                    Bundle bu = new Bundle();
                    bu.PutString("name", "data");
                    bu.PutString("update", "");
                    it.PutExtras(bu);
                    if (li_rowcount <= 0)
                    {
                        it.SetClass(this.ApplicationContext, typeof(Loading));
                    }
                    else
                    {
                        it.SetClass(this.ApplicationContext, typeof(Index));
                    }
                    LocalYW.of_SetMySysSet("comname", "defaultcomname", GyERP.ComName);
                    LocalYW.of_SetMySysSet("comname", "defaultusername", ls_username);
                    ERPAddCols.of_AddCols();

                    StartActivity(it);
                    Finish();
                }
                #endregion
                else
                {
                    Toast.MakeText(this, "登陆失败,请检查用户名密码", ToastLength.Short).Show();
                    return;
                }
            };
            //刷新登陆数据
            Refresh.Click += delegate
            {
                baseclass.GyERP.of_YwInit();
                GyERP.of_Down_group_User(true);
                baseclass.GyERP.of_SetComName(GyERP.ComName);
                StartActivity(typeof(SplashScreen));
                Finish();
            };
            txt_msg.Click += delegate
            {
                if (as_date == null)
                    ai_clickNum++;
                else
                {
                    if (SysVisitor.DateDiff(as_date, SysVisitor.timeSpan.Milliseconds) < 300)
                    {
                        if (ai_clickNum == 3)
                        {
                            SysVisitor.GetVibrator(this);
                            StartActivity(typeof(TelePhoneManager));
                            Finish();
                        }
                        ai_clickNum++;
                    }
                    else
                    {
                        ai_clickNum = 0;
                    }
                }
                as_date = DateTime.Now;
            };
            ImageButton netType_del = FindViewById<ImageButton>(Resource.Id.Index_netType_del);
            LinearLayout netType_view = FindViewById<LinearLayout>(Resource.Id.Index_netType_LinearLayout);
            TextView netType = FindViewById<TextView>(Resource.Id.Index_netType_text);
            netType_del.Click += delegate { netType_view.Visibility = ViewStates.Gone; ab_shouNetType = true; };
            netType.Click += delegate
            {
                Intent intent = null;
                if (int.Parse(Android.OS.Build.VERSION.Sdk) > 10)
                {
                    intent = new Intent(Android.Provider.Settings.ActionWirelessSettings);
                }
                else
                {
                    intent = new Intent();
                    ComponentName component = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
                    intent.SetComponent(component);
                    intent.SetAction("android.intent.action.VIEW");
                }
                StartActivity(intent);
            };
            System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ThreadStart(of_netType));
            thr.Start();
        }
Example #13
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            RequestWindowFeature(WindowFeatures.NoTitle);
            SetContentView(Resource.Layout.Login);

            if (SysVisitor.getVersionCode(this) != -1)
            {
                _publicfuns.of_SetMySysSet("app", "vercode", SysVisitor.getVersionCode(this).ToString());
            }
            if (SysVisitor.getVersionName(this) != "")
            {
                _publicfuns.of_SetMySysSet("app", "vername", SysVisitor.getVersionName(this));
            }
            _publicfuns.of_SetMySysSet("phone", "meid", SysVisitor.MEID(this));
            #region 自动登录
            if (_publicfuns.of_GetMySysSet("Login", "Login") == "Y")
            {
                string ls_user = _publicfuns.of_GetMySysSet("Login", "username");
                string ls_pwd = _publicfuns.of_GetMySysSet("Login", "password");
                string ls_logindate = _publicfuns.of_GetMySysSet("Login", "logindate");
                if (!string.IsNullOrEmpty(ls_user) && !string.IsNullOrEmpty(ls_pwd))
                {
                    DateTime time;
                    try
                    {
                        time = Convert.ToDateTime(ls_logindate);
                    }
                    catch
                    {
                        time = DateTime.Now.AddDays(-100);
                    }
                    if (SysVisitor.DateDiff(time.ToString(), SysVisitor.timeSpan.Days) <= 7)
                    {
                        SysVisitor.UserName = ls_user;
                        Intent it = new Intent();
                        Bundle bu = new Bundle();
                        bu.PutString("name", "data");
                        bu.PutString("update", "");
                        it.PutExtras(bu);
                        it.SetClass(this.ApplicationContext, typeof(Index));
                        StartActivity(it);
                        Finish();
                        return;
                    }
                }
            }
            #endregion
            string ls_DeviceId = SysVisitor.MEID(this);

            #region 初始化控件
            spinner = FindViewById<Spinner>(Resource.Id.login_company);
            spinner_mygroup = FindViewById<Spinner>(Resource.Id.login_group);
            username = FindViewById<Spinner>(Resource.Id.login_username);
            btn_cancel = FindViewById<Button>(Resource.Id.login_cancel);
            btn_login = FindViewById<Button>(Resource.Id.login_submit);
            Refresh = FindViewById<TextView>(Resource.Id.login_Refresh);
            password = FindViewById<EditText>(Resource.Id.login_pass);
            chk_showpwd = FindViewById<CheckBox>(Resource.Id.login_showpwd);//显示密码
            chk_login = FindViewById<CheckBox>(Resource.Id.login_checklogin);//自动登录
            text = FindViewById<TextView>(Resource.Id.login_text);//底部说明文字
            #endregion

            int li_row = SqliteHelper.ExecuteNum("select count(*) from customer");
            if (li_row <= 0)
            {
                text.Text = "首次登陆时需要从服务器获取大量数据\n可能需要几分钟甚至更长时间\n建议在网络条件较好的环境下操作\n获取数据过程中请不要关闭程序";
            }
            string CompanyList = _publicfuns.of_GetMySysSet("Login", "CompanyList");
            string CompanyHost = _publicfuns.of_GetMySysSet("Login", "CompanyHost");
            //未获取到本地数据  从服务器获取
            if (string.IsNullOrEmpty(CompanyList) || string.IsNullOrEmpty(CompanyHost))
            {
                Intent it = new Intent();
                Bundle bu = new Bundle();
                bu.PutString("name", "login");
                it.PutExtras(bu);
                it.SetClass(this.ApplicationContext, typeof(Loading));
                StartActivity(it);
                Finish();
                return;
            }
            string[] list = { };
            if (CompanyList.Substring(0, 2) == "OK")
            {
                list = CompanyList.Substring(2).Split(',');
            }
            if (CompanyHost.Substring(0, 2) == "OK")
            {
                _publicfuns.of_SetMySysSet("Login", "CompanyHost", CompanyHost);
            }
            #region 为控件绑定数据
            var adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            for (int i = 0; i < list.Length; i++)
            {
                adapter.Add(list[i]);
            }
            spinner.Adapter = adapter;
            spinner.SetSelection(list.Length - 1, true);//默认选中项

            adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            DataTable ldt = new DataTable();
            ldt = SqliteHelper.ExecuteDataTable("select groupname from mygroup");
            for (int i = 0; i < ldt.Rows.Count; i++)
            {
                adapter.Add(ldt.Rows[i]["groupname"].ToString());
            }
            spinner_mygroup.Adapter = adapter;

            adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleSpinnerDropDownItem);
            ldt = new DataTable();
            string ls_gid = "";
            ls_gid = SqliteHelper.ExecuteScalar("select gid from mygroup");
            ldt = SqliteHelper.ExecuteDataTable("select username from myuser where gid='" + ls_gid + "'");
            for (int i = 0; i < ldt.Rows.Count; i++)
            {
                adapter.Add(ldt.Rows[i]["username"].ToString());
            }
            username.Adapter = adapter;
            #endregion

            spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);
            spinner_mygroup.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs>(group_ItemSelected);

            chk_showpwd.CheckedChange += delegate
            {
                if (chk_showpwd.Checked)
                {
                    password.InputType = Android.Text.InputTypes.TextVariationWebEditText;
                }
                else
                {
                    password.InputType = Android.Text.InputTypes.ClassText | Android.Text.InputTypes.TextVariationPassword;
                }
                password.SetSelection(password.Text.Length);
            };

            btn_cancel.Click += delegate
            {
                SysVisitor.EXIT(this);
            };

            //登陆
            btn_login.Click += delegate
            {
                string local_user = _publicfuns.of_GetMySysSet("Login", "username");
                string local_pwd = _publicfuns.of_GetMySysSet("Login", "password");
                string local_logindate = _publicfuns.of_GetMySysSet("Login", "logindate");

                string ls_username = username.SelectedItem.ToString();
                string ls_password = password.Text;

                string ls_Login = "";
                DateTime time;
                try
                {
                    time = Convert.ToDateTime(local_logindate);
                }
                catch
                {
                    time = DateTime.Now.AddDays(-100);
                }
                #region 本地登陆
                if (SysVisitor.DateDiff(time.ToString(), SysVisitor.timeSpan.Days) <= 7)
                {
                    if (!string.IsNullOrEmpty(local_user) && !string.IsNullOrEmpty(local_pwd))
                    {
                        if (local_user == ls_username && local_pwd == baseclass.DES.of_EncryStr_64(ls_password, "loginpasskey"))
                        {
                            ls_Login = "******";//本地账号密码校验成功
                                            //测试时关闭本地校验
                        }
                    }
                }
                if (string.IsNullOrEmpty(ls_Login))//未完成本地登陆
                {
                    if (!SysVisitor.isNetworkConnected(this))
                    {
                        Toast.MakeText(this, "当前网络不可用,请检查你的网络设置", ToastLength.Short).Show();
                        return;
                    }
                    string ls_error = YW.of_GetCompanyList(ls_DeviceId);
                    if (ls_error.Substring(0, 2) != "OK")
                    {
                        //Toast.MakeText(this, "该手机未注册,请重新注册", ToastLength.Long).Show();
                        //return;
                        StartActivity(typeof(enroll));
                        Finish();
                        return;
                    }
                    YW.of_GetERPurl(SysVisitor.Get_Comname(), ls_DeviceId);
                    ls_error = YW.of_CheckNetWorkOK();
                    if (ls_error != "OK")
                    {
                        Toast.MakeText(this, "未能成功连接服务器,请重试", ToastLength.Short).Show();
                        return;
                    }
                    ls_Login = YW.Of_loginYW(SysVisitor.Get_Comname(), ls_username, ls_password);//登陆
                }
                #endregion
                //YW.SendMessage_MygroupUser_json();
                if (string.IsNullOrEmpty(ls_username) || string.IsNullOrEmpty(ls_password))
                {
                    Toast.MakeText(this, "用户名或密码不能为空", ToastLength.Short).Show();
                }
                #region 登陆成功
                if (ls_Login == "OK")
                {
                    _publicfuns.of_SetMySysSet("Login", "username", ls_username);
                    _publicfuns.of_SetMySysSet("Login", "password", baseclass.DES.of_EncryStr_64(ls_password, "loginpasskey"));
                    _publicfuns.of_SetMySysSet("Login", "logindate", DateTime.Now.ToString());
                    if (chk_login.Checked)//下次自动登录
                    {
                        _publicfuns.of_SetMySysSet("Login", "Login", "Y");
                    }
                    else
                    {
                        _publicfuns.of_SetMySysSet("Login", "Login", "N");
                    }
                    //登陆成功
                    string ls_row = SqliteHelper.ExecuteScalar("select count(*) from customer_small");
                    int row = 0;
                    try
                    {
                        row = int.Parse(ls_row);
                    }
                    catch { }
                    Toast.MakeText(this, "登陆成功", ToastLength.Short).Show();
                    Intent it = new Intent();
                    Bundle bu = new Bundle();
                    bu.PutString("name", "data");
                    bu.PutString("update", "");
                    it.PutExtras(bu);
                    if (row <= 0)
                    {
                        it.SetClass(this.ApplicationContext, typeof(Loading));
                    }
                    else
                    {
                        it.SetClass(this.ApplicationContext, typeof(Index));
                    }
                    SysVisitor.UserName = ls_username;
                    StartActivity(it);
                    Finish();
                }
                #endregion
                else
                {
                    Toast.MakeText(this, "登陆失败,请检查用户名密码", ToastLength.Short).Show();
                }
            };

            //Android.Views.InputMethods.InputMethodManager imm = (Android.Views.InputMethods.InputMethodManager)GetSystemService(Context.InputMethodService);
            //imm.HideSoftInputFromWindow(btn_login.WindowToken, Android.Views.InputMethods.HideSoftInputFlags.None);
            //刷新登陆数据
            Refresh.Click += delegate
            {
                Intent it = new Intent();
                Bundle bu = new Bundle();
                bu.PutString("name", "login");
                it.PutExtras(bu);
                it.SetClass(this.ApplicationContext, typeof(Loading));
                StartActivity(it);
                Finish();
            };

            ImageButton netType_del = FindViewById<ImageButton>(Resource.Id.Index_netType_del);
            LinearLayout netType_view = FindViewById<LinearLayout>(Resource.Id.Index_netType_LinearLayout);
            TextView netType = FindViewById<TextView>(Resource.Id.Index_netType_text);
            netType_del.Click += delegate { netType_view.Visibility = ViewStates.Gone; ab_shouNetType = true; };
            netType.Click += delegate
            {
                Intent intent = null;
                if (int.Parse(Android.OS.Build.VERSION.Sdk) > 10)
                {
                    intent = new Intent(Android.Provider.Settings.ActionWirelessSettings);
                }
                else
                {
                    intent = new Intent();
                    ComponentName component = new ComponentName("com.android.settings", "com.android.settings.WirelessSettings");
                    intent.SetComponent(component);
                    intent.SetAction("android.intent.action.VIEW");
                }
                StartActivity(intent);
            };
            System.Threading.Thread thr = new System.Threading.Thread(new System.Threading.ThreadStart(of_netType));
            thr.Start();
        }