public void incarca() { using (IstorieEntities context = new IstorieEntities()) { evenimentePanel.Children.Clear(); var query = (from x in context.Evenimentes where x.data.Value.Month == evenimentData.SelectedDate.Value.Month && x.data.Value.Day == evenimentData.SelectedDate.Value.Day select x).ToList(); foreach (var eveniment in query) { Border border = new Border(); border.BorderThickness = new Thickness(1); border.BorderBrush = new SolidColorBrush(Color.FromRgb(0, 0, 0)); border.Margin = new Thickness(2); //TextBloc TextBlock textBlock = new TextBlock(); textBlock.Text = eveniment.data.Value.Year + " : " + eveniment.text; textBlock.TextWrapping = TextWrapping.Wrap; textBlock.Margin = new Thickness(2); //StackPanel All StackPanel stackPanelAll = new StackPanel(); stackPanelAll.Children.Add(textBlock); //StackPanel StackPanel stack = new StackPanel(); stack.Orientation = Orientation.Horizontal; //modifButton Button modifButton = new Button(); modifButton.Width = 80; modifButton.Height = 27; modifButton.Content = "Modifica"; modifButton.Tag = eveniment; modifButton.Click += new RoutedEventHandler(modifButton_Click); modifButton.Margin = new Thickness(2, 0, 10, 2); stack.Children.Add(modifButton); //deleteButton Button deleteButton = new Button(); deleteButton.Width = 80; deleteButton.Height = 27; deleteButton.Content = "Sterge"; deleteButton.Tag = eveniment; deleteButton.Margin = new Thickness(2, 0, 0, 2); deleteButton.Click += new RoutedEventHandler(deleteButton_Click); stack.Children.Add(deleteButton); stackPanelAll.Children.Add(stack); border.Child = stackPanelAll; evenimentePanel.Children.Add(border); } } }
private void connect_bttn_Click(object sender, RoutedEventArgs e) { if (!string.Equals(parolaUtilizator.Password, repetareParolaUtilizator.Password)) { MessageBox.Show("Parola nu sunt identice"); return; } if (string.IsNullOrEmpty(numeUtilizator.Text) || string.IsNullOrWhiteSpace(numeUtilizator.Text) || string.IsNullOrEmpty(parolaUtilizator.Password) || string.IsNullOrWhiteSpace(parolaUtilizator.Password)) { MessageBox.Show("Nu ai introdus numele de utilizator sau parola."); return; } if (dataNasterii.SelectedDate == null) { MessageBox.Show("Nu ati selectat data nasterii."); return; } if (dataNasterii.SelectedDate > DateTime.Now) { MessageBox.Show("Data nasterii este gresita."); return; } using (IstorieEntities context = new IstorieEntities()) { try { int rolul = (bool)elevRadio.IsChecked ? 1 : 2; User user = new User() { name = numeUtilizator.Text, fullName = numeCompletUtilizator.Text, pass = parolaUtilizator.Password, email = emailUtilizator.Text, birthday = dataNasterii.SelectedDate, role = rolul }; context.Users.Add(user); context.SaveChanges(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } MessageBox.Show("Utilizator adaugat"); } }
public void incarcaEvenimente() { using (IstorieEntities context = new IstorieEntities()) { evenimentePanel.Children.Clear(); var query = (from x in context.Evenimentes where x.data.Value.Month == dataEveniment.SelectedDate.Value.Month && x.data.Value.Day == dataEveniment.SelectedDate.Value.Day select x).ToList(); foreach (var eveniment in query) { //TextBlock TextBlock textBlock = new TextBlock(); textBlock.Text = eveniment.data.Value.Year + " : " + eveniment.text; textBlock.TextWrapping = TextWrapping.Wrap; evenimentePanel.Children.Add(textBlock); } } }
private void deleteButton_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Sigur doriti sa stergeti evenimentul?", "Atentie", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { using (IstorieEntities context = new IstorieEntities()) { Button deleteButton = (Button)sender; var entry = context.Entry((Evenimente)deleteButton.Tag); if (entry.State == System.Data.Entity.EntityState.Detached) { context.Evenimentes.Attach((Evenimente)deleteButton.Tag); } context.Evenimentes.Remove((Evenimente)deleteButton.Tag); context.SaveChanges(); MessageBox.Show("Operatiunea s-a realizat cu succes"); incarca(); } } }
private void save_Click(object sender, RoutedEventArgs e) { if (evenimentInitial == null) { using (IstorieEntities context = new IstorieEntities()) { try { Evenimente eveniment = new Evenimente(); DateTime evenimentDateTime = (DateTime)(evenimentData.SelectedDate == null ? DateTime.Now : evenimentData.SelectedDate); int an = 0; int an_1 = evenimentDateTime.Year; try { an = int.Parse(anEveniment.Text.ToString()); } catch (Exception ex) { MessageBox.Show("Anul nu are formatul corespunzator."); return; } evenimentDateTime = evenimentDateTime.AddYears(an); evenimentDateTime = evenimentDateTime.AddYears(-an_1); eveniment.data = evenimentDateTime; TextRange text = new TextRange(textEveniment.Document.ContentStart, textEveniment.Document.ContentEnd); if (text.Text.Length < 10) { MessageBox.Show("Lungimea textului trebuie sa fie mai mare sau egala cu 10"); return; } eveniment.text = text.Text; eveniment.isDHr = (bool)isDHr.IsChecked; context.Evenimentes.Add(eveniment); context.SaveChanges(); MessageBox.Show("Eveniment adaugat cu succes."); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } else { using (IstorieEntities context = new IstorieEntities()) { try { DateTime evenimentDateTime = (DateTime)(evenimentData.SelectedDate == null ? DateTime.Now : evenimentData.SelectedDate); int an = 0; int an_1 = evenimentDateTime.Year; try { an = int.Parse(anEveniment.Text.ToString()); } catch (Exception ex) { MessageBox.Show("Anul nu are formatul corespunzator."); return; } TextRange text = new TextRange(textEveniment.Document.ContentStart, textEveniment.Document.ContentEnd); if (text.Text.Length < 10) { MessageBox.Show("Lungimea textului trebuie sa fie mai mare sau egala cu 10"); return; } var entry = context.Entry(evenimentInitial); if (entry.State == System.Data.Entity.EntityState.Detached) { context.Evenimentes.Attach(evenimentInitial); } evenimentInitial.text = text.Text; evenimentInitial.isDHr = isDHr.IsChecked; evenimentInitial.data = evenimentData.SelectedDate; context.SaveChanges(); MessageBox.Show("Eveniment modificat cu succes."); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }
public void fill() { panel_Intrebari.Children.Clear(); intrebariGrila.Clear(); using (IstorieEntities context = new IstorieEntities()) { var query = (from c in context.Intrebaris select c).ToList(); foreach (var x in query) { int id = int.Parse(x.intrebareId.ToString()); string intrebare = x.text.ToString(); string raspunsuriT = x.raspunsuri.ToString(); string[] raspunsuri = raspunsuriT.Split(new string[] { "[spatiu]" }, StringSplitOptions.RemoveEmptyEntries); string varianteCorecteT_1 = x.varianteCorecte.ToString(); string[] varianteCorect_1 = varianteCorecteT_1.Split(new string[] { "[spatiu]" }, StringSplitOptions.RemoveEmptyEntries); intrebariGrila.Add(new IntrebareGrila(id, intrebare, raspunsuri, varianteCorect_1)); } } //intrebare int contor = 0; foreach (var grila in intrebariGrila) { //INTREBARE Label intrebareTextBox = new Label(); intrebareTextBox.Name = "intrebareTextBox_" + contor; intrebareTextBox.IsEnabled = true; intrebareTextBox.BorderThickness = new Thickness(0); intrebareTextBox.Content = grila.Intrebare; intrebareTextBox.Margin = new Thickness(0, 10, 0, 3); intrebareTextBox.Tag = grila; intrebareTextBox.MouseDoubleClick += new MouseButtonEventHandler(intrebare_DoubleClick); panel_Intrebari.Children.Add(intrebareTextBox); //RASPUNSURI int contorRaspunsuri = 0; foreach (var raspuns in grila.getRaspunsuri()) { TextBox raspunsuTextBox = new TextBox(); raspunsuTextBox.Name = "intrebareTextBox_" + contor + "_" + contorRaspunsuri; raspunsuTextBox.IsEnabled = false; raspunsuTextBox.BorderThickness = new Thickness(0); raspunsuTextBox.Text = raspuns; raspunsuTextBox.Foreground = (SolidColorBrush)(new BrushConverter().ConvertFrom("#000000")); if (grila.returnECorect(contorRaspunsuri) == true) { raspunsuTextBox.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#d2ffc8")); } else { raspunsuTextBox.Background = (SolidColorBrush)(new BrushConverter().ConvertFrom("#ffd3d3")); } raspunsuTextBox.TextWrapping = TextWrapping.Wrap; raspunsuTextBox.Margin = new Thickness(0, 0, 0, 3); panel_Intrebari.Children.Add(raspunsuTextBox); contorRaspunsuri++; } contor++; } }