private void btnSubmit_Click(object sender, EventArgs e) { IEnumerable <DBTableInfo> lst = gvTables.DataSource as IEnumerable <DBTableInfo>; if (lst == null) { return; } List <string> selection = new List <string>(); foreach (DBTableInfo info in lst) { if (info.IsGenerate) { selection.Add(info.Name); } } DBInfo db = DbInfo.CreateDBInfo(); using (BatchAction ba = db.DefaultOperate.StarBatchAction()) { using (FrmProcess frmPro = FrmProcess.ShowProcess()) { string file = DesignerInfo.SelectDocView.DocData.FileName; XmlDocument doc = DBEntityInfo.GetClassDiagram(file); frmPro.UpdateProgress(0, 10, "正在读取类信息"); List <DBTableInfo> lstGen = TableChecker.GetTableInfo(db, selection); string entityNamespace = DesignerInfo.GetNameSpace(); for (int i = 0; i < lstGen.Count; i++) { frmPro.UpdateProgress(i, lstGen.Count, "正在生成"); string baseType = cmbBaseType.Text; if (string.IsNullOrEmpty(baseType)) { baseType = GetDefaultBaseType(); } DBEntityInfo info = new DBEntityInfo(entityNamespace, lstGen[i], DesignerInfo, DbInfo, baseType); info.GreanCode(doc); } //拷贝备份 File.Copy(file, file + ".bak", true); EntityMappingConfig.SaveXML(file, doc); } } this.Close(); }
/// <summary> /// 生成数据层 /// </summary> private void GreanDataAccess() { ClassDesignerInfo cinfo = GetDesignerInfo(); List <ClrClass> lstClass = Connect.GetAllClass(cinfo.SelectedDiagram); using (FrmProcess frmLoading = FrmProcess.ShowProcess()) { frmLoading.UpdateProgress(0, 0, "正在生成类"); for (int i = 0; i < lstClass.Count; i++) { ClrClass cls = lstClass[i]; EntityConfig entity = new EntityConfig(cls, cinfo); Generate3Tier g3t = new Generate3Tier(entity); if (!string.IsNullOrEmpty(entity.TableName)) { g3t.GenerateIDataAccess(); g3t.GenerateDataAccess(); g3t.GenerateBQLDataAccess(); } frmLoading.UpdateProgress(i + 1, lstClass.Count, "正在生成"); } } }