using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Collections; namespace Common { /// /// FixDBManager 的摘要说明。 /// public sealed class FixDBManager { public FixDBManager() { // // TODO: 在此处添加构造函数逻辑 // } public static object[] FixValues(object[] values) { for ( int i = 0 ;i< values.Length ;i++) { if (values[i] == null) { values[i] = DBNull.Value ; } else if(values[i].GetType().FullName == "System.String") { values[i] = ((string)values[i]).Length != 0? values[i]: DBNull.Value; } } return values; } public static string CheckNullStr(object obj) { if(obj == null || obj.GetType() == typeof(System.DBNull)) { return ""; } else { return Convert.ToString(obj); } } public static int CheckNullInt(object obj) { if(obj == null || obj.GetType() == typeof(System.DBNull)) { return 0; } else { return Convert.ToInt32(obj); } } public static System.Decimal CheckNullDecimal(object obj) { if(obj == null || obj.GetType() == typeof(System.DBNull)) { return 0; } else { return Convert.ToDecimal(obj); } } public static void Init_ComboControl(System.Windows.Forms.Control ComboControl, string TableName, string _displayMember, string _valueMember, ref System.Data.DataSet dst) { try { switch (ComboControl.GetType().ToString()) { case "Infragistics.Win.UltraWinGrid.UltraCombo": if (!dst.Tables.Contains(TableName)) { MessageBox.Show("绑定表:" + TableName + "不存在,不能对控件" + ComboControl.Name + "进行初始化!"); return; } System.Data.DataTable newTable = dst.Tables[TableName].Copy(); newTable.TableName = TableName; System.Data.DataRow newRow = newTable.NewRow(); for (int i = 0; i < dst.Tables[TableName].Columns.Count; i++) { newRow[i] = ""; } newTable.Rows.Add(newRow); newTable.AcceptChanges(); ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DataSource = new System.Data.DataView(newTable); ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayMember = _displayMember; ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).ValueMember = _valueMember; foreach (System.Data.DataColumn col in dst.Tables[TableName].Columns) { if (col.ColumnName != _displayMember) { ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Hidden = true; } else { ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Band.ColHeadersVisible = false; ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).DisplayLayout.Bands[TableName].Columns[col.ColumnName].Width = ((Infragistics.Win.UltraWinGrid.UltraCombo)ComboControl).Width; } } break; } } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); } } public static string splitArray(object obj, char splitor) { IList checkedItems = null; string checkedItem = ""; StringBuilder str = new StringBuilder(); checkedItems = obj as IList; if (checkedItems != null) { for (int i = 0; i < checkedItems.Count; i++) { // Each item in the list will be the value in the row that corresponds // to the ValueMember of the combo str = str.Append(splitor).Append((string)checkedItems[i]); } } checkedItem = str.ToString(); return checkedItem; } } }