protected void Page_Load(object sender, EventArgs e)
        {
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        AccountRequest oAccountRequest = new AccountRequest(intProfile, dsn);
                        Requests       oRequest        = new Requests(intProfile, dsn);
                        Users          oUser           = new Users(intProfile, dsn);
                        DataSet        ds      = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
                        Domains        oDomain = new Domains(intProfile, dsn);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string         strUser   = ds.Tables[0].Rows[0]["username"].ToString();
                            int            intDomain = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                            int            intEnv    = Int32.Parse(oDomain.Get(intDomain, "environment"));
                            int            intUser   = oRequest.GetUser(intRequest);
                            AD             oAD       = new AD(intProfile, dsn, intEnv);
                            DirectoryEntry oEntry    = oAD.UserSearch(strUser);
                            if (oEntry == null)
                            {
                                strResult = "";
                            }
                            else
                            {
                                if (oAD.IsLocked(oEntry) == true)
                                {
                                    strResult = oAD.Unlock(oEntry);
                                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Unlock", strResult, "Account " + strUser + " was successfully unlocked", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                                    if (strResult == "")
                                    {
                                        strResult = "<p>Account " + strUser + " was unlocked</p>";
                                    }
                                }
                                else
                                {
                                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Unlock", "", "Account " + strUser + " was not locked", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                                    strResult = "<p>Account " + strUser + " was not locked</p>";
                                }
                            }
                        }
                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td><img src=\"/images/bigCheck.gif\" border=\"0\" align=\"absmiddle\"/></td><td class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td><img src=\"/images/bigError.gif\" border=\"0\" align=\"absmiddle\"/></td><td class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td><img src=\"/images/bigCheck.gif\" border=\"0\" align=\"absmiddle\"/></td><td class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }
        protected void btnApprove_Click(Object Sender, EventArgs e)
        {
            oResourceRequest.UpdateWorkflowHours(intResourceWorkflow);
            DataSet ds             = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
            int     intUser        = oRequest.GetUser(intRequest);
            DataSet dsParameters   = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
            string  strMaintenance = ds.Tables[0].Rows[0]["maintenance"].ToString();
            string  strUser        = ds.Tables[0].Rows[0]["username"].ToString();
            int     intDomain      = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
            Domains oDomain        = new Domains(intProfile, dsn);

            intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
            AD             oAD       = new AD(intProfile, dsn, intDomain);
            Variables      oVariable = new Variables(intDomain);
            DirectoryEntry oEntry    = oAD.UserSearch(strUser);

            if (oEntry != null)
            {
                switch (strMaintenance)
                {
                case "DISABLE":
                    // Account Disable
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Disable", oAD.Enable(oEntry, false), "Account " + strUser + " was successfully disabled", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "UNLOCK":
                    // Account Unlock
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Unlock", oAD.Unlock(oEntry), "Account " + strUser + " was successfully unlocked", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "ENABLE":
                    // Account Enable
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Enable", oAD.Enable(oEntry, true), "Account " + strUser + " was successfully enabled", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "EMAIL":
                    // Account Email
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Email", oAD.CreateMailbox(oEntry), "Account " + strUser + " was successfully created a mailbox", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "MOVE":
                    // Account Move
                    string strPath = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Move", oAD.MoveAccount(oEntry, strPath), "Account " + strUser + " was successfully moved", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "PASSWORD":
                    // Account Password Change
                    Encryption oEncrypt    = new Encryption();
                    string     strPassword = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Password Change", oAD.SetPassword(oEntry, oEncrypt.Decrypt(strPassword, "adpass")), "The password for account " + strUser + " was successfully changed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "COPY":
                    // Account Copy
                    string strID    = txtID.Text;
                    string strFirst = txtFirst.Text;
                    string strLast  = txtLast.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Copy", oAD.CreateUser(strID, strFirst, strLast, txtPassword.Text, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.UserOU()), "Account " + strUser + " was successfully copied", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    foreach (ListItem oList in chkGroups.Items)
                    {
                        if (oList.Selected == true)
                        {
                            oRequest.AddResult(intRequest, intItem, intNumber, "Group Membership", oAD.JoinGroup(strID, oList.Value, 0), "Account " + strUser + " was successfully added to the group " + oList.Value, intEnvironment, (oService.Get(intService, "notify_client") == "1"), "");
                        }
                    }
                    break;

                case "DELETE":
                    // Account Deletion
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Deletion", oAD.Delete(oEntry), "Account " + strUser + " was successfully deleted", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "RENAME":
                    // Account Rename
                    string strI = txtID.Text;
                    string strF = txtFirst.Text;
                    string strL = txtLast.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Account Rename", oAD.Rename(oEntry, strI, strF, strL), "Account " + strUser + " was successfully renamed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;
                }
            }
            oAccountRequest.UpdateMaintenance(intRequest, intItem, intNumber, 1, txtComments.Text);
            Complete();
        }
        protected void btnApprove_Click(Object Sender, EventArgs e)
        {
            oResourceRequest.UpdateWorkflowHours(intResourceWorkflow);
            DataSet ds             = oGroupRequest.GetMaintenance(intRequest, intItem, intNumber);
            int     intUser        = oRequest.GetUser(intRequest);
            DataSet dsParameters   = oGroupRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
            string  strMaintenance = ds.Tables[0].Rows[0]["maintenance"].ToString();
            string  strGroup       = ds.Tables[0].Rows[0]["name"].ToString();
            int     intDomain      = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
            Domains oDomain        = new Domains(intProfile, dsn);

            intDomain = Int32.Parse(oDomain.Get(intDomain, "environment"));
            AD             oAD       = new AD(intProfile, dsn, intDomain);
            Variables      oVariable = new Variables(intDomain);
            DirectoryEntry oEntry    = oAD.GroupSearch(strGroup);

            if (oEntry != null)
            {
                switch (strMaintenance)
                {
                case "MOVE":
                    // Group Move
                    string strPath = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Move", oAD.MoveGroup(oEntry, strPath), "Group " + strGroup + " was successfully moved", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "COPY":
                    // Group Copy
                    string strID     = txtID.Text;
                    string strScope2 = dsParameters.Tables[0].Rows[1]["value"].ToString();
                    if (strScope2 == "Domain Local")
                    {
                        strScope2 = "DLG";
                    }
                    if (strScope2 == "Global")
                    {
                        strScope2 = "GG";
                    }
                    if (strScope2 == "Universal")
                    {
                        strScope2 = "UG";
                    }
                    string strType2 = dsParameters.Tables[0].Rows[2]["value"].ToString();
                    if (strType2 == "Security")
                    {
                        strType2 = "S";
                    }
                    if (strType2 == "Distribution")
                    {
                        strType2 = "D";
                    }
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Copy", oAD.CreateGroup(strID, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.GroupOU(), strScope2, strType2), "Group " + strGroup + " was successfully copied", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    foreach (ListItem oList in chkUsers.Items)
                    {
                        if (oList.Selected == true)
                        {
                            oRequest.AddResult(intRequest, intItem, intNumber, "Group Membership", oAD.JoinGroup(oList.Value, strID, 0), "Account " + oList.Value + " was successfully added to the group " + strGroup, intEnvironment, (oService.Get(intService, "notify_client") == "1"), "");
                        }
                    }
                    break;

                case "DELETE":
                    // Group Deletion
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Deletion", oAD.Delete(oEntry), "Group " + strGroup + " was successfully deleted", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "RENAME":
                    // Group Rename
                    string strI = txtID.Text;
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Rename", oAD.Rename(oEntry, strI, "", ""), "Group " + strGroup + " was successfully renamed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;

                case "CHANGE":
                    // Group Change
                    string strScope3 = dsParameters.Tables[0].Rows[0]["value"].ToString();
                    if (strScope3 == "Domain Local")
                    {
                        strScope3 = "DLG";
                    }
                    if (strScope3 == "Global")
                    {
                        strScope3 = "GG";
                    }
                    if (strScope3 == "Universal")
                    {
                        strScope3 = "UG";
                    }
                    string strType3 = dsParameters.Tables[0].Rows[1]["value"].ToString();
                    if (strType3 == "Security")
                    {
                        strType3 = "S";
                    }
                    if (strType3 == "Distribution")
                    {
                        strType3 = "D";
                    }
                    oRequest.AddResult(intRequest, intItem, intNumber, "Group Change", oAD.Change(oEntry, strScope3, strType3), "Group " + strGroup + " was successfully changed", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                    break;
                }
            }
            else if (strMaintenance == "CREATE")
            {
                // Group Creation
                string strScope1 = dsParameters.Tables[0].Rows[0]["value"].ToString();
                if (strScope1 == "Domain Local")
                {
                    strScope1 = "DLG";
                }
                if (strScope1 == "Global")
                {
                    strScope1 = "GG";
                }
                if (strScope1 == "Universal")
                {
                    strScope1 = "UG";
                }
                string strType1 = dsParameters.Tables[0].Rows[1]["value"].ToString();
                if (strType1 == "Security")
                {
                    strType1 = "S";
                }
                if (strType1 == "Distribution")
                {
                    strType1 = "D";
                }
                oRequest.AddResult(intRequest, intItem, intNumber, "Group Creation", oAD.CreateGroup(txtID.Text, "", "Created by ClearView - " + DateTime.Now.ToShortDateString(), oVariable.GroupOU(), strScope1, strType1), "Group " + strGroup + " was successfully created", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
            }
            oGroupRequest.UpdateMaintenance(intRequest, intItem, intNumber, 1, txtComments.Text);
            Complete();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            intProfile = Int32.Parse(Request.Cookies["profileid"].Value);
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        Asset    oAsset   = new Asset(intProfile, dsnAsset);
                        Requests oRequest = new Requests(intProfile, dsn);
                        Users    oUser    = new Users(intProfile, dsn);
                        oAsset.UpdateDecommission(intRequest, intItem, intNumber, 1);
                        strResult += "<p>The server(s) were successfully queued for decommission</p>";
                        strError   = "";
                        oRequest.AddResult(intRequest, intItem, intNumber, "Server Decommission", strError, strResult, intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intProfile));
                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }
Beispiel #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool          boolSuccess = true;
                        StringBuilder sbResult    = new StringBuilder(oService.GetName(intService) + " Completed");
                        StringBuilder sbError     = new StringBuilder(oService.GetName(intService) + " Error");

                        // ********* BEGIN PROCESSING **************
                        AccountRequest oAccountRequest = new AccountRequest(intProfile, dsn);
                        Requests       oRequest        = new Requests(intProfile, dsn);
                        Users          oUser           = new Users(intProfile, dsn);
                        DataSet        ds      = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
                        Domains        oDomain = new Domains(intProfile, dsn);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string         strUser      = ds.Tables[0].Rows[0]["username"].ToString();
                            int            intDomain    = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                            int            intEnv       = Int32.Parse(oDomain.Get(intDomain, "environment"));
                            int            intUser      = oRequest.GetUser(intRequest);
                            DataSet        dsParameters = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
                            AD             oAD          = new AD(intProfile, dsn, intEnv);
                            DirectoryEntry oEntry       = oAD.UserSearch(strUser);

                            if (oEntry == null)
                            {
                                sbResult = new StringBuilder();
                            }
                            else
                            {
                                sbError = new StringBuilder();

                                string strFirstOld = "";
                                if (oEntry.Properties.Contains("givenname") == true)
                                {
                                    strFirstOld = oEntry.Properties["givenname"].Value.ToString();
                                }
                                string strLastOld = "";
                                if (oEntry.Properties.Contains("sn") == true)
                                {
                                    strLastOld = oEntry.Properties["sn"].Value.ToString();
                                }
                                string strFirstNew        = dsParameters.Tables[0].Rows[0]["value"].ToString();
                                string strLastNew         = dsParameters.Tables[0].Rows[1]["value"].ToString();
                                string strEnable          = dsParameters.Tables[0].Rows[2]["value"].ToString();
                                string strUnlock          = dsParameters.Tables[0].Rows[3]["value"].ToString();
                                string strGroupsRequested = dsParameters.Tables[0].Rows[4]["value"].ToString();
                                if (strFirstOld != strFirstNew || strLastOld != strLastNew)
                                {
                                    if (strFirstOld != strFirstNew && strLastOld != strLastNew)
                                    {
                                        oEntry.Properties["givenname"].Value   = strFirstNew;
                                        oEntry.Properties["sn"].Value          = strLastNew;
                                        oEntry.Properties["displayname"].Value = strLastNew + ", " + strFirstNew;
                                        oEntry.CommitChanges();
                                        sbResult.Append("<p>The first name and last name for account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully updated</p>");
                                    }
                                    else if (strFirstOld != strFirstNew)
                                    {
                                        oEntry.Properties["givenname"].Value   = strFirstNew;
                                        oEntry.Properties["displayname"].Value = strLastNew + ", " + strFirstNew;
                                        oEntry.CommitChanges();
                                        sbResult.Append("<p>The first name for account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully updated</p>");
                                    }
                                    else
                                    {
                                        oEntry.Properties["sn"].Value          = strLastNew;
                                        oEntry.Properties["displayname"].Value = strLastNew + ", " + strFirstNew;
                                        oEntry.CommitChanges();
                                        sbResult.Append("<p>The last name for account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully updated</p>");
                                    }
                                }
                                if (strEnable == "1")
                                {
                                    strEnable = oAD.Enable(oEntry, true);
                                    if (strEnable == "")
                                    {
                                        sbResult.Append("<p>The user account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully enabled</p>");
                                    }
                                    else
                                    {
                                        sbError.Append("<p>The user account ");
                                        sbError.Append(strUser);
                                        sbError.Append(" was NOT successfully enabled</p>");
                                    }
                                }
                                if (strUnlock == "1")
                                {
                                    strUnlock = oAD.Unlock(oEntry);
                                    if (strUnlock == "")
                                    {
                                        sbResult.Append("<p>The user account ");
                                        sbResult.Append(strUser);
                                        sbResult.Append(" was successfully unlocked</p>");
                                    }
                                    else
                                    {
                                        sbError.Append("<p>The user account ");
                                        sbError.Append(strUser);
                                        sbError.Append(" was NOT successfully unlocked</p>");
                                    }
                                }

                                string   strGroupsExist = oAD.GetGroups(oEntry);
                                string[] strGroupRequested;
                                string[] strGroupExist;
                                char[]   strSplit = { ';' };
                                strGroupRequested = strGroupsRequested.Split(strSplit);
                                strGroupExist     = strGroupsExist.Split(strSplit);

                                // Add Groups
                                for (int ii = 0; ii < strGroupRequested.Length; ii++)
                                {
                                    if (strGroupRequested[ii].Trim() != "")
                                    {
                                        bool boolExist = false;
                                        for (int jj = 0; jj < strGroupExist.Length; jj++)
                                        {
                                            if (strGroupExist[jj].Trim() != "" && strGroupRequested[ii].Trim() == strGroupExist[jj].Trim())
                                            {
                                                boolExist = true;
                                                break;
                                            }
                                        }
                                        if (boolExist == false)
                                        {
                                            // Add the group
                                            string strJoin = oAD.JoinGroup(strUser, strGroupRequested[ii].Trim(), 0);
                                            if (strJoin == "")
                                            {
                                                sbResult.Append("<p>The user ");
                                                sbResult.Append(strUser);
                                                sbResult.Append(" was successfully joined to the group ");
                                                sbResult.Append(strGroupRequested[ii].Trim());
                                                sbResult.Append("</p>");
                                            }
                                            else
                                            {
                                                sbError.Append("<p>The user ");
                                                sbError.Append(strUser);
                                                sbError.Append(" was NOT successfully joined to the group ");
                                                sbError.Append(strGroupRequested[ii].Trim());
                                                sbError.Append(" : ");
                                                sbError.Append(strJoin);
                                                sbError.Append("</p>");
                                            }
                                        }
                                    }
                                }
                                // Remove Groups
                                for (int ii = 0; ii < strGroupExist.Length; ii++)
                                {
                                    if (strGroupExist[ii].Trim() != "")
                                    {
                                        bool boolExist = false;
                                        for (int jj = 0; jj < strGroupRequested.Length; jj++)
                                        {
                                            if (strGroupRequested[jj].Trim() != "" && strGroupExist[ii].Trim() == strGroupRequested[jj].Trim())
                                            {
                                                boolExist = true;
                                                break;
                                            }
                                        }
                                        if (boolExist == false)
                                        {
                                            // Remove the group
                                            string strJoin = oAD.RemoveGroup(strUser, strGroupExist[ii].Trim());
                                            if (strJoin == "")
                                            {
                                                sbResult.Append("<p>The user ");
                                                sbResult.Append(strUser);
                                                sbResult.Append(" was successfully removed from the group ");
                                                sbResult.Append(strGroupExist[ii].Trim());
                                                sbResult.Append("</p>");
                                            }
                                            else
                                            {
                                                sbError.Append("<p>The user ");
                                                sbError.Append(strUser);
                                                sbError.Append(" was NOT successfully removed from the group ");
                                                sbError.Append(strGroupExist[ii].Trim());
                                                sbError.Append(" : ");
                                                sbError.Append(strJoin);
                                                sbError.Append("</p>");
                                            }
                                        }
                                    }
                                }
                                oRequest.AddResult(intRequest, intItem, intNumber, "Account Modification", sbError.ToString(), sbResult.ToString(), intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                            }
                        }

                        if (sbResult.ToString() == "")
                        {
                            boolSuccess = false;
                        }

                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + sbResult.ToString() + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + sbError.ToString() + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }
Beispiel #6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        DNS oDNS = new DNS(intProfile, dsn);
                        strResult = "";
                        strError  = "";
                        if (intEnvironment < 3)
                        {
                            intEnvironment = 3;
                        }
                        Variables oVariable = new Variables(intEnvironment);
                        Requests  oRequest  = new Requests(intProfile, dsn);
                        Users     oUser     = new Users(intProfile, dsn);
                        DataSet   ds        = oDNS.GetDNS(intRequest, intItem, intNumber);
                        Domains   oDomain   = new Domains(intProfile, dsn);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string strAction       = ds.Tables[0].Rows[0]["action"].ToString();
                            string strNameCurrent  = ds.Tables[0].Rows[0]["name_current"].ToString();
                            string strIPCurrent    = ds.Tables[0].Rows[0]["ip_current"].ToString();
                            string strAliasCurrent = ds.Tables[0].Rows[0]["alias_current"].ToString();
                            string strNameNew      = ds.Tables[0].Rows[0]["name_new"].ToString();
                            string strIPNew        = ds.Tables[0].Rows[0]["ip_new"].ToString();
                            string strAliasNew     = ds.Tables[0].Rows[0]["alias_new"].ToString();
                            string strDomain       = ds.Tables[0].Rows[0]["domain"].ToString();
                            string strObject       = ds.Tables[0].Rows[0]["value"].ToString();
                            int    intUser         = oRequest.GetUser(intRequest);

                            // Connect to DNS to process the request
                            System.Net.NetworkCredential oCredentials = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain());
                            ClearViewWebServices         oWebService  = new ClearViewWebServices();
                            oWebService.Timeout     = Int32.Parse(ConfigurationManager.AppSettings["WS_TIMEOUT"]);
                            oWebService.Credentials = oCredentials;
                            oWebService.Url         = oVariable.WebServiceURL();
                            Settings oSetting        = new Settings(0, dsn);
                            bool     boolDNS_QIP     = oSetting.IsDNS_QIP();
                            bool     boolDNS_Bluecat = oSetting.IsDNS_Bluecat();

                            string strWebServiceResult = "";

                            switch (strAction)
                            {
                            case "CREATE":
                                if (strIPNew != "" && strNameNew != "")
                                {
                                    if (boolDNS_QIP == true)
                                    {
                                        strWebServiceResult = oWebService.CreateDNSforPNC(strIPNew, strNameNew, strObject, strAliasNew, oVariable.DNS_Domain(), oVariable.DNS_NameService(), oVariable.DNS_DynamicDNSUpdate(), intProfile, 0, true);
                                        if (strWebServiceResult == "SUCCESS")
                                        {
                                            strResult += "<p>The following record was successfully created in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                        }
                                        else if (strWebServiceResult.StartsWith("***DUPLICATE") == true)
                                        {
                                            strResult += "<p>The following record was already created in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                        }
                                        else if (strWebServiceResult.StartsWith("***CONFLICT") == true)
                                        {
                                            strError += "<p>A CONFLICT occurred when attempting to create the following record in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Conflict Message:</p><p>" + strWebServiceResult + "</p>";
                                        }
                                        else
                                        {
                                            strError += "<p>An ERROR occurred when attempting to create the following record in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Error Message:</p><p>" + strWebServiceResult + "</p>";
                                        }
                                    }
                                    if (boolDNS_Bluecat == true)
                                    {
                                        strWebServiceResult = oWebService.CreateBluecatDNS(strIPNew, strNameNew, strNameNew, "");
                                        if (strWebServiceResult == "SUCCESS")
                                        {
                                            strResult += "<p>The following record was successfully created in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                        }
                                        else if (strWebServiceResult.StartsWith("***DUPLICATE") == true)
                                        {
                                            strResult += "<p>The following record was already created in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                        }
                                        else if (strWebServiceResult.StartsWith("***CONFLICT") == true)
                                        {
                                            strError += "<p>A CONFLICT occurred when attempting to create the following record in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Conflict Message:</p><p>" + strWebServiceResult + "</p>";
                                        }
                                        else
                                        {
                                            strError += "<p>An ERROR occurred when attempting to create the following record in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Error Message:</p><p>" + strWebServiceResult + "</p>";
                                        }
                                    }
                                }
                                else
                                {
                                    strError = "<p>Invalid Parameters...</p>";
                                }

                                break;

                            case "UPDATE":
                                string strIP    = (strIPNew != "" ? strIPNew : strIPCurrent);
                                string strName  = (strNameNew != "" ? strNameNew : strNameCurrent);
                                string strAlias = (((strAliasCurrent != "" && strAliasNew == "") || strAliasNew != "") ? strAliasNew : strAliasCurrent);
                                if (strObject == "")
                                {
                                    strObject = "Server";
                                }
                                if (boolDNS_QIP == true)
                                {
                                    strWebServiceResult = oWebService.UpdateDNSforPNC(strIP, strName, strObject, strAlias, oVariable.DNS_Domain(), oVariable.DNS_NameService(), oVariable.DNS_DynamicDNSUpdate(), intProfile, 0, true);
                                    if (strWebServiceResult == "SUCCESS")
                                    {
                                        strResult += "<p>The following record was successfully updated in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                    }
                                    else if (strWebServiceResult.StartsWith("***DUPLICATE") == true)
                                    {
                                        strResult += "<p>The following record was already updated in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                    }
                                    else if (strWebServiceResult.StartsWith("***CONFLICT") == true)
                                    {
                                        strError += "<p>A CONFLICT occurred when attempting to update the following record in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Conflict Message:</p><p>" + strWebServiceResult + "</p>";
                                    }
                                    else
                                    {
                                        strError += "<p>An ERROR occurred when attempting to update the following record in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Error Message:</p><p>" + strWebServiceResult + "</p>";
                                    }
                                }
                                if (boolDNS_Bluecat == true)
                                {
                                    strWebServiceResult = oWebService.UpdateBluecatDNS(strIP, strName, strNameNew, "");
                                    if (strWebServiceResult == "SUCCESS")
                                    {
                                        strResult += "<p>The following record was successfully updated in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                    }
                                    else if (strWebServiceResult.StartsWith("***DUPLICATE") == true)
                                    {
                                        strResult += "<p>The following record was already updated in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                    }
                                    else if (strWebServiceResult.StartsWith("***CONFLICT") == true)
                                    {
                                        strError += "<p>A CONFLICT occurred when attempting to update the following record in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Conflict Message:</p><p>" + strWebServiceResult + "</p>";
                                    }
                                    else
                                    {
                                        strError += "<p>An ERROR occurred when attempting to update the following record in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Error Message:</p><p>" + strWebServiceResult + "</p>";
                                    }
                                }
                                break;

                            case "DELETE":
                                if (boolDNS_QIP == true)
                                {
                                    if (strIPCurrent != "")
                                    {
                                        strWebServiceResult = oWebService.DeleteDNSforPNC(strIPCurrent, "", intProfile, true);
                                    }
                                    else if (strNameCurrent != "")
                                    {
                                        strWebServiceResult = oWebService.DeleteDNSforPNC("", strNameCurrent, intProfile, true);
                                    }

                                    if (strWebServiceResult == "SUCCESS")
                                    {
                                        strResult += "<p>The following record was successfully deleted in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                    }
                                    else
                                    {
                                        strError += "<p>An ERROR occurred when attempting to delete the following record in QIP DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Error Message:</p><p>" + strWebServiceResult + "</p>";
                                    }
                                }
                                if (boolDNS_Bluecat == true)
                                {
                                    if (strIPCurrent != "")
                                    {
                                        strWebServiceResult = oWebService.DeleteBluecatDNS(strIPCurrent, "", false, false);
                                    }
                                    else if (strNameCurrent != "")
                                    {
                                        strWebServiceResult = oWebService.DeleteBluecatDNS("", strNameCurrent, false, false);
                                    }

                                    if (strWebServiceResult == "SUCCESS")
                                    {
                                        strResult += "<p>The following record was successfully deleted in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p>";
                                    }
                                    else
                                    {
                                        strError += "<p>An ERROR occurred when attempting to delete the following record in BlueCat DNS...</p><p>" + oDNS.GetDNSBody(intRequest, intItem, intNumber, true, intEnvironment) + "</p><p>Error Message:</p><p>" + strWebServiceResult + "</p>";
                                    }
                                }
                                break;
                            }
                            if (strResult != "")
                            {
                                oRequest.AddResult(intRequest, intItem, intNumber, oService.GetName(intService), "", strResult, intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                            }
                            else if (strError != "")
                            {
                                oRequest.AddResult(intRequest, intItem, intNumber, oService.GetName(intService), strError, "", intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                            }
                            oDNS.UpdateDNSCompleted(intRequest, intItem, intNumber);
                        }
                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td><img src=\"/images/bigCheck.gif\" border=\"0\" align=\"absmiddle\"/></td><td class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td><img src=\"/images/bigError.gif\" border=\"0\" align=\"absmiddle\"/></td><td class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td><img src=\"/images/bigCheck.gif\" border=\"0\" align=\"absmiddle\"/></td><td class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            intProfile = Int32.Parse(Request.Cookies["profileid"].Value);
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);

            oFunction = new Functions(intProfile, dsn, intEnvironment);
            oUser     = new Users(intProfile, dsn);
            oRequest  = new Requests(intProfile, dsn);

            int     intRequest = Int32.Parse(Request.QueryString["rid"]);
            string  strStatus  = oServiceRequest.Get(intRequest, "checkout");
            DataSet dsItems    = oRequestItem.GetForms(intRequest);

            int intItem    = 0;
            int intService = 0;
            int intNumber  = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        bool boolIsServerVMWare = false;
                        bool boolIsNotManual    = false;
                        int  intServer          = 0;
                        int  intModel           = 0;

                        Customized oCustomized   = new Customized(intProfile, dsn);
                        DataSet    dsDecomServer = oCustomized.GetDecommissionServer(intRequest, intItem, intNumber);
                        if (dsDecomServer.Tables[0].Rows.Count > 0)
                        {
                            intServer = Int32.Parse(dsDecomServer.Tables[0].Rows[0]["serverid"].ToString());
                            DateTime datPower    = DateTime.Parse(dsDecomServer.Tables[0].Rows[0]["poweroff"].ToString());
                            string   strPowerNew = dsDecomServer.Tables[0].Rows[0]["poweroff_new"].ToString();
                            string   strName     = dsDecomServer.Tables[0].Rows[0]["servername"].ToString();
                            Asset    oAsset      = new Asset(intProfile, dsnAsset);
                            Servers  oServers    = new Servers(intProfile, dsn);
                            DataSet  dsAssets    = oServers.GetAssets(intServer);

                            if (intServer > 0)
                            {
                                DataSet          dsServer          = oServers.Get(intServer);
                                ModelsProperties oModelsProperties = new ModelsProperties(intProfile, dsn);
                                if (dsServer.Tables[0].Rows[0]["modelid"] != DBNull.Value)
                                {
                                    intModel = Int32.Parse(dsServer.Tables[0].Rows[0]["modelid"].ToString());
                                }
                                if (intModel > 0 && oModelsProperties.IsTypeVMware(intModel) == true)
                                {
                                    boolIsServerVMWare = true;
                                }
                                boolIsNotManual = true;
                            }
                            // VMWARE
                            if (boolIsNotManual == true)
                            {
                                bool boolUnique = true;
                                foreach (DataRow drAsset in dsAssets.Tables[0].Rows)
                                {
                                    if (drAsset["latest"].ToString() == "1" || drAsset["dr"].ToString() == "1")
                                    {
                                        int intAsset = Int32.Parse(drAsset["assetid"].ToString());
                                        boolUnique = oAsset.AddDecommission(intRequest, intItem, intNumber, intAsset, intProfile, dsDecomServer.Tables[0].Rows[0]["reason"].ToString(), datPower, strName + (drAsset["dr"].ToString() == "1" ? "-DR" : ""), (drAsset["dr"].ToString() == "1" ? 1 : 0), strPowerNew);
                                        if (boolUnique == false)
                                        {
                                            break;
                                        }
                                    }
                                }
                                if (boolUnique == true || strPowerNew != "")
                                {
                                    oAsset.UpdateDecommission(intRequest, intItem, intNumber, 1);
                                    strResult += "<p>The server " + strName + " was successfully queued for decommission on " + (strPowerNew != "" ? strPowerNew : datPower.ToShortDateString()) + "</p>";
                                    strError   = "";
                                }
                                else
                                {
                                    strError = "<p>The server " + strName + " has already been queued for decommission</p>";
                                }
                                //Send service center notification
                                //"Assignment: Complete and Close"
                                # region "Send Service Center Notification"
                                ResourceRequest oResourceRequest = new ResourceRequest(intProfile, dsn);
                                DataSet         dsRR             = oResourceRequest.GetResourceRequest(intRequest, intItem, intNumber);
                                int             intRRId          = 0;
                                if (dsRR.Tables[0].Rows.Count > 0)
                                {
                                    intRRId = Int32.Parse(dsRR.Tables[0].Rows[0]["id"].ToString());
                                }

                                //int intServerDecommServiceID = Int32.Parse(ConfigurationManager.AppSettings["SERVICEID_SERVER_DECOMMISSION"]);
                                //if (intService == intServerDecommServiceID)
                                //{
                                //    SendServiceCenterNotification(intRequest, intItem, intService, intNumber, 0);
                                //}
                                #endregion
                            }
                            else
                            {
                                // MANUAL (non-automated)
                                double dblHours   = 0.00;
                                int    intDevices = 1;
                                Field  oField     = new Field(intProfile, dsn);

                                strResult += "<p>The server decommission request was submitted for " + strName + ".</p>";
                                strError   = "";

                                string strTable = oField.GetTableName2(intService);
                                if (strTable != "")
                                {
                                    DataSet ds = oField.GetTableServiceRequest(strTable, intRequest.ToString(), intItem.ToString(), intNumber.ToString());
                                    if (ds.Tables[0].Columns.Contains("hours") == true)
                                    {
                                        foreach (DataRow dr in ds.Tables[0].Rows)
                                        {
                                            dblHours += double.Parse(dr["hours"].ToString());
                                        }
                                    }
                                    if (ds.Tables[0].Columns.Contains("devices") == true)
                                    {
                                        foreach (DataRow dr in ds.Tables[0].Rows)
                                        {
                                            intDevices += Int32.Parse(dr["devices"].ToString());
                                        }
                                    }
                                }
                                if (oService.Get(intService, "quantity_is_device") == "1")
                                {
                                    DataSet dsTemp = oService.GetSelected(intRequest, intService);
                                    if (dsTemp.Tables[0].Rows.Count > 0)
                                    {
                                        intDevices = Int32.Parse(dsTemp.Tables[0].Rows[0]["quantity"].ToString());
                                    }
                                }
                                int intResource = oServiceRequest.AddRequest(intRequest, intItem, intService, intDevices, dblHours, 2, intNumber, dsnServiceEditor);
                                if (oServiceRequest.NotifyApproval(intResource, intResourceRequestApprove, intEnvironment, "", dsnServiceEditor) == false)
                                {
                                    oServiceRequest.NotifyTeamLead(intItem, intResource, intAssignPage, intViewPage, intEnvironment, "", dsnServiceEditor, dsnAsset, dsnIP, 0);
                                }

                                oRequest.AddResult(intRequest, intItem, intNumber, "Server Decommission", strError, strResult, intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intProfile));
                            }
                        }
                        else
                        {
                            strResult     = "";
                            dsDecomServer = oCustomized.GetDecommissionServerDeleted(intRequest, intItem, intNumber);
                            string strName = "";
                            if (dsDecomServer.Tables[0].Rows.Count > 0)
                            {
                                strName = dsDecomServer.Tables[0].Rows[0]["servername"].ToString();
                            }
                            if (strName == "")
                            {
                                strError = "<p>One or more of the servers you attempted to decommission have already been queued for decommission</p>";
                            }
                            else
                            {
                                strError = "<p>The server " + strName + " has already been queued for decommission</p>";
                            }
                            oRequestItem.DeleteForms(intRequest, intService, intNumber);
                        }

                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1, (boolIsNotManual?1:0));
                    }
                }
            }
        protected void Page_Load(object sender, EventArgs e)
        {
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        AccountRequest oAccountRequest = new AccountRequest(intProfile, dsn);
                        Requests       oRequest        = new Requests(intProfile, dsn);
                        Users          oUser           = new Users(intProfile, dsn);
                        DataSet        ds      = oAccountRequest.GetMaintenance(intRequest, intItem, intNumber);
                        Domains        oDomain = new Domains(intProfile, dsn);
                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            string         strUser      = ds.Tables[0].Rows[0]["username"].ToString();
                            int            intDomain    = Int32.Parse(ds.Tables[0].Rows[0]["domain"].ToString());
                            int            intEnv       = Int32.Parse(oDomain.Get(intDomain, "environment"));
                            int            intUser      = oRequest.GetUser(intRequest);
                            DataSet        dsParameters = oAccountRequest.GetMaintenanceParameters(intRequest, intItem, intNumber);
                            AD             oAD          = new AD(intProfile, dsn, intEnv);
                            Variables      oVariable    = new Variables(intEnv);
                            DirectoryEntry oEntry       = oAD.UserSearch(strUser);
                            if (oEntry != null)
                            {
                                strResult = "<p>The account " + strUser + " already exists in " + oDomain.Get(intDomain, "name") + "</p>";
                            }
                            else
                            {
                                strError = "";
                                Encryption oEncrypt     = new Encryption();
                                string     strFirst     = dsParameters.Tables[0].Rows[0]["value"].ToString();
                                string     strLast      = dsParameters.Tables[0].Rows[1]["value"].ToString();
                                string     strEmail     = dsParameters.Tables[0].Rows[2]["value"].ToString();
                                string     strTechnical = dsParameters.Tables[0].Rows[3]["value"].ToString();
                                string     strPassword  = oEncrypt.Decrypt(dsParameters.Tables[0].Rows[4]["value"].ToString(), "adpass");
                                if (strTechnical == "1")
                                {
                                    strResult = oAD.CreateUser(strUser, strFirst, strLast, strPassword, "", "Created By ClearView on " + DateTime.Today.ToShortDateString() + Environment.NewLine + "Requested by " + oUser.GetFullName(intProfile) + " (" + oUser.GetName(intProfile) + ")", oVariable.UserOUTechnical());
                                    if (strResult == "")
                                    {
                                        strResult = "<p>The account " + strUser + " was successfully created in " + oDomain.Get(intDomain, "name") + " with registry access (Password: "******")</p>";
                                    }
                                }
                                else
                                {
                                    strResult = oAD.CreateUser(strUser, strFirst, strLast, strPassword, "", "Created By ClearView on " + DateTime.Today.ToShortDateString() + Environment.NewLine + "Requested by " + oUser.GetFullName(intProfile) + " (" + oUser.GetName(intProfile) + ")", oVariable.UserOU());
                                    if (strResult == "")
                                    {
                                        strResult = "<p>The account " + strUser + " was successfully created in " + oDomain.Get(intDomain, "name") + " (Password: "******")</p>";
                                    }
                                }
                                string   strGroupsRequested = dsParameters.Tables[0].Rows[5]["value"].ToString();
                                string[] strGroupRequested;
                                char[]   strSplit = { ';' };
                                strGroupRequested = strGroupsRequested.Split(strSplit);
                                // Add Groups
                                for (int ii = 0; ii < strGroupRequested.Length; ii++)
                                {
                                    if (strGroupRequested[ii].Trim() != "")
                                    {
                                        // Add the group
                                        string strJoin = oAD.JoinGroup(strUser, strGroupRequested[ii].Trim(), 0);
                                        if (strJoin == "")
                                        {
                                            strResult += "<p>The user " + strUser + " was successfully joined to the group " + strGroupRequested[ii].Trim() + "</p>";
                                        }
                                        else
                                        {
                                            strError += "<p>The user " + strUser + " was NOT successfully joined to the group " + strGroupRequested[ii].Trim() + " : " + strJoin + "</p>";
                                        }
                                    }
                                }
                                oRequest.AddResult(intRequest, intItem, intNumber, "Account Modification", strError, strResult, intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intUser));
                            }
                        }
                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1);
                    }
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            intProfile = Int32.Parse(Request.Cookies["profileid"].Value);
            RequestItems    oRequestItem    = new RequestItems(intProfile, dsn);
            RequestFields   oRequestField   = new RequestFields(intProfile, dsn);
            ServiceRequests oServiceRequest = new ServiceRequests(intProfile, dsn);
            Services        oService        = new Services(intProfile, dsn);
            int             intRequest      = Int32.Parse(Request.QueryString["rid"]);
            string          strStatus       = oServiceRequest.Get(intRequest, "checkout");
            DataSet         dsItems         = oRequestItem.GetForms(intRequest);
            int             intItem         = 0;
            int             intService      = 0;
            int             intNumber       = 0;

            if (dsItems.Tables[0].Rows.Count > 0)
            {
                bool boolBreak = false;
                foreach (DataRow drItem in dsItems.Tables[0].Rows)
                {
                    if (boolBreak == true)
                    {
                        break;
                    }
                    if (drItem["done"].ToString() == "0")
                    {
                        intItem    = Int32.Parse(drItem["itemid"].ToString());
                        intService = Int32.Parse(drItem["serviceid"].ToString());
                        intNumber  = Int32.Parse(drItem["number"].ToString());
                        boolBreak  = true;
                    }
                    if (intItem > 0 && (strStatus == "1" || strStatus == "2"))
                    {
                        bool   boolSuccess = true;
                        string strResult   = oService.GetName(intService) + " Completed";
                        string strError    = oService.GetName(intService) + " Error";
                        // ********* BEGIN PROCESSING **************
                        Requests         oRequest          = new Requests(intProfile, dsn);
                        Users            oUser             = new Users(intProfile, dsn);
                        Workstations     oWorkstation      = new Workstations(intProfile, dsn);
                        Workstations     oRemote           = new Workstations(intProfile, dsnRemote);
                        Asset            oAsset            = new Asset(intProfile, dsnAsset);
                        Domains          oDomain           = new Domains(intProfile, dsn);
                        ModelsProperties oModelsProperties = new ModelsProperties(intProfile, dsn);
                        DataSet          ds = oWorkstation.GetVirtualDecommissions(intRequest, intItem, intNumber);
                        strResult = "";
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            int    intID    = Int32.Parse(dr["id"].ToString());
                            int    intName  = Int32.Parse(dr["nameid"].ToString());
                            string strName  = oWorkstation.GetName(intName);
                            int    intAsset = Int32.Parse(dr["assetid"].ToString());
                            int    intModel = Int32.Parse(dr["modelid"].ToString());
                            if (oModelsProperties.IsTypeVMware(intModel) == true)
                            {
                                // VMware Workstation
                                bool boolUnique = oAsset.AddDecommission(intRequest, intItem, intNumber, intAsset, intProfile, "", DateTime.Now, strName, 0, "");
                                if (boolUnique == true)
                                {
                                    oAsset.UpdateDecommission(intRequest, intItem, intNumber, 1);
                                    VMWare  oVMWare    = new VMWare(intProfile, dsn);
                                    DataSet dsGuest    = oVMWare.GetGuest(strName);
                                    string  strCluster = "???";
                                    if (dsGuest.Tables[0].Rows.Count > 0 && dsGuest.Tables[0].Rows[0]["hostid"].ToString() != "")
                                    {
                                        int intHost    = Int32.Parse(dsGuest.Tables[0].Rows[0]["hostid"].ToString());
                                        int intCluster = Int32.Parse(oVMWare.GetHost(intHost, "clusterid"));
                                        strCluster = oVMWare.GetCluster(intCluster, "name");
                                    }
                                    strResult += "<p>The VMware workstation " + strName + " is queued to be decommissioned from the cluster " + strCluster + ".</p>";
                                }
                                else
                                {
                                    strResult += "<p>The VMware workstation " + strName + " is ALREADY queued to be decommissioned</p>";
                                }
                            }
                            else
                            {
                                // Microsoft Virtual Workstation
                                int     intHost       = Int32.Parse(dr["virtualhostid"].ToString());
                                int     intOS         = Int32.Parse(dr["osid"].ToString());
                                string  strHost       = oAsset.GetServerOrBlade(intHost, "name");
                                string  strVirtualDir = "";
                                DataSet dsOS          = oAsset.GetVirtualHostOs(intHost);
                                foreach (DataRow drOS in dsOS.Tables[0].Rows)
                                {
                                    if (Int32.Parse(drOS["osid"].ToString()) == intOS)
                                    {
                                        strVirtualDir = drOS["virtualdir"].ToString();
                                        break;
                                    }
                                }
                                int intDomain = Int32.Parse(dr["domainid"].ToString());
                                int intEnv    = Int32.Parse(oDomain.Get(intDomain, "environment"));
                                oRemote.AddRemoteVirtualDecom(intEnv, strHost, strVirtualDir, strName);
                                // Clean up database
                                oWorkstation.DeleteVirtual(intID);
                                oWorkstation.UpdateName(intName, 1);
                                oAsset.DeleteGuest(intAsset);
                                oAsset.AddStatus(intAsset, "", (int)AssetStatus.Decommissioned, intProfile, DateTime.Now);
                                strResult += "<p>The virtual workstation " + strName + " was successfully decommissioned from the host " + strHost + ".</p>";
                            }
                            strError = "";
                        }
                        oRequest.AddResult(intRequest, intItem, intNumber, "Virtual Workstation Decommission", strError, strResult, intEnvironment, (oService.Get(intService, "notify_client") == "1"), oUser.GetName(intProfile));
                        if (strResult == "")
                        {
                            boolSuccess = false;
                        }
                        // ******** END PROCESSING **************
                        if (oService.Get(intService, "automate") == "1" && boolSuccess == true)
                        {
                            strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strResult + "</td></tr></table>";
                        }
                        else
                        {
                            if (boolSuccess == false)
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_error.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + strError + "</td></tr></table>";
                            }
                            else
                            {
                                strDone += "<table border=\"0\"><tr><td valign=\"top\"><img src=\"/images/ico_check.gif\" border=\"0\" align=\"absmiddle\"/></td><td valign=\"top\" class=\"biggerbold\">" + oService.GetName(intService) + " Submitted</td></tr></table>";
                            }
                        }
                        oRequestItem.UpdateFormDone(intRequest, intItem, intNumber, 1, 1);
                    }
                }
            }
        }