private void OnGetSave(string keycolumn) { foreach (PdmColumn item in pTable.Columns) { if (item.ColumnCode.ToLower() == keycolumn.ToLower()) { keyCol = item; break; } } }
public static void DeleteColumn(SqlConnection conn, SqlCommand cmd, PdmTable pTable, bool islog) { PdmColumn rtn = new PdmColumn(); ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, pTable.DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pTable.TableCode)); paras.Add(DBUtils.MakeInParam("IsLog", SqlDbType.Bit, islog)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Delete_Column", paras); }
public static void SaveColumn(SqlConnection conn, SqlCommand cmd, PdmColumn pColumn) { ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, pColumn.DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pColumn.TableCode)); paras.Add(DBUtils.MakeInParam("ColumnID", SqlDbType.Int, pColumn.ColumnID)); paras.Add(DBUtils.MakeInParam("ColumnName", SqlDbType.NVarChar, 40, pColumn.ColumnName)); paras.Add(DBUtils.MakeInParam("ColumnCode", SqlDbType.NVarChar, 40, pColumn.ColumnCode)); paras.Add(DBUtils.MakeInParam("DataType", SqlDbType.NVarChar, 40, pColumn.DataType)); paras.Add(DBUtils.MakeInParam("ColumnLength", SqlDbType.Int, pColumn.Length)); paras.Add(DBUtils.MakeInParam("ColumnPrecision", SqlDbType.Int, pColumn.Precision)); paras.Add(DBUtils.MakeInParam("ColumnIdentity", SqlDbType.Bit, pColumn.Identity)); paras.Add(DBUtils.MakeInParam("ColumnNotNull", SqlDbType.Bit, pColumn.NotNull)); paras.Add(DBUtils.MakeInParam("PreSerial", SqlDbType.Int, pColumn.PreSerial)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Save_Column", paras); }
public static PdmColumn GetColumnByID(int dbid, string tablecode, string columncode) { PdmColumn rtn = new PdmColumn(); try { ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, dbid)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, tablecode)); paras.Add(DBUtils.MakeInParam("ColumnCode", SqlDbType.NVarChar, 40, columncode)); SqlDataReader reader = DBUtils.ExecuteReader(CommandType.StoredProcedure, "dbo.P_Get_ColumnByID", paras); if (reader.Read()) { rtn.OnPopulate(reader); } reader.Close(); } catch { throw; } return(rtn); }
public static PdmColumn GetColumnByID(SqlConnection conn, SqlCommand cmd, PdmColumn pColumn) { PdmColumn rtn = new PdmColumn(); try { ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, pColumn.DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pColumn.TableCode)); paras.Add(DBUtils.MakeInParam("ColumnCode", SqlDbType.NVarChar, 40, pColumn.ColumnCode)); SqlDataReader reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_ColumnByID", paras); if (reader.Read()) { rtn.OnPopulate(reader); } reader.Close(); } catch { throw; } return(rtn); }
public static void SaveIndexColumn(SqlConnection conn, SqlCommand cmd, PdmIndex pIndex, PdmColumn pColumn) { ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, pIndex.DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pIndex.TableCode)); paras.Add(DBUtils.MakeInParam("IndexCode", SqlDbType.NVarChar, 40, pIndex.IndexCode)); paras.Add(DBUtils.MakeInParam("ColumnCode", SqlDbType.NVarChar, 40, pColumn.ColumnCode)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Save_IndexColumn", paras); }
public static PdmColumn GetColumnByID(PdmColumn pColumn) { return(GetColumnByID(null, null, pColumn)); }
public static void GetTableByCode(PdmTable pTable, int DBID, string TableCode) { SqlConnection conn = null; SqlCommand cmd = null; try { conn = DBUtils.GetConnection(); cmd = DBUtils.GetCommand(); ArrayList paras = new ArrayList(); paras.Clear(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, TableCode)); SqlDataReader reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_TableByCode", paras); pTable.OnInit(); if (reader.Read()) { pTable.OnPopulate(reader); } reader.Close(); if (!String.IsNullOrEmpty(pTable.TableCode)) { reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_SetByCode", paras); if (reader.Read()) { pTable.TableSet = reader["TableSet"] as string; } else { pTable.TableSet = String.Empty; } reader.Close(); reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_ColumnByTable", paras); while (reader.Read()) { PdmColumn item = new PdmColumn(reader); pTable.AddColumn(item); } reader.Close(); reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_KeyByTable", paras); while (reader.Read()) { PdmKey item = new PdmKey(reader); pTable.AddKey(item); } reader.Close(); reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_IndexByTable", paras); while (reader.Read()) { PdmIndex item = new PdmIndex(reader); pTable.AddIndex(item); } reader.Close(); foreach (PdmKey pKey in pTable.Keys) { paras.Clear(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pTable.TableCode)); paras.Add(DBUtils.MakeInParam("KeyCode", SqlDbType.NVarChar, 40, pKey.KeyCode)); reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_ColumnByKey", paras); while (reader.Read()) { foreach (PdmColumn pColumn in pTable.Columns) { if (pColumn.ColumnCode == reader["ColumnCode"].ToString()) { pKey.AddColumn(pColumn); break; } } } reader.Close(); } foreach (PdmIndex pIndex in pTable.Indexs) { paras.Clear(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pTable.TableCode)); paras.Add(DBUtils.MakeInParam("IndexCode", SqlDbType.NVarChar, 40, pIndex.IndexCode)); reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_ColumnByIndex", paras); while (reader.Read()) { foreach (PdmColumn pColumn in pTable.Columns) { if (pColumn.ColumnCode == reader["ColumnCode"].ToString()) { pIndex.AddColumn(pColumn); break; } } } reader.Close(); } } } catch { throw; } finally { DBUtils.SetDispose(conn, cmd); } }
private void savefile_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(filename.Text)) { MessageBox.Show("数据库定义文件不能为空!"); return; } if (String.IsNullOrEmpty(dbname.Text)) { MessageBox.Show("数据库名称不能为空!"); return; } if (String.IsNullOrEmpty(dbcode.Text)) { MessageBox.Show("数据库代码不能为空!"); return; } if (ddlProject.SelectedValue.ToString() == DropAddFlag.Select.ToString()) { Global.ShowSysInfo("请选择所属项目!"); return; } SqlConnection conn = null; SqlCommand cmd = null; try { PdmHelper pdm = new PdmHelper(filename.Text); pdm.InitData(); conn = DBUtils.GetConnection(); cmd = DBUtils.GetCommand(); cmd.Transaction = conn.BeginTransaction(); #region Save DB ArrayList paras = new ArrayList(); paras.Add(DBUtils.MakeInParam("DBCode", SqlDbType.NVarChar, 40, dbcode.Text)); SqlDataReader reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_DBByCode", paras); PdmDatabase db = new PdmDatabase(); if (reader.Read()) { db.OnPopulate(reader); } reader.Close(); if (String.IsNullOrEmpty(db.DBCode)) { db.DBCode = dbcode.Text; db.DBName = dbname.Text; } db.ProjectID = ddlProject.SelectedValue.ToString(); if (db.DBID > 0) { paras.Clear(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, db.DBID)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Delete_Info", paras); } //if (db.DBID <= 0) //{ // 新数据库文件 paras.Clear(); paras.Add(DBUtils.MakeOutParam("DBID", SqlDbType.Int)); paras.Add(DBUtils.MakeInParam("DBName", SqlDbType.NVarChar, 40, db.DBName)); paras.Add(DBUtils.MakeInParam("DBCode", SqlDbType.NVarChar, 40, db.DBCode)); paras.Add(DBUtils.MakeInParam("IsLog", SqlDbType.Bit, cbLog.Checked)); paras.Add(DBUtils.MakeInParam("DBType", SqlDbType.Int, DataBaseType.MySql)); paras.Add(DBUtils.MakeInParam("ProjectID", SqlDbType.VarChar, db.ProjectID)); paras.Add(DBUtils.MakeInParam("ACTION", SqlDbType.Int, DataProviderAction.Create)); DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Save_DB", paras); db.DBID = ((SqlParameter)paras[0]).Value != DBNull.Value ? Convert.ToInt32(((SqlParameter)paras[0]).Value) : 0; db.DBSerial = 0; //} //else //{ // paras.Clear(); // paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, db.DBID)); // paras.Add(DBUtils.MakeInParam("DBName", SqlDbType.NVarChar, 40, db.DBName)); // paras.Add(DBUtils.MakeInParam("DBCode", SqlDbType.NVarChar, 40, db.DBCode)); // paras.Add(DBUtils.MakeInParam("ProjectID", SqlDbType.VarChar, db.ProjectID)); // paras.Add(DBUtils.MakeInParam("IsLog", SqlDbType.Bit, cbLog.Checked)); // paras.Add(DBUtils.MakeInParam("ACTION", SqlDbType.Int, DataProviderAction.Update)); // DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Save_DB", paras); // if (cbLog.Checked) // db.DBSerial += 1; //} # endregion Save DB # region Save Table & Columns PdmTable oTable = new PdmTable(); PdmColumn oColumn = new PdmColumn(); foreach (PdmTable pTable in pdm.Tables) { pTable.DBID = db.DBID; oTable.OnInit(); // 判断该表是否已经存在 paras.Clear(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, db.DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pTable.TableCode.ToLower())); reader = DBUtils.ExecuteReader(conn, cmd, CommandType.StoredProcedure, "dbo.P_Get_TableByCode", paras); if (reader.Read()) { oTable.OnPopulate(reader); } reader.Close(); if ((pTable.TableCode.ToLower().IndexOf("_pmt_") >= 0) || (pTable.TableCode.ToLower().IndexOf("pm_") >= 0)) { pTable.IsPmt = true; } // 保存表信息 paras.Clear(); paras.Add(DBUtils.MakeInParam("DBID", SqlDbType.Int, db.DBID)); paras.Add(DBUtils.MakeInParam("TableCode", SqlDbType.NVarChar, 40, pTable.TableCode)); paras.Add(DBUtils.MakeInParam("TableName", SqlDbType.NVarChar, 40, pTable.TableName)); paras.Add(DBUtils.MakeInParam("Comment", SqlDbType.NVarChar, 400, pTable.Comment)); paras.Add(DBUtils.MakeInParam("IsPmt", SqlDbType.Bit, pTable.IsPmt)); paras.Add(DBUtils.MakeInParam("IsLog", SqlDbType.Bit, cbLog.Checked)); if (String.IsNullOrEmpty(oTable.TableCode)) { paras.Add(DBUtils.MakeInParam("ACTION", SqlDbType.Int, DataProviderAction.Create)); } else { paras.Add(DBUtils.MakeInParam("ACTION", SqlDbType.Int, DataProviderAction.Update)); } DBUtils.ExecuteNonQuery(conn, cmd, CommandType.StoredProcedure, "dbo.P_Save_Table", paras); SqlBaseProvider.DeleteColumn(conn, cmd, pTable, cbLog.Checked); foreach (PdmColumn pColumn in pTable.Columns) { pColumn.DBID = pTable.DBID; pColumn.TableCode = pTable.TableCode; SqlBaseProvider.SaveColumn(conn, cmd, pColumn); } if (String.IsNullOrEmpty(oTable.TableCode) || cbLog.Checked) { SqlBaseProvider.LogColumn(conn, cmd, pTable, true); } SqlBaseProvider.DeleteKey(conn, cmd, pTable, cbLog.Checked); foreach (PdmKey pKey in pTable.Keys) { pKey.DBID = pTable.DBID; pKey.TableCode = pTable.TableCode; SqlBaseProvider.SaveKey(conn, cmd, pKey); foreach (PdmColumn pColumn in pKey.Columns) { SqlBaseProvider.SaveKeyColumn(conn, cmd, pKey, pColumn); } } if (String.IsNullOrEmpty(oTable.TableCode) || cbLog.Checked) { SqlBaseProvider.LogKey(conn, cmd, pTable, true); } SqlBaseProvider.DeleteIndex(conn, cmd, pTable); foreach (PdmIndex pIndex in pTable.Indexs) { pIndex.DBID = pTable.DBID; pIndex.TableCode = pTable.TableCode; SqlBaseProvider.SaveIndex(conn, cmd, pIndex); foreach (PdmColumn pColumn in pIndex.Columns) { SqlBaseProvider.SaveIndexColumn(conn, cmd, pIndex, pColumn); } } if (String.IsNullOrEmpty(oTable.TableCode) || cbLog.Checked) { SqlBaseProvider.LogIndex(conn, cmd, pTable, true); } } # endregion Save Table & Columns & Key Index
private void ddlTable_SelectedIndexChanged(object sender, EventArgs e) { try { DataTable columns = SqlBaseProvider.GetColumnByTable(Convert.ToInt32(ddlDB.SelectedValue), ddlTable.SelectedValue.ToString()); SqlBaseProvider.GetTableByCode(pTable, Convert.ToInt32(ddlDB.SelectedValue), ddlTable.SelectedValue.ToString()); PdmKeyColumn pkc = SqlBaseProvider.GetKeyColumn(Convert.ToInt32(ddlDB.SelectedValue), ddlTable.SelectedValue.ToString()); txtPackage.Text = Program.ProjectCode; txtSet.Text = String.Empty; txtResult.Text = String.Empty; txtPrefix.Text = String.Empty; txtCatalog.Text = String.Empty; txtClassName.Text = String.Empty; txtValue.Text = String.Empty; string tablename = String.Empty; if (columns.Rows.Count > 0) { string table = ddlTable.SelectedValue.ToString(); if (table.IndexOf("T_") >= 0) { string[] tables = table.Split('_'); for (int i = 1; i < tables.Length; i++) { tablename += tables[i]; } txtPrefix.Text = tables[1]; txtCatalog.Text = tables[1].ToLower(); txtClassName.Text = tablename; txtValue.Text = tablename.ToLower(); } else { string[] tables = table.Split('_'); for (int i = 0; i < tables.Length; i++) { tablename += tables[i].Substring(0, 1).ToUpper() + tables[i].Substring(1).ToLower(); } txtPrefix.Text = tables[0].Substring(0, 1).ToUpper() + tables[0].Substring(1).ToLower(); txtCatalog.Text = tables[0].ToLower(); txtClassName.Text = tablename; txtValue.Text = tablename.ToLower(); } if (pkc != null) { keycolumn = pkc.ColumnCode; OnGetSave(keycolumn); } else { keyCol = pTable.Columns[0]; keycolumn = pTable.Columns[0].ColumnCode; } if (String.IsNullOrEmpty(pTable.TableSet)) { if (pkc != null) { String txtSetText = "G|" + tablename + "|" + pkc.ColumnCode + PublicTools.WriteEnter(1); txtSetText += "S|" + tablename + "|" + pkc.ColumnCode; txtSet.Text = txtSetText; saveConfig(); } else { String txtSetText = "G|" + tablename + "|" + keycolumn + PublicTools.WriteEnter(1); txtSetText += "S|" + tablename + "|" + keycolumn; txtSet.Text = txtSetText; saveConfig(); } } else { txtSet.Text = pTable.TableSet; } } } catch (Exception ex) { Global.ShowSysInfo(ex.Message); } }