public Group GetGroupByID(int id) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.Groups.SingleOrDefault(ent => ent.GroupID == id)); } }
public bool IsUserInRole(string username, string role) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.Accounts.Any(ent => ent.Username == username && ent.Roles.Any(r => r.RoleName == role))); } }
public PictureView GetByID(int id) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.PictureViews.SingleOrDefault(ent => ent.PictureViewID == id)); } }
public Models.Object GetObjectByID(int id) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.Objects.SingleOrDefault(ent => ent.ObjectID == id)); } }
public AlarmLog GetByID(long id) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.AlarmLogs.SingleOrDefault(ent => ent.AlarmLogID == id)); } }
public bool Update(Logger obj) { bool result = false; using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(new[] { SecurityBLL.ROLE_DATA_EDIT, SecurityBLL.ROLE_DATA_MANAGE }); Validate(obj); obj.LastEditedDate = DateTime.Now; obj.LastEditedUser = AppContext.Current.LogedInUser.Username; entityConntext.AttachUpdatedObject(obj); result = entityConntext.SaveChanges() > 0; } if (result) { if (!obj.AutomaticReadData) { ReaderThreadManager.Current.RemoveThread(obj); } else { ReaderThreadManager.Current.SaveThread(obj); } } return(result); }
public Account GetByUsername(string username) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.Accounts.SingleOrDefault(ent => ent.Username == username)); } }
public void Login(string username, string password) { using (var entityConntext = new GeoViewerEntities()) { string md5Pass = password.GetMd5Hash(); Account obj = entityConntext.Accounts.SingleOrDefault(ent => ent.Username == username); if (obj == null) { throw new Exception(Properties.Resources.Error_Account_AccountNotExist); } if (obj.Password != md5Pass) { throw new Exception(Properties.Resources.Error_Account_PasswordNotMatch); } if (!obj.IsApproved) { throw new Exception(Resources.Error_Account_UnApproved); } if (obj.IsLocked) { throw new Exception(Resources.Error_Account_IsLocked); } _logedInUser = obj; obj.LastLoginDate = DateTime.Now; entityConntext.SaveChanges(); } }
public bool Insert(Logger obj) { bool result = false; using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_DATA_MANAGE); Validate(obj); obj.ProjectID = AppContext.Current.OpenProject.ProjectID; obj.CreatedDate = obj.LastEditedDate = DateTime.Now; obj.CreatedUser = obj.LastEditedUser = AppContext.Current.LogedInUser.Username; entityConntext.Loggers.AddObject(obj); result = entityConntext.SaveChanges() > 0; } // Auto Add Sensor if (result) { DataReaderBLL.Current.ReadHeader(obj.LoggerID); } //foreach (var sensor in obj.Sensors) //{ // obj.CreatedDate = obj.LastEditedDate = DateTime.Now; // obj.CreatedUser = obj.LastEditedUser = AppContext.Current.LogedInUser.Username; //} return(result); }
public Logger GetByID(int id) { using (var entityConntext = new GeoViewerEntities()) { return(entityConntext.Loggers.SingleOrDefault(ent => ent.LoggerID == id)); } }
public bool SetRolesForUser(string userName, string[] roles) { using (var entityConntext = new GeoViewerEntities()) { // Check RootAdmin if (userName == "RootAdmin" && !roles.Contains(ROLE_ACCOUNT_MANAGE)) { throw new Exception(Resources.Error_CannotRemoveAccountRoleOfRootAdmin); } var user = entityConntext.Accounts.FirstOrDefault(ent => ent.Username == userName); if (user != null) { user.Roles.Clear(); foreach (var role in roles) { var r = entityConntext.Roles.SingleOrDefault(ent => ent.RoleName == role); if (r != null) { user.Roles.Add(r); } } return(entityConntext.SaveChanges() > 0); } return(false); } }
private void markUnendedMenuItem_Click(object sender, EventArgs e) { try { using (var entityConntext = new GeoViewerEntities()) { if (logGridView.SelectedRows.Count == 0) { MessageBox.Show(Resources.Warning_NoRecordSelected); return; } long id = 0; for (int i = 0; i < logGridView.SelectedRows.Count; i++) { id = logGridView.SelectedRows[i].Cells["AlarmLogID"].Value.ToInt64TryParse(); var obj = entityConntext.AlarmLogs.SingleOrDefault(ent => ent.AlarmLogID == id); if (obj != null) { obj.IsEnded = false; obj.EndAlarmDatetime = null; } } if (entityConntext.SaveChanges() > 0) { ShowSuccessMessage(string.Format("Đánh dấu chưa kết thúc thành công cho {0} cảnh báo!", logGridView.SelectedRows.Count)); ReloadGrid(); } } } catch (Exception exception) { ShowErrorMessage(exception.Message); } }
private void markAsReadMenuItem_Click(object sender, EventArgs e) { try { using (var entityConntext = new GeoViewerEntities()) { if (logGridView.SelectedRows.Count == 0) { MessageBox.Show(Resources.Warning_NoRecordSelected); return; } long id = 0; for (int i = 0; i < logGridView.SelectedRows.Count; i++) { id = logGridView.SelectedRows[i].Cells["AlarmLogID"].Value.ToInt64TryParse(); var obj = entityConntext.AlarmLogs.SingleOrDefault(ent => ent.AlarmLogID == id); if (obj != null) { obj.LastEditedDate = DateTime.Now; obj.LastEditedUser = AppContext.Current.LogedInUser.Username; } } if (entityConntext.SaveChanges() > 0) { ShowSuccessMessage(string.Format("Đánh dấu đã đọc thành công cho {0} cảnh báo!", logGridView.SelectedRows.Count)); ReloadGrid(); } } } catch (Exception exception) { ShowErrorMessage(exception.Message); } }
public bool Insert(Project obj) { using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_DATA_MANAGE); Validate(obj); entityConntext.Projects.AddObject(obj); return(entityConntext.SaveChanges() > 0); } }
public DateTime?GetLastTime() { using (var entityConntext = new GeoViewerEntities()) { var last = entityConntext.AlarmLogs.OrderByDescending(ent => ent.StartAlarmDatetime).FirstOrDefault(); if (last != null) { return(last.StartAlarmDatetime); } return(null); } }
public bool InsertGroup(Group obj) { using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_VIEWS_MANAGE); ValidateGroup(obj); obj.ProjectID = AppContext.Current.OpenProject.ProjectID; obj.CreatedDate = obj.LastEditedDate = DateTime.Now; obj.CreatedUser = obj.LastEditedUser = AppContext.Current.LogedInUser.Username; entityConntext.Groups.AddObject(obj); return(entityConntext.SaveChanges() > 0); } }
/// <summary> /// Find all loggers which set AutomaticReadData = true and ReadData for it (only new data,calculate value) /// </summary> public void ReadData() { using (var entityConntext = new GeoViewerEntities()) { foreach (var logger in entityConntext.Loggers.Where(ent => ent.AutomaticReadData).ToList()) { int totalRecords; int readRecords; string currentFile; ReadData(logger.LoggerID, true, true, new ReaderProccess()); } } }
//public bool Delete(AlarmLog obj) //{ // using (var entityConntext = new GeoViewerEntities()) // { // SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_ALARM_MANAGE); // entityConntext.AttachUpdatedObject(obj, EntityState.Deleted); // return entityConntext.SaveChanges() > 0; // } //} public bool Delete(long id) { using (var entityConntext = new GeoViewerEntities()) { var obj = entityConntext.AlarmLogs.SingleOrDefault(ent => ent.AlarmLogID == id); if (obj != null) { entityConntext.AlarmLogs.DeleteObject(obj); return(entityConntext.SaveChanges() > 0); } return(false); } }
//public bool Delete(Logger obj) //{ // SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_DATA_MANAGE); // entityConntext.Loggers.DeleteObject(obj); // DataReaderBLL.Current.RemoveThread(obj); // bool result = entityConntext.SaveChanges() > 0; // return result; //} public bool Delete(int id) { using (var entityConntext = new GeoViewerEntities()) { var obj = entityConntext.Loggers.SingleOrDefault(ent => ent.LoggerID == id); if (obj != null) { ReaderThreadManager.Current.RemoveThread(obj); entityConntext.Loggers.DeleteObject(obj); return(entityConntext.SaveChanges() > 0); } return(false); } }
public bool Update(Project obj) { using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(new string[] { SecurityBLL.ROLE_DATA_EDIT, SecurityBLL.ROLE_DATA_MANAGE }); Validate(obj); entityConntext.AttachUpdatedObject(obj); return(entityConntext.SaveChanges() > 0); } }
/// <summary> /// Admin change password of an user /// </summary> /// <param name="user"></param> /// <param name="newPassword"></param> /// <returns></returns> public bool ChangePassword(Account user, string newPassword) { using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(new string[] { SecurityBLL.ROLE_ACCOUNT_EDIT, SecurityBLL.ROLE_ACCOUNT_MANAGE }); user.Password = newPassword.GetMd5Hash(); entityConntext.AttachUpdatedObject(user); return(entityConntext.SaveChanges() > 0); } }
public bool Delete(Account account) { using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_ACCOUNT_MANAGE); // Check RootAdmin if (account.Username == "RootAdmin") { throw new Exception(Resources.Error_CannotDeleteRootAdmin); } entityConntext.AttachUpdatedObject(account, EntityState.Deleted); return(entityConntext.SaveChanges() > 0); } }
public bool Insert(AlarmLog obj) { using (var entityConntext = new GeoViewerEntities()) { Validate(obj); if (AppContext.Current.OpenProject != null) { obj.ProjectID = AppContext.Current.OpenProject.ProjectID; } obj.IsEnded = false; entityConntext.AlarmLogs.AddObject(obj); return(entityConntext.SaveChanges() > 0); } }
public DataTable BindToDataTable(List <Sensor> sensors, bool rawValue = true, DateTime?startDate = null, DateTime?endDate = null) { // fix datetime if (startDate != null) { startDate = new DateTime(startDate.Value.Year, startDate.Value.Month, startDate.Value.Day, 0, 0, 0); } if (endDate != null) { endDate = new DateTime(endDate.Value.Year, endDate.Value.Month, endDate.Value.Day, 23, 59, 59); } using (var entityContext = new GeoViewerEntities()) { DataTable table = new DataTable(); if (sensors == null) { return(table); } var col = table.Columns.Add("MeaTime", typeof(DateTime)); table.PrimaryKey = new DataColumn[] { col }; foreach (var sensor in sensors) { table.Columns.Add(GetColumnName(sensor), typeof(string)); } foreach (var sensor in sensors) { foreach (var value in entityContext.SensorValues.Where(ent => ent.SensorID == sensor.SensorID && (startDate == null || ent.MeaTime >= startDate) && (endDate == null || ent.MeaTime <= endDate) ).ToList()) { var row = table.Rows.Find(value.MeaTime); if (row == null) { row = table.NewRow(); row["MeaTime"] = value.MeaTime; row[GetColumnName(sensor)] = rawValue ? value.RawValue : value.CalcValue; table.Rows.Add(row); } else { row[GetColumnName(sensor)] = rawValue ? value.RawValue : value.CalcValue; } } } return(table); } }
/// <summary> /// LogedIn user changes his password /// </summary> /// <param name="oldPassword"></param> /// <param name="newPassword"></param> /// <returns></returns> public bool ChangePassword(string oldPassword, string newPassword) { using (var entityConntext = new GeoViewerEntities()) { if (AppContext.Current.LogedInUser.Password != oldPassword.GetMd5Hash()) { throw new Exception(Properties.Resources.Error_OldPasswordNotMatch); } AppContext.Current.LogedInUser.Password = newPassword.GetMd5Hash(); entityConntext.AttachUpdatedObject(AppContext.Current.LogedInUser); return(entityConntext.SaveChanges() > 0); } }
public bool Update(AlarmLog obj) { using (var entityConntext = new GeoViewerEntities()) { SecurityBLL.Current.CheckPermissionThrowException(new string[] { SecurityBLL.ROLE_ALARM_EDIT, SecurityBLL.ROLE_ALARM_MANAGE }); Validate(obj); obj.LastEditedDate = DateTime.Now; obj.LastEditedUser = AppContext.Current.LogedInUser.Username; entityConntext.AttachUpdatedObject(obj); return(entityConntext.SaveChanges() > 0); } }
/// <summary> /// Get list of sensors which displayed in this picture view /// </summary> /// <param name="pictureView"></param> /// <returns></returns> public List <Sensor> GetSensorsInPictureView(PictureView pictureView) { using (var entityContext = new GeoViewerEntities()) { var sensors = new List <Sensor>(); foreach (var obj in entityContext.Objects.Where(ent => ent.PictureViewID == pictureView.PictureViewID && ent.Type != OBJECT_TYPE_GROUP_INDICATOR && ent.Type != OBJECT_TYPE_IMAGE)) { var sensor = SensorBLL.Current.GetByID(obj.Parameters.ToInt32TryParse()); if (sensor != null && !sensors.Contains(sensor)) { sensors.Add(sensor); } } return(sensors); } }
private void BindingData() { using (var entityConntext = new GeoViewerEntities()) { accountGridView.DataSource = entityConntext.Accounts.Select(ent => new { ent.Username, ent.Email, ent.FullName, ent.IsApproved, ent.IsLocked, ent.CreatedDate, ent.LastLoginDate }); } }
public void OpenProject(int id) { using (var entityConntext = new GeoViewerEntities()) { var obj = entityConntext.Projects.SingleOrDefault(ent => ent.ProjectID == id); if (obj != null) { AppContext.Current.OpenProject = obj; foreach (var pro in entityConntext.Projects) { pro.IsDefault = false; } obj.IsDefault = true; entityConntext.SaveChanges(); } } }
public bool Delete(long[] ids) { using (var entityConntext = new GeoViewerEntities()) { //SecurityBLL.Current.CheckPermissionThrowException(SecurityBLL.ROLE_ALARM_MANAGE); foreach (var id in ids) { var obj = entityConntext.AlarmLogs.SingleOrDefault(ent => ent.AlarmLogID == id); if (obj != null) { entityConntext.AlarmLogs.DeleteObject(obj); } } return(entityConntext.SaveChanges() > 0); } }