/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (!IsEdit && ChkTable) { Alert(Label1, "表已经存在!", "line1px_2"); } else { if (IsEdit) { CurrentTable = SiteTable.Tables.Find(a => { return(a.ID == EditID); }); if (TableName.Text.ToLower() != CurrentTable.TableName.ToLower()) { if (ChkTable) { Alert(Label1, "表已经存在!", "line1px_2"); return; } else { String sql = String.Format("EXEC sp_rename '{0}','{1}'", CurrentTable.TableName, TableName.Text);//修改表名 try { db.ExecuteCommand(sql); } catch (Exception ex) { Alert(Label1, ex.Message, "line1px_2"); return; } } } } else { CurrentTable = new SiteTable { ID = Guid.NewGuid(), Columns = new List <WebSite.Core.Table.Field>() }; try { String sql = string.Format("CREATE TABLE [{0}]([ID] [bigint] IDENTITY(1,1) NOT NULL PRIMARY KEY,[SettingsXML] [varchar] (8000) DEFAULT '')", TableName.Text); db.ExecuteCommand(sql); } catch (Exception ex) { Alert(Label1, ex.Message, "line1px_2"); return; } SiteTable.Tables.Add(CurrentTable); } this.GetFormValue <SiteTable>(CurrentTable); SiteTable.SaveTables(SiteTable.Tables); Alert(Label1, "保存成功!", "line1px_3"); } }
/// <summary> /// 列表事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { String id = ((HtmlInputCheckBox)e.Item.FindControl("ID")).Value; if (e.CommandName == "del") { var field = CurrentFields.Find(a => { return(a.ID == Guid.Parse(id)); }); if (field != null) { if (!field.isVirtual) { String sql = String.Format("ALTER TABLE {0} DROP COLUMN {1}", TableName, field.FieldName); db.ExecuteCommand(sql); } CurrentFields.Remove(field); SiteTable.SaveTables(SiteTable.Tables); } this.BindData(); } }
/// <summary> /// 批量删除 刷新表结构 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { Int32 arguments = Convert.ToInt32(Request.Form["__EVENTARGUMENT"]); switch (arguments) { case 1: SiteTable.RefreshTable(); this.BindData(); break; case -1: List <SiteTable> list = new List <SiteTable>(); foreach (RepeaterItem item in Repeater1.Items) { HtmlInputCheckBox chk = item.FindControl("id") as HtmlInputCheckBox; if (chk.Checked) { var tabid = Guid.Parse(chk.Value); var tab = CurrentTables.Find(a => { return(a.ID == tabid); }); if (tab != null) { String sql = "DROP TABLE " + tab.TableName; db.ExecuteCommand(sql); CurrentTables.Remove(tab); } var frm = TableForm.TableForms.Find(a => { return(a.TableID == tabid); }); if (frm != null) { TableForm.TableForms.Remove(frm); TableForm.SaveForms(); } } } SiteTable.SaveTables(CurrentTables); this.BindData(); break; } }
/// <summary> /// 批量删除 刷新表结构 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnDelete_Click(object sender, EventArgs e) { Int32 arguments = Convert.ToInt32(Request.Form["__EVENTARGUMENT"]); switch (arguments) { case 1: SiteTable.RefreshField(CurrentTable); this.BindData(); break; case -1: List <SiteTable> list = new List <SiteTable>(); foreach (RepeaterItem item in Repeater1.Items) { HtmlInputCheckBox chk = item.FindControl("id") as HtmlInputCheckBox; if (chk.Checked) { var field = CurrentFields.Find(a => { return(a.ID == Guid.Parse(chk.Value)); }); if (field.FieldName == "id" || field.FieldName == "settingsxml") { continue; } if (field != null) { if (!field.isVirtual) { String sql = String.Format("ALTER TABLE {0} DROP COLUMN {1}", TableName, field.FieldName); db.ExecuteCommand(sql); } CurrentFields.Remove(field); } } } SiteTable.SaveTables(SiteTable.Tables); this.BindData(); break; } }
/// <summary> /// 列表事件 /// </summary> /// <param name="source"></param> /// <param name="e"></param> protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e) { String id = ((HtmlInputCheckBox)e.Item.FindControl("ID")).Value; if (e.CommandName == "del") { Guid tabid = Guid.Parse(id); var tab = CurrentTables.Find(a => { return(a.ID == tabid); }); if (tab != null) { String sql = "DROP TABLE " + tab.TableName; db.ExecuteCommand(sql); CurrentTables.Remove(tab); SiteTable.SaveTables(CurrentTables); } var frm = TableForm.TableForms.Find(a => { return(a.TableID == tabid); }); if (frm != null) { TableForm.TableForms.Remove(frm); TableForm.SaveForms(); } this.BindData(); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { if (!IsEdit && ChkField) { Alert(Label1, "字段已经存在!", "line1px_2"); } else { Int32 _length = 0; Int32.TryParse(@Length.Text, out _length); @Length.Text = _length.ToString(); Int32 _columns = 1; Int32.TryParse(RepeatColumns.Text, out _columns); RepeatColumns.Text = _columns.ToString(); String sql = String.Empty; Int32 _datatypevalue = Convert.ToInt32(Enum.Parse(db.dbType, @DataType.SelectedValue, true)); DataTypeValue.Value = _datatypevalue.ToString(); if (IsEdit) { CurrentField = CurrentFields.Find(a => { return(a.ID == EditID); }); #region 检查数据库改动 if (isVirtual.SelectedIndex == 1) { //类型类型改动 sql = String.Format("ALTER TABLE {0} ALTER COLUMN {1} {2}", CurrentTable.TableName, CurrentField.FieldName, @DataType.SelectedValue); if (CurrentField.Length != _length && _length != 0)//检查长度 { sql += "(" + _length + ")"; } if (CurrentField.DataType != _datatypevalue || (CurrentField.Length != _length && _length != 0)) { try { db.ExecuteCommand(sql); } catch (Exception ex) { Alert(Label1, ex.Message, "line1px_2"); return; } } } #endregion } else { CurrentField = new WebSite.Core.Table.Field() { ID = Guid.NewGuid() }; if (isVirtual.SelectedIndex == 1)//添加真实字段 { sql = sql = String.Format("ALTER TABLE {0} ADD {1} {2}", CurrentTable.TableName, FieldName.Text, @DataType.SelectedValue); if (_length != 0)//设置长度 { sql += "(" + _length + ")"; } try { db.ExecuteCommand(sql); } catch (Exception ex) { Alert(Label1, ex.Message, "line1px_2"); return; } } CurrentFields.Add(CurrentField); } CurrentField = this.GetFormValue <WebSite.Core.Table.Field>(CurrentField); //数据源类型 CurrentField.DataSource = this.GetFormValue <FieldDataSource>(CurrentField.DataSource); //布局模式 CurrentField.DataSource.Layout = this.GetFormValue <DataSourceLayout>(CurrentField.DataSource.Layout); //SQL数据源 CurrentField.DataSource.SQLDataSource = this.GetFormValue <SQLDataSource>(CurrentField.DataSource.SQLDataSource); //列表项目 if (Repeater1.Items.Count > 0) { CurrentField.DataSource.ListItemDataSource = new List <ListItemDataSource>(); foreach (RepeaterItem item in Repeater1.Items) { String text = ((TextBox)item.Controls[0].FindControl("t1")).Text; String value = ((TextBox)item.Controls[0].FindControl("t2")).Text; Boolean chk = ((CheckBox)item.Controls[0].FindControl("c1")).Checked; ListItemDataSource listitem = new ListItemDataSource { Selected = chk, Text = text, Value = value }; CurrentField.DataSource.ListItemDataSource.Add(listitem); } } SiteTable.SaveTables(SiteTable.Tables); Alert(Label1, "保存成功!", "line1px_3"); } }