Esempio n. 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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public static CultivationComment AddCultivationComents(string text, int breeding)
        {
            Cultivation lastBreedingComments = new Cultivation()
            {
                id = GetMax("cultivation.cultivation_comments")
            };

            pgSqlSingleManager.ExecuteSQL($"insert into cultivation.cultivation_comments (id,text,cultivation,create_date) " +
                                          $"values ({lastBreedingComments.id + 1},'{text}',{breeding},'{DateTime.Now}')");
            var breedingCommentResult = pgSqlSingleManager.ExecuteSQL($"select * from cultivation.cultivation_comments where id = {lastBreedingComments.id + 1}");

            CultivationComment newBreedingComment = new CultivationComment {
                id          = Int32.Parse(breedingCommentResult[0]["id"]),
                text        = breedingCommentResult[0]["text"],
                cultivation = Int32.Parse(breedingCommentResult[0]["cultivation"]),
                create_date = DateTime.Parse(breedingCommentResult[0]["create_date"])
            };

            return(newBreedingComment);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public static Cultivation CreateCultivation(Cultivation cultivation)
 {
     return(CreateCultivation(cultivation.name, cultivation.plant.id, cultivation.pieces, cultivation.tunnel.id, cultivation.start_date));
 }