In IE11 Rad ajax Lading Panel on Rad Tab shows thrown exception behind ajax lading panel and hangs

7 posts, 0 answers
  1. Sandhya
    Sandhya avatar
    9 posts
    Member since:
    Nov 2014

    Posted 28 Nov 2014 Link to this post

    I am using rad tabs with with content URL with following settings
    .aspx code
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="Server">
        <telerik:RadAjaxPanel ID="rjxPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
     </telerik:RadAjaxPanel>
    </asp:Content>

    aspx.cs code

     protected void Page_Load(object sender, EventArgs e)
        {   RadAjaxManager rjxManager = RadAjaxManager.GetCurrent(this);
            //Create a new delegate to handle the AjaxRequest event   
            rjxManager.AjaxRequest += new RadAjaxControl.AjaxRequestDelegate(RadAjaxManager_AjaxRequest);
            rjxManager.AjaxSettings.AddAjaxSetting(rjxManager, pnl_OpportunityGroups);
       }

     protected void RadAjaxManager_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            try
            {
                if (!string.IsNullOrEmpty(e.Argument))
                {
                    if (e.Argument == "Rebind")
                        RadGrid_Group.Rebind();
                }
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }



        }

    when exception is thrown then exception is shown behind loading panel In IE11 only.

    I could not get solution
    PFA.
  2. Sandhya
    Sandhya avatar
    9 posts
    Member since:
    Nov 2014

    Posted 01 Dec 2014 in reply to Sandhya Link to this post

    can any body help me out with this. I have searched a lot no solution found till now. :(
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 02 Dec 2014 Link to this post

    Hello Sandhya,

    The presented issue is rather strange and we do not have reports for similar problem form other users of ours.
    Therefore I would kindly ask you to post the full page markup as well as the related code behind of the problematic page. Thus we will be able to recreate the page locally and see of the issue could be replicated on our end.

    Regards,
    Maria Ilieva
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  5. Sandhya
    Sandhya avatar
    9 posts
    Member since:
    Nov 2014

    Posted 03 Dec 2014 in reply to Maria Ilieva Link to this post

    Hello Maria,

    Thanks for the reply.

    We are using asp.net 3.5 and Telerik version 2012.2.2607.35.

    PFA files.  ManageOpportunity.aspx  is main page which is having rad tabs which include tab Manage Groups which include the page ManageOpportunityGroups.aspx.  On Margin % update  Sets grid get refreshed with Ajax call. but on update if exception is thrown then it appears behind loading panel.

    Regards,
    Sandhya
  6. Sandhya
    Sandhya avatar
    9 posts
    Member since:
    Nov 2014

    Posted 03 Dec 2014 in reply to Sandhya Link to this post

    Hello Maria,

    The code formatting taking a long at my end. Can you please provide an email or some other option so that i can upload the files.

    Thanks & Regards,
    Sandhya.
  7. Sandhya
    Sandhya avatar
    9 posts
    Member since:
    Nov 2014

    Posted 04 Dec 2014 in reply to Sandhya Link to this post

    Please find code here

    ModuleMasterPage.master

    ----------------------
    <%@ Master Language="C#" AutoEventWireup="true" Inherits="ModuleMasterPage" CodeBehind="ModuleMasterPage.master.cs" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>ERPByNet</title>

        <script type="text/javascript" src="../App_Themes/Default/jquery1_7.js"> </script>

        <script src="../js/RadWindowMethods.js" type="text/javascript"></script>

        <script src="../js/OpenStatusPopup.js" type="text/javascript"></script>
        
        <script src="../js/userAgentDetector.js" type="text/javascript"></script>
        
        <link rel="stylesheet" href="../RupeesFont/RupeeForadianStylesheet.css" type="text/css" charset="utf-8" />

        <base target="_self" />
         
    </head>

       

    <body class="LoginBodyMaster">
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager" runat="server" EnableTheming="True" AsyncPostBackTimeout="6000">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
        
        <telerik:RadAjaxManager ID="RadAjaxManagerMaster" runat="server" EnableAJAX="true">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rmServiceMenu">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rmServiceMenu" LoadingPanelID="AjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">

                Sys.WebForms.PageRequestManager.getInstance()._origOnFormActiveElement = Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive;
                Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive = function(element, offsetX, offsetY) {
                    if (element.tagName.toUpperCase() === 'INPUT' && element.type === 'image') {
                        offsetX = Math.floor(offsetX);
                        offsetY = Math.floor(offsetY);
                    }
                    this._origOnFormActiveElement(element, offsetX, offsetY);
                };

            </script>
        </telerik:RadCodeBlock>
        
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1"
            Style="position: absolute; top: -10; left: -10; height: 100%; width: 100%; z-index:999999;" />
        <div id="HeaderImageDiv" runat="server" class="newHeader">
            <div class="headerLeft">
                <div class="XecomModuleLogo" align="center">
                    <telerik:RadBinaryImage runat="server" ID="XECOMLogo" AutoAdjustImageControlSize="false"
                        ImageUrl="" Width="86px" Height="68px" ToolTip='Application Logo' AlternateText='Application Logo' />
                </div>
                <div class="XecomModuleNameAndDetails">
                    <asp:Label runat="server" ID="lblModuleName" Text="" Font-Bold="true" CssClass="LblModule"
                        Font-Names="arial" />
                    <asp:Label runat="server" ID="lblVersion" Text="" Font-Bold="true" Font-Names="arial" />
                    <telerik:RadNotification ID="MasterPageNotifier" runat="server" AutoCloseDelay="5000"
                        EnableShadow="True" Overlay="True" Position="TopLeft" Title="Notification">
                        <NotificationMenu ID="TitleMenu">
                        </NotificationMenu>
                    </telerik:RadNotification>
                </div>
            </div>
            <div class="headerRight">
                <div style="width: 180px; float: right; margin: 0 0 10px;">
                    <telerik:RadBinaryImage runat="server" ID="OrganizationLogo" AutoAdjustImageControlSize="false"
                        ToolTip='Organization Logo' AlternateText='Organization Logo' />
                </div>
              <div style=" float: right; ">
                <asp:Label runat="server" ID="lblUserName" Text="" Font-Bold="false" CssClass="LblUser"
                    Font-Names="arial" />
             </div>
                <div style=" float: right; display:none;">
                    Themes:<telerik:RadSkinManager ID="RadSkinManager1" runat="server" Skin="Default"
                        ShowChooser="false">
                        <TargetControls>
                            <telerik:TargetControl ControlID="mnuModule" ControlsToApplySkin="RadMenu, RadAjaxLoadingPanel, RadAsynchUpload, RadButton, RadCalendar" />
                        </TargetControls>
                    </telerik:RadSkinManager>
                </div>
            </div>
        </div>
        <div id="MastermainDiv" runat="server" class="menuNavigation">
            <telerik:RadMenu ID="mnuModule" runat="server" Width="100%" OnItemClick="mnuModule_ItemClick">
                <Items>
                    <telerik:RadMenuItem runat="server" NavigateUrl="~/ModuleSelector.aspx" Text="Switch">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenu>
        </div>
     
        <div class="space10"></div>
        <div class="mainPlaceholder">
            <div class="mainPlaceholderInner">
                <asp:ContentPlaceHolder ID="MainContentPlaceHolder" runat="server">
                </asp:ContentPlaceHolder>
            </div>
        </div>
     
        <telerik:RadWindowManager ID="msgWindowManager" runat="server" EnableShadow="true">
        </telerik:RadWindowManager>
        <telerik:RadWindow ID="messageWindow" runat="server" Modal="true" Title="Message">
            <ContentTemplate>
                <asp:Label runat="server" ID="lblMessage" Text="" Font-Bold="true" Font-Size="Large"
                    Font-Names="arial" />
            </ContentTemplate>
        </telerik:RadWindow>
        </form>
    </body>
    </html>


    ----------------------

    <%@ Master Language="C#" AutoEventWireup="true" Inherits="ModuleMasterPage" CodeBehind="ModuleMasterPage.master.cs" %>

    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="act" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>ERPByNet</title>

        <script type="text/javascript" src="../App_Themes/Default/jquery1_7.js"> </script>

        <script src="../js/RadWindowMethods.js" type="text/javascript"></script>

        <script src="../js/OpenStatusPopup.js" type="text/javascript"></script>
        
        <script src="../js/userAgentDetector.js" type="text/javascript"></script>
        
        <link rel="stylesheet" href="../RupeesFont/RupeeForadianStylesheet.css" type="text/css" charset="utf-8" />

        <base target="_self" />
         
    </head>

       

    <body class="LoginBodyMaster">
        <form id="form1" runat="server">
        <telerik:RadScriptManager ID="ScriptManager" runat="server" EnableTheming="True" AsyncPostBackTimeout="6000">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
        
        <telerik:RadAjaxManager ID="RadAjaxManagerMaster" runat="server" EnableAJAX="true">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="rmServiceMenu">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="rmServiceMenu" LoadingPanelID="AjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
            <script type="text/javascript">

                Sys.WebForms.PageRequestManager.getInstance()._origOnFormActiveElement = Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive;
                Sys.WebForms.PageRequestManager.getInstance()._onFormElementActive = function(element, offsetX, offsetY) {
                    if (element.tagName.toUpperCase() === 'INPUT' && element.type === 'image') {
                        offsetX = Math.floor(offsetX);
                        offsetY = Math.floor(offsetY);
                    }
                    this._origOnFormActiveElement(element, offsetX, offsetY);
                };

            </script>
        </telerik:RadCodeBlock>
        
        <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1"
            Style="position: absolute; top: -10; left: -10; height: 100%; width: 100%; z-index:999999;" />
        <div id="HeaderImageDiv" runat="server" class="newHeader">
            <div class="headerLeft">
                <div class="XecomModuleLogo" align="center">
                    <telerik:RadBinaryImage runat="server" ID="XECOMLogo" AutoAdjustImageControlSize="false"
                        ImageUrl="" Width="86px" Height="68px" ToolTip='Application Logo' AlternateText='Application Logo' />
                </div>
                <div class="XecomModuleNameAndDetails">
                    <asp:Label runat="server" ID="lblModuleName" Text="" Font-Bold="true" CssClass="LblModule"
                        Font-Names="arial" />
                    <asp:Label runat="server" ID="lblVersion" Text="" Font-Bold="true" Font-Names="arial" />
                    <telerik:RadNotification ID="MasterPageNotifier" runat="server" AutoCloseDelay="5000"
                        EnableShadow="True" Overlay="True" Position="TopLeft" Title="Notification">
                        <NotificationMenu ID="TitleMenu">
                        </NotificationMenu>
                    </telerik:RadNotification>
                </div>
            </div>
            <div class="headerRight">
                <div style="width: 180px; float: right; margin: 0 0 10px;">
                    <telerik:RadBinaryImage runat="server" ID="OrganizationLogo" AutoAdjustImageControlSize="false"
                        ToolTip='Organization Logo' AlternateText='Organization Logo' />
                </div>
              <div style=" float: right; ">
                <asp:Label runat="server" ID="lblUserName" Text="" Font-Bold="false" CssClass="LblUser"
                    Font-Names="arial" />
             </div>
                <div style=" float: right; display:none;">
                    Themes:<telerik:RadSkinManager ID="RadSkinManager1" runat="server" Skin="Default"
                        ShowChooser="false">
                        <TargetControls>
                            <telerik:TargetControl ControlID="mnuModule" ControlsToApplySkin="RadMenu, RadAjaxLoadingPanel, RadAsynchUpload, RadButton, RadCalendar" />
                        </TargetControls>
                    </telerik:RadSkinManager>
                </div>
            </div>
        </div>
        <div id="MastermainDiv" runat="server" class="menuNavigation">
            <telerik:RadMenu ID="mnuModule" runat="server" Width="100%" OnItemClick="mnuModule_ItemClick">
                <Items>
                    <telerik:RadMenuItem runat="server" NavigateUrl="~/ModuleSelector.aspx" Text="Switch">
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenu>
        </div>
     
        <div class="space10"></div>
        <div class="mainPlaceholder">
            <div class="mainPlaceholderInner">
                <asp:ContentPlaceHolder ID="MainContentPlaceHolder" runat="server">
                </asp:ContentPlaceHolder>
            </div>
        </div>
     
        <telerik:RadWindowManager ID="msgWindowManager" runat="server" EnableShadow="true">
        </telerik:RadWindowManager>
        <telerik:RadWindow ID="messageWindow" runat="server" Modal="true" Title="Message">
            <ContentTemplate>
                <asp:Label runat="server" ID="lblMessage" Text="" Font-Bold="true" Font-Size="Large"
                    Font-Names="arial" />
            </ContentTemplate>
        </telerik:RadWindow>
        </form>
    </body>
    </html>
    ----------------------------------
    ModuleMasterPage.Master.cs
    -------------------------------------------------------------------------------------------
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using ERPByNet.HelperClasses;
    using XECOMIT.ERPByNet.DataAccessEntities;
    using Csla.Data;
    using Telerik.Web.UI;
    using XECOMIT.ERPByNet.SecurityServices;
    using Microsoft.Practices.EnterpriseLibrary.Data;
    using XECOMIT.ERPByNet.BusinessEntities;

    public partial class ModuleMasterPage : System.Web.UI.MasterPage, IMessagePopup, INotifier
    {
        #region Constants

        private const int HELP_REPORT_TEMPLATE_ID = 101;

        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.CacheControl = "no-cache";
            Response.AddHeader("Pragma", "no-cache");
            Response.Expires = -1;
            ScriptManager.AsyncPostBackTimeout = 6000;
            if (Request.QueryString["app"] != null && Request.QueryString["module"] != null)
            {
                Session["app"] = Request.QueryString["app"];
                Session["module"] = Request.QueryString["module"];
            }
            else if (Session["module"] == null)
            {
                Response.Redirect(@"~/ModuleSelector.aspx");
            }
            string appVersionNo = ApplicationHelper.GetApplicationVesionNo();
            if (ApplicationHelper.INVALIDVERSION == appVersionNo)
            {
                Session["APPERROR"] = ApplicationHelper.INVALIDVERSION;
                Response.Redirect(@"~/Shared/AppError.aspx");
            }
            int ModuleID = int.Parse(Session["module"].ToString());
            int ApplicationID = int.Parse(Session["app"].ToString());
            
            populateMenus(ApplicationID, ModuleID, UIHelper.GetUserIDOfLoggedInUser(), UIHelper.GetCurrentUsersLanguageID());
            populateApplicationLogo(ApplicationID);
            populateOrganizationLogo(UIHelper.GetCurrentUsersOrganizationId());
            populateApplicationModuleName(ModuleID);
            populateLoginName();
            populateVersionNo(appVersionNo);
        }

        private void showNotification()
        {
            int RefreshNotificationTime = GetRefreshNotificationTime();
            CheckNeedToShowNotification(RefreshNotificationTime);
            RadMenuItem mnuAlertNotification = mnuModule.Items.FindItemByValue("mnuAlertNotification");
            if (mnuAlertNotification != null)
            {
                if (Session["DisplayImage"] != null)
                {
                    if (Convert.ToBoolean(Session["DisplayImage"].ToString()) == true)
                        mnuAlertNotification.Visible = true;
                    else
                        mnuAlertNotification.Visible = false;
                }
            }
        }

        protected void mnuModule_ItemClick(object sender, RadMenuEventArgs e)
        {
            if (e.Item.Value == "Help")
            {
                PageHelp();
            }
            else if (e.Item.Value == "LogOff")
            {
                LogOffUser();
            }
        }

        private int GetNotificationCount()
        {
            return (UserDA.GetUserNotificationsCount(UIHelper.GetLoggedInUserEmployeeID(), UIHelper.GetCurrentUsersLanguageID(), ApplicationHelper.GetApplicationID()));
        }

        private void CheckNeedToShowNotification(int RefreshNotificationTime)
        {
            DateTime StartRequestTime;
            DateTime EndRequestTime;

            if (Session["StartRequestTime"] == null)
            {
                Session["StartRequestTime"] = DateTime.Now;
                Session["PrevNotificationCount"] = null;
            }

            Session["EndRequestTime"] = DateTime.Now;
            int CurrentNotificationCount = 0;

            StartRequestTime = Convert.ToDateTime(Session["StartRequestTime"].ToString());
            EndRequestTime = Convert.ToDateTime(Session["EndRequestTime"].ToString());

            if (Session["PrevNotificationCount"] == null)
            {
                Session["PrevNotificationCount"] = GetNotificationCount();
            }

            if (EndRequestTime >= StartRequestTime.AddMinutes(RefreshNotificationTime))
            {
                CurrentNotificationCount = GetNotificationCount();

                if (int.Parse(Session["PrevNotificationCount"].ToString()) < CurrentNotificationCount)
                {
                    Session["PrevNotificationCount"] = CurrentNotificationCount;
                    Session["StartRequestTime"] = Session["EndRequestTime"];
                    Session["DisplayImage"] = true;
                }
            }
        }

        private int GetRefreshNotificationTime()
        {
            ConfigurationParameterSettingInfoList oConfigurationParameterSettingInfoList;
            oConfigurationParameterSettingInfoList = ConfigurationParameterSettingInfoList.GetConfigurationParameterSettings(ModuleHelper.GetCurrentModuleId(), ModuleHelper.GetDeploymentSettingsConfigurationCategoryID());
            ConfigurationParameterSettingInfo oConfigurationRefreshNotificationTimeValue = oConfigurationParameterSettingInfoList.GetConfigurationParameterID(ModuleHelper.GetConfigurationParameterIDForRefreshNotificationTime());

            int RefreshNotificationTime = Convert.ToInt32(oConfigurationRefreshNotificationTimeValue.ConfigurationParameterValue);
            return RefreshNotificationTime;
        }

        private void populateMenus(int ApplicationID, int moduleID, int userID, int languageID)
        {
            DataSet menuData = XECOMIT.ERPByNet.SecurityServices.Applications.GetApplicationModuleMenus(moduleID, userID, languageID);
            mnuModule.DataSource = menuData;
            mnuModule.DataFieldID = "ApplicationModuleUIElementID";
            mnuModule.DataFieldParentID = "ParentApplicationModuleUIElementID";
            mnuModule.DataTextField = "UIElementName";
            mnuModule.DataNavigateUrlField = "UIElementInfo";
            mnuModule.DataBind();
            addStaticMenus(ApplicationID,moduleID);
        }

        private void addStaticMenus(int ApplicationID,int ModuleID)
        {

            RadMenuItem switchMenu = new RadMenuItem();
            //switchMenu.NavigateUrl = @"~\Default.aspx";
            switchMenu.Value    = "LogOff";
            switchMenu.ToolTip  = "Log Off";
            switchMenu.ImageUrl = @"~\images\logoff.png";
            switchMenu.HoveredImageUrl = @"~\images\logoff_Hover.png";
            mnuModule.Items.Insert(0, switchMenu);

            switchMenu = new RadMenuItem();
            switchMenu.NavigateUrl = @"~\ModuleSelector.aspx";
            switchMenu.ImageUrl = @"~\images\Switch.png";
            switchMenu.HoveredImageUrl = @"~\images\Switch_Hover.png";
            mnuModule.Items.Insert(0, switchMenu);

            switchMenu = new RadMenuItem();
            switchMenu.NavigateUrl = GetHomePageURL(ApplicationID,ModuleID);// @"~\Home.aspx";
            switchMenu.ImageUrl = @"~\images\iconHome.png";
            switchMenu.HoveredImageUrl = @"~\images\iconHome_hover.png";
            mnuModule.Items.Insert(0, switchMenu);

            switchMenu = new RadMenuItem();
            switchMenu.Value = "mnuAlertNotification";
            switchMenu.NavigateUrl = @"~\Shared\ShowUserNotifications.aspx";// @"~\Home.aspx";
            switchMenu.ImageUrl = @"~\images\Alert.gif";
            switchMenu.HoveredImageUrl = @"~\images\Alert.gif";
            switchMenu.Visible = false;
            mnuModule.Items.Insert(0, switchMenu);

            switchMenu = new RadMenuItem();
            switchMenu.Value = "Help";
            switchMenu.ImageUrl = @"~\images\help.png";
            //switchMenu.ID = "HelpButton";
            //switchMenu.NavigateUrl = @"~\Shared\ShowUserNotifications.aspx";
            mnuModule.Items.Insert(0, switchMenu);

            
        }

        private void PageHelp()
        {
            try
            {
                string strScript;
                string url;

                string WhereClause = GetWhereClause();//" AND HelpContents.ApplicationID= " + ApplicationHelper.GetApplicationID() + " AND PageName= '" + HiddenField_PageName.Value + "' ";
                url = string.Format("/Shared/RDLReportViewer.aspx?&Filters=" + Server.UrlEncode(WhereClause) + "&ReportTemplateID=" + HELP_REPORT_TEMPLATE_ID + "&RDLFileName=" + "HelpContents.rdl" + "&AppendWhereClause=false");// +oReportTemplate.AppendWhereClause;
           
                strScript = "javascript:window.open(\"" + url + "\");";
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "lnkPageHelp", strScript, true);
             

            }
            catch (Exception ex)
            {

            }
        }


        private void LogOffUser()
        {
            try
            {
                string strScript;
                UIHelper.LogOffUser();
                strScript = "<SCRIPT>document.execCommand(ClearAuthenticationCache);</SCRIPT>";
                System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "LogOff", strScript, true);
                Response.Redirect("~/default.aspx");
            }
            catch (Exception ex)
            {

            }
        }

        private string GetWhereClause()
        {

            string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
            System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);

            int ApplicationID =  ApplicationHelper.GetApplicationID();

            ReportFilters oReportFilters = ReportFilters.NewReportFilters();//SQLReportSettings.GetReportFilterValues(ApplicationID);
            ReportFilter oRFilter = oReportFilters.AddNew(0);

            oRFilter.ReportTemplateParameterField = "ApplicationID";
            oRFilter.ReportCriteriaOperatorName = "=";
            oRFilter.ReportFilterValue = ApplicationID.ToString();

            oRFilter = oReportFilters.AddNew(0);
            oRFilter.ReportTemplateParameterField = "PageName";
            oRFilter.ReportCriteriaOperatorName = "=";
            oRFilter.ReportFilterValue =  oInfo.Name;

            oRFilter = oReportFilters.AddNew(0);
            oRFilter.ReportTemplateParameterField = "StatusTypeID";
            oRFilter.ReportCriteriaOperatorName = "=";
            oRFilter.ReportFilterValue = GetStatusTypeID(ApplicationID).ToString();

            return SQLReportSettings.GetWhereClause(oReportFilters);
        }

        private int GetStatusTypeID(int ApplicationID)
        {
            int StatusTypeID;
            switch (ApplicationID)
            {
                case 3:
                    {
                        StatusTypeID = 2;
                        break;
                    }
                case 5:
                    {
                        StatusTypeID = 6; //Installation Project
                        break;
                    }
                case 9:
                    {
                        StatusTypeID = 3;
                        break;
                    }
                default:
                    {
                        StatusTypeID = 0;
                        break;
                    }
            }
            return StatusTypeID;
        }

        private void populateApplicationLogo(int applicationID)
        {
           //XECOMLogo.DataValue = UIHelper.GetApplicationLogo(applicationID);
           XECOMLogo.ImageUrl = UIHelper.GetApplicationLogo(applicationID);
        }
        private void populateOrganizationLogo(int applicationID)
        {
            OrganizationLogo.DataValue = UIHelper.GetLegalOrganizationLogo(applicationID);
        }
        private void populateApplicationModuleName(int applicationModuleID)
        {
            lblModuleName.Text = UIHelper.GetApplicationModuleName(applicationModuleID);
        }
        private void populateVersionNo(string appVersionNo)
        {
            lblVersion.Text = appVersionNo;
        }
        private void populateLoginName()
        {
            lblUserName.Text = @"Logged in user: " + UIHelper.GetLoggedInUserLoginID().ToUpper() + ", " + UIHelper.GetOrganizationName(UIHelper.GetLoggedinUserLegalEntityOrganizationID());
        }

        private string GetHomePageURL(int ApplicationID, int ModuleID)
        {
            string HomePageURL = @"~\Home.aspx";
            switch(ApplicationID)
            {
                case 1:
                    {
                        HomePageURL = @"~/SecurityStudio/XESSHome.aspx";
                        break;
                    }
                case 2:
                    {
                        HomePageURL   = @"~/Productstudio/Home.aspx";
                        break;
                    }

                case 3:
                    {
                        HomePageURL = @"~/SalesPundit/Home.aspx";
                        break;
                    }

                  case 4:
                      {
                          HomePageURL = "/ACEMrp/MRPHome.aspx";//"/AceMRP/XESSHome.aspx";
                          break;
                      }

                case 5:
                    {
                        HomePageURL = "/AceSiteManager/PEARLHome.aspx";
                        break;
                    }

                case 6:
                    {
                        HomePageURL = "/AceService/Home.aspx";
                        break;
                    }
                case 7:
                    {
                        HomePageURL = "/AceFinance/FINHome.aspx";
                        break;
                    }
                case 9:
                    {
                        HomePageURL = "/ServiceSales/Home.aspx";
                        break;
                    }
                default:
                    {
                        HomePageURL = @"\Home.aspx";
                        break;
                    }

            }
            return HomePageURL + "?app=" + ApplicationID.ToString() + "&module=" + ModuleID.ToString();
        }

        #region IMessagePopup Members

        public void ShowMessage(string message)
        {
            //this.lblMessage.Text = message;
            //messagePanel.Update();
            //this.ModalPopupExtenderForMessage.Show();
            //messageWindow
            msgWindowManager.RadAlert(message, 400, 400, "Error", null);
        }

        public void ShowMessage(string message, string title)
        {       
            msgWindowManager.RadAlert(message, 400, 400, title, null);
        }

        #endregion

        #region INotifier Members

        public void ShowNotification(string message)
        {
            MasterPageNotifier.Show(message);
        }

        #endregion

        
    }
    -------------------------------------------------------------------------------------------
    ManageOpportunity.aspx
    ----------------------------------------------------------------------------------
    <%@ Page Language="C#" MaintainScrollPositionOnPostBack="true" MasterPageFile="~/MasterPages/ModuleMasterPage.Master" AutoEventWireup="true" Inherits="ManageOpportunityMOD" Title="<t>Manage Projects</t>"   Codebehind="ManageOpportunity.aspx.cs" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" Runat="Server">
    <telerik:RadAjaxPanel ID="rjxPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel1" onajaxrequest="rjxPanel_AjaxRequest">   
    <fieldset>
    <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
    <script type="text/javascript" language="javascript" >
        $(document).ready(

        function() {

            $(".GridHieghtMain").css("height", ($(document).height() - (152)) + "px");

        });
        function SetGridHeightMain() {

            $(".GridHieghtMain").css("height", ($(document).height() - (200)) + "px");

        };
       </script>
     
       
    </telerik:RadCodeBlock>

        <table style="width:99%">
        <tr style="height:5px;">
        <td align="left">
            <asp:Label CssClass="ClsLabelHead" ID="Label2" runat="server" Text="<t>Manage Projects</t>"> </asp:Label>
        </td>
        </tr>
        <tr align=center>
        <td align="center">
            <table style=" border:1px solid gray; ">                    
                <tr >                       
                    <td  >  
                    &nbsp;&nbsp;
                  <asp:Label ID="Label_OpportunityName" runat="server" Font-Size="Small" Font-Bold="true" Text="<t>Opportunity Name :</t>" ></asp:Label>
                   <asp:Label ID="Label_OpportunityName_Value" runat="server" Text=""  Font-Size="12px" >
                   </asp:Label>&nbsp;&nbsp;
                   <asp:Label ID="Label_OpportunityNo_Header" runat="server" Font-Size="Small" Font-Bold="true" Text="<t>Opportunity No :</t>" ></asp:Label>
                   <asp:Label ID="Label_OpportunityNo_Header_Value" runat="server" Text=""  Font-Size="12px"  >
                   </asp:Label>&nbsp;&nbsp;
                   <asp:Label  ID="lblOrganization" runat="server" Font-Bold="true" Font-Size="Small" Text="<t>Organization :</t>" ></asp:Label>
                   <asp:Label ID="lblOrganization_Value" runat="server" Text=""  Font-Size="12px"  >
                   </asp:Label>&nbsp;&nbsp;
                   <asp:Label  ID="lblOpportunity_Status" runat="server" Font-Size="Small" Font-Bold="true" Text="<t>Status :</t>" ></asp:Label>
                   <asp:Label ID="lblOpportunity_Status_value" runat="server" Text="" Font-Size="12px" >
                   </asp:Label>&nbsp;&nbsp;
                   <asp:Label  ID="lblContract_No" runat="server" Font-Size="Small" Text="<t>Contract No :</t>" Font-Bold="true" ></asp:Label>
                   <asp:Label ID="lblContract_No_value" runat="server" Text="" Font-Size="12px" >
                   </asp:Label>&nbsp;&nbsp;
                    </td>
                 </tr>
            </table>
        </td>
        </tr>
        <tr  style="height:10px; ">
            <td colspan="2">
            </td>
        </tr>
        <tr>
        <td align="left" colspan="2">
            <telerik:RadTabStrip ID="RadTabStrip_ManageProjects" runat="server" MultiPageID="mpProjectsHeader" PerTabScrolling="True" ReorderTabsOnSelect="True" OnTabClick="RadTabStrip_ManageProjects_click" SelectedIndex="0">
              <Tabs>
                 <telerik:RadTab  ID="Tab_Basic" runat="server" Text="Basic Info"  PageViewID="MPBasicInfoDataView" TabIndex="1" />
                 <telerik:RadTab  ID="Tab_Address" runat="server" Text="Address Info" PageViewID="MPAddressInfoDataView"  TabIndex="2"/>
                 <telerik:RadTab  ID="Tab_Contact" runat="server" Text="Customer / Contact" PageViewID="MPCustomerDataView"  TabIndex="3" />
                 <telerik:RadTab  ID="Tab_ManageGroup" runat="server" Text="Manage Groups" PageViewID="MPManageGrpDataView"  TabIndex="4" />
                 <telerik:RadTab  ID="Tab_Terms" runat="server" Text="Terms & Conditions" PageViewID="MPTermsCondDataView"  TabIndex="5" />
                 <telerik:RadTab  ID="Tab_ContractInfo" runat="server" Text="Contract Info" PageViewID="MPContractInfDataView"  TabIndex="6" />
                 <telerik:RadTab  ID="Tab_BillingPlan" runat="server" Text="Billing Plan" PageViewID="MPBillingPlanDataView"  TabIndex="7" />
                 <telerik:RadTab  ID="Tab_ProjectBudget" runat="server" Text="Budget" PageViewID="MPProjectBudgetDataView"  TabIndex="8" Enabled="false" />
                 <telerik:RadTab  ID="Tab_DocumentManagement" runat="server" Text="Document Management" PageViewID="MPDocumentManagementDataView"  TabIndex="9" />
            </Tabs>
          </telerik:RadTabStrip>    
            <telerik:RadMultiPage ID="mpProjectsHeader" runat="server" SelectedIndex="0" RenderSelectedPageOnly="true">
                 <telerik:RadPageView ID="MPBasicInfoDataView" runat="server" TabIndex="0" CssClass="ClsDivBorder">
                 <asp:MultiView ID="MultiView_BasicInfo" runat="server" ActiveViewIndex="0">
                    <asp:View ID="BasicInfoView" runat="server">
                        <table style="width:100%; margin:15px 0 0 0; border:1px solid #000000;">
                        <tr>
                        <td align="right" colspan="4" >
                            <telerik:RadButton ID="RadButtonRemarks" Text="Remark"  runat="server"  OnClientClicked="ShowRemarkPopup"
                                ToolTip="Remark" />&nbsp;&nbsp;
                            <telerik:RadButton ID="ButtonShowAuditrailReport" Text="Audit Trail Report"  runat="server"  OnClientClicked="ShowAuditTrailReportPopup"
                                ToolTip="Audit Trail Report" Width="110" />&nbsp;&nbsp;
                            <telerik:RadButton ID="RadBtnPendingActions" runat="server" OnClientClicked="PendingActions"  Width="100"
                                CausesValidation="False" TabIndex="28"  Text="Pending Actions" ToolTip="Pending Actions"/>
                          </td>
                        </tr>
                            <tr style="height:25px;">
                                <td align="left" style="width:14%;">
                                    <asp:Label ID="Label_OpportunityNo" runat="server" Font-Bold="true" Text="<t>Opportunity No:</t>" >
                                    </asp:Label>
                                    <asp:Label ID="lbl_OpportunityNo_Mandatory" runat="server" CssClass="ClsLabelMdt" Text="*" ></asp:Label>
                                </td>
                                <td align="left" style="width:29%;">
                                    <asp:Label ID="lbl_OpportunityNo" runat="server" Text="" ForeColor="red" Font-Bold="true"  >
                                    </asp:Label>
                                    <asp:TextBox ID="TextBox_OpportunityNo" runat="server" CssClass="ClsTextBoxMid" TabIndex="11">
                                    </asp:TextBox>
                                    <asp:RegularExpressionValidator ID="OpportunityNoRegularExpressionValidator" runat="server"
                                                                   ErrorMessage="Space is not allowed"
                                                                   ControlToValidate="TextBox_OpportunityNo"
                                                                   ValidationExpression="^\S+$">
                                    </asp:RegularExpressionValidator>
                                </td>
                                <td align="left" style="width:14%;">
                                    <asp:Label ID="Label_SiteName" runat="server" Font-Bold="true" Text="<t>Site Name:</t>" >
                                    </asp:Label>
                                    <asp:Label ID="Label_SiteNameMandatory" runat="server"  CssClass="ClsLabelMdt" Text="*" ></asp:Label>
                                </td>
                                <td align="left" style="width:29%;">
                                       <asp:TextBox ID="TextBox_SiteName" runat="server" CssClass="ClsTextBoxMid" TabIndex="12">
                                    </asp:TextBox>                               
                                </td>                            
                            </tr>
                            <tr style="height:25px;">
                                <td align="left" >
                                        <asp:Label ID="Label_Status" runat="server" Text="<t>Current Status:</t>"></asp:Label>
                                        <asp:Label ID="Label_StatusMandatory" runat="server"  CssClass="ClsLabelMdt" Text="*" ></asp:Label>
                                </td>
                                <td align="left" >
                                        <asp:TextBox ID="TextBox_OpportunityStatusName" Enabled="False" runat="server" CssClass="ClsTextBoxMid" TabIndex="13"></asp:TextBox>
                                        <telerik:RadButton id="Button_OpportunityStatus" runat="server" width="28px" TabIndex="14"  OnClientClicked="Button_OpportunityStatus_Click" Text="...">
                                        </telerik:RadButton>
                                        <telerik:RadButton ID="Button_ViewStatusHistory" runat="server" Icon-PrimaryIconCssClass="btnHistory"  Width="22px"
                                        ToolTip="<t>Opportunity Status History</t>" TabIndex="15" AutoPostBack="false"  
                                        OnClientClicked="ViewStatusHistory" />                                     
                               </td>                           
                               <td align="left">
                                    <asp:Label ID="Label_ExpectedCompletionDate" runat="server" Text="<t>Expected Closing:</t>"></asp:Label>
                                    <asp:Label ID="Lbl_Mandatory_ExpectedCompletionDate" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                                </td>
                                <td align="left">
                                    <telerik:RadDatePicker ID="DatePicker_ExpectedCompletionDate"  runat="server" ForeColor="Black"
                                     TabIndex="16">
                                    <DateInput ID="DateInput1" runat="server" TabIndex="17"> </DateInput>                             
                                    <DatePopupButton TabIndex="18"/>
                                    </telerik:RadDatePicker>
                                </td>                        
                            </tr>
                            <tr>
                                <td align="left">
                                    <asp:Label ID="Label_ContractStartDate" runat="server" Text="<t>Contract Start Date:</t>" > </asp:Label>                               
                                </td>                                
                                <td align="left">       
                                    <telerik:RadDatePicker ID="DatePicker_ContractStartDate"  runat="server" ForeColor="Black" TabIndex="16">
                                        <DateInput ID="DateInput_ContractStartDate" runat="server" TabIndex="17"> </DateInput>                             
                                        <DatePopupButton TabIndex="18"/>
                                    </telerik:RadDatePicker>
                                </td>                        
                                <td align="left">
                                    <asp:Label ID="Label_ContractEndDate" runat="server" Text="<t>Contract End Date:</t>" > </asp:Label>                                
                                 </td>                         
                                 <td align="left">
                                    <telerik:RadDatePicker ID="DatePicker_ContractEndDate"  runat="server" ForeColor="Black" TabIndex="16">
                                       <DateInput ID="DateInput_ContractEndDate" runat="server" TabIndex="17"> </DateInput>                             
                                       <DatePopupButton TabIndex="18"/>
                                    </telerik:RadDatePicker>  
                                </td>                        
                            </tr>
                            <tr style="height:25px;">                        
                                <td align="left">
                                    <asp:Label ID="Label_DateCreated" runat="server" Text="<t>Date Created:</t>" > </asp:Label>
                                </td>
                                <td align="left">
                                    <%--<telerik:RadDatePicker ID="DatePicker_CreatedDate"  runat="server" ForeColor="Black"
                                              TabIndex="5" Culture="English (United States)" >
                                    <DateInput  runat="server" TabIndex="6" > </DateInput>                             
                                    <DatePopupButton TabIndex="7"/>
                                    </telerik:RadDatePicker>--%>
                                    <asp:Label ID="lbl_CreatedDate" runat="server" CssClass="ClsLabelMdt" Text=""> </asp:Label>
                                </td>
                                <td align="left">
                                    <asp:Label ID="lbl_Owner" runat="server" Text="<t>Owner:</t>" > </asp:Label>
                                </td>
                                <td align="left">
                                    <asp:Label ID="lbl_Owner_Value" runat="server" Text="" Font-Bold="true"> </asp:Label>
                                </td>                            
                            </tr>                        
                            <tr>
                            <td align="left">
                                <asp:Label ID="Label_EsimatedPrice" runat="server" Text="<t>Estimated Price:</t>" > </asp:Label>
                            </td>                                
                            <td align="left">       
                                <asp:Label ID="Label_EsimatedPrice_Value" runat="server" Text="" > </asp:Label>  
                            </td>                        
                            <td align="left">
                                <asp:Label ID="Label_QuotedPrice" runat="server" Text="<t>Quoted Price:</t>" > </asp:Label>
                             </td>                         
                             <td align="left">
                                   <asp:Label ID="Label_QuotedPrice_Value" runat="server" Text="" > </asp:Label>    
                            </td>                        
                            </tr>
                             
                             <tr>
                            <td align="left">
                                <asp:Label ID="Label_BillingAmount" runat="server" Text="<t>Billing Amount:</t>" > </asp:Label>
                            </td>                                
                            <td align="left">       
                                <asp:Label ID="Label_BillingAmount_Value" runat="server" Text="" > </asp:Label>  
                            </td>                        
                            <td align="left">
                                <asp:Label ID="Label_BilledAmount" runat="server" Text="<t>Billed Amount:</t>" > </asp:Label>
                             </td>                         
                             <td align="left">
                                   <asp:Label ID="Label_BilledAmount_Value" runat="server" Text="" > </asp:Label>    
                            </td>                        
                            </tr>
                                                     
                        </table>                    
                        <table style="width:100%; margin:15px 0 0 0; border:1px solid #000000; table-layout:fixed;">
                            <tr style="height:25px;">
                                <td align="left" style="width:14%;">
                                    <asp:Label ID="Label_SalesType" runat="server" Text="<t>Sales Type:</t>"></asp:Label>
                                    <asp:Label ID="Label_SalesTypeMandatory" runat="server" Text="*" CssClass="ClsLabelMdt" ></asp:Label>
                                 
                                </td>
                                <td align="left" style="width:29%;">
                                    <telerik:RadComboBox ID="rcbSalesType"
                                                      runat="server"                                     
                                                      DataTextField="SalesTypeName"
                                                      DataValueField="SalesTypeID" MarkFirstMatch="true"
                                                      TabIndex="21" AllowCustomText="false" AutoPostBack="true"
                                                      OnSelectedIndexChanged="RadComboBox_SalesType_SelectedIndexChanged"
                                                       > <%-- Width="170px"--%>                                                       
                                 </telerik:RadComboBox>   
                                    
                                </td>
                                <td align="left" style="width:14%;">
                                <asp:Label ID="Label_OpportunityType" runat="server" Text="<t>Type:</t>"></asp:Label>
                                </td>
                                <td align="left" style="width:29%;">
                                    <telerik:RadComboBox ID="RadComboBox_OpportunityType" runat="server"
                                                       MarkFirstMatch="true"
                                                       DataTextField="OpportunityTypeName"
                                                       DataValueField="OpportunityTypeID"
                                                       TabIndex="20">
                                    </telerik:RadComboBox>
                                </td>                                                      
                            </tr>
                             <tr style="height:25px;">
                                <td align="left">
                                    <asp:Label ID="label_Category" runat="server" Text="<t>Category:</t>" > </asp:Label>
                                    <asp:Label ID="Label10" runat="server" Text="*"  CssClass="ClsLabelMdt"> </asp:Label>
                                 </td>
                                <td align="left">
                                       <telerik:RadComboBox ID="RadComboBox_OpportunityCategory"
                                                          runat="server"
                                                          AutoPostBack="true"
                                                          DataTextField="OpportunityCategoryName"
                                                          DataValueField="OpportunityCategoryID"
                                                          MarkFirstMatch="true"
                                                          OnSelectedIndexChanged="RadComboBox_OpportunityCategory_SelectedIndexChanged"
                                                          TabIndex="19">
                                    </telerik:RadComboBox>                        
                                </td>
                                <td align="left" >
                                    <asp:Label ID="Label_FutureProspect" runat="server" Text="<t>Future Prospect :</t>"></asp:Label>
                                </td>
                                <td align="left" >
                                 <telerik:RadComboBox ID="RadComboBox_FutureProspect"
                                                      runat="server"
                                                      MarkFirstMatch="true"
                                                      DataTextField="FutureProspectName"
                                                      DataValueField="FutureProspectID"
                                                      TabIndex="23" >
                                    </telerik:RadComboBox>
                                    
                                 </td>    
                                <td align="left" style="display:none">
                                <asp:Label ID="label_ProfitCenter" runat="server" Text="<t>Profit Center:</t>" Visible="false"></asp:Label>
                                </td>
                                <td align="left" style="display:none">
                                    <telerik:RadComboBox ID="RadComboBox_ProfitCenter" runat="server"
                                                       MarkFirstMatch="true"
                                                       DataTextField="Key"
                                                       DataValueField="Value"
                                                       TabIndex="20" Visible="false">
                                    </telerik:RadComboBox>
                                </td>                                                                        
                            </tr>
                            <tr style="height:25px;">
                               <td align="left">
                                <asp:Label ID="lblSource" runat="server" Text="<t>Source:</t>"></asp:Label>                               
                                </td>
                                <td align="left" >
                                     <telerik:RadComboBox ID="rcbSource"
                                                  runat="server"
                                                  DataTextField="OpportunitySourceName"
                                                  DataValueField="OpportunitySourceNameID"
                                                  MarkFirstMatch="true"
                                                  TabIndex="22" >
                                                 
                                    </telerik:RadComboBox>
                                </td>
                                <td align="left" >
                                     
                                       <asp:Label ID="label_Currrency" runat="server" Text="<t>Currency:</t>"></asp:Label>
                                    <asp:Label ID="lblrederrorCurrency" runat="server" Text="*"  CssClass="ClsLabelMdt"> </asp:Label>
                                </td>
                                <td align="left">
                                 <telerik:RadComboBox ID="rcbCurrency" AutoPostBack="true" OnSelectedIndexChanged="rcbCurrency_OnSelectedIndexChanged"
                                                        runat="server"
                                                        TabIndex="24" CssClass="RupeeFFont">
                                     </telerik:RadComboBox> <%--Width="170px"--%>
                                   
                                </td>                            
                            </tr>
                            <tr>                   
                                <td align="left">
                                  <asp:Label ID="label_CostCenter" runat="server" Text="<t>Cost Center:</t>" > </asp:Label>
                                     <asp:Label ID="lblCostCentermandatory" runat="server" Text="*"  CssClass="ClsLabelMdt"> </asp:Label>
                                 
                                </td>
                                <td align="left">
                                 <telerik:RadComboBox ID="RadComboBox_CostCenter"
                                                          runat="server"
                                                          EmptyMessage="Select"
                                                          AllowCustomText="True"
                                                          MarkFirstMatch="True"
                                                          ShowMoreResultsBox="True"
                                                          ItemRequestTimeout="500"
                                                          EnableLoadOnDemand="true"
                                                          OnItemsRequested="RadComboBox_CostCenter_OnItemsRequested"                                                      
                                                          TabIndex="19">
                                    </telerik:RadComboBox>  
                                     
                                </td>     
                                 <td align="left">
                                    <asp:Label ID="lblForex" runat="server" Text="Forex:"> </asp:Label>
                                    <asp:Label ID="Label12" runat="server" CssClass="ClsLabelMdt" ForeColor="red" Text="*"></asp:Label>
                                </td>
                                <td align="left">
                                    <telerik:RadComboBox ID="rcbExchangeRate" runat="server" MarkFirstMatch="True"
                                                        TabIndex="31" Height="100px" DataTextField="ExchangeRate"
                                                        DataValueField="ForexID" DropDownWidth="280px" ExpandEffect="pixelate">
                                                        <HeaderTemplate>
                                                            <table width="92%">
                                                                <tr>
                                                                    <td style="font-weight: bold">
                                                                        &nbsp; SOB Currency
                                                                    </td>
                                                                    <td style="font-weight: bold">
                                                                        Exchange Rate Type
                                                                    </td>
                                                                    <td style="font-weight: bold" align="right">
                                                                        Rate
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </HeaderTemplate>
                                                        <ItemTemplate>
                                                            <table width="100%">
                                                                <tr>
                                                                    <td style="width: 50%; font-size: 8pt; font-family: Arial;" align="left">
                                                                        &nbsp;
                                                                        <%# DataBinder.Eval(Container.DataItem, "NumOfCurrency")%>
                                                                    </td>
                                                                    <td align="left" style="font-size: 8pt; font-family: Arial;">
                                                                        <%# DataBinder.Eval(Container.DataItem, "ForeignExchangeRateTypeName")%>
                                                                    </td>
                                                                    <td align="right" style="font-size: 8pt; font-family: Arial;">
                                                                        <%# DataBinder.Eval(Container.DataItem, "ExchangeRate")%>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </ItemTemplate>
                                  </telerik:RadComboBox>
                                </td>                    
                            </tr>    
                            <tr>
                                <td align="left">
                                        <asp:Label ID="Label_Competitors" runat="server" Text="<t>Competitors :</t>"></asp:Label>
                                </td>
                                <td align="left">
                                    <telerik:RadComboBox ID="RadCombobox_MainCompetitor"
                                                  runat="server"
                                                  EmptyMessage="Select"
                                                  DataTextField="ProductManufacturerName"
                                                  DataValueField="ProductManufacturerID"
                                                  MarkFirstMatch="true"
                                                  AllowCustomText="true"
                                                  AppendDataBoundItems="true"
                                                  EnableLoadOnDemand="True"
                                                  HighlightTemplatedItems="true"
                                                  TabIndex="25"
                                                  OnItemsRequested="RadCombobox_MainCompetitor_ItemsRequested"
                                                  OnClientDropDownClosed="onDropDownClosing" >
                                        <ItemTemplate>
                                            <div>
                                                <asp:CheckBox runat="server" ID="chk1" onclick="onCheckBoxClick(this)"/>
                                                <asp:Label runat="server" ID="Label1" AssociatedControlID="chk1"></asp:Label>
                                            </div>
                                        </ItemTemplate>
                                    </telerik:RadComboBox>&nbsp;
                                    <telerik:RadButton id="btn_CompetitorDetails" runat="server"
                                                width="28px" OnClientClicked="btn_CompetitorDetails_Click" Text="..." Enabled="false" TabIndex="26">
                                    </telerik:RadButton>
                                </td>
                                <td>
                                    <asp:Label ID="Label14" runat="server" Text="<t>Sales from Local :</t>"></asp:Label>
                                </td>
                                <td>
                                    <asp:CheckBox runat="server" ID="chkIsSaleForLocal" />
                                </td>
                            </tr>                                         
                        </table>                    
                        <table style="width:100%; margin:15px 0 0 0; border:1px solid #000000; table-layout:fixed;">
                            <tr style="height:25px;">
                                <td align="left" style="width:14%;">
                                    <asp:Label ID="lbl_Activity" runat="server" Text="<t>Latest Completed Activity On Project:</t>" ></asp:Label>
                                </td>
                                <td align="left" style="width:29%;">
                                    <asp:Label ID="Label_LastActivity" runat="server" Text="" Font-Bold="true"> </asp:Label>
                                </td>
                                <td  align="right">
                                    <telerik:RadButton ID="Button_Activity_Top" runat="server"  
                                        OnClick="Button_Activities_Click"
                                        ToolTip="Activity" TabIndex="27"
                                        Text="Activities"/>
                                </td>
                              <%--  <td align="left" style="width:8%;">
                                    <asp:Label ID="label10" runat="server" Text="<t>Date:</t>" ></asp:Label>
                                </td>
                                <td align="left" style="width:17%;">
                                    <telerik:RadDatePicker ID="RadDatePicker1"  runat="server" ForeColor="Black"
                                              TabIndex="17" Culture="English (United States)" >
                                    <DateInput ID="DateInput2" runat="server" TabIndex="18" > </DateInput>                             
                                    <DatePopupButton TabIndex="19"/>
                                    </telerik:RadDatePicker>
                                </td>--%>
                            </tr>
                        </table>
                        <table style="width:100%; margin:15px 0 0 0; border:1px solid #000000; table-layout:fixed;">
                        <tr>
                            <td align="left">
                                <asp:Label CssClass="ClsLabelHead" ID="Label11" runat="server" Text="<t>Add Notes :</t>" ></asp:Label>
                            </td>
                        </tr>
                            <tr>
                                <td>
                                    <div class="ClsFormattedGridDIVForPopup">   
                                      <telerik:RadGrid ID="RadGrid_OpportunityNotes"
                                                      runat="server"                          
                                                      PageSize="5" AllowPaging="True"
                                                      PagerStyle-AlwaysVisible="false"
                                                      AllowFilteringByColumn="false" TabIndex="20"
                                                       OnNeedDataSource="RadGrid_OpportunityNotes_NeedDataSource"
                                                        OnInsertCommand="RadGrid_OpportunityNotes_InsertCommand"
                                                        OnDeleteCommand="RadGrid_OpportunityNotes_DeleteCommand"
                                                        OnItemDataBound="RadGrid_OpportunityNotes_OnItemDataBound"
                                                        OnUpdateCommand="RadGrid_OpportunityNotes_UpdateCommand"
                                                       >
                                          <MasterTableView CommandItemDisplay="Top" EditMode="InPlace">
                                          <Columns>
                                          <telerik:GridBoundColumn DataField="OpportunityNoteID" UniqueName="OpportunityNoteID" HeaderText="OpportunityNoteID" Visible="false">
                                          </telerik:GridBoundColumn>
                                          <telerik:GridBoundColumn DataField="OpportunityID" UniqueName="OpportunityID" HeaderText="OpportunityID" Visible="false">
                                          </telerik:GridBoundColumn>
                                          <telerik:GridBoundColumn DataField="AddedOn" UniqueName="AddedOn" HeaderText="Added On" DataFormatString="{0:d}">
                                          <ItemStyle HorizontalAlign="Left" Width="15%" />
                                          </telerik:GridBoundColumn>
                                          <telerik:GridTemplateColumn DataField="OpportuityNote" UniqueName="OpportuityNote" HeaderText="<t>Opportunity Note</t>" >
                                            <ItemTemplate>
                                            <asp:Label ID="lbl_Notes" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "OpportuityNote")%>'></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                            <asp:TextBox ID="text_Notes" runat="server" Width="75%" TextMode="MultiLine"></asp:TextBox>
                                            </EditItemTemplate>
                                            <ItemStyle HorizontalAlign="Left" Width="70%" />
                                          </telerik:GridTemplateColumn>
                                          <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="Edit" HeaderText="<t>Edit</t>">
                                            <ItemStyle HorizontalAlign="Center" Width="5%" />
                                          </telerik:GridEditCommandColumn>
                                
                                          <telerik:GridButtonColumn CommandName="Delete" HeaderText="<t>Delete</t>" ButtonType="ImageButton"
                                                Text="Delete" UniqueName="DeleteCommandColumn"  ConfirmText="<t>Do you want to delete this record?</t>">
                                                <ItemStyle HorizontalAlign="Left" Width="5%" />
                                          </telerik:GridButtonColumn>
                                          </Columns>
                                          </MasterTableView>  
                                    </telerik:RadGrid>
                                 </div>
                                </td>
                            </tr>
                        </table>
                        <table style="width:100%; margin:15px 0 0 0; border:1px solid #000000; table-layout:fixed;">
                        <tr>
                        <td align="right">
                                 <telerik:RadButton ID="Button_UploadDocument" runat="server" Text="Attach"
                                 CausesValidation="False"  OnClientClicked="UploadDocuments" TabIndex="28"
                                 ToolTip="<t>Attachment</t>" Visible="false" />
                                 <telerik:RadButton ID="btnManageCustomFields" runat="server" Text="Custom Fields"   TabIndex="29"  Visible="false"  Width="110px"
                                CausesValidation="False" ToolTip="<t>Manage Additional Fields</t>" OnClientClicked="ViewOpportunityCustomFields"/>  
                                 <telerik:RadButton ID="Button_Save_Top" runat="server" TabIndex="31"
                                     ToolTip="<t>Save Opportunity</t>" OnClick="Button_Save_Click" Text="Save"/>
                                 <telerik:RadButton ID="Button_Cancel" runat="server"
                                   TabIndex="30" OnClick="Button_Cancel_Click"
                                 ToolTip="<t>Cancel</t>"  Text="Cancel"/>
                                 <%-- <telerik:RadButton ID="Button_GenerateOpportunityData" runat="server" Width="180px"
                                      TabIndex="32" Visible="false"
                                     ToolTip="Generate Excel" OnClick="Button_GenerateOpportunityData_Click" Text="<t>Generate Opportunity Data</t>"/>    --%>
                                  <telerik:RadButton ID="Button_ExportOpportunityData" runat="server" Width="180px"
                                      TabIndex="32" Visible="false"
                                     ToolTip="Export Excel" OnClick="Button_ExportOpportunityData_Click" Text="<t>Export Opportunity Data</t>"/>
                        </td>
                                       
                        </tr>
                        </table>
                    </asp:View>                    
                    <asp:View ID="EmployeeActivityView" runat="server">
                        <table width="100%">
           <tr>
           <td style="height:5px" colspan="4">
           </td>
           </tr>
               <tr>
                   <td class="ClsTableHeadSub" align="left" colspan="4">
                      &nbsp;<asp:Label CssClass="ClsLabelHead" ID="Label7" runat="server"  Text="Manage Employee Activity"></asp:Label>
                   </td>
               </tr>
              <tr>
                     <td align="left" style="height: 10px">
                       <asp:Label Width="60px" ID="OpportunityName" runat="server" Font-Bold="true" Text="<t>Opportunity:</t> " visible="false"></asp:Label>
                       &nbsp;
                        <asp:Label ID="lblOpportunityName" runat="server" Font-Bold="true" ></asp:Label>
                    </td>
                    <td align="right">             
                    </td>
                </tr>   
               <tr>
                   <td align="left" colspan="4" style="height: 10px">
                   </td>
               </tr>
               <tr>
                   <td align="left" colspan="4">
                        <telerik:RadGrid ID="RadGrid_EmployeeActivityList" runat="server"                                     
                                        OnDeleteCommand="RadGrid_EmployeeActivityList_DeleteCommand"
                                        OnInsertCommand="RadGrid_EmployeeActivityList_InsertCommand"
                                        OnNeedDataSource="RadGrid_EmployeeActivityList_NeedDataSource"
                                        OnUpdateCommand="RadGrid_EmployeeActivityList_UpdateCommand"
                                        OnItemCommand="RadGrid_EmployeeActivityList_ItemCommand"
                                        OnItemDataBound="RadGrid_EmployeeActivityList_ItemDataBound"
                                        OnCancelCommand="RadGrid_Activities_CancelCommand"
                                        OnEditCommand="RadGrid_Activities_EditCommand"
                                        AllowFilteringByColumn ="true" GroupingSettings-CaseSensitive="false" PagerStyle-AlwaysVisible="false">
                            <MasterTableView DataKeyNames="EmployeeActivityID" CommandItemDisplay="Top" >
                            <EditFormSettings EditFormType="Template">
                              <FormTemplate>
                                <asp:Table ID="Table_Employee" runat="server" Width="95%">
                                    <asp:TableRow Visible="false">
                                         <asp:TableCell>&nbsp;&nbsp;
                                            <asp:Label ID="Label_EmployeeActivityID" runat="server" Text="EmployeeActivityID"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                            <asp:TextBox ID="TextBox_EmployeeActivityID" runat="server"  
                                                         Text='<%# Bind("EmployeeActivityID") %>'>
                                            </asp:TextBox>
                                        </asp:TableCell>
                                        <asp:TableCell></asp:TableCell>
                                        <asp:TableCell></asp:TableCell>
                                     </asp:TableRow>
                                     <asp:TableRow>
                                         <asp:TableCell Width="25%">&nbsp;&nbsp;
                                            <asp:Label ID="Label_GroupName" runat="server" Text="Group Name"></asp:Label>
                                            <asp:Label ID="Label5" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell >
                                           <telerik:RadComboBox ID="RadComboBox_GroupName" runat="server"                                                      
                                                          DataTextField="ActivityGroupName"
                                                          DataValueField="ActivityGroupID"
                                                          AutoPostBack="True" Width="200px"
                                                          OnSelectedIndexChanged="RadComboBox_GroupName_SelectedIndexChanged"
                                                          AllowCustomText="True" EnableLoadOnDemand="True"
                                                          MarkFirstMatch="True"
                                                          ShowMoreResultsBox="True"
                                                          OnItemsRequested="RadComboBox_GroupName_ItemsRequested"
                                                          ItemRequestTimeout="500"
                                                          Height="140px">
                                            </telerik:RadComboBox>
                                        </asp:TableCell>
                                        <asp:TableCell>&nbsp;&nbsp;
                                            <asp:Label ID="Label_ActivityName" runat="server" Text="Activity"></asp:Label>
                                            <asp:Label ID="Label9" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                             <telerik:RadComboBox ID="RadComboBox_Activity" runat="server"
                                                              Width="200px"
                                                              DataTextField="ActivityName" DataValueField="ActivityID"
                                                              AllowCustomText="True"
                                                              EnableLoadOnDemand="True"
                                                              MarkFirstMatch="True"
                                                              ShowMoreResultsBox="True"
                                                              OnItemsRequested="RadComboBox_Activity_ItemsRequested"
                                                              ItemRequestTimeout="500"
                                                              
                                                              Height="140px" >
                                            </telerik:RadComboBox>
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell>&nbsp;&nbsp;
                                                 <asp:Label ID="Label_EmpActivityCustomer" runat="server" Text="Customer"></asp:Label>
                                                 <asp:Label ID="Label3" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                                        </asp:TableCell>
                                        <asp:TableCell>
                                                 <telerik:RadComboBox ID="RadComboBox_EmpActivityCustomer" runat="server"
                                                                  Width="200px"
                                                                  AllowCustomText="True"
                                                                  MarkFirstMatch="True"
                                                                  ShowMoreResultsBox="True"
                                                                  EnableLoadOnDemand="true"
                                                                  OnItemsRequested="RadComboBox_EmpActivityCustomer_OnItemsRequested"
                                                                  OnSelectedIndexChanged="RadComboBox_EmpActivityCustomer_OnSelectedIndexChanged"
                                                                  ItemRequestTimeout="500"
                                                                  AutoPostBack="True"
                                                                  Height="140px" >
                                                </telerik:RadComboBox>
                                         </asp:TableCell>
                                         <asp:TableCell>&nbsp;&nbsp;
                                                 <asp:Label ID="Label_EmpActivityCustomerContact" runat="server" Text="Customer Contact"></asp:Label>
                                                 <asp:Label ID="Label7" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                                        </asp:TableCell>
                                        <asp:TableCell>
                                                 <telerik:RadComboBox ID="RadComboBox_EmpActivityCustomerContact" runat="server"
                                                                  Width="200px"
                                                                  AllowCustomText="True"
                                                                  MarkFirstMatch="True"
                                                                  ShowMoreResultsBox="True"
                                                                  ItemRequestTimeout="500"
                                                                  EnableLoadOnDemand="true"
                                                                  OnItemsRequested="RadComboBox_EmpActivityCustomerContact_OnItemsRequested"
                                                                  Height="140px" >
                                                </telerik:RadComboBox>
                                         </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                         <asp:TableCell>&nbsp;&nbsp;
                                                    <asp:Label ID="Label_PlannedActivityDate" runat="server" Text="Planned Date:"></asp:Label>
                                                    <asp:Label ID="Label_Must" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                                                    <asp:Label ID="Label_plannedDate_format" runat="server" Text="(dd-mm-yyyy hh:mm)"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                            <telerik:RadDateTimePicker ID="DatePicker_PlannedActivityDate" runat="server"
                                                                  Width="140px"  TimePopupButton-Visible="false"
                                                                  DbSelectedDate='<%# Bind("PlannedActivityDate") %>' >
                                             <DateInput ID="DateInput1" runat="server" TabIndex="7"> </DateInput>
                                            </telerik:RadDateTimePicker>
                                          
                                         </asp:TableCell>
                                         <asp:TableCell>&nbsp;&nbsp;
                                              <asp:Label ID="Label_ActualDate" runat="server" Text="Actual Date:"></asp:Label>
                                              <asp:Label ID="Label_ActualDate_Format" runat="server" Text="(dd-mm-yyyy hh:mm)"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                               <telerik:RadDateTimePicker ID="RadDatePicker_ActualActivityDate" runat="server"
                                                                     MaxDate="9999-12-31" MinDate="1900-01-01"  Width="140px" TimePopupButton-Visible="false"
                                                                     DbSelectedDate='<%# Bind("ActualActivityDate") %>' >
                                              <DateInput ID="DateInput2" runat="server" TabIndex="7"> </DateInput>                   
                                            </telerik:RadDateTimePicker>
                                          
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow>
                                        <asp:TableCell>&nbsp;&nbsp;
                                             <asp:Label ID="Label_Purpose" runat="server" Text="Purpose"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                                 <asp:TextBox ID="TextBox_Purpose" runat="server"  Rows="2" TextMode="MultiLine" Width="200px"
                                                    Text='<%# Bind("Purpose") %>' >
                                                </asp:TextBox>
                                         </asp:TableCell>
                                         <asp:TableCell>&nbsp;&nbsp;
                                             <asp:Label ID="Label_Venue" runat="server" Text="Venue"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                              <asp:TextBox ID="TextBox_Venue" runat="server"   Rows="2" TextMode="MultiLine" Width="200px"
                                                    Text='<%# Bind("Venue") %>'>
                                            </asp:TextBox>
                                         </asp:TableCell>
                                     </asp:TableRow>
                                     <asp:TableRow>
                                        <asp:TableCell>&nbsp;&nbsp;
                                             <asp:Label ID="Label_Notes" runat="server" Text="Notes"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell ColumnSpan="3">
                                                <asp:TextBox ID="TextBox_Notes" runat="server" Text='<%# Bind("Notes") %>'  Rows="3" Width="400px" TextMode="MultiLine" ></asp:TextBox>
                                         </asp:TableCell>
                                      </asp:TableRow>
                                      <asp:TableRow>
                                         <asp:TableCell>&nbsp;&nbsp;
                                             <asp:Label ID="Label_IsCompleted" runat="server" Text="Is Completed"></asp:Label>
                                         </asp:TableCell>
                                         <asp:TableCell>
                                                <asp:CheckBox ID="CheckBox_IsCompleted" runat="server"  />
                                         </asp:TableCell>
                                         <asp:TableCell></asp:TableCell>
                                         <asp:TableCell></asp:TableCell>
                                      </asp:TableRow>
                                        <asp:TableRow HorizontalAlign="Left">
                                                <asp:TableCell Width="5%">&nbsp;&nbsp;
                                                
                                                    <asp:ImageButton ID="Button_Save" runat="server"  CommandName='<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted"))?"PerformInsert":"Update"%>' ImageUrl = '<%# ((bool)DataBinder.Eval(Container, "OwnerTableView.IsItemInserted")) ? "~/Images/Insert.gif" : "~/Images/Update.gif" %>'/>
                                                    <asp:ImageButton ID="Button_Close" runat="server"  ImageUrl="~/Images/Cancel.gif" CommandName="Cancel" CausesValidation="false" />
                                                </asp:TableCell>
                                                <asp:TableCell ColumnSpan="5">
                                                </asp:TableCell>
                                        </asp:TableRow>
                                </asp:Table>
                       </FormTemplate>
                        </EditFormSettings>
                         <Columns>
                             <telerik:GridBoundColumn HeaderText="EmployeeActivityID" UniqueName="EmployeeActivityID" DataField="EmployeeActivityID" Visible="False">
                             </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Activity Name" UniqueName="ActivityName" DataField="ActivityName">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Activity Group ID" UniqueName="ActivityGroupID" Visible="false" DataField="ActivityGroupID">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Activity Group Name" UniqueName="ActivityGroupName" Visible="false" DataField="ActivityName">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="OpportunityID" Visible="false" UniqueName="OpportunityID" DataField="OpportunityID">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="CustomerID" Visible="false" UniqueName="CustomerID" DataField="CustomerID">
                              </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn HeaderText="CustomerContactID" Visible="false" UniqueName="CustomerContactID" DataField="CustomerContactID">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Planned Date" UniqueName="PlannedActivityDate" DataField="PlannedActivityDate" DataFormatString="{0:d}">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Actual Date" UniqueName="ActualActivityDate" DataField="ActualActivityDate" DataFormatString="{0:d}">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Venue" UniqueName="Venue" DataField="Venue" Visible="false">
                              </telerik:GridBoundColumn>
                               <telerik:GridBoundColumn HeaderText="Purpose" UniqueName="Purpose" DataField="Purpose" Visible="false">
                              </telerik:GridBoundColumn>
                              <telerik:GridBoundColumn HeaderText="Notes" UniqueName="Notes" DataField="Notes" >
                              </telerik:GridBoundColumn>
                              <telerik:GridCheckBoxColumn DataField="IsCompleted" HeaderText="Is Completed"
                                                      UniqueName="IsCompleted"
                                                      DataType="System.Boolean">
                                       <ItemStyle HorizontalAlign="left" width="5%"/>
                              </telerik:GridCheckBoxColumn>
                             <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderText="Edit">
                              <ItemStyle HorizontalAlign="center" width="5%"/>
                             </telerik:GridEditCommandColumn>
                             <telerik:GridButtonColumn  ButtonType="ImageButton" CommandName="Delete" HeaderText="Delete"
                                                    Text="Delete"                                            
                                                    UniqueName="DeleteCommandColumn" ConfirmText ="Are you sure you want to delete the Activity?">
                                                     <ItemStyle HorizontalAlign="center" width="5%"/>
                             </telerik:GridButtonColumn>
                            </Columns>
                            <ExpandCollapseColumn Visible="False">
                            <HeaderStyle Width="19px" />
                            </ExpandCollapseColumn>
                            <RowIndicatorColumn Visible="False">
                            <HeaderStyle Width="20px" />
                            </RowIndicatorColumn>
                            <PagerStyle Mode="NextPrevAndNumeric" />
                        </MasterTableView>
                     <GroupingSettings CaseSensitive="False" />
                    </telerik:RadGrid>
                   </td>
               </tr>
               <tr>
                   <td align="left" style="height: 10px" colspan="4">
                   </td>
               </tr>
               <tr>
                   <td align="center" colspan="4" style="height: 16px">
                        &nbsp;<telerik:RadButton ID="ImageButton_Back" runat="server"  
                        CausesValidation="False" Text="Back"
                        OnClick="Button_Back_Click" />
                     
                   </td>
               </tr>
           </table>
                    </asp:View>
                </asp:MultiView>          
                </telerik:RadPageView>             
                <telerik:RadPageView ID="MPAddressInfoDataView" runat="server"  CssClass="ClsDivBorder">
                       <table style="width:100%; margin:15px 0 0 0; border:1px solid gray; table-layout:fixed;">
                    <th colspan="4" align="left">
                    <asp:Label ID="Label13" runat="server" Text="Site Address:" CssClass="ClsLabelHead"></asp:Label>
                    </th>
                        <tr style="height:25px;">
                            <td align="left" style="width:8%;">
                               <asp:Label ID="Label_SLine1" runat="server" Text="<t>Line 1:</t>"></asp:Label>
                               <asp:Label ID="Label_SLine1_Mandatory" runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label>
                            </td>
                            
                            <td align="left" style="width:17%;">
                              <asp:TextBox ID="TextBox_SAddressLine1" runat="server" CssClass="ClsTextBoxMid" TabIndex="11"  ></asp:TextBox>
                            </td>
                            <td style="width: 8%;" align="left">
                                    <asp:Label ID="Label_SCountry" runat="server" Text="<t>Country:</t>" Width="58px"></asp:Label><asp:Label ID="Label23"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td style="width: 17%;" align="left">
                                    <telerik:RadComboBox ID="RadComboBox_SCountryName" runat="server" AllowCustomText="True"
                                                          AutoPostBack="true"                                                     
                                                          TabIndex="12"
                                                          MarkFirstMatch="True"
                                                          OnSelectedIndexChanged="RadComboBox_SCountryName_SelectedIndexChanged"
                                                          >
                                        </telerik:RadComboBox>
                                    </td>
                            
                        </tr>
                        <tr style="height:25px;">
                            <td align="left">
                               <asp:Label ID="Label_SLine2" runat="server" Text="<t>Line 2:</t>" ></asp:Label>
                            </td>
                             <td align="left">
                               <asp:TextBox ID="TextBox_SAddressLine2" runat="server" CssClass="ClsTextBoxMid" TabIndex="13" ></asp:TextBox>
                            </td>
                            <td  align="left">
                                    <asp:Label ID="Label_SState" runat="server" Text="<t>State:</t>" Width="56px"></asp:Label><asp:Label ID="Label22"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td  align="left">
                                    <telerik:RadComboBox ID="RadComboBox_SStateName" runat="server"
                                                          AutoPostBack="true" MarkFirstMatch="true"
                                                          TabIndex="14"
                                                          OnSelectedIndexChanged="RadComboBox_SStateName_SelectedIndexChanged">
                                   </telerik:RadComboBox>
                                    </td>
                        </tr>
                        <tr style="height:25px;">
                            <td align="left">
                                <asp:Label ID="Label_SLine3" runat="server" Text="<t>Line 3:</t>"></asp:Label>
                            </td>
                            <td align="left" >
                                <asp:TextBox ID="TextBox_SAddressLine3" runat="server" CssClass="ClsTextBoxMid" TabIndex="15"  ></asp:TextBox>
                            </td>
                            <td  align="left">
                                    <asp:Label ID="Label_SCity" runat="server" Text="<t>City:</t>" Width="57px"> </asp:Label>
                                    <asp:Label ID="Label21" runat="server" CssClass="ClsLabelMdt" Text="*"> </asp:Label>
                            </td>
                                <td  align="left">
                                   <telerik:RadComboBox ID="RadComboBox_SCityName" runat="server"
                                                          AutoPostBack="true"
                                                          DataTextField="Value"
                                                          DataValueField="Key"
                                                          ItemRequestTimeout="500"
                                                          MarkFirstMatch="True"  
                                                          TabIndex="16"
                                                          OnSelectedIndexChanged="RadComboBox_SCityName_SelectedIndexChanged"
                                                          >
                                         </telerik:RadComboBox>
                                         <asp:TextBox ID="TextBox_SCity" runat="server" CssClass="ClsTextBoxLrgMdt" Visible="False" TabIndex="17"></asp:TextBox>
                                 </td>
                            
                        </tr>
                        <tr style="height:25px;">
                            <td align="left">
                                <asp:Label ID="Label_SPinCode" runat="server" Text="<t>Pin Code:</t>"></asp:Label>
                            </td>
                             <td align="left">
                                <asp:TextBox ID="TextBox_SZipCode" runat="server" CssClass="ClsTextBoxMid" TabIndex="18" ></asp:TextBox>
                            </td>
                            <td align="left">
                                <asp:Label ID="Label_STelephoneNo" runat="server" Text="<t>Tel:</t>" ></asp:Label>
                            </td>
                            <td align="left">
                                <asp:TextBox ID="TextBox_STelephoneNo" runat="server" CssClass="ClsTextBoxMid" TabIndex="19" ></asp:TextBox>
                            </td>
                           
                        </tr>
                    </table>                
                       <table style="width:100%; margin:15px 0 0 0; border:1px solid gray; table-layout:fixed;">
                      <th colspan="4" align="left">
                            <asp:Label ID="Label_BillingAddress" runat="server" Text="Billing Address:" CssClass="ClsLabelHead"></asp:Label>
                            <telerik:RadButton ID="Button_SameAsAbove" runat="server" Text="Same As Above" Width="110px"
                                 CausesValidation="False"  OnClick="Button_SameAsAbove_OnClick" TabIndex="20"
                                 ToolTip="<t>Same As Above</t>" />
                      </th>
                        <tr style="height:25px;">
                            <td align="left" style="width:8%;">
                               <asp:Label ID="Label_BLine1" runat="server" Text="<t>Line 1:</t>"></asp:Label>
                            </td>
                            <td align="left" style="width:17%;">
                              <asp:TextBox ID="TextBox_BAddressLine1" runat="server" CssClass="ClsTextBoxMid" TabIndex="21"  ></asp:TextBox>
                            </td>
                            <td style="width: 8%;" align="left">
                                    <asp:Label ID="Label_bCountry" runat="server" Text="<t>Country:</t>" Width="58px"></asp:Label><asp:Label ID="Label4"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td style="width: 17%;" align="left">
                                    <telerik:RadComboBox ID="RadComboBox_BCountryName" runat="server" AllowCustomText="True"
                                                          AutoPostBack="true"
                                                         
                                                          TabIndex="22"
                                                          MarkFirstMatch="True"
                                                           OnSelectedIndexChanged="RadComboBox_BCountryName_SelectedIndexChanged"
                                                          >
                                        </telerik:RadComboBox>
                                        </td>
                                    
                            
                        </tr>
                        <tr style="height:25px;">
                            <td align="left">
                               <asp:Label ID="Label_BLine2" runat="server" Text="<t>Line 2:</t>" ></asp:Label>
                            </td>
                             <td align="left">
                               <asp:TextBox ID="TextBox_BAddressLine2" runat="server" CssClass="ClsTextBoxMid" TabIndex="23" ></asp:TextBox>
                            </td>
                            <td  align="left">
                                    <asp:Label ID="Label_BState" runat="server" Text="<t>State:</t>" Width="56px"></asp:Label><asp:Label ID="Label5"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td  align="left">
                                    <telerik:RadComboBox ID="RadComboBox_BStateName" runat="server"
                                                          AutoPostBack="true" MarkFirstMatch="true"
                                                         OnSelectedIndexChanged="RadComboBox_BStateName_SelectedIndexChanged"
                                                          TabIndex="24"
                                                          
                                                          >
                                        </telerik:RadComboBox>
                                    </td>
                                    
                             
                        </tr>
                        <tr style="height:25px;">
                            <td align="left" style="width:8%;">
                                <asp:Label ID="Label_BLine3" runat="server" Text="<t>Line 3:</t>"></asp:Label>
                            </td>
                            <td align="left" style="width:17%;">
                                <asp:TextBox ID="TextBox_BAddressLine3" runat="server" CssClass="ClsTextBoxMid" TabIndex="25"  ></asp:TextBox>
                            </td>
                            <td  align="left">
                                    <asp:Label ID="Label_BCity" runat="server" Text="<t>City:</t>" Width="57px"></asp:Label><asp:Label ID="Label3"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td  align="left">
                                   <telerik:RadComboBox ID="RadComboBox_BCityName" runat="server"
                                                          AutoPostBack="true"
                                                          DataTextField="Value"
                                                          DataValueField="Key"
                                                          ItemRequestTimeout="500"
                                                          MarkFirstMatch="True"  
                                                          TabIndex="26"
                                                          OnSelectedIndexChanged="RadComboBox_BCityName_SelectedIndexChanged"
                                                          >
                                         </telerik:RadComboBox>
                                          <asp:TextBox ID="TextBox_BCity" runat="server" CssClass="ClsTextBoxLrgMdt" Visible="False" TabIndex="7"></asp:TextBox>
                                 </td>
                            
                        </tr>
                        <tr style="height:25px;">
                            <td align="left">
                                <asp:Label ID="Label_BPinCode" runat="server" Text="<t>Pin Code:</t>"></asp:Label>
                            </td>
                             <td align="left">
                                <asp:TextBox ID="TextBox_BZipcode" runat="server" CssClass="ClsTextBoxMid" TabIndex="27" ></asp:TextBox>
                            </td>
                            <td align="left">
                                <asp:Label ID="Label_BTelephoneNo" runat="server" Text="<t>Tel:</t>" ></asp:Label>
                            </td>
                            <td align="left">
                                <asp:TextBox ID="TextBox_BTelephoneNo" runat="server" CssClass="ClsTextBoxMid" TabIndex="28" ></asp:TextBox>
                            </td>
                           
                        </tr>
                    </table>                 
                       <table style="width:100%; margin:15px 0 0 0; border:1px solid gray; table-layout:fixed;">
                      <th colspan="4" align="left">
                            <asp:Label ID="Label_TempStorage_location" runat="server" Text="Temporary  Storage Location:" CssClass="ClsLabelHead"></asp:Label>
                            
                      </th>                  
                      <tr>
                          <td align="left" style="width:8%;">
                              <asp:Label ID="Label_Material_InDate" runat="server" Text="<t>Material In Date:</t>"></asp:Label>
                          </td>
                          <td align="left" style="width:17%;">
                               <telerik:RadDatePicker ID="RadDatePicker_InDate"  runat="server" ForeColor="Black" TabIndex="29">
                               <DateInput ID="DateInput3" runat="server" TabIndex="30"> </DateInput>                             
                               <DatePopupButton TabIndex="31"/>
                               </telerik:RadDatePicker>
                          </td>
                          <td align="left" style="width:8%;">
                                <asp:Label ID="Label_Material_DispatchedDate" runat="server" Text="<t>Dispatched Date:</t>"></asp:Label>
                          </td>
                          <td align="left" style="width:17%;">
                                <telerik:RadDatePicker ID="RadDatePicker_DispatchedDate"  runat="server" ForeColor="Black" TabIndex="32">
                                <DateInput ID="DateInput4" runat="server" TabIndex="33" > </DateInput>                           
                                <DatePopupButton TabIndex="34"/>
                                </telerik:RadDatePicker>
                          </td>
                        </tr>                        
                        <tr style="height:25px;">
                            <td align="left" >
                               <asp:Label ID="Label_TLine1" runat="server" Text="<t>Line 1:</t>"></asp:Label>
                            </td>
                            <td align="left" >
                              <asp:TextBox ID="TextBox_TAddressLine1" runat="server" CssClass="ClsTextBoxMid" TabIndex="35"  ></asp:TextBox>
                            </td>
                            <td  align="left">
                                    <asp:Label ID="Label_TCountry" runat="server" Text="<t>Country:</t>" Width="58px"></asp:Label><asp:Label ID="Label6"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td  align="left">
                                    <telerik:RadComboBox ID="RadComboBox_TCountryName" runat="server" AllowCustomText="True"
                                                          AutoPostBack="true"
                                                         
                                                          TabIndex="36"
                                                          MarkFirstMatch="True"
                                                          OnSelectedIndexChanged="RadComboBox_TCountryName_SelectedIndexChanged"
                                                          >
                                        </telerik:RadComboBox>
                            
                        </tr>
                        <tr>
                        <td align="left">
                               <asp:Label ID="Label_TLine2" runat="server" Text="<t>Line 2:</t>" ></asp:Label>
                            </td>
                             <td align="left">
                               <asp:TextBox ID="TextBox_TAddressLine2" runat="server" CssClass="ClsTextBoxMid" TabIndex="37" ></asp:TextBox>
                            </td>
                            <td align="left">
                                    <asp:Label ID="Label_TState" runat="server" Text="<t>State:</t>" Width="56px"></asp:Label><asp:Label ID="Label8"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td  align="left">
                                    <telerik:RadComboBox ID="RadComboBox_TStateName" runat="server"
                                                          AutoPostBack="true" MarkFirstMatch="true"
                                                         
                                                          TabIndex="38"
                                                          OnSelectedIndexChanged="RadComboBox_TStateName_SelectedIndexChanged"
                                                          >
                                        </telerik:RadComboBox>
                                    
                                    </td>
                            
                        </tr>
                        <tr style="height:25px;">
                            
                            <td align="left" style="width:8%;">
                                <asp:Label ID="Label_TLine3" runat="server" Text="<t>Line 3:</t>"></asp:Label>
                            </td>
                            <td align="left" style="width:17%;">
                                <asp:TextBox ID="TextBox_TAddressLine3" runat="server" CssClass="ClsTextBoxMid" TabIndex="39"  ></asp:TextBox>
                            </td>
                            <td  align="left">
                                    <asp:Label ID="Label_TCity" runat="server" Text="<t>City:</t>" Width="57px"></asp:Label><asp:Label ID="Label9"
                                        runat="server" CssClass="ClsLabelMdt" Text="*"></asp:Label></td>
                                <td  align="left">
                                   <telerik:RadComboBox ID="RadComboBox_TCityName" runat="server"
                                                          AutoPostBack="true"
                                                          DataTextField="Value"
                                                          DataValueField="Key"
                                                          ItemRequestTimeout="500"
                                                          MarkFirstMatch="True"  
                                                          TabIndex="40"
                                                          OnSelectedIndexChanged="RadComboBox_TCityName_SelectedIndexChanged"
                                                          >
                                         </telerik:RadComboBox>
                                          <asp:TextBox ID="TextBox_TCity" runat="server" CssClass="ClsTextBoxLrgMdt" Visible="False" TabIndex="41"></asp:TextBox>
                                 </td>
                             
                        </tr>
                        <tr style="height:25px;">                        
                            <td align="left">
                                <asp:Label ID="Label_TPinCode" runat="server" Text="<t>Pin Code:</t>"></asp:Label>
                            </td>
                             <td align="left">
                                <asp:TextBox ID="TextBox_TZipCode" runat="server" CssClass="ClsTextBoxMid" TabIndex="42" ></asp:TextBox>
                            </td>
                            <td align="left">
                                <asp:Label ID="Label_TTel" runat="server" Text="<t>Tel:</t>" ></asp:Label>
                            </td>
                            <td align="left">
                                <asp:TextBox ID="TextBox_TTelephoneNo" runat="server" CssClass="ClsTextBoxMid" TabIndex="43" ></asp:TextBox>
                            </td>                        
                        </tr>
                        <tr style="height:25px;">
                            <td align="left">
                                    <asp:Label ID="Label_ContactPerson" runat="server" Text="<t>Contact Person:</t>" Visible="false"></asp:Label>
                                </td>
                                <td align="left">
                                     <asp:TextBox ID="TextBox_ContactPerson" runat="server" CssClass="ClsTextBoxMid" TabIndex="44" Visible="false"></asp:TextBox>
                                </td>
                                <td colspan="2"></td>
                        </tr>
                    </table>                
                       <table style="width:100%; margin:15px 0 0 0; border:1px solid gray; table-layout:fixed;">
                        <tr>
                            <td align="right">
                                 <%--<telerik:RadButton ID="Button5" runat="server"
                                             TabIndex="34"
                                             ToolTip="<t>Save Opportunity</t>"  Text="Cancel"/>--%>
                                    
                                 <telerik:RadButton ID="Button_Save_OppLocations" runat="server"
                                             TabIndex="45" OnClick="Button_Save_OppLocations_OnClick"
                                             ToolTip="<t>Save Opportunity Locations</t>"  Text="Save"/>
                            </td>
                        </tr>
                     </table>                            
                </telerik:RadPageView>
                <telerik:RadPageView ID="MPCustomerDataView" runat="server" width="100%"  CssClass="ClsDivBorder">
                       <table style="width:100%;" >
                      <tr>
                          <td style="height:7px;"> </td>
                      </tr>
                      <tr>
                       <td align="right">
                          <%--  <telerik:RadButton ID="Button1" Text="Audit Trail Report"  runat="server"  OnClick="OnButtonClick_ShowAuditrailReport" visible="false"
                            ToolTip="Audit Trail Report" Width="130" />--%>
                            </td>
                      </tr>
                        <tr>
                            <td align="left" > &nbsp;
                                     <asp:Label CssClass="ClsSubLabelHead" ID="Label_SoldToParty" runat="server"  Text="<t>Sold To Party</t>" > </asp:Label>
                            </td>
                            
                        </tr>
                
                      <tr>
                            <td align="left"> &nbsp;
                                     <asp:LinkButton ID="LinkButton_SoldTo_AddNew"  Font-Size="Small" OnClientClick="javascript: ShowSearchPopupForOpportunityCustomers('IsSoldTo=true')" runat="server"  Text="Add New" ></asp:LinkButton>
                           </td>
                      </tr>
                     <tr><td>
                         <div class="ClsFormattedGridDIVForPopup">
                          <telerik:RadGrid ID="RadGrid_OpportunityCustomerContacts_SoldToParty" runat="server"
                                         
                                          AllowPaging="True" AllowFilteringByColumn="false"
                                          PageSize="5"                               
                                          OnNeedDataSource="RadGrid_OpportunityCustomerContacts_SoldToParty_NeedDataSource"
                                          OnUpdateCommand="RadGrid_OpportunityCustomerContacts_SoldToParty_UpdateCommand"
                                          OnDeleteCommand="RadGrid_OpportunityCustomerContacts_SoldToParty_DeleteCommand"
                                          OnCreateColumnEditor="RadGrid_OpportunityCustomerContacts_SoldToParty_CreateColumnEditor"
                                          OnItemCommand="RadGrid_OpportunityCustomerContacts_SoldToParty_ItemCommand"  
                                          OnItemCreated="RadGrid_OpportunityCustomerContacts_SoldToParty_OnItemCreated"
                                          OnItemDataBound="RadGrid_OpportunityCustomerContacts_SoldToParty_OnItemDataBound"                                     
                                          PagerStyle-AlwaysVisible="false">
                                <MasterTableView  DataKeyNames="OpportunityID,CustomerID" EditMode="InPlace">
                                    <ExpandCollapseColumn Visible="False">
                                        <HeaderStyle  HorizontalAlign="Left" Width="19px" />
                                    </ExpandCollapseColumn>
                                    <RowIndicatorColumn Visible="False">
                                        <HeaderStyle Width="20px" HorizontalAlign="Left" />
                                    </RowIndicatorColumn>
                                    <Columns>
                                        <telerik:GridBoundColumn AllowFiltering="False" DataField="OpportunityID" HeaderText="Opportunity ID"
                                                              UniqueName="OpportunityID" Visible="False" ReadOnly="True">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer ID" UniqueName="CustomerID" ReadOnly="True" Visible="False">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerName" HeaderStyle-HorizontalAlign="Left" HeaderText="Company" UniqueName="CustomerName" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                           <telerik:GridBoundColumn DataField="CustomerNo" HeaderStyle-HorizontalAlign="Left" HeaderText="Company No" UniqueName="CustomerNo" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="PhoneNumber1" HeaderStyle-HorizontalAlign="Left" HeaderText="Phone # " UniqueName="PhoneNumber" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="FaxNumber" HeaderStyle-HorizontalAlign="Left" HeaderText="Fax #" UniqueName="FaxNumber" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>                                   
                                        <telerik:GridBoundColumn DataField="CustomerTypeName" HeaderStyle-HorizontalAlign="Left" HeaderText="Company Type" UniqueName="CustomerTypeName" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerRoleID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer ID" UniqueName="CustomerRoleID" Visible="False">
                                        </telerik:GridBoundColumn>
                                         <telerik:GridBoundColumn DataField="CustomerContactID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer Contact ID"
                                                               UniqueName="CustomerContactID" Visible="false"> <%--Visible="False" ReadOnly="True"--%>
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerContactName" HeaderText="Contact" HeaderStyle-HorizontalAlign="Left"
                                                              UniqueName="CustomerContactName" ReadOnly="True">
                                                              <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                         <telerik:GridHyperLinkColumn DataTextField="CustomerContactEmailID" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Email</t>" AllowFiltering="true" DataType="System.String"
                                                                  UniqueName="CustomerContactEmailID"  DataNavigateUrlFields="CustomerContactEmailID" DataNavigateUrlFormatString="mailto:{0}">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridHyperLinkColumn>
                                         <telerik:GridCheckBoxColumn DataField="AttentionTo" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Attention To?</t>"  UniqueName="AttentionTo">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridDropDownColumn DataField="CustomerContactRoleID" ListTextField="Value"  HeaderStyle-HorizontalAlign="Left"
                                                                 ListValueField="Key" UniqueName="CustomerContactRoleID" HeaderText="Role">
                                                                
                                        </telerik:GridDropDownColumn>
                                        <telerik:GridBoundColumn DataField="DesignationName" HeaderStyle-HorizontalAlign="Left" HeaderText="Designation" UniqueName="Designation" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>   
                                    <telerik:GridCheckBoxColumn DataField="IsMain" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Main?</t>" UniqueName="IsMain">
                                        </telerik:GridCheckBoxColumn>
                                        
                                        <%-- <telerik:GridTemplateColumn DataField="IsMain" UniqueName="IsMain" HeaderText="<t>Is Main</t>" >
                                             <ItemTemplate>
                                             <asp:CheckBox ID="chkIsMain" runat="server" Checked='<%# DataBinder.Eval(Container.DataItem, "IsMain")%>' />
                                             </ItemTemplate>
                                             <EditItemTemplate>
                                                  <asp:CheckBox ID="lblOrganizationName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "IsMain")%>' />                                       
                                             </EditItemTemplate>
                                             <ItemStyle HorizontalAlign="Left" Width="40%" />
                    </telerik:GridTemplateColumn>--%>
                      
                                        
                                        <telerik:GridCheckBoxColumn DataField="IsActive" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Active?</t>" UniqueName="IsActive">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridEditCommandColumn HeaderStyle-HorizontalAlign="Left" ButtonType="ImageButton" HeaderText="Edit">
                                        </telerik:GridEditCommandColumn>
                                        <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete" ButtonType="ImageButton" HeaderStyle-HorizontalAlign="Left"
                                                               Text="Delete" UniqueName="DeleteCommandColumn" ConfirmText="Do you want to delete this record?">
                                        </telerik:GridButtonColumn>
                                         <telerik:GridCheckBoxColumn DataField="IsSoldTo" HeaderText="IsSoldTo"
                                        UniqueName="IsSoldTo" Visible="false" AutoPostBackOnFilter="true" DataType="System.Boolean">
                                        <ItemStyle HorizontalAlign="Center" />
                                        <HeaderStyle Width="5%" />
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridTemplateColumn HeaderText="Report" UniqueName="CustomerReport" Display="false"  
                                                  AllowFiltering="False"  >
                                          <ItemTemplate>
                                            <asp:LinkButton ID="Button_CustomerReport" runat="server" ToolTip="Report"
                                                  CommandName="Report" Text="Report" />
                                          </ItemTemplate>
                                          <EditItemTemplate>
                                                <asp:ImageButton ID="Button_CustomerReport" runat="server" Text="Report" ToolTip="Report"
                                                CommandName="Report" ImageUrl="~/Images/Print.gif"   />
                                          </EditItemTemplate>
                                        <HeaderStyle Width="5%"/>
                                       </telerik:GridTemplateColumn>
                                       <telerik:GridClientSelectColumn HeaderText="<t>Select</t>" UniqueName="CheckBoxSelect" >
                                            <ItemStyle HorizontalAlign="Center" />
                                            </telerik:GridClientSelectColumn>
                                        </Columns>
                                        <EditFormSettings>
                                        <EditColumn ButtonType="ImageButton">    </EditColumn>
                                    </EditFormSettings>
                                </MasterTableView>
                                
                                <ClientSettings Selecting-AllowRowSelect="true">
                                </ClientSettings>
                              </telerik:RadGrid>
                         </div>
                        </td>
                     </tr>   
                            <tr>
                               <td align="right">
                                    <telerik:RadButton ID="Button_Copy" runat="server" Text="Copy As Bill To" CssClass="ClsButton100px"  Visible="True" TabIndex="26"
                                         OnClick="Button_Copy_Click" ToolTip="Copy selected record"/>
                                   
                               </td>
                            </tr>
                  </table>                          
                       <table style="width:100%;" runat="server" id="tblBillToLbl" >
                        <tr>
                           <td style="height:7px;"> </td>
                        </tr>
                              
                        <tr>
                            <td align="left" > &nbsp;
                               <asp:Label CssClass="ClsSubLabelHead" ID="lbl_BillToParty" runat="server"  Text="<t>Bill To Party</t>" > </asp:Label>
                            </td>
                           
                        </tr>
                
                 <tr>
                     <td align="left"> &nbsp;
                         <asp:LinkButton ID="LinkButton_BillTo_AddNew"  Font-Size="Small" OnClientClick="javascript: ShowSearchPopupForOpportunityCustomers('IsBillTo=true')" runat="server"  Text="Add New" ></asp:LinkButton>
                     </td>
                 </tr>
                  <tr><td>
                           <div class="ClsFormattedGridDIVForPopup">
                           <telerik:RadGrid ID="RadGrid_OpportunityCustomerContacts_BillToParty" runat="server"
                                         
                                          AllowPaging="True" AllowFilteringByColumn="false"
                                          PageSize="5"                               
                                          OnNeedDataSource="RadGrid_OpportunityCustomerContacts_BillToParty_NeedDataSource"
                                          OnUpdateCommand="RadGrid_OpportunityCustomerContacts_BillToParty_UpdateCommand"
                                          OnDeleteCommand="RadGrid_OpportunityCustomerContacts_BillToParty_DeleteCommand"
                                          OnCreateColumnEditor="RadGrid_OpportunityCustomerContacts_BillToParty_CreateColumnEditor"
                                          PagerStyle-AlwaysVisible="false">
                                  <MasterTableView  DataKeyNames="OpportunityID,CustomerID" EditMode="InPlace">
                                    <ExpandCollapseColumn Visible="False">
                                        <HeaderStyle  HorizontalAlign="Left" Width="19px" />
                                    </ExpandCollapseColumn>
                                    <RowIndicatorColumn Visible="False">
                                        <HeaderStyle Width="20px" HorizontalAlign="Left" />
                                    </RowIndicatorColumn>
                                    <Columns>
                                        <telerik:GridBoundColumn AllowFiltering="False" DataField="OpportunityID" HeaderText="Opportunity ID"
                                                              UniqueName="OpportunityID" Visible="False" ReadOnly="True">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer ID" UniqueName="CustomerID" ReadOnly="True" Visible="False">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerName" HeaderStyle-HorizontalAlign="Left" HeaderText="Company" UniqueName="CustomerName" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerNo" HeaderStyle-HorizontalAlign="Left" HeaderText="Company No" UniqueName="CustomerNo" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="PhoneNumber1" HeaderStyle-HorizontalAlign="Left" HeaderText="Phone #" UniqueName="PhoneNumber1" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="FaxNumber" HeaderStyle-HorizontalAlign="Left" HeaderText="Fax #" UniqueName="FaxNumber" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>                                   
                                        <telerik:GridBoundColumn DataField="CustomerTypeName" HeaderStyle-HorizontalAlign="Left" HeaderText="Company Type" UniqueName="CustomerTypeName" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerRoleID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer ID" UniqueName="CustomerRoleID" Visible="False">
                                        </telerik:GridBoundColumn>
                                         <telerik:GridBoundColumn DataField="CustomerContactID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer Contact ID"
                                                               UniqueName="CustomerContactID" Visible="false"> <%--Visible="False" ReadOnly="True"--%>
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerContactName" HeaderText="Contact" HeaderStyle-HorizontalAlign="Left"
                                                              UniqueName="CustomerContactName" ReadOnly="True">
                                                              <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                         <telerik:GridHyperLinkColumn DataTextField="CustomerContactEmailID" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Email</t>" AllowFiltering="true" DataType="System.String"
                                                                  UniqueName="CustomerContactEmailID"  DataNavigateUrlFields="CustomerContactEmailID" DataNavigateUrlFormatString="mailto:{0}">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridHyperLinkColumn>
                                         <telerik:GridCheckBoxColumn DataField="AttentionTo" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Attention To?</t>" Visible="false" UniqueName="AttentionTo">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridDropDownColumn DataField="CustomerContactRoleID" ListTextField="Value"  HeaderStyle-HorizontalAlign="Left"
                                                                 ListValueField="Key" UniqueName="CustomerContactRoleID" HeaderText="Role">
                                                                
                                        </telerik:GridDropDownColumn>
                                        <telerik:GridBoundColumn DataField="DesignationName" HeaderStyle-HorizontalAlign="Left" HeaderText="Designation" UniqueName="Designation" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>   
                                        <telerik:GridCheckBoxColumn DataField="IsMain" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Main?</t>" UniqueName="IsMain" Visible="false">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridCheckBoxColumn DataField="IsActive" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Active?</t>" UniqueName="IsActive" ReadOnly="true">
                                        </telerik:GridCheckBoxColumn>

                                    <telerik:GridEditCommandColumn HeaderStyle-HorizontalAlign="Left" ButtonType="ImageButton" HeaderText="Edit">
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete" ButtonType="ImageButton" HeaderStyle-HorizontalAlign="Left"
                                                           Text="Delete" UniqueName="DeleteCommandColumn" ConfirmText="Do you want to delete this record?">
                                    </telerik:GridButtonColumn>
                                     <telerik:GridCheckBoxColumn DataField="IsBillTo" HeaderText="IsBillTo"
                                    UniqueName="IsBillTo" Visible="false" AutoPostBackOnFilter="true" DataType="System.Boolean">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle Width="5%" />
                                    </telerik:GridCheckBoxColumn>
                                    <telerik:GridTemplateColumn HeaderText="Report" UniqueName="CustomerReportForBillTo"  
                                              AllowFiltering="False" Visible="false" >
                                      <ItemTemplate>
                                        <asp:LinkButton ID="Button_CustomerReport" runat="server" ToolTip="Report"
                                              CommandName="Report" Text="Report" />
                                      </ItemTemplate>
                                      <EditItemTemplate>
                                            <asp:ImageButton ID="Button_CustomerReport" runat="server" Text="Report" ToolTip="Report"
                                            CommandName="Report" ImageUrl="~/Images/Print.gif"   />
                                      </EditItemTemplate>
                                    <HeaderStyle Width="5%"/>
                                   </telerik:GridTemplateColumn>
                                   <telerik:GridClientSelectColumn HeaderText="<t>Select</t>" UniqueName="CheckBoxSelect" >
                                            <ItemStyle HorizontalAlign="Center" />
                                            </telerik:GridClientSelectColumn>
                                 </Columns>
                                    <EditFormSettings>
                                          <EditColumn ButtonType="ImageButton">    </EditColumn>
                                    </EditFormSettings>
                            </MasterTableView>
                                <ClientSettings Selecting-AllowRowSelect="true">
                                </ClientSettings>
                          </telerik:RadGrid>
                         </div>
                     </td>
                 </tr>
                 
                           <tr>
                                <td align="right">
                                    <telerik:RadButton ID="Button_Copy_ShipTo" runat="server" Text="Copy As Ship To" CssClass="ClsButton100px"  Visible="True" TabIndex="26"
                                        OnClick="Button_Copy_ShipTo_Click" ToolTip="Copy selected record"/>
                               </td>
                            </tr>
                  </table>
                    <table style="width:100%;" runat="server" id="tblShipToParty">
                        <tr>
                           <td style="height:7px;"> </td>
                        </tr>
                              
                        <tr>
                            <td align="left" > &nbsp;
                               <asp:Label CssClass="ClsSubLabelHead" ID="lbl_ShipToParty" runat="server"  Text="<t>Ship To Party</t>" > </asp:Label>
                            </td>
                        </tr>
                
                 <tr>
                     <td align="left"> &nbsp;
                         <asp:LinkButton ID="LinkButton_ShipTo_AddNew"  Font-Size="Small" OnClientClick="javascript: ShowSearchPopupForOpportunityCustomers('IsShipTo=true')" runat="server"  Text="Add New" ></asp:LinkButton>
                     </td>
                 </tr>
                  <tr><td>
                           <div class="ClsFormattedGridDIVForPopup">
                           <telerik:RadGrid ID="RadGrid_OpportunityCustomerContacts_ShipToParty" runat="server"
                                         
                                          AllowPaging="True" AllowFilteringByColumn="false"
                                          PageSize="5"                               
                                          OnNeedDataSource="RadGrid_OpportunityCustomerContacts_ShipToParty_NeedDataSource"
                                          OnUpdateCommand="RadGrid_OpportunityCustomerContacts_ShipToParty_UpdateCommand"
                                          OnDeleteCommand="RadGrid_OpportunityCustomerContacts_ShipToParty_DeleteCommand"                                  
                                      
                                          OnCreateColumnEditor="RadGrid_OpportunityCustomerContacts_ShipToParty_CreateColumnEditor"
                                          OnItemCommand="RadGrid_OpportunityCustomerContacts_ShipToParty_ItemCommand" PagerStyle-AlwaysVisible="false">
                                  <MasterTableView  DataKeyNames="OpportunityID,CustomerID" EditMode="InPlace">
                                    <ExpandCollapseColumn Visible="False">
                                        <HeaderStyle  HorizontalAlign="Left" Width="19px" />
                                    </ExpandCollapseColumn>
                                    <RowIndicatorColumn Visible="False">
                                        <HeaderStyle Width="20px" HorizontalAlign="Left" />
                                    </RowIndicatorColumn>
                                    <Columns>
                                        <telerik:GridBoundColumn AllowFiltering="False" DataField="OpportunityID" HeaderText="Opportunity ID"
                                                              UniqueName="OpportunityID" Visible="False" ReadOnly="True">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer ID" UniqueName="CustomerID" ReadOnly="True" Visible="False">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerName" HeaderStyle-HorizontalAlign="Left" HeaderText="Company" UniqueName="CustomerName" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        
                                           <telerik:GridBoundColumn DataField="CustomerNo" HeaderStyle-HorizontalAlign="Left" HeaderText="Company No" UniqueName="CustomerNo" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="PhoneNumber1" HeaderStyle-HorizontalAlign="Left" HeaderText="Phone #" UniqueName="PhoneNumber1" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="FaxNumber" HeaderStyle-HorizontalAlign="Left" HeaderText="Fax #" UniqueName="FaxNumber" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridHyperLinkColumn DataTextField="EmailAddress" HeaderStyle-HorizontalAlign="Left" HeaderText="Email" AllowFiltering="true" DataType="System.String"
                                                                  UniqueName="EmailAddress"  DataNavigateUrlFields="EmailAddress" DataNavigateUrlFormatString="mailto:{0}">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridHyperLinkColumn>
                                        <telerik:GridBoundColumn DataField="CustomerTypeName" HeaderStyle-HorizontalAlign="Left" HeaderText="Company Type" UniqueName="CustomerTypeName" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerRoleID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer ID" UniqueName="CustomerRoleID" Visible="False">
                                        </telerik:GridBoundColumn>
                                         <telerik:GridBoundColumn DataField="CustomerContactID" HeaderStyle-HorizontalAlign="Left" HeaderText="Customer Contact ID"
                                                               UniqueName="CustomerContactID" Visible="false"> <%--Visible="False" ReadOnly="True"--%>
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn DataField="CustomerContactName" HeaderText="Contact" HeaderStyle-HorizontalAlign="Left"
                                                              UniqueName="CustomerContactName" ReadOnly="True">
                                                              <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>
                                         <telerik:GridCheckBoxColumn DataField="AttentionTo" HeaderStyle-HorizontalAlign="Left" Visible="false" HeaderText="<t>Attention To?</t>" UniqueName="AttentionTo">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridDropDownColumn DataField="CustomerContactRoleID" ListTextField="Value"  HeaderStyle-HorizontalAlign="Left"
                                                                 ListValueField="Key" UniqueName="CustomerContactRoleID" HeaderText="Role">
                                                                
                                        </telerik:GridDropDownColumn>
                                        <telerik:GridBoundColumn DataField="DesignationName" HeaderStyle-HorizontalAlign="Left" HeaderText="Designation" UniqueName="Designation" ReadOnly="True">
                                        <ItemStyle HorizontalAlign="Left" />
                                        </telerik:GridBoundColumn>   
                                        <telerik:GridCheckBoxColumn DataField="IsMain" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Main?</t>" UniqueName="IsMain" Visible="false">
                                        </telerik:GridCheckBoxColumn>
                                        <telerik:GridCheckBoxColumn DataField="IsActive" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Active?</t>" UniqueName="IsActive"  ReadOnly="true">
                                        </telerik:GridCheckBoxColumn>

                                    <telerik:GridEditCommandColumn HeaderStyle-HorizontalAlign="Left" ButtonType="ImageButton" HeaderText="Edit">
                                    </telerik:GridEditCommandColumn>
                                    <telerik:GridButtonColumn CommandName="Delete" HeaderText="Delete" ButtonType="ImageButton" HeaderStyle-HorizontalAlign="Left"
                                                           Text="Delete" UniqueName="DeleteCommandColumn" ConfirmText="Do you want to delete this record?">
                                    </telerik:GridButtonColumn>
                                     <telerik:GridCheckBoxColumn DataField="IsShipTo" HeaderText="IsShipTo"
                                    UniqueName="IsBillTo" Visible="false" AutoPostBackOnFilter="true" DataType="System.Boolean">
                                    <ItemStyle HorizontalAlign="Center" />
                                    <HeaderStyle Width="5%" />
                                    </telerik:GridCheckBoxColumn>
                                 </Columns>
                                    <EditFormSettings>
                                          <EditColumn ButtonType="ImageButton">    </EditColumn>
                                    </EditFormSettings>
                            </MasterTableView>
                          </telerik:RadGrid>
                         </div>
                     </td>
                 </tr>
                 
                           <tr>
                                <td align="right">
                                    <telerik:RadButton ID="Button_ViewDiscountSummary" runat="server"  
                                         Text="Discount" CausesValidation="False"
                                         OnClientClicked="ViewOpportunityDiscountSummary"
                                         TabIndex="36" ToolTip="<t>Discount Summary</t>" Visible="false"/> &nbsp;
                                                                                                 
                                    <telerik:RadButton ID="Button_Doc" runat="server" Text="Documents" CssClass="ClsButton100px"  Visible="false" TabIndex="26"
                                         OnClick="Button_Document_Click" ToolTip="Generate Document"/>                                       
                                    <telerik:RadButton ID="Button_InvoiceDoc" runat="server" Text="Ad Hoc Documents" CssClass="ClsButton100px" width="150px" Visible="false" TabIndex="26"
                                         OnClick="Button_InvoiceDoc_Click" ToolTip="Generate Invoices"/>
                               </td>
                            </tr>
                  </table>              
                  <table style="width:100%;" runat="server" id="tblPricing">
                    <tr>
                        <td align="right">
                        <telerik:RadButton ID="Button_Price" runat="server" Text="Pricing" CssClass="ClsButton100px"  Visible="True" TabIndex="26"
                                         OnClientClicked="ViewOpportunityPriceSummary" ToolTip="Pricing"/>
                        </td>
                    </tr>                                     
                  </table>
                       <table style="width:100%;" >
                   <tr> <td style="height:7px;"> </td></tr>
                <tr>
                    <td align="left">&nbsp;            
                        <asp:Label CssClass="ClsSubLabelHead" ID="Label_Employee" runat="server"  Text="<t>Employees</t>" ></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td align="left">&nbsp;
                         <asp:LinkButton ID="LinkButton_Employee" OnClientClick="javascript: ShowSearchPopupForOpportunityEmployee()" runat="server" Font-Size="Small" Text="<t>Add New</t>" ></asp:LinkButton>
                    </td>
                </tr>
                <tr>
                    <td >
                    <div class="ClsFormattedGridDIVForPopup">
                    <telerik:RadGrid ID="RadGrid_Employee"
                                  runat="server"
                                  OnNeedDataSource="RadGrid_Employee_NeedDataSource"
                                  OnUpdateCommand="RadGrid_Employee_UpdateCommand"
                                  OnDeleteCommand="RadGrid_Employee_DeleteCommand"
                                  OnItemCommand="RadGrid_Employee_ItemCommand"
                                  OnCreateColumnEditor="RadGrid_Employee_CreateColumnEditor"
                                  OnItemDataBound="RadGrid_Employee_ItemDataBound"
                                  PageSize="5"
                                  PagerStyle-AlwaysVisible="false"
                                  AllowFilteringByColumn="false">
                                 
                        <MasterTableView  DataKeyNames="OpportunityID,EmployeeID"  EditMode="InPlace">
                            <ExpandCollapseColumn Visible="False">
                                <HeaderStyle Width="19px"  />
                            </ExpandCollapseColumn>
                            <RowIndicatorColumn Visible="False">
                                <HeaderStyle Width="20px"  />
                            </RowIndicatorColumn>
                            <Columns>
                                <telerik:GridBoundColumn AllowFiltering="False" DataField="OpportunityID" HeaderText="Opportunity ID"
                                    UniqueName="OpportunityID" Visible="False" ReadOnly="True">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID" Display="false">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="EmployeeName" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderText="<t>Name</t>" UniqueName="EmployeeName" ReadOnly="True">
                                </telerik:GridBoundColumn>
                                <telerik:GridDropDownColumn DataField="DesignationID" ListTextField="Value"  HeaderStyle-HorizontalAlign="Left"
                                                            ListValueField="Key" UniqueName="DesignationID" HeaderText="Designation">
                                <ItemStyle Width="15%" />                                                            
                                </telerik:GridDropDownColumn>
                                <telerik:GridCheckBoxColumn DataField="IsOwner" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Is Owner?</t>" UniqueName="IsOwner">
                                <ItemStyle width="5%"/>
                                </telerik:GridCheckBoxColumn>
                                <telerik:GridEditCommandColumn ButtonType="ImageButton" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" HeaderText="<t>Edit</t>">
                               <ItemStyle width="5%"/>
                                </telerik:GridEditCommandColumn>
                                <telerik:GridButtonColumn CommandName="Delete" HeaderStyle-HorizontalAlign="Left" HeaderText="<t>Delete</t>" ItemStyle-HorizontalAlign="Left" ButtonType="ImageButton"
                                        Text="Delete" UniqueName="DeleteCommandColumn"  ConfirmText="<t>Do you want to delete this record?</t>">
                                         <ItemStyle width="5%"/>
                                </telerik:GridButtonColumn>
                                
                            </Columns>
                          <EditFormSettings>
                                <EditColumn ButtonType="ImageButton">
                                 </EditColumn>
                            </EditFormSettings>
                        </MasterTableView>
                    </telerik:RadGrid>
                    </div>
                    </td>
                </tr>
               </table>              
                </telerik:RadPageView>



                <telerik:RadPageView ID="MPManageGrpDataView" runat="server" TabIndex="3" CssClass="ClsDivBorder" Height="580px">  
                  <%--<asp:MultiView ID="MultiView_OpportunityGroups" runat="server" ActiveViewIndex="-1">    
                          
                   <asp:View ID="View_OpportunityGroups" runat="server">
               
                      <div id="Div2"  runat="server">                                    
                           <iframe id="iframe2"  width="100%"  onload= "SetGridHeightMain()" frameborder="0"   scrolling="no" class="GridHieghtMain"
                                    src= "ManageOpportunityGroups.aspx?OpportunityID=<%=HiddenField_OpportunityID.Value %>">
                           </iframe>                    
                     </div>
                   </asp:View>
                 </asp:MultiView>--%>
                </telerik:RadPageView>
                <telerik:RadPageView ID="MPTermsCondDataView" runat="server" TabIndex="4" CssClass="ClsDivBorder" Height="450px">
                <%-- <asp:MultiView ID="MultiView_OpportunityTAndC" runat="server" ActiveViewIndex="-1">                
                   <asp:View ID="View_OpportunityTAndC" runat="server">
                      <div id="Div3"  runat="server" style="height:auto;"  >                                    
                           <iframe id="iframe3" frameborder="0"
                                    src= "ManageOpportunityTermsAndConditions.aspx?OpportunityID=<%=HiddenField_OpportunityID.Value %>"
                                    width="100%"  scrolling="no" class="GridHieghtMain"  onload= "SetGridHeightMain()">
                           </iframe>                    
                     </div>
                   </asp:View>
                 </asp:MultiView>--%>
                </telerik:RadPageView>
                <telerik:RadPageView ID="MPContractInfDataView" runat="server" TabIndex="5" CssClass="ClsDivBorder" Height="450px">
                <%-- <asp:MultiView ID="MultiView_ContractInfo" runat="server" ActiveViewIndex="-1">                
                  <asp:View ID="View_ContractInfo" runat="server">  
                    <asp:Panel id="panel_Contract" runat="server" Height="100%" width="100%">
                     <div id="Div_Contract"  runat="server">
                            <iframe id="iframe_Contarct" frameborder="0"  
                                    src= "ManageOpportunityContractInfo.aspx?OpportunityID=<%=HiddenField_OpportunityID.Value %>"
                                    width="100%"  class="GridHieghtMain"  onload= "SetGridHeightMain()">
                            </iframe>
                        </div>
                  </asp:View>
                 </asp:MultiView>--%>
                     <%--</asp:Panel>--%>
                </telerik:RadPageView>
                <telerik:RadPageView ID="MPBillingPlanDataView" runat="server" TabIndex="6" CssClass="ClsDivBorder" Height="450px">
            <%--     <asp:MultiView ID="MultiView_BillingPlan" runat="server" ActiveViewIndex="-1">                
                    <asp:View ID="View1" runat="server">
                    <div id="Div_BillingPlan"  runat="server" style="height:auto;">
                            <iframe id="iframe_BillingPlan" frameborder="0"
                                    src= "ManageBillingPlan.aspx?OpportunityID=<%=HiddenField_OpportunityID.Value %>"
                                    width="100%"class="GridHieghtMain"  onload= "SetGridHeightMain()">
                            </iframe>
                        </div>
                    </asp:View>
                 </asp:MultiView> --%>                  
                </telerik:RadPageView>
                <telerik:RadPageView ID="MPProjectBudgetDataView" runat="server" TabIndex="7" CssClass="ClsDivBorder" Height="450px">
    <%--                 <asp:MultiView ID="MultiView_Budget" runat="server" ActiveViewIndex="-1">                
                          <asp:View ID="View2" runat="server">
                            <div id="Div1"  runat="server" style="height:auto;"  >
                                    
                                   <iframe id="iframe1" frameborder="0"
                                            src= "ManageProjectBudget.aspx?OpportunityID=<%=HiddenField_OpportunityID.Value %>"
                                            width="100%"  scrolling="no" class="GridHieghtMain"  onload= "SetGridHeightMain()">
                                   </iframe>
                                    
                                </div>
                          </asp:View>
                     </asp:MultiView>  --%>                
                </telerik:RadPageView>
                <telerik:RadPageView ID="MPDocumentManagementDataView" runat="server" TabIndex="7" CssClass="ClsDivBorder" Height="450px">
                    <%-- <asp:MultiView ID="MultiView_DocumentManagement" runat="server" ActiveViewIndex="-1">                
                          <asp:View ID="View3" runat="server">
                            <div id="Div4"  runat="server" style="height:auto;"  >
                                    
                                   <iframe id="iframe4" frameborder="0"
                                            src="ManageOpportunityDocuments.aspx"
                                            width="100%"  class="GridHieghtMain"  onload= "SetGridHeightMain()">
                                   </iframe>
                                    
                                </div>
                               
                          </asp:View>--%>
                     </asp:MultiView>                  
                </telerik:RadPageView>
         </telerik:RadMultiPage>   
        </td>
          <asp:HiddenField ID="HiddenField_OpportunityID" runat="server" />
                              <asp:HiddenField ID="HiddenField_OpportunityName" runat="server" />
                            <asp:HiddenField ID="HiddenField_CompetitorIDs" runat="server" />
                            <asp:HiddenField ID="HiddenField_OpportunityEntityID" runat="server" />
                            <asp:HiddenField ID ="HiddenField_QuestionanierID" runat ="server" Value =""/>
                            <asp:HiddenField ID="HiddenField_NexrStatusID" runat="server" />
                             <asp:HiddenField ID="HiddenField_EmployeeEditFlag" runat="server" />
                            <asp:HiddenField ID="HiddenField_EmployeeID" runat="server" />
                            <asp:HiddenField ID="HiddenField_InitialLogin_StatusID" runat="server" />
                             <asp:HiddenField ID="HiddenField_TermsAndConditionID" runat="server" />
                            <asp:HiddenField ID="HiddenField_LocationID" runat="server" />
                            <asp:HiddenField ID="HiddenField_SiteAddress" runat="server" />
                            <asp:HiddenField ID="HiddenField_BillingAddress" runat="server" />
                            <asp:HiddenField ID="HiddenField_TemporaryStorage" runat="server" />
                            <asp:HiddenField ID="HiddenField_SalesTypeID" runat="server" />
                            <asp:HiddenField ID="HiddenField_IsOwner" runat="server" />
                             <asp:HiddenField ID="HiddenField_CustomerID" runat="server" />
                             <asp:HiddenField ID="HiddenField_CurrentStatusAction" runat="server" />
                             <asp:HiddenField ID="HiddenField_OrganizationID" runat="server" />
        </tr>
        </table>  
         <div id="RestrictionZone" class="module" style="margin-top: 4px; height: 300px; width: 400px;
            display: none;">
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" Style="z-index: 7001">
                <Windows>                
                    <telerik:RadWindow ID="RadWindow1" runat="server" ReloadOnShow="true" ShowContentDuringLoad="true"
                        Modal="true" Height="620px" Width="620px" NavigateUrl="~/Shared/CustomerSearchPopupForOpportunity.aspx" />
                    <telerik:RadWindow runat="server" ID="RadWindow_StatusHistory" ReloadOnShow="true" ShowContentDuringLoad="true"
                        Modal="true" Height="500px" Width="700px" NavigateUrl="StatusChangeHistoryPopup.aspx" Animation="Fade">
                    </telerik:RadWindow>
                </Windows>
            </telerik:RadWindowManager>
        </div>
      <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
       <script language="javascript" type="text/javascript">

           var cancelDropDownClosing = false;

           function onDropDownClosing() {
               cancelDropDownClosing = false;
               onCheckBoxClick(null);
           }

           function onCheckBoxClick(chk) {
               var combo = $find("<%= RadCombobox_MainCompetitor.ClientID %>");
               //prevent second combo from closing
               cancelDropDownClosing = true;
               //holds the text of all checked items
               var text = "";
               //holds the values of all checked items
               var values = "";
               //get the collection of all items
               var items = combo.get_items();
               //enumerate all items
               for (var i = 0; i < items.get_count(); i++) {
                   var item = items.getItem(i);
                   //get the checkbox element of the current item
                   var chk1 = $get(combo.get_id() + "_i" + i + "_chk1");
                   if (chk1.checked) {
                       text += item.get_text() + ",";
                       values += item.get_value() + ",";
                   }
               }
               //remove the last comma from the string
               text = removeLastComma(text);
               values = removeLastComma(values);

               if (text.length > 0) {
                   //set the text of the combobox
                   combo.set_text(text);
                   //update the treeview in the second combobox
               }
               else {
                   //all checkboxes are unchecked
                   //so reset the controls
                   combo.set_text("");
               }
           }

           function removeLastComma(str) {
               return str.replace(/,$/, "");
           }

           function btn_CompetitorDetails_Click(sender, args) {
               var OpportunityID = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_OpportunityID").value;
               OpenRadWindowOnTOP("ManageOpportunityCompetitors.aspx?OpportunityID=" + OpportunityID);
           }

           function ViewStatusHistory() {

               var EntityID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityEntityID').value;
               var EntityKeyID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityID').value;
               var EntityName = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityName').value;
               OpenRadWindowOnTOP(GetUrl("Shared") + '/StatusChangeHistoryPopup.aspx?EntityID=' + EntityID + '&EntityKeyID=' + EntityKeyID + '&EntityName=' + EntityName);
            }

           function Button_OpportunityStatus_Click() {          
               var OpportunityID = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_OpportunityID").value;
               var QuestionanierID = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_QuestionanierID").value;
               var EntityID = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_OpportunityEntityID").value;
               var StatusID = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_NexrStatusID").value;
               OpenRadWindowOnTOP(GetUrl("Shared") + '/ManageStatusChange.aspx?EntityKeyID=' + OpportunityID + '&StatusTypeID=' + 2 + '&EntityID=' + EntityID + '&SessionString=OpportunityBeingEdited&EntityType=Opportunity');
              }

              function ViewOpportunityCustomFields() {
                  var EntityID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityEntityID').value;
                  var OpportunityID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityID').value;
                  OpenRadWindowOnTOP("ManageCustomFields.aspx?EntityID=" + EntityID + "&EntityKeyID=" + OpportunityID);
              }
              function UploadDocuments() {
                  OpenRadWindowOnTOP("AttachedOpportunityDocuments.aspx?");
              }
              function ShowSearchPopupForOpportunityCustomers(CustomerType) {
                  var OpportunityID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityID').value;
                  OpenRadWindowOnTOP(GetUrl("Shared") + "/CustomerSearchPopupForOpportunity.aspx?OpportunityID=" + OpportunityID + "&" + CustomerType + "");
              }

              function ShowSearchPopupForOpportunityEmployee() {
                  var OpportunityID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityID').value;
                  OpenRadWindowOnTOP("ManageOpportunityEmployeeSearchPopup.aspx?OpportunityID=" + OpportunityID);
              }
              
               function ViewOpportunityPriceSummary() {
               var CurrentStatusAction = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_CurrentStatusAction').value;
                OpenRadWindowOnTOP("ViewOpportunityPriceSummary.aspx?CurrentStatusAction=" + CurrentStatusAction);
              }

              function ViewOpportunityDiscountSummary() {
                  var CurrentStatusAction = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_CurrentStatusAction').value;
                  OpenRadWindowOnTOP("ManageProductDiscount.aspx?CurrentStatusAction=" + CurrentStatusAction);
              }

              function ShowAuditTrailReportPopup(sender, args) {
                  var TableName = "Opportunities";
                  var EntityKey = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_OpportunityID").value;
                  OpenRadWindowOnTOP(GetUrl("Shared") + '/ManageAuditTrailReport.aspx?&TableName=' + TableName + '&EntityKey=' + EntityKey + '&Flag=' + true)
              }
              function ShowRemarkPopup(sender, args) {
                  var EntityKey = document.getElementById("ctl00_MainContentPlaceHolder_HiddenField_OpportunityID").value;
                  OpenRadWindowOnTOP(GetUrl("Shared") + '/ManageRemarks.aspx?&EntityID=10&EntityKey=' + EntityKey)
              }

              function PendingActions(sender, args) {
                  var OpportunityID = document.getElementById('ctl00_MainContentPlaceHolder_HiddenField_OpportunityID').value;
                  OpenRadWindowOnTOP(GetUrl("Shared") + '/ManagePendingActions.aspx?EntityID=10&EntityType=Opportunity&EntityKey=' + OpportunityID, "RadWindow_PendingActions");
              }
              function refreshGrid(arg) {
               if (arg == "RebindSoldToGrid") {
                   var grid = $find("<%= RadGrid_OpportunityCustomerContacts_SoldToParty.ClientID %>").get_masterTableView();
                   grid.rebind();
               }
               if (arg == "RebindBillToGrid") {
                   var grid = $find("<%= RadGrid_OpportunityCustomerContacts_BillToParty.ClientID %>").get_masterTableView();
                   grid.rebind();
               }
               if (arg == "RebindShipToGrid") {
                   var grid = $find("<%= RadGrid_OpportunityCustomerContacts_ShipToParty.ClientID %>").get_masterTableView();
                   grid.rebind();
               }
               if (arg == "RefreshPage" || arg == "Rebind") {
     
                 $find("<%= rjxPanel.ClientID %>").ajaxRequest("Rebind");
               }
               if (arg == "RebindEmp") {
                   var grid = $find("<%= RadGrid_Employee.ClientID %>").get_masterTableView();
                   grid.rebind();
                 }
               
           }
        
    </script>
    </telerik:RadCodeBlock>
    </fieldset>
     </telerik:RadAjaxPanel>
    </asp:Content>
    ----------------------------------------------------------------------------------
    ManageOpportunity.aspx.cs
    ---------------------------------------------------------------------------------
    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Diagnostics;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using Csla;
    using Csla.Data;
    using Telerik.Web.UI;
    using XECOMIT.Enterprise.ApplicationFramework.Security;
    using XECOMIT.ERPByNet.AceWorkflow.BusinessEntities;
    using XECOMIT.ERPByNet.AceWorkflow.DataAccessEntities;
    using XECOMIT.ERPByNet.BusinessEntities;
    using XECOMIT.ERPByNet.DataAccessEntities;
    using XECOMIT.ERPByNet.DynamicObjectBuilders.ProductInformation.Common;
    using XECOMIT.ERPByNet.DynamicObjectBuilders.ProductInformationBuilder;
    using XECOMIT.ERPByNet.ExceptionHandler;
    using XECOMIT.ERPByNet.SecurityServices;
    using XECOMIT.ERPByNet.CommonUtilities;

    using System.Drawing;
    //using XECOMIT.EnterpriseLibrary.ApplicationActivation;
    //using System.ComponentModel;
    using System.IO;
    using ERPByNet.HelperClasses;
    //using System.Resources;

    public partial class ManageOpportunityMOD : System.Web.UI.Page
    {
        #region Datamembers

        private int mOpportunityID;
        private int mEntityID;
        private int mEmployeeID;
        private int mCustomerID;
        private int mTermsAndConditionID;
        private string Filter;

        // private int mTermsAndConditionDetailTypeID;
        private bool IsNewOpportunity;
        private int mIsEditMode = 0;
        private int mOpportunityStatusID;
        //private int mLanguageID = UIHelper.GetCurrentUsersLanguageID();
        private int mLanguageID;
        int mModuleId;// = ModuleHelper.GetCurrentModuleId();
        // private int mMakingOpportunityNumberEditable = ModuleHelper.GetConfigurationParameterIDForMakingOpportunityNumberEditable();
        private DataTable oDataTableOpportunityCustomers = new DataTable();
        private DataTable oDataTableOpportunityCustomerContacts = new DataTable();
        private DataSet oDatasetOppRef;
        private static int STATUSTYPEID;


        string[] CompetitorIDs = null;
        private DataTable oCompetitorsTable = new DataTable();
        private DataTable oOpportunityNotesTable = new DataTable();
        private int mRootOrganizationID; //= UIHelper.GetCurrentUsersRootOrganizationId();
        private int mOrganizationID; //= UIHelper.GetCurrentUsersOrganizationId();
        // private int mOpportunityGroupHeaderID;
        // private bool mBindTreeView = false;

        // private bool mLockProduct = false;

        ArrayList ArrForSoldToParty = new ArrayList();
        ArrayList ArrForBillToParty = new ArrayList();

        StringBuilder sErrorMessage = new StringBuilder();

        private DataTable oActivityGroupDataTable = new DataTable();
        private DataTable oActivityDataTable = new DataTable();

        #endregion

        #region Constants

        private const string CURRENT_SEARCH_MODE_OPPORTUNITYCUSTOMERS = "OPPORTUNITYCUSTOMERS";
        private const string CURRENT_SEARCH_MODE_OPPORTUNITYCUSTOMERCONTACTS = "OPPORTUNITYCUSTOMERCONTACTS";
        private const string CURRENT_SEARCH_MODE_OPPORTUNITYEMPLOYEES = "OPPORTUNITYEMPLOYEE";
        private const string BLANK = "";
        private const string CUSTOMER_SHOULD_NOT_DELETE = "Selected customer for deletion is Main customer,Hence can not be deleted.";
        private const string MAIN_CUSTOMER_SHOULD_BE_ACTIVE = "Main Customer should be Active.";
        private const string ENTER_OPPORTUNITY_SATUS = "Please enter opportunity status.";
        private const string ENTER_Expected_Completion_Date = "Please Enter Expected Closing Date";
        private const string ENTER_CITY = "Please Enter City";
        private const string CITY_NAME_ALREADY_EXIST = "City already exists for this State";
        private const string CAN_NOT_DELETE_OPPORTUNITY_OWNER = "Opportunity Owner can not be deleted.";
        private const string APPLICATION_TASK_NAME_FOR_CUSTOMER_REPORT = "360ViewCustomerReport";
        private const string ENTER_OPPORTUNITY_NO = "Please Enter Opportunity No....";
        private const string OPPORTUNITY_NO_EXIST = "Opportunity no already exist....";
        private const string EXPECTED_CLOSING_DATE_NOT_VALID = "Expected closing Date should be greater than Created/Added Date..";

        const int SITE_LOCATION_TYPE = 3;
        const int BILLING_LOCATION_TYPE = 2;
        const int TEMPORARY_STORAGE_LOCATION_TYPE = 5;
        private const int NEW_SALESGROUP_TYPE = 1;
        private const int WIN_STATUS_ANALYSIS_TYPE_ID = 2;
        private const int POC_STATUS_ANALYSIS_TYPE_ID = 4;
        private const int OPPORTUNITY_STATUSENTITY_ID = 10;
        private const string OPPORTUNITY_STATUSENTITY_DATAKEY = "OpportunityID";
        private const string TABLENAME = "Opportunities";
        private const char FILTER_VALUE_SEPARATOR = '\u0182';
        private const char SAPARATOR = ',';

        int InvalidProductCount = 0;
        private StringBuilder mInvalidProductList = new StringBuilder("Please validate products specifications, as they have latest publish.\r\n");


        private const string ENTER_NOTES = "Please Enter Notes for Completed Activity.";

        private const int CONFIGURATION_PARAMETER_ID_FOR_MAKE_OPPORTUNITY_NO_EDITABLE = 16;
        private const int CONFIGURATION_PARAMETER_ID_FOR_DOC_GEN = 45;
        private const int CONFIGURATION_PARAMETER_ID_FOR_ALLOW_BILLING_PLAN = 49;
        private const int CONFIGURATION_PARAMETER_ID_FOR_ALLOW_PROJECT_BUDGET = 52;
        private const int CONFIGURATION_PARAMETER_ID_FOR_ADD_DEFAULT_TANDC = 57;
        //private const int CONFIGURATION_PARAMETER_ID_FOR_CONTRACTDATE_SETTING = 62;
        //private const int CONFIGURATION_PARAMETER_ID_FOR_SHOWCOSTCENTRE = 63;
        //private const int CONFIGURATION_PARAMETER_ID_FOR_SHOWFOREXRATES = 64;
        //private const int CONFIGURATION_PARAMETER_ID_FOR_SHOWSALESFROMLOCAL = 65;
        private const string APPLICATION_TASK_NAME_FOR_MULTIPLE_DISCOUNT_VIEW = "OpportunityMultipleDiscountView";
        private const int CONFIGURATION_PARAMETER_ID_FOR_WORKBENCH_REPORT_BUTTON = 48;
        private const int CONFIGURATION_PARAMETER_ID_FOR_DISPLAY_CUSTOMER_LOCATION_AS_OPPORTUNITY_ADDRESS = 27;

        #endregion

        #region Page Load

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {

                mLanguageID = UIHelper.GetCurrentUsersLanguageID();
                mModuleId = ModuleHelper.GetCurrentModuleId();
                mRootOrganizationID = UIHelper.GetCurrentUsersRootOrganizationId();

                if (HiddenField_OpportunityID.Value != null && HiddenField_OpportunityID.Value != string.Empty)
                {
                    mOpportunityID = Convert.ToInt32(HiddenField_OpportunityID.Value);
                }

                if (HiddenField_CustomerID.Value != null && HiddenField_CustomerID.Value != string.Empty)
                    mCustomerID = Convert.ToInt32(HiddenField_CustomerID.Value);

                if (HiddenField_TermsAndConditionID.Value != null && HiddenField_TermsAndConditionID.Value != string.Empty)
                    mTermsAndConditionID = Convert.ToInt32(HiddenField_TermsAndConditionID.Value);

                if (HiddenField_OrganizationID.Value != null && HiddenField_OrganizationID.Value != string.Empty)
                    mOrganizationID = Convert.ToInt32(HiddenField_OrganizationID.Value);

                #region Initialize Data Members

                InitialiseDataMembers();

                #endregion

                #region Permission for Multiple Discount

                EnableMultipleDiscountView();

                #endregion

                if (!Page.IsPostBack)
                {
                    ClearRequiredSessions();
                    FillSalesTypesCombo();
                    FillOpportunityCategoryCombo();
                    FillOpportunityTypeCombo();
                    FillOpportunitySourceCombo();
                    FillFutureProspectCombo();


                    if (Request.QueryString["OpportunityID"] != "" && Request.QueryString["OpportunityID"] != null)
                    {
                        mOpportunityID = int.Parse(Request.QueryString["OpportunityID"]);
                        HiddenField_OpportunityID.Value = mOpportunityID.ToString();
                        IsNewOpportunity = false;
                        btn_CompetitorDetails.Enabled = true;
                        Button_Save_OppLocations.Enabled = true;
                        rcbSalesType.Enabled = false;

                        FillOpportunityDetailsInControls();
                    }
                    else
                    {
                        IsNewOpportunity = true;
                        btn_CompetitorDetails.Enabled = false;
                        mOrganizationID = int.Parse(Request.QueryString["OrganizationID"]);
                        HiddenField_OrganizationID.Value = mOrganizationID.ToString();
                        FillCurrencyCombo();
                        FillExchangeRateCombo();
                        CreateNewOpportunityObject();
                        GetOpportuntiyRefDetail();
                    }

                    InitializeLocationRadComboBox();


                    if (mOpportunityID > 0)
                    {
                        SetValueOfControlsForSelectedLocation();
                        if (!IsOpportunityEmployee(mEmployeeID))
                        {
                            LockOpportunity();
                            LockCustomerContacts();
                            LockControlsForNonEmployee();
                        }
                    }
                    HiddenField_CustomerID.Value = Request.QueryString["CustomerID"];

                    Session["OpportunityContactsBeingEdited"] = null;
                    Session["CustomerContactRoleNameValue"] = null;
                    Session["CustomerInfoList"] = null;

                    #region Update Products Assembly reference

                    if (!IsNewOpportunity)
                    {
                        UpdateAssemblyReferenceforProducts();
                        SetCompetitorCombo(mOpportunityID);
                    }

                    #endregion

                    ShowOpportunityRefNo();

                    IsReferenceDataAvailable();

                    #region Check For Owner

                    if (!IsOwner() || !(Opportunity.CanDeleteObject()))
                    {

                        LinkButton_Employee.Visible = false;
                        // HiddenField_IsOwner.Value = "false";
                        RadGridHelper.MaskUpdateButtonColumn(RadGrid_Employee);
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_Employee);
                    }
                    if (IsOwner())
                    {
                        LinkButton_Employee.Visible = true;
                        HiddenField_IsOwner.Value = "true";
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_Employee);
                        RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_Employee);
                    }
                    #endregion

                    if (Request.QueryString["CustomerInformation"] != null && Request.QueryString["CustomerInformation"] != BLANK)
                    {
                        SetValuesOfOpportunityCustomersAndContactsFromQueryString();
                        DisplayCustomerLocationAsOpportunityAddress();
                    }

                    #region SET CONGURATION SETTING
                    SetConfigurationSetting();
                    #endregion

                }
                if (mOpportunityID > 0)
                {
                    ApplyOpportunityApplicableActions();
                }

                #region fill Customer and Customer Contact grid from search popup

                //To fill Customer and Customer Contact grid from search popup
                if (Session["CurrentSearchMode"] != null)
                {
                    if (Session["CurrentSearchMode"].ToString() == CURRENT_SEARCH_MODE_OPPORTUNITYCUSTOMERS)
                    {
                        RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                        RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                        RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();
                    }

                    if (Session["CurrentSearchMode"].ToString() == CURRENT_SEARCH_MODE_OPPORTUNITYEMPLOYEES)
                        RadGrid_Employee.Rebind();

                    Session["CurrentSearchMode"] = null;
                }

                #endregion

                SetPropertiesForActivities();

                #region get changed opportunity status

                if (Session["NextStatusID"] != null)
                {

                    HiddenField_InitialLogin_StatusID.Value = ((Opportunity)Session["OpportunityBeingEdited"]).StatusID.ToString();
                    mOpportunityStatusID = Convert.ToInt32(HiddenField_InitialLogin_StatusID.Value);
                    int LanguageID = UIHelper.GetCurrentUsersLanguageID();
                    StatusInfoList AllStatusInfoList = StatusInfoList.GetStatusInfoList(mOpportunityStatusID, LanguageID);
                    StatusInfo oStatusInfo = AllStatusInfoList.GetItem(mOpportunityStatusID);
                    lblOpportunity_Status_value.Text = oStatusInfo.StatusName;
                    TextBox_OpportunityStatusName.Text = oStatusInfo.StatusName;

                    //    //ApplyOpportunityApplicableActions();
                    //    //ApplyActionOnCurrentStatus();
                }
                Session["NextStatusID"] = null;

                EnableStatusChangeButton();

                #endregion

                # region check Opportunity Status

                if (mOpportunityID > 0)
                {
                    Opportunities AllOpportunities = Opportunities.GetOpportunities(mOpportunityID, mLanguageID);
                    Opportunity oOpportunity = AllOpportunities.GetItem(mOpportunityID);
                    lblContract_No_value.Text = oOpportunity.ContractNo;
                    
                    ArrayList StatusArrayList = UIHelper.GetMultipleStatusIDByAnalysisTypeID(WIN_STATUS_ANALYSIS_TYPE_ID);

                    bool bCheckStatus = false;

                    foreach (string StatusID in StatusArrayList)
                    {
                        if (oOpportunity.StatusID.ToString() == StatusID)

                            bCheckStatus = true;
                    }
                    if (bCheckStatus)
                    {
                        if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_WORKBENCH_REPORT_BUTTON).ToLower() == "yes")
                        {
                            Button_ExportOpportunityData.Visible = bCheckStatus;
                            //Button_GenerateOpportunityData.Visible = bCheckStatus;
                        }
                    }

                    //For Enable Project Budget Tab
                    if (ProjectBudget.CanGetObject())
                    {
                        ArrayList POCStatusArrayList = UIHelper.GetMultipleStatusIDByAnalysisTypeID(POC_STATUS_ANALYSIS_TYPE_ID);
                        foreach (string StatusID in POCStatusArrayList)
                        {
                            if (oOpportunity.StatusID.ToString() == StatusID)
                                Tab_ProjectBudget.Enabled = true;
                        }
                    }
                }

                #endregion

                EnableDisableTabs();
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        #endregion

        #region RadTab Event

        protected void RadTabStrip_ManageProjects_click(object sender, RadTabStripEventArgs e)
        {
            if (RadTabStrip_ManageProjects.SelectedIndex == 0)
            {
                MultiView_BasicInfo.ActiveViewIndex = 0;
                if (Session["OpportunityBeingEdited"] != null)
                {
                    Session["OpportunityBeingEdited"] = null;
                    Session["currentOpportunityObject"] = null;
                    GetOpportunityBeingEdited();
                    Opportunity oOpportunity = GetOpportunityBeingEdited();
                    Label_EsimatedPrice_Value.Text = oOpportunity.EstimatedPrice.ToString("N2");
                    Label_QuotedPrice_Value.Text = oOpportunity.QuotedPrice.ToString("N2");
                    Label_BillingAmount_Value.Text = oOpportunity.BillingAmount.ToString("N2");
                    Label_BilledAmount_Value.Text = oOpportunity.BilledAmount.ToString("N2");

                    DatePicker_ContractStartDate.SelectedDate = ((Opportunity)Session["OpportunityBeingEdited"]).ContractStartDate;
                    DatePicker_ContractEndDate.SelectedDate = ((Opportunity)Session["OpportunityBeingEdited"]).ContractEndDate;
                }
            }

            else if (RadTabStrip_ManageProjects.SelectedIndex == 2)
            {
                RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();
                RadGrid_Employee.Rebind();
            }
            else if (RadTabStrip_ManageProjects.SelectedIndex == 3)
            {
                MPManageGrpDataView.ContentUrl = "ManageOpportunityGroups.aspx?OpportunityID=" + HiddenField_OpportunityID.Value;
                // MultiView_OpportunityGroups.ActiveViewIndex = 0;          
            }
            else if (RadTabStrip_ManageProjects.SelectedIndex == 4)
            {
                MPTermsCondDataView.ContentUrl = "ManageOpportunityTermsAndConditions.aspx?OpportunityID=" + HiddenField_OpportunityID.Value;
                //  MultiView_OpportunityTAndC.ActiveViewIndex = 0;
            }
            else if (RadTabStrip_ManageProjects.SelectedIndex == 5)
            {
                MPContractInfDataView.ContentUrl = "ManageOpportunityContractInfo.aspx?OpportunityID=" + HiddenField_OpportunityID.Value;
                // MultiView_ContractInfo.ActiveViewIndex = 0;
            }
            else if (RadTabStrip_ManageProjects.SelectedIndex == 6)
            {
                MPBillingPlanDataView.ContentUrl = "ManageBillingPlan.aspx?OpportunityID=" + HiddenField_OpportunityID.Value;
                // MultiView_BillingPlan.ActiveViewIndex = 0;
            }
            else if (RadTabStrip_ManageProjects.SelectedIndex == 7)
            {
                MPProjectBudgetDataView.ContentUrl = "ManageProjectBudget.aspx?OpportunityID=" + HiddenField_OpportunityID.Value;
                // MultiView_Budget.ActiveViewIndex = 0;
            }
            else if (RadTabStrip_ManageProjects.SelectedIndex == 8)
            {
                MPDocumentManagementDataView.ContentUrl = "ManageOpportunityDocuments.aspx?OpportunityID=" + HiddenField_OpportunityID.Value;
                // MultiView_DocumentManagement.ActiveViewIndex = 0;
            }

        }

        #endregion

        #region Grid Events

        #region Opportunity Notes

        protected void RadGrid_OpportunityNotes_NeedDataSource(object Source, GridNeedDataSourceEventArgs e)
        {
            RadGrid_OpportunityNotes.DataSource = GetOpportunityNotes();
        }

        protected void RadGrid_OpportunityNotes_InsertCommand(object Source, GridCommandEventArgs e)
        {
            DoInsert(e);
        }
        protected void RadGrid_OpportunityNotes_UpdateCommand(object Source, GridCommandEventArgs e)
        {
            DoUpdate(e);
        }

        protected void RadGrid_OpportunityNotes_OnItemDataBound(object sender, GridItemEventArgs e)
        {
            GridBoundColumn AddedOn = (GridBoundColumn)RadGrid_OpportunityNotes.Columns.FindByUniqueName("AddedOn");
            GridEditCommandColumn Edit = (GridEditCommandColumn)RadGrid_OpportunityNotes.Columns.FindByUniqueName("Edit");
            GridDataItem DataItem = e.Item as GridDataItem;
            GridEditableItem GridEditableItem = e.Item as GridEditableItem;
            Hashtable oHashTable = new Hashtable();

            //TextBox text_notes = DataItem.FindControl("text_Notes") as TextBox;
            //text_notes.Text=
            //Edit.Display = true;
            if (e.Item is GridDataItem)
            {
                if (e.Item.IsInEditMode)
                {
                    RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_OpportunityNotes);
                    //GridEditableItem item = e.Item as GridEditableItem;
                    //Label lbl_AddedOn = (Label)item.FindControl("lbl_AddedOn");
                    //lbl_AddedOn.Visible = false;

                    //Edit.Display = true;
                    AddedOn.ReadOnly = true;
                    if (GridEditableItem != null && GridEditableItem is GridEditableItem)
                    {
                        e.Item.OwnerTableView.ExtractValuesFromItem(oHashTable, GridEditableItem);
                        TextBox text_notes = GridEditableItem.FindControl("text_Notes") as TextBox;
                        Label EditingLable = GridEditableItem.FindControl("lbl_Notes") as Label;
                        if (!(e.Item.DataItem is GridInsertionObject))
                            text_notes.Text = ((OpportunityNote)(e.Item.DataItem)).OpportuityNote.ToString();
                        if (text_notes != null && EditingLable != null)
                            text_notes.Text = EditingLable.Text;
                    }
                }
                else
                {

                   RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityNotes);
                    //RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityNotes);
                    //Edit.Display = false;
                    AddedOn.Display = true;
                }
            }

        }

        protected void RadGrid_OpportunityNotes_DeleteCommand(object Source, GridCommandEventArgs e)
        {
            DoDelete(e);
        }

        #endregion

        #region Grid event for Customer Contact

        #region SoldTo Party

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (RadTabStrip_ManageProjects.SelectedIndex == 2)
            {
                RadGrid_OpportunityCustomerContacts_SoldToParty.DataSource = GetOpportunityContactsForSoldTo();
            }
        }

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_OnItemCreated(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridDataItem && e.Item.IsInEditMode)
                {
                    GridEditableItem item = (GridEditableItem)e.Item;
                    CheckBox chkIsMain = (CheckBox)item["IsMain"].Controls[0];
                    CheckBox chkAttentionTo = (CheckBox)item["AttentionTo"].Controls[0];
                    chkIsMain.AutoPostBack = true;
                    chkIsMain.CheckedChanged += new EventHandler(SetAttensionTo);

                    if (chkIsMain.Checked)
                        chkAttentionTo.Enabled = true;
                    else
                    {
                        chkAttentionTo.Checked = false;
                        chkAttentionTo.Enabled = false;
                    }

                }
            }
            catch
            {
            }
        }

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_OnItemDataBound(object sender, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridDataItem && e.Item.IsInEditMode)
                {
                    GridEditableItem item = (GridEditableItem)e.Item;
                    CheckBox chkIsMain = (CheckBox)item["IsMain"].Controls[0];
                    CheckBox chkAttentionTo = (CheckBox)item["AttentionTo"].Controls[0];

                    if (chkIsMain.Checked)
                        chkAttentionTo.Enabled = true;
                    else
                    {
                        chkAttentionTo.Checked = false;
                        chkAttentionTo.Enabled = false;
                    }

                }
            }
            catch
            {
            }
        }

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_ItemCommand(object source, GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem item = e.Item as GridEditableItem;
                GridDataItem oDataItem = e.Item as GridDataItem;
                GridColumn selectColumn = RadGrid_OpportunityCustomerContacts_SoldToParty.Columns.FindByUniqueNameSafe("CheckBoxSelect");
                GridColumn ReportLinkColumn = RadGrid_OpportunityCustomerContacts_SoldToParty.Columns.FindByUniqueNameSafe("CustomerReport");
                selectColumn.Visible = true;

                ReportLinkColumn.Visible = true;
                switch (e.CommandName)
                {
                    case RadGrid.InitInsertCommandName:
                        RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
                        selectColumn.Visible = false;
                        ReportLinkColumn.Visible = false;
                        break;
                    case RadGrid.EditCommandName:
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
                        mIsEditMode = 1;
                        selectColumn.Visible = false;
                        ReportLinkColumn.Visible = false;
                        break;
                    case RadGrid.CancelCommandName:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
                        break;


                    case "Report":
                        {

                            int mCustomerID = Convert.ToInt32(oDataItem["CustomerID"].Text);

                            string url = string.Format("360degreesViewOfCustomerTillDateReportViewer.aspx?CustomerID=" + mCustomerID);
                            //PopupNewWindow(url);
                            OpenWindow(this, "Msg", "Key", url);
                        }
                        break;

                    default:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
                        break;
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_DeleteCommand(object source, GridCommandEventArgs e)
        {
            DoDeleteOpportunityCustomerAndContact(e);
        }

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_UpdateCommand(object source, GridCommandEventArgs e)
        {
            DoUpdateOpportunityCustomerAndContact(e);
        }

        protected void RadGrid_OpportunityCustomerContacts_SoldToParty_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
        {
            try
            {
                if (e.ColumnEditor is GridDropDownListColumnEditor)
                {
                    switch (e.Column.UniqueName)
                    {
                        case "CustomerContactRoleID":
                            {
                                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)e.ColumnEditor;

                                editor.DataSource = GetCustomerContactRoleNameValue();
                                editor.DataTextField = "Value";
                                editor.DataValueField = "Key";
                                editor.DataBind();
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        #endregion

        #region Bill To Party

        protected void RadGrid_OpportunityCustomerContacts_BillToParty_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {

            if (RadTabStrip_ManageProjects.SelectedIndex == 2)
            {
                Session["OpportunityContactsBeingEdited"] = null;
                OpportunityContacts OOpportunityContacts = GetOpportunityContactsForBillTo();
                RadGrid_OpportunityCustomerContacts_BillToParty.DataSource = OOpportunityContacts;
                //if (OOpportunityContacts.Count > 0)
                //    LinkButton_BillTo_AddNew.Visible = false;

            }

        }

        protected void RadGrid_OpportunityCustomerContacts_BillToParty_ItemCommand(object source, GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem item = e.Item as GridEditableItem;
                GridDataItem oDataItem = e.Item as GridDataItem;

                GridColumn ReportLinkColumnForBillTo = RadGrid_OpportunityCustomerContacts_BillToParty.Columns.FindByUniqueNameSafe("CustomerReportForBillTo");
                ReportLinkColumnForBillTo.Visible = true;


                item["IsActive"].Enabled = true;

                switch (e.CommandName)
                {
                    case RadGrid.InitInsertCommandName:
                        RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
                        ReportLinkColumnForBillTo.Visible = false;
                        break;
                    case RadGrid.EditCommandName:
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
                        ReportLinkColumnForBillTo.Visible = false;


                        break;
                    case RadGrid.CancelCommandName:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
                        break;

                    case "Report":
                        {
                            //mCustomerID = Convert.ToInt32(HiddenField_CustomerID.Value);
                            int mCustomerID = Convert.ToInt32(oDataItem["CustomerID"].Text);
                            string url = string.Format("360degreesViewOfCustomerTillDateReportViewer.aspx?CustomerID=" + mCustomerID);
                            //PopupNewWindow(url);
                            OpenWindow(this, "Msg", "Key", url);
                        }
                        break;
                    default:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
                        break;
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void RadGrid_OpportunityCustomerContacts_BillToParty_DeleteCommand(object source, GridCommandEventArgs e)
        {
            DoDeleteOpportunityCustomerAndContactForBillToOrShipTo(e, "BillTo");
        }

        protected void RadGrid_OpportunityCustomerContacts_BillToParty_UpdateCommand(object source, GridCommandEventArgs e)
        {
            DoUpdateOpportunityCustomerAndContact(e);
        }

        protected void RadGrid_OpportunityCustomerContacts_BillToParty_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
        {
            try
            {
                if (e.ColumnEditor is GridDropDownListColumnEditor)
                {
                    switch (e.Column.UniqueName)
                    {
                        case "CustomerContactRoleID":
                            {
                                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)e.ColumnEditor;

                                editor.DataSource = GetCustomerContactRoleNameValue();
                                editor.DataTextField = "Value";
                                editor.DataValueField = "Key";
                                editor.DataBind();
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        #endregion

        #region Ship To Party

        protected void RadGrid_OpportunityCustomerContacts_ShipToParty_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {

            if (RadTabStrip_ManageProjects.SelectedIndex == 2)
            {
                OpportunityContacts OOpportunityContacts = GetOpportunityContactsForShipTo();
                RadGrid_OpportunityCustomerContacts_ShipToParty.DataSource = OOpportunityContacts;
                if (OOpportunityContacts.Count > 0)
                    LinkButton_ShipTo_AddNew.Visible = false;

            }

        }

        protected void RadGrid_OpportunityCustomerContacts_ShipToParty_ItemCommand(object source, GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem item = e.Item as GridEditableItem;
                GridDataItem oDataItem = e.Item as GridDataItem;

                if (e.CommandName == "Edit")
                    item["IsActive"].Enabled = true;

                switch (e.CommandName)
                {
                    case RadGrid.InitInsertCommandName:
                        RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);

                        break;
                    case RadGrid.EditCommandName:
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);



                        break;
                    case RadGrid.CancelCommandName:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);
                        break;

                    case "Report":
                        {
                            //mCustomerID = Convert.ToInt32(HiddenField_CustomerID.Value);
                            int mCustomerID = Convert.ToInt32(oDataItem["CustomerID"].Text);
                            string url = string.Format("360degreesViewOfCustomerTillDateReportViewer.aspx?CustomerID=" + mCustomerID);
                            //PopupNewWindow(url);
                            OpenWindow(this, "Msg", "Key", url);
                        }
                        break;
                    default:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);
                        break;
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void RadGrid_OpportunityCustomerContacts_ShipToParty_DeleteCommand(object source, GridCommandEventArgs e)
        {
            DoDeleteOpportunityCustomerAndContactForBillToOrShipTo(e, "ShipTo");
        }

        protected void RadGrid_OpportunityCustomerContacts_ShipToParty_UpdateCommand(object source, GridCommandEventArgs e)
        {
            DoUpdateOpportunityCustomerAndContact(e);
        }

        protected void RadGrid_OpportunityCustomerContacts_ShipToParty_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
        {
            try
            {
                if (e.ColumnEditor is GridDropDownListColumnEditor)
                {
                    switch (e.Column.UniqueName)
                    {
                        case "CustomerContactRoleID":
                            {
                                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)e.ColumnEditor;

                                editor.DataSource = GetCustomerContactRoleNameValue();
                                editor.DataTextField = "Value";
                                editor.DataValueField = "Key";
                                editor.DataBind();
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        #endregion

        #endregion

        #region Grid Event for Employee

        protected void RadGrid_Employee_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            if (RadTabStrip_ManageProjects.SelectedIndex == 2)
            {
                RadGrid_Employee.DataSource = GetOpportunityEmployees();
            }
        }

        protected void RadGrid_Employee_UpdateCommand(object source, GridCommandEventArgs e)
        {
            DoUpdateOpportunityEmployee(e);
        }

        protected void RadGrid_Employee_DeleteCommand(object source, GridCommandEventArgs e)
        {
            DoDeleteOpportunityEmployee(e);
        }

        protected void RadGrid_Employee_ItemCommand(object source, GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem item = e.Item as GridEditableItem;
                GridDataItem oDataItem = e.Item as GridDataItem;
                switch (e.CommandName)
                {
                    case RadGrid.InitInsertCommandName:
                        RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_Employee);
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_Employee);
                        break;
                    case RadGrid.EditCommandName:
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_Employee);
                        break;
                    case RadGrid.CancelCommandName:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_Employee);
                        break;
                    default:
                        RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_Employee);
                        break;
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void RadGrid_Employee_CreateColumnEditor(object sender, GridCreateColumnEditorEventArgs e)
        {
            try
            {
                if (e.ColumnEditor is GridDropDownListColumnEditor)
                {
                    switch (e.Column.UniqueName)
                    {
                        case "DesignationID":
                            {
                                GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)e.ColumnEditor;

                                editor.DataSource = GetDesignationNameValue();
                                editor.DataTextField = "Value";
                                editor.DataValueField = "Key";
                                editor.DataBind();
                            }
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void RadGrid_Employee_ItemDataBound(object source, GridItemEventArgs e)
        {
            try
            {
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {
                    GridDataItem gridItem = e.Item as GridDataItem;
                    GridEditableItem EditItem = e.Item as GridEditableItem;
                    int iEmployeeOrganizationID = ((OpportunityEmployee)(e.Item.DataItem)).OrganizationID;
                    bool iIsOwner = ((OpportunityEmployee)(e.Item.DataItem)).IsOwner;
                    //Commented on  06/01/2014 for Enabling add and delete of employee after project is released
                    //if (mOrganizationID != iEmployeeOrganizationID || iIsOwner)
                    //EditItem["IsOwner"].Enabled = false;
                    //Commentted Ends here
                    //Added on 06/01/2014 for Enabling add and delete of employee after project is released
                    EditItem["IsOwner"].Enabled = true;
                }

            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        #endregion

        #region Employee Activities

        protected void RadGrid_EmployeeActivityList_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            RadGrid_EmployeeActivityList.DataSource = GetEmployeeActivities();
        }

        protected void RadGrid_EmployeeActivityList_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (mIsEditMode == 1)
            {
                if (e.Item is GridEditableItem && e.Item.IsInEditMode)
                {
                    GridEditableItem oGridEditableItem = e.Item as GridEditableItem;

                    RadComboBox RadComboBox_GroupName = oGridEditableItem.FindControl("RadComboBox_GroupName") as RadComboBox;
                    RadComboBox_GroupName.SelectedValue = ((EmployeeActivity)(e.Item.DataItem)).ActivityGroupID.ToString();
                    RadComboBox_GroupName.Text = ((EmployeeActivity)(e.Item.DataItem)).ActivityGroupName.ToString();


                    RadComboBox RadComboBox_Activity = oGridEditableItem.FindControl("RadComboBox_Activity") as RadComboBox;
                    RadComboBox_Activity.SelectedValue = ((EmployeeActivity)(e.Item.DataItem)).ActivityID.ToString();
                    RadComboBox_Activity.Text = ((EmployeeActivity)(e.Item.DataItem)).ActivityName.ToString();

                    RadComboBox RadComboBox_EmpActivityCustomer = oGridEditableItem.FindControl("RadComboBox_EmpActivityCustomer") as RadComboBox;
                    RadComboBox_EmpActivityCustomer.SelectedValue = ((EmployeeActivity)(e.Item.DataItem)).CustomerID.ToString();
                    RadComboBox_EmpActivityCustomer.Text = ((EmployeeActivity)(e.Item.DataItem)).CustomerName.ToString();

                    RadComboBox RadComboBox_EmpActivityCustomerContact = oGridEditableItem.FindControl("RadComboBox_EmpActivityCustomerContact") as RadComboBox;
                    RadComboBox_EmpActivityCustomerContact.SelectedValue = ((EmployeeActivity)(e.Item.DataItem)).CustomerContactID.ToString();
                    RadComboBox_EmpActivityCustomerContact.Text = ((EmployeeActivity)(e.Item.DataItem)).CustomerContactName.ToString();

                    RadDatePicker RadDatePicker_PlannedDate = (RadDatePicker)oGridEditableItem.FindControl("DatePicker_PlannedActivityDate");
                    RadDatePicker_PlannedDate.SelectedDate = ((EmployeeActivity)(e.Item.DataItem)).PlannedActivityDate;
                    RadDatePicker_PlannedDate.Enabled = false;

                    RadDatePicker RadDatePicker_ActualActivityDate = (RadDatePicker)oGridEditableItem.FindControl("RadDatePicker_ActualActivityDate");

                    if (((EmployeeActivity)(e.Item.DataItem)).ActualActivityDate != null)
                    {
                        if (((EmployeeActivity)(e.Item.DataItem)).ActualActivityDate.Value.Year > 1900)
                            RadDatePicker_ActualActivityDate.SelectedDate = ((EmployeeActivity)(e.Item.DataItem)).ActualActivityDate;
                    }
                    //else
                    //    RadDatePicker_ActualActivityDate.SelectedDate = null;

                    CheckBox CheckBox_IsCompleted = (CheckBox)oGridEditableItem.FindControl("CheckBox_IsCompleted");
                    CheckBox_IsCompleted.Checked = ((EmployeeActivity)(e.Item.DataItem)).IsCompleted;

                    if (((EmployeeActivity)(e.Item.DataItem)).IsCompleted)
                        CheckBox_IsCompleted.Enabled = false;
                    if (CheckBox_IsCompleted.Checked)
                        RadDatePicker_ActualActivityDate.Enabled = false;

                }
            }

            //if (e.Item is GridDataItem)
            //{
            //    GridDataItem gridItem = e.Item as GridDataItem;
            //    //TextBox txtActualDate = gridItem["ActualActivityDate"].Controls[0] as TextBox;
            //    DateTime ActualDate = Convert.ToDateTime(gridItem["ActualActivityDate"].Text);
            //    if (ActualDate.Year < 1950)
            //        gridItem["ActualActivityDate"].Text = "";
            //}
        }

        protected void RadGrid_EmployeeActivityList_ItemCommand(object source, GridCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case RadGrid.InitInsertCommandName:
                    e.Canceled = true;
                    SetActivityDefaultValues(e);
                    RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_EmployeeActivityList);
                    RadGridHelper.MaskDeleteButtonColumn(RadGrid_EmployeeActivityList);

                    break;
                case RadGrid.EditCommandName:
                    if (!EmployeeActivity.CanEditObject())
                    {
                        e.Canceled = true;
                        XITingExceptionProcessor.ProcessException(this, "Logged-in user is not authorized to edit Activities.");
                    }
                    else
                        RadGridHelper.MaskDeleteButtonColumn(RadGrid_EmployeeActivityList);
                    mIsEditMode = 1;

                    break;
                default:

                    break;
            }
        }

        protected void RadGrid_EmployeeActivityList_InsertCommand(object source, GridCommandEventArgs e)
        {
            DoInsertEmployeeActivity(e);
        }

        protected void RadGrid_EmployeeActivityList_UpdateCommand(object source, GridCommandEventArgs e)
        {
            DoUpdateEmployeeActivity(e);
        }

        protected void RadGrid_Activities_CancelCommand(object source, GridCommandEventArgs e)
        {
            ApplyAuthorizationRulesForEmployeeACtivity();
        }

        protected void RadGrid_Activities_EditCommand(object source, GridCommandEventArgs e)
        {
            if (!EmployeeActivity.CanEditObject())
                e.Canceled = true;
        }

        protected void RadGrid_EmployeeActivityList_DeleteCommand(object source, GridCommandEventArgs e)
        {
            DoDeleteEmployeeActivity(e);
        }

        #endregion

        #endregion

        #region EmployeeActivities Methods

        private EmployeeActivities GetEmployeeActivities()
        {
            object businessObject = null;
            if (businessObject == null || !(businessObject is EmployeeActivities))
            {
                businessObject = EmployeeActivities.GetOpportunityActivity(mOpportunityID);
                //Session["EmployeeActivities"] = businessObject;
            }
            return (EmployeeActivities)businessObject;
        }

        private void DoInsertEmployeeActivity(GridCommandEventArgs e)
        {

            try
            {
                EmployeeActivities AllEmployeeActivities = GetEmployeeActivities();
                GridEditableItem editedItem = e.Item as GridEditableItem;
                GridEditFormItem oGridEditFormItem = e.Item as GridEditFormItem;

                Hashtable oHashTableNewValues = new Hashtable();

                ExtractValuesFromEditForm(oHashTableNewValues, oGridEditFormItem);

                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, editedItem);

                EmployeeActivity AnEmployeeActivity = AllEmployeeActivities.AddNew();
                EmployeeActivity CloneEmployeeActivity = AnEmployeeActivity.Clone();

                Csla.Data.DataMapper.Map(oHashTableNewValues, CloneEmployeeActivity, "AnEmployeeActivity");

                SaveEmployeeActivity(CloneEmployeeActivity, AnEmployeeActivity, AllEmployeeActivities, e);


            }

            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["currentOpportunityObject"] = null;
                e.Canceled = true;
            }
            ApplyAuthorizationRulesForEmployeeACtivity();
        }

        private void DoUpdateEmployeeActivity(GridCommandEventArgs e)
        {
            try
            {
                EmployeeActivities AllEmployeeActivities = GetEmployeeActivities();
                GridEditFormItem editedItem = e.Item as GridEditFormItem;
                Hashtable oHashTableNewValues = new Hashtable();

                ExtractValuesFromEditForm(oHashTableNewValues, editedItem);

                oHashTableNewValues["EmployeeActivityID"] = int.Parse(editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["EmployeeActivityID"].ToString());

                EmployeeActivity AnEmployeeActivity = AllEmployeeActivities.GetItem(Convert.ToInt32(oHashTableNewValues["EmployeeActivityID"].ToString()));
                EmployeeActivity CloneEmployeeActivity = AnEmployeeActivity.Clone();

                AllEmployeeActivities.BeginEdit();
                Csla.Data.DataMapper.Map(oHashTableNewValues, CloneEmployeeActivity, "EmployeeActivityID");
                SaveEmployeeActivity(CloneEmployeeActivity, AnEmployeeActivity, AllEmployeeActivities, e);
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["EmployeeActivities"] = null;
                e.Canceled = true;
            }
            ApplyAuthorizationRulesForEmployeeACtivity();
        }

        private void DoDeleteEmployeeActivity(GridCommandEventArgs e)
        {
            try
            {
                GridDataItem oDataItem = e.Item as GridDataItem;

                int iEmployeeActivityID = Convert.ToInt32(oDataItem["EmployeeActivityID"].Text);
                EmployeeActivities AllEmployeeActivities = GetEmployeeActivities();
                AllEmployeeActivities.Remove(iEmployeeActivityID);
                AllEmployeeActivities.Save();
                RadGrid_EmployeeActivityList.DataBind();
                e.Canceled = false;
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["EmployeeActivities"] = null;
                e.Canceled = true;
            }
            ApplyAuthorizationRulesForEmployeeACtivity();
        }

        private void SaveEmployeeActivity(EmployeeActivity ClonedEmployeeActivity,
                                        EmployeeActivity UpdatedEmployeeActivity,
                                        EmployeeActivities AllEmployeeActivities,
                                        GridCommandEventArgs e)
        {
            if (ClonedEmployeeActivity.BrokenRulesCollection.Count == 0)
            {
                Csla.Data.DataMapper.Map(ClonedEmployeeActivity, UpdatedEmployeeActivity, "EmployeeActivityID");
                AllEmployeeActivities.ApplyEdit();
                Session["EmployeeActivities"] = AllEmployeeActivities.Save();
                RadGrid_EmployeeActivityList.Rebind();
                e.Canceled = false;
                Label_LastActivity.Text = EmployeeActivityDA.OpportunityLastActivity(mOpportunityID);
            }
            else
            {
                AllEmployeeActivities.CancelEdit();
                RadGrid_EmployeeActivityList.Rebind();
                e.Canceled = true;
                XITingExceptionProcessor.ProcessException(this, ClonedEmployeeActivity.BrokenRulesCollection.ToString());
            }
        }

        private void ApplyAuthorizationRulesForEmployeeACtivity()
        {
            try
            {
                if (!IsOpportunityEmployee(mEmployeeID))
                {
                    RadGridHelper.RemoveCommandItemDisplay(RadGrid_EmployeeActivityList);
                    RadGridHelper.MaskDeleteButtonColumn(RadGrid_EmployeeActivityList);
                    RadGridHelper.MaskUpdateButtonColumn(RadGrid_EmployeeActivityList);
                }
                else
                {
                    RadGridHelper.ApplyAuthorizationRules(EmployeeActivity.CanAddObject(), EmployeeActivity.CanEditObject(), EmployeeActivity.CanDeleteObject(), RadGrid_EmployeeActivityList);
                }
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        private void SetActivityDefaultValues(GridCommandEventArgs e)
        {
            e.Item.OwnerTableView.InsertItem(GetOpportunityDefaultValues(e));
        }

        private System.Collections.Specialized.ListDictionary GetOpportunityDefaultValues(GridCommandEventArgs e)
        {
            System.Collections.Specialized.ListDictionary DefaultValues = new System.Collections.Specialized.ListDictionary();
            return DefaultValues;
        }

        private void ExtractValuesFromEditForm(Hashtable oHashTableNewValues, GridEditFormItem oGridEditFormItem)
        {
            oHashTableNewValues.Clear();

            sErrorMessage = new StringBuilder();

            if ((((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_GroupName")).Text) == BLANK)
            {
                sErrorMessage.Append(" Please Select Activity Group");
                sErrorMessage.Append(Environment.NewLine);
            }
            if ((((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_Activity")).Text) == BLANK)
            {
                sErrorMessage.Append(" Please Select Activity");
                sErrorMessage.Append(Environment.NewLine);
            }
            if ((((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_EmpActivityCustomer")).Text) == BLANK)
            {
                sErrorMessage.Append(" Please Select Customer");
                sErrorMessage.Append(Environment.NewLine);
            }
            if ((((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_EmpActivityCustomerContact")).Text) == BLANK)
            {
                sErrorMessage.Append(" Please Select Customer Contact");
                sErrorMessage.Append(Environment.NewLine);
            }

            if (((RadDatePicker)oGridEditFormItem.FindControl("DatePicker_PlannedActivityDate")).SelectedDate.ToString() == BLANK)
            {
                sErrorMessage.Append(" Please Select Planned Activity Date.");
                sErrorMessage.Append(Environment.NewLine);
            }
            if (sErrorMessage.ToString() != "")
            {
                throw new Exception(sErrorMessage.ToString());
            }

            oHashTableNewValues.Add("EmployeeID", mEmployeeID.ToString());
            oHashTableNewValues.Add("OpportunityID", mOpportunityID.ToString());

            oHashTableNewValues.Add("PlannedActivityDate", ((RadDatePicker)oGridEditFormItem.FindControl("DatePicker_PlannedActivityDate")).SelectedDate);


            oHashTableNewValues.Add("Purpose", ((TextBox)oGridEditFormItem.FindControl("TextBox_Purpose")).Text.Trim());
            oHashTableNewValues.Add("Venue", ((TextBox)oGridEditFormItem.FindControl("TextBox_Venue")).Text.Trim());
            oHashTableNewValues.Add("Notes", ((TextBox)oGridEditFormItem.FindControl("TextBox_Notes")).Text.Trim());

            CheckBox oCheckBox = (CheckBox)oGridEditFormItem.FindControl("CheckBox_IsCompleted");
            oHashTableNewValues.Add("IsCompleted", oCheckBox.Checked);

            oHashTableNewValues.Add("ActivityID", int.Parse(((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_Activity")).SelectedValue));
            oHashTableNewValues.Add("ActivityName", (((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_Activity")).Text.Trim()));

            oHashTableNewValues.Add("ActivityGroupID", int.Parse(((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_GroupName")).SelectedValue));
            oHashTableNewValues.Add("ActivityGroupName", (((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_GroupName")).Text));

            oHashTableNewValues.Add("CustomerID", int.Parse(((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_EmpActivityCustomer")).SelectedValue));
            oHashTableNewValues.Add("CustomerContactID", int.Parse(((RadComboBox)oGridEditFormItem.FindControl("RadComboBox_EmpActivityCustomerContact")).SelectedValue));

            if (oCheckBox.Checked && ((TextBox)oGridEditFormItem.FindControl("TextBox_Notes")).Text == BLANK)
                throw new Exception(ENTER_NOTES);

            RadDatePicker RadDatePicker_ActualActivityDate = (RadDatePicker)oGridEditFormItem.FindControl("RadDatePicker_ActualActivityDate");


            if (oCheckBox.Checked && RadDatePicker_ActualActivityDate.SelectedDate.ToString() == BLANK || RadDatePicker_ActualActivityDate.SelectedDate.ToString() == null)
            {
                oHashTableNewValues.Add("ActualActivityDate", DateTime.Now);
                RadDatePicker_ActualActivityDate.Enabled = false;
            }
            else
            {
                if (RadDatePicker_ActualActivityDate.SelectedDate.ToString() != BLANK)
                    oHashTableNewValues.Add("ActualActivityDate", RadDatePicker_ActualActivityDate.SelectedDate);
                else
                    oHashTableNewValues.Add("ActualActivityDate", null);
            }
        }

        #endregion

        #region RadComboBox Events

        public void rcbCurrency_OnSelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                FillExchangeRateCombo();
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }
        protected void rjxPanel_AjaxRequest(object sender, AjaxRequestEventArgs e)
        {
            Opportunity oOpportunity = (Opportunity)Session["OpportunityBeingEdited"];
            SetCompetitorCombo(oOpportunity.OpportunityID);

        }

        protected void RadCombobox_MainCompetitor_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            RadCombobox_MainCompetitor.Items.Clear();
            LoadCompetitorCombo();

            try
            {
                DataRow[] rows;
                //if (e.Text.Contains(","))
                //{
                //    string[] text;
                //    text = e.Text.Split(',');
                //    rows = oCompetitorsTable.Select("ProductManufacturerName LIKE '" + text[text.Length - 1].ToString() + "*'", "ProductManufacturerID");
                //}
                //else
                //{
                string text;
                text = e.Text;
                //rows = oCompetitorsTable.Select("ProductManufacturerName LIKE '" + text + "*'", "ProductManufacturerID");
                rows = oCompetitorsTable.Select("ProductManufacturerName LIKE '*'", "ProductManufacturerID");
                //}

                int itemsPerRequest = rows.Length;
                int itemOffset = e.NumberOfItems;
                int endOffset = itemOffset + itemsPerRequest;
                //if (endOffset > rows.Length)
                //{
                //    endOffset = rows.Length;
                //}

                for (int i = itemOffset; i < endOffset; i++)
                {
                    RadComboBoxItem newItem = new RadComboBoxItem(rows[i]["ProductManufacturerName"].ToString(), rows[i]["ProductManufacturerID"].ToString());
                    RadCombobox_MainCompetitor.Items.Add(newItem);

                    CheckBox chk1 = (CheckBox)newItem.FindControl("chk1");

                    CompetitorIDs = HiddenField_CompetitorIDs.Value.Split(',');

                    for (int j = 1; j < CompetitorIDs.Length; j++)
                    {
                        if (rows[i]["ProductManufacturerID"].ToString() == CompetitorIDs[j])
                        {
                            chk1.Checked = true;
                        }
                    }

                    Label label1 = (Label)newItem.FindControl("Label1");
                    label1.Text = rows[i]["ProductManufacturerName"].ToString();
                }
                if (rows.Length > 0)
                {
                    e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
                }
                else
                {
                    e.Message = "No matches";
                }


            }
            catch (Exception ex)
            {
                ex.Source = this.AppRelativeVirtualPath;
                e.Message = "No matches";
            }
        }

        protected void RadComboBox_SCountryName_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillSiteAddStates();
            FillSiteAddCities();
        }

        protected void RadComboBox_SStateName_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillSiteAddCities();
        }

        protected void RadComboBox_SCityName_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Populate list of Area based on the country,state,city selected.
            if (RadComboBox_SCityName.Text.ToLower().Trim() != "other")
            {
                //if (RadComboBox_AreaName.Visible)
                //{
                //    RadComboBox_AreaName.Items.Clear();
                //    RadComboBox_PinCode.Items.Clear();
                //    GetAreaName();
                //    PopulateArea_PinCodeDetail();
                //}
                TextBox_SCity.Visible = false;
            }
            else
            {
                TextBox_SCity.Visible = true;
            }
        }

        protected void RadComboBox_BCountryName_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillBillingAddStates();
            FillBillingAddCities();
        }

        protected void RadComboBox_BStateName_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillBillingAddCities();
        }

        protected void RadComboBox_BCityName_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Populate list of Area based on the country,state,city selected.
            if (RadComboBox_BCityName.Text.ToLower().Trim() != "other")
            {
                //if (RadComboBox_AreaName.Visible)
                //{
                //    RadComboBox_AreaName.Items.Clear();
                //    RadComboBox_PinCode.Items.Clear();
                //    GetAreaName();
                //    PopulateArea_PinCodeDetail();
                //}
                TextBox_BCity.Visible = false;
            }
            else
            {
                TextBox_BCity.Visible = true;
            }
        }

        protected void RadComboBox_TCountryName_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillStorageAddStates();
            FillStorageAddCities();
        }

        protected void RadComboBox_TStateName_SelectedIndexChanged(object sender, EventArgs e)
        {
            FillStorageAddCities();

        }

        protected void RadComboBox_TCityName_SelectedIndexChanged(object sender, EventArgs e)
        {
            //Populate list of Area based on the country,state,city selected.
            if (RadComboBox_TCityName.Text.ToLower().Trim() != "other")
            {
                //if (RadComboBox_AreaName.Visible)
                //{
                //    RadComboBox_AreaName.Items.Clear();
                //    RadComboBox_PinCode.Items.Clear();
                //    GetAreaName();
                //    PopulateArea_PinCodeDetail();
                //}
                TextBox_TCity.Visible = false;
            }
            else
            {
                TextBox_TCity.Visible = true;
            }
        }

        protected void RadComboBox_SalesType_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetOpportuntiyRefDetail();
        }

        protected void RadComboBox_OpportunityCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            GetOpportuntiyCategoryWithCostCenter();
        }

        //for employee Activities
        #region Load RadComboBox

        private void LoadRadComboActivityGroup()
        {
            SafeDataReader dr = ActivityGroupDA.GetNameValue(NEW_SALESGROUP_TYPE);
            oActivityGroupDataTable.Load(dr);
        }

        private void LoadRadComboEmpActivityCustomer()
        {
            SafeDataReader dr = CustomerDA.GetOpportunityCustomerNameValue(mOpportunityID);
            oDataTableOpportunityCustomers.Load(dr);
        }

        private void LoadRadComboEmpActivityCustomerContacts(int CustomerID)
        {
            SafeDataReader dr = CustomerContactsDA.GetCustomerContactNameValue(CustomerID);
            oDataTableOpportunityCustomerContacts.Load(dr);
        }

        private void LoadRadComboActivity(int AcitivityGroupID)
        {
            SafeDataReader dr = ActivityDA.GetNameValue(AcitivityGroupID);
            oActivityGroupDataTable.Load(dr);
        }

        #endregion

        protected void RadComboBox_GroupName_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox RadComboBox_Group;
            RadComboBox_Group = (RadComboBox)o;

            RadComboBox RadComboBox_Activity = RadComboBox_Group.Parent.FindControl("RadComboBox_Activity") as RadComboBox;
            RadComboBox_Activity.ClearSelection();
            RadComboBox_Activity.SelectedValue = BLANK;
            RadComboBox_Activity.Text = BLANK;
            Session["ActivityGroupID"] = RadComboBox_Group.SelectedValue;
        }

        protected void RadComboBox_GroupName_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadRadComboActivityGroup();
            RadComboBox oRadComboBox_GroupName = (RadComboBox)o;
            oRadComboBox_GroupName.Items.Clear();
            string text = e.Text;
            try
            {
                DataRow[] rows = oActivityGroupDataTable.Select("ActivityGroupName LIKE '" + text + "*'");

                int itemsPerRequest = 10;
                int itemOffset = e.NumberOfItems;
                int endOffset = itemOffset + itemsPerRequest;

                if (endOffset > rows.Length)
                {
                    endOffset = rows.Length;
                }

                for (int i = itemOffset; i < endOffset; i++)
                {
                    oRadComboBox_GroupName.Items.Add(new RadComboBoxItem(rows[i]["ActivityGroupName"].ToString(), rows[i]["ActivityGroupID"].ToString()));
                }

                if (rows.Length > 0)
                {
                    e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
                }
                else
                {
                    e.Message = "No matches";
                }
            }
            catch
            {
                e.Message = "No matches";
            }


        }

        protected void RadComboBox_Activity_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            RadComboBox oRadComboBox_Activity = (RadComboBox)o;

            RadComboBox oRadComboBox_GroupName = oRadComboBox_Activity.Parent.FindControl("RadComboBox_GroupName") as RadComboBox;

            if (oRadComboBox_GroupName.Text != BLANK)
            {
                LoadRadComboActivity(Convert.ToInt32(oRadComboBox_GroupName.SelectedValue));

                oRadComboBox_Activity.Items.Clear();

                string text = e.Text;

                try
                {
                    DataRow[] rows = oActivityGroupDataTable.Select("ActivityName LIKE '" + text + "*'", "ActivityName");

                    int itemsPerRequest = 10;
                    int itemOffset = e.NumberOfItems;
                    int endOffset = itemOffset + itemsPerRequest;
                    if (endOffset > rows.Length)
                    {
                        endOffset = rows.Length;
                    }

                    for (int i = itemOffset; i < endOffset; i++)
                    {
                        oRadComboBox_Activity.Items.Add(new RadComboBoxItem(rows[i]["ActivityName"].ToString(), rows[i]["ActivityID"].ToString()));
                    }
                    if (rows.Length > 0)
                    {
                        e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
                    }
                    else
                    {
                        e.Message = "No matches";
                    }
                }
                catch (Exception ex)
                {
                    ex.Source = this.AppRelativeVirtualPath;
                    e.Message = "No matches";
                }
            }
            else
                throw new ApplicationException("Select Activity Group");
        }

        protected void RadComboBox_EmpActivityCustomer_OnItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadRadComboEmpActivityCustomer();
            RadComboBox RadComboBox_EmpActivityCustomer = (RadComboBox)o;
            RadComboBox_EmpActivityCustomer.Items.Clear();
            string text = e.Text;
            try
            {
                DataRow[] rows = oDataTableOpportunityCustomers.Select();//.Select("CustomerName LIKE '" + text + "*'");

                int itemsPerRequest = 10;
                int itemOffset = e.NumberOfItems;
                int endOffset = itemOffset + itemsPerRequest;

                if (endOffset > rows.Length)
                {
                    endOffset = rows.Length;
                }

                for (int i = itemOffset; i < endOffset; i++)
                {
                    RadComboBox_EmpActivityCustomer.Items.Add(new RadComboBoxItem(rows[i]["CustomerName"].ToString(), rows[i]["CustomerID"].ToString()));
                }

                if (rows.Length > 0)
                {
                    e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
                }
                else
                {
                    e.Message = "No matches";
                }
            }
            catch
            {
                e.Message = "No matches";
            }
        }

        protected void RadComboBox_EmpActivityCustomer_OnSelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            RadComboBox RadComboBox_EmpActivityCustomer = (RadComboBox)o;
            HiddenField_CustomerID.Value = e.Value;
            RadComboBox RadComboBox_EmpActivityCustomerContact = RadComboBox_EmpActivityCustomer.Parent.FindControl("RadComboBox_EmpActivityCustomerContact") as RadComboBox;
            RadComboBox_EmpActivityCustomerContact.ClearSelection();
            RadComboBox_EmpActivityCustomerContact.SelectedValue = BLANK;
            RadComboBox_EmpActivityCustomerContact.Text = BLANK;

        }

        protected void RadComboBox_EmpActivityCustomerContact_OnItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {

            if (!string.IsNullOrEmpty(HiddenField_CustomerID.Value))
            {
                LoadRadComboEmpActivityCustomerContacts(Convert.ToInt32(HiddenField_CustomerID.Value));

                RadComboBox RadComboBox_EmpActivityCustomerContact = (RadComboBox)o;

                RadComboBox_EmpActivityCustomerContact.Items.Clear();
                string text = e.Text;
                try
                {
                    DataRow[] rows = oDataTableOpportunityCustomerContacts.Select();//.Select("CustomerContactName LIKE '" + text + "*'");

                    int itemsPerRequest = 10;
                    int itemOffset = e.NumberOfItems;
                    int endOffset = itemOffset + itemsPerRequest;

                    if (endOffset > rows.Length)
                    {
                        endOffset = rows.Length;
                    }

                    for (int i = itemOffset; i < endOffset; i++)
                    {
                        RadComboBox_EmpActivityCustomerContact.Items.Add(new RadComboBoxItem(rows[i]["CustomerContactName"].ToString(), rows[i]["CustomerContactID"].ToString()));
                    }

                    if (rows.Length > 0)
                    {
                        e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), rows.Length.ToString());
                    }
                    else
                    {
                        e.Message = "No matches";
                    }
                }
                catch
                {
                    e.Message = "No matches";
                }
            }

        }

        protected void RadComboBox_CostCenter_OnItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            DataTable mProfitCenterDataTable = new DataTable();
            RadComboBox_CostCenter.Items.Clear();
            string text = e.Text;

            try
            {
                int itemsPerRequest = 10;
                int itemOffset = e.NumberOfItems;
                int endOffset = itemOffset + itemsPerRequest;

                using (SafeDataReader dr = CostCentreDA.GetProfitCentreNameValue(endOffset, e.Text))
                {
                    mProfitCenterDataTable.Load(dr);
                }

                int RowCount = int.Parse(mProfitCenterDataTable.Rows[0][0].ToString());

                DataRow[] rows = mProfitCenterDataTable.Select("CostCentreDescription LIKE '" + text + "*'", "SequenceNo");

                if (endOffset > RowCount)
                {
                    endOffset = RowCount;
                }
                int index = RadComboBox_CostCenter.Items.Count;
                for (int i = itemOffset; i < endOffset; i++)
                {
                    RadComboBox_CostCenter.Items.Add(new RadComboBoxItem(rows[i]["CostCentreDescription"].ToString(), rows[i]["CostCentreID"].ToString()));

                    index++;
                }
                if (RowCount > 0)
                {
                    e.Message = String.Format("Items <b>1</b>-<b>{0}</b> out of <b>{1}</b>", endOffset.ToString(), RowCount.ToString());
                }
                else
                {
                    e.Message = "No matches";
                }
            }
            catch (Exception ex)
            {
                // throw new Exception("No matches",ex.InnerException);
            }
        }

        #endregion

        #region Basic Info

        #region Fill ComboBox

        private void FillOpportunityTypeCombo()
        {
            try
            {
                OpportunityTypeNameValue oOpportunityTypeNameValue = GetOpportunityTypeNameValue();
                RadComboBox_OpportunityType.DataSource = oOpportunityTypeNameValue;
                RadComboBox_OpportunityType.DataTextField = "Value";
                RadComboBox_OpportunityType.DataValueField = "Key";
                RadComboBox_OpportunityType.DataBind();

            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }

        private void SetCompetitorCombo(int OpportunityID)
        {
            string CompetitorNames = string.Empty;
            LoadCompetitorCombo();
            OpportunityCompetitors AllOpportunityCompetitors = OpportunityCompetitors.GetOpportunityCompetitors(OpportunityID);
            foreach (OpportunityCompetitor AnOpportunityCompetitor in AllOpportunityCompetitors)
            {
                HiddenField_CompetitorIDs.Value += "," + AnOpportunityCompetitor.CompetitorID.ToString();
                DataRow[] rows = oCompetitorsTable.Select("ProductManufacturerID = " + AnOpportunityCompetitor.CompetitorID);
                CompetitorNames += "," + rows[0]["ProductManufacturerName"].ToString();
            }
            if (AllOpportunityCompetitors.Count != 0)
            {
                RadCombobox_MainCompetitor.Text = CompetitorNames.Remove(0, 1);

            }

            CompetitorIDs = HiddenField_CompetitorIDs.Value.Split(',');
        }

        private void FillFutureProspectCombo()
        {

            try
            {
                FutureProspectNameValue oFutureProspectNameValue = GetFutureProspectNameValue();

                RadComboBox_FutureProspect.DataSource = oFutureProspectNameValue;
                RadComboBox_FutureProspect.DataTextField = "Value";
                RadComboBox_FutureProspect.DataValueField = "Key";
                RadComboBox_FutureProspect.DataBind();

            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }

        private void FillSalesTypesCombo()
        {
            try
            {
                SalesTypesNameValue oSalesTypesNameValue = GetSalesTypesNameValue();
                UIHelper.BindDataToRadComboBox(rcbSalesType, oSalesTypesNameValue, "Value", "Key");
                //rcbSalesType.SelectedIndex = 0;
                HiddenField_SalesTypeID.Value = rcbSalesType.SelectedValue.ToString();
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }

        private void FillCurrencyCombo()
        {
            CurrenciesNameValue oCurrenciesNameValue = CurrenciesNameValue.GetCurrenciesNameValue(mLanguageID);
            UIHelper.BindDataToRadComboBox(rcbCurrency, oCurrenciesNameValue, "Value", "Key");
        }

        private void GetOpportuntiyRefDetail()
        {
            STATUSTYPEID = Convert.ToInt32(rcbSalesType.SelectedValue.Replace("1", "2"));
            if (rcbSalesType.SelectedValue != "1")
                STATUSTYPEID = Convert.ToInt32(rcbSalesType.SelectedValue.Replace("3", "15").Replace("4", "15"));
            oDatasetOppRef = OpportunityDA.GetOpportuntyRef(mOrganizationID, STATUSTYPEID, mEntityID, 0);
            RadComboBox_OpportunityCategory.SelectedValue = oDatasetOppRef.Tables[0].Rows[0][0].ToString();
            RadComboBox_CostCenter.Text = "";
            RadComboBox_CostCenter.SelectedValue = null;
            RadComboBox_CostCenter.SelectedValue = oDatasetOppRef.Tables[0].Rows[0][1].ToString();
            RadComboBox_CostCenter.Text = oDatasetOppRef.Tables[0].Rows[0][3].ToString();

        }
        private void GetOpportuntiyCategoryWithCostCenter()
        {
            STATUSTYPEID = Convert.ToInt32(rcbSalesType.SelectedValue.Replace("1", "2"));
            if (rcbSalesType.SelectedValue != "1")
                STATUSTYPEID = Convert.ToInt32(rcbSalesType.SelectedValue.Replace("3", "15").Replace("4","15"));
            oDatasetOppRef = OpportunityDA.GetOpportuntyRef(mOrganizationID, STATUSTYPEID, mEntityID, Convert.ToInt32(RadComboBox_OpportunityCategory.SelectedValue));
            RadComboBox_CostCenter.SelectedValue = oDatasetOppRef.Tables[0].Rows[0]["CostCenterID"].ToString();
            RadComboBox_CostCenter.Text = oDatasetOppRef.Tables[0].Rows[0]["CostCentreDescription"].ToString();

        }
        private void FillOpportunityCategoryCombo()
        {
            try
            {
                OpportunityCategoryNameValue oOpportunityCategoryNameValue = GetOpportunityCategoryNameValue();

                RadComboBox_OpportunityCategory.DataSource = oOpportunityCategoryNameValue;
                RadComboBox_OpportunityCategory.DataTextField = "Value";
                RadComboBox_OpportunityCategory.DataValueField = "Key";
                RadComboBox_OpportunityCategory.DataBind();
                RadComboBoxItem oItem = new RadComboBoxItem("Select", "0");
                RadComboBox_OpportunityCategory.Items.Insert(0, oItem);
                RadComboBox_OpportunityCategory.SelectedIndex = 0;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }

        private void FillOpportunitySourceCombo()
        {
            try
            {
                OpportunitySourceNameValue oOpportunitySourceNameValue = OpportunitySourceNameValue.GetOpportunitySourceNameValue(mRootOrganizationID, mLanguageID);
                UIHelper.BindDataToRadComboBox(rcbSource, oOpportunitySourceNameValue, "Value", "Key");
                rcbSource.SelectedIndex = 0;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }

        private void LoadCompetitorCombo()
        {
            oCompetitorsTable.Clear();
            SafeDataReader dr = ProductManufacturersDA.GetCompetitorNameValue();
            oCompetitorsTable.Load(dr);
        }

        private void FillSitesAddCountry()
        {
            object businessObject;
            businessObject = CountryNameValue.GetCountriesforWhichSatesAndCitiesExist(mRootOrganizationID, true, true);

            CountryNameValue oCountryNameValue = (CountryNameValue)businessObject;
            if (oCountryNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_SCountryName, oCountryNameValue, "Value", "Key");
                RadComboBox_SStateName.SelectedIndex = 0;
            }
            else
                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillSiteAddStates()
        {

            object businessObject;
            int CountryID = Convert.ToInt32(RadComboBox_SCountryName.SelectedValue);

            businessObject = StateNameValue.GetStatesConsistingWhichConsistsCities(CountryID, true);

            StateNameValue oStateNameValue = (StateNameValue)businessObject;
            if (oStateNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_SStateName, oStateNameValue, "Value", "Key");
                RadComboBox_SStateName.SelectedIndex = 0;
            }
            else

                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillSiteAddCities()
        {
            object businessObject;
            int CountryID = Convert.ToInt32(RadComboBox_SCountryName.SelectedValue);
            int StateID = Convert.ToInt32(RadComboBox_SStateName.SelectedValue);

            Session["CountryID"] = CountryID;
            Session["StateID"] = StateID;

            businessObject = CityNameValue.GetCityNameValue(CountryID, StateID);

            CityNameValue oCityNameValue = (CityNameValue)businessObject;

            if (oCityNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_SCityName, oCityNameValue, "Value", "Key");
                RadComboBox_SCityName.SelectedIndex = 0;
            }
            else
                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillBillingAddCountry()
        {
            object businessObject;
            businessObject = CountryNameValue.GetCountriesforWhichSatesAndCitiesExist(mRootOrganizationID, true, true);

            CountryNameValue oCountryNameValue = (CountryNameValue)businessObject;
            if (oCountryNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_BCountryName, oCountryNameValue, "Value", "Key");
                RadComboBox_BStateName.SelectedIndex = 0;
            }
            else
                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillBillingAddStates()
        {

            object businessObject;
            int CountryID = Convert.ToInt32(RadComboBox_BCountryName.SelectedValue);
            businessObject = StateNameValue.GetStatesConsistingWhichConsistsCities(CountryID, true);

            StateNameValue oStateNameValue = (StateNameValue)businessObject;
            if (oStateNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_BStateName, oStateNameValue, "Value", "Key");
                RadComboBox_BStateName.SelectedIndex = 0;
            }
            else

                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillBillingAddCities()
        {
            object businessObject;
            int CountryID = Convert.ToInt32(RadComboBox_BCountryName.SelectedValue);
            int StateID = Convert.ToInt32(RadComboBox_BStateName.SelectedValue);

            Session["CountryID"] = CountryID;
            Session["StateID"] = StateID;
            businessObject = CityNameValue.GetCityNameValue(CountryID, StateID);

            CityNameValue oCityNameValue = (CityNameValue)businessObject;

            if (oCityNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_BCityName, oCityNameValue, "Value", "Key");
                RadComboBox_BCityName.SelectedIndex = 0;
            }
            else
                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillStorageAddCountry()
        {
            object businessObject;
            businessObject = CountryNameValue.GetCountriesforWhichSatesAndCitiesExist(mRootOrganizationID, true, true);

            CountryNameValue oCountryNameValue = (CountryNameValue)businessObject;
            if (oCountryNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_TCountryName, oCountryNameValue, "Value", "Key");
                RadComboBox_TStateName.SelectedIndex = 0;
            }
            else
                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillStorageAddStates()
        {

            object businessObject;
            int CountryID = Convert.ToInt32(RadComboBox_TCountryName.SelectedValue);
            businessObject = StateNameValue.GetStatesConsistingWhichConsistsCities(CountryID, true);

            StateNameValue oStateNameValue = (StateNameValue)businessObject;
            if (oStateNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_TStateName, oStateNameValue, "Value", "Key");
                RadComboBox_TStateName.SelectedIndex = 0;
            }
            else

                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void FillStorageAddCities()
        {
            object businessObject;
            int CountryID = Convert.ToInt32(RadComboBox_TCountryName.SelectedValue);
            int StateID = Convert.ToInt32(RadComboBox_TStateName.SelectedValue);

            Session["CountryID"] = CountryID;
            Session["StateID"] = StateID;

            businessObject = CityNameValue.GetCityNameValue(CountryID, StateID);

            CityNameValue oCityNameValue = (CityNameValue)businessObject;

            if (oCityNameValue.Count > 0)
            {
                UIHelper.BindDataToRadComboBox(RadComboBox_TCityName, oCityNameValue, "Value", "Key");
                RadComboBox_TCityName.SelectedIndex = 0;
            }
            else
                throw new System.Exception("City permissions are not defined for the user.");
        }

        private void BindExchnageRateCombo(int ExchangeRateID)
        {
            int iForeignExchangeRateTypeID = 1;
            ForexRatesInfoList AllActiveForexRatesInfoList = ForexRatesInfoList.GetAllActiveForexRatesInfoListForInvoices(UIHelper.GetLoggedInUserOrganizationCurrencyId(mOrganizationID), int.Parse(rcbCurrency.SelectedValue), GlobalConstants.DEFAULT_LANGUAGE_ID, iForeignExchangeRateTypeID);

            ForexRatesInfoList AllForexRatesInfoList = ForexRatesInfoList.GetForexRatesInfoList(ExchangeRateID);
            if (AllForexRatesInfoList.Count > 0)
                if (!AllActiveForexRatesInfoList.Contains(AllForexRatesInfoList[0]))
                    AllActiveForexRatesInfoList.AddItem(AllForexRatesInfoList[0]);
            rcbExchangeRate.DataSource = null;
            rcbExchangeRate.DataSource = AllActiveForexRatesInfoList;
            rcbExchangeRate.DataBind();
        }

        private void FillExchangeRateCombo()
        {
            int iForeignExchangeRateTypeID = 1;
            if (!string.IsNullOrEmpty(Convert.ToString(rcbExchangeRate.SelectedItem)))
                rcbExchangeRate.Text = "";
            ForexRatesInfoList AllForexRatesInfoList = ForexRatesInfoList.GetAllActiveForexRatesInfoListForInvoices(UIHelper.GetLoggedInUserOrganizationCurrencyId(mOrganizationID), int.Parse(rcbCurrency.SelectedValue), GlobalConstants.DEFAULT_LANGUAGE_ID, iForeignExchangeRateTypeID);
            rcbExchangeRate.DataSource = AllForexRatesInfoList;
            rcbExchangeRate.DataBind();
        }

        private void SetConfigurationSetting()
        {
            #region Allow Billing Plan

            if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_ALLOW_BILLING_PLAN).ToLower() == "yes")
            {
                Tab_BillingPlan.Visible = true;
                Label_BillingAmount_Value.Visible = true;
                Label_BillingAmount.Visible = true;
                Label_BilledAmount.Visible = true;
                Label_BilledAmount_Value.Visible = true;
                Tab_BillingPlan.Enabled = true;
                if (!BillingPlan.CanGetObject())
                    Tab_BillingPlan.Enabled = false;
            }
            else
            {
                Tab_BillingPlan.Visible = false;
                Label_BillingAmount_Value.Visible = false;
                Label_BilledAmount_Value.Visible = false;
                Label_BillingAmount.Visible = false;
                Label_BilledAmount.Visible = false;
            }
            #endregion

            #region Allow Project Budget
            if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_ALLOW_PROJECT_BUDGET).ToLower() == "yes")
            {
                Tab_ProjectBudget.Visible = true;
            }
            else
                Tab_ProjectBudget.Visible = false;

            #endregion

            //#region Show Cost Center
            //if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_SHOWCOSTCENTRE).ToLower() == "no")
            //{
            //    RadComboBox_CostCenter.Visible = false;
            //    lblCostCentermandatory.Visible = false;
            //    label_CostCenter.Visible = false;
            //}
            //#endregion

            //#region Show Forex Rates
            //if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_SHOWFOREXRATES).ToLower() == "no")
            //{
            //    lblForex.Visible = false;
            //    Label12.Visible = false;
            //    rcbExchangeRate.Visible = false;
            //}
            //#endregion

            //#region Show Contract Start and End Date
            //if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_CONTRACTDATE_SETTING).ToLower() == "no")
            //{
            //    Label_ContractStartDate.Visible = false;
            //    DatePicker_ContractStartDate.Visible = false;
            //    Label_ContractEndDate.Visible = false;
            //    DatePicker_ContractEndDate.Visible = false;
            //}
            //#endregion

            //#region Show Is Local Sale
            //if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_SHOWSALESFROMLOCAL).ToLower() == "no")
            //{
            //    Label14.Visible = false;
            //    chkIsSaleForLocal.Visible = false;
            //}
            //#endregion

        }

        #endregion

        #region Private Methods

        private void DoInsert(GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                Hashtable oHashTableNewValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, editedItem);

                OpportunityNotes AllOpportunityNotes = GetOpportunityNotes();
                OpportunityNote AnOpportunityNote = AllOpportunityNotes.AddNew();
                AnOpportunityNote.OpportunityID = Convert.ToInt32(HiddenField_OpportunityID.Value);
                AnOpportunityNote.IsActive = true;
                AnOpportunityNote.OpportuityNote = ((TextBox)editedItem.FindControl("text_Notes")).Text;
                OpportunityNote CloneOpportunityNote = AnOpportunityNote.Clone();

                SaveNote(CloneOpportunityNote, AnOpportunityNote, AllOpportunityNotes, e);
            }
            catch (Exception ex)
            {
                e.Canceled = true;
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }
        private void DoUpdate(GridCommandEventArgs e)
        {
            try
            {
                OpportunityNotes AllOpportunityNotes = GetOpportunityNotes();
                GridEditableItem editedItem = e.Item as GridEditableItem;
                Hashtable oHashTableNewValues = new Hashtable();

                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, editedItem);
                ExtractValuesFromTemplateControls(editedItem, oHashTableNewValues);
                AllOpportunityNotes.BeginEdit();

                OpportunityNote AnOpportunityNote = AllOpportunityNotes.GetItem(Convert.ToInt32(editedItem.SavedOldValues["OpportunityNoteID"].ToString()));
                OpportunityNote CloneOpportunityNote = AnOpportunityNote.Clone();

                Csla.Data.DataMapper.Map(oHashTableNewValues, CloneOpportunityNote, "OpportunityID", "OpportunityNoteID");
                SaveNote(CloneOpportunityNote, AnOpportunityNote, AllOpportunityNotes, e);
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["currentObject"] = null;
                e.Canceled = true;
            }

        }

        private void DoDelete(GridCommandEventArgs e)
        {
            try
            {
                GridDataItem oDataItem = e.Item as GridDataItem;

                int iOpportunityNoteID = Convert.ToInt32(oDataItem["OpportunityNoteID"].Text);

                OpportunityNotes AllOpportunityNotes = GetOpportunityNotes();
                AllOpportunityNotes.Remove(iOpportunityNoteID);
                AllOpportunityNotes.Save();
                RadGrid_OpportunityNotes.DataBind();
                e.Canceled = false;
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["currentOpportunityObject"] = null;
                e.Canceled = true;
            }
            //ApplyAuthorizationRules();
        }

        private void SaveNote(OpportunityNote ClonedOpportunityNote,
                                        OpportunityNote UpdatedOpportunityNote,
                                        OpportunityNotes AllOpportunityNotes,
                                        GridCommandEventArgs e)
        {
            if (ClonedOpportunityNote.BrokenRulesCollection.Count == 0)
            {
                Csla.Data.DataMapper.Map(ClonedOpportunityNote, UpdatedOpportunityNote, "OpportunityNoteID");
                AllOpportunityNotes.ApplyEdit();
                AllOpportunityNotes.Save();
                RadGrid_OpportunityNotes.Rebind();
                e.Canceled = false;
            }
            else
            {
                AllOpportunityNotes.CancelEdit();
                e.Canceled = true;
                XITingExceptionProcessor.ProcessException(this, ClonedOpportunityNote.BrokenRulesCollection.ToString());
            }
        }
        private void ExtractValuesFromTemplateControls(GridEditableItem editedItem, Hashtable oHashTableNewValues)
        {
            TextBox Text_Notes = (TextBox)editedItem.FindControl("text_Notes");
            oHashTableNewValues.Add("OpportuityNote", Text_Notes.Text);
        }
        private void MaskAddedOn(GridCommandEventArgs e)
        {
            if (e.Item.IsInEditMode)
            {
                //GridEditableItem item = e.Item as GridEditableItem;
                //Label lbl_AddedOn = (Label)item.FindControl("lbl_AddedOn");
                //lbl_AddedOn.Visible = false;

                GridBoundColumn AddedOn = RadGrid_OpportunityNotes.Columns.FindByUniqueName("AddedOn") as GridBoundColumn;
                AddedOn.Display = false;
            }
        }

        private OpportunityNotes GetOpportunityNotes()
        {
            try
            {
                object businessObject = null;
                if (businessObject == null || !(businessObject is OpportunityNotes))
                {
                    businessObject = OpportunityNotes.GetOpportunityNote(mOpportunityID);
                }
                return (OpportunityNotes)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private void SetAttensionTo(object sender, EventArgs e)
        {
            CheckBox chkIsMain = (CheckBox)sender;
            GridEditableItem item = (GridEditableItem)chkIsMain.NamingContainer;

            CheckBox chkAttentionTo = (CheckBox)item["AttentionTo"].Controls[0];
            if (chkIsMain.Checked)
            {
                chkAttentionTo.Enabled = true;
                chkAttentionTo.Checked = true;
            }

            else
            {
                chkAttentionTo.Checked = false;
                chkAttentionTo.Enabled = false;
            }

        }

        #endregion

        #endregion

        #region Address Info

        #region Fill ComboBox

        private void InitializeLocationRadComboBox()
        {
            try
            {
                int StateID = 0, CountryID = 0;

                // mOrganizationID = UIHelper.GetCurrentUsersOrganizationId();
                Organizations AllOrganizations = Organizations.GetOrganizations();
                Organization AnOrganizations = AllOrganizations.GetItem(mOrganizationID);

                StateID = AnOrganizations.StateID;
                CountryID = AnOrganizations.CountryID;


                FillSitesAddCountry();

                if (RadComboBox_SCountryName.Items.Count > 0)
                {
                    RadComboBox_SCountryName.SelectedValue = CountryID.ToString();
                    FillSiteAddStates();

                    if (RadComboBox_SStateName.Items.Count > 0)
                    {
                        RadComboBox_SStateName.SelectedValue = StateID.ToString();
                        FillSiteAddCities();

                        RadComboBox_SCityName.SelectedIndex = 0;

                    }
                }


                FillBillingAddCountry();

                if (RadComboBox_BCountryName.Items.Count > 0)
                {
                    RadComboBox_BCountryName.SelectedIndex = 0;
                    FillBillingAddStates();
                    if (RadComboBox_BStateName.Items.Count > 0)
                    {
                        RadComboBox_BStateName.SelectedIndex = 0;
                        FillBillingAddCities();

                        RadComboBox_BCityName.SelectedIndex = 0;

                    }
                }

                FillStorageAddCountry();

                if (RadComboBox_TCountryName.Items.Count > 0)
                {
                    RadComboBox_TCountryName.SelectedIndex = 0;
                    FillStorageAddStates();
                    if (RadComboBox_TStateName.Items.Count > 0)
                    {
                        RadComboBox_TStateName.SelectedIndex = 0;
                        FillStorageAddCities();

                        RadComboBox_TCityName.SelectedIndex = 0;

                    }
                }
            }
            catch (Exception Ex)
            {
                XITingExceptionProcessor.ProcessException(this, Ex);
            }
        }

        private void PopulateLocationValuesFromControls(OpportunityLocation oOpportunityLocation, int LocationType)
        {

            if (LocationType == SITE_LOCATION_TYPE)
            {
                int iCityID;
                int iCountryID = Convert.ToInt32(RadComboBox_SCountryName.SelectedValue.ToString());
                int iStateID = Convert.ToInt32(RadComboBox_SStateName.SelectedValue.ToString());

                oOpportunityLocation.LocationAddress1 = TextBox_SAddressLine1.Text;
                oOpportunityLocation.LocationAddress2 = TextBox_SAddressLine2.Text;
                oOpportunityLocation.LocationAddress3 = TextBox_SAddressLine3.Text;
                oOpportunityLocation.ZipCode = TextBox_SZipCode.Text.Trim();

                if (TextBox_SCity.Visible == false)
                {
                    iCityID = Convert.ToInt32(RadComboBox_SCityName.SelectedValue);
                }
                else
                {
                    if (TextBox_SCity.Text == BLANK)
                        throw new Exception(ENTER_CITY);

                    if (DoesCityAlreadyExistForInsert(iCountryID, iStateID, TextBox_SCity.Text.ToString()))
                        throw new Exception(CITY_NAME_ALREADY_EXIST);

                    iCityID = GetCityID(iCountryID, iStateID, TextBox_SCity.Text);
                    FillSiteAddCities();
                    RadComboBox_SCityName.SelectedValue = iCityID.ToString();
                }
                oOpportunityLocation.TelephoneNo = TextBox_STelephoneNo.Text;
                //oOpportunityLocation.MaterialInDate = System.DateTime.Now;
                //oOpportunityLocation.DispatchedDate = System.DateTime.Now;
                oOpportunityLocation.StateID = iStateID;
                oOpportunityLocation.CountryID = iCountryID;
                oOpportunityLocation.CityID = iCityID;
                oOpportunityLocation.IsActive = true;
            }
            if (LocationType == BILLING_LOCATION_TYPE)
            {
                int iCityID;
                int iCountryID = Convert.ToInt32(RadComboBox_BCountryName.SelectedValue.ToString());
                int iStateID = Convert.ToInt32(RadComboBox_BStateName.SelectedValue.ToString());

                oOpportunityLocation.LocationAddress1 = TextBox_BAddressLine1.Text;
                oOpportunityLocation.LocationAddress2 = TextBox_BAddressLine2.Text;
                oOpportunityLocation.LocationAddress3 = TextBox_BAddressLine3.Text;
                oOpportunityLocation.ZipCode = TextBox_BZipcode.Text;

                if (TextBox_BCity.Visible == false)
                {
                    iCityID = Convert.ToInt32(RadComboBox_BCityName.SelectedValue);
                }
                else
                {
                    if (TextBox_BCity.Text == BLANK)
                        throw new Exception(ENTER_CITY);

                    if (DoesCityAlreadyExistForInsert(iCountryID, iStateID, TextBox_BCity.Text.ToString()))
                        throw new Exception(CITY_NAME_ALREADY_EXIST);

                    iCityID = GetCityID(iCountryID, iStateID, TextBox_BCity.Text);
                    FillBillingAddCities();
                    RadComboBox_BCityName.SelectedValue = iCityID.ToString();
                }
                oOpportunityLocation.TelephoneNo = TextBox_BTelephoneNo.Text;
                oOpportunityLocation.StateID = iStateID;
                oOpportunityLocation.CountryID = iCountryID;
                oOpportunityLocation.CityID = iCityID;
                //oOpportunityLocation.MaterialInDate = System.DateTime.Now;
                //oOpportunityLocation.DispatchedDate = System.DateTime.Now;
                oOpportunityLocation.IsActive = true;
            }
            if (LocationType == TEMPORARY_STORAGE_LOCATION_TYPE)
            {
                int iCityID;
                int iCountryID = Convert.ToInt32(RadComboBox_TCountryName.SelectedValue.ToString());
                int iStateID = Convert.ToInt32(RadComboBox_TStateName.SelectedValue.ToString());

                oOpportunityLocation.LocationAddress1 = TextBox_TAddressLine1.Text;
                oOpportunityLocation.LocationAddress2 = TextBox_TAddressLine2.Text;
                oOpportunityLocation.LocationAddress3 = TextBox_TAddressLine3.Text;
                oOpportunityLocation.ZipCode = TextBox_TZipCode.Text.Trim();

                if (TextBox_TCity.Visible == false)
                {
                    iCityID = Convert.ToInt32(RadComboBox_TCityName.SelectedValue);
                }
                else
                {
                    if (TextBox_TCity.Text == BLANK)
                        throw new Exception(ENTER_CITY);

                    if (DoesCityAlreadyExistForInsert(iCountryID, iStateID, TextBox_TCity.Text.ToString()))
                        throw new Exception(CITY_NAME_ALREADY_EXIST);

                    iCityID = GetCityID(iCountryID, iStateID, TextBox_TCity.Text);
                    FillStorageAddCities();
                    RadComboBox_TCityName.SelectedValue = iCityID.ToString();
                }
                oOpportunityLocation.TelephoneNo = TextBox_TTelephoneNo.Text;
                oOpportunityLocation.StateID = iStateID;
                oOpportunityLocation.CountryID = iCountryID;
                oOpportunityLocation.CityID = iCityID;
                oOpportunityLocation.MaterialInDate = RadDatePicker_InDate.SelectedDate;
                oOpportunityLocation.DispatchedDate = RadDatePicker_DispatchedDate.SelectedDate;
                oOpportunityLocation.IsActive = true;
            }
        }



        #endregion

        #region Private Methods

        private void SetValuesToOpportunitySiteAddress(OpportunityLocation oOpportunityLocation)
        {
            HiddenField_SiteAddress.Value = oOpportunityLocation.OpportunityLocationID.ToString();
            FillSitesAddCountry();
            RadComboBox_SCountryName.SelectedValue = Convert.ToString(oOpportunityLocation.CountryID);

            RadComboBox_SStateName.Items.Clear();
            FillSiteAddStates();
            RadComboBox_SStateName.SelectedValue = Convert.ToString(oOpportunityLocation.StateID);

            RadComboBox_SCityName.Items.Clear();
            FillSiteAddCities();
            RadComboBox_SCityName.SelectedValue = Convert.ToString(oOpportunityLocation.CityID);


            TextBox_SAddressLine1.Text = oOpportunityLocation.LocationAddress1;
            TextBox_SAddressLine2.Text = oOpportunityLocation.LocationAddress2;
            TextBox_SAddressLine3.Text = oOpportunityLocation.LocationAddress3;

            TextBox_SZipCode.Text = oOpportunityLocation.ZipCode.Trim();
            TextBox_STelephoneNo.Text = oOpportunityLocation.TelephoneNo;

        }

        private void SetValuesToOpportunityBillingAddress(OpportunityLocation oOpportunityLocation)
        {
            HiddenField_BillingAddress.Value = oOpportunityLocation.OpportunityLocationID.ToString();
            FillBillingAddCountry();
            RadComboBox_BCountryName.SelectedValue = Convert.ToString(oOpportunityLocation.CountryID);

            RadComboBox_BStateName.Items.Clear();
            FillBillingAddStates();
            RadComboBox_BStateName.SelectedValue = Convert.ToString(oOpportunityLocation.StateID);

            RadComboBox_BCityName.Items.Clear();
            FillBillingAddCities();
            RadComboBox_BCityName.SelectedValue = Convert.ToString(oOpportunityLocation.CityID);


            TextBox_BAddressLine1.Text = oOpportunityLocation.LocationAddress1;
            TextBox_BAddressLine2.Text = oOpportunityLocation.LocationAddress2;
            TextBox_BAddressLine3.Text = oOpportunityLocation.LocationAddress3;
            TextBox_BZipcode.Text = oOpportunityLocation.ZipCode.Trim();
            TextBox_BTelephoneNo.Text = oOpportunityLocation.TelephoneNo;

        }

        private void SetValuesToOpportunityStorageAddress(OpportunityLocation oOpportunityLocation)
        {
            HiddenField_TemporaryStorage.Value = oOpportunityLocation.OpportunityLocationID.ToString();
            FillStorageAddCountry();
            RadComboBox_TCountryName.SelectedValue = Convert.ToString(oOpportunityLocation.CountryID);

            RadComboBox_TStateName.Items.Clear();
            FillStorageAddStates();
            RadComboBox_TStateName.SelectedValue = Convert.ToString(oOpportunityLocation.StateID);

            RadComboBox_TCityName.Items.Clear();
            FillStorageAddCities();
            RadComboBox_TCityName.SelectedValue = Convert.ToString(oOpportunityLocation.CityID);


            TextBox_TAddressLine1.Text = oOpportunityLocation.LocationAddress1;
            TextBox_TAddressLine2.Text = oOpportunityLocation.LocationAddress2;
            TextBox_TAddressLine3.Text = oOpportunityLocation.LocationAddress3;

            TextBox_TZipCode.Text = oOpportunityLocation.ZipCode.Trim();
            TextBox_TTelephoneNo.Text = oOpportunityLocation.TelephoneNo;
            RadDatePicker_InDate.SelectedDate = oOpportunityLocation.MaterialInDate;
            RadDatePicker_DispatchedDate.SelectedDate = oOpportunityLocation.DispatchedDate;

        }

        private Location GetLocation(int locationID)
        {
            Locations locations;

            locations = Locations.GetLocation(locationID);
            return locations == null ? null : locations[0];
        }

        private Locations GetLocations()
        {
            object businessObject;
            businessObject = Locations.GetLocations(mRootOrganizationID);
            return (Locations)businessObject;
        }

        private Locations GetLocations(int locationID)
        {
            Locations locations;

            locations = Locations.GetLocation(locationID);
            return locations;
        }

        private Locations GetNewLocations()
        {
            object businessObject;
            businessObject = Locations.NewLocations();
            return (Locations)businessObject;
        }

        private Cities GetCities(int iCountryID, int iStateID)
        {
            object businessObject = null;
            if (businessObject == null || !(businessObject is Cities))
            {
                try
                {
                    businessObject = Cities.GetCities(iCountryID, iStateID);
                }
                catch (Exception e)
                {
                    XITingExceptionProcessor.ProcessException(this, e);
                }
            }
            return (Cities)businessObject;
        }

        private int GetCityID(int iCountryID, int iStateID, string sCityName)
        {
            int CityID = 0;
            Cities AllCities = GetCities(iCountryID, iStateID);
            Hashtable oHashTableNewValues = new Hashtable();
            //AllCities.BeginEdit();
            City oCity = AllCities.AddNew(iCountryID, iStateID);
            oCity.CityName = sCityName;
            oCity.IsActive = true;
            AllCities.Save();
            CityID = oCity.CityID;
            return CityID;
        }

        #endregion

        #endregion

        #region Customer & Contact

        #region Customer And Contact Data Update Methods

        private void DoUpdateOpportunityCustomerAndContact(GridCommandEventArgs e)
        {
            try
            {
                GridEditableItem editedItem = e.Item as GridEditableItem;
                Hashtable oHashTableNewValues = new Hashtable();

                bool bIsActive;
                //The GridTableView will fill the values from all editable columns in the hashtable.
                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, editedItem);
                int iMainCustomerID = 0;
                int iAttentionToCount = 0;

                int iCustomerContactRoleID = Convert.ToInt32(oHashTableNewValues["CustomerContactRoleID"]);
                int iCustomerID = Convert.ToInt32(editedItem.GetDataKeyValue("CustomerID"));
                int iOpportunityID = Convert.ToInt32(editedItem.GetDataKeyValue("OpportunityID"));
                int iCustomerContactID = Convert.ToInt32(editedItem.SavedOldValues["CustomerContactID"].ToString());
                if (!Convert.ToBoolean(oHashTableNewValues["IsBillTo"]))
                {
                    bIsActive = Convert.ToBoolean(oHashTableNewValues["IsActive"]);
                }
                else
                    bIsActive = true;
                bool bIsMain = Convert.ToBoolean(oHashTableNewValues["IsMain"]);
                //bool IsSoldTo = Convert.ToBoolean(oHashTableNewValues["IsSoldTo"]);
                bool bAttentionTo = Convert.ToBoolean(oHashTableNewValues["AttentionTo"]);

                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts();
                OpportunityContact oOpportunityContact = AllOpportunityContacts.Get(iOpportunityID, iCustomerID, iCustomerContactID);
                oOpportunityContact.CustomerContactRoleID = iCustomerContactRoleID;


                if (bAttentionTo == true)//uncheck AttentionTo of previous customer & set it to current customer
                {

                    foreach (OpportunityContact item in AllOpportunityContacts)
                    {
                        if (item.AttentionTo == true && item.CustomerID != oOpportunityContact.CustomerID)
                            item.AttentionTo = false;
                        if (item.CustomerID == oOpportunityContact.CustomerID)
                            item.AttentionTo = false;

                    }
                    oOpportunityContact.AttentionTo = bAttentionTo;
                }

                if (bIsMain == true) // uncheck ismain of previous customer and check ismain of current customer//ismain is true then record must be active
                {
                    foreach (OpportunityContact item in AllOpportunityContacts)
                    {
                        if (item.IsMain == true && item.CustomerID != oOpportunityContact.CustomerID)
                        {
                            item.IsMain = false;
                            item.AttentionTo = false; //uncheck attension to of the customers whoes is main is disabled.
                        }
                    }

                    oOpportunityContact.IsMain = bIsMain;
                    oOpportunityContact.IsActive = true;


                    for (int i = 0; i < AllOpportunityContacts.Count; i++)
                    {
                        if (AllOpportunityContacts[i].CustomerID == oOpportunityContact.CustomerID)
                        {
                            AllOpportunityContacts[i].IsMain = true;
                            oOpportunityContact.IsActive = true;

                        }
                    }

                    for (int i = 0; i < AllOpportunityContacts.Count; i++)
                    {
                        if (AllOpportunityContacts[i].IsMain == true && AllOpportunityContacts[i].AttentionTo == true)
                            iAttentionToCount++;
                    }

                    if (iAttentionToCount == 0)
                        oHashTableNewValues["AttentionTo"] = bAttentionTo;

                }
                else
                {
                    bool flag = false;
                    foreach (OpportunityContact item in AllOpportunityContacts)
                    {
                        if (item.IsMain == true && item.CustomerID != oOpportunityContact.CustomerID)
                            flag = true;

                    }
                    if (!flag && bIsMain == false)
                    {
                        throw new Exception("Atleast one customer should be main");
                    }


                    //if(bIsMain==false)
                    //throw new Exception("Atleast one customer should be main");

                    if (AllOpportunityContacts.Count == 1) // if only one customer then it must be main,active and attention to
                    {
                        oOpportunityContact.IsMain = bIsMain;
                        oHashTableNewValues["IsMain"] = true;
                        oOpportunityContact.IsActive = true;
                        oHashTableNewValues["IsActive"] = true;
                        oOpportunityContact.AttentionTo = bAttentionTo;
                        oHashTableNewValues["AttentionTo"] = true;

                    }
                    else
                    {
                        foreach (OpportunityContact item in AllOpportunityContacts)
                        {
                            if (oOpportunityContact.CustomerID == item.CustomerID)
                            {
                                item.IsMain = false;
                                //item.AttentionTo = false;
                            }

                            if (item.IsMain)
                                iMainCustomerID = item.CustomerID;

                        }
                        if (iMainCustomerID == 0)
                        {
                            for (int i = 0; i < AllOpportunityContacts.Count; i++)
                            {
                                if (oOpportunityContact.CustomerID != AllOpportunityContacts[i].CustomerID)
                                {
                                    iMainCustomerID = AllOpportunityContacts[i].CustomerID;
                                    AllOpportunityContacts[i].AttentionTo = true;

                                    if (AllOpportunityContacts[i].CustomerID == iMainCustomerID)
                                    {
                                        AllOpportunityContacts[i].IsMain = true;
                                        AllOpportunityContacts[i].IsActive = true;
                                        AllOpportunityContacts[i].AttentionTo = bAttentionTo;

                                    }
                                    break;
                                }
                            }
                        }
                        for (int i = 0; i < AllOpportunityContacts.Count; i++)
                        {
                            if (AllOpportunityContacts[i].CustomerID == iMainCustomerID)

                                AllOpportunityContacts[i].IsMain = true;

                        }
                    }

                }

                if (bIsActive == false && oOpportunityContact.IsMain == true)
                {
                    e.Canceled = true;
                    throw new Exception(MAIN_CUSTOMER_SHOULD_BE_ACTIVE);
                }

                //oOpportunityContact.AttentionTo =Convert.ToBoolean(oHashTableNewValues["AttentionTo"]);

                if (mOpportunityID > 0)
                {

                    AllOpportunityContacts.BeginEdit();
                    OpportunityContact ClonedOpportunityContact = oOpportunityContact.Clone();
                    Csla.Data.DataMapper.Map(oHashTableNewValues, ClonedOpportunityContact, "OpportunityID", "CustomerID", "CustomerContactID", "CustomerRoleID");
                    SaveOpportunityContacts(ClonedOpportunityContact, oOpportunityContact, AllOpportunityContacts, e);
                }
                RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();

            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }

        private void DoDeleteOpportunityCustomerAndContact(GridCommandEventArgs e)
        {
            try
            {
                GridDataItem oDataItem = e.Item as GridDataItem;
                GridEditableItem item = e.Item as GridEditableItem;

                Hashtable oHashTableNewValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, item);

                int iCustomerID = Convert.ToInt32(oDataItem["CustomerID"].Text);
                int iCustomerContactID = Convert.ToInt32(oDataItem["CustomerContactID"].Text);
                int iCustomerContactRoleID = Convert.ToInt32(oHashTableNewValues["CustomerContactRoleID"]);

                if (Convert.ToBoolean(oHashTableNewValues["IsMain"]) == true)
                    throw new Exception(CUSTOMER_SHOULD_NOT_DELETE);

                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts();

                OpportunityContact oOpportunityContact = AllOpportunityContacts.Get(mOpportunityID, iCustomerID, iCustomerContactID);
                oOpportunityContact.IsSoldTo = false;
                //AllOpportunityContacts.Get(mOpportunityID, iCustomerID, iCustomerContactID).IsDeleted = true;
                if (!oOpportunityContact.IsBillTo && !oOpportunityContact.IsSoldTo)
                {
                    if (Convert.ToBoolean(oHashTableNewValues["IsMain"]) == true)
                    {
                        oOpportunityContact.IsSoldTo = true;
                        throw new Exception(CUSTOMER_SHOULD_NOT_DELETE);
                    }
                    AllOpportunityContacts.Remove(mOrganizationID, mOpportunityID, iCustomerID, iCustomerContactID, iCustomerContactRoleID);
                }


                if (mOpportunityID > 0)
                {
                    //AllOpportunityContacts.Save();
                    Session["OpportunityContactsBeingEdited"] = AllOpportunityContacts.Save();
                    RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();

                }
                e.Canceled = false;

            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["currentOpportunityObject"] = null;
                e.Canceled = true;
            }
        }

        private void DoDeleteOpportunityCustomerAndContactForBillToOrShipTo(GridCommandEventArgs e, String CustomerType)
        {
            try
            {
                GridDataItem oDataItem = e.Item as GridDataItem;
                GridEditableItem item = e.Item as GridEditableItem;

                Hashtable oHashTableNewValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, item);


                int iCustomerID = Convert.ToInt32(oDataItem["CustomerID"].Text);
                int iCustomerContactID = Convert.ToInt32(oDataItem["CustomerContactID"].Text);
                int iCustomerContactRoleID = Convert.ToInt32(oHashTableNewValues["CustomerContactRoleID"]);

                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts();
                OpportunityContact oOpportunityContact = AllOpportunityContacts.Get(mOpportunityID, iCustomerID, iCustomerContactID);
                if (CustomerType.ToUpper() == "BillTo".ToUpper())
                    oOpportunityContact.IsBillTo = false;
                else
                    oOpportunityContact.IsShipTo = false;
                //AllOpportunityContacts.Get(mOpportunityID, iCustomerID, iCustomerContactID).IsDeleted = true;
                if (!oOpportunityContact.IsBillTo && !oOpportunityContact.IsSoldTo && !oOpportunityContact.IsShipTo)
                {
                    if (Convert.ToBoolean(oHashTableNewValues["IsMain"]) == true)
                    {
                        oOpportunityContact.IsBillTo = true;
                        throw new Exception(CUSTOMER_SHOULD_NOT_DELETE);
                    }

                    AllOpportunityContacts.Remove(mOrganizationID, mOpportunityID, iCustomerID, iCustomerContactID, iCustomerContactRoleID);
                }

                if (mOpportunityID > 0)
                {
                    //AllOpportunityContacts.Save();
                    Session["OpportunityContactsBeingEdited"] = AllOpportunityContacts.Save();
                    //RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                    if (CustomerType.ToUpper() == "BillTo".ToUpper())
                        RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                    else
                        RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();
                }
                e.Canceled = false;
                if (CustomerType.ToUpper() == "BillTo".ToUpper())
                    LinkButton_BillTo_AddNew.Visible = true;
                else
                    LinkButton_ShipTo_AddNew.Visible = true;
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["currentOpportunityObject"] = null;
                e.Canceled = true;
            }
        }

        private void SaveOpportunityContacts(OpportunityContact ClonedOpportunityContact,
                                          OpportunityContact UpdatedOpportunityContact,
                                          OpportunityContacts AllOpportunityContacts,
                                          GridCommandEventArgs e)
        {

            if (ClonedOpportunityContact.BrokenRulesCollection.Count == 0)
            {
                Csla.Data.DataMapper.Map(ClonedOpportunityContact, UpdatedOpportunityContact, "OpportunityID", "CustomerID", "CustomerContactID", "CustomerRoleID");
                AllOpportunityContacts.ApplyEdit();
                Session["OpportunityContactsBeingEdited"] = AllOpportunityContacts.Save();
                RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();
                e.Canceled = false;
            }
            else
            {
                AllOpportunityContacts.CancelEdit();
                RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();


                e.Canceled = true;
                XITingExceptionProcessor.ProcessException(this, ClonedOpportunityContact.BrokenRulesCollection.ToString());
            }

        }


        #endregion

        #region Collection Methods for Customer & Contact

        private OpportunityContacts GetOpportunityContacts()
        {
            try
            {
                object businessObject; //= Session["OpportunityContactsBeingEdited"];
                //if (businessObject == null || !(businessObject is OpportunityContacts))
                //{
                businessObject = OpportunityContacts.GetOpportunityCustomerContacts(mOpportunityID, mLanguageID);
                Session["OpportunityContactsBeingEdited"] = businessObject;
                //}

                return (OpportunityContacts)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private OpportunityContacts GetOpportunityContactsForSoldTo()
        {
            try
            {
                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts().GetSoldToCustomers();
                return AllOpportunityContacts;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private OpportunityContacts GetOpportunityContactsForBillTo()
        {
            try
            {
                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts().GetBillToCustomers();
                return AllOpportunityContacts;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private OpportunityContacts GetOpportunityContactsForShipTo()
        {
            try
            {
                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts().GetShipToCustomers();
                return AllOpportunityContacts;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private CustomerContactRoleNameValue GetCustomerContactRoleNameValue()
        {
            try
            {
                //object businessObject = Session["CustomerContactRoleNameValue"];
                object businessObject = null;
                if (businessObject == null || !(businessObject is CustomerContactRoleNameValue))
                {
                    businessObject = CustomerContactRoleNameValue.GetCustomerContactRoleNameValue();
                    //Session["CustomerContactRoleNameValue"] = businessObject;
                }
                return (CustomerContactRoleNameValue)businessObject;

            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private DesignationNameValue GetDesignationNameValue()
        {
            try
            {
                object businessObject = null;
                businessObject = DesignationNameValue.GetDesignationNameValue(UIHelper.GetCurrentUsersRootOrganizationId(), mLanguageID);
                return (DesignationNameValue)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private void SetValuesOfOpportunityCustomersAndContactsFromQueryString()
        {
            ArrayList ArrCustomer = GetCustomerOpportunityInformationFromQueryString();
            if (ArrCustomer.Count > 0)
            {
                int[] ArrCustomerType = (int[])ArrCustomer[0];
                int[] ArrCustomerID = (int[])ArrCustomer[1];
                int[] ArrCustomerContactID = (int[])ArrCustomer[2];

                OpportunityContacts AllOpportunityContacts = GetOpportunityContacts();
                CustomerInfoList oCustomerInfoList = GetCustomerInfoList();

                for (int iCurrentRecord = 0; iCurrentRecord < ArrCustomerID.Length; iCurrentRecord++)
                {
                    if (ArrCustomerID[iCurrentRecord] != 0)
                    {

                        OpportunityContact oOpportunityContact = AllOpportunityContacts.AddNew();
                        CustomerInfo oCustomerInfo = oCustomerInfoList.GetItem(ArrCustomerID[iCurrentRecord]);

                        CustomerType oCustomerType = (CustomerType)CustomerTypes.GetCustomerTypes(mRootOrganizationID).GetCustomerTypeById(ArrCustomerType[iCurrentRecord]);

                        CustomerContacts AllCustomerContacts = CustomerContacts.GetCustomerContacts(ArrCustomerID[iCurrentRecord], mRootOrganizationID);
                        CustomerContact oCustomerContacts = AllCustomerContacts.GetCustomerContact(ArrCustomerID[iCurrentRecord], ArrCustomerContactID[iCurrentRecord]);

                        oOpportunityContact.OpportunityID = mOpportunityID;
                        oOpportunityContact.CustomerID = ArrCustomerID[iCurrentRecord];
                        oOpportunityContact.CustomerName = oCustomerInfo.CustomerName;
                        oOpportunityContact.PhoneNumber1 = oCustomerInfo.PhoneNumber1;
                        oOpportunityContact.FaxNumber = oCustomerInfo.Fax;
                        oOpportunityContact.EmailAddress = oCustomerInfo.Email;
                        oOpportunityContact.CustomerTypeName = oCustomerType.CustomerTypeName;
                        oOpportunityContact.CustomerRoleID = GetDefaultCustomerRoleID();
                        oOpportunityContact.CustomerContactID = ArrCustomerContactID[iCurrentRecord];
                        oOpportunityContact.CustomerContactRoleID = GetDefaultCustomerConatctRoleID();
                        oOpportunityContact.CustomerContactName = oCustomerContacts.CustomerContactFirstName + " " + oCustomerContacts.CustomerContactLastName;
                        oOpportunityContact.IsActive = true;
                        oOpportunityContact.IsSoldTo = true;
                        oOpportunityContact.CustomerNo = oCustomerInfo.CustomerNo;
                        oOpportunityContact.CustomerContactEmailID = oCustomerContacts.EmailAddress;

                        oOpportunityContact.DesignationName = oCustomerContacts.DesignationName;


                        if (iCurrentRecord == 0)
                        {
                            oOpportunityContact.IsMain = true;
                            //oOpportunityContact.AttentionTo = true;
                            oOpportunityContact.IsSoldTo = true;


                        }
                        else
                            oOpportunityContact.IsMain = false;
                        //oOpportunityContact.AttentionTo = false;
                        if (oOpportunityContact.IsMain == true)
                            oOpportunityContact.AttentionTo = true;



                    }

                }
            }

        }

        private ArrayList GetCustomerOpportunityInformationFromQueryString()
        {
            ArrayList ArrayListCustomer = new ArrayList();

            int[] CustomerID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int[] CustomerTypeID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int[] ContactID = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            if (Request.QueryString["CustomerInformation"] != null && Request.QueryString["CustomerInformation"] != BLANK)
            {
                string CustomerInformation = Request.QueryString["CustomerInformation"].ToString();

                CustomerInformation = Server.UrlDecode(CustomerInformation);

                string[] ArrCustomers = CustomerInformation.Split(',');

                for (int i = 0, j = 0; i < ArrCustomers.Length; i++, j++)
                {

                    char[] ArrSplit = { '-', '-' };
                    string[] IDs = ArrCustomers[i].Split(ArrSplit);

                    CustomerTypeID[j] = int.Parse(IDs[0]);
                    CustomerID[j] = int.Parse(IDs[1]);
                    ContactID[j] = int.Parse(IDs[2]);
                }
            }
            ArrayListCustomer.Add(CustomerTypeID);
            ArrayListCustomer.Add(CustomerID);
            ArrayListCustomer.Add(ContactID);

            return ArrayListCustomer;
        }

        private CustomerInfoList GetCustomerInfoList()
        {
            try
            {
                // object businessObject = Session["CustomerInfoList"];
                object businessObject = null;
                if (businessObject == null || !(businessObject is CustomerInfoList))
                {
                    businessObject = CustomerInfoList.GetCustomerInfoList(mRootOrganizationID);
                    //Session["CustomerInfoList"] = businessObject;
                }
                return (CustomerInfoList)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private int GetDefaultCustomerRoleID()
        {
            return CustomerRoleDA.GetDefaultCustomerRoleID(mOrganizationID);
        }

        private int GetDefaultCustomerConatctRoleID()
        {
            return CustomerContactRoleDA.GetDefaultCustomerContactRoleID(mOrganizationID);
        }

        #endregion

        #region Employee Data Update Method



        private void DoUpdateOpportunityEmployee(GridCommandEventArgs e)
        {
            try
            {
                // int iCount = 0;
                GridEditableItem editedItem = e.Item as GridEditableItem;

                Hashtable oHashTableNewValues = new Hashtable();
                GridDataItem oDataItem = e.Item as GridDataItem;

                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, editedItem);

                int iEmployeeID = Convert.ToInt32(oHashTableNewValues["EmployeeID"]);
                int iOpportunityID = Convert.ToInt32(editedItem.GetDataKeyValue("OpportunityID"));
                bool bIsOwner = Convert.ToBoolean(oHashTableNewValues["IsOwner"]);
                int iDesignationID = Convert.ToInt32(oHashTableNewValues["DesignationID"]);

                OpportunityEmployees AllOpportunityEmployees = GetOpportunityEmployees();
                OpportunityEmployee oOpportunityEmployee = AllOpportunityEmployees.Get(iOpportunityID, iEmployeeID);

                if (bIsOwner == true)
                {
                    foreach (OpportunityEmployee item in AllOpportunityEmployees)
                    {
                        if (item.IsOwner == true)
                            item.IsOwner = false;
                    }

                }
                else
                {
                    bool flag = false;
                    foreach (OpportunityEmployee item in AllOpportunityEmployees)
                    {
                        if (item.IsOwner == true && item.EmployeeID != oOpportunityEmployee.EmployeeID)
                            flag = true;

                    }
                    if (!flag && bIsOwner == false)
                    {
                        throw new Exception("Atleast one Employee should be Owner");
                    }
                }
                oOpportunityEmployee.IsOwner = bIsOwner;
                oOpportunityEmployee.DesignationID = iDesignationID;
                HiddenField_EmployeeEditFlag.Value = "False";


                if (mOpportunityID > 0)
                {

                    AllOpportunityEmployees.BeginEdit();
                    OpportunityEmployee ClonedOpportunityEmployee = oOpportunityEmployee.Clone();
                    Csla.Data.DataMapper.Map(oHashTableNewValues, ClonedOpportunityEmployee, "OpportunityID", "EmployeeID");
                    SaveOpportunityEmployees(ClonedOpportunityEmployee, oOpportunityEmployee, AllOpportunityEmployees, e);
                }
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
            }
        }



        private void DoDeleteOpportunityEmployee(GridCommandEventArgs e)
        {
            try
            {
                GridDataItem oDataItem = e.Item as GridDataItem;
                GridEditableItem item = e.Item as GridEditableItem;

                Hashtable oHashTableNewValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(oHashTableNewValues, item);

                int iEmployeeID = Convert.ToInt32(oDataItem["EmployeeID"].Text);

                OpportunityEmployees AllOpportunityEmployees = GetOpportunityEmployees();
                OpportunityEmployee oOpportunityEmployee = AllOpportunityEmployees.Get(mOpportunityID, iEmployeeID);

                if (!oOpportunityEmployee.IsOwner)
                    AllOpportunityEmployees.Remove(oOpportunityEmployee);
                else
                    throw new Exception(CAN_NOT_DELETE_OPPORTUNITY_OWNER);

                if (mOpportunityID > 0)
                {
                    AllOpportunityEmployees.Save();
                }
                RadGrid_Employee.Rebind();
                e.Canceled = false;
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
                Session["currentOpportunityObject"] = null;
                e.Canceled = true;
            }
        }

        private void SaveOpportunityEmployees(OpportunityEmployee ClonedOpportunityEmployee,
                                     OpportunityEmployee UpdatedOpportunityEmployee,
                                     OpportunityEmployees AllOpportunityEmployees,
                                     GridCommandEventArgs e)
        {
            if (ClonedOpportunityEmployee.BrokenRulesCollection.Count == 0)
            {
                Csla.Data.DataMapper.Map(ClonedOpportunityEmployee, UpdatedOpportunityEmployee, "OpportunityID", "EmployeeID");
                AllOpportunityEmployees.ApplyEdit();
                Session["OpportunityEmployees"] = AllOpportunityEmployees.Save();
                RadGrid_Employee.Rebind();
                e.Canceled = false;
            }
            else
            {
                AllOpportunityEmployees.CancelEdit();
                RadGrid_Employee.Rebind();
                e.Canceled = true;
                XITingExceptionProcessor.ProcessException(this, ClonedOpportunityEmployee.BrokenRulesCollection.ToString());
            }
        }

        #endregion

        #endregion

        #region Common methods

        private void EnableDisableTabs()
        {
            int iOpportunityLocationID = 0;
            if (HiddenField_SiteAddress.Value != null && HiddenField_SiteAddress.Value != string.Empty)
                iOpportunityLocationID = int.Parse(HiddenField_SiteAddress.Value);
            if (mOpportunityID > 0)
            {
                Tab_Address.Enabled = true;
                if (IsOpportunityEmployee(mEmployeeID))
                {
                    Button_Save_OppLocations.Enabled = true;
                    Button_SameAsAbove.Enabled = true;
                }
                if (iOpportunityLocationID > 0)
                {
                    Tab_Contact.Enabled = true;
                    Tab_ContractInfo.Enabled = true;
                    Tab_ManageGroup.Enabled = true;
                    Tab_Terms.Enabled = true;
                    Tab_DocumentManagement.Enabled = true;
                    if (BillingPlan.CanGetObject())
                        Tab_BillingPlan.Enabled = true;

                }
                else
                {
                    Tab_Contact.Enabled = false;
                    Tab_BillingPlan.Enabled = false;
                    Tab_ContractInfo.Enabled = false;
                    Tab_ManageGroup.Enabled = false;
                    Tab_Terms.Enabled = false;
                    Tab_DocumentManagement.Enabled = false;
                }
            }
            else
            {
                Tab_Address.Enabled = false;
                Tab_Contact.Enabled = false;
                Tab_BillingPlan.Enabled = false;
                Tab_ContractInfo.Enabled = false;
                Tab_ManageGroup.Enabled = false;
                Tab_Terms.Enabled = false;
                Tab_DocumentManagement.Enabled = false;
            }

        }

        private void CreateNewOpportunityObject()
        {
            SetUIForNewOpportunity();

            mEmployeeID = UIHelper.GetLoggedInUserEmployeeID();
            HiddenField_EmployeeID.Value = mEmployeeID.ToString();

            Opportunities AllOpportunities = GetOpportunities();
            Opportunity AnOpportunity;

            AnOpportunity = AllOpportunities.AddNew(mOrganizationID);

            Session["OpportunityBeingEdited"] = AnOpportunity;
            Session["OpportunityStatusID"] = UIHelper.GetDefaultStatusID(mEntityID, mLanguageID, GlobalConstants.NEW_SALES_STATUS_TYPE).ToString();
            HiddenField_InitialLogin_StatusID.Value = Session["OpportunityStatusID"].ToString();
            AnOpportunity.StatusID = Convert.ToInt32(HiddenField_InitialLogin_StatusID.Value);


            HiddenField_OpportunityName.Value = BLANK;
            HiddenField_OpportunityID.Value = Convert.ToString(AnOpportunity.OpportunityID);
        }

        private void ShowOpportunityRefNo()
        {
            //ConfigurationParameterSettingInfoList oConfigurationParameterSettingInfoList;
            //oConfigurationParameterSettingInfoList = ConfigurationParameterSettingInfoList.GetConfigurationParameterSettings(mModuleId, ModuleHelper.GetConfigurationParameterIDForUserInterfaceCatagoryId());
            //ConfigurationParameterSettingInfo oOpportunityRefNo = oConfigurationParameterSettingInfoList.GetConfigurationParameterID(mMakingOpportunityNumberEditable);

            string ConfigSetting = ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_MAKE_OPPORTUNITY_NO_EDITABLE).ToString();

            if (ConfigSetting.ToLower() == "autogeneratenoneditable" || ConfigSetting.ToLower() == "generatebyaction")
            {
                Label_OpportunityNo.Visible = true;
                lbl_OpportunityNo.Visible = true;
                TextBox_OpportunityNo.Visible = false;
                lbl_OpportunityNo_Mandatory.Visible = false;
            }
            else
            {
                Label_OpportunityNo.Visible = true;
                lbl_OpportunityNo.Visible = false;
                TextBox_OpportunityNo.Visible = true;
                lbl_OpportunityNo_Mandatory.Visible = true;

                //if (ConfigSetting.ToLower() == "autogenerateeditable")
                //    if (string.IsNullOrEmpty(TextBox_OpportunityNo.Text))
                //        TextBox_OpportunityNo.Enabled = false;            
            }
        }

        private void SetUIForNewOpportunity()
        {
            TextBox_OpportunityStatusName.Text = UIHelper.GetDefaultStatus(mEntityID);
            TextBox_SiteName.Text = BLANK;
            TextBox_OpportunityNo.Text = "";
            lbl_OpportunityNo.Text = "Yet to be assigned";

            RadComboBox_OpportunityType.SelectedIndex = 0;
            RadComboBox_OpportunityCategory.SelectedIndex = 0;
            RadComboBox_FutureProspect.SelectedIndex = 0;
            // RadComboBox_ProfitCenter.SelectedIndex = 0;
            RadComboBox_CostCenter.SelectedIndex = 0;
            rcbSource.SelectedIndex = 0;

            Button_ViewStatusHistory.Enabled = false;
            Button_UploadDocument.Enabled = false;
            Button_OpportunityStatus.Enabled = false;
            LinkButton_Employee.Visible = false;
            Button_Save_OppLocations.Enabled = false;
            Button_SameAsAbove.Enabled = false;
            Button_Doc.Enabled = false;
            Button_Price.Enabled = false;
            btn_CompetitorDetails.Enabled = false;

            RadGrid_OpportunityNotes.Enabled = false;
            UnLockControls();
        }

        private void UnLockControls()
        {
            TextBox_SAddressLine1.Enabled = true;
            TextBox_SAddressLine2.Enabled = true;
            TextBox_SAddressLine3.Enabled = true;
            TextBox_SZipCode.Enabled = true;

            TextBox_BAddressLine1.Enabled = true;
            TextBox_BAddressLine2.Enabled = true;
            TextBox_BAddressLine3.Enabled = true;
            TextBox_BZipcode.Enabled = true;

            TextBox_TAddressLine1.Enabled = true;
            TextBox_TAddressLine2.Enabled = true;
            TextBox_TAddressLine3.Enabled = true;
            TextBox_TZipCode.Enabled = true;

            RadComboBox_SCityName.Enabled = true;
            RadComboBox_SCountryName.Enabled = true;
            RadComboBox_SStateName.Enabled = true;

            RadComboBox_BCityName.Enabled = true;
            RadComboBox_BCountryName.Enabled = true;
            RadComboBox_BStateName.Enabled = true;

            RadComboBox_TCityName.Enabled = true;
            RadComboBox_TCountryName.Enabled = true;
            RadComboBox_TStateName.Enabled = true;

            lbl_OpportunityNo.Enabled = true;
            RadComboBox_OpportunityCategory.Enabled = true;
            RadComboBox_OpportunityType.Enabled = true;
            RadComboBox_FutureProspect.Enabled = true;
            RadCombobox_MainCompetitor.Enabled = true;
            RadComboBox_CostCenter.Enabled = true;
            chkIsSaleForLocal.Enabled = true;
            // RadComboBox_ProfitCenter.Enabled = true;
            TextBox_SiteName.Enabled = true;

            DatePicker_ExpectedCompletionDate.Enabled = true;
            DatePicker_ContractStartDate.Enabled = true;
            DatePicker_ContractEndDate.Enabled = true;
            rcbSource.Enabled = true;

        }

        private void FillOpportunityDetailsInControls()
        {
            //Session["OpportunityBeingEdited"] = null;
            //Session["currentOpportunityObject"] = null;
            Opportunity oOpportunity = GetOpportunityBeingEdited();
            // OpportunityLocations OpportunityLocation = OpportunityLocations.GetOpportunityLocationOfLocationType(mOpportunityID, SITE_LOCATION_TYPE);
            if (oOpportunity != null)
            {
                mOrganizationID = oOpportunity.OrganizationID;
                HiddenField_OrganizationID.Value = mOrganizationID.ToString();

                TextBox_OpportunityNo.Text = oOpportunity.OpportunityNo;
                lbl_OpportunityNo.Text = oOpportunity.OpportunityNo;
                lblOpportunity_Status_value.Text = oOpportunity.StatusName;
                lblContract_No_value.Text = oOpportunity.ContractNo;
                lblOrganization_Value.Text = UIHelper.GetOrganizationName(oOpportunity.OrganizationID);
                Label_OpportunityName_Value.Text = oOpportunity.OpportunityName;
                Label_OpportunityNo_Header_Value.Text = oOpportunity.OpportunityNo;
                TextBox_SiteName.Text = oOpportunity.OpportunityName;

                SetOpportunityEmployee();
                lbl_CreatedDate.Text = oOpportunity.CreatedOn.ToString();
                TextBox_OpportunityStatusName.Text = oOpportunity.StatusName;

                Label_LastActivity.Text = EmployeeActivityDA.OpportunityLastActivity(mOpportunityID);
                FillCurrencyCombo();
                rcbCurrency.SelectedValue = oOpportunity.CurrencyID.ToString();

                // FillExchangeRateCombo();
                BindExchnageRateCombo(oOpportunity.ExchangeRateID);
                rcbExchangeRate.SelectedValue = oOpportunity.ExchangeRateID.ToString();
                if (oOpportunity.ExpectedClosingDate.Value.Year > 1980)
                    DatePicker_ExpectedCompletionDate.SelectedDate = oOpportunity.ExpectedClosingDate;
                Label_EsimatedPrice_Value.Text = oOpportunity.EstimatedPrice.ToString("N2");
                Label_QuotedPrice_Value.Text = oOpportunity.QuotedPrice.ToString("N2");
                Label_BillingAmount_Value.Text = oOpportunity.BillingAmount.ToString("N2");
                Label_BilledAmount_Value.Text = oOpportunity.BilledAmount.ToString("N2");

                //Label_EsimatedPrice_Value.Text = oOpportunity.EstimatedPrice.ToString("N0");
                //Label_QuotedPrice_Value.Text = oOpportunity.QuotedPrice.ToString("N0");
                //Label_BillingAmount_Value.Text = oOpportunity.BillingAmount.ToString("N0");
                //Label_BilledAmount_Value.Text = oOpportunity.BilledAmount.ToString("N0");
                HiddenField_OpportunityName.Value = TextBox_SiteName.Text;
                HiddenField_InitialLogin_StatusID.Value = Convert.ToString(oOpportunity.StatusID);
                RadComboBox_OpportunityType.SelectedValue = oOpportunity.OpportunityTypeID.ToString();
                RadComboBox_OpportunityCategory.SelectedValue = oOpportunity.OpportunityCategoryID.ToString();
                RadComboBox_FutureProspect.SelectedValue = oOpportunity.FutureProspectID.ToString();
                RadComboBox_CostCenter.SelectedValue = oOpportunity.CostCentreID.ToString();
                RadComboBox_CostCenter.Text = oOpportunity.CostCentreDescription.ToString();
                // RadComboBox_ProfitCenter.SelectedValue = oOpportunity.ProfitCentreID.ToString();
                rcbSalesType.SelectedValue = oOpportunity.SalesTypeID.ToString();
                HiddenField_SalesTypeID.Value = oOpportunity.SalesTypeID.ToString();
                Session["OpportunityStatusID"] = oOpportunity.StatusID.ToString();
                mOpportunityStatusID = oOpportunity.StatusID;
                rcbSource.SelectedValue = oOpportunity.OpportunitySourceID.ToString();
                chkIsSaleForLocal.Checked = oOpportunity.IsLocalSales;
                DatePicker_ContractStartDate.SelectedDate = oOpportunity.ContractStartDate;
                DatePicker_ContractEndDate.SelectedDate = oOpportunity.ContractEndDate;
                //SetValueOfControlsForSelectedLocation();
            }
        }

        private void SetValueOfControlsForSelectedLocation()
        {

            OpportunityLocations oOpportunityLocations = OpportunityLocations.GetOpportunityLocation(mOpportunityID);
            OpportunityLocation oOpportunityLocation = oOpportunityLocations.GetItem(mOpportunityID, SITE_LOCATION_TYPE);
            if (oOpportunityLocation != null)
            {
                SetValuesToOpportunitySiteAddress(oOpportunityLocation);
            }
            //else
            //    UIHelper.ShowMessage(this.Page, "Please enter Site Address at \"Address Info\" tab...");

            oOpportunityLocation = oOpportunityLocations.GetItem(mOpportunityID, BILLING_LOCATION_TYPE);
            if (oOpportunityLocation != null)
            {
                SetValuesToOpportunityBillingAddress(oOpportunityLocation);
            }
            oOpportunityLocation = oOpportunityLocations.GetItem(mOpportunityID, TEMPORARY_STORAGE_LOCATION_TYPE);
            if (oOpportunityLocation != null)
            {
                SetValuesToOpportunityStorageAddress(oOpportunityLocation);
            }
        }

        private Boolean IsOwner()
        {
            int EmployeeID = UIHelper.GetLoggedInUserEmployeeID();
            OpportunityEmployees AllOpportunityEmployees = GetOpportunityEmployees();

            if (AllOpportunityEmployees.Get(mOpportunityID, EmployeeID) == null)
                return false;
            else
                return AllOpportunityEmployees.Get(mOpportunityID, EmployeeID).IsOwner;

        }

        private void InitialiseDataMembers()
        {
            mEmployeeID = UIHelper.GetLoggedInUserEmployeeID();
            HiddenField_EmployeeID.Value = Convert.ToString(mEmployeeID);

            mEntityID = UIHelper.GetOpportunityStatusEntityID();
            HiddenField_OpportunityEntityID.Value = mEntityID.ToString();
            //if (mOpportunityID > 0 && Session["OpportunityBeingEdited"] != null && !string.IsNullOrEmpty(((Opportunity)Session["OpportunityBeingEdited"]).OpportunityNo))
            //{
            //    this.lbl_OpportunityNo.Text = ((Opportunity)Session["OpportunityBeingEdited"]).OpportunityNo;

            //    this.TextBox_OpportunityNo.Text = this.lbl_OpportunityNo.Text;
            //    Label_OpportunityNo_Header_Value.Text = lbl_OpportunityNo.Text;

            //    this.lbl_CreatedDate.Text = ((Opportunity)Session["OpportunityBeingEdited"]).CreatedOn.ToString();
            //}
            if (mOpportunityID > 0 && Session["OpportunityBeingEdited"] != null)
            {
                string OpportunityNo = OpportunityDA.GetOpportunityNo(mOpportunityID);
                string CountryAbbriviation = CountryDA.GetCountryAbbreviation(((Opportunity)Session["OpportunityBeingEdited"]).CountryID);
                if (!string.IsNullOrEmpty(OpportunityNo) && CountryAbbriviation != this.lbl_OpportunityNo.Text)
                {
                    this.lbl_OpportunityNo.Text = OpportunityNo;
                    this.TextBox_OpportunityNo.Text = this.lbl_OpportunityNo.Text;
                    Label_OpportunityNo_Header_Value.Text = lbl_OpportunityNo.Text;
                    lblOrganization_Value.Text = UIHelper.GetOrganizationName(((Opportunity)Session["OpportunityBeingEdited"]).OrganizationID);
                    lblContract_No_value.Text = ((Opportunity)Session["OpportunityBeingEdited"]).ContractNo;

                    ((Opportunity)Session["OpportunityBeingEdited"]).OpportunityNo = OpportunityNo;
                }
                this.lbl_CreatedDate.Text = ((Opportunity)Session["OpportunityBeingEdited"]).CreatedOn.ToString();
            }


        }

        private void EnableStatusChangeButton()
        {
            bool bIsOwner = true;
            if (mOpportunityID > 0)
            {
                if (Session["OpportunityStatusID"] != null)
                {
                    int UserID = UIHelper.GetUserIDOfLoggedInUser();

                    Opportunity oOpportunity = GetOpportunityBeingEdited();

                    //if (UIHelper.IsRestrictSalesPersonViewToSELFProject() && UIHelper.IsInSalesRepRole(UserID))
                    //{
                    //    int EmployeeID = UIHelper.GetLoggedInUserEmployeeID();

                    //    OpportunityEmployees AllOpportunityEmployees = GetOpportunityEmployees();
                    //    OpportunityEmployee oOpportunityEmployee = AllOpportunityEmployees.Get(mOrganizationID, mOpportunityID, EmployeeID);

                    //    if (oOpportunityEmployee != null)
                    //    {
                    //        if (!oOpportunityEmployee.IsOwner)
                    //        {
                    //            Button_OpportunityStatus.Enabled = false;
                    //            bIsOwner = false;
                    //        }
                    //    }
                    //}
                    if (bIsOwner)
                    {
                        StatusWorkFlowNameValue oStatusWorkFlowNameValue = StatusWorkFlowNameValue.GetNextStatuses(oOpportunity.StatusID, UserID);
                        if (oStatusWorkFlowNameValue.Count > 0 & IsOpportunityEmployee(mEmployeeID))
                            Button_OpportunityStatus.Enabled = true;
                        else
                            Button_OpportunityStatus.Enabled = false;
                    }
                }
                else
                    Button_OpportunityStatus.Enabled = false;
            }
            else
                Button_OpportunityStatus.Enabled = false;
        }

        private void ClearRequiredSessions()
        {
            Session["currentOpportunityObject"] = null;
            Session["OpportunityBeingEdited"] = null;
            Session["Lock Product"] = null;
            Session["Lock Opportunity"] = null;
            Session["Change Order"] = null;
            Session["Lock_Optional"] = null;
            Session["IsOpportunityEmployee"] = null;
        }

        #endregion

        #region Button Click

        protected void Button_Save_Click(object sender, EventArgs e)
        {
            Opportunities oOpportunities = GetOpportunities();
            try
            {
                IsReferenceDataAvailable();

                if (TextBox_OpportunityStatusName.Text.Trim() == string.Empty)
                {
                    throw new System.ApplicationException(ENTER_OPPORTUNITY_SATUS);
                }

                #region Save Opportunity

                if (oOpportunities != null)
                {
                    oOpportunities.BeginEdit();
                    Opportunity oOpportunity = (Opportunity)Session["OpportunityBeingEdited"];

                    this.lbl_OpportunityNo.Text = this.TextBox_OpportunityNo.Text.Trim();
                    DoSaveOpportunity(oOpportunities, oOpportunity);


                    this.lbl_OpportunityNo.Text = oOpportunity.OpportunityNo;

                    this.TextBox_OpportunityNo.Text = oOpportunity.OpportunityNo;
                    this.lbl_CreatedDate.Text = oOpportunity.CreatedOn.ToString();

                    // Save opportunity Employees
                    OpportunityEmployees AllOpportunityEmployees = GetOpportunityEmployees();

                    if (AllOpportunityEmployees != null)
                    {
                        OpportunityEmployee oOpportunityEmployee = AllOpportunityEmployees.Get(mOrganizationID, mOpportunityID, mEmployeeID);
                        if (AllOpportunityEmployees.Count == 0)
                        {
                            if (oOpportunityEmployee == null)
                            {
                                oOpportunityEmployee = AllOpportunityEmployees.AddNew();
                                oOpportunityEmployee.OrganizationID = mOrganizationID;
                                oOpportunityEmployee.OpportunityID = mOpportunityID;
                                oOpportunityEmployee.EmployeeID = mEmployeeID;
                                oOpportunityEmployee.IsOwner = true;
                                oOpportunityEmployee.IsActive = true;

                            }
                        }
                        AllOpportunityEmployees.Save();
                        SetOpportunityEmployee();
                    }

                    #region Save Opportunity Customers

                    OpportunityContacts oOpportunityContacts = (OpportunityContacts)Session["OpportunityContactsBeingEdited"];
                    if (oOpportunityContacts != null)
                    {
                        if (oOpportunityContacts.Count > 0)
                        {
                            if (oOpportunityContacts[0].OpportunityID <= 0)
                            {
                                foreach (OpportunityContact item in oOpportunityContacts)
                                {
                                    item.OpportunityID = mOpportunityID;
                                }
                            }
                        }
                    }
                    Session["OpportunityContactsBeingEdited"] = oOpportunityContacts.Save();

                    #endregion

                    #region Save Opportunity Employees

                    OpportunityEmployees oOpportunityEmployees = (OpportunityEmployees)Session["OpportunityEmployees"];
                    if (oOpportunityEmployees != null)
                    {
                        if (oOpportunityEmployees.Count > 0)
                        {
                            if (oOpportunityEmployees[0].OpportunityID <= 0)
                            {
                                foreach (OpportunityEmployee item in oOpportunityEmployees)
                                {
                                    item.OpportunityID = mOpportunityID;
                                }
                            }
                        }

                        Session["OpportunityEmployees"] = oOpportunityEmployees.Save();
                    }

                    RadGridHelper.UnmaskUpdateButtonColumn(RadGrid_Employee);
                    RadGridHelper.UnmaskDeleteButtonColumn(RadGrid_Employee);
                    #endregion

                    LinkButton_Employee.Visible = true;

                    #region Save Opportunity Locations

                    if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_DISPLAY_CUSTOMER_LOCATION_AS_OPPORTUNITY_ADDRESS).ToLower() == "yes")
                        SaveOpportunityLocations();
                    //else if(string.IsNullOrEmpty(HiddenField_SiteAddress.Value))
                    //    UIHelper.ShowMessage(this.Page, "Please enter Site Address at \"Address Info\" tab...");

                    #endregion

                    #region Save Default Opportunity T&C

                    if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_ADD_DEFAULT_TANDC).ToLower() == "yes")
                    {
                        OpportunityTermsAndConditions AllOpportunityTermsAndConditions = OpportunityTermsAndConditions.GetOpportunityTermsAndCondition(mOpportunityID);
                        if (AllOpportunityTermsAndConditions.Count == 0)
                        {
                            DataSet TCEntities = OpportunityDA.GetOpportuntyRef(mOrganizationID, STATUSTYPEID, mEntityID, 0);
                            //TermsAndConditionEntities AllTermsAndConditionEntities = TermsAndConditionEntities.GetDefaultTAndCEntity(mEntityID, int.Parse(HiddenField_SalesTypeID.Value));
                            if (TCEntities.Tables[0].Rows.Count > 0)
                            {
                                OpportunityTermsAndCondition AnOpportunityTermsAndCondition = AllOpportunityTermsAndConditions.AddNew();
                                Hashtable oTAndCHashtable = new Hashtable();
                                AnOpportunityTermsAndCondition.OpportunityID = mOpportunityID;
                                AnOpportunityTermsAndCondition.ProfitCenterID = 0;
                                AnOpportunityTermsAndCondition.TermsAndConditionDetailTypeID = Convert.ToInt32(TCEntities.Tables[0].Rows[0]["TermsAndConditionDetailTypeID"]);
                                AnOpportunityTermsAndCondition.TermsAndConditionID = Convert.ToInt32(TCEntities.Tables[0].Rows[0]["TermsAndConditionID"]);
                                AnOpportunityTermsAndCondition.TaxTypeID = TaxTypeDA.GetTaxTypeID(Convert.ToInt32(TCEntities.Tables[0].Rows[0]["TaxStructureID"]));
                                AnOpportunityTermsAndCondition.IsStandred = false;
                                AnOpportunityTermsAndCondition.IsActive = true;
                            }
                        }
                        AllOpportunityTermsAndConditions.Save();
                    }

                    #endregion

                    if (!IsOpportunityEmployee(mEmployeeID))
                    {
                        LockOpportunity();
                        LockControlsForNonEmployee();
                    }

                    rcbSalesType.Enabled = false;
                    Button_OpportunityStatus.Enabled = true;
                    Button_ViewStatusHistory.Enabled = true;
                    Button_UploadDocument.Enabled = true;
                    Button_Price.Enabled = true;
                    btn_CompetitorDetails.Enabled = true;
                }

                #endregion

            }
            catch (Exception ex)
            {
                oOpportunities.CancelEdit();
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void Button_Cancel_Click(object sender, EventArgs e)
        {

            Response.Redirect("ManageOpportunitiesDetermined.aspx");

        }

        protected void Button_Copy_Click(object sender, EventArgs e)
        {
            int iOpportunityID;

            try
            {
                if (RadGrid_OpportunityCustomerContacts_SoldToParty.SelectedItems.Count <= 0)
                {
                    throw new Exception("Please select Customer from SoldToParty");
                }
                else
                {
                    //if (GetOpportunityContactsForBillTo().Count > 0)
                    //{

                    //    throw new Exception("The Customer for BillToParty is already present.");

                    //}
                    //else
                    //{

                    foreach (GridDataItem item in RadGrid_OpportunityCustomerContacts_SoldToParty.SelectedItems)
                    {
                        if (mOpportunityID < 0)
                            iOpportunityID = 0;
                        else
                            iOpportunityID = mOpportunityID;
                        OpportunityContact oOpportunityContact = GetOpportunityContacts().Get(iOpportunityID, Convert.ToInt32(item["CustomerID"].Text), Convert.ToInt32(item["CustomerContactID"].Text));
                        //oOpportunityContact.IsActive = true;
                        oOpportunityContact.IsBillTo = true;
                        //oOpportunityContact.AttentionTo = true;
                        //   Session["OpportunityContactsBeingEdited"] = GetOpportunityContacts();


                    }
                    //}
                }
                // save Customer
                OpportunityContacts oOpportunityContacts = (OpportunityContacts)Session["OpportunityContactsBeingEdited"];
                if (oOpportunityContacts != null)
                {
                    if (oOpportunityContacts.Count > 0)
                    {
                        if (oOpportunityContacts[0].OpportunityID <= 0)
                        {
                            foreach (OpportunityContact item in oOpportunityContacts)
                            {
                                item.OpportunityID = mOpportunityID;
                                //item.AttentionTo = true;
                            }
                        }
                    }
                }
                Session["OpportunityContactsBeingEdited"] = oOpportunityContacts.Save();

                RadGrid_OpportunityCustomerContacts_SoldToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void Button_Copy_ShipTo_Click(object sender, EventArgs e)
        {
            int iOpportunityID;

            try
            {
                if (RadGrid_OpportunityCustomerContacts_BillToParty.SelectedItems.Count <= 0)
                {
                    throw new Exception("Please select Customer from BillToParty");
                }
                else
                {
                    if (GetOpportunityContactsForShipTo().Count > 0)
                    {

                        throw new Exception("The Customer for ShipToParty is already present.");

                    }
                    else
                    {

                        foreach (GridDataItem item in RadGrid_OpportunityCustomerContacts_BillToParty.SelectedItems)
                        {
                            if (mOpportunityID < 0)
                                iOpportunityID = 0;
                            else
                                iOpportunityID = mOpportunityID;
                            OpportunityContact oOpportunityContact = GetOpportunityContacts().Get(iOpportunityID, Convert.ToInt32(item["CustomerID"].Text), Convert.ToInt32(item["CustomerContactID"].Text));
                            oOpportunityContact.IsActive = true;
                            oOpportunityContact.IsShipTo = true;
                            //  Session["OpportunityContactsBeingEdited"] = GetOpportunityContacts();

                        }
                    }
                }
                // save Customer
                OpportunityContacts oOpportunityContacts = (OpportunityContacts)Session["OpportunityContactsBeingEdited"];
                if (oOpportunityContacts != null)
                {
                    if (oOpportunityContacts.Count > 0)
                    {
                        if (oOpportunityContacts[0].OpportunityID <= 0)
                        {
                            foreach (OpportunityContact item in oOpportunityContacts)
                            {
                                item.OpportunityID = mOpportunityID;
                            }
                        }
                    }
                }
                Session["OpportunityContactsBeingEdited"] = oOpportunityContacts.Save();

                RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
                RadGrid_OpportunityCustomerContacts_ShipToParty.Rebind();
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
            }
        }

        protected void Button_Document_Click(object sender, EventArgs e)
        {
            string strScript;
            string url;
            if (GenerateOpportunityLevelDocument())
                url = "ManageGeneratedDocuments.aspx?InformationContentType=Opportunity&SalesTypeID=" + HiddenField_SalesTypeID.Value;
            else
                url = "ManageGroupLevelGeneratedDocument.aspx?InformationContentType=Opportunity&SalesTypeID=" + HiddenField_SalesTypeID.Value;
            strScript = "javascript:window.showModalDialog(\"" + url + "\",'','dialogWidth:850px;dialogHeight:600px;status:no;help:no;scroll:yes;center:yes');";
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Button_GenerateDocuments", strScript, true);
        }

        protected void Button_InvoiceDoc_Click(object sender, EventArgs e)
        {
            DataTable dt;
            string strScript;
            string url, EntityKey = string.Empty, opportunityID = string.Empty;
            int EntityID = UIHelper.GetOpportunityStatusEntityID();

            // organizationID = UIHelper.GetCurrentUsersOrganizationId();
            // EntityID = UIHelper.GetOpportunityStatusEntityID();
            dt = StatusEntityDA.GetStatusEntityDataKey(EntityID);

            if (dt.Rows.Count > 0)
                EntityKey = dt.Rows[0]["DataKey"].ToString();

            if (EntityID == OPPORTUNITY_STATUSENTITY_ID && EntityKey.ToLower() == OPPORTUNITY_STATUSENTITY_DATAKEY.ToLower())
            {
                if (!string.IsNullOrEmpty(Request.QueryString["OpportunityID"].ToString()))
                    opportunityID = Request.QueryString["OpportunityID"].ToString();
            }


            url = "ManageDocumentData.aspx?OrganizationID=" + mOrganizationID.ToString() + "&EntityID=" + EntityID.ToString() + "&" + EntityKey + "=" + opportunityID;

            strScript = "javascript:window.showModalDialog(\"" + url + "\",'','dialogWidth:1000px;dialogHeight:600px;status:no;help:no;scroll:yes;center:yes');";
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Button_InvoiceDoc", strScript, true);
        }

        protected void Button_SameAsAbove_OnClick(object sender, EventArgs e)
        {
            TextBox_BAddressLine1.Text = TextBox_SAddressLine1.Text;
            TextBox_BAddressLine2.Text = TextBox_SAddressLine2.Text;
            TextBox_BAddressLine3.Text = TextBox_SAddressLine3.Text;
            TextBox_BZipcode.Text = TextBox_SZipCode.Text;
            TextBox_BTelephoneNo.Text = TextBox_STelephoneNo.Text;
            RadComboBox_BCountryName.SelectedValue = RadComboBox_SCountryName.SelectedValue;
            RadComboBox_BStateName.Items.Clear();
            FillBillingAddStates();
            RadComboBox_BStateName.SelectedValue = RadComboBox_SStateName.SelectedValue;
            RadComboBox_BCityName.Items.Clear();
            FillBillingAddCities();
            RadComboBox_BCityName.SelectedValue = RadComboBox_SCityName.SelectedValue;

        }

        protected void Button_Save_OppLocations_OnClick(object sender, EventArgs e)
        {
            try
            {
                SaveOpportunityLocations();

                #region Set Location For New City

                if (TextBox_SCity.Visible == true || TextBox_BCity.Visible == true || TextBox_TCity.Visible == true)
                {
                    TextBox_SCity.Text = BLANK;
                    TextBox_SCity.Visible = false;
                    TextBox_BCity.Text = BLANK;
                    TextBox_BCity.Visible = false;
                    TextBox_TCity.Text = BLANK;
                    TextBox_TCity.Visible = false;
                    InitializeLocationRadComboBox();
                    SetValueOfControlsForSelectedLocation();
                }

                #endregion
            }
            catch (Exception Ex)
            {
                XITingExceptionProcessor.ProcessException(this, Ex);

            }

        }

        protected void Button_Activities_Click(object sender, EventArgs e)
        {
            MultiView_BasicInfo.ActiveViewIndex++;
            ApplyAuthorizationRulesForEmployeeACtivity();
            RadGrid_EmployeeActivityList.Rebind();
        }

        protected void Button_Back_Click(object sender, EventArgs e)
        {
            MultiView_BasicInfo.ActiveViewIndex--;
        }

        //protected void Button_GenerateOpportunityData_Click(object sender, EventArgs e)
        //{
        //    try
        //    {


        //        if (HiddenField_OpportunityID.Value != null)
        //        {                
        //            mOpportunityID = int.Parse(HiddenField_OpportunityID.Value);
        //            OpportunityDA.GenerateTKEAEstimateSet(mOpportunityID);

        //        }
        //    }
        //    catch (Exception oException)
        //    {
        //        XITingExceptionProcessor.ProcessException(this, oException);

        //    }
        //}

        protected void Button_ExportOpportunityData_Click(object sender, EventArgs e)
        {
            try
            {
                if (HiddenField_OpportunityID.Value != null)
                {
                    StringBuilder SB = new StringBuilder();
                    mOpportunityID = int.Parse(HiddenField_OpportunityID.Value);

                    Opportunities AllOpportunities = GetOpportunities();
                    Opportunity AnOpportunity = AllOpportunities.GetItem(mOpportunityID);

                    OpportunityDA.GenerateTKEAEstimateSet(mOpportunityID);

                    ApplicationDirectoryTypeInfoList oApplicationDirectoryTypeInfoList = ApplicationDirectoryTypeInfoList.GetAllApplicationDirectories();
                    ApplicationDirectoryTypeInfo oApplicationDirectoryTypeInfo = oApplicationDirectoryTypeInfoList.GetItem(33);

                    string directoryPath = oApplicationDirectoryTypeInfo.ApplicationDirectoryFQN;


                    string fullpath = AppDomain.CurrentDomain.BaseDirectory + directoryPath.Substring(directoryPath.IndexOf("/") + 1);

                    SB.Append("Following excels are generated successfully in folder " + fullpath + "...\r\n\r\n");

                    SB.Append("1.  " + this.generateEstimateFile(fullpath, AnOpportunity.OpportunityID, AnOpportunity.OpportunityName) + "\r\n");

                    SB.Append("2.  " + this.generateJobsExportFile(fullpath, AnOpportunity.OpportunityID, AnOpportunity.OpportunityName) + "\r\n");

                    SB.Append("3.  " + this.generateCompanyExportData(fullpath, AnOpportunity.OpportunityID, AnOpportunity.OpportunityName) + "\r\n");

                    UIHelper.ShowMessage(this, SB.ToString());
                }
            }
            catch (Exception oException)
            {
                XITingExceptionProcessor.ProcessException(this, oException);
            }
        }


        #region Estimate Excel

        private string generateEstimateFile(string path, int opportunityID, string opportunityName)
        {
            DataTable estimateDataTable = OpportunityDA.GetTKEAEstimateSetForOpprtunity(opportunityID);

            path = path.Replace(@"/", @"\");
            string filePath = path.EndsWith(@"\") ? path : path + @"\";

            string filePrefix = "EstimateSet_" + opportunityID.ToString() + "_" + opportunityName + "_Rev";
            string extension = ".xls";

            string newFileName = getNextFileName(filePath, filePrefix, extension);

            string newFileNameWithPath = filePath + newFileName;

            Utilities.ExportDataToExcel(estimateDataTable, newFileNameWithPath);

            UploadedEntityDocumentsDA.AddUploadedEntityDocument(mEntityID, opportunityID, 0, newFileName, newFileName, @"TKEAEstimateSet\" + newFileName, 7, true, Csla.ApplicationContext.User.Identity.Name, "CreateTKEAEstimateSet");
            return newFileName;
        }
        #endregion

        #region Jobs Excel

        private string generateJobsExportFile(string path, int opportunityID, string opportunityName)
        {
            DataTable jobsDataTable = OpportunityDA.GetTKEJobsExportForOpprtunity(opportunityID);

            path = path.Replace(@"/", @"\");
            string filePath = path.EndsWith(@"\") ? path : path + @"\";

            string filePrefix = "Jobs_" + mOpportunityID.ToString() + "_" + opportunityName + "_Rev";
            string extension = ".xls";

            string newFileName = getNextFileName(filePath, filePrefix, extension);

            string newFileNameWithPath = filePath + newFileName;

            Utilities.ExportDataToExcel(jobsDataTable, newFileNameWithPath);

            UploadedEntityDocumentsDA.AddUploadedEntityDocument(mEntityID, opportunityID, 0, newFileName, newFileName, @"TKEAEstimateSet\" + newFileName, 7, true, Csla.ApplicationContext.User.Identity.Name, "CreateTKEAEstimateSet");

            return newFileName;
        }
        #endregion

        #region Company Excel

        private string generateCompanyExportData(string path, int opportunityID, string opportunityName)
        {
            DataTable companyDataTable = OpportunityDA.GetTKECompanyDataExportForOpprtunity(mOpportunityID);

            path = path.Replace(@"/", @"\");
            string filePath = path.EndsWith(@"\") ? path : path + @"\";

            string filePrefix = "Company_" + opportunityID.ToString() + "_" + opportunityName + "_Rev";
            string extension = ".xls";

            string newFileName = getNextFileName(filePath, filePrefix, extension);

            string newFileNameWithPath = filePath + newFileName;

            Utilities.ExportDataToExcel(companyDataTable, newFileNameWithPath);

            UploadedEntityDocumentsDA.AddUploadedEntityDocument(mEntityID, opportunityID, 0, newFileName, newFileName, @"TKEAEstimateSet\" + newFileName, 7, true, Csla.ApplicationContext.User.Identity.Name, "CreateTKEAEstimateSet");

            return newFileName;
        }

        #endregion

        private string getNextFileName(string filePath, string filePrefix, string extension)
        {
            string searchPattern = filePrefix + "*" + extension;
            int lastRevNo = 1;
            //Get the existing files with matching names
            string[] filesList = Directory.GetFiles(filePath, searchPattern, SearchOption.TopDirectoryOnly);
            if (filesList.Length > 0)
            {
                Array.Sort(filesList);

                string lastFileName = filesList[filesList.Length - 1];
                int.TryParse(lastFileName.Replace(filePath + filePrefix, "").Replace(extension, ""), out lastRevNo);
                lastRevNo += 1;
            }
            string newFileName = filePrefix + lastRevNo.ToString("000000") + extension;
            return newFileName;
        }

        #endregion

        # region report

        public void OpenWindow(System.Web.UI.Page ObjPage, string strMsg, string strKey, string url)
        {
            string strScript;

            Type jsType = ObjPage.GetType();
            ClientScriptManager CS = ObjPage.ClientScript;

            strScript = "window.open(" + "\"" + url + "\"" + ")";
            System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "Button_CustomerReport", strScript, true);
        }

        #endregion

        #region Set Controls Values

        private void SetOpportunityID()
        {
            if (Request.QueryString["OpportunityName"] != null && Request.QueryString["OpportunityName"].ToString() != "")
                mOpportunityID = GetOpportunityID(mOrganizationID, Request.QueryString["OpportunityName"].ToString());
        }

        #endregion

        # region Common Methods

        private void DoSaveOpportunity(Opportunities oOpportunities, Opportunity oOpportunity)
        {
            // Update changed fields in opportunity       
            if (RadComboBox_SCountryName.SelectedValue == null)
                oOpportunity.CountryID = 0;
            else
                oOpportunity.CountryID = int.Parse(RadComboBox_SCountryName.SelectedValue);

            if (TextBox_OpportunityNo.Visible)
            {
                string str = ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_MAKE_OPPORTUNITY_NO_EDITABLE).ToLower();
                if (String.IsNullOrEmpty(TextBox_OpportunityNo.Text.Trim()) && ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_MAKE_OPPORTUNITY_NO_EDITABLE).ToLower() != "autogenerateeditable")
                {
                    throw new Exception(ENTER_OPPORTUNITY_NO);
                }
                else if (oOpportunity.OpportunityNo != null && TextBox_OpportunityNo.Text.Trim() == "")
                {
                    throw new Exception(ENTER_OPPORTUNITY_NO);
                }
                else
                {
                    if (OpportunityDA.IsOpportunityNoExist(TextBox_OpportunityNo.Text.Trim(), oOpportunity.OpportunityID) && TextBox_OpportunityNo.Text.Trim() != "")
                        throw new Exception(OPPORTUNITY_NO_EXIST);
                    else
                        oOpportunity.OpportunityNo = TextBox_OpportunityNo.Text;
                }
            }
            else
                oOpportunity.OpportunityNo = lbl_OpportunityNo.Text;

            if (string.IsNullOrEmpty(TextBox_SiteName.Text.Trim()))
                throw new Exception("Please enter Site Name");

            String iAddedOnDate = oOpportunity.CreatedOn.ToString();
            String iExpectedCompletionDate;
            if (string.IsNullOrEmpty(iAddedOnDate))
                iAddedOnDate = DateTime.Today.ToString();

            if (DatePicker_ExpectedCompletionDate.SelectedDate.ToString() == BLANK)
                throw new System.ApplicationException(ENTER_Expected_Completion_Date);
            else
                iExpectedCompletionDate = DatePicker_ExpectedCompletionDate.SelectedDate.ToString();

            if (DateTime.Compare(DateTime.Parse(iExpectedCompletionDate), DateTime.Parse(iAddedOnDate)) < 0)
                throw new Exception(EXPECTED_CLOSING_DATE_NOT_VALID);

            //if (DatePicker_ContractStartDate.SelectedDate.ToString() == BLANK || DatePicker_ContractEndDate.SelectedDate.ToString() == BLANK)
            //    throw new System.ApplicationException("please enter Contract start date & Contract end date.");

            if (RadComboBox_OpportunityCategory.SelectedValue.ToString() == "0")
                throw new Exception("please select Opportunity Category.");

            if (((string.IsNullOrEmpty(RadComboBox_CostCenter.SelectedValue)) || RadComboBox_CostCenter.SelectedValue == "0") && RadComboBox_CostCenter.Visible == true)
                throw new Exception("please select cost center.");

            oOpportunity.OpportunityAbbreviation = BLANK;
            oOpportunity.OpportunityName = TextBox_SiteName.Text;

            oOpportunity.ExpectedClosingDate = DatePicker_ExpectedCompletionDate.SelectedDate;

            oOpportunity.ContractStartDate = DatePicker_ContractStartDate.SelectedDate;
            oOpportunity.ContractEndDate = DatePicker_ContractEndDate.SelectedDate;
            if (!string.IsNullOrEmpty(RadComboBox_CostCenter.SelectedValue))
                oOpportunity.CostCentreID = Convert.ToInt32(RadComboBox_CostCenter.SelectedValue);
            oOpportunity.CostCentreDescription = RadComboBox_CostCenter.Text;

            oOpportunity.OpportunityTypeID = Convert.ToInt32(RadComboBox_OpportunityType.SelectedValue);
            oOpportunity.OpportunityCategoryID = Convert.ToInt32(RadComboBox_OpportunityCategory.SelectedValue);
            oOpportunity.FutureProspectID = Convert.ToInt32(RadComboBox_FutureProspect.SelectedValue);
            // oOpportunity.ProfitCentreID = int.Parse(RadComboBox_ProfitCenter.SelectedValue);
            oOpportunity.IsActive = true;
            oOpportunity.IsLocalSales = chkIsSaleForLocal.Checked;
            oOpportunity.CurrencyID = Convert.ToInt32(rcbCurrency.SelectedValue);
            oOpportunity.SalesTypeID = Convert.ToInt32(rcbSalesType.SelectedValue);
            HiddenField_SalesTypeID.Value = rcbSalesType.SelectedValue.ToString();

            oOpportunity.SalesTypeName = rcbSalesType.Text;
            if (!string.IsNullOrEmpty(rcbExchangeRate.SelectedValue))
                oOpportunity.ExchangeRateID = Convert.ToInt32(rcbExchangeRate.SelectedValue);
            oOpportunity.StatusID = Convert.ToInt32(HiddenField_InitialLogin_StatusID.Value);
            oOpportunity.OwnerEmployeeID = mEmployeeID;
            oOpportunity.TermsAndConditionID = 34;
            if (rcbSource.SelectedIndex == 0)
                rcbSource.SelectedIndex = 1;
            else
                oOpportunity.OpportunitySourceID = Convert.ToInt32(rcbSource.SelectedValue);

            oOpportunity.LocationID = 3;
            oOpportunity.LocationTypeID = SITE_LOCATION_TYPE;

            //Save Opportunity address details

            // Save data in the database.
            if (oOpportunity.BrokenRulesCollection.Count == 0)
            {
                oOpportunities.ApplyEdit();

                Opportunity AnOpportunity = oOpportunities.GetItem(oOpportunity.OpportunityID);

                // From the  hash table map all the data excluding Opportunity id .
                // to the clone object Opportunity.
                Csla.Data.DataMapper.Map(oOpportunity, AnOpportunity, "OpportunityID", "OrganizationID", "Margin", "MinimumPrice", "MaxDiscount", "ActualQuotedPrice");
                Session["currentOpportunityObject"] = oOpportunities.Save();

                Session["OpportunityBeingEdited"] = oOpportunity = AnOpportunity;
                Session["OpportunityStatusID"] = AnOpportunity.StatusID;
                mOpportunityID = AnOpportunity.OpportunityID;
                HiddenField_OpportunityID.Value = mOpportunityID.ToString();
                RadGrid_OpportunityNotes.Enabled = true;

                oOpportunities = GetOpportunities();
                Session["OpportunityBeingEdited"] = oOpportunities[0];

                lbl_CreatedDate.Text = oOpportunities[0].CreatedOn.ToString();
                Label_OpportunityName_Value.Text = oOpportunities[0].OpportunityName;
                HiddenField_OpportunityName.Value = Label_OpportunityName_Value.Text;
                Label_OpportunityNo_Header_Value.Text = oOpportunities[0].OpportunityNo;
                lblOrganization_Value.Text = UIHelper.GetOrganizationName(oOpportunities[0].OrganizationID);
                StatusInfoList AllStatusInfoList = StatusInfoList.GetStatusInfoList(oOpportunities[0].StatusID, mLanguageID);
                lblOpportunity_Status_value.Text = AllStatusInfoList.GetItem(oOpportunities[0].StatusID).StatusName;

                EnableDisableTabs();
            }
            else
            {
                oOpportunities.CancelEdit();
                throw new Exception(oOpportunity.BrokenRulesCollection.ToString());
                //  XITingExceptionProcessor.ProcessException(this, oOpportunity.BrokenRulesCollection.ToString());
            }

            #region Save Opportunity Competitors

            int iStart = 1;
            if (RadCombobox_MainCompetitor.Text != string.Empty)
            {
                HiddenField_CompetitorIDs.Value = BLANK;
                LoadCompetitorCombo();
                string[] CompetitorNames = RadCombobox_MainCompetitor.Text.Split(',');
                //CheckBox chk1 = (CheckBox)RadCombobox_MainCompetitor.Items[0].FindControl("chk1");        
                for (int i = 0; i < CompetitorNames.Length; i++)
                {
                    DataRow[] rows = oCompetitorsTable.Select("ProductManufacturerName = '" + CompetitorNames[i] + "'", "ProductManufacturerID");
                    HiddenField_CompetitorIDs.Value += "," + rows[0]["ProductManufacturerID"].ToString();
                }

                CompetitorIDs = HiddenField_CompetitorIDs.Value.Split(',');
            }
            else
            {
                HiddenField_CompetitorIDs.Value = BLANK;
                CompetitorIDs = HiddenField_CompetitorIDs.Value.Split(',');
            }

            OpportunityCompetitors AllOpportunityCompetitors = OpportunityCompetitors.GetOpportunityCompetitors(mOpportunityID);
            ArrayList ObjectsToBeKeep = new ArrayList();
            ArrayList ObjectsToBeRemoved = new ArrayList();

            for (int i = iStart; i < CompetitorIDs.Length; i++)
            {
                if (AllOpportunityCompetitors.Count == 0)
                {
                    OpportunityCompetitor AnOpportunityCompetitor = AllOpportunityCompetitors.AddNew();
                    AnOpportunityCompetitor.OpportunityID = mOpportunityID;
                    AnOpportunityCompetitor.CompetitorID = Convert.ToInt32(CompetitorIDs[i]);
                    AnOpportunityCompetitor.IsActive = true;
                    ObjectsToBeKeep.Add(Convert.ToInt32(CompetitorIDs[i]));
                }
                else
                {
                    OpportunityCompetitor AnOpportunityCompetitor = AllOpportunityCompetitors.GetItem(mOpportunityID, Convert.ToInt32(CompetitorIDs[i]));

                    if (AnOpportunityCompetitor == null)
                    {
                        OpportunityCompetitor oOpportunityCompetitor = AllOpportunityCompetitors.AddNew();
                        oOpportunityCompetitor.OpportunityID = mOpportunityID;
                        oOpportunityCompetitor.CompetitorID = Convert.ToInt32(CompetitorIDs[i]);
                        oOpportunityCompetitor.IsActive = true;

                        ObjectsToBeKeep.Add(Convert.ToInt32(CompetitorIDs[i]));
                    }
                    else
                    {
                        AnOpportunityCompetitor.OpportunityID = mOpportunityID;
                        AnOpportunityCompetitor.CompetitorID = Convert.ToInt32(CompetitorIDs[i]);
                        AnOpportunityCompetitor.IsActive = true;

                        ObjectsToBeKeep.Add(Convert.ToInt32(CompetitorIDs[i]));
                    }

                }


            }

            bool TempFlag = false;

            foreach (OpportunityCompetitor Olditem in AllOpportunityCompetitors)
            {
                foreach (int CompetitorID in ObjectsToBeKeep)
                {
                    if (Olditem.CompetitorID == CompetitorID)
                    {
                        //AllOpportunityCompetitors.Remove(Olditem);
                        TempFlag = true;
                    }
                }

                if (TempFlag == false)
                {
                    ObjectsToBeRemoved.Add(Olditem);
                }
                TempFlag = false;
            }

            foreach (OpportunityCompetitor AnOpportunityCompetitor in ObjectsToBeRemoved)
            {
                AllOpportunityCompetitors.Remove(AnOpportunityCompetitor);
            }

            AllOpportunityCompetitors.Save();


            #endregion

        }

        private bool IsOpportunityEmployee(int EmployeeID)
        {
            bool IsOpportunityEmployee;
            OpportunityEmployees oOpportunityEmployees = GetOpportunityEmployees();
            IsOpportunityEmployee = oOpportunityEmployees.IsOpportunityEmployee(mOpportunityID, mEmployeeID);
            Session["IsOpportunityEmployee"] = IsOpportunityEmployee;
            return IsOpportunityEmployee;
        }

        private void SaveOpportunityLocations()
        {
            OpportunityLocations AllOpportunityLocation = OpportunityLocations.GetOpportunityLocation(mOpportunityID);

            if (TextBox_SAddressLine1.Text == BLANK)
                throw new Exception("Please Enter Site Address");
            else if (RadComboBox_SCountryName.SelectedValue == null)
                throw new Exception("Please Enter Country");
            else if (RadComboBox_SStateName.SelectedValue == null)
                throw new Exception("Please Enter State");
            else if (RadComboBox_SCityName.SelectedValue == null)
                throw new Exception(ENTER_CITY);
            else
            {
                Save_Site_Address(AllOpportunityLocation);

                if (!string.IsNullOrEmpty(TextBox_BAddressLine1.Text))
                    Save_Billing_Address(AllOpportunityLocation);

                if (!string.IsNullOrEmpty(TextBox_TAddressLine1.Text))
                    Save_Storage_Address(AllOpportunityLocation);

                // AllOpportunityLocation.Save();
            }

            //  Button_Save_OppLocations.Enabled = true;
            //  Button_SameAsAbove.Enabled = true;
        }

        private void Save_Site_Address(OpportunityLocations AllOpportunityLocation)
        {
            OpportunityLocation AnOpportunityLocation = AllOpportunityLocation.GetItem(mOpportunityID, SITE_LOCATION_TYPE);

            if (AnOpportunityLocation == null)
            {
                OpportunityLocation OpportunityLocation = AllOpportunityLocation.AddNew();
                PopulateLocationValuesFromControls(OpportunityLocation, SITE_LOCATION_TYPE);

                OpportunityLocation.LocationTypeID = SITE_LOCATION_TYPE;
                OpportunityLocation.OpportunityID = mOpportunityID;

                AllOpportunityLocation.Save();
                HiddenField_SiteAddress.Value = OpportunityLocation.OpportunityLocationID.ToString();
            }
            else
            {
                PopulateLocationValuesFromControls(AnOpportunityLocation, SITE_LOCATION_TYPE);
                AllOpportunityLocation.Save();
                HiddenField_SiteAddress.Value = AnOpportunityLocation.OpportunityLocationID.ToString();
            }
            EnableDisableTabs();
        }

        private void Save_Billing_Address(OpportunityLocations AllOpportunityLocation)
        {
            OpportunityLocation AnOpportunityLocation = AllOpportunityLocation.GetItem(mOpportunityID, BILLING_LOCATION_TYPE);
            if (AnOpportunityLocation == null)
            {
                OpportunityLocation OpportunityLocation = AllOpportunityLocation.AddNew();
                PopulateLocationValuesFromControls(OpportunityLocation, BILLING_LOCATION_TYPE);

                OpportunityLocation.LocationTypeID = BILLING_LOCATION_TYPE;
                OpportunityLocation.OpportunityID = mOpportunityID;

                AllOpportunityLocation.Save();
                HiddenField_BillingAddress.Value = OpportunityLocation.OpportunityLocationID.ToString();
            }
            else
            {
                PopulateLocationValuesFromControls(AnOpportunityLocation, BILLING_LOCATION_TYPE);
                AllOpportunityLocation.Save();
                HiddenField_BillingAddress.Value = AnOpportunityLocation.OpportunityLocationID.ToString();
            }
        }

        private void Save_Storage_Address(OpportunityLocations AllOpportunityLocation)
        {
            OpportunityLocation AnOpportunityLocation = AllOpportunityLocation.GetItem(mOpportunityID, TEMPORARY_STORAGE_LOCATION_TYPE);
            if (AnOpportunityLocation == null)
            {
                OpportunityLocation OpportunityLocation = AllOpportunityLocation.AddNew();
                PopulateLocationValuesFromControls(OpportunityLocation, TEMPORARY_STORAGE_LOCATION_TYPE);

                OpportunityLocation.LocationTypeID = TEMPORARY_STORAGE_LOCATION_TYPE;
                OpportunityLocation.OpportunityID = mOpportunityID;

                AllOpportunityLocation.Save();
                HiddenField_TemporaryStorage.Value = OpportunityLocation.OpportunityLocationID.ToString();
            }
            else
            {
                PopulateLocationValuesFromControls(AnOpportunityLocation, TEMPORARY_STORAGE_LOCATION_TYPE);
                AllOpportunityLocation.Save();
                HiddenField_TemporaryStorage.Value = AnOpportunityLocation.OpportunityLocationID.ToString();
            }
        }

        private Boolean DoesCityAlreadyExistForInsert(int iCountryID, int iStateID, string sCityName)
        {
            //Check whether City Name is already exists for CityID And OrganizationID If Yes Then
            //Return True And Cancel Insert.
            Cities oCities = GetCities(iCountryID, iStateID);
            for (int iCounter = 0; iCounter < oCities.Count; iCounter++)
                if (oCities[iCounter].CityName.Trim().ToLower() == sCityName.Trim().ToLower())
                    return true;
            return false;
        }

        private void LockOpportunity()
        {
            Session["Lock Opportunity"] = true;
            Button_OpportunityStatus.Enabled = false;
            Button_Save_Top.Enabled = false;
            //edited on 06/01/2014 for enabling Add or delete EMployee even after the project Release
            //LinkButton_Employee.Visible = false;
            //edit ended here
            //LinkButton_BillTo_AddNew.Visible = false;
            //LinkButton_SoldTo_AddNew.Visible = false;
            //LinkButton_ShipTo_AddNew.Visible = false;


            //RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
            //RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
            //RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);

            //edited on 06/01/2014 for enabling Add or delete EMployee even after the project Release
            //RadGridHelper.MaskUpdateButtonColumn(RadGrid_Employee);

            //RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
            //RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
            //RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);

            //edited on 06/01/2014 for enabling Add or delete EMployee even after the project Release
            //RadGridHelper.MaskDeleteButtonColumn(RadGrid_Employee);


            //RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();

            //Lock Buttins from Location Tab
            Button_SameAsAbove.Enabled = false;
            Button_Save_OppLocations.Enabled = false;

            // Hide Revised hyperlink column from Products Grid


            LockControls();
        }

        private void LockControls()
        {

            TextBox_SAddressLine1.Enabled = false;
            TextBox_SAddressLine2.Enabled = false;
            TextBox_SAddressLine3.Enabled = false;
            TextBox_SZipCode.Enabled = false;
            TextBox_STelephoneNo.Enabled = false;


            TextBox_BAddressLine1.Enabled = false;
            TextBox_BAddressLine2.Enabled = false;
            TextBox_BAddressLine3.Enabled = false;
            TextBox_BZipcode.Enabled = false;
            TextBox_BTelephoneNo.Enabled = false;

            TextBox_TAddressLine1.Enabled = false;
            TextBox_TAddressLine2.Enabled = false;
            TextBox_TAddressLine3.Enabled = false;
            TextBox_TZipCode.Enabled = false;
            TextBox_TTelephoneNo.Enabled = false;

            RadComboBox_SCityName.Enabled = false;
            RadComboBox_SCountryName.Enabled = false;
            RadComboBox_SStateName.Enabled = false;

            RadComboBox_BCityName.Enabled = false;
            RadComboBox_BCountryName.Enabled = false;
            RadComboBox_BStateName.Enabled = false;

            RadComboBox_TCityName.Enabled = false;
            RadComboBox_TCountryName.Enabled = false;
            RadComboBox_TStateName.Enabled = false;


            RadComboBox_OpportunityCategory.Enabled = false;
            RadComboBox_OpportunityType.Enabled = false;
            RadComboBox_FutureProspect.Enabled = false;
            RadCombobox_MainCompetitor.Enabled = false;
            RadComboBox_CostCenter.Enabled = false;
            rcbExchangeRate.Enabled = false;
            // RadComboBox_ProfitCenter.Enabled = false;
            DatePicker_ExpectedCompletionDate.Enabled = false;
            DatePicker_ContractStartDate.Enabled = false;
            DatePicker_ContractEndDate.Enabled = false;

            rcbCurrency.Enabled = false;
            rcbSource.Enabled = false;
            rcbSalesType.Enabled = false;

            TextBox_SiteName.Enabled = false;
            TextBox_OpportunityNo.Enabled = false;

            btn_CompetitorDetails.Enabled = false;
            Button_Save_OppLocations.Enabled = false;
            Button_SameAsAbove.Enabled = false;
            Button_Copy.Enabled = false;
            Button_Copy_ShipTo.Enabled = false;
            chkIsSaleForLocal.Enabled = false;
            RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
        }

        private void LockCustomerContacts()
        {
            Button_SameAsAbove.Enabled=false;
            Button_Save_OppLocations.Enabled = false;

            LinkButton_Employee.Visible = false;
            LinkButton_BillTo_AddNew.Visible = false;
            LinkButton_SoldTo_AddNew.Visible = false;
            LinkButton_ShipTo_AddNew.Visible = false;
            RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
            RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
            RadGridHelper.MaskUpdateButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);
            RadGridHelper.MaskUpdateButtonColumn(RadGrid_Employee);
            RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_SoldToParty);
            RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
            RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_ShipToParty);
            RadGridHelper.MaskDeleteButtonColumn(RadGrid_Employee);
            //RadGrid_OpportunityCustomerContacts_BillToParty.Rebind();
            Button_Copy.Enabled = false;
            Button_Copy_ShipTo.Enabled = false;
            RadGridHelper.MaskDeleteButtonColumn(RadGrid_OpportunityCustomerContacts_BillToParty);
            Button_Price.Enabled = false;
        }

        private void LockControlsForNonEmployee()
        {
            //// Lock Buttons from Basic Info
            //RadButtonRemarks.Enabled = false;     //Removed and Handled on Remark page explicitly.
            //RadBtnPendingActions.Enabled = false;
            Button_Activity_Top.Enabled = false;
        }

        private void ApplyOpportunityApplicableActions()
        {
            //  UnLockSpecifications();
            //  UnLockPricing();
            //  UnLockOpportunity();

            EntityApplicableActions AllEntityApplicableActions = EntityApplicableActions.GetEntityApplicableAction(mEntityID, mOpportunityID);

            if (AllEntityApplicableActions.Count > 0)
            {
                foreach (EntityApplicableAction oEntityApplicableAction in AllEntityApplicableActions)
                {
                    string sAction = oEntityApplicableAction.ActionName.ToString().Trim();
                    switch (sAction)
                    {
                        case "Lock Product":
                            {
                                LockProduct();
                                break;
                            }
                        case "Lock Specification":
                            {
                                //  LockSpecifications();
                                break;
                            }
                        case "Fill Discount Basket":
                            {
                                // bFillDiscountBasket = true;
                                break;
                            }
                        case "Lock Pricing":
                            {
                                LockPricing();
                                break;
                            }
                        case "Lock Opportunity":
                            {
                                LockOpportunity();
                                HiddenField_CurrentStatusAction.Value = "Lock Pricing";
                                break;
                            }
                        case "Reqest For Change Order":
                            {
                                Session["Change Order"] = true;
                                break;
                            }
                        case "Lock Opptional":
                            {
                                Session["Lock_Optional"] = true;
                                break;
                            }
                        //case "Create Contract No":
                        //    {
                        //        Tab_ProjectBudget.Enabled = true;
                        //        break;
                        //    }
                        default:
                            {
                                break;
                            }
                    }
                }
            }
        }

        private void LockProduct()
        {
            Session["Lock Product"] = true;
            rcbExchangeRate.Enabled = false;
        }

        #endregion

        #region Questionaner

        private void SetQuestionanierID()
        {
            HiddenField_QuestionanierID.Value = "";
            Opportunity oOpportunity = GetOpportunityBeingEdited();

            if (oOpportunity.OpportunityID > 0)
            {
                int UserID = UIHelper.GetUserIDOfLoggedInUser();

                string QuestionnaireID = QuestionnairesVerification.GetQuestionnaireIDOfNextStatus(mEntityID, oOpportunity.OpportunityID.ToString(), oOpportunity.StatusID, UserID);
                string[] QuestionnaireArr = QuestionnaireID.Split(',');

                if (QuestionnaireID != "")
                {
                    HiddenField_QuestionanierID.Value = QuestionnaireArr[0].ToString();
                    HiddenField_NexrStatusID.Value = QuestionnaireArr[1].ToString();
                }

            }
        }

        #endregion

        #region check valid data

        private void IsReferenceDataAvailable()
        {
            StringBuilder oStringbuilder = new StringBuilder();
            int DefaultCustomerRoleID = CustomerRoleDA.GetDefaultCustomerRoleID(mRootOrganizationID);
            int DefaultCustomerContactRoleID = CustomerContactRoleDA.GetDefaultCustomerContactRoleID(mRootOrganizationID);

            if (DefaultCustomerRoleID == 0)
            {
                oStringbuilder.Append(Environment.NewLine)
                .Append("Default Customer RoleID data not available.");
            }
            if (DefaultCustomerContactRoleID == 0)
            {
                oStringbuilder.Append(Environment.NewLine)
                .Append("Default Customer Contact RoleID data not available.");
            }
            if (rcbSalesType.Items.Count <= 0)
            {
                oStringbuilder.Append("Sales Type is not defined for current user.");
            }
            if (!string.IsNullOrEmpty(oStringbuilder.ToString()))
                throw new Exception(oStringbuilder.ToString());
        }

        #endregion

        #region Private Methods

        private OpportunityEmployees GetOpportunityEmployees()
        {
            try
            {
                object businessObject = null;
                if (businessObject == null || !(businessObject is OpportunityEmployees))
                {
                    businessObject = OpportunityEmployees.GetOpportunityEmployees(mOpportunityID);

                }
                return (OpportunityEmployees)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private void SetOpportunityEmployee()
        {
            OpportunityEmployees AllOpportunityEmployees = GetOpportunityEmployees();
            if (AllOpportunityEmployees.Count > 0)
                foreach (OpportunityEmployee OEmp in AllOpportunityEmployees)
                {
                    if (OEmp.IsOwner)
                        lbl_Owner_Value.Text = OEmp.EmployeeName;
                }
        }

        private int GetOpportunityID(int iOrganizationID, string sOpportunityName)
        {
            try
            {
                OpportunityNameValue oOpportunityNameValue = GetOpportunityNameValue();
                return oOpportunityNameValue.Key(sOpportunityName);
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return 0;
            }
        }

        private OpportunityNameValue GetOpportunityNameValue()
        {
            try
            {
                object businessObject = null;
                if (businessObject == null || !(businessObject is OpportunityNameValue))
                {
                    businessObject = OpportunityNameValue.GetOpportunityNameValue(mOrganizationID);

                }
                return (OpportunityNameValue)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private bool GenerateOpportunityLevelDocument()
        {
            bool result = true;
            ConfigurationParameterSettingInfoList ParameterList;
            ParameterList = ConfigurationParameterSettingInfoList.GetConfigurationParameterSettings(ModuleHelper.GetCurrentModuleId(), 13);
            ConfigurationParameterSettingInfo DiscountParam = ParameterList.GetConfigurationParameterID(CONFIGURATION_PARAMETER_ID_FOR_DOC_GEN);
            if (DiscountParam.ConfigurationParameterValue.ToLower() == "yes")
                result = true;
            else
                result = false;
            return result;
        }

        private void LockPricing()
        {
            HiddenField_CurrentStatusAction.Value = "Lock Pricing";
        }

        private void UnLockPricing()
        {
            HiddenField_CurrentStatusAction.Value = BLANK;
        }

        private OrganizationProductList GetOrganizationProductList()
        {
            object businessObject = null;
            try
            {
                // businessObject = Session["OrganizationProductList"];
                if (businessObject == null || !(businessObject is OrganizationProductList))
                {
                    businessObject = OrganizationProductList.GetOrganizationProductList(mOrganizationID);
                    Session["OrganizationProductList"] = businessObject;
                }
                return (OrganizationProductList)businessObject;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
                return null;
            }
        }

        private void UpdateAssemblyReferenceforProducts()
        {
            OpportunityInfoList AllOpportunityInfoList = OpportunityInfoList.GetOpportunityInfoListForAnOpportunity(mOpportunityID, UIHelper.GetCurrentUsersLanguageID());

            OpportunityInfo AnOpportunityInfo = AllOpportunityInfoList.GetItem(mOpportunityID);

            OpportunityGroups AllOpportunityGroups = GetOpportunityProducts();

            ArrayList StatusArray = UIHelper.GetMultipleStatusIDByAnalysisTypeID(GlobalConstants.PRODUCT_VALIDITY_TYPE);

            bool CheckForValidityOfProduct = false;

            foreach (string StatusID in StatusArray)
            {
                if (AnOpportunityInfo.StatusID.ToString() == StatusID)
                {
                    CheckForValidityOfProduct = true;
                }
            }

            if (CheckForValidityOfProduct)
            {
                OrganizationProductList oOrganizationProductList = GetOrganizationProductList();

                //  oOrganizationProductList = RemoveUnmappedProductsOfSalesTypes(oOrganizationProductList);

                foreach (OpportunityGroup AnOpportunityGroup in AllOpportunityGroups)
                {
                    string ProductDefinitionAssembly = null;
                    foreach (IProduct oProduct in oOrganizationProductList)
                    {
                        if ((AnOpportunityGroup.ProductDefinitionAssembly != oProduct.Knowledgebase.GetType().Assembly.ManifestModule.Name) && !(string.IsNullOrEmpty(AnOpportunityGroup.ProductDefinitionAssembly)))
                        {
                            if (oProduct.ProductID == AnOpportunityGroup.ProductID)
                            {
                                ProductDefinitionAssembly = oProduct.Knowledgebase.GetType().Assembly.ManifestModule.Name;

                            }
                        }
                    }
                    if (!string.IsNullOrEmpty(ProductDefinitionAssembly))
                    {
                        OpportunityGroupDA.UpdateAssemblyReferenceforProducts(AnOpportunityGroup.OpportunityID, AnOpportunityGroup.OpportunityGroupID, ProductDefinitionAssembly, true, true);
                    }

                }

                Session["OpportunityGroups"] = AllOpportunityGroups.Save();
            }

            #region Check product specs validation required

            // CheckSpecsValidationRequired();

            #endregion
        }

        private void CheckSpecsValidationRequired()
        {
            OpportunityGroups AllOpportunityGroups = GetOpportunityProducts();
            foreach (OpportunityGroup AnGroup in AllOpportunityGroups)
            {
                if (AnGroup.IsSpecsValidationRequired == true)
                {
                    InvalidProductCount++;
                    mInvalidProductList.Append(InvalidProductCount.ToString()).Append(". ").Append(AnGroup.ProductStandardName).Append("\r\n");
                }
            }

            if (InvalidProductCount > 0)
            {
                throw new ApplicationException(mInvalidProductList.ToString());
            }
        }

        private void EnableMultipleDiscountView()
        {
            if (!UIHelper.EnableButton(APPLICATION_TASK_NAME_FOR_MULTIPLE_DISCOUNT_VIEW))
                Button_ViewDiscountSummary.Visible = false;
            else
                Button_ViewDiscountSummary.Visible = true;
        }
        #endregion

        #region Set ActivityEmployeeID

        private void SetPropertiesForActivities()
        {
            OpportunityContacts AllOpportunityContacts = (OpportunityContacts)(Session["OpportunityContactsBeingEdited"]);
            if (Session["OpportunityContactsBeingEdited"] == null)
            {
                AllOpportunityContacts = GetOpportunityContacts();
                Session["OpportunityContactsBeingEdited"] = AllOpportunityContacts;
            }
            Opportunity oOpportunity = GetOpportunityBeingEdited();
            if (AllOpportunityContacts != null && AllOpportunityContacts.Count > 0)
            {
                for (int count = 0; count < AllOpportunityContacts.Count; count++)
                {
                    if (AllOpportunityContacts[count].IsMain)
                    {
                        oOpportunity.ActivityCustomerID = AllOpportunityContacts[count].CustomerID;
                        oOpportunity.ActivityCustomerContactID = AllOpportunityContacts[count].CustomerContactID;
                    }
                }
            }
            oOpportunity.ActivityEmployeeID = mEmployeeID;
            //lblOpportunityName.Text = oOpportunity.OpportunityName;
            Session["OpportunityBeingEdited"] = oOpportunity;
        }

        #region Address Controls

        private void DisplayCustomerLocationAsOpportunityAddress()
        {
            //  if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_DISPLAY_CUSTOMER_LOCATION_AS_OPPORTUNITY_ADDRESS).ToLower() == "yes")
            SetContactAddress();
        }

        private void SetContactAddress()
        {
            if (Session["OpportunityCustomerInformation"] != null)
            {
                ArrayList CustomerInfoArray = (ArrayList)(Session["OpportunityCustomerInformation"]);
                if (CustomerInfoArray.Count > 0)
                {
                    OpportunityCustomerInformations oOpportunityCustomerInformations = (OpportunityCustomerInformations)(CustomerInfoArray[0]);

                    TextBox_SAddressLine1.Text = oOpportunityCustomerInformations.AddressLine1;
                    TextBox_SAddressLine2.Text = oOpportunityCustomerInformations.AddressLine2;
                    TextBox_SAddressLine3.Text = oOpportunityCustomerInformations.AddressLine3;
                    TextBox_SZipCode.Text = oOpportunityCustomerInformations.ZipCode;
                    TextBox_STelephoneNo.Text = oOpportunityCustomerInformations.PhoneNumber;

                    //FillCountry();
                    FillSitesAddCountry();
                    RadComboBox_SCountryName.SelectedValue = oOpportunityCustomerInformations.CountryID.ToString();
                    // RadComboBox_SCountryName.SelectedItem.Text = oLocationInfoList[0].CountryName.ToString();

                    //FillStates();
                    FillSiteAddStates();
                    RadComboBox_SStateName.SelectedValue = oOpportunityCustomerInformations.StateID.ToString();
                    // RadComboBox_SStateName.SelectedItem.Text = oLocationInfoList[0].StateName.ToString();

                    //FillCities();
                    FillSiteAddCities();
                    RadComboBox_SCityName.SelectedValue = oOpportunityCustomerInformations.CityID.ToString();
                    //  RadComboBox_SCityName.SelectedItem.Text = oLocationInfoList[0].CityName.ToString();

                    if (ApplicationHelper.GetConfigurationParameterSetting(CONFIGURATION_PARAMETER_ID_FOR_MAKE_OPPORTUNITY_NO_EDITABLE).ToLower() == "autogenerateeditable")
                        TextBox_OpportunityNo.Text = CountryDA.GetCountryAbbreviation(oOpportunityCustomerInformations.CountryID);
                }
            }

        }

        private int GetDefaultCustomerLocationTypeID()
        {
            return LocationTypeInfoList.GetDefaultCustomerLocationTypeID(mRootOrganizationID);
        }

        private int GetCustomerLocationID(int CustomerID, int DefaultCustomerLocationTypeID)
        {
            return CustomerLocationsDA.GetCustomerLocation(CustomerID, DefaultCustomerLocationTypeID);
        }

        #endregion

        #endregion

        #region collection Methods

        private OpportunityGroups GetOpportunityProducts()
        {
            object businessObject = null;
            try
            {
                if (businessObject == null || !(businessObject is OpportunityGroups))
                {
                    businessObject = OpportunityGroups.GetOpportunityGroups(mOpportunityID);
                }
                return (OpportunityGroups)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private OpportunityCategoryNameValue GetOpportunityCategoryNameValue()
        {
            object businessObject = null;
            try
            {
                businessObject = null;
                if (businessObject == null || !(businessObject is OpportunityCategoryNameValue))
                {
                    businessObject = OpportunityCategoryNameValue.GetOpportunityCategoryNameValue(mRootOrganizationID, mLanguageID);
                }
                return (OpportunityCategoryNameValue)businessObject;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
                return null;
            }
        }

        private FutureProspectNameValue GetFutureProspectNameValue()
        {
            object businessObject = null;
            try
            {
                businessObject = FutureProspectNameValue.GetFutureProspectNameValue(mRootOrganizationID, mLanguageID);
                return (FutureProspectNameValue)businessObject;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
                return null;
            }
        }

        private OpportunityTypeNameValue GetOpportunityTypeNameValue()
        {
            object businessObject = null;
            try
            {
                businessObject = OpportunityTypeNameValue.GetOpportunityTypeNameValue(mRootOrganizationID, mLanguageID);
                return (OpportunityTypeNameValue)businessObject;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
                return null;
            }
        }

        private Opportunity GetOpportunityBeingEdited()
        {
            try
            {

                object businessObject = Session["OpportunityBeingEdited"];
                if (businessObject == null || !(businessObject is Opportunity))
                {
                    Opportunities oOpportunities = GetOpportunities();

                    businessObject = oOpportunities.GetItem(mOpportunityID);
                    Session["OpportunityBeingEdited"] = businessObject;
                }
                return (Opportunity)businessObject;

            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private Opportunities GetOpportunities()
        {
            object businessObject = null;

            try
            {
                businessObject = Session["currentOpportunityObject"];
                if (businessObject == null || !(businessObject is Opportunities))
                {
                    businessObject = Opportunities.GetOpportunities(mOpportunityID, mLanguageID);
                    Session["currentOpportunityObject"] = businessObject;
                }
                return (Opportunities)businessObject;
            }
            catch (Exception ex)
            {
                XITingExceptionProcessor.ProcessException(this, ex);
                return null;
            }
        }

        private SalesTypesNameValue GetSalesTypesNameValue()
        {
            object businessObject = null;
            try
            {
                businessObject = SalesTypesNameValue.GetSalesTypesNameValue(UIHelper.GetUserIDOfLoggedInUser(), mLanguageID, ApplicationHelper.GetApplicationID(), ModuleHelper.GetSelectedModuleID());
                return (SalesTypesNameValue)businessObject;
            }
            catch (Exception exc)
            {
                XITingExceptionProcessor.ProcessException(this, exc);
                return null;
            }
        }

        #endregion


    }
    ---------------------------------------------------------------------------------
    ManageOpportunityGroups.aspx
    ---------------------------------------------------------------------------------
    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/ModuleMasterPage.Master" AutoEventWireup="true" Inherits="ManageOpportunityGroupsMOD"
         Codebehind="ManageOpportunityGroups.aspx.cs" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="Server">
        <telerik:RadAjaxPanel ID="Group_rjxPanel" runat="server" LoadingPanelID="RadAjaxLoadingPanel1">
       <asp:panel ID="pnl_OpportunityGroups" runat="server">
            <fieldset style="overflow: hidden; width: 100%; margin: 0px; padding: 0px;">
                <telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">
                </telerik:RadCodeBlock>
                <telerik:RadSplitter ID="RadSplitter_OpportunityGroups" runat="server"
                    CssClass="GridHieght2" Width="100%" VisibleDuringInit="false" ResizeWithBrowserWindow="true"
                    LiveResize="true" ResizeMode="AdjacentPane">
                    <telerik:RadPane ID="RadPane_treeProjects" runat="server" Width="18%" MinWidth="110"
                        CssClass="GridHieght1">
                        <div style="float: left; margin-left: 0px; text-align: left; padding-right: 0px;">
                            <asp:LinkButton ID="LinkButton_Refresh" runat="server" Text="Refresh" OnClick="LinkButton_Refresh_Click">
                            </asp:LinkButton>
                             <asp:LinkButton runat="server" Text="Save State" ID="BtnSaveState" OnClick="BtnSaveState_Click" />
                            <telerik:RadTreeView ID="RadTreeView_Projects" runat="server" OnContextMenuItemClick="RadTreeView_Projects_OnContextMenuItemClick"
                                OnNodeClick="RadTreeView_Projects_OnNodeClick" Width="100%" ExpandAnimation-Type="OutSine"
                                CollapseAnimation-Type="InSine">
                            </telerik:RadTreeView>
                        </div>
                    </telerik:RadPane>
                    <telerik:RadSplitBar ID="RadSplitBar1" runat="server"
                        CssClass="GridHieght1" />
                    <telerik:RadPane ID="RadPane2" runat="server"  CssClass="GridHieght1">
                        <asp:MultiView ID="MultiView_Group_Set" runat="server" ActiveViewIndex="0">
                            <asp:View ID="View_AllGroups" runat="server">
                                <asp:Panel ID="panel_AllGroups" runat="server" Width="100%">
                                    <div id="Div_AllGroups" class="panel" runat="server" style="width: 100%">
                                        <table width="100%">
                                            <tr>
                                                <td align="left">
                                                    &nbsp;
                                                    <asp:Label CssClass="ClsSubLabelHead" ID="Label_AllGroupsGrid" runat="server" Text="<t>Opportunity Groups:</t>"></asp:Label>
                                                </td>
                                            </tr>
                                            <tr>
                                                <td style="height: 20px">
                                                </td>
                                            </tr>
                                            <tr>
                                                <td>
                                                    <telerik:RadGrid ID="RadGrid_AllGroups" runat="server" OnNeedDataSource="RadGrid_AllGroups_NeedDataSource"
                                                        OnItemDataBound="RadGrid_AllGroups_ItemDataBound" OnItemCommand="RadGrid_AllGroups_ItemCommand"
                                                        ShowGroupPanel="False" AllowMultiRowSelection="true" ShowFooter="true" AutoGenerateColumns="False"
                                                        AllowSorting="True" AllowPaging="false">
                                                        <MasterTableView ShowGroupFooter="true" GroupsDefaultExpanded="false" ExpandCollapseColumn-Groupable="true"
                                                            ExpandCollapseColumn-GroupByExpression="OpportunityGroupHeaderNo" CommandItemSettings-ShowAddNewRecordButton="false"
                                                            GroupLoadMode="Client">
                                                            <GroupByExpressions>
                                                                <telerik:GridGroupByExpression>
                                                                    <SelectFields>
                                                                        <telerik:GridGroupByField FieldAlias="Group" FieldName="OpportunityGroupHeaderName" />
                                                                    </SelectFields>
                                                                    <GroupByFields>
                                                                        <telerik:GridGroupByField FieldName="OpportunityGroupHeaderID" SortOrder="Ascending" />
                                                                    </GroupByFields>
                                                                </telerik:GridGroupByExpression>
                                                                <%--<telerik:GridGroupByExpression>
                                                                    <SelectFields>
                                                                        <telerik:GridGroupByField FieldAlias="Sub-Group" FieldName="OptionalSolutionName" />
                                                                    </SelectFields>
                                                                    <GroupByFields>
                                                                        <telerik:GridGroupByField FieldName="OptionalSolutionNo" SortOrder="Ascending" />
                                                                    </GroupByFields>
                                                                </telerik:GridGroupByExpression>--%>
                                                            </GroupByExpressions>
                                                            <Columns>
                                                                <telerik:GridBoundColumn DataField="OpportunityID" HeaderText="Opportunity ID" UniqueName="OpportunityID"
                                                                    Visible="False" ReadOnly="True">
                                                                </telerik:GridBoundColumn>
                                                                <telerik:GridBoundColumn DataField="OpportunityGroupID" HeaderText="Opportunity Group ID"
                                                                    UniqueName="OpportunityGroupID" Visible="False">
                                                                </telerik:GridBoundColumn>
                                                                <telerik:GridBoundColumn DataField="OpportunityGroupHeaderID" HeaderText="OpportunityGroupHeaderID"
                                                                    UniqueName="OpportunityGroupHeaderID" Visible="false">
                                                                </telerik:GridBoundColumn>
                                                                <telerik:GridBoundColumn DataField="OpportunityGroupHeaderNo" HeaderText="OpportunityGroupHeaderNo"