public void Update(User model) { User dbUserData = Get(model.Id); if (dbUserData.UserName == model.UserName) { DatabaseUtility.Exec("UPDATE BookUsers SET Name=@Name, Position=@Position, AccessToRegion=@AccessToRegion, AccessToBook=@AccessToBook WHERE Id=@Id", new List <SqlParameter> { new SqlParameter("@Id", model.Id), new SqlParameter("@Name", (object)model.Name ?? DBNull.Value), new SqlParameter("@Position", (object)model.Position ?? DBNull.Value), //new SqlParameter("@UserName", (object)model.UserName ?? DBNull.Value), new SqlParameter("@AccessToRegion", model.AccessToRegion), new SqlParameter("@AccessToBook", model.AccessToBook), }); if (dbUserData.AccessToBook.Equals(model.AccessToBook) || (dbUserData.AccessToRegion.Equals(model.AccessToRegion))) { MessageBox.Show("Права доступа будут применены \nпри следующем входе"); } } else { if (dbUserData.Id.ToString() == Application.Current.Properties["CurrentUserId"].ToString()) { MessageBox.Show("Недопустимо изменение собственного имени входа", "Внимание!", MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (MessageBox.Show($"Пользователь будет пересоздан,\n так как изменилось имя входа в систему \nУдалить старое имя входа?", "Пересоздание пользователя", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { Delete(model); // Удаляем логин старого пользователя TODO: ДОРАБОТАТЬ! Вместо DELETE удалять логин } Set(model); // создаём нового пользователя //TODO: ДОРАБОТАТЬ! Вместо DELETE удалять логин } }
public void Update(VTUPS model) { DatabaseUtility.Exec("UPDATE VTUPS SET " + "UPSId = @UPSId," + "YearUsingSince = @YearUsingSince," + "InventoryNo = @InventoryNo," + "SerialNumber = @SerialNumber," + "Room = @Room," + "Note = @Note," + "OwnerRegion = @OwnerRegion," + "InUse = @InUse," + "DateEdit = GETDATE() WHERE Id = @Id", new List <SqlParameter>() { new SqlParameter("@Id", model.Id), new SqlParameter("@UPSId", model.UPSId), new SqlParameter("@YearUsingSince", model.YearUsingSince), new SqlParameter("@InventoryNo", (object)model.InventoryNo ?? DBNull.Value), new SqlParameter("@SerialNumber", (object)model.SerialNumber ?? DBNull.Value), new SqlParameter("@Room", (object)model.Room ?? DBNull.Value), new SqlParameter("@Note", (object)model.Note ?? DBNull.Value), new SqlParameter("@OwnerRegion", model.OwnerRegion), new SqlParameter("@InUse", model.InUse) }); }
public ObservableCollection <VTPrinter> GetAll(int regionId) { ObservableCollection <VTPrinter> vtPrinters = new ObservableCollection <VTPrinter>(); DataTable vtPrintersTable = (regionId != 25) ? DatabaseUtility.GetTable("SELECT * FROM v_GetPrinters WHERE OwnerRegion IN (" + regionId + ")") : DatabaseUtility.GetTable("SELECT * FROM v_GetPrinters"); foreach (DataRow row in vtPrintersTable.Rows) { VTPrinter vtPrinter = new VTPrinter() { Id = row.Field <int>("Id"), PrinterId = row.Field <int>("PrinterId"), Printer = new Printer() { Id = row.Field <int>("PrinterId"), NamePrinter = row.Field <string>("NamePrinter"), MonoColor = row.Field <bool>("MonoColor"), MFU = row.Field <bool>("MFU"), LaserJet = row.Field <bool>("LaserJet") }, // ниже общие поля для всех моделей VT YearUsingSince = row.Field <int>("YearUsingSince"), InventoryNo = row.Field <string>("InventoryNo"), SerialNumber = row.Field <string>("SerialNumber"), Ip = row.Field <string>("Ip"), Room = row.Field <string>("Room"), Note = row.Field <string>("Note"), OwnerRegion = row.Field <int>("OwnerRegion"), InUse = row.Field <bool>("InUse") }; vtPrinters.Add(vtPrinter); } return(vtPrinters); }
static void Main(string[] args) { int a = DatabaseUtility.ExecStorageProcWithReturnValue("Test", new List <SqlParameter>()); }
private void AccessEditWindow_OnLoaded(object sender, RoutedEventArgs e) { var gridView = new GridView(); gridView.Columns.Add(new GridViewColumn { Header = "Ид", DisplayMemberBinding = new Binding() { Path = new PropertyPath("Id") } }); switch (WorkWith) { case WorkWithVariants.Region: // Выбор данных для региона { gridView.Columns.Add(new GridViewColumn { Header = "Город", DisplayMemberBinding = new Binding() { Path = new PropertyPath("NameCity") } }); string[] regionsAccessArray = AccessString.Split(new char[] { ',' }); foreach (var region in DB.Regions.GetAll()) { AccessCollection.Add(new AccessData() { Id = region.Id, NameCity = region.NameCity, Access = regionsAccessArray.Any(r => r == region.Id.ToString()) }); } AccessEditView.ItemsSource = AccessCollection; break; } case WorkWithVariants.Book: // Выбор данных для справочника { gridView.Columns.Add(new GridViewColumn { Header = "Справочник", DisplayMemberBinding = new Binding() { Path = new PropertyPath("NameBook") } }); string[] bookAccessArray = AccessString.Split(','); ObservableCollection <Book> books = new ObservableCollection <Book>(); DataTable bookTable = DatabaseUtility.GetTable("SELECT * FROM BookBooks"); foreach (DataRow row in bookTable.Rows) { books.Add(new Book() { Id = row.Field <int>("Id"), NameBook = row.Field <string>("NameBook") }); } foreach (var book in books) { AccessCollection.Add(new AccessData() { Id = book.Id, NameBook = book.NameBook, Access = bookAccessArray.Any(r => r == book.Id.ToString()) }); } AccessEditView.ItemsSource = AccessCollection; break; } } DataTemplate dataTemplate = new DataTemplate(); FrameworkElementFactory elementFactory = new FrameworkElementFactory(typeof(CheckBox)); elementFactory.SetBinding(CheckBox.IsCheckedProperty, new Binding() { Path = new PropertyPath("Access"), UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }); dataTemplate.VisualTree = elementFactory; gridView.Columns.Add(new GridViewColumn { Header = "Доступ", CellTemplate = dataTemplate }); AccessEditView.View = gridView; }
private void LoginButton_OnClick(object sender, RoutedEventArgs e) { User user = new User() { UserName = this.UsernameTextBox.Text, UserPassword = this.UserPasswordBox.Password }; //SqlConnection connection = new ServerConnection().ConnectToServer(user); try { string ConnectionString = $"Data Source = {Properties.Settings.Default.ServerHostname}\\{Properties.Settings.Default.SQLInstance};" + $" Persist Security Info = True; " + $"Password = {user.UserPassword};" + $" User ID = {user.UserName};" + $" Initial Catalog = {Properties.Settings.Default.Database}"; DatabaseUtility.OpenConnection(ConnectionString); if (System.Windows.Application.Current.Properties["ConnectionString"] != null) { System.Windows.Application.Current.Properties.Remove("ConnectionString"); } System.Windows.Application.Current.Properties.Add("ConnectionString", ConnectionString); //Получаем из БД информацию о пользователе var extUserDataTable = DatabaseUtility.GetTable("SELECT TOP 1 * FROM dbo.fn_t_GetExtendedUserData()"); if (extUserDataTable.Rows.Count == 0) { Exception ex = new Exception("У пользователя нет доступа к данным ни одного района"); throw ex; } MainWindow main = new MainWindow(); main.CurrentUser = user; main.CurrentUser.Id = extUserDataTable.Rows[0].Field <int>("Id"); main.CurrentUser.AccessToRegion = extUserDataTable.Rows[0].Field <string>("AccessToRegion"); main.CurrentUser.AccessToBook = extUserDataTable.Rows[0].Field <string>("AccessToBook"); main.CurrentUser.Name = extUserDataTable.Rows[0].Field <string>("Name"); System.Windows.Application.Current.Properties.Add("CurrentUserId", main.CurrentUser.Id); this.Close(); main.Show(); } catch (SqlException ex) { switch (ex.Number) { case 18456: { MessageBox.Show("Неверное имя пользователя или пароль"); break; } case -1: { MessageBox.Show("Не удалось найти сервер MSSQL, указанный в настройках\nПроверьте сеть и файл app.config "); break; } case 4060: { MessageBox.Show("Не удалось найти БД, указанную в настройках\nПроверьте файл app.config "); break; } default: { throw ex; } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }