Exemple #1
0
 public static ItemFieldData[] getItemFieldData(string fieldName, string child, string parent)
 {
     ArrayList list = new ArrayList();
     string filePath = AppDomain.CurrentDomain.BaseDirectory + "\\Data\\" + fieldName + child + ".txt";
     if (File.Exists(filePath))
     {
         try
         {
             StreamReader sr = new StreamReader(filePath);
             string line = null;
             while ((line = sr.ReadLine()) != null)
             {
                 int pos = line.IndexOf(',');
                 if (pos > 0)
                 {
                     string value = line.Substring(0, pos);
                     string name = line.Substring(pos + 1, line.Length - pos - 1);
                     ItemFieldData data = new ItemFieldData();
                     data.Name = name;
                     data.Value = value;
                     data.Parent = parent;
                     list.Add(data);
                 }
             }
         }
         catch (Exception e)
         {
             log.error("读取配置文件出错" + filePath);
             log.error(e);
         }
     }
     return (ItemFieldData[])list.ToArray(typeof(ItemFieldData));
 }
        void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox      cb       = sender as ComboBox;
            ItemFieldData data     = cb.SelectedItem as ItemFieldData;
            ItemProperty  pro      = null;
            ItemProperty  proChild = null;

            foreach (ItemProperty p in this.properties)
            {
                if (cb.Name.Substring(cb.Name.IndexOf('_') + 1).ToLower() == p.Name.ToLower())
                {
                    pro = p;
                    break;
                }
            }
            foreach (ItemProperty p in this.properties)
            {
                if (pro.Child == p.Name)
                {
                    proChild = p;
                    break;
                }
            }
            if (data == null || pro == null || proChild == null || pro.Child == null || pro.Child.Trim().Length == 0)
            {
                return;
            }
            foreach (UIElement element in this.mainGrid.Children)
            {
                ComboBox cbChild = element as ComboBox;
                if (cbChild != null && cbChild.Name.ToLower() == "cb_" + proChild.Name.ToLower())
                {
                    cbChild.ItemsSource   = Configuration.getItemFieldData(pro.Child.ToLower(), data.Value, pro.Name);
                    cbChild.SelectedValue = proChild.Value;
                }
            }
        }
Exemple #3
0
        public static DataTable Items2DataTable(Item[] items)
        {
            DataTable dt = new DataTable();

            if (items != null && items.Length > 0)
            {
                Dictionary <string, ItemFieldData[]> dic_itemfields = new Dictionary <string, ItemFieldData[]>();
                ItemProperty[] properties = items[0].Properties;
                foreach (ItemProperty p in properties)
                {
                    DataColumn c = new DataColumn();
                    c.ColumnName = p.Name;
                    c.Caption    = p.DisplayName;
                    c.DataType   = p.ValueType == null ? typeof(String) : p.ValueType;
                    dt.Columns.Add(c);
                    string fieldName = p.Name;
                    if (p.Data != null && p.Data.Trim() != string.Empty)
                    {
                        fieldName = p.Data;
                    }
                    if (dic_itemfields.ContainsKey(fieldName))
                    {
                        c.DataType = typeof(String);
                        continue;
                    }
                    ItemFieldData[] fieldData = Configuration.getItemFieldData(fieldName);
                    if (fieldData.Length > 0)
                    {
                        dic_itemfields.Add(fieldName, fieldData);
                        c.DataType = typeof(String);
                    }
                }
                DataColumn clm_edit = new DataColumn("editColumn");
                dt.Columns.Add(clm_edit);
                DataColumn clm_del = new DataColumn("delColumn");
                dt.Columns.Add(clm_del);
                foreach (Item item in items)
                {
                    ItemProperty[] arr_p = item.Properties;
                    object[]       objs  = new object[arr_p.Length + 2];
                    for (int i = 0; i < arr_p.Length; i++)
                    {
                        ItemProperty p         = arr_p[i];
                        string       fieldName = p.Name;
                        string       value     = p.Value;
                        if (p.Data != null && p.Data.Trim() != string.Empty)
                        {
                            fieldName = p.Data;
                        }
                        if (p.Parent != null && p.Parent.Trim() != string.Empty)
                        {
                            ItemProperty pp = item.getProperty(p.Parent);
                            if (pp != null)
                            {
                                fieldName += pp.Value;
                                if (!dic_itemfields.ContainsKey(fieldName))
                                {
                                    ItemFieldData[] fieldData = Configuration.getItemFieldData(fieldName);
                                    if (fieldData.Length > 0)
                                    {
                                        dic_itemfields.Add(fieldName, fieldData);
                                        dt.Columns[i].DataType = typeof(String);
                                    }
                                }
                                else
                                {
                                    dt.Columns[i].DataType = typeof(String);
                                }
                            }
                        }

                        if (dic_itemfields.ContainsKey(fieldName))
                        {
                            ItemFieldData data = getFieldDataByValue(value, dic_itemfields[fieldName]);
                            if (data != null && data.Value != null && data.Value.Trim() != string.Empty)
                            {
                                value = data.Name;
                            }
                        }
                        objs[i] = value;
                    }
                    objs[objs.Length - 2] = "修改";
                    objs[objs.Length - 1] = "删除";
                    dt.Rows.Add(objs);
                }
            }
            return(dt);
        }