Пример #1
0
 private void Refresh_Click(object sender, EventArgs e)
 {
     showProgress(true);
     //Task<RefreshDataCT> task = null;
     new Thread((ThreadStart)(() =>
     {
         try
         {
             using (NmdWSAdapter nmdWS = new NmdWSAdapter(this))
                 using (dbHelper = new NmdMobileDBAdapter(this))
                 {
                     dbHelper.OpenOrCreateDatabase(dbHelper.DBNamaad);//ToDo: We should create a preference UI which will write to XML resource file to read DBNamaad name.
                     ((SharedEnviroment)ApplicationContext).DbNameServer = ((SharedEnviroment)ApplicationContext).DbNameClient = dbHelper.DBNamaad;
                     DataTable dt = null;
                     using (dt = dbHelper.ExecuteSQL("Select Cast(1 As int) As SystemCode, Cast(1 As int) As TableCode ,'WebTableName' As TableName"))
                     {
                         nmdWS.RefreshWsCall(dt, 0).Wait();//task.Wait();//For Throwing exception, otherwise next line will be executed in case of exception.
                         if (dbHelper.Exist("WebTableCode"))
                         {
                             dt = dbHelper.ExecuteSQL("Select * From WebTableCode Where SystemCode=1 And TableCode>1 And TableCode<1000 ");
                             nmdWS.RefreshWsCall(dt, 0).Wait();//task.Wait();
                         }
                     }
                 }
         }
         catch (AggregateException ae)
         {
             ExceptionHandler.logDActivity(ae.ToString(), _logging, TAG);
             RunOnUiThread(() =>
             {
                 ExceptionHandler.toastAggregateException(this, ae);
             });
         }
         catch (Exception ex)
         {
             ExceptionHandler.logDActivity(ex.ToString(), _logging, TAG);
             RunOnUiThread(() =>
             {
                 ExceptionHandler.toastMsg(this, ex.Message);
             });
         }
         finally
         {
             RunOnUiThread(() =>
             {
                 showProgress(false);
             });
         }
     }
                              ))
     {
         IsBackground = true
     }.Start();
 }
 private void btnRef_Click(object sender, EventArgs e)
 {
     showProgress(true);
     new Thread((ThreadStart)(() =>
     {
         int size = listView.Count;
         StringBuilder strTableCode = null;
         for (int i = 0; i < size; i++)
         {
             if (listView.IsItemChecked(i))
             {
                 var t = tableDesc[i];
                 if (strTableCode != null)
                 {
                     strTableCode.Append(",");
                 }
                 else if (strTableCode == null)
                 {
                     strTableCode = new StringBuilder();
                 }
                 strTableCode.Append(t.TableCode);
             }
         }
         try
         {
             using (NmdWSAdapter nmdWS = new NmdWSAdapter(this))
                 using (dbHelper = new NmdMobileDBAdapter(this))
                 {
                     dbHelper.OpenOrCreateDatabase(dbHelper.DBNamaad);
                     using (DataTable dt = dbHelper.ExecuteSQL("Select * From WebTableCode Where OrgID=" + ((SharedEnviroment)ApplicationContext).OrgID + " And SystemCode=" + ((SharedEnviroment)ApplicationContext).SystemCode + " And TableCode in(" + strTableCode.ToString() + ")"))
                     {
                         var task = nmdWS.RefreshWsCall(dt, 0);
                         task.Wait();
                     }
                 }
         }
         catch (AggregateException ae)
         {
             ExceptionHandler.logDActivity(ae.ToString(), ((SharedEnviroment)ApplicationContext).Logging, ((SharedEnviroment)ApplicationContext).TAG);
             RunOnUiThread(() =>
             {
                 ExceptionHandler.toastAggregateException(this, ae);
             });
         }
         catch (Exception ex)
         {
             ExceptionHandler.logDActivity(ex.ToString(), ((SharedEnviroment)ApplicationContext).Logging, ((SharedEnviroment)ApplicationContext).TAG);
             RunOnUiThread(() =>
             {
                 ExceptionHandler.toastMsg(this, ex.Message);
             });
         }
         finally
         {
             RunOnUiThread(() =>
             {
                 showProgress(false);
             });
         }
     }))
     {
         IsBackground = true
     }.Start();
 }