/// <summary> /// Event (nastan) koj se povikuva pri PreLoad na sekoja web-strana /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void Page_PreLoad(object sender, EventArgs e) { // TODO: Da se zema od Session HashSet <int> usersSet = (HashSet <int>)HttpContext.Current.Application["usersSet"]; HttpContext.Current.Application.UnLock(); Broker.DataAccess.User user = this.PageUser; Broker.DataAccess.Branch branch = this.PageBranch; if (IsPostBack) { if (user == null) { Response.Redirect(AuthenticationController.ERROR_PAGE + "?errMessage=" + AuthenticationController.SESSION_ERROR_MESSAGE); return; } } if (user == null) { Response.Redirect(AuthenticationController.ERROR_PAGE + "?errMessage=" + AuthenticationController.SESSION_ERROR_MESSAGE); return; } int userId = user.ID; string IpAddress = HttpContext.Current.Request.UserHostAddress; string relativeUrl = Request.ServerVariables["PATH_INFO"].Substring(1); if (!AuthenticationController.IsUserPrivileged(userId, relativeUrl)) { Response.Redirect(AuthenticationController.ERROR_PAGE + "?errMessage=" + AuthenticationController.ERROR_MESSAGE); //Response.Write("Error for "+userId + " "+ relativeUrl+"..redirecting..."); } NBOTreeDataSource treeDataSource = Page.Master.FindControl("NBOTreeDataSource1") as NBOTreeDataSource; treeDataSource.UserID = userId; string sessionId = System.Web.HttpContext.Current.Session.SessionID; if (relativeUrl != "ASUCBroker/Broker/LoggingReport.aspx" && relativeUrl != "ASUCBroker/Broker/LoggingReportQuery.aspx" && relativeUrl != "ASUCBroker/Broker/LoggingReportSelectQuery.aspx" && relativeUrl != "ASUCBroker/Broker/LoggingReportAction.aspx" && relativeUrl != "ASUCBroker/Broker/LoggingReportPagesAndActions.aspx") { using (Broker.LoggingDataAccess.LoggingDataContext dc = new Broker.LoggingDataAccess.LoggingDataContext()) { if (!IsPostBack) { Broker.LoggingDataAccess.DBAccessedPage acPage = new Broker.LoggingDataAccess.DBAccessedPage(); acPage.IpAddress = IpAddress; acPage.UserID = userId; acPage.TimeOfAccess = DateTime.Now; acPage.SessionID = sessionId; acPage.Title = this.Page.Title; acPage.RelativeUrl = relativeUrl; dc.DBAccessedPages.InsertOnSubmit(acPage); dc.SubmitChanges(); Broker.LoggingDataAccess.DBAccessedPageAction newAction = new Broker.LoggingDataAccess.DBAccessedPageAction(); newAction.DBAccessedPage = acPage; //newAction.ControlID = myControl.ID; newAction.TimeAccessed = DateTime.Now; newAction.Action = "Отворил Преглед"; //newAction.ControlNamingContainer = namingControler; //newAction.ControlUniqueID = myControl.UniqueID; newAction.RelativeUrl = relativeUrl; dc.DBAccessedPageActions.InsertOnSubmit(newAction); dc.SubmitChanges(); } if (IsPostBack) { System.Web.UI.Control myControl = GetPostBackControl(this); string tempTitle = myControl.Page.Title; string tempID = string.Empty; if (myControl != null) { string namingControler = string.Empty; if (myControl.NamingContainer != null) { namingControler = myControl.NamingContainer.ID; } if (myControl.ID != null) { string actionText = ""; try { Button btn = (Button)myControl; actionText = btn.Text; } catch { } Broker.LoggingDataAccess.DBAccessedPageAction newAction = new Broker.LoggingDataAccess.DBAccessedPageAction(); Broker.LoggingDataAccess.DBAccessedPage acPage = dc.DBAccessedPages.Where(c => c.UserID == userId && c.SessionID == sessionId).OrderByDescending(c => c.ID).First(); newAction.DBAccessedPage = acPage; newAction.ControlID = myControl.ID; newAction.TimeAccessed = DateTime.Now; if (actionText == string.Empty) { switch (myControl.ID) { case "btnNew": { actionText = "Отворил форма за внес"; break; } case "btnDelete": { actionText = "Отворил форма за бришење"; break; } case "btnEdit": { actionText = "Посетил"; //DetailsView tempControl = FindControl("ctl00$ContentPlaceHolder1$DetailsView1") as DetailsView; //if (tempControl != null) //{ // if (tempControl.SelectedValue != null) // { // tempID = tempControl.SelectedValue.ToString(); // } //} GXGridView tempGV = FindControl("ctl00$ContentPlaceHolder1$GXGridView1") as GXGridView; if (tempGV.SelectedValue != null) { tempID = tempGV.SelectedValue.ToString(); } //if (Session["GXGridView1SelectedValue"] != null) //{ // tempID = Session["GXGridView1SelectedValue"].ToString(); //} break; } case "btnReport": { actionText = "Отворил форма за извештај"; break; } case "btnRepresentationDeal": { actionText = "Отворил форма за Договор - клиенти"; break; } default: { actionText = "Друго"; break; } } } else { switch (actionText) { case "Внеси": { actionText = "Внел/Креирал"; break; } case "Измени": { actionText = "Изменил"; break; } case "Избриши": { actionText = "Избришал"; break; } case "Печати": { actionText = "Испечатил"; break; } case "Нов запис": { if (myControl.ID == "btnNewAccreditation") { actionText = "Отворил форма за внес на нов договор"; } else { actionText = "Запишал"; } break; } case "Откажи": { actionText = "Откажал"; break; } default: break; } } newAction.Action = actionText; newAction.ControlNamingContainer = namingControler; newAction.ControlUniqueID = myControl.UniqueID; newAction.RelativeUrl = relativeUrl; newAction.OpenedFormID = tempID; dc.DBAccessedPageActions.InsertOnSubmit(newAction); dc.SubmitChanges(); } } } } } }
public override void SubmitChanges(ConflictMode failureMode) { var delta = GetChangeSet(); object services = this.GetType().BaseType.GetField("services", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField).GetValue(this); object tracker = services.GetType().GetField("tracker", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField).GetValue(services); System.Collections.IDictionary trackerItems = (System.Collections.IDictionary)tracker.GetType().GetField("items", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField).GetValue(tracker); foreach (System.Collections.DictionaryEntry entry in trackerItems) { EntityBase original = (EntityBase)entry.Value.GetType().GetField("original", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField).GetValue(entry.Value); EntityBase modified = (EntityBase)entry.Key; object asdasd = modified.GetType(); if (!(IsInIgnoreList(modified.GetType().ToString()))) { var columnNames = Mapping.MappingSource .GetModel(typeof(Broker.DataAccess.DataClassesDataContext)) .GetMetaType(modified.GetType()) .PersistentDataMembers; var tempasas = Mapping.MappingSource .GetModel(typeof(Broker.DataAccess.DataClassesDataContext)) .GetMetaType(modified.GetType()).Table.TableName.Last(); using (Broker.LoggingDataAccess.LoggingDataContext dc = new Broker.LoggingDataAccess.LoggingDataContext()) { string sessionID = HttpContext.Current.Session.SessionID; int userID = Convert.ToInt32(HttpContext.Current.Session["UserID"]); Broker.LoggingDataAccess.DBUpdatedTable updatedTable = new LoggingDataAccess.DBUpdatedTable(); updatedTable.TableName = modified.GetType().ToString(); updatedTable.UserID = userID; updatedTable.SessionID = sessionID; updatedTable.TimeOfUpdate = DateTime.Now; Broker.LoggingDataAccess.DBAccessedPage tempPage = dc.DBAccessedPages.Where(c => c.UserID == userID && c.SessionID == sessionID).OrderByDescending(x => x.ID).First(); updatedTable.DBAccessedPageAction = dc.DBAccessedPageActions.Where(c => c.DbAccesedPagesID == tempPage.ID).OrderByDescending(x => x.ID).First(); dc.DBUpdatedTables.InsertOnSubmit(updatedTable); dc.SubmitChanges(); for (int i = 0; i < columnNames.Count; i++) { if (original == null) { //PropertyInfo prOld = original.GetType().GetProperty(columnNames[i].Name); PropertyInfo prNew = modified.GetType().GetProperty(columnNames[i].Name); Type t = prNew.PropertyType; if ((t.IsValueType || t == typeof(string)) && (prNew.CanRead) && (prNew.CanWrite)) { string value = string.Empty; try { value = prNew.GetValue(modified, null).ToString(); } catch { } string oldValue = string.Empty; string tableName = updatedTable.TableName.Split('.').Last() + "s"; var results = dc.ExecuteQuery <int>( @"SELECT ID FROM " + tableName + " ORDER BY ID DESC"); int lastID = results.First(); Broker.LoggingDataAccess.DBUpdatedTableField updatedField = new LoggingDataAccess.DBUpdatedTableField(); updatedField.DBUpdatedTable = updatedTable; updatedField.FieldName = columnNames[i].Name; if (updatedField.FieldName == "ID" && value == "0") { updatedField.Value = (lastID + 1).ToString(); } else { updatedField.Value = value; } updatedField.OldValue = oldValue; dc.SubmitChanges(); } } else { PropertyInfo prOld = original.GetType().GetProperty(columnNames[i].Name); PropertyInfo prNew = modified.GetType().GetProperty(columnNames[i].Name); Type t = prNew.PropertyType; if ((t.IsValueType || t == typeof(string)) && (prNew.CanRead) && (prNew.CanWrite)) { string value = string.Empty; string oldValue = string.Empty; try { value = prNew.GetValue(modified, null).ToString(); } catch { } try { oldValue = prOld.GetValue(original, null).ToString(); } catch { } Broker.LoggingDataAccess.DBUpdatedTableField updatedField = new LoggingDataAccess.DBUpdatedTableField(); updatedField.DBUpdatedTable = updatedTable; updatedField.FieldName = columnNames[i].Name; updatedField.Value = value; updatedField.OldValue = oldValue; dc.SubmitChanges(); } } } } } } base.SubmitChanges(failureMode); }