Advertisement
fruffl

Untitled

Aug 12th, 2011
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Fruffi.Db;
  6. using Fruffi.Db.BrainTableAdapters;
  7. using System.Data;
  8. using System.Data.SqlServerCe;
  9.  
  10. namespace Fruffi.Bot
  11. {
  12.     class Connection
  13.     {
  14.         private SqlCeConnection connection;
  15.         private Db.BrainTableAdapters.remTableAdapter adapter;
  16.         private string dbfile;
  17.         public Connection()
  18.         {
  19.             Fruffi.say("Connect to brain.sdf in the program folder");
  20.            
  21.             this.dbfile = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\Db\\Brain.sdf";
  22.             Fruffi.sayInit(dbfile);
  23.  
  24.             this.connection = new SqlCeConnection("datasource=" + dbfile);
  25.             Fruffi.sayInit(connection);
  26.  
  27.             this.adapter = new Db.BrainTableAdapters.remTableAdapter();
  28.             Fruffi.sayInit(adapter);
  29.  
  30.             Fruffi.say(this.remember("bar"));
  31.             Fruffi.say(this.remember("foo"));
  32.         }
  33.  
  34.  
  35.         public string remember(string rememberTo)
  36.         {
  37.             Brain.remDataTable table = adapter.remember(rememberTo);
  38.             Fruffi.sayInit(table);
  39.  
  40.             int summary = table.Rows.Count;
  41.  
  42.             string result = "";
  43.  
  44.             Random rand = new Random();
  45.             int say = rand.Next(0, summary);
  46.  
  47.             int current = 0;
  48.             foreach (DataRow row in table.Rows)
  49.             {
  50.                 if(say == current)
  51.                     foreach (DataColumn column in table.Columns)
  52.                         if (column.Caption == "say")
  53.                             result = row[column].ToString();
  54.                 current++;
  55.             }
  56.  
  57.             return result;
  58.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement