コード例 #1
0
        public FormRealEstateEditor(RealEstate realEstate)
        {
            InitializeComponent();

            this.realEsate = realEstate;

            numericUpDownRooms.DecimalPlaces = 0;
            numericUpDownRooms.Minimum       = 1;
            numericUpDownRooms.Maximum       = 99;
            numericUpDownFloor.DecimalPlaces = 0;
            numericUpDownFloor.Minimum       = 1;
            numericUpDownFloor.Maximum       = 99;

            textBoxPrice.Text       = "0";
            comboBoxCity.DataSource = Enum.GetValues(typeof(Cities));

            ofd.Title       = "Select profile photo";
            ofd.Filter      = "JPG|*.jpg|PNG|*.png";
            ofd.Multiselect = false;

            textBoxStreet.Text        = realEstate.Street;
            comboBoxCity.SelectedItem = realEstate.City;
            textBoxPrice.Text         = realEstate.Price.ToString();
            numericUpDownFloor.Value  = realEstate.Floor;
            numericUpDownRooms.Value  = realEstate.Rooms;
            textBoxDescription.Text   = realEstate.Description;

            photoSlider            = ImageManip.ByteArrToPhotoSlider(realEstate.PhotoSlider);
            pictureBoxSlider.Image = ImageManip.ByteArrayToImage(photoSlider[photoNumber]);
        }
コード例 #2
0
        private void buttonAddPhoto_Click(object sender, EventArgs e)
        {
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                photo = Image.FromFile(ofd.FileName);
                photo = ImageManip.ResizeImage(photo, new Size(400, 240));
            }

            photoByteArr           = ImageManip.ImageToByteArray(photo);
            pictureBoxSlider.Image = photo;

            photoSlider[photoNumber] = photoByteArr;
        }
コード例 #3
0
        private void buttonNext_Click(object sender, EventArgs e)
        {
            if (photoNumber + 1 >= 5)
            {
                return;
            }
            photoNumber++;
            labelPhotoNumber.Text = $"{photoNumber + 1}/5";

            if (photoSlider[photoNumber] != null)
            {
                pictureBoxSlider.Image = ImageManip.ByteArrayToImage(photoSlider[photoNumber]);
            }
            else
            {
                pictureBoxSlider.Image = ImageManip.ResizeImage(Image.FromFile(noPhotoPath), new Size(400, 240));
            }
        }
コード例 #4
0
        public FormRealEstateCreator()
        {
            InitializeComponent();
            realEstate = new RealEstate();

            numericUpDownRooms.DecimalPlaces = 0;
            numericUpDownRooms.Minimum       = 1;
            numericUpDownRooms.Maximum       = 99;
            numericUpDownFloor.DecimalPlaces = 0;
            numericUpDownFloor.Minimum       = 1;
            numericUpDownFloor.Maximum       = 99;

            Image noPhoto = Image.FromFile(noPhotoPath);

            noPhoto = ImageManip.ResizeImage(noPhoto, new Size(400, 240));
            pictureBoxSlider.Image = noPhoto;

            textBoxPrice.Text       = "0";
            comboBoxCity.DataSource = Enum.GetValues(typeof(Cities));

            ofd.Title       = "Select profile photo";
            ofd.Filter      = "JPG|*.jpg|PNG|*.png";
            ofd.Multiselect = false;
        }
コード例 #5
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            realEsate = db.RealEstate.Single(x => x.Id == realEsate.Id);

            if (String.IsNullOrWhiteSpace(textBoxStreet.Text) ||
                String.IsNullOrWhiteSpace(textBoxPrice.Text) ||
                String.IsNullOrWhiteSpace(textBoxDescription.Text))
            {
                MessageBox.Show("Fields can not be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                realEsate.Street      = textBoxStreet.Text;
                realEsate.Description = textBoxDescription.Text;
                realEsate.Rooms       = Convert.ToInt32(numericUpDownRooms.Value);
                realEsate.Floor       = Convert.ToInt32(numericUpDownFloor.Value);
            }

            Cities city;

            Enum.TryParse(comboBoxCity.SelectedValue.ToString(), out city);
            realEsate.City = city;

            if (FormRealEstateCreator.CheckPrice(textBoxPrice.Text))
            {
                realEsate.Price = Convert.ToInt32(textBoxPrice.Text);
            }
            else
            {
                MessageBox.Show("Invalid price value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool hasPhoto = false;
            int  photoIdx = 0;

            foreach (var arr in photoSlider)
            {
                if (arr != null)
                {
                    if (photoSlider[photoIdx++].GetUpperBound(0) > 1)
                    {
                        hasPhoto = true;
                    }
                }
            }
            if (!hasPhoto)
            {
                MessageBox.Show("Pick at least one photo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            realEsate.PhotoSlider = ImageManip.PhotoSliderToByteArray(photoSlider);

            db.SaveChanges();

            textBoxStreet.Text       = String.Empty;
            textBoxDescription.Text  = String.Empty;
            textBoxPrice.Text        = "0";
            numericUpDownRooms.Value = 1;
            numericUpDownFloor.Value = 1;
            pictureBoxSlider.Image   = null;
            photoNumber           = 0;
            labelPhotoNumber.Text = "1/5";
        }
コード例 #6
0
 private void buttonDeletePhoto_Click(object sender, EventArgs e)
 {
     photoSlider[photoNumber] = null;
     pictureBoxSlider.Image   = ImageManip.ResizeImage(Image.FromFile(noPhotoPath), new Size(400, 240));
 }
コード例 #7
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(textBoxStreet.Text) ||
                String.IsNullOrWhiteSpace(textBoxPrice.Text) ||
                String.IsNullOrWhiteSpace(textBoxDescription.Text))
            {
                MessageBox.Show("Fields can not be empty", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                realEstate.Street      = textBoxStreet.Text;
                realEstate.Description = textBoxDescription.Text;
                realEstate.Rooms       = Convert.ToInt32(numericUpDownRooms.Value);
                realEstate.Floor       = Convert.ToInt32(numericUpDownFloor.Value);
            }

            Cities city;

            Enum.TryParse(comboBoxCity.SelectedValue.ToString(), out city);
            realEstate.City = city;

            if (CheckPrice(textBoxPrice.Text))
            {
                realEstate.Price = Convert.ToInt32(textBoxPrice.Text);
            }
            else
            {
                MessageBox.Show("Invalid price value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            bool hasPhoto = false;

            for (int i = 0; i < photoSlider.Length; ++i)
            {
                if (photoSlider[i] != null)
                {
                    if (photoSlider[i].GetUpperBound(0) > 1)
                    {
                        hasPhoto = true;
                    }
                }
            }
            if (!hasPhoto)
            {
                MessageBox.Show("Pick at least one photo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            realEstate.PhotoSlider = ImageManip.PhotoSliderToByteArray(photoSlider);

            realEstate.Client = db.Clients.FirstOrDefault();

            db.RealEstate.Add(realEstate);
            db.SaveChanges();

            textBoxStreet.Text       = String.Empty;
            textBoxDescription.Text  = String.Empty;
            textBoxPrice.Text        = "0";
            numericUpDownRooms.Value = 1;
            numericUpDownFloor.Value = 1;
            pictureBoxSlider.Image   = null;
            photoByteArr             = null;
            photoSlider           = new byte[5][];
            photoNumber           = 0;
            labelPhotoNumber.Text = "1/5";
        }