Example #1
0
        private void AutoTestExecute()
        {
            try
            {
                int lowMinSeconds  = 300;
                int longMinSeconds = 1000;
                this.tabControl1.TabIndex = 0;
                Thread.Sleep(lowMinSeconds);
                this.txtServer.Text = PageCache.server;
                this.txtName.Text   = PageCache.name;
                this.txtPwd.Text    = PageCache.pwd;
                this.txtPort.Text   = PageCache.port.ToString();
                Thread.Sleep(lowMinSeconds);
                this.btnConnect_Click(this.btnConnect, new EventArgs());
                Thread.Sleep(lowMinSeconds);
                foreach (ListViewItem item in this.lstDBs.Items)
                {
                    if (item.Text == PageCache.DatabaseName)
                    {
                        item.Selected = true;
                        break;
                    }
                }

                Thread.Sleep(longMinSeconds);
                foreach (ListViewItem item in this.lstTables.Items)
                {
                    if (item.Text == PageCache.TableName)
                    {
                        item.Selected = true;
                        break;
                    }
                }

                Thread.Sleep(longMinSeconds);
                this.btnNext_Click(this.btnNext, new EventArgs());
                Thread.Sleep(lowMinSeconds);

                this.lstExtendAttribute.Items.Clear();
                foreach (var extendInfo in PageCache.GetExtendList())
                {
                    ListViewItem item = new ListViewItem(extendInfo.NewAttName);
                    item.Tag = extendInfo;
                    item.SubItems.AddRange(new string[] { extendInfo.Comment, extendInfo.AttributeType });
                    this.lstExtendAttribute.Items.Add(item);
                }

                Thread.Sleep(lowMinSeconds);
                this.lstCmdList.Items.Clear();
                foreach (var info in PageCache.GetCmdList())
                {
                    ListViewItem cmdItem = new ListViewItem(info.CmdName);
                    cmdItem.SubItems.AddRange(new string[] { string.Join(",", (from f in info.AttrList select f.AttrName).ToArray()) });
                    cmdItem.Tag = Guid.NewGuid().ToString("N");
                    this.lstCmdList.Items.Add(cmdItem);
                }

                Thread.Sleep(lowMinSeconds);
                this.btnNext_Click(this.btnNext, new EventArgs());

                rbtn_Sql.Checked        = PageCache.DbTool == 0;
                rbtn_ORM_Dapper.Checked = PageCache.DbTool == 1;
                rbtn_NHibernate.Checked = PageCache.DbTool == 2;
                rbtn_EF.Checked         = PageCache.DbTool == 3;

                rbtnEasyUI.Checked    = PageCache.UIType == 0;
                rbtnBootstrap.Checked = PageCache.UIType == 1;
                rbtn_Layui.Checked    = PageCache.UIType == 2;

                rbtn_web_asp_net.Checked = PageCache.WebType == 0;
                rbtn_web_mvc.Checked     = PageCache.WebType == 1;
                rbtn_web_html.Checked    = PageCache.WebType == 2;

                this.txtNameSpace.Text   = PageCache.NameSpaceStr;
                this.txtModelSuffix.Text = PageCache.ModelSuffix;
                this.txtDalSuffix.Text   = PageCache.DALSuffix;
                this.txtUISuffix.Text    = PageCache.UISuffix;

                MessageBox.Show("导入成功.");
            }
            finally
            {
                isImport = false;
            }
        }
        public static string CreateModel()
        {
            StringBuilder content = new StringBuilder();

            content.AppendLine("using System;");
            content.AppendLine("using System.Collections.Generic;");
            content.AppendLine("using System.ComponentModel;");
            content.AppendLine("using System.Text;");
            content.AppendLine("namespace " + (string.IsNullOrEmpty(PageCache.NameSpaceStr) ? "命名空间" : PageCache.NameSpaceStr));
            content.AppendLine("{");
            if (!string.IsNullOrEmpty(PageCache.TableName))
            {
                content.Append(CommentTool.CreateComment(PageCache.TableName, 1));
            }

            content.AppendFormat("\tpublic class {0}\r\n", PageCache.TableName_Model);
            content.AppendLine("\t{");

            var colList = PageCache.GetColumnList();

            for (int i = 0; i < colList.Count; i++)
            {
                var item = colList[i];
                content.AppendLine();
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\t[DefaultValue(typeof({0}), \"{1}\")]\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     SqlTool.GetDefaultValueAttributeStr(item.DbType));
                content.AppendFormat("\t\tpublic {0} {1}\r\n",
                                     SqlTool.GetFormatString(item.DbType),
                                     item.Name);
                content.AppendLine("\t\t{");
                content.AppendLine("\t\t\tget { return this._" + item.Name + "; }");
                content.AppendLine("\t\t\tset { this._" + item.Name + " = value; }");
                content.AppendLine("\t\t}\r\n");
            }

            var extendList = PageCache.GetExtendList();

            for (int i = 0; i < extendList.Count; i++)
            {
                var item = extendList[i];
                if (!string.IsNullOrEmpty(item.Comment))
                {
                    content.Append(CommentTool.CreateComment(item.Comment, 2));
                }

                content.AppendFormat("\t\tpublic {0} {1}\r\n",
                                     item.AttributeType,
                                     item.NewAttName);
                content.AppendLine("\t\t{");
                content.AppendLine("\t\t\tget");
                content.AppendLine("\t\t\t{");
                if (item.FormatType == 0)
                {
                    string formatStr = item.FormatStr.Replace("{c1}", item.DependColumn);
                    content.AppendLine("\t\t\treturn " + formatStr + ";");
                }
                else if (item.FormatType == 1)
                {
                    content.AppendLine("\t\t\t\treturn " + item.DependColumn.ToString() + ".ToString(\"" + item.FormatStr + "\");");
                }
                else if (item.FormatType == 2)
                {
                    string   formatStr = item.FormatStr;
                    string[] lineArray = item.FormatStr.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    content.AppendLine("\t\t\t\tswitch (" + item.DependColumn + ")");
                    content.AppendLine("\t\t\t\t{");
                    foreach (var line in lineArray)
                    {
                        var lineItemArray = line.Split(new string[] { "---" }, StringSplitOptions.None);
                        if (lineItemArray[0] != StaticVariable.Switch_Default_Key)
                        {
                            content.AppendLine("\t\t\t\t\tcase " + lineItemArray[0] + ":");
                            content.AppendLine("\t\t\t\t\t\treturn \"" + lineItemArray[1] + "\";");
                        }
                    }

                    foreach (var line in lineArray)
                    {
                        var lineItemArray = line.Split(new string[] { "---" }, StringSplitOptions.None);
                        if (lineItemArray[0] == StaticVariable.Switch_Default_Key)
                        {
                            content.AppendLine("\t\t\t\t\tdefault:");
                            content.AppendLine("\t\t\t\t\t\treturn \"" + lineItemArray[1] + "\";");
                        }
                    }



                    content.AppendLine("\t\t\t\t}");
                }

                content.AppendLine("\t\t\t}");

                if (extendList.Count == i - 1)
                {
                    content.AppendLine("\t\t}");
                }
                else
                {
                    content.AppendLine("\t\t}\r\n");
                }
            }

            content.AppendLine("\t}");
            content.AppendLine("}");

            return(content.ToString());
        }