private void dgMaster_Click(object sender, EventArgs e) { if (this.dgMaster.SelectedCells.Count == 0) { return; } SqlSyncBuildData.BuildRow row = (SqlSyncBuildData.BuildRow)((System.Data.DataRowView) this.dgMaster.SelectedCells[0].OwningRow.DataBoundItem).Row; System.Data.DataView view = this.sqlSyncBuildData1.ScriptRun.DefaultView; view.RowFilter = this.sqlSyncBuildData1.ScriptRun.Build_IdColumn.ColumnName + "= '" + row.Build_Id.ToString() + "'"; this.scriptRunBindingSource.DataSource = view; }
private void saveBuildDetailsForSelectedRowsToolStripMenuItem_Click(object sender, EventArgs e) { if (this.dgMaster.SelectedCells.Count == 0) { return; } List <SqlSyncBuildData.BuildRow> rows = new List <SqlSyncBuildData.BuildRow>(); for (int i = 0; i < this.dgMaster.SelectedCells.Count; i++) { SqlSyncBuildData.BuildRow row = (SqlSyncBuildData.BuildRow)((System.Data.DataRowView) this.dgMaster.SelectedCells[i].OwningRow.DataBoundItem).Row; if (!rows.Contains(row)) { rows.Add(row); } } if (DialogResult.OK == saveFileDialog1.ShowDialog()) { try { //Perform a deep copy of the build data... SqlSyncBuildData data = new SqlSyncBuildData(); using (StringReader sr = new StringReader("<?xml version=\"1.0\" standalone=\"yes\"?>" + this.sqlSyncBuildData1.GetXml())) { data.ReadXml(sr); } //Get ID's for selected rows... StringBuilder sb = new StringBuilder("("); foreach (SqlSyncBuildData.BuildRow row in rows) { sb.Append("'" + row.BuildId.ToString() + "',"); } sb.Length = sb.Length - 1; sb.Append(")"); //Filter out any rows that were not selected System.Data.DataView view = data.Build.DefaultView; view.RowFilter = data.Build.BuildIdColumn.ColumnName + " not in " + sb.ToString(); //Delete the non-selected rows from the build data copy object. while (view.Count > 0) { DataRow[] kids = view[0].Row.GetChildRows("Builds_Build"); for (int j = 0; j < kids.Length; j++) { kids[j].Delete(); } view[0].Row.Delete(); } //Save the file... string fileName = saveFileDialog1.FileName; data.AcceptChanges(); data.WriteXml(fileName); if (DialogResult.Yes == MessageBox.Show("Saved history to " + fileName + "\r\nOpen this file?", "Save Complete", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) { System.Diagnostics.Process.Start(fileName); } } catch (Exception exe) { MessageBox.Show("There was an error saving the history.\r\n" + exe.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }