Exemplo n.º 1
0
        // Constructor, currently fetches all current data every time ... later may try to cache some in Session etc.
        public HumansController()
        {
            config = new cConfig();
            gcs    = config.GetConnectionString();

            SqlConnection  db_conn;
            SqlCommand     db_cmd = new SqlCommand();
            SqlDataAdapter db_adapter;

            ds = new DataSet();

            humans = new List <Human>();

            try
            {
                String cs = gcs;
                db_conn = new SqlConnection(cs);
                db_conn.Open();
                db_cmd.Connection  = db_conn;
                db_cmd.CommandType = CommandType.StoredProcedure;
                db_cmd.CommandText = "[Humans].[GetAllHumanData]";
                db_cmd.Parameters.Clear();
                db_adapter = new SqlDataAdapter(db_cmd);
                db_adapter.TableMappings.Clear();
                db_adapter.TableMappings.Add("Table", "Humans");
                db_adapter.TableMappings.Add("Table1", "Children");
                db_adapter.Fill(ds);
            }
            catch (Exception theError)
            {
                throw new Exception("DB Lookup failed", theError);
            }

            int theCount = ds.Tables["Humans"].Rows.Count;

            if (theCount != 0)
            {
                int ndx, lastNdx;
                lastNdx = theCount - 1;
                for (ndx = 0; ndx <= lastNdx; ndx++)
                {
                    humans.Add(buildHumanObjectFromData(ndx));
                }
            }
        }
Exemplo n.º 2
0
 public void LoadConfig()
 {
     if (!File.Exists("config.json"))
     {
         NewConfig();
     }
     else
     {
         try
         {
             Config = JsonConvert.DeserializeObject <cConfig>(File.ReadAllText("config.json"));
         }
         catch
         {
             NewConfig();
         }
     }
     if (Config == null || Config.MaxItens > 10)
     {
         NewConfig();
     }
 }
Exemplo n.º 3
0
 public void NewConfig()
 {
     Config = new cConfig();
     File.WriteAllText("config.json", JsonConvert.SerializeObject(Config));
 }