private void NavigateToMyFarm(object sender, EventArgs e, Activity currentActivity)
        {
            try
            {
                btn_myfarmdash.Click -= (sndr, argus) => NavigateToMyFarm(sndr, argus, currentActivity);

                MyFarmDashboardFragment obj = new MyFarmDashboardFragment();
                Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                tx.Replace(Resource.Id.m_main, obj, Constants.myfarmdash);
                mCurrentFragment = obj;
                tx.Commit();
            }
            catch (Exception ex)
            {
                currentActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
        }
        private void ItemSearch_clicked(object sender, AdapterView.ItemClickEventArgs e, Activity currentActivity)
        {
            try
            {
                androidGridView.ItemClick -= (sndr, argus) => ItemSearch_clicked(sndr, argus, currentActivity);

                switch (gridViewCodeString[e.Position])
                {
                case "WLC":
                {
                    AppInfoFragment appInfoFragment = new AppInfoFragment();
                    Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, appInfoFragment, Constants.appinfo);
                    mCurrentFragment = appInfoFragment;
                    tx.Commit();
                    break;
                }

                case "MYFRM":
                {
                    MyFarmDashboardFragment obj = new MyFarmDashboardFragment();
                    Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, obj, Constants.myfarmdash);
                    mCurrentFragment = obj;
                    tx.Commit();
                    break;
                }

                case "VWACT":
                {
                    ActivityViewerFragment activityViewerFragment = new ActivityViewerFragment();
                    Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, activityViewerFragment, Constants.activityviewer);
                    mCurrentFragment = activityViewerFragment;
                    tx.Commit();
                    break;
                }
                }
            }
            catch (Exception ex)
            {
                currentActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        androidGridView.ItemClick += (sndr, argus) => ItemSearch_clicked(sndr, argus, currentActivity);
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
        }
Exemplo n.º 3
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout._fragment_content_selectfarm, null);

            try
            {
                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Farm/GetAllFarmsDetails", Method.GET);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("IsRegister", "true");
                IRestResponse response = client.Execute(request);
                var           content  = response.Content;
                arrFields = Newtonsoft.Json.JsonConvert.DeserializeObject <List <FarmDetailResponse> >(content);

                spinnerx0 = root.FindViewById <Spinner>(Resource.Id.spinnerx0);
                spinnerx0.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinnerx0_ItemSelected);
                var x = arrFields.Where(a => a.Status == ResponseStatus.Successful).ToList();
                if (x != null && x.Count() > default(int))
                {
                    spinnerx0.Adapter = new ArrayAdapter <string>(this.Activity, Android.Resource.Layout.SimpleSpinnerItem, x.Select(a => a.FarmName).ToList());
                }
                else
                {
                    throw new Exception("No farm data found");
                }

                btn_map_farm        = root.FindViewById <Button>(Resource.Id.btn_map_farm);
                btn_map_farm.Click += (sndr, argus) => AddFarm_Clicked(sndr, argus, this.Activity);
            }
            catch (Exception ex)
            {
                this.Activity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(this.Activity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        MyFarmDashboardFragment obj = new MyFarmDashboardFragment();
                        Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, obj, Constants.myfarmdash);
                        tx.Commit();
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            return(root);
        }
        protected void Cancel_Selection(object sender, EventArgs e, Activity currentActivity)
        {
            try
            {
                btn_cancel_plot.Click -= (sndr, argus) => Cancel_Selection(sndr, argus, currentActivity);

                currentActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderGeneric);
                    alertDiag.SetMessage(Resource.String.cancelFromAddItemMessage);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonYes, (senderAlert, args) =>
                    {
                        MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                        Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                        tx.Commit();
                    });
                    alertDiag.SetNegativeButton(Resource.String.DialogButtonNo, (senderAlert, args) =>
                    {
                        //btn_cancel_plot.Click += (sndr, argus) => Cancel_Selection(sndr, argus, currentActivity);
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            catch (Exception ex)
            {
                currentActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(currentActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        //btn_cancel_plot.Click += (sndr, argus) => Cancel_Selection(sndr, argus, currentActivity);
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
        }
Exemplo n.º 5
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_content_chatlist, null);

            this.Activity.RunOnUiThread(() =>
            {
                Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(this.Activity);
                alertDiag.SetTitle(Resource.String.DialogHeaderError);
                alertDiag.SetMessage(string.Format("Firebase id 0be8c237-cca6-4895-8f9c-9bd026023709 is not registered with your device id {0}", Android.Provider.Settings.Secure.GetString(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.Secure.AndroidId)));
                alertDiag.SetIcon(Resource.Drawable.alert);
                alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                {
                    MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                    Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                    tx.Commit();
                });
                Dialog diag = alertDiag.Create();
                diag.Show();
                diag.SetCanceledOnTouchOutside(false);
            });

            return(root);
        }
        private void GetPlotById(ProgressDialog dialog, Activity curActivity, string plotid, SoilDataResponse sm)
        {
            try
            {
                string mStringLoginInfo    = string.Empty;
                string mStringSessionToken = string.Empty;
                try
                {
                    objdb = new DBaseOperations();
                    var lstu = objdb.selectTable();
                    if (lstu != null && lstu.Count > default(int))
                    {
                        var uobj = lstu.FirstOrDefault();
                        if (uobj.Password == " ")
                        {
                            throw new Exception("Please login again");
                        }
                        mStringLoginInfo    = uobj.EmailId;
                        mStringSessionToken = uobj.AuthToken;
                    }
                }
                catch { }

                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Plot/GetPlotDetailsById", Method.GET);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("TokenKey", mStringSessionToken);
                request.AddQueryParameter("PlotId", System.Net.WebUtility.UrlEncode(plotid));
                IRestResponse response = client.Execute(request);
                var           content  = response.Content;

                var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PlotDetailResponse> >(content);
                if (responseObj != null && responseObj.Count() > default(int))
                {
                    var obj = responseObj.FirstOrDefault();
                    obj.PlotId               = plotid;
                    input_plot_name.Text     = obj.PlotName;
                    input_plot_size.Text     = obj.PlotSize.ToString();
                    input_plot_notes.Text    = obj.Notes;
                    isorganic_switch.Checked = obj.Organic;

                    ArrayAdapter adap = (ArrayAdapter)spinner_soilph.Adapter;
                    int          a    = default(int);
                    if (sm.soilphdetail.Where(p => p.SoilPhId == obj.SoilPhId).FirstOrDefault() != null)
                    {
                        a = adap.GetPosition(sm.soilphdetail.Where(p => p.SoilPhId == obj.SoilPhId).Select(s => s.SoilPhvalue).FirstOrDefault().ToString());
                    }
                    spinner_soilph.SetSelection(a);

                    ArrayAdapter adap_ = (ArrayAdapter)spinner_soiltype.Adapter;
                    int          a_    = default(int);
                    if (sm.soildetail.Where(p => p.SoilId == obj.SoilId).FirstOrDefault() != null)
                    {
                        a_ = adap_.GetPosition(sm.soildetail.Where(p => p.SoilId == obj.SoilId).Select(s => s.SoilName).FirstOrDefault().ToString());
                    }
                    spinner_soiltype.SetSelection(a_);

                    btn_add_new_plot.Text = "Update";
                }
            }
            catch (Exception ex)
            {
                curActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                        Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                        tx.Commit();
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            finally
            {
                if (dialog != null && dialog.IsShowing)
                {
                    dialog.Hide();
                    dialog.Dismiss();
                }
            }
        }
        protected void SavePlot(ProgressDialog dialog, Activity curActivity, PlotDetailResponse obj)
        {
            try
            {
                string mStringLoginInfo    = string.Empty;
                string mStringSessionToken = string.Empty;
                try
                {
                    objdb = new DBaseOperations();
                    var lstu = objdb.selectTable();
                    if (lstu != null && lstu.Count > default(int))
                    {
                        var uobj = lstu.FirstOrDefault();
                        if (uobj.Password == " ")
                        {
                            throw new Exception("Please login again");
                        }
                        mStringLoginInfo    = uobj.EmailId;
                        mStringSessionToken = uobj.AuthToken;
                    }
                }
                catch { }

                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Plot/CreateUpdatePlot", Method.POST);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("TokenKey", mStringSessionToken);
                request.AddJsonBody(new { PlotName = obj.PlotName, PlotSize = obj.PlotSize, Organic = obj.Organic, SoilPhId = obj.SoilPhId, SoilId = obj.SoilId, Notes = obj.Notes, FarmId = obj.FarmId, PlotId = obj.PlotId });
                IRestResponse response    = client.Execute(request);
                var           content     = response.Content;
                var           responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <PlotDetailResponse>(content);
                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    if (responseObj.Status == ResponseStatus.Successful)
                    {
                        curActivity.RunOnUiThread(() =>
                        {
                            Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                            alertDiag.SetTitle(Resource.String.DialogHeaderGeneric);
                            alertDiag.SetMessage(string.Format("'{0}' plot has been {1} successfully", obj.PlotName, (string.IsNullOrEmpty(obj.PlotId) ? "saved" : "updated")));
                            alertDiag.SetIcon(Resource.Drawable.success);
                            alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                            {
                                MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                                Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                                tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                                tx.Commit();
                            });
                            Dialog diag = alertDiag.Create();
                            diag.Show();
                            diag.SetCanceledOnTouchOutside(false);
                        });
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(responseObj.Error))
                        {
                            throw new Exception(responseObj.Error);
                        }
                        else
                        {
                            throw new Exception("Unable to save data now. Please try again later");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                curActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            finally
            {
                if (dialog != null && dialog.IsShowing)
                {
                    dialog.Hide();
                    dialog.Dismiss();
                }
            }
        }
Exemplo n.º 8
0
        public static Android.Support.V4.App.Fragment newInstance(Context context)
        {
            MyFarmDashboardFragment busrouteFragment = new MyFarmDashboardFragment();

            return(busrouteFragment);
        }
Exemplo n.º 9
0
        protected void GetPlotsByUser(ProgressDialog dialog, Activity curActivity, ViewGroup root, string frmid)
        {
            try
            {
                string mStringLoginInfo    = string.Empty;
                string mStringSessionToken = string.Empty;
                try
                {
                    objdb = new DBaseOperations();
                    var lstu = objdb.selectTable();
                    if (lstu != null && lstu.Count > default(int))
                    {
                        var uobj = lstu.FirstOrDefault();
                        if (uobj.Password == " ")
                        {
                            throw new Exception("Please login again");
                        }
                        mStringLoginInfo    = uobj.EmailId;
                        mStringSessionToken = uobj.AuthToken;
                    }
                }
                catch { }

                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Plot/GetPlotListDetails", Method.GET);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("TokenKey", mStringSessionToken);
                request.AddQueryParameter("farmid", System.Net.WebUtility.UrlEncode(frmid));
                IRestResponse response    = client.Execute(request);
                var           content     = response.Content;
                var           responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PlotDetailResponse> >(content);
                if (responseObj != null && responseObj.Count() > default(int))
                {
                    var newresponseObj = responseObj.OrderBy(o => o.PlotName);
                    if (newresponseObj != null && newresponseObj.Count() > default(int) && newresponseObj.FirstOrDefault() != null && !string.IsNullOrEmpty(newresponseObj.FirstOrDefault().PlotId))
                    {
                        gridViewString     = newresponseObj.Select(s => s.PlotName).ToArray();
                        gridViewCodeString = newresponseObj.Select(p => p.PlotId).ToArray();
                        var sp = newresponseObj.Select(s => s.PlotName).ToArray();
                        var sd = new List <string>();
                        foreach (var s in sp)
                        {
                            sd.Add(s[0].ToString().ToUpper());
                        }
                        gridViewLetterImage = sd.ToArray();
                        _letter_grid_menu_helper adapterViewAndroid = new _letter_grid_menu_helper(this.Activity, gridViewString, gridViewCodeString, gridViewLetterImage);
                        androidGridView = root.FindViewById <GridView>(Resource.Id.grid_view_plot_list_l);
                        new System.Threading.Thread(new System.Threading.ThreadStart(() =>
                        {
                            if (this.Activity != null)
                            {
                                this.Activity.RunOnUiThread(() =>
                                {
                                    androidGridView.SetAdapter(adapterViewAndroid);
                                });
                            }
                        })).Start();
                        androidGridView.ItemClick += (sndr, argus) => ItemSearch_clicked(sndr, argus, this.Activity);
                    }
                    else
                    {
                        throw new Exception("No plot found in our system");
                    }
                }
            }
            catch (Exception ex)
            {
                curActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                        Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                        tx.Commit();
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            finally
            {
                if (dialog != null && dialog.IsShowing)
                {
                    dialog.Hide();
                    dialog.Dismiss();
                }
            }
        }
        protected override void OnCreate(Bundle bundle)
        {
            try
            {
                base.OnCreate(bundle);
                SetContentView(Resource.Layout.activity_maincontent);

                mToolbar      = FindViewById <SupportToolbar>(Resource.Id.m_toolbar);
                mDrawerLayout = FindViewById <DrawerLayout>(Resource.Id.m_drawer_layout);
                mLeftDrawer   = FindViewById <ListView>(Resource.Id.m_left_drawer);

                dashboardFragment       = new DashboardFragment();
                myFarmDashboardFragment = new MyFarmDashboardFragment();
                myProfileFragment       = new MyProfileFragment();
                addActivityFragment     = new AddActivityFragment();
                activityViewerFragment  = new ActivityViewerFragment();
                askAggieFragment        = new AskAggieFragment();
                settingsFragment        = new SettingsFragment();
                contactFragment         = new ContactFragment();
                chatbotFragment         = new ChatbotFragment();
                chatListManagerFragment = new ChatListManagerFragment();

                mStackFragments = new Stack <SupportFragment>();

                mLeftDrawer.Tag = 0;

                SetSupportActionBar(mToolbar);

                mLeftDataSet = new List <string>();
                mLeftDataSet.Add("My Dashboard");
                mLeftDataSet.Add("My Farm");
                mLeftDataSet.Add("My Profile");
                mLeftDataSet.Add("Add Activitiy");
                mLeftDataSet.Add("View Activities");
                /*mLeftDataSet.Add("Ask an Aggie");*/
                /*mLeftDataSet.Add("Settings");*/

                var objdbTemp = new DBaseOperations();
                var lstux     = objdbTemp.selectTable();
                if (lstux != null && lstux.Count > default(int))
                {
                    var uobj = lstux.FirstOrDefault();
                    if (uobj != null && uobj.IsAdmin > default(int))
                    {
                        mLeftDataSet.Add("Chat Management");
                    }
                    else
                    {
                        mLeftDataSet.Add("Ask an Aggie");
                    }
                }
                else
                {
                    mLeftDataSet.Add("Ask an Aggie");
                }

                mLeftDataSet.Add("Contact Us");
                mLeftAdapter           = new ArrayAdapter <string>(this, Android.Resource.Layout.SimpleListItem1, mLeftDataSet);
                mLeftDrawer.Adapter    = mLeftAdapter;
                mLeftDrawer.ItemClick += MenuListView_ItemClick;

                mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, Resource.String.openDrawer, Resource.String.closeDrawer);

                mDrawerLayout.SetDrawerListener(mDrawerToggle);
                SupportActionBar.SetHomeButtonEnabled(true);
                SupportActionBar.SetDisplayShowTitleEnabled(true);
                SupportActionBar.SetDisplayHomeAsUpEnabled(true);
                mDrawerToggle.SyncState();

                if (bundle != null)
                {
                    if (bundle.GetString("DrawerState") == "Opened")
                    {
                        SupportActionBar.SetTitle(Resource.String.openDrawer);
                    }
                    else
                    {
                        SupportActionBar.SetTitle(Resource.String.closeDrawer);
                    }
                }
                else
                {
                    SupportActionBar.SetTitle(Resource.String.closeDrawer);
                }

                try
                {
                    string mStringLoginInfo    = string.Empty;
                    string mStringSessionToken = string.Empty;
                    string mStringGoodName     = string.Empty;
                    circular_imageViewLogo = this.FindViewById <Refractored.Controls.CircleImageView>(Resource.Id.circular_imageViewLogo);
                    imageViewLogo          = this.FindViewById <ImageView>(Resource.Id.imageViewLogo);
                    textView = this.FindViewById <TextView>(Resource.Id.textView);
                    try
                    {
                        objdb = new DBaseOperations();
                        var lstu = objdb.selectTable();
                        if (lstu != null && lstu.Count > default(int))
                        {
                            var uobj = lstu.FirstOrDefault();
                            if (uobj.Password == " ")
                            {
                                throw new Exception("Please login again");
                            }
                            mStringLoginInfo    = uobj.EmailId;
                            mStringSessionToken = uobj.AuthToken;
                            mStringGoodName     = uobj.GoodName;
                            _profilepicbase64   = uobj.ProfilePicture;
                        }
                    }
                    catch { }

                    if (!string.IsNullOrEmpty(_profilepicbase64))
                    {
                        var btmpimg = BitmapHelpers.Base64ToBitmap(_profilepicbase64);
                        circular_imageViewLogo.Visibility = ViewStates.Visible;
                        imageViewLogo.Visibility          = ViewStates.Gone;
                        textView.Text = string.Format("Hello, {0}", mStringGoodName);
                        circular_imageViewLogo.RecycleBitmap();
                        circular_imageViewLogo.SetImageBitmap(btmpimg);
                    }
                    else
                    {
                        circular_imageViewLogo.Visibility = ViewStates.Gone;
                        imageViewLogo.Visibility          = ViewStates.Visible;
                        textView.Text = !string.IsNullOrEmpty(mStringGoodName) ? string.Format("Hello, {0}", mStringGoodName) : "";
                    }
                }
                catch { }

                IList <Android.Support.V4.App.Fragment> fragmentsarray = SupportFragmentManager.Fragments;
                if (fragmentsarray != null && fragmentsarray.Count > default(int))
                {
                    foreach (Android.Support.V4.App.Fragment fragment in fragmentsarray)
                    {
                        string tag = fragment.Tag;
                        Android.Support.V4.App.FragmentTransaction tx = SupportFragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, fragment, fragment.Tag);
                        tx.Commit();
                        break;
                    }
                }
                else
                {
                    Android.Support.V4.App.FragmentTransaction tx = SupportFragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, dashboardFragment, Constants.dashboard);
                    tx.Commit();
                }
            }
            catch (Exception ex)
            {
                this.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(this);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        Intent intent = new Intent(this, typeof(MainActivity));
                        StartActivity(intent);
                        this.Finish();
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
        }
Exemplo n.º 11
0
        private void MapFarmToUserCall(ProgressDialog dialog, Activity curActivity)
        {
            try
            {
                farmId = arrFields.Where(x => x.FarmName == spinnerx0txt).Select(f => f.FarmId).FirstOrDefault();

                string mStringLoginInfo    = string.Empty;
                string mStringSessionToken = string.Empty;
                try
                {
                    objdb = new DBaseOperations();
                    var lstu = objdb.selectTable();
                    if (lstu != null && lstu.Count > default(int))
                    {
                        var uobj = lstu.FirstOrDefault();
                        if (uobj.Password == " ")
                        {
                            throw new Exception("Please login again");
                        }
                        mStringLoginInfo    = uobj.EmailId;
                        mStringSessionToken = uobj.AuthToken;
                    }
                }
                catch { }

                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Farm/MapFarmByUserDetail", Method.POST);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("TokenKey", mStringSessionToken);
                request.AddQueryParameter("FarmId", farmId);
                IRestResponse response    = client.Execute(request);
                var           content     = response.Content;
                var           responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <FarmDetailResponse>(content);
                if (responseObj.Status == ResponseStatus.Successful)
                {
                    MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                    Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                    tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                    tx.Commit();
                }
                else
                {
                    throw new Exception(responseObj.Error);
                }
            }
            catch (Exception ex)
            {
                curActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            finally
            {
                if (dialog != null && dialog.IsShowing)
                {
                    dialog.Hide();
                    dialog.Dismiss();
                }
            }
        }