Exemplo n.º 1
0
        /// <summary>
        /// 请假申请
        /// </summary>
        public void Request(LeaveRequestDto input)
        {
            CheckCanRequest(input);
            var leave = new LeaveOrder
            {
                ApplicantId     = input.LeaveerId,
                LeaveerId       = input.LeaveerId,
                StartTime       = input.StartTime,
                EndOfTime       = input.EndOfTime,
                LeaveDays       = input.LeaveDays,
                LeaveType       = input.LeaveType,
                Reason          = input.ReasonForLeave,
                AttachmentsPath = input.AttachmentsPath,
                Status          = "0"
            };

            foreach (var item in input.Approvers)
            {
                AddAndSave(new LeaveApprove
                {
                    ApproverId   = item,
                    OrderId      = leave.Id,
                    ApproveLevel = 1
                });
            }
            AddAndSave(leave);
            SaveChanges();
        }
Exemplo n.º 2
0
        /// <summary>
        /// 设置请假单状态
        /// </summary>
        /// <param name="leave"></param>
        private void SetOrderStatus(LeaveOrder order)
        {
            if (order.LeaveDays <= 3)
            {
                order.Status = "1";
                return;
            }
            var currentUserId = Operator.GetCurrent().Id;
            var approve       = Read <LeaveApprove>(p => p.OrderId.Equals(order.Id) && p.ApproverId.Equals(currentUserId)).FirstOrDefaultAsync().Result;

            //if (approve.ApproveLevel == 2)  多级审批,只要有一个人审批通过,就算通过
            order.Status = "1";
        }
Exemplo n.º 3
0
        public static Order ParseOrder(Person person, Faction faction, string command, string arguments)
        {
            Order order;

            switch (command)
            {
            case "address":
                order = new AddressOrder(arguments);
                break;

            case "attack":
                order = new AttackOrder(arguments);
                break;

            case "avoid":
                order = new AvoidOrder(arguments);
                break;

            case "build":
                order = new BuildOrder(arguments);
                break;

            case "burn":
                order = new BurnOrder(arguments);
                break;

            case "consume":
                order = new ConsumeOrder(person, arguments);
                break;

            case "cure":
                order = new CureOrder(arguments);
                break;

            case "declare":
                order = new DeclareOrder(faction, arguments);
                break;

            case "describe":
                order = new DescribeOrder(arguments);
                break;

            case "drive":
                order = new DriveOrder(arguments);
                break;

            case "enter":
                order = new EnterOrder(arguments);
                break;

            case "equipment":
                order = new EquipmentOrder(arguments);
                break;

            case "evict":
                order = new EvictOrder(arguments);
                break;

            case "give":
                order = new GiveOrder(arguments);
                break;

            case "greedy":
                order = new GreedyOrder(arguments);
                break;

            case "hide":
                order = new HideOrder(arguments);
                break;

            case "install":
                order = new InstallOrder(arguments);
                break;

            case "kick":
                order = new KickOrder();
                break;

            case "leave":
                order = new LeaveOrder();
                break;

            case "move":
                order = new MoveOrder(arguments);
                break;

            case "name":
                order = new NameOrder(arguments);
                break;

            case "option":
                order = new OptionOrder(arguments);
                break;

            case "password":
                order = new PasswordOrder(arguments);
                break;

            case "patrol":
                order = new PatrolOrder();
                break;

            case "produce":
                order = new ProduceOrder(arguments);
                break;

            case "quit":
                order = new QuitOrder(faction, arguments);
                break;

            case "scavenge":
                order = new ScavengeOrder(arguments);
                break;

            case "show":
                order = new ShowOrder(arguments);
                break;

            case "spoils":
                order = new SpoilsOrder(arguments);
                break;

            case "team":
                order = new TeamOrder(arguments);
                break;

            case "trade":
                order = new TradeOrder(arguments);
                break;

            case "uninstall":
                order = new UninstallOrder(arguments);
                break;

            default:
                throw new Exception("Bad order " + command);
            }
            return(order);
        }
Exemplo n.º 4
0
        public static void Load(string filename, bool checker)
        {
            TextReader tr = new StreamReader(filename, System.Text.Encoding.GetEncoding(1251));

            bool      do_read       = false;
            Person    person        = null;
            Faction   faction       = null;
            bool      errors        = false;
            ArrayList CheckerOutput = new ArrayList();

            while (true)
            {
                try
                {
                    string line = tr.ReadLine();
                    string s    = line;
                    if (s == null)
                    {
                        break;
                    }

                    // Store repeating lines
                    if (s.Length > 0 && s[0] == '@')
                    {
                        if (person != null)
                        {
                            person.RepeatingLines.Add(line);
                        }
                        s = s.Substring(1);
                    }

                    // Strip comments
                    s = MyStrings.Uncomment(s).Trim();

                    // Get first word as command
                    string cmd = MyStrings.GetToken(ref s).ToLower();

                    // Directives
                    if (cmd == "#orders")
                    {
                        string t2 = MyStrings.GetToken(ref s);
                        if (!MyStrings.IsNumber(t2))
                        {
                            throw new Exception("Bad faction");
                        }
                        int    num      = Convert.ToInt32(t2);
                        string password = MyStrings.GetQuotedToken(ref s);
                        faction = (Faction)Faction.Get(num);
                        if (faction == null)
                        {
                            throw new Exception("No such faction");
                        }
                        if (password != faction.Password || faction.IsNPC)
                        {
                            throw new Exception("Wrong password");
                        }

                        Console.WriteLine("..orders for " + faction.Num.ToString());

                        CheckerOutput.Add("To: " + faction.Email);
                        CheckerOutput.Add("Subject: Checker Output");
                        CheckerOutput.Add("");
                        CheckerOutput.Add(line);

                        do_read = true;
                        continue;
                    }
                    if (cmd == "#end")
                    {
                        do_read = false;
                    }
                    if (!do_read || cmd == "")
                    {
                        continue;
                    }
                    if (cmd == "person")
                    {
                        string t2 = MyStrings.GetToken(ref s);
                        if (!MyStrings.IsNumber(t2))
                        {
                            throw new Exception("Bad person");
                        }
                        int num = Convert.ToInt32(t2);
                        person = faction.Persons.GetByNumber(num);
                        if (person == null)
                        {
                            throw new Exception("This person is not in your faction");
                        }
                        CheckerOutput.Add("\r\n" + line);
                        continue;
                    }

                    CheckerOutput.Add(line);

                    if (person == null)
                    {
                        throw new Exception("Order given with no person specified");
                    }

                    Order order;

                    if (cmd == "address")
                    {
                        order = ReadAddressOrder(s);
                    }
                    else if (cmd == "attack")
                    {
                        order = ReadPersonNumOrder(s, new AttackOrder());
                    }
                    else if (cmd == "avoid")
                    {
                        order = ReadAvoidOrder(s);
                    }
                    else if (cmd == "build")
                    {
                        order = ReadBuildOrder(s);
                    }
                    else if (cmd == "burn")
                    {
                        order = ReadItemTypeListOrder(s, new BurnOrder());
                    }
                    else if (cmd == "consume")
                    {
                        order = ReadItemTypeListOrder(s, new ConsumeOrder());
                    }
                    else if (cmd == "cure")
                    {
                        order = ReadCureOrder(s);
                    }
                    else if (cmd == "declare")
                    {
                        order = ReadDeclareOrder(faction, s);
                    }
                    else if (cmd == "describe")
                    {
                        order = ReadDescribeOrder(s);
                    }
                    else if (cmd == "drive")
                    {
                        order = ReadDriveOrder(s);
                    }
                    else if (cmd == "enter")
                    {
                        order = ReadEnterOrder(s);
                    }
                    else if (cmd == "equipment")
                    {
                        order = ReadItemTypeListOrder(s, new EquipmentOrder());
                    }
                    else if (cmd == "evict")
                    {
                        order = ReadPersonNumOrder(s, new EvictOrder());
                    }
                    else if (cmd == "give")
                    {
                        order = ReadGiveOrder(s);
                    }
                    else if (cmd == "hide")
                    {
                        order = ReadHideOrder(s);
                    }
                    else if (cmd == "install")
                    {
                        order = ReadInstallOrder(s);
                    }
                    else if (cmd == "kick")
                    {
                        order = new KickOrder();
                    }
                    else if (cmd == "leave")
                    {
                        order = new LeaveOrder();
                    }
                    else if (cmd == "maintain")
                    {
                        order = new MaintainOrder();
                    }
                    else if (cmd == "move")
                    {
                        order = ReadMoveOrder(s);
                    }
                    else if (cmd == "name")
                    {
                        order = ReadNameOrder(s);
                    }
                    else if (cmd == "option")
                    {
                        order = ReadOptionOrder(s);
                    }
                    else if (cmd == "password")
                    {
                        order = ReadPasswordOrder(s);
                    }
                    else if (cmd == "patrol")
                    {
                        order = new PatrolOrder();
                    }
                    else if (cmd == "produce")
                    {
                        order = ReadProduceOrder(s);
                    }
                    else if (cmd == "quit")
                    {
                        order = ReadQuitOrder(s, faction);
                    }
                    else if (cmd == "scavenge")
                    {
                        order = ReadItemTypeListOrder(s, new ScavengeOrder());
                    }
                    else if (cmd == "show")
                    {
                        order = ReadShowOrder(s);
                    }
                    else if (cmd == "team")
                    {
                        order = ReadTeamOrder(s);
                    }
                    else if (cmd == "trade")
                    {
                        order = ReadTradeOrder(s);
                    }
                    else if (cmd == "uninstall")
                    {
                        order = ReadUninstallOrder(s);
                    }
                    else
                    {
                        throw new Exception("Bad order");
                    }

                    // Overwrite monthlong order
                    if (order.IsMonthlong)
                    {
                        int i = 0;
                        while (i < person.Orders.Count)
                        {
                            if (((Order)person.Orders[i]).IsMonthlong)
                            {
                                person.Orders.RemoveAt(i);
                                CheckerOutput.Add("; **** Overwriting previous monthlong order ****\r\n");
                                errors = true;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }

                    // Overwrite trade order
                    if (order.GetType() == typeof(TradeOrder))
                    {
                        int i = 0;
                        while (i < person.Orders.Count)
                        {
                            if (person.Orders[i].GetType() == typeof(TradeOrder))
                            {
                                person.Orders.RemoveAt(i);
                                CheckerOutput.Add("; **** Overwriting previous trade order ****\r\n");
                                errors = true;
                            }
                            else
                            {
                                i++;
                            }
                        }
                    }

                    person.Orders.Add(order);
                }
                catch (Exception ex)
                {
                    CheckerOutput.Add("; **** " + ex.Message + " ****\r\n");
                    errors = true;
                }
            }

            tr.Close();

            if (checker)
            {
                TextWriter tw = new StreamWriter(filename + ".checker", false, System.Text.Encoding.GetEncoding(1251));
                if (errors)
                {
                    foreach (string s in CheckerOutput)
                    {
                        tw.WriteLine(s);
                    }
                }
                else
                {
                    // Write only message header
                    foreach (string s in CheckerOutput)
                    {
                        tw.WriteLine(s);
                        if (s == "")
                        {
                            break;
                        }
                    }
                    tw.WriteLine("Your order was accepted without errors.");
                }
                tw.Close();
            }
        }