/// <summary> ///dodanie danych do bazy danych /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { //tboxRent.Text = ""; Income_ManagerEntities context = new Income_ManagerEntities(); var usersadd = context.Table_user; var users = context.Table_user.ToArray(); var t = new Table_user { username = "******", rent = decimal.Parse(tboxRent.Text), food = decimal.Parse(tboxFood.Text), clothes = decimal.Parse(tboxClothes.Text), income = decimal.Parse(tboxIncome.Text) }; usersadd.Add(t); try { context.SaveChanges(); } catch (DbEntityValidationException b) { var errors = b.EntityValidationErrors; } }
private void Button_Click_2(object sender, RoutedEventArgs e) { using (var context = new Income_ManagerEntities()) { var rowClean = context.Database.ExecuteSqlCommand("TRUNCATE TABLE [Table_user]"); //rowClean.All<>; } }
//window itself contains info about author and last change to income /// <summary> /// tymi metodami pokazujemy nowe okna /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { Income_ManagerEntities context = new Income_ManagerEntities(); var users = context.Table_user.ToArray(); foreach (var user in users) { // MessageBox.Show(user.rent.ToString()); } DiagramWindow win1 = new DiagramWindow(); win1.Show(); //should open diagram }
private void LoadBarChartData() { Income_ManagerEntities context = new Income_ManagerEntities(); if (context.Table_user.Count() == 0) { MessageBox.Show("no data!"); } var usersadd = context.Table_user; var users = context.Table_user.ToArray(); int sumOfRent = Convert.ToInt32(context.Table_user.Sum(user => user.rent)); int sumOfFood = Convert.ToInt32(context.Table_user.Sum(user => user.food)); int sumOfClothes = Convert.ToInt32(context.Table_user.Sum(user => user.clothes)); int sumOfIncome = Convert.ToInt32(context.Table_user.Sum(user => user.income)); ((BarSeries)wydatkiChart.Series[0]).ItemsSource = new KeyValuePair <string, int>[] { new KeyValuePair <string, int>("rent", sumOfRent), new KeyValuePair <string, int>("food", sumOfFood), new KeyValuePair <string, int>("clothes", sumOfClothes), new KeyValuePair <string, int>("income", sumOfIncome) }; XMLexport expo = new XMLexport(); expo.createXML(sumOfRent, sumOfFood, sumOfClothes, sumOfIncome); }