Пример #1
0
        private static List <Cultivation> GetCultivations(string query)
        {
            List <Cultivation> cultivations = new List <Cultivation>();

            foreach (var cultivation in pgSqlSingleManager.ExecuteSQL(query))
            {
                Cultivation newCultivation = new Cultivation()
                {
                    id         = Int32.Parse(cultivation["id"]),
                    name       = cultivation["name"],
                    plant      = Plant.GetPlant(Int32.Parse(cultivation["plant"])),
                    pieces     = Int32.Parse(cultivation["pieces"]),
                    tunnel     = Tunnel.GetTunnel(Int32.Parse(cultivation["tunnel"])),
                    start_date = DateTime.Parse(cultivation["start_date"]),
                    end_date   = null
                };
                if (cultivation["end_date"] != "")
                {
                    newCultivation.end_date = DateTime.Parse(cultivation["end_date"]);
                }

                cultivations.Add(newCultivation);
            }
            return(cultivations);
        }
Пример #2
0
        private static List <AvrDevice> GetAvrDevices(string query, bool getTunnelInfo)
        {
            List <AvrDevice> avrDevices = new List <AvrDevice>();

            foreach (var avrDevice in pgSqlSingleManager.ExecuteSQL(query))
            {
                AvrDevice newAvrDevice = new AvrDevice()
                {
                    id          = Int32.Parse(avrDevice["id"]),
                    ip          = avrDevice["ip"],
                    last_update = null
                };

                if (getTunnelInfo)
                {
                    newAvrDevice.tunnel = Tunnel.GetTunnel(Int32.Parse(avrDevice["tunnel"]));
                }

                if (avrDevice["last_update"] != "")
                {
                    newAvrDevice.last_update = DateTime.Parse(avrDevice["last_update"]);
                }

                avrDevices.Add(newAvrDevice);
            }
            return(avrDevices);
        }
Пример #3
0
        public static Cultivation UpdateCultivation(Cultivation cultivation)
        {
            string endDateValue = "";

            if (cultivation.end_date == null)
            {
                endDateValue = "null";
            }
            else
            {
                endDateValue = $"'{cultivation.end_date}'";
            }


            string sql = $"update cultivation.cultivation set " +
                         $"name = '{cultivation.name}', pieces = {cultivation.pieces}, tunnel = {cultivation.tunnel.id}," +
                         $" start_date = '{cultivation.start_date}', end_date = {endDateValue} " +
                         $"where id = {cultivation.id} ";

            pgSqlSingleManager.ExecuteSQL(sql);
            var cultivationResult = pgSqlSingleManager.ExecuteSQL($"select * from cultivation.cultivation where id = {cultivation.id}");

            Cultivation updatedCultivation = new Cultivation {
                id         = Int32.Parse(cultivationResult[0]["id"]),
                name       = cultivationResult[0]["name"],
                pieces     = Int32.Parse(cultivationResult[0]["pieces"]),
                plant      = Plant.GetPlant(Int32.Parse(cultivationResult[0]["plant"])),
                tunnel     = Tunnel.GetTunnel(Int32.Parse(cultivationResult[0]["tunnel"])),
                start_date = DateTime.Parse(cultivationResult[0]["start_date"])
            };

            return(updatedCultivation);
        }
Пример #4
0
        public static Tunnel GetTunnel(int id)
        {
            var    sqlresults   = pgSqlSingleManager.ExecuteSQL($"select * from cultivation.tunnels where id = {id}");
            Tunnel resultTunnel = new Tunnel();

            foreach (var c_result in sqlresults)
            {
                resultTunnel = new Tunnel()
                {
                    id   = Int32.Parse(c_result["id"]),
                    name = c_result["name"]
                };
            }

            return(resultTunnel);
        }
Пример #5
0
        public static Tunnel CreateTunnel(string name)
        {
            var    tunnelMaxResult = pgSqlSingleManager.ExecuteSQL($"select max(id) from cultivation.tunnels");
            Tunnel lastTunnel      = new Tunnel();

            Int32.TryParse(tunnelMaxResult[0]["max"], out lastTunnel.id);

            pgSqlSingleManager.ExecuteSQL($"insert into cultivation.tunnels (id,name) values ({lastTunnel.id + 1},'{name}')");
            var tunnelResult = pgSqlSingleManager.ExecuteSQL($"select * from cultivation.tunnels where id = {lastTunnel.id + 1}");

            Tunnel newTunnel = new Tunnel {
                id   = Int32.Parse(tunnelResult[0]["id"]),
                name = tunnelResult[0]["name"]
            };

            return(newTunnel);
        }
Пример #6
0
        //Do przerobienia - plant to nie ten plant
        public static Cultivation CreateCultivation(string name, int plant, int pieces, int tunnel, DateTime start_date)
        {
            Cultivation lastCultivation = new Cultivation()
            {
                id = GetMax("cultivation.cultivation")
            };

            pgSqlSingleManager.ExecuteSQL($"insert into cultivation.cultivation (id,name,plant,pieces,tunnel,start_date) " +
                                          $"values ({lastCultivation.id + 1},'{name}',{plant},{pieces},{tunnel},'{start_date}')");
            var cultivationResult = pgSqlSingleManager.ExecuteSQL($"select * from cultivation.cultivation where id = {lastCultivation.id + 1}");

            Cultivation newCultivation = new Cultivation {
                id         = Int32.Parse(cultivationResult[0]["id"]),
                name       = cultivationResult[0]["name"],
                pieces     = Int32.Parse(cultivationResult[0]["pieces"]),
                plant      = Plant.GetPlant(Int32.Parse(cultivationResult[0]["plant"])),
                tunnel     = Tunnel.GetTunnel(Int32.Parse(cultivationResult[0]["tunnel"])),
                start_date = DateTime.Parse(cultivationResult[0]["start_date"])
            };

            return(newCultivation);
        }
Пример #7
0
 public static Tunnel UpdateTunnel(Tunnel oldTunnel, string newName)
 {
     oldTunnel.name = newName;
     pgSqlSingleManager.ExecuteSQL($"update cultivation.tunnels set name = '{newName}' where id = {oldTunnel.id} and name = '{oldTunnel.name}'");
     return(GetTunnel(oldTunnel.id));
 }