public static void ValidateAlreadyAttended(string html, AttendanceTypes type)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(html);

            // 出勤に成功していれば、 id="ctl00_ContentMain_txtStartTime" がある
            // 退勤に成功していれば、 id="ctl00_ContentMain_txtEndTime" がある
            var id   = (type == AttendanceTypes.Arrival) ? "ctl00_ContentMain_txtStartTime" : "ctl00_ContentMain_txtEndTime";
            var node = doc.DocumentNode.SelectSingleNode("//input[@id='" + id + "']");

            if (node == null)
            {
                return; // まだ打刻していない
            }
            // 時刻が入力されているかをチェック
            var valueAttribute = node.GetAttributeValue("value", null);

            if (valueAttribute == null)
            {
                return; // まだ打刻していない
            }

            throw new AttendanceProAlreadyAttendException(type);
        }
Ejemplo n.º 2
0
 public static Attendance GetLastPunchByType(int userID, AttendanceTypes type)
 {
     using (ISession session = NHibernateHelper.OpenSession <Attendance>())
     {
         var obj = session.Query <Attendance>().Where(x => x.UserID == userID && x.CurrentPunchType.Equals(type.ToString())).OrderByDescending(y => y.PunchDateTime).FirstOrDefault();
         if (obj == null)
         {
             obj = new Attendance();
         }
         return(obj);
     }
 }
Ejemplo n.º 3
0
        public static string ToName(this AttendanceTypes type)
        {
            switch (type)
            {
            case AttendanceTypes.Arrival:
                return(Properties.Resources.Arrival);

            case AttendanceTypes.Depart:
                return(Properties.Resources.Depart);

            default:
                throw new ArgumentOutOfRangeException("type", type, null);
            }
        }
Ejemplo n.º 4
0
        // 出退勤実行
        async Task Attend(AttendanceTypes type)
        {
            try
            {
                var workingLog = await Client.AttendanceProClient.Instance.Attend(AccountManager.Instance.Account, type);

                // 出勤退勤の完了メッセージ(短めの時間表示させる)
                int showingTime = 1000;
                notifyIcon.ShowBalloonTip(string.Format(Properties.Resources.AttendanceSucceeded, type.ToName()), ToolTipIcon.Info, timeout: showingTime);

                // 少しのディレイを挿んで通知メッセージの表示
                await Task.Delay(showingTime);

                ShowWorkingLog(workingLog);
            }
            catch (AttendanceProLoginException e)
            {
                var message = e.Message ?? Properties.Resources.LoginFailed;
                notifyIcon.ShowBalloonTip(message, ToolTipIcon.Error);
            }
            catch (AttendanceProPasswordExpiredException)
            {
                notifyIcon.ShowBalloonTip(Properties.Resources.PasswordHasExpired, ToolTipIcon.Error);
            }
            catch (AttendanceProAlreadyAttendException e)
            {
                notifyIcon.ShowBalloonTip(string.Format(Properties.Resources.AttendAlready, e.AttendanceType.ToName()), ToolTipIcon.Warning);
            }
            catch (AttendanceProAttendException e)
            {
                notifyIcon.ShowBalloonTip(string.Format(Properties.Resources.AttendanceFailed, e.AttendanceType.ToName()), ToolTipIcon.Error);
            }
            catch (AttendanceProFetchTableFullTimeException)
            {
                notifyIcon.ShowBalloonTip(Properties.Resources.FailedToFetchWorkingTable, ToolTipIcon.Error);
            }
            catch (Exception e)
            {
                notifyIcon.ShowBalloonTip(Properties.Resources.AnUnknownErrorOccurred + " : " + e.ToString(), ToolTipIcon.Error);
            }
        }
Ejemplo n.º 5
0
 public Student(string firstName, string lastName, AttendanceTypes attendanceType)
 {
     FirstName      = firstName;
     LastName       = lastName;
     AttendanceType = attendanceType;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// トップページを解析し、出退勤リクエストを作成する。
        /// </summary>
        /// <param name="html"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static NameValueCollection QueryForAttendanceTableDailyPage(string html, AttendanceTypes type)
        {
            var ps = new NameValueCollection();

            var doc = new HtmlDocument();

            doc.LoadHtml(html);

            ps.Add("__EVENTTARGET", "");
            ps.Add("__EVENTARGUMENT", "");
            ps.Add("__LASTFOCUS", "");

            foreach (var node in doc.DocumentNode.SelectNodes("//select"))
            {
                var value = node.SelectNodes("//option[@selected]")[0].GetAttributeValue("value", null);
                ps.Add(node.GetAttributeValue("name", ""), value);
            }
            foreach (var node in doc.DocumentNode.SelectNodes("//input"))
            {
                var    typeAttribute  = node.GetAttributeValue("type", null);
                var    nameAttribute  = node.GetAttributeValue("name", null);
                string valueAttribute = null;

                if (typeAttribute == "radio")
                {
                    if (node.GetAttributeValue("checked", null) == "checked")
                    {
                        valueAttribute = node.GetAttributeValue("value", "");
                    }
                }
                else
                {
                    if (nameAttribute == "clDT")
                    {
                        valueAttribute = System.DateTime.Now.ToString("yyyy/M/dd HH:mm");
                    }
                    else if (typeAttribute != "submit" && node.GetAttributeValue("disabled", null) != "disabled")
                    {
                        valueAttribute = node.GetAttributeValue("value", "");
                    }
                }
                if (nameAttribute != null && valueAttribute != null)
                {
                    ps.Add(nameAttribute, valueAttribute);
                }
            }

            switch (type)
            {
            case AttendanceTypes.Arrival:
                // 出社
                ps.Add("ctl00$ContentMain$btnWebStartTime", "出社");
                break;

            case AttendanceTypes.Depart:
                // 退社
                ps.Add("ctl00$ContentMain$btnWebEndTime", "退社");
                break;
            }

            return(ps);
        }
 public AttendanceProAlreadyAttendException(AttendanceTypes type)
 {
     AttendanceType = type;
 }
Ejemplo n.º 8
0
 public Student(string firstName, string lastName, AttendanceTypes attendanceType)
 {
     this.FirstName      = firstName;
     this.LastName       = lastName;
     this.AttendanceType = attendanceType;
 }
        async Task <WorkingLogOwn> Attend(string userId, string password, string companyCode, AttendanceTypes type)
        {
            // ログイン後のページ
            var html = await LogOn(userId, password, companyCode);

            await Task.Run(() =>
            {
                // 既に出退勤済かどうか
                ResponseValidator.ValidateAlreadyAttended(html, type);

                // 出退勤実行
                var query = QueryCreator.QueryForAttendanceTableDailyPage(html, type);
                html      = wc.Post(AttendanceProURLs.AttendanceTableDaily, query);

                // 出退勤が正常に完了しているかのチェック
                ResponseValidator.ValidateAttended(html, type);
            });

            // 月次勤務表の情報を取得
            return(await FetchOwnWorkingLog(userId, password, companyCode, withLogOn : false));
        }
 /// <summary>
 /// 出社 or 退社の実行
 /// </summary>
 /// <param name="account"></param>
 /// <param name="type"></param>
 public async Task <WorkingLogOwn> Attend(Account.Account account, AttendanceTypes type)
 {
     return(await Attend(account.UserId, account.Password, account.CompanyCode, type));
 }