Ejemplo n.º 1
0
        private void DepartmentCostCreateForm_Load(object sender, EventArgs e)
        {
            BindingSource bdsDepartment = new BindingSource();
            bdsDepartment.DataSource = CurrentDepartment.Get();
            cboDepartment.DataSource = bdsDepartment;
            cboDepartment.DisplayMember = "DepartmentName";
            costList = new DepartmentCostCollection(bdsCost);
            bdsCost.ResetBindings(true);
            dgvCost.Refresh();
            dgvCost.Invalidate();
            DisableCostControls();
            txtCostDate.Text = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
            timer1.Start();
            DepartmentCostEventArgs eventArgs = new DepartmentCostEventArgs();
            EventUtility.fireEvent(SearchDepartmentCostEvent,this,eventArgs);

            if(eventArgs.CostList != null && eventArgs.CostList.Count > 0)
            {
                foreach (DepartmentCost cost in eventArgs.CostList)
                {
                    costList.Add(cost);
                }
            }
        }
Ejemplo n.º 2
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (!CreateFlag)
            {
                CreateFlag = true;
                EnableCostControls();
                btnCreate.Text = "Lưu";

                btnEdit.Enabled = false;
                btnCancel.Enabled = true;
            }
            else
            {
                DepartmentCost cost = new DepartmentCost();
                cost.DepartmentCostPK = new DepartmentCostPK
                                            {
                                                DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                CostDate = DateTime.Now
                                            };
                cost.CreateDate = DateTime.Now;
                cost.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                cost.UpdateDate = DateTime.Now;
                cost.UpdateId = ClientInfo.getInstance().LoggedUser.Name;

                cost.Cost = Int64.Parse(txtCost.Text.Trim());
                cost.CostDescription = txtCostDescription.Text.Trim();
                cost.CostName = txtCostName.Text.Trim();
                cost.CostType = cboCostType.SelectedIndex;
                DepartmentCostEventArgs eventArgs = new DepartmentCostEventArgs();
                eventArgs.CreateCost = cost;

                EventUtility.fireEvent(CreateDepartmentCostEvent, this, eventArgs);
                if (!eventArgs.HasErrors)
                {
                    costList.Add(eventArgs.CreateCost);
                    bdsCost.ResetBindings(false);
                    dgvCost.Refresh();
                    dgvCost.Invalidate();
                    CreateFlag = false;
                    ClearCostControls();
                    DisableCostControls();
                    btnCreate.Text = "Tạo";
                    btnEdit.Enabled = true;
                    btnCancel.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Có lỗi khi thêm chi phí. Liên hệ người quản trị", "Lỗi", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 3
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if(dgvCost.CurrentCell ==null)
            {
                return;
            }
            if (!UpdateFlag)
            {
                UpdateFlag = true;
                EnableCostControls();
                btnEdit.Text = "Lưu";
                DepartmentCost cost = costList[dgvCost.CurrentCell.RowIndex];
                txtCost.Text = cost.Cost.ToString();
                txtCostName.Text = cost.CostName;
                txtCostDescription.Text = cost.CostDescription;
                cboCostType.SelectedIndex = (int)cost.CostType;
                dgvCost.Enabled = false;

                btnCreate.Enabled = false;
                btnCancel.Enabled = true;

            }
            else
            {
                DepartmentCost cost = costList[dgvCost.CurrentCell.RowIndex];
                cost.UpdateDate = DateTime.Now;
                cost.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                cost.Cost = Int64.Parse(txtCost.Text.Trim());
                cost.CostDescription = txtCostDescription.Text.Trim();
                cost.CostName = txtCostName.Text.Trim();
                cost.CostType = cboCostType.SelectedIndex;
                DepartmentCostEventArgs eventArgs = new DepartmentCostEventArgs();
                eventArgs.UpdateCost = cost;

                EventUtility.fireEvent(EditDepartmentCostEvent, this, eventArgs);
                if (!eventArgs.HasErrors)
                {
                    costList.Add(eventArgs.CreateCost);
                    bdsCost.ResetBindings(false);
                    dgvCost.Refresh();
                    dgvCost.Invalidate();
                    CreateFlag = false;
                    ClearCostControls();
                    DisableCostControls();
                    btnEdit.Text = "Sửa";
                    dgvCost.Enabled = true;

                    btnCreate.Enabled = true;
                    btnCancel.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Có lỗi khi sửa chi phí. Liên hệ người quản trị", "Lỗi", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                }
            }
        }
Ejemplo n.º 4
0
        void departmentCostSummaryView_CommitDepartmentCostEvent(object sender, DepartmentCostEventArgs e)
        {
            // Save the end of period
            // select 5 day nearest
            //IList departmentTimelineList = new ArrayList();
            ObjectCriteria crit = new ObjectCriteria();
            crit.AddOrder("EmployeeMoneyPK.WorkingDay", false);
            crit.MaxResult = 5;
            IList prevList = EmployeeMoneyLogic.FindAll(crit);
            DateTime startTime = DateUtility.ZeroTime(DateTime.Now);
            if (prevList != null && prevList.Count > 0)
            {
                // update end time of nearest 5 timeline for sure transparency
                EmployeeMoney fixEmpMoney = (EmployeeMoney)prevList[0];
                DateTime lastSubmitEndTime = fixEmpMoney.EmployeeMoneyPK.WorkingDay;

                // get days which customer do not submit period
                TimeSpan timeSpan = DateUtility.ZeroTime(DateTime.Now).Subtract(DateUtility.ZeroTime(lastSubmitEndTime));
                // fix those days in order we can sync for today.

                //startTime = lastSubmitEndTime.AddSeconds(1);
                for (int i = 0; i < timeSpan.Days - 1; i++)
                {
                    DateTime nextDateTime = lastSubmitEndTime.AddDays(i + 1);
                    EmployeeMoney fixEmplMoney = new EmployeeMoney();
                    fixEmplMoney.WorkingDay = DateUtility.DateOnly(nextDateTime);
                    fixEmplMoney.CreateDate = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.UpdateDate = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                    fixEmplMoney.DateLogin = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.DateLogout = DateUtility.MaxTime(nextDateTime);
                    fixEmplMoney.InMoney = 0;
                    fixEmplMoney.OutMoney = 0;
                    EmployeeMoneyPK fixTimelinePK = new EmployeeMoneyPK
                    {
                        DepartmentId = CurrentDepartment.Get().DepartmentId,
                        EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                        WorkingDay = DateUtility.DateOnly(nextDateTime)
                    };

                    fixEmplMoney.EmployeeMoneyPK = fixTimelinePK;
                    EmployeeMoneyLogic.Add(fixEmplMoney);
                    //startTime = fixEmplMoney.EndTime.AddSeconds(1);
                }

            }
            #region unused code
            // If submit period ( ket so ) then we ' ket so '
            /*DepartmentTimeline timeline = null;
            if (isSubmitPeriod)
            {
                timeline = new DepartmentTimeline();
                timeline.WorkingDay = DateUtility.ZeroTime(DateTime.Now);
                timeline.CreateDate = DateTime.Now;
                timeline.UpdateDate = DateTime.Now;
                timeline.CreateId = ClientInfo.getInstance().LoggedUser.Name;
                timeline.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                timeline.StartTime = startTime;
                timeline.EndTime = DateTime.Now;
                DepartmentTimelinePK timelinePK = new DepartmentTimelinePK
                {
                    DepartmentId = CurrentDepartment.Get().DepartmentId,
                    Period = DateTime.Now.DayOfYear
                };
                var dbTimeline = DepartmentTimelineDAO.FindById(timelinePK);
                if (dbTimeline != null)
                {
                    throw new BusinessException("Ngày hôm nay đã kết sổ");
                }
                timeline.DepartmentTimelinePK = timelinePK;
                DepartmentTimelineDAO.Add(timeline);

                //departmentTimelineList.Add(timeline);
            }*/

            #endregion
            DateTime toDay = DateUtility.DateOnly(DateTime.Now);

            EmployeeMoney employeeMoney = new EmployeeMoney();
            employeeMoney.EmployeeMoneyPK = new EmployeeMoneyPK
                                                {
                                                    DepartmentId = CurrentDepartment.Get().DepartmentId,
                                                    EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                                                    WorkingDay = toDay
                                                };
            employeeMoney.WorkingDay = toDay;
            employeeMoney.CreateDate = DateTime.Now;
            employeeMoney.UpdateDate = DateTime.Now;
            employeeMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            employeeMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            employeeMoney.DateLogin = DateTime.Now;
            employeeMoney.DateLogout = DateTime.Now;
            employeeMoney.InMoney = 0;

            DateTime nextDay = toDay.AddDays(1);
            EmployeeMoney nextMoney = new EmployeeMoney();
            nextMoney.EmployeeMoneyPK = new EmployeeMoneyPK
            {
                DepartmentId = CurrentDepartment.Get().DepartmentId,
                EmployeeId = ClientInfo.getInstance().LoggedUser.Name,
                WorkingDay = nextDay
            };
            nextMoney.WorkingDay = nextDay;
            nextMoney.CreateDate = nextDay;
            nextMoney.UpdateDate = nextDay;
            nextMoney.CreateId = ClientInfo.getInstance().LoggedUser.Name;
            nextMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
            nextMoney.DateLogin = DateTime.Now;
            nextMoney.DateLogout = DateTime.Now;
            employeeMoney.InMoney = e.OutMoney;

            EmployeeMoney nextMoneyInDB = EmployeeMoneyLogic.FindById(employeeMoney.EmployeeMoneyPK);
            if (nextMoneyInDB != null)
            {
                throw new BusinessException("Ngày hôm nay đã kết sổ !");
            }

            ObjectCriteria objectCriteria = new ObjectCriteria();
            objectCriteria.AddEqCriteria("EmployeeMoneyPK.WorkingDay", toDay);
            objectCriteria.AddEqCriteria("EmployeeMoneyPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
            IList list = EmployeeMoneyLogic.FindAll(objectCriteria);
            if(list!=null && list.Count == 1)
            {
                employeeMoney = (EmployeeMoney)list[0];
                // count out money
                employeeMoney.OutMoney = e.OutMoney;
                employeeMoney.UpdateDate = DateTime.Now;
                employeeMoney.UpdateId = ClientInfo.getInstance().LoggedUser.Name;
                EmployeeMoneyLogic.Update(employeeMoney);
            }
            else
            {
                employeeMoney.OutMoney = e.OutMoney;
                EmployeeMoneyLogic.Add(employeeMoney);
            }

            EmployeeMoneyLogic.Add(nextMoney);
            e.EventResult = "Success";
        }
Ejemplo n.º 5
0
 void departmentCostListView_SearchDepartmentCostEvent(object sender, DepartmentCostEventArgs e)
 {
     if(e.FromDate == DateTime.MinValue && e.ToDate == DateTime.MinValue)
        {
         ObjectCriteria objectCriteria = new ObjectCriteria();
         objectCriteria.AddBetweenCriteria("DepartmentCostPK.CostDate", DateUtility.ZeroTime(DateTime.Now),
                                          DateUtility.MaxTime(DateTime.Now));
         objectCriteria.AddEqCriteria("DepartmentCostPK.DepartmentId", CurrentDepartment.Get().DepartmentId);
        IList list = DepartmentCostLogic.FindAll(objectCriteria);
        e.CostList = list;
        }
 }
Ejemplo n.º 6
0
        void departmentCostEditView_EditDepartmentCostEvent(object sender, DepartmentCostEventArgs e)
        {
            try
            {
                if (e.CreateCost != null)
                    DepartmentCostLogic.Update(e.UpdateCost);
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                e.HasErrors = true;

            }
        }
Ejemplo n.º 7
0
 private void btnCommit_Click(object sender, EventArgs e)
 {
     if (outMoney < 0)
     {
         MessageBox.Show("Xin vui lòng chạy báo cáo trước để lấy số liệu !");
         return;
     }
     DepartmentCostEventArgs eventArgs = new DepartmentCostEventArgs();
     eventArgs.FromDate = DateTime.Now;
     eventArgs.ToDate = DateTime.Now;
     eventArgs.OutMoney = outMoney;
     EventUtility.fireEvent(CommitDepartmentCostEvent,this,eventArgs);
     if(eventArgs.EventResult!=null)
     {
         InfoBox.InformationBox.Show("Chốt sổ thành công !", new AutoCloseParameters(1));
     }
 }