private void insertButton_Click(object sender, EventArgs e)
        {
            if (SupplierName.Length == 0)
            {
                MessageBox.Show(String.Format(Messages.ElEMENT_NAME_REQUIRED, EntityNames.SUPPLIER_ENTITY_NAME), Constants.MESSAGE_CAPTION);
                return;
            }

            if (SupplierDataServices.ExistSupplierByName(SupplierName))
            {
                MessageBox.Show(Messages.ELEMENT_EXISTS, Constants.MESSAGE_CAPTION);
                return;
            }

            byte[] photoUploaded = null;
            if (supplierPictureBox.Image != null)
            {
                photoUploaded = PictureViewUtils.ReadImageFromFilePath(openFileDialog1.FileName);
            }


            SupplierDataServices.InsertSupplier(SupplierName, Address, photoUploaded);
            ResetView();
            MessageBox.Show(String.Format(Messages.ELEMENT_INSERT_SUCESS, EntityNames.SUPPLIER_ENTITY_NAME, SupplierName), Constants.MESSAGE_CAPTION);
        }
Example #2
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            if (SelectedSupplier == null)
            {
                return;
            }

            if (SupplierName.Length == 0)
            {
                MessageBox.Show(String.Format(Messages.ElEMENT_NAME_REQUIRED, EntityNames.SUPPLIER_ENTITY_NAME), Constants.MESSAGE_CAPTION);
                return;
            }

            if (SelectedSupplier.Name != SupplierName &&
                SupplierDataServices.ExistSupplierByName(SupplierName))
            {
                MessageBox.Show(Messages.ELEMENT_EXISTS, Constants.MESSAGE_CAPTION);
                return;
            }

            byte[] newUploadPhoto = SelectedSupplier.Photo;
            if (UploadNewPhoto)
            {
                newUploadPhoto = PictureViewUtils.ReadImageFromFilePath(openFileDialog1.FileName);
            }

            var sellerDto = new SupplierDto
            {
                SupplierId = SelectedSupplier.SupplierId,
                Name       = SupplierName,
                Address    = SupplierAddress,
                Photo      = newUploadPhoto
            };

            SupplierDataServices.UpdateSupplier(sellerDto);
            UpdateView(sellerDto);
            MessageBox.Show(string.Format(Messages.ELEMENT_UPDATED_SUCCESS, EntityNames.SUPPLIER_ENTITY_NAME), Constants.MESSAGE_CAPTION);
        }