UpdateText() private method

private UpdateText ( ) : void
return void
Exemplo n.º 1
0
        public static void ShowBusStop(object obj)
        {
            object[] args = (object[])obj;
            MainForm form = (MainForm)args[0];

            form.UpdateText("Loading database");
            List <BusStop> bss = (from b in db.BusStop select b).ToList();

            form.UpdateText("Print search result");
            string msg = "BusStop List";

            form.UpdateLog(msg);
            foreach (BusStop bs in bss)
            {
                form.UpdateLogMessage(bs.BSID + ",\t" + bs.Name + ",\t" + bs.District + ",\t" + bs.Address + ",\t" + bs.Direction + ",\t" + bs.BSCID);
            }
            form.UpdateText("Finished");
        }
Exemplo n.º 2
0
        public void Die(Player player, CombatForm combatForm, MainForm mainForm)
        {
            DialogResult victory = MessageBox.Show(combatForm,
                                                   $"{this.name} defeated!\n" +
                                                   $"Experience earned: {this.expReward(this.level)}\n" +
                                                   $"Gold found: {this.gold}g\n" +
                                                   $"Items found: wip",
                                                   "Victory!",
                                                   MessageBoxButtons.OK);

            player.IncreaseExp(this.expReward(this.level));
            player.gold += this.gold;

            mainForm.UpdateText();

            if (victory == DialogResult.OK)
            {
                combatForm.Close();
            }
        }
Exemplo n.º 3
0
        public static void Execute(object obj)
        {
            int[]    dates = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
            object[] objs  = (object[])obj;

            Application excel   = new Application();
            string      strPath = @"C:\Users\Allen Chou\Documents\013-U5發車準點稽核.xlsx";
            Workbook    Wbook   = excel.Workbooks.Open(strPath);

            System.IO.FileInfo xlsAttribute = new FileInfo(strPath);
            xlsAttribute.Attributes = FileAttributes.Normal;

            MainForm mform = (MainForm)objs[0];

            // oms {cmd [args]}
            //oms 2017 02 02 04 01 1000 013-U5
            string[] cmd        = (string[])objs[1];
            string   year       = cmd[0];
            int      smonth     = Convert.ToInt32(cmd[1]);
            int      sdate      = Convert.ToInt32(cmd[2]);
            int      emonth     = Convert.ToInt32(cmd[3]);
            int      edate      = Convert.ToInt32(cmd[4]);
            string   limit      = cmd[5];
            string   carNum     = cmd[6];
            int      month      = smonth;
            int      date       = sdate;
            int      sheetcount = 1;

            mform.UpdateText("Start Login");
            if (!IsLogin())
            {
                Login();
            }
            mform.UpdateLog("Start Login");

            mform.UpdateText("Query car number[ " + carNum + " ]'s data from " + smonth + "/" + sdate + " to " + emonth + "/" + edate);
            mform.UpdateLog("Query car number[ " + carNum + " ]'s data from " + smonth + "/" + sdate + " to " + emonth + "/" + edate);
            while (month != emonth || date != edate)
            {
                mform.UpdateLog("Start query [ " + month + "/" + date + " ]");
                string cmonth = (Convert.ToString(month).Length < 2) ? "0" + Convert.ToString(month) : Convert.ToString(month);
                string cdate  = (Convert.ToString(date).Length < 2) ? "0" + Convert.ToString(date) : Convert.ToString(date);

                string         query = "http://oms.5284.com.tw/OMS/action/auditRecordTP/findA1_1_1?companyId=200&companyName=%E9%A6%96%E9%83%BD%E5%AE%A2%E9%81%8B&stationId=16225&stationName=%E6%B0%91%E7%94%9F%E7%AB%99&pathId=16111&pathName=307&recordDate=" + year + "%2F" + cmonth + "%2F" + cdate + "&page=1&start=0&limit=" + limit + "&sort=%5B%7B%22property%22%3A%22sysMemo1%22%2C%22direction%22%3A%22ASC%22%7D%5D";
                HttpWebRequest req   = WebRequest.CreateHttp(query);
                req.CookieContainer = new CookieContainer();
                req.CookieContainer.Add(cookies);
                req.Referer   = oms_index + "jsp/index.jsp";
                req.Accept    = "*/*";
                req.KeepAlive = true;
                HttpWebResponse response = (HttpWebResponse)req.GetResponse();
                StreamReader    input    = new StreamReader(response.GetResponseStream());
                string          json     = "";
                while (!input.EndOfStream)
                {
                    json += input.ReadLine();
                }
                OMSObject model = JsonConvert.DeserializeObject <OMSObject>(json);

                Wbook.Worksheets.Add(Type.Missing, Wbook.Worksheets[sheetcount], 1, Type.Missing);
                Worksheet Wsheet = excel.Worksheets[sheetcount + 1];
                Wsheet.Name = carNum + "發車準點稽核" + cmonth + cdate;

                int rowcount = 1;

                List <string> list = new List <string>();
                foreach (Datum d in model.data)
                {
                    if (d.carNum2 != null && d.carNum2.Equals(carNum))
                    {
                        bool empexist = false;
                        foreach (string name in list)
                        {
                            if (name != null && name.Equals(d.empName))
                            {
                                empexist = true;
                                break;
                            }
                        }
                        if (!empexist && d.empName != null)
                        {
                            list.Add(d.empName);
                        }
                        Wsheet.get_Range("A" + rowcount + 1, "D" + rowcount + 1).NumberFormatLocal = "@";
                        Wsheet.Cells[rowcount + 1, 1] = (d.sysDepartureTime.Length < 6) ? "0" + d.sysDepartureTime.Substring(0, 3) : d.sysDepartureTime.Substring(0, 4);
                        Wsheet.Cells[rowcount + 1, 2] = (d.sysArrivalTime.Length < 6) ? "0" + d.sysArrivalTime.Substring(0, 3) : d.sysArrivalTime.Substring(0, 4);
                        Wsheet.Cells[rowcount + 1, 3] = d.stopSeq;
                        Wsheet.Cells[rowcount + 1, 4] = d.stopInfo;
                        rowcount++;
                    }
                }
                if (rowcount == 1)
                {
                    Wsheet.Cells[1, 1] = "無資料";
                }
                else
                {
                    Wsheet.Cells[1, 1] = "發車時間";
                    Wsheet.Cells[1, 2] = "返站時間";
                    Wsheet.Cells[1, 3] = "觸發站序";
                    Wsheet.Cells[1, 4] = "觸發站位";
                }

                for (int i = 0; i < list.Count; i++)
                {
                    Wsheet.Cells[rowcount + 1, i + 1] = list[i];
                }

                sheetcount++;
                date++;
                if (date > dates[month - 1])
                {
                    month++;
                    date = 1;
                }
            }
            mform.UpdateText("Saveing......");
            Wbook.Save();
            Wbook.Close();
            mform.UpdateText("Finished");
            mform.UpdateLog("Finished");
        }
Exemplo n.º 4
0
        public static void Kiss(string user, string pwd, MainForm mform)
        {
            mform.UpdateText("Start Kissing");
            mform.UpdateLog("Start Kissing");
            mform.UpdateText("Start Login " + user);

            // Get first session id
            mform.UpdateLog("[LOGIN] Get first session id");
            HttpWebRequest   request   = WebRequest.CreateHttp("http://kiss.taipei.gov.tw/");
            HttpWebResponse  response  = (HttpWebResponse)request.GetResponse();
            CookieCollection sessionid = response.Cookies;

            // Get redirect url
            mform.UpdateLog("[LOGIN] Login");
            request             = WebRequest.CreateHttp("http://kiss.taipei.gov.tw/Login/Login_Check.asp");
            request.ContentType = "application/x-www-form-urlencoded";
            request.Method      = "POST";
            CookieContainer sid = new CookieContainer();

            sid.Add(sessionid);
            request.CookieContainer = sid;
            string param = "Login_Name=" + user + "&Login_PassWord="******"";

            while (!input.EndOfStream)
            {
                content += input.ReadLine();
            }
            Regex  regex = new Regex("location.href=\"(?<uri>[^\"]+)\";");
            Match  match = regex.Match(content);
            string uri   = match.Groups["uri"].Value;

            // Get Userid & .net session id
            mform.UpdateLog("[LOGIN] Get user id & .NET session id");
            request = WebRequest.CreateHttp("http://kiss.taipei.gov.tw/Login/" + uri);
            sid     = new CookieContainer();
            sid.Add(response.Cookies);
            request.CookieContainer = sid;
            response = (HttpWebResponse)request.GetResponse();
            input    = new StreamReader(response.GetResponseStream());
            while (!input.EndOfStream)
            {
                input.ReadLine();
            }
            mform.UpdateText("Login " + user + " successful!");
            mform.UpdateLog("Login " + user + " successful!");

            // Get index content
            mform.UpdateText("Start auto kissing");
            request = WebRequest.CreateHttp("http://kiss.taipei.gov.tw/Calendar/index.aspx");
            CookieContainer cl = new CookieContainer();

            cl.Add(response.Cookies);
            request.CookieContainer = cl;
            content = "";
            using (response = (HttpWebResponse)request.GetResponse())
            {
                sid = new CookieContainer();
                sid.Add(response.Cookies);
                input = new StreamReader(response.GetResponseStream());
                while (!input.EndOfStream)
                {
                    content += input.ReadLine();
                }
            }

            // Analysis content
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(content);

            string             countx = "//*[@id=\"ctl00_ContentPlaceHolder2_WebPartManager1_gwpPanel4_dlmsg_ctl00_lblimsg\"]/li[1]";
            string             linkx  = "//*[@id=\"ctl00_ContentPlaceHolder2_WebPartManager1_gwpPanel4_dlmsg_ctl00_lblimsg\"]/li/a";
            HtmlNodeCollection c      = doc.DocumentNode.SelectNodes(countx);

            // Get total unread message count
            string title = "";

            foreach (HtmlNode node in c)
            {
                title = node.InnerText;
            }
            regex = new Regex("[0-9]+");
            match = regex.Match(title);
            int count = Convert.ToInt32(match.Value);

            mform.UpdateLog("[MESSAGE] " + count + " LINKS FOUND!");

            // Get <=10 unread message url
            List <string>      urls  = new List <string>();
            HtmlNodeCollection links = doc.DocumentNode.SelectNodes(linkx);

            regex = new Regex("href='(?<url>[^']+)'");
            foreach (HtmlNode link in links)
            {
                urls.Add("http://kiss.taipei.gov.tw" + regex.Match(link.OuterHtml).Groups["url"].Value);
            }

            // Read to end
            while (count > 0)
            {
                count -= links.Count;
                foreach (string url in urls)
                {
                    mform.UpdateLog("[OPEN URL] : " + url);

                    request = WebRequest.CreateHttp(url);
                    request.CookieContainer = sid;
                    response = (HttpWebResponse)request.GetResponse();
                    input    = new StreamReader(response.GetResponseStream());
                    while (!input.EndOfStream)
                    {
                        input.ReadLine();
                    }

                    Thread.Sleep(20);
                }
            }
            mform.UpdateText("FINISHED!");
            mform.UpdateLog("FINISHED!");
        }
Exemplo n.º 5
0
        public static void ImportBusStop(object obj)
        {
            object[] args = (object[])obj;
            string   path = (string)args[0];
            MainForm form = (MainForm)args[1];

            form.UpdateText("Getting data from database");
            List <BusStop>      dbStop      = (from s in db.BusStop select s).ToList();
            List <BusStopClass> dbStopClass = (from c in db.BusStopClass select c).ToList();

            form.UpdateLog("Getting data from database");
            List <BusStop>      temp  = new List <BusStop>();
            List <BusStopClass> tempC = new List <BusStopClass>();

            form.UpdateText("Start reading file");
            StreamReader input = new StreamReader(path);

            while (!input.EndOfStream)
            {
                string[]     data = input.ReadLine().Split(',');
                BusStopClass bsc  = (from bc in dbStopClass where bc.Name.Equals(data[5]) select bc).FirstOrDefault();
                if (bsc == null)
                {
                    bsc = (from b in tempC where b.Name.Equals(data[5]) select b).FirstOrDefault();
                    if (bsc == null)
                    {
                        bsc      = new BusStopClass();
                        bsc.Name = data[5];
                        db.BusStopClass.Add(bsc);

                        tempC.Add(bsc);
                        db.SaveChanges();
                    }
                }

                BusStop stop = (from st in dbStop where
                                st.District.Equals(data[1].Trim()) &&
                                st.Name.Equals(data[2].Trim()) &&
                                st.Address.Equals(data[3].Trim()) &&
                                st.Direction.Equals(data[4].Trim()) &&
                                st.BSCID == bsc.BSCID
                                select st).FirstOrDefault();
                if (stop == null)
                {
                    stop = (from tt in temp
                            where
                            tt.District.Equals(data[1].Trim()) &&
                            tt.Name.Equals(data[2].Trim()) &&
                            tt.Address.Equals(data[3].Trim()) &&
                            tt.Direction.Equals(data[4].Trim()) &&
                            tt.BSCID == bsc.BSCID
                            select tt).FirstOrDefault();
                    if (stop == null)
                    {
                        stop          = new BusStop();
                        stop.District = data[1].Trim();
                        stop.Name     = data[2].Trim().Replace(" ", String.Empty).Replace(" ", String.Empty);
                        if (stop.Name.Length > 20)
                        {
                            form.UpdateLog("STOP [ " + stop.Name + " ]\t:\t NAME LENGTH > 20");
                        }
                        stop.Address = data[3].Trim();
                        if (stop.Name.Length > 50)
                        {
                            form.UpdateLog("STOP [ " + stop.Name + " ]\t:\t ADDRESS LENGTH > 50");
                        }
                        if (stop.Address.Equals(""))
                        {
                            stop.Address = "unknown";
                        }
                        stop.Direction = data[4].Trim().Replace("往", String.Empty).Replace("向", String.Empty);
                        if (stop.Name.Length > 20)
                        {
                            form.UpdateLog("STOP [ " + stop.Name + " ]\t:\t NAME DIRECTION > 1");
                        }
                        if (stop.Direction.Equals(""))
                        {
                            stop.Direction = "N";
                        }
                        stop.BSCID = bsc.BSCID;

                        temp.Add(stop);
                        db.BusStop.Add(stop);
                    }
                }
            }
            form.UpdateLog("Start reading file");
            form.UpdateText("Read finished");
            form.UpdateLog("Read finished");
            form.UpdateText("Incert data into database");
            db.SaveChanges();
            form.UpdateLog("Incert finished");
        }