コード例 #1
0
        private async void btnGetIds_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            employeesInfo = new List <TBL_EMPLOYEES>();

            this.resetData();
            this.resetBindings();

            if (string.IsNullOrWhiteSpace(this.txtEmployeesCodes.Text))
            {
                return;
            }

            string[] employeesCodes = txtEmployeesCodes.Text.Split(',');
            var      db             = new QAMS();

            this.employeesInfo = await db.TBL_EMPLOYEES.Where(emp => employeesCodes.Contains(emp.EPCODE)).AsNoTracking().ToListAsync();

            resetBindings();

            this.Cursor = Cursors.Default;
        }
コード例 #2
0
        private async void btnGetRowAttendance_Click(object sender, EventArgs e)
        {
            if (this.employeesInfo == null || this.employeesInfo.Count < 1 || dtFrom.Value.Date > dtTo.Value.Date)
            {
                return;
            }

            this.Cursor = Cursors.WaitCursor;
            this.resetData();
            this.resetBindings();

            DateTime fromDate = dtFrom.Value.Date;
            DateTime toDate   = dtTo.Value.AddDays(1).Date;

            //Setup old data dates
            DateTime oldDataMaxDate  = new DateTime(2018, 12, 1).Date;
            DateTime?oldDataFromDate = fromDate < oldDataMaxDate ? fromDate : default(DateTime?);
            DateTime oldDataToDate   = toDate >= oldDataMaxDate ? oldDataMaxDate : toDate;

            //Setup new data dates
            DateTime newDataFromDate = fromDate >= oldDataMaxDate ? fromDate : oldDataMaxDate;
            DateTime?newDataToDate   = toDate >= oldDataMaxDate ? toDate : default(DateTime?);

            if (oldDataFromDate.HasValue)
            {
                var db           = new QAMS();
                var employeesIds = this.employeesInfo.Select(emp => emp.EPID).ToList();
                this.allOldTransactionsRecords = await db.TBL_TRANSDUMPS
                                                 .Where(tr => tr.TRDATE >= oldDataFromDate.Value &&
                                                        tr.TRDATE < oldDataToDate &&
                                                        tr.EPID.HasValue &&
                                                        employeesIds.Contains(tr.EPID.Value))
                                                 .OrderBy(tr => tr.EPID)
                                                 .ThenBy(tr => tr.TRDATE).AsNoTracking().ToListAsync();

                var oldVacations = await db.TBL_EMP_VACATION
                                   .Where(v => ((v.EVFROM <= oldDataFromDate.Value && v.EVTO >= oldDataFromDate.Value) ||
                                                (v.EVFROM >= oldDataFromDate.Value && v.EVFROM <= oldDataToDate)) && employeesIds.Contains(v.EPID))
                                   .ToListAsync();

                var vacationsTypes = await db.TBL_VAC_TYPE.ToListAsync();

                this.allOldVacationsRecords = oldVacations.Select(v => new EmployeeVacation
                {
                    EmployeeId       = int.Parse(this.employeesInfo.FirstOrDefault(emp => emp.EPID == v.EPID).EPCODE),
                    RegisterDate     = v.SYS_DATE.Date,
                    StartDate        = v.EVFROM,
                    EndDate          = v.EVTO,
                    VacationTypeName = vacationsTypes.FirstOrDefault(vt => vt.VTID == v.VTID).VTNAME ?? ""
                }).ToList();

                var duties = await db.TBL_EMP_DUTY.Where(d => d.EDFROM.HasValue && d.EDTO.HasValue && ((d.EDFROM <= oldDataFromDate.Value && d.EDTO >= oldDataFromDate.Value) ||
                                                                                                       (d.EDFROM >= oldDataFromDate.Value && d.EDTO <= oldDataToDate)) && employeesIds.Contains(d.EPID)).ToListAsync();

                var dutiesVacations = duties.Select(d => new EmployeeVacation
                {
                    EmployeeId       = int.Parse(this.employeesInfo.FirstOrDefault(emp => emp.EPID == d.EPID).EPCODE),
                    RegisterDate     = d.SYS_DATE.Date,
                    StartDate        = d.EDFROM.Value,
                    EndDate          = d.EDTO.Value,
                    VacationTypeName = d.EDNAME,
                    Note             = d.EDDESC,
                    IsExcuse         = true
                }).ToList();

                this.allOldVacationsRecords.AddRange(dutiesVacations);

                this.allOldShiftsRecords = await db.TBL_EMP_SHIFT
                                           .Where(sh => employeesIds.Contains(sh.EPID) &&
                                                  sh.ESSTART >= oldDataFromDate.Value && sh.ESSTART <= oldDataToDate)
                                           .AsNoTracking().ToListAsync();

                this.allShiftsHolidaies = await db.TBL_EMP_TRANS_MST
                                          .Where(h => employeesIds.Contains(h.EPID) &&
                                                 h.TMDATE >= oldDataFromDate.Value &&
                                                 h.TMDATE <= oldDataToDate &&
                                                 !string.IsNullOrEmpty(h.HOCODE))
                                          .AsNoTracking().ToListAsync();



                if (oldDataToDate >= new DateTime(2016, 1, 1))
                {
                    try
                    {
                        var client = new HttpClient();
                        client.BaseAddress = new Uri(uriString: @"http://172.16.11.44:810/HrPortalApi/api/Hr/portal/");
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType: "application/json"));

                        DateTime sapVacationsFromDate = oldDataFromDate.Value < new DateTime(2016, 1, 1) ? new DateTime(2016, 1, 1) : oldDataFromDate.Value;

                        string vacationsRequestUrl = $"vacations?fromdate={oldDataFromDate.Value.ToString("yyyy-MM-dd", new CultureInfo("en-US"))}&todate={oldDataToDate.ToString("yyyy-MM-dd", new CultureInfo("en-US"))}&employeesIds={this.txtEmployeesCodes.Text}";

                        HttpResponseMessage vacationsResponse = await client.GetAsync(vacationsRequestUrl);

                        if (vacationsResponse.IsSuccessStatusCode)
                        {
                            string vacationsContent = await vacationsResponse.Content.ReadAsStringAsync();

                            this.newVacationsRecords = JsonConvert.DeserializeObject <List <EmployeeVacation> >(vacationsContent);
                        }

                        if (this.newVacationsRecords.Count > 0)
                        {
                            this.allOldVacationsRecords.AddRange(newVacationsRecords);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }

            //if (newDataToDate.HasValue)
            //{
            //    try
            //    {
            //        var client = new HttpClient();
            //        client.BaseAddress = new Uri(uriString: @"http://172.16.11.44:810/HrPortalApi/api/Hr/portal/");
            //        client.DefaultRequestHeaders.Accept.Clear();
            //        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(mediaType: "application/json"));

            //        string recordsRequestUrl = $"RawAttendanceTransactions?fromdate={newDataFromDate.ToString("yyyy-MM-dd", new CultureInfo("en-US"))}&todate={newDataToDate.Value.ToString("yyyy-MM-dd", new CultureInfo("en-US"))}&employeesIds={this.txtEmployeesCodes.Text}";

            //        HttpResponseMessage recordsResponse = await client.GetAsync(recordsRequestUrl);
            //        if (recordsResponse.IsSuccessStatusCode)
            //        {
            //            string content = await recordsResponse.Content.ReadAsStringAsync();
            //            this.newTransactionsRecords = JsonConvert.DeserializeObject<List<EmployeeAttendanceRecord>>(content);
            //        }

            //        string vacationsRequestUrl = $"vacations?fromdate={newDataFromDate.ToString("yyyy-MM-dd", new CultureInfo("en-US"))}&todate={newDataToDate.Value.ToString("yyyy-MM-dd", new CultureInfo("en-US"))}&employeesIds={this.txtEmployeesCodes.Text}";

            //        HttpResponseMessage vacationsResponse = await client.GetAsync(vacationsRequestUrl);
            //        if (vacationsResponse.IsSuccessStatusCode)
            //        {
            //            string vacationsContent = await vacationsResponse.Content.ReadAsStringAsync();
            //            this.newVacationsRecords = JsonConvert.DeserializeObject<List<EmployeeVacation>>(vacationsContent);
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        MessageBox.Show(ex.Message);
            //    }
            //}

            //this.allTransactionsRecords = this.oldTransactionsRecords.Select(t => new EmployeeAttendanceRecord
            //{
            //    EmployeeId = int.Parse(t.TREMP_ID),
            //    TransactionDate = t.TRDATE
            //}).ToList();

            //this.allTransactionsRecords.AddRange(this.newTransactionsRecords);

            //this.allTransactionsRecords = this.allTransactionsRecords.OrderBy(t => t.EmployeeId).ThenBy(t => t.TransactionDate).ToList();

            //this.allVacationsRecords.AddRange(this.oldVacationsRecords);
            //this.allVacationsRecords.AddRange(this.newVacationsRecords);

            //this.allVacationsRecords = this.allVacationsRecords.OrderBy(v => v.EmployeeId).ThenBy(v => v.StartDate).ToList();

            this.resetBindings();

            this.Cursor = Cursors.Default;
        }