Ejemplo n.º 1
0
 public ActivityHistoryDetails(CAFTable item)
 {
     InitializeComponent();
     GetCafDetails(item.CAFNo);
     GetRekorida(item.CAFNo);
     GetMerchandizing(item.CAFNo);
     GetTradeCheck(item.CAFNo);
     GetOthers(item.CAFNo);
     GetRapport(item.CAFNo);
     GetStock(item.CAFNo);
     GetReplenish(item.CAFNo);
     GetRetouch(item.CAFNo);
     GetFeed(item.CAFNo);
     GetLocation(item.CustomerID);
     GetRetailerName(item.CustomerID);
 }
Ejemplo n.º 2
0
        private async void lstActivity_ItemTapped(object sender, ItemTappedEventArgs e)
        {
            try
            {
                var appdate = Preferences.Get("appdatetime", String.Empty, "private_prefs");

                if (string.IsNullOrEmpty(appdate))
                {
                    Preferences.Set("appdatetime", DateTime.Now.ToString(), "private_prefs");
                }
                else
                {
                    try
                    {
                        if (DateTime.Now >= DateTime.Parse(Preferences.Get("appdatetime", String.Empty, "private_prefs")))
                        {
                            Preferences.Set("appdatetime", DateTime.Now.ToString(), "private_prefs");

                            CAFTable item = (CAFTable)e.Item;

                            await Application.Current.MainPage.Navigation.PushModalAsync(new NavigationPage(new ActivityHistoryDetails(item))
                            {
                                BarBackgroundColor = Color.FromHex("#f1c40f")
                            });
                        }
                        else
                        {
                            await DisplayAlert("Application Error", "It appears you change the time/date of your phone. You will be logged out. Please restore the correct time/date", "Ok");

                            await Navigation.PopToRootAsync();
                        }
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        await DisplayAlert("Application Error", "Error:\n\n" + ex.Message.ToString() + "\n\n Please contact your administrator", "Ok");
                    }
                }
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
                await DisplayAlert("Application Error", "Error:\n\n" + ex.Message.ToString() + "\n\n Please contact your administrator", "Ok");
            }
        }
        public async void Send_offline()
        {
            try
            {
                var cafNo            = entCafNo.Text;
                var customerID       = entCustomerID.Text;
                var contactPerson    = entContactPerson.Text;
                var activityID       = entActivity.Text;
                var date             = dpDate.Text;
                var startTime        = tpTime.Text;
                var endTime          = DateTime.Now.ToString("HH:mm:ss");
                var remarks          = entRemarks.Text;
                var others           = entOthers.Text;
                var breakfast        = entBreakfast.Text;
                var lunch            = entLunch.Text;
                var dinner           = entDinner.Text;
                var hotel            = entHotel.Text;
                var transportation   = entTransportation.Text;
                var cash             = entCash.Text;
                var deleted          = 0;
                var current_datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var signatureFile    = cafNo + ".jpg";

                Stream sigimage = await Signature.GetImageStreamAsync(SignaturePad.Forms.SignatureImageFormat.Jpeg);

                string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), signatureFile);

                using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
                {
                    await sigimage.CopyToAsync(fileStream);
                }

                var db   = DependencyService.Get <ISQLiteDB>();
                var conn = db.GetConnection();

                var caf_insert = new CAFTable
                {
                    CAFNo              = cafNo,
                    EmployeeID         = contact,
                    CAFDate            = DateTime.Parse(date),
                    CustomerID         = customerID,
                    ContactPersonID    = contactPerson,
                    ActivityID         = activityID,
                    Breakfast          = float.Parse(breakfast),
                    Lunch              = float.Parse(lunch),
                    Dinner             = float.Parse(dinner),
                    HotelAccommodation = float.Parse(hotel),
                    TransportationFare = float.Parse(transportation),
                    CashAdvance        = float.Parse(cash),
                    StartTime          = DateTime.Parse(startTime),
                    EndTime            = DateTime.Parse(endTime),
                    Remarks            = remarks,
                    MobileSignature    = fileName,
                    Signature          = fileName,
                    OtherConcern       = others,
                    Deleted            = deleted,
                    LastUpdated        = DateTime.Parse(current_datetime)
                };

                await conn.InsertAsync(caf_insert);

                await DisplayAlert("Offline Save", "Your activity has been saved offline. Connect to the server to send your activity", "Got it");

                await Application.Current.MainPage.Navigation.PopAsync();

                //if (File.Exists(fileName))
                //{
                //    await DisplayAlert("File", "exist", "ok");
                //}
                //else
                //{
                //    await DisplayAlert("ad", "not exist", "ok");
                //}
            }
            catch (Exception ex)
            {
                Crashes.TrackError(ex);
            }
        }
Ejemplo n.º 4
0
 public ActivityHistoryDetails(CAFTable item)
 {
     InitializeComponent();
     GetCafDetails(item.CAFNo);
 }
        public async void Send_online()
        {
            var cafNo            = entCafNo.Text;
            var customerID       = entCustomerID.Text;
            var contactPerson    = entContactPerson.Text;
            var activityID       = entActivity.Text;
            var date             = dpDate.Text;
            var startTime        = tpTime.Text;
            var endTime          = DateTime.Now.ToString("HH:mm:ss");
            var remarks          = entRemarks.Text;
            var others           = entOthers.Text;
            var breakfast        = entBreakfast.Text;
            var lunch            = entLunch.Text;
            var dinner           = entDinner.Text;
            var hotel            = entHotel.Text;
            var transportation   = entTransportation.Text;
            var cash             = entCash.Text;
            var deleted          = 0;
            var current_datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var signatureFile    = cafNo + ".jpg";

            Stream sigimage = await Signature.GetImageStreamAsync(SignaturePad.Forms.SignatureImageFormat.Jpeg);

            string fileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), signatureFile);

            using (var fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write))
            {
                await sigimage.CopyToAsync(fileStream);
            }

            string  url         = "http://" + ipaddress + Constants.requestUrl + "Host=" + host + "&Database=" + database + "&Request=k5N7PE";
            string  contentType = "application/json";
            JObject json        = new JObject
            {
                { "CAFNo", cafNo },
                { "EmployeeID", contact },
                { "ContactPersonID", contactPerson },
                { "CAFDate", DateTime.Parse(date) },
                { "CustomerID", customerID },
                { "ActivityID", activityID },
                { "StartTime", DateTime.Parse(startTime) },
                { "EndTime", DateTime.Parse(endTime) },
                { "Breakfast", breakfast },
                { "Lunch", lunch },
                { "Dinner", dinner },
                { "HotelAccommodation", hotel },
                { "TransportationFare", transportation },
                { "CashAdvance", cash },
                { "MobileSignature", fileName },
                { "Remarks", remarks },
                { "OtherConcern", others },
                { "Deleted", deleted },
                { "LastUpdated", DateTime.Parse(current_datetime) }
            };

            HttpClient client   = new HttpClient();
            var        response = await client.PostAsync(url, new StringContent(json.ToString(), Encoding.UTF8, contentType));

            if (response.IsSuccessStatusCode)
            {
                byte[] crSignatureData = File.ReadAllBytes(fileName);

                var     siglink        = "http://" + ipaddress + Constants.requestUrl + "Host=" + host + "&Database=" + database + "&Contact=" + contact + "&Request=N4f5GL";
                string  sigcontentType = "application/json";
                JObject sigjson        = new JObject
                {
                    { "CAFNo", cafNo },
                    { "CAFDate", DateTime.Parse(date) },
                    { "Signature", crSignatureData }
                };

                HttpClient sigclient   = new HttpClient();
                var        sigresponse = await sigclient.PostAsync(siglink, new StringContent(sigjson.ToString(), Encoding.UTF8, sigcontentType));

                if (sigresponse.IsSuccessStatusCode)
                {
                    try
                    {
                        var db   = DependencyService.Get <ISQLiteDB>();
                        var conn = db.GetConnection();

                        var caf_insert = new CAFTable
                        {
                            CAFNo              = cafNo,
                            EmployeeID         = contact,
                            CAFDate            = DateTime.Parse(date),
                            CustomerID         = customerID,
                            ContactPersonID    = contactPerson,
                            ActivityID         = activityID,
                            Breakfast          = float.Parse(breakfast),
                            Lunch              = float.Parse(lunch),
                            Dinner             = float.Parse(dinner),
                            HotelAccommodation = float.Parse(hotel),
                            TransportationFare = float.Parse(transportation),
                            CashAdvance        = float.Parse(cash),
                            StartTime          = DateTime.Parse(startTime),
                            EndTime            = DateTime.Parse(endTime),
                            Remarks            = remarks,
                            MobileSignature    = fileName,
                            Signature          = fileName,
                            OtherConcern       = others,
                            Deleted            = deleted,
                            LastSync           = DateTime.Parse(current_datetime),
                            LastUpdated        = DateTime.Parse(current_datetime)
                        };

                        await conn.InsertAsync(caf_insert);

                        await DisplayAlert("Data Sent", "Your activity has been sent to the server", "Got it");

                        await Application.Current.MainPage.Navigation.PopAsync();
                    }
                    catch (Exception ex)
                    {
                        Crashes.TrackError(ex);
                        Send_offline();
                    }
                }
            }
        }