コード例 #1
0
ファイル: Crud.cs プロジェクト: Potatismoose/FamilyTree
        /// <summary>
        /// Creates one person from the Relative class.
        /// </summary>
        /// <param name="row">Takes an DataRow as inparameter.</param>
        /// <returns>Returns a person object of the Relative class.</returns>
        public Relative CreatePersonFromQuery(DataRow row)
        {
            /*******************************************************************
            *               CREATEPERSONFROMQUERY() - PUBLIC
            *******************************************************************/
            var person = new Relative()
            {
                Id        = (int)row["id"],
                FirstName = row["firstName"].ToString(),
                LastName  = row["lastName"].ToString(),
                MotherId  = (int)row["motherId"],
                FatherId  = (int)row["fatherId"]
            };

            if (!(row["birthDate"] is DBNull))
            {
                person.BirthDate = (DateTime)row["birthDate"];
            }
            if (!(row["birthPlace"] is DBNull))
            {
                person.BirthPlace = row["birthPlace"].ToString();
            }
            if (!(row["deathDate"] is DBNull))
            {
                person.DeathDate = (DateTime)row["deathDate"];
            }
            if (!(row["deathPlace"] is DBNull))
            {
                person.DeathPlace = row["deathPlace"].ToString();
            }

            return(person);
        }
コード例 #2
0
    public static void Main()
    {
        var allPersons = new List <Person>();

        while (true)
        {
            string   line          = Console.ReadLine();
            string[] input         = line.Split();
            string   personName    = input[0];
            Person   currentPerson = allPersons.FirstOrDefault(p => p.Name == personName);

            if (line == "End")
            {
                break;
            }

            string filter = input[1];

            if (currentPerson == null)
            {
                allPersons.Add(new Person(personName));
                currentPerson = allPersons.FirstOrDefault(p => p.Name == personName);
            }

            switch (filter)
            {
            case "company":
                var companyInfo = new CompanyInfo(input[2], input[3], decimal.Parse(input[4]));
                currentPerson.CompanyInfo = companyInfo;
                break;

            case "pokemon":
                var currentPokemon = new Pokemon(input[2], input[3]);
                currentPerson.Pokemons.Add(currentPokemon);
                break;

            case "parents":
                var currentParent = new Relative(input[2], input[3]);
                currentPerson.Parents.Add(currentParent);
                break;

            case "children":
                var currentChild = new Relative(input[2], input[3]);
                currentPerson.Children.Add(currentChild);
                break;

            case "car":
                var currentCar = new Car(input[2], int.Parse(input[3]));
                currentPerson.Car = currentCar;
                break;

            default:
                break;
            }
        }

        string personToFindByName = Console.ReadLine();

        Console.WriteLine(allPersons.FirstOrDefault(p => p.Name == personToFindByName));
    }
コード例 #3
0
        public List <Relative> GetRelatives()
        {
            List <Relative> relativeList = new List <Relative>();

            using (SqlConnection connection = new SqlConnection(CronusQueryWebService.GetConnectionString()))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand("SELECT[CRONUS Sverige AB$Employee].[First Name], [CRONUS Sverige AB$Employee].[Last Name],[CRONUS Sverige AB$Employee].No_, [Relative Code], [CRONUS Sverige AB$Employee Relative].[First Name], [CRONUS Sverige AB$Employee Relative].[Last Name] FROM[CRONUS Sverige AB$Employee] INNER JOIN[CRONUS Sverige AB$Employee Relative]  ON[CRONUS Sverige AB$Employee].[No_] = [CRONUS Sverige AB$Employee Relative].[Employee No_]", connection))
                {
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Relative newRelative = new Relative();
                            newRelative.empFirstName = reader.GetValue(0).ToString();
                            newRelative.empLastName  = reader.GetValue(1).ToString();
                            newRelative.empNo_       = reader.GetValue(2).ToString();
                            newRelative.relativeCode = reader.GetValue(3).ToString();
                            newRelative.firstName    = reader.GetValue(4).ToString();
                            newRelative.lastName     = reader.GetValue(5).ToString();
                            relativeList.Add(newRelative);
                        }
                    }
                }
            }
            return(relativeList);
        }
コード例 #4
0
 public Person(string name, string RelativeName, string birthday, string type)
     : this(name)
 {
     this.Relatives = new List <Relative>();
     Relative parent = new Relative(RelativeName, birthday, type);
     Relatives.Add(parent);
 }
コード例 #5
0
        private void ProcessIncomeTable(Table table, PublicServant person)
        {
            var rows = table.Descendants <TableRow>().ToList().Skip(1);

            foreach (var row in rows)
            {
                var cells      = row.Descendants <TableCell>().ToList();
                var incomeType = cells[1].InnerText.OnlyRussianLowercase();
                if (incomeType.StartsWith("декларированныйгодовойдоход"))
                {
                    var incomeRaw = cells[2].InnerText.Trim();
                    if (incomeRaw == "")
                    {
                        continue;
                    }
                    person.DeclaredYearlyIncomeRaw = incomeRaw;
                    person.DeclaredYearlyIncome    = DataHelper.ParseDeclaredIncome(incomeRaw, false);
                }
                else if (DataHelper.IsRelativeInfo(incomeType))
                {
                    var incomeRaw    = cells[2].InnerText.Trim();
                    var relationType = DataHelper.ParseRelationType(incomeType, false);
                    var relative     = new Relative();
                    relative.RelationType            = relationType;
                    relative.DeclaredYearlyIncomeRaw = incomeRaw;
                    relative.DeclaredYearlyIncome    = DataHelper.ParseDeclaredIncome(incomeRaw, false);
                    person.AddRelative(relative);
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Adds Relative to Specific Citizen
        /// </summary>
        /// <param name="citizenId">Citizen Id</param>
        /// <param name="relativeId">Relative Id</param>
        /// <param name="relationId">Relation Type Id</param>
        /// <param name="notifyRelative">delegate that runs after adding relative to notify user</param>
        public void AddRelative(long citizenId, long relativeId, int relationId, Action notifyRelative = null)
        {
            Relative relative = new Relative();

            if (relationId != 4)
            {
                relative.CitizenID         = citizenId;
                relative.RelativeID        = relativeId;
                relative.RelationTypeID    = relationId;
                relative.CitizenConfirmed  = true;
                relative.RelativeConfirmed = false;
            }
            else
            {
                relative.RelativeID        = citizenId;
                relative.CitizenID         = relativeId;
                relative.RelationTypeID    = 1;
                relative.RelativeConfirmed = true;
                relative.CitizenConfirmed  = false;
            }

            DBEntities.Relatives.Add(relative);
            DBEntities.SaveChanges();
            notifyRelative?.Invoke();
        }
コード例 #7
0
 public override bool Equals(object other)
 {
     if (other == null)
     {
         return(false);
     }
     else if (other is ScreenPoint)
     {
         return(Equals((ScreenPoint)other));
     }
     else if (other is Vector2)
     {
         return(Relative.Equals((Vector2)other));
     }
     else if (other is Point)
     {
         return(Absolute.Equals((Point)other));
     }
     else if ((other = other as string) != null)
     {
         return(ToString().Equals(other));
     }
     else
     {
         return(false);
     }
 }
コード例 #8
0
        public async Task <ActionResult> Details(string id)
        {
            Relative relative = await relatives.GetOneDocument(id);

            if (relative != null)
            {
                RelativeViewModel model = new RelativeViewModel
                {
                    Identification = relative.Identification,
                    Name           = relative.Name,
                    FirstSurname   = relative.FirstSurname,
                    SecondSurname  = relative.SecondSurname,
                    Address        = relative.Address,
                    Related        = relative.Related,
                    Phone          = relative.Phone,
                    OlderAdultId   = relative.OlderAdultId,
                    Email          = relative.Email
                };

                return(View(model));
            }
            else
            {
                ViewBag.ErrirMessage = "El id de ensayo ingresado no fue encontrado";
                return(View("Error"));
            }
        }
コード例 #9
0
        public Boolean Insert(BinaryTreeNode <E> node, Relative rel)
        {
            Boolean inserted = true;

            if ((rel == Relative.leftChild && current.Left != null) ||
                (rel == Relative.rightChild && current.Right != null))
            {
                inserted = false;
            }
            else
            {
                switch (rel)
                {
                case Relative.leftChild:
                    current.Left = node;
                    break;

                case Relative.rightChild:
                    current.Right = node;
                    break;

                case Relative.root:
                    if (root == null)
                    {
                        root = node;
                    }
                    current = root;
                    break;
                }
                size++;
            }

            return(inserted);
        }
コード例 #10
0
        public void RelativeTest()
        {
            var minTime     = DateTime.MinValue;
            var maxTime     = DateTime.MaxValue;
            var offset      = 1;
            var offsetTypes = new Dictionary <TimeOffset, PropertyInfo>()
            {
                { TimeOffset.Milliseconds, typeof(TimeSpan).GetProperty("Milliseconds") },
                { TimeOffset.Seconds, typeof(TimeSpan).GetProperty("Seconds") },
                { TimeOffset.Minutes, typeof(TimeSpan).GetProperty("Minutes") },
                { TimeOffset.Hours, typeof(TimeSpan).GetProperty("Hours") },
                { TimeOffset.Days, typeof(TimeSpan).GetProperty("Days") }
                //TimeOffset.Months,
                //TimeOffset.Years
            };

            foreach (var offsetType in offsetTypes)
            {
                var rc = new Relative()
                {
                    MinValue   = minTime,
                    Offset     = offset,
                    OffsetType = offsetType.Key,
                    MaxValue   = maxTime
                };
                var      range = new TimeRangeImpl();
                DateTime now   = DateTime.UtcNow;
                rc.Convert(range);
                TimeSpan delta = now - range.StartTime;
                Assert.AreEqual(offsetType.Value.GetValue(delta), offset);
            }
        }
コード例 #11
0
 private void BtnDelete_Click(object sender, EventArgs e)
 {
     if (txtNameRelative.Text == "")
     {
         MessageBox.Show("Choose Relation");
     }
     else
     {
         DialogResult dr = MessageBox.Show("Do you want delete this Relative?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
         if (DialogResult.Yes == dr)
         {
             try
             {
                 int      id   = (int)gridStudent.GetFocusedRowCellValue("ID");
                 var      name = txtNameRelative.Text;
                 Relative tg   = context.Relatives.Where(p => p.ID_Student == id & p.Name == name).FirstOrDefault();
                 context.Relatives.Remove(tg);
                 context.SaveChanges();
                 MessageBox.Show("Deleted");
                 LoadDgvStudent();
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Failed\n" + ex.Message, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
 }
コード例 #12
0
        private void AddRelative(Relative relative)
        {
            relatives.Add(relative);
            var view = new RelativeView();

            view.Margin               = new Thickness(5);
            view.CollapseButtons      = false;
            view.Relative             = relative;
            view.DeleteButtonClicked += (sender, args) =>
            {
                if (view.Relative.Id > 0)
                {
                    idsForDelete.Add(view.Relative.Id);
                }
                RelativePanel.Children.Remove(view);
                relatives.Remove(view.Relative);
            };
            view.EditButtonClicked += (sender, args) =>
            {
                var window = new EditRelativeWindow();
                window.Owner        = this;
                window.RelativeView = view;
                window.ShowDialog();
            };
            RelativePanel.Children.Add(view);
        }
コード例 #13
0
ファイル: Crud.cs プロジェクト: Potatismoose/FamilyTree
        /// <summary>
        /// Method for updating a person in the database.
        /// </summary>
        /// <param name="person">Takes a Person (relative) object as argument.</param>
        /// <returns>Returns number of rows affected in the database.</returns>
        public int EditPerson(Relative person)
        {
            /*******************************************************************
            *               EDITPERSON() - PUBLIC
            *******************************************************************/

            var sql = $"UPDATE Persons " +
                      $"SET firstName = @fname," +
                      $"lastName = @lName," +
                      $"birthDate = @birthDate," +
                      $"deathDate = @deathDate," +
                      $"motherId = @motherId," +
                      $"fatherId = @fatherId," +
                      $"birthPlace = @birthPlace, " +
                      $"deathPlace = @deathPlace " +
                      $"WHERE id = @id";


            return(ExecuteSQL(sql,
                              ("@fName", $"{person.FirstName}"),
                              ("@lName", $"{person.LastName}"),
                              ("@birthDate", $"{person.BirthDate}"),
                              ("@deathDate", $"{person.DeathDate}"),
                              ("@motherId", $"{person.MotherId}"),
                              ("@fatherId", $"{person.FatherId}"),
                              ("@birthPlace", $"{person.BirthPlace}"),
                              ("@deathPlace", $"{person.DeathPlace}"),
                              ("@id", $"{person.Id}")));
        }
コード例 #14
0
        private static void OnRelativePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var      view     = (RelativeView)sender;
            Relative relative = view.Relative;

            if (e.Property == RelationshipTypeProperty)
            {
                relative.RelationshipType = (string)e.NewValue;
            }
            else if (e.Property == FullNameProperty)
            {
                relative.FullName = (string)e.NewValue;
            }
            else if (e.Property == BirthYearProperty)
            {
                relative.BirthYear = (int)e.NewValue;
            }
            else if (e.Property == BirthPlaceProperty)
            {
                relative.BirthPlace = (string)e.NewValue;
            }
            else if (e.Property == WorkPlaceProperty)
            {
                relative.WorkPlace = (string)e.NewValue;
            }
        }
コード例 #15
0
            public void CreateNewRelative(DataRow row)
            {
                Logger.Debug("Relative {0} at row {1}", row.RelativeType, row.GetRowIndex());
                if (CurrentDeclarant == null)
                {
                    if (FailOnRelativeOrphan)
                    {
                        throw new SmartParserRelativeWithoutPersonException(
                                  string.Format("Relative {0} at row {1} without main Person", row.RelativeType, row.GetRowIndex()));
                    }
                    else
                    {
                        return;
                    }
                }
                Relative relative = new Relative();

                CurrentDeclarant.AddRelative(relative);
                CurrentPerson = relative;

                RelationType relationType = DataHelper.ParseRelationType(row.RelativeType, false);

                if (relationType == RelationType.Error)
                {
                    throw new SmartParserException(
                              string.Format("Wrong relative name '{0}' at row {1} ", row.RelativeType, row));
                }
                relative.RelationType      = relationType;
                relative.document_position = row.NameDocPosition;
                relative.sheet_index       = _Declaration.Properties.SheetNumber;
            }
コード例 #16
0
        // parses relatives including synonyms
        void parse_data_line(string ln, string searchstr, byte pos)
        {
            string [] fields = ln.Split();
            //char ss_type = fields[ss_type_field][0];

            UInt16 j;
            List<string> synonyms = get_synonms(fields, searchstr, out j);
            if (synonyms.Count > 0)
            {
                trim_adj_marker(ref synonyms, pos);
                try
                {
                    RelativeFamily syns = _relatives[strSynonym];
                    syns.Terms.AddRange(synonyms);
                }
                catch (KeyNotFoundException)
                {
                                                                   // relative type is 0 for synonyms
                    _relatives.Add(strSynonym, new RelativeFamily{ relType = 0, Terms = synonyms });
                }
            }

            UInt16 ptr_cnt = UInt16.Parse(fields[j++]);
            List<Relative> relatives = new List<Relative>();
            for(UInt16 i = 0; i < ptr_cnt; ++i, j += 4)
            {
                sbyte ptrType = (sbyte) Array.IndexOf<string>(pointer_symbols, fields[j]);
                if (-1 != ptrType)
                {
                    long _offset = long.Parse(fields[j + 1]);
                    Relative r = new Relative { relativeType = (byte)ptrType, offset = _offset, pos = fields[j + 2][0] };
                    relatives.Add(r);
                }
            }

            foreach (Relative r in relatives)
            {
                StreamReader reader = _dictFiles[getDataFile(r.pos)];
                reader.DiscardBufferedData();
                reader.BaseStream.Position = r.offset;
                string sln = reader.ReadLine();

                UInt16 temp;
                List<string> rel_terms = get_synonms(sln.TrimEnd().Split(), searchstr, out temp);
                if (rel_terms.Count > 0)
                {
                    trim_adj_marker(ref rel_terms, posCharToIndex[r.pos]);
                    try
                    {
                        RelativeFamily d = _relatives[relative_names[r.relativeType]];
                        d.Terms.AddRange(rel_terms);
                    }
                    catch (KeyNotFoundException)
                    {
                        _relatives.Add(relative_names[r.relativeType], new RelativeFamily { relType = r.relativeType,
                                                                                            Terms = rel_terms });
                    }
                }
            }
        }
コード例 #17
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Path.Expression != null)
            {
                targetCommand.AddParameter("Path", Path.Get(context));
            }

            if (LiteralPath.Expression != null)
            {
                targetCommand.AddParameter("LiteralPath", LiteralPath.Get(context));
            }

            if (Relative.Expression != null)
            {
                targetCommand.AddParameter("Relative", Relative.Get(context));
            }

            if (Credential.Expression != null)
            {
                targetCommand.AddParameter("Credential", Credential.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
コード例 #18
0
        public Boolean Insert(TreeNode <T> treeNode, Relative relative)
        {
            Boolean      inserted = true;
            TreeNode <T> newNode  = treeNode;

            if ((relative == Relative.LeftChild && current.Left != null) ||
                relative == Relative.RightChild && current.Right != null)
            {
                inserted = false;
            }
            else
            {
                if (relative == Relative.LeftChild)
                {
                    current.Left = newNode;
                }
                else if (relative == Relative.RightChild)
                {
                    current.Right = newNode;
                }
                else if (relative == Relative.Root)
                {
                    if (root == null)
                    {
                        root = newNode;
                    }
                    current  = root;
                    inserted = false;
                }
            }

            return(inserted);
        }
コード例 #19
0
        public bool Insert(E data, Relative rel)
        {
            bool inserted = true;

            BinaryTreeNode <E> node = new BinaryTreeNode <E>(data);

            if ((rel == Relative.leftChild && Current.Left != null) ||
                (rel == Relative.rightChild && Current.Right != null))
            {
                inserted = false;
            }
            else
            {
                switch (rel)
                {
                case Relative.leftChild:
                    Current.Left = node;
                    break;

                case Relative.rightChild:
                    Current.Right = node;
                    break;

                case Relative.root:
                    if (Root == null)
                    {
                        Root = node;
                    }
                    Current = Root;
                    break;
                }
                Size++;
            }
            return(inserted);
        }
コード例 #20
0
 string CreatTooltip(Relative relative)
 {
     _tooltip = "<color=#000000><b>" + relative.relativeName + "</b></color>\n\n" +
                "<color=#000000>" + "Relation: " + relative.relativeRelation +
                "\n\nAge: " + relative.relativeAge +
                "\n\nDescription: " + relative.relativeDescription + "</color>";
     return(_tooltip);
 }
コード例 #21
0
 private void FillData(Relative relative)
 {
     RelationshipText.Text = relative.RelationshipType;
     FullNameText.Text     = relative.FullName;
     BirthYearText.Text    = relative.BirthYear.ToString();
     BirthPlaceText.Text   = relative.BirthPlace;
     WorkPlaceText.Text    = relative.WorkPlace;
 }
コード例 #22
0
 public virtual async Task <JsonResult> Update(Relative model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new { IsSuccessful = false, Message = ModelState.GetModelError() }));
     }
     return(Json(await _MemberRelativeSrv.UpdateAsync(model)));
 }
コード例 #23
0
    int IComparable.CompareTo(object o)
    {
        int      returnVal;
        Relative temp = (Relative)o;

        returnVal = this.Name.CompareTo(temp.Name);
        return(returnVal);
    }
コード例 #24
0
        public ActionResult DeleteConfirmed(int id)
        {
            Relative relative = db.Relatives.Find(id);

            db.Relatives.Remove(relative);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #25
0
ファイル: Channel.cs プロジェクト: vasyaabr/Discord.Net
        public async Task <Message[]> DownloadMessages(int limit            = 100, ulong?relativeMessageId = null,
                                                       Relative relativeDir = Relative.Before, bool useCache = true)
        {
            if (limit < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(limit));
            }
            if (limit == 0 || Type != ChannelType.Text)
            {
                return(new Message[0]);
            }

            try
            {
                string dir;
                switch (relativeDir)
                {
                case Relative.Before:
                default: dir = "before"; break;

                case Relative.After: dir = "after"; break;

                case Relative.Around: dir = "around"; break;
                }
                var request = new GetMessagesRequest(Id)
                {
                    Limit       = limit,
                    RelativeDir = relativeMessageId.HasValue ? dir : null,
                    RelativeId  = relativeMessageId ?? 0
                };
                var msgs = await Client.ClientAPI.Send(request).ConfigureAwait(false);

                return(msgs.Select(x =>
                {
                    Message msg = null;
                    if (useCache)
                    {
                        msg = AddMessage(x.Id, GetUserFast(x.Author.Id), x.Timestamp.Value);
                        var user = msg.User;
                        if (user != null)
                        {
                            user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
                        }
                    }
                    else
                    {
                        msg = new Message(x.Id, this, GetUserFast(x.Author.Id));
                    }
                    msg.Update(x);
                    return msg;
                })
                       .ToArray());
            }
            catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.Forbidden)
            {
                return(new Message[0]);
            }
        }
コード例 #26
0
        public virtual bool Equals(SkillMod mod)
        {
            if (ReferenceEquals(null, mod))
            {
                return(false);
            }

            return(Value.Equals(mod.Value) && Relative.Equals(mod.Relative) && Skill == mod.Skill);
        }
コード例 #27
0
        static void Main(String[] arg)
        {
            Relative relative = new Relative();

            relative.Hello();
            relative.GutenTag();
            relative.Goodbye();
            relative.Aufwiedersehen();
        }
コード例 #28
0
        static void Main(string[] arg)
        {
            Relative   relative   = new Relative();
            SayHiToYou sayHiToYou = new SayHiToYou(relative.Hello);
            Publisher  p          = new Publisher();

            p.State("Meet");
            p.State("Leave");
        }
コード例 #29
0
        private static string GetRelativePart(Relative r)
        {
            if (r.Descendant == true)
            {
                return(string.Format("descendant::{0}", r.Name));
            }

            return(string.Format("ancestor::{0}", r.Name));
        }
コード例 #30
0
 public virtual async Task <JsonResult> Add(Relative model)
 {
     model.UserId = User.GetUserId();
     if (!ModelState.IsValid)
     {
         return(Json(new { IsSuccessful = false, Message = ModelState.GetModelError() }));
     }
     return(Json(await _MemberRelativeSrv.AddAsync(model)));
 }
コード例 #31
0
 public void testBeans()
 {
     Pickler p=new Pickler(false);
     Unpickler pu=new Unpickler();
     byte[] o;
     Relative person=new Relative("Tupac",true);
     o=p.dumps(person);
     Hashtable map=(Hashtable) pu.loads(o);
     Hashtable testmap=new Hashtable();
     testmap.Add("Name","Tupac");
     testmap.Add("Deceased",true);
     testmap.Add("Relation","unspecified");
     testmap.Add("__class__","Pyrolite.Tests.Pickle.PicklerTests+Relative");
     AssertUtils.AssertEqual(testmap, map);
 }
コード例 #32
0
 public static Task<Message[]> DownloadMessages(this DiscordClient client, Channel channel, int limit = 100, ulong? relativeMessageId = null, Relative relativeDir = Relative.Before, bool useCache = true)
 {
     if (channel == null) throw new ArgumentNullException(nameof(channel));
     return channel.DownloadMessages(limit, relativeMessageId, relativeDir, useCache);
 }
コード例 #33
0
ファイル: Channel.cs プロジェクト: Carbonitex/Discord.Net
        public async Task<Message[]> DownloadMessages(int limit = 100, ulong? relativeMessageId = null,
            Relative relativeDir = Relative.Before, bool useCache = true)
        {
            if (limit < 0) throw new ArgumentOutOfRangeException(nameof(limit));
            if (limit == 0 || Type != ChannelType.Text) return new Message[0];

            try
            {
                string dir;
                switch (relativeDir)
                {
                    case Relative.Before: default: dir = "before"; break;
                    case Relative.After: dir = "after"; break;
                    case Relative.Around: dir = "around"; break;
                }
                var request = new GetMessagesRequest(Id)
                {
                    Limit = limit,
                    RelativeDir = relativeMessageId.HasValue ? dir : null,
                    RelativeId = relativeMessageId ?? 0
                };
                var msgs = await Client.ClientAPI.Send(request).ConfigureAwait(false);
                return msgs.Select(x =>
                {
                    Message msg = null;
                    if (useCache)
                    {
                        msg = AddMessage(x.Id, GetUserFast(x.Author.Id), x.Timestamp.Value);
                        var user = msg.User;
                        if (user != null)
                            user.UpdateActivity(msg.EditedTimestamp ?? msg.Timestamp);
                    }
                    else
                        msg = new Message(x.Id, this, GetUserFast(x.Author.Id));
                    msg.Update(x);
                    return msg;
                })
                .ToArray();
            }
            catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.Forbidden)
            {
                return new Message[0];
            }
        }
コード例 #34
0
ファイル: PicklerTests.cs プロジェクト: davies/Pyrolite
	public void testClass() 
	{
		Pickler p=new Pickler(false);
		Unpickler pu=new Unpickler();
		byte[] o;
		Relative person=new Relative("Tupac",true, new int[] {3,4,5});
		o=p.dumps(person);
		Hashtable map=(Hashtable) pu.loads(o);
		
		Assert.AreEqual(5, map.Count);
		Assert.AreEqual("Pyrolite.Tests.Pickle.PicklerTests+Relative", map["__class__"]);
		Assert.AreEqual("Tupac", map["Name"]);
		Assert.AreEqual("unspecified", map["Relation"]);
		Assert.AreEqual(true, map["Deceased"]);
		Assert.AreEqual(new int[] {3,4,5}, map["Values"]);
	}
コード例 #35
0
 public override object CreateNewItem()
 {
     editableItem = new Relative();
     return editableItem;
 }
コード例 #36
0
ファイル: MSSQL_Manager.cs プロジェクト: Lootero4eg/UBureau
        public void UpdateRelative(Relative rel)
        {
            _cmd = CreateCommand("UpdateRelative");
            _param = CreateParameter("@relative_id", DbType.Int32, 4);
            _param.Value = rel.Id;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@rel_type_id", DbType.Int32, 4);
            _param.Value = rel.RelativeType;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@phone_type_id", DbType.Int32, 4);
            _param.Value = rel.PhoneType;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@fio", DbType.String, 75);
            _param.Value = rel.Name;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@phone_number", DbType.String, 25);
            _param.Value = rel.Phone;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@is_ordered_by", DbType.Boolean, 0);
            _param.Value = rel.Zakazchik;
            _cmd.Parameters.Add(_param);
            ExecuteCommand(_cmd.ExecuteNonQuery);
        }
コード例 #37
0
ファイル: MSSQL_Manager.cs プロジェクト: Lootero4eg/UBureau
        private void GetCardRelatives(DeceasedCard card)
        {
            _cmd = CreateCommand("GetCardRelatives");
            _param = CreateParameter("@card_id", DbType.Int32, 4);
            _param.Value = card.CardId;
            _cmd.Parameters.Add(_param);
            _DR = ExecuteDataReader(_cmd.ExecuteReader);

            while (_DR.Read())
            {
                Relative rel = new Relative();
                rel.Id = (int)_DR["relative_id"];
                rel.Name = _DR["relative_fio"].ToString();
                rel.Phone = _DR["phone_number"].ToString();
                rel.RelativeType = (int)_DR["rel_type_id"];
                rel.PhoneType = (int)_DR["phone_type_id"];

                card.Relatives.Add(rel);
            }

            _DR.Close();
        }
コード例 #38
0
ファイル: MSSQL_Manager.cs プロジェクト: Lootero4eg/UBureau
        public void AddRelative(int card_id, Relative rel)
        {
            _cmd = CreateCommand("AddRelative");
            _param = CreateParameter("@card_id", DbType.Int32, 4);
            _param.Value = card_id;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@rel_type_id", DbType.Int32, 4);
            _param.Value = rel.RelativeType;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@phone_type_id", DbType.Int32, 4);
            _param.Value = rel.PhoneType;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@fio", DbType.String, 75);
            _param.Value = rel.Name;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@phone_number", DbType.String, 25);
            _param.Value = rel.Phone;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@is_ordered_by", DbType.Boolean, 0);
            _param.Value = rel.Zakazchik;
            _cmd.Parameters.Add(_param);

            _param = CreateParameter("@relative_id", DbType.Int32, 4);
            _param.Direction = ParameterDirection.Output;
            _cmd.Parameters.Add(_param);
            ExecuteCommand(_cmd.ExecuteNonQuery);

            rel.Id = (int)_cmd.Parameters["@relative_id"].Value;
        }