public void AppendEditViewFieldsEdit(string sEDIT_NAME, HtmlTable tbl, DataRowView rdr, ref int nRowIndex, string sFIELD_WIDTH, Hashtable hashIncludedFields, bool bIsPostBack) { DataTable dtFields = SplendidCache.EditViewFields(sEDIT_NAME); DataView dvFields = dtFields.DefaultView; string sIDSuffix = String.Empty; //if ( nRecordIndex > 0 ) // sIDSuffix = nRecordIndex.ToString("_##"); int nColIndex = 0; HtmlTableRow tr = null; HtmlTableCell tdLabel = null; HtmlTableCell tdField = null; if ( dvFields.Count == 0 && tbl.Rows.Count <= 1 ) tbl.Visible = false; // 01/18/2010 To apply ACL Field Security, we need to know if the current record has an ASSIGNED_USER_ID field, and its value. Guid gASSIGNED_USER_ID = Guid.Empty; DataColumnCollection vwSchema = null; if ( rdr != null ) { vwSchema = rdr.DataView.Table.Columns; if ( vwSchema.Contains("ASSIGNED_USER_ID") ) { gASSIGNED_USER_ID = Sql.ToGuid(rdr["ASSIGNED_USER_ID"]); } } bool bEnableTeamManagement = Crm.Config.enable_team_management(); bool bRequireTeamManagement = Crm.Config.require_team_management(); bool bRequireUserAssignment = Crm.Config.require_user_assignment(); // 08/01/2010 Allow dynamic teams to be turned off. bool bEnableDynamicTeams = Crm.Config.enable_dynamic_teams(); HttpSessionState Session = HttpContext.Current.Session; foreach(DataRowView row in dvFields) { int nFIELD_INDEX = Sql.ToInteger(row["FIELD_INDEX" ]); string sFIELD_TYPE = Sql.ToString (row["FIELD_TYPE" ]); string sDATA_LABEL = Sql.ToString (row["DATA_LABEL" ]); string sDATA_FIELD = Sql.ToString (row["DATA_FIELD" ]); string sDISPLAY_FIELD = Sql.ToString (row["DISPLAY_FIELD" ]); string sCACHE_NAME = Sql.ToString (row["CACHE_NAME" ]); bool bDATA_REQUIRED = Sql.ToBoolean(row["DATA_REQUIRED" ]); bool bUI_REQUIRED = Sql.ToBoolean(row["UI_REQUIRED" ]); string sONCLICK_SCRIPT = Sql.ToString (row["ONCLICK_SCRIPT" ]); string sFORMAT_SCRIPT = Sql.ToString (row["FORMAT_SCRIPT" ]); short nFORMAT_TAB_INDEX = Sql.ToShort (row["FORMAT_TAB_INDEX" ]); int nFORMAT_MAX_LENGTH = Sql.ToInteger(row["FORMAT_MAX_LENGTH"]); int nFORMAT_SIZE = Sql.ToInteger(row["FORMAT_SIZE" ]); int nFORMAT_ROWS = Sql.ToInteger(row["FORMAT_ROWS" ]); int nFORMAT_COLUMNS = Sql.ToInteger(row["FORMAT_COLUMNS" ]); int nCOLSPAN = Sql.ToInteger(row["COLSPAN" ]); // 04/02/2008 Add support for Regular Expression validation. string sFIELD_VALIDATOR_MESSAGE = Sql.ToString (row["FIELD_VALIDATOR_MESSAGE"]); string sVALIDATION_TYPE = Sql.ToString (row["VALIDATION_TYPE" ]); string sREGULAR_EXPRESSION = Sql.ToString (row["REGULAR_EXPRESSION" ]); string sDATA_TYPE = Sql.ToString (row["DATA_TYPE" ]); string sMININUM_VALUE = Sql.ToString (row["MININUM_VALUE" ]); string sMAXIMUM_VALUE = Sql.ToString (row["MAXIMUM_VALUE" ]); string sCOMPARE_OPERATOR = Sql.ToString (row["COMPARE_OPERATOR" ]); // 09/01/2009 Add support for a generic module popup. string sMODULE_TYPE = String.Empty; try { sMODULE_TYPE = Sql.ToString (row["MODULE_TYPE"]); } catch(Exception ex) { // 09/01/2009 The MODULE_TYPE is not in the view, then log the error and continue. SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } // 12/24/2008 Each field should be on a new line. nCOLSPAN = 0; // 12/27/2008 The data field will need to be in upper case in order for it to be found and saved. sDATA_FIELD = sDATA_FIELD.ToUpper(); sDISPLAY_FIELD = sDISPLAY_FIELD.ToUpper(); // 08/01/2010 To apply ACL Field Security, we need to know if the Module Name, which we will extract from the EditView Name. string sMODULE_NAME = String.Empty; string[] arrEDIT_NAME = sEDIT_NAME.Split('.'); if ( arrEDIT_NAME.Length > 0 ) sMODULE_NAME = arrEDIT_NAME[0]; bool bIsReadable = true; bool bIsWriteable = true; if ( SplendidInit.bEnableACLFieldSecurity ) { Security.ACL_FIELD_ACCESS acl = Security.GetUserFieldSecurity(sMODULE_NAME, sDATA_FIELD, gASSIGNED_USER_ID); bIsReadable = acl.IsReadable(); bIsWriteable = acl.IsWriteable(); } // 08/01/2010 If not readable, then just skip the field. if ( !bIsReadable ) continue; sDATA_LABEL = m_sMODULE + ".LBL_" + sDATA_FIELD; if ( sDATA_FIELD == "TEAM_ID" || sDATA_FIELD == "TEAM_SET_NAME" ) sDATA_LABEL = "Teams.LBL_TEAM"; else if ( sDATA_FIELD == "ASSIGNED_USER_ID" ) sDATA_LABEL = ".LBL_ASSIGNED_TO"; // 11/25/2006 If Team Management has been disabled, then convert the field to a blank. // Keep the field, but treat it as blank so that field indexes will still be valid. // 12/03/2006 Allow the team field to be visible during layout. if ( sDATA_FIELD == "TEAM_ID" || sDATA_FIELD == "TEAM_SET_NAME" ) { if ( !bEnableTeamManagement ) { sFIELD_TYPE = "Blank"; bUI_REQUIRED = false; } else { if ( bEnableDynamicTeams ) { // 08/31/2009 Don't convert to TeamSelect inside a Search view or Popup view. if ( sEDIT_NAME.IndexOf(".Search") < 0 && sEDIT_NAME.IndexOf(".Popup") < 0 ) { sDATA_LABEL = ".LBL_TEAM_SET_NAME"; sDATA_FIELD = "TEAM_SET_NAME"; sFIELD_TYPE = "TeamSelect"; sONCLICK_SCRIPT = String.Empty; } } else { // 04/18/2010 If the user manually adds a TeamSelect, we need to convert to a ModulePopup. if ( sFIELD_TYPE == "TeamSelect" ) { sDATA_LABEL = "Teams.LBL_TEAM"; sDATA_FIELD = "TEAM_ID"; sDISPLAY_FIELD = "TEAM_NAME"; sFIELD_TYPE = "ModulePopup"; sMODULE_TYPE = "Teams"; sONCLICK_SCRIPT = String.Empty; } } // 11/25/2006 Override the required flag with the system value. // 01/01/2008 If Team Management is not required, then let the admin decide. if ( bRequireTeamManagement ) bUI_REQUIRED = true; } } // 08/01/2010 Hide the Exchange Folder field if disabled for this module or user. if ( sDATA_FIELD == "EXCHANGE_FOLDER" ) { if ( !Crm.Modules.ExchangeFolders(sMODULE_NAME) || !Security.HasExchangeAlias() ) { sFIELD_TYPE = "Blank"; } } if ( String.Compare(sFIELD_TYPE, "AddressButtons", true) == 0 ) continue; else if ( String.Compare(sFIELD_TYPE, "Blank", true) == 0 ) continue; else if ( hashIncludedFields != null && !hashIncludedFields.ContainsKey(sDATA_FIELD) ) continue; if ( sDATA_FIELD == "ASSIGNED_USER_ID" ) { // 01/01/2008 We need a quick way to require user assignments across the system. if ( bRequireUserAssignment ) bUI_REQUIRED = true; } // 08/01/2010 Clear the Required flag if the field is writeable. // Clearing at this stage will apply it to all edit types. if ( bUI_REQUIRED && !bIsWriteable ) bUI_REQUIRED = false; if ( (nCOLSPAN >= 0 && nColIndex == 0) || tr == null ) { // 12/27/2008 We need an extra row for the set primary and remove links. if ( nRowIndex == 0 && tbl == tblMain ) { if ( tbl.Rows.Count > nRowIndex ) { tr = tbl.Rows[nRowIndex]; } else { tr = new HtmlTableRow(); tbl.Rows.Insert(nRowIndex, tr); } nRowIndex++; tdLabel = new HtmlTableCell(); tdField = new HtmlTableCell(); tr.Cells.Add(tdLabel); tr.Cells.Add(tdField); Label lblPrimaryID = new Label(); tdField.Controls.Add(lblPrimaryID); if ( rdr != null ) { Guid gPrimaryID = Sql.ToGuid(rdr["ID"]); #if DEBUG lblPrimaryID.Text = gPrimaryID.ToString(); #endif } } if ( tbl.Rows.Count > nRowIndex ) { tr = tbl.Rows[nRowIndex]; } else { tr = new HtmlTableRow(); tbl.Rows.Insert(nRowIndex, tr); } nRowIndex++; } // 12/03/2006 Move literal label up so that it can be accessed when processing a blank. Literal litLabel = new Literal(); if ( !Sql.IsEmptyString(sDATA_FIELD) ) litLabel.ID = sDATA_FIELD + "_LABEL" + sIDSuffix; if ( nCOLSPAN >= 0 || tdLabel == null || tdField == null ) { tdLabel = new HtmlTableCell(); tdField = new HtmlTableCell(); tr.Cells.Add(tdLabel); tr.Cells.Add(tdField); if ( nCOLSPAN > 0 ) { tdField.ColSpan = nCOLSPAN; } tdLabel.Attributes.Add("class", "dataLabel"); tdLabel.VAlign = "top"; tdLabel.Width = sFIELD_WIDTH; tdField.Attributes.Add("class", "dataField"); tdField.VAlign = "top"; tdField.Width = sFIELD_WIDTH; tdLabel.Controls.Add(litLabel); //litLabel.Text = nFIELD_INDEX.ToString() + " (" + nRowIndex.ToString() + "," + nColIndex.ToString() + ")"; try { // 12/03/2006 Move code to blank able in layout mode to blank section below. if ( sDATA_LABEL.IndexOf(".") >= 0 ) litLabel.Text = L10n.Term(sDATA_LABEL); else if ( !Sql.IsEmptyString(sDATA_LABEL) && rdr != null ) { // 01/27/2008 If the data label is not in the schema table, then it must be free-form text. // It is not used often, but we allow the label to come from the result set. For example, // when the parent is stored in the record, we need to pull the module name from the record. litLabel.Text = sDATA_LABEL; if ( rdr.DataView.Table.Columns.Contains(sDATA_LABEL) ) litLabel.Text = Sql.ToString(rdr[sDATA_LABEL]) + L10n.Term("Calls.LBL_COLON"); } // 07/15/2006 Always put something for the label so that table borders will look right. // 07/20/2007 Vandalo. Skip the requirement to create a terminology entry and just so the label. else litLabel.Text = sDATA_LABEL; // " "; } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); litLabel.Text = ex.Message; } if ( bUI_REQUIRED ) { Label lblRequired = new Label(); tdLabel.Controls.Add(lblRequired); lblRequired.CssClass = "required"; lblRequired.Text = L10n.Term(".LBL_REQUIRED_SYMBOL"); } } if ( String.Compare(sFIELD_TYPE, "Label", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { Literal litField = new Literal(); tdField.Controls.Add(litField); // 07/25/2006 Align label values to the middle so the line-up with the label. tdField.VAlign = "middle"; // 07/24/2006 Set the ID so that the literal control can be accessed. litField.ID = sDATA_FIELD + sIDSuffix; try { if ( sDATA_FIELD.IndexOf(".") >= 0 ) litField.Text = L10n.Term(sDATA_FIELD); else if ( rdr != null ) litField.Text = Sql.ToString(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); litField.Text = ex.Message; } } } else if ( String.Compare(sFIELD_TYPE, "ListBox", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/02/2007 If format rows > 0 then this is a list box and not a drop down list. ListControl lstField = null; if ( nFORMAT_ROWS > 0 ) { ListBox lb = new ListBox(); lb.SelectionMode = ListSelectionMode.Multiple; lb.Rows = nFORMAT_ROWS; lstField = lb; } else { // 04/25/2008 Use KeySortDropDownList instead of ListSearchExtender. lstField = new KeySortDropDownList(); // 07/23/2010 Lets try the latest version of the ListSearchExtender. // 07/28/2010 We are getting an undefined exception on the Accounts List Advanced page. // Lets drop back to using KeySort. //lstField = new DropDownList(); } tdField.Controls.Add(lstField); lstField.ID = sDATA_FIELD + sIDSuffix; lstField.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. lstField.Enabled = bIsWriteable; // 07/23/2010 Lets try the latest version of the ListSearchExtender. // 07/28/2010 We are getting an undefined exception on the Accounts List Advanced page. /* if ( nFORMAT_ROWS == 0 ) { AjaxControlToolkit.ListSearchExtender extField = new AjaxControlToolkit.ListSearchExtender(); extField.ID = lstField.ID + "_ListSearchExtender"; extField.TargetControlID = lstField.ID; extField.PromptText = L10n.Term(".LBL_TYPE_TO_SEARCH"); extField.PromptCssClass = "ListSearchExtenderPrompt"; tdField.Controls.Add(extField); } */ try { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/04/2005 Don't populate list if this is a post back. if ( !Sql.IsEmptyString(sCACHE_NAME) && (!bIsPostBack) ) { // 12/24/2007 Use an array to define the custom caches so that list is in the Cache module. // This should reduce the number of times that we have to edit the SplendidDynamic module. // 02/16/2012 Move custom cache logic to a method. SplendidCache.SetListSource(sCACHE_NAME, lstField); lstField.DataBind(); // 08/08/2006 Allow onchange code to be stored in the database. // ListBoxes do not have a useful onclick event, so there should be no problem overloading this field. if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) ) lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT); // 02/21/2006 Move the NONE item inside the !IsPostBack code. // 12/02/2007 We don't need a NONE record when using multi-selection. // 12/03/2007 We do want the NONE record when using multi-selection. // This will allow searching of fields that are null instead of using the unassigned only checkbox. if ( !bUI_REQUIRED ) { lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), "")); // 12/02/2007 AppendEditViewFields should be called inside Page_Load when not a postback, // and in InitializeComponent when it is a postback. If done wrong, // the page will bind after the list is populated, causing the list to populate again. // This event will cause the NONE entry to be cleared. Add a handler to catch this problem, // but the real solution is to call AppendEditViewFields at the appropriate times based on the postback event. lstField.DataBound += new EventHandler(SplendidDynamic.ListControl_DataBound_AllowNull); } } if ( rdr != null ) { try { // 02/21/2006 All the DropDownLists in the Calls and Meetings edit views were not getting set. // The problem was a Page.DataBind in the SchedulingGrid and in the InviteesView. Both binds needed to be removed. // 12/30/2007 A customer needed the ability to save and restore the multiple selection. // 12/30/2007 Require the XML declaration in the data before trying to treat as XML. string sVALUE = Sql.ToString(rdr[sDATA_FIELD]); if ( nFORMAT_ROWS > 0 && sVALUE.StartsWith("<?xml") ) { XmlDocument xml = new XmlDocument(); xml.LoadXml(sVALUE); XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value"); foreach ( XmlNode xValue in nlValues ) { foreach ( ListItem item in lstField.Items ) { if ( item.Value == xValue.InnerText ) item.Selected = true; } } } else { // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, sVALUE); } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } // 08/21/2010 Add support for Radio buttons. else if ( String.Compare(sFIELD_TYPE, "Radio", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { ListControl lstField = new RadioButtonList(); tdField.Controls.Add(lstField); lstField.ID = sDATA_FIELD + sIDSuffix; lstField.TabIndex = nFORMAT_TAB_INDEX; lstField.CssClass = "radio"; // 08/01/2010 Apply ACL Field Security. lstField.Enabled = bIsWriteable; try { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/04/2005 Don't populate list if this is a post back. if ( !Sql.IsEmptyString(sCACHE_NAME) && (!bIsPostBack) ) { // 12/24/2007 Use an array to define the custom caches so that list is in the Cache module. // This should reduce the number of times that we have to edit the SplendidDynamic module. // 02/16/2012 Move custom cache logic to a method. SplendidCache.SetListSource(sCACHE_NAME, lstField); lstField.DataBind(); if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) ) lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT); if ( !bUI_REQUIRED ) { lstField.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), "")); lstField.DataBound += new EventHandler(SplendidDynamic.ListControl_DataBound_AllowNull); } } if ( rdr != null ) { try { string sVALUE = Sql.ToString(rdr[sDATA_FIELD]); if ( sVALUE.StartsWith("<?xml") ) { XmlDocument xml = new XmlDocument(); xml.LoadXml(sVALUE); XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value"); foreach ( XmlNode xValue in nlValues ) { foreach ( ListItem item in lstField.Items ) { if ( item.Value == xValue.InnerText ) item.Selected = true; } } } else { // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, sVALUE); } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } // 08/21/2010 Add support for CheckBoxList. else if ( String.Compare(sFIELD_TYPE, "CheckBoxList", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/02/2007 If format rows > 0 then this is a list box and not a drop down list. ListControl lstField = new CheckBoxList(); tdField.Controls.Add(lstField); lstField.ID = sDATA_FIELD + sIDSuffix; lstField.TabIndex = nFORMAT_TAB_INDEX; lstField.CssClass = "checkbox"; // 08/01/2010 Apply ACL Field Security. lstField.Enabled = bIsWriteable; try { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/04/2005 Don't populate list if this is a post back. if ( !Sql.IsEmptyString(sCACHE_NAME) && (!bIsPostBack) ) { // 12/24/2007 Use an array to define the custom caches so that list is in the Cache module. // This should reduce the number of times that we have to edit the SplendidDynamic module. // 02/16/2012 Move custom cache logic to a method. SplendidCache.SetListSource(sCACHE_NAME, lstField); lstField.DataBind(); if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) ) lstField.Attributes.Add("onchange" , sONCLICK_SCRIPT); } if ( rdr != null ) { try { string sVALUE = Sql.ToString(rdr[sDATA_FIELD]); if ( sVALUE.StartsWith("<?xml") ) { XmlDocument xml = new XmlDocument(); xml.LoadXml(sVALUE); XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value"); foreach ( XmlNode xValue in nlValues ) { foreach ( ListItem item in lstField.Items ) { if ( item.Value == xValue.InnerText ) item.Selected = true; } } } else { // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, sVALUE); } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } else if ( String.Compare(sFIELD_TYPE, "CheckBox", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { CheckBox chkField = new CheckBox(); tdField.Controls.Add(chkField); chkField.ID = sDATA_FIELD + sIDSuffix; chkField.CssClass = "checkbox"; chkField.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. chkField.Enabled = bIsWriteable; try { if ( rdr != null ) chkField.Checked = Sql.ToBoolean(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } // 07/11/2007 A checkbox can have a click event. if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) ) chkField.Attributes.Add("onclick", sONCLICK_SCRIPT); } } else if ( String.Compare(sFIELD_TYPE, "ChangeButton", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { //05/06/2010 Manually generate ClearModuleType so that it will be UpdatePanel safe. DropDownList lstField = null; // 12/04/2005 If the label is PARENT_TYPE, then change the label to a DropDownList. if ( sDATA_LABEL == "PARENT_TYPE" ) { tdLabel.Controls.Clear(); // 04/25/2008 Use KeySortDropDownList instead of ListSearchExtender. lstField = new KeySortDropDownList(); // 07/23/2010 Lets try the latest version of the ListSearchExtender. // 07/28/2010 We are getting an undefined exception on the Accounts List Advanced page. // Lets drop back to using KeySort. //lstField = new DropDownList(); tdLabel.Controls.Add(lstField); lstField.ID = sDATA_LABEL + sIDSuffix; lstField.TabIndex = nFORMAT_TAB_INDEX; // 07/23/2010 Lets try the latest version of the ListSearchExtender. // 07/28/2010 We are getting an undefined exception on the Accounts List Advanced page. /* if ( nFORMAT_ROWS == 0 ) { AjaxControlToolkit.ListSearchExtender extField = new AjaxControlToolkit.ListSearchExtender(); extField.ID = lstField.ID + "_ListSearchExtender"; extField.TargetControlID = lstField.ID; extField.PromptText = L10n.Term(".LBL_TYPE_TO_SEARCH"); extField.PromptCssClass = "ListSearchExtenderPrompt"; tdLabel.Controls.Add(extField); } */ if ( !bIsPostBack ) { // 07/29/2005 SugarCRM 3.0 does not allow the NONE option. lstField.DataValueField = "NAME" ; lstField.DataTextField = "DISPLAY_NAME"; lstField.DataSource = SplendidCache.List("record_type_display"); lstField.DataBind(); if ( rdr != null ) { try { // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, Sql.ToString(rdr[sDATA_LABEL])); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } } TextBox txtNAME = new TextBox(); tdField.Controls.Add(txtNAME); txtNAME.ID = sDISPLAY_FIELD + sIDSuffix; txtNAME.ReadOnly = true; txtNAME.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. txtNAME.Enabled = bIsWriteable; // 11/25/2006 Turn off viewstate so that we can fix the text on postback. txtNAME.EnableViewState = false; try { if ( bIsPostBack ) { // 11/25/2006 In order for this posback fix to work, viewstate must be disabled for this field. if ( tbl.Page.Request[txtNAME.UniqueID] != null ) txtNAME.Text = Sql.ToString(tbl.Page.Request[txtNAME.UniqueID]); } else if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && rdr != null ) txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); txtNAME.Text = ex.Message; } HtmlInputHidden hidID = new HtmlInputHidden(); tdField.Controls.Add(hidID); hidID.ID = sDATA_FIELD + sIDSuffix; try { if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null ) hidID.Value = Sql.ToString(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); txtNAME.Text = ex.Message; } //05/06/2010 Manually generate ClearModuleType so that it will be UpdatePanel safe. // 07/27/2010 Add the ability to submit after clear. if ( sDATA_LABEL == "PARENT_TYPE" && lstField != null ) lstField.Attributes.Add("onChange", "ClearModuleType('', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);"); Literal litNBSP = new Literal(); tdField.Controls.Add(litNBSP); litNBSP.Text = " "; HtmlInputButton btnChange = new HtmlInputButton("button"); tdField.Controls.Add(btnChange); // 05/07/2006 Specify a name for the check button so that it can be referenced by SplendidTest. btnChange.ID = sDATA_FIELD + "_btnChange" + sIDSuffix; btnChange.Attributes.Add("class", "button"); //05/06/2010 Manually generate ParentPopup so that it will be UpdatePanel safe. if ( lstField != null ) btnChange.Attributes.Add("onclick", "return ModulePopup(document.getElementById('" + lstField.ClientID + "').options[document.getElementById('" + lstField.ClientID + "').options.selectedIndex].value, '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', null, false, null);"); else if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) ) btnChange.Attributes.Add("onclick" , sONCLICK_SCRIPT); // 03/31/2007 SugarCRM now uses Select instead of Change. btnChange.Attributes.Add("title" , L10n.Term(".LBL_SELECT_BUTTON_TITLE")); // 07/31/2006 Stop using VisualBasic library to increase compatibility with Mono. // 03/31/2007 Stop using AccessKey for change button. //btnChange.Attributes.Add("accessKey", L10n.Term(".LBL_SELECT_BUTTON_KEY").Substring(0, 1)); btnChange.Value = L10n.Term(".LBL_SELECT_BUTTON_LABEL"); // 08/01/2010 Apply ACL Field Security. btnChange.Disabled = !bIsWriteable; // 12/03/2007 Also create a Clear button. // 05/06/2010 A Parent Type will always have a clear button. if ( sONCLICK_SCRIPT.IndexOf("Popup();") > 0 || sDATA_LABEL == "PARENT_TYPE" ) { litNBSP = new Literal(); tdField.Controls.Add(litNBSP); litNBSP.Text = " "; HtmlInputButton btnClear = new HtmlInputButton("button"); tdField.Controls.Add(btnClear); btnClear.ID = sDATA_FIELD + "_btnClear" + sIDSuffix; btnClear.Attributes.Add("class", "button"); //05/06/2010 Manually generate ClearModuleType so that it will be UpdatePanel safe. // 07/27/2010 Add the ability to submit after clear. btnClear.Attributes.Add("onclick" , "return ClearModuleType('', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);"); btnClear.Attributes.Add("title" , L10n.Term(".LBL_CLEAR_BUTTON_TITLE")); btnClear.Value = L10n.Term(".LBL_CLEAR_BUTTON_LABEL"); // 08/01/2010 Apply ACL Field Security. btnClear.Disabled = !bIsWriteable; } if ( bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) ) { RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs(); reqID.ID = sDATA_FIELD + "_REQUIRED" + sIDSuffix; reqID.ControlToValidate = hidID.ID; reqID.ErrorMessage = L10n.Term(".ERR_REQUIRED_FIELD"); reqID.CssClass = "required"; reqID.EnableViewState = false; // 01/16/2006 We don't enable required fields until we attempt to save. // This is to allow unrelated form actions; the Cancel button is a good example. reqID.EnableClientScript = false; reqID.Enabled = false; // 02/21/2008 Add a little padding. reqID.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqID); } } } // 09/01/2009 Add support for ModulePopups. // 08/01/2010 Lets do the same for ModuleAutoComplete. else if ( String.Compare(sFIELD_TYPE, "ModulePopup", true) == 0 || String.Compare(sFIELD_TYPE, "ModuleAutoComplete", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { TextBox txtNAME = new TextBox(); tdField.Controls.Add(txtNAME); // 10/05/2010 A custom field will not have a display field, but we still want to be able to access by name. txtNAME.ID = (Sql.IsEmptyString(sDISPLAY_FIELD) ? sDATA_FIELD + "_NAME" : sDISPLAY_FIELD) + sIDSuffix; txtNAME.ReadOnly = true; txtNAME.TabIndex = nFORMAT_TAB_INDEX; // 11/25/2006 Turn off viewstate so that we can fix the text on postback. txtNAME.EnableViewState = false; // 08/01/2010 Apply ACL Field Security. txtNAME.Enabled = bIsWriteable; try { if ( bIsPostBack ) { // 11/25/2006 In order for this posback fix to work, viewstate must be disabled for this field. if ( tbl.Page.Request[txtNAME.UniqueID] != null ) txtNAME.Text = Sql.ToString(tbl.Page.Request[txtNAME.UniqueID]); } else if ( !Sql.IsEmptyString(sDISPLAY_FIELD) && rdr != null ) txtNAME.Text = Sql.ToString(rdr[sDISPLAY_FIELD]); else if ( rdr != null ) txtNAME.Text = Crm.Modules.ItemName(Application, sMODULE_TYPE, rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); txtNAME.Text = ex.Message; } HtmlInputHidden hidID = new HtmlInputHidden(); tdField.Controls.Add(hidID); hidID.ID = sDATA_FIELD + sIDSuffix; try { if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null ) hidID.Value = Sql.ToString(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); txtNAME.Text = ex.Message; } Literal litNBSP = new Literal(); tdField.Controls.Add(litNBSP); litNBSP.Text = " "; HtmlInputButton btnChange = new HtmlInputButton("button"); tdField.Controls.Add(btnChange); // 05/07/2006 Specify a name for the check button so that it can be referenced by SplendidTest. btnChange.ID = sDATA_FIELD + "_btnChange" + sIDSuffix; btnChange.Attributes.Add("class", "button"); if ( !Sql.IsEmptyString(sONCLICK_SCRIPT) ) btnChange.Attributes.Add("onclick" , sONCLICK_SCRIPT); else btnChange.Attributes.Add("onclick" , "return ModulePopup('" + sMODULE_TYPE + "', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', null, false, null);"); // 03/31/2007 SugarCRM now uses Select instead of Change. btnChange.Attributes.Add("title" , L10n.Term(".LBL_SELECT_BUTTON_TITLE")); // 07/31/2006 Stop using VisualBasic library to increase compatibility with Mono. // 03/31/2007 Stop using AccessKey for change button. //btnChange.Attributes.Add("accessKey", L10n.Term(".LBL_SELECT_BUTTON_KEY").Substring(0, 1)); btnChange.Value = L10n.Term(".LBL_SELECT_BUTTON_LABEL"); // 08/01/2010 Apply ACL Field Security. btnChange.Disabled = !bIsWriteable; litNBSP = new Literal(); tdField.Controls.Add(litNBSP); litNBSP.Text = " "; HtmlInputButton btnClear = new HtmlInputButton("button"); tdField.Controls.Add(btnClear); btnClear.ID = sDATA_FIELD + "_btnClear" + sIDSuffix; btnClear.Attributes.Add("class", "button"); // 07/27/2010 Add the ability to submit after clear. btnClear.Attributes.Add("onclick" , "return ClearModuleType('" + sMODULE_TYPE + "', '" + hidID.ClientID + "', '" + txtNAME.ClientID + "', false);"); btnClear.Attributes.Add("title" , L10n.Term(".LBL_CLEAR_BUTTON_TITLE")); btnClear.Value = L10n.Term(".LBL_CLEAR_BUTTON_LABEL"); // 08/01/2010 Apply ACL Field Security. btnClear.Disabled = !bIsWriteable; if ( bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) ) { RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs(); reqID.ID = sDATA_FIELD + "_REQUIRED" + sIDSuffix; reqID.ControlToValidate = hidID.ID; reqID.ErrorMessage = L10n.Term(".ERR_REQUIRED_FIELD"); reqID.CssClass = "required"; reqID.EnableViewState = false; // 01/16/2006 We don't enable required fields until we attempt to save. // This is to allow unrelated form actions; the Cancel button is a good example. reqID.EnableClientScript = false; reqID.Enabled = false; // 02/21/2008 Add a little padding. reqID.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqID); } } } else if ( String.Compare(sFIELD_TYPE, "TextBox", true) == 0 || String.Compare(sFIELD_TYPE, "Password", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { TextBox txtField = new TextBox(); tdField.Controls.Add(txtField); txtField.ID = sDATA_FIELD + sIDSuffix; txtField.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. txtField.Enabled = bIsWriteable; try { if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 ) { txtField.Rows = nFORMAT_ROWS ; txtField.Columns = nFORMAT_COLUMNS; txtField.TextMode = TextBoxMode.MultiLine; } else { txtField.MaxLength = nFORMAT_MAX_LENGTH ; txtField.Attributes.Add("size", nFORMAT_SIZE.ToString()); txtField.TextMode = TextBoxMode.SingleLine; } if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null ) { if ( rdr[sDATA_FIELD].GetType() == typeof(System.Decimal) ) txtField.Text = Sql.ToDecimal(rdr[sDATA_FIELD]).ToString("#,##0.00"); else txtField.Text = Sql.ToString(rdr[sDATA_FIELD]); } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); txtField.Text = ex.Message; } if ( String.Compare(sFIELD_TYPE, "Password", true) == 0 ) txtField.TextMode = TextBoxMode.Password; if ( bUI_REQUIRED && !Sql.IsEmptyString(sDATA_FIELD) ) { RequiredFieldValidator reqNAME = new RequiredFieldValidator(); reqNAME.ID = sDATA_FIELD + "_REQUIRED" + sIDSuffix; reqNAME.ControlToValidate = txtField.ID; reqNAME.ErrorMessage = L10n.Term(".ERR_REQUIRED_FIELD"); reqNAME.CssClass = "required"; reqNAME.EnableViewState = false; // 01/16/2006 We don't enable required fields until we attempt to save. // This is to allow unrelated form actions; the Cancel button is a good example. reqNAME.EnableClientScript = false; reqNAME.Enabled = false; reqNAME.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqNAME); } if ( !Sql.IsEmptyString(sDATA_FIELD) ) { if ( sVALIDATION_TYPE == "RegularExpressionValidator" && !Sql.IsEmptyString(sREGULAR_EXPRESSION) && !Sql.IsEmptyString(sFIELD_VALIDATOR_MESSAGE) && bIsWriteable ) { RegularExpressionValidator reqVALIDATOR = new RegularExpressionValidator(); reqVALIDATOR.ID = sDATA_FIELD + "_VALIDATOR" + sIDSuffix; reqVALIDATOR.ControlToValidate = txtField.ID; reqVALIDATOR.ErrorMessage = L10n.Term(sFIELD_VALIDATOR_MESSAGE); reqVALIDATOR.ValidationExpression = sREGULAR_EXPRESSION; reqVALIDATOR.CssClass = "required"; reqVALIDATOR.EnableViewState = false; // 04/02/2008 We don't enable required fields until we attempt to save. // This is to allow unrelated form actions; the Cancel button is a good example. reqVALIDATOR.EnableClientScript = false; reqVALIDATOR.Enabled = false; reqVALIDATOR.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqVALIDATOR); } } } } // 04/04/2011 Add support for HtmlEditor. else if ( String.Compare(sFIELD_TYPE, "HtmlEditor", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 09/18/2011 Upgrade to CKEditor 3.6.2. CKEditorControl txtField = new CKEditorControl(); tdField.Controls.Add(txtField); txtField.ID = sDATA_FIELD; txtField.Toolbar = "Taoqi"; // 09/18/2011 Set the language for CKEditor. txtField.Language = L10n.NAME; txtField.BasePath = "~/ckeditor/"; // 04/26/2012 Add file uploader. txtField.FilebrowserUploadUrl = txtField.ResolveUrl("~/ckeditor/upload.aspx"); txtField.FilebrowserBrowseUrl = txtField.ResolveUrl("~/Images/Popup.aspx"); //txtField.FilebrowserWindowWidth = "640"; //txtField.FilebrowserWindowHeight = "480"; txtField.Visible = bIsWriteable; try { if ( nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0 ) { txtField.Height = nFORMAT_ROWS ; // 04/04/2011 Reduce the width to make it easier to edit. txtField.Width = nFORMAT_COLUMNS / 2; } if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null ) { txtField.Text = Sql.ToString(rdr[sDATA_FIELD]); // 01/18/2010 FCKEditor does not have an Enable field, so just hide and replace with a Literal control. if ( !bIsWriteable ) { txtField.Visible = false; Literal litField = new Literal(); litField.ID = sDATA_FIELD + "_ReadOnly"; tdField.Controls.Add(litField); litField.Text = Sql.ToString(rdr[sDATA_FIELD]); } } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); txtField.Text = ex.Message; } } } else if ( String.Compare(sFIELD_TYPE, "DatePicker", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/03/2005 UserControls must be loaded. DatePicker ctlDate = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker; tdField.Controls.Add(ctlDate); ctlDate.ID = sDATA_FIELD + sIDSuffix; // 05/10/2006 Set the tab index. ctlDate.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. ctlDate.Enabled = bIsWriteable; try { if ( rdr != null ) ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } else if ( String.Compare(sFIELD_TYPE, "DateRange", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/17/2007 Use table to align before and after labels. Table tblDateRange = new Table(); tdField.Controls.Add(tblDateRange); TableRow trAfter = new TableRow(); TableRow trBefore = new TableRow(); tblDateRange.Rows.Add(trAfter); tblDateRange.Rows.Add(trBefore); TableCell tdAfterLabel = new TableCell(); TableCell tdAfterData = new TableCell(); TableCell tdBeforeLabel = new TableCell(); TableCell tdBeforeData = new TableCell(); trAfter .Cells.Add(tdAfterLabel ); trAfter .Cells.Add(tdAfterData ); trBefore.Cells.Add(tdBeforeLabel); trBefore.Cells.Add(tdBeforeData ); // 12/03/2005 UserControls must be loaded. DatePicker ctlDateStart = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker; DatePicker ctlDateEnd = tbl.Page.LoadControl("~/_controls/DatePicker.ascx") as DatePicker; Literal litAfterLabel = new Literal(); Literal litBeforeLabel = new Literal(); litAfterLabel .Text = L10n.Term("SavedSearch.LBL_SEARCH_AFTER" ); litBeforeLabel.Text = L10n.Term("SavedSearch.LBL_SEARCH_BEFORE"); //tdField.Controls.Add(litAfterLabel ); //tdField.Controls.Add(ctlDateStart ); //tdField.Controls.Add(litBeforeLabel); //tdField.Controls.Add(ctlDateEnd ); tdAfterLabel .Controls.Add(litAfterLabel ); tdAfterData .Controls.Add(ctlDateStart ); tdBeforeLabel.Controls.Add(litBeforeLabel); tdBeforeData .Controls.Add(ctlDateEnd ); ctlDateStart.ID = sDATA_FIELD + "_AFTER" + sIDSuffix; ctlDateEnd .ID = sDATA_FIELD + "_BEFORE" + sIDSuffix; // 05/10/2006 Set the tab index. ctlDateStart.TabIndex = nFORMAT_TAB_INDEX; ctlDateEnd .TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. ctlDateStart.Enabled = bIsWriteable; ctlDateEnd .Enabled = bIsWriteable; try { if ( rdr != null ) { ctlDateStart.Value = T10n.FromServerTime(rdr[sDATA_FIELD]); ctlDateEnd .Value = T10n.FromServerTime(rdr[sDATA_FIELD]); } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } else if ( String.Compare(sFIELD_TYPE, "DateTimePicker", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/03/2005 UserControls must be loaded. DateTimePicker ctlDate = tbl.Page.LoadControl("~/_controls/DateTimePicker.ascx") as DateTimePicker; tdField.Controls.Add(ctlDate); ctlDate.ID = sDATA_FIELD + sIDSuffix; // 05/10/2006 Set the tab index. ctlDate.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. ctlDate.Enabled = bIsWriteable; try { if ( rdr != null ) ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } else if ( String.Compare(sFIELD_TYPE, "DateTimeEdit", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { // 12/03/2005 UserControls must be loaded. DateTimeEdit ctlDate = tbl.Page.LoadControl("~/_controls/DateTimeEdit.ascx") as DateTimeEdit; tdField.Controls.Add(ctlDate); ctlDate.ID = sDATA_FIELD + sIDSuffix; // 05/10/2006 Set the tab index. ctlDate.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. ctlDate.Enabled = bIsWriteable; try { if ( rdr != null ) ctlDate.Value = T10n.FromServerTime(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } if ( bUI_REQUIRED ) { ctlDate.EnableNone = false; } } } else if ( String.Compare(sFIELD_TYPE, "File", true) == 0 ) { // 11/23/2010 File should act just like an image. if ( !Sql.IsEmptyString(sDATA_FIELD) ) { HtmlInputHidden ctlHidden = null; HtmlInputFile ctlField = new HtmlInputFile(); tdField.Controls.Add(ctlField); // 04/17/2006 The image needs to reference the file control. // 11/25/2010 Appending _File breaks the previous behavior of Notes, Bugs and Documents. // 11/25/2010 The file field is special in that it may not exist as a table column. ctlField.ID = sDATA_FIELD + sIDSuffix; if ( rdr != null ) { if ( vwSchema.Contains(sDATA_FIELD) ) { ctlField.ID = sDATA_FIELD + "_File" + sIDSuffix; ctlHidden = new HtmlInputHidden(); tdField.Controls.Add(ctlHidden); ctlHidden.ID = sDATA_FIELD + sIDSuffix; } } ctlField.MaxLength = nFORMAT_MAX_LENGTH; ctlField.Size = nFORMAT_SIZE; ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString()); // 08/01/2010 Apply ACL Field Security. ctlField.Disabled = !bIsWriteable; if ( bUI_REQUIRED ) { RequiredFieldValidator reqNAME = new RequiredFieldValidator(); reqNAME.ID = sDATA_FIELD + "_REQUIRED" + sIDSuffix; reqNAME.ControlToValidate = ctlField.ID; reqNAME.ErrorMessage = L10n.Term(".ERR_REQUIRED_FIELD"); reqNAME.CssClass = "required"; reqNAME.EnableViewState = false; // 01/16/2006 We don't enable required fields until we attempt to save. // This is to allow unrelated form actions; the Cancel button is a good example. reqNAME.EnableClientScript = false; reqNAME.Enabled = false; reqNAME.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqNAME); } Literal litBR = new Literal(); litBR.Text = "<br />"; tdField.Controls.Add(litBR); HyperLink lnkField = new HyperLink(); // 04/13/2006 Give the image a name so that it can be validated with SplendidTest. lnkField.ID = "lnk" + sDATA_FIELD + sIDSuffix; try { if ( rdr != null ) { // 11/25/2010 The file field is special in that it may not exist as a table column. if ( ctlHidden != null && !Sql.IsEmptyString(rdr[sDATA_FIELD]) ) { ctlHidden.Value = Sql.ToString(rdr[sDATA_FIELD]); lnkField.NavigateUrl = "~/Images/Image.aspx?ID=" + ctlHidden.Value; lnkField.Text = Crm.Modules.ItemName(Application, "Images", ctlHidden.Value); // 04/13/2006 Only add the image if it exists. tdField.Controls.Add(lnkField); // 04/17/2006 Provide a clear button. Literal litClear = new Literal(); litClear.Text = " <input type=\"button\" class=\"button\" onclick=\"document.getElementById('" + ctlHidden.ClientID + "').value='';document.getElementById('" + lnkField.ClientID + "').innerHTML='';" + "\" value='" + " " + L10n.Term(".LBL_CLEAR_BUTTON_LABEL" ) + " " + "' title='" + L10n.Term(".LBL_CLEAR_BUTTON_TITLE" ) + "' />"; tdField.Controls.Add(litClear); } } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); Literal litField = new Literal(); litField.Text = ex.Message; tdField.Controls.Add(litField); } } } else if ( String.Compare(sFIELD_TYPE, "Image", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { HtmlInputHidden ctlHidden = new HtmlInputHidden(); tdField.Controls.Add(ctlHidden); ctlHidden.ID = sDATA_FIELD + sIDSuffix; HtmlInputFile ctlField = new HtmlInputFile(); tdField.Controls.Add(ctlField); // 04/17/2006 The image needs to reference the file control. ctlField.ID = sDATA_FIELD + "_File" + sIDSuffix; ctlField.MaxLength = nFORMAT_MAX_LENGTH; ctlField.Size = nFORMAT_SIZE; ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString()); // 08/01/2010 Apply ACL Field Security. ctlField.Disabled = !bIsWriteable; if ( bUI_REQUIRED ) { RequiredFieldValidator reqNAME = new RequiredFieldValidator(); reqNAME.ID = sDATA_FIELD + "_REQUIRED" + sIDSuffix; reqNAME.ControlToValidate = ctlField.ID; reqNAME.ErrorMessage = L10n.Term(".ERR_REQUIRED_FIELD"); reqNAME.CssClass = "required"; reqNAME.EnableViewState = false; // 01/16/2006 We don't enable required fields until we attempt to save. // This is to allow unrelated form actions; the Cancel button is a good example. reqNAME.EnableClientScript = false; reqNAME.Enabled = false; reqNAME.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqNAME); } Literal litBR = new Literal(); litBR.Text = "<br />"; tdField.Controls.Add(litBR); Image imgField = new Image(); // 04/13/2006 Give the image a name so that it can be validated with SplendidTest. imgField.ID = "img" + sDATA_FIELD + sIDSuffix; try { if ( rdr != null ) { if ( !Sql.IsEmptyString(rdr[sDATA_FIELD]) ) { ctlHidden.Value = Sql.ToString(rdr[sDATA_FIELD]); imgField.ImageUrl = "~/Images/Image.aspx?ID=" + ctlHidden.Value; // 04/13/2006 Only add the image if it exists. tdField.Controls.Add(imgField); // 04/17/2006 Provide a clear button. Literal litClear = new Literal(); litClear.Text = " <input type=\"button\" class=\"button\" onclick=\"document.getElementById('" + ctlHidden.ClientID + "').value='';document.getElementById('" + imgField.ClientID + "').src='';" + "\" value='" + " " + L10n.Term(".LBL_CLEAR_BUTTON_LABEL" ) + " " + "' title='" + L10n.Term(".LBL_CLEAR_BUTTON_TITLE" ) + "' />"; tdField.Controls.Add(litClear); } } } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); Literal litField = new Literal(); litField.Text = ex.Message; tdField.Controls.Add(litField); } } } // 04/04/2011 Add support for hidden field. else if ( String.Compare(sFIELD_TYPE, "Hidden", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { HtmlInputHidden hidID = new HtmlInputHidden(); tdField.Controls.Add(hidID); hidID.ID = sDATA_FIELD + sIDSuffix; try { if ( !Sql.IsEmptyString(sDATA_FIELD) && rdr != null ) hidID.Value = Sql.ToString(rdr[sDATA_FIELD]); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } // 08/01/2010 Add support for dynamic teams. else if ( String.Compare(sFIELD_TYPE, "TeamSelect", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { TeamSelect ctlTeamSelect = tbl.Page.LoadControl("~/_controls/TeamSelect.ascx") as TeamSelect; tdField.Controls.Add(ctlTeamSelect); ctlTeamSelect.ID = sDATA_FIELD; // 05/06/2010 Use a special Page flag to override the default IsPostBack behavior. ctlTeamSelect.NotPostBack = !bIsPostBack; //ctlTeamSelect.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. ctlTeamSelect.Enabled = bIsWriteable; try { Guid gTEAM_SET_ID = Guid.Empty; if ( rdr != null ) { if ( vwSchema.Contains("TEAM_SET_ID") ) { gTEAM_SET_ID = Sql.ToGuid(rdr["TEAM_SET_ID"]); } } // 08/31/2009 Don't provide defaults in a Search view or a Popup view. bool bAllowDefaults = sEDIT_NAME.IndexOf(".Search") < 0 && sEDIT_NAME.IndexOf(".Popup") < 0; ctlTeamSelect.LoadLineItems(gTEAM_SET_ID, bAllowDefaults); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } // 04/04/2011 Add support for dynamic teams. else if ( String.Compare(sFIELD_TYPE, "KBTagSelect", true) == 0 ) { if ( !Sql.IsEmptyString(sDATA_FIELD) ) { KBTagSelect ctlKBTagSelect = tbl.Page.LoadControl("~/_controls/KBTagSelect.ascx") as KBTagSelect; tdField.Controls.Add(ctlKBTagSelect); ctlKBTagSelect.ID = sDATA_FIELD; // 05/06/2010 Use a special Page flag to override the default IsPostBack behavior. ctlKBTagSelect.NotPostBack = !bIsPostBack; //ctlTeamSelect.TabIndex = nFORMAT_TAB_INDEX; // 08/01/2010 Apply ACL Field Security. ctlKBTagSelect.Enabled = bIsWriteable; try { Guid gID = Guid.Empty; if ( rdr != null ) { gID = Sql.ToGuid(rdr["ID"]); } ctlKBTagSelect.LoadLineItems(gID); } catch(Exception ex) { SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex); } } } else { Literal litField = new Literal(); tdField.Controls.Add(litField); litField.Text = "Unknown field type " + sFIELD_TYPE; SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Unknown field type " + sFIELD_TYPE); } nColIndex = 0; } }
protected void UpdateImportMappings(XmlDocument xml, bool bInitialize, bool bUpdateMappings) { Hashtable hashFieldMappings = new Hashtable(); tblImportMappings.Rows.Clear(); HtmlTableRow rowHeader = new HtmlTableRow(); tblImportMappings.Rows.Add(rowHeader); HtmlTableCell cellField = new HtmlTableCell(); HtmlTableCell cellRowHdr = new HtmlTableCell(); HtmlTableCell cellRow1 = new HtmlTableCell(); HtmlTableCell cellRow2 = new HtmlTableCell(); rowHeader.Cells.Add(cellField ); if ( chkHasHeader.Checked || radXML.Checked ) rowHeader.Cells.Add(cellRowHdr); rowHeader.Cells.Add(cellRow1 ); rowHeader.Cells.Add(cellRow2 ); cellField .Attributes.Add("class", "tabDetailViewDL"); cellRowHdr.Attributes.Add("class", "tabDetailViewDL"); cellRow1 .Attributes.Add("class", "tabDetailViewDL"); cellRow2 .Attributes.Add("class", "tabDetailViewDL"); cellField .Attributes.Add("style", "TEXT-ALIGN: left"); cellRowHdr.Attributes.Add("style", "TEXT-ALIGN: left"); cellRow1 .Attributes.Add("style", "TEXT-ALIGN: left"); cellRow2 .Attributes.Add("style", "TEXT-ALIGN: left"); Label lblField = new Label(); Label lblRowHdr = new Label(); Label lblRow1 = new Label(); Label lblRow2 = new Label(); cellField .Controls.Add(lblField ); cellRowHdr.Controls.Add(lblRowHdr); cellRow1 .Controls.Add(lblRow1 ); cellRow2 .Controls.Add(lblRow2 ); lblField .Font.Bold = true; lblRowHdr.Font.Bold = true; lblRow1 .Font.Bold = true; lblRow2 .Font.Bold = true; lblField .Text = L10n.Term("Import.LBL_DATABASE_FIELD"); lblRowHdr.Text = L10n.Term("Import.LBL_HEADER_ROW" ); lblRow1 .Text = L10n.Term("Import.LBL_ROW" ) + " 1"; lblRow2 .Text = L10n.Term("Import.LBL_ROW" ) + " 2"; if ( xml.DocumentElement != null ) { XmlNodeList nl = xml.DocumentElement.SelectNodes(sImportModule.ToLower()); if ( nl.Count > 0 ) { vwColumns.Sort = "DISPLAY_NAME"; XmlNode nodeH = nl[0]; XmlNode node1 = nl[0]; XmlNode node2 = null; // 08/22/2006 An XML Spreadsheet will have a header record, // so don't assume that an XML file will use the tag names as the header. if ( chkHasHeader.Checked ) { if ( nl.Count > 1 ) node1 = nl[1]; if ( nl.Count > 2 ) node2 = nl[2]; } else { if ( nl.Count > 1 ) node2 = nl[1]; } bDuplicateFields = false; Hashtable hashSelectedFields = new Hashtable(); for ( int i = 0 ; i < nodeH.ChildNodes.Count ; i++ ) { rowHeader = new HtmlTableRow(); tblImportMappings.Rows.Add(rowHeader); cellField = new HtmlTableCell(); cellRowHdr = new HtmlTableCell(); cellRow1 = new HtmlTableCell(); cellRow2 = new HtmlTableCell(); rowHeader.Cells.Add(cellField ); if ( chkHasHeader.Checked || radXML.Checked ) rowHeader.Cells.Add(cellRowHdr); rowHeader.Cells.Add(cellRow1 ); if ( node2 != null && i < node2.ChildNodes.Count ) rowHeader.Cells.Add(cellRow2); cellField .Attributes.Add("class", "tabDetailViewDF"); cellRowHdr.Attributes.Add("class", "tabDetailViewDF"); cellRow1 .Attributes.Add("class", "tabDetailViewDF"); cellRow2 .Attributes.Add("class", "tabDetailViewDF"); // 04/25/2008 Use KeySortDropDownList instead of ListSearchExtender. DropDownList lstField = new KeySortDropDownList(); // 07/23/2010 Lets try the latest version of the ListSearchExtender. // 07/28/2010 We are getting an undefined exception on the Accounts List Advanced page. // Lets drop back to using KeySort. //DropDownList lstField = new DropDownList(); lblRowHdr = new Label(); lblRow1 = new Label(); lblRow2 = new Label(); cellField .Controls.Add(lstField ); cellRowHdr.Controls.Add(lblRowHdr); cellRow1 .Controls.Add(lblRow1 ); cellRow2 .Controls.Add(lblRow2 ); // 08/20/2006 Clear any previous filters. vwColumns.RowFilter = null; // 08/20/2006 Don't use real column names as they may collide. lstField.ID = "ImportField" + i.ToString("000"); lstField.DataValueField = "NAME"; lstField.DataTextField = "DISPLAY_NAME"; lstField.DataSource = vwColumns; lstField.DataBind(); // 04/25/2008 Add AJAX searching. // 04/25/2008 ListSearchExtender needs work. I don't like the delay when a list is selected // and there are problems when the browser window is scrolled. KeySortDropDownList is a better solution. // 07/23/2010 Lets try the latest version of the ListSearchExtender. // 07/28/2010 We are getting an undefined exception on the Accounts List Advanced page. /* AjaxControlToolkit.ListSearchExtender extField = new AjaxControlToolkit.ListSearchExtender(); extField.ID = lstField.ID + "_ListSearchExtender"; extField.TargetControlID = lstField.ID; extField.PromptText = L10n.Term(".LBL_TYPE_TO_SEARCH"); extField.PromptCssClass = "ListSearchExtenderPrompt"; cellField .Controls.Add(extField ); */ lstField.Items.Insert(0, new ListItem(L10n.Term("Import.LBL_DONT_MAP"), String.Empty)); try { if ( bInitialize ) { if ( chkHasHeader.Checked ) { // 08/22/2006 If Has Header is checked, then always expect the body to contain the header names. string sFieldName = nodeH.ChildNodes[i].InnerText.Trim(); // 08/20/2006 Use the DataView to locate matching fields so that we don't have to worry about case significance. // 05/09/2010 Also match against a custom field name. // 04/22/2012 Calculate a display name without spaces to get better hits with Salesforce field names. sFieldName = Sql.EscapeSQL(sFieldName); vwColumns.RowFilter = "NAME = '" + sFieldName + "' or NAME_NOUNDERSCORE = '" + sFieldName + "' or DISPLAY_NAME = '" + sFieldName + "' or DISPLAY_NAME_NOSPACE = '" + sFieldName + "' or NAME = '" + sFieldName.Replace(" ", "_") + "_C" + "'"; if ( vwColumns.Count > 0 ) { hashFieldMappings.Add(i, Sql.ToString(vwColumns[0]["NAME"])); // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, Sql.ToString(vwColumns[0]["NAME"])); } } else if ( radXML.Checked ) { // 08/22/2006 If Has Header is not checked for XML, then use the tag ame as the field name. string sFieldName = nodeH.ChildNodes[i].Name; // 08/20/2006 Use the DataView to locate matching fields so that we don't have to worry about case significance. // 05/09/2010 Also match against a custom field name. // 04/22/2012 Calculate a display name without spaces to get better hits with Salesforce field names. sFieldName = Sql.EscapeSQL(sFieldName); vwColumns.RowFilter = "NAME = '" + sFieldName + "' or NAME_NOUNDERSCORE = '" + sFieldName + "' or DISPLAY_NAME = '" + sFieldName + "' or DISPLAY_NAME_NOSPACE = '" + sFieldName + "' or NAME = '" + sFieldName.Replace(" ", "_") + "_C" + "'"; if ( vwColumns.Count > 0 ) { hashFieldMappings.Add(i, Sql.ToString(vwColumns[0]["NAME"])); // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, Sql.ToString(vwColumns[0]["NAME"])); } } else hashFieldMappings.Add(i, "ImportField" + i.ToString("000")); } else { // 08/20/2006 Manually set the last value. hashFieldMappings.Add(i, Sql.ToString(Request[lstField.UniqueID])); // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, Sql.ToString(Request[lstField.UniqueID])); if ( lstField.SelectedValue.Length > 0 ) { if ( hashSelectedFields.ContainsKey(lstField.SelectedValue) ) { bDuplicateFields = true; } else { hashSelectedFields.Add(lstField.SelectedValue, null); } } } } catch //(Exception ex) { } // XML data will use the node-name as the header. if ( chkHasHeader.Checked ) { // 08/22/2006 If Has Header is checked, then always expect the body to contain the header names. lblRowHdr.Text = nodeH.ChildNodes[i].InnerText; } else if ( radXML.Checked ) { // 08/22/2006 If Has Header is not checked for XML, then use the tag name as the field name. lblRowHdr.Text = nodeH.ChildNodes[i].Name; } if ( node1 != null && i < node1.ChildNodes.Count ) lblRow1.Text = node1.ChildNodes[i].InnerText; if ( node2 != null && i < node2.ChildNodes.Count ) lblRow2.Text = node2.ChildNodes[i].InnerText; } if ( bDuplicateFields ) { throw(new Exception(L10n.Term("Import.ERR_MULTIPLE"))); } if ( bUpdateMappings ) { DuplicateFilterUpdate(); XmlNodeList nlFields = xmlMapping.DocumentElement.SelectNodes("Fields/Field"); foreach ( XmlNode xField in nlFields ) { XmlUtil.SetSingleNode(xmlMapping, xField, "Mapping", String.Empty); } // 08/22/2006 We should always use the header mappings instead of an index as nodes may move around. XmlNode node = nl[0]; for ( int j = 0; j < node.ChildNodes.Count; j++ ) { XmlNode xField = xmlMapping.DocumentElement.SelectSingleNode("Fields/Field[@Name='" + hashFieldMappings[j] + "']"); if ( xField != null ) { XmlUtil.SetSingleNode(xmlMapping, xField, "Mapping", node.ChildNodes[j].Name); } } } else { // 12/17/2008 Apply current filter fields. ctlDuplicateFilterChooser_Bind(); // 10/12/2006 If we are not updating the mappings, then we are setting the mappings. XmlNodeList nlFields = xmlMapping.DocumentElement.SelectNodes("Fields/Field"); foreach ( XmlNode xField in nlFields ) { string sName = xField.Attributes.GetNamedItem("Name").Value; string sMapping = XmlUtil.SelectSingleNode(xField, "Mapping"); if ( !Sql.IsEmptyString(sMapping) ) { DropDownList lstField = tblImportMappings.FindControl(sMapping) as DropDownList; if ( lstField != null ) { try { // 08/19/2010 Check the list before assigning the value. Utils.SetSelectedValue(lstField, sName); } catch { } } } } } } } }
public static void AppendEditViewFields(DataView dvFields, HtmlTable tbl, System.Data.SqlClient.SqlDataReader rdr, CommandEventHandler Page_Command, bool bLayoutMode, string sEDIT_NAME) { bool bIsMobile = false; CRMPage Page = tbl.Page as CRMPage; if (Page != null) bIsMobile = Page.IsMobile; HtmlTableRow tr = null; int nRowIndex = tbl.Rows.Count - 1; int nColIndex = 0; HtmlTableCell tdLabel = null; HtmlTableCell tdField = null; if (bLayoutMode) tbl.Border = 1; if (dvFields.Count == 0 && tbl.Rows.Count <= 1) tbl.Visible = false; DataView vwSchema = null; if (rdr != null) vwSchema = new DataView(rdr.GetSchemaTable()); bool bEnableTeamManagement = Common.Config.enable_team_management(); bool bRequireTeamManagement = Common.Config.require_team_management(); bool bRequireUserAssignment = Common.Config.require_user_assignment(); HttpSessionState Session = HttpContext.Current.Session; foreach (DataRowView row in dvFields) { int gID = TypeConvert.ToInteger(row["ID"]); int nFIELD_INDEX = TypeConvert.ToInteger(row["FIELD_INDEX"]); string sFIELD_TYPE = TypeConvert.ToString(row["FIELD_TYPE"]); string sDATA_LABEL = TypeConvert.ToString(row["DATA_LABEL"]); string sDATA_FIELD = TypeConvert.ToString(row["DATA_FIELD"]); string sDISPLAY_FIELD = TypeConvert.ToString(row["DISPLAY_FIELD"]); string sCACHE_NAME = TypeConvert.ToString(row["CACHE_NAME"]); bool bDATA_REQUIRED = TypeConvert.ToBoolean(row["DATA_REQUIRED"]); bool bUI_REQUIRED = TypeConvert.ToBoolean(row["UI_REQUIRED"]); string sONCLICK_SCRIPT = TypeConvert.ToString(row["ONCLICK_SCRIPT"]); string sFORMAT_SCRIPT = TypeConvert.ToString(row["FORMAT_SCRIPT"]); short nFORMAT_TAB_INDEX = TypeConvert.ToShort(row["FORMAT_TAB_INDEX"]); int nFORMAT_MAX_LENGTH = TypeConvert.ToInteger(row["FORMAT_MAX_LENGTH"]); int nFORMAT_SIZE = TypeConvert.ToInteger(row["FORMAT_SIZE"]); int nFORMAT_ROWS = TypeConvert.ToInteger(row["FORMAT_ROWS"]); int nFORMAT_COLUMNS = TypeConvert.ToInteger(row["FORMAT_COLUMNS"]); int nCOLSPAN = TypeConvert.ToInteger(row["COLSPAN"]); int nROWSPAN = TypeConvert.ToInteger(row["ROWSPAN"]); string sLABEL_WIDTH = TypeConvert.ToString(row["LABEL_WIDTH"]); string sFIELD_WIDTH = TypeConvert.ToString(row["FIELD_WIDTH"]); int nDATA_COLUMNS = TypeConvert.ToInteger(row["DATA_COLUMNS"]); string sFIELD_VALIDATOR_MESSAGE = TypeConvert.ToString(row["FIELD_VALIDATOR_MESSAGE"]); string sVALIDATION_TYPE = TypeConvert.ToString(row["VALIDATION_TYPE"]); string sREGULAR_EXPRESSION = TypeConvert.ToString(row["REGULAR_EXPRESSION"]); string sDATA_TYPE = TypeConvert.ToString(row["DATA_TYPE"]); string sMININUM_VALUE = TypeConvert.ToString(row["MININUM_VALUE"]); string sMAXIMUM_VALUE = TypeConvert.ToString(row["MAXIMUM_VALUE"]); string sCOMPARE_OPERATOR = TypeConvert.ToString(row["COMPARE_OPERATOR"]); if (nDATA_COLUMNS == 0) nDATA_COLUMNS = 2; if (!bLayoutMode && sDATA_FIELD == "TEAM_ID") { if (!bEnableTeamManagement) { sFIELD_TYPE = "Blank"; bUI_REQUIRED = false; } else { if (bRequireTeamManagement) bUI_REQUIRED = true; } } if (!bLayoutMode && sDATA_FIELD == "ASSIGNED_USER_ID") { if (bRequireUserAssignment) bUI_REQUIRED = true; } if (bIsMobile && String.Compare(sFIELD_TYPE, "AddressButtons", true) == 0) { continue; } if ((nCOLSPAN >= 0 && nColIndex == 0) || tr == null || bIsMobile) { nRowIndex++; tr = new HtmlTableRow(); tbl.Rows.Insert(nRowIndex, tr); } if (bLayoutMode) { HtmlTableCell tdAction = new HtmlTableCell(); tr.Cells.Add(tdAction); tdAction.Attributes.Add("class", "tabDetailViewDL"); tdAction.NoWrap = true; Literal litIndex = new Literal(); tdAction.Controls.Add(litIndex); litIndex.Text = " " + nFIELD_INDEX.ToString() + " "; ImageButton btnMoveUp = CreateLayoutImageButtonSkin(gID, "Layout.MoveUp", nFIELD_INDEX, Translation.GetTranslation.Term("Dropdown.LNK_UP"), "uparrow_inline", Page_Command); ImageButton btnMoveDown = CreateLayoutImageButtonSkin(gID, "Layout.MoveDown", nFIELD_INDEX, Translation.GetTranslation.Term("Dropdown.LNK_DOWN"), "downarrow_inline", Page_Command); ImageButton btnInsert = CreateLayoutImageButtonSkin(gID, "Layout.Insert", nFIELD_INDEX, Translation.GetTranslation.Term("Dropdown.LNK_INS"), "plus_inline", Page_Command); ImageButton btnEdit = CreateLayoutImageButtonSkin(gID, "Layout.Edit", nFIELD_INDEX, Translation.GetTranslation.Term("Dropdown.LNK_EDIT"), "edit_inline", Page_Command); ImageButton btnDelete = CreateLayoutImageButtonSkin(gID, "Layout.Delete", nFIELD_INDEX, Translation.GetTranslation.Term("Dropdown.LNK_DELETE"), "delete_inline", Page_Command); tdAction.Controls.Add(btnMoveUp); tdAction.Controls.Add(btnMoveDown); tdAction.Controls.Add(btnInsert); tdAction.Controls.Add(btnEdit); tdAction.Controls.Add(btnDelete); } Literal litLabel = new Literal(); if (!TypeConvert.IsEmptyString(sDATA_FIELD)) litLabel.ID = sDATA_FIELD + "_LABEL"; if (nCOLSPAN >= 0 || tdLabel == null || tdField == null) { tdLabel = new HtmlTableCell(); tdField = new HtmlTableCell(); tr.Cells.Add(tdLabel); tr.Cells.Add(tdField); if (nCOLSPAN > 0) { tdField.ColSpan = nCOLSPAN; if (bLayoutMode) tdField.ColSpan++; } tdLabel.Attributes.Add("class", "dataLabel"); tdLabel.VAlign = "top"; tdLabel.Width = sLABEL_WIDTH; tdField.Attributes.Add("class", "dataField"); tdField.VAlign = "top"; if (nCOLSPAN == 0) tdField.Width = sFIELD_WIDTH; tdLabel.Controls.Add(litLabel); if (bLayoutMode) litLabel.Text = sDATA_LABEL; else if (sDATA_LABEL.IndexOf(".") >= 0) litLabel.Text = Translation.GetTranslation.Term(sDATA_LABEL); else if (!TypeConvert.IsEmptyString(sDATA_LABEL) && rdr != null) { litLabel.Text = sDATA_LABEL; if (vwSchema != null) { vwSchema.RowFilter = "ColumnName = '" + TypeConvert.EscapeSQL(sDATA_LABEL) + "'"; if (vwSchema.Count > 0) litLabel.Text = TypeConvert.ToString(rdr[sDATA_LABEL]) + Translation.GetTranslation.Term("Calls.LBL_COLON"); } } else litLabel.Text = sDATA_LABEL; // " "; if (!bLayoutMode && bUI_REQUIRED) { Label lblRequired = new Label(); tdLabel.Controls.Add(lblRequired); lblRequired.CssClass = "required"; lblRequired.Text = Translation.GetTranslation.Term(".LBL_REQUIRED_SYMBOL"); } } if (String.Compare(sFIELD_TYPE, "Blank", true) == 0) { Literal litField = new Literal(); tdField.Controls.Add(litField); if (bLayoutMode) { litLabel.Text = "*** BLANK ***"; litField.Text = "*** BLANK ***"; } else { litLabel.Text = " "; litField.Text = " "; } } else if (String.Compare(sFIELD_TYPE, "Label", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { Literal litField = new Literal(); tdField.Controls.Add(litField); tdField.VAlign = "middle"; litField.ID = sDATA_FIELD; if (bLayoutMode) litField.Text = sDATA_FIELD; else if (sDATA_FIELD.IndexOf(".") >= 0) litField.Text = Translation.GetTranslation.Term(sDATA_FIELD); else if (rdr != null) litField.Text = TypeConvert.ToString(rdr[sDATA_FIELD]); } } else if (String.Compare(sFIELD_TYPE, "ListBox", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { ListControl lstField = null; if (nFORMAT_ROWS > 0) { ListBox lb = new ListBox(); lb.SelectionMode = ListSelectionMode.Multiple; lb.Rows = nFORMAT_ROWS; lstField = lb; } else { lstField = new KeySortDropDownList(); } tdField.Controls.Add(lstField); lstField.ID = sDATA_FIELD; lstField.TabIndex = nFORMAT_TAB_INDEX; if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { if (!TypeConvert.IsEmptyString(sCACHE_NAME) && (bLayoutMode || !tbl.Page.IsPostBack)) { lstField.DataValueField = "NAME"; lstField.DataTextField = "DISPLAY_NAME"; lstField.DataSource = CRMCache.List(sCACHE_NAME); if (sCACHE_NAME != "lead_status_dom") { if (sCACHE_NAME != "Currencies") { lstField.Attributes.Add("class", "dropdown"); } } if (sCACHE_NAME != "program_plan" || sCACHE_NAME != "Currencies") { if (sCACHE_NAME != "Currencies") { lstField.Attributes.Add("dom", sCACHE_NAME); } } lstField.DataBind(); if (!TypeConvert.IsEmptyString(sONCLICK_SCRIPT)) lstField.Attributes.Add("onchange", sONCLICK_SCRIPT); if (!bUI_REQUIRED) { lstField.Items.Insert(0, new ListItem(Translation.GetTranslation.Term(".LBL_NONE"), "")); lstField.DataBound += new EventHandler(ListControl_DataBound_AllowNull); } } if (rdr != null) { string sVALUE = TypeConvert.ToString(rdr[sDATA_FIELD]); if (nFORMAT_ROWS > 0 && sVALUE.StartsWith("<?xml")) { XmlDocument xml = new XmlDocument(); xml.LoadXml(sVALUE); XmlNodeList nlValues = xml.DocumentElement.SelectNodes("Value"); foreach (XmlNode xValue in nlValues) { foreach (ListItem item in lstField.Items) { if (item.Value == xValue.InnerText) item.Selected = true; } } } else { lstField.SelectedValue = sVALUE; } } else if (rdr == null && !tbl.Page.IsPostBack && sCACHE_NAME == "AssignedUser") { if (nFORMAT_ROWS == 0) lstField.SelectedValue = CRMSecurity.USER_ID.ToString(); } } if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); } } } else if (String.Compare(sFIELD_TYPE, "CheckBox", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { CheckBox chkField = new CheckBox(); tdField.Controls.Add(chkField); chkField.ID = sDATA_FIELD; chkField.CssClass = "checkbox"; chkField.TabIndex = nFORMAT_TAB_INDEX; if (rdr != null) chkField.Checked = TypeConvert.ToBoolean(rdr[sDATA_FIELD]); if (!TypeConvert.IsEmptyString(sONCLICK_SCRIPT)) chkField.Attributes.Add("onclick", sONCLICK_SCRIPT); if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); chkField.Enabled = false; } } } else if (String.Compare(sFIELD_TYPE, "ChangeButton", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { if (sDATA_LABEL == "PARENT_TYPE") { tdLabel.Controls.Clear(); DropDownList lstField = new KeySortDropDownList(); tdLabel.Controls.Add(lstField); lstField.ID = sDATA_LABEL; lstField.TabIndex = nFORMAT_TAB_INDEX; lstField.Attributes.Add("onChange", "ChangeParentType();"); if (bLayoutMode || !tbl.Page.IsPostBack) { lstField.DataValueField = "NAME"; lstField.DataTextField = "DISPLAY_NAME"; lstField.DataSource = CRMCache.List("record_type_display"); lstField.DataBind(); if (rdr != null) { lstField.ClearSelection(); lstField.SelectedValue = TypeConvert.ToString(rdr[sDATA_LABEL]); } } } TextBox txtNAME = new TextBox(); tdField.Controls.Add(txtNAME); txtNAME.ID = sDISPLAY_FIELD; txtNAME.ReadOnly = true; txtNAME.TabIndex = nFORMAT_TAB_INDEX; txtNAME.EnableViewState = false; if (bLayoutMode) { txtNAME.Text = sDISPLAY_FIELD; txtNAME.Enabled = false; } else if (tbl.Page.IsPostBack) { if (tbl.Page.Request[txtNAME.UniqueID] != null) txtNAME.Text = TypeConvert.ToString(tbl.Page.Request[txtNAME.UniqueID]); } else if (!TypeConvert.IsEmptyString(sDISPLAY_FIELD) && rdr != null) txtNAME.Text = TypeConvert.ToString(rdr[sDISPLAY_FIELD]); else if (sDATA_FIELD == "TEAM_ID" && rdr == null && !tbl.Page.IsPostBack) txtNAME.Text = CRMSecurity.TEAM_NAME; else if (sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !tbl.Page.IsPostBack) txtNAME.Text = CRMSecurity.USER_NAME; HtmlInputHidden hidID = new HtmlInputHidden(); tdField.Controls.Add(hidID); hidID.ID = sDATA_FIELD; if (!bLayoutMode) { if (!TypeConvert.IsEmptyString(sDATA_FIELD) && rdr != null) { hidID.Value = TypeConvert.ToString(rdr[sDATA_FIELD]); hidID.Value = (TypeConvert.ToGuid(hidID.Value) == Guid.Empty) ? "" : hidID.Value; } else if (sDATA_FIELD == "TEAM_ID" && rdr == null && !tbl.Page.IsPostBack) hidID.Value = CRMSecurity.TEAM_ID.ToString(); else if (sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !tbl.Page.IsPostBack) hidID.Value = CRMSecurity.USER_ID.ToString(); } if (!String.IsNullOrEmpty(CRMSecurity.TEAM_NAME)) { txtNAME.Text = CRMSecurity.TEAM_NAME; } else { InlineQueryDBManager oQuery = new InlineQueryDBManager(); oQuery.CommandText = "select Teams.name,Teams.id from Teams where id in (select t.team_ID from users u " + "inner join Team_Memberships t on u.id = t.USER_ID " + "and u.id ='" + Security.USER_ID.ToString() + "')"; using (DataTable dt = oQuery.GetTable()) { if (dt.Rows.Count > 0 && (sDATA_FIELD != "ASSIGNED_USER_ID" && rdr == null && !tbl.Page.IsPostBack)) { txtNAME.Text = dt.Rows[0]["name"].ToString(); hidID.Value = dt.Rows[0]["id"].ToString(); } } } Literal litNBSP = new Literal(); tdField.Controls.Add(litNBSP); litNBSP.Text = " "; HtmlInputButton btnChange = new HtmlInputButton("button"); tdField.Controls.Add(btnChange); btnChange.ID = sDATA_FIELD + "_btnChange"; btnChange.Attributes.Add("class", "button"); if (!TypeConvert.IsEmptyString(sONCLICK_SCRIPT)) btnChange.Attributes.Add("onclick", sONCLICK_SCRIPT); btnChange.Attributes.Add("title", Translation.GetTranslation.Term(".LBL_SELECT_BUTTON_TITLE")); btnChange.Value = Translation.GetTranslation.Term(".LBL_SELECT_BUTTON_LABEL"); if (sONCLICK_SCRIPT.IndexOf("Popup();") > 0) { litNBSP = new Literal(); tdField.Controls.Add(litNBSP); litNBSP.Text = " "; HtmlInputButton btnClear = new HtmlInputButton("button"); tdField.Controls.Add(btnClear); btnClear.ID = sDATA_FIELD + "_btnClear"; btnClear.Attributes.Add("class", "button"); btnClear.Attributes.Add("onclick", sONCLICK_SCRIPT.Replace("Popup();", "('', '');").Replace("return ", "return Change")); btnClear.Attributes.Add("title", Translation.GetTranslation.Term(".LBL_CLEAR_BUTTON_TITLE")); btnClear.Value = Translation.GetTranslation.Term(".LBL_CLEAR_BUTTON_LABEL"); } if (!bLayoutMode && bUI_REQUIRED && !TypeConvert.IsEmptyString(sDATA_FIELD)) { RequiredFieldValidatorForHiddenInputs reqID = new RequiredFieldValidatorForHiddenInputs(); reqID.ID = sDATA_FIELD + "_REQUIRED"; reqID.ControlToValidate = hidID.ID; reqID.ErrorMessage = Translation.GetTranslation.Term(".ERR_REQUIRED_FIELD"); reqID.CssClass = "required"; reqID.EnableViewState = false; reqID.EnableClientScript = false; reqID.Enabled = false; reqID.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqID); } } } else if (String.Compare(sFIELD_TYPE, "TextBox", true) == 0 || String.Compare(sFIELD_TYPE, "Password", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { TextBox txtField = new TextBox(); tdField.Controls.Add(txtField); txtField.ID = sDATA_FIELD; txtField.TabIndex = nFORMAT_TAB_INDEX; if (nFORMAT_ROWS > 0 && nFORMAT_COLUMNS > 0) { txtField.Rows = nFORMAT_ROWS; txtField.Columns = nFORMAT_COLUMNS; txtField.TextMode = TextBoxMode.MultiLine; } else { txtField.MaxLength = nFORMAT_MAX_LENGTH; txtField.Attributes.Add("size", nFORMAT_SIZE.ToString()); txtField.TextMode = TextBoxMode.SingleLine; } if (bLayoutMode) { txtField.Text = sDATA_FIELD; txtField.ReadOnly = true; } else if (!TypeConvert.IsEmptyString(sDATA_FIELD) && rdr != null) { int nOrdinal = rdr.GetOrdinal(sDATA_FIELD); string sTypeName = rdr.GetDataTypeName(nOrdinal); if (sTypeName == "money" || rdr[sDATA_FIELD].GetType() == typeof(System.Decimal)) txtField.Text = TypeConvert.ToDecimal(rdr[sDATA_FIELD]).ToString("#,##0.00"); else txtField.Text = TypeConvert.ToString(rdr[sDATA_FIELD]); } if (String.Compare(sFIELD_TYPE, "Password", true) == 0) txtField.TextMode = TextBoxMode.Password; if (!bLayoutMode && bUI_REQUIRED && !TypeConvert.IsEmptyString(sDATA_FIELD)) { RequiredFieldValidator reqNAME = new RequiredFieldValidator(); reqNAME.ID = sDATA_FIELD + "_REQUIRED"; reqNAME.ControlToValidate = txtField.ID; reqNAME.ErrorMessage = Translation.GetTranslation.Term(".ERR_REQUIRED_FIELD"); reqNAME.CssClass = "required"; reqNAME.EnableViewState = false; reqNAME.EnableClientScript = false; reqNAME.Enabled = false; reqNAME.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqNAME); } if (!bLayoutMode && !TypeConvert.IsEmptyString(sDATA_FIELD)) { if (sVALIDATION_TYPE == "RegularExpressionValidator" && !TypeConvert.IsEmptyString(sREGULAR_EXPRESSION) && !TypeConvert.IsEmptyString(sFIELD_VALIDATOR_MESSAGE)) { RegularExpressionValidator reqVALIDATOR = new RegularExpressionValidator(); reqVALIDATOR.ID = sDATA_FIELD + "_VALIDATOR"; reqVALIDATOR.ControlToValidate = txtField.ID; reqVALIDATOR.ErrorMessage = Translation.GetTranslation.Term(sFIELD_VALIDATOR_MESSAGE); reqVALIDATOR.ValidationExpression = sREGULAR_EXPRESSION; reqVALIDATOR.CssClass = "required"; reqVALIDATOR.EnableViewState = false; reqVALIDATOR.EnableClientScript = false; reqVALIDATOR.Enabled = false; reqVALIDATOR.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqVALIDATOR); } } } } else if (String.Compare(sFIELD_TYPE, "DatePicker", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { DatePicker ctlDate = tbl.Page.LoadControl("~/CRM/UserControls/DatePicker.ascx") as DatePicker; tdField.Controls.Add(ctlDate); ctlDate.ID = sDATA_FIELD; ctlDate.TabIndex = nFORMAT_TAB_INDEX; if (rdr != null) ctlDate.Value = CRM.Common.TimeZone.GetTimeZone.FromServerTime(rdr[sDATA_FIELD]); if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); } } } else if (String.Compare(sFIELD_TYPE, "DateRange", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { Table tblDateRange = new Table(); tdField.Controls.Add(tblDateRange); TableRow trAfter = new TableRow(); TableRow trBefore = new TableRow(); tblDateRange.Rows.Add(trAfter); tblDateRange.Rows.Add(trBefore); TableCell tdAfterLabel = new TableCell(); TableCell tdAfterData = new TableCell(); TableCell tdBeforeLabel = new TableCell(); TableCell tdBeforeData = new TableCell(); trAfter.Cells.Add(tdAfterLabel); trAfter.Cells.Add(tdAfterData); trBefore.Cells.Add(tdBeforeLabel); trBefore.Cells.Add(tdBeforeData); DatePicker ctlDateStart = tbl.Page.LoadControl("~/CRM/UserControls/DatePicker.ascx") as DatePicker; DatePicker ctlDateEnd = tbl.Page.LoadControl("~/CRM/UserControls/DatePicker.ascx") as DatePicker; Literal litAfterLabel = new Literal(); Literal litBeforeLabel = new Literal(); litAfterLabel.Text = Translation.GetTranslation.Term("SavedSearch.LBL_SEARCH_AFTER"); litBeforeLabel.Text = Translation.GetTranslation.Term("SavedSearch.LBL_SEARCH_BEFORE"); tdAfterLabel.Controls.Add(litAfterLabel); tdAfterData.Controls.Add(ctlDateStart); tdBeforeLabel.Controls.Add(litBeforeLabel); tdBeforeData.Controls.Add(ctlDateEnd); ctlDateStart.ID = sDATA_FIELD + "_AFTER"; ctlDateEnd.ID = sDATA_FIELD + "_BEFORE"; ctlDateStart.TabIndex = nFORMAT_TAB_INDEX; ctlDateEnd.TabIndex = nFORMAT_TAB_INDEX; if (rdr != null) { ctlDateStart.Value = CRM.Common.TimeZone.GetTimeZone.FromServerTime(rdr[sDATA_FIELD]); ctlDateEnd.Value = CRM.Common.TimeZone.GetTimeZone.FromServerTime(rdr[sDATA_FIELD]); } if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); } } } else if (String.Compare(sFIELD_TYPE, "DateTimePicker", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { DateTimePicker ctlDate = tbl.Page.LoadControl("~/CRM/UserControls/DateTimePicker.ascx") as DateTimePicker; tdField.Controls.Add(ctlDate); ctlDate.ID = sDATA_FIELD; ctlDate.TabIndex = nFORMAT_TAB_INDEX; if (rdr != null) ctlDate.Value = CRM.Common.TimeZone.GetTimeZone.FromServerTime(rdr[sDATA_FIELD]); if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); } } } else if (String.Compare(sFIELD_TYPE, "DateTimeEdit", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { DateTimeEdit ctlDate = tbl.Page.LoadControl("~/CRM/UserControls/DateTimeEdit.ascx") as DateTimeEdit; tdField.Controls.Add(ctlDate); ctlDate.ID = sDATA_FIELD; ctlDate.TabIndex = nFORMAT_TAB_INDEX; if (rdr != null) ctlDate.Value = CRM.Common.TimeZone.GetTimeZone.FromServerTime(rdr[sDATA_FIELD]); if (!bLayoutMode && bUI_REQUIRED) { ctlDate.EnableNone = false; } if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); } } } else if (String.Compare(sFIELD_TYPE, "File", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { HtmlInputFile ctlField = new HtmlInputFile(); tdField.Controls.Add(ctlField); ctlField.ID = sDATA_FIELD; ctlField.MaxLength = nFORMAT_MAX_LENGTH; ctlField.Size = nFORMAT_SIZE; ctlField.Attributes.Add("TabIndex", nFORMAT_TAB_INDEX.ToString()); if (!bLayoutMode && bUI_REQUIRED) { RequiredFieldValidator reqNAME = new RequiredFieldValidator(); reqNAME.ID = sDATA_FIELD + "_REQUIRED"; reqNAME.ControlToValidate = ctlField.ID; reqNAME.ErrorMessage = Translation.GetTranslation.Term(".ERR_REQUIRED_FIELD"); reqNAME.CssClass = "required"; reqNAME.EnableViewState = false; reqNAME.EnableClientScript = false; reqNAME.Enabled = false; reqNAME.Style.Add("padding-left", "4px"); tdField.Controls.Add(reqNAME); } } } else if (String.Compare(sFIELD_TYPE, "Image", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { HtmlInputHidden ctlHidden = new HtmlInputHidden(); if (!bLayoutMode) { tdField.Controls.Add(ctlHidden); ctlHidden.ID = sDATA_FIELD; HtmlInputFile ctlField = new HtmlInputFile(); tdField.Controls.Add(ctlField); ctlField.ID = sDATA_FIELD + "_File"; Literal litBR = new Literal(); litBR.Text = "<br />"; tdField.Controls.Add(litBR); } Image imgField = new Image(); imgField.ID = "img" + sDATA_FIELD; try { if (bLayoutMode) { Literal litField = new Literal(); litField.Text = sDATA_FIELD; tdField.Controls.Add(litField); } else if (rdr != null) { if (!TypeConvert.IsEmptyString(rdr[sDATA_FIELD])) { ctlHidden.Value = TypeConvert.ToString(rdr[sDATA_FIELD]); imgField.ImageUrl = "~/CRM/Images/Image.aspx?ID=" + ctlHidden.Value; tdField.Controls.Add(imgField); Literal litClear = new Literal(); litClear.Text = "<br /><input type=\"button\" class=\"button\" onclick=\"form." + ctlHidden.ClientID + ".value='';form." + imgField.ClientID + ".src='';" + "\" value='" + " " + Translation.GetTranslation.Term(".LBL_CLEAR_BUTTON_LABEL") + " " + "' title='" + Translation.GetTranslation.Term(".LBL_CLEAR_BUTTON_TITLE") + "' />"; tdField.Controls.Add(litClear); } } } catch (Exception ex) { Literal litField = new Literal(); litField.Text = ex.Message; tdField.Controls.Add(litField); } } } else if (String.Compare(sFIELD_TYPE, "AddressButtons", true) == 0) { tr.Cells.Remove(tdField); tdLabel.Width = "10%"; tdLabel.RowSpan = nROWSPAN; tdLabel.VAlign = "middle"; tdLabel.Align = "center"; tdLabel.Attributes.Remove("class"); tdLabel.Attributes.Add("class", "tabFormAddDel"); HtmlInputButton btnCopyRight = new HtmlInputButton("button"); Literal litSpacer = new Literal(); HtmlInputButton btnCopyLeft = new HtmlInputButton("button"); tdLabel.Controls.Add(btnCopyRight); tdLabel.Controls.Add(litSpacer); tdLabel.Controls.Add(btnCopyLeft); btnCopyRight.Attributes.Add("title", Translation.GetTranslation.Term("Accounts.NTC_COPY_BILLING_ADDRESS")); btnCopyRight.Attributes.Add("onclick", "return copyAddressRight()"); btnCopyRight.Value = ">>"; litSpacer.Text = "<br><br>"; btnCopyLeft.Attributes.Add("title", Translation.GetTranslation.Term("Accounts.NTC_COPY_SHIPPING_ADDRESS")); btnCopyLeft.Attributes.Add("onclick", "return copyAddressLeft()"); btnCopyLeft.Value = "<<"; nColIndex = 0; } else if (String.Compare(sFIELD_TYPE, "Hidden", true) == 0) { if (!TypeConvert.IsEmptyString(sDATA_FIELD)) { HtmlInputHidden hidID = new HtmlInputHidden(); tdField.Controls.Add(hidID); hidID.ID = sDATA_FIELD; if (bLayoutMode) { TextBox txtNAME = new TextBox(); tdField.Controls.Add(txtNAME); txtNAME.ReadOnly = true; txtNAME.EnableViewState = false; txtNAME.Text = sDATA_FIELD; txtNAME.Enabled = false; } else { nCOLSPAN = -1; tr.Cells.Remove(tdLabel); tdField.Attributes.Add("style", "display:none"); if (!TypeConvert.IsEmptyString(sDATA_FIELD) && rdr != null) hidID.Value = TypeConvert.ToString(rdr[sDATA_FIELD]); else if (sDATA_FIELD == "TEAM_ID" && rdr == null && !tbl.Page.IsPostBack) hidID.Value = CRMSecurity.TEAM_ID.ToString(); else if (sDATA_FIELD == "ASSIGNED_USER_ID" && rdr == null && !tbl.Page.IsPostBack) hidID.Value = CRMSecurity.USER_ID.ToString(); } } } else { Literal litField = new Literal(); tdField.Controls.Add(litField); litField.Text = "Unknown field type " + sFIELD_TYPE; } if (nCOLSPAN > 0) nColIndex += nCOLSPAN; else if (nCOLSPAN == 0) nColIndex++; if (nColIndex >= nDATA_COLUMNS) nColIndex = 0; } }