private void SaveBt_Click(object sender, EventArgs e) { WaresLogic wares = new WaresLogic(manager); WareCodesLogic codes = new WareCodesLogic(manager); string name = NameTB.Text; int? categoryId = null; if (CategoriesCB.SelectedIndex > 0) { categoryId = Convert.ToInt32(CategoriesCB.SelectedValue); } int?manufacturerId = null; if (ManufacturersCB.SelectedIndex > 0) { manufacturerId = Convert.ToInt32(ManufacturersCB.SelectedValue); } int unitId = Convert.ToInt32(UnitsCB.SelectedValue); int? secondaryUnitId = null; decimal?secondaryUnitQuantity = null; if (SecondaryUnitsCB.SelectedIndex > 0) { secondaryUnitId = Convert.ToInt32(SecondaryUnitsCB.SelectedValue); secondaryUnitQuantity = Convert.ToDecimal(SecondaryQuantityNUD.Value); } Model.Ware ware = null; if (mode == "new") { ware = wares.Create(NameTB.Text, unitId, 0, manufacturerId, categoryId, secondaryUnitId, secondaryUnitQuantity); } if (mode == "edit") { ware = wares.Update(Convert.ToInt32(id), NameTB.Text, unitId, manufacturerId, categoryId, secondaryUnitId, secondaryUnitQuantity); foreach (string code in codesListForDelete) { codes.Delete(Convert.ToInt32(id), code); } } foreach (string code in codesList) { codes.Create(ware, code); } manager.Save(); this.Close(); }
private void SaveBt_Click(object sender, EventArgs e) { WaresLogic wares = new WaresLogic(manager); WareCodesLogic codes = new WareCodesLogic(manager); string name = NameTB.Text; int? categoryId = null; if (CategoriesCB.SelectedIndex > 0) { categoryId = Convert.ToInt32(CategoriesCB.SelectedValue); } int?manufacturerId = null; if (ManufacturersCB.SelectedIndex > 0) { manufacturerId = Convert.ToInt32(ManufacturersCB.SelectedValue); } int unitId = Convert.ToInt32(UnitsCB.SelectedValue); int? secondaryUnitId = null; decimal?secondaryUnitQuantity = null; decimal timeLimit = 0; timeLimit = TimeLimitNUD.Value; if (SecondaryUnitsCB.SelectedIndex > 0) { secondaryUnitId = Convert.ToInt32(SecondaryUnitsCB.SelectedValue); secondaryUnitQuantity = Convert.ToDecimal(SecondaryQuantityNUD.Value); } Model.Ware ware = null; //зберігаємо код якщо він введений в текстове поле, а інших кодів немає if ((codesList.Count == 0) & (CodeTB.Text.Trim().Length > 0)) { codesList.Add(CodeTB.Text.Trim()); codesListForDelete.Remove(CodeTB.Text.Trim()); } if (mode == "new") { if (openFileDialog1.CheckPathExists == true) { image = Helpers.ImageOperations.ConvertImageToByteArray(openFileDialog1.FileName); } ware = wares.Create(NameTB.Text, unitId, 0, manufacturerId, categoryId, secondaryUnitId, secondaryUnitQuantity, image); } if (mode == "edit") { if (_image != null) { image = Helpers.ImageOperations.ImageToByteArray(_image); } else { image = null; } ware = wares.Update(Convert.ToInt32(id), NameTB.Text, unitId, manufacturerId, categoryId, secondaryUnitId, secondaryUnitQuantity, image); foreach (string code in codesListForDelete) { codes.Delete(Convert.ToInt32(id), code); } } foreach (string code in codesList) { if (codes.CodeForOtherWareExists(id, code) == false) { codes.Create(ware, code); } else { MessageBox.Show("Введений код " + code + " вже існує і не був збережений"); } } WareTimeLimitsLogic timeLimits = new WareTimeLimitsLogic(manager); timeLimits.Create(ware, Convert.ToDecimal(TimeLimitNUD.Value), true); manager.Save(); if (AddComponentsCB.Checked == true) { Wares.Ware.WareComponentData form = new Wares.Ware.WareComponentData("edit", Convert.ToInt32(ware.ID)); form.ShowDialog(); } this.Close(); }
private void SaveBt_Click(object sender, EventArgs e) { WaresLogic wares = new WaresLogic(manager); WareCodesLogic codes = new WareCodesLogic(manager); string name = NameTB.Text; int? categoryId = null; if (CategoriesCB.SelectedIndex > 0) categoryId = Convert.ToInt32(CategoriesCB.SelectedValue); int? manufacturerId = null; if (ManufacturersCB.SelectedIndex > 0) manufacturerId = Convert.ToInt32(ManufacturersCB.SelectedValue); int unitId = Convert.ToInt32(UnitsCB.SelectedValue); int? secondaryUnitId = null; decimal? secondaryUnitQuantity = null; decimal timeLimit = 0; timeLimit = TimeLimitNUD.Value; if (SecondaryUnitsCB.SelectedIndex > 0) { secondaryUnitId = Convert.ToInt32(SecondaryUnitsCB.SelectedValue); secondaryUnitQuantity = Convert.ToDecimal(SecondaryQuantityNUD.Value); } Model.Ware ware = null; //зберігаємо код якщо він введений в текстове поле, а інших кодів немає if ((codesList.Count == 0) & (CodeTB.Text.Trim().Length > 0)) { codesList.Add(CodeTB.Text.Trim()); codesListForDelete.Remove(CodeTB.Text.Trim()); } if (mode == "new") { if (openFileDialog1.CheckPathExists == true) image = Helpers.ImageOperations.ConvertImageToByteArray(openFileDialog1.FileName); ware = wares.Create(NameTB.Text, unitId, 0, manufacturerId, categoryId, secondaryUnitId, secondaryUnitQuantity,image); } if (mode == "edit") { if (_image != null) image = Helpers.ImageOperations.ImageToByteArray(_image); else image = null; ware = wares.Update(Convert.ToInt32(id), NameTB.Text, unitId, manufacturerId, categoryId, secondaryUnitId, secondaryUnitQuantity, image); foreach (string code in codesListForDelete) { codes.Delete(Convert.ToInt32(id), code); } } foreach (string code in codesList) { if (codes.CodeForOtherWareExists(id, code) == false) codes.Create(ware, code); else MessageBox.Show("Введений код " + code + " вже існує і не був збережений"); } WareTimeLimitsLogic timeLimits = new WareTimeLimitsLogic(manager); timeLimits.Create(ware, Convert.ToDecimal(TimeLimitNUD.Value), true); manager.Save(); if (AddComponentsCB.Checked == true) { Wares.Ware.WareComponentData form = new Wares.Ware.WareComponentData("edit", Convert.ToInt32(ware.ID)); form.ShowDialog(); } this.Close(); }