private void ComboBox_Loaded(object sender, RoutedEventArgs e) { try { SqlDbUtils util = new SqlDbUtils(); DataTable dtTable = new DataTable(); string conStr = ConfigurationManager.ConnectionStrings["connection"].ConnectionString; SqlConnection scon = new SqlConnection(conStr); //string sqlStr = " select Table_schema,Table_name from information_schema.tables where Table_schema not in('dbo','dbutil') order by TABLE_NAME"; string sqlStr = " select Table_schema,Table_name from information_schema.tables order by TABLE_NAME"; string errorMsg = ""; dtTable = util.FetchDataTable(scon, sqlStr, out errorMsg, null, CommandType.Text, null); cmbTable.DisplayMemberPath = dtTable.Columns[1].ToString(); cmbTable.SelectedValuePath = dtTable.Columns[0].ToString(); DataRow newRow = dtTable.NewRow(); newRow[1] = "---Select---"; dtTable.Rows.InsertAt(newRow, 0); cmbTable.ItemsSource = dtTable.DefaultView; cmbTable.SelectedIndex = 0; } catch (Exception ex) { } }
private void Button_Click(object sender, RoutedEventArgs e) { try { SqlDbUtils util = new SqlDbUtils(); DataTable dtTableColumn = new DataTable(); string conStr = ConfigurationManager.ConnectionStrings["connection"].ConnectionString; SqlConnection scon = new SqlConnection(conStr); string tableName = cmbTable.Text.ToString(); string schemaName = cmbTable.SelectedValue.ToString(); string sqlStr = "select COLUMN_NAME,DATA_TYPE from information_schema.columns where TABLE_NAME= '" + tableName + "' and Table_schema= '" + schemaName + "'"; string errorMsg = ""; tableName = GetQualifyName(tableName); dtTableColumn = util.FetchDataTable(scon, sqlStr, out errorMsg, null, CommandType.Text, null); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine("using System;"); stringBuilder.AppendLine("using System.Collections.Generic;"); stringBuilder.AppendLine("using System.Data.SqlClient;"); stringBuilder.AppendLine("using System.Data;"); stringBuilder.AppendLine("using System.Linq;"); stringBuilder.AppendLine("using MCLSystem;"); stringBuilder.AppendLine("using System.Web;"); stringBuilder.AppendLine("using System.ComponentModel.DataAnnotations;"); stringBuilder.AppendLine("using System.ComponentModel;"); stringBuilder.AppendLine("using System.Web.Mvc;"); stringBuilder.AppendLine("\r\n public class " + tableName + "\r\n {\r\n"); string dataType = null; string columnName = null; for (int i = 0; i < dtTableColumn.Rows.Count; i++) { columnName = Convert.ToString(dtTableColumn.Rows[i][0]); dataType = Convert.ToString(dtTableColumn.Rows[i][1]); stringBuilder.AppendLine("\n public " + GetDataType(dataType, true) + " " + GetQualifyName(columnName) + " { get; set; }"); } stringBuilder.AppendLine("\r\n}"); GenerateFiles(stringBuilder.ToString(), txtPath.Text + "\\" + tableName + "ViewModel.cs"); stringBuilder.Clear(); System.Windows.MessageBox.Show("Succsessfully generated !"); } catch (Exception ex) { } }
private void SpGenerate_Click(object sender, RoutedEventArgs e) { try { SqlDbUtils util = new SqlDbUtils(); DataTable dtTableColumn = new DataTable(); string conStr = ConfigurationManager.ConnectionStrings["connection"].ConnectionString; SqlConnection scon = new SqlConnection(conStr); string tableName = cmbTable.Text.ToString(); string schemaName = cmbTable.SelectedValue.ToString(); string sqlStr = "select Table_schema, COLUMN_NAME,DATA_TYPE ,CHARACTER_MAXIMUM_LENGTH from information_schema.columns where TABLE_NAME= '" + tableName + "' and Table_schema= '" + schemaName + "' "; string errorMsg = ""; dtTableColumn = util.FetchDataTable(scon, sqlStr, out errorMsg, null, CommandType.Text, null); InsertSpGenerate(dtTableColumn, tableName); stringBuilder.AppendLine("\r\n-- update-----------"); updateSpGenerate(dtTableColumn, tableName); stringBuilder.AppendLine("\r\n-- delete-----------"); deleteSpGenerate(dtTableColumn, tableName); stringBuilder.AppendLine("\r\n-- Exists Validate-----------"); ExistValidate(dtTableColumn, tableName); stringBuilder.AppendLine("\r\n-- Get----------"); GetFunctionGenerate(dtTableColumn, tableName); stringBuilder.AppendLine("\r\n"); GenerateFiles(stringBuilder.ToString(), txtPath.Text + "\\" + tableName + ".txt"); stringBuilder.Clear(); System.Windows.MessageBox.Show("Succsessfully generated !"); } catch (Exception ex) { } }