Пример #1
0
        private void SetDatasourceGridView()
        {
            DateTime startDate = dtpStartWorkDate.Value.Date;
            DateTime endDate   = DateTime.Now.Date;

            //Dictionary<Int32, decimal> monthAndYear = ProvidentFundCalculator.GetMonthAndYearPVDPaid(startDate, endDate);

            decimal month    = ProvidentFundCalculator.GetMonthPVDPaid(startDate, endDate);
            decimal monthCal = ProvidentFundCalculator.GetMonthPVDPaid(startDate, endDate);

            monthCal -= 3;
            decimal yearWork = ProvidentFundCalculator.GetWorkYear(startDate, endDate);

            if (yearWork == 0)
            {
                return;
            }

            List <EmployeeLogDetail> providentFunds = new List <EmployeeLogDetail>();

            for (int row = 0; row <= yearWork; row++)
            {
                EmployeeLogDetail providentFund = new EmployeeLogDetail();

                if (row == 0)
                {
                    providentFund.Month = month - 11 >= 0 ? 11 : month;
                }
                else if (month - 12 >= 0)
                {
                    providentFund.Month = 12;
                }
                else
                {
                    providentFund.Month = month;
                }

                month -= providentFund.Month;

                providentFund.WorkYear             = row == 0 ? "1-11 M" : row + "+";
                providentFund.ProvidentFundCollect = 0;
                providentFund.Salary = Convert.ToDecimal(txtSalary.Text);

                DateTime newEndDate = endDate.AddMonths(-Convert.ToInt32(monthCal));
                providentFund.CompanyPaidPercent = ProvidentFundCalculator.GetCompanyPaidPercent(startDate, newEndDate);
                monthCal -= providentFund.Month;

                ConditionsDatetime conditionsDatetime = new ConditionsDatetime(startDate);

                providentFunds.Add(providentFund);
            }

            gridViewDisplay.DataSource = providentFunds;

            SetComBoboxOnGird(startDate, endDate, providentFunds);
        }
        public static List <EmployeeLogDetail> GetEmployeeLogDetail(int employeeLogID)
        {
            List <EmployeeLogDetail> employeeLogDetails = new List <EmployeeLogDetail>();
            MySqlConnection          conn = new MySqlConnection(GlobalVariable.ConnectionString);

            try
            {
                conn.Open();
                MySqlCommand cmd = conn.CreateCommand();
                cmd.CommandText = QueryGetEmployeeLogDetail(employeeLogID);
                MySqlDataReader reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    EmployeeLogDetail emp = new EmployeeLogDetail();
                    emp.EmployeeLogID       = ReaderHepler.GetValueFromReader <int>(reader, nameof(EmployeeLogDetail.EmployeeLogID));
                    emp.EmployeeLogDetailID = ReaderHepler.GetValueFromReader <int>(reader, nameof(EmployeeLogDetail.EmployeeLogDetailID));
                    emp.WorkYear            = ReaderHepler.GetValueFromReader <string>(reader, nameof(EmployeeLogDetail.WorkYear));
                    emp.Month                = ReaderHepler.GetValueFromReader <decimal>(reader, nameof(EmployeeLogDetail.Month));
                    emp.Salary               = ReaderHepler.GetValueFromReader <decimal>(reader, nameof(EmployeeLogDetail.Salary));
                    emp.PVDRate              = ReaderHepler.GetValueFromReader <decimal>(reader, nameof(EmployeeLogDetail.PVDRate));
                    emp.CompanyPaidPercent   = ReaderHepler.GetValueFromReader <decimal>(reader, nameof(EmployeeLogDetail.CompanyPaidPercent));
                    emp.ProvidentFundCollect = ReaderHepler.GetValueFromReader <decimal>(reader, nameof(EmployeeLogDetail.ProvidentFundCollect));

                    employeeLogDetails.Add(emp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }
            }

            return(employeeLogDetails);
        }
        private static string QuerySaveLogEmployeeDetail(EmployeeLogDetail employeeDetail)
        {
            List <QuerySource> querySources = new List <QuerySource>();

            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.EmployeeLogID), Value = (employeeDetail.EmployeeLogID)
            });
            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.WorkYear), Value = StringFormatHelper.GetSingleQuote(employeeDetail.WorkYear)
            });
            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.Month), Value = (employeeDetail.Month)
            });
            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.Salary), Value = (employeeDetail.Salary)
            });
            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.PVDRate), Value = (employeeDetail.PVDRate)
            });
            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.CompanyPaidPercent), Value = (employeeDetail.CompanyPaidPercent)
            });
            querySources.Add(new QuerySource {
                FieldName = nameof(EmployeeLogDetail.ProvidentFundCollect), Value = (employeeDetail.ProvidentFundCollect)
            });

            var fieldNames = querySources.Select(a => a.FieldName).ToArray();
            var values     = querySources.Select(a => a.Value).ToArray();

            string query = "INSERT INTO provident.employeelogdetail ( " + string.Join(",", fieldNames)
                           + ") VALUES ( " + string.Join(",", values) + " "
                           + ");"
            ;

            return(query);
        }