/// <summary> /// 生成 /// </summary> private void btnGen_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtNamespace.Text) || string.IsNullOrWhiteSpace(txtNamespace.Text)) { return; } if (string.IsNullOrEmpty(txtWebProjNameSpace.Text) || string.IsNullOrWhiteSpace(txtWebProjNameSpace.Text)) { return; } string tbName = cbTables.Text.Trim(); if (string.IsNullOrEmpty(tbName)) { return; } if (string.IsNullOrEmpty(txtModalName.Text) || string.IsNullOrWhiteSpace(txtModalName.Text)) { return; } bool hasTable = false; foreach (var item in this.Database.Tables) { if (item.Name == tbName) { SelectedTable = item; hasTable = true; break; } } if (!hasTable) { return; } txtModalName.Enabled = false; txtNamespace.Enabled = false; txtWebProjNameSpace.Enabled = false; cbTables.Enabled = false; btnGen.Enabled = false; btnGen.Text = "正在生成..."; btnView.Hide(); //lblTable.DataBindings.Remove(_tableNameBinding); //firstFileTreeNode = null; tableName = cbTables.Text.Trim(); nsString = txtNamespace.Text.Trim(); webNSString = txtWebProjNameSpace.Text.Trim(); modalName = txtModalName.Text.Trim(); AspnetMVCSetting setting = new AspnetMVCSetting(); setting.Namespace = nsString; setting.WebProjNameSpace = webNSString; SettingStore.Instance.Save<AspnetMVCSetting>(setting, this.Database.Name + "_aspnetmvc.xml"); BackgroundWorker _bgWorker = new BackgroundWorker(); _bgWorker.WorkerSupportsCancellation = false; _bgWorker.WorkerReportsProgress = false; _bgWorker.DoWork += _bgWorker_DoWork; _bgWorker.RunWorkerCompleted += _bgWorker_RunWorkerCompleted; _bgWorker.RunWorkerAsync(); }
private void btnGen_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtParentObjectName.Text) || string.IsNullOrWhiteSpace(txtParentObjectName.Text)) { return; } if (string.IsNullOrEmpty(txtNamespace.Text) || string.IsNullOrWhiteSpace(txtNamespace.Text)) { return; } if (string.IsNullOrEmpty(txtWebProjNameSpace.Text) || string.IsNullOrWhiteSpace(txtWebProjNameSpace.Text)) { return; } bool hasForeignKey = false; string foreignKey = cbForeignKey.Text.Trim(); if (string.IsNullOrEmpty(foreignKey)) { return; } foreach (var item in SelectedChildTable.Columns) { if (item.PascalName == foreignKey) { hasForeignKey = true; break; } } if (!hasForeignKey) { return; } bool hasChildTable = false; string tbChildName = cbTablesForChild.Text.Trim(); if (string.IsNullOrEmpty(tbChildName)) { return; } foreach (var item in Database.Tables) { if (item.Name == tbChildName) { SelectedChildTable = item; hasChildTable = true; break; } } if (!hasChildTable) { return; } bool hasParentTable = false; string tbParentName = cbTablesForParent.Text.Trim(); if (string.IsNullOrEmpty(tbParentName)) { return; } foreach (var item in Database.Tables) { if (item.Name == tbParentName) { SelectedParentTable = item; hasParentTable = true; break; } } if (!hasParentTable) { return; } string childCollectionName = txtChildName.Text.Trim(); if (string.IsNullOrEmpty(childCollectionName)) { return; } if(tbParentName == tbChildName) { MessageBox.Show("父对象和子对象不能是同一个表", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } txtChildName.Enabled = false; txtNamespace.Enabled = false; txtWebProjNameSpace.Enabled = false; cbTablesForChild.Enabled = false; cbTablesForParent.Enabled = false; gvFields.Enabled = false; btnGen.Enabled = false; btnGen.Text = "正在生成..."; btnView.Hide(); //设置SimpleChildGenModel GenModel.ParentObjectName = txtParentObjectName.Text.Trim(); GenModel.ForeignKey = foreignKey; GenModel.NameSpacePR = txtNamespace.Text.Trim(); GenModel.WebProjNameSpace = txtWebProjNameSpace.Text.Trim(); GenModel.ChildCollectionName = childCollectionName; GenModel.ChildModel = this.SelectedChildTable; GenModel.ParentModel = this.SelectedParentTable; GenModel.Items.Clear(); foreach (DataGridViewRow item in gvFields.Rows) { InputItem inp = new InputItem(); string rawName = item.Cells[0].Value.ToString(); inp.Title = item.Cells[3].Value.ToString(); inp.PascalName = StringHelper.SetPascalCase(rawName); inp.CamelName = StringHelper.SetCamelCase(rawName); inp.InputType = item.Cells[4].Value.ToString(); GenModel.Items.Add(inp); } AspnetMVCSetting setting = new AspnetMVCSetting(); setting.Namespace = GenModel.NameSpacePR; setting.WebProjNameSpace = GenModel.WebProjNameSpace; SettingStore.Instance.Save<AspnetMVCSetting>(setting, this.Database.Name + "_aspnetmvc.xml"); BackgroundWorker _bgWorker = new BackgroundWorker(); _bgWorker.WorkerSupportsCancellation = false; _bgWorker.WorkerReportsProgress = false; _bgWorker.DoWork += _bgWorker_DoWork; _bgWorker.RunWorkerCompleted += _bgWorker_RunWorkerCompleted; _bgWorker.RunWorkerAsync(); }