/// <summary> /// Only support the ComboBox control from WinForm/Visual WebGUI /// </summary> /// <param name="ddList">the ComboBox control from WinForm/Visual WebGUI</param> /// <param name="TextField">e.g. new string[]{"FieldName1", "FieldName2", ...}</param> /// <param name="TextFormatString">e.g. "{0} - {1}"</param> /// <param name="SwitchLocale">Can be localized, if the FieldName has locale suffix, e.g. '_chs'</param> /// <param name="BlankLine">add blank label text to ComboBox or not</param> /// <param name="BlankLineText">the blank label text</param> /// <param name="ParentFilter">e.g. "ForeignFieldName = 'value'"</param> /// <param name="WhereClause">Where Clause for SQL Statement. e.g. "FieldName = 'SomeCondition'"</param> /// <param name="OrderBy">Sorting order, string array, e.g. {"FieldName1", "FiledName2"}</param> public static void LoadCombo(ref ComboBox ddList, string [] TextField, string TextFormatString, bool SwitchLocale, bool BlankLine, string BlankLineText, string ParentFilter, string WhereClause, string[] OrderBy) { if (SwitchLocale) { TextField = GetSwitchLocale(TextField); } ddList.Items.Clear(); SupplierTermsCollection source; if (OrderBy == null || OrderBy.Length == 0) { OrderBy = TextField; } if (WhereClause.Length > 0) { source = SupplierTerms.LoadCollection(WhereClause, OrderBy, true); } else { source = SupplierTerms.LoadCollection(OrderBy, true); } Common.ComboList sourceList = new Common.ComboList(); if (BlankLine) { sourceList.Add(new Common.ComboItem(BlankLineText, Guid.Empty)); } foreach (SupplierTerms item in source) { bool filter = false; if (ParentFilter.Trim() != String.Empty) { filter = true; if (item.ParentTerms != Guid.Empty) { filter = IgnorThis(item, ParentFilter); } } if (!(filter)) { string code = GetFormatedText(item, TextField, TextFormatString); sourceList.Add(new Common.ComboItem(code, item.TermsId)); } } ddList.DataSource = sourceList; ddList.DisplayMember = "Code"; ddList.ValueMember = "Id"; if (ddList.Items.Count > 0) { ddList.SelectedIndex = 0; } }
private static string GetFormatedText(SupplierTerms target, string [] textField, string textFormatString) { for (int i = 0; i < textField.Length; i++) { PropertyInfo pi = target.GetType().GetProperty(textField[i]); textFormatString = textFormatString.Replace("{" + i.ToString() + "}", pi != null ? pi.GetValue(target, null).ToString() : string.Empty); } return(textFormatString); }
/// <summary> /// Loads a collection of SupplierTerms objects from the database. /// </summary> /// <returns>A collection containing all of the SupplierTerms objects in the database.</returns> public static SupplierTermsCollection LoadCollection(string spName, SqlParameter[] parms) { SupplierTermsCollection result = new SupplierTermsCollection(); using (SqlDataReader reader = SqlHelper.Default.ExecuteReader(spName, parms)) { while (reader.Read()) { SupplierTerms tmp = new SupplierTerms(); tmp.LoadFromReader(reader); result.Add(tmp); } } return(result); }
/// <summary> /// Loads a SupplierTerms object from the database using the given where clause /// </summary> /// <param name="whereClause">The filter expression for the query</param> /// <returns>A SupplierTerms object</returns> public static SupplierTerms LoadWhere(string whereClause) { SqlParameter[] parameterValues = new SqlParameter[] { new SqlParameter("@WhereClause", whereClause) }; using (SqlDataReader reader = SqlHelper.Default.ExecuteReader("spSupplierTerms_SelAll", parameterValues)) { if (reader.Read()) { SupplierTerms result = new SupplierTerms(); result.LoadFromReader(reader); return(result); } else { return(null); } } }
/// <summary> /// Loads a SupplierTerms object from the database using the given TermsId /// </summary> /// <param name="termsId">The primary key value</param> /// <returns>A SupplierTerms object</returns> public static SupplierTerms Load(Guid termsId) { SqlParameter[] parameterValues = new SqlParameter[] { new SqlParameter("@TermsId", termsId) }; using (SqlDataReader reader = SqlHelper.Default.ExecuteReader("spSupplierTerms_SelRec", parameterValues)) { if (reader.Read()) { SupplierTerms result = new SupplierTerms(); result.LoadFromReader(reader); return(result); } else { return(null); } } }
private static bool IgnorThis(SupplierTerms target, string parentFilter) { bool result = true; parentFilter = parentFilter.Replace(" ", ""); // remove spaces parentFilter = parentFilter.Replace("'", ""); // remove ' string [] parsed = parentFilter.Split('='); // parse if (target.ParentTerms == Guid.Empty) { PropertyInfo pi = target.GetType().GetProperty(parsed[0]); string filterField = (string)pi.GetValue(target, null); if (filterField.ToLower() == parsed[1].ToLower()) { result = false; } } else { SupplierTerms parentTemplate = SupplierTerms.Load(target.ParentTerms); result = IgnorThis(parentTemplate, parentFilter); } return(result); }