Пример #1
0
        private async void SaveBtn_Click(object sender, RoutedEventArgs e)
        {
            var  obj  = iS3Property.GetInstance(_domain, _objType);
            Type type = iS3Property.GetType(_domain, _objType);

            foreach (PropertyDef def in _propertyDefs)
            {
                PropertyInfo info = type.GetProperty(def.key); //获取指定名称的属性
                if (TBDict.ContainsKey(def.id))
                {
                    string value = TBDict[def.id].Text.ToString();
                    if (!info.PropertyType.IsGenericType)
                    {
                        //非泛型
                        info.SetValue(obj, string.IsNullOrEmpty(value) ? null : Convert.ChangeType(value, info.PropertyType), null);
                    }
                    else
                    {
                        //泛型Nullable<>
                        Type genericTypeDefinition = info.PropertyType.GetGenericTypeDefinition();
                        if (genericTypeDefinition == typeof(Nullable <>))
                        {
                            info.SetValue(obj, string.IsNullOrEmpty(value) ? null : Convert.ChangeType(value, Nullable.GetUnderlyingType(info.PropertyType)), null);
                        }
                    }
                }
            }
            DGObject _obj = await RepositoryForClient.Create(obj as DGObject, _domain, _objType);

            if (DGObjectHandler != null)
            {
                DGObjectHandler(this, _obj);
            }
            this.Close();
        }
Пример #2
0
        private async void OpenCSVFile(string filepath)
        {
            string strpath = filepath; //csv文件的路径

            try
            {
                int  intColCount = 0;
                bool blnFlag     = true;

                string                   strline;
                string[]                 aryline;
                StreamReader             mysr          = new StreamReader(strpath, System.Text.Encoding.Default);
                Dictionary <string, int> Propertyindex = new Dictionary <string, int>();
                while ((strline = mysr.ReadLine()) != null)
                {
                    aryline     = strline.Split(new char[] { ',' });
                    intColCount = aryline.Length;

                    //给属性建立索引,可以根据属性名找到对应的列
                    if (blnFlag)
                    {
                        blnFlag = false;
                        for (int i = 0; i < aryline.Length; i++)
                        {
                            Propertyindex[aryline[i]] = i;
                        }
                    }
                    else
                    {
                        var  obj  = iS3Property.GetInstance(_domain, _objType);
                        Type type = iS3Property.GetType(_domain, _objType);
                        foreach (PropertyDef def in _propertyDefs)
                        {
                            PropertyInfo info = type.GetProperty(def.key); //获取指定名称的属性
                            if (Propertyindex.ContainsKey(def.key))
                            {
                                var value = aryline[Propertyindex[def.key]];
                                if (!info.PropertyType.IsGenericType)
                                {
                                    //非泛型
                                    info.SetValue(obj, string.IsNullOrEmpty(value) ? null : Convert.ChangeType(value, info.PropertyType), null);
                                }
                                else
                                {
                                    //泛型Nullable<>
                                    Type genericTypeDefinition = info.PropertyType.GetGenericTypeDefinition();
                                    if (genericTypeDefinition == typeof(Nullable <>))
                                    {
                                        info.SetValue(obj, string.IsNullOrEmpty(value) ? null : Convert.ChangeType(value, Nullable.GetUnderlyingType(info.PropertyType)), null);
                                    }
                                }
                            }
                        }
                        DGObject _obj = await RepositoryForClient.Create(obj as DGObject, _domain, _objType);

                        if (DGObjectHandler != null)
                        {
                            DGObjectHandler(this, _obj);
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Пример #3
0
        private async void SaveChangeBT_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                TreeNode node = LYTunnelTreeview.SelectedItem as TreeNode;
                if ((node == null) || (node.Level != 2))
                {
                    return;
                }
                if (newdatatable == null)
                {
                    return;
                }


                DGObjectDef objectDef = LYTunnelStandard.GetDGObjectDefByName(newdatatable.TableName);
                StageDef    _domain   = LYTunnelStandard.GetStageDefByName(newdatatable.TableName);
                if ((objectDef == null) || (_domain == null))
                {
                    MessageBox.Show("检查数据标准表!");
                    return;
                }

                var                         obj            = iS3Property.GetInstance(_domain.Code, objectDef.Code);
                Type                        _type          = iS3Property.GetType(_domain.Code, objectDef.Code);
                MethodInfo                  mi             = typeof(iS3Property).GetMethod("GetProperty").MakeGenericMethod(_type);
                List <PropertyDef>          _propertyDefs  = mi.Invoke(new iS3Property(), new object[] { Activator.CreateInstance(_type) }) as List <PropertyDef>;
                Dictionary <string, object> Property2Value = new Dictionary <string, object>();

                foreach (DataRow row in newdatatable.Rows)
                {
                    foreach (PropertyMeta meta in objectDef.PropertyContainer)
                    {
                        Property2Value[meta.PropertyName] = row[meta.LangStr];
                        if (Property2Value[meta.PropertyName].ToString() == "")
                        {
                            Property2Value[meta.PropertyName] = null;
                        }
                    }
                    foreach (PropertyDef def in _propertyDefs)
                    {
                        PropertyInfo info = _type.GetProperty(def.key); //获取指定名称的属性
                        if (Property2Value.ContainsKey(def.key))
                        {
                            var value = Property2Value[def.key];
                            if (!info.PropertyType.IsGenericType)
                            {
                                //非泛型
                                info.SetValue(obj, (value != null) ? Convert.ChangeType(value, info.PropertyType) : null);
                            }
                            else
                            {
                                //泛型Nullable<>
                                Type genericTypeDefinition = info.PropertyType.GetGenericTypeDefinition();
                                if (genericTypeDefinition == typeof(Nullable <>))
                                {
                                    info.SetValue(obj, (value != null) ? Convert.ChangeType(value, Nullable.GetUnderlyingType(info.PropertyType)) : null);
                                }
                            }
                        }
                    }
                    DGObject _obj = await RepositoryForClient.Create(obj as DGObject, _domain.Code, objectDef.Code);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            System.Windows.MessageBox.Show("数据已存储至数据库"); //Data has been stored to DataBase!
            DataTemplateTreeview_SelectedItemChanged(this, new RoutedEventArgs());
            newdatatable = null;
        }