private void buttonSave_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxName.Text)) { MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } try { if (id.HasValue) { service.UpdStorage(new StorageBindingModel { Id = id.Value, StorageName = textBoxName.Text }); } else { service.AddStorage(new StorageBindingModel { StorageName = textBoxName.Text }); } MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); DialogResult = DialogResult.OK; Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Заведем в базу первоначальные данные при первой загрузке приложения /// </summary> public void Initialize() { if (_storageService.GetAll().Count != 0) { return; } var storage = _storageService.AddStorage(new Storage { Name = "Основной склад" }); if (storage.Id == 0) { throw new Exception("Ошибка при инициализации данных в базе: не удалось создать склад"); } //заполнить единицы измерения var units = FillUnits(); //заполнить возможные продукты var products = FillProducts(units); //заполнить правило реализации товара (цены реализации) FillRuleSales(products); //заполнить типы операции var operationTypes = FillOperationTypes(); //заполнить типы документа var documentTypes = FillDocumentTypes(); //---Создадим поступление товара //задать операцию поступления по документу (Приход) var operationTypeId = operationTypes.FirstOrDefault(f => f.IsDebit)?.Id; //задать тип документа var documentTypeId = documentTypes.FirstOrDefault(f => f.Name.Equals("Поступление", StringComparison.CurrentCultureIgnoreCase))?.Id; //Создать первый документ поступления CreateDocumentReceipt(documentTypeId, PrepareOperationsArrivalVar1(products, storage.Id, operationTypeId)); //Создать второй документ поступления CreateDocumentReceipt(documentTypeId, PrepareOperationsArrivalVar2(products, storage.Id, operationTypeId)); //Создать третий документ поступления CreateDocumentReceipt(documentTypeId, PrepareOperationsArrivalVar3(products, storage.Id, operationTypeId)); }