コード例 #1
0
        public ActionResult Create([Bind(Include = "absenceTypeId,staffNr,startHour,endHour, duration,durationType,remark,absenceDate")] AbsenceRecrod model)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                msg = DoValidation(model);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    model.durationType = (int)DurationType.Hour;
                    IAbsenceRecordService cs = new AbsenceRecordService(Settings.Default.db);
                    bool isSucceed           = cs.Create(model);

                    msg.Success = isSucceed;
                    msg.Content = isSucceed ? "" : "添加失败";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultMessage()
                {
                    Success = false, Content = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
        // GET: AttendanceRecordCal/Delete/5
        public ActionResult Delete(int id)
        {
            IAttendanceRecordCalService arcs = new AttendanceRecordCalService(Settings.Default.db);

            AttendanceRecordCal record = arcs.FindById(id);

            SetExtraWorkTypeList(record.extraworkType);



            if (record != null)
            {
                AbsenceRecordView   absenceRecord   = new AbsenceRecordService(Settings.Default.db).FindViewByStaffNrAndDate(record.staffNr, record.attendanceDate);
                ExtraWorkRecordView extraWorkRecord = new ExtraWorkRecordService(Settings.Default.db).FindViewByStaffNrAndDate(record.staffNr, record.attendanceDate);

                List <AttendanceRecordDetailView> records = new List <AttendanceRecordDetailView>();
                IAttendanceRecordDetailService    s       = new AttendanceRecordDetailService(Settings.Default.db);
                records = s.GetDetailsViewByStaffAndDateWithExtrawork(record.staffNr, record.attendanceDate);
                ViewData["attendRecords"]   = records;
                ViewData["absenceRecord"]   = absenceRecord;
                ViewData["extraWorkRecord"] = extraWorkRecord;
            }
            else
            {
                SetExtraWorkTypeList(null);
            }


            return(View(record));
        }
コード例 #3
0
        // GET: AbsenceRecrod/Delete/5
        public ActionResult Delete(int id)
        {
            IAbsenceRecordService cs = new AbsenceRecordService(Settings.Default.db);

            AbsenceRecrod cp = cs.FindById(id);

            SetDropDownList(cp);
            return(View(cp));
        }
コード例 #4
0
        // GET: AbsenceRecrod/Edit/5
        public ActionResult Edit(int id)
        {
            IAbsenceRecordService cs = new AbsenceRecordService(Settings.Default.db);

            AbsenceRecrod jt = cs.FindById(id);

            SetDropDownList(jt);
            return(View(jt));
        }
コード例 #5
0
        public ActionResult Search([Bind(Include = "staffNr,absenceTypeId,durStart,durEnd")] AbsenceRecrodSearchModel q)
        {
            SetDropDownList(null);

            int pageIndex = 0;

            int.TryParse(Request.QueryString.Get("page"), out pageIndex);
            pageIndex = PagingHelper.GetPageIndex(pageIndex);

            IAbsenceRecordService ss = new AbsenceRecordService(Settings.Default.db);

            IPagedList <AbsenceRecrod> models = ss.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize);

            ViewBag.Query = q;

            return(View("Index", models));
        }
コード例 #6
0
        public ActionResult Index(int?page)
        {
            SetDropDownList(null);

            int pageIndex = PagingHelper.GetPageIndex(page);

            AbsenceRecrodSearchModel q = new AbsenceRecrodSearchModel();

            IAbsenceRecordService ss = new AbsenceRecordService(Settings.Default.db);

            IPagedList <AbsenceRecrod> models = ss.Search(q).ToPagedList(pageIndex, Settings.Default.pageSize);

            ViewBag.Query = q;

            AbsenceRecrodInfoModel info = ss.GetAbsenceRecrodInfo(q);

            ViewBag.Info = info;

            return(View(models));
        }
コード例 #7
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                ////存在员工时不可删除
                //IAbsenceRecordService shfSi = new AbsenceRecordService(Settings.Default.db);
                //List<AbsenceRecrod> shf = shfSi.FindByAbsenceType(id);

                //if (null != shf && shf.Count() > 0)
                //{
                //    msg.Success = false;
                //    msg.Content = "缺勤类型正在使用,不能删除!";

                //    return Json(msg, JsonRequestBehavior.AllowGet);
                //}
                //else
                {
                    IAbsenceRecordService cs = new AbsenceRecordService(Settings.Default.db);
                    bool isSucceed           = cs.DeleteById(id);

                    msg.Success = isSucceed;
                    msg.Content = isSucceed ? "" : "删除失败";

                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                return(Json(new ResultMessage()
                {
                    Success = false, Content = ex.Message
                }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #8
0
        /// <summary>
        /// 导入
        /// </summary>
        /// <returns></returns>
        public ImportMessage Import()
        {
            ImportMessage msg = new ImportMessage()
            {
                Success = true
            };

            try
            {
                FileInfo fileInfo = new FileInfo(this.FilePath);
                List <AbsenceRecordExcelModel> records = new List <AbsenceRecordExcelModel>();
                string sheetName = "Tmp";
                /// 读取excel文件
                using (ExcelPackage ep = new ExcelPackage(fileInfo))
                {
                    if (ep.Workbook.Worksheets.Count > 0)
                    {
                        ExcelWorksheet ws = ep.Workbook.Worksheets.First();
                        sheetName = ws.Name;
                        for (int i = 2; i <= ws.Dimension.End.Row; i++)
                        {
                            records.Add(new AbsenceRecordExcelModel()
                            {
                                AbsenceDateStr = ws.Cells[i, 1].Value == null ? string.Empty : ws.Cells[i, 1].Value.ToString(),
                                StaffNr        = ws.Cells[i, 2].Value == null ? string.Empty : ws.Cells[i, 2].Value.ToString(),
                                Name           = ws.Cells[i, 3].Value == null ? string.Empty : ws.Cells[i, 3].Value.ToString(),
                                StartHourStr   = ws.Cells[i, 4].Value == null ? string.Empty : ws.Cells[i, 4].Value.ToString(),
                                EndHourStr     = ws.Cells[i, 5].Value == null ? string.Empty : ws.Cells[i, 5].Value.ToString(),
                                Duration       = ws.Cells[i, 6].Value == null ? string.Empty : ws.Cells[i, 6].Value.ToString(),
                                AbsenceTypeStr = ws.Cells[i, 7].Value == null ? string.Empty : ws.Cells[i, 7].Value.ToString(),
                                Remark         = ws.Cells[i, 8].Value == null ? string.Empty : ws.Cells[i, 8].Value.ToString()
                            });
                        }
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Content = "文件不包含数据表,请检查";
                    }
                }
                if (msg.Success)
                {
                    /// 验证数据
                    if (records.Count > 0)
                    {
                        Validates(records);
                        if (records.Where(s => s.ValidateMessage.Success == false).Count() > 0)
                        {
                            /// 创建错误文件
                            msg.Success = false;
                            /// 写入文件夹,然后返回
                            string tmpFile = FileHelper.CreateFullTmpFilePath(Path.GetFileName(this.FilePath), true);
                            msg.Content       = FileHelper.GetDownloadTmpFilePath(tmpFile);
                            msg.ErrorFileFeed = true;

                            FileInfo tmpFileInfo = new FileInfo(tmpFile);
                            using (ExcelPackage ep = new ExcelPackage(tmpFileInfo))
                            {
                                ExcelWorksheet sheet = ep.Workbook.Worksheets.Add(sheetName);
                                ///写入Header
                                for (int i = 0; i < AbsenceRecordExcelModel.Headers.Count(); i++)
                                {
                                    sheet.Cells[1, i + 1].Value = AbsenceRecordExcelModel.Headers[i];
                                }
                                ///写入错误数据
                                for (int i = 0; i < records.Count(); i++)
                                {
                                    sheet.Cells[i + 2, 1].Value = records[i].AbsenceDateStr;
                                    sheet.Cells[i + 2, 2].Value = records[i].StaffNr;
                                    sheet.Cells[i + 2, 3].Value = records[i].Name;
                                    sheet.Cells[i + 2, 4].Value = records[i].StartHourStr;
                                    sheet.Cells[i + 2, 5].Value = records[i].EndHourStr;
                                    sheet.Cells[i + 2, 6].Value = records[i].AbsenceTypeStr;
                                    sheet.Cells[i + 2, 7].Value = records[i].Remark;
                                    sheet.Cells[i + 2, 8].Value = records[i].Duration;
                                    sheet.Cells[i + 2, 9].Value = records[i].ValidateMessage.ToString();
                                }

                                /// 保存
                                ep.Save();
                            }
                        }
                        else
                        {
                            /// 数据写入数据库
                            List <AbsenceRecrod>  details = AbsenceRecordExcelModel.Convert(records);
                            IAbsenceRecordService ss      = new AbsenceRecordService(this.DbString);
                            ss.Creates(details);
                        }
                    }
                    else
                    {
                        msg.Success = false;
                        msg.Content = "文件不包含数据,请检查";
                    }
                }
            }
            catch (Exception e)
            {
                msg.Success = false;
                msg.Content = "导入失败:" + e.Message + ",请联系系统管理员";
                LogUtil.Logger.Error(e.Message);
                LogUtil.Logger.Error(e.StackTrace);
            }
            return(msg);
        }