/// <summary> /// Получение данных из БД, для дальнейшей работы с ними /// </summary> public void loadData(Firm frm) { ConnectionStringSettings connSetting = ConfigurationManager.ConnectionStrings["LocalDB"]; if (connSetting == null || string.IsNullOrEmpty(connSetting.ConnectionString)) { throw new Exception("Fatal error: missing connecting string in web.config file"); } string connectionString = connSetting.ConnectionString; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); string queryString = "SELECT * FROM Employeers"; SqlCommand command = new SqlCommand(queryString, connection); SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { string _surname = reader["Surname"].ToString(); string _name = reader["Name"].ToString(); string _patronymic = reader["Patronymic"].ToString(); string _department = reader["DepartmentId"].ToString(); frm.personList.Add(new Person(_surname, _name, _patronymic, _department)); } reader.Close(); queryString = "SELECT * FROM Department"; command.CommandText = queryString; reader = command.ExecuteReader(); while (reader.Read()) { int _id = (int)reader["Id"]; string _depName = reader["Name"].ToString(); frm.departmentList.Add(new Department(_id, _depName)); } command.Dispose(); reader.Dispose(); } }
public HomeModule() { Get["/"] = x => { return(View["FirstPage"]); }; Get["/FirstPage.html"] = x => { return(View["FirstPage"]); }; Get["/SeconfPage.html"] = x => { return(View["SeconfPage"]); }; ///Позвращает клиенту строку с данными о сотрудниках в html-формате Get["/ajax_employeers_get_list"] = x => { string result = ""; try { string separator = this.Request.Query.separator; DbModel db = new DbModel(); Firm firm = new Firm(separator); db.loadData(firm); result = firm.printWorkersByDepartments(); } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } return(result); }; ///Позвращает клиенту строку с данными о сотрудниках в json-формате Get["/ajax_employeers_bind"] = x => { DbModel db = new DbModel(); string result = db.selectEmployeersToJson(); return(result); }; ///Позвращает клиенту строку с данными о сотрудниках в json-формате Get["/ajax_departments"] = x => { DbModel db = new DbModel(); string result = db.selectDepartmentsToJson(); return(result); }; ///Обновление данных Post["/ajax_employeers_bind"] = x => { var jsonString = this.Request.Body.AsString(); Person p = JsonConvert.DeserializeObject <Person>(jsonString); DbModel db = new DbModel(); db.updateEmployee(p); return(""); }; ///Добавление новой записи Post["/ajax_employeers_add"] = x => { var jsonString = this.Request.Body.AsString(); Person p = JsonConvert.DeserializeObject <Person>(jsonString); DbModel db = new DbModel(); db.insertEmployee(p); return(""); ; }; }