Ejemplo n.º 1
0
        private void HandleClickSaveInfo(object sender, EventArgs e)
        {
            HideKeyboard();
            TypeWorkDB typeWork;
            string specialistSid;
            using (var dbConnection = new SQLiteConnection(mDBUnitAndroidPrinterApp))
            {
                string selectTypeWork = mSpinner.SelectedItem.ToString();
                typeWork = dbConnection.Get<TypeWorkDB>(x => x.Name == selectTypeWork);

                specialistSid = dbConnection.Get<AccountDB>(x => x.Login == mLogin).Sid;
            }
            DispatchDB dispatch = new DispatchDB()
            {
                DeviceSerialNum = mSerialKey.Text,
                Address = mAddress.Text,
                ClientName = mClientName.Text,
                CounterColor = mColorCounter.Text,
                CounterMono = mMonoCounter.Text,
                DateCreate = DateTime.Now,
                Descr = mComment.Text,
                DeviceModel = mDeviceModel.Text,
                CityName = string.Empty,
                IdDevice = m_deviceInfoDB.DeviceId,
                IdWorkType = typeWork.Id,
                SpecialistSid = specialistSid
            };

            try
            {
                m_unitAPIShellSaver.PushData(dispatch);
            }
            catch (WebException webEx)
            {
                try
                {
                    m_unitAPIShellSaver.SaveLocalData(dispatch);
                }
                catch (SQLiteException dbEx)
                {
                    string resError = Resources.GetString(Resource.String.ErrorSaveInfo);
                    string errorDescr = string.Format(
                        resError + System.Environment.NewLine +
                        "Web error: {0}" + System.Environment.NewLine + "DB error: {1}",
                        webEx.Message, dbEx.Message);
                    Toast.MakeText(this, errorDescr, ToastLength.Long).Show();
                }
            }

            GoCompleteSaveEntryActivity();
        }
Ejemplo n.º 2
0
        protected async Task<string> PushPrinterEntryAsync(DispatchDB dispatch)
        {
            string urlApi = "http://test.api.unitgroup.ru/data/ServiceMobile/SavePlanServiceIssue";

            string jsonStr = JsonConvert.SerializeObject(dispatch);

            string responseStr = await _getApiResponseAsync(_getApiRequest(urlApi, jsonStr));

            var id = JsonConvert.DeserializeAnonymousType(responseStr, new { id = string.Empty });
            if (id.id == null)
            {
                var errorMessage = JsonConvert.DeserializeAnonymousType(
                    responseStr, new { errorMessage = string.Empty });
                throw new WebException(errorMessage.errorMessage);
            }

            return id.id;
        }