private void tsbtnSave_Click(object sender, EventArgs e) { try { if (this.selectInfo == null) { SaveForm saveForm = new SaveForm(); DialogResult rslt = saveForm.ShowDialog(); if (rslt == DialogResult.OK) { this.selectInfo = this.databaseInfo.CreateSelect(saveForm.SaveName, this.txtMain.Text); if (this.selectInfo != null) { this.selectInfo.IsOpen = true; TreeNode dbNode = this.databaseInfo.Node; TreeNode sgNode = dbNode.Nodes[2]; NodeTypeInfo sgNodeTypeInfo = sgNode.Tag as NodeTypeInfo; TreeNode sNode = new TreeNode(); sNode.Text = this.selectInfo.Name; sNode.ImageKey = Resources.image_key_select; sNode.SelectedImageKey = Resources.image_key_select; sNode.Tag = new NodeTypeInfo(NodeType.eSelect, sNode, this.selectInfo); sgNode.Nodes.Add(sNode); sgNodeTypeInfo.SelectList.AddItem(this.selectInfo, Resources.image_key_select); this.page.Text = $"{this.selectInfo.Name}@{this.databaseInfo.Name}({this.databaseInfo.ConnectInfo.Name})-查询"; TabPageTypeInfo pageTypeInfo = this.page.Tag as TabPageTypeInfo; pageTypeInfo.PageType = TabPageType.eOpenSelect; pageTypeInfo.Info = this.selectInfo; this.selectInfo.OpenSelectPage = this.page; } else { throw new NotImplementedException(); } } } else { this.databaseInfo.AlterSelect(this.selectInfo.Name, this.txtMain.Text); } } catch (Exception ex) { LogHelper.Error(ex); this.tsbtnSave.Enabled = true; } }
private void tsbtnSave_Click(object sender, EventArgs e) { try { if (this.dgvFields.Rows.Count == 0) { return; } if (this.tableInfo == null) { SaveForm saveForm = new SaveForm(); if (saveForm.ShowDialog() == DialogResult.OK) { StringBuilder tb = new StringBuilder(); tb.Append($"CREATE TABLE {saveForm.SaveName} \n(\n"); StringBuilder pk = new StringBuilder(); foreach (DataRow dr in this.designTable.Rows) { tb.Append($" {dr[Resources.FieldName]} {dr[Resources.FieldType]}"); if (dr[Resources.FieldLength].ToString() != "0") { tb.Append($" ({dr[Resources.FieldLength]}"); if (dr[Resources.FieldScale].ToString() != "0") { tb.Append($",{dr[Resources.FieldScale]}"); } tb.Append(")"); } if (Convert.ToBoolean(dr[Resources.FieldIsNull])) { tb.Append(" NOT NULL"); } if (Convert.ToBoolean(dr[Resources.FieldIsPrimayrKey])) { if (pk.Length == 0) { pk.Append("PRIMARY KEY("); } pk.Append($"{dr[Resources.FieldName]},"); } if (dr[Resources.FieldDefault].ToString() != "") { tb.Append($" DEFAULT {dr[Resources.FieldDefault]}"); } else { if (!Convert.ToBoolean(dr[Resources.FieldIsPrimayrKey]) && !Convert.ToBoolean(dr[Resources.FieldIsNull])) { tb.Append(" DEFAULT NULL"); } } tb.Append(",\n"); } if (pk.Length != 0) { pk.Remove(pk.Length - 1, 1); pk.Append(")\n"); tb.Append(pk); tb.Append(")\n"); } else { tb.Remove(tb.Length - 2, 2); tb.Append(")\n"); } this.tableInfo = this.databaseInfo.CreateTable(saveForm.SaveName, tb.ToString()); if (this.tableInfo != null) { this.tableInfo.IsDesign = true; this.BindData(); TreeNode dbNode = this.databaseInfo.Node; TreeNode tgNode = dbNode.Nodes[0]; NodeTypeInfo tgNodeTypeInfo = tgNode.Tag as NodeTypeInfo; TreeNode tbNode = new TreeNode(); tbNode.Text = this.tableInfo.Name; tbNode.ImageKey = Resources.image_key_table; tbNode.SelectedImageKey = Resources.image_key_table; tbNode.Tag = new NodeTypeInfo(NodeType.eTable, tbNode, this.tableInfo); tgNode.Nodes.Add(tbNode); tgNodeTypeInfo.TableList.AddItem(this.tableInfo, Resources.image_key_table); this.page.Text = $"{this.tableInfo.Name}@{this.databaseInfo.Name}({this.databaseInfo.ConnectInfo.Name})-表"; } else { throw new NotImplementedException(); } } } else { //TODO alter table string str = ""; this.databaseInfo.AlterTable(this.tableInfo.Name, str); this.BindData(); } } catch (Exception ex) { LogHelper.Error(ex); } }