protected void AppendDetailViewFields(string sDETAIL_NAME, HtmlTable tbl, IDataReader rdr, CommandEventHandler Page_Command)
 {
     // 11/17/2007 Paul.  Convert all view requests to a mobile request if appropriate.
     sDETAIL_NAME = sDETAIL_NAME + (this.IsMobile ? ".Mobile" : "");
     // 12/02/2005 Paul.  AppendEditViewFields will get called inside InitializeComponent(),
     // which occurs before OnInit(), so make sure to initialize L10n.
     SplendidDynamic.AppendDetailViewFields(sDETAIL_NAME, tbl, rdr, GetL10n(), GetT10n(), Page_Command);
 }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         if (Page.IsValid)
         {
             string            sCUSTOM_MODULE = "CURRENCIES";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         float dCONVERSION_RATE = float.Parse(txtCONVERSION_RATE.Text, NumberStyles.AllowDecimalPoint);
                         // 05/10/2006 Paul.  Sql.ToFloat() was having a problem when an alternate decimal point is used.
                         SqlProcs.spCURRENCIES_Update
                             (ref gID
                             , txtNAME.Text
                             , txtSYMBOL.Text
                             , txtISO4217.Text
                             , dCONVERSION_RATE
                             , lstSTATUS.SelectedValue
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                         // 04/20/2006 Paul.  Make sure to clear the cache.
                         Cache.Remove("vwCURRENCIES_LISTBOX");
                         // 07/07/2007 Paul.  The currency in the application scope needs to be updated.
                         Currency C10n = new Currency
                                             (gID
                                             , txtNAME.Text
                                             , txtSYMBOL.Text
                                             , dCONVERSION_RATE
                                             );
                         Application["CURRENCY." + C10n.ID.ToString()] = C10n;
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                         lblError.Text = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("default.aspx");
         }
     }
     else if (e.CommandName == "Clear")
     {
         Response.Redirect("default.aspx");
     }
 }
Esempio n. 3
0
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         // 01/16/2006 Paul.  Enable validator before validating page.
         SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
         if (Page.IsValid)
         {
             //string sCUSTOM_MODULE = "IFRAMES";
             //DataTable dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         SqlProcs.spIFRAMES_Update
                             (ref gID
                             , new DynamicControl(this, "NAME").Text
                             , new DynamicControl(this, "URL").Text
                             , new DynamicControl(this, "TYPE").SelectedValue
                             , new DynamicControl(this, "PLACEMENT").SelectedValue
                             , new DynamicControl(this, "STATUS").Checked
                             , trn
                             );
                         //SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                         ctlEditButtons.ErrorText = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("default.aspx");
         }
     }
     else if (e.CommandName == "Cancel")
     {
         if (Sql.IsEmptyGuid(gID))
         {
             Response.Redirect("default.aspx");
         }
         else
         {
             Response.Redirect("default.aspx");                     //Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
 }
 protected override void LayoutView_Bind()
 {
     if (dtFields != null)
     {
         tblMain.Rows.Clear();
         DataView dv = dtFields.DefaultView;
         dv.RowFilter = "DELETED = 0";
         dv.Sort      = LayoutIndexName();
         SplendidDynamic.AppendDetailViewFields(dv, tblMain, null, GetL10n(), GetT10n(), new CommandEventHandler(Page_Command), true);
     }
 }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         if (Page.IsValid)
         {
             string            sCUSTOM_MODULE = "EMAIL_MARKETING";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         SqlProcs.spEMAIL_TEMPLATES_Update
                             (ref gID
                             , false                                      // 11/17/2005 Paul.  The PUBLISH flag is no longer used in SugarCRM 3.5.0B
                             , txtNAME.Text
                             , txtDESCRIPTION.Text
                             , txtSUBJECT.Text
                             , String.Empty                                       // BODY
                             , txtBODY.Value                                      // BODY_HTML
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                         ctlEditButtons.ErrorText = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
     else if (e.CommandName == "Cancel")
     {
         if (Sql.IsEmptyGuid(gID))
         {
             Response.Redirect("default.aspx");
         }
         else
         {
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
 }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save" || e.CommandName == "SaveNew")
     {
         if (Page.IsValid)
         {
             string            sCUSTOM_MODULE = "RELEASES";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         SqlProcs.spRELEASES_Update
                             (ref gID
                             , txtNAME.Text
                             , Sql.ToInteger(txtLIST_ORDER.Text)
                             , lstSTATUS.SelectedValue
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                         // 07/04/2007 Paul.  Clear the cache any time the Releases list changes.
                         Cache.Remove("vwRELEASES_LISTBOX");
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                         lblError.Text = ex.Message;
                         return;
                     }
                 }
             }
             if (e.CommandName == "SaveNew")
             {
                 Response.Redirect("edit.aspx");
             }
             else
             {
                 Response.Redirect("edit.aspx?ID=" + gID.ToString());
             }
         }
     }
     else if (e.CommandName == "Cancel")
     {
         Response.Redirect("default.aspx");
     }
 }
        protected void btnProductChanged_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    string sSQL;
                    sSQL = "select *                       " + ControlChars.CrLf
                           + "  from vwPRODUCTS_FromTemplate " + ControlChars.CrLf
                           + " where 1 = 1                   " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        Guid gPRODUCT_TEMPLATE_ID = new DynamicControl(this, "PRODUCT_TEMPLATE_ID").ID;
                        Sql.AppendParameter(cmd, gPRODUCT_TEMPLATE_ID, "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;

                                SplendidDynamic.SetEditViewFields(this, m_sMODULE + ".EditView", rdr, GetL10n(), GetT10n());
                                SplendidDynamic.SetEditViewFields(this, m_sMODULE + ".CostView", rdr, GetL10n(), GetT10n());
                                SplendidDynamic.SetEditViewFields(this, m_sMODULE + ".MftView", rdr, GetL10n(), GetT10n());
                                // 07/05/2006 Paul.  The Product Name should be editable.
                                TextBox txtNAME = FindControl("NAME") as TextBox;
                                if (txtNAME != null)
                                {
                                    txtNAME.ReadOnly = false;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         if (Page.IsValid)
         {
             string            sCUSTOM_MODULE = "ROLES";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         SqlProcs.spROLES_Update
                             (ref gID
                             , new DynamicControl(this, "NAME").Text
                             , new DynamicControl(this, "DESCRIPTION").Text
                             , ctlChooser.LeftValues
                             , ctlChooser.RightValues
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                         ctlEditButtons.ErrorText = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
     else if (e.CommandName == "Cancel")
     {
         if (Sql.IsEmptyGuid(gID))
         {
             Response.Redirect("default.aspx");
         }
         else
         {
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
 }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                // 01/31/2006 Paul.  Enable validator before validating page.
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".ConvertView", this);
                if (Page.IsValid)
                {
                    // 02/27/2006 Paul.  Fix condition on notes.  Enable only if text exists.
                    txtCONTACT_NOTES_NAME_DESCRIPTION.Text = txtCONTACT_NOTES_NAME_DESCRIPTION.Text.Trim();
                    reqCONTACT_NOTES_NAME.Enabled          = !Sql.IsEmptyString(txtCONTACT_NOTES_NAME_DESCRIPTION.Text);
                    reqCONTACT_NOTES_NAME.Validate();

                    txtACCOUNT_NOTES_NAME_DESCRIPTION.Text = txtACCOUNT_NOTES_NAME_DESCRIPTION.Text.Trim();
                    reqACCOUNT_NOTES_NAME.Enabled          = !Sql.IsEmptyString(txtACCOUNT_NOTES_NAME_DESCRIPTION.Text);
                    reqACCOUNT_NOTES_NAME.Validate();

                    txtOPPORTUNITY_NOTES_NAME_DESCRIPTION.Text = txtOPPORTUNITY_NOTES_NAME_DESCRIPTION.Text.Trim();
                    reqOPPORTUNITY_NOTES_NAME.Enabled          = !Sql.IsEmptyString(txtOPPORTUNITY_NOTES_NAME_DESCRIPTION.Text);
                    reqOPPORTUNITY_NOTES_NAME.Validate();

                    // 01/31/2006 Paul.  SelectAccount is required if not creating an account but creating an opportunity.
                    reqSELECT_ACCOUNT_ID.Enabled = !chkCreateAccount.Checked && chkCreateOpportunity.Checked;
                    reqSELECT_ACCOUNT_ID.Validate();
                    reqACCOUNT_NAME.Enabled = chkCreateAccount.Checked;
                    reqACCOUNT_NAME.Validate();
                    reqOPPORTUNITY_NAME.Enabled = chkCreateOpportunity.Checked;
                    reqOPPORTUNITY_NAME.Validate();
                    reqOPPORTUNITY_AMOUNT.Enabled = chkCreateOpportunity.Checked;
                    reqOPPORTUNITY_AMOUNT.Validate();
                    reqAPPOINTMENT_NAME.Enabled = chkCreateAppointment.Checked;
                    reqAPPOINTMENT_NAME.Validate();
                    reqAPPOINTMENT_TIME_START.Enabled = chkCreateAppointment.Checked;
                    reqAPPOINTMENT_TIME_START.Validate();
                    if (chkCreateAppointment.Checked)
                    {
                        ctlAPPOINTMENT_DATE_START.Validate();
                    }
                }
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "LEADS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                Guid gCONTACT_ID     = Guid.Empty;
                                Guid gACCOUNT_ID     = Guid.Empty;
                                Guid gOPPORTUNITY_ID = Guid.Empty;
                                Guid gAPPOINTMENT_ID = Guid.Empty;

                                // 01/31/2006 Paul.  Create the contact first so that it can be used as the parent of the related records.
                                // We would normally create the related records second, but then it will become a pain to update the Contact ACCOUNT_ID field.
                                SqlProcs.spCONTACTS_New
                                    (ref gCONTACT_ID
                                    , new DynamicControl(this, "FIRST_NAME").Text
                                    , new DynamicControl(this, "LAST_NAME").Text
                                    , new DynamicControl(this, "PHONE_WORK").Text
                                    , new DynamicControl(this, "EMAIL1").Text
                                    , trn
                                    );

                                if (chkCreateAccount.Checked)
                                {
                                    SqlProcs.spACCOUNTS_Update
                                        (ref gACCOUNT_ID
                                        , Security.USER_ID
                                        , txtACCOUNT_NAME.Text
                                        , String.Empty
                                        , Guid.Empty
                                        , String.Empty
                                        , String.Empty
                                        , Sql.ToString(ViewState["PHONE_FAX"])
                                        , Sql.ToString(ViewState["BILLING_ADDRESS_STREET"])
                                        , Sql.ToString(ViewState["BILLING_ADDRESS_CITY"])
                                        , Sql.ToString(ViewState["BILLING_ADDRESS_STATE"])
                                        , Sql.ToString(ViewState["BILLING_ADDRESS_POSTALCODE"])
                                        , Sql.ToString(ViewState["BILLING_ADDRESS_COUNTRY"])
                                        , txtACCOUNT_DESCRIPTION.Text
                                        , String.Empty
                                        , txtACCOUNT_PHONE_WORK.Text
                                        , Sql.ToString(ViewState["PHONE_OTHER"])
                                        , Sql.ToString(ViewState["EMAIL1"])
                                        , Sql.ToString(ViewState["EMAIL2"])
                                        , txtACCOUNT_WEBSITE.Text
                                        , String.Empty
                                        , String.Empty
                                        , String.Empty
                                        , String.Empty
                                        , Sql.ToString(ViewState["SHIPPING_ADDRESS_STREET"])
                                        , Sql.ToString(ViewState["SHIPPING_ADDRESS_CITY"])
                                        , Sql.ToString(ViewState["SHIPPING_ADDRESS_STATE"])
                                        , Sql.ToString(ViewState["SHIPPING_ADDRESS_POSTALCODE"])
                                        , Sql.ToString(ViewState["SHIPPING_ADDRESS_COUNTRY"])
                                        , trn
                                        );

                                    if (!Sql.IsEmptyString(txtACCOUNT_NOTES_NAME.Text))
                                    {
                                        Guid gNOTE_ID = Guid.Empty;
                                        SqlProcs.spNOTES_Update
                                            (ref gNOTE_ID
                                            , txtACCOUNT_NOTES_NAME.Text
                                            , "Accounts"
                                            , gACCOUNT_ID
                                            , Guid.Empty
                                            , txtACCOUNT_NOTES_NAME_DESCRIPTION.Text
                                            , trn
                                            );
                                    }
                                }
                                else
                                {
                                    gACCOUNT_ID = Sql.ToGuid(txtSELECT_ACCOUNT_ID.Value);
                                }
                                if (chkCreateOpportunity.Checked)
                                {
                                    SqlProcs.spOPPORTUNITIES_Update
                                        (ref gOPPORTUNITY_ID
                                        , Security.USER_ID
                                        , gACCOUNT_ID
                                        , txtOPPORTUNITY_NAME.Text
                                        , String.Empty
                                        , new DynamicControl(this, "LEAD_SOURCE").SelectedValue
                                        , Sql.ToDecimal(txtOPPORTUNITY_AMOUNT.Text)
                                        , Guid.Empty
                                        , T10n.ToServerTime(ctlOPPORTUNITY_DATE_CLOSED.Value)
                                        , String.Empty
                                        , lstOPPORTUNITY_SALES_STAGE.SelectedValue
                                        , (float)0.0
                                        , txtOPPORTUNITY_DESCRIPTION.Text
                                        , String.Empty
                                        , Guid.Empty
                                        , trn
                                        );
                                    if (!Sql.IsEmptyString(txtOPPORTUNITY_NOTES_NAME.Text))
                                    {
                                        Guid gNOTE_ID = Guid.Empty;
                                        SqlProcs.spNOTES_Update
                                            (ref gNOTE_ID
                                            , txtOPPORTUNITY_NOTES_NAME.Text
                                            , "Opportunities"
                                            , gOPPORTUNITY_ID
                                            , Guid.Empty
                                            , txtOPPORTUNITY_NOTES_NAME_DESCRIPTION.Text
                                            , trn
                                            );
                                    }
                                    // 03/04/2006 Paul.  Must be included in the transaction, otherwise entire operation will fail with a timeout message.
                                    SqlProcs.spOPPORTUNITIES_CONTACTS_Update(gOPPORTUNITY_ID, gCONTACT_ID, String.Empty, trn);
                                }
                                if (chkCreateAppointment.Checked)
                                {
                                    DateTime dtDATE_START = T10n.ToServerTime(Sql.ToDateTime(ctlAPPOINTMENT_DATE_START.DateText + " " + txtAPPOINTMENT_TIME_START.Text));
                                    if (radScheduleCall.Checked)
                                    {
                                        SqlProcs.spCALLS_Update
                                            (ref gAPPOINTMENT_ID
                                            , Security.USER_ID
                                            , txtAPPOINTMENT_NAME.Text
                                            , 1
                                            , 0
                                            , dtDATE_START
                                            , "Accounts"
                                            , Guid.Empty
                                            , "Planned"
                                            , "Outbound"
                                            , -1
                                            , txtAPPOINTMENT_DESCRIPTION.Text
                                            , gCONTACT_ID.ToString()                                                     // 01/31/2006 Paul.  This is were we relate this call to the contact.
                                            , trn
                                            );
                                    }
                                    else
                                    {
                                        SqlProcs.spMEETINGS_Update
                                            (ref gAPPOINTMENT_ID
                                            , Security.USER_ID
                                            , txtAPPOINTMENT_NAME.Text
                                            , String.Empty
                                            , 1
                                            , 0
                                            , dtDATE_START
                                            , "Planned"
                                            , "Accounts"
                                            , Guid.Empty
                                            , -1
                                            , txtAPPOINTMENT_DESCRIPTION.Text
                                            , gCONTACT_ID.ToString()                                                     // 01/31/2006 Paul.  This is were we relate this meeting to the contact.
                                            , trn
                                            );
                                    }
                                }
                                SqlProcs.spCONTACTS_ConvertLead
                                    (ref gCONTACT_ID
                                    , gID                                                                       // 01/31/2006 Paul.  Update the Lead with this contact.
                                    , Security.USER_ID
                                    , new DynamicControl(this, "SALUTATION").SelectedValue
                                    , new DynamicControl(this, "FIRST_NAME").Text
                                    , new DynamicControl(this, "LAST_NAME").Text
                                    , gACCOUNT_ID
                                    , new DynamicControl(this, "LEAD_SOURCE").SelectedValue
                                    , new DynamicControl(this, "TITLE").Text
                                    , new DynamicControl(this, "DEPARTMENT").Text
                                    , new DynamicControl(this, "DO_NOT_CALL").Checked
                                    , new DynamicControl(this, "PHONE_HOME").Text
                                    , new DynamicControl(this, "PHONE_MOBILE").Text
                                    , new DynamicControl(this, "PHONE_WORK").Text
                                    , new DynamicControl(this, "PHONE_OTHER").Text
                                    , new DynamicControl(this, "PHONE_FAX").Text
                                    , new DynamicControl(this, "EMAIL1").Text
                                    , new DynamicControl(this, "EMAIL2").Text
                                    , new DynamicControl(this, "EMAIL_OPT_OUT").Checked
                                    , new DynamicControl(this, "INVALID_EMAIL").Checked
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_STREET").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_CITY").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_STATE").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_COUNTRY").Text
                                    , Sql.ToString(ViewState["ALT_ADDRESS_STREET"])
                                    , Sql.ToString(ViewState["ALT_ADDRESS_CITY"])
                                    , Sql.ToString(ViewState["ALT_ADDRESS_STATE"])
                                    , Sql.ToString(ViewState["ALT_ADDRESS_POSTALCODE"])
                                    , Sql.ToString(ViewState["ALT_ADDRESS_COUNTRY"])
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , gOPPORTUNITY_ID
                                    , txtOPPORTUNITY_NAME.Text
                                    , txtOPPORTUNITY_AMOUNT.Text
                                    , trn
                                    );
                                if (!Sql.IsEmptyString(txtCONTACT_NOTES_NAME.Text))
                                {
                                    Guid gNOTE_ID = Guid.Empty;
                                    SqlProcs.spNOTES_Update
                                        (ref gNOTE_ID
                                        , txtCONTACT_NOTES_NAME.Text
                                        , String.Empty
                                        , Guid.Empty
                                        , gCONTACT_ID
                                        , txtCONTACT_NOTES_NAME_DESCRIPTION.Text
                                        , trn
                                        );
                                }

                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
Esempio n. 10
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 06/08/2006 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                TextBox         txtNAME = FindControl("NAME") as TextBox;
                HtmlInputHidden txtPRODUCT_TEMPLATE_ID = FindControl("PRODUCT_TEMPLATE_ID") as HtmlInputHidden;
                // 07/05/2006 Paul.  The NAME field can be derived from a product template or manually entered.
                // In order to fake-out the normal required-field mechanism, assign the empty Guid to the template ID.
                // The name cannot be null, so if it is, then clear the template ID.
                if (Sql.IsEmptyString(txtNAME.Text.Trim()))
                {
                    txtPRODUCT_TEMPLATE_ID.Value = String.Empty;
                }
                else if (Sql.IsEmptyString(txtPRODUCT_TEMPLATE_ID.Value))
                {
                    txtPRODUCT_TEMPLATE_ID.Value = Guid.Empty.ToString();
                }

                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".CostView", this);
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".MftView", this);
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "PRODUCTS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                SqlProcs.spPRODUCTS_Update
                                    (ref gID
                                    , new DynamicControl(this, "PRODUCT_TEMPLATE_ID").ID
                                    , new DynamicControl(this, "NAME").Text
                                    , new DynamicControl(this, "STATUS").SelectedValue
                                    , new DynamicControl(this, "ACCOUNT_ID").ID
                                    , new DynamicControl(this, "CONTACT_ID").ID
                                    , new DynamicControl(this, "QUANTITY").IntegerValue
                                    , new DynamicControl(this, "DATE_PURCHASED").DateValue
                                    , new DynamicControl(this, "DATE_SUPPORT_EXPIRES").DateValue
                                    , new DynamicControl(this, "DATE_SUPPORT_STARTS").DateValue
                                    , new DynamicControl(this, "MANUFACTURER_ID").ID
                                    , new DynamicControl(this, "CATEGORY_ID").ID
                                    , new DynamicControl(this, "TYPE_ID").ID
                                    , new DynamicControl(this, "WEBSITE").Text
                                    , new DynamicControl(this, "MFT_PART_NUM").Text
                                    , new DynamicControl(this, "VENDOR_PART_NUM").Text
                                    , new DynamicControl(this, "SERIAL_NUMBER").Text
                                    , new DynamicControl(this, "ASSET_NUMBER").Text
                                    , new DynamicControl(this, "TAX_CLASS").SelectedValue
                                    , new DynamicControl(this, "WEIGHT").FloatValue
                                    , new DynamicControl(this, "CURRENCY_ID").ID
                                    , new DynamicControl(this, "COST_PRICE").DecimalValue
                                    , new DynamicControl(this, "LIST_PRICE").DecimalValue
                                    , new DynamicControl(this, "BOOK_VALUE").DecimalValue
                                    , new DynamicControl(this, "BOOK_VALUE_DATE").DateValue
                                    , new DynamicControl(this, "DISCOUNT_PRICE").DecimalValue
                                    , new DynamicControl(this, "PRICING_FACTOR").IntegerValue
                                    , new DynamicControl(this, "PRICING_FORMULA").SelectedValue
                                    , new DynamicControl(this, "SUPPORT_NAME").Text
                                    , new DynamicControl(this, "SUPPORT_CONTACT").Text
                                    , new DynamicControl(this, "SUPPORT_DESCRIPTION").Text
                                    , new DynamicControl(this, "SUPPORT_TERM").SelectedValue
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         // 01/16/2006 Paul.  Enable validator before validating page.
         SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
         if (Page.IsValid)
         {
             string            sCUSTOM_MODULE = "CAMPAIGNS";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         // 04/24/2006 Paul.  Upgrade to SugarCRM 4.2 Schema.
                         SqlProcs.spCAMPAIGNS_Update
                             (ref gID
                             , new DynamicControl(this, "ASSIGNED_USER_ID").ID
                             , new DynamicControl(this, "NAME").Text
                             , new DynamicControl(this, "REFER_URL").Text
                             , new DynamicControl(this, "TRACKER_TEXT").Text
                             , new DynamicControl(this, "START_DATE").DateValue
                             , new DynamicControl(this, "END_DATE").DateValue
                             , new DynamicControl(this, "STATUS").SelectedValue
                             , new DynamicControl(this, "BUDGET").DecimalValue
                             , new DynamicControl(this, "EXPECTED_COST").DecimalValue
                             , new DynamicControl(this, "ACTUAL_COST").DecimalValue
                             , new DynamicControl(this, "EXPECTED_REVENUE").DecimalValue
                             , new DynamicControl(this, "CAMPAIGN_TYPE").SelectedValue
                             , new DynamicControl(this, "OBJECTIVE").Text
                             , new DynamicControl(this, "CONTENT").Text
                             , new DynamicControl(this, "CURRENCY_ID").ID
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                         ctlEditButtons.ErrorText = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
     else if (e.CommandName == "Cancel")
     {
         if (Sql.IsEmptyGuid(gID))
         {
             Response.Redirect("default.aspx");
         }
         else
         {
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
 }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         // 01/16/2006 Paul.  Enable validator before validating page.
         SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".ConvertView", this);
         SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".ConvertAddress", this);
         SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".ConvertDescription", this);
         if (Page.IsValid)
         {
             Guid              gLEAD_ID       = Guid.Empty;
             string            sCUSTOM_MODULE = "LEADS";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         // 04/24/2006 Paul.  Upgrade to SugarCRM 4.2 Schema.
                         SqlProcs.spLEADS_ConvertProspect
                             (ref gLEAD_ID
                             , gID                                                                       // 01/31/2006 Paul.  Update the Prospect with this lead.
                             , new DynamicControl(this, "ASSIGNED_USER_ID").ID
                             , new DynamicControl(this, "SALUTATION").SelectedValue
                             , new DynamicControl(this, "FIRST_NAME").Text
                             , new DynamicControl(this, "LAST_NAME").Text
                             , new DynamicControl(this, "TITLE").Text
                             , new DynamicControl(this, "REFERED_BY").Text
                             , new DynamicControl(this, "LEAD_SOURCE").SelectedValue
                             , new DynamicControl(this, "LEAD_SOURCE_DESCRIPTION").Text
                             , new DynamicControl(this, "STATUS").SelectedValue
                             , new DynamicControl(this, "STATUS_DESCRIPTION").Text
                             , new DynamicControl(this, "DEPARTMENT").Text
                             , Guid.Empty                                      // 06/24/2005. REPORTS_TO_ID is not used in version 3.0.
                             , new DynamicControl(this, "DO_NOT_CALL").Checked
                             , new DynamicControl(this, "PHONE_HOME").Text
                             , new DynamicControl(this, "PHONE_MOBILE").Text
                             , new DynamicControl(this, "PHONE_WORK").Text
                             , new DynamicControl(this, "PHONE_OTHER").Text
                             , new DynamicControl(this, "PHONE_FAX").Text
                             , new DynamicControl(this, "EMAIL1").Text
                             , new DynamicControl(this, "EMAIL2").Text
                             , new DynamicControl(this, "EMAIL_OPT_OUT").Checked
                             , new DynamicControl(this, "INVALID_EMAIL").Checked
                             , new DynamicControl(this, "PRIMARY_ADDRESS_STREET").Text
                             , new DynamicControl(this, "PRIMARY_ADDRESS_CITY").Text
                             , new DynamicControl(this, "PRIMARY_ADDRESS_STATE").Text
                             , new DynamicControl(this, "PRIMARY_ADDRESS_POSTALCODE").Text
                             , new DynamicControl(this, "PRIMARY_ADDRESS_COUNTRY").Text
                             , new DynamicControl(this, "ALT_ADDRESS_STREET").Text
                             , new DynamicControl(this, "ALT_ADDRESS_CITY").Text
                             , new DynamicControl(this, "ALT_ADDRESS_STATE").Text
                             , new DynamicControl(this, "ALT_ADDRESS_POSTALCODE").Text
                             , new DynamicControl(this, "ALT_ADDRESS_COUNTRY").Text
                             , new DynamicControl(this, "DESCRIPTION").Text
                             , new DynamicControl(this, "ACCOUNT_NAME").Text
                             , new DynamicControl(this, "CAMPAIGN_ID").ID
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                         ctlEditButtons.ErrorText = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
     else if (e.CommandName == "Cancel")
     {
         if (Sql.IsEmptyGuid(gID))
         {
             Response.Redirect("default.aspx");
         }
         else
         {
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
 }
Esempio n. 13
0
        //protected _controls.DateTimePicker  ctlDATE_START      ;

        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                /*
                 * DateTimePicker ctlDATE_START = FindControl("DATE_START") as DateTimePicker;
                 * if ( ctlDATE_START != null )
                 *      ctlDATE_START.Validate();
                 */
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "CALLS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwCALLS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spCALLS_Update(ref gID
                                                        , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                                                        , new DynamicControl(this, rowCurrent, "NAME").Text
                                                        , new DynamicControl(this, rowCurrent, "DURATION_HOURS").IntegerValue
                                                        , new DynamicControl(this, rowCurrent, "DURATION_MINUTES").IntegerValue
                                                        , new DynamicControl(this, rowCurrent, "DATE_START").DateValue
                                                        , new DynamicControl(this, rowCurrent, "PARENT_TYPE").SelectedValue
                                                        , new DynamicControl(this, rowCurrent, "PARENT_ID").ID
                                                        , new DynamicControl(this, rowCurrent, "STATUS").SelectedValue
                                                        , new DynamicControl(this, rowCurrent, "DIRECTION").SelectedValue
                                                        , new DynamicControl(this, rowCurrent, "SHOULD_REMIND").Checked ? new DynamicControl(this, "REMINDER_TIME").IntegerValue : -1
                                                        , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                                        , txtINVITEE_ID.Value
                                                        , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                                                        , trn
                                                        );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
            else if (e.CommandName == "Invitees.Add")
            {
                if (txtINVITEE_ID.Value.Length > 0)
                {
                    txtINVITEE_ID.Value += ",";
                }
                txtINVITEE_ID.Value     += e.CommandArgument;
                ctlInviteesView.INVITEES = txtINVITEE_ID.Value.Split(',');
                BindSchedule();
            }
            else if (e.CommandName == "Invitees.Delete")
            {
                string        sDELETE_ID  = e.CommandArgument.ToString().ToLower();
                string[]      arrINVITEES = txtINVITEE_ID.Value.Split(',');
                StringBuilder sb          = new StringBuilder();
                foreach (string sINVITEE_ID in arrINVITEES)
                {
                    if (sINVITEE_ID != sDELETE_ID)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(",");
                        }
                        sb.Append(sINVITEE_ID);
                    }
                }
                txtINVITEE_ID.Value      = sb.ToString();
                ctlInviteesView.INVITEES = txtINVITEE_ID.Value.Split(',');
                BindSchedule();
            }
            else if (e.CommandName == "Search")
            {
                BindSchedule();
            }
        }
Esempio n. 14
0
 protected void AppendDetailViewFields(string sDETAIL_NAME, HtmlTable tbl, IDataReader rdr, CommandEventHandler Page_Command)
 {
     // 12/02/2005 Paul.  AppendEditViewFields will get called inside InitializeComponent(),
     // which occurs before OnInit(), so make sure to initialize L10n.
     SplendidDynamic.AppendDetailViewFields(sDETAIL_NAME, tbl, rdr, GetL10n(), GetT10n(), Page_Command);
 }
Esempio n. 15
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                try
                {
                    // 01/16/2006 Paul.  Enable validator before validating page.
                    this.ValidateEditViewFields(m_sMODULE + ".EditView");
                    this.ValidateEditViewFields(m_sMODULE + ".EditOptions");

                    if (Page.IsValid)
                    {
                        DropDownList SERVICE = FindControl("SERVICE") as DropDownList;
                        if (SERVICE != null)
                        {
                            if (SERVICE.SelectedValue == "imap")
                            {
                                ctlEditButtons.ErrorText += "POP3 is the only supported service at this time. ";
                                return;
                            }
                        }
                        DropDownList MAILBOX_TYPE = FindControl("MAILBOX_TYPE") as DropDownList;
                        if (MAILBOX_TYPE != null)
                        {
                            if (MAILBOX_TYPE.SelectedValue != "bounce")
                            {
                                ctlEditButtons.ErrorText += "Bounce handling is the only supported action at this time. ";
                                return;
                            }
                        }
                    }
                    if (Page.IsValid)
                    {
                        // 01/08/2008 Paul.  If the encryption key does not exist, then we must create it and we must save it back to the database.
                        // 01/08/2008 Paul.  SugarCRM uses blowfish for the inbound email encryption, but we will not since .NET 2.0 does not support blowfish natively.
                        Guid gINBOUND_EMAIL_KEY = Sql.ToGuid(Application["CONFIG.InboundEmailKey"]);
                        if (Sql.IsEmptyGuid(gINBOUND_EMAIL_KEY))
                        {
                            gINBOUND_EMAIL_KEY = Guid.NewGuid();
                            SqlProcs.spCONFIG_Update("mail", "InboundEmailKey", gINBOUND_EMAIL_KEY.ToString());
                            Application["CONFIG.InboundEmailKey"] = gINBOUND_EMAIL_KEY;
                        }
                        Guid gINBOUND_EMAIL_IV = Sql.ToGuid(Application["CONFIG.InboundEmailIV"]);
                        if (Sql.IsEmptyGuid(gINBOUND_EMAIL_IV))
                        {
                            gINBOUND_EMAIL_IV = Guid.NewGuid();
                            SqlProcs.spCONFIG_Update("mail", "InboundEmailIV", gINBOUND_EMAIL_IV.ToString());
                            Application["CONFIG.InboundEmailIV"] = gINBOUND_EMAIL_IV;
                        }

                        string            sCUSTOM_MODULE = "INBOUND_EMAIL";
                        DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                        DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            con.Open();
                            // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                            DataRow   rowCurrent = null;
                            DataTable dtCurrent  = new DataTable();
                            if (!Sql.IsEmptyGuid(gID))
                            {
                                string sSQL;
                                sSQL = "select *                    " + ControlChars.CrLf
                                       + "  from vwINBOUND_EMAILS_Edit" + ControlChars.CrLf
                                       + " where ID = @ID             " + ControlChars.CrLf;
                                using (IDbCommand cmd = con.CreateCommand())
                                {
                                    cmd.CommandText = sSQL;
                                    Sql.AddParameter(cmd, "@ID", gID);
                                    using (DbDataAdapter da = dbf.CreateDataAdapter())
                                    {
                                        ((IDbDataAdapter)da).SelectCommand = cmd;
                                        da.Fill(dtCurrent);
                                        if (dtCurrent.Rows.Count > 0)
                                        {
                                            rowCurrent = dtCurrent.Rows[0];
                                        }
                                        else
                                        {
                                            // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                            // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                            gID = Guid.Empty;
                                        }
                                    }
                                }
                            }
                            using (IDbTransaction trn = con.BeginTransaction())
                            {
                                try
                                {
                                    string sEMAIL_PASSWORD = new DynamicControl(this, "EMAIL_PASSWORD").Text;
                                    if (sEMAIL_PASSWORD == "**********")
                                    {
                                        if (rowCurrent != null)
                                        {
                                            sEMAIL_PASSWORD = Sql.ToString(rowCurrent["EMAIL_PASSWORD"]);
                                        }
                                        else
                                        {
                                            sEMAIL_PASSWORD = "";
                                        }
                                    }
                                    else
                                    {
                                        string sENCRYPTED_EMAIL_PASSWORD = Security.EncryptPassword(sEMAIL_PASSWORD, gINBOUND_EMAIL_KEY, gINBOUND_EMAIL_IV);
                                        if (Security.DecryptPassword(sENCRYPTED_EMAIL_PASSWORD, gINBOUND_EMAIL_KEY, gINBOUND_EMAIL_IV) != sEMAIL_PASSWORD)
                                        {
                                            throw(new Exception("Decryption failed"));
                                        }
                                        sEMAIL_PASSWORD = sENCRYPTED_EMAIL_PASSWORD;
                                    }
                                    SqlProcs.spINBOUND_EMAILS_Update
                                        (ref gID
                                        , new DynamicControl(this, rowCurrent, "NAME").Text
                                        , new DynamicControl(this, rowCurrent, "STATUS").SelectedValue
                                        , new DynamicControl(this, rowCurrent, "SERVER_URL").Text
                                        , new DynamicControl(this, rowCurrent, "EMAIL_USER").Text
                                        , sEMAIL_PASSWORD
                                        , Sql.ToInteger(new DynamicControl(this, rowCurrent, "PORT").Text)
                                        , new DynamicControl(this, rowCurrent, "MAILBOX_SSL").Checked
                                        , new DynamicControl(this, rowCurrent, "SERVICE").SelectedValue
                                        , "INBOX"
                                        , new DynamicControl(this, rowCurrent, "MARK_READ").Checked
                                        , new DynamicControl(this, rowCurrent, "ONLY_SINCE").Checked
                                        , new DynamicControl(this, rowCurrent, "MAILBOX_TYPE").SelectedValue
                                        , new DynamicControl(this, rowCurrent, "TEMPLATE_ID").ID
                                        , new DynamicControl(this, rowCurrent, "GROUP_ID").ID
                                        , new DynamicControl(this, rowCurrent, "FROM_NAME").Text
                                        , new DynamicControl(this, rowCurrent, "FROM_ADDR").Text
                                        , new DynamicControl(this, rowCurrent, "FILTER_DOMAIN").Text
                                        , trn
                                        );
                                    SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                    trn.Commit();
                                }
                                catch (Exception ex)
                                {
                                    trn.Rollback();
                                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                    ctlEditButtons.ErrorText = ex.Message;
                                    return;
                                }
                            }
                        }
                        SplendidCache.ClearEmailGroups();
                        SplendidCache.ClearInboundEmails();
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
                catch (Exception ex)
                {
                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                    ctlEditButtons.ErrorText = ex.Message;
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
Esempio n. 16
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "BUGS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                //die("ERROR: uploaded file was too big: max filesize: {$sugar_config['upload_maxsize']}");
                                HtmlInputFile  fileATTACHMENT = FindControl("ATTACHMENT") as HtmlInputFile;
                                HttpPostedFile pstATTACHMENT  = null;
                                if (fileATTACHMENT != null)
                                {
                                    pstATTACHMENT = fileATTACHMENT.PostedFile;
                                }
                                if (pstATTACHMENT != null)
                                {
                                    long lFileSize      = pstATTACHMENT.ContentLength;
                                    long lUploadMaxSize = Sql.ToLong(Application["CONFIG.upload_maxsize"]);
                                    if ((lUploadMaxSize > 0) && (lFileSize > lUploadMaxSize))
                                    {
                                        throw(new Exception("ERROR: uploaded file was too big: max filesize: " + lUploadMaxSize.ToString()));
                                    }
                                }
                                SqlProcs.spBUGS_Update
                                    (ref gID
                                    , new DynamicControl(this, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, "NAME").Text
                                    , new DynamicControl(this, "STATUS").SelectedValue
                                    , new DynamicControl(this, "PRIORITY").SelectedValue
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , new DynamicControl(this, "RESOLUTION").SelectedValue
                                    , new DynamicControl(this, "RELEASE").SelectedValue
                                    , new DynamicControl(this, "TYPE").SelectedValue
                                    , new DynamicControl(this, "FIXED_IN_RELEASE").SelectedValue
                                    , new DynamicControl(this, "WORK_LOG").Text
                                    , new DynamicControl(this, "SOURCE").Text
                                    , new DynamicControl(this, "PRODUCT_CATEGORY").SelectedValue
                                    , sMODULE
                                    , gPARENT_ID
                                    , trn
                                    );
                                if (pstATTACHMENT != null)
                                {
                                    // 08/20/2005 Paul.  File may not have been provided.
                                    if (pstATTACHMENT.FileName.Length > 0)
                                    {
                                        string sFILENAME       = Path.GetFileName(pstATTACHMENT.FileName);
                                        string sFILE_EXT       = Path.GetExtension(sFILENAME);
                                        string sFILE_MIME_TYPE = pstATTACHMENT.ContentType;

                                        Guid gAttachmentID = Guid.Empty;
                                        // 01/20/2006 Paul.  Must include in transaction
                                        SqlProcs.spBUG_ATTACHMENTS_Insert(ref gAttachmentID, gID, pstATTACHMENT.FileName, sFILENAME, sFILE_EXT, sFILE_MIME_TYPE, trn);
                                        LoadFile(gAttachmentID, pstATTACHMENT.InputStream, trn);
                                    }
                                }
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "PROJECT_TASK";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                SqlProcs.spPROJECT_TASKS_Update
                                    (ref gID
                                    , new DynamicControl(this, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, "NAME").Text
                                    , new DynamicControl(this, "STATUS").SelectedValue
                                    , new DynamicControl(this, "DATE_DUE").DateValue
                                    , new DynamicControl(this, "DATE_START").DateValue
                                    , new DynamicControl(this, "PROJECT_ID").ID
                                    , new DynamicControl(this, "PRIORITY").SelectedValue
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , new DynamicControl(this, "ORDER_NUMBER").IntegerValue
                                    , new DynamicControl(this, "TASK_NUMBER").IntegerValue
                                    , new DynamicControl(this, "DEPENDS_ON_ID").ID
                                    , new DynamicControl(this, "MILESTONE_FLAG").Checked
                                    , new DynamicControl(this, "ESTIMATED_EFFORT").IntegerValue
                                    , new DynamicControl(this, "ACTUAL_EFFORT").IntegerValue
                                    , new DynamicControl(this, "UTILIZATION").IntegerValue
                                    , new DynamicControl(this, "PERCENT_COMPLETE").IntegerValue
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    // 11/17/2005 Paul.  SugarCRM does not redirect to the Project, even if the user changed it. Just do the same.
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
Esempio n. 18
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID))
                {
                    // 03/04/2006 Paul.  The Enable flag cannot be modified prior to ValidateEditViewFields because the change will get over-ridden.
                    //RequiredFieldValidator reqCONTENT  = FindControl("CONTENT_REQUIRED" ) as RequiredFieldValidator;
                    //RequiredFieldValidator reqREVISION = FindControl("REVISION_REQUIRED") as RequiredFieldValidator;
                    //if ( reqCONTENT != null )
                    //	reqCONTENT.Enabled = false;
                    //if ( reqREVISION != null )
                    //	reqREVISION.Enabled = false;
                }
                // 01/16/2006 Paul.  Enable validator before validating page.
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "DOCUMENTS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                HtmlInputFile  fileCONTENT = FindControl("CONTENT") as HtmlInputFile;
                                HttpPostedFile pstCONTENT  = null;
                                if (fileCONTENT != null)
                                {
                                    pstCONTENT = fileCONTENT.PostedFile;
                                }
                                // 03/04/2006 Paul.  This is a new document if gID and gDuplicateID are both empty.
                                bool bNewDocument = Sql.IsEmptyGuid(gID) && Sql.IsEmptyGuid(gDuplicateID);
                                if (bNewDocument)
                                {
                                    //die("ERROR: uploaded file was too big: max filesize: {$sugar_config['upload_maxsize']}");
                                    if (pstCONTENT != null)
                                    {
                                        long lFileSize      = pstCONTENT.ContentLength;
                                        long lUploadMaxSize = Sql.ToLong(Application["CONFIG.upload_maxsize"]);
                                        if ((lUploadMaxSize > 0) && (lFileSize > lUploadMaxSize))
                                        {
                                            throw(new Exception("ERROR: uploaded file was too big: max filesize: " + lUploadMaxSize.ToString()));
                                        }
                                    }
                                }
                                // 04/24/2006 Paul.  Upgrade to SugarCRM 4.2 Schema.
                                SqlProcs.spDOCUMENTS_Update
                                    (ref gID
                                    , new DynamicControl(this, "DOCUMENT_NAME").Text
                                    , new DynamicControl(this, "ACTIVE_DATE").DateValue
                                    , new DynamicControl(this, "EXP_DATE").DateValue
                                    , new DynamicControl(this, "CATEGORY_ID").SelectedValue
                                    , new DynamicControl(this, "SUBCATEGORY_ID").SelectedValue
                                    , new DynamicControl(this, "STATUS_ID").SelectedValue
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , new DynamicControl(this, "MAIL_MERGE_DOCUMENT").Checked
                                    , new DynamicControl(this, "RELATED_DOC_ID").ID
                                    , new DynamicControl(this, "RELATED_DOC_REV_ID").ID
                                    , new DynamicControl(this, "IS_TEMPLATE").Checked
                                    , new DynamicControl(this, "TEMPLATE_TYPE").Text
                                    , trn
                                    );
                                if (bNewDocument)
                                {
                                    if (pstCONTENT != null)
                                    {
                                        // 08/20/2005 Paul.  File may not have been provided.
                                        if (pstCONTENT.FileName.Length > 0)
                                        {
                                            string sFILENAME       = Path.GetFileName(pstCONTENT.FileName);
                                            string sFILE_EXT       = Path.GetExtension(sFILENAME);
                                            string sFILE_MIME_TYPE = pstCONTENT.ContentType;

                                            Guid gRevisionID = Guid.Empty;
                                            // 01/16/2006 Paul.  spDOCUMENT_REVISIONS_Insert needs to be in the transaction,
                                            // otherwise the entire transaction will timeout. This is because the transaction has
                                            // locked the tables that are needed by spDOCUMENT_REVISIONS_Insert.
                                            SqlProcs.spDOCUMENT_REVISIONS_Insert
                                                (ref gRevisionID
                                                , gID
                                                , new DynamicControl(this, "REVISION").Text
                                                , "Document Created"
                                                , sFILENAME
                                                , sFILE_EXT
                                                , sFILE_MIME_TYPE
                                                , trn
                                                );
                                            LoadFile(gRevisionID, pstCONTENT.InputStream, trn);
                                        }
                                    }
                                }
                                else if (Sql.IsEmptyGuid(Request["ID"]) && !Sql.IsEmptyGuid(gDuplicateID))
                                {
                                    Guid gRevisionID = Guid.Empty;
                                    // 03/04/2006 Paul.  We need a separate procedure to copy the document stored in the revisions table.
                                    SqlProcs.spDOCUMENT_REVISIONS_Duplicate
                                        (ref gRevisionID
                                        , gID
                                        , gDuplicateID
                                        , new DynamicControl(this, "REVISION").Text
                                        , "Document Created"
                                        , trn
                                        );
                                }

                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
Esempio n. 19
0
 public void AppendGridColumns(string sGRID_NAME)
 {
     SplendidDynamic.AppendGridColumns(sGRID_NAME, this);
 }
Esempio n. 20
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                this.ValidateEditViewFields(m_sMODULE + ".EditAddress");
                if (Page.IsValid)
                {
                    string      sUSER_PREFERENCES = String.Empty;
                    XmlDocument xml = new XmlDocument();
                    try
                    {
                        try
                        {
                            sUSER_PREFERENCES = Sql.ToString(ViewState["USER_PREFERENCES"]);
                            xml.LoadXml(sUSER_PREFERENCES);
                        }
                        catch (Exception ex)
                        {
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                            xml.AppendChild(xml.CreateProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\""));
                            xml.AppendChild(xml.CreateElement("USER_PREFERENCE"));
                        }
                        // user_settings
                        XmlUtil.SetSingleNode(xml, "gridline", chkGRIDLINE.Checked ? "true" : "false");
                        XmlUtil.SetSingleNode(xml, "culture", lstLANGUAGE.SelectedValue);
                        XmlUtil.SetSingleNode(xml, "theme", lstTHEME.SelectedValue);
                        XmlUtil.SetSingleNode(xml, "dateformat", lstDATE_FORMAT.SelectedValue);
                        XmlUtil.SetSingleNode(xml, "timeformat", lstTIME_FORMAT.SelectedValue);
                        XmlUtil.SetSingleNode(xml, "timezone", lstTIMEZONE.SelectedValue);
                        XmlUtil.SetSingleNode(xml, "currency_id", lstCURRENCY.SelectedValue);
                        XmlUtil.SetSingleNode(xml, "num_grp_sep", txtGROUP_SEPARATOR.Text);
                        XmlUtil.SetSingleNode(xml, "dec_sep", txtDECIMAL_SEPARATOR.Text);
                        // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.
                        //XmlUtil.SetSingleNode(xml, "reminder_time"       , chkSHOULD_REMIND.Checked ? lstREMINDER_TIME.SelectedValue : "0" );
                        // mail_options

                        string sMAIL_SMTPPASS = Sql.ToString(ViewState["mail_smtppass"]);
                        // 08/06/2005 Paul.  Password might be our empty value.
                        TextBox txtMAIL_SMTPPASS = FindControl("MAIL_SMTPPASS") as TextBox;
                        if (txtMAIL_SMTPPASS != null)
                        {
                            // 08/05/2006 Paul.  Allow the password to be cleared.
                            if (txtMAIL_SMTPPASS.Text != sEMPTY_PASSWORD)
                            {
                                sMAIL_SMTPPASS = txtMAIL_SMTPPASS.Text;
                            }
                        }

                        XmlUtil.SetSingleNode(xml, "mail_fromname", new DynamicControl(this, "MAIL_FROMNAME").Text);
                        XmlUtil.SetSingleNode(xml, "mail_fromaddress", new DynamicControl(this, "MAIL_FROMADDRESS").Text);
                        XmlUtil.SetSingleNode(xml, "mail_smtpserver", new DynamicControl(this, "MAIL_SMTPSERVER").Text);
                        XmlUtil.SetSingleNode(xml, "mail_smtpport", new DynamicControl(this, "MAIL_SMTPPORT").Text);
                        XmlUtil.SetSingleNode(xml, "mail_sendtype", new DynamicControl(this, "MAIL_SENDTYPE").Text);
                        XmlUtil.SetSingleNode(xml, "mail_smtpauth_req", new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked ? "true" : "false");
                        XmlUtil.SetSingleNode(xml, "mail_smtpuser", new DynamicControl(this, "MAIL_SMTPUSER").Text);
                        XmlUtil.SetSingleNode(xml, "mail_smtppass", sMAIL_SMTPPASS);

                        // freebusy
                        // 08/05/2006 Paul.  Remove stub of unsupported code. Calendar Publish Key is not supported at this time.
                        //XmlUtil.SetSingleNode(xml, "calendar_publish_key", txtCALENDAR_PUBLISH_KEY .Text         );
                        //XmlUtil.SetSingleNode(xml, "calendar_publish_url", txtCALENDAR_PUBLISH_URL .Text         );
                        //XmlUtil.SetSingleNode(xml, "calendar_search_url" , txtCALENDAR_SEARCH_URL  .Text         );
                    }
                    catch (Exception ex)
                    {
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                    }
                    if (Sql.ToBoolean(Application["CONFIG.XML_UserPreferences"]))
                    {
                        sUSER_PREFERENCES = xml.OuterXml;
                    }
                    else
                    {
                        sUSER_PREFERENCES = XmlUtil.ConvertToPHP(xml.DocumentElement);
                    }

                    // 12/06/2005 Paul.  Need to prevent duplicate users.
                    string            sUSER_NAME = txtUSER_NAME.Text.Trim();
                    DbProviderFactory dbf        = DbProviderFactories.GetFactory();
                    try
                    {
                        // 11/10/2006 Paul.  If the decimal and group separate match, then .NET will not be able to parse decimals.
                        // The exception "Input string was not in a correct format." is thrown.
                        if (txtGROUP_SEPARATOR.Text == txtDECIMAL_SEPARATOR.Text)
                        {
                            throw(new Exception(L10n.Term("Users.LBL_INVALID_DECIMAL")));
                        }
                        if (!Sql.IsEmptyString(sUSER_NAME))
                        {
                            using (IDbConnection con = dbf.CreateConnection())
                            {
                                string sSQL;
                                sSQL = "select USER_NAME             " + ControlChars.CrLf
                                       + "  from vwUSERS               " + ControlChars.CrLf
                                       + " where USER_NAME = @USER_NAME" + ControlChars.CrLf;
                                using (IDbCommand cmd = con.CreateCommand())
                                {
                                    cmd.CommandText = sSQL;
                                    Sql.AddParameter(cmd, "@USER_NAME", sUSER_NAME);
                                    if (!Sql.IsEmptyGuid(gID))
                                    {
                                        // 12/06/2005 Paul.  Only include the ID if it is not null as we cannot compare NULL to anything.
                                        cmd.CommandText += "   and ID <> @ID" + ControlChars.CrLf;
                                        Sql.AddParameter(cmd, "@ID", gID);
                                    }
                                    con.Open();
                                    using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                    {
                                        if (rdr.Read())
                                        {
                                            string sMESSAGE = String.Empty;
                                            sMESSAGE = String.Format(L10n.Term("Users.ERR_USER_NAME_EXISTS_1") + "{0}" + L10n.Term("Users.ERR_USER_NAME_EXISTS_2"), sUSER_NAME);
                                            throw(new Exception(sMESSAGE));
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                        ctlEditButtons.ErrorText = ex.Message;
                        return;
                    }

                    string    sCUSTOM_MODULE = "USERS";
                    DataTable dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwUSERS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                bool bNewUser = Sql.IsEmptyGuid(gID);
                                // 04/24/2006 Paul.  Upgrade to SugarCRM 4.2 Schema.
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                SqlProcs.spUSERS_Update
                                    (ref gID
                                    , sUSER_NAME
                                    , txtFIRST_NAME.Text
                                    , txtLAST_NAME.Text
                                    , new DynamicControl(this, rowCurrent, "REPORTS_TO_ID").ID
                                    , (Security.IS_ADMIN ? chkIS_ADMIN.Checked : Sql.ToBoolean(ViewState["IS_ADMIN"]))
                                    , chkRECEIVE_NOTIFICATIONS.Checked
                                    , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                    , new DynamicControl(this, rowCurrent, "TITLE").Text
                                    , new DynamicControl(this, rowCurrent, "DEPARTMENT").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_HOME").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_MOBILE").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_WORK").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_OTHER").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_FAX").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL1").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL2").Text
                                    , lstSTATUS.SelectedValue
                                    , new DynamicControl(this, rowCurrent, "ADDRESS_STREET").Text
                                    , new DynamicControl(this, rowCurrent, "ADDRESS_CITY").Text
                                    , new DynamicControl(this, rowCurrent, "ADDRESS_STATE").Text
                                    , new DynamicControl(this, rowCurrent, "ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, rowCurrent, "ADDRESS_COUNTRY").Text
                                    , sUSER_PREFERENCES
                                    , chkPORTAL_ONLY.Checked
                                    , new DynamicControl(this, rowCurrent, "EMPLOYEE_STATUS").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "MESSENGER_ID").Text
                                    , new DynamicControl(this, rowCurrent, "MESSENGER_TYPE").SelectedValue
                                    , sMODULE
                                    , gPARENT_ID
                                    , new DynamicControl(this, rowCurrent, "IS_GROUP").Checked
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                                // 09/09/2006 Paul.  Refresh cached user information.
                                if (bNewUser)
                                {
                                    SplendidCache.ClearUsers();
                                }
                                // 08/27/2005 Paul. Reload session with user preferences.
                                // 08/30/2005 Paul. Only reload preferences the user is editing his own profile.
                                // We want to allow an administrator to update other user profiles.
                                if (Security.USER_ID == gID)
                                {
                                    SplendidInit.LoadUserPreferences(gID, lstTHEME.SelectedValue, lstLANGUAGE.SelectedValue);
                                }
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else if (bMyAccount)
                    {
                        Response.Redirect("MyAccount.aspx");
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (bMyAccount)
                {
                    Response.Redirect("MyAccount.aspx");
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "CONTRACTS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *               " + ControlChars.CrLf
                                   + "  from vwCONTRACTS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 11/19/2006 Paul.  OPPORTUNITY_ID was added.
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                // 11/30/2007 Paul.  Change TYPE to unique identifier and rename to TYPE_ID.
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spCONTRACTS_Update
                                    (ref gID
                                    , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, rowCurrent, "NAME").Text
                                    , new DynamicControl(this, rowCurrent, "REFERENCE_CODE").Text
                                    , new DynamicControl(this, rowCurrent, "STATUS").Text
                                    , new DynamicControl(this, rowCurrent, "TYPE_ID").ID
                                    , new DynamicControl(this, rowCurrent, "ACCOUNT_ID").ID
                                    , new DynamicControl(this, rowCurrent, "OPPORTUNITY_ID").ID
                                    , new DynamicControl(this, rowCurrent, "START_DATE").DateValue
                                    , new DynamicControl(this, rowCurrent, "END_DATE").DateValue
                                    , new DynamicControl(this, rowCurrent, "COMPANY_SIGNED_DATE").DateValue
                                    , new DynamicControl(this, rowCurrent, "CUSTOMER_SIGNED_DATE").DateValue
                                    , new DynamicControl(this, rowCurrent, "EXPIRATION_NOTICE").DateValue
                                    , new DynamicControl(this, rowCurrent, "CURRENCY_ID").ID
                                    , new DynamicControl(this, rowCurrent, "TOTAL_CONTRACT_VALUE").DecimalValue
                                    , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                    , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);

                                // 04/29/2007 Paul.  Assign quote if created from Quote.
                                Guid gQUOTE_ID = Sql.ToGuid(Request["QUOTE_ID"]);
                                if (!Sql.IsEmptyGuid(gQUOTE_ID))
                                {
                                    SqlProcs.spCONTRACTS_QUOTES_Update(gID, gQUOTE_ID, trn);
                                }
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid gPARENT_ID = Sql.ToGuid(Request["PARENT_ID"]);
            // 05/31/2007 Paul.  Use separate request fields when creating a contact from a call or a meeting.
            Guid   gCALL_ID     = Sql.ToGuid(Request["CALL_ID"]);
            Guid   gMEETING_ID  = Sql.ToGuid(Request["MEETING_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                this.ValidateEditViewFields(m_sMODULE + ".EditAddress");
                this.ValidateEditViewFields(m_sMODULE + ".EditDescription");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "CONTACTS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *              " + ControlChars.CrLf
                                   + "  from vwCONTACTS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spCONTACTS_Update
                                    (ref gID
                                    , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, rowCurrent, "SALUTATION").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "FIRST_NAME").Text
                                    , new DynamicControl(this, rowCurrent, "LAST_NAME").Text
                                    , new DynamicControl(this, rowCurrent, "ACCOUNT_ID").ID
                                    , new DynamicControl(this, rowCurrent, "LEAD_SOURCE").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "TITLE").Text
                                    , new DynamicControl(this, rowCurrent, "DEPARTMENT").Text
                                    , new DynamicControl(this, rowCurrent, "REPORTS_TO_ID").ID
                                    , new DynamicControl(this, rowCurrent, "BIRTHDATE").DateValue
                                    , new DynamicControl(this, rowCurrent, "DO_NOT_CALL").Checked
                                    , new DynamicControl(this, rowCurrent, "PHONE_HOME").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_MOBILE").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_WORK").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_OTHER").Text
                                    , new DynamicControl(this, rowCurrent, "PHONE_FAX").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL1").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL2").Text
                                    , new DynamicControl(this, rowCurrent, "ASSISTANT").Text
                                    , new DynamicControl(this, rowCurrent, "ASSISTANT_PHONE").Text
                                    , new DynamicControl(this, rowCurrent, "EMAIL_OPT_OUT").Checked
                                    , new DynamicControl(this, rowCurrent, "INVALID_EMAIL").Checked
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_STREET").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_CITY").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_STATE").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, rowCurrent, "PRIMARY_ADDRESS_COUNTRY").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_STREET").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_CITY").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_STATE").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, rowCurrent, "ALT_ADDRESS_COUNTRY").Text
                                    , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                    , sMODULE
                                    , gPARENT_ID
                                    , new DynamicControl(this, "SYNC_CONTACT").Checked
                                    , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);

                                // 05/31/2007 Paul.  Use separate request fields when creating a contact from a call or a meeting.
                                if (!Sql.IsEmptyGuid(gCALL_ID))
                                {
                                    SqlProcs.spCALLS_CONTACTS_Update(gCALL_ID, gID, false, String.Empty, trn);
                                }
                                if (!Sql.IsEmptyGuid(gMEETING_ID))
                                {
                                    SqlProcs.spMEETINGS_CONTACTS_Update(gMEETING_ID, gID, false, String.Empty, trn);
                                }
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else if (!Sql.IsEmptyGuid(gCALL_ID))
                    {
                        Response.Redirect("~/Calls/view.aspx?ID=" + gCALL_ID.ToString());
                    }
                    else if (!Sql.IsEmptyGuid(gMEETING_ID))
                    {
                        Response.Redirect("~/Meetings/view.aspx?ID=" + gMEETING_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (!Sql.IsEmptyGuid(gCALL_ID))
                {
                    Response.Redirect("~/Calls/view.aspx?ID=" + gCALL_ID.ToString());
                }
                else if (!Sql.IsEmptyGuid(gMEETING_ID))
                {
                    Response.Redirect("~/Meetings/view.aspx?ID=" + gMEETING_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            Guid gCAMPAIGN_ID = Sql.ToGuid(Request["CAMPAIGN_ID"]);

            if (e.CommandName == "Save")
            {
                // 09/22/2007 Paul.  When the IE text box is disabled, it does not submit the data.
                // Correcting this behavior here seems reasonable.
                bool bIS_OPTOUT = new DynamicControl(this, "IS_OPTOUT").Checked;
                if (bIS_OPTOUT)
                {
                    new DynamicControl(this, "TRACKER_URL").Text = "RemoveMe.aspx";
                }

                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "CAMPAIGN_TRKRS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *                    " + ControlChars.CrLf
                                   + "  from vwCAMPAIGN_TRKRS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                SqlProcs.spCAMPAIGN_TRKRS_Update(ref gID
                                                                 , new DynamicControl(this, rowCurrent, "TRACKER_NAME").Text
                                                                 , new DynamicControl(this, rowCurrent, "TRACKER_URL").Text
                                                                 , new DynamicControl(this, rowCurrent, "CAMPAIGN_ID").ID
                                                                 , new DynamicControl(this, rowCurrent, "IS_OPTOUT").Checked
                                                                 , trn
                                                                 );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gCAMPAIGN_ID))
                    {
                        Response.Redirect("~/Campaigns/view.aspx?ID=" + gCAMPAIGN_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gCAMPAIGN_ID))
                {
                    Response.Redirect("~/Campaigns/view.aspx?ID=" + gCAMPAIGN_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
 protected void Page_Command(Object sender, CommandEventArgs e)
 {
     if (e.CommandName == "Save")
     {
         // 01/16/2006 Paul.  Enable validator before validating page.
         SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
         if (Page.IsValid)
         {
             string            sCUSTOM_MODULE = "PRODUCT_TEMPLATES";
             DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
             DbProviderFactory dbf            = DbProviderFactories.GetFactory();
             using (IDbConnection con = dbf.CreateConnection())
             {
                 con.Open();
                 using (IDbTransaction trn = con.BeginTransaction())
                 {
                     try
                     {
                         SqlProcs.spPRODUCT_TEMPLATES_Update
                             (ref gID
                             , new DynamicControl(this, "NAME").Text
                             , new DynamicControl(this, "STATUS").SelectedValue
                             , new DynamicControl(this, "QUANTITY").IntegerValue
                             , new DynamicControl(this, "DATE_AVAILABLE").DateValue
                             , new DynamicControl(this, "DATE_COST_PRICE").DateValue
                             , new DynamicControl(this, "ACCOUNT_ID").ID
                             , new DynamicControl(this, "MANUFACTURER_ID").ID
                             , new DynamicControl(this, "CATEGORY_ID").ID
                             , new DynamicControl(this, "TYPE_ID").ID
                             , new DynamicControl(this, "WEBSITE").Text
                             , new DynamicControl(this, "MFT_PART_NUM").Text
                             , new DynamicControl(this, "VENDOR_PART_NUM").Text
                             , new DynamicControl(this, "TAX_CLASS").SelectedValue
                             , new DynamicControl(this, "WEIGHT").FloatValue
                             , new DynamicControl(this, "CURRENCY_ID").ID
                             , new DynamicControl(this, "COST_PRICE").DecimalValue
                             , new DynamicControl(this, "LIST_PRICE").DecimalValue
                             , new DynamicControl(this, "DISCOUNT_PRICE").DecimalValue
                             , new DynamicControl(this, "PRICING_FACTOR").IntegerValue
                             , new DynamicControl(this, "PRICING_FORMULA").SelectedValue
                             , new DynamicControl(this, "SUPPORT_NAME").Text
                             , new DynamicControl(this, "SUPPORT_CONTACT").Text
                             , new DynamicControl(this, "SUPPORT_DESCRIPTION").Text
                             , new DynamicControl(this, "SUPPORT_TERM").SelectedValue
                             , new DynamicControl(this, "DESCRIPTION").Text
                             , trn
                             );
                         SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                         trn.Commit();
                     }
                     catch (Exception ex)
                     {
                         trn.Rollback();
                         SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                         ctlEditButtons.ErrorText = ex.Message;
                         return;
                     }
                 }
             }
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
     else if (e.CommandName == "Cancel")
     {
         if (Sql.IsEmptyGuid(gID))
         {
             Response.Redirect("default.aspx");
         }
         else
         {
             Response.Redirect("view.aspx?ID=" + gID.ToString());
         }
     }
 }
Esempio n. 25
0
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "PROSPECT_LISTS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *                    " + ControlChars.CrLf
                                   + "  from vwPROSPECT_LISTS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                // 04/24/2006 Paul.  Upgrade to SugarCRM 4.2 Schema.
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spPROSPECT_LISTS_Update
                                    (ref gID
                                    , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, rowCurrent, "NAME").Text
                                    , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                    , sMODULE
                                    , gPARENT_ID
                                    , new DynamicControl(this, rowCurrent, "LIST_TYPE").Text
                                    , new DynamicControl(this, rowCurrent, "DOMAIN_NAME").Text
                                    , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            if (e.CommandName == "Save")
            {
                try
                {
                    // 01/16/2006 Paul.  Enable validator before validating page.
                    SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                    if (Page.IsValid)
                    {
                        DataTable         dtACLACCESS = null;
                        DbProviderFactory dbf         = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            con.Open();
                            string sSQL;
                            sSQL = "select MODULE_NAME          " + ControlChars.CrLf
                                   + "     , DISPLAY_NAME         " + ControlChars.CrLf
                                   + "     , ACLACCESS_ADMIN      " + ControlChars.CrLf
                                   + "     , ACLACCESS_ACCESS     " + ControlChars.CrLf
                                   + "     , ACLACCESS_VIEW       " + ControlChars.CrLf
                                   + "     , ACLACCESS_LIST       " + ControlChars.CrLf
                                   + "     , ACLACCESS_EDIT       " + ControlChars.CrLf
                                   + "     , ACLACCESS_DELETE     " + ControlChars.CrLf
                                   + "     , ACLACCESS_IMPORT     " + ControlChars.CrLf
                                   + "     , ACLACCESS_EXPORT     " + ControlChars.CrLf
                                   + "  from vwACL_ACCESS_ByModule" + ControlChars.CrLf
                                   + " order by MODULE_NAME       " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    dtACLACCESS = new DataTable();
                                    da.Fill(dtACLACCESS);
                                }
                            }

                            string    sCUSTOM_MODULE = "ACL_ROLES";
                            DataTable dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                            using (IDbTransaction trn = con.BeginTransaction())
                            {
                                try
                                {
                                    SqlProcs.spACL_ROLES_Update(ref gID
                                                                , new DynamicControl(this, "NAME").Text
                                                                , new DynamicControl(this, "DESCRIPTION").Text
                                                                , trn
                                                                );
                                    SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);

                                    foreach (DataRow row in dtACLACCESS.Rows)
                                    {
                                        string sMODULE_NAME = Sql.ToString(row["MODULE_NAME"]);
                                        // 04/25/2006 Paul.  FindControl needs to be executed on the DataGridItem.  I'm not sure why.
                                        DropDownList lstAccess       = lstAccess = ctlAccessView.FindACLControl(sMODULE_NAME, "access");
                                        DropDownList lstView         = ctlAccessView.FindACLControl(sMODULE_NAME, "view");
                                        DropDownList lstList         = ctlAccessView.FindACLControl(sMODULE_NAME, "list");
                                        DropDownList lstEdit         = ctlAccessView.FindACLControl(sMODULE_NAME, "edit");
                                        DropDownList lstDelete       = ctlAccessView.FindACLControl(sMODULE_NAME, "delete");
                                        DropDownList lstImport       = ctlAccessView.FindACLControl(sMODULE_NAME, "import");
                                        DropDownList lstExport       = ctlAccessView.FindACLControl(sMODULE_NAME, "export");
                                        Guid         gActionAccessID = Guid.Empty;
                                        Guid         gActionViewID   = Guid.Empty;
                                        Guid         gActionListID   = Guid.Empty;
                                        Guid         gActionEditID   = Guid.Empty;
                                        Guid         gActionDeleteID = Guid.Empty;
                                        Guid         gActionImportID = Guid.Empty;
                                        Guid         gActionExportID = Guid.Empty;
                                        if (lstAccess != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionAccessID, gID, "access", sMODULE_NAME, Sql.ToInteger(lstAccess.SelectedValue), trn);
                                        }
                                        if (lstView != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionViewID, gID, "view", sMODULE_NAME, Sql.ToInteger(lstView.SelectedValue), trn);
                                        }
                                        if (lstList != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionListID, gID, "list", sMODULE_NAME, Sql.ToInteger(lstList.SelectedValue), trn);
                                        }
                                        if (lstEdit != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionEditID, gID, "edit", sMODULE_NAME, Sql.ToInteger(lstEdit.SelectedValue), trn);
                                        }
                                        if (lstDelete != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionDeleteID, gID, "delete", sMODULE_NAME, Sql.ToInteger(lstDelete.SelectedValue), trn);
                                        }
                                        if (lstImport != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionImportID, gID, "import", sMODULE_NAME, Sql.ToInteger(lstImport.SelectedValue), trn);
                                        }
                                        if (lstExport != null)
                                        {
                                            SqlProcs.spACL_ROLES_ACTIONS_Update(ref gActionExportID, gID, "export", sMODULE_NAME, Sql.ToInteger(lstExport.SelectedValue), trn);
                                        }
                                        //break;
                                    }
                                    trn.Commit();
                                }
                                catch (Exception ex)
                                {
                                    trn.Rollback();
                                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                    ctlEditButtons.ErrorText = ex.Message;
                                    return;
                                }
                            }
                        }
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
                catch (Exception ex)
                {
                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                    ctlEditButtons.ErrorText = ex.Message;
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "OPPORTUNITIES";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                SqlProcs.spOPPORTUNITIES_Update
                                    (ref gID
                                    , new DynamicControl(this, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, "ACCOUNT_ID").ID
                                    , new DynamicControl(this, "NAME").Text
                                    , new DynamicControl(this, "OPPORTUNITY_TYPE").SelectedValue
                                    , new DynamicControl(this, "LEAD_SOURCE").SelectedValue
                                    , new DynamicControl(this, "AMOUNT").DecimalValue
                                    , new DynamicControl(this, "CURRENCY_ID").ID                                           // 03/04/2006 Paul.  Correct name is CURRENCY_ID.
                                    , new DynamicControl(this, "DATE_CLOSED").DateValue
                                    , new DynamicControl(this, "NEXT_STEP").Text
                                    , new DynamicControl(this, "SALES_STAGE").SelectedValue
                                    , new DynamicControl(this, "PROBABILITY").FloatValue
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , sMODULE
                                    , gPARENT_ID
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                this.ValidateEditViewFields(m_sMODULE + ".EditView");
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "BUGS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                        DataRow   rowCurrent = null;
                        DataTable dtCurrent  = new DataTable();
                        if (!Sql.IsEmptyGuid(gID))
                        {
                            string sSQL;
                            sSQL = "select *          " + ControlChars.CrLf
                                   + "  from vwBUGS_Edit" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Security.Filter(cmd, m_sMODULE, "edit");
                                Sql.AppendParameter(cmd, gID, "ID", false);
                                using (DbDataAdapter da = dbf.CreateDataAdapter())
                                {
                                    ((IDbDataAdapter)da).SelectCommand = cmd;
                                    da.Fill(dtCurrent);
                                    if (dtCurrent.Rows.Count > 0)
                                    {
                                        rowCurrent = dtCurrent.Rows[0];
                                    }
                                    else
                                    {
                                        // 11/19/2007 Paul.  If the record is not found, clear the ID so that the record cannot be updated.
                                        // It is possible that the record exists, but that ACL rules prevent it from being selected.
                                        gID = Guid.Empty;
                                    }
                                }
                            }
                        }

                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                //die("ERROR: uploaded file was too big: max filesize: {$sugar_config['upload_maxsize']}");
                                HtmlInputFile  fileATTACHMENT = FindControl("ATTACHMENT") as HtmlInputFile;
                                HttpPostedFile pstATTACHMENT  = null;
                                if (fileATTACHMENT != null)
                                {
                                    pstATTACHMENT = fileATTACHMENT.PostedFile;
                                }
                                if (pstATTACHMENT != null)
                                {
                                    long lFileSize      = pstATTACHMENT.ContentLength;
                                    long lUploadMaxSize = Sql.ToLong(Application["CONFIG.upload_maxsize"]);
                                    if ((lUploadMaxSize > 0) && (lFileSize > lUploadMaxSize))
                                    {
                                        throw(new Exception("ERROR: uploaded file was too big: max filesize: " + lUploadMaxSize.ToString()));
                                    }
                                }
                                // 07/04/2007 Paul.  The Releases list references the fields as IDs, but we need to use them as text values in the detail and grid views.
                                // This also fixes a bug whereby the FOUND_IN_RELEASE field was feed data from a field call RELEASE, which did not exist.
                                // 11/18/2007 Paul.  Use the current values for any that are not defined in the edit view.
                                // 12/29/2007 Paul.  TEAM_ID is now in the stored procedure.
                                SqlProcs.spBUGS_Update
                                    (ref gID
                                    , new DynamicControl(this, rowCurrent, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, rowCurrent, "NAME").Text
                                    , new DynamicControl(this, rowCurrent, "STATUS").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "PRIORITY").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "DESCRIPTION").Text
                                    , new DynamicControl(this, rowCurrent, "RESOLUTION").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "FOUND_IN_RELEASE_ID").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "TYPE").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "FIXED_IN_RELEASE_ID").SelectedValue
                                    , new DynamicControl(this, rowCurrent, "WORK_LOG").Text
                                    , new DynamicControl(this, rowCurrent, "SOURCE").Text
                                    , new DynamicControl(this, rowCurrent, "PRODUCT_CATEGORY").SelectedValue
                                    , sMODULE
                                    , gPARENT_ID
                                    , new DynamicControl(this, rowCurrent, "TEAM_ID").ID
                                    , trn
                                    );
                                if (pstATTACHMENT != null)
                                {
                                    // 08/20/2005 Paul.  File may not have been provided.
                                    if (pstATTACHMENT.FileName.Length > 0)
                                    {
                                        string sFILENAME       = Path.GetFileName(pstATTACHMENT.FileName);
                                        string sFILE_EXT       = Path.GetExtension(sFILENAME);
                                        string sFILE_MIME_TYPE = pstATTACHMENT.ContentType;

                                        Guid gAttachmentID = Guid.Empty;
                                        // 01/20/2006 Paul.  Must include in transaction
                                        SqlProcs.spBUG_ATTACHMENTS_Insert(ref gAttachmentID, gID, pstATTACHMENT.FileName, sFILENAME, sFILE_EXT, sFILE_MIME_TYPE, trn);
                                        LoadFile(gAttachmentID, pstATTACHMENT.InputStream, trn);
                                    }
                                }
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
        protected void Page_Command(Object sender, CommandEventArgs e)
        {
            // 08/21/2005 Paul.  Redirect to parent if that is where the note was originated.
            Guid   gPARENT_ID   = Sql.ToGuid(Request["PARENT_ID"]);
            string sMODULE      = String.Empty;
            string sPARENT_TYPE = String.Empty;
            string sPARENT_NAME = String.Empty;

            try
            {
                SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                // The only possible error is a connection failure, so just ignore all errors.
                gPARENT_ID = Guid.Empty;
            }
            if (e.CommandName == "Save")
            {
                // 01/16/2006 Paul.  Enable validator before validating page.
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditView", this);
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditAddress", this);
                SplendidDynamic.ValidateEditViewFields(m_sMODULE + ".EditDescription", this);
                if (Page.IsValid)
                {
                    string            sCUSTOM_MODULE = "CONTACTS";
                    DataTable         dtCustomFields = SplendidCache.FieldsMetaData_Validated(sCUSTOM_MODULE);
                    DbProviderFactory dbf            = DbProviderFactories.GetFactory();
                    using (IDbConnection con = dbf.CreateConnection())
                    {
                        con.Open();
                        using (IDbTransaction trn = con.BeginTransaction())
                        {
                            try
                            {
                                SqlProcs.spCONTACTS_Update
                                    (ref gID
                                    , new DynamicControl(this, "ASSIGNED_USER_ID").ID
                                    , new DynamicControl(this, "SALUTATION").SelectedValue
                                    , new DynamicControl(this, "FIRST_NAME").Text
                                    , new DynamicControl(this, "LAST_NAME").Text
                                    , new DynamicControl(this, "ACCOUNT_ID").ID
                                    , new DynamicControl(this, "LEAD_SOURCE").SelectedValue
                                    , new DynamicControl(this, "TITLE").Text
                                    , new DynamicControl(this, "DEPARTMENT").Text
                                    , new DynamicControl(this, "REPORTS_TO_ID").ID
                                    , new DynamicControl(this, "BIRTHDATE").DateValue
                                    , new DynamicControl(this, "DO_NOT_CALL").Checked
                                    , new DynamicControl(this, "PHONE_HOME").Text
                                    , new DynamicControl(this, "PHONE_MOBILE").Text
                                    , new DynamicControl(this, "PHONE_WORK").Text
                                    , new DynamicControl(this, "PHONE_OTHER").Text
                                    , new DynamicControl(this, "PHONE_FAX").Text
                                    , new DynamicControl(this, "EMAIL1").Text
                                    , new DynamicControl(this, "EMAIL2").Text
                                    , new DynamicControl(this, "ASSISTANT").Text
                                    , new DynamicControl(this, "ASSISTANT_PHONE").Text
                                    , new DynamicControl(this, "EMAIL_OPT_OUT").Checked
                                    , new DynamicControl(this, "INVALID_EMAIL").Checked
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_STREET").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_CITY").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_STATE").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, "PRIMARY_ADDRESS_COUNTRY").Text
                                    , new DynamicControl(this, "ALT_ADDRESS_STREET").Text
                                    , new DynamicControl(this, "ALT_ADDRESS_CITY").Text
                                    , new DynamicControl(this, "ALT_ADDRESS_STATE").Text
                                    , new DynamicControl(this, "ALT_ADDRESS_POSTALCODE").Text
                                    , new DynamicControl(this, "ALT_ADDRESS_COUNTRY").Text
                                    , new DynamicControl(this, "DESCRIPTION").Text
                                    , sMODULE
                                    , gPARENT_ID
                                    , new DynamicControl(this, "SYNC_CONTACT").Checked
                                    , trn
                                    );
                                SplendidDynamic.UpdateCustomFields(this, trn, gID, sCUSTOM_MODULE, dtCustomFields);
                                trn.Commit();
                            }
                            catch (Exception ex)
                            {
                                trn.Rollback();
                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                                ctlEditButtons.ErrorText = ex.Message;
                                return;
                            }
                        }
                    }
                    if (!Sql.IsEmptyGuid(gPARENT_ID))
                    {
                        Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                    }
                    else
                    {
                        Response.Redirect("view.aspx?ID=" + gID.ToString());
                    }
                }
            }
            else if (e.CommandName == "Cancel")
            {
                if (!Sql.IsEmptyGuid(gPARENT_ID))
                {
                    Response.Redirect("~/" + sMODULE + "/view.aspx?ID=" + gPARENT_ID.ToString());
                }
                else if (Sql.IsEmptyGuid(gID))
                {
                    Response.Redirect("default.aspx");
                }
                else
                {
                    Response.Redirect("view.aspx?ID=" + gID.ToString());
                }
            }
        }
Esempio n. 30
0
 protected void AppendEditViewFields(string sEDIT_NAME, HtmlTable tbl, IDataReader rdr)
 {
     // 12/02/2005 Paul.  AppendEditViewFields will get called inside InitializeComponent(),
     // which occurs before OnInit(), so make sure to initialize L10n.
     SplendidDynamic.AppendEditViewFields(sEDIT_NAME, tbl, rdr, GetL10n(), GetT10n());
 }