private void Page_Load(object sender, System.EventArgs e)
 {
     if (!IsPostBack)
     {
         Page.DataBind();
         lstTIMEZONE.DataSource = SplendidCache.TimezonesListbox();
         try
         {
             lstTIMEZONE.SelectedValue = SplendidDefaults.TimeZone().ToLower();
             lstTIMEZONE.DataBind();
         }
         catch                 //(Exception ex)
         {
             //lblError.Text = ex.Message;
         }
     }
 }
        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                // 09/15/2005 Paul.  Values will always be in the query string.
                int nCHART_LENGTH = Sql.ToInteger(Request.QueryString["CHART_LENGTH"]);
                int nYEAR         = Sql.ToInteger(Request.QueryString["YEAR"]);
                nYEAR = Math.Max(1900, nYEAR);
                nYEAR = Math.Min(2100, nYEAR);
                DateTime dtDATE_START = new DateTime(nYEAR, 1, 1);
                DateTime dtDATE_END   = new DateTime(nYEAR, 12, 31);
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrASSIGNED_USER_ID = Request.QueryString.GetValues("ASSIGNED_USER_ID");

                xml.LoadXml(SplendidCache.XmlFile(Server.MapPath(Session["themeURL"] + "BarChart.xml")));
                XmlNode nodeRoot        = xml.SelectSingleNode("graphData");
                XmlNode nodeXData       = xml.CreateElement("xData");
                XmlNode nodeYData       = xml.CreateElement("yData");
                XmlNode nodeColorLegend = xml.CreateElement("colorLegend");
                XmlNode nodeGraphInfo   = xml.CreateElement("graphInfo");
                XmlNode nodeChartColors = nodeRoot.SelectSingleNode("chartColors");

                nodeRoot.InsertBefore(nodeGraphInfo, nodeChartColors);
                nodeRoot.InsertBefore(nodeColorLegend, nodeGraphInfo);
                nodeRoot.InsertBefore(nodeYData, nodeColorLegend);
                nodeRoot.InsertBefore(nodeXData, nodeYData);

                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "length", "20");
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "min", "0");
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "max", "0");
                if (nCHART_LENGTH < 4)
                {
                    nCHART_LENGTH = 4;
                }
                else if (nCHART_LENGTH > 10)
                {
                    nCHART_LENGTH = 10;
                }
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "length", nCHART_LENGTH.ToString());
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "prefix", Sql.ToString(Session["USER_SETTINGS/CURRENCY_SYMBOL"]));
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "suffix", "");
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "defaultAltText", L10n.Term("Dashboard.LBL_ROLLOVER_DETAILS"));

                nodeGraphInfo.InnerText = L10n.Term("Dashboard.LBL_DATE_RANGE") + " " + Sql.ToDateString(T10n.FromServerTime(dtDATE_START)) + " " + L10n.Term("Dashboard.LBL_DATE_RANGE_TO") + Sql.ToDateString(T10n.FromServerTime(dtDATE_END)) + "<BR/>"
                                          + L10n.Term("Dashboard.LBL_OPP_SIZE") + " " + Strings.FormatCurrency(1, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS");

                Hashtable         hashOUTCOME = new Hashtable();
                DbProviderFactory dbf         = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string sSQL;
                    // 09/19/2005 Paul.  Prepopulate the outcome.
                    string[] arrOUTCOME = new string[] { "Closed Lost", "Closed Won", "Other" };
                    foreach (string sOUTCOME in arrOUTCOME)
                    {
                        if (!hashOUTCOME.ContainsKey(sOUTCOME))
                        {
                            XmlNode nodeMapping = xml.CreateElement("mapping");
                            nodeColorLegend.AppendChild(nodeMapping);
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "id", sOUTCOME);
                            if (sOUTCOME == "Other")
                            {
                                XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", L10n.Term("Dashboard.LBL_LEAD_SOURCE_OTHER"));
                            }
                            else
                            {
                                XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", Sql.ToString(L10n.Term(".sales_stage_dom.", sOUTCOME)));
                            }
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "color", SplendidDefaults.generate_graphcolor(sOUTCOME, hashOUTCOME.Count));
                            hashOUTCOME.Add(sOUTCOME, sOUTCOME);
                        }
                    }
                    sSQL = "select SALES_STAGE                                   " + ControlChars.CrLf
                           + "     , MONTH_CLOSED                                  " + ControlChars.CrLf
                           + "     , sum(AMOUNT_USDOLLAR/1000) as TOTAL            " + ControlChars.CrLf
                           + "     , count(*)                  as OPPORTUNITY_COUNT" + ControlChars.CrLf
                           + "  from vwOPPORTUNITIES_PipelineMonth                 " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        Security.Filter(cmd, "Opportunities", "list");
                        cmd.CommandText += "   and DATE_CLOSED >= @DATE_START" + ControlChars.CrLf;
                        cmd.CommandText += "   and DATE_CLOSED <= @DATE_END  " + ControlChars.CrLf;
                        // 09/14/2005 Paul.  Use add because <= and >= are not supported.
                        Sql.AddParameter(cmd, "@DATE_START", dtDATE_START);
                        Sql.AddParameter(cmd, "@DATE_END", dtDATE_END);
                        // 09/14/2005 Paul.  Use append because it supports arrays using the IN clause.
                        Sql.AppendGuids(cmd, arrASSIGNED_USER_ID, "ASSIGNED_USER_ID");

                        cmd.CommandText += ""
                                           + " group by SALES_STAGE                                " + ControlChars.CrLf
                                           + "        , MONTH_CLOSED                               " + ControlChars.CrLf
                                           + " order by MONTH_CLOSED, SALES_STAGE desc             " + ControlChars.CrLf;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            double dMAX_TOTAL        = 0;
                            double dPIPELINE_TOTAL   = 0;
                            string sMONTHYEAR_FORMAT = m_sDATEFORMAT;
                            // 09/21/2005 Paul.  Remove day from format.
                            sMONTHYEAR_FORMAT = sMONTHYEAR_FORMAT.Replace("dd", "");
                            sMONTHYEAR_FORMAT = sMONTHYEAR_FORMAT.Replace("--", "-");
                            sMONTHYEAR_FORMAT = sMONTHYEAR_FORMAT.Replace("//", "/");
                            sMONTHYEAR_FORMAT = sMONTHYEAR_FORMAT.Replace("  ", " ");
                            while (rdr.Read())
                            {
                                int      nMONTH_CLOSED      = Sql.ToInteger(rdr["MONTH_CLOSED"]);
                                string   sSALES_STAGE       = Sql.ToString(rdr["SALES_STAGE"]);
                                double   dTOTAL             = Sql.ToDouble(rdr["TOTAL"]);
                                int      nOPPORTUNITY_COUNT = Sql.ToInteger(rdr["OPPORTUNITY_COUNT"]);
                                DateTime dtMONTH_CLOSED     = new DateTime(nYEAR, nMONTH_CLOSED, 1);
                                string   sMONTH_CLOSED      = dtMONTH_CLOSED.ToString(sMONTHYEAR_FORMAT);

                                dPIPELINE_TOTAL += dTOTAL;
                                if (dTOTAL > dMAX_TOTAL)
                                {
                                    dMAX_TOTAL = dTOTAL;
                                }
                                XmlNode nodeRow = nodeXData.SelectSingleNode("dataRow[@title=\'" + L10n.Term(sMONTH_CLOSED).Replace("'", "\'") + "\']");
                                if (nodeRow == null)
                                {
                                    nodeRow = xml.CreateElement("dataRow");
                                    nodeXData.AppendChild(nodeRow);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", sMONTH_CLOSED);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", dTOTAL.ToString("0"));
                                }
                                else
                                {
                                    if (nodeRow.Attributes.GetNamedItem("endLabel") != null)
                                    {
                                        double dEND_LABEL = Sql.ToDouble(nodeRow.Attributes.GetNamedItem("endLabel").Value);
                                        dEND_LABEL += dTOTAL;
                                        if (dEND_LABEL > dMAX_TOTAL)
                                        {
                                            dMAX_TOTAL = dEND_LABEL;
                                        }
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", dEND_LABEL.ToString("0"));
                                    }
                                }

                                XmlNode nodeBar = xml.CreateElement("bar");
                                nodeRow.AppendChild(nodeBar);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "id", sSALES_STAGE);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "totalSize", dTOTAL.ToString("0"));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "altText", sMONTH_CLOSED + ": " + nOPPORTUNITY_COUNT.ToString() + " " + L10n.Term("Dashboard.LBL_OPPS_WORTH") + " " + dTOTAL.ToString("0") + L10n.Term("Dashboard.LBL_OPP_THOUSANDS") + " " + L10n.Term("Dashboard.LBL_OPPS_OUTCOME") + " " + Sql.ToString(L10n.Term(".sales_stage_dom.", sSALES_STAGE)));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "url", Sql.ToString(Application["rootURL"]) + "Opportunities/default.aspx?DATE_CLOSED=" + Server.UrlEncode(Sql.ToDateString(T10n.FromServerTime(dtMONTH_CLOSED))) + "&SALES_STAGE=" + Server.UrlEncode(sSALES_STAGE));
                            }
                            int    nNumLength   = Math.Floor(dMAX_TOTAL).ToString("0").Length - 1;
                            double dWhole       = Math.Pow(10, nNumLength);
                            double dDecimal     = 1 / dWhole;
                            double dMAX_ROUNDED = Math.Ceiling(dMAX_TOTAL * dDecimal) * dWhole;

                            XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "max", dMAX_ROUNDED.ToString("0"));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "title", L10n.Term("Dashboard.LBL_TOTAL_PIPELINE") + Strings.FormatCurrency(dPIPELINE_TOTAL, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS"));
                        }
                    }
                }
                Response.ContentType = "text/xml";
                Response.Write(xml.OuterXml);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                Response.Write(ex.Message);
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                // 09/15/2005 Paul.  Values will always be in the query string.
                int nCHART_LENGTH = Sql.ToInteger(Request.QueryString["CHART_LENGTH"]);
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrASSIGNED_USER_ID = Request.QueryString.GetValues("ASSIGNED_USER_ID");
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrLEAD_SOURCE = Request.QueryString.GetValues("LEAD_SOURCE");

                xml.LoadXml(SplendidCache.XmlFile(Server.MapPath(Session["themeURL"] + "BarChart.xml")));
                XmlNode nodeRoot        = xml.SelectSingleNode("graphData");
                XmlNode nodeXData       = xml.CreateElement("xData");
                XmlNode nodeYData       = xml.CreateElement("yData");
                XmlNode nodeColorLegend = xml.CreateElement("colorLegend");
                XmlNode nodeGraphInfo   = xml.CreateElement("graphInfo");
                XmlNode nodeChartColors = nodeRoot.SelectSingleNode("chartColors");

                nodeRoot.InsertBefore(nodeGraphInfo, nodeChartColors);
                nodeRoot.InsertBefore(nodeColorLegend, nodeGraphInfo);
                nodeRoot.InsertBefore(nodeXData, nodeColorLegend);
                nodeRoot.InsertBefore(nodeYData, nodeXData);

                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "defaultAltText", L10n.Term("Dashboard.LBL_ROLLOVER_DETAILS"));
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "min", "0");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", "0");
                if (nCHART_LENGTH < 4)
                {
                    nCHART_LENGTH = 4;
                }
                else if (nCHART_LENGTH > 10)
                {
                    nCHART_LENGTH = 10;
                }
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "length", nCHART_LENGTH.ToString());
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "prefix", Sql.ToString(Session["USER_SETTINGS/CURRENCY_SYMBOL"]));
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "suffix", "");

                nodeGraphInfo.InnerText = L10n.Term("Dashboard.LBL_OPP_SIZE") + " " + Strings.FormatCurrency(1, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS");

                Hashtable         hashOUTCOME = new Hashtable();
                DbProviderFactory dbf         = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string sSQL;
                    // 09/19/2005 Paul.  Prepopulate the stage rows so that empty rows will appear.  The SQL query will not return empty rows.
                    if (arrLEAD_SOURCE != null)
                    {
                        foreach (string sLEAD_SOURCE in arrLEAD_SOURCE)
                        {
                            XmlNode nodeRow = xml.CreateElement("dataRow");
                            nodeYData.AppendChild(nodeRow);
                            // 05/27/2007 Paul.  LBL_NONE is --None--, so create a new term LBL_NONE_VALUE.
                            if (sLEAD_SOURCE == String.Empty)
                            {
                                XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", Sql.ToString(L10n.Term(".LBL_NONE_VALUE")));
                            }
                            else
                            {
                                XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", Sql.ToString(L10n.Term(".lead_source_dom.", sLEAD_SOURCE)));
                            }
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", "0");
                        }
                    }
                    // 09/19/2005 Paul.  Prepopulate the outcome.
                    string[] arrOUTCOME = new string[] { "Closed Lost", "Closed Won", "Other" };
                    foreach (string sOUTCOME in arrOUTCOME)
                    {
                        if (!hashOUTCOME.ContainsKey(sOUTCOME))
                        {
                            XmlNode nodeMapping = xml.CreateElement("mapping");
                            nodeColorLegend.AppendChild(nodeMapping);
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "id", sOUTCOME);
                            if (sOUTCOME == "Other")
                            {
                                XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", L10n.Term("Dashboard.LBL_LEAD_SOURCE_OTHER"));
                            }
                            else
                            {
                                XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", Sql.ToString(L10n.Term(".sales_stage_dom.", sOUTCOME)));
                            }
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "color", SplendidDefaults.generate_graphcolor(sOUTCOME, hashOUTCOME.Count));
                            hashOUTCOME.Add(sOUTCOME, sOUTCOME);
                        }
                    }
                    sSQL = "select LEAD_SOURCE                                   " + ControlChars.CrLf
                           + "     , SALES_STAGE                                   " + ControlChars.CrLf
                           + "     , LIST_ORDER                                    " + ControlChars.CrLf
                           + "     , sum(AMOUNT_USDOLLAR/1000) as TOTAL            " + ControlChars.CrLf
                           + "     , count(*)                  as OPPORTUNITY_COUNT" + ControlChars.CrLf
                           + "  from vwOPPORTUNITIES_ByLeadOutcome                 " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        Security.Filter(cmd, "Opportunities", "list");
                        // 09/14/2005 Paul.  Use append because it supports arrays using the IN clause.
                        Sql.AppendGuids(cmd, arrASSIGNED_USER_ID, "ASSIGNED_USER_ID");
                        Sql.AppendParameter(cmd, arrLEAD_SOURCE, "LEAD_SOURCE");
#if false
                        if (arrLEAD_SOURCE != null)
                        {
                            nodeGraphInfo.InnerText = "LEAD_SOURCE = " + String.Join(", ", arrLEAD_SOURCE);
                        }
#endif

                        cmd.CommandText += ""
                                           + " group by LEAD_SOURCE                                " + ControlChars.CrLf
                                           + "        , LIST_ORDER                                 " + ControlChars.CrLf
                                           + "        , SALES_STAGE                                " + ControlChars.CrLf
                                           + " order by LIST_ORDER                                 " + ControlChars.CrLf
                                           + "        , SALES_STAGE                                " + ControlChars.CrLf;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            double dMAX_TOTAL      = 0;
                            double dPIPELINE_TOTAL = 0;
                            while (rdr.Read())
                            {
                                string sLEAD_SOURCE       = Sql.ToString(rdr["LEAD_SOURCE"]);
                                string sSALES_STAGE       = Sql.ToString(rdr["SALES_STAGE"]);
                                double dTOTAL             = Sql.ToDouble(rdr["TOTAL"]);
                                int    nOPPORTUNITY_COUNT = Sql.ToInteger(rdr["OPPORTUNITY_COUNT"]);

                                dPIPELINE_TOTAL += dTOTAL;
                                if (dTOTAL > dMAX_TOTAL)
                                {
                                    dMAX_TOTAL = dTOTAL;
                                }
                                // 05/27/2007 Paul.  LBL_NONE is --None--, so create a new term LBL_NONE_VALUE.
                                string sLEAD_SOURCE_TERM = String.Empty;
                                if (sLEAD_SOURCE == String.Empty)
                                {
                                    sLEAD_SOURCE_TERM = L10n.Term(".LBL_NONE_VALUE");
                                }
                                else
                                {
                                    sLEAD_SOURCE_TERM = Sql.ToString(L10n.Term(".lead_source_dom.", sLEAD_SOURCE));
                                }
                                XmlNode nodeRow = nodeYData.SelectSingleNode("dataRow[@title=\'" + sLEAD_SOURCE_TERM.Replace("'", "\'") + "\']");
                                if (nodeRow == null)
                                {
                                    nodeRow = xml.CreateElement("dataRow");
                                    nodeYData.AppendChild(nodeRow);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", sLEAD_SOURCE_TERM);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", dTOTAL.ToString("0"));
                                }
                                else
                                {
                                    if (nodeRow.Attributes.GetNamedItem("endLabel") != null)
                                    {
                                        double dEND_LABEL = Sql.ToDouble(nodeRow.Attributes.GetNamedItem("endLabel").Value);
                                        dEND_LABEL += dTOTAL;
                                        if (dEND_LABEL > dMAX_TOTAL)
                                        {
                                            dMAX_TOTAL = dEND_LABEL;
                                        }
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", dEND_LABEL.ToString("0"));
                                    }
                                }

                                XmlNode nodeBar = xml.CreateElement("bar");
                                nodeRow.AppendChild(nodeBar);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "id", sSALES_STAGE);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "totalSize", dTOTAL.ToString("0"));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "altText", nOPPORTUNITY_COUNT.ToString() + " " + L10n.Term("Dashboard.LBL_OPPS_WORTH") + " " + dTOTAL.ToString("0") + L10n.Term("Dashboard.LBL_OPP_THOUSANDS") + " " + L10n.Term("Dashboard.LBL_OPPS_OUTCOME") + " " + Sql.ToString(L10n.Term(".sales_stage_dom.", sSALES_STAGE)));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "url", Sql.ToString(Application["rootURL"]) + "Opportunities/default.aspx?LEAD_SOURCE=" + Server.UrlEncode(sLEAD_SOURCE) + "&SALES_STAGE=" + Server.UrlEncode(sSALES_STAGE));
                            }
                            int    nNumLength   = Math.Floor(dMAX_TOTAL).ToString("0").Length - 1;
                            double dWhole       = Math.Pow(10, nNumLength);
                            double dDecimal     = 1 / dWhole;
                            double dMAX_ROUNDED = Math.Ceiling(dMAX_TOTAL * dDecimal) * dWhole;

                            XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", dMAX_ROUNDED.ToString("0"));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "title", L10n.Term("Dashboard.LBL_TOTAL_PIPELINE") + Strings.FormatCurrency(dPIPELINE_TOTAL, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS"));
                        }
                    }
                }
                Response.ContentType = "text/xml";
                Response.Write(xml.OuterXml);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                Response.Write(ex.Message);
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrASSIGNED_USER_ID = Request.QueryString.GetValues("ASSIGNED_USER_ID");
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrLEAD_SOURCE = Request.QueryString.GetValues("LEAD_SOURCE");

                xml.LoadXml(SplendidCache.XmlFile(Server.MapPath(Session["themeURL"] + "PieChart.xml")));
                XmlNode nodeRoot        = xml.SelectSingleNode("graphData");
                XmlNode nodePie         = xml.CreateElement("pie");
                XmlNode nodeGraphInfo   = xml.CreateElement("graphInfo");
                XmlNode nodeChartColors = nodeRoot.SelectSingleNode("chartColors");

                nodeRoot.InsertBefore(nodeGraphInfo, nodeChartColors);
                nodeRoot.InsertBefore(nodePie, nodeGraphInfo);

                XmlUtil.SetSingleNodeAttribute(xml, nodePie, "defaultAltText", L10n.Term("Dashboard.LBL_ROLLOVER_WEDGE_DETAILS"));

                Hashtable         hashLEAD_SOURCE = new Hashtable();
                DbProviderFactory dbf             = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string sSQL;
                    sSQL = "select LEAD_SOURCE                                   " + ControlChars.CrLf
                           + "     , LIST_ORDER                                    " + ControlChars.CrLf
                           + "     , sum(AMOUNT_USDOLLAR/1000) as TOTAL            " + ControlChars.CrLf
                           + "     , count(*)                  as OPPORTUNITY_COUNT" + ControlChars.CrLf
                           + "  from vwOPPORTUNITIES_ByLeadSource                  " + ControlChars.CrLf
                           + " where 1 = 1                                         " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        // 09/14/2005 Paul.  Use append because it supports arrays using the IN clause.
                        Sql.AppendGuids(cmd, arrASSIGNED_USER_ID, "ASSIGNED_USER_ID");
                        Sql.AppendParameter(cmd, arrLEAD_SOURCE, "LEAD_SOURCE");
#if false
                        if (arrLEAD_SOURCE != null)
                        {
                            nodeGraphInfo.InnerText = "LEAD_SOURCE = " + String.Join(", ", arrLEAD_SOURCE);
                        }
#endif
                        cmd.CommandText += ""
                                           + " group by LEAD_SOURCE                                " + ControlChars.CrLf
                                           + "        , LIST_ORDER                                 " + ControlChars.CrLf
                                           + " order by LIST_ORDER                                 " + ControlChars.CrLf;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            double dMAX_TOTAL      = 0;
                            double dPIPELINE_TOTAL = 0;
                            while (rdr.Read())
                            {
                                string sLEAD_SOURCE       = Sql.ToString(rdr["LEAD_SOURCE"]);
                                double dTOTAL             = Sql.ToDouble(rdr["TOTAL"]);
                                int    nOPPORTUNITY_COUNT = Sql.ToInteger(rdr["OPPORTUNITY_COUNT"]);

                                dPIPELINE_TOTAL += dTOTAL;
                                if (dTOTAL > dMAX_TOTAL)
                                {
                                    dMAX_TOTAL = dTOTAL;
                                }
                                if (sLEAD_SOURCE == String.Empty)
                                {
                                    sLEAD_SOURCE = "None";
                                }

                                XmlNode nodeWedge = xml.CreateElement("bar");
                                nodePie.AppendChild(nodeWedge);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeWedge, "title", Sql.ToString(L10n.Term(".lead_source_dom.", sLEAD_SOURCE)));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeWedge, "value", dTOTAL.ToString("0"));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeWedge, "color", SplendidDefaults.generate_graphcolor(sLEAD_SOURCE, hashLEAD_SOURCE.Count));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeWedge, "labelText", Strings.FormatCurrency(dTOTAL, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeWedge, "url", Sql.ToString(Application["rootURL"]) + "Opportunities/default.aspx?LEAD_SOURCE=" + Server.UrlEncode(sLEAD_SOURCE));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeWedge, "altText", nOPPORTUNITY_COUNT.ToString() + " " + L10n.Term("Dashboard.LBL_OPPS_IN_LEAD_SOURCE") + " " + Sql.ToString(L10n.Term(".lead_source_dom.", sLEAD_SOURCE)));
                                hashLEAD_SOURCE.Add(sLEAD_SOURCE, sLEAD_SOURCE);
                            }
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "title", L10n.Term("Dashboard.LBL_TOTAL_PIPELINE") + Strings.FormatCurrency(dPIPELINE_TOTAL, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS"));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "subtitle", L10n.Term("Dashboard.LBL_OPP_SIZE") + " " + Strings.FormatCurrency(1.0, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS"));
                        }
                    }
                }
                Response.ContentType = "text/xml";
                Response.Write(xml.OuterXml);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                Response.Write(ex.Message);
            }
        }
Exemplo n.º 5
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                Guid gID = Sql.ToGuid(Request["ID"]);
                xml.LoadXml(SplendidCache.XmlFile(Server.MapPath(Session["themeURL"] + "BarChart.xml")));
                XmlNode nodeRoot        = xml.SelectSingleNode("graphData");
                XmlNode nodeXData       = xml.CreateElement("xData");
                XmlNode nodeYData       = xml.CreateElement("yData");
                XmlNode nodeColorLegend = xml.CreateElement("colorLegend");
                XmlNode nodeGraphInfo   = xml.CreateElement("graphInfo");
                XmlNode nodeChartColors = nodeRoot.SelectSingleNode("chartColors");

                nodeRoot.InsertBefore(nodeGraphInfo, nodeChartColors);
                nodeRoot.InsertBefore(nodeColorLegend, nodeGraphInfo);
                nodeRoot.InsertBefore(nodeXData, nodeColorLegend);
                nodeRoot.InsertBefore(nodeYData, nodeXData);

                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "defaultAltText", L10n.Term("Campaigns.LBL_ROLLOVER_VIEW"));
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "min", "0");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", "100");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "length", "10");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "prefix", "");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "suffix", "");

                Hashtable         hashTARGET = new Hashtable();
                DbProviderFactory dbf        = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string sSQL;
                    // 12/25/2007 Paul.  Prepopulate the activity type rows so that empty rows will appear.  The SQL query will not return empty rows.
                    DataTable dtActivityTypes     = SplendidCache.List("campainglog_activity_type_dom").Copy();
                    DataRow   rowActivityTypeNone = dtActivityTypes.NewRow();
                    dtActivityTypes.Rows.InsertAt(rowActivityTypeNone, 0);
                    rowActivityTypeNone["NAME"]         = "";
                    rowActivityTypeNone["DISPLAY_NAME"] = L10n.Term("Campaigns.NTC_NO_LEGENDS");
                    foreach (DataRow row in dtActivityTypes.Rows)
                    {
                        XmlNode nodeRow = xml.CreateElement("dataRow");
                        nodeYData.AppendChild(nodeRow);
                        XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", Sql.ToString(row["DISPLAY_NAME"]));
                        XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", "0");
                    }

                    // 12/25/2007 Paul.  Prepopulate the targets.
                    DataTable dtLegend = SplendidCache.List("campainglog_target_type_dom");
                    XmlUtil.SetSingleNodeAttribute(xml, nodeColorLegend, "status", "on");
                    for (int i = 0; i < dtLegend.Rows.Count; i++)
                    {
                        DataRow row     = dtLegend.Rows[i];
                        string  sTARGET = Sql.ToString(row["NAME"]);
                        if (!hashTARGET.ContainsKey(sTARGET))
                        {
                            XmlNode nodeMapping = xml.CreateElement("mapping");
                            nodeColorLegend.AppendChild(nodeMapping);
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "id", Sql.ToString(row["NAME"]));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", Sql.ToString(row["DISPLAY_NAME"]));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "color", SplendidDefaults.generate_graphcolor(String.Empty, hashTARGET.Count));
                            hashTARGET.Add(sTARGET, sTARGET);
                        }
                    }

                    sSQL = "select ACTIVITY_TYPE                         " + ControlChars.CrLf
                           + "     , TARGET_TYPE                           " + ControlChars.CrLf
                           + "     , LIST_ORDER                            " + ControlChars.CrLf
                           + "     , count(*)                  as HIT_COUNT" + ControlChars.CrLf
                           + "  from vwCAMPAIGNS_Activity                  " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        Security.Filter(cmd, "Campaigns", "view");
                        Sql.AppendParameter(cmd, gID, "ID", false);
                        cmd.CommandText += ""
                                           + " group by ACTIVITY_TYPE                      " + ControlChars.CrLf
                                           + "        , LIST_ORDER                         " + ControlChars.CrLf
                                           + "        , TARGET_TYPE                        " + ControlChars.CrLf
                                           + " order by LIST_ORDER                         " + ControlChars.CrLf
                                           + "        , TARGET_TYPE                        " + ControlChars.CrLf;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            int nMAX_COUNT = 0;
                            while (rdr.Read())
                            {
                                string sACTIVITY_TYPE = Sql.ToString(rdr["ACTIVITY_TYPE"]);
                                string sTARGET_TYPE   = Sql.ToString(rdr["TARGET_TYPE"]);
                                int    nHIT_COUNT     = Sql.ToInteger(rdr["HIT_COUNT"]);

                                if (nHIT_COUNT > nMAX_COUNT)
                                {
                                    nMAX_COUNT = nHIT_COUNT;
                                }
                                string sACTIVITY_TYPE_TERM = String.Empty;
                                if (sACTIVITY_TYPE == String.Empty)
                                {
                                    sACTIVITY_TYPE_TERM = L10n.Term("Campaigns.NTC_NO_LEGENDS");
                                }
                                else
                                {
                                    sACTIVITY_TYPE_TERM = Sql.ToString(L10n.Term(".campainglog_activity_type_dom.", sACTIVITY_TYPE));
                                }

                                int nEND_LABEL = nHIT_COUNT;

                                XmlNode nodeRow = nodeYData.SelectSingleNode("dataRow[@title=\'" + sACTIVITY_TYPE_TERM.Replace("'", "\'") + "\']");
                                if (nodeRow == null)
                                {
                                    nodeRow = xml.CreateElement("dataRow");
                                    nodeYData.AppendChild(nodeRow);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", sACTIVITY_TYPE_TERM);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", nEND_LABEL.ToString());
                                }
                                else
                                {
                                    if (nodeRow.Attributes.GetNamedItem("endLabel") != null)
                                    {
                                        nEND_LABEL  = Sql.ToInteger(nodeRow.Attributes.GetNamedItem("endLabel").Value);
                                        nEND_LABEL += nHIT_COUNT;
                                        if (nEND_LABEL > nMAX_COUNT)
                                        {
                                            nMAX_COUNT = nEND_LABEL;
                                        }
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", nEND_LABEL.ToString());
                                    }
                                }
                                XmlNode nodeBar = xml.CreateElement("bar");
                                nodeRow.AppendChild(nodeBar);

                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "id", sTARGET_TYPE);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "totalSize", nHIT_COUNT.ToString());

                                if (sACTIVITY_TYPE == "targeted")
                                {
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "altText", L10n.Term("Campaigns.LBL_TARGETED") + nHIT_COUNT.ToString() + ", " + L10n.Term("Campaigns.LBL_TOTAL_TARGETED") + " " + nEND_LABEL.ToString() + ".");
                                }
                                else
                                {
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "altText", nHIT_COUNT.ToString() + " " + Sql.ToString(L10n.Term(".campainglog_target_type_dom.", sTARGET_TYPE)));
                                }
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "url", "#ACTIVITY_TYPE=" + Server.UrlEncode(sACTIVITY_TYPE) + "&TARGET_TYPE=" + Server.UrlEncode(sTARGET_TYPE));
                            }
                            if (nMAX_COUNT < 10)
                            {
                                nMAX_COUNT = 10;
                            }
                            XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", nMAX_COUNT.ToString());
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "title", L10n.Term("Campaigns.LBL_CAMPAIGN_RESPONSE_BY_RECIPIENT_ACTIVITY"));
                        }
                    }
                }
                Response.ContentType = "text/xml";
                Response.Write(xml.OuterXml);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                Response.Write(ex.Message);
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            // 07/11/2006 Paul.  Users must be able to view and edit their own settings.
            this.Visible = bMyAccount || SplendidCRM.Security.IS_ADMIN;              //(SplendidCRM.Security.GetUserAccess(m_sMODULE, "view") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                if (bMyAccount)
                {
                    // 11/19/2005 Paul.  SugarCRM 3.5.0 allows administrator to duplicate itself.
                    btnDuplicate.Visible = Security.IS_ADMIN;
                    gID = Security.USER_ID;
                }
                ctlAccessView.USER_ID = gID;

                // 12/06/2005 Paul.  The password button is only visible if not windows authentication or Admin.
                // The reason to allow the admin to change a password is so that the admin can prepare to turn off windows authentication.
                btnChangePassword.Visible = !Security.IsWindowsAuthentication() || Security.IS_ADMIN;
                btnReset.Visible          = Security.IS_ADMIN;
                if (!Sql.IsEmptyString(txtNEW_PASSWORD.Value))
                {
                    bool bValidOldPassword = false;
                    if (!Security.IS_ADMIN)
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            // 07/17/2006 Paul.  The USER_HASH has been removed from the main vwUSERS view to prevent its use in reports.
                            sSQL = "select *                     " + ControlChars.CrLf
                                   + "  from vwUSERS_Login         " + ControlChars.CrLf
                                   + " where ID        = @ID       " + ControlChars.CrLf
                                   + "   and USER_HASH = @USER_HASH" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Sql.AddParameter(cmd, "@ID", gID);
                                Sql.AddParameter(cmd, "@USER_HASH", Security.HashPassword(txtOLD_PASSWORD.Value));
                                con.Open();
                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        bValidOldPassword = true;
                                    }
                                }
                            }
                        }
                        if (!bValidOldPassword)
                        {
                            lblError.Text = L10n.Term("Users.ERR_PASSWORD_INCORRECT_OLD");
                        }
                    }
                    if (bValidOldPassword || Security.IS_ADMIN)
                    {
                        if (txtNEW_PASSWORD.Value == txtCONFIRM_PASSWORD.Value)
                        {
                            SqlProcs.spUSERS_PasswordUpdate(gID, Security.HashPassword(txtNEW_PASSWORD.Value));
                            if (bMyAccount)
                            {
                                Response.Redirect("MyAccount.aspx");
                            }
                            else
                            {
                                Response.Redirect("view.aspx?ID=" + gID.ToString());
                            }
                        }
                        else
                        {
                            lblError.Text = L10n.Term("Users.ERR_REENTER_PASSWORDS");
                        }
                    }
                }
                if (!IsPostBack)
                {
                    // 05/09/2006 Paul.  We need to always initialize the separators, just in case the user is new.
                    txtGROUP_SEPARATOR.Text   = SplendidDefaults.GroupSeparator();
                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();
                    if (!Sql.IsEmptyGuid(gID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwUSERS_Edit" + ControlChars.CrLf
                                   + " where ID = @ID    " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Sql.AddParameter(cmd, "@ID", gID);
                                con.Open();

                                if (bDebug)
                                {
                                    RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                                }

                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["FULL_NAME"]) + " (" + Sql.ToString(rdr["USER_NAME"]) + ")";
                                        SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);

                                        // main
                                        txtNAME.Text      = Sql.ToString(rdr["FULL_NAME"]);
                                        txtUSER_NAME.Text = Sql.ToString(rdr["USER_NAME"]);
                                        txtSTATUS.Text    = Sql.ToString(L10n.Term(".user_status_dom.", rdr["STATUS"]));
                                        // user_settings
                                        chkIS_ADMIN.Checked              = Sql.ToBoolean(rdr["IS_ADMIN"]);
                                        chkPORTAL_ONLY.Checked           = Sql.ToBoolean(rdr["PORTAL_ONLY"]);
                                        chkRECEIVE_NOTIFICATIONS.Checked = Sql.ToBoolean(rdr["RECEIVE_NOTIFICATIONS"]);

                                        this.AppendDetailViewFields(m_sMODULE + ".DetailView", tblMain, rdr);
                                        // 08/05/2006 Paul.  MailOptions are populated manually.
                                        this.AppendDetailViewFields(m_sMODULE + ".MailOptions", tblMailOptions, null);
                                        // 01/20/2008 Paul.  The mail options panel is manually populated.
                                        new DynamicControl(this, "EMAIL1").Text = Sql.ToString(rdr["EMAIL1"]);
                                        new DynamicControl(this, "EMAIL2").Text = Sql.ToString(rdr["EMAIL2"]);

                                        string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]);
                                        if (!Sql.IsEmptyString(sUSER_PREFERENCES))
                                        {
                                            XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES);
                                            try
                                            {
                                                // user_settings
                                                txtLANGUAGE.Text = L10N.NormalizeCulture(XmlUtil.SelectSingleNode(xml, "culture"));
                                                try
                                                {
                                                    DataView vwLanguages = new DataView(SplendidCache.Languages());
                                                    vwLanguages.RowFilter = "NAME = '" + txtLANGUAGE.Text + "'";
                                                    if (vwLanguages.Count > 0)
                                                    {
                                                        txtLANGUAGE.Text = Sql.ToString(vwLanguages[0]["NATIVE_NAME"]);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                txtDATEFORMAT.Text = XmlUtil.SelectSingleNode(xml, "dateformat");
                                                txtTIMEFORMAT.Text = XmlUtil.SelectSingleNode(xml, "timeformat");
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Show Gridline is not supported at this time.
                                                //chkGRIDLINE             .Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "gridline"             ));
                                                // mail_options
                                                new DynamicControl(this, "MAIL_FROMNAME").Text        = XmlUtil.SelectSingleNode(xml, "mail_fromname");
                                                new DynamicControl(this, "MAIL_FROMADDRESS").Text     = XmlUtil.SelectSingleNode(xml, "mail_fromaddress");
                                                new DynamicControl(this, "MAIL_SENDTYPE").Text        = XmlUtil.SelectSingleNode(xml, "mail_sendtype");
                                                new DynamicControl(this, "MAIL_SMTPSERVER").Text      = XmlUtil.SelectSingleNode(xml, "mail_smtpserver");
                                                new DynamicControl(this, "MAIL_SMTPPORT").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpport");
                                                new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "mail_smtpauth_req"));
                                                new DynamicControl(this, "MAIL_SMTPUSER").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpuser");
                                                // freebusy
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Calendar Publish Key is not supported at this time.
                                                //txtCALENDAR_PUBLISH_KEY .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_key" );
                                                //txtCALENDAR_PUBLISH_URL .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_url" );
                                                //txtCALENDAR_SEARCH_URL  .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_search_url"  );

                                                // 05/09/2006 Paul.  Initialize the numeric separators.
                                                txtGROUP_SEPARATOR.Text   = XmlUtil.SelectSingleNode(xml, "num_grp_sep");
                                                txtDECIMAL_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "dec_sep");
                                                // 05/09/2006 Paul.  Check for empty strings as the user may have legacy data.
                                                if (Sql.IsEmptyString(txtGROUP_SEPARATOR.Text))
                                                {
                                                    txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator();
                                                }
                                                if (Sql.IsEmptyString(txtDECIMAL_SEPARATOR.Text))
                                                {
                                                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();
                                                }

                                                string   sTIMEZONE   = XmlUtil.SelectSingleNode(xml, "timezone");
                                                DataView vwTimezones = new DataView(SplendidCache.Timezones());
                                                vwTimezones.RowFilter = "ID = '" + sTIMEZONE + "'";
                                                if (vwTimezones.Count > 0)
                                                {
                                                    txtTIMEZONE.Text = Sql.ToString(vwTimezones[0]["NAME"]);
                                                }

                                                string   sCURRENCY    = XmlUtil.SelectSingleNode(xml, "currency_id");
                                                DataView vwCurrencies = new DataView(SplendidCache.Currencies());
                                                vwCurrencies.RowFilter = "ID = '" + sCURRENCY + "'";
                                                if (vwCurrencies.Count > 0)
                                                {
                                                    txtCURRENCY.Text = Sql.ToString(vwCurrencies[0]["NAME_SYMBOL"]);
                                                }
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.

                                                /*
                                                 * try
                                                 * {
                                                 *      int nREMINDER_TIME = Sql.ToInteger(XmlUtil.SelectSingleNode(xml, "reminder_time"));
                                                 *      if ( nREMINDER_TIME > 0 )
                                                 *      {
                                                 *              txtREMINDER_TIME.Text = L10n.Term(".reminder_time_options." + nREMINDER_TIME.ToString());
                                                 *              chkREMINDER.Checked = true;
                                                 *      }
                                                 * }
                                                 * catch(Exception ex)
                                                 * {
                                                 *      SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                 * }
                                                 */
                                            }
                                            catch (Exception ex)
                                            {
                                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                            }
                                        }
                                        //txtDESCRIPTION.Text = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("YToxODp7czo4OiJncmlkbGluZSI7czozOiJvZmYiO3M6ODoibWF4X3RhYnMiO3M6MjoiMTIiO3M6MTI6ImRpc3BsYXlfdGFicyI7YToxNTp7aTowO3M6NDoiSG9tZSI7aToxO3M6NzoiaUZyYW1lcyI7aToyO3M6ODoiQ2FsZW5kYXIiO2k6MztzOjEwOiJBY3Rpdml0aWVzIjtpOjQ7czo4OiJBY2NvdW50cyI7aTo1O3M6NToiTGVhZHMiO2k6NjtzOjEzOiJPcHBvcnR1bml0aWVzIjtpOjc7czo1OiJDYXNlcyI7aTo4O3M6NDoiQnVncyI7aTo5O3M6OToiRG9jdW1lbnRzIjtpOjEwO3M6NjoiRW1haWxzIjtpOjExO3M6OToiQ2FtcGFpZ25zIjtpOjEyO3M6NzoiUHJvamVjdCI7aToxMztzOjU6IkZlZWRzIjtpOjE0O3M6OToiRGFzaGJvYXJkIjt9czoxMzoicmVtaW5kZXJfdGltZSI7czozOiI5MDAiO3M6NToidGltZWYiO3M6MzoiSDppIjtzOjg6ImN1cnJlbmN5IjtzOjM6Ii05OSI7czo1OiJkYXRlZiI7czo1OiJZLW0tZCI7czo1OiJ0aW1leiI7czoxOiIwIjtzOjEzOiJtYWlsX2Zyb21uYW1lIjtzOjQ6IlBhdWwiO3M6MTY6Im1haWxfZnJvbWFkZHJlc3MiO3M6MTM6InBhdWxAcm9ueS5jb20iO3M6MTM6Im1haWxfc2VuZHR5cGUiO3M6NDoiU01UUCI7czoxNToibWFpbF9zbXRwc2VydmVyIjtzOjM6Im5zMSI7czoxMzoibWFpbF9zbXRwcG9ydCI7czoyOiIyMyI7czoxMzoibWFpbF9zbXRwdXNlciI7czo4OiJwYXVscm9ueSI7czoxMzoibWFpbF9zbXRwcGFzcyI7czo3OiJwb2NrZXQxIjtzOjE3OiJtYWlsX3NtdHBhdXRoX3JlcSI7czowOiIiO3M6MTY6Im1haWxfcG9wYXV0aF9yZXEiO3M6MDoiIjtzOjIwOiJjYWxlbmRhcl9wdWJsaXNoX2tleSI7czoxMToicHVibGlzaCBoZXkiO30="));
                                    }
                                }
                            }
                        }
                    }
                }
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                lblError.Text = ex.Message;
            }
        }
Exemplo n.º 7
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            // 07/11/2006 Paul.  Users must be able to view and edit their own settings.
            this.Visible = bMyAccount || SplendidCRM.Security.IS_ADMIN;              //(SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            reqUSER_NAME.DataBind();
            reqLAST_NAME.DataBind();
            try
            {
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
                gID = Sql.ToGuid(Request["ID"]);
                if (bMyAccount)
                {
                    gID = Security.USER_ID;
                }
                // 07/12/2006 Paul.  Status can only be edited by an administrator.
                lstSTATUS.Enabled = false;
                // 12/06/2005 Paul.  A user can only edit his own user name if Windows Authentication is off.
                if (Security.IS_ADMIN)
                {
                    // 12/06/2005 Paul.  An administrator can always edit the user name.  This is to allow him to pre-add any NTLM users.
                    txtUSER_NAME.Enabled = true;
                    lstSTATUS.Enabled    = true;
                }
                else if (gID == Security.USER_ID)
                {
                    // 12/06/2005 Paul.  If editing yourself, then you can only edit if not NTLM.
                    // txtUSER_NAME.Enabled = !Security.IsWindowsAuthentication();
                    // 11/26/2006 Paul.  A user cannot edit their own user name. This is a job for the admin.
                    txtUSER_NAME.Enabled = false;
                }
                else
                {
                    // 12/06/2005 Paul.  If not an administrator and not editing yourself, then the name cannot be edited.
                    txtUSER_NAME.Enabled = false;
                }

                if (!IsPostBack)
                {
                    // 'date_formats' => array('Y-m-d'=>'2006-12-23', 'm-d-Y'=>'12-23-2006', 'Y/m/d'=>'2006/12/23', 'm/d/Y'=>'12/23/2006')
                    // 'time_formats' => array('H:i'=>'23:00', 'h:ia'=>'11:00pm', 'h:iA'=>'11:00PM', 'H.i'=>'23.00', 'h.ia'=>'11.00pm', 'h.iA'=>'11.00PM' )
                    lstSTATUS.DataSource = SplendidCache.List("user_status_dom");
                    lstSTATUS.DataBind();
                    // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.
                    //lstREMINDER_TIME  .DataSource = SplendidCache.List("reminder_time_dom");
                    //lstREMINDER_TIME  .DataBind();
                    lstTIMEZONE.DataSource = SplendidCache.TimezonesListbox();
                    lstTIMEZONE.DataBind();
                    lstCURRENCY.DataSource = SplendidCache.Currencies();
                    lstCURRENCY.DataBind();
                    // 05/09/2006 Paul.  We need to always initialize the separators, just in case the user is new.
                    txtGROUP_SEPARATOR.Text   = SplendidDefaults.GroupSeparator();
                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();

                    lstLANGUAGE.DataSource = SplendidCache.Languages();
                    lstLANGUAGE.DataBind();
                    lstLANGUAGE_Changed(null, null);
                    lstTHEME.DataSource = SplendidCache.Themes();
                    lstTHEME.DataBind();

                    Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                    if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwUSERS_Edit" + ControlChars.CrLf
                                   + " where ID = @ID    " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                if (!Sql.IsEmptyGuid(gDuplicateID))
                                {
                                    Sql.AddParameter(cmd, "@ID", gDuplicateID);
                                    gID = Guid.Empty;
                                }
                                else
                                {
                                    Sql.AddParameter(cmd, "@ID", gID);
                                }
                                con.Open();

                                if (bDebug)
                                {
                                    RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                                }

                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["FULL_NAME"]);
                                        SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title + " (" + Sql.ToString(rdr["USER_NAME"]) + ")");
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;

                                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, rdr);
                                        // 08/05/2006 Paul.  Use the dynamic grid to create the fields, but populate manually.
                                        this.AppendEditViewFields(m_sMODULE + ".EditMailOptions", tblMailOptions, null);
                                        // 01/20/2008 Paul.  The mail options panel is manually populated.
                                        new DynamicControl(this, "EMAIL1").Text = Sql.ToString(rdr["EMAIL1"]);
                                        new DynamicControl(this, "EMAIL2").Text = Sql.ToString(rdr["EMAIL2"]);

                                        // main
                                        txtUSER_NAME.Text  = Sql.ToString(rdr["USER_NAME"]);
                                        txtFIRST_NAME.Text = Sql.ToString(rdr["FIRST_NAME"]);
                                        txtLAST_NAME.Text  = Sql.ToString(rdr["LAST_NAME"]);
                                        // user_settings
                                        chkIS_ADMIN.Checked              = Sql.ToBoolean(rdr["IS_ADMIN"]);
                                        chkPORTAL_ONLY.Checked           = Sql.ToBoolean(rdr["PORTAL_ONLY"]);
                                        chkRECEIVE_NOTIFICATIONS.Checked = Sql.ToBoolean(rdr["RECEIVE_NOTIFICATIONS"]);
                                        // 12/04/2005 Paul.  Only allow the admin flag to be changed if the current user is an admin.
                                        chkIS_ADMIN.Enabled = Security.IS_ADMIN;
                                        // 12/04/2005 Paul.  Save admin flag in ViewState to prevent hacking.
                                        ViewState["IS_ADMIN"] = Sql.ToBoolean(rdr["IS_ADMIN"]);

                                        try
                                        {
                                            lstSTATUS.SelectedValue = Sql.ToString(rdr["STATUS"]);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                        }

                                        string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]);
                                        if (!Sql.IsEmptyString(sUSER_PREFERENCES))
                                        {
                                            XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES);
                                            try
                                            {
                                                ViewState["USER_PREFERENCES"] = xml.OuterXml;
                                                // user_settings
                                                chkGRIDLINE.Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "gridline"));
                                                try
                                                {
                                                    lstLANGUAGE.SelectedValue = L10N.NormalizeCulture(XmlUtil.SelectSingleNode(xml, "culture"));
                                                    lstLANGUAGE_Changed(null, null);
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstLANGUAGE.SelectedValue = XmlUtil.SelectSingleNode(xml, "theme");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstDATE_FORMAT.SelectedValue = XmlUtil.SelectSingleNode(xml, "dateformat");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstTIME_FORMAT.SelectedValue = XmlUtil.SelectSingleNode(xml, "timeformat");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstTIMEZONE.SelectedValue = XmlUtil.SelectSingleNode(xml, "timezone");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstCURRENCY.SelectedValue = XmlUtil.SelectSingleNode(xml, "currency_id");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }

                                                // mail_options
                                                new DynamicControl(this, "MAIL_FROMNAME").Text        = XmlUtil.SelectSingleNode(xml, "mail_fromname");
                                                new DynamicControl(this, "MAIL_FROMADDRESS").Text     = XmlUtil.SelectSingleNode(xml, "mail_fromaddress");
                                                new DynamicControl(this, "MAIL_SENDTYPE").Text        = XmlUtil.SelectSingleNode(xml, "mail_sendtype");
                                                new DynamicControl(this, "MAIL_SMTPSERVER").Text      = XmlUtil.SelectSingleNode(xml, "mail_smtpserver");
                                                new DynamicControl(this, "MAIL_SMTPPORT").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpport");
                                                new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "mail_smtpauth_req"));
                                                new DynamicControl(this, "MAIL_SMTPUSER").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpuser");
                                                new DynamicControl(this, "MAIL_SMTPPASS").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtppass");

                                                ViewState["mail_smtppass"] = XmlUtil.SelectSingleNode(xml, "mail_smtppass");
                                                // 08/06/2005 Paul.  Never return password to user.
                                                TextBox txtMAIL_SMTPPASS = FindControl("MAIL_SMTPPASS") as TextBox;
                                                if (txtMAIL_SMTPPASS != null)
                                                {
                                                    if (!Sql.IsEmptyString(txtMAIL_SMTPPASS.Text))
                                                    {
                                                        txtMAIL_SMTPPASS.Text = sEMPTY_PASSWORD;
                                                    }
                                                }

                                                // 05/09/2006 Paul.  Initialize the numeric separators.
                                                txtGROUP_SEPARATOR.Text   = XmlUtil.SelectSingleNode(xml, "num_grp_sep");
                                                txtDECIMAL_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "dec_sep");
                                                // 05/09/2006 Paul.  Check for empty strings as the user may have legacy data.
                                                if (Sql.IsEmptyString(txtGROUP_SEPARATOR.Text))
                                                {
                                                    txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator();
                                                }
                                                if (Sql.IsEmptyString(txtDECIMAL_SEPARATOR.Text))
                                                {
                                                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();
                                                }

                                                // freebusy
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Calendar Publish Key is not supported at this time.
                                                //txtCALENDAR_PUBLISH_KEY .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_key" );
                                                //txtCALENDAR_PUBLISH_URL .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_url" );
                                                //txtCALENDAR_SEARCH_URL  .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_search_url"  );
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.

                                                /*
                                                 * try
                                                 * {
                                                 *      int nREMINDER_TIME = Sql.ToInteger(XmlUtil.SelectSingleNode(xml, "reminder_time"));
                                                 *      if ( nREMINDER_TIME > 0 )
                                                 *      {
                                                 *              lstREMINDER_TIME.SelectedValue = nREMINDER_TIME.ToString();
                                                 *              chkSHOULD_REMIND.Checked = true;
                                                 *      }
                                                 * }
                                                 * catch(Exception ex)
                                                 * {
                                                 *      SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                 * }
                                                 */
                                            }
                                            catch (Exception ex)
                                            {
                                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditMailOptions", tblMailOptions, null);

                        try
                        {
                            lstTHEME.SelectedValue = SplendidDefaults.Theme();
                        }
                        catch (Exception ex)
                        {
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                        }
                        try
                        {
                            string sDefaultLanguage = Sql.ToString(Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"]);
                            if (Sql.IsEmptyString(sDefaultLanguage))
                            {
                                sDefaultLanguage = "en-US";
                            }
                            lstLANGUAGE.SelectedValue = sDefaultLanguage;
                        }
                        catch (Exception ex)
                        {
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                        }
                        lstLANGUAGE_Changed(null, null);
                    }
                }
                else
                {
                    // 12/02/2005 Paul.  When validation fails, the header title does not retain its value.  Update manually.
                    ctlModuleHeader.Title = Sql.ToString(ViewState["ctlModuleHeader.Title"]);
                    SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
Exemplo n.º 8
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                // 09/15/2005 Paul.  Values will always be in the query string.
                int      nCHART_LENGTH = Sql.ToInteger(Request.QueryString["CHART_LENGTH"]);
                DateTime dtDATE_START  = T10n.ToServerTime(Sql.ToDateTime(Request.QueryString["DATE_START"]));
                DateTime dtDATE_END    = T10n.ToServerTime(Sql.ToDateTime(Request.QueryString["DATE_END"]));
                if (dtDATE_START == DateTime.MinValue)
                {
                    // 09/14/2005 Paul.  SugarCRM uses a max date of 01/01/2100.
                    dtDATE_START = DateTime.Today;
                }
                if (dtDATE_END == DateTime.MinValue)
                {
                    // 09/14/2005 Paul.  SugarCRM uses a max date of 01/01/2100.
                    dtDATE_END = new DateTime(2100, 1, 1);
                }
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrASSIGNED_USER_ID = Request.QueryString.GetValues("ASSIGNED_USER_ID");
                // 09/15/2005 Paul.  Values will always be in the query string.
                string[] arrSALES_STAGE = Request.QueryString.GetValues("SALES_STAGE");

                xml.LoadXml(SplendidCache.XmlFile(Server.MapPath(Session["themeURL"] + "BarChart.xml")));
                XmlNode nodeRoot        = xml.SelectSingleNode("graphData");
                XmlNode nodeXData       = xml.CreateElement("xData");
                XmlNode nodeYData       = xml.CreateElement("yData");
                XmlNode nodeColorLegend = xml.CreateElement("colorLegend");
                XmlNode nodeGraphInfo   = xml.CreateElement("graphInfo");
                XmlNode nodeChartColors = nodeRoot.SelectSingleNode("chartColors");

                nodeRoot.InsertBefore(nodeGraphInfo, nodeChartColors);
                nodeRoot.InsertBefore(nodeColorLegend, nodeGraphInfo);
                nodeRoot.InsertBefore(nodeXData, nodeColorLegend);
                nodeRoot.InsertBefore(nodeYData, nodeXData);

                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "defaultAltText", L10n.Term("Dashboard.LBL_ROLLOVER_DETAILS"));
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "min", "0");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", "0");
                if (nCHART_LENGTH < 4)
                {
                    nCHART_LENGTH = 4;
                }
                else if (nCHART_LENGTH > 10)
                {
                    nCHART_LENGTH = 10;
                }
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "length", nCHART_LENGTH.ToString());
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "prefix", Sql.ToString(Session["USER_SETTINGS/CURRENCY_SYMBOL"]));
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "suffix", "");

                nodeGraphInfo.InnerText = L10n.Term("Dashboard.LBL_DATE_RANGE") + " " + Sql.ToDateString(T10n.FromServerTime(dtDATE_START)) + " " + L10n.Term("Dashboard.LBL_DATE_RANGE_TO") + Sql.ToDateString(T10n.FromServerTime(dtDATE_END)) + "<BR/>"
                                          + L10n.Term("Dashboard.LBL_OPP_SIZE") + " " + Strings.FormatCurrency(1, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS");

                Hashtable         hashUSER = new Hashtable();
                DbProviderFactory dbf      = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string sSQL;
                    // 09/19/2005 Paul.  Prepopulate the stage rows so that empty rows will appear.  The SQL query will not return empty rows.
                    if (arrSALES_STAGE != null)
                    {
                        foreach (string sSALES_STAGE in arrSALES_STAGE)
                        {
                            XmlNode nodeRow = xml.CreateElement("dataRow");
                            nodeYData.AppendChild(nodeRow);
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", Sql.ToString(L10n.Term(".sales_stage_dom.", sSALES_STAGE)));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", "0");
                        }
                    }
                    // 09/19/2005 Paul.  Prepopulate the user key with all the users specified.
                    if (arrASSIGNED_USER_ID != null)
                    {
                        sSQL = "select ID          " + ControlChars.CrLf
                               + "     , USER_NAME   " + ControlChars.CrLf
                               + "  from vwUSERS_List" + ControlChars.CrLf
                               + " where 1 = 1       " + ControlChars.CrLf;
                        using (IDbCommand cmd = con.CreateCommand())
                        {
                            cmd.CommandText = sSQL;
                            Sql.AppendGuids(cmd, arrASSIGNED_USER_ID, "ID");
                            cmd.CommandText += " order by USER_NAME" + ControlChars.CrLf;
                            using (IDataReader rdr = cmd.ExecuteReader())
                            {
                                while (rdr.Read())
                                {
                                    Guid   gUSER_ID   = Sql.ToGuid(rdr["ID"]);
                                    string sUSER_NAME = Sql.ToString(rdr["USER_NAME"]);
                                    if (!hashUSER.ContainsKey(gUSER_ID.ToString()))
                                    {
                                        XmlNode nodeMapping = xml.CreateElement("mapping");
                                        nodeColorLegend.AppendChild(nodeMapping);
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "id", gUSER_ID.ToString());
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", sUSER_NAME);
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "color", SplendidDefaults.generate_graphcolor(gUSER_ID.ToString(), hashUSER.Count));
                                        hashUSER.Add(gUSER_ID.ToString(), sUSER_NAME);
                                    }
                                }
                            }
                        }
                    }
                    sSQL = "select SALES_STAGE                                   " + ControlChars.CrLf
                           + "     , ASSIGNED_USER_ID                              " + ControlChars.CrLf
                           + "     , USER_NAME                                     " + ControlChars.CrLf
                           + "     , LIST_ORDER                                    " + ControlChars.CrLf
                           + "     , sum(AMOUNT_USDOLLAR/1000) as TOTAL            " + ControlChars.CrLf
                           + "     , count(*)                  as OPPORTUNITY_COUNT" + ControlChars.CrLf
                           + "  from vwOPPORTUNITIES_Pipeline                      " + ControlChars.CrLf
                           + " where DATE_CLOSED >= @DATE_START                    " + ControlChars.CrLf
                           + "   and DATE_CLOSED <= @DATE_END                      " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        // 09/14/2005 Paul.  Use add because <= and >= are not supported.
                        Sql.AddParameter(cmd, "@DATE_START", dtDATE_START);
                        Sql.AddParameter(cmd, "@DATE_END", dtDATE_END);
                        // 09/14/2005 Paul.  Use append because it supports arrays using the IN clause.
                        Sql.AppendGuids(cmd, arrASSIGNED_USER_ID, "ASSIGNED_USER_ID");
                        Sql.AppendParameter(cmd, arrSALES_STAGE, "SALES_STAGE");
#if false
                        if (arrSALES_STAGE != null)
                        {
                            nodeGraphInfo.InnerText = "SALES_STAGE = " + String.Join(", ", arrSALES_STAGE);
                        }
#endif

                        cmd.CommandText += ""
                                           + " group by SALES_STAGE                                " + ControlChars.CrLf
                                           + "        , LIST_ORDER                                 " + ControlChars.CrLf
                                           + "        , ASSIGNED_USER_ID                           " + ControlChars.CrLf
                                           + "        , USER_NAME                                  " + ControlChars.CrLf
                                           + " order by LIST_ORDER                                 " + ControlChars.CrLf
                                           + "        , USER_NAME                                  " + ControlChars.CrLf;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            double dMAX_TOTAL      = 0;
                            double dPIPELINE_TOTAL = 0;
                            while (rdr.Read())
                            {
                                string sSALES_STAGE       = Sql.ToString(rdr["SALES_STAGE"]);
                                double dTOTAL             = Sql.ToDouble(rdr["TOTAL"]);
                                int    nOPPORTUNITY_COUNT = Sql.ToInteger(rdr["OPPORTUNITY_COUNT"]);
                                Guid   gASSIGNED_USER_ID  = Sql.ToGuid(rdr["ASSIGNED_USER_ID"]);
                                string sUSER_NAME         = Sql.ToString(rdr["USER_NAME"]);

                                dPIPELINE_TOTAL += dTOTAL;
                                if (dTOTAL > dMAX_TOTAL)
                                {
                                    dMAX_TOTAL = dTOTAL;
                                }
                                XmlNode nodeRow = nodeYData.SelectSingleNode("dataRow[@title=\'" + Sql.ToString(L10n.Term(".sales_stage_dom.", sSALES_STAGE)).Replace("'", "\'") + "\']");
                                if (nodeRow == null)
                                {
                                    nodeRow = xml.CreateElement("dataRow");
                                    nodeYData.AppendChild(nodeRow);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", Sql.ToString(L10n.Term(".sales_stage_dom.", sSALES_STAGE)));
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", dTOTAL.ToString("0"));
                                }
                                else
                                {
                                    if (nodeRow.Attributes.GetNamedItem("endLabel") != null)
                                    {
                                        double dEND_LABEL = Sql.ToDouble(nodeRow.Attributes.GetNamedItem("endLabel").Value);
                                        dEND_LABEL += dTOTAL;
                                        if (dEND_LABEL > dMAX_TOTAL)
                                        {
                                            dMAX_TOTAL = dEND_LABEL;
                                        }
                                        XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", dEND_LABEL.ToString("0"));
                                    }
                                }

                                if (!hashUSER.ContainsKey(gASSIGNED_USER_ID.ToString()))
                                {
                                    XmlNode nodeMapping = xml.CreateElement("mapping");
                                    nodeColorLegend.AppendChild(nodeMapping);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "id", gASSIGNED_USER_ID.ToString());
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", sUSER_NAME);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "color", SplendidDefaults.generate_graphcolor(gASSIGNED_USER_ID.ToString(), hashUSER.Count));
                                    hashUSER.Add(gASSIGNED_USER_ID.ToString(), sUSER_NAME);
                                }

                                XmlNode nodeBar = xml.CreateElement("bar");
                                nodeRow.AppendChild(nodeBar);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "id", gASSIGNED_USER_ID.ToString());
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "totalSize", dTOTAL.ToString("0"));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "altText", sUSER_NAME + ": " + nOPPORTUNITY_COUNT.ToString() + " " + L10n.Term("Dashboard.LBL_OPPS_WORTH") + " " + dTOTAL.ToString("0") + L10n.Term("Dashboard.LBL_OPP_THOUSANDS") + " " + L10n.Term("Dashboard.LBL_OPPS_IN_STAGE") + " " + Sql.ToString(L10n.Term(".sales_stage_dom.", sSALES_STAGE)));
                                XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "url", Sql.ToString(Application["rootURL"]) + "Opportunities/default.aspx?SALES_STAGE=" + Server.UrlEncode(sSALES_STAGE) + "&ASSIGNED_USER_ID=" + gASSIGNED_USER_ID.ToString());
                            }
                            int    nNumLength   = Math.Floor(dMAX_TOTAL).ToString("0").Length - 1;
                            double dWhole       = Math.Pow(10, nNumLength);
                            double dDecimal     = 1 / dWhole;
                            double dMAX_ROUNDED = Math.Ceiling(dMAX_TOTAL * dDecimal) * dWhole;

                            XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", dMAX_ROUNDED.ToString("0"));
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "title", L10n.Term("Dashboard.LBL_TOTAL_PIPELINE") + Strings.FormatCurrency(dPIPELINE_TOTAL, 0, TriState.UseDefault, TriState.UseDefault, TriState.UseDefault) + L10n.Term("Dashboard.LBL_OPP_THOUSANDS"));
                        }
                    }
                }
                Response.ContentType = "text/xml";
                Response.Write(xml.OuterXml);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                Response.Write(ex.Message);
            }
        }
Exemplo n.º 9
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            XmlDocument xml = new XmlDocument();

            try
            {
                Guid gID = Sql.ToGuid(Request["ID"]);
                xml.LoadXml(SplendidCache.XmlFile(Server.MapPath(Session["themeURL"] + "BarChart.xml")));
                XmlNode nodeRoot        = xml.SelectSingleNode("graphData");
                XmlNode nodeXData       = xml.CreateElement("xData");
                XmlNode nodeYData       = xml.CreateElement("yData");
                XmlNode nodeColorLegend = xml.CreateElement("colorLegend");
                XmlNode nodeGraphInfo   = xml.CreateElement("graphInfo");
                XmlNode nodeChartColors = nodeRoot.SelectSingleNode("chartColors");

                nodeRoot.InsertBefore(nodeGraphInfo, nodeChartColors);
                nodeRoot.InsertBefore(nodeColorLegend, nodeGraphInfo);
                nodeRoot.InsertBefore(nodeXData, nodeColorLegend);
                nodeRoot.InsertBefore(nodeYData, nodeXData);

                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "min", "0");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", "80");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "length", "10");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "prefix", "");
                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "suffix", "");

                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "min", "0");
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "max", "10");
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "length", "10");
                XmlUtil.SetSingleNodeAttribute(xml, nodeYData, "defaultAltText", L10n.Term("Campaigns.LBL_ROLLOVER_VIEW"));

                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string    sSQL;
                    DataTable dtLegend = SplendidCache.List("roi_type_dom");
                    XmlUtil.SetSingleNodeAttribute(xml, nodeColorLegend, "status", "on");
                    for (int i = 0; i < dtLegend.Rows.Count; i++)
                    {
                        DataRow row         = dtLegend.Rows[i];
                        XmlNode nodeMapping = xml.CreateElement("mapping");
                        nodeColorLegend.AppendChild(nodeMapping);
                        XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "id", Sql.ToString(row["NAME"]));
                        XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "name", Sql.ToString(row["DISPLAY_NAME"]));
                        XmlUtil.SetSingleNodeAttribute(xml, nodeMapping, "color", SplendidDefaults.generate_graphcolor(String.Empty, i));
                    }

                    sSQL = "select *              " + ControlChars.CrLf
                           + "  from vwCAMPAIGNS_Roi" + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        Security.Filter(cmd, "Campaigns", "view");
                        Sql.AppendParameter(cmd, gID, "ID", false);
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            if (rdr.Read())
                            {
                                double    dBUDGET           = 0.0;
                                double    dEXPECTED_REVENUE = 0.0;
                                double    dINVESTMENT       = 0.0;
                                double    dREVENUE          = 0.0;
                                Hashtable hashTOTALS        = new Hashtable();
                                try
                                {
                                    dBUDGET           = Sql.ToDouble(rdr["BUDGET"]);
                                    dEXPECTED_REVENUE = Sql.ToDouble(rdr["EXPECTED_REVENUE"]);
                                    dINVESTMENT       = Sql.ToDouble(rdr["ACTUAL_COST"]);
                                    dREVENUE          = Sql.ToDouble(rdr["REVENUE"]);
                                    hashTOTALS.Add("Budget", dBUDGET);
                                    hashTOTALS.Add("Expected_Revenue", dEXPECTED_REVENUE);
                                    hashTOTALS.Add("Investment", dINVESTMENT);
                                    hashTOTALS.Add("Revenue", dREVENUE);
                                }
                                catch (Exception ex)
                                {
                                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                }
                                foreach (DataRow row in dtLegend.Rows)
                                {
                                    string  sNAME         = Sql.ToString(row["NAME"]);
                                    string  sDISPLAY_NAME = Sql.ToString(row["DISPLAY_NAME"]);
                                    XmlNode nodeRow       = xml.CreateElement("dataRow");
                                    nodeYData.AppendChild(nodeRow);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "title", sDISPLAY_NAME);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeRow, "endLabel", sDISPLAY_NAME.Substring(0, 1));

                                    XmlNode nodeBar = xml.CreateElement("bar");
                                    nodeRow.AppendChild(nodeBar);
                                    double dTOTAL = Sql.ToDouble(hashTOTALS[sNAME]);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "id", sNAME);
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "totalSize", dTOTAL.ToString("0"));
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "altText", dTOTAL.ToString("0"));
                                    XmlUtil.SetSingleNodeAttribute(xml, nodeBar, "url", "#" + sNAME);
                                }

                                double dMAX = 0.0;
                                dMAX = Math.Max(dMAX, dREVENUE);
                                dMAX = Math.Max(dMAX, dINVESTMENT);
                                dMAX = Math.Max(dMAX, dBUDGET);
                                dMAX = Math.Max(dMAX, dEXPECTED_REVENUE);
                                dMAX = dMAX * 1.2;                                  // Increase by 20%.
                                if (dMAX <= 0.0)
                                {
                                    dMAX = 80.0;
                                }
                                double dMAX_ROUNDED = Math.Ceiling(dMAX);
                                XmlUtil.SetSingleNodeAttribute(xml, nodeXData, "max", dMAX_ROUNDED.ToString("0"));
                            }
                            XmlUtil.SetSingleNodeAttribute(xml, nodeRoot, "title", L10n.Term("Campaigns.LBL_CAMPAIGN_RETURN_ON_INVESTMENT") + "                                                                                                            ");
                        }
                    }
                }
                Response.ContentType = "text/xml";
                Response.Write(xml.OuterXml);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                Response.Write(ex.Message);
            }
        }