//-----End of the code. #region Methods //----- #region UserLoader public void UserLoader() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.User> users = null; users = dataBaseContext.Users .OrderBy(current => current.FullName) .ToList(); userDataGridView.DataSource = users; //userDataGridView.AutoResizeColumns // (autoSizeColumnsMode: System.Windows.Forms.DataGridViewAutoSizeColumnsMode.AllCells); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//-----End of coding line #region Founction //----- #region TemporaryClientLoaded private void TemporaryClientLoaded() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.TemporaryClient> temporaryClients = null; temporaryClients = dataBaseContext.TemporaryClients .OrderBy(current => current.Full_Name) .ToList(); temporaryClientDataGridView.DataSource = temporaryClients; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void RefreshData() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.User> users = null; users = dataBaseContext.Users .OrderBy(currnet => currnet.First_Name) .ToList(); userListDataGridView.DataSource = users; } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//-----End of the code. #region Method //----- #region LoginControlLoaded public void LoginControlLoaded() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.LogHistory> logHistories = null; logHistories = dataBaseContext.LogHistories .OrderByDescending(current => current.LoginTime) .ToList(); loginDataGridView.DataSource = logHistories; } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
public void DessertLoader() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.DessertAndAppetizer> desserts = null; desserts = dataBaseContext.DessertAndAppetizers .OrderBy(current => current.DessertName) .ToList(); dessertDataGridView.DataSource = desserts; } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void MainForm_Load(object sender, System.EventArgs e) { Models.DataBaseContext databaseContext = null; try { databaseContext = new Models.DataBaseContext(); Models.User user = new Models.User() { IsActive = true, Password = "******", UserName = "******", FullName = "Leila Jafari", EmailAddress = "*****@*****.**", }; databaseContext.Users.Add(user); databaseContext.SaveChanges(); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { if (databaseContext != null) { databaseContext.Dispose(); databaseContext = null; } } }
public void FoodLoader() { Models.DataBaseContext databaseContext = null; try { databaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.Food> foods = null; foods = databaseContext.Foods .OrderBy(current => current.FoodName) .ToList(); foodDataGridView.DataSource = foods; } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (databaseContext != null) { databaseContext.Dispose(); databaseContext = null; } } }
//-----End of coding line #region Founctions //----- #region UsersLoaded public void UsersLoaded() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.User> users = null; users = dataBaseContext.Users .OrderBy(currnet => currnet.Username) .ToList(); userListDataGridView.DataSource = users; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//-----End of coding line #region Founctions //----- #region FormLoad private void FormLoad() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.Hookah hookah = dataBaseContext.Hookahs .Where(current => string.Compare(current.HookahName, HookahName_FirstLoad, true) == 0) .FirstOrDefault(); HookahName = null; HookahName_New = null; hookahNameTextBox.Text = hookah.HookahName; HookahPrice = null; HookahName_New = null; HookahPrice_Int = 0; hookahPriceTextBox.Text = hookah.HookahPrice; HookahPrice_FirstLoad = hookah.HookahPrice; hookahPriceTextBox.ForeColor = Infrastructure.Utility.DimGrayColor(); hookahPricePanel.BackColor = Infrastructure.Utility.DimGrayColor(); HookahDescription = null; HookahDescription_New = null; hookahDescriptionTextBox.Text = hookah.HookahDescription; HookahDescription_FirstLoad = hookah.HookahDescription; hookahDescriptionTextBox.ForeColor = Infrastructure.Utility.DimGrayColor(); hookahDescriptionPanel.BackColor = Infrastructure.Utility.DimGrayColor(); HookahImage = null; HookahImage_New = null; Select_HookahImage = null; HookahImage_FirstLoad = hookah.HookahImage; var byteImage = hookah.HookahImage; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteImage)) { hookahImagePicturBox.Image = System.Drawing.Image.FromStream(ms); } } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void EditClientButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Windows.Forms.DialogResult dialogResult = Mbb.Windows.Forms.MessageBox.Show (text: "آیا برای انجام تغییر اطمینان دارید؟", caption: "دستور ویرایش", icon: Mbb.Windows.Forms.MessageBoxIcon.Question, button: Mbb.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.PermanentClient permanentClient = new Models.PermanentClient { Client_ID = ClientID_New, Full_Name = FullName_New, }; dataBaseContext.SaveChanges(); Infrastructure.Utility.WindowsNotification (message: "ویرایش انجام شد.", caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); #region EventLog Username = Program.AuthenticatedUser.Username; FullName = $"{Program.AuthenticatedUser.First_Name} {Program.AuthenticatedUser.Last_Name}"; EventDate = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}"; EventTime = $"{Infrastructure.Utility.ShowTime()}"; EventTitle = $"ویرایش کد {ClientID_FirstLoad} به {ClientID_New} و یا نام {FullName_FirstLoad} به {FullName_New}"; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
public UnitOfWork(Models.DataBaseContext dataBaseContext) { if (dataBaseContext == null) { dataBaseContext = new Models.DataBaseContext(); } this.dataBaseContext = dataBaseContext; }
protected override void Dispose(bool disposing) { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } base.Dispose(disposing); }
private void UpdatePassword() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); if (Infrastructure.Utility.PasswordSet(password: Password, passwordConfirm: PasswordConfirm) == false) { Mbb.Windows.Forms.MessageBox.Show (text: "عدم تطابق پسوردها", caption: "خطای ورودی", icon: Mbb.Windows.Forms.MessageBoxIcon.Error, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); passwordTextBox.Focus(); return; } System.Windows.Forms.DialogResult dialogResult = Mbb.Windows.Forms.MessageBox.Show (text: "از تغییر رمز اطمینان دارید؟", caption: "هشدار تغییر", icon: Mbb.Windows.Forms.MessageBoxIcon.Warning, button: Mbb.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.User user = dataBaseContext.Users .Where(current => string.Compare(current.Username, Username) == 0) .FirstOrDefault(); if (user != null) { user.Password = Password; } dataBaseContext.SaveChanges(); Mbb.Windows.Forms.MessageBox.Show (text: "رمز عبور با موفقیت تغییر یاقت.", caption: "تغییر رمز عبور", icon: Mbb.Windows.Forms.MessageBoxIcon.Success, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); } } catch (Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void UserSearch(string username) { if (string.Compare(username, "admin") == 0 || string.IsNullOrEmpty(username)) { return; } else { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.User user = dataBaseContext.Users .Where(current => string.Compare(current.Username, username) == 0) .FirstOrDefault(); if (user == null) { Infrastructure.Utility.WindowsNotification (message: "کاربر مورد نظر موجود نیست!", caption: Infrastructure.PopupNotificationForm.Caption.اخطار); return; } else { fullNameLabel.Text = user.FullName; usernameLabel.Text = user.Username; administratorCheckBox.Checked = user.IsAdministrator; activeCheckBox.Checked = user.IsActive; var byteImage = user.UserPicture; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteImage)) { userPicturBox.BackgroundImage = System.Drawing.Image.FromStream(ms); } } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } } }
private void SubscriptionCodeTextBox_TextChanged(object sender, System.EventArgs e) { if (string.Compare(subscriptionCodeTextBox.Text, "کد اشتراک") == 0) { return; } else { if (subscriptionCodeTextBox.Text.Length < 4) { clearButton.Visible = false; return; } else { clearButton.Visible = true; SubscriptionCode = int.Parse(subscriptionCodeTextBox.Text); Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.Client client = dataBaseContext.Clients .Where(current => string.Compare(current.SubscriptionCode.ToString(), SubscriptionCode.ToString()) == 0) .FirstOrDefault(); if (client == null) { Infrastructure.Utility.WindowsNotification (message: $" کد اشتراک {SubscriptionCode} موجود نیست!", caption: Infrastructure.PopupNotificationForm.Caption.خطا); } else { clientName.Text = client.ClientName; clientTel.Text = client.ClientTel; clientAddress.Text = client.ClientAddress; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } } } }
//-----End of coding line #region Founctions //----- #region FoodLoad private void FoodLoad() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.Food food = dataBaseContext.Foods .Where(current => string.Compare(current.FoodName, FoodName_FirstLoad, true) == 0) .FirstOrDefault(); FoodName = null; FoodDescription_New = null; foodNameTextBox.Text = food.FoodName; FoodPrice = null; FoodPrice_Int = 0; foodPriceTextBox.Text = food.FoodPrice; foodPriceTextBox.ForeColor = Infrastructure.Utility.BlackColor(); foodPricePanel.BackColor = Infrastructure.Utility.BlackColor(); FoodPrice_FirstLoad = food.FoodPrice; FoodDescription = null; foodDescriptionTextBox.Text = food.FoodDescription; foodDescriptionTextBox.ForeColor = Infrastructure.Utility.BlackColor(); foodDescriptionPanel.BackColor = Infrastructure.Utility.BlackColor(); FoodDescription_FirstLoad = food.FoodDescription; FoodImage = null; FoodImage_New = null; FoodImage_FirstLoad = food.FoodImage; var byteImage = food.FoodImage; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(byteImage)) { foodImagePicturBox.Image = System.Drawing.Image.FromStream(ms); } } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
public Repository(Models.DataBaseContext dataBaseContext) { if (dataBaseContext == null) { dataBaseContext = new Models.DataBaseContext(); } DataBaseContext = dataBaseContext; DbSet = DataBaseContext.Set <T>(); }
public Repository(Models.DataBaseContext databaseContext) { if (databaseContext == null) { throw (new System.ArgumentNullException("databaseContext")); } DatabaseContext = databaseContext; DbSet = DatabaseContext.Set <T>(); }
private void SaveLoginHistory(Models.User user) { LoginTime = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now).ToString()} " + $"{Infrastructure.Utility.ShowTime().ToString()}"; LogOutTime = $"Null"; string fullName; Models.DataBaseContext dataBaseContext = null; try { if (string.IsNullOrWhiteSpace(user.First_Name) && string.IsNullOrWhiteSpace(user.Last_Name)) { fullName = "Null"; } else { fullName = $"{user.First_Name} {user.First_Name}"; } dataBaseContext = new Models.DataBaseContext(); Models.LogHistory logHistory = dataBaseContext.LogHistories .OrderBy(current => current.LoginTime) .FirstOrDefault(); logHistory = new Models.LogHistory { FullName = fullName, Username = user.Username, UserPicture = user.User_Image, LoginTime = LoginTime, LogoutTime = LogOutTime, }; dataBaseContext.LogHistories.Add(logHistory); dataBaseContext.SaveChanges(); Program.AutenticatLogHistory = logHistory; } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } }
protected virtual void Dispose(bool disposing) { if (IsDisposed == false) { if (disposing) { _databaseContext.Dispose(); _databaseContext = null; } } IsDisposed = true; }
protected override void Dispose(bool disposing) { if (disposing) { if (_myDatabaseContext != null) { _myDatabaseContext.Dispose(); _myDatabaseContext = null; } } base.Dispose(disposing); }
//-----End of coding line #region Founctions //----- #region HookahFounded private void HookahFounded(string searchHooka) { if (searchHooka.Contains("جستجو کالا ...")) { return; } else { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.Hookah> hookah = null; if (string.IsNullOrEmpty(searchHooka)) { hookah = dataBaseContext.Hookahs .OrderBy(current => current.HookahName) .ToList(); } else { hookah = dataBaseContext.Hookahs .Where(current => current.HookahName.Contains(searchHooka)) .OrderBy(current => current.HookahName) .ToList(); } hookahStoreDataGridView.DataSource = hookah; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } } return; }
//-----End of coding line #region Founctions //----- #region FoodFounded private void FoodFounded(string searchDrink) { if (searchDrink.Contains("جستجو کالا ...")) { return; } else { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.Food> foods = null; if (string.IsNullOrEmpty(searchDrink)) { foods = dataBaseContext.Foods .OrderBy(current => current.FoodName) .ToList(); } else { foods = dataBaseContext.Foods .Where(current => current.FoodName.Contains(searchDrink)) .OrderBy(current => current.FoodName) .ToList(); } foodStoreDataGridView.DataSource = foods; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } } return; }
//----- #endregion /SearchTextBox #region DeleteTableButton_Click private void DeleteTableButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.LogHistory> logHistories = null; System.Windows.Forms.DialogResult dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage( text: "آیا گزارش پاک گردد؟", captiopn: "پاک کردن گزارش", 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 (dialogResult == System.Windows.Forms.DialogResult.Yes) { var rows = from o in dataBaseContext.LogHistories select o; foreach (var row in rows) { dataBaseContext.LogHistories.Remove(row); } dataBaseContext.SaveChanges(); LoginControlLoaded(); return; } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
protected override void Seed(NayanTraders.Models.DataBaseContext context) { Models.DataBaseContext db = new Models.DataBaseContext(); db.Countries.Add(new Models.Country() { Id = 1, Name = "Bangladesh" }); db.SaveChanges(); db.Cities.Add(new Models.City() { Id = 1, Name = "Bangladesh" }); db.SaveChanges(); }
public void LogHistoryLoaded() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.LogHistory> logHistories = null; logHistories = dataBaseContext.LogHistories .OrderByDescending(current => current.Logout_Time) .ToList(); loginControlDataGridView.DataSource = logHistories; if (loginControlDataGridView.Rows.Count <= 9) { userSearchTextBox.Enabled = false; printButton.Enabled = false; return; } if (loginControlDataGridView.Rows.Count >= 10 && loginControlDataGridView.Rows.Count < 15) { userSearchTextBox.Enabled = true; printButton.Enabled = false; return; } if (loginControlDataGridView.Rows.Count >= 15) { userSearchTextBox.Enabled = true; printButton.Enabled = true; return; } } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//----- #endregion / Methods #region UpdateButton_Click private void UpdateButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); if (string.Compare(usernameLabel.Text, "شناسه کاربری") == 0) { return; } Models.User user = dataBaseContext.Users .Where(current => string.Compare(current.Username, usernameLabel.Text) == 0) .FirstOrDefault(); if (user == null) { Infrastructure.Utility.WindowsNotification (message: "کاربر مورد نظر حذف گردیده!", caption: Infrastructure.PopupNotificationForm.Caption.اخطار); return; } user.IsAdministrator = administratorCheckBox.Checked; user.IsActive = activeCheckBox.Checked; dataBaseContext.SaveChanges(); Infrastructure.Utility.WindowsNotification (message: $" کاربر {usernameLabel.Text} به روز گردید", caption: Infrastructure.PopupNotificationForm.Caption.اطلاع); UserLoader(); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void NewCodeButton_Click(object sender, System.EventArgs e) { this.Size = new System.Drawing.Size(490, 225); errorMessageLabel.Visible = false; int number = RandomNumbers(); Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.Client client = dataBaseContext.Clients .Where(current => string.Compare(current.SubscriptionCode.ToString(), number.ToString()) == 0) .FirstOrDefault(); if (client != null) { checkPicturBox.Visible = true; checkPicturBox.Image = Resturant.Properties.Resources.Tik_False; return; } else { checkPicturBox.Visible = true; checkPicturBox.Image = Resturant.Properties.Resources.Tik_True; SubscriptionCode = number; subscriptionCodeLabel.Text = SubscriptionCode.ToString(); } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void ClientTelTextBox_Validated(object sender, System.EventArgs e) { if (string.IsNullOrEmpty(ClientTel)) { return; } else { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.Client client = dataBaseContext.Clients .Where(current => string.Compare(current.ClientTel, ClientTel) == 0) .FirstOrDefault(); if (client != null) { Infrastructure.Utility.WindowsNotification (message: $"تلفن {ClientTel} در سیستم موجود میباشد!", caption: Infrastructure.PopupNotificationForm.Caption.اخطار); ClientTel = string.Empty; return; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } } }
//-----End of coding line #region Founctions //----- #region UsernameSearch private void UsernameSearch(string text) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.LogHistory> logHistories = null; if (string.IsNullOrWhiteSpace(text)) { logHistories = dataBaseContext.LogHistories .OrderByDescending(current => current.Logout_Time) .ToList(); } else { logHistories = dataBaseContext.LogHistories .Where(current => current.Username.Contains(text)) .OrderByDescending(current => current.Logout_Time) .ToList(); } loginControlDataGridView.DataSource = logHistories; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } return; }