public void PermanentClientListLoaded() { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.PermanentClient> permanentClients = null; permanentClients = dataBaseContext.PermanentClients .OrderBy(current => current.Full_Name) .ToList(); permanentClientDataGridView.DataSource = permanentClients; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
/// <summary> /// ---- تمام فعالیتهایی که توسط متصدی صورت گرفته است ثبت میگردد! /// </summary> /// <param name="username"></param> /// <param name="fullName"></param> /// <param name="eventRegisterDate"></param> /// <param name="eventTitle"></param> public static void EventLog(string username, string fullName, string eventDate, string eventTime, string eventTitle) { if (string.Compare(username, "administrator") == 0) //-----اگر شناسه کاربری برابر با administrator باشد یعنی در حال حاضر حساب مدیریت وارد سیستم شده { return; } else //----- در غیر این صورت سایر حسابها وارد سیستم شده اند. { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.EventLog eventLog = dataBaseContext.EventLogs .OrderByDescending(current => current.Event_Date) .OrderByDescending(current => current.Event_Time) .FirstOrDefault(); eventLog = new Models.EventLog() { Username = username, Full_Name = fullName, Event_Date = eventDate, Event_Time = eventTime, Event_Title = eventTitle, }; dataBaseContext.EventLogs.Add(eventLog); dataBaseContext.SaveChanges(); } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } } }
public static void SaveLogOutTime(Models.LogHistory log) { string logOutTime = null; Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); Models.LogHistory logHistory = dataBaseContext.LogHistories .Where(current => string.Compare(current.Username, log.Username) == 0) .OrderByDescending(current => current.Login_Time) .SingleOrDefault(current => current.Id == log.Id); if (logHistory != null) { logOutTime = $"{Infrastructure.Utility.ShowTime()}" + $"{Infrastructure.Utility.PersianCalendar(System.DateTime.Now)} "; logHistory.Logout_Time = logOutTime; dataBaseContext.SaveChanges(); } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
private void SearchClientName(string seach) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); System.Collections.Generic.List <Models.PermanentClient> permanentClients = null; if (string.IsNullOrEmpty(seach)) { permanentClients = dataBaseContext.PermanentClients .OrderBy(current => current.Full_Name) .ToList(); } else { permanentClients = dataBaseContext.PermanentClients .Where(current => current.Full_Name.Contains(seach)) .OrderBy(current => current.Full_Name) .ToList(); } permanentClientDataGridView.DataSource = permanentClients; } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }
//----- #endregion /FullNameTextBox #region SaveButton_Click private void SaveButton_Click(object sender, System.EventArgs e) { Models.DataBaseContext dataBaseContext = null; try { dataBaseContext = new Models.DataBaseContext(); string errorMessage = null; #region Validate //----- if (string.IsNullOrWhiteSpace(clientIDTextBox.Text) || string.Compare(clientIDTextBox.Text, "کد شناسه") == 0) { errorMessage = "فیلد کد شناسه را تکمیل کنید!"; } if (string.IsNullOrWhiteSpace(fullNameTextBox.Text) || string.Compare(fullNameTextBox.Text, "نام کامل") == 0) { if (errorMessage != null) { errorMessage += System.Environment.NewLine; } errorMessage += "فیلد نام کامل را تکمیل کنید!"; } if (errorMessage != null) { if (string.IsNullOrWhiteSpace(clientIDTextBox.Text) || string.Compare(clientIDTextBox.Text, "کد شناسه") == 0) { clientIDTextBox.Focus(); } else if (string.IsNullOrWhiteSpace(fullNameTextBox.Text) || string.Compare(fullNameTextBox.Text, "نام کامل") == 0) { fullNameTextBox.Focus(); } Mbb.Windows.Forms.MessageBox.Show (text: errorMessage, caption: "خطای ورودی", icon: Mbb.Windows.Forms.MessageBoxIcon.Error, button: Mbb.Windows.Forms.MessageBoxButtons.Ok); return; } //----- #endregion /Validate System.Windows.Forms.DialogResult dialogResult; string message = $"کد شناسه {ClientID} ذخیره گردد؟."; 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.PermanentClient client = dataBaseContext.PermanentClients .Where(current => string.Compare(current.Client_ID, ClientID) == 0) .FirstOrDefault(); if (client == null) { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); client = new Models.PermanentClient { Client_ID = ClientID, Full_Name = ClientFullName, Register_Date = $"{RegisterTime} - {RegisterDate}", Last_Order = "00:00:00 - 0000/00/00", Number_Order = 0, Edit_Date = "00:00:00 - 0000/00/00", }; dataBaseContext.PermanentClients.Add(client); dataBaseContext.SaveChanges(); if (ClientManegmentForm.PermanentClientListForm != null) { ClientManegmentForm.PermanentClientListForm.PermanentClientListLoaded(); } #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} و نام {ClientFullName}"; Infrastructure.Utility.EventLog (username: Username, fullName: FullName, eventDate: EventDate, eventTime: EventTime, eventTitle: EventTitle); #endregion /EventLog } } else { return; } string successMessage = $"اطلاعات کاربر {ClientID} با موفقیت ذخیره گرید!"; Infrastructure.Utility.WindowsNotification (message: successMessage, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت); AllClear(); } catch (System.Exception ex) { Infrastructure.Utility.ExceptionShow(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }