public ActionResult Create([Bind(Include = "extraWorkTypeId,staffNr,otTime,startHour,endHour,duration,durationType,otReason")] ExtraWorkRecord model)
        {
            ResultMessage msg = new ResultMessage();

            try
            {
                model.durationType = (int)DurationType.Hour;

                msg = DoValidation(model);

                if (!msg.Success)
                {
                    return(Json(msg, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    IExtraWorkRecordService cs = new ExtraWorkRecordService(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));
            }
        }
Exemple #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));
        }
        // GET: ExtraWorkRecord/Delete/5
        public ActionResult Delete(int id)
        {
            IExtraWorkRecordService cs = new ExtraWorkRecordService(Settings.Default.db);

            ExtraWorkRecord cp = cs.FindById(id);

            SetDropDownList(cp);
            return(View(cp));
        }
        // GET: ExtraWorkRecord/Edit/5
        public ActionResult Edit(int id)
        {
            IExtraWorkRecordService cs = new ExtraWorkRecordService(Settings.Default.db);

            ExtraWorkRecord jt = cs.FindById(id);

            SetDropDownList(jt);
            return(View(jt));
        }
        public ActionResult Search([Bind(Include = "staffNr,extraWorkTypeId,durStart,durEnd")] ExtraWorkRecordSearchModel q)
        {
            SetDropDownList(null);

            int pageIndex = 0;

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

            IExtraWorkRecordService ss = new ExtraWorkRecordService(Settings.Default.db);

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

            ViewBag.Query = q;

            return(View("Index", models));
        }
        public ActionResult Index(int?page)
        {
            SetDropDownList(null);

            int pageIndex = PagingHelper.GetPageIndex(page);

            ExtraWorkRecordSearchModel q = new ExtraWorkRecordSearchModel();

            IExtraWorkRecordService ss = new ExtraWorkRecordService(Settings.Default.db);

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

            ViewBag.Query = q;

            ExtraWorkRecordInfoModel info = ss.GetExtraWorkRecordInfo(q);

            ViewBag.Info = info;

            return(View(models));
        }
        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
                {
                    IExtraWorkRecordService cs = new ExtraWorkRecordService(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));
            }
        }
        /// <summary>
        /// 导入
        /// </summary>
        /// <returns></returns>
        public ImportMessage Import()
        {
            ImportMessage msg = new ImportMessage()
            {
                Success = true
            };

            try
            {
                FileInfo fileInfo = new FileInfo(this.FilePath);
                List <ExtraWorkRecordExcelModel> records = new List <ExtraWorkRecordExcelModel>();
                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 ExtraWorkRecordExcelModel()
                            {
                                OtTimeStr        = 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(),
                                ExtraWorkTypeStr = ws.Cells[i, 7].Value == null ? string.Empty : ws.Cells[i, 7].Value.ToString(),
                                OtReason         = 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 < ExtraWorkRecordExcelModel.Headers.Count(); i++)
                                {
                                    sheet.Cells[1, i + 1].Value = ExtraWorkRecordExcelModel.Headers[i];
                                }
                                ///写入错误数据
                                for (int i = 0; i < records.Count(); i++)
                                {
                                    sheet.Cells[i + 2, 1].Value = records[i].OtTimeStr;
                                    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].Duration;
                                    sheet.Cells[i + 2, 7].Value = records[i].DurationTypeStr;
                                    sheet.Cells[i + 2, 8].Value = records[i].OtReason;
                                    sheet.Cells[i + 2, 9].Value = records[i].ValidateMessage.ToString();
                                }

                                /// 保存
                                ep.Save();
                            }
                        }
                        else
                        {
                            /// 数据写入数据库
                            List <ExtraWorkRecord>  details = ExtraWorkRecordExcelModel.Convert(records);
                            IExtraWorkRecordService ss      = new ExtraWorkRecordService(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);
        }