コード例 #1
0
        public CaseModel Func_GetValue_SetValue()
        {
            return(new CaseModel()
            {
                NameSign = @"获取/设置值",
                ExeEvent = () => {
                    GS answer = new GS()
                    {
                        Age = RandomData.GetInt(),
                        DateOfBirth = RandomData.GetDateTime(),
                        Name = RandomData.GetChineseString(),
                        Price = RandomData.GetDouble(),
                        Sex = RandomData.Item(EnumInfo.GetALLItem <GS.SexEnum>()),
                    };

                    GS result = new GS();

                    ShineUponParser parser = new ShineUponParser(typeof(GS));
                    foreach (ShineUponInfo info in parser.GetDictionary().Values)
                    {
                        KeyString ks = parser.GetValue_KeyString(info, answer);
                        parser.SetValue_Object(info, result, ks.Value);
                    }

                    return true;
                },
            });
        }
コード例 #2
0
ファイル: Learn_XML.cs プロジェクト: YellowTulipShow/CSharp
        private XmlNode CreateRandomNode(XmlDocument xmldocument)
        {
            char[] ISBN_Sour = new List <char>(CommonData.ASCII_Number())
            {
                '-'
            }.ToArray();
            char[]     Ascii_words        = CommonData.ASCII_WordText();
            char[]     Ascii_lowerenglish = CommonData.ASCII_LowerEnglish();
            XmlElement book = xmldocument.CreateElement(@"book");
            Dictionary <string, string> Dic_Attrs = new Dictionary <string, string>()
            {
                { @"Type", RandomData.GetChineseString(2) + @"课" },
                { @"ISBN", RandomData.GetString(ISBN_Sour, RandomData.GetInt(4, 13)) }
            };

            foreach (KeyValuePair <string, string> item in Dic_Attrs)
            {
                book.SetAttributeNode(XmlHelper.CreateNewAttribute(xmldocument, item.Key, item.Value));
            }
            Dictionary <string, string> Dic_Nodes = new Dictionary <string, string>()
            {
                { @"title", RandomData.GetString(Ascii_words, RandomData.GetInt(4, 10)) },
                { @"author", RandomData.GetString(Ascii_lowerenglish, RandomData.GetInt(2, 4)) },
                { @"price", RandomData.GetDouble().ToString() },
            };

            foreach (KeyValuePair <string, string> item in Dic_Nodes)
            {
                book.AppendChild(XmlHelper.CreateNewElement(xmldocument, item.Key, item.Value));
            }
            return(book);
        }
コード例 #3
0
        public void InsertData()
        {
            bool result = bllUser.Insert(new ModelUser()
            {
                Email       = RandomData.GetString(RandomData.GetInt(5, 10)),
                TelePhone   = RandomData.GetString(CommonData.ASCII_Number(), 12),
                MobilePhone = RandomData.GetString(CommonData.ASCII_Number(), 11),
                NickName    = RandomData.GetString(CommonData.ASCII_UpperEnglish(), RandomData.GetInt(5, 16)),
                Password    = RandomData.GetString(30),
                RealName    = RandomData.GetChineseString(RandomData.GetInt(2, 4)),
                Remark      = RandomData.GetString(RandomData.GetInt(10, 81)),
                Sex         = RandomData.Item(ConvertTool.EnumForeachArray <ModelUser.SexEnum>()),
                TimeAdd     = RandomData.GetDateTime(),
            });

            Print.WriteLine(result);
        }
コード例 #4
0
 public TestModel[] GetRandomDatas(int rewrite_sum = 0)
 {
     if (rewrite_sum <= 0)
     {
         rewrite_sum = RandomData.GetInt(30, 81);
     }
     TestModel[] array = new TestModel[rewrite_sum];
     for (int i = 0; i < array.Length; i++)
     {
         string name = string.Format("第{0}条 - ", i);
         array[i] = new TestModel()
         {
             RecordIndex = i,
             Age         = RandomData.GetInt(7828, 546822),
             DateOfBirth = RandomData.GetDateTime(SqlDateTime.MinValue.Value, SqlDateTime.MaxValue.Value),
             Name        = name + RandomData.GetChineseString(RandomData.GetInt(3, 5)),
             Sex         = RandomData.Item(EnumInfo.GetALLItem <TestModel.SexEnum>()),
         };
     }
     return(array);
 }
コード例 #5
0
        public CaseModel Func_Insert()
        {
            return(new CaseModel()
            {
                NameSign = @"插入数据",
                ExeEvent = () => {
                    List <TestModel> model_list = new List <TestModel>();
                    int record_count = RandomData.GetInt(10, 51);
                    record_count = 15;
                    for (int i = 0; i < record_count; i++)
                    {
                        model_list.Add(new TestModel()
                        {
                            IID = i,
                            Name = RandomData.GetChineseString(RandomData.GetInt(3, 5)),
                            Sex = RandomData.Item(EnumInfo.GetALLItem <TestModel.SexEnum>()),
                            TimeRelease = RandomData.GetDateTime(SqlDateTime.MinValue.Value, SqlDateTime.MaxValue.Value),
                        });
                    }

                    Func <TestModel, string> get_formatprint = (model) => {
                        return JSON.Serializer(model);
                    };

                    List <string> lines = new List <string>();
                    foreach (TestModel model in model_list)
                    {
                        string text = get_formatprint(model);
                        lines.Add(text);
                    }
                    string abs_file_path = Get_AbsFilePath();
                    File.Delete(abs_file_path);
                    File.Create(abs_file_path).Close();
                    WriterLine(abs_file_path, lines.ToArray());

                    Func_Select().ExeEvent();
                    return true;
                },
            });
        }
コード例 #6
0
        public CaseModel Error_DateTimeType()
        {
            return(new CaseModel()
            {
                NameSign = @"时间类型",
                ExeEvent = () => {
                    DAL_MSSQLServer <TestModel> dal = new DAL_MSSQLServer <TestModel>();
                    TestModel[] array = new TestModel[999];
                    for (int i = 0; i < array.Length; i++)
                    {
                        string name = string.Format("第{0}条 - ", i);
                        array[i] = new TestModel()
                        {
                            RecordIndex = i,
                            Age = RandomData.GetInt(7828, 546822),
                            DateOfBirth = new DateTime(2018, 10, 30, 14, 42, 33, i),
                            Name = name + RandomData.GetChineseString(RandomData.GetInt(3, 5)),
                            Sex = RandomData.Item(EnumInfo.GetALLItem <TestModel.SexEnum>()),
                        };
                    }

                    Console.WriteLine("dal.Delete(null): {0}s", RunHelp.GetRunTime(() => {
                        dal.Delete(null);
                    }));

                    string[] sqls = null;

                    Console.WriteLine("sqls create: {0}s", RunHelp.GetRunTime(() => {
                        sqls = ConvertTool.ListConvertType(array, (model) => dal.SQLInsert(model, false));
                    }));

                    Console.WriteLine("dal.Transaction(sqls): {0}s", RunHelp.GetRunTime(() => {
                        dal.Transaction(sqls);
                    }));

                    //dal.Insert(array);

                    DataTable dt = dal.QueryRecords(0, null, "RecordIndex asc").Tables[0];

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        TestModel a = array[i];
                        DataRow dr = dt.Rows[i];
                        TestModel s = dal.DataRowToModel(dr);

                        if (a.DateOfBirth != s.DateOfBirth)
                        {
                            throw new Exception("错误");
                        }
                    }



                    /*
                     * TestModel[] result = dal.Select(0, null, new KeyBoolean[] {
                     *  new KeyBoolean("RecordIndex", true),
                     * });
                     * VerifyIList<TestModel, TestModel> verify = new VerifyIList<TestModel, TestModel>(CalcWayEnum.SingleCycle) {
                     *  Answer = array,
                     *  Source = result,
                     *  Func_isEquals = (a, s) => {
                     *      if (a.RecordIndex != s.RecordIndex) {
                     *          return false;
                     *      }
                     *      if (a.Age != s.Age) {
                     *          return false;
                     *      }
                     *      if (a.Name != s.Name) {
                     *          return false;
                     *      }
                     *      if (a.Sex != s.Sex) {
                     *          return false;
                     *      }
                     *
                     *      if (a.DateOfBirth != s.DateOfBirth) {
                     *          string a_dt = a.DateOfBirth.ToString(Format.DATETIME_SECOND);
                     *          string s_dt = s.DateOfBirth.ToString(Format.DATETIME_SECOND);
                     *          Console.WriteLine("时间不一致!  a:{0}  s:{1}", a, s);
                     *          throw new Exception("错误");
                     *          return false;
                     *      }
                     *      return true;
                     *  },
                     * };
                     *
                     * bool isby = verify.Calc();
                     * if (!isby) {
                     *  return false;
                     * }
                     */
                    return true;
                },
            });
        }