Ejemplo n.º 1
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            using (var context = new BookLotEntities())
            {
                try
                {
                    int   bookId        = Int32.Parse(txtBookId.Text);
                    Books booksToUpdate = context.BookCategories.Find(bookId);
                    if (booksToUpdate != null)
                    {
                        booksToUpdate.BookId          = Int32.Parse(txtBookId.Text);
                        booksToUpdate.AuthorId        = Int32.Parse(txtAuthorId.Text);
                        booksToUpdate.PublisherId     = Int32.Parse(txtAuthorId.Text);
                        booksToUpdate.Title           = txtTitle.Text;
                        booksToUpdate.ISBN            = txtISBN.Text;
                        booksToUpdate.Genre           = txtGenre.Text;
                        booksToUpdate.Type            = txtType.Text;
                        booksToUpdate.PublicationYear = txtPubYear.Text;
                        booksToUpdate.Price           = Int32.Parse(txtPrice.Text);

                        booksToUpdate.Condition = txtCondition.Text;
                        context.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Empty format, try again");
                }
            }
        }
Ejemplo n.º 2
0
        public bool Register(User buf)
        {
            BookLotEntities context = new BookLotEntities();

            var user = context.Users.FirstOrDefault(item => item.Login == buf.Login);

            if (user != null)
            {
                return(false);
            }
            //else
            //{
            //    if (buf.Photo != null && buf.PhotoName != null)
            //    {
            //        FtpWebRequest requestFind = (FtpWebRequest)WebRequest.Create(localpath);
            //        requestFind.Method = WebRequestMethods.Ftp.ListDirectory;
            //        requestFind.Credentials = new NetworkCredential("OlegKret", "26021982OlegKret");

            //        FtpWebResponse responseFind = (FtpWebResponse)requestFind.GetResponse();
            //        Stream streamFind = responseFind.GetResponseStream();
            //        StreamReader readerFind = new StreamReader(streamFind);

            //        string files = readerFind.ReadToEnd();

            //        readerFind.Close();
            //        streamFind.Close();
            //        responseFind.Close();

            //        if (files.Contains(buf.PhotoName))
            //        {
            //            return false;
            //        }
            //        else
            //        {
            //            FtpWebRequest requestCreate = (FtpWebRequest)WebRequest.Create(localpath + buf.PhotoName);
            //            requestCreate.Method = WebRequestMethods.Ftp.UploadFile;
            //            requestCreate.Credentials = new NetworkCredential("OlegKret", "26021982OlegKret");

            //            Stream streamCreate = requestCreate.GetRequestStream();
            //            streamCreate.Write(buf.Photo, 0, buf.Photo.Length);
            //            streamCreate.Close();

            //            FtpWebResponse responseCreate = (FtpWebResponse)requestCreate.GetResponse();
            //            responseCreate.Close();
            //        }
            //    }

            context.Users.Add(buf);

            context.SaveChanges();

            return(true);
        }
Ejemplo n.º 3
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int userId = Int32.Parse(txtId.Text);

            using (var context = new BookLotEntities())
            {
                User userToDelete = new User()
                {
                    Id = userId
                };
                AccountClient accountClient = new AccountClient();
                accountClient.Delete(userToDelete);
            }
        }
Ejemplo n.º 4
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int bookId = Int32.Parse(txtBookId.Text);

            using (var context = new BookLotEntities())
            {
                Books booksToDelete = new Books()
                {
                    BookId = bookId
                };
                context.Entry(booksToDelete).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
Ejemplo n.º 5
0
        private Boolean checkEmail()
        {
            using (var context = new BookLotEntities())
            {
                Boolean emailavailable = false;

                int userid = (from x in context.Users
                              where x.Email == txtPhoneNumber.Text
                              select x.Id).SingleOrDefault();
                if (userid > 0)
                {
                    emailavailable = true;
                }
                return(emailavailable);
            }
        }
Ejemplo n.º 6
0
        private Boolean checkLogin()
        {
            using (var context = new BookLotEntities())
            {
                Boolean loginavailable = false;

                int userid = (from x in context.Users
                              where x.Login == txt_Login.Text
                              select x.Id).SingleOrDefault();
                if (userid > 0)
                {
                    loginavailable = true;
                }
                return(loginavailable);
            }
        }
Ejemplo n.º 7
0
        //string localpath = "ftp://OlegKret.somee.com/www.OlegKret.somee.com/WCFServiceBooks/App_Data/Users/Photo/";

        public User Login(string login, string password)
        {
            BookLotEntities context = new BookLotEntities();

            var user = context.Users.FirstOrDefault(item => item.Login == login);

            if (user != null && user.Password == password)
            {
                // System.IO.File.ReadAllBytes(Properties.Settings.Default.localPath + user.PhotoName);

                return(user);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 8
0
        private void Form1_Load(object sender, EventArgs e)
        {
            label11.Text = "You login as :" + ((Form)this.MdiParent).Controls["label1"].Text;
            if (((Form)this.MdiParent).Controls["label1"].Text != "Admin")
            {
                btnClear.Enabled  = false;
                btnSave.Enabled   = false;
                btnDelete.Enabled = false;

                btnUpdate.Enabled = false;
            }
            using (var context = new BookLotEntities())
            {
                //foreach (Books c in context.Books)
                //{
                //    cboBooks.Items.Add(c.Title);

                //}

                var source = context.BookCategories.ToList();
                cboBooks.DataSource = source;
                //cboBooks.BindingContext=this.BindingContext();
                cboBooks.ValueMember   = "BookId";
                cboBooks.DisplayMember = "Title";

                //cboBooks.DisplayMember = "Genre";
                cboBooks.Invalidate();
                cboBooks.DataBindings.Clear();
                //cboBooks.SelectedValueChanged += new EventHandler(cboBooks_SelectedValueChanged);
                txtAuthorId.DataBindings.Add("Text", source, "AuthorId", true);

                txtPublisherId.DataBindings.Add("Text", source, "PublisherId", true);
                txtTitle.DataBindings.Add("Text", source, "Title", true);
                txtISBN.DataBindings.Add("Text", source, "ISBN", true);
                txtBookId.DataBindings.Add("Text", source, "BookID");
                txtGenre.DataBindings.Add("Text", source, "Genre", true);
                txtType.DataBindings.Add("Text", source, "Type", true);

                txtPubYear.DataBindings.Add("Text", source, "PublicationYear");
                txtPrice.DataBindings.Add("Text", source, "Price", true);

                txtCondition.DataBindings.Add("Text", source, "Condition", true);
            }
        }
Ejemplo n.º 9
0
        private void Login_Load(object sender, EventArgs e)
        {
            using (var context = new BookLotEntities())
            {
                var source = context.Users.ToList();
                cboUsers.DataSource    = source;
                cboUsers.ValueMember   = "Id";
                cboUsers.DisplayMember = "Login";

                cboUsers.Invalidate();
                cboUsers.DataBindings.Clear();
                txtId.DataBindings.Add("Text", source, "Id", true);

                txt_Login.DataBindings.Add("Text", source, "Login", true);
                txtLogin.DataBindings.Add("Text", source, "Login", true);
                txt_Password.DataBindings.Add("Text", source, "Password", true);
                txtEmail.DataBindings.Add("Text", source, "Email", true);
                txtPassword.DataBindings.Add("Text", source, "Password");
                txtRole.DataBindings.Add("Text", source, "role");
                txtPhoneNumber.DataBindings.Add("Text", source, "PhoneNumber");
                txtPic.DataBindings.Add("Text", source, "Pic");
                this.pictureBox1.DataBindings.Add(new System.Windows.Forms.Binding("Image", source, "Image", true));
            }
        }
Ejemplo n.º 10
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            using (var context = new BookLotEntities())
            {
                try
                {
                    int  userId       = Int32.Parse(txtId.Text);
                    User userToUpdate = context.Users.Find(userId);
                    if (userToUpdate != null)
                    {
                        AccountClient accountClient = new AccountClient();
                        string        remoteUri     = "ftp://olegkret.somee.com/www.OlegKret.somee.com/BOOOOK/App_Data/Users/Photo/" + txtPic.Text;
                        WebClient     webClient     = new WebClient();

                        webClient.Credentials = new NetworkCredential("OlegKret", "26021982OlegKret");
                        MessageBox.Show("Downloading " + remoteUri);
                        byte[] myDataBuffer = webClient.DownloadData(remoteUri);
                        userToUpdate.Id          = Int32.Parse(txtId.Text);
                        userToUpdate.Login       = txt_Login.Text;
                        userToUpdate.Password    = txt_Password.Text;
                        userToUpdate.Email       = txtEmail.Text;
                        userToUpdate.PhoneNumber = txtPhoneNumber.Text;
                        userToUpdate.role        = txtRole.Text;
                        userToUpdate.Pic         = txtPic.Text;
                        userToUpdate.Image       = myDataBuffer;
                        accountClient.Save(userToUpdate);
                        //context.SaveChanges();
                        accountClient.Close();
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Empty format, try again");
                }
            }
        }
Ejemplo n.º 11
0
        //private void btnEnter_Click(object sender, EventArgs e)
        //{
        //    try
        //    {
        //        if (txtLogin.Text == "")
        //        {
        //            throw new EmptyLoginException("Введіть логін!");
        //        }
        //        if (txtPassword.Text == "")
        //        {
        //            throw new EmptyPasswordException("Введіть пароль!");
        //        }

        //        AccountClient accountClient = new AccountClient();
        //        User input = accountClient.Login(txtLogin.Text, txtPassword.Text);

        //        if (input != null)
        //        {
        //            MessageBox.Show("Вхід успішний!");

        //            //if (input.PhotoName != null)
        //            //{
        //            //    Form2 form2 = new Form2(accountClient.GetImage(input.PhotoName));
        //            //    form2.ShowDialog();
        //            //}
        //            //else
        //            //{
        //            //    Form2 form2 = new Form2(null);
        //            //    form2.ShowDialog();
        //            //}

        //        }
        //        if (input == null)
        //        {
        //            MessageBox.Show("Ви НЕ ввійшли в особистий кабінет! \n Перевірте логін і пароль!");
        //        }

        //        accountClient.Close();
        //    }
        //    catch (EmptyLoginException emptyLoginException)
        //    {
        //        MessageBox.Show(emptyLoginException.Message);
        //    }
        //    catch (EmptyPasswordException emptyPasswordException)
        //    {
        //        MessageBox.Show(emptyPasswordException.Message);
        //    }
        //    catch (Exception exception)
        //    {
        //        MessageBox.Show(exception.Message);
        //    }
        //}

        private void btnSave_Click(object sender, EventArgs e)
        {
            //Service1Client client = new Service1Client();

            Books books = new Books();

            //client.Add(books);
            //client.Save(books);
            books.AuthorId        = Int32.Parse(txtAuthorId.Text);
            books.PublisherId     = Int32.Parse(txtPublisherId.Text);
            books.Title           = txtTitle.Text;
            books.ISBN            = txtISBN.Text;
            books.Genre           = txtGenre.Text;
            books.Type            = txtType.Text;
            books.PublicationYear = txtPubYear.Text;
            books.Price           = Int32.Parse(txtPrice.Text);

            books.Condition = txtCondition.Text;

            BookLotEntities lotEntities = new BookLotEntities();

            lotEntities.BookCategories.Add(books);
            lotEntities.SaveChanges();
        }