Exemplo n.º 1
0
 public void SetValues <T>(object obj)
 {
     PropertyInfo[] pis = typeof(T).GetProperties();
     foreach (PropertyInfo pi in pis)
     {
         if (_SFieldDic.ContainsKey(pi.Name))
         {
             SField sField = _SFieldDic[pi.Name];
             object val    = pi.GetValue(obj, null);
             Type   piType = pi.PropertyType;
             if (sField.InputType == SInputType.Int && piType != typeof(int))
             {
                 if (piType == typeof(short))
                 {
                     val = Convert.ToInt32(val);
                 }
                 else if (piType == typeof(long))
                 {
                     val = Convert.ToInt32(val);
                 }
             }
             _SFieldDic[pi.Name].Value = val;
         }
     }
 }
Exemplo n.º 2
0
        public object GetValues <T>()
        {
            Type   type = typeof(T);
            object obj  = (type.GetConstructors()[0].Invoke(null));

            PropertyInfo[] pis = type.GetProperties();
            foreach (PropertyInfo pi in pis)
            {
                if (_SFieldDic.ContainsKey(pi.Name))
                {
                    SField sField = _SFieldDic[pi.Name];
                    Type   piType = pi.PropertyType;
                    object val    = _SFieldDic[pi.Name].Value;
                    if (sField.InputType == SInputType.Int && piType != typeof(int))
                    {
                        if (piType == typeof(short))
                        {
                            val = Convert.ToInt16(val);
                        }
                        else if (piType == typeof(long))
                        {
                            val = Convert.ToInt64(val);
                        }
                    }
                    pi.SetValue(obj, val, null);
                }
            }
            return(obj);
        }
Exemplo n.º 3
0
        private void InitSFieldDic()
        {
            // 获取输入枚举列表
            List <string> enumNameList = new List <string>(typeof(SInputType).GetEnumNames());

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "FormCfg.xml");
            XmlNode node = xmlDoc.SelectSingleNode(string.Format("/Forms/{0}/SFields", _FormName));

            foreach (XmlNode subNode in node.ChildNodes)
            {
                string     name         = subNode.Attributes["Name"].Value;
                bool       hasLabel     = subNode.Attributes["HasLabel"].Value == "true";
                string     strInputType = subNode.Attributes["InputType"].Value;
                object     data         = subNode.Attributes["Data"].Value;
                int        indexEnum    = enumNameList.IndexOf(strInputType);
                SInputType inputType    = (SInputType)indexEnum;

                int startRowIndex = int.Parse(subNode.Attributes["StartRowIndex"].Value);
                int startColIndex = int.Parse(subNode.Attributes["StartColIndex"].Value);
                int rowSpan       = int.Parse(subNode.Attributes["RowSpan"].Value);
                int colSpan       = int.Parse(subNode.Attributes["ColSpan"].Value);

                SField sField = new SField(_FormInfo, name, _SFieldDic.Count, hasLabel, inputType, data);
                sField.StartRowIndex = startRowIndex;
                sField.StartColIndex = startColIndex;
                sField.RowSpan       = rowSpan;
                sField.ColSpan       = colSpan;
                if (hasLabel)
                {
                    sField.Label = subNode.Attributes["Label"].Value;
                }
                _SFieldDic.Add(name, sField);
            }
        }
Exemplo n.º 4
0
        private void InitSFieldList()
        {
            //SField sField = new SField("image", _SFieldList.Count, false, SInputType.Image,
            //    Image.FromFile(@"D:\Documents\Pictures\bao\yan.png"));
            //sField.StartRowIndex = 0;
            //sField.StartColIndex = 0;
            //sField.RowSpan = 8;
            //sField.ColSpan = 2;
            //_SFieldList.Add(sField);

            ////        SField sField2 = new SField("image", _SFieldList.Count, false, SInputType.Image,
            ////Image.FromFile(@"D:\Documents\Pictures\bao\yellow.png"));
            ////        sField2.StartRowIndex = 0;
            ////        sField2.StartColIndex = 1;
            ////        sField2.RowSpan = 8;
            ////        sField2.ColSpan = 1;
            ////        _SFieldList.Add(sField2);


            //SField sField3 = new SField("姓名", _SFieldList.Count, true, SInputType.String, "小白");
            //sField3.LabelCtrl.Text = "姓名:";
            //sField3.StartRowIndex = 0;
            //sField3.StartColIndex = 2;
            //sField3.RowSpan = 2;
            //sField3.ColSpan = 1;
            //_SFieldList.Add(sField3);


            //SField sField4 = new SField("年龄", _SFieldList.Count, true, SInputType.Decimal, "22");
            //sField4.LabelCtrl.Text = "年龄:";
            //sField4.StartRowIndex = 2;
            //sField4.StartColIndex = 2;
            //sField4.RowSpan = 2;
            //sField4.ColSpan = 1;
            //_SFieldList.Add(sField4);

            //SField sField5 = new SField("性别", _SFieldList.Count, true, SInputType.Combo, new List<string>() { "男", "女" });
            //sField5.LabelCtrl.Text = "性别:";
            //sField5.StartRowIndex = 4;
            //sField5.StartColIndex = 2;
            //sField5.RowSpan = 2;
            //sField5.ColSpan = 1;
            //_SFieldList.Add(sField5);

            //SField sField6 = new SField("生日", _SFieldList.Count, true, SInputType.Date, "1991-02-12");
            //sField6.LabelCtrl.Text = "生日:";
            //sField6.StartRowIndex = 6;
            //sField6.StartColIndex = 2;
            //sField6.RowSpan = 2;
            //sField6.ColSpan = 1;
            //_SFieldList.Add(sField6);

            //SField sField7 = new SField("简介", _SFieldList.Count, true, SInputType.MultiLine, "因为前几年工作当中接触过一些计算机图形方面的基础内容,所以平时闲暇之余对于游戏开发也就有些好奇。年前听说Milo Yip翻译的新书《游戏引擎架构》要上市了,所以就有心想买来一读,满足一下好奇心。除此之外,出于敬仰译者在对待技术方面的严谨态度,除了拜读以外,也希望能够收藏此书。 上上周的周末,拿到了此书,接下来花了一个多星期的时间通读了一遍。因为自己并不是做游戏开发的,所以这里只是谈一谈自己的阅读感.");
            //sField7.LabelCtrl.Text = "简介:";
            //sField7.StartRowIndex = 8;
            //sField7.StartColIndex = 0;
            //sField7.RowSpan = 3;
            //sField7.ColSpan = 3;
            //_SFieldList.Add(sField7);


            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(AppDomain.CurrentDomain.BaseDirectory + "FormCfg.xml");
            XmlNode node = xmlDoc.SelectSingleNode(string.Format("/Forms/{0}/SFields", _FormName));

            foreach (XmlNode subNode in node.ChildNodes)
            {
                string     name         = subNode.Attributes["Name"].Value;
                bool       hasLabel     = subNode.Attributes["HasLabel"].Value == "true";
                string     strInputType = subNode.Attributes["InputType"].Value;
                object     data         = subNode.Attributes["Data"].Value;
                SInputType inputType;
                switch (strInputType)
                {
                default:
                case "String":
                    inputType = SInputType.String;
                    break;

                case "MultiLine":
                    inputType = SInputType.MultiLine;
                    break;

                case "Decimal":
                    inputType = SInputType.Decimal;
                    break;

                case "Date":
                    inputType = SInputType.Date;
                    break;

                case "Combo":
                    inputType = SInputType.Combo;
                    data      = data.ToString().Split(';');
                    break;

                case "Image":
                    inputType = SInputType.Image;
                    break;
                }
                int startRowIndex = int.Parse(subNode.Attributes["StartRowIndex"].Value);
                int startColIndex = int.Parse(subNode.Attributes["StartColIndex"].Value);
                int rowSpan       = int.Parse(subNode.Attributes["RowSpan"].Value);
                int colSpan       = int.Parse(subNode.Attributes["ColSpan"].Value);

                SField sField = new SField(_FormInfo, name, _SFieldList.Count, hasLabel, inputType, data);
                sField.StartRowIndex = startRowIndex;
                sField.StartColIndex = startColIndex;
                sField.RowSpan       = rowSpan;
                sField.ColSpan       = colSpan;
                if (hasLabel)
                {
                    sField.Label = subNode.Attributes["Label"].Value;
                }
                _SFieldList.Add(sField);
            }
        }