/// <summary> /// 在DrectSoftWordbooks.XML中根据指定的字典名搜索定义数据,创建字典实例 /// XML文件的数据要符合Wordbook.XSD的定义。下面的处理流程是按XSD的定义进行的。 /// </summary> /// <param name="name">字典名称</param> protected BaseWordbook(string name) { Schema.Wordbook source = WordbookStaticHandle.GetSourceWordbookByName(name); if (String.IsNullOrEmpty(source.WordbookName)) { throw new ArgumentException("没有正确初始化字典,请检查基础数据"); } // 开始处理字典的属性 _wordbookName = source.WordbookName; _caption = source.Caption; _querySentence = PersistentObjectFactory.GetQuerySentenceByName(source.QuerySentence); _codeField = source.CodeField; _nameField = source.NameField; _queryCodeField = source.QueryCodeField; _codeFieldIsString = source.CodeFieldIsString; // 过滤参数 _parameters = new FilterParameterCollection(); _showStyles = new Collection <GridColumnStyleCollection>(); _defaultFilterFields = new Collection <string>(); if (source.FilterFieldCollection != null) { foreach (string field in source.FilterFieldCollection) { _defaultFilterFields.Add(field); } } if (source.ParameterCollection != null) { _parameters.AddRange(source.ParameterCollection); } GridColumnStyleCollection columnStyle; foreach (GridColumnStyle[] style in source.ViewStyleCollection) { columnStyle = new GridColumnStyleCollection(); columnStyle.AddRange(style); _showStyles.Add(columnStyle); } // 下列属性使用默认值 SelectedStyleIndex = 0; ExtraCondition = ""; _currentMatchFields = new Collection <string>(); foreach (string field in _defaultFilterFields) { _currentMatchFields.Add(field); } }
/// <summary> /// 将传入的字符串转换为GridColumnStyleCollection对象 /// </summary> /// <param name="stylesComb">列样式字符串组合</param> /// <returns></returns> public static GridColumnStyleCollection CreateColumnStyleCollectionByString(string stylesComb) { GridColumnStyleCollection styleCollection = new GridColumnStyleCollection(); if (String.IsNullOrEmpty(stylesComb)) { return(styleCollection); } // 先分解出单个的列显示样式 string[] sepColumn = new string[] { SeparatorSign.OtherSeparator }; string[] styles = stylesComb.Split(sepColumn, StringSplitOptions.None); string[] sepValue = new string[] { SeparatorSign.ListSeparator }; string[] values; foreach (string styleString in styles) { values = styleString.Split(sepValue, StringSplitOptions.None); styleCollection.Add(new GridColumnStyle(values[0], values[1] , Convert.ToInt32(values[2], CultureInfo.CurrentCulture))); } return(styleCollection); }
/// <summary> /// 保存对类做过的修改 /// </summary> private void SaveChanges() { try { CheckValue(); } catch (ArgumentNullException ae) { MessageBox.Show(ae.Message, "提示", MessageBoxButtons.OK , MessageBoxIcon.Information , MessageBoxDefaultButton.Button1 , MessageBoxOptions.DefaultDesktopOnly); return; } catch { throw; } GridColumnStyleCollection styleCollection = new GridColumnStyleCollection(); if (lvColumnStyles.Items.Count > 0) { foreach (ListViewItem item in lvColumnStyles.Items) { styleCollection.Add(new GridColumnStyle(item.Text , item.SubItems[1].Text , Convert.ToInt32(item.SubItems[2].Text, CultureInfo.CurrentCulture))); } } _wordbook = new SqlWordbook(tBoxName.Text.Trim() , tBoxQuery.Text.Trim() , tBoxCodeField.Text.Trim() , tBoxNameField.Text.Trim() , styleCollection , tBoxFilter.Text.Trim()); }
/// <summary> /// 查找指定名称的字段对应的显示样式对象在列表中的位置 /// </summary> /// <param name="fieldName"></param> /// <returns></returns> public int IndexOf(string fieldName) { return(GridColumnStyleCollection.IndexOf(this.InnerList, fieldName)); }
/// <summary> /// 用指定的SQL语句等信息创建SQL字典类实例。 /// 字段的显示名称、显示哪些列、列宽等信息在columnStyles中指定 /// </summary> /// <param name="uniqueName">局部唯一的名称</param> /// <param name="query">查询语句</param> /// <param name="codeField">代码字段名</param> /// <param name="nameField">名称字段名</param> /// <param name="columnStyles">字段的显示名称、显示哪些列、列宽等信息</param> public SqlWordbook(string uniqueName, string query, string codeField, string nameField, GridColumnStyleCollection columnStyles) : base() { Debug.Assert(uniqueName != null, "类名不能为NULL"); Debug.Assert(uniqueName.Length > 0, "类名不能为空"); WordbookName = uniqueName; Caption = WordbookName; ExtraCondition = ""; if (query.Length == 0) { throw new ArgumentNullException("必须指定查询语句"); } QuerySentence = query; if (codeField.Length == 0) { throw new ArgumentNullException("必须指定代码字段"); } CodeField = codeField; QueryCodeField = CodeField; if (nameField.Length == 0) { throw new ArgumentNullException("必须指定名称字段"); } NameField = nameField; DefaultFilterFields = new Collection <string>(); // 使用默认的代码列和名称列进行过滤 DefaultFilterFields.Add(codeField); DefaultFilterFields.Add(nameField); CurrentMatchFields = new Collection <string>(); foreach (string field in DefaultFilterFields) { CurrentMatchFields.Add(field); } Parameters = new FilterParameterCollection(); ShowStyles = new Collection <GridColumnStyleCollection>(); ShowStyles.Add(columnStyles); SelectedStyleIndex = 0; // Sql字典默认为不缓存数据 CacheTime = -1; _useSqlStatement = true; //_bookData = null; //m_DrawConditions = new Collection<CustomDrawSetting>(); }
/// <summary> /// 用指定的DataTable等信息创建SQL字典类实例。 /// 列的显示名用DataColumn的Caption代替,需要显示的列及其列宽通过columnWidthes设置 /// </summary> /// <param name="uniqueName">局部唯一的字典名</param> /// <param name="sourceData">数据集</param> /// <param name="codeField">代码字段名</param> /// <param name="nameField">名称字段名</param> /// <param name="columnWidthes">需要显示的列名及其列宽</param> public SqlWordbook(string uniqueName, DataTable sourceData, string codeField, string nameField, Dictionary <string, int> columnWidthes) : base() { Debug.Assert(uniqueName != null, "类名不能为NULL"); Debug.Assert(uniqueName.Length > 0, "类名不能为空"); WordbookName = uniqueName; Caption = WordbookName; if (sourceData == null) { throw new ArgumentNullException("数据集不能为空"); } //if (sourceData.Rows.Count == 0) // throw new ArgumentNullException("数据集中未包含数据"); _bookData = sourceData; // DataTable中默认RowFilter作为扩展条件保存 ExtraCondition = _bookData.DefaultView.RowFilter; QuerySentence = ""; if (codeField.Length == 0) { throw new ArgumentNullException("必须指定代码字段"); } if (!sourceData.Columns.Contains(codeField)) { throw new ArgumentOutOfRangeException("指定的代码字段在数据集中不存在"); } CodeField = codeField; QueryCodeField = CodeField; if (nameField.Length == 0) { throw new ArgumentNullException("必须指定名称字段"); } if (!sourceData.Columns.Contains(nameField)) { throw new ArgumentOutOfRangeException("指定的名称字段在数据集中不存在"); } NameField = nameField; DefaultFilterFields = new Collection <string>(); // 使用默认的代码列和名称列进行过滤 DefaultFilterFields.Add(codeField); DefaultFilterFields.Add(nameField); CurrentMatchFields = new Collection <string>(); foreach (string field in DefaultFilterFields) { CurrentMatchFields.Add(field); } Parameters = new FilterParameterCollection(); ShowStyles = new Collection <GridColumnStyleCollection>(); GridColumnStyleCollection styleCollection = new GridColumnStyleCollection(); GridColumnStyle style; foreach (KeyValuePair <string, int> keyValue in columnWidthes) { style = new GridColumnStyle(keyValue.Key , sourceData.Columns[keyValue.Key].Caption, keyValue.Value); styleCollection.Add(style); } if (styleCollection.Count == 0) { throw new ArgumentException("必须设置字典的显示列信息"); } ShowStyles.Add(styleCollection); SelectedStyleIndex = 0; // Sql字典默认为不缓存数据 CacheTime = -1; //_useSqlStatement = false; //_autoAddShortCode = false; //_shortCodeAdded = true; //m_DrawConditions = new Collection<CustomDrawSetting>(); }
/// <summary> /// 用指定的SQL语句等信息创建SQL字典类实例。 /// 字段的显示名称、显示哪些列、列宽等信息在columnStyles中指定 /// </summary> /// <param name="uniqueName">局部唯一的名称</param> /// <param name="query">查询语句</param> /// <param name="codeField">代码字段名</param> /// <param name="nameField">名称字段名</param> /// <param name="columnStyles">字段的显示名称、显示哪些列、列宽等信息</param> /// <param name="autoAddShortCode">自动添加拼音、五笔列</param> public SqlWordbook(string uniqueName, string query, string codeField, string nameField, GridColumnStyleCollection columnStyles, bool autoAddShortCode) : this(uniqueName, query, codeField, nameField, columnStyles) { if (autoAddShortCode) { DefaultFilterFields.Add("py"); DefaultFilterFields.Add("wb"); CurrentMatchFields.Add("py"); CurrentMatchFields.Add("wb"); m_AutoAddShortCode = true; } }
/// <summary> /// 用指定的SQL语句等信息创建SQL字典类实例。 /// 字段的显示名称、显示哪些列、列宽等信息在columnStyles中指定 /// </summary> /// <param name="uniqueName">局部唯一的名称</param> /// <param name="query">查询语句</param> /// <param name="codeField">代码字段名</param> /// <param name="nameField">名称字段名</param> /// <param name="columnStyles">字段的显示名称、显示哪些列、列宽等信息</param> /// <param name="matchFieldComb">指定用来匹配输入数据的字段名,多个时用“//”格开,可以传入空</param> public SqlWordbook(string uniqueName, string query, string codeField, string nameField, GridColumnStyleCollection columnStyles, string matchFieldComb) : this(uniqueName, query, codeField, nameField, columnStyles) { string[] separator = new string[] { SeparatorSign.ListSeparator }; string[] values = matchFieldComb.Split(separator, StringSplitOptions.RemoveEmptyEntries); if (values.Length > 0) { DefaultFilterFields.Clear(); CurrentMatchFields.Clear(); for (int i = 0; i < values.Length; i++) { DefaultFilterFields.Add(values[i]); CurrentMatchFields.Add(values[i]); } } }