public Operation <Cooperative> UpdateCooperative(Cooperative cooperative) => Operation.Try(async() => { await cooperative .ThrowIfNull(new GaiaException(PolluxErrorCodes.InvalidArgument)) .Validate(); var persisted = (await _queries .GetCooperative(cooperative.Id)) .ThrowIfNull(new GaiaException(ErrorCodes.InvalidStoreQueryResult)); //Ensure that the right principal has access to this data await _dataAccessAuthorizer.AuthorizeAccess( typeof(Cooperative).FullName, persisted.Id.ToString()); //copy values persisted.Title = cooperative.Title; persisted.Address = cooperative.Address; persisted.ContactEmail = cooperative.ContactEmail; persisted.ContactMobile = cooperative.ContactMobile; persisted.ContactName = cooperative.ContactName; var storeCommand = _storeProvider.CommandFor(typeof(Cooperative).FullName); return((await storeCommand .Update(persisted)) .ThrowIfNull(new GaiaException(ErrorCodes.InvalidStoreCommandResult))); });
private void button1_Click(object sender, EventArgs e) { Cooperative c = new Cooperative(); c.Show(); blackBackground.Show(); c.FormClosing += new FormClosingEventHandler(Close); }
public ActionResult DeleteConfirmed(int id) { Cooperative cooperative = db.Cooperatives.Find(id); db.Cooperatives.Remove(cooperative); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Start() { shootingCooldown = new Cooldown(1); bulletData = new BulletData(); bulletData.position = new Position(); bulletData.direction = new Position(); coopData = new Cooperative(); }
public ActionResult Edit([Bind(Include = "CooperativeID,NomCooperative")] Cooperative cooperative) { if (ModelState.IsValid) { db.Entry(cooperative).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cooperative)); }
public ActionResult RegisterCooperative(string Coop_Name, string Coop_Latitude, string Coop_Longtitude, string Coop_Tel, string Coop_A_No, string Coop_A_Sup, string Coop_A_District, string AD_ID, string Coop_A_Province) { Cooperative cooperative = new Cooperative(); cooperative.Coop_Name = Coop_Name; cooperative.Coop_Latitude = Coop_Latitude; cooperative.Coop_Longitude = Coop_Longtitude; cooperative.Coop_Tel = Coop_Tel; cooperative.Coop_A_No = Coop_A_No; cooperative.Coop_A_Sup = Coop_A_Sup; cooperative.Coop_A_District = Coop_A_District; cooperative.AD_ID = AD_ID; Address_Coop address = new Address_Coop(); address.Coop_A_Province = Coop_A_Province; address.Coop_A_District = Coop_A_District; address.Coop_A_Sup = Coop_A_Sup; if (ModelState.IsValid) { if (Coop_Name != null) { //var check_User = db.Users.Where(a => a.U_IDCard.Equals(U_IDCard)).FirstOrDefault<User>(); //if (check_User != null) //{ // ViewBag.Message = " Please try again."; // return View(); //} //else //{ try { db.Cooperatives.Add(cooperative); db.Address_Coop.Add(address); db.SaveChanges(); return(RedirectToAction("Index", "Index")); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(e => e.ValidationErrors).Select(e => e.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } //} } } return(RedirectToAction("Login", "Login")); }
public ActionResult Create([Bind(Include = "CooperativeID,NomCooperative")] Cooperative cooperative) { if (ModelState.IsValid) { db.Cooperatives.Add(cooperative); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cooperative)); }
public bool validForm(ManagersCooperativesViewModels managerCoop) { bool valid = true; //validation si les mots de passes sont pareils if (Request.Form["password1"] == "" || Request.Form["password2"] == "" || (Request.Form["password2"] != Request.Form["password1"])) { valid = false; ModelState.AddModelError("", UtilResources.GetLabel("Les mots de passe ne correspondent pas")); } //validation si la cooperative existe déjà dans la base de données if (db.Cooperative.Any(o => o.Name == managerCoop.cooperative.Name)) { //Met à jour les données de la coopérative Cooperative temp = db.Cooperative.Where(o => o.Name == managerCoop.cooperative.Name).First(); managerCoop.manager.IDCooperative = temp.IDCooperative; temp.NoStreet = managerCoop.cooperative.NoStreet; temp.Street = managerCoop.cooperative.Street; temp.PostalCode = managerCoop.cooperative.PostalCode; temp.City = managerCoop.cooperative.City; db.Entry(temp).State = EntityState.Modified; db.SaveChanges(); } //validation pour le courriel if (managerCoop.manager.Email != "" || managerCoop.manager.Email != null) { try { MailAddress mail = new MailAddress(managerCoop.manager.Email); } catch (FormatException) { ModelState.AddModelError("", UtilResources.GetLabel("L'adresse courriel n'est pas valide.")); valid = false; } } else { ModelState.AddModelError("", UtilResources.GetLabel("L'adresse courriel n'est pas valide.")); valid = false; } // On regarde si l'email est déjà en BD if (db.Manager.Any(o => o.Email == managerCoop.manager.Email)) { valid = false; ModelState.AddModelError("", UtilResources.GetLabel("L'adresse courriel est déjà utilisé")); } return(valid); }
// GET: Cooperatives/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Cooperative cooperative = db.Cooperatives.Find(id); if (cooperative == null) { return(HttpNotFound()); } return(View(cooperative)); }
public ActionResult RegisterCooperative(string Coop_Name, string Coop_Latitude, string Coop_Longtitude, string Coop_Tel, string Coop_A_No, string Coop_A_Sup, string Coop_A_District, string AD_ID, string Coop_A_Province) { Cooperative cooperative = new Cooperative(); cooperative.Coop_Name = Coop_Name; cooperative.Coop_Latitude = Coop_Latitude; cooperative.Coop_Longitude = Coop_Longtitude; cooperative.Coop_Tel = Coop_Tel; cooperative.Coop_A_No = Coop_A_No; cooperative.Coop_A_Sup = Coop_A_Sup; cooperative.Coop_A_District = Coop_A_District; cooperative.Coop_A_Province = Coop_A_Province; if (ModelState.IsValid) { if (Coop_Name != null) { var check_coop = db.Cooperatives.Where(a => a.Coop_Name.Equals(Coop_Name)).FirstOrDefault <Cooperative>(); if (check_coop != null) { ViewBag.Message = " Try again ."; return(View()); } else { try { db.Cooperatives.Add(cooperative); db.SaveChanges(); return(RedirectToAction("Index", "Index")); } catch (DbEntityValidationException ex) { var errorMessages = ex.EntityValidationErrors.SelectMany(e => e.ValidationErrors).Select(e => e.ErrorMessage); var fullErrorMessage = string.Join("; ", errorMessages); var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage); throw new DbEntityValidationException(exceptionMessage, ex.EntityValidationErrors); } } } } return(RedirectToAction("Login", "Login")); }
private void readDDPDemandByCollection(Demand demand) { excel = new ExcelUtil(); excel.AddWorkbook(); excel.Worksheet("Sheet1"); String cell = null; String path = null; foreach (String cntr in demand.RowCollection) { cell = demand.DdpDemandkeywordColumn + cntr; path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell; excel.WriteCell(1, 1, path); String data = excel.ReadCell("A1").ToString(); dataType = new DataType(data); dataType = (DataType)dataTypeSessionData.createIfNotExist(dataType); Area area = new Area("Luzon"); area = (Area)areaSessionData.createIfNotExist(area); Regions region = new Regions(demand.Region.ToString().Replace("_", " "), area.areaId); region = (Regions)regionSessionData.createIfNotExist(region); Cooperative cooperative = new Cooperative(demand.Cooperative, demand.CooperativeAccronym, region.regionId); cooperative = (Cooperative)cooperativeSessionData.createIfNotExist(cooperative); CooperativeDataValues coopSearch = cooperativeDataValueSessionData.findDataValuesByCoopertiveId(cooperative, dataType); if (coopSearch != null) { cooperativeDataContentSessionData.deleteByDataValueId(coopSearch.cooperativeDataValuesId); cooperativeDataValue = coopSearch; } else { cooperativeDataValue = new CooperativeDataValues(cooperative, dataType); cooperativeDataValue = (CooperativeDataValues)cooperativeDataValueSessionData.add(cooperativeDataValue); } writeDDPDemandCoopCollection(demand, cntr); } excel.Close(); }
public Operation <Cooperative> CreateCooperative(Cooperative cooperative) => Operation.Try(async() => { await cooperative .ThrowIfNull(new GaiaException(PolluxErrorCodes.InvalidArgument)) .Validate(); //Ensure that the right principal has access to this data await _dataAccessAuthorizer.AuthorizeAccess(typeof(Cooperative).FullName); cooperative.Id = Guid.NewGuid(); cooperative.Admins = null; cooperative.Farms = null; cooperative.Status = CooperativeStatus.Active; var storeCommand = _storeProvider.CommandFor(typeof(Cooperative).FullName); return((await storeCommand .Add(cooperative)) .ThrowIfNull(new GaiaException(ErrorCodes.InvalidStoreCommandResult))); });
private void button7_Click(object sender, EventArgs e) { Demand demand = (Demand)propertyGrid.SelectedObject; NumberToLetterUtil converter = new NumberToLetterUtil(); demand.PscEcsData.Clear(); demand.PscEcsData.Add(new PscEcsData() { Name = "2008", Column = "J" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2009", Column = "K" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2010", Column = "L" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2011", Column = "M" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2012", Column = "N" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2013", Column = "O" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2014", Column = "P" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2015", Column = "Q" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2016", Column = "R" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2017", Column = "S" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2018", Column = "T" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2019", Column = "U" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2020", Column = "V" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2021", Column = "W" }); demand.PscEcsData.Add(new PscEcsData() { Name = "2022", Column = "X" }); NumberToLetterUtil numUtil = new NumberToLetterUtil(); if (demand.RowSequenceType == RowSequenceType.Range) { try { String firstLetter = demand.RowRangeFrom.ElementAt(0).ToString(); ExcelUtil excel = new ExcelUtil(); excel.Open(demand.Path + "/" + demand.FileName); excel.Worksheet(demand.WorkSheet); Object[,] obj = excel.ReadCellByRange(demand.RowRangeFrom + ":" + demand.RowRangeTo); for (int row = 1; row <= obj.GetUpperBound(0); row++) { //for (int col = 1; col <= obj.GetUpperBound(1); col++) { // if (obj[row, col] == null) { // Console.WriteLine("NUl"); // continue; // } // Console.WriteLine(obj[row, col].ToString()); //} int numberGap = Int32.Parse(numUtil.getNumberByLetter(firstLetter)); //Area area = new Area(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.AreaColumn)) - numberGap + 1].ToString()); Area area = new Area("Luzon"); area = (Area)areaSessionData.createIfNotExist(area); Regions region = new Regions(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.RegionColumn)) - numberGap + 1].ToString(), area.areaId); region = (Regions)regionSessionData.createIfNotExist(region); Cooperative cooperative = new Cooperative(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.CooperativeColumn)) - numberGap + 1].ToString(), "", region.regionId); cooperative = (Cooperative)cooperativeSessionData.createIfNotExist(cooperative); if (obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.PlantColumn)) - numberGap + 1] == null) { continue; } Plant plant = new Plant(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.PlantColumn)) - numberGap + 1].ToString(), cooperative.cooperativeId); plant = (Plant)plantSessionData.createIfNotExist(plant); //plant = (Plant)plantSessionData.add(plant); //if (plant == null) continue; Console.WriteLine("Plant: " + plant.plantId); DataType dataType = new DataType(obj[row, Int32.Parse(numUtil.getNumberByLetter(demand.PscEcsKeywordColumn)) - numberGap + 1].ToString()); dataType = (DataType)dataTypeSessionData.createIfNotExist(dataType); DataValues dataValue = new DataValues(plant.plantId, dataType.dataTypeId); dataValue = (DataValues)dataValuesSessionData.createIfNotExist(dataValue); foreach (PscEcsData ecsData in demand.PscEcsData) { object dataObect = obj[row, Int32.Parse(numUtil.getNumberByLetter(ecsData.Column)) - numberGap + 1]; String data = "0"; if (dataObect != null) { data = dataObect.ToString(); } DataContent dataContent = new DataContent(ecsData.Name, data, dataValue.dataValuesId); dataContentSessionData.add(dataContent); } } excel.Close(); } catch (WorksheetNotFoundException wnfe) { MessageBox.Show(null, wnfe.Message, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (RangeInvalidException rie) { MessageBox.Show(null, rie.Message, "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (IndexOutOfRangeException iore) { MessageBox.Show(null, "Index not in a range.", "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (demand.RowSequenceType == RowSequenceType.Collection) { try { excel = new ExcelUtil(); excel.AddWorkbook(); excel.Worksheet("Sheet1"); String cell = null; String path = null; foreach (String row in demand.RowCollection) { cell = demand.PlantColumnIndex + row; path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell; excel.WriteCell(1, 1, path); String plantName = excel.ReadCell("A1").ToString(); Console.WriteLine(plantName); int rowIndex = Int32.Parse(row) + 2; for (int cntr = rowIndex; cntr < (rowIndex + 2); cntr++) { cell = demand.SupplyContractedKeywordColumn + cntr; path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell; excel.WriteCell(1, 1, path); String data = excel.ReadCell("A1").ToString(); dataType = new DataType(data); dataType = (DataType)dataTypeSessionData.createIfNotExist(dataType); Console.WriteLine("data: " + dataType.dataTypeId); Area area = new Area("Luzon"); area = (Area)areaSessionData.createIfNotExist(area); Regions region = new Regions(demand.SupplyContractedRegion.ToString().Replace("_", " "), area.areaId); region = (Regions)regionSessionData.createIfNotExist(region); Cooperative cooperative = new Cooperative(demand.SupplyContractedCooperative, demand.SupplyContractedCooperativeAccronym, region.regionId); cooperative = (Cooperative)cooperativeSessionData.createIfNotExist(cooperative); Plant plant = new Plant(plantName, cooperative.cooperativeId); plant = (Plant)plantSessionData.createIfNotExist(plant); Console.WriteLine("Plant: " + plant.plantId); //DataValues coopSearch = data DataValues coopSearch = dataValuesSessionData.findDataValuesByPlantId(plant, dataType); if (coopSearch != null) { dataContentSessionData.deleteByDataValueId(coopSearch.dataValuesId); dataValue = coopSearch; } else { dataValue = new DataValues(); dataValue.plantId = plant.plantId; dataValue.dataTypeId = dataType.dataTypeId; dataValue = (DataValues)dataValuesSessionData.add(dataValue); } foreach (DDPSupplyContractedData contractedData in demand.SupplyContractedData) { cell = contractedData.Column + cntr; path = @"='" + demand.Path + "\\[" + demand.FileName + "]" + demand.WorkSheet + "'!" + cell; excel.WriteCell(1, 1, path); Console.WriteLine(contractedData.Name + " - " + excel.ReadCell(1, "A")); dataContent = new DataContent(); dataContent.header = contractedData.Name; dataContent.value = excel.ReadCell("A1"); dataContent.dataValuesId = dataValue.dataValuesId; dataContentSessionData.add(dataContent); } } } excel.Close(); } catch (NullReferenceException nre) { MessageBox.Show(null, nre.Message.ToString(), "Error Window", MessageBoxButtons.OK, MessageBoxIcon.Error); } } Console.WriteLine("Success!"); Console.WriteLine(demand.Region); }
private void button1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); String fileName = openFileDialog1.FileName; search(fileName); Int32 row = 0; foreach (DataRow dr in ds.Tables["tbl"].Rows) { ++row; DataValues dataValue = new DataValues(); String plantName = dr[4].ToString(); String coopName = dr[3].ToString(); String coopAccrnym = dr[2].ToString(); String regionName = dr[1].ToString(); String areaName = dr[0].ToString(); Regions region = regionDataSession.getRegionByName(regionName); Plant plant = plantDataSession.getPlantByName(plantName); if (plant == null) { Cooperative coop = cooperativeDataSession.getCooperativeByName(coopName); if (coop == null) { if (region == null) { Area area = areaSessionData.getAreaByName(areaName); region = new Regions(regionName, area.areaId); coop = new Cooperative(coopName, coopAccrnym, region); } else { coop = new Cooperative(coopName, coopAccrnym, region.regionId); } plant = new Plant(plantName, coop); dataValue.plant = plant; } else { plant = new Plant(plantName, coop.cooperativeId); dataValue.plant = plant; } } else { Plant plantTemp = plantDataSession.getPlantByPlantNCoop(plantName, coopName); if (plantTemp == null) { var db = Dbase.getCurrentInstance(); Cooperative coop = cooperativeDataSession.getCooperativeByName(coopName); if (coop == null) { Regions regionTemp = regionDataSession.getRegionByName(regionName); if (regionTemp == null) { Area area = areaSessionData.getAreaByName(areaName); regionTemp = new Regions(regionName, area.areaId); db.regions.Add(regionTemp); db.SaveChanges(); } coop = new Cooperative(coopName, coopAccrnym, regionTemp.regionId); db.cooperatives.Add(coop); db.SaveChanges(); } Plant plantNew = new Plant(plantName, coop.cooperativeId); db.plants.Add(plantNew); db.SaveChanges(); dataValue.plantId = plantNew.plantId; } else { dataValue.plantId = plantTemp.plantId; } } dataValue.dataTypeId = dataTypeSessionData.getDataTypeByName(dr[8].ToString()).dataTypeId; using (var db = new Dbase()) { db.dataValues.Add(dataValue); db.SaveChanges(); PSA psa = new PSA(); ExcelUtil exc = new ExcelUtil(); exc.Open(fileName); exc.Worksheet("PSC_ECs"); foreach (PscEcsData kwh in psa.Kwh_Data) { DataContent content = new DataContent(); content.header = kwh.Name; //content.value = dr[Int32.Parse(kwh.Name) - 1999].ToString(); content.value = exc.ReadCell(kwh.Column + row); Console.WriteLine(row + " = " + content.value); content.dataValuesId = dataValue.dataValuesId; db.dataContents.Add(content); db.SaveChanges(); } } /* * dataValue.d2008 = Double.Parse("0" + dr[9].ToString()); * dataValue.d2009 = Double.Parse("0" + dr[10].ToString()); * dataValue.d2010 = Double.Parse("0" + dr[11].ToString()); * dataValue.d2011 = Double.Parse("0" + dr[12].ToString()); * dataValue.d2012 = Double.Parse("0" + dr[13].ToString()); * dataValue.d2013 = Double.Parse("0" + dr[14].ToString()); * dataValue.d2014 = Double.Parse("0" + dr[15].ToString()); * dataValue.d2015 = Double.Parse("0" + dr[16].ToString()); * dataValue.d2016 = Double.Parse("0" + dr[17].ToString()); * dataValue.d2017 = Double.Parse("0" + dr[18].ToString()); * dataValue.d2018 = Double.Parse("0" + dr[19].ToString()); * dataValue.d2019 = Double.Parse("0" + dr[20].ToString()); * dataValue.d2020 = Double.Parse("0" + dr[21].ToString()); * dataValue.d2021 = Double.Parse("0" + dr[22].ToString()); * dataValue.d2022 = Double.Parse("0" + dr[23].ToString()); */ using (var db = new Dbase()) { db.dataValues.Add(dataValue); db.SaveChanges(); } } Console.WriteLine("DONE!"); }