Example #1
0
        public static List<Operation> GetMachines()
        {
            Database db = new Database("SELECT * FROM [machines]");
            List<Dictionary<string,object>> dataList = db.Fetch();
            if(dataList != null)
            {
                List<Operation> result = new List<Operation> { };
                foreach(Dictionary<string, object> item in dataList)
                {
                    int id = (int)item["id"];
                    int duration = (int)item["duration"];
                    int number = (int)item["amount"];
                    string name = (string)item["name"];
                    result.Add(new Operation(id, name, duration, number));
                }

                if(result.Count != 0)
                {
                    return result;
                }
                else
                {
                    return null;
                }
            }
            else
            {
                return null;
            }
        }
Example #2
0
 public static List<Item> GetItems()
 {
     try
     {
         Database db = new Database("SELECT * FROM [items]");
         List<Dictionary<string, object>> datalist = db.Fetch();
         if (datalist != null)
         {
             List<Item> items = new List<Item> { };
             foreach (Dictionary<string, object> data in datalist)
             {
                 int id = (int)data["id"];
                 int num = (int)data["inStock"];
                 string name = (string)data["name"];
                 items.Add(new Item(id, name, num));
             }
             return items;
         }
         else
         {
             return null;
         }
     }
     catch(Exception exc)
     {
         Log.Record(exc);
         return null;
     }
 }
Example #3
0
        public static List<Order> GetWorkLine()
        {
            Database db = new Database("SELECT * FROM [viewWorkLine]");
            List<Dictionary<string, object>> data = db.Fetch();

            if (data != null)
            {
                List<Order> orders = new List<Order> { };

                foreach (Dictionary<string, object> item in data)
                {
                    int id = (int)item["id"];
                    int cid = (int)item["customerId"];
                    DateTime oDate = (DateTime)item["orderDate"];
                    DateTime eDate = (DateTime)item["expectDate"];
                    DateTime? dDate = item["deliverDate"] as DateTime?;

                    orders.Add(new Order(id, cid, oDate, eDate, dDate));
                }

                return orders;
            }
            else
            {
                return null;
            }
        }
Example #4
0
        public static List<Employee> GetEmployees()
        {
            try
            {
                Database db = new Database("SELECT * FROM [employees] ORDER BY [firstname] ASC");
                List<Dictionary<string, object>> datalist = db.Fetch();

                if(datalist != null)
                {
                    List<Employee> workers = new List<Employee> { };
                    foreach (Dictionary<string, object> item in datalist)
                    {
                        // Initiate Employee informations
                        int id = (int)item["id"];
                        string firstname = (string)item["firstname"];
                        string lastname = (string)item["lastname"];
                        string user = (string)item["username"];

                        Employee worker = new Employee(id, firstname, lastname, user);

                        // Load task for each Employee
                        Dictionary<string, object> param = new Dictionary<string, object> { };
                        param.Add("id", id);
                        List<Dictionary<string, object>> block = new Database("getTask", param).FetchProcedure();

                        // Checking if Employee have any task
                        if (block != null)
                        {
                            foreach (Dictionary<string, object> jobdata in block)
                            {
                                int mid = (int)jobdata["machineId"];
                                int eid = (int)jobdata["employeeId"];
                                DateTime aDate = (DateTime)jobdata["activeDate"];
                                DateTime dDate = (DateTime)jobdata["deadline"];
                                bool jid = (bool)jobdata["completed"];

                                worker.Joblist.Add(new Job(mid, eid, aDate, dDate, jid));
                            }
                        }

                        // Add Employee to list
                        workers.Add(worker);
                    }

                    return workers;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception exc)
            {
                Log.Record(exc);
                return null;
            }
        }