public static void DeleteRow(CatalogueItem itemToDelete) { using (SqlConnection connection = new SqlConnection(GetConecctionString().ConnectionString)) { connection.Open(); String sql = @"delete dbo.Goods where Name = @name"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("name", System.Data.SqlDbType.NVarChar).Value = itemToDelete.Name; command.ExecuteNonQuery(); } } }
public override void ViewDidLoad() { item = new CatalogueItem(); CancelButton.Activated += (sender, e) => DismissController(this); AddButton.Activated += (sender, e) => { if (CheckExpressions()) { item.Name = NameField.StringValue; item.Brand = BrandField.StringValue; item.Price = PriceField.IntValue; item.Available = AvailableField.IntValue; item.Description = DescriptionField.Value; //обращение к базе данных на добавление элемента try { SqlClass.AddItemToBase(item); addOne(this, new EventArgs()); DismissViewController(this); } catch { (SqlClass.GetError("Не удалось добавить в БД")).RunModal(); } } else { (SqlClass.GetError("Поля введены не верно")).RunModal(); } }; UploadButton.Activated += (sender, e) => { NSOpenPanel openpanel = new NSOpenPanel(); openpanel.AllowedFileTypes = new string[] { @"jpg" }; openpanel.RunModal(); ImageView.Image = new NSImage(openpanel.Url); if (openpanel.Url.Path != null) { item.Image = File.ReadAllBytes(openpanel.Url.Path); } }; }
public static void EditRow(CatalogueItem itemToEdit) { using (SqlConnection connection = new SqlConnection(GetConecctionString().ConnectionString)) { connection.Open(); String sql = @"update dbo.Goods set Name = @name, Brand = @brand , Price = @price , Available = @available , Description = @description , Picture = @binaryvalue where Name = @name"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("name", System.Data.SqlDbType.NVarChar).Value = itemToEdit.Name; command.Parameters.Add("brand", System.Data.SqlDbType.NVarChar).Value = itemToEdit.Brand; command.Parameters.Add("price", System.Data.SqlDbType.Int).Value = itemToEdit.Price; command.Parameters.Add("available", System.Data.SqlDbType.Int).Value = itemToEdit.Available; command.Parameters.Add("description", System.Data.SqlDbType.NVarChar).Value = itemToEdit.Description; command.Parameters.Add("binaryvalue", System.Data.SqlDbType.VarBinary).Value = itemToEdit.Image; command.ExecuteNonQuery(); } } }
public static void AddItemToBase(CatalogueItem itemToAdd) { using (SqlConnection connection = new SqlConnection(GetConecctionString().ConnectionString)) { connection.Open(); String sql = @"insert dbo.Goods(Name, Brand, Price, Available, Description, Picture) values(@name, @brand, @price, @available, @description ,@binaryvalue);"; using (SqlCommand command = new SqlCommand(sql, connection)) { command.Parameters.Add("name", System.Data.SqlDbType.NVarChar).Value = itemToAdd.Name; command.Parameters.Add("brand", System.Data.SqlDbType.NVarChar).Value = itemToAdd.Brand; command.Parameters.Add("price", System.Data.SqlDbType.Int).Value = itemToAdd.Price; command.Parameters.Add("available", System.Data.SqlDbType.Int).Value = itemToAdd.Available; command.Parameters.Add("description", System.Data.SqlDbType.NVarChar).Value = itemToAdd.Description; command.Parameters.Add("binaryvalue", System.Data.SqlDbType.VarBinary).Value = itemToAdd.Image; command.ExecuteNonQuery(); } } }