private void FillDataRec(SqlDataReader reader, AddAccr addAccr)
        {
            int      resInt  = 0;
            DateTime resDate = DateTime.MinValue;
            decimal  resDec  = 0;

            if (int.TryParse(reader["AddAccr_Id"].ToString(), out resInt))
            {
                addAccr.AddAccr_Id = resInt;
            }

            if (int.TryParse(reader["AddAccr_PersCard_Id"].ToString(), out resInt))
            {
                addAccr.AddAccr_PersCard_Id = resInt;
            }
            if (int.TryParse(reader["AddAccr_RefDep_Id"].ToString(), out resInt))
            {
                addAccr.AddAccr_RefDep_Id = resInt;
            }
            if (int.TryParse(reader["AddAccr_RefTypeAddAccr_Id"].ToString(), out resInt))
            {
                addAccr.AddAccr_RefTypeAddAccr_Id = resInt;
            }
            if (DateTime.TryParse(reader["AddAccr_Date"].ToString(), out resDate))
            {
                addAccr.AddAccr_Date = resDate;
            }
            if (decimal.TryParse(reader["AddAccr_Sm"].ToString(), out resDec))
            {
                addAccr.AddAccr_Sm = resDec;
            }
        }
Ejemplo n.º 2
0
        public AddAccr GetData()
        {
            AddAccr addAccr = new AddAccr();

            addAccr.AddAccr_Id          = _id;
            addAccr.AddAccr_PersCard_Id = _cmbCardParams.PersCard_Id;
            addAccr.AddAccr_RefDep_Id   = _cmbDepParams.RefDep_Id;
            addAccr.AddAccr_Date        = SalaryHelper.GetDateByIndex(cmbCalendar.SelectedIndex, DateTime.Today.Year - SetupProgram.YearSalary, false);

            int     resInt = 0;
            decimal resDec = 0;

            ResField fldId = resFldTypeAddAccr.FirstOrDefault(rec => rec.Name == "RefTypeAddAccr_Id");

            if (fldId != null)
            {
                if (int.TryParse(fldId.Val, out resInt))
                {
                    addAccr.AddAccr_RefTypeAddAccr_Id = resInt;
                }
            }
            //Сумма
            if (decimal.TryParse(tbSm.Text, out resDec))
            {
                addAccr.AddAccr_Sm = resDec;
            }

            return(addAccr);
        }
Ejemplo n.º 3
0
        //Обновление строки
        private void UpdateRecord()
        {
            if (dgvAddAccr.CurrentRow == null)
            {
                return;
            }
            v_AddAccr addAccrSet = dgvAddAccr.CurrentRow.DataBoundItem as v_AddAccr;

            if (addAccrSet == null)
            {
                MessageBox.Show("Не знайдений рядок для оновлення", "Помилка");
                return;
            }
            fmAddAccrEdit fmEdit = new fmAddAccrEdit(EnumFormMode.Edit, "Зміна додаткового нарахування");

            fmEdit.SetData(addAccrSet);
            if (fmEdit.ShowDialog() == DialogResult.OK)
            {
                AddAccr addAccrGet = fmEdit.GetData();
                string  error;
                if (!_repoAddAccr.ModifyAddAccr(addAccrGet, out error))
                {
                    MessageBox.Show("Помилка оновлення рядка.\nТехнічна інформація: " + error, "Помилка");
                    return;
                }
                RefreshTableAddAccr(_depId, _datBeg, _datEnd);
            }
        }
        //Получить доп. начисления по параметрам
        public List <AddAccr> GetAddAccrByParams(int addAccr_id, int refDep_id, DateTime addAccr_dateBeg, DateTime addAccr_dateEnd, out string error)
        {
            error = string.Empty;

            if (conn == null)
            {
                error = "conn == null";
                return(null);
            }
            if (addAccr_id == 0 && refDep_id == 0 && addAccr_dateBeg == DateTime.MinValue && addAccr_dateEnd == DateTime.MinValue)
            {
                error = "Не задані вхідні параметри";
                return(null);
            }
            if (addAccr_dateBeg == DateTime.MinValue || addAccr_dateEnd == DateTime.MinValue)
            {
                error = "Не заданий період";
                return(null);
            }

            List <AddAccr> addAccrs = new List <AddAccr>();

            SqlCommand command = new SqlCommand(spAddAccrSelect, conn);

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

            command.Parameters.AddWithValue("@inAddAccr_Id", addAccr_id);
            command.Parameters.AddWithValue("@inAddAccr_RefDep_Id", refDep_id);
            command.Parameters.AddWithValue("@inAddAccr_DateBeg", (addAccr_dateBeg == DateTime.MinValue) ? Convert.DBNull : addAccr_dateBeg);
            command.Parameters.AddWithValue("@inAddAccr_DateEnd", (addAccr_dateEnd == DateTime.MinValue) ? Convert.DBNull : addAccr_dateEnd);

            SqlDataReader reader = null;

            try
            {
                reader = command.ExecuteReader();
                while (reader.Read())
                {
                    AddAccr addAccr = new AddAccr();
                    FillDataRec(reader, addAccr);
                    addAccrs.Add(addAccr);
                }
            }
            catch (Exception ex)
            {
                error    = ex.Message;
                addAccrs = null;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(addAccrs);
        }
Ejemplo n.º 5
0
        public void SetData(AddAccr addAccr)
        {
            _id = addAccr.AddAccr_Id;
            cmbCalendar.SelectedIndex = SalaryHelper.GetIndexByDate(
                DateTime.Today.Year - SetupProgram.YearSalary, addAccr.AddAccr_Date, false);

            cmbCard.ReadCombobox(addAccr.AddAccr_PersCard_Id);
            cmbDep.ReadCombobox(addAccr.AddAccr_RefDep_Id);
            cmbTypeAddAccr.ReadCombobox("RefTypeAddAccr_Id", addAccr.AddAccr_RefTypeAddAccr_Id.ToString());
            tbSm.Text = addAccr.AddAccr_Sm.ToString("0.00");
        }
        //Добавить доп. начисление
        public int AddAddAccr(AddAccr addAccr, out string error)
        {
            error = string.Empty;
            if (addAccr == null)
            {
                error = "addAccr == null";
                return(0);
            }
            if (conn == null)
            {
                error = "conn == null";
                return(0);
            }
            SqlCommand command = new SqlCommand(spAddAccrInsert, conn);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Connection  = conn;
            command.Parameters.AddWithValue("@inAddAccr_PersCard_Id",
                                            addAccr.AddAccr_PersCard_Id == 0 ? Convert.DBNull : addAccr.AddAccr_PersCard_Id);
            command.Parameters.AddWithValue("@inAddAccr_RefDep_Id",
                                            addAccr.AddAccr_RefDep_Id == 0 ? Convert.DBNull : addAccr.AddAccr_RefDep_Id);
            command.Parameters.AddWithValue("@inAddAccr_RefTypeAddAccr_Id",
                                            addAccr.AddAccr_RefTypeAddAccr_Id == 0 ? Convert.DBNull : addAccr.AddAccr_RefTypeAddAccr_Id);
            command.Parameters.AddWithValue("@inAddAccr_Date",
                                            addAccr.AddAccr_Date == DateTime.MinValue ? Convert.DBNull : addAccr.AddAccr_Date);
            command.Parameters.AddWithValue("@inAddAccr_Sm", addAccr.AddAccr_Sm);
            // определяем выходной параметр
            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);;
        }
        //Получить список доп начислений
        public List <AddAccr> GetAllAddAccrs(out string error)
        {
            error = string.Empty;

            List <AddAccr> addAccrs = new List <AddAccr>();

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

            SqlCommand command = new SqlCommand(spAddAccrSelect, conn);

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

            try
            {
                reader = command.ExecuteReader();

                while (reader.Read())
                {
                    AddAccr addAccr = new AddAccr();
                    FillDataRec(reader, addAccr);
                    addAccrs.Add(addAccr);
                }
            }
            catch (Exception exc)
            {
                error = exc.Message;
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(addAccrs);
        }
Ejemplo n.º 8
0
        //Вставка строки
        private void InsertRecord()
        {
            fmAddAccrEdit fmEdit  = new fmAddAccrEdit(EnumFormMode.Insert, "Створення додаткового нарахування");
            AddAccr       accrSet = new AddAccr();
            int           month   = SalaryHelper.GetMonthByIndex(cmbCalendar.SelectedIndex, true);

            if (month == 0)
            {
                accrSet.AddAccr_Date = DateTime.MinValue.AddYears(DateTime.Today.Year - 1).AddMonths(DateTime.Today.Month - 1);
            }
            else
            {
                int year = SalaryHelper.GetYearByIndex(DateTime.Today.Year - SetupProgram.YearSalary, cmbCalendar.SelectedIndex, true);
                accrSet.AddAccr_Date = DateTime.MinValue.AddYears(year - 1).AddMonths(month - 1);
            }

            if (MenuItemDeps.CheckState == CheckState.Checked && dgvDep.CurrentRow != null)
            {
                v_Dep dep = dgvDep.CurrentRow.DataBoundItem as v_Dep;
                if (dep != null)
                {
                    accrSet.AddAccr_RefDep_Id = dep.Id;
                }
            }
            fmEdit.SetData(accrSet);
            if (fmEdit.ShowDialog() == DialogResult.OK)
            {
                string  error;
                AddAccr accrGet = fmEdit.GetData();
                int     id      = _repoAddAccr.AddAddAccr(accrGet, out error);
                if (id == 0)
                {
                    MessageBox.Show("Помилка додавання рядка.\nТехнічна інформація: " + error, "Помилка");
                    return;
                }
                RefreshTableAddAccr(_depId, _datBeg, _datEnd);
                dgvAddAccr.SetPositionRow <v_AddAccr>("AddAccr_Id", id.ToString());
            }
        }
        //Изменить доп. начисление
        public bool ModifyAddAccr(AddAccr addAccr, out string error)
        {
            error = string.Empty;
            if (conn == null)
            {
                error = "conn == null";
                return(false);
            }
            if (addAccr == null)
            {
                error = "addAccr == null";
                return(false);
            }
            SqlCommand command = new SqlCommand(spAddAccrUpdate, conn);

            command.CommandType = System.Data.CommandType.StoredProcedure;
            command.Connection  = conn;
            command.Parameters.AddWithValue("@inAddAccr_Id", addAccr.AddAccr_Id);
            command.Parameters.AddWithValue("@inAddAccr_PersCard_Id",
                                            addAccr.AddAccr_PersCard_Id == 0 ? Convert.DBNull : addAccr.AddAccr_PersCard_Id);
            command.Parameters.AddWithValue("@inAddAccr_RefDep_Id",
                                            addAccr.AddAccr_RefDep_Id == 0 ? Convert.DBNull : addAccr.AddAccr_RefDep_Id);
            command.Parameters.AddWithValue("@inAddAccr_RefTypeAddAccr_Id",
                                            addAccr.AddAccr_RefTypeAddAccr_Id == 0 ? Convert.DBNull : addAccr.AddAccr_RefTypeAddAccr_Id);
            command.Parameters.AddWithValue("@inAddAccr_Date",
                                            addAccr.AddAccr_Date == DateTime.MinValue ? Convert.DBNull : addAccr.AddAccr_Date);
            command.Parameters.AddWithValue("@inAddAccr_Sm", addAccr.AddAccr_Sm);
            try
            {
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
            return(true);
        }