示例#1
0
        private void btnSave_Click(object sender, EventArgs e) // Кнопка Сохранить
        {
            var tablePutevoi = new AutoparkDBTableAdapters.PutevoiListLegkTableAdapter();
            var tableDannie  = new AutoparkDBTableAdapters.PutListLegkovogoDannieTableAdapter();

            if (_modeIsNew)
            {
                PutevoiId = int.Parse(tablePutevoi.InsertQuery(int.Parse(txtNumber.Text), dtpStart.Value, dtpEnd.Value,
                                                               int.Parse(((DataRowView)_bindingAuto[cbNomerAuto.SelectedIndex]).Row.ItemArray[0].ToString()),
                                                               int.Parse(
                                                                   ((DataRowView)_bindingVoditel[cbVodUdostoverenie.SelectedIndex]).Row.ItemArray[0].ToString()),
                                                               int.Parse(((DataRowView)_bindingOtdel[cbOtdel.SelectedIndex]).Row.ItemArray[0].ToString())).ToString());
                _bindingDannie.DataSource     = tableDannie.GetDataById(PutevoiId);
                dgvPutevieLegkovie.DataSource = _bindingDannie;
                var dataGridViewColumn = dgvPutevieLegkovie.Columns["ID_Путевого листа"];
                if (dataGridViewColumn != null)
                {
                    dataGridViewColumn.Visible = false;
                }
                dataGridViewColumn = dgvPutevieLegkovie.Columns["id_Данных"];
                if (dataGridViewColumn != null)
                {
                    dataGridViewColumn.Visible = false;
                }
                var res = tablePutevoi.GetDataByID(PutevoiId).ToList();
                _number    = res[0].Номер_путевого_листа;
                _idauto    = res[0].ID_Автомобиль;
                _idvod     = res[0].ID_Водитель;
                _idotd     = res[0].ID_Отдела;
                _dateStart = res[0].За_период_с;
                _dateEnd   = res[0].За_период_по;
                _modeIsNew = false;
            }
            else
            {
                tablePutevoi.Update(int.Parse(txtNumber.Text), dtpStart.Value, dtpEnd.Value,
                                    int.Parse(((DataRowView)_bindingAuto[cbNomerAuto.SelectedIndex]).Row.ItemArray[0].ToString()),
                                    int.Parse(
                                        ((DataRowView)_bindingVoditel[cbVodUdostoverenie.SelectedIndex]).Row.ItemArray[0].ToString()),
                                    int.Parse(((DataRowView)_bindingOtdel[cbOtdel.SelectedIndex]).Row.ItemArray[0].ToString()),
                                    PutevoiId, _number, _dateStart, _dateEnd, _idauto, _idvod, _idotd);

                tableDannie.Update((AutoparkDB.Данные_Путевой_лист_легкового_автоDataTable)_bindingDannie.DataSource);
                //_bindingDannie.DataSource = tableDannie.GetData();
                _bindingDannie.Filter         = "[ID_Путевого листа] = " + PutevoiId;
                dgvPutevieLegkovie.DataSource = _bindingDannie;
                _number = int.Parse(txtNumber.Text);
                _idauto = int.Parse(((DataRowView)_bindingAuto[cbNomerAuto.SelectedIndex]).Row.ItemArray[0].ToString());
                _idvod  =
                    int.Parse(
                        ((DataRowView)_bindingVoditel[cbVodUdostoverenie.SelectedIndex]).Row.ItemArray[0].ToString());
                _idotd     = int.Parse(((DataRowView)_bindingOtdel[cbOtdel.SelectedIndex]).Row.ItemArray[0].ToString());
                _dateStart = dtpStart.Value;
                _dateEnd   = dtpEnd.Value;
            }
            btnCancel.Visible = false;
        }
示例#2
0
        public PutListLegkovogoavto(int id)
        {
            InitializeComponent();
            PrepareComboBoxDataSources();

            _modeIsNew = false;
            PutevoiId  = id;

            var tableDannie = new AutoparkDBTableAdapters.PutListLegkovogoDannieTableAdapter();

            _bindingDannie.DataSource     = tableDannie.GetData();
            _bindingDannie.Filter         = "[ID_Путевого листа] = " + PutevoiId;
            dgvPutevieLegkovie.DataSource = _bindingDannie;

            var dataGridViewColumn = dgvPutevieLegkovie.Columns["ID_Путевого листа"];

            if (dataGridViewColumn != null)
            {
                dataGridViewColumn.Visible = false;
            }
            dataGridViewColumn = dgvPutevieLegkovie.Columns["id_Данных"];
            if (dataGridViewColumn != null)
            {
                dataGridViewColumn.Visible = false;
            }
            var tablePutevoi = new AutoparkDBTableAdapters.PutevoiListLegkTableAdapter();
            var res          = tablePutevoi.GetDataByID(id).ToList();

            _number    = res[0].Номер_путевого_листа;
            _idauto    = res[0].ID_Автомобиль;
            _idvod     = res[0].ID_Водитель;
            _idotd     = res[0].ID_Отдела;
            _dateStart = res[0].За_период_с;
            _dateEnd   = res[0].За_период_по;

            txtNumber.Text                  = _number.ToString(CultureInfo.InvariantCulture);
            cbNomerAuto.SelectedItem        = _bindingAuto[_bindingAuto.Find("ID", _idauto)];
            cbVodUdostoverenie.SelectedItem = _bindingVoditel[_bindingVoditel.Find("табельный_номер", _idvod)];
            cbOtdel.SelectedItem            = _bindingOtdel[_bindingOtdel.Find("Код", _idotd)];
            dtpStart.Value                  = _dateStart;
            dtpEnd.Value = _dateEnd;
        }