Beispiel #1
0
        private void btn_Click(object sender, EventArgs e)
        {
            fmCmbExpAllwnc fmCmbAllwnc = new fmCmbExpAllwnc(_cmbParams.expAllwncs);

            if (fmCmbAllwnc.ShowDialog() == DialogResult.OK)
            {
                RefExpAllwnc allwnc = fmCmbAllwnc.GetData();
                _cmbParams.RefExpAllwnc_Id = allwnc.RefExpAllwnc_Id;
                if (_cmbParams.tbCd != null)
                {
                    _cmbParams.tbCd.Text = allwnc.RefExpAllwnc_Cd;
                }
                if (_cmbParams.tbPct != null)
                {
                    if (allwnc.RefExpAllwncMech_RefDep_Id == _cmbParams.RefDep_MechId)
                    {
                        _cmbParams.tbPct.Text = allwnc.RefExpAllwnc_Mech.ToString("0.00");
                    }
                    else
                    {
                        _cmbParams.tbPct.Text = allwnc.RefExpAllwnc_Oth.ToString("0.00");
                    }
                }
                if (_cmbParams.tbNm != null)
                {
                    _cmbParams.tbNm.Text = allwnc.RefExpAllwnc_Nm;
                }
            }
        }
        public RefExpAllwnc GetData()
        {
            RefExpAllwnc expAllwnc = new RefExpAllwnc();
            decimal      decRes    = 0;
            int          intRes    = 0;

            expAllwnc.RefExpAllwnc_Id = id;
            expAllwnc.RefExpAllwnc_Cd = tbCd.Text;
            expAllwnc.RefExpAllwnc_Nm = tbNm.Text;
            if (decimal.TryParse(tbMech.Text, out decRes))
            {
                expAllwnc.RefExpAllwnc_Mech = decRes;
            }
            if (decimal.TryParse(tbOth.Text, out decRes))
            {
                expAllwnc.RefExpAllwnc_Oth = decRes;
            }
            if (int.TryParse(tbYear.Text, out intRes))
            {
                expAllwnc.RefExpAllwnc_Year = intRes;
            }

            expAllwnc.RefExpAllwncMech_RefDep_Id = _cmbDepParams.RefDep_Id;
            if (cbUse.Checked)
            {
                expAllwnc.RefExpAllwnc_Flg &= ~(int)EnumExpAllwnc_Flg.ALLWNC_NOTUSE;
            }
            else
            {
                expAllwnc.RefExpAllwnc_Flg |= (int)EnumExpAllwnc_Flg.ALLWNC_NOTUSE;
            }

            return(expAllwnc);
        }
        //Обновление строки
        private void UpdateRecord()
        {
            if (dgvRefExpAllwnc.CurrentRow == null)
            {
                return;
            }
            string         error;
            v_RefExpAllwnc v_expAllwnc = dgvRefExpAllwnc.CurrentRow.DataBoundItem as v_RefExpAllwnc;

            if (v_expAllwnc == null)
            {
                MessageBox.Show("Не знайдений рядок для оновлення", "Помилка");
                return;
            }

            fmRefExpAllwncEdit fmEdit = new fmRefExpAllwncEdit(EnumFormMode.Edit, "Зміна надбавки за стаж");

            fmEdit.SetData(v_expAllwnc);
            if (fmEdit.ShowDialog() == DialogResult.OK)
            {
                RefExpAllwnc expAllwnc = fmEdit.GetData();
                if (!_repository.ModifyExpAllwnc(expAllwnc, out error))
                {
                    MessageBox.Show("Помилка оновлення рядка.\nТехнічна інформація: " + error, "Помилка");
                    return;
                }
                RefreshTable();
            }
        }
        private void FillDataRec(SqlDataReader reader, RefExpAllwnc expAllwnc)
        {
            int     resInt     = 0;
            decimal resDecimal = 0;

            if (int.TryParse(reader["RefExpAllwnc_Id"].ToString(), out resInt))
            {
                expAllwnc.RefExpAllwnc_Id = resInt;
            }
            expAllwnc.RefExpAllwnc_Cd = reader["RefExpAllwnc_Cd"].ToString();
            expAllwnc.RefExpAllwnc_Nm = reader["RefExpAllwnc_Nm"].ToString();
            if (int.TryParse(reader["RefExpAllwnc_Year"].ToString(), out resInt))
            {
                expAllwnc.RefExpAllwnc_Year = resInt;
            }
            if (decimal.TryParse(reader["RefExpAllwnc_Mech"].ToString(), out resDecimal))
            {
                expAllwnc.RefExpAllwnc_Mech = resDecimal;
            }
            if (int.TryParse(reader["RefExpAllwncMech_RefDep_Id"].ToString(), out resInt))
            {
                expAllwnc.RefExpAllwncMech_RefDep_Id = resInt;
            }
            if (decimal.TryParse(reader["RefExpAllwnc_Oth"].ToString(), out resDecimal))
            {
                expAllwnc.RefExpAllwnc_Oth = resDecimal;
            }
            if (int.TryParse(reader["RefExpAllwnc_Flg"].ToString(), out resInt))
            {
                expAllwnc.RefExpAllwnc_Flg = resInt;
            }
        }
        //Зачитка комбика надбавки за стаж
        private void SetDataExpAllwnc()
        {
            PersCard card = _cards.FirstOrDefault(rec => rec.PersCard_Id == _cmbCardParams.PersCard_Id);

            if (card == null)
            {
                cmbExpAllwnc.ReadCombobox(0);
                tbExpSm.Text = string.Empty;
                return;
            }
            _cmbExpAllwncParams.RefDep_MechId = _cmbDepParams.RefDep_Id;

            RefExpAllwnc allwmc = _cmbExpAllwncParams.expAllwncs.FirstOrDefault(
                rec => rec.RefExpAllwnc_Year == card.PersCard_Exp
                );

            if (allwmc != null)
            {
                cmbExpAllwnc.ReadCombobox(allwmc.RefExpAllwnc_Id);
            }
            else
            {
                cmbExpAllwnc.ReadCombobox(0);
                tbExpSm.Text = string.Empty;
            }
        }
Beispiel #6
0
        public RefExpAllwnc GetData()
        {
            if (dgvExpAllwnc.CurrentRow == null)
            {
                return(null);
            }

            RefExpAllwnc allowance = dgvExpAllwnc.CurrentRow.DataBoundItem as RefExpAllwnc;

            return(allowance);
        }
 public void SetData(RefExpAllwnc expAllwnc)
 {
     if (expAllwnc == null)
     {
         return;
     }
     id          = expAllwnc.RefExpAllwnc_Id;
     tbCd.Text   = expAllwnc.RefExpAllwnc_Cd;
     tbNm.Text   = expAllwnc.RefExpAllwnc_Nm;
     tbYear.Text = expAllwnc.RefExpAllwnc_Year.ToString();
     tbMech.Text = expAllwnc.RefExpAllwnc_Mech.ToString();
     tbOth.Text  = expAllwnc.RefExpAllwnc_Oth.ToString();
     _cmbDep.ReadCombobox(expAllwnc.RefExpAllwncMech_RefDep_Id);
     cbUse.Checked = (expAllwnc.RefExpAllwnc_Flg & (int)EnumGradeAllwnc_Flg.ALLWNC_NOTUSE) > 0 ? false : true;
 }
        //Добавить надбавку за стаж
        public int AddExpAllwnc(RefExpAllwnc еxpAllwnc, out string error)
        {
            error = string.Empty;
            if (еxpAllwnc == null)
            {
                error = "еxpAllwnc == null";
                return(0);
            }
            if (conn == null)
            {
                error = "conn == null";
                return(0);
            }
            SqlCommand command = new SqlCommand(spRefExpAllwncInsert, conn);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Connection  = conn;
            command.Parameters.AddWithValue("@inRefExpAllwnc_Cd", еxpAllwnc.RefExpAllwnc_Cd);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Nm", еxpAllwnc.RefExpAllwnc_Nm);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Year", еxpAllwnc.RefExpAllwnc_Year);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Mech", еxpAllwnc.RefExpAllwnc_Mech);
            command.Parameters.AddWithValue("@inRefExpAllwncMech_RefDep_Id",
                                            еxpAllwnc.RefExpAllwncMech_RefDep_Id == 0 ? Convert.DBNull : еxpAllwnc.RefExpAllwncMech_RefDep_Id);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Oth", еxpAllwnc.RefExpAllwnc_Oth);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Flg", еxpAllwnc.RefExpAllwnc_Flg);
            // определяем выходной параметр
            SqlParameter outId = new SqlParameter
            {
                ParameterName = "outId",
                Direction     = ParameterDirection.Output,
                SqlDbType     = SqlDbType.Int
            };

            command.Parameters.Add(outId);
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(0);
            }
            int id = 0;

            int.TryParse(command.Parameters["outId"].Value.ToString(), out id);
            return(id);
        }
Beispiel #9
0
        //Вставка строки
        private void InsertRecord()
        {
            fmRefExpAllwncEdit fmEdit = new fmRefExpAllwncEdit(EnumFormMode.Insert, "Створення надбавки");

            if (fmEdit.ShowDialog() == DialogResult.OK)
            {
                string       error;
                RefExpAllwnc expAllwnc = fmEdit.GetData();

                if (!_repository.AddExpAllwnc(expAllwnc, out error))
                {
                    MessageBox.Show("Помилка додавання картки.\nТехнічна інформація: " + error, "Помилка");
                    return;
                }
                RefreshTable();
            }
        }
        //Получить надбавки за стаж
        public List <RefExpAllwnc> GetAllExpAllwnc(out string error)
        {
            error = string.Empty;

            List <RefExpAllwnc> refExpAllwncs = new List <RefExpAllwnc>();

            if (conn == null)
            {
                error = "conn == null";
                return(refExpAllwncs);
            }

            SqlCommand command = new SqlCommand(spRefExpAllwncSelect, conn);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            SqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    RefExpAllwnc refExpAllwnc = new RefExpAllwnc();
                    FillDataRec(reader, refExpAllwnc);
                    //for (int i = 0; i < reader.FieldCount; i++)
                    //{
                    //    FillDataRec(refExpAllwnc, reader.GetName(i), reader.GetValue(i).ToString());
                    //}
                    refExpAllwncs.Add(refExpAllwnc);
                }
            }
            catch (Exception exc)
            {
                error = exc.Message;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(refExpAllwncs);
        }
        //Вставка строки
        private void InsertRecord()
        {
            fmRefExpAllwncEdit fmEdit = new fmRefExpAllwncEdit(EnumFormMode.Insert, "Створення надбавки за стаж");

            if (fmEdit.ShowDialog() == DialogResult.OK)
            {
                string       error;
                RefExpAllwnc expAllwnc = fmEdit.GetData();
                int          id        = _repository.AddExpAllwnc(expAllwnc, out error);
                if (id == 0)
                {
                    MessageBox.Show("Помилка додавання рядка.\nТехнічна інформація: " + error, "Помилка");
                    return;
                }
                RefreshTable();
                dgvRefExpAllwnc.SetPositionRow <v_RefExpAllwnc>("RefExpAllwnc_Id", id.ToString());
            }
        }
Beispiel #12
0
        public void ReadCombobox(int id)
        {
            if (_cmbParams == null)
            {
                return;
            }
            if (_cmbParams.expAllwncs == null)
            {
                return;
            }

            RefExpAllwnc allwnc = _cmbParams.expAllwncs.FirstOrDefault(rec => rec.RefExpAllwnc_Id == id);

            if (allwnc == null)
            {
                _cmbParams.ClearParams();
                return;
            }
            _cmbParams.RefExpAllwnc_Id = allwnc.RefExpAllwnc_Id;

            if (_cmbParams.tbCd != null)
            {
                _cmbParams.tbCd.Text = allwnc.RefExpAllwnc_Cd;
            }

            if (_cmbParams.tbNm != null)
            {
                _cmbParams.tbNm.Text = allwnc.RefExpAllwnc_Nm;
            }

            if (_cmbParams.tbPct != null)
            {
                if (allwnc.RefExpAllwncMech_RefDep_Id == _cmbParams.RefDep_MechId)
                {
                    _cmbParams.tbPct.Text = allwnc.RefExpAllwnc_Mech.ToString("0.00");
                }
                else
                {
                    _cmbParams.tbPct.Text = allwnc.RefExpAllwnc_Oth.ToString("0.00");
                }
            }
        }
Beispiel #13
0
        private void tbCd_Validating(object sender, CancelEventArgs e)
        {
            if (_cmbParams.tbCd.Text == string.Empty)
            {
                _cmbParams.ClearParams();
                return;
            }
            RefExpAllwnc allwnc = _cmbParams.expAllwncs.FirstOrDefault(rec => rec.RefExpAllwnc_Cd == _cmbParams.tbCd.Text);

            if (allwnc != null)
            {
                _cmbParams.RefExpAllwnc_Id = allwnc.RefExpAllwnc_Id;

                if (_cmbParams.tbCd != null)
                {
                    _cmbParams.tbCd.Text = allwnc.RefExpAllwnc_Cd;
                }

                if (_cmbParams.tbNm != null)
                {
                    _cmbParams.tbNm.Text = allwnc.RefExpAllwnc_Nm;
                }

                if (_cmbParams.tbPct != null)
                {
                    if (allwnc.RefExpAllwncMech_RefDep_Id == _cmbParams.RefDep_MechId)
                    {
                        _cmbParams.tbPct.Text = allwnc.RefExpAllwnc_Mech.ToString("0.00");
                    }
                    else
                    {
                        _cmbParams.tbPct.Text = allwnc.RefExpAllwnc_Oth.ToString("0.00");
                    }
                }
            }
            else
            {
                _cmbParams.ClearParams();
                btn_Click(sender, e);
            }
        }
        //Получить надбавку за стаж по id
        public RefExpAllwnc GetExpAllwncById(int id, out string error)
        {
            error = string.Empty;
            RefExpAllwnc resExpAllwnc = null;

            if (conn == null)
            {
                error = "conn == null";
                return(null);
            }
            SqlCommand command = new SqlCommand(spRefExpAllwncSelect, conn);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Connection  = conn;
            command.Parameters.AddWithValue("@inRefExpAllwnc_Id", id);
            SqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    reader.Read();
                    resExpAllwnc = new RefExpAllwnc();
                    FillDataRec(reader, resExpAllwnc);
                }
            }
            catch (Exception ex)
            {
                error = ex.Message;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(resExpAllwnc);
        }
        //Изменить надбавку за стаж
        public bool ModifyExpAllwnc(RefExpAllwnc еxpAllwnc, out string error)
        {
            error = string.Empty;
            if (conn == null)
            {
                error = "conn == null";
                return(false);
            }
            if (еxpAllwnc == null)
            {
                error = "еxpAllwnc == null";
                return(false);
            }
            SqlCommand command = new SqlCommand(spRefExpAllwncUpdate, conn);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Connection  = conn;

            command.Parameters.AddWithValue("@inRefExpAllwnc_Id", еxpAllwnc.RefExpAllwnc_Id);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Cd", еxpAllwnc.RefExpAllwnc_Cd);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Nm", еxpAllwnc.RefExpAllwnc_Nm);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Year", еxpAllwnc.RefExpAllwnc_Year);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Mech", еxpAllwnc.RefExpAllwnc_Mech);
            command.Parameters.AddWithValue("@inRefExpAllwncMech_RefDep_Id",
                                            еxpAllwnc.RefExpAllwncMech_RefDep_Id == 0 ? Convert.DBNull : еxpAllwnc.RefExpAllwncMech_RefDep_Id);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Oth", еxpAllwnc.RefExpAllwnc_Oth);
            command.Parameters.AddWithValue("@inRefExpAllwnc_Flg", еxpAllwnc.RefExpAllwnc_Flg);

            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
            return(true);
        }