예제 #1
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]
            }
        }
예제 #2
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");
        }