Esempio n. 1
0
        private void Login()
        {
            if (Regsetting.DMS_Setting.UserID.Length == 0 || Regsetting.DMS_Setting.Password.Length == 0)
            {
                result.Add("No UserID/Pasword, Can't Login.");
                log.WriteLine("No UserID/Pasword, Can't Login.");
                loggedin = false;
                return;
            }

            try
            {
                resultsPage = browser.NavigateToPage(new Uri(URLBase + "/DMS/index.jsp"));

                form = resultsPage.FindForm("loginActionForm");
                form["personcode"] = Regsetting.DMS_Setting.UserID;
                form["password"]   = Regsetting.DMS_Setting.getPassword();
                form.Method        = HttpVerb.Post;
                resultsPage        = form.Submit();
                log.WriteLine("Login form submitted.");
#if (DEBUG)
                string cookie = resultsPage.RawRequest.Headers.FirstOrDefault(c => (c.Key == "Set-Cookie") || (c.Key == "Cookie")).Value;
                //cookie = cookie.Substring(cookie.IndexOf("="), cookie.Length);
                result.Add("[D]DMS Login with Session: " + cookie);
#endif
                var valid = resultsPage.Html.CssSelect("h3");
                if (valid.Count() > 0)
                {
                    result.Add(resultsPage.Html.CssSelect("h3").First()?.InnerText?.Trim());
                    result.Add(resultsPage.Html.CssSelect("ul").First().InnerText.Trim());
                    loggedin = false;
                }
                else
                {
                    loggedin = true;
                }
            }
            catch (Exception ex)
            {
                result.Add("Connection fail : " + ex.Message + " -> " + ex.InnerException.Message);
                log.WriteLine("Login fail : " + ex.Message + " -> " + ex.InnerException.Message);
                loggedin = false;
            }
        }
Esempio n. 2
0
        public bool UpdateDailyReport()
        {
            if (!loggedin)
            {
                result.Add("Not Loggedin, can't perform futher action.");
                log.WriteLine("Not Loggedin, can't perform futher action.[UpdateDailyReport)");
                return(false);
            }
            result.Add("DMS start updating daily report.");
            // Get project list
            List <Dictionary <string, string> > projects = getProjectList();

            // Select Project
            Dictionary <string, string> project = projects.Find(p => p["projectcode"] + p["fabid"] + p["workitemcode"] == Regsetting.DMS_Setting.project);

            if (project == null)
            {
                result.Add((Regsetting.DMS_Setting.project == "auto") ?
                           "Select first On-Schedule prject automatically." :
                           "Can't find pre-defined project, select first On-Schedule project automatically.");
                project = projects.Find(p => p["datestatus"] == "On-Schedule");
                if (project == null)
                {
                    result.Add("Can't find any On-Schedule project, select first available project.");
                    project = projects.First();
                    if (project == null)
                    {
                        result.Add("Can't find any available project.");
                        return(false);
                    }
                }
            }


            try
            {
                resultsPage          = browser.NavigateToPage(new Uri(URLBase + "/DMS/dailyreport/dailyRecordMaintain.jsp"));
                form                 = resultsPage.FindForm("form_send");
                form["projectcode"]  = project["projectcode"];
                form["fabid"]        = project["fabid"];
                form["workitemcode"] = project["workitemcode"];
                form["workitemname"] = project["workitemname"];
                form["status"]       = project["status"];
                form["isstudy"]      = "N";
                form.Method          = HttpVerb.Post;
                resultsPage          = form.Submit();

                // Submit content
                string date = DateTime.Now.ToString("yyyy-MM-dd");
                //string date = new DateTime(2018, 12, 11, 0, 0, 0).ToString("yyyy-MM-dd");
                form = resultsPage.FindForm("dailyreportActionForm");
                string content = getContent();
                form["content"] = (content.Length > 0) ? content : "Working on " + project["projectname"] + " " + project["workitemname"];
                form["ftime"]   = date + Regsetting.DMS_Setting.From.ToString(" HH:mm:00"); //2018-12-06 08:00:00
                form["ttime"]   = date + Regsetting.DMS_Setting.To.ToString(" HH:mm:00");
                form["hours"]   = Regsetting.DMS_Setting.To.TimeOfDay.Subtract(Regsetting.DMS_Setting.From.TimeOfDay).TotalHours.ToString();
                form.Method     = HttpVerb.Post;
                resultsPage     = form.Submit();

                result.Add(string.Format("Form {0} to {1} ({2} hours)", form["ftime"], form["ttime"], form["hours"]));
                result.Add(string.Format("Project : {0} / {1}", project["projectname"], project["workitemname"]));

                if (resultsPage.Html.CssSelect("title").ToArray().FirstOrDefault().InnerText.Equals("displayDailyWorkitemsInformation"))
                {
                    result.Add(string.Format("Content : {0}", form["content"]));
                    return(true);
                }
                else
                {
                    result.Add(resultsPage.Html.CssSelect("h3").First().InnerText.Trim());
                    result.Add(resultsPage.Html.CssSelect("ul").First().InnerText.Trim());
                    return(false);
                }
            }
            catch (Exception ex)
            {
                result.Add("Connection error : " + ex.Message + " -> " + ex.InnerException.Message);
                log.WriteLine("Connection error : (UpdateDailyReport)" + ex.Message + " -> " + ex.InnerException.Message);
                return(false);
            }
        }