private void wcf_ClientUpdateGridSettingsCompleted(IAsyncResult ar)
 {
     try
     {
         WCF.UpdateGridSettingsResponse rsWCF = ((WCF.SettingsContractClient)ar.AsyncState).EndUpdateGridSettings(ar);
         Merge(rsWCF.GridSettingsCD, false, MissingSchemaAction.Ignore);
         PrepareDataAfterUpdate();
         ClientUpdateGridSettingsCompleted(this, new EventArgs());
     }
     catch { }
 }
        /// <summary>
        /// Client callable code to update GridSettings.
        /// </summary>
        /// <param name="async">Do the update async.</param>
        /// <returns>True if update is successful. If False, check for RowErrors.</returns>
        public bool ClientUpdateGridSettings(bool async)
        {
            if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_gridName))
            {
                throw new Exception("The UserName and/or GridName is null or empty.");
            }

            PrepareDataBeforeUpdate();

            if (GridSettings.Select("", "", DataViewRowState.Deleted).Length > 0 ||
                GridSettings.Select("", "", DataViewRowState.Added).Length > 0 ||
                GridSettings.Select("", "", DataViewRowState.ModifiedCurrent).Length > 0)
            {
                var ds = new GridSettingsCD();
                foreach (GridSettingsRow deletedRow in GridSettings.Select("", "", DataViewRowState.Deleted))
                {
                    ds.GridSettings.ImportRow(deletedRow);
                }
                foreach (GridSettingsRow addedRow in GridSettings.Select("", "", DataViewRowState.Added))
                {
                    ds.GridSettings.ImportRow(addedRow);
                }
                foreach (GridSettingsRow modifiedCurrentRow in GridSettings.Select("", "", DataViewRowState.ModifiedCurrent))
                {
                    ds.GridSettings.ImportRow(modifiedCurrentRow);
                }

                if (UseWcfService)
                {
                    try
                    {
                        var svWCF = new WCF.SettingsContractClient();
                        var rqWCF = new WCF.UpdateGridSettingsRequest {
                            GridSettingsCD = new WCF.GridSettingsCD()
                        };
                        rqWCF.GridSettingsCD.Merge(ds, false, MissingSchemaAction.Ignore);

                        if (async)
                        {
                            if (String.IsNullOrEmpty(svWCF.Ping()))
                            {
                                throw new Exception("WCF is offline.");
                            }

                            svWCF.BeginUpdateGridSettings(rqWCF, wcf_ClientUpdateGridSettingsCompleted, svWCF);
                            return(true);
                        }

                        WCF.UpdateGridSettingsResponse rsWCF = svWCF.UpdateGridSettings(rqWCF);
                        Merge(rsWCF.GridSettingsCD, false, MissingSchemaAction.Ignore);
                        PrepareDataAfterUpdate();
                        return(true);
                    }
                    catch { UseWcfService = false; }                     // ignore if not responding
                }
                if (UseAsmxService)
                {
                    try
                    {
                        var svASMX = new ASMX.SettingsServiceASMX();
                        var rqASMX = new ASMX.UpdateGridSettingsRequest {
                            GridSettingsCD = new ASMX.GridSettingsCD()
                        };
                        rqASMX.GridSettingsCD.Merge(ds, false, MissingSchemaAction.Ignore);

                        if (async)
                        {
                            svASMX.UpdateGridSettingsCompleted += asmx_ClientUpdateGridSettingsCompleted;
                            svASMX.UpdateGridSettingsAsync(rqASMX);
                            return(true);
                        }

                        ASMX.UpdateGridSettingsResponse rsASMX = svASMX.UpdateGridSettings(rqASMX);
                        Merge(rsASMX.GridSettingsCD, false, MissingSchemaAction.Ignore);
                        PrepareDataAfterUpdate();
                        return(true);
                    }
                    catch { UseAsmxService = false; }                     // ignore if not responding
                }
                if (UseClientServer)
                {
                    try
                    {
                        Merge(UpdateGridSettings(ds), false, MissingSchemaAction.Ignore);
                        PrepareDataAfterUpdate();
                        return(true);
                    }
                    catch { UseClientServer = false; }                     // ignore if not responding
                }
            }
            return(false);
        }