Exemplo n.º 1
0
        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();
        }
Exemplo n.º 2
0
        protected void FillTreeNavigation(int major, TreeNode tNode, ContextMenuStrip nodeContextMenuStrip)
        {
            //change the type of data base
            if (tNode != null)
            {
                TreeNodeData dataNode = (TreeNodeData)tNode.Tag;
                currentConnectionStringName = dataNode.ConnectionStringName;
            }

            if (!string.IsNullOrEmpty(currentConnectionStringName))
            {
                currentProviderName = ConfigurationManager.ConnectionStrings[currentConnectionStringName].ProviderName;
                currentConnectionString = ConfigurationManager.ConnectionStrings[currentConnectionStringName].ConnectionString;

                switch (currentProviderName)
                {
                    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");
                        }
                }
            }
            else
            {
               throw new Exception("Bad  name of current connection string");
            }

            //logic
            dbConnection.Open();
            dbConnectionDaughter.Open();

            TreeNodeData treeNodeData;
            TreeNode currentNode;
            int i = 0, n = 0;

            dbCommand.CommandText = "Select Id, Name From TUObjects Where Major = " + major + " Order by ClassId, Name";
            dbDataReader = dbCommand.ExecuteReader();

            while (dbDataReader.Read())
            {
                treeNodeData = new TreeNodeData(dbDataReader.GetInt32(0), false, currentConnectionStringName);

                currentNode = new TreeNode(dbDataReader.GetString(1));
                currentNode.Tag = treeNodeData;
                if(nodeContextMenuStrip != null)
                    currentNode.ContextMenuStrip = nodeContextMenuStrip;

                if (tNode != null)
                    tNode.Nodes.Add(currentNode);
                else
                    treeNavigation.Nodes.Add(currentNode);

                dbCommandDaughter.CommandText = "Select Count(Id) From TUObjects Where Major = " + dbDataReader.GetInt32(0);

                n = (int)dbCommandDaughter.ExecuteScalar();
                if (n > 0)
                {
                    if (tNode != null)
                        tNode.Nodes[i].Nodes.Add("Virtual Node");
                    else
                        treeNavigation.Nodes[i].Nodes.Add("Virtual Node");
                }

                i++;
            }
            dbDataReader.Close();
            dbConnection.Close();
            dbConnectionDaughter.Close();
        }
Exemplo n.º 3
0
        protected override void BaseTreeNavigator_Shown(object sender, EventArgs e)
        {
            //currentConnectionStringName = ConfigurationManager.AppSettings["currentConnectionStringName"];
            ChooseDBDialog chooseDB = new ChooseDBDialog();

            if (chooseDB.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                treeNavigation.BeginUpdate();
                treeNavigation.UseWaitCursor = true;

                nativeConnectionStringName = chooseDB.ConnectionStringName;
                currentConnectionStringName = chooseDB.ConnectionStringName;

                FillTreeNavigation(0, null, nodeContextMenuStrip);

                TreeNodeData linkNodeData = new TreeNodeData(0, false, string.Empty);

                linkNode = new TreeNode("Link");
                linkNode.Tag = linkNodeData;
                linkNode.ContextMenuStrip = linkContextMenuStrip;
                linkNode.Nodes.Add("Virtual Node");

                wasLoaded_linkNode = false;
                treeNavigation.Nodes.Add(linkNode);

                treeNavigation.UseWaitCursor = false;
                treeNavigation.EndUpdate();
            }
            else
            {
                Application.Exit();
            }
        }