protected override void OnCreate(Bundle savedInstanceState) { try { LayoutInflater.Factory = CustomViewFactory.getInstance(); base.OnCreate(savedInstanceState); initForm(); } catch (Exception exc) { ToolMobile.setExceptionInner(exc); var err = ToolException.unwrap(exc); Close(); Android.Widget.Toast.MakeText(this.ApplicationContext, err, Android.Widget.ToastLength.Long).Show(); } }
void doneAsync() { lock (environment) { bool ok = false; try { // log.set(MessageCollection.T_MSG_OPERATION_STARTING); // makeDbReadonly(); // string fileWorkDir = ToolMobile.getFullPath("data"); ToolMobile.createDir(fileWorkDir); string fileOutputZip = Path.Combine(fileWorkDir, "toava.zip"); string fileOutputXml = Path.Combine(fileWorkDir, "toava.xml"); // bool res = false; //Source //if (environment.getAppSettings().getBool(AvaExt.Settings.SettingsAvaAgent.MOB_USE_LOCAL_EXPIMP_B)) //{ // //SaveFileDialog sfd = new SaveFileDialog(); // //if (sfd.ShowDialog() == DialogResult.OK) // // fileOutputXml = sfd.FileName; // //else // // throw new Exception(string.Empty); //} // log.set(MessageCollection.T_MSG_DATA_READING); // XmlDocument doc = new XmlDocument(); string docID = "LOGICALREF"; AdapterUserDocument[] adapters = new AdapterUserDocument[] { new AdapterUserWholesaleSlip(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetWholesaleSlip(environment))), new AdapterUserWholesaleOrder(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetWholesaleOrder(environment))), new AdapterUserCashClient(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetCashClient(environment))) }; IPagedSource[] sources = new IPagedSource[] { new PagedSourceSlip(environment), new PagedSourceOrder(environment), new PagedSourceCashTrans(environment) }; string[] arrDesc = new string[] { environment.translate(WordCollection.T_DOC_STOCK_TRANS), environment.translate(WordCollection.T_DOC_STOCK_ORDERS), environment.translate(WordCollection.T_DOC_FINANCE) }; bool hasData = false; for (int i = 0; i < sources.Length; ++i) { IPagedSource source = sources[i]; source.getBuilder().addParameterValue(TableDUMMY.CANCELLED, ConstBool.not); AdapterUserDocument adapter = adapters[i]; log.set(MessageCollection.T_MSG_DATA_READING, new object[] { arrDesc[i] }); DataTable table = source.getAll(); log.set(MessageCollection.T_MSG_DATA_EXPORT, new object[] { arrDesc[i] }); foreach (DataRow row in table.Rows) { hasData = true; adapter.edit(row[docID]); adapter.export(doc); } } if (!hasData) { throw new Exception(MessageCollection.T_MSG_ERROR_NO_DATA); } // string[] expSettings = environment.getSysSettings().getAllSettings(); foreach (string settingsName in expSettings) { if (settingsName.StartsWith("MOB_SYS_")) { XmlAttribute attr = doc.CreateAttribute(settingsName); attr.Value = environment.getSysSettings().getString(settingsName); doc.DocumentElement.Attributes.Append(attr); } } // log.set(MessageCollection.T_MSG_DATA_WRITING); // doc.Save(fileOutputXml); ToolZip.compress(fileOutputZip, fileOutputXml); // if (!environment.getAppSettings().getBool(AvaExt.Settings.SettingsAvaAgent.MOB_USE_LOCAL_EXPIMP_B)) // { if (ToolMobile.existsFile(fileOutputZip)) { // log.set(MessageCollection.T_MSG_DATA_SENDING); // AgentData ad = new AgentData(environment); ad.chackOperationResult(ad.sendData(ToolMobile.readFileData(fileOutputZip))); } // } ok = true; } catch (Exception exc) { log.error(ToolException.unwrap(exc)); environment.getExceptionHandler().setException(exc); } finally { log.set(MessageCollection.T_MSG_OPERATION_FINISHING); Thread.Sleep(1000); log.hide(); } } }
void doneAsync() { lock (environment) { ISettings oldSysSettings = environment.getSysSettings(); try { // bool localDebugImport = false; #if DEBUG localDebugImport = false; #endif log.set(MessageCollection.T_MSG_OPERATION_STARTING); // ToolMobile.setRuntimeMsg("Data import starting"); if (!localDebugImport) { checkDataSource(); } // string fileWorkDir = Path.Combine(ToolMobile.curDir(), "data"); ToolMobile.createDir(fileWorkDir); string fileInputZip = Path.Combine(fileWorkDir, "fromava.zip"); string fileInputXml = Path.Combine(fileWorkDir, "fromava.xml"); // bool state = false; //Source if (localDebugImport)//CurrentVersion.ENV.isLocalExim() { //!!// } else { { // log.set(MessageCollection.T_MSG_DATA_RECEIVING); // AgentData ad = new AgentData(environment); ServerResult sr; ad.chackOperationResult(sr = ad.resiveData()); byte[] data = sr.data; // log.set(MessageCollection.T_MSG_DATA_WRITING); // ToolMobile.writeFileData(fileInputZip, data); ToolZip.decompress(fileInputZip, Path.GetDirectoryName(fileInputZip)); } } //Get log.set(MessageCollection.T_MSG_DATA_READING); // XmlDocument doc = new XmlDocument(); doc.Load(fileInputXml); // if (isSameData(doc, oldSysSettings)) { throw new Exception(MessageCollection.T_MSG_DATA_OLD); } // var commited = false; try { environment.beginBatch(); // #region delete firm prm log.set(MessageCollection.T_MSG_DATA_DELETING); // { string[] arrTables = new string[] { TableFIRMPARAMS.TABLE_FULL_NAME }; string[] arrDesc = new string[] { environment.translate(WordCollection.T_ADDITIONAL) }; deleteTables(arrTables, arrDesc); } // // #endregion // #region import firm prm // log.set(MessageCollection.T_MSG_DATA_IMPORT); // { AdapterUserRecords[] arrAdapters = new AdapterUserRecords[] { new AdapterUserFirmParams(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetFirmParams(environment))) }; string[] arrDesc = new string[] { environment.translate(WordCollection.T_ADDITIONAL) }; importRecords(doc, arrAdapters, arrDesc); } #endregion // #region sys settings environment.setSysSettings(getSysSettings()); //environment.getSysSettings().set(SettingsSysMob.MOB_SYS_LAST_IMPORT, DateTime.Now); #endregion // #region delete rec log.set(MessageCollection.T_MSG_DATA_DELETING); // { string[] arrTables = new string[] { TableCLCARD.TABLE_FULL_NAME, TableITEMS.TABLE_FULL_NAME, TableWHOUSE.TABLE_FULL_NAME, TableINFOFIRM.TABLE_FULL_NAME, TableINFOPERIOD.TABLE_FULL_NAME, TableINFODOCSAVE.TABLE_FULL_NAME }; string[] arrDesc = new string[] { environment.translate(WordCollection.T_CLIENT), environment.translate(WordCollection.T_MATERIAL), environment.translate(WordCollection.T_WAREHOUSE), environment.translate(WordCollection.T_INFO), environment.translate(WordCollection.T_INFO), environment.translate(WordCollection.T_INFO) }; deleteTables(arrTables, arrDesc); } // // #endregion // #region docs log.set(MessageCollection.T_MSG_DOCS_DELETING); // DateTime limDate = environment.getSysSettings().getDateTime(SettingsSysMob.MOB_SYS_CMD_DELETE_DOCS_BEFORE, new DateTime(DateTime.Now.Year, 1, 1)); { string[][] arrTablesGroup = new string[][] { new string[] { TableINVOICE.TABLE_FULL_NAME, TableSTLINE.TABLE_LONG }, new string[] { TableORFICHE.TABLE_FULL_NAME, TableORFLINE.TABLE_LONG }, new string[] { TableKSLINES.TABLE_FULL_NAME } }; string[] arrDesc = new string[] { environment.translate(WordCollection.T_DOC_STOCK_TRANS), environment.translate(WordCollection.T_DOC_STOCK_ORDERS), environment.translate(WordCollection.T_DOC_FINANCE) }; deleteDocTables(arrTablesGroup, arrDesc, limDate); } #endregion // #region import // log.set(MessageCollection.T_MSG_DATA_IMPORT); // { AdapterUserRecords[] arrAdapters = new AdapterUserRecords[] { new AdapterUserClient(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetClient(environment))), new AdapterUserMaterial(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetMaterial(environment))), new AdapterUserWarehouse(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetWarehouse(environment))), new AdapterUserInfoFirm(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetInfoFirm(environment))), new AdapterUserInfoPeriod(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetInfoPeriod(environment))), new AdapterUserInfoDocSave(environment, new ImplAdapterDataSetStub(environment, new AdapterDataSetInfoDocSave(environment))) }; string[] arrDesc = new string[] { environment.translate(WordCollection.T_CLIENT), environment.translate(WordCollection.T_MATERIAL), environment.translate(WordCollection.T_WAREHOUSE), environment.translate(WordCollection.T_INFO), environment.translate(WordCollection.T_INFO), environment.translate(WordCollection.T_INFO) }; importRecords(doc, arrAdapters, arrDesc); } #endregion //clear // environment.clearStateData(); // //ToolMobile.setRuntimeMsg("Data importded, commit started"); environment.commitBatch(); // state = true; commited = true; // ToolMobile.setRuntimeMsg("Data importded, commited"); #region files { try { var files = doc.SelectSingleNode("DATA/ITEM[@ei_code='ADP_FILES']"); if (files != null) { foreach (var file in files) { var el = file as XmlElement; if (el != null) { var dir = ToolXml.getAttribValue(el, "dir", null); var name = ToolXml.getAttribValue(el, "name", null); var value_ = ToolXml.getAttribValue(el, "value", null); if (dir != null && name != null && value_ != null) { if (Path.IsPathRooted(dir)) { log.error(WordCollection.T_FILE + ": Path rooted: " + dir); } else { if (!ToolMobile.existsDir(dir)) { ToolMobile.createDir(dir); } var path = Path.Combine(dir, name); log.set(WordCollection.T_FILE + ": " + path); var data = Convert.FromBase64String(value_); ToolMobile.writeFileData(path, data); } } } } } } catch (Exception exc) { ToolMobile.setExceptionInner(exc); log.error("Files import error"); ToolMobile.setException(exc); } } #endregion } catch (Exception exc) { try { ToolMobile.setExceptionInner(exc); } catch { } try { if (!commited) { ToolMobile.setRuntimeMsg("Data import error, rollback started"); environment.rollbackBatch(); ToolMobile.setRuntimeMsg("Data import error, rollback ended"); } } catch { } environment.setSysSettings(oldSysSettings); throw new Exception(exc.Message, exc); } //if (commited) //{ // var dir = "cache"; // if (ToolMobile.existsDir(dir)) // ToolMobile.deleteDir(dir); //} } catch (Exception exc) { ToolMobile.setExceptionInner(exc); var err = ToolException.unwrap(exc); ToolMobile.setRuntimeMsg(err); ToolMobile.getContextLast().RunOnUiThread(() => { try { Android.Widget.Toast.MakeText(Android.App.Application.Context, err, Android.Widget.ToastLength.Long).Show(); } catch { } }); // ActivityExt.errMessageOnResume = err; log.error(ToolException.unwrap(exc)); environment.getExceptionHandler().setException(exc); } finally { log.set(MessageCollection.T_MSG_OPERATION_FINISHING); Thread.Sleep(1000); log.hide(); } } }