public static string requestNextAvailableTrain(string jobID, string userID)
        {
            TaskRecord    tr     = new TaskRecord();
            List <object> oblist = RTDB.selectObList("SELECT * FROM TaskRecord WHERE JobID='" + jobID + "'" + " AND TrainCount < MaxTrains", tr, "TrainTasker");
            TrainRecord   trn    = new TrainRecord();

            for (int i = 0; i < oblist.Count; ++i)
            {
                tr  = (TaskRecord)oblist[i];
                trn = (TrainRecord)trn.selectOb("WHERE UserID='" + userID + "'" + " AND TaskRecordID = " + tr.ID);
                if (trn == null)
                {
                    trn = new TrainRecord();
                    trn.ResourcePath = tr.ResourcePath;
                    trn.TaskRecordID = tr.ID;
                    trn.RequesterID  = tr.RequesterID;
                    trn.JobID        = tr.JobID;
                    string s = trn.serialize();
                    s = s.Replace("1/1/1800 12:00:00 AM", "");
                    s = s.Replace("\\", "/");  // \ breaks client json
                    return(s);
                }
            }
            return("Error: No Train available");
        }
Beispiel #2
0
        public static object selectValue(string sql, string database)
        {
            List <List <object> > list = RTDB.lowSelectObs(sql, database);

            if (list.Count == 0)
            {
                return(null);
            }
            return(list[2][0]);
        }
Beispiel #3
0
        public void deleteFromTable()
        {
            Type   type      = this.GetType();
            string tableName = type.Name.Replace(getNameSpace() + ".", "");

            try
            {
                RTDB.deleteFromTable(tableName, "WHERE ID=" + this.ID.ToString(), database);
            }
            catch (Exception err) { }
        }
        public static string getTrainResultsPerTask(string taskID)
        {
            List <object> oblist = RTDB.selectObList("SELECT * FROM TrainRecord WHERE TaskID=" + taskID, new TrainRecord(), "TrainTasker");
            string        s      = "";

            for (int i = 0; i < oblist.Count; ++i)
            {
                if (i > 0)
                {
                    s += ",";
                }
                TrainRecord tr = (TrainRecord)oblist[i];
                s += tr.serialize();
            }
            return(s);
        }
Beispiel #5
0
        //string serializeActiveJobs()
        //{
        //    string s = "";
        //    for (int i = 0; i < activeJobs.Count; ++i)
        //    {
        //        Job job = activeJobs[i];
        //        if (job.start < DateTime.Now && job.end > DateTime.Now && job.active)
        //        {
        //            string js = job.serialize();
        //            if (s != "") s += ",";
        //            s += js;
        //        }
        //    }
        //    s = "{" + s + "}";
        //    return s;

        //}

        public string getAllJobs()
        {
            List <object> oblist = RTDB.selectObList("SELECT * FROM JobRecord", new JobRecord(), "TrainTasker");

            string s = "";

            for (int i = 0; i < oblist.Count; ++i)
            {
                JobRecord job = (JobRecord)oblist[i];
                if (i > 0)
                {
                    s += ",";
                }
                s += job.serialize();
            }
            return("{" + s + "}");
        }
Beispiel #6
0
        public string getUserJobs(string userID)
        {
            List <object> oblist = RTDB.selectObList("SELECT * FROM JobRecord WHERE userID= '" + userID + "'", new JobRecord(), "TrainTasker");

            string s = "";

            for (int i = 0; i < oblist.Count; ++i)
            {
                JobRecord job = (JobRecord)oblist[i];
                if (i > 0)
                {
                    s += ",";
                }
                s += job.serialize();
            }
            return("[" + s + "]");
        }
Beispiel #7
0
        public static decimal selectDecimal(string sql, string database)
        {
            List <List <string> > list = RTDB.lowSelect(sql, database);

            if (list.Count < 2)
            {
                return(0);
            }
            string s = list[1][0];

            try
            {
                return(decimal.Parse(s));
            }
            catch (Exception err)
            {
                return(0M);
            }
        }
Beispiel #8
0
        public int updateOb(string sql)
        {
            Type      type      = this.GetType();
            string    tableName = type.Name.Replace(getNameSpace() + ".", "");
            Hashtable h         = new Hashtable();

            foreach (FieldInfo prop in this.GetType().GetFields())
            {
                string name = prop.Name;
                if (name != "ID")
                {
                    object value = prop.GetValue(this);
                    h.Add(name, value);
                }
            }
            int rows = RTDB.updateTable(tableName, h, "WHERE [ID] = " + this.ID.ToString(), database);

            return(rows);
        }
Beispiel #9
0
        public static int selectInt(string sql, string database)
        {
            List <List <string> > list = RTDB.lowSelect(sql, database);

            if (list.Count < 2)
            {
                return(0);
            }
            string s = list[1][0];

            try
            {
                decimal d = decimal.Parse(s);
                return((int)d);
            }
            catch (Exception err)
            {
                return(0);
            }
        }
Beispiel #10
0
        public void insertOb()
        {
            Type      type      = this.GetType();
            string    tableName = type.Name.Replace(getNameSpace() + ".", "");
            Hashtable h         = new Hashtable();

            foreach (FieldInfo prop in this.GetType().GetFields())
            {
                string name = prop.Name;
                if (name != "ID")
                {
                    object value = prop.GetValue(this);
                    h.Add(name, value);
                }
            }
            int rows = RTDB.insertIntoTable(tableName, h, database);

            if (rows > 0)
            {
                selectOb();  // populate ID from db.
            }
        }
Beispiel #11
0
        public static string getTaskIDsPerJob(string jobID)
        {
            List <int>    list   = new List <int>();
            List <object> oblist = RTDB.selectObList("SELECT * FROM TrainRecord WHERE JobID=" + jobID, new TrainRecord(), "TrainTasker");
            string        s      = "";

            for (int i = 0; i < oblist.Count; ++i)
            {
                TrainRecord tr = (TrainRecord)oblist[i];
                if (!list.Contains(tr.TaskRecordID))
                {
                    if (s != "")
                    {
                        s += ",";
                    }
                    s += tr.serialize();
                    list.Add(tr.TaskRecordID);
                }
            }

            return("[" + s + "]");
        }
Beispiel #12
0
        public object select(string sql)
        {
            Type type = this.GetType();


            List <List <object> > table = RTDB.lowSelectObs(sql, database);

            if (table.Count == 0)
            {
                return(null);
            }
            if (table.Count == 1)
            {
                var wtf = true;
                return(null);
            }
            List <string> names = new List <string>();

            for (int i = 0; i < table[0].Count; ++i)
            {
                names.Add(table[0][i] as string);
            }

            FieldInfo[] fields = this.GetType().GetFields();

            for (int i = 0; i < fields.Length; ++i)
            //foreach (FieldInfo prop in this.GetType().GetFields())
            {
                FieldInfo prop = fields[i];
                type = Nullable.GetUnderlyingType(prop.FieldType) ?? prop.FieldType;
                string name  = prop.Name;
                int    index = names.IndexOf(name);
                object value = table[2][index];
                if (type.Name == "String")
                {
                    if (value == null)
                    {
                        value = "";
                    }
                    if (value.GetType().Name == "DBNull")
                    {
                        value = "";
                    }
                }
                if (type.Name == "Bool" || type.Name == "Boolean")
                {
                    if (value == null)
                    {
                        value = false;
                    }
                    if (value.GetType().Name == "DBNull")
                    {
                        value = false;
                    }
                    if (value.ToString().Contains("1"))
                    {
                        value = true;
                    }
                    if (value.ToString().Contains("0"))
                    {
                        value = false;
                    }
                }
                if (type.Name == "DateTime" || type.Name == "DateTime")
                {
                    try
                    {
                        value = parseDateTime(value as string);
                    }
                    catch (Exception err)
                    {
                        value = new DateTime(1899, 1, 1);
                    }
                }
                if (type.Name != value.GetType().Name)
                {
                    var wtf = value.GetType().Name;
                }
                else
                {
                    prop.SetValue(this, value);
                }
            }
            return(this);
        }