private void SetupForm(Timesheet.Timesheet ts) { string monthName = new DateTime(ts.year, ts.month, 1).ToString("MMM", CultureInfo.InvariantCulture); this.Text = monthName + " " + ts.year + " Qtr: " + ts.quarter; _lblDate.Text = monthName + " " + ts.year + " Qtr: " + ts.quarter; }
public static Timesheet.Timesheet ToTimesheet(this DataTable value) { Timesheet.Timesheet ts = new Timesheet.Timesheet(); Timesheet.Employee emp = new Timesheet.Employee(); Timesheet.Day day = new Timesheet.Day(); Timesheet.Hours hour; int pair = 0; DateTime dayCheck; foreach (DataRow row in value.Rows) { dayCheck = new DateTime(); if (DateTime.TryParse(row["Date"].ToString(), out dayCheck)) { if (day.date != (DateTime)row["Date"]) { if (pair >= 1) { ts.days.Add(day); pair = 0; } day = new Timesheet.Day(); day.date = (DateTime)row["Date"]; day.description = row["DateDescription"].ToString(); } hour = new Timesheet.Hours(); hour.start = row["StartHours"].ToString(); hour.end = row["EndHours"].ToString(); hour.hours = (double)row["Hours"]; hour.lunch = (double)row["Lunch"]; day.AddHoursObject(hour); emp.firstname = row["FirstName"].ToString(); emp.lastname = row["LastName"].ToString(); emp.employeeToken = Guid.Parse(Properties.Settings.Default.EmployeeToken); emp.email = row["DefaultEmailAddress"].ToString(); ts.month = Int32.Parse(row["Month"].ToString()); ts.year = Int32.Parse(row["Year"].ToString()); ts.quarter = Int32.Parse(row["Quarter"].ToString()); ts.totalhours = float.Parse(row["TotalHours"].ToString()); pair++; } } ts.days.Add(day); ts.employee = emp; return(ts); }
public ActionResult AddOrEdit(Timesheet.Timesheet ts) { if (string.IsNullOrEmpty(ts.TimesheetUser)) { ts.TimesheetUser = Common.CommonHelper.CurrentUser; } if (ts.Id == 0) { ts.Creator = Common.CommonHelper.CurrentUser; _appService.CreateTimesheet(ts); return(Json(new { success = true, message = "新增工时成功!" }, JsonRequestBehavior.AllowGet)); } else { _appService.UpdateTimesheet(ts); return(Json(new { success = true, message = "更新工时成功!" }, JsonRequestBehavior.AllowGet)); } }
public _timesheetForm(Timesheet.Timesheet ts) { InitializeComponent(); SetupForm(ts); DataTable dt = FlattenToDatatable(ts); //var timesheetrange = (from table in dt.AsEnumerable() // group table by table["Date"] into g // let f = g.FirstOrDefault() // select new // { // MinDate = g.Min(c => c["Date"]), // MaxDate = g.Max(c => c["Date"]), // }); _gridTimesheet.DataSource = dt; FormatDataGridView(); }
public DataTable FlattenToDatatable(Timesheet.Timesheet ts) { DataTable dt = new DataTable(); DataRow row; dt.TableName = "Records"; DataColumn dateCol = new DataColumn(); dateCol.ColumnName = "Date"; DataColumn startCol = new DataColumn(); startCol.ColumnName = "StartHours"; DataColumn endCol = new DataColumn(); endCol.ColumnName = "EndHours"; DataColumn hourCol = new DataColumn(); hourCol.ColumnName = "Hours"; dt.Columns.Add(dateCol); dt.Columns.Add(startCol); dt.Columns.Add(endCol); dt.Columns.Add(hourCol); foreach (Timesheet.Day day in ts.days) { foreach (Timesheet.Hours hour in day.hours) { row = dt.NewRow(); string dateOnly = day.date.ToShortDateString(); row["Date"] = dateOnly; row["StartHours"] = hour.start; row["EndHours"] = hour.end; row["Hours"] = hour.hours; dt.Rows.Add(row); } } return(dt); }
public GoogleSheets(Timesheet.Timesheet ts) { _ts = ts; DriveService service = GetCredentials().Result; //stream.CopyTo(mstream); fileTitle = CreateExcelTimesheet(); Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File(); body.Title = fileTitle; body.Description = "Test1"; body.MimeType = "application/vnd.ms-excel"; byte[] byteArray = System.IO.File.ReadAllBytes(@"C:\Dump\" + fileTitle); MemoryStream mstream = new MemoryStream(byteArray); FilesResource.InsertMediaUpload request = service.Files.Insert(body, mstream, "application/vnd.ms-excel"); request.Upload(); Google.Apis.Drive.v2.Data.File file = request.ResponseBody; }
private void AutoCreateManagerTimesheet(DateTime timeNow) { //每个部门的manager都自动创建本周的工时,项目对应名称是“部门管理”的项目,还需要结合节假日 var project = IocManager.Instance.Resolve <IProjectAppService>().GetAllProjectList().Where(p => p.ProjectName == "部门管理").FirstOrDefault(); if (project != null) { List <DateTime> dateTimeList = Comm.GetWorkDateTimes(timeNow); //拿到当前日期区间没填写工时的部门manager var userList = IocManager.Instance.Resolve <IReportAppService>().GetDepartmentManagerList(dateTimeList.Min(), dateTimeList.Max()); var tsAppService = IocManager.Instance.Resolve <ITimesheetAppService>(); for (int k = 0; k < userList.Rows.Count; k++) { for (int i = 0; i < dateTimeList.Count; i++) { Timesheet.Timesheet ts = new Timesheet.Timesheet() { ApprovedTime = timeNow, Approver = "", CreationTime = timeNow, Creator = "", IsDeleted = false, LastModifier = "", LastModifyTime = timeNow, ProjectGroup = "", ProjectID = project.Id, ProjectName = project.ProjectName, Remarks = "自动创建", Status = ApproveStatus.Approved, TimesheetDate = dateTimeList[i], TimesheetUser = userList.Rows[k]["UserNum"].ToString(), WorkContent = "部门管理", WorkflowInstanceID = "", Workload = 8 }; tsAppService.CreateTimesheet(ts); } } } }
public void CreateWorkbook(Timesheet.Timesheet ts, string filetitle, int qtyWorksheets) { _ts = ts; //create new xls file _file = filetitle + ".xls"; workbook = new Workbook(); worksheets = new List <Worksheet>(); for (int i = 1; i <= qtyWorksheets; i++) { worksheets.Add(new Worksheet("Worksheet" + i)); } for (int i = 0; i < 150; i++) { for (int j = 0; j < 10; j++) { worksheets[0].Cells[i + 10, j + 10] = new Cell(" "); } } }
/// <summary> /// 获取当前工时的下一个操作人 /// </summary> /// <param name="ts"></param> /// <returns></returns> private string GetNextOperator(Timesheet.Timesheet ts) { //根据项目对应的类型Category判断 var projectInfo = _projectService.GetAllProjectList().Where(p => p.Id == ts.ProjectID).FirstOrDefault(); if (projectInfo != null) { if (projectInfo.Category == "售前售后") {//Category是售前售后则走科室审批(先找user对应的team,然后再找team的teamleader) var us = GetUserTeamId(); if (us != -1) { return(_teamService.GetTeam(us).TeamLeader); } } else {//Category是其他则走项目的经理,(先找项目,然后找项目的projectmanager) return(projectInfo.ProjectManagerID); } } return(""); }
public void AddTimesheet(Timesheet.Timesheet ts) { int i = 2; DateTime dtFrom = new DateTime(); DateTime dtTo = new DateTime(); DateTime date = new DateTime(); foreach (Timesheet.Day day in ts.days) { date = DateTime.Parse(day.date.ToString()); dtFrom = DateTime.Parse(day.hours[0].start); dtTo = DateTime.Parse(day.hours[0].end); AddCellToWorksheet(0, i, 0, date.ToString("MM/dd/yyyy")); AddCellToWorksheet(0, i, 1, dtFrom.ToString("hh:mm tt")); AddCellToWorksheet(0, i, 2, dtTo.ToString("hh:mm tt")); AddCellToWorksheet(0, i, 3, day.hours[0].lunch.ToString()); AddCellToWorksheet(0, i, 4, day.hours[0].hours.ToString()); i++; } AddCellToWorksheet(0, i + 2, 3, "Total:"); AddCellToWorksheet(0, i + 2, 4, _ts.totalhours.ToString()); }
public TimesheetClient.TimesheetService.ResponseData AddTimesheet(Timesheet.Timesheet ts) { return(base.Channel.AddTimesheet(ts)); }
public ActionResult AddOrEditForWeek(string id = null) { var startDate = DateTime.Now.Date; var endDate = DateTime.Now.Date; if (string.IsNullOrEmpty(id)) { var dateNow = DateTime.Now.Date; var dayOfWeek = (int)dateNow.DayOfWeek; if (dayOfWeek == 0) { dayOfWeek = 7; } startDate = startDate.AddDays(-1 * dayOfWeek + 1); endDate = startDate.AddDays(6); } else { startDate = DateTime.Parse(id.Split('到')[0]); endDate = DateTime.Parse(id.Split('到')[1]); } //判断endDate是否为调休成上班,如果是则周日也允许填写工时 var workDate = Comm.GetWorkDateTimes(startDate); startDate = workDate.Min(); endDate = workDate.Max(); Timesheet.TimesheetForWeek tfw = new TimesheetForWeek(); tfw.startDate = startDate.ToString("yyyy-MM-dd"); tfw.endDate = endDate.ToString("yyyy-MM-dd"); var tss = _appService.GetAllTimesheetsByUser(Common.CommonHelper.CurrentUser, startDate, endDate); decimal allWorkload = Math.Round(tss.Sum(t => t.Workload).Value, 0); decimal allWorkloadByWorkday = 0; for (int i = 0; i < workDate.Count; i++) { allWorkloadByWorkday += 8; Timesheet.Timesheet findTimesheet = tss.Find(ts => { return(ts.TimesheetDate.Value == workDate[i]); }); if (findTimesheet == null) {//把缺少的日期初始化一个空白的记录 tss.Add(new Timesheet.Timesheet() { Id = 0, TimesheetDate = workDate[i], Status = ApproveStatus.Draft, }); } } //排序 tss.Sort((a, b) => a.TimesheetDate.Value.CompareTo(b.TimesheetDate.Value)); //将项目的名称更新到对象中,方便前端展示 var allProjectList = _projectService.GetAllProjectList(); foreach (var tsItem in tss) { if (tsItem.ProjectID.HasValue && tsItem.ProjectID.Value != 0) { tsItem.ProjectName = Common.CommonHelper.GetProjectNameByProjectID(allProjectList, tsItem.ProjectID.Value); } } //SetProjectListToViewData(); tfw.AllWorkloadByInput = allWorkload; tfw.AllWorkloadByWorkDay = allWorkloadByWorkday; tfw.TimesheetList = tss; return(View(tfw)); }
public static List <Timesheet.Timesheet> ToTimesheet(this DataTable value) { List <Timesheet.Timesheet> _tsList = new List <Timesheet.Timesheet>(); List <DataTable> _dtList = new List <DataTable>(); DataTable _dt = new DataTable(); Timesheet.Timesheet _ts; Timesheet.Employee _emp = new Timesheet.Employee(); Timesheet.Day _day = new Timesheet.Day(); Timesheet.Hours _hour; int pair = 0; var timesheetid = from record in value.AsEnumerable() group record by record.Field <Guid>("ID") into final select final.Key; foreach (Guid id in timesheetid) { var timesheet = from record in value.AsEnumerable() where record.Field <Guid>("ID") == id select record; _dt = timesheet.CopyToDataTable <DataRow>(); _dtList.Add(_dt); } foreach (DataTable dt in _dtList) { _ts = new Timesheet.Timesheet(); foreach (DataRow row in dt.Rows) { if (_day.date != (DateTime)row["Date"]) { if (pair >= 1) { _ts.days.Add(_day); pair = 0; } _day = new Timesheet.Day(); _day.date = (DateTime)row["Date"]; _day.description = row["DateDescription"].ToString(); } _hour = new Timesheet.Hours(); _hour.start = row["StartHours"].ToString(); _hour.end = row["EndHours"].ToString(); _hour.hours = (double)row["Hours"]; _hour.lunch = (double)row["Lunch"]; _day.AddHoursObject(_hour); _emp.firstname = row["FirstName"].ToString(); _emp.lastname = row["LastName"].ToString(); _emp.email = row["DefaultEmailAddress"].ToString(); _emp.employeeToken = (Guid)row["EmployeeToken"]; _ts.month = Int32.Parse(row["Month"].ToString()); _ts.year = Int32.Parse(row["Year"].ToString()); _ts.quarter = Int32.Parse(row["Quarter"].ToString()); _ts.totalhours = float.Parse(row["TotalHours"].ToString()); pair++; } _ts.days.Add(_day); _ts.employee = _emp; _tsList.Add(_ts); pair = 0; } return(_tsList); }