Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Session.Abandon();
            string key = Response.Cookies["OpenPasteLogin"].Value;
            Response.Cookies["OpenPasteLogin"].Expires = DateTime.MinValue;
            Response.Redirect("Pastes.aspx");

            using (var ctx = new Models.DatabaseContext())
            {
                Models.LoggedByCookie lbc = (from logging in ctx.LoggedUsers where logging.session_id == key select logging).First();
                ctx.LoggedUsers.Remove(lbc);
                ctx.SaveChanges();
            }
        }
Exemplo n.º 2
0
        private void SaveButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.User user =
                    databaseContext.Users
                    .Where(current => string.Compare(current.Username, Username, true) == 0)
                    .FirstOrDefault();

                if (user == null)
                {
                    Dtx.Windows.Forms.MessageBox.ShowError("اطلاعات این کاربر حذف شده است!");
                    Close();
                }

                user.FullName    = fullNameTextBox.Text;
                user.Description = descriptionTextBox.Text;

                user.IsActive        = isActiveCheckBox.Checked;
                user.IsAdministrator = isAdministratorCheckBox.Checked;

                databaseContext.SaveChanges();

                Dtx.Windows.Forms.MessageBox.ShowInformation("اطلاعات شما با موفقیت ذخیره گردید.");

                // **************************************************
                MyUserListForm.Search();
                Program.AuthenticatedUser = user;
                Program.MainForm.Initialize();
                // **************************************************
            }
            catch (System.Exception ex)
            {
                Dtx.Windows.Forms.MessageBox.ShowError(ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
        private void DisplayResourceForm_Load(object sender, System.EventArgs e)
        {
            typeComboBox.DataSource =
                System.Enum.GetValues(typeof(Models.Enums.ResourceType));

            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.Resource resource =
                    databaseContext.Resources
                    .Where(current => current.Id == Id)
                    .FirstOrDefault();

                if (resource == null)
                {
                    System.Windows.Forms.MessageBox.Show("There is not resource any more!");
                    Close();
                }

                resource.VisitCount++;

                databaseContext.SaveChanges();

                titleTextBox.Text       = resource.Title;
                authorTextBox.Text      = resource.Author;
                translatorTextBox.Text  = resource.Translator;
                descriptionTextBox.Text = resource.Description;
                publishYearTextBox.Text = resource.PublishYear.ToString();

                //typeComboBox.SelectedText = resource.Type.ToString();
                typeComboBox.SelectedItem = (Models.Enums.ResourceType)resource.Type;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show($"Error: { ex.Message }");
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    //databaseContext = null;
                }
            }
        }
Exemplo n.º 4
0
        private void loginButton_click(object sender, EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;
            try
            {
                databaseContext = new Models.DatabaseContext();
                Models.User foundeduser = databaseContext.Users.Where(current => string.Compare(current.Username, usernameTextBox.Text, true) == 0).FirstOrDefault();

                if (foundeduser == null)
                {
                    System.Windows.Forms.MessageBox.Show("your username or password is wrong!");
                    usernameTextBox.Focus();
                    return;
                }
                if (string.Compare(foundeduser.Password, passwordTextBox.Text, ignoreCase: false) != 0)
                {
                    System.Windows.Forms.MessageBox.Show("your username or password is wrong!");
                    usernameTextBox.Focus();
                    return;
                }
                if (foundeduser.IsActive == false)
                {
                    System.Windows.Forms.MessageBox.Show("You can not Login to This Application");
                    usernameTextBox.Focus();
                    return;
                }
                System.Windows.Forms.MessageBox.Show("Welcome!");

                Infrastructure.Utility.AuthenticatedUser = foundeduser;
                Hide();
                MainForm mainForm = new MainForm();
                mainForm.Show();
                //foundeduser = new Models.User();
                //foundeduser.Username = usernameTextBox.Text;
                //foundeduser.Password = passwordTextBox.Text;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error:", ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 5
0
        private void RegistrationButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext oDatabaseContext = null;


            try
            {
                oDatabaseContext =
                    new Models.DatabaseContext();

                Models.Task oTask =
                    new Models.Task();


                oTask.TaskTitle = TitleTextBox.Text;

                oTask.TaskDescription = DescriptionTextBox.Text;
                oTask.ImportanceLevel = ImportanceComboBox.Text;
                oTask.Date            = dateTimePicker1.Text;



                oDatabaseContext.Tasks.Add(oTask);

                oDatabaseContext.SaveChanges();


                System.Windows.Forms.MessageBox.Show("کار جدید مورد نظر شما اضافه گردید.");

                TitleTextBox.Text       = string.Empty;
                DescriptionTextBox.Text = string.Empty;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                if (oDatabaseContext != null)
                {
                    oDatabaseContext.Dispose();
                    oDatabaseContext = null;
                    Main oMian = new Main();
                    oMian.Show();
                }
            }
        }
Exemplo n.º 6
0
        private void saveButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.User foundedUser =
                    databaseContext.Users
                    .Where(current => current.Id == SelectedUser.Id)
                    //.Where(current => current.Id == SelectedUserId)
                    .FirstOrDefault();

                if (foundedUser == null)
                {
                    System.Windows.Forms.MessageBox.Show("There is no such a user anymore!");

                    Close();
                }

                foundedUser.IsAdmin  = isAdminCheckBox.Checked;
                foundedUser.IsActive = isActiveCheckBox.Checked;

                foundedUser.FullName    = fullNameTextBox.Text;
                foundedUser.Description = descriptionTextBox.Text;

                databaseContext.SaveChanges();

                Close();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                Close();
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 7
0
        private void registerBook_Click(object sender, EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;
            try
            {
                databaseContext = new Models.DatabaseContext();
                Models.Book book =
                    databaseContext.Books
                    .Where(current => string.Compare(current.ISBN, isbnTextBox.Text, true) == 0)
                    .FirstOrDefault();

                if (book != null)
                {
                    System.Windows.Forms.MessageBox.Show
                        ("This book is already exist! Please choose another one...");
                    isbnTextBox.Focus();

                    return;
                }
                book                 = new Models.Book();
                book.ISBN            = isbnTextBox.Text;
                book.AuthorName      = authorNameTextBox.Text;
                book.Title           = titleTextBox.Text;
                book.PublicationDate = DateTime.Now;

                Image temp = new Bitmap(strFilePath);
                System.IO.MemoryStream strm = new System.IO.MemoryStream();
                temp.Save(strm, System.Drawing.Imaging.ImageFormat.Jpeg);
                imageByteArray = strm.ToArray();

                book.ImageByteArray = imageByteArray;


                databaseContext.Books.Add(book);
                databaseContext.SaveChanges();


                System.Windows.Forms.MessageBox.Show("Registration Done!");
                Close();
            }
            catch (Exception)

            {
                throw;
            }
        }
Exemplo n.º 8
0
        private void deleteBooksButton_Click(object sender, EventArgs e)
        {
            if (booksListbox.SelectedItems.Count == 0)
            {
                System.Windows.Forms.MessageBox.Show("You did not select any book for deleting!");

                return;
            }

            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                foreach (var selectedItem in booksListbox.SelectedItems)
                {
                    Models.Book selectedBook = selectedItem as Models.Book;

                    if (selectedBook != null)
                    {
                        databaseContext.Entry(selectedBook).State = System.Data.Entity.EntityState.Deleted;

                        // Note: Does Not Work!
                        //databaseContext.Users.Remove(selectedUser);

                        databaseContext.SaveChanges();
                    }
                }

                SearchBook();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 9
0
        private void UpdateBooksForm_Load(object sender, EventArgs e)
        {
            Models.DatabaseContext databaseContext = new Models.DatabaseContext();

            try
            {
                Models.Book foundedBook = databaseContext.Books
                                          .Where(current => current.Id == SelectedBook.Id)
                                          .FirstOrDefault();

                if (foundedBook == null)
                {
                    System.Windows.Forms.MessageBox.Show("There is no such a book anymore");
                    Close();
                }

                authorNameTextBox.Text = foundedBook.AuthorName;
                titleTextBox.Text      = foundedBook.Title;
                isbnTextBox.Text       = foundedBook.ISBN;

                byte[] ImageArray = (byte[])foundedBook.ImageByteArray;
                if (ImageArray.Length == 0)
                {
                    booksPictureBox.Image = defaultImage;
                }
                else
                {
                    booksPictureBox.Image = Image.FromStream(new System.IO.MemoryStream(ImageArray));
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                Close();
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 10
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.Book foundedBook =
                    databaseContext.Books
                    .Where(current => current.Id == SelectedBook.Id)

                    .FirstOrDefault();

                if (foundedBook == null)
                {
                    System.Windows.Forms.MessageBox.Show("There is no such a user anymore!");

                    Close();
                }

                foundedBook.IsActive = activeCheckBox.Checked;

                foundedBook.BookName = bookNameTextbox.Text;

                databaseContext.SaveChanges();

                Close();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);

                Close();
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
        public void Search()
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext = new Models.DatabaseContext();

                System.Collections.Generic.List <Models.User> user = null;

                string fullName;
                fullName = fullNameTextBox.Text;

                fullName = fullName.Trim();

                while (fullName.Contains("  "))
                {
                    fullName.Replace("  ", " ");
                }

                user = databaseContext.Users
                       .Where(current => current.FullName.Contains(fullName))
                       .OrderBy(current => current.FullName)
                       .ToList()
                ;

                userListBox.ValueMember = nameof(Models.User.Id);

                userListBox.DisplayMember = "DisplayName";

                userListBox.DataSource = user;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
		internal BaseRepository(Models.DatabaseContext databaseContext) : base()
		{
			// **************************************************
			//if (databaseContext == null)
			//{
			//	throw new System.ArgumentNullException(paramName: "databaseContext");
			//}

			//DatabaseContext = databaseContext;
			// **************************************************

			// **************************************************
			DatabaseContext =
				databaseContext ?? throw new System.ArgumentNullException(paramName: "databaseContext");
			// **************************************************

			DbSet = DatabaseContext.Set<T>();
		}
Exemplo n.º 13
0
        private void saveButton_Click(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.User currentUser =
                    databaseContext.Users
                    .Where(current => current.Id == Infrastructure.Utility.AuthenticatedUser.Id)
                    .FirstOrDefault();

                if (currentUser == null)
                {
                    System.Windows.Forms.Application.Exit();
                }

                currentUser.FullName    = fullNameTextBox.Text;
                currentUser.Description = descriptionTextBox.Text;

                databaseContext.SaveChanges();

                Infrastructure.Utility.AuthenticatedUser = currentUser;

                ((MainForm)this.MdiParent).UpdateWelcomeToolStripStatusLabel();

                System.Windows.Forms.MessageBox
                .Show("Your profile was updated successfully...");
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error: " + ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 14
0
 private void MainForm_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
 {
     if (IsHidden == true)
     {
         return;
     }
     System.Windows.Forms.DialogResult result = System.Windows.Forms.DialogResult.None;
     if (RightToLeft == System.Windows.Forms.RightToLeft.No)
     {
         result =
             System.Windows.Forms.MessageBox.Show(text: Resources.MainForm.FormClosingMessage,
                                                  caption: Resources.MainForm.FormClosingMessageCaption,
                                                  buttons: System.Windows.Forms.MessageBoxButtons.YesNo,
                                                  icon: System.Windows.Forms.MessageBoxIcon.Question,
                                                  defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2);
     }
     if (RightToLeft == System.Windows.Forms.RightToLeft.Yes)
     {
         result =
             System.Windows.Forms.MessageBox.Show(text: Resources.MainForm.FormClosingMessage,
                                                  caption: Resources.MainForm.FormClosingMessageCaption,
                                                  buttons: System.Windows.Forms.MessageBoxButtons.YesNo,
                                                  icon: System.Windows.Forms.MessageBoxIcon.Question,
                                                  defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2,
                                                  options: System.Windows.Forms.MessageBoxOptions.RightAlign
                                                  | System.Windows.Forms.MessageBoxOptions.RtlReading);
     }
     if (result == System.Windows.Forms.DialogResult.Yes)
     {
         this.FormClosing -= MainForm_FormClosing;
         if (databaseContext != null)
         {
             databaseContext.Dispose();
             databaseContext = null;
         }
         System.Windows.Forms.Application.Exit();
         return;
     }
     else
     {
         e.Cancel = true;
         return;
     }
 }
Exemplo n.º 15
0
        //public System.Guid SelectedUserId { get; set; }

        private void UpdateUserForm_Load(object sender, System.EventArgs e)
        {
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                Models.User foundedUser =
                    databaseContext.Users
                    .Where(current => current.Id == SelectedUser.Id)
                    //.Where(current => current.Id == SelectedUserId)
                    .FirstOrDefault();

                if (foundedUser == null)
                {
                    System.Windows.Forms.MessageBox.Show("There is no such a user anymore!");

                    Close();
                }

                isAdminCheckBox.Checked  = foundedUser.IsAdmin;
                isActiveCheckBox.Checked = foundedUser.IsActive;

                fullNameTextBox.Text    = foundedUser.FullName;
                descriptionTextBox.Text = foundedUser.Description;
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show($"Error: { ex.Message }");

                Close();
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 16
0
        //-----

        #region AdminUser
        public static void AdminUser()
        {
            Models.DatabaseContext databaseContext = null;
            try
            {
                databaseContext =
                    new Models.DatabaseContext();

                string username = "******";

                Models.User adminUser =
                    databaseContext.Users
                    .Where(current => string.Compare(current.Username, username, true) == 0)
                    .FirstOrDefault();

                if (adminUser == null)
                {
                    adminUser = new Models.User
                    {
                        Username = username,
                        Email    = "*****@*****.**",
                        Password = "******",
                    };

                    databaseContext.Users.Add(adminUser);
                }

                databaseContext.SaveChanges();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                    databaseContext = null;
                }
            }
        }
Exemplo n.º 17
0
        private void updateButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(fullnameTextBox.Text) || string.IsNullOrWhiteSpace(descriptionTextBox.Text))
            {
            }
            Models.DatabaseContext databaseContext = null;

            try
            {
                databaseContext = new Models.DatabaseContext();

                Models.User user = databaseContext.Users
                                   .Find(Infrastructure.Utility.AuthenticatedUser.Id);
                if (user == null)
                {
                    System.Windows.Forms.MessageBox.Show("خطایی رخ داده است با مدیر سیستم تماس بگیرید");
                }
                else
                {
                    user.FullName    = fullnameTextBox.Text;
                    user.Description = descriptionTextBox.Text;
                    databaseContext.Entry(user).State = System.Data.Entity.EntityState.Modified;
                    databaseContext.SaveChanges();

                    Infrastructure.Utility.AuthenticatedUser = user;
                    ResetForm();
                    System.Windows.Forms.MessageBox.Show("اطلاعات با موفقیت ویرایش شد ");
                }
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("خطایی رخ داده است با مدیر سیستم تماس بگیرید"
                                                     + Environment.NewLine + ex.Message);
            }
            finally
            {
                if (databaseContext != null)
                {
                    databaseContext.Dispose();
                }
            }
        }
Exemplo n.º 18
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            PageSize  = 10;
            PageIndex = 0;

            try
            {
                MyDatabaseContext =
                    new Models.DatabaseContext();

                DisplayCountries();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
            }
            finally
            {
            }
        }
Exemplo n.º 19
0
 private void DisplayUsers(string Name, bool wantAdmin, bool wantDeactive)
 {
     Models.DatabaseContext databaseContext = null;
     try
     {
         databaseContext = new Models.DatabaseContext();
         var data = databaseContext.Users
                    .Where(current => current.Username.ToLower().Contains(Name.ToLower()) == true ||
                           current.FullName.FirstName.ToLower().Contains(Name.ToLower()) == true ||
                           current.FullName.LastName.ToLower().Contains(Name.ToLower()))
                    .OrderBy(current => current.Username)
                    .AsQueryable();
         if (wantAdmin == true)
         {
             data = data.Where(current => current.IsAdmin == true)
                    .OrderBy(current => current.Username);
         }
         if (wantDeactive == true)
         {
             data = data.Where(current => current.IsActive == false)
                    .OrderBy(current => current.Username);
         }
         var Users = data.ToList();
         displayUsersListbox.DataSource    = Users;
         displayUsersListbox.DisplayMember = nameof(Models.User.DisplayListName);
         displayUsersListbox.ValueMember   = nameof(Models.User.Username);
     }
     catch (System.Exception ex)
     {
         System.Windows.Forms.MessageBox.Show($"Unexpected Error:{ex.Message}",
                                              caption: "ERROR", buttons: System.Windows.Forms.MessageBoxButtons.OK,
                                              icon: System.Windows.Forms.MessageBoxIcon.Error);
     }
     finally
     {
         if (databaseContext != null)
         {
             databaseContext.Dispose();
         }
     }
 }
Exemplo n.º 20
0
 public ActionResult RegistreringsResultat()
 {
     var db = new Models.DatabaseContext();
     List<Models.dbKunde> listeAvKunder = db.Kunder.ToList();
     return View(listeAvKunder);
 }
Exemplo n.º 21
0
        public ActionResult NyKunde(FormCollection innListe)
        {
            if (ModelState.IsValid)
            {
                /*
                return "Fornavn: " + innListe["Fornavn"] + "\nEtternavn: " + innListe["Etternavn"] + "\nAdresse: " + innListe["Adresse"] +
                     "\nTelefonnr: " + innListe["Telefonnummer"] + "\nEpost: " + innListe["Epost"] + "\nPassord: " + innListe["Passord"] +
                     "\nPoststed: " + innListe["Poststed"] + "\nPostnr: " + innListe["Postnummer"];
                */
               // Console.WriteLine("In the mucK");
                try
                {
                    using (var db = new Models.DatabaseContext())
                    {
                        Session["Bruker"] = null;
                        Session["LoggetInn"] = false;
                        var nyKunde = new Models.dbKunde();
                        nyKunde.Fornavn = innListe["Fornavn"];
                        nyKunde.Etternavn = innListe["Etternavn"];
                        nyKunde.Adresse = innListe["Adresse"];
                        nyKunde.Telefonnummer = int.Parse(innListe["Telefonnummer"]);
                        nyKunde.Epost = innListe["Epost"];
                        if (innListe["Passord"].Equals(innListe["PassordKopi"]))
                        {
                            nyKunde.Passord = (Logikk.hashPword(innListe["Passord"]));
                        }

                          //Kan ikke bruke dette array i LINQ nedenfor
                          string innPostNr = innListe["Postnummer"];
                          var funnetPoststed = db.Poststeder
                              .FirstOrDefault(p => p.Postnummer == innPostNr);
                          if (funnetPoststed == null) //fant ikke poststed, må legge inn et nytt
                          {
                              var nyttPoststed = new Models.dbPoststed();
                              nyttPoststed.Postnummer = innListe["Postnummer"];
                              nyttPoststed.Poststed = innListe["Poststed"];
                              db.Poststeder.Add(nyttPoststed);
                              //det nye poststedet legges i den nye brukeren
                              nyKunde.Poststed = nyttPoststed;
                          }
                          else
                          {
                              //fant poststedet, legger det inn på bruker
                              nyKunde.Poststed = funnetPoststed;
                          }
                        var exist = db.Kunder
                            .FirstOrDefault(k => k.Epost == nyKunde.Epost);
                        if (exist == null)
                        {
                            db.Kunder.Add(nyKunde);

                            Session["Bruker"] = nyKunde;
                            db.SaveChanges();
                        }
                        else if(funnetPoststed== null)
                        {
                            db.SaveChanges();
                        }

                        return RedirectToAction("RegistreringsResultat");

                    }
                }
                catch (Exception feil)
                {
                return View();
                }
            }
            else return View();
        }