コード例 #1
0
        private void BindColumnList(SqlTable sql_table)
        {
            if (this.clbColumns.Items.Count != 0)
                    this.clbColumns.Items.Clear();

                foreach (var item in sql_table.Columns)
                    this.clbColumns.Items.AddRange(new object[] { item.Value.Name });
        }
コード例 #2
0
        public SqlColumn(SqlTable sql_table, string column_name, string datatype, int length, int precision, int scale, 
                             bool is_nullable, bool is_pk, bool is_identity, int column_ordinal, string default_value)
        {
            _SqlTable           = sql_table;

                _Name               = column_name;
                _DataType           = datatype;
                _Length             = length;
                _Precision          = precision;
                _Scale				= scale;
                _IsNullable         = is_nullable;
                _IsPk               = is_pk;
                _IsIdentity         = is_identity;
                _ColumnOrdinal      = column_ordinal;
                _DefaultValue       = default_value;
        }
コード例 #3
0
        public FieldSelector(List<string> selected_columns, SqlTable sql_table, string instructions, int min_selections, int max_selections)
        {
            InitializeComponent();

               this.Size = new Size(Properties.Settings.Default.FieldSelectorWidth, Properties.Settings.Default.FieldSelectorHeight);

                _SelectedColumns                = selected_columns;
                _MinSelections                  = min_selections;
                _MaxSelections                  = max_selections;
                this.lblInstructions.Text       = instructions;

                this.ListSelectedColumns();
                this.BindColumnList(sql_table);

                this.btnDone.Enabled = ValidateSelections();
        }
コード例 #4
0
        public static OutputObject GenerateCountAllProc(SqlTable sql_table, bool generate_stored_proc_perms)
        {
            if (sql_table == null)
                    return null;

                string procedure_name = GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.CountAll, null);

                OutputObject output = new OutputObject();
                output.Name = procedure_name + ".sql";
                output.Type = OutputObject.eObjectType.Sql;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine(GenerateSqlExistanceChecker(procedure_name));
                sb.AppendLine(GenerateHeader(procedure_name));

                sb.AppendLine("CREATE PROCEDURE " + procedure_name);
                sb.AppendLine("AS");
                sb.AppendLine();
                sb.AppendLine("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
                sb.AppendLine("SET NOCOUNT ON");
                sb.AppendLine();
                sb.AppendLine("SELECT\tCOUNT(*)");
                sb.AppendLine("FROM\t[" + sql_table.Name + "]");
                sb.AppendLine("WHERE\t[Disabled] = 0");
                sb.AppendLine("GO");
                sb.AppendLine();

                if (generate_stored_proc_perms)
                {
                    sb.AppendLine(GenerateSqlStoredProcPerms(procedure_name));
                    sb.AppendLine();
                }

                output.Body = sb.ToString();
                return output;
        }
コード例 #5
0
        private static string FindIdField(SqlTable sql_table)
        {
            // occasionally we might need to figure out a primary key for a table.
                // this method isn't perfect, but its a decent stab at the problem.
                // grab the first PK we have. If there is no PKs defined, grab the
                // first int we find.

                if (sql_table.PkList.Count == 0)
                {
                    foreach (var column in sql_table.Columns)
                    {
                        if (column.Value.BaseType == eSqlBaseType.Integer)
                            return column.Key;
                    }

                    // still here? no matches then...
                    return string.Empty;
                }
                else
                {
                    return sql_table.PkList[0].Name;
                }
        }
コード例 #6
0
 public static OutputObject GenerateWinformViewCodeDesigner(SqlTable sql_table)
 {
     return null;
 }
コード例 #7
0
        public static OutputObject GenerateXmlLoader(SqlTable sql_table)
        {
            if (sql_table == null)
                    return null;

                string object_name          = NameFormatter.ToCSharpClassName(sql_table.Name);
                string class_name           = object_name + "DataLoader";
                string collection_type      = "List<" + object_name + ">";
                int longest_column          = GetLongestColumnLength(sql_table) + sql_table.Name.Length;

                OutputObject output = new OutputObject();
                output.Name = class_name + ".cs";
                output.Type = OutputObject.eObjectType.CSharp;

                StringBuilder sb = new StringBuilder();

                #region Header block

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using System.Xml;");
                sb.AppendLine();
                sb.AppendLine("using DAL;");
                sb.AppendLine();

                #endregion

                sb.AppendLine("namespace " + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));
                sb.AppendLine("{");
                sb.AppendLine(AddTabs(1) + "[Serializable]");
                sb.AppendLine(AddTabs(1) + "public partial class " + class_name);
                sb.AppendLine(AddTabs(1) + "{");

                sb.AppendLine(AddTabs(2) + "#region Fields");
                sb.AppendLine();
                sb.AppendLine(AddTabs(3) + "protected bool _ParseErrors;");
                sb.AppendLine(AddTabs(3) + "protected " + collection_type + " _CollectionData;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "#region Properties");
                sb.AppendLine();
                sb.AppendLine(AddTabs(3) + "public " + collection_type + " CollectionData");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get { return _CollectionData; }");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "#region Methods");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "//CTOR");
                sb.AppendLine(AddTabs(3) + "public " + class_name + "()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "public bool ParseData(string file_name)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "string xml;");
                sb.AppendLine(AddTabs(4) + "string error_message;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "_ParseErrors        = !FileIo.ReadFromFile(file_name, out xml, out error_message);");
                sb.AppendLine(AddTabs(4) + "_CollectionData     = new " + collection_type + "();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "XmlDocument document;");
                sb.AppendLine(AddTabs(4) + "XmlNodeList selected_nodes;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + object_name +" item_data;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "try");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "document = new XmlDocument();");
                sb.AppendLine(AddTabs(5) + "document.InnerXml = xml;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "selected_nodes = document.SelectNodes(\"//" + NameFormatter.ToCSharpPropertyName(sql_table.Name) + "\");");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "foreach (XmlNode item in selected_nodes)");
                sb.AppendLine(AddTabs(5) + "{");
                sb.AppendLine(AddTabs(6) + "item_data = new " + object_name + "();");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    // format:
                    // critter_data.Name       = item.Attributes["Name"].Value;
                    sb.AppendLine(AddTabs(6) + PadCSharpVariableName("item_data." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column + 7) + "= " + NameFormatter.GetCSharpCastString(sql_column) + "(item.Attributes[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"].Value);");
                }

                sb.AppendLine();
                sb.AppendLine(AddTabs(6) + "_CollectionData.Add(item_data);");
                sb.AppendLine(AddTabs(5) + "}");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "catch");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "_ParseErrors = true;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "finally");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "document        = null;");
                sb.AppendLine(AddTabs(5) + "selected_nodes  = null;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "return !_ParseErrors;");
                sb.AppendLine(AddTabs(2) + "}");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine(AddTabs(1) + "}");

                sb.AppendLine("}");

                output.Body = sb.ToString();
                return output;
        }
コード例 #8
0
        private static int GetLongestColumnLength(SqlTable sql_table)
        {
            if (sql_table == null)
                    throw new Exception("Cannot compute longest column length on a null table.");

                int longest_column_length = 0;

                foreach (var column in sql_table.Columns.Values)
                {
                    if (column.Name.Length > longest_column_length)
                        longest_column_length = column.Name.Length;
                }

                return longest_column_length;
        }
コード例 #9
0
        // SQL Procs
        public static OutputObject GenerateSelectSingleProc(SqlTable sql_table, bool generate_stored_proc_perms)
        {
            if (sql_table == null)
                    return null;

                string procedure_name   = GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.SelectSingle, null);
                int longest_column      = GetLongestColumnLength(sql_table) + sql_table.Name.Length;
                bool flag_first_value;
                string name_buffer;

                OutputObject output = new OutputObject();
                output.Name = procedure_name + ".sql";
                output.Type = OutputObject.eObjectType.Sql;

                // sanity check - if there are no primary keys in the table, we cannot know
                // what would a good choice would be for a qualifier. Abort and return error msg.
                if (sql_table.PkList.Count == 0)
                {
                    output.Body = "/* Cannot generate " + procedure_name + ", no primary keys set on " + sql_table.Name + ". */" + Environment.NewLine + Environment.NewLine;
                    return output;
                }

                StringBuilder sb = new StringBuilder();

                sb.AppendLine(GenerateSqlExistanceChecker(procedure_name));
                sb.AppendLine(GenerateHeader(procedure_name));

                sb.AppendLine("CREATE PROCEDURE " + procedure_name);
                sb.AppendLine(GenerateSqlStoredProcParameters(sql_table, eIncludedFields.PKOnly));

                sb.AppendLine("AS");
                sb.AppendLine();
                sb.AppendLine("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
                sb.AppendLine("SET NOCOUNT ON");
                sb.AppendLine();

                #region Selected Columns

                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (flag_first_value)
                    {
                        sb.Append("SELECT" + AddTabs(1));
                        flag_first_value = false;
                    }
                    else
                    {
                        sb.Append("," + Environment.NewLine + AddTabs(2));
                    }

                    name_buffer = NameFormatter.ToTSQLName(sql_column.Table.Name) + "." + NameFormatter.ToTSQLName(sql_column.Name);
                    sb.Append(PadSqlVariableName(name_buffer, longest_column) + "AS " + NameFormatter.ToTSQLName(sql_column.Name));
                }
                #endregion

                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("FROM" + AddTabs(1) + NameFormatter.ToTSQLName(sql_table.Name));
                sb.AppendLine();

                #region Where Clause
                flag_first_value = true;
                sb.AppendLine("WHERE" + AddTabs(1) + PadSqlVariableName(NameFormatter.ToTSQLName(sql_table.Name) + ".[Disabled]", longest_column) + "= 0");

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    string tsql_variablename = NameFormatter.ToTSQLVariableName(sql_column);

                    if (sql_column.IsPk)
                    {
                        name_buffer = NameFormatter.ToTSQLName(sql_column.Table.Name) + "." + NameFormatter.ToTSQLName(sql_column.Name);
                        sb.AppendLine("AND" + AddTabs(2) + PadSqlVariableName(name_buffer, longest_column) + "= " + tsql_variablename);
                    }
                }
                #endregion

                sb.AppendLine("GO");
                sb.AppendLine();

                if (generate_stored_proc_perms)
                {
                    sb.AppendLine(GenerateSqlStoredProcPerms(procedure_name));
                    sb.AppendLine();
                }

                output.Body = sb.ToString();
                return output;
        }
コード例 #10
0
        private static string GenerateSearchClause(SqlTable sql_table, List<string> column_names, int tabs_in, int tabs_over)
        {
            if (sql_table == null || column_names == null || column_names.Count == 0)
                    return string.Empty;

                StringBuilder sb = new StringBuilder();

                bool flag_first_value = true;

                sb.Append(AddTabs(tabs_in) + "WHERE");
                sb.Append(Environment.NewLine + AddTabs(tabs_in) + "(");

                foreach (var item in column_names)
                {
                    sb.Append(Environment.NewLine + AddTabs(tabs_in + 1));

                    if (flag_first_value)
                        flag_first_value = false;
                    else
                        sb.Append("OR ");

                    sb.Append(NameFormatter.ToTSQLName(sql_table.Name) + "." + NameFormatter.ToTSQLName(item) + " LIKE '%' + @SearchString + '%'");
                }
                sb.Append(Environment.NewLine + AddTabs(tabs_in) + ")");

                return sb.ToString();
        }
コード例 #11
0
        private static string GenerateSelectClauseArguments(SqlTable sql_table, List<string> column_names)
        {
            if (column_names == null)
                    return AddTabs(1) + "-- @A_VALUE [SOME_DATA_TYPE]";

                StringBuilder sb = new StringBuilder();

                bool flag_first_value = true;

                foreach (var item in column_names)
                {
                    if (flag_first_value)
                        flag_first_value = false;
                    else
                        sb.Append("," + Environment.NewLine);

                    sb.Append(AddTabs(1) + NameFormatter.ToTSQLVariableName(sql_table.Columns[item]) + AddTabs(2) + NameFormatter.ToTSQLType(sql_table.Columns[item]));
                }

                return sb.ToString();
        }
コード例 #12
0
        // Webservice Generation
        public static OutputObject GenerateWebServiceCodeInfrontClass(SqlTable sql_table)
        {
            if (sql_table == null)
                    return null;

                string class_name = NameFormatter.ToCSharpClassName(sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name = class_name + ".asmx";
                output.Type = OutputObject.eObjectType.WebService;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("<%@ WebService Language=\"C#\" CodeBehind=\"Service1.asmx.cs\" Class=\"WebService1.Service1\" %>");

                output.Body = sb.ToString();
                return output;
        }
コード例 #13
0
        public static OutputObject GenerateWebViewPageCodeBehind(SqlTable sql_table, List<string> namespace_includes)
        {
            if (sql_table == null)
                    return null;

                string view_class_name  = "View" + NameFormatter.ToCSharpPropertyName(sql_table.Name);
                int longest_column      = GetLongestColumnLength(sql_table) + sql_table.Name.Length;

                OutputObject output = new OutputObject();
                output.Name =  view_class_name + ".aspx.cs";
                output.Type = OutputObject.eObjectType.CSharp;

                namespace_includes.Add(NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));

                StringBuilder sb = new StringBuilder();

                #region Includes
                sb.AppendLine("using System;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Configuration;");
                sb.AppendLine("using System.Collections;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using System.Web;");
                sb.AppendLine("using System.Web.Security;");
                sb.AppendLine("using System.Web.UI;");
                sb.AppendLine("using System.Web.UI.WebControls;");
                sb.AppendLine("using System.Web.UI.WebControls.WebParts;");
                sb.AppendLine("using System.Web.UI.HtmlControls;");
                sb.AppendLine();

                sb.AppendLine(GenerateNamespaceIncludes(namespace_includes));
                sb.AppendLine();

                #endregion

                sb.AppendLine("namespace WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));
                sb.AppendLine("{");
                sb.AppendLine(AddTabs(1) + "public partial class " + view_class_name + " : System.Web.UI.Page");
                sb.AppendLine(AddTabs(1) + "{");

                sb.AppendLine(AddTabs(2) + "#region Fields");
                sb.AppendLine();

                #region Fields
                sb.AppendLine(AddTabs(3) + "protected string _SQLConnection = ConfigurationManager.ConnectionStrings[\"SQLConnection\"].ConnectionString;");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#region Properties");
                sb.AppendLine();

                #region Properties
                sb.AppendLine(AddTabs(3) + "protected string PageName");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get { return \"" + view_class_name + "\"; }");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine(AddTabs(3) + "protected PaginationManager PageinationData");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"PaginationManager\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"PaginationManager\"] = new PaginationManager();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (PaginationManager)ViewState[\"PaginationManager\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"PaginationManager\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine(AddTabs(3) + "protected string ReturnPage");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"ReturnPage\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"ReturnPage\"] = \"~/Default.aspx\";");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (string)ViewState[\"ReturnPage\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"ReturnPage\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine(AddTabs(3) + "protected int EditingID");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"EditingID\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"EditingID\"] = 0;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (int)ViewState[\"EditingID\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"EditingID\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#region Methods");
                sb.AppendLine();

                #region BindForm Method
                sb.AppendLine(AddTabs(3) + "protected void BindForm()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + NameFormatter.ToCSharpClassName("DAL" + sql_table.Name) + " dal_obj = new " + NameFormatter.ToCSharpClassName("DAL" + sql_table.Name) + "(_SQLConnection);");
                sb.AppendLine(AddTabs(4) + "dal_obj.LoadSingleFromDb(this.EditingID);");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "if (dal_obj.Collection.Count > 0)");
                sb.AppendLine(AddTabs(4) + "{");

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (!sql_column.IsPk)
                    {
                        // need to account for datatypes that need to be converted to a string.

                        switch (sql_column.BaseType)
                        {
                            case eSqlBaseType.Bool:
                                sb.AppendLine(AddTabs(5) + PadCSharpVariableName("chk" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ".Checked", longest_column, 11) + "= dal_obj.Collection[0]." + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ";");
                                break;

                            case eSqlBaseType.Guid:
                                sb.AppendLine(AddTabs(5) + PadCSharpVariableName("lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) +".Text", longest_column, 11) + "= dal_obj.Collection[0]." + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ".ToString();");
                                break;

                            case eSqlBaseType.Integer:
                                sb.AppendLine(AddTabs(5) + PadCSharpVariableName("lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) +".Text", longest_column, 11) + "= dal_obj.Collection[0]." + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ".ToString();");
                                break;

                            case eSqlBaseType.Float:
                                sb.AppendLine(AddTabs(5) + PadCSharpVariableName("lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) +".Text", longest_column, 11) + "= dal_obj.Collection[0]." + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ".ToString();");
                                break;

                            case eSqlBaseType.Time:
                                sb.AppendLine(AddTabs(5) + PadCSharpVariableName("lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) +".Text", longest_column, 11) + "= dal_obj.Collection[0]." + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ".ToString();");
                                break;

                            default:
                                sb.AppendLine(AddTabs(5) + PadCSharpVariableName("lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) +".Text", longest_column, 11) + "= dal_obj.Collection[0]." + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ";");
                                break;
                        }
                    }
                }
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "else");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "this.lblErrorMessage.Text = \"Load Failed\";");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region Check Credentials method
                sb.AppendLine(AddTabs(3) + "protected void CheckCredentials()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#region Events");
                sb.AppendLine();

                #region pageload event method
                sb.AppendLine(AddTabs(3) + "protected void Page_Load(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "CheckCredentials();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "if (!Page.IsPostBack)");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (Request.QueryString[\"Id\"] != null)");
                sb.AppendLine(AddTabs(6) + "this.EditingID = Convert.ToInt32(Request.QueryString[\"Id\"]);");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "if (Request.QueryString[\"ReturnPage\"] != null)");
                sb.AppendLine(AddTabs(6) + "this.ReturnPage = (string)Request.QueryString[\"ReturnPage\"];");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "if (Request.QueryString[\"PageData\"] != null)");
                sb.AppendLine(AddTabs(6) + "this.PageinationData = new PaginationManager(Request.QueryString[\"PageData\"].ToString());");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "BindForm();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");

                sb.AppendLine(AddTabs(1) + "}");
                sb.AppendLine("}");

                output.Body = sb.ToString();
                return output;
        }
コード例 #14
0
        public static OutputObject GenerateWebListPageCodeInFront(SqlTable sql_table, bool create_as_asp_control)
        {
            if (sql_table == null)
                    return null;

                string list_object_name     = "List" + NameFormatter.ToCSharpPropertyName(sql_table.Name);
                string edit_object_name     = "Edit" + NameFormatter.ToCSharpPropertyName(sql_table.Name);
                string orm_class_name       = NameFormatter.ToCSharpClassName(sql_table.Name);
                string list_class_name      = NameFormatter.ToCSharpClassName(list_object_name);

                OutputObject output = new OutputObject();
                output.Name =  list_object_name + ".aspx";
                output.Type = OutputObject.eObjectType.Aspx;

                bool first_flag = true;

                StringBuilder sb = new StringBuilder();

                if (create_as_asp_control)
                {
                    sb.AppendLine("<%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"" + list_object_name + ".aspx.cs\" Inherits=\"WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "." + list_object_name + "\" %>");
                }
                else
                {
                    sb.AppendLine("<%@ Page Language=\"C#\" MasterPageFile=\"~/MasterPage.master\" AutoEventWireup=\"true\" CodeBehind=\"" + list_object_name + ".aspx.cs\" Inherits=\"WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "." + list_object_name + "\" %>");
                    sb.AppendLine();
                    sb.AppendLine("<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"head\" Runat=\"Server\">");
                    sb.AppendLine("</asp:Content>");
                    sb.AppendLine();
                    sb.AppendLine("<asp:Content ID=\"Content2\" ContentPlaceHolderID=\"body\" Runat=\"Server\">");
                }

                sb.AppendLine("<asp:Panel ID=\"panList\" DefaultButton=\"btnSearch\" runat=\"server\">");
                sb.AppendLine();

                sb.AppendLine(AddTabs(1) + "<div class=\"PageTitle\">" + NameFormatter.ToFriendlyName(sql_table.Name));
                sb.AppendLine(AddTabs(1) + "<asp:LinkButton ID=\"btnAddNewItem\" OnClick=\"btnAddNewItem_Click\" runat=\"server\" Text=\"(Add new item)\" CssClass=\"AddItemLink\" />");
                sb.AppendLine(AddTabs(1) + "</div>");
                sb.AppendLine();

                sb.AppendLine(AddTabs(1) + "<asp:TextBox ID=\"txtSearch\" runat=\"server\" />");
                sb.AppendLine(AddTabs(1) + "<asp:Button ID=\"btnSearch\" runat=\"server\" CssClass=\"Button1\" Text=\"Search\" OnClick=\"btnSearch_Click\" />");
                sb.AppendLine();

                #region Repeater
                sb.AppendLine(AddTabs(1) + "<asp:Repeater ID=\"rptList\" runat=\"server\" >");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "<HeaderTemplate>");
                sb.AppendLine(AddTabs(2) + "<table width=\"100%\">");
                sb.AppendLine(AddTabs(2) + "<tr class=\"RepeaterHeaderStyle\">");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    sb.AppendLine(AddTabs(3) + "<td><span class=\"RepeaterHeader\">" + NameFormatter.ToFriendlyName(sql_column.Name) + "</span></td>");
                }

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "</tr>");
                sb.AppendLine(AddTabs(2) + "</HeaderTemplate>");
                sb.AppendLine();

                // Item template
                sb.AppendLine(AddTabs(2) + "<ItemTemplate>");
                sb.AppendLine(AddTabs(2) + "<tr class=\"RepeaterItemStyle\">");
                sb.AppendLine();

                first_flag = true;

                foreach (var item in sql_table.Columns.Values)
                {
                    string current_item_binding = "((" + sql_table.Database.Name + "." + orm_class_name + ")Container.DataItem)." + NameFormatter.ToCSharpPropertyNameString(item);

                    if (first_flag)
                    {
                        first_flag = false;
                        sb.AppendLine(AddTabs(3) + "<td valign=\"top\"><a href=\"" +  edit_object_name + ".aspx?id=<%# " + current_item_binding + " %>&ReturnPage=" + list_object_name + "&PageData=<%=PageinationData.ToString()%>\"><%# " + current_item_binding + " %></a></td>");
                    }
                    else
                    {
                        sb.AppendLine(AddTabs(3) + "<td valign=\"top\"><span class=\"RepeaterCell\"><%# " + current_item_binding + " %></span></td>");
                    }
                }

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "</tr>");
                sb.AppendLine(AddTabs(2) + "</ItemTemplate>");
                sb.AppendLine();

                // Alternating item template
                sb.AppendLine(AddTabs(2) + "<AlternatingItemTemplate>");
                sb.AppendLine(AddTabs(2) + "<tr class=\"AlternatingRepeaterItemStyle\">");
                sb.AppendLine();

                first_flag = true;

                foreach (var item in sql_table.Columns.Values)
                {
                    string current_item_binding = "((" + sql_table.Database.Name + "." + orm_class_name + ")Container.DataItem)." + NameFormatter.ToCSharpPropertyNameString(item);

                    if (first_flag)
                    {
                        first_flag = false;
                        sb.AppendLine(AddTabs(3) + "<td valign=\"top\"><a href=\"" +  edit_object_name + ".aspx?id=<%# " + current_item_binding + " %>&ReturnPage=" + list_object_name + "&PageData=<%=PageinationData.ToString()%>\"><%# " + current_item_binding + " %></a></td>");
                    }
                    else
                    {
                        sb.AppendLine(AddTabs(3) + "<td valign=\"top\"><span class=\"RepeaterCell\"><%# " + current_item_binding + " %></span></td>");
                    }
                }

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "</tr>");
                sb.AppendLine(AddTabs(2) + "</AlternatingItemTemplate>");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "<FooterTemplate>");
                sb.AppendLine(AddTabs(2) + "</table>");
                sb.AppendLine(AddTabs(2) + "</FooterTemplate>");
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "</asp:Repeater>");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "<asp:Button ID=\"btnFirstPage\" runat=\"server\" CssClass=\"Button1\" OnClick=\"btnFirstPage_Click\" Text=\"&lt;&lt;\" />");
                sb.AppendLine(AddTabs(1) + "<asp:Button ID=\"btnPrevPage\" runat=\"server\" CssClass=\"Button1\" OnClick=\"btnPrevPage_Click\" Text=\"&lt;\" />");
                sb.AppendLine(AddTabs(1) + "<asp:Label ID=\"lblCounter\" runat=\"server\" Text=\"Label\" />");
                sb.AppendLine(AddTabs(1) + "<asp:Button ID=\"btnNextPage\" runat=\"server\" CssClass=\"Button1\" OnClick=\"btnNextPage_Click\" Text=\"&gt;\" />");
                sb.AppendLine(AddTabs(1) + "<asp:Button ID=\"btnLastPage\" runat=\"server\" CssClass=\"Button1\" OnClick=\"btnLastPage_Click\" Text=\"&gt;&gt;\" />");
                sb.AppendLine(AddTabs(1) + "<asp:DropDownList ID=\"ddlPageSize\" runat=\"server\" OnSelectedIndexChanged=\"ddlPageSize_SelectedIndexChanged\" AutoPostBack=\"True\" /> items per page");

                sb.AppendLine();
                sb.AppendLine("</asp:Panel>");

                if (!create_as_asp_control)
                    sb.AppendLine("</asp:Content>");

                output.Body = sb.ToString();
                return output;
        }
コード例 #15
0
        public static OutputObject GenerateWebServiceCodeBehindClass(SqlTable sql_table, List<string> namespace_includes)
        {
            if (sql_table == null)
                    return null;

                string class_name = NameFormatter.ToCSharpClassName(sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name = class_name + ".asmx.cs";
                output.Type = OutputObject.eObjectType.CSharp;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Web;");
                sb.AppendLine("using System.Collections;");
                sb.AppendLine("using System.Web.Services;");
                sb.AppendLine("using System.Web.Services.Protocols;");
                sb.AppendLine("using System.ComponentModel;");
                sb.AppendLine();

                sb.AppendLine(GenerateNamespaceIncludes(namespace_includes));
                sb.AppendLine();

                sb.AppendLine("namespace WebService1");
                sb.AppendLine("{");
                sb.AppendLine(AddTabs(1) + "[WebService(Namespace = \"http://tempuri.org/\")]");
                sb.AppendLine(AddTabs(1) + "[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]");
                sb.AppendLine(AddTabs(1) + "[ToolboxItem(false)]");
                sb.AppendLine(AddTabs(1) + "public class Service1 : System.Web.Services.WebService");
                sb.AppendLine(AddTabs(1) + "{");
                sb.AppendLine(AddTabs(2) + "[WebMethod]");
                sb.AppendLine(AddTabs(2) + "public string HelloWorld()");
                sb.AppendLine(AddTabs(2) + "{");
                sb.AppendLine(AddTabs(3) + "return \"Hello World\";");
                sb.AppendLine(AddTabs(2) + "}");
                sb.AppendLine(AddTabs(1) + "}");
                sb.AppendLine("}");

                output.Body = sb.ToString();
                return output;
        }
コード例 #16
0
        public static OutputObject GenerateWebListPageCodeBehind(SqlTable sql_table, List<string> namespace_includes)
        {
            if (sql_table == null)
                    return null;

                string class_name = "List" + NameFormatter.ToCSharpPropertyName(sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name =  class_name + ".aspx.cs";
                output.Type = OutputObject.eObjectType.CSharp;

                namespace_includes.Add(NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));

                StringBuilder sb = new StringBuilder();

                #region Includes
                sb.AppendLine("using System;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Configuration;");
                sb.AppendLine("using System.Collections;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using System.Web;");
                sb.AppendLine("using System.Web.Security;");
                sb.AppendLine("using System.Web.UI;");
                sb.AppendLine("using System.Web.UI.WebControls;");
                sb.AppendLine("using System.Web.UI.WebControls.WebParts;");
                sb.AppendLine("using System.Web.UI.HtmlControls;");
                sb.AppendLine();

                sb.AppendLine(GenerateNamespaceIncludes(namespace_includes));
                sb.AppendLine();

                #endregion

                sb.AppendLine("namespace WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));
                sb.AppendLine("{");
                sb.AppendLine(AddTabs(1) + "public partial class " + class_name + " : System.Web.UI.Page");
                sb.AppendLine(AddTabs(1) + "{");

                #region Fields
                sb.AppendLine(AddTabs(2) + "#region Fields");
                sb.AppendLine();
                sb.AppendLine(AddTabs(3) + "protected string _SQLConnection = ConfigurationManager.ConnectionStrings[\"SQLConnection\"].ConnectionString;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                #endregion

                #region Properties
                sb.AppendLine(AddTabs(2) + "#region Properties");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "protected string PageName");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get { return \"" + class_name + "\"; }");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine(AddTabs(3) + "protected PaginationManager PageinationData");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"PaginationManager\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"PaginationManager\"] = new PaginationManager();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (PaginationManager)ViewState[\"PaginationManager\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"PaginationManager\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine(AddTabs(3) + "protected string ReturnPage");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"ReturnPage\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"ReturnPage\"] = \"~/Default.aspx\";");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (string)ViewState[\"ReturnPage\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"ReturnPage\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine(AddTabs(3) + "protected int EditingID");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"EditingID\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"EditingID\"] = -1;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (int)ViewState[\"EditingID\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"EditingID\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine(AddTabs(3) + "protected string SearchString");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "get");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (ViewState[\"SearchString\"] == null)");
                sb.AppendLine(AddTabs(6) + "ViewState[\"SearchString\"] = string.Empty;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "return (string)ViewState[\"SearchString\"];");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "set");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "ViewState[\"SearchString\"] = value;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                #endregion

                sb.AppendLine(AddTabs(2) + "#region Methods");
                sb.AppendLine();

                #region Bind Repeater method
                sb.AppendLine(AddTabs(3) + "protected void BindRepeater()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "var dal_obj = new " + NameFormatter.ToCSharpClassName("Dal" + sql_table.Name) + "(_SQLConnection);");
                sb.AppendLine(AddTabs(4) + "dal_obj.LoadAllFromDbPaged(this.PageinationData.ItemIndex, this.PageinationData.PageSize, this.SearchString);");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "this.PageinationData.SetSize = dal_obj.GetSearchCountFromDb(this.SearchString);");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "rptList.DataSource = dal_obj.Collection;");
                sb.AppendLine(AddTabs(4) + "rptList.DataBind();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region Bind Page Size Control method
                sb.AppendLine(AddTabs(3) + "protected void BindPageSizeControl()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.ddlPageSize.Items.Clear();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "this.ddlPageSize.Items.Add(new ListItem(\"10\"));");
                sb.AppendLine(AddTabs(4) + "this.ddlPageSize.Items.Add(new ListItem(\"25\"));");
                sb.AppendLine(AddTabs(4) + "this.ddlPageSize.Items.Add(new ListItem(\"50\"));");
                sb.AppendLine(AddTabs(4) + "this.ddlPageSize.Items.Add(new ListItem(\"100\"));");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "this.ddlPageSize.Text = this.PageinationData.PageSize.ToString();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region Bind Page Counter method
                sb.AppendLine(AddTabs(3) + "protected void BindPageCounter()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.lblCounter.Text = string.Format(\"Items {0} - {1} of {2}\",");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.FirstItemOnCurrentPage, ");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.LastItemOnCurrentPage, ");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.SetSize);");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region Check Credentials method
                sb.AppendLine(AddTabs(3) + "protected void CheckCredentials()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#region Events");
                sb.AppendLine();

                #region pageload event method
                sb.AppendLine(AddTabs(3) + "protected void Page_Load(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "CheckCredentials();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "this.txtSearch.Focus();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "if (!Page.IsPostBack)");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "if (Request.QueryString[\"ReturnPage\"] != null)");
                sb.AppendLine(AddTabs(6) + "this.ReturnPage = (string)Request.QueryString[\"ReturnPage\"];");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "if (Request.QueryString[\"PageData\"] != null)");
                sb.AppendLine(AddTabs(6) + "this.PageinationData = new PaginationManager(Request.QueryString[\"PageData\"].ToString());");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "BindPageSizeControl();");
                sb.AppendLine(AddTabs(5) + "BindRepeater();");
                sb.AppendLine(AddTabs(5) + "BindPageCounter();");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region btnPrevPage_Click method
                sb.AppendLine(AddTabs(3) + "protected void btnPrevPage_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.PreviousPage();");
                sb.AppendLine(AddTabs(4) + "BindRepeater();");
                sb.AppendLine(AddTabs(4) + "BindPageCounter();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region btnNextPage_Click method
                sb.AppendLine(AddTabs(3) + "protected void btnNextPage_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.NextPage();");
                sb.AppendLine(AddTabs(4) + "BindRepeater();");
                sb.AppendLine(AddTabs(4) + "BindPageCounter();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region btnFirstPage_Click method
                sb.AppendLine(AddTabs(3) + "protected void btnFirstPage_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.JumpToFirstPage();");
                sb.AppendLine(AddTabs(4) + "BindRepeater();");
                sb.AppendLine(AddTabs(4) + "BindPageCounter();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region btnLastPage_Click method
                sb.AppendLine(AddTabs(3) + "protected void btnLastPage_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.JumpToLastPage();");
                sb.AppendLine(AddTabs(4) + "BindRepeater();");
                sb.AppendLine(AddTabs(4) + "BindPageCounter();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region btnAddNewItem_Click method
                sb.AppendLine(AddTabs(3) + "protected void btnAddNewItem_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.Response.Redirect(\"Edit" + NameFormatter.ToCSharpPropertyName(sql_table.Name) + ".Aspx?id=0&ReturnPage=\" + this.PageName + \"&PageData=\" + this.PageinationData.ToString(), true);");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region btnSearch_Click method
                sb.AppendLine(AddTabs(3) + "protected void btnSearch_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.SearchString = this.txtSearch.Text;");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.ItemIndex = 1;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "BindPageSizeControl();");
                sb.AppendLine(AddTabs(4) + "BindRepeater();");
                sb.AppendLine(AddTabs(4) + "BindPageCounter();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                #region ddlPageSize_SelectedIndexChanged method
                sb.AppendLine(AddTabs(3) + "protected void ddlPageSize_SelectedIndexChanged(Object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.PageinationData.PageSize = Convert.ToInt32(this.ddlPageSize.Text);");
                sb.AppendLine(AddTabs(4) + "BindRepeater();");
                sb.AppendLine(AddTabs(4) + "BindPageCounter();");
                sb.AppendLine(AddTabs(3) + "}");
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine(AddTabs(1) + "}");
                sb.AppendLine("}");
                sb.AppendLine();
                output.Body = sb.ToString();
                return output;
        }
コード例 #17
0
        public static OutputObject GenerateWebEditPageCodeInFront(SqlTable sql_table, bool create_as_asp_control)
        {
            if (sql_table == null)
                    return null;

                string list_class_name = "List" + NameFormatter.ToCSharpPropertyName(sql_table.Name);
                string edit_class_name = "Edit" + NameFormatter.ToCSharpPropertyName(sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name =  edit_class_name + ".aspx";
                output.Type = OutputObject.eObjectType.Aspx;

                StringBuilder sb = new StringBuilder();

                if (create_as_asp_control)
                {
                    sb.AppendLine("<%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"" + edit_class_name + ".aspx.cs\" Inherits=\"WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "." + edit_class_name + "\" %>");
                }
                else
                {
                    sb.AppendLine("<%@ Page Language=\"C#\" MasterPageFile=\"~/MasterPage.master\" AutoEventWireup=\"True\" CodeBehind=\"" + edit_class_name + ".aspx.cs\" Inherits=\"WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "." + edit_class_name + "\" %>");
                    sb.AppendLine();
                    sb.AppendLine("<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"head\" Runat=\"Server\">");
                    sb.AppendLine("</asp:Content>");
                    sb.AppendLine();
                    sb.AppendLine("<asp:Content ID=\"Content2\" ContentPlaceHolderID=\"body\" Runat=\"Server\">");
                }

                sb.AppendLine();
                sb.AppendLine("<div class=\"PageTitle\">" + NameFormatter.ToFriendlyName(sql_table.Name) + "</div>");
                sb.AppendLine();

                sb.AppendLine("<asp:Panel CssClass=\"DetailsPanel\" ID=\"panDetails\" runat=\"server\">");
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "<div class=\"Spacer\">");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "<table border=\"0\" width=\"100%\">");
                sb.AppendLine(AddTabs(2) + "<tr>");
                sb.AppendLine(AddTabs(3) + "<td></td>");
                sb.AppendLine(AddTabs(3) + "<td class=\"SectionTitle\"><asp:Label ID=\"lblTitle\" runat=\"server\" /></td>");
                sb.AppendLine(AddTabs(2) + "</tr>");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (!sql_column.IsPk)
                    {
                        sb.AppendLine(AddTabs(2) + "<tr>");
                        sb.AppendLine(AddTabs(3) + "<td class=\"ControlLabel\">" + NameFormatter.ToFriendlyName(sql_column.Name) + ":</td>");

                        switch (sql_column.BaseType)
                        {
                            case eSqlBaseType.Bool:
                            sb.AppendLine(AddTabs(3) + "<td><asp:CheckBox ID=\"chk" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" /></td>");
                            break;

                            case eSqlBaseType.Time:
                            sb.AppendLine(AddTabs(3) + "<td><asp:TextBox ID=\"txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" /></td>");
                            break;

                            default:
                            if (sql_column.BaseType == eSqlBaseType.String)
                            {
                                if (sql_column.Length == -1)
                                {
                                    sb.AppendLine(AddTabs(3) + "<td><asp:TextBox ID=\"txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" TextMode=\"MultiLine\" Rows=\"8\" Width=\"400\" /></td>");
                                }
                                else if (sql_column.Length > 100 )
                                {
                                    sb.AppendLine(AddTabs(3) + "<td><asp:TextBox ID=\"txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" Width=\"400\" Rows=\"" + (sql_column.Length/100).ToString() + "\" TextMode=\"MultiLine\" /></td>");
                                }
                                else
                                {
                                    sb.AppendLine(AddTabs(3) + "<td><asp:TextBox ID=\"txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" Width=\"400\" MaxLength=\"" + sql_column.Length.ToString() + "\" /></td>");
                                }
                            }
                            else
                            {
                                //This might need to have the max length fixed. ints and stuff can end up here.
                                sb.AppendLine(AddTabs(3) + "<td><asp:TextBox ID=\"txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" Width=\"400\" MaxLength=\"" + sql_column.Length.ToString() + "\" /></td>");
                            }
                            break;
                        }

                        sb.AppendLine(AddTabs(2) + "</tr>");
                        sb.AppendLine();
                    }
                }

                // buttons
                sb.AppendLine(AddTabs(2) + "<tr>");
                sb.AppendLine(AddTabs(3) + "<td></td>");
                sb.AppendLine(AddTabs(3) + "<td class=\"SectionTitle\">");
                sb.AppendLine(AddTabs(4) + "<asp:Button ID=\"btnSave\" runat=\"server\" CssClass=\"Button1\" Text=\"Save\" OnClick=\"btnSave_Click\" />");
                sb.AppendLine(AddTabs(4) + "<asp:Button ID=\"btnUndo\" runat=\"server\" CssClass=\"Button1\" Text=\"Undo Changes\" OnClick=\"btnUndo_Click\" />");
                sb.AppendLine(AddTabs(3) + "</td>");
                sb.AppendLine(AddTabs(2) + "</tr>");
                sb.AppendLine(AddTabs(2) + "</table>");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "<asp:Label ID=\"lblErrorMessage\" CssClass=\"ErrorMessage\" runat=\"server\" />");
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "</div>");
                sb.AppendLine();
                sb.AppendLine("</asp:Panel>");

                if (!create_as_asp_control)
                {
                    sb.AppendLine();
                    sb.AppendLine("</asp:Content>");
                }

                output.Body = sb.ToString();
                return output;
        }
コード例 #18
0
        public static OutputObject GenerateSetProc(SqlTable sql_table, bool generate_stored_proc_perms)
        {
            if (sql_table == null)
                    return null;

                string procedure_name       = GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.UpdateInsert, null);
                int longest_column          = GetLongestColumnLength(sql_table);
                bool flag_first_value       = true;

                OutputObject output = new OutputObject();
                output.Name = procedure_name + ".sql";
                output.Type = OutputObject.eObjectType.Sql;

                // sanity check - if there are no primary keys in the table, we cannot know
                // what would a good choice would be for a qualifier. Abort and return error msg.
                if (sql_table.PkList.Count == 0)
                {
                    output.Body = "/* Cannot generate " + procedure_name + ", no primary keys set on " + sql_table.Name + ". */" + Environment.NewLine + Environment.NewLine;
                    return output;
                }

                StringBuilder sb = new StringBuilder();

                sb.AppendLine(GenerateSqlExistanceChecker(procedure_name));
                sb.AppendLine(GenerateHeader(procedure_name));

                sb.AppendLine("CREATE PROCEDURE " + procedure_name);
                sb.AppendLine(GenerateSqlStoredProcParameters(sql_table, eIncludedFields.All));

                sb.AppendLine("AS");
                sb.AppendLine();
                sb.AppendLine("SET NOCOUNT ON");
                sb.AppendLine();

                #region Existance Check
                sb.Append("IF EXISTS (SELECT 1 FROM [" + sql_table.Name + "] ");

                // Build where clause
                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (sql_column.IsPk)
                    {
                        if (flag_first_value)
                        {
                            sb.Append("WHERE ");
                            flag_first_value = false;
                        }
                        else
                        {
                            sb.Append(" AND ");
                        }

                        sb.Append(sql_column.Name + " = " + NameFormatter.ToTSQLVariableName(sql_column));
                    }
                }

                sb.AppendLine(")");
                #endregion

                sb.AppendLine("BEGIN");

                #region Update Clause
                sb.Append(AddTabs(1) + "-- Already Exists, Update" + Environment.NewLine );
                sb.Append(AddTabs(1) + "UPDATE\t[" + sql_table.Name + "]" + Environment.NewLine );

                // list selected columns
                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (!sql_column.IsPk && !sql_column.IsIdentity)
                    {
                        if (flag_first_value)
                        {
                            sb.Append(AddTabs(1) + "SET" + AddTabs(2));
                            flag_first_value = false;
                        }
                        else
                        {
                            sb.Append("," + Environment.NewLine + AddTabs(3));
                        }

                        sb.Append(PadSqlVariableName(NameFormatter.ToTSQLName(sql_column.Name), longest_column) + "= " + NameFormatter.ToTSQLVariableName(sql_column));
                    }
                }

                sb.Append(Environment.NewLine);

                // Build where clause
                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (sql_column.IsPk)
                    {
                        if (flag_first_value)
                        {
                            sb.Append(AddTabs(1) + "WHERE" + AddTabs(1));
                            flag_first_value = false;
                        }
                        else
                        {
                            sb.Append(Environment.NewLine + AddTabs(1) + "AND" + AddTabs(1));
                        }

                        sb.Append(PadSqlVariableName(NameFormatter.ToTSQLName(sql_column.Name), longest_column) + "= " + NameFormatter.ToTSQLVariableName(sql_column));
                    }
                }

                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "RETURN @Id"); // HACK - this will work with my PK designs....
                #endregion

                sb.AppendLine("END");
                sb.AppendLine("ELSE");
                sb.AppendLine("BEGIN");

                #region Insert Clause
                sb.AppendLine(AddTabs(1) + "-- New Entry, Insert");
                sb.AppendLine(AddTabs(1) + "INSERT [" + sql_table.Name + "]");
                sb.AppendLine(AddTabs(1) + "(");

                // list selected columns
                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (!sql_column.IsIdentity)
                    {
                        if (flag_first_value)
                        {
                            sb.Append(AddTabs(2));
                            flag_first_value = false;
                        }
                        else
                        {
                            sb.Append("," + Environment.NewLine + AddTabs(2));
                        }

                        sb.Append(NameFormatter.ToTSQLName(sql_column.Name));
                    }
                }

                sb.Append(Environment.NewLine + AddTabs(1) + ")");
                sb.Append(Environment.NewLine + AddTabs(1) + "VALUES");
                sb.Append(Environment.NewLine + AddTabs(1) + "(");

                // Build where clause
                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (!sql_column.IsIdentity)
                    {
                        if (flag_first_value)
                        {
                            sb.Append(Environment.NewLine + AddTabs(2));
                            flag_first_value = false;
                        }
                        else
                        {
                            sb.Append("," + Environment.NewLine + AddTabs(2));
                        }

                        sb.Append(NameFormatter.ToTSQLVariableName(sql_column));
                    }
                }

                sb.Append(Environment.NewLine + AddTabs(1) + ")");
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "RETURN SCOPE_IDENTITY()");
                #endregion

                sb.AppendLine("END");
                sb.AppendLine("GO");
                sb.AppendLine();

                if (generate_stored_proc_perms)
                {
                    sb.AppendLine(GenerateSqlStoredProcPerms(procedure_name));
                    sb.AppendLine();
                }

                output.Body = sb.ToString();
                return output;
        }
コード例 #19
0
        private static string FindNameField(SqlTable sql_table)
        {
            // occasionally we might need to figure out a friendly name field for
                // a table. this method isn't perfect, but its a decent stab at the problem.
                // grab the first text field we have, and hope for the best.

                foreach (var column in sql_table.Columns)
                {
                    if (column.Value.BaseType == eSqlBaseType.String)
                        return column.Key;
                }

                // still here? no matches then...
                return string.Empty;
        }
コード例 #20
0
        public static OutputObject GenerateWebViewPageCodeInFront(SqlTable sql_table, bool create_as_asp_control)
        {
            if (sql_table == null)
                    return null;

                string view_class_name = "View" + NameFormatter.ToCSharpPropertyName(sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name =  view_class_name + ".aspx";
                output.Type = OutputObject.eObjectType.Aspx;

                StringBuilder sb = new StringBuilder();

                if (create_as_asp_control)
                {
                    sb.AppendLine("<%@ Control Language=\"C#\" AutoEventWireup=\"true\" CodeBehind=\"" + view_class_name + ".aspx.cs\" Inherits=\"WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "." + view_class_name + "\" %>");
                }
                else
                {
                    sb.AppendLine("<%@ Page Language=\"C#\" MasterPageFile=\"~/MasterPage.master\" AutoEventWireup=\"True\" CodeBehind=\"" + view_class_name + ".aspx.cs\" Inherits=\"WebControls." + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "." + view_class_name + "\" %>");
                    sb.AppendLine();
                    sb.AppendLine("<asp:Content ID=\"Content1\" ContentPlaceHolderID=\"head\" Runat=\"Server\">");
                    sb.AppendLine("</asp:Content>");
                    sb.AppendLine();
                    sb.AppendLine("<asp:Content ID=\"Content2\" ContentPlaceHolderID=\"body\" Runat=\"Server\">");
                }

                sb.AppendLine();
                sb.AppendLine("<div class=\"PageTitle\">View " + NameFormatter.ToFriendlyName(sql_table.Name) + "</div>");
                sb.AppendLine();

                sb.AppendLine("<asp:Panel CssClass=\"DetailsPanel\" ID=\"panDetails\" runat=\"server\">");
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "<div class=\"Spacer\">");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "<table border=\"0\" width=\"100%\">");
                sb.AppendLine(AddTabs(2) + "<tr>");
                sb.AppendLine(AddTabs(3) + "<td></td>");
                sb.AppendLine(AddTabs(3) + "<td class=\"SectionTitle\"><asp:Label ID=\"lblTitle\" runat=\"server\" /></td>");
                sb.AppendLine(AddTabs(2) + "</tr>");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (!sql_column.IsPk)
                    {
                        sb.AppendLine(AddTabs(2) + "<tr>");
                        sb.AppendLine(AddTabs(3) + "<td class=\"ControlLabel\">" + NameFormatter.ToFriendlyName(sql_column.Name) + ":</td>");

                        switch (sql_column.BaseType)
                        {
                            case eSqlBaseType.Bool:
                            sb.AppendLine(AddTabs(3) + "<td><asp:CheckBox ID=\"chk" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" Enabled=\"False\"  runat=\"server\" /></td>");
                            break;

                            //case eSqlBaseType.Time:
                            //sb.AppendLine(AddTabs(3) + "<td><asp:Calendar ID=\"cal" + NameFormatter.ToCSharpPropertyName(sql_column.ColumnName) + " runat=\"server\" /></td>");
                            //break;

                            default:
                            sb.AppendLine(AddTabs(3) + "<td><asp:Label ID=\"lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\" runat=\"server\" /></td>");
                            break;
                        }

                        sb.AppendLine(AddTabs(2) + "</tr>");
                        sb.AppendLine();
                    }
                }

                // buttons
                sb.AppendLine(AddTabs(2) + "</table>");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "<asp:Label ID=\"lblErrorMessage\" CssClass=\"ErrorMessage\" runat=\"server\" />");
                sb.AppendLine();
                sb.AppendLine(AddTabs(1) + "</div>");
                sb.AppendLine();
                sb.AppendLine("</asp:Panel>");

                if (!create_as_asp_control)
                {
                    sb.AppendLine();
                    sb.AppendLine("</asp:Content>");
                }

                output.Body = sb.ToString();
                return output;
        }
コード例 #21
0
        private static string GenerateOrderByClause(SqlTable sql_table, List<string> column_names)
        {
            if (column_names == null || column_names.Count == 0)
                    return "-- ORDER BY [<A_COLUMN_NAME>]";

                StringBuilder sb = new StringBuilder();

                sb.Append("ORDER BY ");

                bool flag_first_value = true;

                foreach (var item in column_names)
                {
                    if (flag_first_value)
                        flag_first_value = false;
                    else
                        sb.Append(",");

                    sb.Append(NameFormatter.ToTSQLName(sql_table.Name) + "." + NameFormatter.ToTSQLName(item));
                }

                return sb.ToString();
        }
コード例 #22
0
        public static OutputObject GenerateCSharpEnumeration(SqlTable sql_table, string string_column, string value_column, DataTable data_table)
        {
            if (sql_table == null)
                    return null;

                string enum_name        = NameFormatter.ToCSharpEnumName(sql_table.Name);
                int longest_column      = GetLongestColumnLength(sql_table);

                OutputObject output = new OutputObject();
                output.Name = enum_name + ".cs";
                output.Type = OutputObject.eObjectType.CSharp;

                StringBuilder sb                = new StringBuilder();

                sb.AppendLine("using System;");
                sb.AppendLine();

                sb.AppendLine("namespace " + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));
                sb.AppendLine("{");
                sb.AppendLine(AddTabs(1) + "public enum " + NameFormatter.ToCSharpEnumName(sql_table.Name));
                sb.AppendLine(AddTabs(1)+ "{");

                // list enumeration
                foreach (DataRow dr in data_table.Rows)
                {
                    string value_string     = dr[value_column].ToString();
                    string enum_string      = dr[string_column].ToString();

                    // make sure that enums are legal names.
                    foreach (string character in s_CSharpUndesireables)
                        enum_string = enum_string.Replace(character, string.Empty);

                    // no leading numbers, foo!
                    if (Char.IsNumber(enum_string[0]))
                        enum_string = "N" + enum_string;

                    sb.AppendLine(AddTabs(2) + PadCSharpVariableName(enum_string, longest_column) + "= " + value_string + ",");
                }

                sb.AppendLine(AddTabs(1) + "}");
                sb.AppendLine("}");

                output.Body = sb.ToString();
                return output;
        }
コード例 #23
0
        private static string GenerateSelectClause(SqlTable sql_table, List<string> column_names)
        {
            #region Sample output:
                // AND [UserId]     = @UserId
                // AND [Age]        = @Age
                // AND [ShoeSize]   = @ShoeSize
                #endregion

                if (sql_table == null || column_names == null || column_names.Count == 0)
                    return string.Empty;

                StringBuilder sb = new StringBuilder();

                bool flag_first_value   = true;
                int longest_column      = GetLongestColumnLength(sql_table) + sql_table.Name.Length;

                foreach (var item in column_names)
                {
                    string field_name = NameFormatter.ToTSQLName(sql_table.Name) + "." + NameFormatter.ToTSQLName(item);

                    if (flag_first_value)
                        flag_first_value = false;
                    else
                        sb.Append(Environment.NewLine);

                    sb.Append("AND" + AddTabs(2) + PadSqlVariableName(field_name, longest_column) + "= " + NameFormatter.ToTSQLVariableName(sql_table.Columns[item]));
                }

                return sb.ToString();
        }
コード例 #24
0
        /// <summary>
        /// Converts table column data to function argument string.
        /// Does not incude function types.
        /// Sample: titles, authors, bookcount. 
        /// </summary>
        public static string GenerateCSharpFunctionList(SqlTable sql_table, eIncludedFields include_types)
        {
            StringBuilder sb    = new StringBuilder();
                bool first_flag     = true;

                foreach (SqlColumn sql_column in sql_table.Columns.Values)
                {
                    if (first_flag)
                        first_flag = false;
                    else
                        sb.Append(", ");

                    switch (include_types)
                    {
                        case eIncludedFields.All:

                            sb.Append(ToLocalCase(sql_column.Name));
                            break;

                        case eIncludedFields.NoIdentities:

                            if (!sql_column.IsIdentity)
                                sb.Append(ToLocalCase(sql_column.Name));

                            break;

                        case eIncludedFields.PKOnly:

                            if (sql_column.IsPk)
                                sb.Append(ToLocalCase(sql_column.Name));

                            break;

                        default:
                            throw new Exception("eIncludedFields value " + include_types.ToString() +" is unrecognised..");
                    }
                }

                return sb.ToString();
        }
コード例 #25
0
        private static string GenerateSqlStoredProcParameters(SqlTable sql_table, eIncludedFields included_fields)
        {
            if (sql_table == null)
                    throw new Exception("Cannot generate stored procedure parameters without a sql table.");

                #region Sample Output
                //(
                //    @CountryID		INT,
                //    @CountryName		VARCHAR(255)
                //)
                #endregion

                StringBuilder sb            = new StringBuilder();
                bool flag_first_value       = true;
                int longest_column          = GetLongestColumnLength(sql_table);

                sb.Append("(");

                // list query parameters
                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if ( (included_fields == eIncludedFields.All) || (included_fields == eIncludedFields.PKOnly && sql_column.IsPk) ||
                        (included_fields == eIncludedFields.NoIdentities && !sql_column.IsIdentity) )
                    {
                        if (flag_first_value)
                            flag_first_value = false;
                        else
                            sb.Append(",");

                        sb.Append(Environment.NewLine + AddTabs(1));
                        sb.Append(PadSqlVariableName(NameFormatter.ToTSQLVariableName(sql_column), longest_column));
                        sb.Append(NameFormatter.ToTSQLType(sql_column));
                    }
                }

                sb.Append(Environment.NewLine + ")");

                return sb.ToString();
        }
コード例 #26
0
        public static OutputObject GenerateCSharpDalClass(SqlTable sql_table, List<string> namespace_includes, bool convert_nullable_fields, bool include_is_dirty_flag)
        {
            #region SampleCode
                //public class FooClass
                //{
                //    private List<FooDataStrure> _Foo = null;

                //    //public FooClass()
                //    //{
                //    //    // foo
                //    //}

                //    public List<FooDataStrure> LoadData(DataTable dt)
                //    {
                //        _Foo.Clear();
                //        foreach (DataRow dr in dt.Rows)
                //        {
                //            p_Foo.Add(new FooDataStrure(Convert.ToInt32(dr["whatever"])));
                //        }

                //        return _Foo;
                //    }
                //}
                #endregion

                if (sql_table == null)
                    return null;

                string list_type			    = NameFormatter.ToCSharpClassName(sql_table.Name);
                string sql_tablename		    = NameFormatter.ToTSQLName(sql_table.Name);
                string collection_type          = "List<" + list_type + ">";
                string class_name               = NameFormatter.ToCSharpClassName("Dal" + sql_table.Name);
                int longest_column              = GetLongestColumnLength(sql_table);

                OutputObject output = new OutputObject();
                output.Name = class_name + ".cs";
                output.Type = OutputObject.eObjectType.CSharp;

                StringBuilder sb = new StringBuilder();

                #region Header block

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using System.Data;");
                sb.AppendLine("using System.Data.SqlClient;");
                sb.AppendLine();

                sb.AppendLine("using DAL;");
                sb.AppendLine(GenerateNamespaceIncludes(namespace_includes));

                #endregion

                sb.AppendLine("namespace " + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name));
                sb.AppendLine("{");
                //sb.AppendLine(AddTabs(1) + "[Serializable]");
                sb.AppendLine(AddTabs(1) + "public partial class " + class_name);
                sb.AppendLine(AddTabs(1) + "{");

                #region Fields bloc
                ////////////////////////////////////////////////////////////////////////////////

                sb.AppendLine(AddTabs(2) + "#region Fields");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "protected string _SQLConnection;");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                sb.AppendLine(AddTabs(2) + "#region Methods");
                sb.AppendLine();

                #region Default CTOR
                ////////////////////////////////////////////////////////////////////////////////

                #region sample output
                //public Foo()
                //{
                //    //foo
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public " + class_name + "(string sql_conn)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "_SQLConnection = sql_conn;");
                sb.AppendLine(AddTabs(3) + "}");

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(3) + "// Public Methods");

                #region GetCountFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public int GetCountFromDb()
                //{
                //    return Database.ExecuteScalarSp<int>("[GalacticConquest].[dbo].[up_Game_CountAll]", null, _SQLConnection);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public int GetCountFromDb()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteScalarSp<int>(\"[" + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "].[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.CountAll, null) + "]\", null, _SQLConnection);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region GetSearchCountFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public int GetSearchCountFromDb(string search_string)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    parameters.Add(new SqlParameter() { ParameterName = "@SearchString", SqlDbType = SqlDbType.VarChar, Size = 50, Value = search_string });
                //    return Database.ExecuteScalarSp<int>("[GalacticConquest].[dbo].[up_Game_CountSearch]", parameters, _SQLConnection);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public int GetSearchCountFromDb(string search_string)");
                sb.AppendLine(AddTabs(3) + "{");

                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");
                sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, "@SearchString", "VarChar", 50, "search_string"));
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteScalarSp<int>(\"" + NameFormatter.ToTSQLName(sql_table.Database.Name) + ".[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.CountSearch, null) + "]\", parameters, _SQLConnection);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region LoadAllFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public List<cGame> LoadAllFromDb()
                //{
                //    return Database.ExecuteQuerySp<cGame>("[GalacticConquest].[dbo].[up_Game_SelectAll]", null, _SQLConnection);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public " + collection_type + " LoadAllFromDb()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteQuerySp<" + list_type + ">(\"[" + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "].[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.SelectAll, null) + "]\", null, _SQLConnection);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region LoadListFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public List<cGame> LoadListFromDb(IEnumerable<int> id_list)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    parameters.Add(new SqlParameter() { ParameterName = "@IdList", SqlDbType = SqlDbType.VarChar, Size = -1, Value = Database.GenericListToStringList(id_list) });
                //    return Database.ExecuteQuerySp<cGame>("[GalacticConquest].[dbo].[up_Game_SelectMany]", parameters, _SQLConnection);
                //}
                #endregion

                if (sql_table.PkList.Count == 0)
                {
                    sb.AppendLine("// Cannot create LoadListFromDb() without a pk on database table.");
                }
                else
                {
                    sb.AppendLine(AddTabs(3) + "public " + collection_type + " LoadListFromDb(IEnumerable<int> id_list)");
                    sb.AppendLine(AddTabs(3) + "{");

                    sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");
                    sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, "@IdList", "VarChar", -1, "Database.GenericListToStringList(id_list)"));
                    sb.AppendLine(AddTabs(4) + "return Database.ExecuteQuerySp<" + list_type + ">(\"" + NameFormatter.ToTSQLName(sql_table.Database.Name) + ".[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.SelectMany, null) + "]\", parameters, _SQLConnection);");
                    sb.AppendLine(AddTabs(3) + "}");
                    sb.AppendLine();
                }

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region LoadAllFromDbPaged
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public List<cGame> LoadAllFromDbPaged(int start_index, int page_size, string search_string)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    parameters.Add(new SqlParameter() { ParameterName = "@StartNumber", SqlDbType = SqlDbType.Int, Size = 4, Value = start_index });
                //    parameters.Add(new SqlParameter() { ParameterName = "@PageSize", SqlDbType = SqlDbType.Int, Size = 4, Value = page_size });
                //    parameters.Add(new SqlParameter() { ParameterName = "@SearchString", SqlDbType = SqlDbType.VarChar, Size = 50, Value = search_string });
                //    return Database.ExecuteQuerySp<cGame>("[GalacticConquest].[dbo].[up_Game_SelectAllPaged]", parameters, _SQLConnection);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public " + collection_type + " LoadAllFromDbPaged(int start_index, int page_size, string search_string)");
                sb.AppendLine(AddTabs(3) + "{");

                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");
                sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, "@StartNumber", "Int", 4, "start_index"));
                sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, "@PageSize", "Int", 4, "page_size"));
                sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, "@SearchString", "VarChar", 50, "search_string"));
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteQuerySp<" + list_type + ">(\"[" + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "].[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.SelectAllPag, null) + "]\", parameters, _SQLConnection);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region LoadSingleFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public cGame LoadSingleFromDb(int id)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    parameters.Add(new SqlParameter() { ParameterName = "@Id", SqlDbType = SqlDbType.Int, Size = 4, Value = id });
                //    var results = Database.ExecuteQuerySp<cGame>("[GalacticConquest].[dbo].[up_Game_SelectSingle]", parameters, _SQLConnection);

                //    if (results != null && results.Count > 0)
                //        return results[0];
                //    else
                //        return null;
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public " + list_type  + " LoadSingleFromDb(" + NameFormatter.GenerateCSharpFunctionArgs(sql_table, eIncludedFields.PKOnly) + ")");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");

                // generate all Sp parameters
                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (sql_column.IsPk)
                        sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, NameFormatter.ToTSQLVariableName(sql_column), sql_column.SqlDataType, sql_column.Length, NameFormatter.ToCSharpLocalVariable(sql_column.Name)));
                }

                sb.AppendLine(AddTabs(4) + "var results = Database.ExecuteQuerySp<" + list_type + ">(\"[" + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "].[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.SelectSingle, null) + "]\", parameters, _SQLConnection);");
                sb.AppendLine();

                sb.AppendLine(AddTabs(4) + "if (results != null && results.Count > 0)");
                sb.AppendLine(AddTabs(5) + "return results[0];");
                sb.AppendLine(AddTabs(4) + "else");
                sb.AppendLine(AddTabs(5) + "return null;");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region DeleteSingleFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public bool DeleteSingleFromDb(int id)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    parameters.Add(new SqlParameter() { ParameterName = "@Id", SqlDbType = SqlDbType.Int, Size = 4, Value = id });
                //    return Database.ExecuteNonQuerySp("[GalacticConquest].[dbo].[up_Game_DeleteSingle]", parameters, _SQLConnection) > 0;
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public bool DeleteSingleFromDb(" + NameFormatter.GenerateCSharpFunctionArgs(sql_table, eIncludedFields.PKOnly) + ")");
                sb.AppendLine(AddTabs(3) + "{");

                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");

                // generate all SP parameters
                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (sql_column.IsPk)
                        sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, NameFormatter.ToTSQLVariableName(sql_column), sql_column.SqlDataType, sql_column.Length, NameFormatter.ToCSharpLocalVariable(sql_column.Name)));
                }

                sb.AppendLine(AddTabs(4) + "return Database.ExecuteNonQuerySp(\"" + NameFormatter.ToTSQLName(sql_table.Database.Name) + ".[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.DelSingle, null) + "]\", parameters, _SQLConnection) > 0;");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region DeleteListFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public int DeleteListFromDb(IEnumerable<int> id_list)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    parameters.Add(new SqlParameter() { ParameterName = "@IdList", SqlDbType = SqlDbType.VarChar, Size = -1, Value = Database.GenericListToStringList<int>(id_list) });
                //    return Database.ExecuteNonQuerySp("[GalacticConquest].[dbo].[up_Game_DeleteMany]", parameters, _SQLConnection);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public int DeleteListFromDb(IEnumerable<int> id_list)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");
                sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPLATE, "@IdList", "VarChar", -1, "Database.GenericListToStringList(id_list)"));
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteNonQuerySp(\"" + NameFormatter.ToTSQLName(sql_table.Database.Name) + ".[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.DelMany, null) + "]\", parameters, _SQLConnection);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region DeleteAllFromDb
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public int DeleteAllFromDb()
                //{
                //    return Database.ExecuteNonQuerySp("[GalacticConquest].[dbo].[up_Game_DeleteAll]", null, _SQLConnection);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public int DeleteAllFromDb()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteNonQuerySp(\"" + NameFormatter.ToTSQLName(sql_table.Database.Name) + ".[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.DelAll, null) + "]\", null, _SQLConnection);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region LoadFromXmlFile
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public bool LoadFromXmlFile(string filename)
                //{
                //    string file_data = FileIo.ReadFromFile(filename, out file_data);
                //    DataSet ds = XmlConverter.XmlStringToDataSet(file_data);
                //    return LoadFromDataTable(ds.Tables["Game"], out results, out exception);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public " + collection_type + " LoadFromXmlFile(string filename)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "string file_data = FileIo.ReadFromFile(filename);");
                sb.AppendLine(AddTabs(4) + "DataSet ds = XmlConverter.XmlStringToDataSet(file_data);");
                sb.AppendLine(AddTabs(4) + "return LoadFromDataTable(ds.Tables[\"" + sql_table.Name + "\"]);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region SaveToXmlFile
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public void SaveToXmlFile(List<cGame> collection, string filename)
                //{
                //    DataTable dt = ConvertToDataTable(collection);
                //    string xml = XmlConverter.DataTableToXmlString(dt, "GalacticConquest");
                //    FileIo.WriteToFile(filename, xml);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public void SaveToXmlFile(" + collection_type  + " collection, string filename)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "DataTable dt = ConvertToDataTable(collection);");
                sb.AppendLine(AddTabs(4) + "string xml = XmlConverter.DataTableToXmlString(dt, \"" + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "\");");
                sb.AppendLine(AddTabs(4) + "FileIo.WriteToFile(filename, xml);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region SaveAll Method
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public void SaveAll(List<cGame> collection)
                //{
                //    foreach (var item in collection)
                //        Save(item);
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public void SaveAll(" + collection_type + " collection)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "foreach (var item in collection)");
                sb.AppendLine(AddTabs(5) + "Save(item);");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region Save Method
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //public bool Save(cGame item)
                //{
                //    List<SqlParameter> parameters = GetSqlParameterList(item);
                //    return Database.ExecuteNonQuerySp("[GalacticConquest].[dbo].[up_Game_Set]", parameters, _SQLConnection) > 0;
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "public bool Save(" + list_type + " item)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = GetSqlParameterList(item);");
                sb.AppendLine(AddTabs(4) + "return Database.ExecuteNonQuerySp(\"" + NameFormatter.ToTSQLName(sql_table.Database.Name) + ".[dbo].[" + GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.UpdateInsert, null) + "]\", parameters, _SQLConnection) > 0;");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region LoadFromDataTable
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //protected List<cGame> LoadFromDataTable(DataTable dt)
                //{
                //    if (dt == null || dt.Rows.Count < 1 || dt.Columns.Count < 1)
                //        return null;

                //    var results = new List<cGame>();

                //    foreach (DataRow dr in dt.Rows)
                //    {
                //        cGame obj = new cGame();

                //        obj.Id = Convert.ToInt32(dr["Id"]);
                //        obj.Name = Convert.ToString(dr["Name"]);
                //        obj.StarDate = Convert.ToDouble(dr["StarDate"]);
                //        obj.GameStateId = Convert.ToInt32(dr["GameStateId"]);
                //        obj.CreatedById = Convert.ToInt32(dr["CreatedById"]);
                //        obj.CreatedDate = Convert.ToDateTime(dr["CreatedDate"]);
                //        obj.Description = Convert.ToString(dr["Description"]);
                //        obj.Disabled = Convert.ToBoolean(dr["Disabled"]);

                //        results.Add(obj);
                //    }

                //    return results;
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "protected " + collection_type + " LoadFromDataTable(DataTable dt)");
                sb.AppendLine(AddTabs(3) + "{");

                sb.AppendLine(AddTabs(4) + "if (dt == null || dt.Rows.Count < 1 || dt.Columns.Count < 1)");
                sb.AppendLine(AddTabs(5) + "return null;");
                sb.AppendLine();

                sb.AppendLine(AddTabs(4) + "var results = new " + collection_type  + "();");
                sb.AppendLine();

                sb.AppendLine(AddTabs(4) + "foreach (DataRow dr in dt.Rows)");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + PadCSharpVariableName(NameFormatter.ToCSharpClassName(sql_table.Name) + " obj", longest_column) + "= new " + NameFormatter.ToCSharpClassName(sql_table.Name) + "();");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    sb.Append(AddTabs(5));

                    if (sql_column.IsNullable)
                    {
                        // hack - nullable doubles need special treatment
                        switch (sql_column.SqlDataType)
                        {
                            case SqlDbType.Float:

                                sb.Append(PadCSharpVariableName("obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column));
                                sb.Append( "= (dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"] == DBNull.Value) ? null : ");
                                sb.Append("new double?(" + NameFormatter.GetCSharpCastString(sql_column) + "(dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]));");
                                break;

                            case SqlDbType.UniqueIdentifier:

                                sb.Append(PadCSharpVariableName("obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column));
                                sb.Append( "= (dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"] == DBNull.Value) ? null : ");
                                sb.Append("new Guid?(new Guid((string)dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]));");
                                break;

                            case SqlDbType.DateTime:

                                sb.Append(PadCSharpVariableName("obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column));
                                sb.Append( "= (dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"] == DBNull.Value) ? null : ");
                                sb.Append("new DateTime?(Convert.ToDateTime(dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]));");
                                break;

                            // TODO may need more switch cases here...

                            default:

                                sb.Append(PadCSharpVariableName("obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column));
                                sb.Append("= (dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"] == DBNull.Value) ? null : ");
                                sb.Append(NameFormatter.GetCSharpCastString(sql_column) + "(dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]);");
                                break;
                        }
                    }
                    else
                    {
                        switch (sql_column.SqlDataType)
                        {
                            case SqlDbType.UniqueIdentifier:

                                sb.Append(PadCSharpVariableName("obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column));
                                sb.Append("= new Guid((string)(dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]));");
                                break;

                            default:

                                sb.Append(PadCSharpVariableName("obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name), longest_column));
                                sb.Append("= " + NameFormatter.GetCSharpCastString(sql_column) + "(dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]);");
                                break;
                        }
                    }

                    sb.AppendLine();
                }
                sb.AppendLine();

                sb.AppendLine(AddTabs(5) + "results.Add(obj);");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "return results;");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region ConvertToDataTable
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //protected DataTable ConvertToDataTable(List<cGame> collection)
                //{
                //    DataTable dt = new DataTable();

                //    dt.Columns.Add("Id", typeof(int));
                //    dt.Columns.Add("Name", typeof(string));
                //    dt.Columns.Add("Disabled", typeof(bool));

                //    dt.TableName = "Game";

                //    foreach (var obj in collection)
                //    {
                //        DataRow dr = dt.NewRow();

                //        dr["Id"]            = obj.Id;
                //        dr["Name"]          = obj.Name;
                //        dr["Disabled"]      = obj.Disabled;

                //        dt.Rows.Add(dr);
                //    }

                //    return dt;
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "protected DataTable ConvertToDataTable(" + collection_type + " collection)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "DataTable dt = new DataTable();");
                sb.AppendLine();

                // dt.Columns.Add("Name", typeof(string));
                foreach (var sql_column in sql_table.Columns.Values)
                    sb.AppendLine(AddTabs(4) + "dt.Columns.Add(\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\", typeof(" + NameFormatter.SQLTypeToCSharpType(sql_column) + "));");

                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "dt.TableName = \"" + sql_table.Name + "\";");
                sb.AppendLine();

                sb.AppendLine(AddTabs(4) + "foreach (var obj in collection)");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "DataRow dr = dt.NewRow();");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    sb.Append(AddTabs(5));
                    sb.Append(PadCSharpVariableName("dr[\"" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + "\"]", longest_column + 7));
                    sb.Append("= obj." + NameFormatter.ToCSharpPropertyName(sql_column.Name)  + ";" + Environment.NewLine);
                }

                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "dt.Rows.Add(dr);");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "return dt;");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                #region GetSqlParameterList Method
                ////////////////////////////////////////////////////////////////////////////////

                #region Code Sample
                //protected List<SqlParameter> GetSqlParameterList(cGame obj)
                //{
                //    List<SqlParameter> parameters = new List<SqlParameter>();
                //    SqlParameter parameter;

                //    parameter = new SqlParameter("@Id", SqlDbType.Int, 4);
                //    parameter.Value = obj.Id;
                //    parameters.Add(parameter);

                //    parameter = new SqlParameter("@Disabled", SqlDbType.Bit, 1);
                //    parameter.Value = obj.Disabled;
                //    parameters.Add(parameter);

                //    return parameters;
                //}
                #endregion

                sb.AppendLine(AddTabs(3) + "protected List<SqlParameter> GetSqlParameterList(" + NameFormatter.ToCSharpClassName(sql_table.Name) + " obj)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "List<SqlParameter> parameters = new List<SqlParameter>();");
                sb.AppendLine(AddTabs(4) + "SqlParameter parameter;");
                sb.AppendLine();

                // build parameter collection here
                foreach (var sql_column in sql_table.Columns.Values)
                {
                    // REFACTOR
                    //sb.AppendLine(AddTabs(4) + string.Format(SQL_PARAMETER_TEMPATE, "@SearchString", SqlDbType.VarChar, 50, "search_string"));

                    string column_name = NameFormatter.ToCSharpPropertyName(sql_column.Name);

                    sb.Append(AddTabs(4) + NameFormatter.ToCSharpSQLParameterString(sql_column));

                    if (sql_column.IsNullable && !convert_nullable_fields)
                    {
                        //parameter.Value = (obj.CancelledDate == null) ? (object)DBNull.Value : _CancelledDate;
                        sb.Append(Environment.NewLine + AddTabs(4) + "parameter.Value = (obj." + column_name + " == null) ? (object)DBNull.Value : obj." + column_name + ";");
                    }
                    else
                    {
                        sb.Append(Environment.NewLine + AddTabs(4) + "parameter.Value = obj." + column_name + ";");
                    }

                    sb.Append(Environment.NewLine + AddTabs(4) + "parameters.Add(parameter);" + Environment.NewLine);
                    sb.AppendLine();
                }

                sb.AppendLine(AddTabs(4) + "return parameters;");
                sb.AppendLine(AddTabs(3) + "}");

                ////////////////////////////////////////////////////////////////////////////////
                #endregion

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");

                sb.AppendLine(AddTabs(1) + "}");
                sb.AppendLine("}");

                output.Body = sb.ToString();

                return output;
        }
コード例 #27
0
        // WinForm Generation
        public static OutputObject GenerateWinformEditCode(SqlTable sql_table)
        {
            #region Sample Output
                //using System;
                //using System.Collections.Generic;
                //using System.ComponentModel;
                //using System.Data;
                //using System.Drawing;
                //using System.Linq;
                //using System.Text;
                //using System.Windows.Forms;

                //namespace MarvelSuperheroesEditor
                //{
                //    public partial class Form1 : Form
                //    {
                //        public Form1()
                //        {
                //            InitializeComponent();
                //        }
                //    }
                //}
                #endregion

                if (sql_table == null)
                    return null;

                string class_name   = "frmEdit" + NameFormatter.ToCSharpPropertyName(sql_table.Name);
                string dal_name     =   NameFormatter.ToCSharpClassName("Dal" + sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name = class_name + ".cs";
                output.Type = OutputObject.eObjectType.CSharp;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("using System;");
                sb.AppendLine("using System.Collections.Generic;");
                sb.AppendLine("using System.Configuration;");
                sb.AppendLine("using System.ComponentModel;");
                sb.AppendLine("using System.Data;");
                //sb.AppendLine("using System.Drawing;");
                //sb.AppendLine("using System.Linq;");
                //sb.AppendLine("using System.Text;");
                sb.AppendLine("using System.Windows.Forms;");
                sb.AppendLine();

                sb.AppendLine("using DAL;");
                sb.AppendLine("using " + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + ";");
                sb.AppendLine();

                sb.AppendLine("namespace " + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "Editor");
                sb.AppendLine("{");

                sb.AppendLine(AddTabs(1) + "public partial class " + class_name + " : Form");
                sb.AppendLine(AddTabs(1) + "{");

                #region Fields
                sb.AppendLine(AddTabs(2) + "#region Fields");
                sb.AppendLine();
                sb.AppendLine(AddTabs(3) + "protected string _SQLConnection = ConfigurationManager.ConnectionStrings[\"SQLConnection\"].ConnectionString;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                #endregion

                #region Methods
                sb.AppendLine(AddTabs(2) + "#region Methods");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "public " + class_name + "()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "InitializeComponent();");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "LoadPopulateItemList();");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "private bool LoadPopulateItemList()");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "this.Cursor = Cursors.WaitCursor;");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "try");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "" + dal_name + " dal = new " + dal_name + "(_SQLConnection);");
                sb.AppendLine();
                sb.AppendLine(AddTabs(5) + "if (dal.LoadAllFromDb())");
                sb.AppendLine(AddTabs(5) + "{");
                sb.AppendLine(AddTabs(6) + "if (dal.Collection != null && dal.Collection.Count != 0)");
                sb.AppendLine(AddTabs(6) + "{");
                sb.AppendLine(AddTabs(7) + "cboItemList.BeginUpdate();");
                sb.AppendLine(AddTabs(7) + "cboItemList.ValueMember     = \"" + FindIdField(sql_table) + "\";");
                sb.AppendLine(AddTabs(7) + "cboItemList.DisplayMember   = \"" + FindNameField(sql_table) + "\";");
                sb.AppendLine(AddTabs(7) + "cboItemList.DataSource      = dal.Collection;");
                sb.AppendLine(AddTabs(7) + "cboItemList.EndUpdate();");
                sb.AppendLine(AddTabs(6) + "}");
                sb.AppendLine(AddTabs(5) + "}");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine(AddTabs(4) + "catch");
                sb.AppendLine(AddTabs(4) + "{");
                sb.AppendLine(AddTabs(5) + "return false;");
                sb.AppendLine(AddTabs(4) + "}");
                sb.AppendLine();
                sb.AppendLine(AddTabs(4) + "this.Cursor = Cursors.Default;");
                sb.AppendLine(AddTabs(4) + "return true;");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                #endregion

                #region Events
                sb.AppendLine(AddTabs(2) + "#region Events");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "private void btnCancel_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine(AddTabs(3) + "private void btnSave_Click(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine(AddTabs(3) + "private void cboItemList_SelectedIndexChanged(object sender, EventArgs e)");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(3) + "}");

                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "#endregion");
                #endregion

                sb.AppendLine(AddTabs(1) + "}");
                sb.AppendLine("}");

                output.Body = sb.ToString();
                return output;
        }
コード例 #28
0
        public static OutputObject GenerateSelectManyByXProc(SqlTable sql_table, List<string> sort_fields, List<string> select_fields, bool generate_stored_proc_perms)
        {
            if (sql_table == null)
                    return null;

                string procedure_name   = GenerateSqlStoredProcName(sql_table.Name, eStoredProcType.SelectManyByX, select_fields);
                int longest_column      = GetLongestColumnLength(sql_table) + sql_table.Name.Length;
                bool flag_first_value;
                string name_buffer;

                OutputObject output = new OutputObject();
                output.Name = procedure_name + ".sql";
                output.Type = OutputObject.eObjectType.Sql;

                StringBuilder sb = new StringBuilder();

                sb.AppendLine(GenerateSqlExistanceChecker(procedure_name));
                sb.AppendLine(GenerateHeader(procedure_name));

                sb.AppendLine("CREATE PROCEDURE " + procedure_name);
                sb.AppendLine("(");
                sb.AppendLine(GenerateSelectClauseArguments(sql_table, select_fields));
                sb.AppendLine(")");
                sb.AppendLine("AS");
                sb.AppendLine();
                sb.AppendLine("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED");
                sb.AppendLine("SET NOCOUNT ON");
                sb.AppendLine();

                #region Selected Columns

                flag_first_value = true;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    if (flag_first_value)
                    {
                        sb.Append("SELECT" + AddTabs(1));
                        flag_first_value = false;
                    }
                    else
                    {
                        sb.Append("," + Environment.NewLine + AddTabs(2));
                    }

                    name_buffer = NameFormatter.ToTSQLName(sql_column.Table.Name) + "." + NameFormatter.ToTSQLName(sql_column.Name);
                    sb.Append(PadSqlVariableName(name_buffer, longest_column) + "AS " + NameFormatter.ToTSQLName(sql_column.Name));
                }
                #endregion

                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("FROM" + AddTabs(1) + NameFormatter.ToTSQLName(sql_table.Name));
                sb.AppendLine();

                sb.AppendLine("WHERE" + AddTabs(1) + PadSqlVariableName(NameFormatter.ToTSQLName(sql_table.Name) + ".[Disabled]", longest_column) + "= 0");
                sb.AppendLine(GenerateSelectClause(sql_table, select_fields));
                sb.AppendLine();
                sb.AppendLine(GenerateOrderByClause(sql_table, sort_fields));
                sb.AppendLine("GO");
                sb.AppendLine();

                if (generate_stored_proc_perms)
                {
                    sb.AppendLine(GenerateSqlStoredProcPerms(procedure_name));
                    sb.AppendLine();
                }

                output.Body = sb.ToString();
                return output;
        }
コード例 #29
0
        public bool LoadDatabaseMetadata(string database_name, string connection_string)
        {
            if (string.IsNullOrEmpty(database_name))
            {
                throw new ArgumentException("Database name is null or empty");
            }

            Reset();

            Name             = database_name;
            ConnectionString = connection_string;

            // load and parse out table data
            try
            {
                string sql_query = GetTableData();

                DataTable dt = Database.ExecuteQuery(sql_query, null, ConnectionString);

                if (dt != null && dt.Rows.Count != 0 && dt.Columns.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        string table_name  = (string)dr["TableName"];
                        string column_name = (string)dr["ColumnName"];

                        if (!Tables.ContainsKey(table_name))
                        {
                            SqlTable sql_table = new SqlTable(this, table_name);
                            Tables.Add(table_name, sql_table);
                        }

                        SqlColumn sql_column = new SqlColumn();

                        sql_column.Table         = Tables[table_name];
                        sql_column.Name          = (string)dr["ColumnName"];
                        sql_column.DataType      = (string)dr["DataType"];
                        sql_column.Length        = Convert.ToInt32(dr["Length"]);
                        sql_column.Precision     = Convert.ToInt32(dr["Precision"]);
                        sql_column.IsNullable    = Convert.ToBoolean(dr["IsNullable"]);
                        sql_column.IsPk          = Convert.ToBoolean(dr["IsPK"]);
                        sql_column.IsIdentity    = Convert.ToBoolean(dr["IsIdentity"]);
                        sql_column.ColumnOrdinal = Convert.ToInt32(dr["ColumnOrdinal"]);

                        if (Tables[table_name].Columns.ContainsKey(column_name))
                        {
                            throw new Exception($"Column {column_name} already exists in table {Tables[table_name]}");
                        }
                        else
                        {
                            Tables[table_name].Columns.Add(column_name, sql_column);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorList.Add(ex);
            }

            // get SP
            try
            {
                string sql_query = GetStoredProcedures();

                DataTable dt = Database.ExecuteQuery(sql_query, null, ConnectionString);

                if (dt != null && dt.Rows.Count != 0 && dt.Columns.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        SqlScript sql_script = new SqlScript();

                        sql_script.Name = (string)dr["Name"];
                        sql_script.Body = (string)dr["Body"];

                        if (StoredProcedures.ContainsKey(sql_script.Name))
                        {
                            StoredProcedures[sql_script.Name].Body += sql_script.Body;
                        }
                        else
                        {
                            StoredProcedures.Add(sql_script.Name, sql_script);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorList.Add(ex);
            }

            // get functions
            try
            {
                string sql_query = GetFunctions();

                DataTable dt = Database.ExecuteQuery(sql_query, null, ConnectionString);

                if (dt != null && dt.Rows.Count != 0 && dt.Columns.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        SqlScript sql_script = new SqlScript();

                        sql_script.Name = (string)dr["Name"];
                        sql_script.Body = (string)dr["Body"];

                        if (Functions.ContainsKey(sql_script.Name))
                        {
                            Functions[sql_script.Name].Body += sql_script.Body;
                        }
                        else
                        {
                            Functions.Add(sql_script.Name, sql_script);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorList.Add(ex);
            }

            // get constraints
            try
            {
                string sql_query = GetConstraints();

                DataTable dt = Database.ExecuteQuery(sql_query, null, ConnectionString);

                if (dt != null && dt.Rows.Count != 0 && dt.Columns.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        SqlConstraint sql_constraint = new SqlConstraint();

                        sql_constraint.ConstraintName = (string)dr["ConstraintName"];
                        sql_constraint.FKTable        = (string)dr["FKTable"];
                        sql_constraint.FKColumn       = (string)dr["FKColumn"];
                        sql_constraint.PKTable        = (string)dr["PKTable"];
                        sql_constraint.PKColumn       = (string)dr["PKColumn"];

                        if (Constraints.ContainsKey(sql_constraint.ConstraintName))
                        {
                            throw new Exception(string.Format("Constraint {0} already exists.", sql_constraint.ConstraintName));
                        }
                        else
                        {
                            Constraints.Add(sql_constraint.ConstraintName, sql_constraint);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorList.Add(ex);
            }

            // load default values
            try
            {
                string sql_query = GetDefaultValues();

                DataTable dt = Database.ExecuteQuery(sql_query, null, ConnectionString);

                if (dt != null && dt.Rows.Count != 0 && dt.Columns.Count != 0)
                {
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (Tables.ContainsKey((string)dr["TableName"]))
                        {
                            if (Tables[(string)dr["TableName"]].Columns.ContainsKey((string)dr["ColumnName"]))
                            {
                                Tables[(string)dr["TableName"]].Columns[(string)dr["ColumnName"]].DefaultValue = RemoveWrappingCharacters((string)dr["DefaultValue"]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorList.Add(ex);
            }

            return(ErrorList.Count == 0);
        }
コード例 #30
0
        public static OutputObject GenerateWinformEditCodeDesigner(SqlTable sql_table)
        {
            #region Code Output
                //namespace MarvelSuperheroesEditor
                //{
                //    partial class Form1
                //    {
                //        /// <summary>
                //        /// Required designer variable.
                //        /// </summary>
                //        private System.ComponentModel.IContainer components = null;

                //        /// <summary>
                //        /// Clean up any resources being used.
                //        /// </summary>
                //        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
                //        protected override void Dispose(bool disposing)
                //        {
                //            if (disposing && (components != null))
                //            {
                //                components.Dispose();
                //            }
                //            base.Dispose(disposing);
                //        }

                //        #region Windows Form Designer generated code

                //        /// <summary>
                //        /// Required method for Designer support - do not modify
                //        /// the contents of this method with the code editor.
                //        /// </summary>
                //        private void InitializeComponent()
                //        {
                //            this.btnSave = new System.Windows.Forms.Button();
                //            this.btnCancel = new System.Windows.Forms.Button();
                //            this.label1 = new System.Windows.Forms.Label();
                //            this.textBox1 = new System.Windows.Forms.TextBox();
                //            this.SuspendLayout();
                //            //
                //            // btnSave
                //            //
                //            this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                //            this.btnSave.Location = new System.Drawing.Point(232, 36);
                //            this.btnSave.Name = "btnSave";
                //            this.btnSave.Size = new System.Drawing.Size(75, 23);
                //            this.btnSave.TabIndex = 0;
                //            this.btnSave.Text = "Save";
                //            this.btnSave.UseVisualStyleBackColor = true;
                //            //
                //            // btnCancel
                //            //
                //            this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
                //            this.btnCancel.Location = new System.Drawing.Point(151, 36);
                //            this.btnCancel.Name = "btnCancel";
                //            this.btnCancel.Size = new System.Drawing.Size(75, 23);
                //            this.btnCancel.TabIndex = 1;
                //            this.btnCancel.Text = "Cancel";
                //            this.btnCancel.UseVisualStyleBackColor = true;
                //            //
                //            // label1
                //            //
                //            this.label1.AutoSize = true;
                //            this.label1.Location = new System.Drawing.Point(12, 9);
                //            this.label1.Name = "label1";
                //            this.label1.Size = new System.Drawing.Size(35, 13);
                //            this.label1.TabIndex = 2;
                //            this.label1.Text = "label1";
                //            //
                //            // textBox1
                //            //
                //            this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                //            | System.Windows.Forms.AnchorStyles.Right)));
                //            this.textBox1.Location = new System.Drawing.Point(118, 6);
                //            this.textBox1.Name = "textBox1";
                //            this.textBox1.Size = new System.Drawing.Size(189, 20);
                //            this.textBox1.TabIndex = 3;
                //            //
                //            // Form1
                //            //
                //            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                //            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                //            this.ClientSize = new System.Drawing.Size(319, 71);
                //            this.Controls.Add(this.textBox1);
                //            this.Controls.Add(this.label1);
                //            this.Controls.Add(this.btnCancel);
                //            this.Controls.Add(this.btnSave);
                //            this.Name = "Form1";
                //            this.Text = "Form1";
                //            this.ResumeLayout(false);
                //            this.PerformLayout();
                //        }

                //        #endregion

                //        private System.Windows.Forms.Button btnSave;
                //        private System.Windows.Forms.Button btnCancel;
                //        private System.Windows.Forms.Label label1;
                //        private System.Windows.Forms.TextBox textBox1;
                //    }
                //}
                #endregion

                if (sql_table == null)
                    return null;

                string class_name = "frmEdit" + NameFormatter.ToCSharpPropertyName(sql_table.Name);

                OutputObject output = new OutputObject();
                output.Name = class_name + ".Designer.cs";
                output.Type = OutputObject.eObjectType.CSharp;

                int total_form_height = 56 + (26 * sql_table.Columns.Values.Count);

                StringBuilder sb = new StringBuilder();

                sb.AppendLine("namespace " + NameFormatter.ToCSharpPropertyName(sql_table.Database.Name) + "Editor");
                sb.AppendLine("{");
                sb.AppendLine(AddTabs(1) + "partial class " + class_name);
                sb.AppendLine(AddTabs(1) + "{");
                sb.AppendLine(AddTabs(2) + "/// <summary>");
                sb.AppendLine(AddTabs(2) + "/// Required designer variable.");
                sb.AppendLine(AddTabs(2) + "/// </summary>");
                sb.AppendLine(AddTabs(2) + "private System.ComponentModel.IContainer components = null;");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "/// <summary>");
                sb.AppendLine(AddTabs(2) + "/// Clean up any resources being used.");
                sb.AppendLine(AddTabs(2) + "/// </summary>");
                sb.AppendLine(AddTabs(2) + "/// <param name=\"disposing\">true if managed resources should be disposed; otherwise, false.</param>");
                sb.AppendLine(AddTabs(2) + "protected override void Dispose(bool disposing)");
                sb.AppendLine(AddTabs(2) + "{");
                sb.AppendLine(AddTabs(3) + "if (disposing && (components != null))");
                sb.AppendLine(AddTabs(3) + "{");
                sb.AppendLine(AddTabs(4) + "components.Dispose();");
                sb.AppendLine(AddTabs(3) + "}");
                sb.AppendLine(AddTabs(3) + " base.Dispose(disposing);");
                sb.AppendLine(AddTabs(2) + "}");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "#region Windows Form Designer generated code");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "/// <summary>");
                sb.AppendLine(AddTabs(2) + "/// Required method for Designer support - do not modify");
                sb.AppendLine(AddTabs(2) + "/// the contents of this method with the code editor.");
                sb.AppendLine(AddTabs(2) + "/// </summary>");
                sb.AppendLine(AddTabs(2) + "private void InitializeComponent()");
                sb.AppendLine(AddTabs(2) + "{");
                sb.AppendLine(AddTabs(3) + "this.btnSave = new System.Windows.Forms.Button();");
                sb.AppendLine(AddTabs(3) + "this.btnCancel = new System.Windows.Forms.Button();");
                sb.AppendLine(AddTabs(3) + "this.cboItemList = new System.Windows.Forms.ComboBox();");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    sb.AppendLine(AddTabs(3) + "this.lbl" + sql_column.Name + " = new System.Windows.Forms.Label();");
                    sb.AppendLine(AddTabs(3) + "this.txt" + sql_column.Name + " = new System.Windows.Forms.TextBox();");
                    sb.AppendLine();
                }

                sb.AppendLine(AddTabs(3) + "this.SuspendLayout();");
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "// btnSave");
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "this.btnSave.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));");
                sb.AppendLine(AddTabs(3) + "this.btnSave.Location = new System.Drawing.Point(232," + (total_form_height-26).ToString() + ");");
                sb.AppendLine(AddTabs(3) + "this.btnSave.Name = \"btnSave\";");
                sb.AppendLine(AddTabs(3) + "this.btnSave.Size = new System.Drawing.Size(75, 23);");
                sb.AppendLine(AddTabs(3) + "this.btnSave.TabIndex = 0;");
                sb.AppendLine(AddTabs(3) + "this.btnSave.Text = \"Save\";");
                sb.AppendLine(AddTabs(3) + "this.btnSave.UseVisualStyleBackColor = true;");
                sb.AppendLine(AddTabs(3) + "this.btnSave.Click += new System.EventHandler(this.btnSave_Click);");
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "// btnCancel");
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.Location = new System.Drawing.Point(151," + (total_form_height-26).ToString() + ");");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.Name = \"btnCancel\";");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.Size = new System.Drawing.Size(75, 23);");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.TabIndex = 1;");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.Text = \"Cancel\";");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.UseVisualStyleBackColor = true;");
                sb.AppendLine(AddTabs(3) + "this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);");
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "// cboItemList");
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.FormattingEnabled = true;");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.Location = new System.Drawing.Point(12, 5);");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.Name = \"cboItemList\";");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.Size = new System.Drawing.Size(295, 21);");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.TabIndex = 2;");
                sb.AppendLine(AddTabs(3) + "this.cboItemList.SelectedIndexChanged += new System.EventHandler(this.cboItemList_SelectedIndexChanged);");

                int height = 26;
                int tab_index = 3;

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    string label_name       = "lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name);
                    string textbox_name     = "txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name);

                    sb.AppendLine(AddTabs(3) + "//");
                    sb.AppendLine(AddTabs(3) + "// " + label_name);
                    sb.AppendLine(AddTabs(3) + "//");
                    sb.AppendLine(AddTabs(3) + "this." + label_name + ".AutoSize = true;");
                    sb.AppendLine(AddTabs(3) + "this." + label_name + ".Location = new System.Drawing.Point(12," + (height + 9).ToString() + ");");
                    sb.AppendLine(AddTabs(3) + "this." + label_name + ".Name = \"" + label_name + "\";");
                    sb.AppendLine(AddTabs(3) + "this." + label_name + ".Size = new System.Drawing.Size(35, 13);");
                    sb.AppendLine(AddTabs(3) + "this." + label_name + ".TabIndex = " + tab_index.ToString() + ";");
                    sb.AppendLine(AddTabs(3) + "this." + label_name + ".Text = \"" + NameFormatter.ToFriendlyName(sql_column.Name) + "\";");

                    tab_index++;

                    sb.AppendLine(AddTabs(3) + "//");
                    sb.AppendLine(AddTabs(3) + "// " + textbox_name);
                    sb.AppendLine(AddTabs(3) + "//");
                    sb.AppendLine(AddTabs(3) + "this." + textbox_name + ".Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));");
                    sb.AppendLine(AddTabs(3) + "this." + textbox_name + ".Location = new System.Drawing.Point(118," + (height + 6).ToString() + ");");
                    sb.AppendLine(AddTabs(3) + "this." + textbox_name + ".Name = \"" + textbox_name + "\";");
                    sb.AppendLine(AddTabs(3) + "this." + textbox_name + ".Size = new System.Drawing.Size(189, 20);");
                    sb.AppendLine(AddTabs(3) + "this." + textbox_name + ".TabIndex = " + tab_index.ToString() + ";");
                    //sb.AppendLine(AddTabs(3) + "this." + textbox_name + ".MaxLength = " + sql_column.Length + ";");

                    tab_index++;
                    height += 26;
                }

                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "// " + class_name);
                sb.AppendLine(AddTabs(3) + "//");
                sb.AppendLine(AddTabs(3) + "this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);");
                sb.AppendLine(AddTabs(3) + "this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;");
                sb.AppendLine(AddTabs(3) + "this.ClientSize = new System.Drawing.Size(319," + total_form_height.ToString() + ");");

                sb.AppendLine(AddTabs(3) + "this.Controls.Add(this.btnCancel);");
                sb.AppendLine(AddTabs(3) + "this.Controls.Add(this.btnSave);");
                sb.AppendLine(AddTabs(3) + "this.Controls.Add(this.cboItemList);");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    sb.AppendLine(AddTabs(3) + "this.Controls.Add(this.txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ");");
                    sb.AppendLine(AddTabs(3) + "this.Controls.Add(this.lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ");");
                    sb.AppendLine();
                }

                sb.AppendLine(AddTabs(3) + "this.MinimumSize = new System.Drawing.Size(319," + total_form_height.ToString() + ");");
                sb.AppendLine(AddTabs(3) + "this.Name = \"" + class_name + "\";");
                sb.AppendLine(AddTabs(3) + "this.Text = \"" +  NameFormatter.ToCSharpPropertyName(sql_table.Name) + "\";");
                sb.AppendLine();

                sb.AppendLine(AddTabs(3) + "this.ResumeLayout(false);");
                sb.AppendLine(AddTabs(3) + "this.PerformLayout();");

                sb.AppendLine(AddTabs(2) + "}");
                sb.AppendLine();

                sb.AppendLine(AddTabs(2) + "#endregion");
                sb.AppendLine();
                sb.AppendLine(AddTabs(2) + "private System.Windows.Forms.Button btnSave;");
                sb.AppendLine(AddTabs(2) + "private System.Windows.Forms.Button btnCancel;");
                sb.AppendLine(AddTabs(2) + "private System.Windows.Forms.ComboBox cboItemList;");
                sb.AppendLine();

                foreach (var sql_column in sql_table.Columns.Values)
                {
                    sb.AppendLine(AddTabs(2) + "private System.Windows.Forms.Label lbl" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ";");
                    sb.AppendLine(AddTabs(2) + "private System.Windows.Forms.TextBox txt" + NameFormatter.ToCSharpPropertyName(sql_column.Name) + ";");
                    sb.AppendLine();
                }

                sb.AppendLine(AddTabs(2) + "}");
                sb.AppendLine(AddTabs(1) + "}");

                output.Body = sb.ToString();
                return output;
        }
コード例 #31
0
 public SqlColumn(SqlTable sql_table, string column_name) : this(sql_table, column_name, string.Empty, 0, 0, 0, false, false, false, 0, string.Empty)
 {
 }
コード例 #32
0
 public static OutputObject GenerateWinformMainCode(SqlTable sql_table)
 {
     return null;
 }