private void asmx_ClientReplaceGridSettingsCompleted(object sender, ASMX.ReplaceGridSettingsCompletedEventArgs e) { try { var rsASMX = new ASMX.ReplaceGridSettingsResponse(); #pragma warning disable 168 var success = rsASMX.ReplaceSuccessful; #pragma warning restore 168 ClientReplaceGridSettingsCompleted(this, new EventArgs()); } catch { } }
/// <summary> /// Save the Grid Settings to the database from a DataGridView /// </summary> /// <param name="dataGridView">The DataGridView to derive the GridSettings from</param> /// <param name="async">Do the update async</param> /// <returns>true if replaced</returns> public bool ClientUpdateGridSettingsFromDataGridView(DataGridView dataGridView, bool async) { if (dataGridView == null || dataGridView.Columns.Count == 0) { throw new Exception("The DataGridView is null or empty."); } if (string.IsNullOrEmpty(_userName) || string.IsNullOrEmpty(_gridName)) { throw new Exception("The UserName and/or GridName is null or empty."); } var ds = new GridSettingsCD(); GridSettingsRow gridSettingsRow; for (int i = 0; i < dataGridView.Columns.Count; i++) { gridSettingsRow = ds.GridSettings.NewGridSettingsRow(); gridSettingsRow.SetDefaultValues(); gridSettingsRow.UserName = SystemInformation.UserName; gridSettingsRow.GridName = _gridName; gridSettingsRow.ColumnName = dataGridView.Columns[i].Name; gridSettingsRow.Visible = dataGridView.Columns[i].Visible; gridSettingsRow.DisplayIndex = dataGridView.Columns[i].DisplayIndex; gridSettingsRow.Width = dataGridView.Columns[i].Width; ds.GridSettings.AddGridSettingsRow(gridSettingsRow); } if (UseWcfService) { try { var svWCF = new WCF.SettingsContractClient(); var rqWCF = new WCF.ReplaceGridSettingsRequest { GridSettingsCD = new WCF.GridSettingsCD() }; rqWCF.GridSettingsCD.Merge(ds, false, MissingSchemaAction.Ignore); if (async) { svWCF.Ping(); svWCF.BeginReplaceGridSettings(rqWCF, wcf_ClientReplaceGridSettingsCompleted, svWCF); return(true); } WCF.ReplaceGridSettingsResponse rsWCF = svWCF.ReplaceGridSettings(rqWCF); return(rsWCF.ReplaceSuccessful); } catch { UseWcfService = false; } // ignore if not responding } if (UseAsmxService) { try { var svASMX = new ASMX.SettingsServiceASMX(); var rqASMX = new ASMX.ReplaceGridSettingsRequest { GridSettingsCD = new ASMX.GridSettingsCD() }; rqASMX.GridSettingsCD.Merge(ds, false, MissingSchemaAction.Ignore); if (async) { svASMX.ReplaceGridSettingsCompleted += asmx_ClientReplaceGridSettingsCompleted; svASMX.ReplaceGridSettingsAsync(rqASMX); return(true); } ASMX.ReplaceGridSettingsResponse rsASMX = svASMX.ReplaceGridSettings(rqASMX); return(rsASMX.ReplaceSuccessful); } catch { UseAsmxService = false; } // ignore if not responding } if (UseClientServer) { try { return(ReplaceGridSettings(ds)); } catch { UseClientServer = false; } // ignore if not responding } return(false); }