Ejemplo n.º 1
0
		// load data from a data table or data set
		public long DataBind () 
		{
			long rowsRetrieved = 0;

			Clear ();

			System.Object o = null;
			o = GetResolvedDataSource (DataSource, DataMember);
			IEnumerable ie = (IEnumerable) o;
			ITypedList tlist = (ITypedList) o;
			TreeIter iter = new TreeIter ();
									
			PropertyDescriptorCollection pdc = tlist.GetItemProperties (new PropertyDescriptor[0]);
			gridColumns = new ArrayList(pdc.Count);

			// define the columns in the treeview store
			// based on the schema of the result
			GLib.GType[] theTypes = new GLib.GType[pdc.Count];
			for (int col = 0; col < pdc.Count; col++) {
				theTypes[col] = GLib.GType.String;
			}
			store.ColumnTypes = theTypes;

			int colndx = -1;
			foreach (PropertyDescriptor pd in pdc) {

				colndx ++;

				DataGridColumn gridCol = new DataGridColumn ();
				gridCol.ColumnName = pd.Name;		
				gridColumns.Add (gridCol);
			}

			foreach (System.Object obj in ie) {
				ICustomTypeDescriptor custom; 
				PropertyDescriptorCollection properties;
				
				custom = (ICustomTypeDescriptor) obj;
				properties = custom.GetProperties ();
				
				rowsRetrieved ++;
				iter = NewRow ();
				int cv = 0;

				foreach (PropertyDescriptor property in properties) {
					object oPropValue = property.GetValue (obj);
					string sPropValue = "";
					if (oPropValue.GetType ().ToString ().Equals ("System.Byte[]")) 
						sPropValue = GetHexString ((byte[]) oPropValue);
					else
						sPropValue = oPropValue.ToString ();
										
					SetColumnValue (iter, cv, sPropValue);
					cv++;			
				}
			}

			treeView.Model = store;
			AutoCreateTreeViewColumns ();
			return rowsRetrieved;
		}
Ejemplo n.º 2
0
        // load data from a data table or data set
        public long DataBind()
        {
            long rowsRetrieved = 0;

            Clear();

            System.Object o = null;
            o = GetResolvedDataSource(DataSource, DataMember);
            IEnumerable ie    = (IEnumerable)o;
            ITypedList  tlist = (ITypedList)o;
            TreeIter    iter  = new TreeIter();

            PropertyDescriptorCollection pdc = tlist.GetItemProperties(new PropertyDescriptor[0]);

            gridColumns = new ArrayList(pdc.Count);

            // define the columns in the treeview store
            // based on the schema of the result
            GLib.GType[] theTypes = new GLib.GType[pdc.Count];
            for (int col = 0; col < pdc.Count; col++)
            {
                theTypes[col] = GLib.GType.String;
            }
            store.ColumnTypes = theTypes;

            int colndx = -1;

            foreach (PropertyDescriptor pd in pdc)
            {
                colndx++;

                DataGridColumn gridCol = new DataGridColumn();
                gridCol.ColumnName = pd.Name;
                gridColumns.Add(gridCol);
            }

            foreach (System.Object obj in ie)
            {
                ICustomTypeDescriptor        custom;
                PropertyDescriptorCollection properties;

                custom     = (ICustomTypeDescriptor)obj;
                properties = custom.GetProperties();

                rowsRetrieved++;
                iter = NewRow();
                int cv = 0;

                foreach (PropertyDescriptor property in properties)
                {
                    object oPropValue = property.GetValue(obj);
                    string sPropValue = "";
                    if (oPropValue.GetType().ToString().Equals("System.Byte[]"))
                    {
                        sPropValue = GetHexString((byte[])oPropValue);
                    }
                    else
                    {
                        sPropValue = oPropValue.ToString();
                    }

                    SetColumnValue(iter, cv, sPropValue);
                    cv++;
                }
            }

            treeView.Model = store;
            AutoCreateTreeViewColumns();
            return(rowsRetrieved);
        }
Ejemplo n.º 3
0
		// alternative to DataBind() - load from a data reader
		public long DataLoad (IDataReader reader)
		{
			long rowsRetrieved = 0;

			Clear ();
			dataMember = "";
			dataSource = null;
			
			if (reader.FieldCount > 0) {
				DataTable schema = reader.GetSchemaTable ();
				GLib.GType[] theTypes = new GLib.GType[reader.FieldCount];
				gridColumns = new ArrayList(reader.FieldCount);

				IDataRecord record = (IDataRecord) reader;
				
				int col = 0;
				for (col = 0; col < reader.FieldCount; col ++)	{
					DataGridColumn gridCol = new DataGridColumn ();
					gridCol.ColumnName = record.GetName (col);
					
					try {
						gridCol.DataType = (Type) schema.Rows [col] ["DataType"];
					}
					catch (Exception e) {
						gridCol.DataType = typeof (string);
					}
					
					theTypes [col] = GLib.GType.String;
					gridColumns.Add (gridCol);
				}
				store.ColumnTypes = theTypes;

				TreeIter iter = new TreeIter ();
				
				while (reader.Read ()) {			
					rowsRetrieved ++;
					iter = NewRow ();

					object oValue = null;
					string sValue = "";

					for (col = 0; col < reader.FieldCount; col ++) {													
						oValue = reader.GetValue (col);
						if (reader.IsDBNull (col))
							sValue = "";
						else {
							oValue = reader[col];
							sValue = "";

							if (oValue.GetType ().ToString ().Equals ("System.Byte[]")) 
								sValue = GetHexString ((byte[]) oValue);
							else 
							{
								sValue = oValue.ToString ();

								// work-around for padding numerics on the right
								// gtk# 2.10 added Alignment property to TreeViewColumn
								// but this app is built with gtk# 2.8
								// also, provide custom formatting of columns
								// such as, dates
								DataGridColumn gcol = ((DataGridColumn) gridColumns [col]);
								if (!sValue.Equals(String.Empty))
									if (!gcol.Format.Equals(String.Empty))
										switch (oValue.GetType().ToString() )
										{
											case "System.DateTime":
												sValue = ((DateTime) oValue).ToString (gcol.Format);
												break;
										}
								int maxSize = gcol.MaxSize;
								if (gcol.MaxSize > 0 || gcol.Alignment == Pango.Alignment.Right)
									sValue = sValue.PadLeft (maxSize);							
							}
						}					
						
						SetColumnValue (iter, col, sValue);
					}
				}

				treeView.Model = store;
				AutoCreateTreeViewColumns ();
			}
			return rowsRetrieved;
		}
Ejemplo n.º 4
0
        // alternative to DataBind() - load from a data reader
        public long DataLoad(IDataReader reader)
        {
            long rowsRetrieved = 0;

            Clear();
            dataMember = "";
            dataSource = null;

            if (reader.FieldCount > 0)
            {
                DataTable    schema   = reader.GetSchemaTable();
                GLib.GType[] theTypes = new GLib.GType[reader.FieldCount];
                gridColumns = new ArrayList(reader.FieldCount);

                IDataRecord record = (IDataRecord)reader;

                int col = 0;
                for (col = 0; col < reader.FieldCount; col++)
                {
                    DataGridColumn gridCol = new DataGridColumn();
                    gridCol.ColumnName = record.GetName(col);

                    try {
                        gridCol.DataType = (Type)schema.Rows [col] ["DataType"];
                    }
                    catch (Exception e) {
                        gridCol.DataType = typeof(string);
                    }

                    theTypes [col] = GLib.GType.String;
                    gridColumns.Add(gridCol);
                }
                store.ColumnTypes = theTypes;

                TreeIter iter = new TreeIter();

                while (reader.Read())
                {
                    rowsRetrieved++;
                    iter = NewRow();

                    object oValue = null;
                    string sValue = "";

                    for (col = 0; col < reader.FieldCount; col++)
                    {
                        oValue = reader.GetValue(col);
                        if (reader.IsDBNull(col))
                        {
                            sValue = "";
                        }
                        else
                        {
                            oValue = reader[col];
                            sValue = "";

                            if (oValue.GetType().ToString().Equals("System.Byte[]"))
                            {
                                sValue = GetHexString((byte[])oValue);
                            }
                            else
                            {
                                sValue = oValue.ToString();

                                // work-around for padding numerics on the right
                                // gtk# 2.10 added Alignment property to TreeViewColumn
                                // but this app is built with gtk# 2.8
                                // also, provide custom formatting of columns
                                // such as, dates
                                DataGridColumn gcol = ((DataGridColumn)gridColumns [col]);
                                if (!sValue.Equals(String.Empty))
                                {
                                    if (!gcol.Format.Equals(String.Empty))
                                    {
                                        switch (oValue.GetType().ToString())
                                        {
                                        case "System.DateTime":
                                            sValue = ((DateTime)oValue).ToString(gcol.Format);
                                            break;
                                        }
                                    }
                                }
                                int maxSize = gcol.MaxSize;
                                if (gcol.MaxSize > 0 || gcol.Alignment == Pango.Alignment.Right)
                                {
                                    sValue = sValue.PadLeft(maxSize);
                                }
                            }
                        }

                        SetColumnValue(iter, col, sValue);
                    }
                }

                treeView.Model = store;
                AutoCreateTreeViewColumns();
            }
            return(rowsRetrieved);
        }