private void insertItem_Click(object sender, EventArgs e) { dbConnection.Open(); //TUObjectDTO tuObjectData = new TUObjectDTO(); int classId = System.Convert.ToInt32(((ToolStripMenuItem)sender).Tag); dbCommand.CommandText = "Select FormName From Classes_ Where ClassId = " + classId; string className = (string)dbCommand.ExecuteScalar(); TUObjects tuObject; Type t = Type.GetType(DefinedConstants.logicLeyerNameSpace + "." + className + ", " + DefinedConstants.logicLeyerNameSpace); tuObject = (TUObjects)Activator.CreateInstance(t, dbConnection, dbServer); TUObjectsDTO tuObjectData; Type tDTO = Type.GetType(DefinedConstants.dataLeyerNameSpace + "." + className + "DTO, " + DefinedConstants.dataLeyerNameSpace); tuObjectData = (TUObjectsDTO)Activator.CreateInstance(tDTO); tuObjectData.ClassId = classId; tuObjectData.Major = ((TreeNodeData)clickNode.Tag).Id; //showing dialog ViewDataClient editDialog = new ViewDataClient(tuObject, tuObjectData, DBAction.Insert); if (editDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { dbCommand.CommandText = "Select Count(Id) From TUObjects Where Major = " + ((TreeNodeData)clickNode.Tag).Id; int count = (int)dbCommand.ExecuteScalar(); dbCommand.CommandText = "Select Max(Id) From TUObjects"; int tmpId = (int)dbCommand.ExecuteScalar(); //tree modification if (((TreeNodeData)clickNode.Tag).WasOpened) { string connectionStr = ((TreeNodeData)clickNode.Tag).ConnectionStringName; TreeNode tmp = new TreeNode(tuObjectData.Name); TreeNodeData cls = new TreeNodeData(tmpId, false, connectionStr); tmp.Tag = cls; tmp.ContextMenuStrip = clickNode.ContextMenuStrip; clickNode.Nodes.Add(tmp); } else if (count == 1) { clickNode.Nodes.Add("Virtual Node"); } } dbConnection.Close(); }
private void editToolStripMenuItem_Click(object sender, EventArgs e) { //string connectionStringName = ((TreeNodeData)(clickNode.Tag)).ConnectionStringName; //string providerName = ConfigurationManager.ConnectionStrings[connectionStringName].ProviderName; //switch (providerName) //{ // case "System.Data.SqlClient": // { // dbConnection = sqlConnection; // dbCommand = sqlCommand; // dbConnectionDaughter = sqlConnectionDaughter; // dbCommandDaughter = sqlCommandDaughter; // break; // } // case "FirebirdSql.Data.FirebirdClient": // { // dbConnection = fbConnection; // dbCommand = fbCommand; // dbConnectionDaughter = fbConnectionDaughter; // dbCommandDaughter = fbCommandDaughter; // break; // } // default: // { // throw new Exception("Bad name of current connection string"); // } //} dbConnection.Open(); TUObjectsDTO tuObjectData = new TUObjectsDTO() { Id = ((TreeNodeData)(clickNode.Tag)).Id }; dbCommand.CommandText = "Select ClassId From TUObjects Where Id = " + tuObjectData.Id; int classId = (int)dbCommand.ExecuteScalar(); dbCommand.CommandText = "Select FormName From Classes_ Where ClassId = " + classId; string className = (string)dbCommand.ExecuteScalar(); TUObjects tuObject; Type t = Type.GetType(DefinedConstants.logicLeyerNameSpace+ "." + className+", "+DefinedConstants.logicLeyerNameSpace); tuObject = (TUObjects)Activator.CreateInstance(t, dbConnection, dbServer); //showing dialog ViewDataClient editDialog = new ViewDataClient(tuObject, tuObjectData, DBAction.Edit); if (editDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { clickNode.Text = editDialog.TuObjectName; } dbConnection.Close(); }