Beispiel #1
0
 public static void GridWizard(QuickGrid grid,
     DataTable table,bool isMetric,IsNewAllowed isNewAllowed,
     IsReadOnly isReadOnly,
     string sortingField,GetFieldDelegate getField,
     HelperFunctions.DataGridClientInterface face,params string[] fieldsIn)
 {
     // When you get the field properties than the leading "*" is stripped
     string[] fields = (string[])fieldsIn.Clone();
     fieldsIn.CopyTo(fields,0);
     HelperFunctions.FieldProperties[] fieldProperties = HelperFunctions.GetProperties(ref fields,isMetric);
     DataTable newTable = new DataTable();
     for (int i=0;i<fields.Length;i++)
     {
         newTable.Columns.Add(fields[i],fieldProperties[i].type);
     }
     for (int i=0;i<table.Rows.Count;i++)
     {
         if (!DataInterface.IsRowAlive(table.Rows[i]))
             continue;
         DataRow targetRow = newTable.NewRow();
         foreach (string fieldName in fields)
         {
             object o = getField(table.Rows[i],isMetric,fieldName);
             targetRow[fieldName] = o;
         }
         newTable.Rows.Add(targetRow);
     }
     DataView view = new DataView(newTable,"",sortingField,
         DataViewRowState.CurrentRows);
     HelperFunctions.UpdateGrid(view,grid,face,isMetric,
         isNewAllowed,isReadOnly,fieldsIn);
 }
Beispiel #2
0
        public static void UpdateGrid(DataView itemTable,
            QuickGrid grid,
            DataGridClientInterface face,bool isKg,
            IsNewAllowed allowNew,
            IsReadOnly readOnly,
            params string[] fieldNames)
        {
            fieldNames = (string[])fieldNames.Clone();
            FieldProperties[] properties = GetProperties(ref fieldNames,isKg);
            int numberOfFields = fieldNames.Length;
            DataTable table = new DataTable();
            for (int i = 0;i<numberOfFields;i++)
            {
                System.Type type = properties[i].type;
                table.Columns.Add(fieldNames[i],type);
            }

            HelperFunctions.DataGridClientBridge bridge = null;
            if (face != null)
                bridge = new DataGridClientBridge(face);

            foreach (DataRowView rowView in itemTable)
            {
                DataRow row = rowView.Row;
                if (!DataInterface.IsRowAlive(row))
                    continue;
                DataRow newRow = table.NewRow();
                for (int i = 0;i<numberOfFields;i++)
                {
                    string fieldName = fieldNames[i];
                    if (!row.IsNull(fieldName) && row[fieldName].GetType() ==
                        typeof(System.DateTime))
                    {
                        DateTime d = (DateTime)row[fieldName];
                        newRow[fieldName] = d.ToShortDateString();
                    }
                    else
                        newRow[fieldName] = row[fieldName];
                }
                table.Rows.Add(newRow);
            }
            table.AcceptChanges();
            grid.ClearAllHandlers();
            ArrayList listOfColumnProperties = new ArrayList();
            for (int i=0;i<properties.Length;i++)
            {
                FieldProperties props = properties[i];
                if (props.isKeyField == true)
                    continue;
                if (IsReadOnly.Yes == readOnly)
                    props.readOnly = true;
                QuickGrid.ColumnProperties coll = new QuickGrid.ColumnProperties();
                switch (props.columnStyle)
                {
                    case ColumnStyle.Text:
                        coll.formatString = props.formatString;
                        break;
                    case ColumnStyle.Date:
                        coll.formatString = "d";
                        grid.AddButtonHandler(i,".",new EventHandler(OnDateClick));
                        break;
                    case ColumnStyle.Item:
                    {
                        if (!props.readOnly)
                        {
                            // since we are not allowing the user
                            // to actually edit the field
                            props.readOnly = true;

                            if (face == null)
                                throw new Exception("Oops, you need a handler for the item clicker");
                            grid.AddButtonHandler(i,".",new EventHandler(bridge.OnItemClick));
                        }
                        break;
                    }
                    default:
                        throw new Exception("Ahh no case statement");
                }
                if (props.columnHeading == "Description")
                {
                    coll.multiline = true;
                    coll.variable = true;
                }
                if (props.columnHeading == "Comments")
                {
                    coll.multiline = true;
                }
                coll.comboBoxValues = props.comboBoxItems;
                coll.heading = props.columnHeading;
                coll.size = props.width;
                coll.alignment = props.alignment;
                coll.readOnly = props.readOnly;
                listOfColumnProperties.Add(coll);
            }
            table.ColumnChanged +=new DataColumnChangeEventHandler(DataGridColumnChanged);
            if (bridge != null)
                table.ColumnChanged +=new DataColumnChangeEventHandler(bridge.DataGridColumnChanged);
            QuickGrid.ColumnProperties[] columnProperties = (QuickGrid.ColumnProperties[])listOfColumnProperties.ToArray
                                                (typeof(QuickGrid.ColumnProperties));
            grid.Setup(table,columnProperties,allowNew==IsNewAllowed.Yes?true:false);
        }