public ActionResult Create(string text) { Comment oComment = new Comment(); oComment.Text = text; oComment.PostID = PostID; db.Comments.Add(oComment); db.SaveChanges(); return(RedirectToAction("Index", new { PostID })); }
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(); }
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; } } }
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; } } }
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 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; } }
//----- #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; } } }
//----- #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 SaveLogOutTime(Models.LogHistory log) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.LogHistory logHistory = dataBaseContext.LogHistories .Where(curren => string.Compare(curren.Username, log.Username) == 0) .OrderByDescending(current => current.LoginTime) .SingleOrDefault(current => current.Id == log.Id); if (logHistory != null) { LogOutTime = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now).ToString()} " + $"{Infrastructure.Utility.ShowTime().ToString()}"; logHistory.LogoutTime = LogOutTime; } dataBaseContext.SaveChanges(); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void AllClearButton_Click(object sender, System.EventArgs e) { if (hookahStoreDataGridView.Rows.Count >= 1) { 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) //----جهت حذف کامل اطلاعات مربوط به نوشیدنی { List <Models.Hookah> hookahs = new List <Models.Hookah>(); using (Models.DataBaseContext dataBaseContext = new Models.DataBaseContext()) { hookahs = dataBaseContext.Hookahs .OrderBy(current => current.HookahName) .ToList(); if (hookahs != null) { foreach (var item in hookahs) //---توسط این کد با پیمایش در لیست نوشیدنی یکی یکی ایتمهای موجود در لیست نوشیدنی را حذف میکند. { dataBaseContext.Hookahs.Remove(item); dataBaseContext.SaveChanges(); } } else if (hookahs == null) { return; } #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 = $"حذف کامل اطلاعات قلیان."; Infrastructure.Utility.EventLog(username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog HookahLoader(); } Infrastructure.Utility.WindowsNotification (message: "کلیه اطلاعات قلیان حذف گردید!", caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); } } else { Mbb.Windows.Forms.MessageBox.Show (text: $"موردی برای حذف وجود ندارد!", caption: "اطلاع", icon: Mbb.Windows.Forms.MessageBoxIcon.Information, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); return; } }
private void DeleteRecordButton_Click(object sender, System.EventArgs e) { if (hookahStoreDataGridView.Rows.Count >= 1) { System.Windows.Forms.DialogResult dialogResult = Mbb.Windows.Forms.MessageBox.Show (text: $"{hookahStoreDataGridView.CurrentRow.Cells[0].Value} حذف گردد؟!", caption: "هشدار", icon: Mbb.Windows.Forms.MessageBoxIcon.Warning, button: Mbb.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) //----جهت حذف مشترک { string hookahName = hookahStoreDataGridView.CurrentRow.Cells[0].Value.ToString(); using (Models.DataBaseContext dataBaseContext = new Models.DataBaseContext()) { Models.Hookah hookah = dataBaseContext.Hookahs .Where(current => string.Compare(current.HookahName, hookahName) == 0) .FirstOrDefault(); if (hookah != null) { var entry = dataBaseContext.Entry(hookah); if (entry.State == EntityState.Detached) { dataBaseContext.Hookahs.Attach(hookah); } } #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 = $"{hookahName} حذف گردید."; Infrastructure.Utility.EventLog(username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog dataBaseContext.Hookahs.Remove(hookah); dataBaseContext.SaveChanges(); HookahLoader(); } Infrastructure.Utility.WindowsNotification (message: "کد مورد نظر حذف گردید!", caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); } } else { Mbb.Windows.Forms.MessageBox.Show (text: $"موردی برای حذف وجود ندارد!", caption: "اطلاع", icon: Mbb.Windows.Forms.MessageBoxIcon.Information, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); return; } }
//----- #endregion /ClientAddressTextBox #region SaveButton_Click private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); #region Validation //=============== int count = 0; string errorMessage = string.Empty; if (string.IsNullOrEmpty(SubscriptionCode.ToString()) || SubscriptionCode == 0) { errorMessage = "انتخاب کد اشتراک الزامی است!"; count++; } if (string.IsNullOrEmpty(ClientName)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد نام مشترک تکمیل گردد! "; count++; } if (string.IsNullOrEmpty(ClientTel)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد تلفن مشترک تکمیل گردد! "; count++; } if (string.IsNullOrEmpty(ClientAddress)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد آدرس مشترک تکمیل گردد! "; count++; } if (errorMessage != string.Empty) { if (count == 1) { this.Size = new System.Drawing.Size(490, 240); ErrorMessage(errorMessage); } else if (count == 2) { this.Size = new System.Drawing.Size(490, 260); ErrorMessage(errorMessage); } else if (count == 3) { this.Size = new System.Drawing.Size(490, 280); ErrorMessage(errorMessage); } else if (count == 4) { this.Size = new System.Drawing.Size(490, 300); ErrorMessage(errorMessage); } return; } //=================== #endregion /Validation System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: "مشترک مورد نظر ثبت گردد؟", captiopn: "ثبت مشتری", buttons: System.Windows.Forms.MessageBoxButtons.YesNo, defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2, icon: System.Windows.Forms.MessageBoxIcon.Question, options: System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Picture = string.Empty; Models.Client client = dataBaseContext.Clients .Where(current => string.Compare(current.ClientAddress, ClientAddress) == 0) .FirstOrDefault(); if (client != null) { newCodeButton.Focus(); return; } else { client = new Models.Client { SubscriptionCode = SubscriptionCode, ClientName = ClientName, ClientTel = ClientTel, ClientAddress = ClientAddress, OrderDate = OrderDate, }; dataBaseContext.Clients.Add(client); dataBaseContext.SaveChanges(); } } else { return; } string message = $"مشترک با کد اشتراک {SubscriptionCode} ثبت گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); if (Resturant.MainForm.ClientsListForm != null) { Resturant.MainForm.ClientsListForm.ClientLoader(); } AllClear(); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//----------Beginning of the code!---------- #region SaveButton_Click private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { if (string.IsNullOrWhiteSpace(firstNameTextBox.Text) || string.IsNullOrWhiteSpace(lastNameTextBox.Text) || string.IsNullOrWhiteSpace(addressTextBox.Text)) { System.Windows.Forms.MessageBox.Show("لطفا فیلد های نام و نام خانوادگی و آدرس را\n تکمیل نمایید!", caption: "", buttons: MessageBoxButtons.OK, icon: MessageBoxIcon.Error, defaultButton: MessageBoxDefaultButton.Button1, options: MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading); firstNameTextBox.Focus(); return; } dataBaseContext = new Models.DataBaseContext(); Models.User username = dataBaseContext.Users .Where(current => string.Compare(current.Address, addressTextBox.Text) == 0) .FirstOrDefault(); if (username != null) { System.Windows.Forms.MessageBox.Show("آدرس مورد نظر در سیستم موجود میباشد!\n لطفا از ادرس دیگری استفاده نمایید."); addressTextBox.Clear(); addressTextBox.Focus(); return; } else { username = new Models.User { First_Name = firstNameTextBox.Text, Last_Name = lastNameTextBox.Text, Address = addressTextBox.Text, }; dataBaseContext.Users.Add(username); dataBaseContext.SaveChanges(); RefreshData(); } string successMessage = $"اطلاعات کاربر {lastNameTextBox.Text} با موفقیت ذخیره گرید!"; System.Windows.Forms.MessageBox.Show(successMessage); ClearData(); } catch (System.Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void MyDataGridView_CellDoubleClick(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) { if (e.RowIndex == -1) { return; } if (e.ColumnIndex == -1) { return; } Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string selectedClient = myDataGridView.CurrentRow.Cells[0].Value.ToString(); Models.Client client = dataBaseContext.Clients .Where(current => string.Compare(current.SubscriptionCode.ToString(), selectedClient) == 0) .FirstOrDefault(); if (client != null) { string message = $"آیا کد {selectedClient} حذف گردد؟"; System.Windows.Forms.DialogResult dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: message, 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) { dataBaseContext.Clients.Remove(client); dataBaseContext.SaveChanges(); } else { return; } } ClientLoader(); Infrastructure.Utility.WindowsNotification (message: "مشترک حذف گردید!", caption: Infrastructure.PopupNotificationForm.Caption.اطلاع); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void UpdateDataHookahButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string hookaName = null; if (string.IsNullOrEmpty(HookahName_New)) { HookahName = HookahName_FirstLoad; } else { HookahName = HookahName_New; } if (string.IsNullOrEmpty(HookahPrice_New)) { HookahPrice = HookahPrice_FirstLoad; } else { HookahPrice = HookahPrice_New; } if (string.IsNullOrEmpty(HookahDescription_New)) { HookahDescription = HookahDescription_FirstLoad; } else { HookahDescription = HookahDescription_New; } if (string.IsNullOrEmpty(Select_HookahImage)) { HookahImage = HookahImage_FirstLoad; } else { HookahImage = HookahImage_New; } System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.Show (text: $"{HookahName} به روز گردد؟", caption: "به روز رسانی", icon: Mbb.Windows.Forms.MessageBoxIcon.Question, button: Mbb.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.Hookah hookah = dataBaseContext.Hookahs .Where(current => string.Compare(current.HookahName, HookahName_FirstLoad, false) == 0) .FirstOrDefault(); HookahNumberUpdate = hookah.NumberUpdate; HookahUpdateTime = $"{Infrastructure.Utility.ShowTime()} - {Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}"; HookahNumberUpdate++; hookah.HookahName = HookahName; hookah.HookahPrice = HookahPrice; hookah.HookahDescription = HookahDescription; hookah.HookahImage = HookahImage; hookah.UpdateTime = HookahUpdateTime; hookah.NumberUpdate = HookahNumberUpdate; dataBaseContext.SaveChanges(); //-----جهت بارگذاری اطلاعات قلیان در جدول داده if (HOOKAH_SALON.MainForm.HookahStoreForm != null) { HOOKAH_SALON.MainForm.HookahStoreForm.HookahLoader(); } #region EventLogForFood if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage)) { return; } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} و مبلغ آن از {HookahPrice_FirstLoad} به {HookahPrice_New} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New}و توضیحات آن از {HookahDescription_FirstLoad} به {HookahDescription_New} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} و عکس آن تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} و قیمت آن از {HookahPrice_FirstLoad} به {HookahPrice_New} و توضیحات آن از {HookahDescription_FirstLoad} به {HookahDescription_New} تغییر یافت."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} و قیمت آن از {HookahPrice_FirstLoad} به {HookahPrice_New} و عکس آن تغییر یافت."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} و توضیحات آن از {HookahDescription_FirstLoad} به {HookahDescription_New} و عکس آن تغییر یافت."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) == false && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"نام {HookahName_FirstLoad} به {HookahName_New} و قیمت از {HookahPrice_FirstLoad} به {HookahPrice_New} و توضیحات از {HookahDescription_FirstLoad} به {HookahDescription_FirstLoad} و عکس آن تغییر یافت."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"قیمت {HookahName_FirstLoad} از {HookahPrice_FirstLoad} به {HookahPrice_New} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"قیمت {HookahName_FirstLoad} از {HookahPrice_FirstLoad} به {HookahPrice_New} و توضیحات آن از {HookahDescription_New} به {HookahDescription_New} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"قیمت {HookahName_FirstLoad} از {HookahPrice_FirstLoad} به {HookahPrice_New} و عکس آن تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) == false && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"قیمت {HookahName_FirstLoad} از {HookahPrice_FirstLoad} به {HookahPrice_New} و توضیحات آن از {HookahDescription_New} به {HookahDescription_New} و عکس آن تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage)) { #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 = $"توضیحات {HookahName_FirstLoad} از {HookahDescription_New} به {HookahDescription_New} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) == false && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"توضیحات {HookahName_FirstLoad} از {HookahDescription_New} به {HookahDescription_New} و عکس آن تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } else if (string.IsNullOrEmpty(HookahName_New) && string.IsNullOrEmpty(HookahPrice_New) && string.IsNullOrEmpty(HookahDescription_New) && string.IsNullOrEmpty(Select_HookahImage) == false) { #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 = $"عکس {HookahName_FirstLoad} تغییر کرد."; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } #endregion /EventLogForFood string message = $"{HookahName} بروز رسانی گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: HookahImage); } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//----- #endregion /ClientAddressTextBox #region SaveEditButton_Click private void SaveEditButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); #region Validation //=============== int count = 0; string errorMessage = string.Empty; if (string.IsNullOrEmpty(ClientName)) { errorMessage += "فیلد نام مشترک تکمیل گردد! "; count++; } if (string.IsNullOrEmpty(ClientTel)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد تلفن مشترک تکمیل گردد! "; count++; } if (string.IsNullOrEmpty(ClientAddress)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد آدرس مشترک تکمیل گردد! "; count++; } if (errorMessage != string.Empty) { if (count == 1) { this.Size = new System.Drawing.Size(490, 250); ErrorMessage(errorMessage); } else if (count == 2) { this.Size = new System.Drawing.Size(490, 270); ErrorMessage(errorMessage); } else if (count == 3) { this.Size = new System.Drawing.Size(490, 290); ErrorMessage(errorMessage); } return; } //=================== #endregion /Validation System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: "مشترک مورد نظر به روز گردد؟", captiopn: "به روز رسانی", buttons: System.Windows.Forms.MessageBoxButtons.YesNo, defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2, icon: System.Windows.Forms.MessageBoxIcon.Question, options: System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.Client client = dataBaseContext.Clients .Where(current => string.Compare(current.SubscriptionCode.ToString(), subscriptionCodeLabel.Text) == 0) .FirstOrDefault(); if (client != null) { client.ClientName = ClientName; client.ClientTel = ClientTel; client.ClientAddress = ClientAddress; dataBaseContext.SaveChanges(); } } else { return; } string message = $"اطلاعات مشترک به روز رسانی شد!."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); if (Resturant.MainForm.ClientsListForm != null) { Resturant.MainForm.ClientsListForm.ClientLoader(); } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string inputError = string.Empty; #region Validation if (string.IsNullOrEmpty(Username)) { inputError = "مشخصه شناسه کاربری را تکمیل کنید!"; } if (string.IsNullOrEmpty(Email)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه پست الکترونیکی را تکمیل کنید!"; } if (string.IsNullOrEmpty(Password)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه رمز عبور را تکمیل کنید!"; } if (string.IsNullOrEmpty(PasswordConfirm)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه تایید رمز عبور را تکمیل کنید!"; } if (string.IsNullOrEmpty(UserImage)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه تصویر کاربری را تکمیل کنید!"; } if (string.IsNullOrEmpty(FirstName)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه نام را تکمیل کنید!"; } if (string.IsNullOrEmpty(LastName)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه نام خانوادگی را تکمیل کنید!"; } if (string.IsNullOrEmpty(Tel)) { if (string.IsNullOrEmpty(inputError) == false) { inputError += System.Environment.NewLine; } inputError += "مشخصه شماره تماس را تکمیل کنید!"; } //------------------------------------------------ if (string.IsNullOrEmpty(inputError) != true) { if (string.IsNullOrEmpty(Username)) { usernameTextBox.Focus(); } else if (string.IsNullOrEmpty(Email)) { emailTextBox.Focus(); } else if (string.IsNullOrEmpty(Password)) { passwordTextBox.Focus(); } else if (string.IsNullOrEmpty(PasswordConfirm)) { passwordConfirmTextBox.Focus(); } else if (string.IsNullOrEmpty(UserImage)) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog { Filter = "JPG (*.jpg)|*.jpg|" + "PNG (*.png)|*.png|" + "BMP (*.bmp)|*.bmp", Title = "Load user picture ", }; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { UserImage = openFileDialog.FileName; userImagePicturBox.BackgroundImage = System.Drawing.Image.FromFile(UserImage); } if (UserImage != string.Empty) { deleteImageButton.Visible = true; } else { deleteImageButton.Visible = false; } } else if (string.IsNullOrEmpty(FirstName)) { firstNameTextBox.Focus(); } else if (string.IsNullOrEmpty(LastName)) { lastNameTextBox.Focus(); } else if (string.IsNullOrEmpty(Tel)) { telTextBox.Focus(); } Mbb.Windows.Forms.MessageBox.Show (text: inputError, caption: "خطای ورودی", icon: Mbb.Windows.Forms.MessageBoxIcon.Error, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); return; } 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; } #endregion /Validation System.Windows.Forms.DialogResult dialogResult; string message = $"نام کاربری {Username} ذخیره گردد؟."; dialogResult = Mbb.Windows.Forms.MessageBox.Show (text: message, caption: "ذخیره اطلاعات", icon: Mbb.Windows.Forms.MessageBoxIcon.Question, button: Mbb.Windows.Forms.MessageBoxButtons.YesNo); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.User username = dataBaseContext.Users .Where(current => string.Compare(current.Username, Username) == 0) .FirstOrDefault(); if (username != null) { Mbb.Windows.Forms.MessageBox.Show (text: $"نام کاربری {Username} در سیستم موجود میباشد. لطفا از نام دیگری استفاده نمایید.", caption: "اطلاعات مشابه", icon: Mbb.Windows.Forms.MessageBoxIcon.Information, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); usernameTextBox.Focus(); return; } else { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); username = new Models.User { IsActive = true, IsAdministrator = false, Username = Username, Email = Email, Password = Password, Description = Description, First_Name = FirstName, Last_Name = LastName, Telephone = Tel.Replace("-", ""), National_Code = NationalCode, Marital_Status = Marride, Address = Address, Registration_Date = RegisterDate, Registration_Time = RegisterTime, User_Image = System.IO.File.ReadAllBytes(UserImage), }; dataBaseContext.Users.Add(username); dataBaseContext.SaveChanges(); } } else { return; } string successMessage = $"اطلاعات کاربر {Username} با موفقیت ذخیره گرید!"; Infrastructure.Utility.WindowsNotification (message: successMessage, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: UserImage); AllClear(); } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string errorMessage = string.Empty; #region Validation //----- if (string.IsNullOrWhiteSpace(dessertNameTextBox.Text) || string.Compare(dessertNameTextBox.Text, "نام دسر") == 0) { errorMessage = "فیلد دسر تکمیل گردد!"; } if (string.IsNullOrWhiteSpace(dessertPriceTextBox.Text) || string.Compare(dessertPriceTextBox.Text, "0 تومان") == 0) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد مبلغ پیش غذا تکمیل گردد!"; } if (string.IsNullOrWhiteSpace(descriptionTextBox.Text) || string.Compare(descriptionTextBox.Text, "توضیحات") == 0) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "فیلد توضیحات تکمیل گردد!"; } if (errorMessage != string.Empty) { if (string.IsNullOrWhiteSpace(dessertNameTextBox.Text) || string.Compare(dessertNameTextBox.Text, "نام غذا") == 0) { dessertNameTextBox.Focus(); dessertNameTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(dessertPriceTextBox.Text) || string.Compare(dessertPriceTextBox.Text, "مبلغ غذا") == 0) { dessertPriceTextBox.Focus(); dessertPriceTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(descriptionTextBox.Text) || string.Compare(descriptionTextBox.Text, "توضیحات") == 0) { descriptionTextBox.Focus(); descriptionTextBox.Clear(); } ErrorMessage(errorMessage); } if (string.IsNullOrEmpty(DessertImage)) { System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog { Filter = "JPEP (*.jpg)|*.jpg|" + "PNG (*.png)|*.png|" + "BMP (*.bmp)|*.bmp", Title = "Load user picture ", }; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { DessertImage = openFileDialog.FileName; dessertImagePicturBox.Image = System.Drawing.Image.FromFile(DessertImage); } return; } //----- #endregion /Validation errorMessageLabel.Visible = false; errorMessage = string.Empty; System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: $"{DessertName} ثبت گردد؟", captiopn: "ثبت نوشیدنی", buttons: System.Windows.Forms.MessageBoxButtons.YesNo, defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2, icon: System.Windows.Forms.MessageBoxIcon.Question, options: System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.DessertAndAppetizer dessertAndAppetizer = dataBaseContext.DessertAndAppetizers .Where(current => string.Compare(current.DessertName, DessertName, false) == 0) .FirstOrDefault(); if (dessertAndAppetizer != null) { //errorMessage = // System.Environment.NewLine; errorMessage = $"{DessertName} در سیستم موجود است!"; ErrorMessage(errorMessage); dessertNameTextBox.Focus(); dessertNameTextBox.SelectAll(); return; } else { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); dessertAndAppetizer = new Models.DessertAndAppetizer { DessertName = DessertName, DessertPrice = $"{DessertPrice.ToString("#,0")} تومان", Description = Description, DessertImage = System.IO.File.ReadAllBytes(DessertImage), RegisterTime = RegisterDate + " " + RegisterTime, UpdateTime = UpdateTime, NumberUpdate = int.Parse(NumberUpdate), }; dataBaseContext.DessertAndAppetizers.Add(dessertAndAppetizer); dataBaseContext.SaveChanges(); //-----جهت بارگذاری اطلاعات غذا در جدول داده if (Resturant.MainForm.MenuListForm != null) { Resturant.MainForm.MenuListForm.DessertLoader(); } string message = $"{DessertName} ثبت گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: DessertImage); AllClear(); } } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void UpdateButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); if (string.Compare(AccessLevel_New, AccessLeve_FirstLoad) == 0) { AccessLevel = AccessLeve_FirstLoad; } else { AccessLevel = AccessLevel_New; } if (Activation_New == Activation_FirstLoad) { IsActive = Activation_FirstLoad; } else { IsActive = Activation_New; } Models.User user = dataBaseContext.Users .Where(current => string.Compare(current.Username, Username) == 0) .FirstOrDefault(); if (user == null) { return; } else { user.IsActive = IsActive; user.Access_Level = AccessLevel; } dataBaseContext.SaveChanges(); if (string.Compare(AccessLevel_New, AccessLeve_FirstLoad) == 0 && Activation_New == Activation_FirstLoad) { return; } else if (string.Compare(AccessLevel_New, AccessLeve_FirstLoad) != 0 && Activation_New == Activation_FirstLoad) { #region EventLog EventLog_Username = Program.AuthenticatedUser.Username; EventLog_FullName = $"{Program.AuthenticatedUser.First_Name} {Program.AuthenticatedUser.Last_Name}"; EventLog_EventDate = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}"; EventLog_EventTime = $"{Infrastructure.Utility.ShowTime()}"; EventLog_EventTitle = $"سطح دسترسی کاربر {Username} از {AccessLeve_FirstLoad} به {AccessLevel_New} تغییر کرد"; Infrastructure.Utility.EventLog (username: EventLog_Username, fullName: EventLog_FullName, eventDate: EventLog_EventDate, eventTime: EventLog_EventTime, eventTitle: EventLog_EventTitle); #endregion /EventLog } else if (string.Compare(AccessLevel_New, AccessLeve_FirstLoad) == 0 && Activation_New != Activation_FirstLoad) { #region EventLog EventLog_Username = Program.AuthenticatedUser.Username; EventLog_FullName = $"{Program.AuthenticatedUser.First_Name} {Program.AuthenticatedUser.Last_Name}"; EventLog_EventDate = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}"; EventLog_EventTime = $"{Infrastructure.Utility.ShowTime()}"; if (Activation_New) { EventLog_EventTitle = $"کاربر {Username} فعال گردید."; } else { EventLog_EventTitle = $"کاربر {Username} غیر فعال گردید."; } Infrastructure.Utility.EventLog (username: EventLog_Username, fullName: EventLog_FullName, eventDate: EventLog_EventDate, eventTime: EventLog_EventTime, eventTitle: EventLog_EventTitle); #endregion /EventLog } else if (string.Compare(AccessLevel_New, AccessLeve_FirstLoad) != 0 && Activation_New != Activation_FirstLoad) { #region EventLog EventLog_Username = Program.AuthenticatedUser.Username; EventLog_FullName = $"{Program.AuthenticatedUser.First_Name} {Program.AuthenticatedUser.Last_Name}"; EventLog_EventDate = $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}"; EventLog_EventTime = $"{Infrastructure.Utility.ShowTime()}"; if (Activation_New) { EventLog_EventTitle = $"سطح دسترسی کاربر {Username} از {AccessLeve_FirstLoad} به {AccessLevel_New} تغییر و فعال گردید."; } else { EventLog_EventTitle = $"سطح دسترسی کاربر {Username} از {AccessLeve_FirstLoad} به {AccessLevel_New} تغییر و غیر فعال گردید."; } Infrastructure.Utility.EventLog (username: EventLog_Username, fullName: EventLog_FullName, eventDate: EventLog_EventDate, eventTime: EventLog_EventTime, eventTitle: EventLog_EventTitle); #endregion /EventLog } UsersLoaded(); } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
public static void Administrator() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string adminPic = "D:\\Visual Studio Project\\C# Project\\Resturant\\Resturant\\Resources\\AdminUser.png"; string user = "******"; string password = "******"; string email = "*****@*****.**"; bool isAdmin = true; bool isActive = true; Models.User adminUser = dataBaseContext.Users .Where(admin => string.Compare(user, admin.Username, true) == 0) .FirstOrDefault(); if (adminUser == null) { adminUser = new Models.User { IsActive = isActive, IsAdministrator = isAdmin, Username = user, Password = password, Email = email, UserPicture = System.IO.File.ReadAllBytes(adminPic), RegistrationTime = "00:00:00 " + "0000/00/00", }; dataBaseContext.Users.Add(adminUser); } else { if (adminUser.IsActive == false) { adminUser.IsActive = true; } if (adminUser.IsAdministrator == false) { adminUser.IsAdministrator = true; } } dataBaseContext.SaveChanges(); } catch (System.Exception ex) { Mbb.Windows.Forms.MessageBox.ErrorMessage(ex.Message); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string errorMessage = string.Empty; if (string.IsNullOrEmpty(Username)) { errorMessage = "وارد کردن شناسه کاربری الزامی است!"; } if (string.IsNullOrEmpty(Email)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "وارد کردن ایمیل الزامی است!"; } if (string.IsNullOrEmpty(Password)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "وارد کردن رمز عبور الزامی است!"; } if (string.IsNullOrEmpty(PasswordConfirm)) { if (errorMessage != string.Empty) { errorMessage += System.Environment.NewLine + " "; } errorMessage += "وارد کردن تایید رمز عبور الزامی است!"; } if (errorMessage != string.Empty) { if (string.IsNullOrEmpty(Username)) { usernameTextBox.Focus(); } else if (string.IsNullOrEmpty(Email)) { emailTextBox.Focus(); } else if (string.IsNullOrEmpty(Password)) { passwordTextBox.Focus(); } else if (string.IsNullOrEmpty(PasswordConfirm)) { passwordConfirmTextBox.Focus(); } ErrorMessage(errorMessage); return; } if (Infrastructure.Utility.PasswordSet(password: Password, passwordConfirm: PasswordConfirm) == false) { errorMessage = "عدم تطابق رمز!"; ErrorMessage(errorMessage); passwordTextBox.Focus(); return; } else { errorMessageLabel.Visible = false; } if (string.IsNullOrEmpty(UserImage)) { UserImage = "D:\\Visual Studio Project\\C# Project\\Resturant\\Resturant\\Resources\\default_picture_512.png"; } System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: "کاربر مورد نظر ثبت گردد؟", captiopn: "ثبت کاربری", buttons: System.Windows.Forms.MessageBoxButtons.YesNo, defaultButton: System.Windows.Forms.MessageBoxDefaultButton.Button2, icon: System.Windows.Forms.MessageBoxIcon.Question, options: System.Windows.Forms.MessageBoxOptions.RightAlign | System.Windows.Forms.MessageBoxOptions.RtlReading); if (dialogResult == System.Windows.Forms.DialogResult.Yes) { Models.User user = dataBaseContext.Users .Where(current => string.Compare(current.Username, Username) == 0) .FirstOrDefault(); if (user != null) { errorMessage = $"شناسه مورد نظر {Username} در سیستم موجود می باشد! لطفااز شناسه دیگری استفاده نمایید. "; Mbb.Windows.Forms.MessageBox.InformationMessage(errorMessage); return; } else { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); FullName = string.Concat(Infrastructure.Utility.TextFixed(FirstName) + " " + Infrastructure.Utility.TextFixed(LastName)); user = new Models.User { IsActive = true, IsAdministrator = false, FullName = FullName, Username = Username, Email = Email, Password = Password, UserPicture = System.IO.File.ReadAllBytes(UserImage), RegistrationTime = RegisterTime + " " + RegisterDate, }; dataBaseContext.Users.Add(user); dataBaseContext.SaveChanges(); } } else { return; } string message = $"شناسه کاربری با نام {Username} ثبت گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: UserImage); AllClear(); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//------------------------------------------------------------------ #region Administrator public static void Administrator() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string adminPic = "D:\\Visual Studio Project\\Personal Project\\HOOKAH_SALON\\HOOKAH_SALON\\Resources\\AdminUser.png"; Models.User adminUser = dataBaseContext.Users .Where(current => string.Compare(current.Username, "administrator", true) == 0) .FirstOrDefault(); if (adminUser == null) { adminUser = new Models.User { IsActive = true, Access_Level = "مدیریت", Username = "******", Email = "-", Password = "******", Description = "-", User_Image = System.IO.File.ReadAllBytes(adminPic), First_Name = "Administrator", Last_Name = " ", Telephone = "-", National_Code = "-", Address = "-", Marital_Status = "-", Registration_Time = "-", Registration_Date = "-", }; dataBaseContext.Users.Add(adminUser); } else { if (adminUser.IsActive == false) { adminUser.IsActive = true; } if (string.Compare(adminUser.Access_Level, "کارمند") == 0 || string.Compare(adminUser.Access_Level, "نیروی خدمات") == 0) { adminUser.Access_Level = "مدیریت"; } } dataBaseContext.SaveChanges(); } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//----- #region Administrator public static void Administrator() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string adminPic = "D:\\Visual Studio Project\\C# Project\\ComputerServices\\Computer Services\\Resources\\AdminUser.png"; Models.User adminUser = dataBaseContext.Users .Where(current => string.Compare(current.Username, "administrator", true) == 0) .FirstOrDefault(); if (adminUser == null) { adminUser = new Models.User { IsActive = true, IsAdministrator = true, Username = "******", Email = "null", Password = "******", Description = "null", User_Image = System.IO.File.ReadAllBytes(adminPic), First_Name = "null", Last_Name = "null", Telephone = "null", National_Code = "null", Address = "null", Marital_Status = "null", Registration_Time = "00:00:00", Registration_Date = "0000/00/00", }; dataBaseContext.Users.Add(adminUser); } else { if (adminUser.IsActive == false) { adminUser.IsActive = true; } if (adminUser.IsAdministrator == false) { adminUser.IsAdministrator = true; } } dataBaseContext.SaveChanges(); } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }