private void GetCode(string tableName) { string getfiled = sqltype == 2 ? "select * from `" + tableName + "` LIMIT 0" : "select top 0 * from [" + tableName + "]"; DataTable dt = ExecuteDataTable(getfiled); CreateCodeHelper helper = new CreateCodeHelper(); string strDAL = cbDAL.SelectedItem.ToString(); StringBuilder sb = new StringBuilder(); switch (strDAL) { case "All DAL": { dalstr = helper.CreateDALCode(tableName, dt); break; } case "ListAll()": { helper.CreateListAll(tableName, dt, sb, ""); dalstr = sb; break; } case "DeleteById()": { helper.CreateDeleteById(tableName, dt, sb, ""); dalstr = sb; break; } case "GetById()": { helper.CreateGetById(tableName, dt, sb, ""); dalstr = sb; break; } case "Insert()": { helper.CreateInsert(tableName, dt, sb, ""); dalstr = sb; break; } case "Update()": { helper.CreateUpdate(tableName, dt, sb, ""); dalstr = sb; break; } case "ListByWhere()": { helper.CreateListByWhere(tableName, sb, ""); dalstr = sb; break; } case "ListByPage()": { helper.CreateListByPage(tableName, dt, sb, ""); dalstr = sb; break; } default: { dalstr = sb; break; } } }
private void CreateIDAL(String tbName) { CreateCodeHelper d = new CreateCodeHelper(); CreateIDAL(tbName, d); }
private void CreateIDAL(String tbName, CreateCodeHelper d) { var s = ""; if (string.IsNullOrEmpty(realyNamespqce)) { s = d.CreateIDAL(tbName); } else { s = d.CreateIDAL(tbName, realyNamespqce); } var p = settings.strPath + "IDAL" + Path.DirectorySeparatorChar; CreateDirectory(p); File.WriteAllText(p + "I" + tbName + "DAL.cs", s, Encoding.UTF8); }
/// <summary> /// 生成代码 /// </summary> /// <param name="tableName"></param> private void CreateCode(string tableName) { if (tableName == null) { tbDAL.Text = tbModel.Text = "请选择要生成的表"; return; } else { string getfiled = sqltype == 2 ? "select * from `" + tableName + "` LIMIT 0" : "select top 0 * from [" + tableName + "]"; DataTable dt = ExecuteDataTable(getfiled); CreateCodeHelper helper = new CreateCodeHelper(); string strDAL = ""; this.Dispatcher.Invoke(delegate { strDAL = cbDAL.SelectedItem.ToString(); }); StringBuilder sb = new StringBuilder(); if (!tbNamespace.Text.Equals("命名空间") && tbNamespace.Text.Trim().Length > 0) { modelstr = helper.CreateModelCode(tableName, dt, tbNamespace.Text); if (strDAL.Equals("All DAL")) { realyNamespqce = tbNamespace.Text + "."; dalstr = helper.CreateDALCode(tableName, dt, tbNamespace.Text); tbDAL.Text = dalstr.ToString(); } else { realyNamespqce = ""; GetCode(tableName); } } else { modelstr = helper.CreateModelCode(tableName, dt); realyNamespqce = ""; GetCode(tableName); } tbDAL.Text = dalstr.ToString(); tbModel.Text = modelstr.ToString(); } btnExport.IsEnabled = true; btnGenerateCode.IsDefault = false; }