コード例 #1
0
        public async Task <int> Add(Cultivation cultivation)
        {
            var cmd = QueriesCreatingHelper.CreateQueryInsert(cultivation);

            cmd += ";SELECT LAST_INSERT_ID();";
            return((await DALHelper.ExecuteQuery <int>(cmd, dbTransaction: DbTransaction, connection: DbConnection)).First());
        }
コード例 #2
0
        public static Cultivation CreateCultivation(CultivationAddModel cultivation)
        {
            if (cultivation.varietyId == 0)
            {
                pgSqlSingleManager.ExecuteSQL($"insert into cultivation.cultivation (name,plant,pieces,tunnel,start_date) " +
                                              $"values ('{cultivation.name}', (select id from cultivation.plants where plant_species = {cultivation.plantSpeciesId} " +
                                              $"and plant_variety is null) ,{cultivation.pieces},{cultivation.tunnelId},'{cultivation.start_date}')");
            }
            else
            {
                pgSqlSingleManager.ExecuteSQL($"insert into cultivation.cultivation (name,plant,pieces,tunnel,start_date) " +
                                              $"values ('{cultivation.name}', (select id from cultivation.plants where plant_species = {cultivation.plantSpeciesId} " +
                                              $"and plant_variety = {cultivation.varietyId}) ,{cultivation.pieces},{cultivation.tunnelId},'{cultivation.start_date}')");
            }


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

            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);
        }
コード例 #3
0
ファイル: TunnelInfo.cs プロジェクト: RedRevenge94/szh
        public static TunnelInfo GetTunnelInfo(int tunnelId)
        {
            TunnelInfo tunnelInfo = new TunnelInfo {
                //TunelInformacje
                tunnel = Tunnel.GetTunnel(tunnelId),
                //Hodowle
                cultivations = Cultivation.GetCultivationsInTunnel(tunnelId),
                //Online
                online = false,
                //Temperature
                temperature = null
            };

            try {
                tunnelInfo.online = (DateTime.Now - (DateTime)AvrDevice.GetAvrDevicesInTunnel(tunnelId)[0].last_update).TotalSeconds < 60;
                if (tunnelInfo.online)
                {
                    tunnelInfo.temperature = Measurement.GetTemperatureInTunnel(tunnelId).value;
                    tunnelInfo.isAlarm     = GetTunnelAlarmInfo(tunnelId);
                }
            } catch {
                ;
            }


            return(tunnelInfo);
        }
コード例 #4
0
 public MoneyValue(Cultivation cultivation, int monthCount)
 {
     Income        = cultivation.MoneyTick;
     Expense       = cultivation.ExpenseTick;
     MonthCount    = monthCount;
     MonthsToGrow  = cultivation.MonthsToGrow;
     MyCultivation = cultivation;
 }
コード例 #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            Cultivation cultivation = db.Cultivations.Find(id);

            db.Cultivations.Remove(cultivation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #6
0
        public static List <CultivationInfoBasic> GetCultivationInfo()
        {
            List <CultivationInfoBasic> cultivationsInfoList = new List <CultivationInfoBasic>();

            foreach (var cultivation in Cultivation.GetCultivations())
            {
                cultivationsInfoList.Add(GetCultivationInfo(cultivation.id));
            }

            return(cultivationsInfoList);
        }
コード例 #7
0
 public ActionResult Edit([Bind(Include = "Id,Id_Field,State,Id_Seed")] Cultivation cultivation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(cultivation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Id_Field = new SelectList(db.Fields, "Id", "Type", cultivation.Id_Field);
     ViewBag.Id_Seed  = new SelectList(db.Seeds, "Id", "Name", cultivation.Id_Seed);
     return(View(cultivation));
 }
コード例 #8
0
ファイル: SimpleMoneyManager.cs プロジェクト: beatt2/FoodGame
 public void RemoveValue(Cultivation cultivation)
 {
     if (_moneyValues.ContainsKey(cultivation.FieldType))
     {
         for (int i = 0; i < _moneyValues[cultivation.FieldType].Count; i++)
         {
             if (_moneyValues[cultivation.FieldType][i].MyCultivation == cultivation)
             {
                 _moneyValues[cultivation.FieldType].RemoveAt(i);
             }
         }
     }
 }
コード例 #9
0
        public ActionResult Create([Bind(Include = "Id,Id_Field,State,Id_Seed")] Cultivation cultivation)
        {
            if (ModelState.IsValid)
            {
                db.Cultivations.Add(cultivation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Id_Field = new SelectList(db.Fields, "Id", "Type", cultivation.Id_Field);
            ViewBag.Id_Seed  = new SelectList(db.Seeds, "Id", "Name", cultivation.Id_Seed);
            return(View(cultivation));
        }
コード例 #10
0
        // GET: Cultivations/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cultivation cultivation = db.Cultivations.Find(id);

            if (cultivation == null)
            {
                return(HttpNotFound());
            }
            return(View(cultivation));
        }
コード例 #11
0
 public IActionResult Update([FromBody] Cultivation cultivation)
 {
     if (cultivation.name == null || cultivation.start_date == null)
     {
         return(BadRequest());
     }
     else
     {
         Cultivation newCultivation = Cultivation.UpdateCultivation(cultivation);
         if (newCultivation.name.Equals(cultivation.name))
         {
             return(CreatedAtRoute("GetCultivation", new { newCultivation.id }, newCultivation));
         }
     }
     return(BadRequest());
 }
コード例 #12
0
        // GET: Cultivations/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Cultivation cultivation = db.Cultivations.Find(id);

            if (cultivation == null)
            {
                return(HttpNotFound());
            }
            ViewBag.Id_Field = new SelectList(db.Fields, "Id", "Type", cultivation.Id_Field);
            ViewBag.Id_Seed  = new SelectList(db.Seeds, "Id", "Name", cultivation.Id_Seed);
            return(View(cultivation));
        }
コード例 #13
0
        public static CultivationInfoBasic GetCultivationInfo(int cultivationId)
        {
            CultivationInfoBasic cultivationInfo = new CultivationInfoBasic {
                cultivation = Cultivation.GetCultivation(cultivationId),
                //Online
                online = false
            };

            try {
                cultivationInfo.online = (DateTime.Now - (DateTime)AvrDevice.GetAvrDevicesInTunnel(cultivationInfo.cultivation.tunnel.id)[0].last_update).TotalSeconds < 60;
            } catch {
                ;
            }

            return(cultivationInfo);
        }
コード例 #14
0
 public IActionResult Create([FromBody] CultivationAddModel cultivation)
 {
     if (cultivation.name == null || cultivation.plantSpeciesId == 0 || cultivation.start_date == null || cultivation.tunnelId == 0)
     {
         return(BadRequest());
     }
     else
     {
         Cultivation newCultivation = CultivationAddModel.CreateCultivation(cultivation);
         if (newCultivation.name.Equals(cultivation.name))
         {
             return(CreatedAtRoute("GetCultivation", new { newCultivation.id }, newCultivation));
         }
     }
     return(BadRequest());
 }
コード例 #15
0
ファイル: DbDataController.cs プロジェクト: RedRevenge94/szh
        public IActionResult PrepareDataBase(bool prepare)
        {
            ClearDataBase();

            if (prepare)
            {
                Random gen = new Random();

                List <string> plantsNames = new List <string>();
                plantsNames.Add("Awokado");
                plantsNames.Add("Lychee");
                plantsNames.Add("Cytryna");
                plantsNames.Add("Pomarańcza");
                plantsNames.Add("Mango");

                foreach (string plantName in plantsNames)
                {
                    int newPlantId = Plant.CreatePlant(plantName).id;

                    for (int i = 0; i < 5; i++)
                    {
                        Variety.CreateVariety(PlantSpecies.GetPlantSpeciesByName(plantName).id, $"Odmiana {i}");
                    }
                }

                for (int i = 0; i < 4; i++)
                {
                    int id = Tunnel.CreateTunnel($"Tunnel {i}").id;
                    AvrDevice.CreateAvrDevice($"localhost/espSim/{i + 10}", id);

                    for (int j = 0; j < gen.Next(1, 6); j++)
                    {
                        List <Plant> plants          = Plant.GetPlants();
                        int          plantTableIndex = gen.Next(0, plants.Count - 1);


                        int breedingId = Cultivation.CreateCultivation($"Hodowla {i}/{j}", plants[plantTableIndex].id, i + i * j + 1, id, DateTime.Now).id;
                        for (int k = 0; k < gen.Next(0, 10); k++)
                        {
                            CultivationComment.AddCultivationComents($"Komentarz do hodowli { i + i * j * k}", breedingId);
                        }
                    }
                }
            }

            return(new NoContentResult());
        }
コード例 #16
0
ファイル: SimpleMoneyManager.cs プロジェクト: beatt2/FoodGame
        public void AddFinance(Cultivation cultivation, int oldMonthCount)
        {
            if (!_moneyValues.ContainsKey(cultivation.FieldType))
            {
                _moneyValues.Add(cultivation.FieldType, new List <MoneyValue>());
                _moneyValues[cultivation.FieldType].Add(new MoneyValue(cultivation, oldMonthCount));
            }
            else
            {
                _moneyValues[cultivation.FieldType].Add(new MoneyValue(cultivation, oldMonthCount));
            }

            for (int i = 0; i < _moneyValues.Keys.Count; i++)
            {
                foreach (var t in _moneyValues.ElementAt(i).Value)
                {
                    t.MyCultivation.MonthCount = t.MonthCount;
                }
            }
        }
コード例 #17
0
 public SaveNodes
 (
     int listIndex,
     NodeState.CurrentStateEnum currentState,
     NodeState.FieldTypeEnum fieldType,
     bool emptyCultivationField,
     Cultivation myCultivation,
     bool fenceLeft,
     bool fenceLeftOwner,
     bool fenceRight,
     bool fenceRightOwner,
     bool fenceUp,
     bool fenceUpOwner,
     bool fenceDown,
     bool fenceDownOwner,
     int sizeRankLeft,
     int sizeRankRight,
     int sizeRankUp,
     int sizeRankDown,
     Cultivation mySavedCultivation
 )
 {
     ListIndex             = listIndex;
     CurrentState          = currentState;
     FieldType             = fieldType;
     EmptyCultivationField = emptyCultivationField;
     MyCultivation         = myCultivation;
     FenceLeft             = fenceLeft;
     FenceLeftOwner        = fenceLeftOwner;
     FenceRight            = fenceRight;
     FenceRightOwner       = fenceRightOwner;
     FenceUp            = fenceUp;
     FenceUpOwner       = fenceUpOwner;
     FenceDown          = fenceDown;
     FenceDownOwner     = fenceDownOwner;
     SizeRankLeft       = sizeRankLeft;
     SizeRankRight      = sizeRankRight;
     SizeRankUp         = sizeRankUp;
     SizeRankDown       = sizeRankDown;
     MySavedCultivation = mySavedCultivation;
 }
コード例 #18
0
ファイル: DbDataController.cs プロジェクト: RedRevenge94/szh
        private void ClearDataBase()
        {
            foreach (Tunnel tunnel in Tunnel.GetTunnels())
            {
                foreach (Cultivation cultivation in Cultivation.GetCultivationsInTunnel(tunnel.id))
                {
                    CultivationComment.DeleteFromBreeding(cultivation.id);
                    Cultivation.DeleteFromTunnel(cultivation.id);
                }

                foreach (AvrDevice avr_device in AvrDevice.GetAvrDevicesInTunnel(tunnel.id))
                {
                    Measurement.DeleteMeasurements();
                    AvrDevice.DeleteAvrDevice(avr_device.id);
                }

                Tunnel.DeleteTunnel(tunnel.id);
            }

            Plant.DeletePlants();
        }
コード例 #19
0
ファイル: SidePanel.cs プロジェクト: beatt2/FoodGame
        public void SetPanel(Cultivation cultivation)
        {
            if (!_panelLerp.IsActive())
            {
                _panelLerp.ToggleLerp();
            }



            TutorialScript.OnClickField();
            _currentCultivation = cultivation;
            HeaderText.text     = cultivation.Name;
            MyImage.sprite      = SidePanelIcons[cultivation.SidePanelSpriteIndex];
            if (!cultivation.Upgrade)
            {
                UpgradeText.text = "Upgrade = " + cultivation.UpgradeValue;
            }
            else
            {
                UpgradeText.text = "";
            }

            if (cultivation.MyCultivationState == NodeState.CurrentStateEnum.EmptyField)
            {
                UpgradeText.text = "Upgrade = " + UglyHiddenBoi();
            }

            MoneyTickText.text    = "Inkomsten: " + cultivation.MoneyTick;
            ExpenseTickText.text  = "Kosten: " + cultivation.ExpenseTick;
            HappinessText.text    = "Populariteit: " + cultivation.Happiness;
            EnviromentalText.text = "Biologisch: " + cultivation.EnviromentValue;
            MonthsToGrow.text     = "Groeitijd: " + _currentCultivation.MonthCount + "/" + _currentCultivation.MonthsToGrow;

            //UpgradeButton.interactable = cultivation.MyCultivationState != NodeState.CurrentStateEnum.Field;
            KillButton.interactable = cultivation.MyCultivationState != NodeState.CurrentStateEnum.EmptyField;
        }
コード例 #20
0
ファイル: Selection.cs プロジェクト: beatt2/FoodGame
 public void SetSidePanel(Cultivation cultivation)
 {
     MySidePanel.SetPanel(cultivation);
 }
コード例 #21
0
        public async Task <int> Update(Cultivation cultivation)
        {
            var cmd = QueriesCreatingHelper.CreateQueryUpdate(cultivation);

            return(await DALHelper.Execute(cmd, dbTransaction : DbTransaction, connection : DbConnection));
        }
コード例 #22
0
ファイル: UpgradeTab.cs プロジェクト: beatt2/FoodGame
 public static void UpdateButtonClicked(Cultivation cultivation)
 {
     Debug.Log("Button has been pressed");
 }
コード例 #23
0
        static void Main(string[] args)
        {
            // default filename in same folder as executable
            string filename         = "Barley_IT_AgMIP.json";
            string filenameErrorOut = "errorOut.txt";
            // default output path to user Documents
            string outpath = System.Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + Path.DirectorySeparatorChar + "AgMIPToMonicaOut";

            for (int i = 0; i < args.Length; i++)
            {
                if (args[i] == "-filename" && i + 1 < args.Length)
                {
                    filename = args[i + 1];
                }
                if (args[i] == "-out" && i + 1 < args.Length)
                {
                    outpath = args[i + 1];
                }
            }
            // check if input file exists
            if (!File.Exists(filename))
            {
                Console.WriteLine("Input file {0} does not exist!", filename);
                Environment.Exit(10);
            }
            // check if output path exists or can be created
            if (!Directory.Exists(outpath))
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(outpath))
                    {
                        Directory.CreateDirectory(outpath);
                    }
                    else
                    {
                        Console.WriteLine("Invaild output directory!");
                        Environment.Exit(10);
                    }
                }
                catch (IOException ex)
                {
                    Console.WriteLine("An error occured:");
                    Console.WriteLine(ex.Message);
                    Environment.Exit(10);
                }
            }

            // read json file, extract relevant data, write to file
            try
            {
                string  jsonText  = File.ReadAllText(filename);
                JObject agMipJson = JObject.Parse(jsonText);
                string  errorOut  = "";
                ClimateData.ExtractWeatherData(outpath, agMipJson, ref errorOut);
                SiteData.ExtractSoilData(outpath, agMipJson, ref errorOut);
                Cultivation.ExtractCropData(outpath, agMipJson);

                if (!string.IsNullOrWhiteSpace(errorOut))
                {
                    File.WriteAllText(outpath + Path.DirectorySeparatorChar + filenameErrorOut, errorOut.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("An error occured:");
                Console.WriteLine(ex.Message);
                Console.ReadKey();
                Environment.Exit(10);
            }
        }
コード例 #24
0
ファイル: UpdateCommand.cs プロジェクト: weedkiller/TrueFail
 public UpdateCommand(Cultivation cultivation)
 {
     Cultivation = cultivation;
 }
コード例 #25
0
 public AddCommand(Cultivation cultivation)
 {
     Cultivation = cultivation;
 }