//function for deleting user group public static bool DeleteUserGroup(int UserModeCode) { bool result = false; try { string query = "Delete UserModeTable where UserModeCode=" + UserModeCode; result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("User Role", "Deleted User Role - ID: " + UserModeCode.ToString(), HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
//function for adding user group public static bool AddUserGroup(string UserModeDesc, bool isEnabled) { bool result = false; try { string query = ""; if (isEnabled == true) { query = "Insert into UserModeTable(UserModeDesc,isLoginOverride) values('" + UserModeDesc + "', 1)"; } else { query = "Insert into UserModeTable(UserModeDesc,isLoginOverride) values('" + UserModeDesc + "', 0)"; } result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("User Role", "Added User Role - User Role: " + UserModeDesc, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
//function to log access rights update in audit log public static void LogAccessRightsUpdate(int UserModeCode) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Access Rights", "Updated Access Rights - ID: " + UserModeCode.ToString(), HostName, IP, HttpContext.Current.Session["Username"].ToString()); }
//for deleting equipment group from table public static bool DeleteMachineGroup(string id) { bool result = false; try { string query = ""; query = "select a.ID from EquipmentTable a left join tblEquipmentGroup b on a.EquipID=b.GroupName where b.ID=" + id; DataTable dt_temp = new DataTable(); dt_temp = DBModel.CustomSelectQuery(query); string tempID = ""; if (dt_temp != null) { if (dt_temp.Rows.Count > 0) { foreach (DataRow dr_temp in dt_temp.Rows) { tempID = dr_temp["ID"].ToString(); } query = "delete EquipmentTable where ID=" + tempID; result = DBModel.ExecuteCustomQuery(query); if (result == true) { query = "delete tblEquipmentGroup where ID=" + id; result = DBModel.ExecuteCustomQuery(query); if (result == true) { result = DeleteMachineGroupRelation(id); if (result == true) { query = "delete tblGroupEnrollment where GroupID=" + id; result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Group Settings", "Deleted Equipment Group - ID: " + id, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } } } } } } catch { result = false; } return(result); }
//for deleting equipment group relation from table public static bool DeleteMachineGroupRelation(string id) { bool result = false; try { List <string> lstEquipID = new List <string>(); string query = ""; query = "select EquipID from MachineGroupRelationTable where groupID=" + id; DataTable dt = new DataTable(); dt = DBModel.CustomSelectQuery(query); if (dt != null) { if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { lstEquipID.Add(dr["EquipID"].ToString()); } } } query = "delete MachineGroupRelationTable where groupID=" + id; result = DBModel.ExecuteCustomQuery(query); if (result == true) { if (lstEquipID != null) { if (lstEquipID.Count > 0) { foreach (string temp in lstEquipID) { MarkEquipmentAsUngrouped(temp); } } } string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Group Settings", "Updated Equipment Group Assignment - ID: " + id, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
//for inserting equipment group table public static bool AddMachineGroupRelation(int groupID, int equipID) { bool result = false; try { string query = ""; query = "insert into MachineGroupRelationTable(GroupID,EquipID) values(" + groupID.ToString() + "," + equipID.ToString() + ")"; result = DBModel.ExecuteCustomQuery(query); if (result == true) { query = "select isEnabled from tblEquipmentGroup where ID=" + groupID.ToString(); DataTable dt = new DataTable(); dt = DBModel.CustomSelectQuery(query); bool isEnabled = false; if (dt != null) { if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { isEnabled = Convert.ToBoolean(dr["isEnabled"]); } } } if (isEnabled == true) { result = MarkEquipmentAsGrouped(equipID.ToString()); } else { result = MarkEquipmentAsUngrouped(equipID.ToString()); } string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Group Settings", "Updated Equipment Group Assignment - ID: " + groupID, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
//for updating equipment type table public static bool UpdateEquipmentType(string id, string type, bool isEnabled, bool isSECSGEM) { bool result = false; try { string bit = ""; if (isEnabled == true) { bit = "1"; } else { bit = "0"; } string bit2 = ""; if (isSECSGEM == true) { bit2 = "1"; } else { bit2 = "0"; } string query = "update tblEquipmentType set Type='" + type + "',IsEnabled=" + bit.ToString() + ",IsSECSGEM=" + bit2.ToString() + " where ID=" + id; result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Machine Type", "Updated Machine Type - ID: " + id, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
//for inserting equipment group table public static bool AddMachineGroup(string name, bool isEnabled) { bool result = false; try { string bit = ""; if (isEnabled == true) { bit = "1"; } else { bit = "0"; } string query = "insert into tblEquipmentGroup(GroupName,IsEnabled) values('" + name + "'," + bit.ToString() + ")"; result = DBModel.ExecuteCustomQuery(query); if (result == true) { query = "insert into EquipmentTable(EquipID,EquipType,EquipModel,EquipSerialNum,EquipData,TimeStamp,EquipIP,EquipPort,HostID,DeviceID) values('" + name + "',0,'','','',getdate(),'','','','')"; result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Group Settings", "Added Equipment Group - Name: " + name, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } } catch { result = false; } return(result); }
//for deleting equipment type from table public static bool DeleteEquipmentType(string id) { bool result = false; try { string query = "delete tblEquipmentType where ID=" + id; result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Machine Type", "Deleted Machine Type - ID: " + id, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
public static bool UpdateEnrollment(string ID, string username, string groupID, string host) { bool result = false; try { string query = "Update tblGroupEnrollment set GroupID=" + groupID + ",UserID='" + username + "',HostID='" + host + "' where ID=" + ID.ToString(); result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Group Enrollment", "Updated Group Enrollment - ID: " + ID, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }
//for updating equipment group table public static bool UpdateMachineGroup(string id, string name, bool isEnabled) { bool result = false; try { string bit = ""; if (isEnabled == true) { bit = "1"; } else { bit = "0"; } string query = ""; query = "select a.ID from EquipmentTable a left join tblEquipmentGroup b on a.EquipID=b.GroupName where b.ID=" + id; DataTable dt_temp = new DataTable(); dt_temp = DBModel.CustomSelectQuery(query); string tempID = ""; if (dt_temp != null) { if (dt_temp.Rows.Count > 0) { foreach (DataRow dr_temp in dt_temp.Rows) { tempID = dr_temp["ID"].ToString(); } query = "update EquipmentTable set EquipID='" + name + "' where ID=" + tempID; result = DBModel.ExecuteCustomQuery(query); if (result == true) { query = "update tblEquipmentGroup set GroupName='" + name + "',IsEnabled=" + bit.ToString() + " where ID=" + id; result = DBModel.ExecuteCustomQuery(query); if (result == true) { query = "select EquipID from MachineGroupRelationTable where GroupID=" + id; DataTable dt = new DataTable(); dt = DBModel.CustomSelectQuery(query); if (dt != null) { if (dt.Rows.Count > 0) { foreach (DataRow dr in dt.Rows) { string EquipID = dr["EquipID"].ToString(); if (isEnabled == true) { MarkEquipmentAsGrouped(EquipID); } else { MarkEquipmentAsUngrouped(EquipID); } } } } string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Group Settings", "Updated Equipment Group - ID: " + id, HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } } } } catch { result = false; } return(result); }
//for saving config settings public static bool SaveConfig(bool isSignalR, double tolerance, bool isOPCTimeout, double OPCTimeout, string DefaultPassword, string NoMarkTemplate, bool isScanner, bool isHost, bool isEffectiveDate) { bool result = false; try { DataTable dt = new DataTable(); string query = "select isSignalR, Tolerance, isOPCTimeout, OPCTimeout, DefaultPassword, NoMarkTemplate, isScanner, isHostEnrollment from tblSettings"; dt = DBModel.CustomSelectQuery(query); string bit = ""; if (isSignalR.ToString().ToLower() == "true") { bit = "1"; } else { bit = "0"; } string bit2 = ""; if (isOPCTimeout.ToString().ToLower() == "true") { bit2 = "1"; } else { bit2 = "0"; } string bit3 = ""; if (isScanner.ToString().ToLower() == "true") { bit3 = "1"; } else { bit3 = "0"; } string bit4 = ""; if (isHost.ToString().ToLower() == "true") { bit4 = "1"; } else { bit4 = "0"; } string bit5 = ""; if (isEffectiveDate.ToString().ToLower() == "true") { bit5 = "1"; } else { bit5 = "0"; } if (dt.Rows.Count > 0) { query = "update tblSettings set isSignalR=" + bit.ToString() + "," + "Tolerance=" + tolerance.ToString() + "," + "isOPCTimeout=" + bit2.ToString() + "," + "OPCTimeout=" + OPCTimeout.ToString() + "," + "isScanner=" + bit3.ToString() + "," + "isHostEnrollment=" + bit4.ToString() + "," + "IsEffectiveDate=" + bit5.ToString() + "," + "NoMarkTemplate='" + NoMarkTemplate.ToString().ToUpper() + "'" + "," + "DefaultPassword='******'"; } else { query = "insert into tblSettings(isSignalR,Tolerance,isOPCTimeout,OPCTimeout,NoMarkTemplate,DefaultPassword,isScanner,isHostEnrollment,IsEffectiveDate) values(" + bit.ToString() + "," + tolerance.ToString() + "," + bit2.ToString() + "," + OPCTimeout.ToString() + "," + "'" + NoMarkTemplate.ToString().ToUpper() + "'" + "," + "'" + DefaultPassword.ToString() + "'" + "," + bit3.ToString() + "," + bit4.ToString() + "," + bit5.ToString() + ")"; } result = DBModel.ExecuteCustomQuery(query); if (result == true) { string[] computer_name = Dns.GetHostEntry(HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]).HostName.Split(new Char[] { '.' }); string HostName = computer_name[0].ToString().ToUpper(); string IP = HttpHandler.GetIPAddress(); AuditModel.AddLog("Configuration", "Updated Configuration", HostName, IP, HttpContext.Current.Session["Username"].ToString()); } } catch { result = false; } return(result); }