예제 #1
0
        // ==================================================================

        private void DownloadVendorCatLists()
        {
            // ==============================================================
            // Use FoxScannerSvc to get string of vendor codes + names
            // ==============================================================

            Message msg = new Message();

            svcCallHandler = new EventandlerSvcCallComplete(this);
            msg            = svcCallHandler.ObtainMessage();

            ProgressDialog progBar = new ProgressDialog(this);

            progBar.SetCancelable(false);
            progBar.SetTitle("Synchronizing...");
            progBar.SetIcon(Resource.Drawable.iconChill64);
            progBar.SetMessage("Downloading vendor list from server");
            progBar.SetProgressStyle(ProgressDialogStyle.Spinner);
            progBar.Show();

            var thread = new System.Threading.Thread(new ThreadStart(delegate
            {
                try
                {
                    FoxScannerSvc.FoxScannerSvc foxSql = new FoxScannerSvc.FoxScannerSvc();
                    vendors = foxSql.GetVendorList();

                    RunOnUiThread(() =>
                    {
                        progBar.SetMessage("Downloading category list from server");
                    });

                    categories = foxSql.GetCategoryList();

                    RunOnUiThread(() =>
                    {
                        progBar.Dismiss();
                    });

                    msg.Arg1 = 0;
                    msg.Arg2 = 1;
                    svcCallHandler.SendMessage(msg);
                }
                catch (Exception ex)
                {
                    RunOnUiThread(() =>
                    {
                        progBar.Dismiss();
                    });

                    msg.Arg1 = 1;
                    msg.Arg2 = 1;
                    svcCallHandler.SendMessage(msg);
                }
            }));

            thread.Start();
        } // ImportVendorAndCategories()
예제 #2
0
        } // ImportVendorAndCategories()

        public void ImportVendorCatListsToDB()
        {
            Message msg = new Message();

            svcCallHandler = new EventandlerSvcCallComplete(this);
            msg            = svcCallHandler.ObtainMessage();

            ProgressDialog progBar = new ProgressDialog(this);

            progBar.SetCancelable(false);
            progBar.SetTitle("Synchronizing...");
            progBar.SetIcon(Resource.Drawable.iconChill64);
            progBar.SetMessage("Importing vendor records...");
            progBar.SetProgressStyle(ProgressDialogStyle.Horizontal);
            progBar.Progress = 0;
            progBar.Max      = vendors.Split('|').GetUpperBound(0);
            progBar.Show();

            var thread = new System.Threading.Thread(new ThreadStart(delegate
            {
                // ============================================
                // IMPORT VENDORS
                // ============================================

                string[] vendorData = vendors.Split('|');

                db.ExecWriteSQLite(Constants.DBFilename, "delete from FoxVendor", ref dbError);

                int i = 0;

                while (i <= vendorData.GetUpperBound(0))
                {
                    string qryInsert      = "";
                    string[] vendorDetail = new string[2];
                    int recCT             = 0;
                    bool chunkOK          = true;

                    while (chunkOK)
                    {
                        if (vendorData[i].Trim() != "")
                        {
                            vendorDetail = vendorData[i].Split(',');
                            qryInsert   += "insert into FoxVendor (VendorCode, VendorName) values ('" + vendorDetail[0] + "','" + vendorDetail[1] + "'); ";
                        }
                        i++;
                        recCT++;
                        if ((recCT >= 25) || (i > vendorData.GetUpperBound(0)))
                        {
                            chunkOK = false;
                        }
                    }

                    if (qryInsert != "")
                    {
                        if (!db.ExecWriteSQLiteBatch(Constants.DBFilename, qryInsert, ref dbError))
                        {
                            //Toast.MakeText((this.ApplicationContext), "Success!", ToastLength.Long).Show();
                            //txtdbResult.Text += "Failed insert code: " + vendorDetail[0] + "  ";
                        }
                    }

                    RunOnUiThread(() =>
                    {
                        progBar.Progress = i;
                    });
                }  // while (i <= vendorData.GetUpperBound(0))

                // =======================================
                // Import Categories
                // =======================================

                RunOnUiThread(() =>
                {
                    progBar.SetTitle("Synchronizing...");
                    progBar.SetIcon(Resource.Drawable.iconChill64);
                    progBar.SetMessage("Importing category records...");
                    progBar.SetProgressStyle(ProgressDialogStyle.Horizontal);
                    progBar.Progress = 0;
                    progBar.Max      = categories.Split('|').GetUpperBound(0);
                });

                string[] categoryData = categories.Split('|');

                db.ExecWriteSQLite(Constants.DBFilename, "delete from FoxCategory", ref dbError);

                i = 0;

                while (i <= categoryData.GetUpperBound(0))
                {
                    string qryInsert        = "";
                    string[] categoryDetail = new string[2];
                    int recCT    = 0;
                    bool chunkOK = true;

                    while (chunkOK)
                    {
                        if (categoryData[i].Trim() != "")
                        {
                            categoryDetail = categoryData[i].Split(',');
                            qryInsert     += "insert into FoxCategory (Category, CategoryName) values ('" + categoryDetail[0] + "','" + categoryDetail[1] + "'); ";
                        }
                        i++;
                        recCT++;
                        if ((recCT >= 26) || (i > categoryData.GetUpperBound(0)))
                        {
                            chunkOK = false;
                        }
                    }

                    if (qryInsert != "")
                    {
                        if (!db.ExecWriteSQLiteBatch(Constants.DBFilename, qryInsert, ref dbError))
                        {
                            //Toast.MakeText((this.ApplicationContext), "Success!", ToastLength.Long).Show();
                            //txtdbResult.Text += "Failed insert code: " + vendorDetail[0] + "  ";
                        }
                    }

                    RunOnUiThread(() =>
                    {
                        progBar.Progress = i;
                    });
                }  // while (i <= vendorData.GetUpperBound(0))

                RunOnUiThread(() =>
                {
                    progBar.Dismiss();
                });

                db.ExecWriteSQLite(Constants.DBFilename, "update FoxAdminRecord set LastVendorCatImport = '" + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToLongTimeString() + "'", ref dbError);

                msg.Arg1 = 0;
                msg.Arg2 = 2;
                svcCallHandler.SendMessage(msg);
            }));

            thread.Start();

            //while (thread.ThreadState == ThreadState.Running)
            //{
            //    await Task.Delay(5000);
            //}

            //progBar.Dismiss();
        } // ImportVendorCatListsToDB()