//public static Dictionary<string, int> GetDictionary(this string compositionStr, string sectorNameStr, int number) //{ // Dictionary<string, int> tempDictionary = new Dictionary<string, int>(); // using (PgContext context = new PgContext()) // { // if (compositionStr != null) // { // string tempStr = null; // foreach (char i in compositionStr.ToArray()) // { // if (i.ToString() != "/" && i.ToString() != ".") // tempStr += i; // else // { // if (context.Materials.Find(tempStr) != null && context.Materials.Find(tempStr).sectorName.Equals(sectorNameStr)) // { // if (!tempDictionary.ContainsKey(tempStr)) // tempDictionary.Add(tempStr, number); // else // tempDictionary[tempStr] += number; // } // tempStr = null; // } // } // } // } // return tempDictionary; //} public static Dictionary <string, int> GetDictionary(this string compositionStr, string sectorNameStr, int number) //??? { Dictionary <string, int> tempDictionary = new Dictionary <string, int>(); using (PgContext context = new PgContext()) { if (compositionStr != null) { StringBuilder sb = new StringBuilder(); foreach (var i in compositionStr.ToArray()) { if (i != '/' & i != '.') { sb.Append(i); } else { if (context.Materials.Find(sb.ToString()) != null & context.Materials.Find(sb.ToString()).sectorName.Equals(sectorNameStr)) { if (!tempDictionary.ContainsKey(sb.ToString())) { tempDictionary.Add(sb.ToString(), number); } else { tempDictionary[sb.ToString()] += number; } } sb.Clear(); } } } } return(tempDictionary); }
public EditWindow(MainWindow mainWindow, MattressObjectV2 obj) { InitializeComponent(); this.mainWindow = mainWindow; mtrObj = obj; lbOrderInfo.Content += mtrObj.OrderInfo; lbTableName.Content += mtrObj.TableName; lbMattressName.Content += mtrObj.Name; lbSize.Content += mtrObj.Size; lbNumbers.Content += mtrObj.Numbers.ToString(); this.mainWindow.GetOrdersList().ForEach(str => cmbOrders.Items.Add(str)); using (PgContext context = new PgContext()) { foreach (var size in context.Sizes) { cmbSizes.Items.Add(size); } foreach (var table in context.Tables) { cmbTables.Items.Add(table); } } }
public MainWindow() { InitializeComponent(); using (PgContext context = new PgContext()) { foreach (Mattresses mtrs in context.Mattresses.OrderBy(m => m.mattressName)) { listBoxMattressList.Items.Add(mtrs); } foreach (Sizes size in context.Sizes) { cmbSizes.Items.Add(size); } if (context.Tables.Count() != 0) { foreach (Tables table in context.Tables) { cmbTables.Items.Add(table); } } else { cmbTables.IsEnabled = false; } } #region Initializing Dictionaries. globalOrdersList = new List <string>(); globalPolyurethaneSheetsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalPolyurethaneForPerimetrsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalPerimetrsMaterialsList3D = new Dictionary <string, List <string> >(); globalMainCompositionsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalBlocksDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); #region Cuts. globalUltrCutsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalV16CutsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalKaterCutsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalNotStegCutsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); #endregion #region Covers. globalUltrCoversDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalV16CoversDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalKaterCoversDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); globalNotStegCoversDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); #endregion globalBurletsDictionary3D = new Dictionary <string, Dictionary <string, Dictionary <string, int> > >(); #endregion CreateDocument = CreateTotalOrderDocument; }
public PatientsRepo() { log = LogManager.GetLogger("PatientsRepo"); if (context == null) { context = new PgContext(); } }
//add person on user's demand, if only it is valid public Person AddNewPerson(string name, GameSummary gameSummary) { using (var context = new PgContext()) { //jezeli jest taka osoba juz, to nie dodawaj jej na pałę: if (context.Persons.Any(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase))) { var person = context.Persons.Single(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); gameSummary.GuessedGamePerson = new GamePerson() { CorrectAnswers = -1, Name = person.Name, OccurenceCount = person.Count, PersonId = person.PersonId }; UpdateStructures(gameSummary); return(person); } // w pp. dodaj ją na pałę: context.Persons.Add(new Person() { Name = name, Count = 0 }); context.SaveChanges(); var personAdded = context.Persons.Single(x => x.Name.Equals(name, StringComparison.CurrentCultureIgnoreCase)); var questions = context.Questions.ToList(); foreach (var question in questions) { if (gameSummary.Entries.Any(x => x.QuestionId == question.QuestionId)) { var summaryQuestion = gameSummary.Entries.Single(x => x.QuestionId == question.QuestionId); context.Answers.Add(new Answer() { NoCount = summaryQuestion.UserAnswer == AnswerType.No ? 1 : 0, YesCount = summaryQuestion.UserAnswer == AnswerType.No ? 0 : 1, PersonId = personAdded.PersonId, QuestionId = question.QuestionId }); } else { context.Answers.Add(new Answer() { NoCount = 0, YesCount = 0, QuestionId = question.QuestionId, PersonId = personAdded.PersonId }); } } context.SaveChanges(); return(personAdded); } }
private void btTransferir_Click(object sender, EventArgs e) { var result = MessageBox.Show("Deseja transferir os dados do banco SQLServer para o Banco Postgres?", "Transferência de dados", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { //Lista para verificar se um novo guid é único List <Guid> guids = new List <Guid>(); //Listas para impedir a que o mesmo email seja cadastrado mais de uma vez para a mesma entidade List <int> ents = new List <int>(); List <string> emails = new List <string>(); for (int i = 1; i <= 7; i++) { PgContext pc = new PgContext(); Entidade ent = new Entidade(); Endereco end = new Endereco(); Telefone tel = new Telefone(); Email em = new Email(); var origem = CadastroModel.GetCadastro(i); if (origem != null) { DataSender ds = new DataSender(); //Entidade ent = ds.CriaEntidade(ent, origem, pc, guids); guids.Add(ent.guid); //Foreign key int fk = ds.GetForeignKey(pc, ent.guid); end.fkEntidade = fk; tel.fkEntidade = fk; em.fkEntidade = fk; //Endereco ds.CriaEndereco(end, origem, pc); //Telefone ds.CriaTelefone(tel, origem, pc); //Email em = ds.CriaEmail(em, origem, pc, ents, emails); ents.Add(fk); emails.Add(em.endereco); } } MessageBox.Show("Dados transferidos com sucesso!"); } }
//add new row in past games table (statistical purposes) public void SaveGameInfo(GameSummary data, bool won) { using (var context = new PgContext()) { var newGame = new PastGame { QuestionsAsked = data.QuestionsAsked, Won = won }; context.PastGames.Add(newGame); context.SaveChanges(); } }
//dont want to talk about it public static Tuple <int, int, int, int, int> GetStats() { using (var context = new PgContext()) { var gameCount = context.PastGames.Count(); var wonCount = context.PastGames.Count(x => x.Won); var questionCount = context.Questions.Count(); var personCount = context.Persons.Count(); var askCount = context.PastGames.Sum(x => x.QuestionsAsked); return(new Tuple <int, int, int, int, int>(personCount, questionCount, gameCount, wonCount, askCount)); } }
static void Main(string[] args) { try { using (PgContext db = new PgContext()) { var posts = db.Posts.Include("comments").ToList(); } } catch (Exception ex) { throw; } }
private void MaintainanceUserData(PgContext context) { // 未確認ユーザかつ、一時確認URLが期限切れとなっているデータを検索 var currentTimestamp = DateTime.Now; var queryResult = from confirm in context.AccountConfirms join users in context.Users on confirm.UserId equals users.UserId where confirm.IsDeleted == false && users.IsDeleted == false && users.IsConfirmed == false && confirm.ExpireLimit < currentTimestamp select new { UserId = users.UserId, TempUri = confirm.ConfirmUri, }; if (queryResult.Count() > 0) { var targetUsers = ( from users in context.Users join queried in queryResult on users.UserId equals queried.UserId select users ).ToArray(); var targetConfirms = ( from confirms in context.AccountConfirms join queried in queryResult on confirms.ConfirmUri equals queried.TempUri select confirms ).ToArray(); context.Users.RemoveRange(targetUsers); context.AccountConfirms.RemoveRange(targetConfirms); context.SaveChanges(); } }
private void txtSearcher_TextChanged(object sender, TextChangedEventArgs e) { listBoxMattressList.Items.Clear(); if (txtSearcher.Text != null) { using (PgContext context = new PgContext()) foreach (var item in context.Mattresses.Where(m => m.mattressName.StartsWith(txtSearcher.Text)).OrderBy(m => m.mattressName)) { listBoxMattressList.Items.Add(item); } } else { using (PgContext context = new PgContext()) foreach (var item in context.Mattresses.OrderBy(m => m.mattressName)) { listBoxMattressList.Items.Add(item); } } }
//add question on user's demand, if only it is valid public void AddNewQuestion(string text, int answer, int?guessedId) { using (var context = new PgContext()) { context.Questions.Add( new Question() { Text = text, Unforgiveable = false }); context.SaveChanges(); var questionAdded = context.Questions.Single(x => x.Text == text); foreach (var person in context.Persons) { if (person.PersonId != guessedId) { context.Answers.Add( new Answer() { NoCount = 0, PersonId = person.PersonId, QuestionId = questionAdded.QuestionId, YesCount = 0 }); } else { context.Answers.Add( new Answer() { NoCount = answer == 1 ? 0 : 1, PersonId = person.PersonId, QuestionId = questionAdded.QuestionId, YesCount = answer == 1 ? 1 : 0 }); } } context.SaveChanges(); } }
//happens in the end of a game - get information about past game public void UpdateStructures(GameSummary data) { using (var context = new PgContext()) { context.Persons.Single(x => x.Name == data.GuessedGamePerson.Name).Count++; context.SaveChanges(); foreach (var question in data.Entries) { var dbQuestion = context.Questions.Single(x => x.Text == question.QuestionText); var answer = context.Answers.Single(x => x.QuestionId == dbQuestion.QuestionId && x.PersonId == data.GuessedGamePerson.PersonId); answer.NoCount = question.UserAnswer == AnswerType.No ? answer.NoCount + 1 : answer.NoCount; answer.YesCount = question.UserAnswer == AnswerType.Yes ? answer.YesCount + 1 : answer.YesCount; context.SaveChanges(); } } }
public AuthenticationController(IOptions <AppSettings> configuration, PgContext context) { this._config = configuration.Value; this._context = context; }
static void Main(string[] args) { using (var db = new PgContext()) { //var resp = db.CitiesDbSet.Where(x => x.DenominazioneRegione == "Sardegna").FirstOrDefault(); //var r = resp.ToList(); //; //var resp = db.CitiesDbSet.Where(x => x.CodiceRegione == 1).ToList(); var filePath = @"C:/GitHub/Playground/ImportFromExcel/ConsoleApp1/ConsoleApp1/ExcelFile/comuni.xlsx"; FileInfo file = new FileInfo(filePath); using (ExcelPackage package = new ExcelPackage(file)) { StringBuilder sb = new StringBuilder(); ExcelWorksheet worksheet = package.Workbook.Worksheets[1]; int rowCount = worksheet.Dimension.Rows; int ColCount = worksheet.Dimension.Columns; var rawText = string.Empty; //row = 2 to be header skipped for (int row = 2; row <= rowCount; row++) { var city = new Cities(); for (int col = 1; col <= ColCount; col++) { if (worksheet.Cells[row, col].Value == null) { continue; } switch (col) { case 1: city.CodiceRegione = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 2: city.CodiceUnita = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 3: city.CodiceProvincia = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 4: city.ProgressivoComune = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 5: city.CodiceComune = worksheet.Cells[row, col].Value.ToString(); break; case 6: city.DenominazioneItalianaStraniera = worksheet.Cells[row, col].Value.ToString(); break; case 7: city.DenominazioneItaliana = worksheet.Cells[row, col].Value.ToString(); break; case 8: city.DenominazioneAltraLingua = worksheet.Cells[row, col].Value.ToString(); break; case 9: city.CodiceRipartizioneGeografica = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 10: city.RipartizioneGeografica = worksheet.Cells[row, col].Value.ToString(); break; case 11: city.DenominazioneRegione = worksheet.Cells[row, col].Value.ToString(); break; case 12: city.DenominazioneUnita = worksheet.Cells[row, col].Value.ToString(); break; case 13: city.FlagComuneCapoluogo = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 14: city.SiglaAutomobilistica = worksheet.Cells[row, col].Value.ToString(); break; case 15: city.CodiceComuneFormatoNumerico = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 16: city.CodiceComuneNumericoCon110Province = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 17: city.CodiceComuneNumericoCon107Province = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 18: city.CodiceComuneNumericoCon103Province = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 19: city.CodiceCatastale = worksheet.Cells[row, col].Value.ToString(); break; case 20: city.PopolazioneLegale2011 = Convert.ToInt32(worksheet.Cells[row, col].Value); break; case 21: city.Nuts1 = worksheet.Cells[row, col].Value.ToString(); break; case 22: city.Nuts2 = worksheet.Cells[row, col].Value.ToString(); break; case 23: city.Nuts3 = worksheet.Cells[row, col].Value.ToString(); break; } } db.CitiesDbSet.Add(city); } db.SaveChanges(); Console.WriteLine(rawText); } } }
public BookController(IOptions <AppSettings> configuration, PgContext context, IHttpClientFactory clientFactory) { this._config = configuration.Value; this._context = context; this._clientFactory = clientFactory; }
public ProductCategory(PgContext pgContext) { _PgContext = pgContext; }
public TournamentPgRepository() { this.dbContext = new PgContext(); }
public TeamPgRepository() { this.dbContext = new PgContext(); }
public PersonServiceImpl(PgContext context) { _context = context; }