using System; using System.Data; using System.Windows.Forms; using System.ComponentModel; namespace Common ... { public class ColumnManager ...{ private string[] _cname; private string[] _cheader; private string[] _clabel; private string[] _ccomment; private string _message; private DataSet ds; private string tb; private CurrencyManager cm; public ColumnManager(string[] cname,string[] cheader,string[] clabel,string[] cc) ...{ this._cname=cname; this._cheader=cheader; this._clabel=clabel; this._ccomment=cc; } public ColumnManager(DataSet cds,string ctb) ...{ ds= new DataSet(); ds.Merge(cds); int count = ds.Tables[ctb].Rows.Count; if(count!=0) ...{ _cname=new string[count]; _cheader=new string[count]; _clabel=new string[count]; _ccomment=new string[count]; ds=cds; this.tb=ctb; int i=0; foreach(DataRow dr in cds.Tables[ctb].Rows) ...{ _cname[i]=dr["pbc_cnam"].ToString(); _cheader[i]=dr["pbc_hdr"].ToString(); _clabel[i]=dr["pbc_labl"].ToString(); _ccomment[i]=dr["pbc_cmnt"].ToString(); i+=1; } } } public ColumnManager(DataSet cds,string ctb,CurrencyManager ccm) ...{ int count =cds.Tables[ctb].Rows.Count; if(count!=0) ...{ _cname=new string[count]; _cheader=new string[count]; _clabel=new string[count]; _ccomment=new string[count]; ds=cds; cm=ccm; this.tb=ctb; int i=0; foreach(DataRow dr in cds.Tables[ctb].Rows) ...{ string d=dr["pbc_cnam"].ToString(); _cname[i]=d.Trim(); _cheader[i]=dr["pbc_hdr"].ToString(); _clabel[i]=dr["pbc_labl"].ToString(); _ccomment[i]=dr["pbc_cmnt"].ToString(); i+=1; } } } public DataGridTableStyle CreateColumns(DataSet tds,string ctb) ...{ DataGridTableStyle GridTableStyle=new DataGridTableStyle(); GridTableStyle.MappingName=ctb; DataGridColumnStyle myStyle; PropertyDescriptor myDescriptor ; foreach(DataColumn dc in tds.Tables[tb].Columns) ...{ myDescriptor=cm.GetItemProperties()[dc.ColumnName]; myStyle =new DataGridTextBoxColumn(myDescriptor); myStyle.MappingName = dc.ColumnName; if(this.GetHeader(dc.ColumnName)!="") myStyle.HeaderText = this.GetHeader(dc.ColumnName); else myStyle.HeaderText = dc.ColumnName; myStyle.Alignment=HorizontalAlignment.Left; myStyle.NullText=String.Empty; GridTableStyle.GridColumnStyles.Add(myStyle); } return GridTableStyle; } public DataGridTableStyle CreateColumns(DataSet dds,string ctb,DataSet cbds,string cbtb,string dmember,string smember,string columnName) ...{ DataGridTableStyle GridTableStyle=new DataGridTableStyle(); GridTableStyle.MappingName=ctb; DataGridColumnStyle myStyle=null; PropertyDescriptor myDescriptor ; foreach(DataColumn dc in dds.Tables[ctb].Columns) ...{ if(dc.ColumnName!=columnName) ...{ myDescriptor=cm.GetItemProperties()[dc.ColumnName]; myStyle =new DataGridTextBoxColumn(myDescriptor); myStyle.MappingName = dc.ColumnName; myStyle.HeaderText = this.GetHeader(dc.ColumnName); myStyle.Alignment=HorizontalAlignment.Left; myStyle.NullText=String.Empty; } else ...{ myStyle =this.AddComboBoxColumn(cbds,ctb,dmember,smember,columnName); } GridTableStyle.GridColumnStyles.Add(myStyle); } return GridTableStyle; } public DataGridColumnStyle AddColumn(string columnName) ...{ DataGridColumnStyle myStyle; PropertyDescriptor myDescriptor ; myDescriptor=cm.GetItemProperties()[columnName]; myStyle =new DataGridTextBoxColumn(myDescriptor); myStyle.MappingName = columnName; myStyle.HeaderText = GetHeader(columnName); myStyle.Alignment=HorizontalAlignment.Left; myStyle.NullText=String.Empty; return myStyle; } public DataGridColumnStyle AddComboBoxColumn(DataSet cbds,string ctb,string dmember,string smember,string columnName) ...{ DataGridColumnStyle myStyle; myStyle =new DataGridComboBoxColumnStyle(cbds.Tables[ctb],dmember,smember); myStyle.MappingName = columnName; myStyle.HeaderText = GetHeader(columnName); myStyle.Alignment=HorizontalAlignment.Left; myStyle.NullText=String.Empty; return myStyle; } public string GetHeader(string cname) ...{ string rt=null; int i=ColumnIndex(cname); if(i<0) _message="No Column"; else ...{ rt=_cheader[i]; } return rt; } public string GetLabel(string cname) ...{ string rt=null; int i=ColumnIndex(cname); if(i<0) _message="No Column"; else ...{ rt=_clabel[i]; } return rt; } public string GetComment(string cname) ...{ string rt=null; int i=ColumnIndex(cname); if(i<0) _message="No Column"; else ...{ rt=_ccomment[i]; } return rt; } private int ColumnIndex(string cname) ...{ int k=-1; for(int i=0;i<_cname.Length;i++) ...{ if(cname==_cname[i]) ...{ k=i; break; } } return k; } public string[] AllColumn ...{ get ...{ return this._cname; } } public CurrencyManager CurrencyManager ...{ get...{return this.cm;} set...{cm=value;} } }}