Ejemplo n.º 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;
            }
        }
Ejemplo n.º 2
0
        public void Add()
        {
            if(Id == 0)
            {
                try
                {
                    Dictionary<string, object> param = new Dictionary<string, object> { };
                    param.Add("employee", EmployeeId);
                    param.Add("machine", StationId);
                    param.Add("date", TaskDate);

                    Database db = new Database("addTask", param);

                    List<Dictionary<string, object>> data = db.FetchProcedure();
                    jobId = (int)data[0]["id"];
                }
                catch
                {
                    // Error occur during Database processing
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Create a Customer
 /// </summary>
 public void Create()
 {
     if (Id == 0)
     {
         try
         {
             Database db = new Database("setCustomer");
             db.Bind("firstname", Firstname);
             db.Bind("lastname", Lastname);
             db.Bind("phone", Phone);
             db.Bind("email", Email);
             Dictionary<string, object> data = db.GetProcedure();
             if(data.Count == 1)
             {
                 customerId = (int)data["id"];
             }
             else if(data.Count > 1)
             {
                 customerId = (int)data["id"];
                 Firstname = (string)data["firstname"];
                 Lastname = (string)data["lastname"];
                 telephone = (string)data["phone"];
                 Email = (string)data["email"];
             }
         }
         catch (Exception exc)
         {
             Log.Record(exc);
         }
     }
 }
Ejemplo n.º 4
0
        public static List<Customer> GetCustomers()
        {
            try
            {
                List<Dictionary<string,object>> datalist = new Database("SELECT * FROM [customers]").Fetch();
                if(datalist != null)
                {
                    List<Customer> customers = new List<Customer> { };
                    foreach (Dictionary<string, object> item in datalist)
                    {
                        int id = (int)item["id"];
                        string firstname = (string)item["firstname"];
                        string lastname = (string)item["lastname"];
                        string email = (string)item["email"];
                        string phone = (string)item["phone"];

                        customers.Add(new Customer(id, firstname, lastname, phone, email));
                    }
                    return customers;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception exc)
            {
                Log.Record(exc);
                return null;
            }
        }
Ejemplo n.º 5
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;
     }
 }
Ejemplo n.º 6
0
 private void Load()
 {
     Database db = new Database("getItemProp");
     db.Bind("id", itemId);
     List<Dictionary<string,object>> datalist = db.FetchProcedure();
     if(datalist != null)
     {
         foreach (Dictionary<string,object> item in datalist)
         {
             int id = (int)item["machineId"];
             int num = (int)item["amount"];
             machines.Add(id, num);
         }
     }
 }
Ejemplo n.º 7
0
        public void Create()
        {
            try
            {
                // Create item
                Database db = new Database("setItem");
                db.Bind("name", Name);
                db.Bind("stock", 0);
                Dictionary<string, object> data = db.GetProcedure();
                itemId = (int)data["id"];
                // Adding item properties
                if(machines.Count > 0)
                {
                    // Generate Multi Insert query
                    string query = null;
                    foreach (KeyValuePair<int,int> item in machines)
                    {
                        if(query != null)
                        {
                            query += String.Format(",({0},{1},{2})", Id, item.Key, item.Value);
                        }
                        else
                        {
                            query += String.Format("INSERT INTO [itemProp] ([itemId],[machineId],[amount]) VALUES({0},{1},{2})", Id, item.Key, item.Value);
                        }
                    }
                    // Insert data
                    new Database(query).Execute();
                }

            }
            catch (Exception exc)
            {
                Log.Record(exc);
            }
        }
Ejemplo n.º 8
0
        public void Sync()
        {
            try
            {
                if (Id == 0)
                {
                    Database db = new Database("addOrder");
                    db.Bind("customer", customerId);
                    db.Bind("order", OrderDate);
                    db.Bind("expect", ExpectDate);

                    Dictionary<string, object> data = db.GetProcedure();
                    if (data != null)
                    {
                        orderId = (int)data["id"];
                    }
                }
                else
                {
                    orderlines = OrderLine.GetOrderLine(Id);
                }
            }
            catch (Exception exc)
            {
                Log.Record(exc);
            }
        }
Ejemplo n.º 9
0
 public void Remove()
 {
     if(Id != 0)
     {
         Database db = new Database("removeOrder");
         db.Bind("id", Id);
         db.Procedure();
     }
 }
Ejemplo n.º 10
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;
            }
        }
Ejemplo n.º 11
0
        public static List<Order> GetOrders(int id)
        {
            Database db = new Database("getOrder");
            db.Bind("id", id);
            List<Dictionary<string, object>> data = db.FetchProcedure();

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

                foreach (Dictionary<string, object> item in data)
                {
                    int oid = (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(oid, cid, oDate, eDate, dDate));
                }

                return orders;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 12
0
        public void Add()
        {
            if(Id == 0 && Firstname != null && Lastname != null && Username != null)
            {
                try
                {
                    Database db = new Database("setEmployee");
                    db.Bind("user", Username);
                    db.Bind("firstname", Firstname);
                    db.Bind("lastname", Lastname);
                    Dictionary<string, object> data = db.GetProcedure();

                    employeeId = (int)data["id"];
                    userName = (string)data["user"];
                    Firstname = (string)data["firstname"];
                    Lastname = (string)data["lastname"];
                }
                catch (Exception exc)
                {
                    Log.Record(exc);
                }
            }
        }
Ejemplo n.º 13
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;
            }
        }
Ejemplo n.º 14
0
        public static List<OrderLine> GetOrderLine(int order)
        {
            try
            {
                Database db = new Database("getOrderLine");
                db.Bind("id", order);
                List<Dictionary<string,object>> datalist = db.FetchProcedure();
                if(datalist != null)
                {
                    List<OrderLine> items = new List<OrderLine> { };
                    foreach(Dictionary<string, object> item in datalist)
                    {
                        int oid = (int)item["orderId"];
                        int iid = (int)item["itemId"];
                        int num = (int)item["quantity"];

                        items.Add(new OrderLine(oid, iid, num, true));
                    }

                    return items;
                }
                else
                {
                    return null;
                }
            }
            catch(Exception exc)
            {
                Log.Record(exc);
                return null;
            }
        }
Ejemplo n.º 15
0
 public void Sync()
 {
     try
     {
         // Synchronize data
         Database db = new Database("addItems");
         db.Bind("order", OrderId);
         db.Bind("item", ItemId);
         db.Bind("num", Quantity);
         db.Procedure();
     }
     catch (Exception exc)
     {
         Log.Record(exc);
     }
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Remove OrderLine from database
 /// </summary>
 public void Remove()
 {
     try
     {
         Database db = new Database("removeOrderLine");
         db.Bind("order", OrderId);
         db.Bind("item", ItemId);
         db.Procedure();
     }
     catch (Exception exc)
     {
         Log.Record(exc);
     }
 }