/// <summary>
        /// This Returns all portfolio Id of a particular customer. Author:Pramod
        /// </summary>
        /// <param name="customerId"></param>
        /// <returns></returns>
        private string GetCustomerAllPortfolio(int customerId)
        {
            string      portfolioIDs = "";
            PortfolioBo portfolioBo  = new PortfolioBo();

            if (!String.IsNullOrEmpty(customerId.ToString())) //Note : customer Id assigned to txtCustomerId(hidden field) when the user selects customer from customer name suggestion text box
            {
                //int customerId = Convert.ToInt32(txtParentCustomerId.Value);
                List <CustomerPortfolioVo> customerPortfolioVos = portfolioBo.GetCustomerPortfolios(customerId); //Get all the portfolios of the selected customer.
                if (customerPortfolioVos != null && customerPortfolioVos.Count > 0)                              //One or more folios available for selected customer
                {
                    foreach (CustomerPortfolioVo custPortfolio in customerPortfolioVos)
                    {
                        if (custPortfolio.PortfolioName == "MyPortfolio" || custPortfolio.PortfolioName == "MyPortfolioProspect")
                        {
                            portfolioIDs = portfolioIDs + custPortfolio.PortfolioId;
                            portfolioIDs = portfolioIDs + ",";
                        }
                        //checkbox.Append("<input type='checkbox' checked name='chk--" + custPortfolio.PortfolioId + "' id='chk--" + custPortfolio.PortfolioId + "'>" + custPortfolio.PortfolioName);
                        //checkboxList.Items.Add(new ListItem(custPortfolio.PortfolioName, custPortfolio.PortfolioId.ToString()));
                    }
                }
            }

            return(portfolioIDs);
        }
        private void ShowCustomerPortfolios()
        {
            int         customerId  = int.Parse(txtCustomerId.Value.ToString());
            PortfolioBo portfolioBo = new PortfolioBo();
            List <CustomerPortfolioVo> customerPortfolioVoList = new List <CustomerPortfolioVo>();

            tdPortfolios.Visible    = true;
            customerPortfolioVoList = portfolioBo.GetCustomerPortfolios(customerId);
            ddlPortfolios.Items.Clear();
            if (customerPortfolioVoList != null)
            {
                for (int i = 0; i < customerPortfolioVoList.Count; i++)
                {
                    ddlPortfolios.Items.Add(new ListItem(customerPortfolioVoList[i].PortfolioName, customerPortfolioVoList[i].PortfolioId.ToString()));
                    if (customerPortfolioVoList[i].IsMainPortfolio == 1)
                    {
                        ddlPortfolios.Items[i].Selected = true;
                    }
                }
            }
            else
            {
                ddlPortfolios.Items.Add(new ListItem("No Portfolios Available", "NA"));
            }
        }
        private void ShowFolios()
        {
            PortfolioBo portfolioBo = new PortfolioBo();

            //divPortfolios.InnerHtml = string.Empty;
            if (!String.IsNullOrEmpty(hdnCustomerId1.Value)) //Note : customer Id assigned to hdnCustomerId(hidden field) when the user selects customer from customer name suggestion text box
            {
                int customerId = Convert.ToInt32(hdnCustomerId1.Value);
                List <CustomerPortfolioVo> customerPortfolioVos = portfolioBo.GetCustomerPortfolios(customerId); //Get all the portfolios of the selected customer.
                if (customerPortfolioVos != null && customerPortfolioVos.Count > 0)                              //One or more folios available for selected customer
                {
                    StringBuilder checkbox = new StringBuilder();

                    //CheckBoxList checkboxList = new CheckBoxList();
                    //checkboxList.RepeatDirection = RepeatDirection.Horizontal;
                    //checkboxList.CssClass = "Field";
                    foreach (CustomerPortfolioVo custPortfolio in customerPortfolioVos)
                    {
                        if (ddlPortfolioGroup.SelectedValue == "MANAGED" && (custPortfolio.IsMainPortfolio != 1))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No managed portfolios found for this customer.Can't create report.</span>");
                            }
                            continue;
                        }
                        else if (ddlPortfolioGroup.SelectedValue == "UN_MANAGED" & (custPortfolio.IsMainPortfolio != 0))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No unmanaged portfolios found for this customer.Can't create report.</span>");
                            }
                            continue;
                        }
                        if (String.IsNullOrEmpty(custPortfolio.PortfolioName))
                        {
                            custPortfolio.PortfolioName = "No Name";
                        }
                        //checkboxList.Items.Add(new ListItem(custPortfolio.PortfolioName, custPortfolio.PortfolioId.ToString()));
                        checkbox.Append("<input type='checkbox' checked name='chk--" + custPortfolio.PortfolioId + "' id='chk--" + custPortfolio.PortfolioId + "'>" + custPortfolio.PortfolioName);
                    }
                    divPortfolios.InnerHtml = checkbox.ToString();
                    //divPortfolios.Controls.Add(checkboxList);
                }
                else //No portfolios found for this customer.
                {
                    divPortfolios.InnerHtml = "<span class='Error'>No portfolios found for this customer.Can't create report.</span>";
                }
            }
            else // Something went wrong :( customer id is not assigned to the hidden field.
            {
                divPortfolios.InnerHtml = "<span class='Error'>Invalid Customer selected.</span>";
            }
            //divGroupCustomers.InnerHtml = string.Empty;
        }
        private void ShowFolios()
        {
            PortfolioBo portfolioBo = new PortfolioBo();

            if (!String.IsNullOrEmpty(hdnCustomerId1.Value))
            {
                int customerId = Convert.ToInt32(hdnCustomerId1.Value);
                List <CustomerPortfolioVo> customerPortfolioVos = portfolioBo.GetCustomerPortfolios(customerId);
                if (customerPortfolioVos != null && customerPortfolioVos.Count > 0)
                {
                    StringBuilder checkbox = new StringBuilder();


                    foreach (CustomerPortfolioVo custPortfolio in customerPortfolioVos)
                    {
                        if (ddlPortfolioGroup.SelectedValue == "MANAGED" && (custPortfolio.IsMainPortfolio != 1))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No managed portfolios found for this customer.Can't create report.</span>");
                            }
                            continue;
                        }
                        else if (ddlPortfolioGroup.SelectedValue == "UN_MANAGED" & (custPortfolio.IsMainPortfolio != 0))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No unmanaged portfolios found for this customer.Can't create report.</span>");
                            }
                            continue;
                        }
                        if (String.IsNullOrEmpty(custPortfolio.PortfolioName))
                        {
                            custPortfolio.PortfolioName = "No Name";
                        }
                        checkbox.Append("<input type='checkbox' checked name='chk--" + custPortfolio.PortfolioId + "' id='chk--" + custPortfolio.PortfolioId + "'>" + custPortfolio.PortfolioName);
                    }
                    divPortfolios.InnerHtml = checkbox.ToString();
                }
                else
                {
                    divPortfolios.InnerHtml = "<span class='Error'>No portfolios found for this customer.Can't create report.</span>";
                }
            }
            else
            {
                divPortfolios.InnerHtml = "<span class='Error'>Invalid Customer selected.</span>";
            }
        }
        private string ShowGroupFolios(int customerId)
        {
            StringBuilder checkbox    = new StringBuilder();
            PortfolioBo   portfolioBo = new PortfolioBo();

            if (!String.IsNullOrEmpty(hdnCustomerId1.Value)) //Note : customer Id assigned to txtCustomerId(hidden field) when the user selects customer from customer name suggestion text box
            {
                //int customerId = Convert.ToInt32(txtParentCustomerId.Value);
                List <CustomerPortfolioVo> customerPortfolioVos = portfolioBo.GetCustomerPortfolios(customerId); //Get all the portfolios of the selected customer.
                if (customerPortfolioVos != null && customerPortfolioVos.Count > 0)                              //One or more folios available for selected customer
                {
                    foreach (CustomerPortfolioVo custPortfolio in customerPortfolioVos)
                    {
                        if (ddlGroupPortfolioGroup.SelectedValue == "MANAGED" && (custPortfolio.IsMainPortfolio != 1))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No portfolio</span>");
                            }
                            continue;
                        }
                        else if (ddlGroupPortfolioGroup.SelectedValue == "UN_MANAGED" & (custPortfolio.IsMainPortfolio != 0))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No portfolio</span>");
                            }
                            continue;
                        }
                        if (String.IsNullOrEmpty(custPortfolio.PortfolioName))
                        {
                            custPortfolio.PortfolioName = "No Name";
                        }
                        checkbox.Append("<input type='checkbox' checked name='chk--" + custPortfolio.PortfolioId + "' id='chk--" + custPortfolio.PortfolioId + "'>" + custPortfolio.PortfolioName);
                        //checkboxList.Items.Add(new ListItem(custPortfolio.PortfolioName, custPortfolio.PortfolioId.ToString()));
                    }
                    //control.Controls.Add(checkboxList);
                }
                else //No portfolios found for this customer.
                {
                    checkbox.Append("--");
                }
            }
            else // Something went wrong :( customer id is not assigned to the hidden field.
            {
                divPortfolios.InnerHtml = "<span class='Error'>Invalid Customer selected.</span>";
            }
            return(checkbox.ToString());
        }
        private string ShowGroupFolios(int customerId)
        {
            StringBuilder checkbox    = new StringBuilder();
            PortfolioBo   portfolioBo = new PortfolioBo();

            if (!String.IsNullOrEmpty(hdnCustomerId1.Value))
            {
                List <CustomerPortfolioVo> customerPortfolioVos = portfolioBo.GetCustomerPortfolios(customerId);
                if (customerPortfolioVos != null && customerPortfolioVos.Count > 0)
                {
                    foreach (CustomerPortfolioVo custPortfolio in customerPortfolioVos)
                    {
                        if (ddlGroupPortfolioGroup.SelectedValue == "MANAGED" && (custPortfolio.IsMainPortfolio != 1))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No portfolio</span>");
                            }
                            continue;
                        }
                        else if (ddlGroupPortfolioGroup.SelectedValue == "UN_MANAGED" & (custPortfolio.IsMainPortfolio != 0))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No portfolio</span>");
                            }
                            continue;
                        }
                        if (String.IsNullOrEmpty(custPortfolio.PortfolioName))
                        {
                            custPortfolio.PortfolioName = "No Name";
                        }
                        checkbox.Append("<input type='checkbox' checked name='chk--" + custPortfolio.PortfolioId + "' id='chk--" + custPortfolio.PortfolioId + "'>" + custPortfolio.PortfolioName);
                    }
                }
                else
                {
                    checkbox.Append("--");
                }
            }
            else
            {
                divPortfolios.InnerHtml = "<span class='Error'>Invalid Customer selected.</span>";
            }
            return(checkbox.ToString());
        }
        private string ShowGroupFolios(int customerId)
        {
            StringBuilder checkbox    = new StringBuilder();
            PortfolioBo   portfolioBo = new PortfolioBo();

            if (!String.IsNullOrEmpty(hdnCustomerId1.Value))                                                     //Note : customer Id assigned to txtCustomerId(hidden field) when the user selects customer from customer name suggestion text box
            {
                List <CustomerPortfolioVo> customerPortfolioVos = portfolioBo.GetCustomerPortfolios(customerId); //Get all the portfolios of the selected customer.
                if (customerPortfolioVos != null && customerPortfolioVos.Count > 0)                              //One or more folios available for selected customer
                {
                    foreach (CustomerPortfolioVo custPortfolio in customerPortfolioVos)
                    {
                        if (ddlGroupPortfolioGroup.SelectedValue == "MANAGED" && (custPortfolio.IsMainPortfolio != 1))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No portfolio</span>");
                            }
                            continue;
                        }
                        else if (ddlGroupPortfolioGroup.SelectedValue == "UN_MANAGED" & (custPortfolio.IsMainPortfolio != 0))
                        {
                            if (customerPortfolioVos.Count == 1)
                            {
                                checkbox.Append("<span class='Error'>No portfolio</span>");
                            }
                            continue;
                        }
                        if (String.IsNullOrEmpty(custPortfolio.PortfolioName))
                        {
                            custPortfolio.PortfolioName = "No Name";
                        }
                        checkbox.Append("<input type='checkbox' checked name='chk--" + custPortfolio.PortfolioId + "' id='chk--" + custPortfolio.PortfolioId + "'>" + custPortfolio.PortfolioName);
                    }
                }
                else //No portfolios found for this customer.
                {
                    checkbox.Append("--");
                }
            }

            return(checkbox.ToString());
        }
        public void CreateEQNetpositionForAllAdviser()
        {
            int adviserId  = 0;
            int customerId = 0;

            CheckForTradeDate(DateTime.Today.AddDays(-1));
            if (isValuationDateTradeDate)
            {
                adviserVoList = adviserMaintenanceBo.GetAdviserList();
                for (int i = 0; i < adviserVoList.Count; i++)
                {
                    adviserId = adviserVoList[i].advisorId;
                    int logId = 0;
                    logId = CreateAdviserEODLog("EQ", DateTime.Today.AddDays(-1), adviserId);
                    try
                    {
                        customerList = customerPortfolioBo.GetAdviserCustomerList_EQ(adviserId);

                        if (customerList != null && customerList.Count > 0)
                        {
                            for (int j = 0; j < customerList.Count; j++)
                            {
                                customerId = customerList[j];
                                try
                                {
                                    customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerId);
                                    customerPortfolioBo.DeleteEquityNetPosition(customerId, DateTime.Today.AddDays(-1));
                                    if (customerPortfolioList != null)
                                    {
                                        for (int k = 0; k < customerPortfolioList.Count; k++)
                                        {
                                            eqPortfolioList = customerPortfolioBo.GetCustomerEquityPortfolio(customerId, customerPortfolioList[k].PortfolioId, DateTime.Today.AddDays(-1), string.Empty, string.Empty);
                                            if (eqPortfolioList != null)
                                            {
                                                customerPortfolioBo.AddEquityNetPosition(eqPortfolioList, 1000);
                                            }
                                        }
                                    }
                                }
                                catch (BaseApplicationException Ex)
                                {
                                    throw Ex;
                                }
                                catch (Exception Ex)
                                {
                                    BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                                    NameValueCollection      FunctionInfo = new NameValueCollection();
                                    FunctionInfo.Add("Method", "EquityNetpositionProcessBo:CreateEQNetpositionForAllAdviser()");
                                    object[] objects = new object[2];
                                    objects[0]   = "EQ";
                                    objects[1]   = customerId;
                                    FunctionInfo = exBase.AddObject(FunctionInfo, objects);
                                    exBase.AdditionalInformation = FunctionInfo;
                                    ExceptionManager.Publish(exBase);
                                    throw exBase;
                                }
                            }
                            UpdateAdviserEODLog("EQ", 1, logId);
                        }
                    }
                    catch (BaseApplicationException Ex)
                    {
                        throw Ex;
                    }
                    catch (Exception Ex)
                    {
                        BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                        NameValueCollection      FunctionInfo = new NameValueCollection();
                        FunctionInfo.Add("Method", "EquityNetpositionProcessBo:CreateEQNetpositionForAllAdviser()");
                        object[] objects = new object[2];
                        objects[0]   = "EQ";
                        objects[1]   = adviserId;
                        FunctionInfo = exBase.AddObject(FunctionInfo, objects);
                        exBase.AdditionalInformation = FunctionInfo;
                        ExceptionManager.Publish(exBase);
                        throw exBase;
                    }
                }
            }
        }
        static void Main(string[] args)
        {
            List <AdvisorVo>           adviserVoList         = new List <AdvisorVo>();
            AdviserMaintenanceBo       adviserMaintenanceBo  = new AdviserMaintenanceBo();
            CustomerPortfolioBo        customerPortfolioBo   = new CustomerPortfolioBo();
            PortfolioBo                portfolioBo           = new PortfolioBo();
            List <CustomerPortfolioVo> customerPortfolioList = new List <CustomerPortfolioVo>();
            List <MFPortfolioVo>       mfPortfolioList       = new List <MFPortfolioVo>();
            List <EQPortfolioVo>       eqPortfolioList       = new List <EQPortfolioVo>();
            List <int> customerList_MF   = new List <int>();
            List <int> customerList_EQ   = new List <int>();
            DataSet    dsMFValuationDate = new DataSet();
            DataSet    dsEQValuationDate = new DataSet();
            DateTime   tradeDate         = new DateTime();
            int        LogId             = 0;
            int        year  = int.Parse(ConfigurationSettings.AppSettings["YEAR"].ToString());
            int        month = int.Parse(ConfigurationSettings.AppSettings["MONTH"].ToString());
            int        day   = int.Parse(ConfigurationSettings.AppSettings["FROMDAY"].ToString());

            tradeDate = new DateTime(year, month, 01);
            while (tradeDate.Year == year && tradeDate.Month == month)
            {
                //if (DateTime.Now.TimeOfDay.Hours < 1)
                //    tradeDate = DateTime.Today.AddDays(-1);
                //else

                Console.WriteLine("Starting for the Year:" + tradeDate.Year.ToString() + "Month:" + tradeDate.Month.ToString());
                DateTime MFValuationDate;
                DateTime EQValuationDate;
                try
                {
                    adviserVoList = adviserMaintenanceBo.GetAdviserList();
                    Console.WriteLine("Starting Valuation Process for " + adviserVoList.Count.ToString() + " Advisers");
                    for (int i = 0; i < adviserVoList.Count; i++)
                    {
                        dsMFValuationDate = customerPortfolioBo.GetAdviserValuationDate(adviserVoList[i].advisorId, "MF", tradeDate.Month, tradeDate.Year);
                        dsEQValuationDate = customerPortfolioBo.GetAdviserValuationDate(adviserVoList[i].advisorId, "EQ", tradeDate.Month, tradeDate.Year);
                        customerList_MF   = customerPortfolioBo.GetAdviserCustomerList_MF(adviserVoList[i].advisorId);
                        customerList_EQ   = customerPortfolioBo.GetAdviserCustomerList_EQ(adviserVoList[i].advisorId);
                        Console.WriteLine("Starting MF Valuation Process for Adviser: " + adviserVoList[i].OrganizationName.ToString());

                        foreach (DataRow drMF in dsMFValuationDate.Tables[0].Rows)
                        {
                            if (DateTime.Parse(drMF["WTD_Date"].ToString()).Day != DateTime.Now.Day && DateTime.Parse(drMF["WTD_Date"].ToString()).Day > day)
                            {
                                MFValuationDate = DateTime.Parse(drMF["WTD_Date"].ToString());
                                if (drMF["STAT"].ToString() == "Pending. Changes Found")
                                {
                                    customerPortfolioBo.DeleteAdviserEODLog(adviserVoList[i].advisorId, "MF", MFValuationDate, 0);
                                }
                                if (drMF["STAT"].ToString() != "Completed")
                                {
                                    if (DateTime.Compare(MFValuationDate, DateTime.Today) <= 0)
                                    {
                                        if (customerList_MF != null && customerList_MF.Count != 0)
                                        {
                                            LogId = CreateAdviserEODLog("MF", MFValuationDate, adviserVoList[i].advisorId);
                                            for (int j = 0; j < customerList_MF.Count; j++)
                                            {
                                                customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList_MF[j]);
                                                customerPortfolioBo.DeleteMutualFundNetPosition(customerList_MF[j], MFValuationDate);
                                                if (customerPortfolioList != null && customerPortfolioList.Count != 0)
                                                {
                                                    for (int k = 0; k < customerPortfolioList.Count; k++)
                                                    {
                                                        Console.WriteLine("Starting MF Valuation Process for Customer:" + j.ToString() + " Portfolio:" + k.ToString() + " Date:" + MFValuationDate.ToShortDateString());
                                                        try
                                                        {
                                                            mfPortfolioList = customerPortfolioBo.GetCustomerMFPortfolio(customerList_MF[j], customerPortfolioList[k].PortfolioId, MFValuationDate, "", "", "");
                                                        }
                                                        catch (Exception ex)
                                                        {
                                                            Console.WriteLine("Exception: " + ex.ToString());
                                                        }
                                                        if (mfPortfolioList != null && mfPortfolioList.Count != 0)
                                                        {
                                                            try
                                                            {
                                                                customerPortfolioBo.AddMutualFundNetPosition(mfPortfolioList, adviserVoList[i].UserId);
                                                            }
                                                            catch (Exception Ex)
                                                            {
                                                                Console.WriteLine("Exception: " + Ex.ToString());
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                            UpdateAdviserEODLog("MF", 1, LogId);
                                        }
                                    }
                                }
                            }
                        }
                        #region Equity Valuation
                        Console.WriteLine("Starting EQ Valuation Process for Adviser " + i.ToString());

                        foreach (DataRow drEQ in dsEQValuationDate.Tables[0].Rows)
                        {
                            EQValuationDate = DateTime.Parse(drEQ["WTD_Date"].ToString());
                            if (drEQ["STAT"].ToString() == "Pending. Changes Found")
                            {
                                customerPortfolioBo.DeleteAdviserEODLog(adviserVoList[i].advisorId, "EQ", EQValuationDate, 0);
                            }
                            if (drEQ["STAT"].ToString() != "Completed")
                            {
                                if (DateTime.Compare(EQValuationDate, DateTime.Today) <= 0)
                                {
                                    if (customerList_EQ != null && customerList_EQ.Count != 0)
                                    {
                                        LogId = CreateAdviserEODLog("EQ", EQValuationDate, adviserVoList[i].advisorId);
                                        for (int j = 0; j < customerList_EQ.Count; j++)
                                        {
                                            customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList_EQ[j]);
                                            customerPortfolioBo.DeleteEquityNetPosition(customerList_EQ[j], EQValuationDate);
                                            if (customerPortfolioList != null && customerPortfolioList.Count != 0)
                                            {
                                                for (int k = 0; k < customerPortfolioList.Count; k++)
                                                {
                                                    Console.WriteLine("Starting EQ Valuation Process for Customer:" + j.ToString() + " Portfolio:" + k.ToString() + " Date:" + EQValuationDate.ToShortDateString());
                                                    try
                                                    {
                                                        eqPortfolioList = customerPortfolioBo.GetCustomerEquityPortfolio(customerList_EQ[j], customerPortfolioList[k].PortfolioId, EQValuationDate, string.Empty, string.Empty);
                                                    }
                                                    catch (Exception Ex)
                                                    {
                                                        Console.WriteLine("Exception: " + Ex.ToString());
                                                    }
                                                    if (eqPortfolioList != null && eqPortfolioList.Count != 0)
                                                    {
                                                        try
                                                        {
                                                            customerPortfolioBo.AddEquityNetPosition(eqPortfolioList, adviserVoList[i].UserId);
                                                        }
                                                        catch (Exception Ex)
                                                        {
                                                            Console.WriteLine("Exception: " + Ex.ToString());
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        UpdateAdviserEODLog("EQ", 1, LogId);
                                    }
                                }
                            }
                        }
                        #endregion Equity Valuation
                    }
                }
                catch (BaseApplicationException Ex)
                {
                    throw Ex;
                }
                catch (Exception Ex)
                {
                    BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                    NameValueCollection      FunctionInfo = new NameValueCollection();
                    FunctionInfo.Add("Method", "DailyValuation.ascx.cs:CreateAdviserEODLog()");
                    object[] objects = new object[2];
                    objects[0]   = 0;
                    objects[1]   = tradeDate;
                    FunctionInfo = exBase.AddObject(FunctionInfo, objects);
                    exBase.AdditionalInformation = FunctionInfo;
                    ExceptionManager.Publish(exBase);
                    throw exBase;
                }
                tradeDate = tradeDate.AddMonths(1);
            }
        }
示例#10
0
        public void UpdateLOG(string value, string assetgroup)
        {
            int        cnt          = 0;
            int        LogId        = 0;
            int        notNullcnt   = 0;
            List <int> customerList = new List <int>();
            List <CustomerPortfolioVo> customerPortfolioList = new List <CustomerPortfolioVo>();
            List <EQPortfolioVo>       eqPortfolioList       = null;
            List <MFPortfolioVo>       mfPortfolioList       = null;
            string status = string.Empty;

            try
            {
                if (value == "1" && assetgroup == "EQ")
                {
                    if (rbtnEquity.Checked)
                    {
                        if (ddTradeMonth.SelectedValue != "" && ddTradeYear.SelectedValue != "")
                        {
                            for (int i = 0; i < dsAdviserValuationDate.Tables[0].Rows.Count; i++)
                            {
                                GridViewRow gvr = gvValuationDate.Rows[i];
                                if (gvValuationDate.Rows[i].RowType == DataControlRowType.DataRow)
                                {
                                    CheckBox checkBox = (CheckBox)gvr.FindControl("chkBx");
                                    status = gvr.Cells[2].Text.ToString();
                                    if (checkBox.Checked)
                                    {
                                        dt = DateTime.Parse(dsAdviserValuationDate.Tables[0].Rows[i][0].ToString());
                                        if (status == "Pending. Changes Found" || status == "Completed")
                                        {
                                            customerPortfolioBo.DeleteAdviserEODLog(advisorVo.advisorId, "EQ", dt, 0);
                                        }



                                        if (DateTime.Compare(dt, DateTime.Today) <= 0)
                                        {
                                            customerList = customerPortfolioBo.GetAdviserCustomerList_EQ(advisorVo.advisorId);

                                            if (customerList != null)
                                            {
                                                notNullcnt = notNullcnt + 1;
                                                LogId      = CreateAdviserEODLog("EQ", dt);
                                                if (LogId != 0)
                                                {
                                                    cnt = 0;
                                                    for (int j = 0; j < customerList.Count; j++)
                                                    {
                                                        customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList[j]);
                                                        customerPortfolioBo.DeleteEquityNetPosition(customerList[j], dt);
                                                        if (customerPortfolioList != null)
                                                        {
                                                            for (int k = 0; k < customerPortfolioList.Count; k++)
                                                            {
                                                                eqPortfolioList = customerPortfolioBo.GetCustomerEquityPortfolio(customerList[j], customerPortfolioList[k].PortfolioId, dt, string.Empty, string.Empty);
                                                                if (eqPortfolioList != null)
                                                                {
                                                                    customerPortfolioBo.AddEquityNetPosition(eqPortfolioList, userVo.UserId);
                                                                }
                                                            }
                                                        }

                                                        cnt = cnt + 1;
                                                    }
                                                }

                                                if (cnt == customerList.Count)
                                                {
                                                    UpdateAdviserEODLog("EQ", 1, LogId);
                                                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Equity Valuation done...!');", true);
                                                }
                                                else
                                                {
                                                    UpdateAdviserEODLog("EQ", 0, LogId);
                                                    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Equity Valuation not done...!');", true);
                                                }

                                                //
                                            }
                                            else
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            if (notNullcnt == 0)
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('No Customers With Equity Transactions....');", true);
                            }
                        }
                    }
                }
                else if (value == "1" && assetgroup == "MF")
                {
                    if (ddTradeMFMonth.SelectedValue != "" && ddTradeMFYear.SelectedValue != "")
                    {
                        for (int i = 0; i < dsAdviserValuationDate.Tables[0].Rows.Count; i++)
                        {
                            GridViewRow gvr = gvValuationDate.Rows[i];
                            if (gvValuationDate.Rows[i].RowType == DataControlRowType.DataRow)
                            {
                                CheckBox checkBox = (CheckBox)gvr.FindControl("chkBx");
                                status = gvr.Cells[2].Text.ToString();
                                if (checkBox.Checked)
                                {
                                    dt = DateTime.Parse(dsAdviserValuationDate.Tables[0].Rows[i][0].ToString());
                                    if (status == "Pending. Changes Found" || status == "Completed")
                                    {
                                        customerPortfolioBo.DeleteAdviserEODLog(advisorVo.advisorId, "MF", dt, 0);
                                    }

                                    if (DateTime.Compare(dt, DateTime.Today) <= 0)
                                    {
                                        customerList = customerPortfolioBo.GetAdviserCustomerList_MF(advisorVo.advisorId);
                                        if (customerList != null)
                                        {
                                            notNullcnt = notNullcnt + 1;
                                            LogId      = CreateAdviserEODLog("MF", dt);
                                            if (LogId != 0)
                                            {
                                                cnt = 0;
                                                for (int j = 0; j < customerList.Count; j++)
                                                {
                                                    customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList[j]);
                                                    customerPortfolioBo.DeleteMutualFundNetPosition(customerList[j], dt);
                                                    if (customerPortfolioList != null)
                                                    {
                                                        for (int k = 0; k < customerPortfolioList.Count; k++)
                                                        {
                                                            mfPortfolioList = customerPortfolioBo.GetCustomerMFPortfolio(customerList[j], customerPortfolioList[k].PortfolioId, dt, "", "", "");


                                                            if (mfPortfolioList != null)
                                                            {
                                                                customerPortfolioBo.AddMutualFundNetPosition(mfPortfolioList, userVo.UserId);
                                                            }
                                                        }
                                                    }


                                                    cnt = cnt + 1;
                                                }
                                            }
                                            if (cnt == customerList.Count)
                                            {
                                                UpdateAdviserEODLog("MF", 1, LogId);
                                                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('MF Valuation done...!');", true);
                                            }
                                            else
                                            {
                                                UpdateAdviserEODLog("MF", 0, LogId);
                                                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('MF Valuation not done...!');", true);
                                            }

                                            //  GetTradeDate();
                                        }
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        if (notNullcnt == 0)
                        {
                            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('No Customers With MF Transactions....');", true);
                        }
                    }
                }
                GetTradeDate();
            }

            catch (BaseApplicationException Ex)
            {
                throw Ex;
            }
            catch (Exception Ex)
            {
                BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                NameValueCollection      FunctionInfo = new NameValueCollection();
                FunctionInfo.Add("Method", "DailyValuation.ascx.cs:UpdateLOG()");
                object[] objects = new object[2];
                objects[0]   = value;
                objects[1]   = assetgroup;
                FunctionInfo = exBase.AddObject(FunctionInfo, objects);
                exBase.AdditionalInformation = FunctionInfo;
                ExceptionManager.Publish(exBase);
                throw exBase;
            }
        }
示例#11
0
        public override JobStatus Start(JobParams JP, out string ErrorMsg)
        {
            List <AdvisorVo>           adviserVoList         = new List <AdvisorVo>();
            AdviserMaintenanceBo       adviserMaintenanceBo  = new AdviserMaintenanceBo();
            CustomerPortfolioBo        customerPortfolioBo   = new CustomerPortfolioBo();
            PortfolioBo                portfolioBo           = new PortfolioBo();
            List <CustomerPortfolioVo> customerPortfolioList = new List <CustomerPortfolioVo>();
            List <MFPortfolioVo>       mfPortfolioList       = new List <MFPortfolioVo>();
            List <EQPortfolioVo>       eqPortfolioList       = new List <EQPortfolioVo>();
            List <int> customerList_MF   = new List <int>();
            List <int> customerList_EQ   = new List <int>();
            DataSet    dsMFValuationDate = new DataSet();
            DataSet    dsEQValuationDate = new DataSet();
            DateTime   tradeDate         = new DateTime();
            int        LogId             = 0;

            // if (DateTime.Now.TimeOfDay.Hours < 1)
            tradeDate = DateTime.Today;
            // else
            //  tradeDate = DateTime.Today;

            DateTime MFValuationDate;
            DateTime EQValuationDate;

            adviserVoList = adviserMaintenanceBo.GetAdviserList();

            for (int i = 0; i < adviserVoList.Count; i++)
            {
                dsMFValuationDate = customerPortfolioBo.GetAdviserValuationDate(adviserVoList[i].advisorId, "MF", tradeDate.Month, tradeDate.Year);
                dsEQValuationDate = customerPortfolioBo.GetAdviserValuationDate(adviserVoList[i].advisorId, "EQ", tradeDate.Month, tradeDate.Year);
                customerList_MF   = customerPortfolioBo.GetAdviserCustomerList_MF(adviserVoList[i].advisorId);
                customerList_EQ   = customerPortfolioBo.GetAdviserCustomerList_EQ(adviserVoList[i].advisorId);
                foreach (DataRow drMF in dsMFValuationDate.Tables[0].Rows)
                {
                    MFValuationDate = DateTime.Parse(drMF["WTD_Date"].ToString());
                    if (MFValuationDate != DateTime.Today || DateTime.Today.Hour > 23)
                    {
                        if (drMF["STAT"].ToString() == "Pending. Changes Found")
                        {
                            customerPortfolioBo.DeleteAdviserEODLog(adviserVoList[i].advisorId, "MF", MFValuationDate, 0);
                        }
                        if (drMF["STAT"].ToString() != "Completed")
                        {
                            if (DateTime.Compare(MFValuationDate, DateTime.Today) <= 0)
                            {
                                if (customerList_MF != null && customerList_MF.Count != 0)
                                {
                                    LogId = CreateAdviserEODLog("MF", MFValuationDate, adviserVoList[i].advisorId);
                                    for (int j = 0; j < customerList_MF.Count; j++)
                                    {
                                        customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList_MF[j]);
                                        customerPortfolioBo.DeleteMutualFundNetPosition(customerList_MF[j], MFValuationDate);
                                        if (customerPortfolioList != null && customerPortfolioList.Count != 0)
                                        {
                                            for (int k = 0; k < customerPortfolioList.Count; k++)
                                            {
                                                try
                                                {
                                                    mfPortfolioList = customerPortfolioBo.GetCustomerMFPortfolio(customerList_MF[j], customerPortfolioList[k].PortfolioId, MFValuationDate, "", "", "");
                                                }
                                                catch (Exception ex)
                                                {
                                                    Console.WriteLine("Exception: " + ex.ToString());
                                                }
                                                if (mfPortfolioList != null && mfPortfolioList.Count != 0)
                                                {
                                                    try
                                                    {
                                                        customerPortfolioBo.AddMutualFundNetPosition(mfPortfolioList, adviserVoList[i].UserId);
                                                    }
                                                    catch (Exception Ex)
                                                    {
                                                        Console.WriteLine("Exception: " + Ex.ToString());
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    UpdateAdviserEODLog("MF", 1, LogId);
                                }
                            }
                        }
                    }
                }

                foreach (DataRow drEQ in dsEQValuationDate.Tables[0].Rows)
                {
                    EQValuationDate = DateTime.Parse(drEQ["WTD_Date"].ToString());
                    if (EQValuationDate != DateTime.Today || DateTime.Today.Hour > 23)
                    {
                        if (drEQ["STAT"].ToString() == "Pending. Changes Found")
                        {
                            customerPortfolioBo.DeleteAdviserEODLog(adviserVoList[i].advisorId, "EQ", EQValuationDate, 0);
                        }
                        if (drEQ["STAT"].ToString() != "Completed")
                        {
                            if (DateTime.Compare(EQValuationDate, DateTime.Today) <= 0)
                            {
                                if (customerList_EQ != null && customerList_EQ.Count != 0)
                                {
                                    LogId = CreateAdviserEODLog("EQ", EQValuationDate, adviserVoList[i].advisorId);
                                    for (int j = 0; j < customerList_EQ.Count; j++)
                                    {
                                        customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList_EQ[j]);
                                        customerPortfolioBo.DeleteEquityNetPosition(customerList_EQ[j], EQValuationDate);
                                        if (customerPortfolioList != null && customerPortfolioList.Count != 0)
                                        {
                                            for (int k = 0; k < customerPortfolioList.Count; k++)
                                            {
                                                try
                                                {
                                                    eqPortfolioList = customerPortfolioBo.GetCustomerEquityPortfolio(customerList_EQ[j], customerPortfolioList[k].PortfolioId, EQValuationDate, string.Empty, string.Empty);
                                                }
                                                catch (Exception Ex)
                                                {
                                                    Console.WriteLine("Exception: " + Ex.ToString());
                                                }
                                                if (eqPortfolioList != null && eqPortfolioList.Count != 0)
                                                {
                                                    try
                                                    {
                                                        customerPortfolioBo.AddEquityNetPosition(eqPortfolioList, adviserVoList[i].UserId);
                                                    }
                                                    catch (Exception Ex)
                                                    {
                                                        Console.WriteLine("Exception: " + Ex.ToString());
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    UpdateAdviserEODLog("EQ", 1, LogId);
                                }
                            }
                        }
                    }
                }
            }

            ErrorMsg = "";
            return(JobStatus.SuccessFull);
        }
        public void UpdateLOG(string value, string assetGroup, int adviserId, DateTime valuationDate)
        {
            int        cnt          = 0;
            int        LogId        = 0;
            int        notNullcnt   = 0;
            List <int> customerList = new List <int>();
            List <CustomerPortfolioVo> customerPortfolioList = new List <CustomerPortfolioVo>();
            List <EQPortfolioVo>       eqPortfolioList       = null;
            List <MFPortfolioVo>       mfPortfolioList       = null;
            string status = string.Empty;

            try
            {
                if (value == "1" && assetGroup == "EQ")
                {
                    if (rbtnEquity.Checked)
                    {
                        if (ddTradeMonth.SelectedValue != "" && ddTradeYear.SelectedValue != "")
                        {
                            customerPortfolioBo.DeleteAdviserEODLog(adviserId, "EQ", valuationDate, 0);

                            if (DateTime.Compare(valuationDate, DateTime.Today) <= 1)
                            {
                                customerList = customerPortfolioBo.GetAdviserCustomerList_EQ(adviserId);

                                if (customerList != null)
                                {
                                    notNullcnt = notNullcnt + 1;
                                    LogId      = CreateAdviserEODLog("EQ", valuationDate, adviserId);
                                    if (LogId != 0)
                                    {
                                        cnt = 0;
                                        for (int j = 0; j < customerList.Count; j++)
                                        {
                                            customerPortfolioList = portfolioBo.GetCustomerPortfolios(customerList[j]);
                                            customerPortfolioBo.DeleteEquityNetPosition(customerList[j], valuationDate);
                                            if (customerPortfolioList != null)
                                            {
                                                for (int k = 0; k < customerPortfolioList.Count; k++)
                                                {
                                                    eqPortfolioList = customerPortfolioBo.GetCustomerEquityPortfolio(customerList[j], customerPortfolioList[k].PortfolioId, valuationDate, string.Empty, string.Empty);
                                                    if (eqPortfolioList != null)
                                                    {
                                                        customerPortfolioBo.AddEquityNetPosition(eqPortfolioList, userVo.UserId);
                                                    }
                                                }
                                            }

                                            cnt = cnt + 1;
                                        }
                                    }

                                    if (cnt == customerList.Count)
                                    {
                                        UpdateAdviserEODLog("EQ", 1, LogId);
                                        if (Cache[adviserId.ToString()] != null && valuationDate == DateTime.Today)
                                        {
                                            Cache.Remove(adviserId.ToString());
                                        }
                                        ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Equity Valuation done...!');", true);
                                    }
                                    else
                                    {
                                        UpdateAdviserEODLog("EQ", 0, LogId);
                                        ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Equity Valuation not done...!');", true);
                                    }

                                    //
                                    BindAdviserGrid("EQ", valuationDate);
                                }
                            }

                            if (notNullcnt == 0)
                            {
                                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('No Customers With Equity Transactions....');", true);
                            }
                        }
                    }
                }
                else if (value == "1" && assetGroup == "MF")
                {
                    customerPortfolioBo.DeleteAdviserEODLog(adviserId, "MF", valuationDate, 0);
                    if (DateTime.Compare(valuationDate, DateTime.Today) <= 1)
                    {
                        MFEngineBo mfEngineBo = new MFEngineBo();
                        //mfEngineBo.MFBalanceCreation(adviserId, 0, valuationFor);

                        advisorBo.InsertHistoricalValuationInQueue(valuationDate, adviserId, userVo.UserId, int.Parse(hfIsCurrentValuation.Value));
                        ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('Request successfully sent !!...Please wait for another 30 mints');", true);

                        BindAdviserGrid("MF", valuationDate);
                    }
                }

                //if (notNullcnt == 0)
                //{
                //    ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "pageloadscript", "alert('No Customers With MF Transactions....');", true);

                //}

                //GetTradeDate();
                btnRunValuation.Visible = true;
            }

            catch (BaseApplicationException Ex)
            {
                throw Ex;
            }
            catch (Exception Ex)
            {
                BaseApplicationException exBase       = new BaseApplicationException(Ex.Message, Ex);
                NameValueCollection      FunctionInfo = new NameValueCollection();
                FunctionInfo.Add("Method", "DailyValuation.ascx.cs:UpdateLOG()");
                object[] objects = new object[2];
                objects[0]   = value;
                objects[1]   = assetGroup;
                FunctionInfo = exBase.AddObject(FunctionInfo, objects);
                exBase.AdditionalInformation = FunctionInfo;
                ExceptionManager.Publish(exBase);
                throw exBase;
            }
        }