コード例 #1
0
        private void Form_Main_Load(object sender, EventArgs e)
        {
            try
            {
                string[] args = new string[] { "/update" };

                if (args.Length > 0)
                {
                    foreach (string s in args)
                    {
                        if (s == "/update")
                        {
                            UpdateLDAPObjects();
                            Application.Exit();
                        }
                    }
                }

                dtOrganizationalUnits = OrganizationalUnit.CreateOrganizationalUnitDataTable();
                dtOrganizationalUnits.ReadXml(Application.StartupPath + "\\LDAPOU.xml");
                if (dtOrganizationalUnits.Rows.Count > 0)
                {
                    foreach (DataRow dr in dtOrganizationalUnits.Rows)
                    {
                        ListViewItem item = new ListViewItem();
                        item.Text = dr["Name"].ToString();
                        item.SubItems.Add(dr["IsOff"].ToString());
                        item.SubItems.Add(dr["CompId"].ToString());
                        item.SubItems.Add(dr["DeptId"].ToString());
                        item.SubItems.Add(dr["LDAPObjectString"].ToString());
                        listView1.Items.Add(item);
                    }
                }


                //GetOrganizationalUnitObjects("OU=Suzhou,OU=帝商科技,DC=regalscan,DC=com");
                //GetOrganizationalUnitObjects("OU=系統部,OU=帝商科技,DC=regalscan,DC=com");
                //GetOrganizationalUnitObjects("OU=業務部,OU=帝商科技,DC=regalscan,DC=com");
                //GetOrganizationalUnitObjects("OU=管理部,OU=帝商科技,DC=regalscan,DC=com");
                //GetOrganizationalUnitObjects("OU=財務部,OU=帝商科技,DC=regalscan,DC=com");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #2
0
        private void UpdateLDAPObjects()
        {
            dtOrganizationalUnits = OrganizationalUnit.CreateOrganizationalUnitDataTable();
            dtOrganizationalUnits.ReadXml(Application.StartupPath + "\\LDAPOU.xml");
            if (dtOrganizationalUnits.Rows.Count > 0)
            {
                foreach (DataRow dr in dtOrganizationalUnits.Rows)
                {
                    string xIsOff  = dr["IsOff"].ToString() == "Y" ? "Y" : "N";
                    string xCompId = dr["CompId"].ToString();
                    string xDeptId = dr["DeptId"].ToString();
                    GetOrganizationalUnitObjects(dr["LDAPObjectString"].ToString(), xIsOff, xCompId, xDeptId);
                }
            }

            if (LdapUsers.Count > 0)
            {
                RGDBManager.ConnectionString = Properties.Settings.Default.RegalAttendance;
#if DEBUG
                RGDBManager.ConnectionString = Properties.Settings.Default.RegalAttendanceTest;
#endif
                RGDBManager.ProviderName = "System.Data.SqlClient";
                if (LdapUsers.Count > 0)
                {
                    try
                    {
                        RGDBManager.BeginTranscation();

                        foreach (LDAPUser user in LdapUsers)
                        {
                            if (int.Parse(RGDBManager.ExecuteScalar("SELECT COUNT(*) FROM LDAPUsers WHERE objectGUID=@objectGUID",
                                                                    new DbParameter[] { RGDBManager.CreateParameter("@objectGUID", DbType.Guid, user.objectGUID) }).ToString()) > 0)
                            {
                                RGDBManager.ExecuteNonQuery("UPDATE LDAPUsers SET Domain=@Domain,sAMAccountName=@sAMAccountName,sAMAccountType=@sAMAccountType,ObjectClass=@ObjectClass,givenName=@givenName,sn=@sn,displayName=@displayName,description=@description,mail=@mail,userAccountControl=@userAccountControl,userPrincipleName=@userPrincipleName,Path=@Path,DN=@DN,CN=@CN,IsOff=@IsOff,CompId=@CompId,DeptId=@DeptId,ERP_UID=@ERP_UID WHERE objectGUID=@objectGUID",
                                                            new DbParameter[] {
                                    RGDBManager.CreateParameter("@DomainAccount", DbType.String, user.DomainAccount),
                                    RGDBManager.CreateParameter("@Domain", DbType.String, user.Domain),
                                    RGDBManager.CreateParameter("@objectGUID", DbType.Guid, user.objectGUID),
                                    RGDBManager.CreateParameter("@sAMAccountName", DbType.String, user.sAMAccountName),
                                    RGDBManager.CreateParameter("@sAMAccountType", DbType.String, user.sAMAccountType),
                                    RGDBManager.CreateParameter("@ObjectClass", DbType.String, user.ObjectClass),
                                    RGDBManager.CreateParameter("@givenName", DbType.String, user.givenName),
                                    RGDBManager.CreateParameter("@sn", DbType.String, user.sn),
                                    RGDBManager.CreateParameter("@displayName", DbType.String, user.displayName),
                                    RGDBManager.CreateParameter("@description", DbType.String, user.description),
                                    RGDBManager.CreateParameter("@mail", DbType.String, user.mail),
                                    RGDBManager.CreateParameter("@userAccountControl", DbType.String, user.userAccountControl),
                                    RGDBManager.CreateParameter("@userPrincipleName", DbType.String, user.userPrincipleName),
                                    RGDBManager.CreateParameter("@Path", DbType.String, user.Path),
                                    RGDBManager.CreateParameter("@DN", DbType.String, user.DN),
                                    RGDBManager.CreateParameter("@CN", DbType.String, user.CN),
                                    RGDBManager.CreateParameter("@IsOff", DbType.String, user.IsOff),
                                    RGDBManager.CreateParameter("@CompId", DbType.String, user.CompId),
                                    RGDBManager.CreateParameter("@DeptId", DbType.String, user.DeptId),
                                    RGDBManager.CreateParameter("@ERP_UID", DbType.String, user.EmployeeId)
                                });
                            }
                            else
                            {
                                RGDBManager.ExecuteNonQuery("INSERT INTO LDAPUsers(DomainAccount,Domain,objectGUID,sAMAccountName,sAMAccountType,ObjectClass,givenName,sn,displayName,description,mail,userAccountControl,userPrincipleName,Path,DN,CN,IsOff,CompId,DeptId,ERP_UID)VALUES(@DomainAccount,@Domain,@objectGUID,@sAMAccountName,@sAMAccountType,@ObjectClass,@givenName,@sn,@displayName,@description,@mail,@userAccountControl,@userPrincipleName,@Path,@DN,@CN,@IsOff,@CompId,@DeptId,@ERP_UID)",
                                                            new DbParameter[] {
                                    RGDBManager.CreateParameter("@DomainAccount", DbType.String, user.DomainAccount),
                                    RGDBManager.CreateParameter("@Domain", DbType.String, user.Domain),
                                    RGDBManager.CreateParameter("@objectGUID", DbType.Guid, user.objectGUID),
                                    RGDBManager.CreateParameter("@sAMAccountName", DbType.String, user.sAMAccountName),
                                    RGDBManager.CreateParameter("@sAMAccountType", DbType.String, user.sAMAccountType),
                                    RGDBManager.CreateParameter("@ObjectClass", DbType.String, user.ObjectClass),
                                    RGDBManager.CreateParameter("@givenName", DbType.String, user.givenName),
                                    RGDBManager.CreateParameter("@sn", DbType.String, user.sn),
                                    RGDBManager.CreateParameter("@displayName", DbType.String, user.displayName),
                                    RGDBManager.CreateParameter("@description", DbType.String, user.description),
                                    RGDBManager.CreateParameter("@mail", DbType.String, user.mail),
                                    RGDBManager.CreateParameter("@userAccountControl", DbType.String, user.userAccountControl),
                                    RGDBManager.CreateParameter("@userPrincipleName", DbType.String, user.userPrincipleName),
                                    RGDBManager.CreateParameter("@Path", DbType.String, user.Path),
                                    RGDBManager.CreateParameter("@DN", DbType.String, user.DN),
                                    RGDBManager.CreateParameter("@CN", DbType.String, user.CN),
                                    RGDBManager.CreateParameter("@IsOff", DbType.String, user.IsOff),
                                    RGDBManager.CreateParameter("@CompId", DbType.String, user.CompId),
                                    RGDBManager.CreateParameter("@DeptId", DbType.String, user.DeptId),
                                    RGDBManager.CreateParameter("@ERP_UID", DbType.String, user.EmployeeId)
                                });
                            }
                        }

                        RGDBManager.CommitTranscation();
                    }
                    catch
                    {
                        RGDBManager.RollBackTranscation();
                        throw;
                    }
                }
            }
        }