Пример #1
0
        private void GenerateViewCode()
        {
            if (treeView1.SelectedNode == null)
            {
                return;
            }

            if (treeView1.SelectedNode.ImageIndex != ICON_View)
            {
                return;
            }

            string database = treeView1.SelectedNode.Parent.Parent.Text;
            string viewName = treeView1.SelectedNode.Text;

            TryToDo(() => {
                string query        = string.Format("select top 1  * from [{0}] where 1>2", viewName);
                List <Field> fields = SqlServerHelper.GetFieldsFromQuery(_connectionString, database, query);

                if (this.ucCsClassStyle1.CodeStyle.SortByName)
                {
                    fields = fields.OrderBy(x => x.Name).ToList();
                }

                ShowCode(Generator.GenerateCode(
                             viewName.TrimPunctuation(),
                             fields,
                             this.ucCsClassStyle1.CodeStyle
                             ), "cs");
                txtSqlScript.Text = SqlServerHelper.GetViewCode(_connectionString, database, viewName);
            });
        }
Пример #2
0
        private void btnGenerate_Click(object sender, EventArgs e)
        {
            if (txtSql.Text.Trim().Length == 0)
            {
                return;
            }

            try {
                string       query  = txtSql.Text.Trim();
                List <Field> fields = SqlServerHelper.GetFieldsFromQuery(_connectionString, _database, query);
                txtCsCode.Text = Generator.GenerateCode(
                    "YourModelClassName",
                    fields,
                    this.ucCsClassStyle1.CodeStyle
                    );
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
            }
        }