private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            DepartmentSumCostReportTableAdapter sumAdapter = new DepartmentSumCostReportTableAdapter();

            DepartmentCostReportTableAdapter adapter = new DepartmentCostReportTableAdapter();
            adapter.ClearBeforeFill = true;
            adapter.Fill(masterDB.DepartmentCostReport, deptId, reqFromDate, reqToDate);
            //sumAdapter.ClearBeforeFill = true;
            //sumAdapter.Fill(masterDB.DepartmentSumCostReport, deptId, reqFromDate, reqToDate);
            //foreach (MasterDB.DepartmentSumCostReportRow row in masterDB.DepartmentSumCostReport)
            //{
            //    outMoney = (long)row.total;
            //}
        }
Exemplo n.º 2
0
        public void EnterPeriod()
        {
            try
            {
                ((MainForm)GlobalCache.Instance().MainForm).showProgressBar();
                GlobalCache.Instance().IsCostSummary = true;
                ObjectCriteria crit = new ObjectCriteria();
                crit.AddEqCriteria("EmployeeMoneyPK.WorkingDay", DateUtility.ZeroTime(DateTime.Now));
                crit.AddEqCriteria("EmployeeMoneyPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
                IList list = EmployeeMoneyLogic.FindAll(crit);

                if (list != null && list.Count == 1)
                {

                }
                else
                {
                    DateTime toDay = DateUtility.ZeroTime(DateTime.Now);
                    DateTime startToday = toDay.AddHours(3);

                    // get total of yesterday
                    MasterDB masterDB = new MasterDB();
                    DepartmentSumCostReportTableAdapter adapter = new DepartmentSumCostReportTableAdapter();
                    adapter.ClearBeforeFill = true;
                    adapter.Fill(masterDB.DepartmentSumCostReport,
                                 (int)CurrentDepartment.Get().DepartmentId,
                                 startToday.Subtract(new TimeSpan(1, 0, 0, 0)),
                                 startToday
                        );

                    int rowCount = masterDB.DepartmentSumCostReport.Rows.Count;
                    long prevAmount = 0;
                    if (rowCount > 0)
                    {
                        prevAmount = Int64.Parse(masterDB.DepartmentSumCostReport.Rows[0][3].ToString());
                    }

                    EmployeeMoney fixEmplMoney = new EmployeeMoney();
                    fixEmplMoney.WorkingDay = toDay;
                    fixEmplMoney.CreateDate = startToday;
                    fixEmplMoney.UpdateDate = startToday;
                    fixEmplMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.DateLogin = startToday;
                    fixEmplMoney.DateLogout = startToday;
                    fixEmplMoney.InMoney = prevAmount;
                    //fixEmplMoney.OutMoney = 0;
                    EmployeeMoneyPK fixTimelinePK = new EmployeeMoneyPK
                    {
                        DepartmentId = CurrentDepartment.Get().DepartmentId,
                        EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                        WorkingDay = toDay
                    };

                    fixEmplMoney.EmployeeMoneyPK = fixTimelinePK;
                    EmployeeMoneyLogic.Add(fixEmplMoney);

                    // update last day
                    ObjectCriteria lastDayCrit = new ObjectCriteria();
                    lastDayCrit.AddEqCriteria("EmployeeMoneyPK.WorkingDay", DateUtility.ZeroTime(toDay.Subtract(new TimeSpan(1, 0, 0, 0))));
                    lastDayCrit.AddEqCriteria("EmployeeMoneyPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
                    IList lastList = EmployeeMoneyLogic.FindAll(lastDayCrit);
                    if (lastList != null && lastList.Count > 0)
                    {
                        EmployeeMoney lastDayMoney = (EmployeeMoney)lastList[0];
                        lastDayMoney.OutMoney = prevAmount;
                        lastDayMoney.UpdateDate = startToday;
                        lastDayMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                        lastDayMoney.DateLogout = startToday;
                        EmployeeMoneyLogic.Update(lastDayMoney);
                    }

                }
                GlobalCache.Instance().IsCostSummary = true;
            }
            catch (Exception exception)
            {
                GlobalCache.Instance().IsCostSummary = false;
            }
            finally
            {
                ((MainForm)GlobalCache.Instance().MainForm).stopProgressBar();
                GlobalCache.Instance().IsCostSummary = false;
            }
        }