tim1979222's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
15 (0.03 per day)
Joined:
23-January 12
Profile Views:
77
Last Active:
User is offline Jan 30 2012 08:59 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   tim1979222 has not set their status

Posts I've Made

  1. In Topic: command doesnt work

    Posted 25 Jan 2012

    tnx for the tips,bytheway i got it to work the code:)
  2. In Topic: command doesnt work

    Posted 25 Jan 2012

    would be nice if you could tell me how,because i really dont know,and tried it since 20 min
  3. In Topic: command doesnt work

    Posted 25 Jan 2012

    do you mean it so`?

    cmd = new FbCommand("select * from Controls where Page = @PageName",conn);
    cmd = new FbCommand("Insert into Controls (Page, ControlID) values (@PageName, @ControlID)",conn);
    cmd = new FbCommand("insert into ControlsToRoles (FKRole, FKPage, FKControlID, invisible, disabled) values (@RoleID, @PageName, @ControlID, @invisible, @disabled",conn);
    


    i should put that in that line?
    sry , like i said i am very new in c#
  4. In Topic: command doesnt work

    Posted 25 Jan 2012

    how can i correctly enter this code, itry since 2 days-

    cmd = new FbCommand(("select * from Controls where Page = @PageName and ControlID = @ControlID)Insert into Controls (Page, ControlID) values (@PageName, @ControlID)and (insert into ControlsToRoles (FKRole, FKPage, FKControlID, invisible, disabled) values (@RoleID, @PageName, @ControlID, @invisible, @disabled)"),conn);
    
    
  5. In Topic: command doesnt work

    Posted 25 Jan 2012

    i send the whole code.that is a control based system.the pagebutton should be binded with the role,and it should appear below in the window. everything works ,but the Save_Click doesnt do his work-

    
    private void PopulatePermissionTree()
            {
    
                 ConnectionStringSettingsCollection connectionStrings =
                  ConfigurationManager.ConnectionStrings;
                string connString = connectionStrings[
                   "xxx.Properties.Settings.xxx"].
                       ToString();
                FbConnection conn = new FbConnection( connString );
                conn.Open();
    
                string queryString = "select controlID, Invisible, Disabled, RoleName " +
                "from ControlsToRoles ctr " +
                " join controls c on c.ControlID = ctr.FKControlID and c.Page = ctr.FKPage " +
                " join roles r on r.RoleID = ctr.FKRole ";
    
                if ( ByControlRB.Checked )
                {
                    queryString += " order by ControlID";
                }
                else
                {
                    queryString += " order by RoleName";
                }
    
                DataSet ds = new DataSet();
                FbDataAdapter dataAdapter = null;
                DataTable dt = null;
                try
                {
                    dataAdapter = new FbDataAdapter( queryString, conn );
                    dataAdapter.Fill( ds, "controlsToRoles" );
                    dt = ds.Tables[0];
                }
                catch (Exception e)
                {
                    MessageBox.Show( "Unable to retrieve permissions: " + e.Message, 
                        "Error retrieving permissions", 
                        MessageBoxButtons.OK, 
                        MessageBoxIcon.Error );
                }
                finally
                {
                    conn.Close();
                }
               
                PermissionTree.BeginUpdate();
                PermissionTree.Nodes.Clear();
                TreeNode parentNode = null;
                TreeNode subNode = null;
    
                string currentName = string.Empty;
                foreach ( DataRow row in dt.Rows )
                {
                    string subNodeText = ByControlRB.Checked ? row["RoleName"].ToString() : row["ControlID"].ToString();
                    subNodeText += ":";
                    subNodeText += Convert.ToInt32( row["Invisible"] ) == 0 ? " visible " : " not visible ";
                    subNodeText += " and ";
                    subNodeText += Convert.ToInt32( row["Disabled"] ) == 0 ? " enabled " : " disabled ";
    
                    subNode = new TreeNode ( subNodeText );
                    string dataName = ByControlRB.Checked ? row["ControlID"].ToString() : row["RoleName"].ToString();
                    if ( currentName != dataName )
                    {
                        parentNode = new TreeNode( dataName );
                        currentName = dataName;
                        PermissionTree.Nodes.Add( parentNode );
                    }
    
                    if ( parentNode != null )
                    {
                        parentNode.Nodes.Add( subNode );
                    }
                }
                PermissionTree.EndUpdate();
            }
     
            private void PermissionTreeButtonchanged( object sender, EventArgs e )
            {
               PopulatePermissionTree();
            }
    
            private void Save_Click( object sender, EventArgs e )
            {
    
                ConnectionStringSettingsCollection connectionStrings =
                       ConfigurationManager.ConnectionStrings;
    
                string connString = connectionStrings["xxx.Properties.Settings.xxx"].ToString();
                FbConnection conn = new FbConnection( connString );
                conn.Open();
                FbParameter param;
    
                foreach ( String controlID in PageControls.SelectedItems )
                {
                    foreach ( DataRowView roleRow in PermissionRoles.SelectedItems )
                    {
    
                        int roleID = Convert.ToInt32( roleRow["RoleID"] );
                        try
                        {
    
                     cmd = new FbCommand(("select * from Controls where Page = @PageName and ControlID = @ControlID) AND Insert into Controls (Page, ControlID) values (@PageName, @ControlID)and (insert into ControlsToRoles (FKRole, FKPage, FKControlID, invisible, disabled) values (@RoleID, @PageName, @ControlID, @invisible, @disabled)"),conn);
                            
                           
    
                            param = cmd.Parameters.Add("@RoleID", FbDbType.Integer);
                            param.Value = roleID;
                            param.Direction = ParameterDirection.Input;
    
                            param = cmd.Parameters.Add("@PageName", FbDbType.VarChar, 50);
                            param.Value = workingForm.Name.ToString();
                            param.Direction = ParameterDirection.Input;
    
                            param = cmd.Parameters.Add( "@ControlID", FbDbType.VarChar, 50 );
                            param.Value = controlID;
                            param.Direction = ParameterDirection.Input;
    
                            param = cmd.Parameters.Add("@invisible", FbDbType.Integer);
                            param.Value = InVisible.Checked ? 1 : 0;
                            param.Direction = ParameterDirection.Input;
    
                            param = cmd.Parameters.Add("@disabled", FbDbType.Integer);
                            param.Value = Disabled.Checked ? 1 : 0;
                            param.Direction = ParameterDirection.Input;
    
    
                            int rowsInserted = cmd.ExecuteNonQuery();
                            if ( rowsInserted < 1 || rowsInserted > 2 )
                            {
                                DisplayError( controlID, roleID, "Rows inserted = " + rowsInserted.ToString() );
                            }
                        }
                        catch ( Exception ex )
                        {
                            DisplayError( controlID, roleID, ex.Message );
                        }
                    }
                }
                conn.Close();
                PopulatePermissionTree();
            }
    
    
    

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

tim1979222 hasn't added any friends yet.

Comments

tim1979222 has no profile comments yet. Why not say hello?