private bool CreateCode(string savePath) { string listTable = string.Empty; string str2 = string.Empty; this.DataAccessList = new List <string>(); this.FacadeList = new List <string>(); this.MyClassList = new List <string>(); tempList = new List <string>(); this.GetTempList(this.TemplateTreeView.Nodes); foreach (var item in lboxTable2.Items) { TableSchema table = this.tables.FirstOrDefault(s => s.Name == item.ToString()); ViewSchema view = this.views.FirstOrDefault(s => s.Name == item.ToString()); foreach (string tempPath in this.tempList) { try { CodeFile file = null; if (table != null) { file = TemplateFactory.BuilderCodes(tempPath, table); } else { file = TemplateFactory.BuilderCodes(tempPath, view); } this.GernalFile(file.Codes, string.Format(@"{0}\{1}", savePath, file.FileName)); this.DataAccessList.Add(file.FileName + "#" + file.Codes); continue; } catch (Exception exception) { if (exception.Message.IndexOf("未设置主键") > 0) { listTable = listTable + "|" + str2; base.DialogResult = base.Alert(exception.Message + ",是否终止生成!", "生成失败", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (base.DialogResult == DialogResult.Yes) { base.Alert("取消成功", "生成失败!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(false); } this.lboxTable.Items.Add(item); } else { base.Alert(exception.Message, "生成失败!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } break; } } } if (!string.IsNullOrEmpty(listTable.Trim())) { this.DelItem(listTable); } base.Alert("生成完成!", "生成完成", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); return(true); }