// public static void LoadRecords() { string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "files//EmployeeRecords.txt"); FileInfo fileInfo = new FileInfo(filePath); if (fileInfo.Exists) { StreamReader f1 = new StreamReader(filePath); string st; string[] buf; while ((st = f1.ReadLine()) != null) { buf = st.Split('|'); EmployeeRecord employee = new EmployeeRecord(); employee.Name = buf[0]; employee.Surname = buf[1]; employee.YearOfBirth = int.Parse(buf[2]); employee.Phone = buf[3]; employee.Id = long.Parse(buf[4]); RecordsRepository.GetRepository().AddRecord(employee); } f1.Close(); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { var data = RecordsRepository.GetRepository().GetAllRecords(); EmployeeGridView.DataSource = data; EmployeeGridView.DataBind(); } }
public static void SaveRecords() { string filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "files//EmployeeRecords.txt"); StreamWriter f = new StreamWriter(filePath); var data = RecordsRepository.GetRepository().GetAllRecords(); foreach (var record in data) { f.WriteLine("{0}|{1}|{2}|{3}|{4}", record.Name, record.Surname, record.YearOfBirth, record.Phone, record.Id); } f.Close(); }
protected void EmployeeGridView_RowDeleting(object sender, GridViewDeleteEventArgs e) { var id = long.Parse(EmployeeGridView.DataKeys[e.RowIndex].Value.ToString()); RecordsRepository.GetRepository().DelRecord(id); var data = RecordsRepository.GetRepository().GetAllRecords(); EmployeeGridView.DataSource = data; EmployeeGridView.DataBind(); EmployeeGridView.Visible = true; FilePersistence.SaveRecords(); }
protected void SortBySurnameAndBirthYear_Click(object sender, EventArgs e) { var data = RecordsRepository.GetRepository().GetAllRecords(); IList <EmployeeRecord> result = data.OrderBy(x => x.Surname).ThenBy(x => x.YearOfBirth).ToList(); data = result; EmployeeGridView.DataSource = data; EmployeeGridView.DataBind(); EmployeeGridView.Visible = true; }
protected void EmployeeGridView_Sorting(object sender, GridViewSortEventArgs e) { var data = RecordsRepository.GetRepository().GetAllRecords(); if (e.SortExpression == "Surname") { IList <EmployeeRecord> result = data.OrderBy(x => x.Surname).ToList(); data = result; } if (e.SortExpression == "YearOfBirth") { IList <EmployeeRecord> result = data.OrderBy(x => x.YearOfBirth).ToList(); data = result; } EmployeeGridView.DataSource = data; EmployeeGridView.DataBind(); EmployeeGridView.Visible = true; }
protected void SubmitEmployeeData_Click(object sender, EventArgs e) { EmployeeRecord record = new EmployeeRecord(); if (TryUpdateModel(record, new FormValueProvider(ModelBindingExecutionContext))) { var allRecords = RecordsRepository.GetRepository().GetAllRecords(); if (allRecords.Any()) { record.Id = RecordsRepository.GetRepository().GetAllRecords().Max(x => x.Id) + 1; } else { record.Id = 0; } RecordsRepository.GetRepository().AddRecord(record); FilePersistence.SaveRecords(); Response.Redirect("Index.aspx"); } }
protected void FindRecords_Click(object sender, EventArgs e) { var allRecords = RecordsRepository.GetRepository().GetAllRecords(); string name = Request.Form["name"].ToLower(); string surname = Request.Form["surname"].ToLower(); string phone = Request.Form["phone"].ToLower(); if (!((name == "") && (surname == "") && (phone == ""))) { var filtered = allRecords.Where(x => ((name == "" ? true : x.Name.ToLower().Contains(name)) && (surname == "" ? true : x.Surname.ToLower().Contains(surname)) && (phone == "" ? true : x.Phone.ToLower().Contains(phone)) )); FoundRecordsGridView.DataSource = filtered; FoundRecordsGridView.DataBind(); } else { FoundRecordsGridView.DataSource = null; FoundRecordsGridView.DataBind(); } }