// Insert, update all tables in local db public async Task InsertUpdateTables(DataTb data) { foreach (FAQ f in data.FAQ) { await InsertOrUpdateTableAsyncFAQ(f); } foreach (Events e in data.Events) { await InsertOrUpdateTableAsyncEvents(e); } foreach (Exhibition ex in data.Exhibition) { await InsertOrUpdateTableAsyncExhibition(ex); } foreach (Map m in data.Map) { await InsertOrUpdateTableAsyncMap(m); } foreach (News n in data.News) { await InsertOrUpdateTableAsyncNews(n); } foreach (QRCodes qr in data.QRCodes) { await InsertOrUpdateTableAsyncQRCodes(qr); } }
private void LoadCmdBtn_Click(object sender, EventArgs e) { using (OpenFileDialog op = new OpenFileDialog()) { op.Title = "Chose CMD"; op.Filter = "CMD files (*.cmd)|*.cmd|All files (*.*)|*.*"; if (op.ShowDialog() == DialogResult.OK) { var fileStream = op.OpenFile(); CmdTb.Clear(); DataTb.Clear(); using (StreamReader reader = new StreamReader(fileStream)) { string line; cmd_array.Clear(); int i = 0; while ((line = reader.ReadLine()) != null) { string[] data_array = line.Split(new char[] { ' ' }); cmd_array.Add(data_array); CmdTb.AppendText("[" + i.ToString() + "] " + line + "\r\n"); i++; } } } } }
protected async void DataAsync() { SQLiteDB deepSeaWorld = new SQLiteDB(); MySqlDBCon mySql = new MySqlDBCon(); DataTb data = new DataTb(); data = await mySql.MySQLConnection(); // connection and data catch from mySQL db on server deepSeaWorld.TableAsync(); // table async - creation of local db tables await deepSeaWorld.InsertUpdateTables(data); // insert data to local db }
static async System.Threading.Tasks.Task Secondary() { Console.WriteLine("Secondary"); DeepSeaWorldSQLiteConnectioniOS deepSeaWorld = new DeepSeaWorldSQLiteConnectioniOS(); MySqlDBCon mySql = new MySqlDBCon(); DataTb data = new DataTb(); data = await mySql.MySQLConnection(); // connection and data catch from mySQL db on server deepSeaWorld.TableAsync(); // table async - creation of local db tables await deepSeaWorld.InsertUpdateTables(data); // insert data to local db }
protected override async void OnCreate(Bundle savedInstanceState) { try { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(savedInstanceState); timer.Start(); timer.Interval = 2000; timer.Elapsed += Timer_Elapsed; PermissionCheck(); // storage permission ZXing.Net.Mobile.Forms.Android.Platform.Init(); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); app = new App(); //get and set screen width and height of device var width = Resources.DisplayMetrics.WidthPixels; var height = Resources.DisplayMetrics.HeightPixels; var density = Resources.DisplayMetrics.Density; App.ScreenWidth = (width - 0.5f) / density; App.ScreenHeight = (height - 0.5f) / density; LoadApplication(app); if (ActivityCompat.CheckSelfPermission(this, Manifest.Permission.Camera) == (int)Permission.Granted) { Toast.MakeText(this, "camera permission granted", ToastLength.Long).Show(); } else { RequestCameraPermission(); } // SQLite connection, table creation, update, insert and get class DeepSeaWorldSQLiteConnectionAndroid deepSeaWorld = new DeepSeaWorldSQLiteConnectionAndroid(); MySqlDBCon mySql = new MySqlDBCon(); DataTb data = new DataTb(); data = await mySql.MySQLConnection(); // connection and data catch from mySQL db on server deepSeaWorld.TableAsync(); // table async - creation of local db tables await deepSeaWorld.InsertUpdateTables(data); // insert data to local db } catch (Exception ex) { throw ex; } }
private void WriteTextSafe(string text) { DataTb.BeginInvoke(new MethodInvoker(() => { DataTb.AppendText(text); })); //if (DataTb.InvokeRequired) //{ // var d = new SafeCallDelegate(WriteTextSafe); // DataTb.Invoke(d, new object[] { text }); //} //else //{ // DataTb.AppendText(text); //} }
// Insert, update all tables in local db public async Task InsertUpdateTables(DataTb data) { foreach (FAQ f in data.FAQ) { await InsertOrUpdateTableAsyncFAQ(f); Log.Debug("FAQ_TB INSERT", f.ToString()); } foreach (Events e in data.Events) { await InsertOrUpdateTableAsyncEvents(e); Log.Debug("Events_TB INSERT", e.ToString()); } foreach (Exhibition ex in data.Exhibition) { await InsertOrUpdateTableAsyncExhibition(ex); Log.Debug("Exhibition_TB INSERT", ex.ToString()); } foreach (Map m in data.Map) { await InsertOrUpdateTableAsyncMap(m); Log.Debug("Map_TB INSERT", m.ToString()); } foreach (News n in data.News) { await InsertOrUpdateTableAsyncNews(n); Log.Debug("News_TB INSERT", n.ToString()); } foreach (QRCodes qr in data.QRCodes) { await InsertOrUpdateTableAsyncQRCodes(qr); Log.Debug("QRCodes_TB INSERT", qr.ToString()); } }
// connection and retriving data from server database, serialization of data to json public async Task <DataTb> MySQLConnection() { DataTb dataTb = new DataTb(); HttpClient client = new HttpClient(); Uri url; if (Device.RuntimePlatform == Device.iOS) { url = new Uri("http://localhost:8888/scripts/dbContent.php"); client.BaseAddress = new Uri("http://localhost:8888/"); } else { url = new Uri("http://10.0.2.2/scripts/dbContentAndroid.php"); client.BaseAddress = new Uri("http://10.0.2.2/"); } var resp = await client.GetAsync(url); // responce from web client service (async with Mysql db) string content = resp.Content.ReadAsStringAsync().Result; // temporary IList to keep db table tada before serialization IList faq = new ArrayList(); IList events = new ArrayList(); IList exhibition = new ArrayList(); IList map = new ArrayList(); IList news = new ArrayList(); IList qrcodes = new ArrayList(); // spliting db data recived web responce service faq.Add(content.Split(']')[0]); events.Add(content.Split(']')[1]); exhibition.Add(content.Split(']')[2]); map.Add(content.Split(']')[3]); news.Add(content.Split(']')[4]); qrcodes.Add(content.Split(']')[5]); // preparing data for deserialization var fq = faq[0].ToString().Trim().Insert(faq[0].ToString().Length, "]"); var ev = events[0].ToString().Trim().Insert(events[0].ToString().Length, "]"); var ex = exhibition[0].ToString().Trim().Insert(exhibition[0].ToString().Length, "]"); var mp = map[0].ToString().Trim().Insert(map[0].ToString().Length, "]"); var nws = news[0].ToString().Trim().Insert(news[0].ToString().Length, "]"); var qr = qrcodes[0].ToString().Trim().Insert(qrcodes[0].ToString().Length, "]"); // deserializatyion of data in json format to responding classes List <FAQ> flist = JsonConvert.DeserializeObject <List <FAQ> >(fq); List <Events> elist = JsonConvert.DeserializeObject <List <Events> >(ev); List <Exhibition> exlist = JsonConvert.DeserializeObject <List <Exhibition> >(ex); List <Map> mlist = JsonConvert.DeserializeObject <List <Map> >(mp); List <News> nlist = JsonConvert.DeserializeObject <List <News> >(nws); List <QRCodes> qrlist = JsonConvert.DeserializeObject <List <QRCodes> >(qr); dataTb.FAQ = flist; dataTb.Events = elist; dataTb.Exhibition = exlist; dataTb.Map = mlist; dataTb.News = nlist; dataTb.QRCodes = qrlist; return(dataTb); }
private void ClearBtn_Click(object sender, EventArgs e) { CmdTb.Clear(); DataTb.Clear(); }