Beispiel #1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 06/04/2006 Paul.  NewRecord should not be displayed if the user does not have edit rights.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
            //this.DataBind();  // Need to bind so that Text of the Button gets updated.
            reqNAME.ErrorMessage       = L10n.Term(".ERR_MISSING_REQUIRED_FIELDS") + " " + L10n.Term("Meetings.LBL_LIST_SUBJECT") + "<br>";
            reqDATE_START.ErrorMessage = L10n.Term(".ERR_MISSING_REQUIRED_FIELDS") + " " + L10n.Term("Meetings.LBL_LIST_DATE") + "<br>";
            reqTIME_START.ErrorMessage = L10n.Term(".ERR_MISSING_REQUIRED_FIELDS") + " " + L10n.Term("Meetings.LBL_LIST_TIME") + "<br>";
            // 08/31/2006 Paul.  Need to bind the text.
            valDATE_START.ErrorMessage = L10n.Term(".ERR_INVALID_DATE") + "<br>";
            valTIME_START.ErrorMessage = L10n.Term(".ERR_INVALID_TIME") + "<br>";
            if (!IsPostBack)
            {
                DateTime dt1100PM = DateTime.Today.AddHours(23);
                lblDATEFORMAT.Text = "(" + Session["USER_SETTINGS/DATEFORMAT"] + ")";
                lblTIMEFORMAT.Text = "(" + dt1100PM.ToShortTimeString() + ")";

                DateTime dtNow = T10n.FromServerTime(DateTime.Now);
                ctlDATE_START.Value = dtNow;
                txtTIME_START.Text  = Sql.ToTimeString(dtNow);
            }
        }
Beispiel #2
0
 private void Page_Load(object sender, System.EventArgs e)
 {
     if (!IsPostBack)
     {
         lstSALES_STAGE.DataSource = SplendidCache.List("sales_stage_dom");
         lstSALES_STAGE.DataBind();
         lstUSERS.DataSource = SplendidCache.ActiveUsers();
         lstUSERS.DataBind();
         // 09/14/2005 Paul.  Default to today, and all sales stages.
         foreach (ListItem item in lstSALES_STAGE.Items)
         {
             item.Selected = true;
         }
         foreach (ListItem item in lstUSERS.Items)
         {
             item.Selected = true;
         }
         // 07/09/2006 Paul.  The date is passed as TimeZone time, so convert from server time.
         ctlDATE_START.Value = T10n.FromServerTime(DateTime.Today);
         ctlDATE_END.Value   = T10n.FromServerTime(new DateTime(2100, 1, 1));
         // 09/15/2005 Paul.  Maintain the pipeline query string separately so that we can respond to specific submit requests
         // and ignore all other control events on the page.
         ViewState["PipelineBySalesStageQueryString"] = PipelineQueryString();
     }
 }
Beispiel #3
0
        protected void lstLANGUAGE_Changed(Object sender, EventArgs e)
        {
            if (lstLANGUAGE.SelectedValue.Length > 0)
            {
                CultureInfo oldCulture   = Thread.CurrentThread.CurrentCulture;
                CultureInfo oldUICulture = Thread.CurrentThread.CurrentUICulture;
                Thread.CurrentThread.CurrentCulture   = CultureInfo.CreateSpecificCulture(lstLANGUAGE.SelectedValue);
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lstLANGUAGE.SelectedValue);

                DateTime           dtNow             = T10n.FromServerTime(DateTime.Now);
                DateTimeFormatInfo oDateInfo         = Thread.CurrentThread.CurrentCulture.DateTimeFormat;
                NumberFormatInfo   oNumberInfo       = Thread.CurrentThread.CurrentCulture.NumberFormat;
                String[]           aDateTimePatterns = oDateInfo.GetAllDateTimePatterns();

                lstDATE_FORMAT.Items.Clear();
                lstTIME_FORMAT.Items.Clear();
                foreach (string sPattern in aDateTimePatterns)
                {
                    // 11/12/2005 Paul.  Only allow patterns that have a full year.
                    if (sPattern.IndexOf("yyyy") >= 0 && sPattern.IndexOf("dd") >= 0 && sPattern.IndexOf("mm") < 0)
                    {
                        lstDATE_FORMAT.Items.Add(new ListItem(sPattern + "   " + dtNow.ToString(sPattern), sPattern));
                    }
                    if (sPattern.IndexOf("yy") < 0 && sPattern.IndexOf("mm") >= 0)
                    {
                        lstTIME_FORMAT.Items.Add(new ListItem(sPattern + "   " + dtNow.ToString(sPattern), sPattern));
                    }
                }
                Thread.CurrentThread.CurrentCulture = oldCulture;
                Thread.CurrentThread.CurrentCulture = oldUICulture;
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            // 11/05/2007 Paul.  Don't show panel if it was manually hidden.
            this.Visible = this.Visible && (SplendidCRM.Security.GetUserAccess(m_sMODULE, "list") >= 0);
            // 09/09/2007 Paul.  We are having trouble dynamically adding user controls to the WebPartZone.
            // Instead, control visibility manually here.  This approach as the added benefit of hiding the
            // control even if the WebPartManager has moved it to an alternate zone.
            if (this.Visible && this.Visible && !Sql.IsEmptyString(sDetailView))
            {
                // 01/17/2008 Paul.  We need to use the sDetailView property and not the hard-coded view name.
                DataView vwFields = new DataView(SplendidCache.DetailViewRelationships(sDetailView));
                vwFields.RowFilter = "CONTROL_NAME = '~/Opportunities/MyPipeline'";
                this.Visible       = vwFields.Count > 0;
            }
            if (!this.Visible)
            {
                return;
            }

            valDATE_START.ErrorMessage = L10n.Term(".ERR_INVALID_DATE");
            valDATE_END.ErrorMessage   = L10n.Term(".ERR_INVALID_DATE");
            if (!IsPostBack)
            {
                lstSALES_STAGE.DataSource = SplendidCache.List("sales_stage_dom");
                lstSALES_STAGE.DataBind();
                // 09/14/2005 Paul.  Default to today, and all sales stages.
                foreach (ListItem item in lstSALES_STAGE.Items)
                {
                    item.Selected = true;
                }
                // 07/09/2006 Paul.  The date is passed in TimeZone time, so convert from server time.
                ctlDATE_START.Value = T10n.FromServerTime(DateTime.Today);
                ctlDATE_END.Value   = T10n.FromServerTime(new DateTime(2100, 1, 1));
                // 09/15/2005 Paul.  Maintain the pipeline query string separately so that we can respond to specific submit requests
                // and ignore all other control events on the page.
                ViewState["MyPipelineQueryString"] = PipelineQueryString();
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            Utils.SetPageTitle(Page, 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.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                // 01/21/2006 Paul.  If there is an error sending the email, we want to make sure to reuse the ID,
                // otherwise multiple emails get created as the user tries to resend.
                gID = Sql.ToGuid(ViewState["ID"]);
                if (Sql.IsEmptyGuid(gID))
                {
                    gID = Sql.ToGuid(Request["ID"]);
                }
                if (!IsPostBack)
                {
                    sEMAIL_TYPE = Sql.ToString(Request["TYPE"]).ToLower();
                    if (sEMAIL_TYPE != "archived")
                    {
                        sEMAIL_TYPE = "draft";
                    }
                    ctlEditButtons.Visible  = !PrintView && (sEMAIL_TYPE != "draft");
                    ctlEmailButtons.Visible = !PrintView && (sEMAIL_TYPE == "draft");

                    if (Sql.IsEmptyGuid(gID))
                    {
                        ctlModuleHeader.EnableModuleLabel = false;
                        if (sEMAIL_TYPE == "archived")
                        {
                            ctlModuleHeader.Title = L10n.Term("Emails.LBL_ARCHIVED_MODULE_NAME") + ":";
                        }
                        else
                        {
                            ctlModuleHeader.Title = L10n.Term("Emails.LBL_COMPOSE_MODULE_NAME") + ":";
                        }
                        // 04/16/2006 Paul.  The subject is not required.
                        //lblNAME_REQUIRED .Visible = (sEMAIL_TYPE == "archived");
                        //reqNAME.Enabled          =  lblNAME_REQUIRED.Visible;
                        ctlDATE_START.Visible              = (sEMAIL_TYPE == "archived");
                        spnDATE_START.Visible              = ctlDATE_START.Visible;
                        spnTEMPLATE_LABEL.Visible          = (sEMAIL_TYPE == "draft");
                        lstEMAIL_TEMPLATE.Visible          = spnTEMPLATE_LABEL.Visible;
                        trNOTE_SEMICOLON.Visible           = (sEMAIL_TYPE == "draft");
                        trFROM.Visible                     = !trNOTE_SEMICOLON.Visible;
                        ViewState["TYPE"]                  = sEMAIL_TYPE;
                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;
                    }

                    lstASSIGNED_USER_ID.DataSource = SplendidCache.AssignedUser();
                    lstASSIGNED_USER_ID.DataBind();
                    lstASSIGNED_USER_ID.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
                    lstPARENT_TYPE.DataSource = SplendidCache.List("record_type_display");
                    lstPARENT_TYPE.DataBind();
                    if (lstEMAIL_TEMPLATE.Visible)
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *                     " + ControlChars.CrLf
                                   + "  from vwEMAIL_TEMPLATES_List" + ControlChars.CrLf
                                   + " order by NAME               " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    using (DataTable dt = new DataTable())
                                    {
                                        da.Fill(dt);
                                        lstEMAIL_TEMPLATE.DataSource = dt.DefaultView;
                                        lstEMAIL_TEMPLATE.DataBind();
                                        lstEMAIL_TEMPLATE.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
                                    }
                                }
                            }
                        }
                    }
                    // 07/29/2005 Paul.  SugarCRM 3.0 does not allow the NONE option.
                    //lstPARENT_TYPE     .Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
                    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 vwEMAILS_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 DEBUG
                                Page.RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
#endif
                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title += Sql.ToString(rdr["NAME"]);
                                        Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;
                                        ViewState["ID"] = gID;

                                        txtNAME.Text        = Sql.ToString(rdr["NAME"]);
                                        ctlDATE_START.Value = T10n.FromServerTime(rdr["DATE_START"]);
                                        txtPARENT_ID.Value  = Sql.ToString(rdr["PARENT_ID"]);
                                        txtPARENT_NAME.Text = Sql.ToString(rdr["PARENT_NAME"]);
                                        txtFROM_NAME.Value  = Sql.ToString(rdr["FROM_NAME"]);
                                        txtFROM_ADDR.Text   = Sql.ToString(rdr["FROM_ADDR"]);

                                        txtTO_ADDRS.Text          = Sql.ToString(rdr["TO_ADDRS"]);
                                        txtCC_ADDRS.Text          = Sql.ToString(rdr["CC_ADDRS"]);
                                        txtBCC_ADDRS.Text         = Sql.ToString(rdr["BCC_ADDRS"]);
                                        txtTO_ADDRS_IDS.Value     = Sql.ToString(rdr["TO_ADDRS_IDS"]);
                                        txtTO_ADDRS_NAMES.Value   = Sql.ToString(rdr["TO_ADDRS_NAMES"]);
                                        txtTO_ADDRS_EMAILS.Value  = Sql.ToString(rdr["TO_ADDRS_EMAILS"]);
                                        txtCC_ADDRS_IDS.Value     = Sql.ToString(rdr["CC_ADDRS_IDS"]);
                                        txtCC_ADDRS_NAMES.Value   = Sql.ToString(rdr["CC_ADDRS_NAMES"]);
                                        txtCC_ADDRS_EMAILS.Value  = Sql.ToString(rdr["CC_ADDRS_EMAILS"]);
                                        txtBCC_ADDRS_IDS.Value    = Sql.ToString(rdr["BCC_ADDRS_IDS"]);
                                        txtBCC_ADDRS_NAMES.Value  = Sql.ToString(rdr["BCC_ADDRS_NAMES"]);
                                        txtBCC_ADDRS_EMAILS.Value = Sql.ToString(rdr["BCC_ADDRS_EMAILS"]);

                                        // 04/16/2006 Paul.  Since the Plug-in saves body in DESCRIPTION, we need to continue to use it as the primary source of data.
                                        txtDESCRIPTION.Value = Sql.ToString(rdr["DESCRIPTION"]);
                                        try
                                        {
                                            lstPARENT_TYPE.SelectedValue = Sql.ToString(rdr["PARENT_TYPE"]);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex.Message);
                                        }
                                        try
                                        {
                                            lstASSIGNED_USER_ID.SelectedValue = Sql.ToString(rdr["ASSIGNED_USER_ID"]);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex.Message);
                                        }
                                        // 11/17/2005 Paul.  Archived emails allow editing of the Date & Time Sent.
                                        sEMAIL_TYPE = Sql.ToString(rdr["TYPE"]).ToLower();
                                        switch (sEMAIL_TYPE)
                                        {
                                        case "archived":
                                            ctlModuleHeader.Title = L10n.Term("Emails.LBL_ARCHIVED_MODULE_NAME") + ":" + txtNAME.Text;
                                            break;

                                        case "out":
                                            ctlModuleHeader.Title = L10n.Term("Emails.LBL_LIST_FORM_SENT_TITLE") + ":" + txtNAME.Text;
                                            break;

                                        default:
                                            sEMAIL_TYPE           = "draft";
                                            ctlModuleHeader.Title = L10n.Term("Emails.LBL_COMPOSE_MODULE_NAME") + ":" + txtNAME.Text;
                                            break;
                                        }
                                        if (sEMAIL_TYPE == "out")
                                        {
                                            // 01/21/2006 Paul.  Editing is not allowed for sent emails.
                                            Response.Redirect("view.aspx?ID=" + gID.ToString());
                                            return;
                                        }
                                        // 04/16/2006 Paul.  The subject is not required.
                                        //lblNAME_REQUIRED .Visible = (sEMAIL_TYPE == "archived");
                                        //reqNAME.Enabled = lblNAME_REQUIRED.Visible;
                                        ctlDATE_START.Visible             = (sEMAIL_TYPE == "archived");
                                        spnDATE_START.Visible             = ctlDATE_START.Visible;
                                        spnTEMPLATE_LABEL.Visible         = (sEMAIL_TYPE == "draft");
                                        lstEMAIL_TEMPLATE.Visible         = spnTEMPLATE_LABEL.Visible;
                                        trNOTE_SEMICOLON.Visible          = (sEMAIL_TYPE == "draft");
                                        trFROM.Visible                    = !trNOTE_SEMICOLON.Visible;
                                        ctlModuleHeader.EnableModuleLabel = false;

                                        ctlEditButtons.Visible  = !PrintView && (sEMAIL_TYPE != "draft");
                                        ctlEmailButtons.Visible = !PrintView && (sEMAIL_TYPE == "draft");
                                        ViewState["TYPE"]       = sEMAIL_TYPE;
                                    }
                                }
                            }
                            sSQL = "select *                   " + ControlChars.CrLf
                                   + "  from vwEMAILS_Attachments" + ControlChars.CrLf
                                   + " where EMAIL_ID = @EMAIL_ID" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Sql.AddParameter(cmd, "@EMAIL_ID", gID);
#if DEBUG
                                Page.RegisterClientScriptBlock("vwEMAILS_Attachments", Sql.ClientScriptBlock(cmd));
#endif
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    using (DataTable dt = new DataTable())
                                    {
                                        da.Fill(dt);
                                        ctlAttachments.DataSource = dt.DefaultView;
                                        ctlAttachments.DataBind();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Guid gPARENT_ID = Sql.ToGuid(Request["PARENT_ID"]);
                        if (!Sql.IsEmptyGuid(gPARENT_ID))
                        {
                            string sMODULE      = String.Empty;
                            string sPARENT_TYPE = String.Empty;
                            string sPARENT_NAME = String.Empty;
                            SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
                            if (!Sql.IsEmptyGuid(gPARENT_ID))
                            {
                                txtPARENT_ID.Value  = gPARENT_ID.ToString();
                                txtPARENT_NAME.Text = sPARENT_NAME;
                                try
                                {
                                    lstPARENT_TYPE.SelectedValue = sPARENT_TYPE;
                                }
                                catch (Exception ex)
                                {
                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex.Message);
                                }
                                // 08/05/2006 Paul.  When an email is composed from a Lead, automatically set the To address.
                                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                                using (IDbConnection con = dbf.CreateConnection())
                                {
                                    string sSQL;
                                    sSQL = "select EMAIL1      " + ControlChars.CrLf
                                           + "  from vwLEADS_Edit" + ControlChars.CrLf
                                           + " where ID = @ID    " + ControlChars.CrLf;
                                    using (IDbCommand cmd = con.CreateCommand())
                                    {
                                        cmd.CommandText = sSQL;
                                        Sql.AddParameter(cmd, "@ID", gPARENT_ID);
                                        con.Open();
#if DEBUG
                                        Page.RegisterClientScriptBlock("vwLEADS_Edit", Sql.ClientScriptBlock(cmd));
#endif
                                        using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                        {
                                            if (rdr.Read())
                                            {
                                                txtTO_ADDRS.Text = Sql.ToString(rdr["EMAIL1"]);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        try
                        {
                            lstASSIGNED_USER_ID.SelectedValue = Security.USER_ID.ToString();
                        }
                        catch (Exception ex)
                        {
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex.Message);
                        }
                    }
                }
                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"]);
                    Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                    sEMAIL_TYPE = Sql.ToString(ViewState["TYPE"]);
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                ctlEditButtons.ErrorText  = ex.Message;
                ctlEmailButtons.ErrorText = ex.Message;
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            Response.BufferOutput = true;
            SetPageTitle(L10n.Term("Schedulers.LBL_MODULE_TITLE"));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = SplendidCRM.Security.IS_ADMIN;
            if (!this.Visible)
            {
                return;
            }

            try
            {
                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    string sSQL;
                    sSQL = "select *               " + ControlChars.CrLf
                           + "     , '' as DATE_RANGE" + ControlChars.CrLf
                           + "  from vwSCHEDULERS    " + ControlChars.CrLf
                           + " where 1 = 1           " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;

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

                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using (DataTable dt = new DataTable())
                            {
                                da.Fill(dt);
                                foreach (DataRow row in dt.Rows)
                                {
                                    string   sJOB_INTERVAL     = Sql.ToString(row["JOB_INTERVAL"]);
                                    DateTime dtDATE_TIME_START = Sql.ToDateTime(row["DATE_TIME_START"]);
                                    DateTime dtDATE_TIME_END   = Sql.ToDateTime(row["DATE_TIME_END"]);
                                    DateTime dtLAST_RUN        = Sql.ToDateTime(row["LAST_RUN"]);
                                    row["JOB_INTERVAL"] = sJOB_INTERVAL + "<br>" + SchedulerUtils.CronDescription(L10n, sJOB_INTERVAL);
                                    if (dtDATE_TIME_START != DateTime.MinValue)
                                    {
                                        row["DATE_RANGE"] = T10n.FromServerTime(dtDATE_TIME_START).ToString() + "-";
                                    }
                                    if (dtDATE_TIME_END == DateTime.MinValue)
                                    {
                                        row["DATE_RANGE"] += L10n.Term("Schedulers.LBL_PERENNIAL");
                                    }
                                    else
                                    {
                                        row["DATE_RANGE"] += T10n.FromServerTime(dtDATE_TIME_END).ToString();
                                    }
                                    if (dtLAST_RUN != DateTime.MinValue)
                                    {
                                        row["LAST_RUN"] = T10n.FromServerTime(dtLAST_RUN);
                                    }
                                    row["STATUS"] = L10n.Term(".scheduler_status_dom.", row["STATUS"]);
                                }
                                vwMain             = dt.DefaultView;
                                grdMain.DataSource = vwMain;
                                if (!IsPostBack)
                                {
                                    grdMain.SortColumn = "NAME";
                                    grdMain.SortOrder  = "asc";
                                    grdMain.ApplySort();
                                    grdMain.DataBind();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                lblError.Text = ex.Message;
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE));
                if (!IsPostBack)
                {
                    lblDATEFORMAT.Text = "(" + Session["USER_SETTINGS/DATEFORMAT"] + ")";
                    lstOPPORTUNITY_SALES_STAGE.DataSource = SplendidCache.List("sales_stage_dom");
                    lstOPPORTUNITY_SALES_STAGE.DataBind();

                    chkCreateAccount.Attributes.Add("onclick", "return ToggleCreateAccount();");
                    chkCreateOpportunity.Attributes.Add("onclick", "return toggleDisplay('divCreateOpportunity');");
                    chkCreateAppointment.Attributes.Add("onclick", "return toggleDisplay('divCreateAppointment');");

                    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 vwLEADS_Convert" + 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 DEBUG
                                Page.RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
#endif
                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = L10n.Term("Leads.LBL_CONVERTLEAD");
                                        Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);

                                        txtACCOUNT_NAME.Text       = Sql.ToString(rdr["ACCOUNT_NAME"]);
                                        txtACCOUNT_PHONE_WORK.Text = Sql.ToString(rdr["PHONE_WORK"]);
                                        // 01/31/2006 Paul.  Default start date and time is now.
                                        ctlAPPOINTMENT_DATE_START.Value = T10n.FromServerTime(DateTime.Now);
                                        txtAPPOINTMENT_TIME_START.Text  = T10n.FromServerTime(DateTime.Now).ToShortTimeString();

                                        this.AppendEditViewFields(m_sMODULE + ".ConvertView", tblMain, rdr);
                                        // 01/31/2006 Paul.  Save all data to be used later.
                                        for (int i = 0; i < rdr.FieldCount; i++)
                                        {
                                            ViewState[rdr.GetName(i)] = rdr.GetValue(i);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".ConvertView", tblMain, null);
                    }
                }
                else
                {
                    // 12/02/2005 Paul.  When validation fails, the header title does not retain its value.  Update manually.
                    ctlModuleHeader.Title = L10n.Term("Leads.LBL_CONVERTLEAD");
                    Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                ctlEditButtons.ErrorText = 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);
            }
        }
Beispiel #9
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.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                if (!IsPostBack)
                {
                    Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                    if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            con.Open();
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwCALLS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                // 11/24/2006 Paul.  Use new Security.Filter() function to apply Team and ACL security rules.
                                Security.Filter(cmd, m_sMODULE, "edit");
                                if (!Sql.IsEmptyGuid(gDuplicateID))
                                {
                                    Sql.AppendParameter(cmd, gDuplicateID, "ID", false);
                                    gID = Guid.Empty;
                                }
                                else
                                {
                                    Sql.AppendParameter(cmd, gID, "ID", false);
                                }

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

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

                                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                                        // 07/12/2006 Paul.  Need to enable schedule updates.
                                        DateTimePicker ctlDATE_START = FindControl("DATE_START") as DateTimePicker;
                                        if (ctlDATE_START != null)
                                        {
                                            ctlDATE_START.Changed     += new System.EventHandler(this.Date_Changed);
                                            ctlDATE_START.AutoPostBack = true;
                                        }
                                        // 08/02/2005 Paul.  Set status to Held when closing from Home page.
                                        // 06/21/2006 Paul.  Change parameter to Close so that the same parameter can be used for Calls, Meetings and Tasks.
                                        if (Sql.ToString(Request["Status"]) == "Close")
                                        {
                                            new DynamicControl(this, "STATUS").SelectedValue = "Held";
                                        }
                                        else
                                        {
                                            new DynamicControl(this, "STATUS").SelectedValue = Sql.ToString(rdr["STATUS"]);
                                        }
                                        int nMinutes = Sql.ToInteger(rdr["DURATION_MINUTES"]);
                                        if (nMinutes <= 7)
                                        {
                                            new DynamicControl(this, "DURATION_MINUTES").SelectedValue = "00";
                                        }
                                        else if (nMinutes <= 15 + 7)
                                        {
                                            new DynamicControl(this, "DURATION_MINUTES").SelectedValue = "15";
                                        }
                                        else if (nMinutes <= 30 + 7)
                                        {
                                            new DynamicControl(this, "DURATION_MINUTES").SelectedValue = "30";
                                        }
                                        else
                                        {
                                            new DynamicControl(this, "DURATION_MINUTES").SelectedValue = "45";
                                        }
                                        int nREMINDER_TIME = Sql.ToInteger(rdr["REMINDER_TIME"]);
                                        if (nREMINDER_TIME >= 0)
                                        {
                                            new DynamicControl(this, "REMINDER_TIME").SelectedValue = nREMINDER_TIME.ToString();
                                            new DynamicControl(this, "SHOULD_REMIND").Checked       = true;
                                        }
                                    }
                                    else
                                    {
                                        // 11/25/2006 Paul.  If item is not visible, then don't allow save
                                        ctlEditButtons.DisableAll();
                                        ctlEditButtons.ErrorText = L10n.Term("ACL.LBL_NO_ACCESS");
                                    }
                                }
                            }
                            sSQL = "select INVITEE_ID                            " + ControlChars.CrLf
                                   + "  from vwCALLS_Invitees                      " + ControlChars.CrLf
                                   + " where CALL_ID = @ID                         " + ControlChars.CrLf
                                   + " order by INVITEE_TYPE desc, INVITEE_NAME asc" + 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);
                                }

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

                                using (IDataReader rdr = cmd.ExecuteReader())
                                {
                                    StringBuilder sb = new StringBuilder();
                                    while (rdr.Read())
                                    {
                                        if (sb.Length > 0)
                                        {
                                            sb.Append(",");
                                        }
                                        sb.Append(Sql.ToString(rdr["INVITEE_ID"]).ToLower());
                                    }
                                    txtINVITEE_ID.Value = sb.ToString();
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);

                        DateTimePicker ctlDATE_START = FindControl("DATE_START") as DateTimePicker;
                        if (ctlDATE_START != null)
                        {
                            ctlDATE_START.Changed     += new System.EventHandler(this.Date_Changed);
                            ctlDATE_START.AutoPostBack = true;
                            // Default start date and time is now.
                            ctlDATE_START.Value = T10n.FromServerTime(DateTime.Now);
                        }
                        // Default value for duration is 15 minutes.
                        new DynamicControl(this, "DURATION_MINUTES").Text = "15";
                        // Default to 0 hours.
                        new DynamicControl(this, "DURATION_HOURS").Text = "0";
                        // Default to remind.
                        new DynamicControl(this, "SHOULD_REMIND").Checked = true;

                        Guid gPARENT_ID = Sql.ToGuid(Request["PARENT_ID"]);
                        if (!Sql.IsEmptyGuid(gPARENT_ID))
                        {
                            string sMODULE      = String.Empty;
                            string sPARENT_TYPE = String.Empty;
                            string sPARENT_NAME = String.Empty;
                            SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
                            if (!Sql.IsEmptyGuid(gPARENT_ID))
                            {
                                new DynamicControl(this, "PARENT_ID").ID              = gPARENT_ID;
                                new DynamicControl(this, "PARENT_NAME").Text          = sPARENT_NAME;
                                new DynamicControl(this, "PARENT_TYPE").SelectedValue = sPARENT_TYPE;
                            }
                        }
                    }
                    // Default to current user.
                    if (txtINVITEE_ID.Value.Length == 0)
                    {
                        txtINVITEE_ID.Value = Security.USER_ID.ToString();
                    }
                    BindSchedule();
                }
                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);
                    // 11/09/2005 Paul.  Need to rebind early so that the Delete event will fire.
                    BindSchedule();
                    ctlInviteesView.INVITEES = txtINVITEE_ID.Value.Split(',');
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList.Schedulers"));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = SplendidCRM.Security.IS_ADMIN;
            if (!this.Visible)
            {
                return;
            }

            NAME_REQUIRED.DataBind();
            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                if (!IsPostBack)
                {
                    STATUS.DataSource = SplendidCache.List("scheduler_status_dom");
                    STATUS.DataBind();
                    foreach (string sJob in SchedulerUtils.Jobs)
                    {
                        JOB.Items.Add(new ListItem(sJob, "function::" + sJob));
                    }

                    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 vwSCHEDULERS" + 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["NAME"]);
                                        SetPageTitle(L10n.Term(".moduleList.Schedulers") + " - " + ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;

                                        NAME.Text        = Sql.ToString(rdr["NAME"]);
                                        CATCH_UP.Checked = Sql.ToBoolean(rdr["CATCH_UP"]);

                                        string JOB_INTERVAL = Sql.ToString(rdr["JOB_INTERVAL"]);
                                        JOB_INTERVAL = JOB_INTERVAL.Replace(" ", "");
                                        string[] arrCRON = JOB_INTERVAL.Replace("::", "|").Split('|');
                                        // minute  hour  dayOfMonth  month  dayOfWeek
                                        CRON_MINUTES.Text    = (arrCRON.Length > 0) ? arrCRON[0] : "*";
                                        CRON_HOURS.Text      = (arrCRON.Length > 1) ? arrCRON[1] : "*";
                                        CRON_DAYOFMONTH.Text = (arrCRON.Length > 2) ? arrCRON[2] : "*";
                                        CRON_MONTHS.Text     = (arrCRON.Length > 3) ? arrCRON[3] : "*";
                                        CRON_DAYOFWEEK.Text  = (arrCRON.Length > 4) ? arrCRON[4] : "*";

                                        if (rdr["DATE_TIME_START"] != DBNull.Value)
                                        {
                                            DATE_TIME_START.Value = T10n.FromServerTime(Sql.ToDateTime(rdr["DATE_TIME_START"]));
                                        }
                                        if (rdr["DATE_TIME_END"] != DBNull.Value)
                                        {
                                            DATE_TIME_END.Value = T10n.FromServerTime(Sql.ToDateTime(rdr["DATE_TIME_END"]));
                                        }
                                        // 12/31/2007 Paul.  TIME_FROM and TIME_TO are just time components, so they should not be translated.
                                        if (rdr["TIME_FROM"] != DBNull.Value)
                                        {
                                            TIME_FROM.Value = Sql.ToDateTime(rdr["TIME_FROM"]);
                                        }
                                        if (rdr["TIME_TO"] != DBNull.Value)
                                        {
                                            TIME_TO.Value = Sql.ToDateTime(rdr["TIME_TO"]);
                                        }
                                        try
                                        {
                                            JOB.SelectedValue = Sql.ToString(rdr["JOB"]);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                        }
                                        try
                                        {
                                            STATUS.SelectedValue = Sql.ToString(rdr["STATUS"]);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                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.Schedulers") + " - " + ctlModuleHeader.Title);
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
Beispiel #11
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);
            }
        }
        public void RunReport(string sRDL)
        {
            try
            {
                RdlDocument rdl = new RdlDocument();
                rdl.LoadRdl(sRDL);

                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        rdl.BuildCommand(cmd);
                        sReportSQL = Sql.ExpandParameters(cmd);

                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            dtReport = new DataTable();
                            {
                                da.Fill(dtReport);

                                // 07/12/2006 Paul.  Every date cell needs to be localized.
                                foreach (DataRow row in dtReport.Rows)
                                {
                                    foreach (DataColumn col in dtReport.Columns)
                                    {
                                        if (col.DataType == typeof(System.DateTime))
                                        {
                                            // 07/13/2006 Paul.  Don't try and translate a NULL.
                                            if (row[col.Ordinal] != DBNull.Value)
                                            {
                                                row[col.Ordinal] = T10n.FromServerTime(row[col.Ordinal]);
                                            }
                                        }
                                    }
                                }

                                /*
                                 * http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=444154&SiteID=1
                                 * Brian Hartman - MSFT  06 Jun 2006, 10:22 PM UTC
                                 * LocalReport has a limitation that the report definition can't be changed once the report has been processed.
                                 * In winforms, you can use the ReportViewer.Reset() method to force the viewer to create a new instance of
                                 * LocalReport and workaround this issue.  But this method is currently not on the webforms version of report viewer.
                                 * We hope to add it in an upcoming service pack, but for now,
                                 * you must workaround this issue by creating a new instance of the ReportViewer.
                                 */
                                /*
                                 * // 07/09/2006 Paul.  Creating a new viewer solves the reset problem, but breaks ReportViewer pagination.
                                 * rdlViewer = new ReportViewer();
                                 * rdlViewer.ID                  = "rdlViewer";
                                 * rdlViewer.Font.Names          = new string[] { "Verdana" };
                                 * rdlViewer.Font.Size           = new FontUnit("8pt");
                                 * rdlViewer.Height              = new Unit("100%");
                                 * rdlViewer.Width               = new Unit("100%");
                                 * rdlViewer.AsyncRendering      = false;
                                 * rdlViewer.SizeToReportContent = true;
                                 * divReportView.Controls.Clear();
                                 * divReportView.Controls.Add(rdlViewer);
                                 */

                                // 06/21/2006 Paul.  The DataSource Name must match the value in the report.
                                string           sDataSetName = rdl.SelectNodeValue("Body/ReportItems/Table/DataSetName");
                                ReportDataSource rds          = new ReportDataSource(sDataSetName, dtReport);
                                rdlViewer.ProcessingMode = ProcessingMode.Local;
                                // 06/25/2006 Paul.  The data sources need to be cleared, otherwise the report will not refresh.
                                rdlViewer.LocalReport.DataSources.Clear();
                                rdlViewer.LocalReport.DataSources.Add(rds);
                                rdlViewer.LocalReport.DisplayName = rdl.SelectNodeAttribute(String.Empty, "Name");

                                // 07/13/2006 Paul.  The ReportViewer is having a problem interpreting the date functions.
                                // To solve the problem, we should go through all the parameters and replace the date functions with values.
                                rdl.ReportViewerFixups();
                                StringReader sr = new StringReader(rdl.OuterXml);
                                rdlViewer.LocalReport.LoadReportDefinition(sr);
                                // 06/25/2006 Paul.  Refresh did not work, clear the data sources instead.
                                //rdlViewer.LocalReport.Refresh();
                                rdlViewer.DataBind();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblError.Text = Utils.ExpandException(ex);
            }
        }
        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.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            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 (!IsPostBack)
                {
                    string sLOAD_MODULE     = "Orders";
                    string sLOAD_MODULE_KEY = "ORDER_ID";
                    Guid   gQUOTE_ID        = Sql.ToGuid(Request["QUOTE_ID"]);
                    Guid   gDuplicateID     = Sql.ToGuid(Request["DuplicateID"]);
                    if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID) || !Sql.IsEmptyGuid(gQUOTE_ID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *            " + ControlChars.CrLf
                                   + "  from vwORDERS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                if (!Sql.IsEmptyGuid(gQUOTE_ID))
                                {
                                    // 04/28/2007 Paul.  Load the data from the QUOTES record.
                                    sLOAD_MODULE     = "Quotes";
                                    sLOAD_MODULE_KEY = "QUOTE_ID";
                                    sSQL             = "select *                      " + ControlChars.CrLf
                                                       + "  from vwQUOTES_ConvertToOrder" + ControlChars.CrLf;
                                    cmd.CommandText = sSQL;
                                    // 04/28/2007 Paul.  Filter by the module we are loading.
                                    Security.Filter(cmd, sLOAD_MODULE, "edit");
                                    Sql.AppendParameter(cmd, gQUOTE_ID, "ID", false);
                                }
                                else
                                {
                                    // 11/24/2006 Paul.  Use new Security.Filter() function to apply Team and ACL security rules.
                                    Security.Filter(cmd, m_sMODULE, "edit");
                                    if (!Sql.IsEmptyGuid(gDuplicateID))
                                    {
                                        Sql.AppendParameter(cmd, gDuplicateID, "ID", false);
                                        gID = Guid.Empty;
                                    }
                                    else
                                    {
                                        Sql.AppendParameter(cmd, gID, "ID", false);
                                    }
                                }
                                con.Open();

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

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

                                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditDescription", tblDescription, rdr);

                                        if (!Sql.IsEmptyGuid(gQUOTE_ID))
                                        {
                                            new DynamicControl(this, "QUOTE_ID").ID     = gQUOTE_ID;
                                            new DynamicControl(this, "QUOTE_NAME").Text = Sql.ToString(rdr["NAME"]);
                                            ctlEditLineItemsView.LoadLineItems(gQUOTE_ID, Guid.Empty, con, rdr, sLOAD_MODULE, sLOAD_MODULE_KEY);
                                        }
                                        else
                                        {
                                            ctlEditLineItemsView.LoadLineItems(gID, gDuplicateID, con, rdr, sLOAD_MODULE, sLOAD_MODULE_KEY);
                                        }
                                    }
                                    else
                                    {
                                        ctlEditLineItemsView.LoadLineItems(gID, gDuplicateID, con, null, String.Empty, String.Empty);

                                        // 11/25/2006 Paul.  If item is not visible, then don't allow save
                                        ctlEditButtons.DisableAll();
                                        ctlEditButtons.ErrorText = L10n.Term("ACL.LBL_NO_ACCESS");
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditDescription", tblDescription, null);

                        // 08/10/2007 Paul.  Default to today.
                        new DynamicControl(this, "ORDER_DATE").DateValue = T10n.FromServerTime(DateTime.Now);

                        // 06/08/2006 Paul.  Prepopulate the Account.
                        Guid gPARENT_ID = Sql.ToGuid(Request["PARENT_ID"]);
                        if (!Sql.IsEmptyGuid(gPARENT_ID))
                        {
                            string sMODULE      = String.Empty;
                            string sPARENT_TYPE = String.Empty;
                            string sPARENT_NAME = String.Empty;
                            SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
                            if (!Sql.IsEmptyGuid(gPARENT_ID) && sMODULE == "Accounts")
                            {
                                UpdateAccount(gPARENT_ID, true, true);
                            }
                            if (!Sql.IsEmptyGuid(gPARENT_ID) && sMODULE == "Contacts")
                            {
                                UpdateContact(gPARENT_ID, true, true);
                            }
                            else if (!Sql.IsEmptyGuid(gPARENT_ID) && sMODULE == "Opportunities")
                            {
                                new DynamicControl(this, "OPPORTUNITY_ID").ID     = gPARENT_ID;
                                new DynamicControl(this, "OPPORTUNITY_NAME").Text = sPARENT_NAME;
                            }
                        }
                        ctlEditLineItemsView.LoadLineItems(gID, gDuplicateID, null, null, String.Empty, String.Empty);
                    }
                }
                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"]);
                    Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);

                    DynamicControl ctlBILLING_ACCOUNT_ID  = new DynamicControl(this, "BILLING_ACCOUNT_ID");
                    DynamicControl ctlSHIPPING_ACCOUNT_ID = new DynamicControl(this, "SHIPPING_ACCOUNT_ID");
                    if (Sql.ToGuid(ViewState["BILLING_ACCOUNT_ID"]) != ctlBILLING_ACCOUNT_ID.ID)
                    {
                        UpdateAccount(ctlBILLING_ACCOUNT_ID.ID, true, true);
                        ViewState["BILLING_ACCOUNT_ID"]  = ctlBILLING_ACCOUNT_ID.ID;
                        ViewState["SHIPPING_ACCOUNT_ID"] = ctlBILLING_ACCOUNT_ID.ID;
                    }
                    if (Sql.ToGuid(ViewState["SHIPPING_ACCOUNT_ID"]) != ctlSHIPPING_ACCOUNT_ID.ID)
                    {
                        UpdateAccount(ctlSHIPPING_ACCOUNT_ID.ID, false, true);
                        ViewState["SHIPPING_ACCOUNT_ID"] = ctlSHIPPING_ACCOUNT_ID.ID;
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
Beispiel #14
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList.Schedulers"));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = SplendidCRM.Security.IS_ADMIN;
            if (!this.Visible)
            {
                return;
            }

            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                // 11/28/2005 Paul.  We must always populate the table, otherwise it will disappear during event processing.
                //if ( !IsPostBack )
                {
                    if (!Sql.IsEmptyGuid(gID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwSCHEDULERS" + 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["NAME"]);
                                        SetPageTitle(L10n.Term(".moduleList.Schedulers") + " - " + ctlModuleHeader.Title);

                                        string   sJOB_INTERVAL     = Sql.ToString(rdr["JOB_INTERVAL"]);
                                        DateTime dtDATE_TIME_START = Sql.ToDateTime(rdr["DATE_TIME_START"]);
                                        DateTime dtDATE_TIME_END   = Sql.ToDateTime(rdr["DATE_TIME_END"]);
                                        DateTime dtTIME_FROM       = Sql.ToDateTime(rdr["TIME_FROM"]);
                                        DateTime dtTIME_TO         = Sql.ToDateTime(rdr["TIME_TO"]);
                                        DateTime dtLAST_RUN        = Sql.ToDateTime(rdr["LAST_RUN"]);
                                        JOB.Text             = Sql.ToString(rdr["JOB"]);
                                        STATUS.Text          = Sql.ToString(L10n.Term(".scheduler_status_dom.", rdr["STATUS"]));
                                        DATE_TIME_START.Text = (dtDATE_TIME_START == DateTime.MinValue) ? L10n.Term("Schedulers.LBL_PERENNIAL") : T10n.FromServerTime(dtDATE_TIME_START).ToString();
                                        DATE_TIME_END.Text   = (dtDATE_TIME_END == DateTime.MinValue) ? L10n.Term("Schedulers.LBL_PERENNIAL") : T10n.FromServerTime(dtDATE_TIME_END).ToString();
                                        LAST_RUN.Text        = (dtLAST_RUN == DateTime.MinValue) ? L10n.Term("Schedulers.LBL_NEVER") : T10n.FromServerTime(dtLAST_RUN).ToString();
                                        TIME_FROM.Text       = (dtTIME_FROM == DateTime.MinValue) ? L10n.Term("Schedulers.LBL_ALWAYS") : dtTIME_FROM.ToShortTimeString();
                                        TIME_TO.Text         = (dtTIME_TO == DateTime.MinValue) ? L10n.Term("Schedulers.LBL_ALWAYS") : dtTIME_TO.ToShortTimeString();
                                        CATCH_UP.Text        = Sql.ToBoolean(rdr["CATCH_UP"])           ? L10n.Term("Schedulers.LBL_ALWAYS") : L10n.Term("Schedulers.LBL_NEVER");
                                        JOB_INTERVAL.Text    = sJOB_INTERVAL + "<br>" + SchedulerUtils.CronDescription(L10n, sJOB_INTERVAL);
                                        DATE_ENTERED.Text    = T10n.FromServerTime(Sql.ToDateTime(rdr["DATE_ENTERED"])).ToString() + " " + L10n.Term(".LBL_BY") + " " + Sql.ToString(rdr["CREATED_BY"]);
                                        DATE_MODIFIED.Text   = T10n.FromServerTime(Sql.ToDateTime(rdr["DATE_MODIFIED"])).ToString() + " " + L10n.Term(".LBL_BY") + " " + Sql.ToString(rdr["MODIFIED_BY"]);
                                    }
                                }
                            }
                        }
                    }
                }
                // 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);
                ctlDetailButtons.ErrorText = ex.Message;
            }
        }