/// <summary> /// On update complete /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataAccess_OnLoad(object sender, EventArgs e) { // Get the data that has been returned. DataAccess.NequeoCompany.Data.User[] returnedDataList = (DataAccess.NequeoCompany.Data.User[])dataAccess.DataModel; DataAccess.NequeoCompany.Data.User data = returnedDataList[0]; // Attach to the property changed event within the model data.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(data_PropertyChanged); SetChangePropertyState(false); // Assign the data to the data context. gridUser.DataContext = data; // Enable the controls. EnableDisable(0); // Load all list items. LoadListItems(); // Start the change (load) process. _loading = true; _addNew = false; // Set the list selected index values. ListSelectedIndex(data); _loading = false; }
/// <summary> /// Before load data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataAccess_OnBeforeLoad(object sender, Custom.OperationArgs e) { // Determine if the data has change. if (PropertyChanged) { // Indicate that the data has changed. MessageBox.Show("The data has changed, please update first", "Load", MessageBoxButton.OK); _updateAttempt = true; e.Cancel = true; } else { // If in Add new state if (_addNew) { // Indicate that the data has changed. MessageBoxResult result = MessageBox.Show("Insert the changes before loading. Disregard the changes (all changes will be lost)?", "Load", MessageBoxButton.YesNo); if (result != MessageBoxResult.Yes) { e.Cancel = true; } } // If loading should take place. if (!e.Cancel) { // Show the selection form Nequeo.Wpf.DataGridWindow selectItem = new DataGridWindow(); selectItem.ConnectionTypeModel = dataAccess.ConnectionTypeModel; selectItem.LoadOnStart = true; selectItem.MaxRecords = 50; selectItem.OrderByClause = "UserID DESC"; selectItem.ShowDialog(); // Has an item been selected. if (selectItem.SelectedRecord != null) { // Get the selected item. DataAccess.NequeoCompany.Data.User data = (DataAccess.NequeoCompany.Data.User)selectItem.SelectedRecord; // Assign the load item. dataAccess.OrderByClause = selectItem.OrderByClause; dataAccess.WhereClause = "UserID = " + data.UserID.ToString(); } else { e.Cancel = true; } } } }
/// <summary> /// Before update data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataAccess_OnBeforeUpdate(object sender, Custom.OperationArgs e) { // Get the binding source data BindingExpression bindingExpression = BindingOperations.GetBindingExpression(txtUserID, TextBox.TextProperty); DataAccess.NequeoCompany.Data.User data = (DataAccess.NequeoCompany.Data.User)bindingExpression.DataItem; // If a previous operation was attempted while // the data was changed an not updated. if (_updateAttempt) { MessageBoxResult result = MessageBox.Show("Disregard the changes (all changes will be lost)?", "Update", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { e.Cancel = true; } } _updateAttempt = false; // Determine if the data has not change. if (!PropertyChanged) { e.Cancel = true; } // Do not update using the default method. e.Cancel = true; // Use the non generic update // to update the user. bool ret = _user.Current.Extension.Update.UpdateItem(data); if (ret) { MessageBox.Show("Update of record succeeded.", "Update"); } else { MessageBox.Show("Update of record un-succeeded.", "Update"); } // If cancel update then set property state. if (e.Cancel) { SetChangePropertyState(false); } EnableDisable(1); }
/// <summary> /// Before insert data. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void dataAccess_OnBeforeInsert(object sender, Custom.OperationArgs e) { // Get the binding source data BindingExpression bindingExpression = BindingOperations.GetBindingExpression(txtUserID, TextBox.TextProperty); DataAccess.NequeoCompany.Data.User data = (DataAccess.NequeoCompany.Data.User)bindingExpression.DataItem; dataAccess.DataModel = data; MessageBoxResult result = MessageBox.Show("Are you sure you wish to insert this record?", "Insert", MessageBoxButton.YesNo); if (result != MessageBoxResult.Yes) { e.Cancel = true; } else { e.Cancel = true; // Use the non generic insert // to insert the user. bool ret = _user.Current.Extension.Insert.InsertItem(data); if (ret) { MessageBox.Show("Insertion of record succeeded.", "Insert"); } else { MessageBox.Show("Insertion of record un-succeeded.", "Insert"); } EnableDisable(2); _loading = false; _addNew = false; } }
/// <summary> /// Main window /// </summary> public MainWindow() { InitializeComponent(); // Inject the data access services. invoice.CustomerDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.ICustomer>(); customer.CustomerDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.ICustomer>(); product.ProductDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IProduct>(); vendor.VendorDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IVendor>(); employee.EmployeeDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IEmployee>(); account.AccountDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IAccount>(); company.CompanyDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.ICompany>(); asset.AssetDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IAsset>(); Service.NequeoCompany.IUser user = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IUser>(); management.User = user; management.ManageDataSource = Service.NequeoCompany.ServiceLocator.Current.Resolve <Service.NequeoCompany.IManage>(); // Open the login page. UI.Security.Login login = new UI.Security.Login(); login.ShowDialog(); string username = login.Username; string domain = login.Domain; // Get the result if (login.DialogResult.HasValue && login.DialogResult.Value) { // Valaidate the user. DataAccess.NequeoCompany.Data.User userData = null; // While the user has not been validated. while (userData == null) { // If data has been returned then valid. userData = user.ValidateUser(login.Username, login.Password); if (userData != null) { // Get the user type. Common.Helper.UserType = (DataAccess.NequeoCompany.Enum.EnumUserType) Enum.Parse(typeof(DataAccess.NequeoCompany.Enum.EnumUserType), userData.UserType); // If the user has been suspended. if (userData.Suspended) { tabControlNequeo.IsEnabled = false; } break; } login = new UI.Security.Login(); login.Username = username; login.Domain = domain; login.ShowDialog(); username = login.Username; domain = login.Domain; // If cancelled. if (!login.DialogResult.HasValue || !login.DialogResult.Value) { tabControlNequeo.IsEnabled = false; break; } } } else { // Do not allow any interaction. tabControlNequeo.IsEnabled = false; } }