Esempio n. 1
0
        public void Download(string l, string r, UpdateProgress invoker)
        {
            JArray        orders = req.Get_Order(l.Replace("-", "/").Replace(" ", "-"), r.Replace("-", "/").Replace(" ", "-"));
            List <JToken> data   = new List <JToken>(from token in orders orderby DateTime.Parse(token["recv_date"].ToString()) select token);

            JArray dish_respond = req.Get_Dish();

            int counter = 5;
            Dictionary <int, int> did_to_cordinate = new Dictionary <int, int>();

            foreach (JToken item in dish_respond)
            {
                if (item["department"]["factory"]["name"].ToString(Newtonsoft.Json.Formatting.None) != "\"" + req.uname + "\"")
                {
                    continue;
                }
                if (item["is_idle"].ToString(Newtonsoft.Json.Formatting.None) == "\"1\"")
                {
                    continue;
                }
                did_to_cordinate[item["dish_id"].ToObject <int>()] = counter;
                excel.Write(1, counter, item["dish_name"].ToString(Newtonsoft.Json.Formatting.None).Replace("\"", ""));
                counter += 1;
            }

            counter = 2;
            foreach (JToken item in data)
            {
                int[] sum = new int[1000];
                foreach (JToken dish in item["dish"])
                {
                    sum[dish.ToObject <int>()] += 1;
                }

                excel.Write(counter, 1, counter - 1);
                excel.Write(counter, 2, item["user"]["seat_no"].ToString());
                excel.Write(counter, 3, Regex.Match(item["recv_date"].ToString(), " [0-9]{2}:[0-9]{2}").Groups[0].ToString().Replace(" ", ""));
                excel.Write(counter, 4, item["money"]["charge"].ToString());

                foreach (JToken dish in dish_respond)
                {
                    if (dish["department"]["factory"]["name"].ToString(Newtonsoft.Json.Formatting.None) != "\"" + req.uname + "\"")
                    {
                        continue;
                    }
                    if (dish["is_idle"].ToString(Newtonsoft.Json.Formatting.None) == "\"1\"")
                    {
                        continue;
                    }
                    excel.Write(counter, did_to_cordinate[dish["dish_id"].ToObject <int>()],
                                sum[dish["dish_id"].ToObject <int>()] == 0 ? "" : sum[dish["dish_id"].ToObject <int>()].ToString());
                }

                counter += 1;
                invoker((int)Math.Ceiling((double)(counter - 2) / data.Count * 100));
            }
        }
        public void Download(UpdateProgress invoker)
        {
            JArray data = req.Get_Dish(), real = new JArray();

            foreach (JToken item in data)
            {
                if (item["department"]["factory"]["boss_id"].ToString() == req.user_id)
                {
                    real.Add(item);
                }
            }

            int sum     = real.Count;
            int counter = 2;

            foreach (JToken item in real)
            {
                int    id            = Int32.Parse(item["dish_id"].ToString());
                string dname         = item["dish_name"].ToString();
                string charge        = item["dish_cost"].ToString();
                string vege          = item["vege"]["name"].ToString();
                string idle          = item["is_idle"].ToString();
                string daily_limit   = item["daily_produce"].ToString();
                int    department_id = Int32.Parse(item["department"]["id"].ToString());
                string department    = item["department"]["name"].ToString() + "(" + ((department_id - 1) % 4 + 1).ToString() + ")";
                string factory       = item["department"]["factory"]["name"].ToString() + "(" + item["department"]["factory"]["id"].ToString() + ")";

                excel.Write(counter, 1, id);
                excel.Write(counter, 2, dname);
                excel.Write(counter, 3, charge);
                excel.Write(counter, 4, (vege == "MEAT" ? "葷" : "素"));
                excel.Write(counter, 5, (idle == "0" ? "否" : "是"));
                excel.Write(counter, 6, daily_limit);
                excel.Write(counter, 7, department);
                excel.Write(counter, 8, factory);
                excel.Write(counter, 9, DateTime.Now.ToString("yyyy/MM/dd-HH:mm:ss"));

                counter += 1;
                invoker((int)Math.Ceiling(((double)(counter - 2)) / sum * 100));
            }
        }
Esempio n. 3
0
        public void Download(string l, string r, UpdateProgress invoker)
        {
            invoker(25);
            JArray data = req.Get_Order(l.Replace("-", "/").Replace(" ", "-"), r.Replace("-", "/").Replace(" ", "-"));
            Dictionary <string, int> charge  = new Dictionary <string, int>();
            Dictionary <int, int>    amounts = new Dictionary <int, int>();

            for (int year = 1; year <= 3; year++)
            {
                for (int cls = 1; cls <= 20; cls++)
                {
                    charge[(year * 100 + cls).ToString()] = 0;
                }
            }
            charge["other"] = 0;
            for (int i = 40; i <= 100; i += 5)
            {
                amounts[i] = 0;
            }
            amounts[-1] = 0;

            foreach (JToken item in data)
            {
                string cno   = item["user"]["class"]["class_no"].ToObject <string>();
                int    value = item["money"]["charge"].ToObject <int>();;
                charge[charge.ContainsKey(cno) ? cno : "other"]  += value;
                amounts[amounts.ContainsKey(value) ? value : -1] += 1;
            }

            invoker(75);
            for (int year = 1; year <= 3; year++)
            {
                for (int cls = 1; cls <= 20; cls++)
                {
                    excel.Write(cls + 1, year * 3 - 1, charge[(year * 100 + cls).ToString()]);
                }
            }
            for (int i = 11; i <= 23; i++)
            {
                excel.Write(i, 11, amounts[(i - 11) * 5 + 40]);
            }
            excel.Write(24, 11, amounts[-1]);
            excel.Write(24, 2, charge["other"]);
            excel.Write(5, 11, req.uname);
            excel.Write(6, 11, l);
            excel.Write(7, 11, r);

            invoker(100);
        }
Esempio n. 4
0
        public void Download(string l, string r, UpdateProgress invoker)
        {
            JArray data = req.Get_Order(l.Replace("-", "/").Replace(" ", "-"), r.Replace("-", "/").Replace(" ", "-"));
            Dictionary <int, string> dish       = new Dictionary <int, string>();
            Dictionary <int, string> department = new Dictionary <int, string>();

            int[]  parent       = new int[1000];
            JArray dish_respond = req.Get_Dish();

            foreach (JToken item in dish_respond)
            {
                if (item["department"]["factory"]["name"].ToString(Newtonsoft.Json.Formatting.None) != "\"" + req.uname + "\"")
                {
                    continue;
                }
                if (item["is_idle"].ToString(Newtonsoft.Json.Formatting.None) == "\"1\"")
                {
                    continue;
                }
                dish[item["dish_id"].ToObject <int>()] = item["dish_name"].ToString() + "(" + item["dish_cost"].ToString() + "$.)";
                department[item["department"]["id"].ToObject <int>()] = item["department"]["name"].ToString();
                parent[item["dish_id"].ToObject <int>()] = item["department"]["id"].ToObject <int>();
            }
            Dictionary <string, int[]> processed = preprocess(data);

            int row, col, i, j, counter;

            counter = row = col = i = j = 1;
            foreach (KeyValuePair <string, int[]> tag in processed)
            {
                row = i;
                foreach (KeyValuePair <int, string> depart in department)
                {
                    excel.Write(i, j, tag.Key);
                    excel.Write(i, j + 1, depart.Value);
                    i += 1;
                    foreach (KeyValuePair <int, string> item in dish)
                    {
                        if (parent[item.Key] != depart.Key)
                        {
                            continue;
                        }
                        excel.Write(i, j, item.Value);
                        excel.Write(i, j + 1, tag.Value[item.Key]);
                        i += 1;
                    }
                    i += 1;
                }

                if (col == 1)
                {
                    col += 1;
                    i    = row;
                    j    = 4;
                }
                else if (col == 2)
                {
                    excel.PageBreak(i);
                    col = 1;
                    j   = 1;
                }

                invoker((int)Math.Ceiling((double)counter / processed.Keys.Count * 100));
                counter += 1;
            }
        }