Skip to content
This repository was archived by the owner on Jun 25, 2024. It is now read-only.

Commit a9a5512

Browse files
committed
fix: saving issue for all except the current tab
1 parent 803563d commit a9a5512

3 files changed

Lines changed: 75 additions & 49 deletions

File tree

screenshot.png

9.36 KB
Loading

src/frmMain.Designer.cs

Lines changed: 51 additions & 41 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/frmMain.cs

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,15 @@ public frmMain()
2626

2727

2828
private void setGridAll() {
29-
while (tabControl1.TabPages.Count > 1) tabControl1.TabPages.RemoveAt(1); //clear
29+
//clear sql tab
30+
//dgvSQL.Rows.Clear();
31+
//dgvSQL.Refresh();
32+
txtSQL.Text = "";
33+
dgvSQL.DataSource = null;
34+
dgvSQL.DataMember = null;
35+
dgvSQL.Refresh();
36+
//clear tabs
37+
while (tabControl1.TabPages.Count > 1) tabControl1.TabPages.RemoveAt(1);
3038
//addSQLTab();
3139
foreach (DataRow row in dsAllTables.Tables[0].Rows) {
3240
string tableName = row[0].ToString();
@@ -66,6 +74,8 @@ private void setGridAll() {
6674
{
6775
MessageBox.Show(tableName + ": tables without primary key cannot be edited/deleted");
6876
dgv.ReadOnly = true;
77+
dgv.AllowUserToAddRows = false;
78+
dgv.AllowUserToDeleteRows = false;
6979
}
7080

7181
dgv.AutoGenerateColumns = true;
@@ -130,22 +140,28 @@ private void btnBrowse_Click(object sender, EventArgs e)
130140

131141
private void btnSave_Click(object sender, EventArgs e)
132142
{
133-
//@todo: loop through all tabs and save all table data, not just the current one.
134-
if (tabControl1.SelectedTab == null) {
135-
MessageBox.Show("No selected data tab.");
143+
if (!havePendingChanges()) {
144+
MessageBox.Show("No changes to save.");
136145
return;
137146
}
138-
string currentTab = tabControl1.SelectedTab.Name;
139-
//MessageBox.Show("current tab: " + currentTab);
140-
adapters[currentTab].Update(datasets[currentTab]);
147+
foreach (TabPage tab in tabControl1.TabPages)
148+
{
149+
if (tab.Name == "_sql") continue;
150+
DataTable changes = datasets[tab.Name].Tables[0].GetChanges();
151+
if (changes != null && changes.Rows.Count > 0)
152+
{
153+
adapters[tab.Name].Update(datasets[tab.Name]);
154+
}
155+
}
156+
MessageBox.Show("Data Saved");
141157
}
142158

143159
private void btnDelete_Click(object sender, EventArgs e)
144160
{
145161
MessageBox.Show("Not implemented yet");
146162
}
147163

148-
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
164+
private void mnuDelete_Click(object sender, EventArgs e)
149165
{
150166
DataGridView dgv = (DataGridView)tabControl1.SelectedTab.Controls["dgv"];
151167
if (dgv.SelectedRows.Count == 0) {

0 commit comments

Comments
 (0)