Esempio n. 1
0
        //Add button action
        private void AddButton_Click(object sender, EventArgs e)
        {
            string firstName   = NameText.Text;
            string lastName    = SurnameText.Text;
            string information = InformationText.Text;
            string text        = "photo_url";

            using (var w = new WebClient())
            {
                string clientID = "d4a165a802843b0";
                w.Headers.Add("Authorization", "Client-ID " + clientID);
                var values = new NameValueCollection
                {
                    { "image", Convert.ToBase64String(File.ReadAllBytes(@"Image1.jpg")) }
                };

                byte[] response = w.UploadValues("https://api.imgur.com/3/upload.xml", values);
                var    xx       = XDocument.Load(new MemoryStream(response)).ToString();
                // MessageBox.Show(xx);
            }

            if (errorcode1 == 0 || errorcode2 == 0 || string.IsNullOrWhiteSpace(firstName) || string.IsNullOrWhiteSpace(lastName) || string.IsNullOrWhiteSpace(information))
            {
                ErrorHandling.Show_Inserting_Error();
            }
            else
            {
                DatabaseInfo data = LazyData.Value;
                //data.Myevent += delegate (object ) { }
                var  connection = data.GetConfigInfo();
                User user       = new User(firstName, lastName, information);


                WebService.WebService service = new WebService.WebService();
                //service.InsertRow(user, connection);
                data.InsertRow(user, connection);// Inesrt row to table
                var Users = new List <User> {
                };
                //service.GetDataFromDatabase(Users, connection);
                data.GetDataFromDatabase(Users, connection);// Read information to Collectionion
                UsersInfo userPhoto   = new UsersInfo(firstName, lastName, text);
                var       UsersPhotos = new List <UsersInfo> {
                };
                data.GetDataFromDatabase(Users, connection);        // Read photo information to Collection
                var OrderedUsers = Users.OrderBy(p => p.FirstName); // Linq ordering by name ascending
                //var JoinedUsers = data.GroupJoinCollections(Users, UsersPhotos);
                var JoinedUsers = from p in OrderedUsers
                                  join c in UsersPhotos
                                  on p.FirstName equals c.FirstName
                                  select new
                {
                    PersonName    = p.FirstName,
                    PersonSurname = c.LastName,
                    PersonInfo    = p.Information,
                    PersonPhoto   = c.Text
                };


                NameText.Text        = String.Empty;
                SurnameText.Text     = String.Empty;
                InformationText.Text = String.Empty;
                ImageView.Image      = null;
                icon1.Image          = null;
                icon2.Image          = null;
            }
        }