public EditWindow(Student student) { _localStudents = XMLContext.StudentsToList(StaticData.Path); CreateButton.Content = "Edit"; _student = student; Title = "Edit"; Loaded += On_WindowLoaded; }
public virtual void Action_Click(object sender, RoutedEventArgs e) { Model.Student student = new Model.Student(); student.FirstName = NameTextBox.Text; student.LastName = LastNameTextBox.Text; if (GenderComboBox.Text == "Male") { student.Gender = Gender.Male; } else { student.Gender = Gender.Female; } try { student.Age = Convert.ToInt32(AgeTextBox.Text); } catch (Exception) { NameValidationTextBlock.Text = "Age must contain only digits."; return; } if (ModelValidation.Validate(student).Count() == 0) { List <Student> localStudent = XMLContext.StudentsToList(StaticData.Path); if (localStudent.Count != 0) { student.Id = localStudent.OrderBy(s => s.Id).LastOrDefault().Id++; } else { student.Id = 0; } localStudent.Add(student); XMLContext.StudentsToXML(localStudent, StaticData.Path); MessageBox.Show($"New student:\nName:{student.FirstName}\nLast Name:{student.LastName}\nAge: {student.Age}\nCreated", "Created", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } else { StringBuilder warning = new StringBuilder(); foreach (var item in ModelValidation.Validate(student)) { warning.AppendLine(item); } NameValidationTextBlock.Text = warning.ToString(); return; } }
protected void RadGrid1_DeleteCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { GridDataItem editForm = (GridDataItem)e.Item; XMLContext context = new XMLContext(); XDocument document = context.LoadDocument(GetPath()); List <XElement> ordersTable = context.GetTable(document, "Orders").ToList(); string orderID = editForm.GetDataKeyValue(RadGrid1.MasterTableView.DataKeyNames[0]).ToString(); XElement orderToDelete = (from order in ordersTable where order.Attribute("OrderID").Value == orderID select order).FirstOrDefault(); context.DeleteElement(ordersTable, orderToDelete); context.SaveChanges(document, GetPath()); }
public override void Action_Click(object sender, RoutedEventArgs e) { _student.FirstName = NameTextBox.Text; _student.LastName = LastNameTextBox.Text; if (GenderComboBox.Text == "Male") { _student.Gender = Gender.Male; } else { _student.Gender = Gender.Female; } try { _student.Age = Convert.ToInt32(AgeTextBox.Text); } catch (Exception) { NameValidationTextBlock.Text = "Age must contain only digits."; return; } if (ModelValidation.Validate(_student).Count() == 0) { _localStudents.Remove(_localStudents.Find(s => s.Id == _student.Id)); _localStudents.Add(_student); XMLContext.StudentsToXML(_localStudents, StaticData.Path); MessageBox.Show($"Student databse updated:\nName:{_student.FirstName}\nLast Name:{_student.LastName}\nAge: {_student.Age}", "Edinted", MessageBoxButton.OK, MessageBoxImage.Information); this.Close(); } else { StringBuilder warning = new StringBuilder(); foreach (var item in ModelValidation.Validate(_student)) { warning.AppendLine(item); } NameValidationTextBlock.Text = warning.ToString(); return; } }
static void Main(string[] args) { TestDbContext db = new ScoreBoardEx.TestDbContext(); foreach (var item in db.getTop(5)) { Console.WriteLine("{0}", item.GamerTagScore); } XMLContext games = new XMLContext("BoardGames.xml"); foreach (var item in XMLContext.BoardGames) { Console.WriteLine("{0}", item.GameData); } Console.ReadKey(); }
protected void RadGrid1_InsertCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { GridEditFormItem editForm = (GridEditFormItem)e.Item; Hashtable newValues = new Hashtable(); XMLContext context = new XMLContext(); XDocument document = context.LoadDocument(GetPath()); List <XElement> ordersTable = context.GetTable(document, "Orders").ToList(); //Extract the new values from the editor controls editForm.ExtractValues(newValues); XElement orderToInsert = new XElement("Order"); int orderID = int.Parse((from order in ordersTable select order).LastOrDefault().Attribute("OrderID").Value); orderToInsert.Add(new XAttribute("OrderID", ++orderID)); context.InsertElement(document, ApplyChanges(orderToInsert, newValues), "Orders"); context.SaveChanges(document, GetPath()); }
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e) { XMLContext context = new XMLContext(); XDocument document = context.LoadDocument(GetPath()); List <XElement> ordersTable = context.GetTable(document, "Orders").ToList(); //RadGrid1.VirtualItemCount = ordersTable.Count(); var gridSource = (from order in ordersTable select new { OrderID = order.Attribute("OrderID").Value, CustomerID = order.Element("CustomerID").Value, OrderDate = order.Element("OrderDate").Value, Freight = order.Element("Freight").Value, ShipName = order.Element("ShipName").Value, ShipCity = order.Element("ShipCity").Value, ShipCountry = order.Element("ShipCountry").Value }); RadGrid1.DataSource = gridSource.Skip(RadGrid1.CurrentPageIndex).Take(RadGrid1.PageSize); }
protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { GridEditFormItem editForm = (GridEditFormItem)e.Item; Hashtable newValues = new Hashtable(); XMLContext context = new XMLContext(); XDocument document = context.LoadDocument(GetPath()); List <XElement> ordersTable = context.GetTable(document, "Orders").ToList(); //Extract the new values from the editor controls editForm.ExtractValues(newValues); //Get the "Primary key" value that will be used to perform CRUD operations string orderID = editForm.GetDataKeyValue(RadGrid1.MasterTableView.DataKeyNames[0]).ToString(); //Get a reference to the modified record XElement orderToUpdate = (from order in ordersTable where order.Attribute("OrderID").Value == orderID select order).FirstOrDefault(); context.UpdateElement(ordersTable, ApplyChanges(orderToUpdate, newValues)); context.SaveChanges(document, GetPath()); ; }
private void DeleteBtn_Click(object sender, RoutedEventArgs e) { if (StudentsDataGrid.SelectedItems != null) { var student = StudentsDataGrid.SelectedItems; if (student.Count > 1) { MessageBoxResult result = System.Windows.MessageBox.Show("Do you really want to delete more than one record?", "Multiple Delete", MessageBoxButton.OKCancel, MessageBoxImage.Warning, MessageBoxResult.Cancel); if (result == MessageBoxResult.OK) { List <int> DeleteId = new List <int>(); var studentLocal = XMLContext.StudentsToList(StaticData.Path); foreach (var item in student) { studentLocal.Remove(studentLocal.Find(s => s.Id == (item as Student).Id)); } XMLContext.StudentsToXML(studentLocal, StaticData.Path); } } else { Student studentModel = new Student(); studentModel = (Student)StudentsDataGrid.SelectedItem; var studentLocal = XMLContext.StudentsToList(StaticData.Path); studentLocal.Remove(studentLocal.Find(s => s.Id == studentModel.Id)); XMLContext.StudentsToXML(studentLocal, StaticData.Path); } } DataContext = new StudentsViewModel(); }
public EditWindow() : base() { CreateButton.Content = "Edit"; _localStudents = XMLContext.StudentsToList(StaticData.Path); }