Пример #1
0
 //
 // DEFAULT BADGES
 //
 public static void CreateDefaultBadge(DefaultBadge badge)
 {
     using (IDbConnection conn = new SqlConnection(Connection))
     {
         string sql = "INSERT INTO DEFAULT_BADGES (badge_id, badge_type, tree_loc_x, tree_loc_y)" +
                      "VALUES (@BadgeId, @Type, @TreeLocX, @TreeLocY);";
         conn.Query(sql, badge);
     }
 }
Пример #2
0
        public static void UpdateDefaultBadge(DefaultBadge badge)
        {
            using (IDbConnection conn = new SqlConnection(Connection))
            {
                string sql = "UPDATE DEFAULT_BADGES SET tree_loc_x = @TreeLocX, tree_loc_y = @TreeLocY badge_type @Type " +
                             "WHERE badge_id = @BadgeId;";

                conn.Query(sql, badge);
            }
        }
Пример #3
0
        public static DefaultBadge GetDefaultBadge(int?BadgeId)
        {
            using (IDbConnection conn = new SqlConnection(Connection))
            {
                string sql = "SELECT badge_id BadgeId, tree_loc_x TreeLocX, tree_loc_y TreeLocY, badge_type Type " +
                             "FROM DEAFULT_BADGES WHERE badge_id = @BadgeId;";

                DefaultBadge badge = conn.Query <DefaultBadge>(sql,
                                                               new
                {
                    BadgeId
                }).FirstOrDefault();

                return(badge);
            }
        }
Пример #4
0
        }// end input user list

        ////////////////////////////////////////////////////////
        // Reads a CSV containing badges into the database
        // format should be in type,retire,start,name,self,student,staff,faculty order
        ////////////////////////////////////////////////////////
        public void InputBadgeList(string choice)
        {
            StreamReader file;
            string       fileName;
            string       line;
            int          lineNumber = 0;

            //Console.WriteLine("Input the file name path: ");
            //fileName = Console.ReadLine();

            fileName = choice + "\\BadgeBank.csv";

            if (File.Exists(fileName))
            {
                file = new StreamReader(fileName);

                while ((line = file.ReadLine()) != null)
                {
                    lineNumber++;
                    string[] words     = line.Split(',');
                    Badge    tempBadge = new Badge();


                    if (words.Length >= 10)
                    {
                        switch (words[0])
                        {
                        case "comendation":
                            tempBadge.Type = BadgeType.Leaf;
                            break;

                        case "competency":
                            tempBadge.Type = BadgeType.Flower;
                            break;

                        case "core":
                            tempBadge.Type = BadgeType.Apple;
                            break;

                        default:
                            throw new InvalidDataException("Invalid badge type on line: " + line);
                        }

                        if (words[1].Length >= 6) // min length of a datetime x/x/xx
                        {
                            tempBadge.RetirementDate = DateTime.Parse(words[1]);
                        }
                        else
                        {
                            // The maximum datetime for the database
                            // This will indicate that the badge has no retirement date
                            //when the field is blank in the .csv
                            // The database can accept null values in retirement date
                            tempBadge.RetirementDate = DateTime.Parse("12/31/9999");
                        }

                        tempBadge.BeginDate   = DateTime.Parse(words[2]);
                        tempBadge.Name        = words[3];
                        tempBadge.SelfGive    = (words[4] == "true" || words[4] == "True" || words[4] == "T");
                        tempBadge.StudentGive = (words[5] == "true" || words[5] == "True" || words[5] == "T");
                        tempBadge.StaffGive   = (words[6] == "true" || words[6] == "True" || words[6] == "T");
                        tempBadge.FacultyGive = (words[7] == "true" || words[7] == "True" || words[7] == "T");
                        tempBadge.Picture     = words[8];
                        tempBadge.Description = words[9];

                        int id = Db.Db.CreateBadge(tempBadge);

                        if (!string.IsNullOrEmpty(words[10]) && !string.IsNullOrEmpty(words[11]))
                        {
                            DefaultBadge tempDefaultBadge = new DefaultBadge();
                            int          treeLocX;
                            int          treeLocY;
                            int.TryParse(words[10], out treeLocX);
                            int.TryParse(words[11], out treeLocY);

                            tempDefaultBadge.BadgeId  = id;
                            tempDefaultBadge.TreeLocX = treeLocX;
                            tempDefaultBadge.TreeLocY = treeLocY;
                            tempDefaultBadge.Type     = tempBadge.Type;

                            Db.Db.CreateDefaultBadge(tempDefaultBadge);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Formatting error line " + lineNumber);
                    } // end if(words.length)
                }     // end while (!= eof)

                Console.WriteLine("Badge database filled");
                file.Close();
            }
            else
            {
                Console.WriteLine("File name incorrect/does not exist!\n");
            }
        } // end input badge list