private void btnSave_Click(object sender, EventArgs e)
        {
            if (_Mode == SubFormMode.Add || _Mode == SubFormMode.Edit)
            {
                if (HasObligatoryNullFields)
                {
                    MessageBox.Show("Заполните все обязательные поля (помечены звездочкой - *)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                _Mode = SubFormMode.View;

                if ((int)goodTableAdapter.ExistsQuery(_ID) > 0 && _Mode != SubFormMode.Add)
                {
                    goodTableAdapter.UpdateQuery(
                        txtName.Text,
                        txtUnit.Text,
                        (float)Convert.ToDouble(txtPrice.Text),
                        _ID);
                }
                else
                {
                    goodTableAdapter.Insert(
                        txtName.Text,
                        txtUnit.Text,
                        (float)Convert.ToDouble(txtPrice.Text));
                    Close();
                }
            }
            else
            {
                _Mode = SubFormMode.Edit;
            }

            SetMode();
        }
        public ViewStorage()
        {
            InitializeComponent();

            _Mode = SubFormMode.Add;


            _Fields = new List <TextBox>();
            _Fields.Add(txtAddress);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_Mode == SubFormMode.Add)
            {
                if (HasObligatoryNullFields)
                {
                    MessageBox.Show("Заполните все обязательные поля (помечены звездочкой - *)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                supplyTableAdapter.InsertQuery(
                    GetID(cbxClient.Text),
                    GetID(cbxCar.Text),
                    GetID(cbxStorage.Text),
                    txtAddress.Text,
                    dateContract.Value.Date.ToShortDateString(),
                    Convert.ToInt32(txtPeriod.Text),
                    cbxShipped.Checked,
                    cbxDelivered.Checked);

                _ID = GetIDByAllAttributes;

                _Mode = SubFormMode.View;
            }
            else if (_Mode == SubFormMode.Edit)
            {
                if (HasObligatoryNullFields)
                {
                    MessageBox.Show("Заполните все обязательные поля (помечены звездочкой - *)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                supplyTableAdapter.UpdateQuery(
                    GetID(cbxClient.Text),
                    GetID(cbxCar.Text),
                    GetID(cbxStorage.Text),
                    txtAddress.Text,
                    dateContract.Value.Date.ToShortDateString(),
                    Convert.ToInt32(txtPeriod.Text),
                    cbxShipped.Checked,
                    cbxDelivered.Checked,
                    _ID);

                _Mode = SubFormMode.View;
            }
            else
            {
                _Mode = SubFormMode.Edit;
            }

            LoadClient();
            LoadCars();
            LoadStorages();
            SetMode();
        }
        public ViewGood()
        {
            InitializeComponent();

            _Mode = SubFormMode.Add;

            _Fields = new List <TextBox>();
            _Fields.Add(txtName);
            _Fields.Add(txtUnit);
            _Fields.Add(txtPrice);
        }
Example #5
0
        public ViewCar()
        {
            InitializeComponent();

            _Mode = SubFormMode.Add;

            _Fields = new List <TextBox>();
            _Fields.Add(txtGov);
            _Fields.Add(txtColor);
            _Fields.Add(txtModel);
        }
        public ViewStorage(int ID, SubFormMode Mode)
        {
            InitializeComponent();

            _ID   = ID;
            _Mode = Mode;
            dgvGoods.Columns[0].ReadOnly = true;

            _Fields = new List <TextBox>();
            _Fields.Add(txtAddress);
        }
        public ViewGood(int ID, SubFormMode Mode)
        {
            InitializeComponent();

            _ID   = ID;
            _Mode = Mode;

            _Fields = new List <TextBox>();
            _Fields.Add(txtName);
            _Fields.Add(txtUnit);
            _Fields.Add(txtPrice);
        }
Example #8
0
        public ViewCar(int ID, SubFormMode Mode)
        {
            InitializeComponent();

            _ID   = ID;
            _Mode = Mode;

            _Fields = new List <TextBox>();
            _Fields.Add(txtGov);
            _Fields.Add(txtColor);
            _Fields.Add(txtModel);
        }
Example #9
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_Mode == SubFormMode.Add || _Mode == SubFormMode.Edit)
            {
                if (HasObligatoryNullFields)
                {
                    MessageBox.Show("Заполните все обязательные поля (помечены звездочкой - *)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                int?driverID;

                if (cbxEmployee.Text == "Нет закрепленного сотрудника")
                {
                    driverID = null;
                }
                else
                {
                    driverID = GetID(cbxEmployee.Text);
                }

                _ID_DRIVER = driverID == null ? -1 : (int)driverID;

                if (_Mode == SubFormMode.Add)
                {
                    carTableAdapter.InsertQuery(driverID,
                                                txtGov.Text,
                                                txtModel.Text,
                                                txtColor.Text);
                    Close();
                }
                else
                {
                    carTableAdapter.UpdateQuery(driverID,
                                                txtGov.Text,
                                                txtModel.Text,
                                                txtColor.Text,
                                                _ID);
                }

                _Mode = SubFormMode.View;
            }
            else
            {
                _Mode = SubFormMode.Edit;
            }

            LoadEmployees();
            SetMode();
        }
Example #10
0
        public ViewClient()
        {
            InitializeComponent();

            _Mode = SubFormMode.Add;

            _Fields = new List <TextBox>();
            _Fields.Add(txtSurname);
            _Fields.Add(txtName);
            _Fields.Add(txtPatron);

            _Fields.Add(txtCompany);
            _Fields.Add(txtAddress);
            _Fields.Add(txtContacts);
        }
Example #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool close = false;

            if (_Mode == SubFormMode.Add || _Mode == SubFormMode.Edit)
            {
                if (HasObligatoryNullFields)
                {
                    MessageBox.Show("Заполните все обязательные поля (помечены звездочкой - *)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                _Mode = SubFormMode.View;

                if (_Mode != SubFormMode.Add)
                {
                    clientTableAdapter.UpdateQuery(
                        txtCompany.Text,
                        txtAddress.Text,
                        txtSurname.Text,
                        txtName.Text,
                        txtPatron.Text,
                        txtContacts.Text,
                        _ID);
                }
                else
                {
                    clientTableAdapter.InsertQuery(
                        txtCompany.Text,
                        txtAddress.Text,
                        txtSurname.Text,
                        txtName.Text,
                        txtPatron.Text,
                        txtContacts.Text);
                    close = true;
                }
            }
            else
            {
                _Mode = SubFormMode.Edit;
            }

            if (close)
            {
                Close();
            }

            SetMode();
        }
Example #12
0
        public ViewEmployee()
        {
            InitializeComponent();

            _Mode = SubFormMode.Add;

            _Fields = new List <TextBox>();
            _Fields.Add(txtSurname);
            _Fields.Add(txtName);
            _Fields.Add(txtPatron);
            _Fields.Add(txtSalary);

            _Fields.Add(txtConvictions);
            _Fields.Add(txtFamily);
            _Fields.Add(txtChildren);
        }
Example #13
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            bool close = false;

            if (_Mode == SubFormMode.Add || _Mode == SubFormMode.Edit)
            {
                if (HasObligatoryNullFields)
                {
                    MessageBox.Show("Заполните все обязательные поля (помечены звездочкой - *)", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                _Mode = SubFormMode.View;

                string dateO;
                if (cbxDischarged.Checked)
                {
                    dateO = dateOut.Value.Date.ToShortDateString();
                }
                else
                {
                    dateO = null;
                }

                if ((int)employeeTableAdapter.ExistsQuery(_ID) > 0 && _Mode != SubFormMode.Add)
                {
                    employeeTableAdapter.UpdateQuery(
                        txtSurname.Text,
                        txtName.Text,
                        txtPatron.Text,
                        dateIn.Value.Date.ToShortDateString(),
                        dateO,
                        (float)Convert.ToDouble(txtSalary.Text),
                        _ID);

                    if (cbxDischarged.Checked)
                    {
                        string        ConnectionString = ConfigurationManager.ConnectionStrings["supplyGood.Properties.Settings.MainDBConnectionString"].ConnectionString;
                        SqlConnection sqlconn          = new SqlConnection(ConnectionString);
                        sqlconn.Open();
                        SqlCommand oda = new SqlCommand("UPDATE Storage SET id_storekeeper=null WHERE id_storekeeper=" + _ID.ToString(), sqlconn);
                        oda.ExecuteNonQuery();
                        oda = new SqlCommand("UPDATE Car SET id_driver=null WHERE id_driver=" + _ID.ToString(), sqlconn);
                        oda.ExecuteNonQuery();
                        sqlconn.Close();
                    }
                }
                else
                {
                    employeeTableAdapter.InsertQuery(
                        txtSurname.Text,
                        txtName.Text,
                        txtPatron.Text,
                        dateIn.Value.Date.ToShortDateString(),
                        dateO,
                        (float)Convert.ToDouble(txtSalary.Text));
                    string        ConnectionString = ConfigurationManager.ConnectionStrings["supplyGood.Properties.Settings.MainDBConnectionString"].ConnectionString;
                    SqlConnection sqlconn          = new SqlConnection(ConnectionString);
                    sqlconn.Open();
                    SqlCommand oda = new SqlCommand("SELECT TOP 1 id FROM Employee ORDER BY id DESC", sqlconn);
                    _ID = Convert.ToInt32(oda.ExecuteScalar());
                    sqlconn.Close();
                    close = true;
                }
                if ((int)personalInfoTableAdapter.ExistsQuery(_ID) > 0 && _Mode != SubFormMode.Add)
                {
                    personalInfoTableAdapter.UpdateQuery(
                        txtFamily.Text,
                        txtChildren.Text,
                        txtConvictions.Text,
                        _ID);
                }
                else
                {
                    personalInfoTableAdapter.Insert(
                        _ID,
                        txtFamily.Text,
                        txtChildren.Text,
                        txtConvictions.Text);
                }
            }
            else
            {
                _Mode = SubFormMode.Edit;
            }

            if (close)
            {
                Close();
            }

            SetMode();
        }
        private void Context_ViewEdit(SubFormMode mode)
        {
            if (_View == TableView.User)
            {
                return;
            }

            try
            {
                var currRowIndex = dgvMain.SelectedCells[0].RowIndex;
                int currID       = Convert.ToInt32(dgvMain.Rows[currRowIndex].Cells[0].Value);
                int currRowOnTop = dgvMain.FirstDisplayedScrollingRowIndex;
                var NextForm     = new Form();

                switch (_View)
                {
                case TableView.Supply:
                {
                    NextForm = new ViewSupply(currID, mode);
                    break;
                }

                case TableView.Good:
                {
                    NextForm = new ViewGood(currID, mode);
                    break;
                }

                case TableView.Car:
                {
                    NextForm = new ViewCar(currID, mode);
                    break;
                }

                case TableView.Storage:
                {
                    NextForm = new ViewStorage(currID, mode);
                    break;
                }

                case TableView.Employee:
                {
                    NextForm = new ViewEmployee(currID, mode);
                    break;
                }

                case TableView.Client:
                {
                    NextForm = new ViewClient(currID, mode);
                    break;
                }
                }

                NextForm.ShowDialog();

                UpdateCurrentData();

                dgvMain.FirstDisplayedScrollingRowIndex = currRowOnTop;
                dgvMain.Rows[currRowIndex].Selected     = true;
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }