/// <summary> /// '表和视图列表框'的选择改变事件. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void clbTablesAndView_SelectedIndexChanged(object sender, EventArgs e) { string name = this.clbTablesAndView .Items[this.clbTablesAndView.SelectedIndex].ToString(); string tabName = this.GetTableOrViewName(name); if (name.StartsWith("@")) { this.lblTabStructure.Text = "视图" + tabName + "相关实体类结构:"; } else { this.lblTabStructure.Text = "表" + tabName + "相关实体类结构:"; } if (!this._clasInfo.Contains(tabName)) { DataTable tabStructure = null; ConnectOracle.OpenConnection(); tabStructure = ConnectOracle.ConvertTableOrViewStructure (ConnectOracle.GetTableOrViewStructure(tabName)); ConnectOracle.CloseConnection(); this._clasInfo.Add(tabName, tabStructure); DataTable tabNameDt = ConnectOracle.GetDataTable(String.Format(@"select COMMENTS from user_tab_comments WHERE TABLE_NAME = '{0}'", tabName)); if (tabNameDt.Rows.Count > 0) { this._clasRemarkInfo.Add(tabName, tabNameDt.Rows[0]["COMMENTS"].ToString()); } else { this._clasRemarkInfo.Add(tabName, ""); } } DataTable data = (DataTable)this._clasInfo[tabName]; this.dgvTableOrViewStructure.DataSource = data; //决定是否保存类注释. if (this._saveClassRemark) { this._clasRemarkInfo[this._tabName] = this.txtTabControlOneClassRemark.Text; this._saveClassRemark = false; } //决定是否保存字段注释. if (this._saveFieldRemark) { DataTable data2 = (DataTable)this._clasInfo[this._tabName2]; data2.Rows[this._index][2] = this.txtTabControlOneFieldInfo.Text; this._saveFieldRemark = false; } this.txtTabControlOneClassRemark.Text = this._clasRemarkInfo[tabName].ToString(); int index = this.dgvTableOrViewStructure.CurrentRow.Index; if (data.Rows.Count > 0) { this.txtTabControlOneFieldInfo.Text = data.Rows[index][2].ToString(); } //更改类注释标签文本. string className = GeneratorTool.CapFirstLetter(tabName) + ToolSetting.Postfix; this.lblClassRemark.Text = className + "类注释:"; }
/// <summary> /// Oracle'连接数据库'按钮的事件处理. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOracleConnectDb_Click(object sender, EventArgs e) { string server = this.txtOracleServer.Text.Trim(); string uid = this.txtOracleUserID.Text.Trim(); string pwd = this.txtOraclePwd.Text.Trim(); //ToolSetting.Language = ".Net"; //ToolSetting.Postfix = this.txtDotNetPostfix.Text.Trim(); //ToolSetting.TabSize = Convert.ToInt32(this.txtTabSize.Text.Trim()); //ToolSetting.SavePath = this.txtSavePath.Text.Trim(); //ToolSetting.References = ToolSetting.FormatStringArray( // Regex.Split(this.rtbReferencesList.Text.Trim(), "\n+", RegexOptions.None)); //ToolSetting.OracleDataMapping = (DataTable)this.dgvOracleMapping.DataSource; ToolSetting.ServiceName = server; ToolSetting.UserName = uid; ToolSetting.UserPassWord = pwd; /* * 保存用户设置信息 * ***/ ToolSetting.SaveUserSetting(); //得到数据库参数. //相关验证. if (server.Equals("") || uid.Equals("")) { MessageBox.Show("服务名和用户名均不能为空!" , "警告" , MessageBoxButtons.OK , MessageBoxIcon.Warning); return; } //得到连接字符串. string conStr = ConnectOracle.GetConnectionStr(server, uid, pwd); //访问数据库. ConnectOracle.OpenConnection(conStr); DataTable tabs = ConnectOracle.GetAllTableAndViewName(); ConnectOracle.CloseConnection(); //必要的验证. if (tabs == null) { return; } //得到所有表和视图的结构信息. //this.GetOracleTablesStructure(tabs); //显示所有的表和视图的名称. if (tabs != null) { this.clbTablesAndView.Items.Clear(); for (int i = 0; i < tabs.Rows.Count; i++) { string type = tabs.Rows[i][1].ToString().Trim().ToUpper(); string temp = null; if (type.Equals("VIEW")) { temp = "@ "; } else { temp = ""; } this.clbTablesAndView.Items .Add(temp + tabs.Rows[i][0].ToString(), false); } } //显示第一个表或视图的结构信息. if (this.clbTablesAndView.Items.Count > 0) { this.clbTablesAndView.SelectedIndex = 0; string tabName = this.GetTableOrViewName (this.clbTablesAndView.Items[0].ToString()); this.lblTabStructure.Text = "表" + tabName + "相关实体类结构:"; this.FormatDgvTableStructure(); } this.lblTabList.Text = "Oracle表/视图:"; }