Ejemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            checkedListBox1.Items.Clear();
            ADMethodsAccountManagement ADcon = new ADMethodsAccountManagement();

            StaffTableAdapter dAdapt = new StaffTableAdapter();

            ITO_DAL.dsITO.StaffDataTable staffTbl = new dsITO.StaffDataTable();

            dAdapt.Fill(staffTbl);

            string filterString = "State > 0";

            // DataRow[] staff = staffTbl.Select(filterString);
            DataRow[] staff = staffTbl.Select(filterString);

            //Отбражаем организационные единицы верхнего уровня UpDepID NULL
            for (int i = 0; i < staff.Length; i++)
            {
                if (!ADcon.IsUserExisiting(staff[i]["Login"].ToString()))
                {
                    listBox1.Items.Add(staff[i]["Login"].ToString() + " " +
                                       staff[i]["LastName"].ToString() + " " +
                                       staff[i]["Name"].ToString() + " " +
                                       staff[i]["SecondName"].ToString() + " not exist");

                    checkedListBox1.Items.Add(staff[i]["Login"].ToString());
                }
                // staff[i]["Login"].ToString()

                //lbStaff.Items
                //  lvStaff.Items.Add(staff[i]["UserID"].ToString(), staff[i]["LastName"].ToString() + " " +
                // staff[i]["Name"].ToString() + " " + staff[i]["SecondName"].ToString(),0);
            }
        }
Ejemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            ADMethodsAccountManagement ADcon = new ADMethodsAccountManagement();

            PasswordGenerator pass = new PasswordGenerator();

            for (int i = 0; i < checkedListBox1.SelectedItems.Count; i++)
            {
                DataTable dt = m_ITOSQLCommand.ExecuteSQLCommand("Select login, Name,SecondName,LastName,UserID, dbo.GetEmailByID(emailID) from staff where login='******'");

                if (dt.Rows.Count > 0)
                {

                    //создаем пользователя в AD
                    string password = pass.GeneratePassword(5);
                    ADcon.CreateNewUser("CN=Users,DC=vniiaes-asutp,DC=lan", dt.Rows[0][0].ToString(), password, dt.Rows[0][1].ToString(), dt.Rows[0][3].ToString());
                    string UserID = dt.Rows[0][4].ToString();
                    string login = dt.Rows[0][0].ToString();
                    UserPrincipal up = ADcon.GetUser(dt.Rows[0][0].ToString());

                    up.DisplayName = dt.Rows[0][3].ToString() + " " + dt.Rows[0][1].ToString() + " " + dt.Rows[0][2].ToString();
                    up.MiddleName = dt.Rows[0][2].ToString();
                    up.PasswordNeverExpires = true;
                    up.EmailAddress = dt.Rows[0][5].ToString();
                    up.Save();
                    //TODO Переделать добавление в группы по умолчанию
                    // ADcon.AddUserToGroup(dt.Rows[0][0].ToString(),"1С-Битрикс - Сотрудники")
                    ADcon.AddUserToGroup(dt.Rows[0][0].ToString(), "grpPermLocalUsers");

                    //Сохраняем пароль

                    if (m_ITOSQLCommand.ExecuteSQLNotQuery(string.Format("insert into stfPasswords (UserID,Type,Password,LastChangeID) values ('{0}','1','{1}','{2}')",
                                                                       UserID,
                                                                       password,
                                                                       m_ProgramUserIdx.ToString())) != 1)
                        MessageBox.Show("Innsert Pass " + pass + " to User " + login + " fails");

                }

                //checkedListBox1.SelectedItems[i]
            }
        }
Ejemplo n.º 3
0
        private void btnADSave_Click(object sender, EventArgs e)
        {
            ADMethodsAccountManagement ADcon = new ADMethodsAccountManagement();

            //проверяем, если такой пользователь уже есть
            if (ADcon.IsUserExisiting(tbLogin.Text))
            {
                MessageBox.Show("Такой пользователь уже есть");
                return;
            }

            string password= null;

            PasswordGenerator pass = new PasswordGenerator();
            password = pass.GeneratePassword(5);  //пароль для AD

            UserPrincipal oUserPrincipal = ADcon.CreateNewUser("OU=RASU,DC=vniiaes-asutp,DC=lan", tbLogin.Text, password, txbName.Text, txbLastName.Text);

            oUserPrincipal.DisplayName = txbLastName.Text + " " + txbName.Text + " " + txbSecondName.Text;
            oUserPrincipal.MiddleName = txbSecondName.Text;
            //oUserPrincipal.PasswordNeverExpires = true;
            oUserPrincipal.EmailAddress = lblMainEmail.Text;

            //Добавляем пользователя в группы по умолчанию

            GroupPrincipal oGroupPrincipal = ADcon.GetGroup("OU=Share Permission,DC=vniiaes-asutp,DC=lan", "grpPermLocalUsers");
            if (oGroupPrincipal != null)
            {
                oGroupPrincipal.Members.Add(oUserPrincipal);
                oGroupPrincipal.Save();
            }

            oGroupPrincipal = ADcon.GetGroup("OU=Bitrix, OU=Share Permission,DC=vniiaes-asutp,DC=lan", "1С-Битрикс - Сотрудники");
            if (oGroupPrincipal != null)
            {
                oGroupPrincipal.Members.Add(oUserPrincipal);
                oGroupPrincipal.Save();
            }

               oGroupPrincipal = ADcon.GetGroup("OU=Service Permission,DC=vniiaes-asutp,DC=lan", "Wi-Fi Users");
               if (oGroupPrincipal != null)
                {
                    oGroupPrincipal.Members.Add(oUserPrincipal);
                    oGroupPrincipal.Save();
                }

            oUserPrincipal.Save();

            try
            {
                m_ITOSQLCommand.ExecuteSQLNotQuery(string.Format("update staff set Login='******' where UserID='{1}'",
                                                                                                  tbLogin.Text,
                                                                                                  m_SelectedUserIdx.ToString()));

            }

            catch (SystemException ex)
            {

            }

            if (password != null)
            {
                try
                {
                    m_ITOSQLCommand.ExecuteSQLNotQuery(string.Format("insert into stfPasswords (Password, Type,LastChangerID,UserID) values ('{0}','{1}','{2}','{3}')",
                                                                                                      password,
                                                                                                      (int)ePasswordTypes.AD,
                                                                                                      m_ProgramUserIdx.ToString(),
                                                                                                       m_SelectedUserIdx.ToString()));

                }

                catch (SystemException ex)
                {

                }

            }
        }
Ejemplo n.º 4
0
        private void btnADCheck_Click(object sender, EventArgs e)
        {
            ADMethodsAccountManagement ADcon = new ADMethodsAccountManagement();
            if (ADcon.IsUserExisiting(tbLogin.Text))
                {
                //такой пользователь уже есть
                }
            else
                {
                //такого пользователя нет
                    btnADCreate.Visible = true;

                }
        }
Ejemplo n.º 5
0
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            label3.Text = "";

            if (e.RowIndex < 0)
                return;

            ADMethodsAccountManagement ADcon = new ADMethodsAccountManagement();

            if (ADcon.IsUserExisiting(m_NewUser.Rows[e.RowIndex]["login"].ToString()))
            { //такой пользователь уже есть в AD
                label3.Text = m_NewUser.Rows[e.RowIndex]["login"].ToString() + " уже существует в AD " + ADcon.GetUserFIO(m_NewUser.Rows[e.RowIndex]["login"].ToString());

            }
        }
Ejemplo n.º 6
0
        private void button5_Click(object sender, EventArgs e)
        {
            ADMethodsAccountManagement ADcon = new ADMethodsAccountManagement();
            ADcon.GetUser("druzhinin");

            listBox2.Items.Clear();
            listBox2.Items.Add("Логин;ФИО;Компания;Подразделение;Должность;Адрес электронной почты;Уволен;AD GUID");

            var excel = new Excel.Application();

            excel.Visible = true;

            Excel.Workbook workbook = excel.Workbooks.Add();

            excel.Cells[1, 1].Font.FontStyle = "Bold";
            excel.Cells[1, 1].Value2 = "Логин";

            excel.Cells[1, 2].Font.FontStyle = "Bold";
            excel.Cells[1, 2].Value2 = "ФИО";

            excel.Cells[1, 3].Font.FontStyle = "Bold";
            excel.Cells[1, 3].Value2 = "Компания";

            excel.Cells[1, 4].Font.FontStyle = "Bold";
            excel.Cells[1, 4].Value2 = "Подразделение";

            excel.Cells[1, 5].Font.FontStyle = "Bold";
            excel.Cells[1, 5].Value2 = "Должность";

            excel.Cells[1, 6].Font.FontStyle = "Bold";
            excel.Cells[1, 6].Value2 = "Адрес электронной почты";

            excel.Cells[1, 7].Font.FontStyle = "Bold";
            excel.Cells[1, 7].Value2 = "Уволен";

            excel.Cells[1, 8].Font.FontStyle = "Bold";
            excel.Cells[1, 8].Value2 = "AD GUID";

            for (int i = 0; i < lbToSaperion.Items.Count; i++)
            {
                DataTable dt = m_ITOSQLCommand.ExecuteSQLCommand("Select login , dbo.GetUserFIOfromStaff(UserID),dbo.GetDepartmentNameByID(DepartmentID), dbo.GetPositionNameByID(PositionID), dbo.GetEmailByID(emailID) from staff where UserID='"
                                                                   + (lbToSaperion.Items[i] as ListElement).Index + "'");

                for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
                {

                    listBox2.Items.Add(string.Format("vniiaes-asutp.lan\\{0};{1};АО \"ВНИИАЭС\";{2};{3};{4};false;{5}",
                                                        dt.Rows[curRow][0].ToString(),
                                                        dt.Rows[curRow][1].ToString(),
                                                        dt.Rows[curRow][2].ToString(),
                                                        dt.Rows[curRow][3].ToString(),
                                                        dt.Rows[curRow][4].ToString(),
                                                        ADcon.GetUserGUID(dt.Rows[curRow][0].ToString())));

                    excel.Cells[i + 2, 1].Value2 = "vniiaes-asutp\\" + dt.Rows[curRow][0].ToString();

                    excel.Cells[i + 2, 2].Value2 = dt.Rows[curRow][1].ToString();

                    excel.Cells[i + 2, 3].Value2 = "АО \"ВНИИАЭС\"";

                    excel.Cells[i + 2, 4].Value2 = dt.Rows[curRow][2].ToString();

                    excel.Cells[i + 2, 5].Value2 = dt.Rows[curRow][3].ToString();

                    excel.Cells[i + 2, 6].Value2 = dt.Rows[curRow][4].ToString();

                    excel.Cells[i + 2, 7].Value = "false";

                    excel.Cells[i + 2, 8].Value2 = ADcon.GetUserGUID(dt.Rows[curRow][0].ToString());

                }

            }
            workbook.SaveAs(@"c:\temp\FromExcel.xlsx");
        }
Ejemplo n.º 7
0
        public ChangeUserForm()
        {
            InitializeComponent();

            /*    m_TableAdapterManager = new TableAdapterManager();
            m_TableAdapterManager.StaffTableAdapter = new StaffTableAdapter();
            m_TableAdapterManager.stfOrgStructureTableAdapter = new stfOrgStructureTableAdapter();
            m_TableAdapterManager.NewUserTableAdapter = new NewUserTableAdapter();

            m_StaffTbl = new dsITO.StaffDataTable();
            m_NewUser = new dsITO.NewUserDataTable();
            m_TableAdapterManager.NewUserTableAdapter.Fill(m_NewUser);

            m_OrgStructure = new dsITO.stfOrgStructureDataTable();

            m_TableAdapterManager.StaffTableAdapter.Fill(m_StaffTbl);*/

            m_ITOSQLCommand = new ITODAL();

            m_ADcon = new ADMethodsAccountManagement();

            m_ITOSQLCommand.OpenConnection("Data Source=10.15.140.2;Initial Catalog=ITO;Persist Security Info=True;User ID=evgeny;Password=ywfaggzu");

            //Заполняем ComboBox данными из базы

            //Должности
            DataTable dt = m_ITOSQLCommand.ExecuteSQLCommand("Select PositionID, Name from stfPositions");

            for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
            {
                ListElement le = new ListElement(dt.Rows[curRow][0].ToString(),dt.Rows[curRow][1].ToString());
                cbPosition.Items.Add(le);

            }

            //Подразделения
            dt = m_ITOSQLCommand.ExecuteSQLCommand("Select ShortName, Name, DepartmentID from stfOrgStructure");

            for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
            {
                ListElement le = new ListElement(dt.Rows[curRow][2].ToString(), dt.Rows[curRow][0].ToString() + " " + dt.Rows[curRow][1].ToString());
                cbDepartment.Items.Add(le);

            }

            //Здания
            dt = m_ITOSQLCommand.ExecuteSQLCommand("Select BuildingID, Name from stfBuildings");

            for (int curRow = 0; curRow < dt.Rows.Count; curRow++)
            {
                ListElement le = new ListElement(dt.Rows[curRow][0].ToString(), dt.Rows[curRow][1].ToString());

                cbWorkPlace.Items.Add(le);

            }

            //Типы Телефонов
            foreach ( Enum value in Enum.GetValues(typeof(ePhoneTypes)))
            {

                ListElement le = new ListElement(Convert.ToString((int)(ePhoneTypes)value), ITO_StringConverter.PhoneTypeToStr((ePhoneTypes)value));
                cbPhoneType.Items.Add(le);
            }
        }