-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
108 lines (97 loc) · 3.39 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WindowsFormsApp1.Database_Tier;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace WindowsFormsApp1
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
GetDatabaseNames();
}
private void GetDatabaseNames()
{
try
{
DataTable databaseNames = DatabaseMethods.GetDatabaseNames();
cbDatabases.DataSource = databaseNames;
cbDatabases.DisplayMember = "name";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cbDatabases_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
string databaseName = cbDatabases.Text.ToString();
dgvTables.DataSource = DatabaseMethods.GetTableNames(databaseName);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void dgvTables_CellClick(object sender, DataGridViewCellEventArgs e)
{
try
{
string databaseName = cbDatabases.Text.ToString();
if (e.RowIndex >= 0 && e.ColumnIndex >= 0)
{
var cellValue = dgvTables[e.ColumnIndex, e.RowIndex].Value;
string tableName = cellValue.ToString();
dgvColumns.DataSource = DatabaseMethods.GetTable(databaseName, tableName);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void btnGenerate_Click(object sender, EventArgs e)
{
try
{
string databaseName = cbDatabases.Text.ToString();
string tableName = dgvTables.CurrentCell.Value?.ToString();
DataTable columns = (DataTable)dgvColumns.DataSource;
if (columns == null)
{
MessageBox.Show("Please choose the table.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
GenerateCode generateCode = new GenerateCode(databaseName, tableName, columns);
tbCode.Text = generateCode.Generate();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void btnCopyDataTierText_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(tbCode.Text))
{
// Copy the text to the clipboard
Clipboard.SetText(tbCode.Text.ToString().Trim());
MessageBox.Show("Code copied to clipboard.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}