/// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDeleteTime_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(hdfUpdateTimeSheetEventId.Text))
                {
                    return;
                }
                var id = int.Parse(hdfUpdateTimeSheetEventId.Text);

                // delete
                var deletedTimeSheetEvent = TimeSheetEventController.Delete(id);

                // get symbol group
                var timeSheetGroupSymbol = TimeSheetGroupSymbolController.GetById(deletedTimeSheetEvent.GroupSymbolId);

                // update annual leave
                if (timeSheetGroupSymbol.Group == Constant.TimesheetLeave)
                {
                    // get annual leave history by record id and event id
                    var annualLeaveHistorys = AnnualLeaveHistoryController.GetAll(null,
                                                                                  deletedTimeSheetEvent.RecordId.ToString(), deletedTimeSheetEvent.Id, false, null, 1);
                    if (annualLeaveHistorys != null && annualLeaveHistorys.Count > 0)
                    {
                        // delete annual leave history
                        var annualLeaveHistory = AnnualLeaveHistoryController.Delete(annualLeaveHistorys.First().Id);

                        // get annual leave config by record id and year
                        var annualLeaveConfigures = AnnualLeaveConfigureController.GetAll(null, annualLeaveHistory.RecordId.ToString(), null,
                                                                                          annualLeaveHistory.UsedLeaveDate.Year, false, null, 1);
                        if (annualLeaveConfigures != null && annualLeaveConfigures.Count > 0)
                        {
                            // get first item
                            var annualLeaveConfigure = annualLeaveConfigures.First();

                            // calc used and remain leave day
                            annualLeaveConfigure.UsedLeaveDay -= annualLeaveHistory.UsedLeaveDay;
                            if (annualLeaveConfigure.AnnualLeaveDay > 0)
                            {
                                annualLeaveConfigure.RemainLeaveDay =
                                    annualLeaveConfigure.AnnualLeaveDay - annualLeaveConfigure.UsedLeaveDay;
                            }
                            annualLeaveConfigure.EditedBy = CurrentUser.User.UserName;

                            // update annual leave configure
                            AnnualLeaveConfigureController.Update(annualLeaveConfigure);
                        }
                    }
                }

                gridUpdateTimeSheet.Reload();
                gridTimeSheet.Reload();
            }
            catch (Exception ex)
            {
                Dialog.ShowNotification("Có lỗi xảy ra" + ex.Message);
            }
        }
Esempio n. 2
0
        protected void Delete(object sender, DirectEventArgs e)
        {
            try
            {
                // init id
                var param = e.ExtraParams["Id"];
                // parse id
                if (!int.TryParse(param, out var id) || id <= 0)
                {
                    // parse error, show error
                    Dialog.ShowError("Có lỗi xảy ra trong quá trình xử lý");
                    return;
                }
                // delete
                var deletedTimeSheetEvent = TimeSheetEventController.Delete(id);

                // get symbol group
                var timeSheetGroupSymbol = TimeSheetGroupSymbolController.GetById(deletedTimeSheetEvent.GroupSymbolId);

                // update annual leave
                if (timeSheetGroupSymbol.Group == Constant.TimesheetLeave)
                {
                    // get annual leave history by record id and event id
                    var annualLeaveHistorys = AnnualLeaveHistoryController.GetAll(null,
                                                                                  deletedTimeSheetEvent.RecordId.ToString(), deletedTimeSheetEvent.Id, false, null, 1);
                    if (annualLeaveHistorys != null && annualLeaveHistorys.Count > 0)
                    {
                        // delete annual leave history
                        var annualLeaveHistory = AnnualLeaveHistoryController.Delete(annualLeaveHistorys.First().Id);

                        // get annual leave config by record id and year
                        var annualLeaveConfigures = AnnualLeaveConfigureController.GetAll(null, annualLeaveHistory.RecordId.ToString(), null,
                                                                                          annualLeaveHistory.UsedLeaveDate.Year, false, null, 1);
                        if (annualLeaveConfigures != null && annualLeaveConfigures.Count > 0)
                        {
                            // get first item
                            var annualLeaveConfigure = annualLeaveConfigures.First();

                            // calc used and remain leave day
                            annualLeaveConfigure.UsedLeaveDay -= annualLeaveHistory.UsedLeaveDay;
                            if (annualLeaveConfigure.AnnualLeaveDay > 0)
                            {
                                annualLeaveConfigure.RemainLeaveDay =
                                    annualLeaveConfigure.AnnualLeaveDay - annualLeaveConfigure.UsedLeaveDay;
                            }
                            annualLeaveConfigure.EditedBy = CurrentUser.User.UserName;

                            // update annual leave configure
                            AnnualLeaveConfigureController.Update(annualLeaveConfigure);
                        }
                    }
                }

                // reload data
                gridTimeAdjust.Reload();
            }
            catch (Exception exception)
            {
                Dialog.ShowError(exception);
            }
        }