private Grade AddGrade(string name)
        {
            var newObj = new Grade()
            {
                Name     = name,
                IdParent = _gradeUnallocated
            };

            string sql =
                $"IF (SELECT top 1 Id from [Grade] where Name = @name) IS NULL BEGIN  INSERT INTO Grade (Name, IdParent, IdSource) VALUES (@name,@idParent,@_sourceClipper); SELECT CAST(SCOPE_IDENTITY() as int) END ELSE (SELECT top 1 Id from [Grade] where Name = @name)";

            using (var connection = ConnectionFactory.GetOpenConnection())
            {
                newObj.Id = connection.Query <int>(sql, new { newObj.Name, newObj.IdParent, _sourceClipper }).Single();

                if (GradesList.Select(s => s.Id == newObj.Id).Count() == 0)
                {
                    GradesList.Add(newObj);
                }
            }

            return(newObj);
        }
Exemplo n.º 2
0
 static void AddStudentGrade(double aGrade)
 {
     GradesList.Add(aGrade);
 }
        private static bool LoadData(String fileName)
        {
            bool succeeded = true;

            try
            {
                using (BinaryReader reader = new BinaryReader(new FileStream(fileName, FileMode.Open)))
                {
                    // conversion, lines, grades, abbr, waste min, waste max
                    int listLen = reader.ReadInt32();

                    StringDoubleConversionList.Clear();
                    for (; listLen > 0; --listLen)
                    {
                        String item1 = reader.ReadString();
                        double item2 = reader.ReadDouble();
                        StringDoubleConversionList.Add(new Tuple <string, double>(item1, item2));
                    }

                    //grades and abbr
                    listLen = reader.ReadInt32();
                    GradesList.Clear();
                    GradeAbbrList.Clear();

                    for (; listLen > 0; --listLen)
                    {
                        String grade = reader.ReadString();
                        String abbr  = reader.ReadString();
                        GradesList.Add(grade);
                        GradeAbbrList.Add(abbr);
                    }

                    // lines
                    listLen = reader.ReadInt32();
                    CoatingLines.Clear();
                    for (; listLen > 0; --listLen)
                    {
                        String line = reader.ReadString();
                        CoatingLines.Add(line);
                    }

                    //waste
                    WasteMin     = reader.ReadDouble();
                    WasteMax     = reader.ReadDouble();
                    CurrentWaste = reader.ReadDouble();

                    listLen = reader.ReadInt32();
                    TexturesList.Clear();
                    for (; listLen > 0; --listLen)
                    {
                        TexturesList.Add(Texture.Load(reader));
                    }


                    // WiP Marker
                    WiPMarker = reader.ReadChar();
                }
            }
            catch (Exception)
            {
                succeeded = false;
            }
            if (succeeded)
            {
                _loaded = true;
            }

            return(succeeded);
        }