using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace СУБД_Альфапол
{
    public partial class FormAddEdit : Form
    {
        public FormAddEdit()
        {
            InitializeComponent();
        }

        private void FormAddEdit_Load(object sender, EventArgs e)
        {
            this.postCodeTableAdapter.Fill(this.alfafloorGDVDataSet1.PostCode);
            this.streetTableAdapter.Fill(this.alfafloorGDVDataSet1.Street);
            this.cityTableAdapter.Fill(this.alfafloorGDVDataSet1.City);
            this.regionTableAdapter.Fill(this.alfafloorGDVDataSet1.Region);
            this.typePartnerTableAdapter.Fill(this.alfafloorGDVDataSet1.TypePartner);
            this.partnerTableAdapter.Fill(this.alfafloorGDVDataSet1.Partner);
            lblIdPartner.Hide();
            if (lblTitleForm.Text == "Добавление партнера")
            {
                bsPartner.AddNew();
            }    
            
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (tbxNamepartner.Text == "" || tbxEmail.Text == "" || tbxHouse.Text == "" || tbxName.Text == "" || tbxPatronomyc.Text == "" ||
                tbxPhone.Text == "" || tbxRating.Text == "" || tbxSurname.Text == "" || cmbCity.SelectedIndex == -1 || cmbPostCode.SelectedIndex == -1 || cmbRegion.SelectedIndex == -1 || cmbStreet.SelectedIndex == -1 || cmbTypePartner.SelectedIndex == -1)
            {
                MessageBox.Show("Все поля должны быть заполнены!", "Внимание, ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            if (int.Parse(tbxRating.Text) < 0 || tbxRating.Text == "-0")
            {
                MessageBox.Show("Рейтинг целое неотрицательное число!", "Внимание, ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }



            bsPartner.EndEdit();
            this.partnerTableAdapter.Update(this.alfafloorGDVDataSet1.Partner);
            this.Close();
        }

        private void tbxRating_Validating(object sender, CancelEventArgs e)
        {
            try
            {
                int.Parse(tbxRating.Text);
            }
            catch 
            {
                MessageBox.Show("Рейтинг должен быть целым неотрицательным числом!", "Внимание, ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            //if (tbxRating.Text.Contains(','))
            //{

            //}
        }

       
    }
}
