当前位置: 首页>>代码示例>>C#>>正文


C# List.FindAll方法代码示例

本文整理汇总了C#中Novacode.List.FindAll方法的典型用法代码示例。如果您正苦于以下问题:C# List.FindAll方法的具体用法?C# List.FindAll怎么用?C# List.FindAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Novacode.List的用法示例。


在下文中一共展示了List.FindAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConvertTermYearToTermId

        /**
         * Convert Term + Year to TermID. If Term + Year did not exist in databse. Will be create in database.
         * @para: Term, Year
         * @return: TermID
         */
        public bool ConvertTermYearToTermId(int Term, int Year, ref int TermID)
        {
            /*
             * Read TermTable from SQL to local variable for process
             * TODO: Need enhanced work directly with database
             */
            var m_TermDatabase = new List<TermDatabase>();
            cmd.CommandText = @"SELECT * FROM TermTable ORDER BY TermID";
            try
            {
                connection.Open();
                reader = cmd.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        m_TermDatabase.Add(new TermDatabase((int) reader[0],(int) reader[1], (int) reader[2]));
                    }
                }
                connection.Close();
            }
            catch (Exception exception)
            {
                connection.Close();
                MessageBox.Show(@"Message: " + exception.ToString(), @"Error", MessageBoxButtons.OK,
                    MessageBoxIcon.Error);
                return false;
                throw;
            }
            /*
             * - Check in list and add to database if need.
             */
            var TermFind = (m_TermDatabase.FindAll(x => x.Year == Year)).Find(y => y.Term == Term);
            if (TermFind != null)
            {
                TermID = TermFind.TermID;
                return true;
            }
            /*
             * Term && Year did not exist in database. Add new Term to database. Begin from last Term in databas
             * Example: In database contain Term 2 Year 2015. So new Term is 1 Year 2016. We should add Term from 3 Year 2015 to Term 1 Year 2016
             * Add: (3,2015), (4,2015), (5,2015), (6,2015), (1,2016).
             * If there is the first Term on database. We should add Term from Term 1 in this Year
             * TermID have format: YearTerm. For Example: 20161 is Term 1 in 2016
             */
            if (m_TermDatabase.IsEmpty())
            {
                connection.Open();
                for (var i = 1; i <= Term; ++i)
                {
                    cmd.CommandText = string.Format(@"INSERT INTO TermTable VALUES({0}, {1}, {2})", Year*10 + i, i, Year);
                    try
                    {

                        cmd.ExecuteNonQuery();
                    }
                    catch (Exception exception)
                    {
                        connection.Close();
                        MessageBox.Show(@"Message: " + exception.ToString(), @"Error", MessageBoxButtons.OK,
                            MessageBoxIcon.Error);
                        throw;
                    }
                }
                connection.Close();
            }
            else
            {
                connection.Open();
                var lastYear = Convert.ToInt32(m_TermDatabase.Last().Year);
                var firstYear = Convert.ToInt32(m_TermDatabase.First().Year);
                var firstTermFirstYear = m_TermDatabase.First().Term;
                var lastTermLastYear = m_TermDatabase.Last().Term + 1;
                if (lastYear <= Year)
                {
                    for (; lastYear <= Year; ++lastYear)
                    {
                        if (lastTermLastYear > 6)
                            lastTermLastYear = 1;
                        var tempTerm = lastYear < Year ? 6 : Term;
                        for (; lastTermLastYear <= tempTerm; ++lastTermLastYear)
                        {
                            if (Equals(lastYear, Year) && Equals(lastTermLastYear == Term))
                                TermID = lastYear * 10 + lastTermLastYear;
                            cmd.CommandText = string.Format(@"INSERT INTO TermTable VALUES({0}, {1}, {2})", lastYear * 10 + lastTermLastYear, lastTermLastYear,
                                lastYear);
                            try
                            {

                                cmd.ExecuteNonQuery();
                            }
                            catch (Exception exception)
                            {
                                connection.Close();
                                MessageBox.Show(@"Message: " + exception.ToString(), @"Error", MessageBoxButtons.OK,
//.........这里部分代码省略.........
开发者ID:thanhtanpc,项目名称:MusicalManager,代码行数:101,代码来源:AddScore.cs


注:本文中的Novacode.List.FindAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。