コード例 #1
0
        private List <PeriodInfo> ParseSchoolDay(IExcelDataReader reader, DayOfWeek day, bool isUpperRowOfWeek)
        {
            int dayColumnWidth             = PeriodHelper.GetCountOfPeriods();
            int firstPeriodAdditionalValue = SubjectSectionWidth + (dayColumnWidth * ((int)day - 1)) - 1;

            var periodsInfo = new List <PeriodInfo>();

            for (PeriodNumber number = PeriodNumber.First; PeriodHelper.IsValidPeriod(number); number++)
            {
                int column = firstPeriodAdditionalValue + (int)number;

                string info = GetStringValue(reader, column);

                var periodInfo = new PeriodInfo()
                {
                    Number = number
                };

                if (isUpperRowOfWeek)
                {
                    periodInfo.UpperInfo = info;
                }
                else
                {
                    periodInfo.LowerInfo = info;
                }

                periodsInfo.Add(periodInfo);
                //ConsoleHelper.WriteOk($"День: {currentDay}, Пара: {currentPeriod}, " +
                //    $"Вверх: {isUpperRowOfWeek}, Четная: {isEvenWeek}," + period);
            }

            return(periodsInfo);
        }
コード例 #2
0
        /// <summary>
        /// 新增PeriodData数据并且更新到PeriodUserInfo
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userName"></param>
        private void addPeriodData(PeriodInfo data, string userName)
        {
            PeriodData pd = new PeriodData()
            {
                MC_Begin    = data.MC_Begin,
                MC_Days     = data.MC_Days,
                MC_Cycle    = data.MC_Cycle,
                MC_Finish   = data.MC_Begin.AddDays(data.MC_Cycle),
                Period_Type = 1,
                UserName    = userName
            };

            periodDB.PeriodData.Add(pd);
            // 修改再上次经期的结束时间
            PeriodData lpd = getLastPeriodData(userName);

            if (lpd != null)
            {
                lpd.MC_Finish = data.MC_Begin;
                lpd.MC_Cycle  = Convert.ToInt32(lpd.MC_Finish.Subtract(lpd.MC_Begin).TotalDays);
            }
            var pui = periodDB.PeriodUserInfo.SingleOrDefault(m => m.UserName == userName);

            if (pui != null)
            {
                pui.Last_MC_Begin = data.MC_Begin;
                pui.MC_Cycle      = data.MC_Cycle;
                pui.MC_days       = data.MC_Days;
                periodDB.SaveChanges();
            }
            // 保存数据
            periodDB.SaveChanges();
        }
コード例 #3
0
        /******** 经期助手辅助程序 ********/
        /// <summary>
        /// 更新最近一次的经期数据,并同步到PeriodUserInfo
        /// </summary>
        /// <param name="data"></param>
        /// <param name="userName"></param>
        private void updatePeriodData(PeriodInfo data, string userName)
        {
            // 获取最近一次的经期数据
            PeriodData pd = (from m in periodDB.PeriodData
                             where m.UserName == userName
                             orderby m.MC_Begin descending
                             select m).FirstOrDefault();

            if (pd != null)
            {
                // 修改上一次经期结束时间
                PeriodData lpd = getLastPeriodData(pd.MC_Begin, userName);
                if (lpd != null)
                {
                    lpd.MC_Finish = data.MC_Begin;
                    lpd.MC_Cycle  = Convert.ToInt32(lpd.MC_Finish.Subtract(lpd.MC_Begin).TotalDays);
                }
                // 修改记录
                pd.MC_Begin  = data.MC_Begin;
                pd.MC_Cycle  = data.MC_Cycle;
                pd.MC_Days   = data.MC_Days;
                pd.MC_Finish = data.MC_Begin.AddDays(data.MC_Cycle);
                // 更新PeriodUserInfo
                var pui = periodDB.PeriodUserInfo.SingleOrDefault(m => m.UserName == userName);
                if (pui != null)
                {
                    pui.Last_MC_Begin = data.MC_Begin;
                    pui.MC_Cycle      = data.MC_Cycle;
                    pui.MC_days       = data.MC_Days;
                    periodDB.SaveChanges();
                }
                // 保存数据
                periodDB.SaveChanges();
            }
        }
コード例 #4
0
        public JsonResult setItCome(int year, int month, int day)
        {
            PeriodData pd          = getLastPeriodData(User.Identity.Name);
            DateTime   periodStart = new DateTime(year, month, day);

            if (pd != null)
            {
                if (periodStart >= pd.MC_Begin.AddDays(14))
                {
                    PeriodInfo info = new PeriodInfo()
                    {
                        MC_Begin = periodStart,
                        MC_Days  = pd.MC_Days,
                        MC_Cycle = Convert.ToInt32(periodStart.Subtract(pd.MC_Begin).TotalDays)
                    };
                    addPeriodData(info, User.Identity.Name);
                    return(Json(new { result = "SUCCESS" }));
                }
                else
                {
                    PeriodInfo info = new PeriodInfo()
                    {
                        MC_Begin = periodStart,
                        MC_Days  = pd.MC_Days,
                        MC_Cycle = pd.MC_Cycle
                    };
                    updatePeriodData(info, User.Identity.Name);
                    return(Json(new { result = "SUCCESS" }));
                }
            }
            return(Json(new { result = "FAIL" }));
        }
        internal List <PeriodInfo> GetMonthlySummaries(List <AccountMarketValue> marketValues, List <CashFlow> cashFlows)
        {
            // Slow this process down to simulate it taking a longer time
            // You wouldn't do this in real life, it is just for the demo
            Thread.Sleep(600);

            // We want to get the market values for all the month ends plus the first day the
            // account had funds and last day the account had funds to calc performance
            var firstMarketValueDate = marketValues.First().Date;
            var lastMarketValueDate  = marketValues.Last().Date;
            var perfMarketValues     = marketValues
                                       .Where(mv => mv.TradeDate.IsMonthEnd ||
                                              mv.Date.IsSameDate(firstMarketValueDate) ||
                                              mv.Date.IsSameDate(lastMarketValueDate))
                                       .ToList();

            // This creates the performance periods.  The first and last period are generally
            // partial months
            List <PeriodInfo> monthlySummaries = new List <PeriodInfo>();

            using (MiniProfiler.Current.Step("Creating Performance Periods"))
            {
                for (int i = 1; i < perfMarketValues.Count; i++)
                {
                    var isFirstPeriod = (i == 1);
                    var isLastPeriod  = (i == perfMarketValues.Count - 1);

                    var startingMarketValue = perfMarketValues[i - 1];
                    var endingMarketValue   = perfMarketValues[i];

                    PeriodInfo period = new PeriodInfo()
                    {
                        PeriodNumber        = i,
                        StartingDate        = (i == 1) ? startingMarketValue.Date : endingMarketValue.Date.FirstDayOfMonth(),
                        StartingMarketValue = (i == 1) ? 0.0m : startingMarketValue.MarketValue,
                        EndingDate          = (isLastPeriod && !endingMarketValue.TradeDate.IsMonthEnd)
                            ? endingMarketValue.Date : endingMarketValue.Date.LastDayOfMonth(),
                        EndingMarketValue = endingMarketValue.MarketValue
                    };
                    monthlySummaries.Add(period);
                }
            }

            // Now assign the Cash Flows to each period
            using (MiniProfiler.Current.Step($"Assigning Cash Flows - { cashFlows.Count} flows"))
            {
                foreach (var cashFlow in cashFlows)
                {
                    var period = monthlySummaries
                                 .First(pp => cashFlow.Date.IsOnOrBetweenDates(pp.StartingDate, pp.EndingDate));

                    period.CashFlows.Add(cashFlow.Amount);
                }
            }

            return(monthlySummaries);
        }
コード例 #6
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        public GoalInfo CloneGoal(GoalInfo goal, PeriodInfo newPeriod)
        {
            GoalInfo cloneGoal = (GoalInfo)((ICloneable)goal).Clone();

            cloneGoal.StartDate  = newPeriod.StartDate;
            cloneGoal.DueDate    = newPeriod.EndDate;
            cloneGoal.EndDate    = newPeriod.EndDate;
            cloneGoal.Definition = "CLONE --- " + goal.Definition;
            cloneGoal.Status     = DTC.StatusEnum.Running;
            cloneGoal.OwnerID    = DB.Owner.GetOwnerID(cloneGoal.Range, cloneGoal.StartDate);

            return(cloneGoal);
        }
コード例 #7
0
 public int Compare(PeriodInfo x, PeriodInfo y)
 {
     if (x.Sort == y.Sort)
     {
         return(0);
     }
     else if (x.Sort > y.Sort)
     {
         return(1);
     }
     else
     {
         return(-1);
     }
 }
コード例 #8
0
        internal List <PeriodInfo> GetMonthlySummaries(List <AccountMarketValue> marketValues, List <CashFlow> cashFlows)
        {
            // We want to get the market values for all the month ends plus the first day the
            // account had funds and last day the account had funds to calc performance
            var firstMarketValueDate = marketValues.First().Date;
            var lastMarketValueDate  = marketValues.Last().Date;
            var perfMarketValues     = marketValues
                                       .Where(mv => mv.TradeDate.IsMonthEnd ||
                                              mv.Date.IsSameDate(firstMarketValueDate) ||
                                              mv.Date.IsSameDate(lastMarketValueDate))
                                       .ToList();

            // This creates the performance periods.  The first and last period are generally
            // partial months
            List <PeriodInfo> monthlySummaries = new List <PeriodInfo>();

            for (int i = 1; i < perfMarketValues.Count; i++)
            {
                var isFirstPeriod = (i == 1);
                var isLastPeriod  = (i == perfMarketValues.Count - 1);

                var startingMarketValue = perfMarketValues[i - 1];
                var endingMarketValue   = perfMarketValues[i];

                PeriodInfo period = new PeriodInfo()
                {
                    PeriodNumber        = i,
                    StartingDate        = (i == 1) ? startingMarketValue.Date : endingMarketValue.Date.FirstDayOfMonth(),
                    StartingMarketValue = (i == 1) ? 0.0m : startingMarketValue.MarketValue,
                    EndingDate          = (isLastPeriod && !endingMarketValue.TradeDate.IsMonthEnd)
                            ? endingMarketValue.Date : endingMarketValue.Date.LastDayOfMonth(),
                    EndingMarketValue = endingMarketValue.MarketValue
                };
                monthlySummaries.Add(period);
            }


            // Now assign the Cash Flows to each period
            foreach (var cashFlow in cashFlows)
            {
                var period = monthlySummaries
                             .First(pp => cashFlow.Date.IsOnOrBetweenDates(pp.StartingDate, pp.EndingDate));

                period.CashFlows.Add(cashFlow.Amount);
            }

            return(monthlySummaries);
        }
コード例 #9
0
        /// <summary>
        /// Return null if there are no more subjects
        /// </summary>
        private WeekInfo ParseWeek(IExcelDataReader reader, bool isEvenWeek)
        {
            bool      isUpperRowOfWeek = true;
            const int rowCount         = 2;

            WeekInfo weekInfo = null;

            for (int weekRow = 1; weekRow <= rowCount; weekRow++, isUpperRowOfWeek = !isUpperRowOfWeek)
            {
                WeekInfo weekRowInfo = ParseWeekRow(reader, isEvenWeek, isUpperRowOfWeek);
                if (weekRowInfo == null)
                {
                    return(null);
                }

                if (weekInfo == null) // if isUpperRowOfWeek
                {
                    weekInfo = weekRowInfo;
                }
                else
                {
                    foreach (SchoolDayInfo day in weekInfo.Days)
                    {
                        foreach (PeriodInfo period in day.Periods)
                        {
                            PeriodInfo periodInfo = weekRowInfo
                                                    .Days.First(lowDay => lowDay.Day == day.Day)
                                                    .Periods.First(lowPeriod => lowPeriod.Number == period.Number);

                            period.LowerInfo = periodInfo.LowerInfo;
                        }
                    }
                }
            }

            DeleteEmptyPeriodsAndEmptyDays(weekInfo);

            // if empty rows were readed
            if (!weekInfo.Days.Any())
            {
                return(null);
            }

            return(weekInfo);
        }
コード例 #10
0
        public JsonResult setItGone(int year, int month, int day)
        {
            PeriodData pd         = getLastPeriodData(User.Identity.Name);
            DateTime   periodDone = new DateTime(year, month, day);

            if (pd != null)
            {
                PeriodInfo info = new PeriodInfo()
                {
                    MC_Begin = pd.MC_Begin,
                    MC_Cycle = pd.MC_Cycle,
                    MC_Days  = Convert.ToInt32(periodDone.AddDays(1).Subtract(pd.MC_Begin).TotalDays)
                };
                updatePeriodData(info, User.Identity.Name);
                return(Json(new { result = "SUCCESS" }));
            }
            return(Json(new { result = "FAIL" }));
        }
コード例 #11
0
        private PeriodModel MapOnePeriod(PeriodInfo parsedPeriod)
        {
            var period = new PeriodModel
            {
                Number = parsedPeriod.Number,
            };

            period.Cabinet = parsedPeriod.UpperInfo;

            if (!string.IsNullOrEmpty(parsedPeriod.LowerInfo))
            {
                period.IsLecture = parsedPeriod.LowerInfo.Contains("л") || parsedPeriod.LowerInfo.Contains("Л");
            }

            if (!period.IsLecture)
            {
                period.Subgroup = parsedPeriod.LowerInfo;
            }

            // TODO: period.Modification? It is processed manually. There are no template.

            return(period);
        }
コード例 #12
0
        public int AddPeriod(PeriodInfo info)
        {
            string strSql = "insert into Period(PeriodNumber,StartDateTime,PeriodDay,PeriodAlias) values (@PeriodNumber,@StartDateTime,@PeriodDay,@PeriodAlias)";

            return(DBFactory.GetDB(DBType.SQLITE, m_strConn).ExecuteNonQuery(strSql, new DbParameter[] {
                new SQLiteParameter()
                {
                    Value = info.PeriodNumber, ParameterName = "@PeriodNumber"
                },
                new SQLiteParameter()
                {
                    Value = info.StartDateTime, ParameterName = "@StartDateTime"
                },
                new SQLiteParameter()
                {
                    Value = info.PeriodDay, ParameterName = "@PeriodDay"
                },
                new SQLiteParameter()
                {
                    Value = info.PeriodAlias, ParameterName = "@PeriodAlias"
                }
            }));
        }
コード例 #13
0
        public bool IsPeriod(string szHardNumber)
        {
            //return false;
            //UpdatePeriodTotal(new PeriodTotalInfo() { PeriodTotalId = 2, PeriodDay = 1, PeriodBool = true });
            DateTime   CurrentDateTime = DateTime.Now;
            PeriodInfo info            = PeriodBll.GetPeriod(szHardNumber);

            PeriodTotalInfo tinfo = GetPeriodTotal();

            if (tinfo == null)
            {
                //默认试用30天
                AddPeriodTotal(new PeriodTotalInfo()
                {
                    PeriodBool = false,
                    PeriodDay  = 30
                });



                if (info == null)
                {
                    PeriodBll.AddPeriod(new PeriodInfo()
                    {
                        PeriodAlias   = "",
                        PeriodDay     = 30,
                        PeriodNumber  = szHardNumber,
                        StartDateTime = CurrentDateTime.ToString("yyyy-MM-dd HH:mm:ss")
                    });
                }

                return(false);
            }
            else
            {
                if (tinfo.PeriodBool)
                {
                    //试用版本
                    if (info == null)
                    {
                        PeriodBll.AddPeriod(new PeriodInfo()
                        {
                            PeriodAlias   = "",
                            PeriodDay     = 30,
                            PeriodNumber  = GetHardDiskNumber(),
                            StartDateTime = CurrentDateTime.ToString("yyyy-MM-dd HH:mm:ss")
                        });
                        return(false);
                    }
                    else
                    {
                        DateTime dt;
                        bool     result = DateTime.TryParse(info.StartDateTime, out dt);
                        if (result)
                        {
                            if (dt.AddDays(tinfo.PeriodDay) < CurrentDateTime)
                            {
                                //到期
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        }
                        else
                        {
                            //时间类型转换失败,直接试用时间到期
                            return(true);
                        }
                    }
                }
                else
                {
                    //未开启试用版本
                    return(false);
                }
            }
        }
コード例 #14
0
        private void InitializeDataGridViewColumn()
        {
            #region DataGridView的Column建立

            ColumnIndex.Clear(); //清除

            DSResponse       dsrsp      = Config.GetPeriodList();
            DSXmlHelper      helper     = dsrsp.GetContent();
            PeriodCollection collection = new PeriodCollection();
            foreach (XmlElement element in helper.GetElements("Period"))
            {
                PeriodInfo info = new PeriodInfo(element);
                collection.Items.Add(info);
            }

            //SetColumn("colClassName", "班級", true);
            //SetColumn("colSeatNo", "座號", true);
            //int ColumnsIndex = SetColumn("colStudentName", "姓名", true);
            //dataGridView.Columns[ColumnsIndex].Frozen = true;
            //SetColumn("colStudentNumber", "學號", true);
            //SetColumn("colDate", "日期", true);
            //SetColumn("colWeek", "星期", true);
            //SetColumn("colSchoolYear", "學年度", false);
            //SetColumn("colSemester", "學期", false);

            int ColumnsIndex = dataGridView.Columns.Add("colClassName", "班級");
            ColumnIndex.Add("班級", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = true;

            ColumnsIndex = dataGridView.Columns.Add("colSeatNo", "座號");
            ColumnIndex.Add("座號", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = true;

            ColumnsIndex = dataGridView.Columns.Add("colStudentName", "姓名");
            ColumnIndex.Add("姓名", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = true;
            dataGridView.Columns[ColumnsIndex].Frozen       = true;

            ColumnsIndex = dataGridView.Columns.Add("colStudentNumber", "學號");
            ColumnIndex.Add("學號", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = true;

            ColumnsIndex = dataGridView.Columns.Add("colDate", "日期");
            ColumnIndex.Add("日期", ColumnsIndex);
            //dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly = true;
            dataGridView.Columns[ColumnsIndex].Width    = 120;

            ColumnsIndex = dataGridView.Columns.Add("colWeek", "星期");
            ColumnIndex.Add("星期", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].SortMode     = DataGridViewColumnSortMode.NotSortable;
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = true;

            ColumnsIndex = dataGridView.Columns.Add("colSchoolYear", "學年度");
            ColumnIndex.Add("學年度", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].SortMode     = DataGridViewColumnSortMode.NotSortable;
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = false;

            ColumnsIndex = dataGridView.Columns.Add("colSemester", "學期");
            ColumnIndex.Add("學期", ColumnsIndex);
            dataGridView.Columns[ColumnsIndex].SortMode     = DataGridViewColumnSortMode.NotSortable;
            dataGridView.Columns[ColumnsIndex].AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
            dataGridView.Columns[ColumnsIndex].ReadOnly     = false;

            _startIndex = ColumnIndex["學期"] + 1;

            List <string> cols = new List <string>()
            {
                "學年度", "學期"
            };

            foreach (PeriodInfo info in collection.GetSortedList())
            {
                cols.Add(info.Name);

                int columnIndex = dataGridView.Columns.Add(info.Name, info.Name);
                ColumnIndex.Add(info.Name, columnIndex); //節次
                DataGridViewColumn column = dataGridView.Columns[columnIndex];
                column.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader;
                column.SortMode     = DataGridViewColumnSortMode.NotSortable;
                column.ReadOnly     = true;
                column.Tag          = info;
            }
            Campus.Windows.DataGridViewImeDecorator dec = new Campus.Windows.DataGridViewImeDecorator(this.dataGridView, cols);

            #endregion
        }
コード例 #15
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
        public GoalInfo CloneGoal(GoalInfo goal)
        {
            PeriodInfo period = new PeriodInfo(goal.StartDate, goal.DueDate);

            return(CloneGoal(goal, period));
        }
コード例 #16
0
        private void GetAbsense()
        {
            LOG.Clear();

            #region 取得缺曠記錄
            List <SHAttendanceRecord> attendList = new List <SHAttendanceRecord>();

            foreach (string each in _studentList)
            {
                if (!LOG.ContainsKey(each))
                {
                    LOG.Add(each, new LogStudent());
                }
            }

            foreach (SHAttendanceRecord each in SHAttendance.SelectByDate(dateTimeInput1.Value, dateTimeInput2.Value))
            {
                if (_studentList.Contains(each.RefStudentID))
                {
                    attendList.Add(each);
                }
            }

            foreach (SHAttendanceRecord attendanceRecord in attendList)
            {
                // 這裡要做一些事情  例如找到東西塞進去
                string occurDate  = attendanceRecord.OccurDate.ToShortDateString();
                string schoolYear = attendanceRecord.SchoolYear.ToString();
                string semester   = attendanceRecord.Semester.ToString();
                string id         = attendanceRecord.ID;
                List <K12.Data.AttendancePeriod> dNode = attendanceRecord.PeriodDetail;

                //log 紀錄修改前的資料 日期部分
                DateTime logDate;
                if (DateTime.TryParse(occurDate, out logDate))
                {
                    if (!LOG[attendanceRecord.RefStudentID].beforeData.ContainsKey(logDate.ToShortDateString()))
                    {
                        LOG[attendanceRecord.RefStudentID].beforeData.Add(logDate.ToShortDateString(), new Dictionary <string, string>());
                    }
                }

                DataGridViewRow row = null;
                foreach (DataGridViewRow r in dataGridView.Rows)
                {
                    if (r.Cells[0].Tag as string == attendanceRecord.RefStudentID && "" + r.Cells[ColumnIndex["日期"]].Value == attendanceRecord.OccurDate.ToShortDateString())
                    {
                        row = r;
                        break;
                    }
                }

                if (row == null)
                {
                    continue;
                }
                RowTag rowTag = row.Tag as RowTag;
                rowTag.IsNew = false;
                rowTag.Key   = id;

                row.Cells[0].Tag = attendanceRecord; //把資料儲存於Cell[0]

                row.Cells[ColumnIndex["學年度"]].Value = schoolYear;
                row.Cells[ColumnIndex["學年度"]].Tag   = new SemesterCellInfo(schoolYear);

                row.Cells[ColumnIndex["學期"]].Value = semester;
                row.Cells[ColumnIndex["學期"]].Tag   = new SemesterCellInfo(semester);

                for (int i = _startIndex; i < dataGridView.Columns.Count; i++)
                {
                    DataGridViewColumn column = dataGridView.Columns[i];
                    PeriodInfo         info   = column.Tag as PeriodInfo;

                    foreach (K12.Data.AttendancePeriod node in dNode)
                    {
                        if (node.Period != info.Name)
                        {
                            continue;
                        }
                        if (node.AbsenceType == null)
                        {
                            continue;
                        }

                        DataGridViewCell cell = row.Cells[i];
                        foreach (AbsenceInfo ai in _absenceList.Values)
                        {
                            if (ai.Name != node.AbsenceType)
                            {
                                continue;
                            }
                            AbsenceInfo ainfo = ai.Clone();
                            cell.Tag   = new AbsenceCellInfo(ainfo);
                            cell.Value = ai.Abbreviation;

                            ////log 紀錄修改前的資料 缺曠明細部分
                            if (!LOG[node.RefStudentID].beforeData[logDate.ToShortDateString()].ContainsKey(info.Name))
                            {
                                LOG[node.RefStudentID].beforeData[logDate.ToShortDateString()].Add(info.Name, ai.Name);
                            }

                            break;
                        }
                    }
                }
            }
            #endregion
        }
コード例 #17
0
ファイル: GoalsEngine.cs プロジェクト: bilginesme/WebApiAzure
 public void CloneGoalToDB(GoalInfo goal, PeriodInfo newPeriod)
 {
     DB.Goals.AddGoal(CloneGoal(goal, newPeriod));
 }
コード例 #18
0
        public PeriodInfo GetPeriod(string statusPeriod)
        {
            string Y_statusPeriod = "Y_" + statusPeriod;

            if (Y_statusPeriod == "Y_14")
            {
                var newPeriodInfo = new PeriodInfo
                {
                    CoNo         = "006",
                    PeriodNo     = "14",
                    YearNow      = "2017",
                    YearPre      = "2016",
                    strYearNow   = "95-96 سال",
                    strYearPre   = "94-95 سال",
                    strTargetNow = "95-96 هدف",
                    strTargetPre = "94-95 هدف"
                };
                return(newPeriodInfo);
            }
            else if (Y_statusPeriod == "Y_13")
            {
                var newPeriodInfo = new PeriodInfo
                {
                    CoNo         = "006",
                    PeriodNo     = "13",
                    YearNow      = "2016",
                    YearPre      = "2015",
                    strYearNow   = "94-95 سال",
                    strYearPre   = "93-94 سال",
                    strTargetNow = "94-95 هدف",
                    strTargetPre = "93-94 هدف"
                };
                return(newPeriodInfo);
            }
            else if (Y_statusPeriod == "Y_12")
            {
                var newPeriodInfo = new PeriodInfo
                {
                    CoNo         = "006",
                    PeriodNo     = "12",
                    YearNow      = "2015",
                    YearPre      = "2014",
                    strYearNow   = "93-94 سال",
                    strYearPre   = "92-93 سال",
                    strTargetNow = "93-94 هدف",
                    strTargetPre = "92-93 هدف"
                };
                return(newPeriodInfo);
            }
            else if (Y_statusPeriod == "Y_11")
            {
                var newPeriodInfo = new PeriodInfo
                {
                    CoNo         = "006",
                    PeriodNo     = "11",
                    YearNow      = "2014",
                    YearPre      = "2013",
                    strYearNow   = "92-93 سال",
                    strYearPre   = "91-92 سال",
                    strTargetNow = "92-93 هدف",
                    strTargetPre = "91-92 هدف"
                };
                return(newPeriodInfo);
            }
            else
            {
                var newPeriodInfo = new PeriodInfo
                {
                    CoNo         = "006",
                    PeriodNo     = "14",
                    YearNow      = "2017",
                    YearPre      = "2016",
                    strYearNow   = "95-96 سال",
                    strYearPre   = "94-95 سال",
                    strTargetNow = "95-96 هدف",
                    strTargetPre = "94-95 هدف"
                };
                return(newPeriodInfo);
            }
        }
コード例 #19
0
        public ActionResult Setting(PeriodUserInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // 判断日期是否合法
                    DateTime currentDate = DateTime.Now.Date;
                    if (model.Last_MC_Begin > currentDate || model.Last_MC_Begin < currentDate.AddDays(-60))
                    {
                        // 判断为不合法
                        #region
                        if (model.Last_MC_Begin > currentDate)
                        {
                            ModelState.AddModelError("Last_MC_Begin", "上次经期大于当前日期");
                        }
                        else
                        {
                            ModelState.AddModelError("Last_MC_Begin", "上次经期小于当前日期前60天");
                        }
                        var current_user = UserManager.FindByName(User.Identity.Name);
                        ViewBag.User = current_user;
                        // 填充年龄下拉框
                        List <Object> age = new List <Object>();
                        for (int i = 14; i <= 70; i++)
                        {
                            age.Add(new { name = i, value = i });
                        }
                        ViewBag.Age = new SelectList(age, "name", "value", 23);
                        // 填充经期下拉框
                        List <Object> periodday = new List <Object>();
                        for (int i = 3; i <= 13; i++)
                        {
                            periodday.Add(new { name = i, value = i });
                        }
                        ViewBag.PeriodDay = new SelectList(periodday, "name", "value", 7);
                        // 填充周期下拉框
                        List <Object> cycle = new List <Object>();
                        for (int i = 14; i <= 60; i++)
                        {
                            cycle.Add(new { name = i, value = i });
                        }
                        ViewBag.Cycle = new SelectList(age, "name", "value", 28);
                        //ModelState.AddModelError("", "设置错误");
                        return(View(model));

                        #endregion
                    }
                    // 判断是否初次记录
                    var setting_item = periodDB.PeriodUserInfo.SingleOrDefault(m => m.UserName == User.Identity.Name);
                    if (setting_item == null)
                    {
                        // 无设置记录,新建记录
                        PeriodUserInfo info = new PeriodUserInfo()
                        {
                            MC_days       = model.MC_days,
                            Last_MC_Begin = model.Last_MC_Begin,
                            MC_Cycle      = model.MC_Cycle,
                            Pregnancy     = model.Pregnancy,
                            Pre_Pregnancy = model.Pre_Pregnancy,
                            UserAge       = model.UserAge,
                            UserName      = model.UserName
                        };
                        periodDB.PeriodUserInfo.Add(info);
                        periodDB.SaveChanges();
                        PeriodInfo pi = new PeriodInfo()
                        {
                            MC_Begin = model.Last_MC_Begin,
                            MC_Days  = model.MC_days,
                            MC_Cycle = model.MC_Cycle
                        };
                        addPeriodData(pi, User.Identity.Name);
                        return(RedirectToAction("UserHome"));
                    }
                    if (model.Last_MC_Begin < setting_item.Last_MC_Begin.AddDays(-14))
                    {
                        // 小于上次记录的14天
                        #region
                        ModelState.AddModelError("Last_MC_Begin", "上次经期小于最近经期前14天");
                        var current_user = UserManager.FindByName(User.Identity.Name);
                        ViewBag.User = current_user;
                        // 填充年龄下拉框
                        List <Object> age = new List <Object>();
                        for (int i = 14; i <= 70; i++)
                        {
                            age.Add(new { name = i, value = i });
                        }
                        ViewBag.Age = new SelectList(age, "name", "value", 23);
                        // 填充经期下拉框
                        List <Object> periodday = new List <Object>();
                        for (int i = 3; i <= 13; i++)
                        {
                            periodday.Add(new { name = i, value = i });
                        }
                        ViewBag.PeriodDay = new SelectList(periodday, "name", "value", 7);
                        // 填充周期下拉框
                        List <Object> cycle = new List <Object>();
                        for (int i = 14; i <= 60; i++)
                        {
                            cycle.Add(new { name = i, value = i });
                        }
                        ViewBag.Cycle = new SelectList(age, "name", "value", 28);
                        //ModelState.AddModelError("", "设置错误");
                        return(View(model));

                        #endregion
                    }
                    else if (model.Last_MC_Begin >= setting_item.Last_MC_Begin.AddDays(15))
                    {
                        // 大于上次记录的15天,新增记录
                        PeriodInfo pi = new PeriodInfo()
                        {
                            MC_Begin = model.Last_MC_Begin,
                            MC_Days  = model.MC_days,
                            MC_Cycle = model.MC_Cycle
                        };
                        addPeriodData(pi, User.Identity.Name);
                    }
                    else
                    {
                        // 中间日期
                        // 判断是否小于再上次记录的前14天
                        var lpd = getLastPeriodData(setting_item.Last_MC_Begin, User.Identity.Name);
                        if (lpd != null)
                        {
                            if (model.Last_MC_Begin < lpd.MC_Begin.AddDays(14))
                            {
                                ModelState.AddModelError("Last_MC_Begin", "上次经期小于最近经期前14天");
                                var current_user = UserManager.FindByName(User.Identity.Name);
                                ViewBag.User = current_user;
                                // 填充年龄下拉框
                                List <Object> age = new List <Object>();
                                for (int i = 14; i <= 70; i++)
                                {
                                    age.Add(new { name = i, value = i });
                                }
                                ViewBag.Age = new SelectList(age, "name", "value", 23);
                                // 填充经期下拉框
                                List <Object> periodday = new List <Object>();
                                for (int i = 3; i <= 13; i++)
                                {
                                    periodday.Add(new { name = i, value = i });
                                }
                                ViewBag.PeriodDay = new SelectList(periodday, "name", "value", 7);
                                // 填充周期下拉框
                                List <Object> cycle = new List <Object>();
                                for (int i = 14; i <= 60; i++)
                                {
                                    cycle.Add(new { name = i, value = i });
                                }
                                ViewBag.Cycle = new SelectList(age, "name", "value", 28);
                                //ModelState.AddModelError("", "设置错误");
                                return(View(model));
                            }
                        }
                        PeriodInfo pi = new PeriodInfo()
                        {
                            MC_Begin = model.Last_MC_Begin,
                            MC_Days  = model.MC_days,
                            MC_Cycle = model.MC_Cycle
                        };
                        updatePeriodData(pi, User.Identity.Name);
                    }
                    return(RedirectToAction("UserHome"));

                    #region

                    /*
                     * var setting_item = periodDB.PeriodUserInfo.SingleOrDefault(m => m.UserName == User.Identity.Name);
                     * if (setting_item != null)
                     * {
                     *  setting_item.MC_days = model.MC_days;
                     *  setting_item.Last_MC_Begin = model.Last_MC_Begin;
                     *  setting_item.MC_Cycle = model.MC_Cycle;
                     *  setting_item.Pregnancy = model.Pregnancy;
                     *  setting_item.Pre_Pregnancy = model.Pre_Pregnancy;
                     *  setting_item.UserAge = model.UserAge;
                     *
                     *  var last_item = (from m in periodDB.PeriodData
                     *                   where m.UserName == User.Identity.Name
                     *                   orderby m.MC_Begin descending
                     *                   select m).FirstOrDefault();
                     *  // 更新历史数据
                     *  if (last_item != null)
                     *  {
                     *      var modify_last = periodDB.PeriodData.SingleOrDefault(m => m.MC_Finish == last_item.MC_Begin);
                     *
                     *      // 调整上一次的月经数据
                     *      if (modify_last != null)
                     *      {
                     *          if (model.Last_MC_Begin < modify_last.MC_Begin.AddDays(14))
                     *          {
                     *              ModelState.AddModelError("Last_MC_Begin", "上次经期日期错误");
                     *              var current_user = UserManager.FindByName(User.Identity.Name);
                     *              ViewBag.User = current_user;
                     *              // 填充年龄下拉框
                     *              List<Object> age = new List<Object>();
                     *              for (int i = 14; i <= 70; i++)
                     *              {
                     *                  age.Add(new { name = i, value = i });
                     *              }
                     *              ViewBag.Age = new SelectList(age, "name", "value", 23);
                     *              // 填充经期下拉框
                     *              List<Object> periodday = new List<Object>();
                     *              for (int i = 3; i <= 12; i++)
                     *              {
                     *                  periodday.Add(new { name = i, value = i });
                     *              }
                     *              ViewBag.PeriodDay = new SelectList(periodday, "name", "value", 7);
                     *              // 填充周期下拉框
                     *              List<Object> cycle = new List<Object>();
                     *              for (int i = 14; i <= 60; i++)
                     *              {
                     *                  cycle.Add(new { name = i, value = i });
                     *              }
                     *              ViewBag.Cycle = new SelectList(age, "name", "value", 28);
                     *              //ModelState.AddModelError("", "设置错误");
                     *              return View(model);
                     *          }
                     *          else
                     *          {
                     *              last_item.MC_Begin = model.Last_MC_Begin;
                     *              last_item.MC_Cycle = model.MC_Cycle;
                     *              last_item.MC_Days = model.MC_days;
                     *              last_item.MC_Finish = model.Last_MC_Begin.AddDays(model.MC_Cycle);
                     *              modify_last.MC_Finish = model.Last_MC_Begin;
                     *              modify_last.MC_Cycle = Convert.ToInt32(model.Last_MC_Begin.Subtract(modify_last.MC_Begin).TotalDays);
                     *          }
                     *      }
                     *  }
                     *  else
                     *  {
                     *      PeriodData data = new PeriodData()
                     *      {
                     *          MC_Begin = model.Last_MC_Begin,
                     *          MC_Cycle = model.MC_Cycle,
                     *          MC_Days = model.MC_days,
                     *          UserName = User.Identity.Name,
                     *          MC_Finish = model.Last_MC_Begin.AddDays(model.MC_Cycle),
                     *          Period_Type = 0 // 默认为普通类型
                     *      };
                     *      periodDB.PeriodData.Add(data);
                     *  }
                     *
                     *  periodDB.SaveChanges();
                     *
                     *  return RedirectToAction("UserHome");
                     * }
                     * else
                     * {
                     *  PeriodUserInfo info = new PeriodUserInfo()
                     *  {
                     *      MC_days = model.MC_days,
                     *      Last_MC_Begin = model.Last_MC_Begin,
                     *      MC_Cycle = model.MC_Cycle,
                     *      Pregnancy = model.Pregnancy,
                     *      Pre_Pregnancy = model.Pre_Pregnancy,
                     *      UserAge = model.UserAge,
                     *      UserName = model.UserName
                     *  };
                     *  periodDB.PeriodUserInfo.Add(info);
                     *  // 首次数据必定添加
                     *  PeriodData data = new PeriodData()
                     *  {
                     *      MC_Begin = model.Last_MC_Begin,
                     *      MC_Cycle = model.MC_Cycle,
                     *      MC_Days = model.MC_days,
                     *      UserName = User.Identity.Name,
                     *      MC_Finish = model.Last_MC_Begin.AddDays(model.MC_Cycle),
                     *      Period_Type = 0 // 默认为普通类型
                     *
                     *  };
                     *  periodDB.PeriodData.Add(data);
                     *  periodDB.SaveChanges();
                     *  return RedirectToAction("UserHome");
                     * }
                     */
                    #endregion
                }
                catch
                {
                    return(View("Error"));
                }
            }
            else
            {
                var current_user = UserManager.FindByName(User.Identity.Name);
                ViewBag.User = current_user;
                // 填充年龄下拉框
                List <Object> age = new List <Object>();
                for (int i = 14; i <= 70; i++)
                {
                    age.Add(new { name = i, value = i });
                }
                ViewBag.Age = new SelectList(age, "name", "value", 23);
                // 填充经期下拉框
                List <Object> periodday = new List <Object>();
                for (int i = 3; i <= 12; i++)
                {
                    periodday.Add(new { name = i, value = i });
                }
                ViewBag.PeriodDay = new SelectList(periodday, "name", "value", 7);
                // 填充周期下拉框
                List <Object> cycle = new List <Object>();
                for (int i = 14; i <= 60; i++)
                {
                    cycle.Add(new { name = i, value = i });
                }
                ViewBag.Cycle = new SelectList(age, "name", "value", 28);
                ModelState.AddModelError("", "设置错误");
                return(View(model));
            }
            //return RedirectToAction("UserHome");
        }
コード例 #20
0
        //儲存
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region Save
            if (!IsValid())
            {
                FISCA.Presentation.Controls.MsgBox.Show("資料驗證失敗,請修正後再行儲存", "驗證失敗", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }
            List <SHAttendanceRecord> InsertHelper = new List <SHAttendanceRecord>(); //新增
            List <SHAttendanceRecord> updateHelper = new List <SHAttendanceRecord>(); //更新
            List <string>             deleteList   = new List <string>();             //清空

            //List<string> synclist = new List<string>();

            ISemester semester = SemesterProvider.GetInstance();
            foreach (DataGridViewRow row in dataGridView.Rows)
            {
                RowTag tag = row.Tag as RowTag;
                semester.SetDate(tag.Date);

                ////log 紀錄修改後的資料 日期部分
                if (row.Cells[0].Tag is string)
                {
                    if (!LOG[row.Cells[0].Tag.ToString()].afterData.ContainsKey(tag.Date.ToShortDateString()))
                    {
                        LOG[row.Cells[0].Tag.ToString()].afterData.Add(tag.Date.ToShortDateString(), new Dictionary <string, string>());
                    }
                }
                else
                {
                    SHAttendanceRecord attRecord = row.Cells[0].Tag as SHAttendanceRecord;

                    if (!LOG[attRecord.RefStudentID].afterData.ContainsKey(tag.Date.ToShortDateString()))
                    {
                        LOG[attRecord.RefStudentID].afterData.Add(tag.Date.ToShortDateString(), new Dictionary <string, string>());
                    }
                }

                if (tag.IsNew)
                {
                    #region IsNew
                    string studentID = row.Cells[0].Tag as string;

                    SHAttendanceRecord attRecord = new SHAttendanceRecord();

                    bool hasContent = false;
                    for (int i = _startIndex; i < dataGridView.Columns.Count; i++)
                    {
                        DataGridViewCell cell = row.Cells[i];
                        if (string.IsNullOrEmpty(("" + cell.Value).Trim()))
                        {
                            continue;
                        }

                        PeriodInfo      pinfo  = dataGridView.Columns[i].Tag as PeriodInfo;
                        AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo;
                        AbsenceInfo     ainfo  = acInfo.AbsenceInfo;

                        K12.Data.AttendancePeriod ap = new K12.Data.AttendancePeriod();
                        ap.Period      = pinfo.Name;
                        ap.AbsenceType = ainfo.Name;
                        attRecord.PeriodDetail.Add(ap);

                        hasContent = true;

                        //log 紀錄修改後的資料 缺曠明細部分
                        if (!LOG[studentID].afterData[tag.Date.ToShortDateString()].ContainsKey(pinfo.Name))
                        {
                            LOG[studentID].afterData[tag.Date.ToShortDateString()].Add(pinfo.Name, ainfo.Name);
                        }
                    }

                    if (hasContent)
                    {
                        attRecord.RefStudentID = studentID;
                        attRecord.SchoolYear   = int.Parse("" + row.Cells[ColumnIndex["學年度"]].Value);
                        attRecord.Semester     = int.Parse("" + row.Cells[ColumnIndex["學期"]].Value);
                        attRecord.OccurDate    = DateTime.Parse(tag.Date.ToShortDateString());
                        InsertHelper.Add(attRecord);
                    }

                    #endregion
                }
                else // 若是原本就有紀錄的
                {
                    #region 是舊的

                    SHAttendanceRecord attRecord = row.Cells[0].Tag as SHAttendanceRecord;
                    attRecord.PeriodDetail.Clear(); //清空

                    bool hasContent = false;
                    for (int i = _startIndex; i < dataGridView.Columns.Count; i++)
                    {
                        DataGridViewCell cell = row.Cells[i];
                        if (string.IsNullOrEmpty(("" + cell.Value).Trim()))
                        {
                            continue;
                        }

                        PeriodInfo      pinfo  = dataGridView.Columns[i].Tag as PeriodInfo;
                        AbsenceCellInfo acInfo = cell.Tag as AbsenceCellInfo;
                        AbsenceInfo     ainfo  = acInfo.AbsenceInfo;

                        K12.Data.AttendancePeriod ap = new K12.Data.AttendancePeriod();
                        ap.Period      = pinfo.Name;
                        ap.AbsenceType = ainfo.Name;
                        attRecord.PeriodDetail.Add(ap);

                        hasContent = true;

                        //log 紀錄修改後的資料 缺曠明細部分
                        if (!LOG[attRecord.RefStudentID].afterData[tag.Date.ToShortDateString()].ContainsKey(pinfo.Name))
                        {
                            LOG[attRecord.RefStudentID].afterData[tag.Date.ToShortDateString()].Add(pinfo.Name, ainfo.Name);
                        }
                    }

                    if (hasContent)
                    {
                        attRecord.SchoolYear = int.Parse("" + row.Cells[ColumnIndex["學年度"]].Value);
                        attRecord.Semester   = int.Parse("" + row.Cells[ColumnIndex["學期"]].Value);
                        updateHelper.Add(attRecord);
                    }
                    else
                    {
                        deleteList.Add(tag.Key);

                        //log 紀錄被刪除的資料
                        LOG[attRecord.RefStudentID].afterData.Remove(tag.Date.ToShortDateString());
                        LOG[attRecord.RefStudentID].deleteData.Add(tag.Date.ToShortDateString());
                    }
                    #endregion
                }
            }

            #region InsertHelper
            if (InsertHelper.Count > 0)
            {
                try
                {
                    SHAttendance.Insert(InsertHelper);
                }
                catch (Exception ex)
                {
                    FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄新增失敗 : " + ex.Message, "新增失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }


                //log 寫入log
                foreach (string each in LOG.Keys)
                {
                    foreach (string date in LOG[each].afterData.Keys)
                    {
                        if (!LOG[each].beforeData.ContainsKey(date) && LOG[each].afterData[date].Count > 0)
                        {
                            StringBuilder desc = new StringBuilder("");
                            desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」");
                            desc.AppendLine("日期「" + date + "」");
                            foreach (string period in LOG[each].afterData[date].Keys)
                            {
                                desc.AppendLine("節次「" + period + "」設為「" + LOG[each].afterData[date][period] + "」");
                            }
                            ApplicationLog.Log("學務系統.缺曠資料", "批次新增缺曠資料", "student", each, desc.ToString());
                            //Log部份
                            //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Insert, _student.ID, desc.ToString(), this.Text, "");
                        }
                    }
                }
            }
            #endregion

            #region updateHelper
            if (updateHelper.Count > 0)
            {
                try
                {
                    SHAttendance.Update(updateHelper);
                }
                catch (Exception ex)
                {
                    FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄更新失敗 : " + ex.Message, "更新失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //log 寫入log
                foreach (string each in LOG.Keys)
                {
                    foreach (string date in LOG[each].afterData.Keys)
                    {
                        if (LOG[each].beforeData.ContainsKey(date) && LOG[each].afterData[date].Count > 0)
                        {
                            bool          dirty = false;
                            StringBuilder desc  = new StringBuilder("");
                            desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」 ");
                            desc.AppendLine("日期「" + date + "」 ");
                            foreach (string period in LOG[each].beforeData[date].Keys)
                            {
                                if (!LOG[each].afterData[date].ContainsKey(period))
                                {
                                    LOG[each].afterData[date].Add(period, "");
                                }
                            }
                            foreach (string period in LOG[each].afterData[date].Keys)
                            {
                                if (LOG[each].beforeData[date].ContainsKey(period))
                                {
                                    if (LOG[each].beforeData[date][period] != LOG[each].afterData[date][period])
                                    {
                                        dirty = true;
                                        desc.AppendLine("節次「" + period + "」由「" + LOG[each].beforeData[date][period] + "」變更為「" + LOG[each].afterData[date][period] + "」");
                                    }
                                }
                                else
                                {
                                    dirty = true;
                                    desc.AppendLine("節次「" + period + "」由「」變更為「" + LOG[each].afterData[date][period] + "」 ");
                                }
                            }
                            if (dirty)
                            {
                                //Log部份
                                ApplicationLog.Log("學務系統.缺曠資料", "批次修改缺曠資料", "student", each, desc.ToString());
                                //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Update, _student.ID, desc.ToString(), this.Text, "");
                            }
                        }
                    }
                }
            }
            #endregion

            #region deleteList
            if (deleteList.Count > 0)
            {
                try
                {
                    SHAttendance.Delete(deleteList);
                }
                catch (Exception ex)
                {
                    FISCA.Presentation.Controls.MsgBox.Show("缺曠紀錄刪除失敗 : " + ex.Message, "刪除失敗", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                //log 寫入被刪除的資料的log
                foreach (string each in LOG.Keys)
                {
                    StringBuilder desc = new StringBuilder("");
                    desc.AppendLine("學生「" + K12.Data.Student.SelectByID(each).Name + "」");
                    foreach (string date in LOG[each].deleteData)
                    {
                        desc.AppendLine("刪除「" + date + "」缺曠紀錄 ");
                    }

                    //Log部份
                    ApplicationLog.Log("學務系統.缺曠資料", "批次刪除缺曠資料", "student", each, desc.ToString());
                    //CurrentUser.Instance.AppLog.Write(EntityType.Student, EntityAction.Delete, _student.ID, desc.ToString(), this.Text, "");
                }
            }
            #endregion

            //觸發變更事件
            //Attendance.Instance.SyncDataBackground(_studentList);

            FISCA.Presentation.Controls.MsgBox.Show("儲存缺曠資料成功!", "完成", MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
            #endregion
        }
コード例 #21
0
        public async Task <object[]> GetProposals(
            AccountParameter sender,
            Int32Parameter level,
            DateTimeParameter timestamp,
            Int32Parameter epoch,
            Int32Parameter period,
            ProtocolParameter proposal,
            BoolParameter duplicated,
            SortParameter sort,
            OffsetParameter offset,
            int limit,
            string field,
            Symbols quote)
        {
            var columns = new HashSet <string>(4);
            var joins   = new HashSet <string>(3);

            switch (field)
            {
            case "id": columns.Add(@"o.""Id"""); break;

            case "level": columns.Add(@"o.""Level"""); break;

            case "timestamp": columns.Add(@"o.""Timestamp"""); break;

            case "hash": columns.Add(@"o.""OpHash"""); break;

            case "delegate": columns.Add(@"o.""SenderId"""); break;

            case "rolls": columns.Add(@"o.""Rolls"""); break;

            case "duplicated": columns.Add(@"o.""Duplicated"""); break;

            case "proposal":
                columns.Add(@"proposal.""Hash"" as ""ProposalHash""");
                columns.Add(@"proposal.""Metadata"" ->> 'alias' as ""ProposalAlias""");
                joins.Add(@"INNER JOIN ""Proposals"" as proposal ON proposal.""Id"" = o.""ProposalId""");
                break;

            case "period":
                columns.Add(@"o.""Epoch""");
                columns.Add(@"o.""Period""");
                columns.Add(@"period.""Kind""");
                columns.Add(@"period.""FirstLevel""");
                columns.Add(@"period.""LastLevel""");
                joins.Add(@"INNER JOIN ""VotingPeriods"" as period ON period.""Index"" = o.""Period""");
                break;

            case "block":
                columns.Add(@"b.""Hash""");
                joins.Add(@"INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""");
                break;

            case "quote": columns.Add(@"o.""Level"""); break;
            }

            if (period != null)
            {
                joins.Add(@"INNER JOIN ""VotingPeriods"" as period ON period.""Index"" = o.""Period""");
            }

            if (proposal != null)
            {
                joins.Add(@"INNER JOIN ""Proposals"" as proposal ON proposal.""Id"" = o.""ProposalId""");
            }

            if (columns.Count == 0)
            {
                return(Array.Empty <object>());
            }

            var sql = new SqlBuilder($@"SELECT {string.Join(',', columns)} FROM ""ProposalOps"" as o {string.Join(' ', joins)}")
                      .Filter("SenderId", sender)
                      .FilterA(@"o.""Level""", level)
                      .FilterA(@"o.""Timestamp""", timestamp)
                      .FilterA(@"o.""Duplicated""", duplicated)
                      .FilterA(@"o.""Epoch""", epoch)
                      .FilterA(@"o.""Period""", period)
                      .FilterA(@"proposal.""Hash""", proposal)
                      .Take(sort, offset, limit, x => x == "level" ? ("Id", "Level") : ("Id", "Id"), "o");

            using var db = GetConnection();
            var rows = await db.QueryAsync(sql.Query, sql.Params);

            //TODO: optimize memory allocation
            var result = new object[rows.Count()];
            var j      = 0;

            switch (field)
            {
            case "id":
                foreach (var row in rows)
                {
                    result[j++] = row.Id;
                }
                break;

            case "level":
                foreach (var row in rows)
                {
                    result[j++] = row.Level;
                }
                break;

            case "block":
                foreach (var row in rows)
                {
                    result[j++] = row.Hash;
                }
                break;

            case "timestamp":
                foreach (var row in rows)
                {
                    result[j++] = row.Timestamp;
                }
                break;

            case "hash":
                foreach (var row in rows)
                {
                    result[j++] = row.OpHash;
                }
                break;

            case "rolls":
                foreach (var row in rows)
                {
                    result[j++] = row.Rolls;
                }
                break;

            case "duplicated":
                foreach (var row in rows)
                {
                    result[j++] = row.Duplicated;
                }
                break;

            case "period":
                foreach (var row in rows)
                {
                    result[j++] = new PeriodInfo
                    {
                        Index      = row.Period,
                        Epoch      = row.Epoch,
                        Kind       = PeriodKinds.ToString(row.Kind),
                        FirstLevel = row.FirstLevel,
                        LastLevel  = row.LastLevel
                    }
                }
                ;
                break;

            case "proposal":
                foreach (var row in rows)
                {
                    result[j++] = new ProposalAlias
                    {
                        Hash  = row.ProposalHash,
                        Alias = row.ProposalAlias
                    }
                }
                ;
                break;

            case "delegate":
                foreach (var row in rows)
                {
                    result[j++] = await Accounts.GetAliasAsync(row.SenderId);
                }
                break;

            case "quote":
                foreach (var row in rows)
                {
                    result[j++] = Quotes.Get(quote, row.Level);
                }
                break;
            }

            return(result);
        }
コード例 #22
0
 private static int SortByOrder(PeriodInfo info1, PeriodInfo info2)
 {
     return(info1.Sort.CompareTo(info2.Sort));
 }