private static void AddRoleToList(PersonalRoleCard item, STabCard sTabCard, bool inwork)
 {
     var temp = new PersonalRoleControl()
     {
         ID = item.ID.Value,
         DockPanel = new DockPanel(),
         Button = new Button
         {
             FontSize = 14,
             Margin = new Thickness(0, 0, 5, 0),
             Content = (string)SystemSingleton.Configuration.mainWindow.FindResource("c_Delete"),
             IsEnabled = !((StaticRoleCard)sTabCard.Card).isEditingNow
         },
         TextBlock = new TextBlock
         {
             FontSize = 14,
             VerticalAlignment = VerticalAlignment.Center,
             Text = item.FullName
         }
     };
     temp.Button.Click += (sender, args) =>
     {
         MessageBoxResult dialogResult = MessageBox.Show((string)SystemSingleton.Configuration.mainWindow.FindResource("m_MakeSureDeletingRoleFromStatic"),
             (string)SystemSingleton.Configuration.mainWindow.FindResource("m_AttentionHeader"),
             MessageBoxButton.YesNo);
         if (dialogResult == MessageBoxResult.Yes)
         {
             if (inwork)
             {
                 sTabCard.ListViews[StaticRoleCardViewStruct.RolesListView].Items.Remove(((StaticRoleCard)sTabCard.Card).NewPersonalControls[item.ID.Value].DockPanel);
             }
             else
             {
                 sTabCard.ListViews[StaticRoleCardViewStruct.RolesListView].Items.Remove(((StaticRoleCard)sTabCard.Card).PersonalControls[item.ID.Value].DockPanel);
             }
             PersonalRoleDelete(item.ID.Value, sTabCard);
         }
         ((StaticRoleCard)sTabCard.Card).rolesChanged = true;
     };
     temp.TextBlock.MouseLeftButtonDown += (sender, args) =>
     {
         if (item.ID.Value ==
     SystemSingleton.CurrentSession.ID)
         {
             EnvironmentHelper.SendDialogBox(
                 (string)SystemSingleton.Configuration.mainWindow.FindResource("m_CantEditMySelf"),
                 "Attention"
             );
             return;
         }
         var tempR = PersonalRoleCardFactory.CreateTab(item.ID.Value);
         if (tempR != null)
         {
             if (SystemSingleton.CurrentSession.TabCards.ContainsKey(((PersonalRoleCard)tempR.Card).ID.Value))
             {
                 EnvironmentHelper.SendDialogBox(
                     (string)SystemSingleton.Configuration.mainWindow.FindResource("m_AlreadyOpened"),
                     "Attention"
                 );
             }
             else
             {
                 if (((PersonalRoleCard)tempR.Card).isEditingNow)
                 {
                     EnvironmentHelper.SendDialogBox(
                         (string)SystemSingleton.Configuration.mainWindow.FindResource("m_AlreadyEditing"),
                         "Attention"
                     );
                 }
                 else
                 {
                     try
                     {
                         using (var con = new SqlConnection(SystemSingleton.Configuration.ConnectionString))
                         {
                             SystemSingleton.Configuration.SqlConnections.Add(con);
                             using (var command = new SqlCommand(SqlCommands.SetEditingToPersonalRole, con))
                             {
                                 command.Parameters.Add("@ID", SqlDbType.UniqueIdentifier);
                                 command.Parameters["@ID"].Value = ((PersonalRoleCard)tempR.Card).ID.Value;
                                 EnvironmentHelper.SendLogSQL(command.CommandText);
                                 con.Open();
                                 int colms = command.ExecuteNonQuery();
                                 con.Close();
                                 if (colms == 0)
                                 {
                                     EnvironmentHelper.SendDialogBox(
                                         (string)SystemSingleton.Configuration.mainWindow.FindResource(
                                             "m_CantSetEditing") + "\n\n" + ((PersonalRoleCard)tempR.Card).ID.Value.ToString(),
                                         "SQL Error"
                                     );
                                 }
                             }
                         }
                     }
                     catch (Exception ex)
                     {
                         EnvironmentHelper.SendErrorDialogBox(ex.Message, "SQL Error", ex.StackTrace);
                     }
                 }
                 SystemSingleton.CurrentSession.TabCards.Add(((PersonalRoleCard)tempR.Card).ID.Value, tempR);
                 SystemSingleton.Configuration.tabControl.Items.Add(tempR.TabItem);
             }
         }
     };
     if (inwork)
     {
         ((StaticRoleCard)sTabCard.Card).NewPersonalRoles.Add(item.ID.Value, item);
         ((StaticRoleCard)sTabCard.Card).NewPersonalControls.Add(item.ID.Value, temp);
     }
     else
     {
         ((StaticRoleCard)sTabCard.Card).PersonalControls.Add(item.ID.Value, temp);
     }
     temp.DockPanel.Children.Add(temp.Button);
     temp.DockPanel.Children.Add(temp.TextBlock);
     sTabCard.ListViews[StaticRoleCardViewStruct.RolesListView].Items.Add(temp.DockPanel);
 }
        public static void CreateNew()
        {
            switch (SystemSingleton.Configuration.mainWindow.TabWorkControl.SelectedIndex)
            {
            case 0:    //PersonalRole
                var temppers = PersonalRoleCardFactory.CreateTab();
                if (temppers != null)
                {
                    if (SystemSingleton.CurrentSession.TabCards.ContainsKey(((PersonalRoleCard)temppers.Card).ID.Value))
                    {
                        EnvironmentHelper.SendDialogBox(
                            (string)SystemSingleton.Configuration.mainWindow.FindResource("m_AlreadyOpened"),
                            "Attention"
                            );
                    }
                    else
                    {
                        SystemSingleton.CurrentSession.TabCards.Add(((PersonalRoleCard)temppers.Card).ID.Value, temppers);
                        SystemSingleton.Configuration.tabControl.Items.Add(temppers.TabItem);
                    }
                }
                break;

            case 1:    //StaticRole
                var tempstat = StaticRoleCardFactory.CreateTab();
                if (tempstat != null)
                {
                    if (SystemSingleton.CurrentSession.TabCards.ContainsKey(((StaticRoleCard)tempstat.Card).ID.Value))
                    {
                        EnvironmentHelper.SendDialogBox(
                            (string)SystemSingleton.Configuration.mainWindow.FindResource("m_AlreadyOpened"),
                            "Attention"
                            );
                    }
                    else
                    {
                        SystemSingleton.CurrentSession.TabCards.Add(((StaticRoleCard)tempstat.Card).ID.Value, tempstat);
                        SystemSingleton.Configuration.tabControl.Items.Add(tempstat.TabItem);
                    }
                }
                break;

            case 2:    //DocTypes
                var tempdoc = DocTypeCardFactory.CreateTab();
                if (tempdoc != null)
                {
                    if (SystemSingleton.CurrentSession.TabCards.ContainsKey(((DocTypeCard)tempdoc.Card).ID.Value))
                    {
                        EnvironmentHelper.SendDialogBox(
                            (string)SystemSingleton.Configuration.mainWindow.FindResource("m_AlreadyOpened"),
                            "Attention"
                            );
                    }
                    else
                    {
                        SystemSingleton.CurrentSession.TabCards.Add(((DocTypeCard)tempdoc.Card).ID.Value, tempdoc);
                        SystemSingleton.Configuration.tabControl.Items.Add(tempdoc.TabItem);
                    }
                }
                break;
            }
        }