Ejemplo n.º 1
0
 public System.IAsyncResult BeginRefreshData(RefreshDataCT composite, System.AsyncCallback callback, object asyncState)
 {
     object[] _args = new object[1];
     _args[0] = composite;
     System.IAsyncResult _result = base.BeginInvoke("RefreshData", _args, callback, asyncState);
     return(_result);
 }
Ejemplo n.º 2
0
        public RefreshDataCT EndRefreshData(System.IAsyncResult result)
        {
            object[]      _args   = new object[0];
            RefreshDataCT _result = ((RefreshDataCT)(base.EndInvoke("RefreshData", _args, result)));

            return(_result);
        }
        private void ReciveGetData(RefreshDataCT ct)
        {
            string sqlString = null;

            if (ct.HasCreateTable)
            {
                dbHelper.DropTable(ct.TableName);
                if (ct.QueryCreateTable != "")
                {
                    sqlString = ct.QueryCreateTable.Replace("@" + ct.TableName, ct.TableName);
                    dbHelper.ExecuteNonQuery(sqlString);
                }
            }
            if (ct.QueryBeforeExec1 != "")
            {
                sqlString = ct.QueryBeforeExec1.Replace("@" + ct.TableName, ct.TableName);
                dbHelper.ExecuteNonQuery(sqlString);
            }
            if (ct.QueryBeforeExec2 != "")
            {
                sqlString = ct.QueryBeforeExec2.Replace("@" + ct.TableName, ct.TableName);
                dbHelper.ExecuteNonQuery(sqlString);
            }

            dbHelper.DropTable("Tmp" + ct.TableName);

            using (DataTable dt = ToDataTable(ct.DataTableArray))
                if (dt.Rows.Count > 0)
                {
                    string destTableName = ct.TableName;
                    if (ct.IsCreateTmpTable)
                    {
                        destTableName = "Tmp" + destTableName;
                        sqlString     = ct.QueryCreateTable.Replace("@" + ct.TableName, destTableName);
                        dbHelper.ExecuteNonQuery(sqlString);
                    }
                    dbHelper.BeginTransaction();
                    dbHelper.CopyToDB(dt, destTableName, ct.TableName, ct.DeleteKey);
                    dbHelper.EndTransaction();

                    if (ct.QueryAfterExec1 != "")
                    {
                        sqlString = ct.QueryAfterExec1.Replace("@" + ct.TableName, ct.TableName);
                        //sqlString = sqlString.Replace( "\r\n", " ");
                        dbHelper.ExecuteNonQuery(sqlString);
                    }
                    if (ct.QueryAfterExec2 != "")
                    {
                        sqlString = ct.QueryAfterExec2.Replace("@" + ct.TableName, ct.TableName);
                        dbHelper.ExecuteNonQuery(sqlString);
                    }
                    if (ct.QueryAfterExec3 != "")
                    {
                        sqlString = ct.QueryAfterExec3.Replace("@" + ct.TableName, ct.TableName);
                        dbHelper.ExecuteNonQuery(sqlString);
                    }
                }
            dbHelper.DropTable("Tmp" + ct.TableName);
        }
Ejemplo n.º 4
0
    private object[] OnEndRefreshData(System.IAsyncResult result)
    {
        RefreshDataCT retVal = ((IService)(this)).EndRefreshData(result);

        return(new object[] {
            retVal
        });
    }
        /// <summary>
        /// Refreshes the Sync ws call
        /// </summary>
        /// <param name="dt">The dt.</param>
        /// <param name="userCode">The user code.</param>
        /// <returns></returns>
        public async Task RefreshWsCall(DataTable dt, int userCode)//DBNameNamaad=DBNamaad
        {
            //Task<RefreshDataCT> res = null;
            RefreshDataCT res = null;

            if (dt.Rows.Count == 0)
            {
                return;
            }

            if (dbHelper == null)
            {
                dbHelper = new NmdMobileDBAdapter(mCtx);
                if (int.Parse(dt.Rows[0]["SystemCode"].ToString()) == 1)
                {
                    dbHelper.OpenOrCreateDatabase(((SharedEnviroment)mCtx.ApplicationContext).DbNameClient);
                }
                else
                {
                    dbHelper.OpenOrCreateDatabase(((SharedEnviroment)mCtx.ApplicationContext).ActionArgument);
                }
                flagCon = true;
            }
            InitializeHelloWorldServiceClient();
            RefreshDataCT ct = new RefreshDataCT();

            using (dt)
            {
                foreach (DataRow row in dt.Rows)
                {
                    ct.SystemCode       = int.Parse(row["SystemCode"].ToString());
                    ct.TableCode        = int.Parse(row["TableCode"].ToString());
                    ct.TableName        = (string)row["tableName"];
                    ct.TableDataVersion = 0;
                    if (ct.TableCode >= 1000 && dbHelper.Exist(ct.TableName))
                    {
                        string s;
                        if (!string.IsNullOrEmpty(s = dbHelper.ExecuteSQL("Select Max(TableDataVersion) As maxTableDataVersion From " + ct.TableName).Rows[0]["maxTableDataVersion"].ToString()))
                        {
                            ct.TableDataVersion = int.Parse(s);
                        }
                    }
                    ct.UserCode = userCode;

                    res = await Task <RefreshDataCT> .Factory.FromAsync(_client.BeginRefreshData, _client.EndRefreshData, ct, null);

                    //res.Wait();//For Throwing exception, otherwise next line will be executed in case of exception.

                    //ReciveGetData(res.Result);
                    //ReciveGetData(_client.RefreshData(ct));
                    ReciveGetData(res);
                }
            }
        }
Ejemplo n.º 6
0
    private void SetDbName(RefreshDataCT composite)
    {
        string StrSQL = "";

        StrSQL = "Select * From WebActions Where CompanyCode=" + composite.CompanyCode + " And ActionCode=1";
        //composite.StrDebug=GetConnectionString();
        using (DataTable dtWebTableCode = NmdDBAdapter.ExecuteSQL(StrSQL))
        {
            composite.DbNameServer = ((string)dtWebTableCode.Rows[0]["DbNameServer"]).Trim();
            composite.DbNameClient = ((string)dtWebTableCode.Rows[0]["DbNameClient"]).Trim();
        }
    }
Ejemplo n.º 7
0
    private void GetDataRefresh(RefreshDataCT composite)
    {
        string StrSQL       = "";
        string DbNameServer = "";
        string DbNameClient = "";

        if (composite.TableCode > 1000)
        {
            DbNameServer = composite.DbNameServer + ".dbo.";
            DbNameClient = composite.DbNameClient + ".dbo.";
        }

        StrSQL = "Select * From " + DbNameServer + "WebTableCode Where CompanyCode=" + composite.CompanyCode + " And TableCode=" + composite.TableCode;
        //composite.StrDebug=GetConnectionString();
        using (DataTable dtWebTableCode = NmdDBAdapter.ExecuteSQL(StrSQL))
        {
            composite.TableName      = ((string)dtWebTableCode.Rows[0]["TableName"]).Trim();
            composite.HasCreateTable = false;
            if ((int)dtWebTableCode.Rows[0]["TableDataVersion"] > composite.TableDataVersion)
            {
                composite.TableDataVersion = 0;
                composite.HasCreateTable   = true;
            }
            composite.QueryCreateTable = ((string)dtWebTableCode.Rows[0]["QueryCreateTable"]).Trim();
            composite.QueryBeforeExec1 = ((string)dtWebTableCode.Rows[0]["QueryBeforeExec1"]).Trim();
            composite.QueryBeforeExec2 = ((string)dtWebTableCode.Rows[0]["QueryBeforeExec2"]).Trim();

            composite.QueryAfterExec1 = ((string)dtWebTableCode.Rows[0]["QueryAfterExec1"]).Trim();
            composite.QueryAfterExec2 = ((string)dtWebTableCode.Rows[0]["QueryAfterExec2"]).Trim();
            composite.QueryAfterExec3 = ((string)dtWebTableCode.Rows[0]["QueryAfterExec3"]).Trim();

            composite.DeleteKey        = ((string)dtWebTableCode.Rows[0]["DeleteKey"]).Trim();
            composite.IsCreateTmpTable = (Int16)dtWebTableCode.Rows[0]["IsCreateTmpTable"];

            StrSQL = ((string)dtWebTableCode.Rows[0]["QueryGetData"]).Replace("@TableDataVersion", composite.TableDataVersion.ToString());
            if (composite.TableCode > 1000)
            {
                StrSQL = ((string)StrSQL).Replace("@DbNameServer.dbo.", DbNameClient);
            }
            else
            {
                StrSQL = ((string)StrSQL).Replace("@DbNameServer.dbo.", DbNameServer);
            }
        }

        //composite.Dt = ExecuteSQL(StrSQL);
        //composite.MS = ToMemStream(ExecuteSQL(StrSQL));
        composite.DataTableArray = ToMemStream(NmdDBAdapter.ExecuteSQL(StrSQL)).ToArray();
    }
Ejemplo n.º 8
0
 public void RefreshDataAsync(RefreshDataCT composite, object userState)
 {
     if ((this.onBeginRefreshDataDelegate == null))
     {
         this.onBeginRefreshDataDelegate = new BeginOperationDelegate(this.OnBeginRefreshData);
     }
     if ((this.onEndRefreshDataDelegate == null))
     {
         this.onEndRefreshDataDelegate = new EndOperationDelegate(this.OnEndRefreshData);
     }
     if ((this.onRefreshDataCompletedDelegate == null))
     {
         this.onRefreshDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnRefreshDataCompleted);
     }
     base.InvokeAsync(this.onBeginRefreshDataDelegate, new object[] {
         composite
     }, this.onEndRefreshDataDelegate, this.onRefreshDataCompletedDelegate, userState);
 }
Ejemplo n.º 9
0
 public RefreshDataCT RefreshData(RefreshDataCT composite)
 {
     if (composite == null)
     {
         throw new ArgumentNullException("RefreshDataCT Is Null");
     }
     else if (string.IsNullOrWhiteSpace(composite.TableCode.ToString()))
     {
         throw new ArgumentException("TableCode IsNullOrWhiteSpace");
     }
     try
     {
         SetDbName(composite);
         GetDataRefresh(composite);
     }
     catch (Exception eDB)
     {
         Console.WriteLine(eDB);
         Debug.WriteLine(eDB, TAG);
     }
     return(composite);
 }
    public RefreshDataCT RefreshData(RefreshDataCT composite)
    {
        if (composite == null)
            throw new ArgumentNullException("RefreshDataCT Is Null");
        else if (string.IsNullOrWhiteSpace(composite.TableCode.ToString()))
            throw new ArgumentException("TableCode IsNullOrWhiteSpace");
        try
        {
            SetDbName(composite);
            GetDataRefresh(composite);

        }
        catch (Exception eDB)
        {
            Console.WriteLine(eDB);
            Debug.WriteLine(eDB, TAG);
        }
        return composite;
    }
 private void SetDbName(RefreshDataCT composite)
 {
     string StrSQL = "";
     StrSQL = "Select * From WebActions Where CompanyCode=" + composite.CompanyCode + " And ActionCode=1";
     //composite.StrDebug=GetConnectionString();
     using (DataTable dtWebTableCode = NmdDBAdapter.ExecuteSQL(StrSQL))
     {
         composite.DbNameServer = ((string)dtWebTableCode.Rows[0]["DbNameServer"]).Trim();
         composite.DbNameClient = ((string)dtWebTableCode.Rows[0]["DbNameClient"]).Trim();
     }
 }
    private void GetDataRefresh(RefreshDataCT composite)
    {
        string StrSQL = "";
        string DbNameServer = "";
        string DbNameClient = "";

        if (composite.TableCode > 1000)
        {
            DbNameServer = composite.DbNameServer + ".dbo.";
            DbNameClient = composite.DbNameClient + ".dbo.";
        }

        StrSQL = "Select * From " + DbNameServer + "WebTableCode Where CompanyCode=" + composite.CompanyCode + " And TableCode=" + composite.TableCode;
        //composite.StrDebug=GetConnectionString();
        using (DataTable dtWebTableCode = NmdDBAdapter.ExecuteSQL(StrSQL))
        {
            composite.TableName = ((string)dtWebTableCode.Rows[0]["TableName"]).Trim();
            composite.HasCreateTable = false;
            if ((int)dtWebTableCode.Rows[0]["TableDataVersion"] > composite.TableDataVersion)
            {
                composite.TableDataVersion = 0;
                composite.HasCreateTable = true;
            }
            composite.QueryCreateTable = ((string)dtWebTableCode.Rows[0]["QueryCreateTable"]).Trim();
            composite.QueryBeforeExec1 = ((string)dtWebTableCode.Rows[0]["QueryBeforeExec1"]).Trim();
            composite.QueryBeforeExec2 = ((string)dtWebTableCode.Rows[0]["QueryBeforeExec2"]).Trim();

            composite.QueryAfterExec1 = ((string)dtWebTableCode.Rows[0]["QueryAfterExec1"]).Trim();
            composite.QueryAfterExec2 = ((string)dtWebTableCode.Rows[0]["QueryAfterExec2"]).Trim();
            composite.QueryAfterExec3 = ((string)dtWebTableCode.Rows[0]["QueryAfterExec3"]).Trim();

            composite.DeleteKey = ((string)dtWebTableCode.Rows[0]["DeleteKey"]).Trim();
            composite.IsCreateTmpTable = (Int16)dtWebTableCode.Rows[0]["IsCreateTmpTable"];

            StrSQL = ((string)dtWebTableCode.Rows[0]["QueryGetData"]).Replace("@TableDataVersion", composite.TableDataVersion.ToString());
            if (composite.TableCode > 1000)
                StrSQL = ((string)StrSQL).Replace("@DbNameServer.dbo.", DbNameClient);
            else
                StrSQL = ((string)StrSQL).Replace("@DbNameServer.dbo.", DbNameServer);

        }

        //composite.Dt = ExecuteSQL(StrSQL);
        //composite.MS = ToMemStream(ExecuteSQL(StrSQL));
        composite.DataTableArray = ToMemStream(NmdDBAdapter.ExecuteSQL(StrSQL)).ToArray();
    }
Ejemplo n.º 13
0
 public void RefreshDataAsync(RefreshDataCT composite)
 {
     this.RefreshDataAsync(composite, null);
 }
Ejemplo n.º 14
0
    private System.IAsyncResult OnBeginRefreshData(object[] inValues, System.AsyncCallback callback, object asyncState)
    {
        RefreshDataCT composite = ((RefreshDataCT)(inValues[0]));

        return(((IService)(this)).BeginRefreshData(composite, callback, asyncState));
    }
Ejemplo n.º 15
0
 System.IAsyncResult IService.BeginRefreshData(RefreshDataCT composite, System.AsyncCallback callback, object asyncState)
 {
     return(base.Channel.BeginRefreshData(composite, callback, asyncState));
 }