Пример #1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     Models.DataBaseContext OdbContext = null;
     try
     {
         OdbContext = new Models.DataBaseContext();
         Models.User Ouser = new Models.User();
         var         model = OdbContext.Users.Where(E => (E.UserName == tbxUserName.Text.Trim() &&
                                                          E.Password == tbxPassword.Text.Trim())).ToList();
         if (model.Count > 0)
         {
             trustUser = true;
             this.Close();
         }
         else
         {
             LoginErrorCount++;
             MessageBox.Show("نام کاربری یا کلمه عبور شما اشتباه است ");
             if (LoginErrorCount == 3)// اگر کاربر سه بار نام کاربری و کلمه عبور را اشتباه وارد کرد برنامه بسته شود
             {
                 this.Close();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Пример #2
0
        public void MonthlyFinancialList()
        {
            Models.DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext =
                    new DataBaseContext();

                List <MonthlyFinancial> monthlyFinancials =
                    dataBaseContext.MonthlyFinancials
                    .OrderBy(current => current.Register_Date)
                    .ToList();

                monthlyFinancialListDataGridView.DataSource = monthlyFinancials;
            }
            catch (System.Exception ex)
            {
                Infrastructure.Utility.ExceptionShow(ex);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
        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;
                }
            }
        }
Пример #4
0
        public UnitOfWork(Models.DataBaseContext dataBaseContext) : base()
        {
            if (dataBaseContext == null)
            {
                dataBaseContext = new Models.DataBaseContext();
            }

            DataBaseContext = dataBaseContext;
        }
Пример #5
0
        /// <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;
                    }
                }
            }
        }
Пример #6
0
        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 bool ApprovalClientName(string search)
        {
            Models.DataBaseContext dataBaseContext = null;
            dataBaseContext =
                new Models.DataBaseContext();

            Models.PermanentClient permanentClient =
                dataBaseContext.PermanentClients
                .Where(current => string.Compare(current.Full_Name, search) == 0)
                .FirstOrDefault();

            if (permanentClient != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        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;
                }
            }
        }
        //-----End of coding line.

        #region Founctions
        //-----
        #region Validation_ClientID
        private bool Validation_ClientID(string clientID)
        {
            bool status = false;

            Models.DataBaseContext dataBaseContext = null;

            dataBaseContext =
                new Models.DataBaseContext();

            Models.PermanentClient client =
                dataBaseContext.PermanentClients
                .Where(current => string.Compare(current.Client_ID, clientID) == 0)
                .FirstOrDefault();

            if (client == null)
            {
                status = true;
            }
            else
            {
                status = false;
            }
            return(status);
        }
Пример #10
0
 public OrderDetailsRepository(Models.DataBaseContext dataBaseContext) : base(dataBaseContext)
 {
 }
Пример #11
0
 public PieRepository(Models.DataBaseContext dataBaseContext) : base(dataBaseContext)
 {
 }
Пример #12
0
        //-----

        #region Founction
        //-----
        #region ClientFinancialAccount
        private void ClientFinancialAccount(string clientID)
        {
            Models.DataBaseContext dataBaseContext = null;
            try
            {
                int payment;
                dataBaseContext =
                    new DataBaseContext();

                Models.PermanentClientStatus permanentClientStatus =
                    dataBaseContext.PermanentClientStatuses
                    .Where(current => string.Compare(current.Client_ID, clientID) == 0)
                    .FirstOrDefault();
                if (permanentClientStatus == null)
                {
                    return;
                }
                else
                {
                    clientNameTextBox.Text = permanentClientStatus.Client_Name;

                    if (string.Compare(amountTextBox.Text, "مبلغ") == 0)
                    {
                        amountTextBox.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
                        amountTextBox.TextAlign   = System.Drawing.ContentAlignment.MiddleRight;
                        payment            = int.Parse(permanentClientStatus.Remaining_Amount.Replace("تومان", string.Empty).Trim().Replace(",", string.Empty).Trim());
                        amountTextBox.Text = $"{payment:#,0} تومان";
                    }
                    else
                    {
                        payment            = int.Parse(permanentClientStatus.Remaining_Amount);
                        payment            = 0;
                        amountTextBox.Text = $"تومان {payment}";
                    }

                    switch (permanentClientStatus.AccountStatus)
                    {
                    case "بدهکار":
                        debtorStatusRadioButton.Checked     = true;
                        settlementStatusRadioButton.Checked = false;
                        creditorStatusRadioButton.Checked   = false;
                        paymentAmountTextBox.Enabled        = true;
                        paymentAmountButton.Enabled         = true;
                        break;

                    case "تسویه":
                        debtorStatusRadioButton.Checked     = false;
                        settlementStatusRadioButton.Checked = true;
                        creditorStatusRadioButton.Checked   = false;
                        paymentAmountTextBox.Enabled        = false;
                        paymentAmountButton.Enabled         = false;
                        break;

                    case "طلبکار":
                        debtorStatusRadioButton.Checked     = false;
                        settlementStatusRadioButton.Checked = false;
                        creditorStatusRadioButton.Checked   = true;
                        paymentAmountTextBox.Enabled        = false;
                        paymentAmountButton.Enabled         = false;
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (System.Exception ex)
            {
                Infrastructure.Utility.ExceptionShow(ex);
            }
            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }
        }
Пример #13
0
        //-----
        #endregion /PaymentAmountTextBox

        #region PaymentAmountButton_Click
        private void PaymentAmountButton_Click(object sender, System.EventArgs e)
        {
            SearchClientID = SearchClientID.Replace("-", string.Empty).Trim();
            int    resultRemaining = Remaining + PaymentAmount_Int;
            string orderDate, dateSettlement;

            dateSettlement = $"{Infrastructure.Utility.ShowTime()} - {Infrastructure.Utility.PersianCalendar(System.DateTime.Now)}";
            if (resultRemaining < 0)
            {
                AccountStatus = "بدهکار";
                debtorStatusRadioButton.Checked     = true;
                settlementStatusRadioButton.Checked = false;
                creditorStatusRadioButton.Checked   = false;
            }
            else if (resultRemaining == 0)
            {
                AccountStatus = "تسویه";
                debtorStatusRadioButton.Checked     = false;
                settlementStatusRadioButton.Checked = true;
                creditorStatusRadioButton.Checked   = false;
            }
            else if (resultRemaining > 0)
            {
                AccountStatus = "طلبکار";
                debtorStatusRadioButton.Checked     = false;
                settlementStatusRadioButton.Checked = false;
                creditorStatusRadioButton.Checked   = true;
            }

            Models.DataBaseContext dataBaseContext = null;

            try
            {
                dataBaseContext =
                    new DataBaseContext();

                Models.PermanentClientStatus permanentClientStatus =
                    dataBaseContext.PermanentClientStatuses
                    .Where(current => string.Compare(current.Client_ID, SearchClientID) == 0)
                    .FirstOrDefault();

                if (permanentClientStatus != null)                //-----ثبت تسویه مالی مشتری
                {
                    string paymentAmount_String = permanentClientStatus.Payment_Amount;
                    int    paymentAmount_Int    = int.Parse(paymentAmount_String.Replace("تومان", string.Empty).Trim().Replace(",", string.Empty).Trim());

                    PaymentAmount_Int += paymentAmount_Int;
                    orderDate          = permanentClientStatus.Order_Date;

                    permanentClientStatus.Payment_Amount   = $"{PaymentAmount_Int:#,0} تومان";
                    permanentClientStatus.Remaining_Amount = $"{resultRemaining:#,0} تومان";
                    permanentClientStatus.Payment_Type     = Payment_Type;
                    permanentClientStatus.AccountStatus    = AccountStatus;

                    permanentClientStatus.Client_ID       = SearchClientID;
                    permanentClientStatus.Client_Name     = clientNameTextBox.Text;
                    permanentClientStatus.Order_Date      = orderDate;
                    permanentClientStatus.Date_Settlement = dateSettlement;

                    dataBaseContext.SaveChanges();
                }

                Models.Financial financial =
                    dataBaseContext.Financials
                    .OrderBy(current => current.Order_Date)
                    .FirstOrDefault();

                string date = Infrastructure.Utility.PersianCalendar(System.DateTime.Now);
                orderDate = $"00:00:00 - 0000/00/00";
                financial =
                    new Models.Financial()               //-----بعد از صورت تعیین وضعیت تسویه حساب در بخش مالی ثبت میگردد!
                {
                    Client_ID        = SearchClientID,
                    Total_Price      = "0",
                    Payment_Amount   = $"{PaymentAmount_Int:#,0} تومان",
                    Remaining_Amount = $"{resultRemaining:#,0} تومان",
                    Payment_Type     = Payment_Type,
                    Order_Date       = orderDate,
                    Register_Date    = date,
                    Date_Settlement  = dateSettlement
                };

                dataBaseContext.Financials.Add(financial);
                dataBaseContext.SaveChanges();

                #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 = $"پرداخت بدهی توسط {clientNameTextBox.Text} به مبلغ {PaymentAmount_Int:#,0} تومان. وضعیت حساب {AccountStatus} ";

                Infrastructure.Utility.EventLog
                    (username: EventLog_Username,
                    fullName: EventLog_FullName,
                    eventDate: EventLog_EventDate,
                    eventTime: EventLog_EventTime,
                    eventTitle: EventLog_EventTitle);
                #endregion /EventLog

                if (resultRemaining < 0)
                {
                    Mbb.Windows.Forms.MessageBox.Show
                        (text: $"{clientNameTextBox.Text} مبلغ {PaymentAmount_Int:#,0} تومان پرداخت و مبلغ \n {resultRemaining:#,0} تومان بدهکار میباشد.",
                        caption: $"بدهکار",
                        icon: Mbb.Windows.Forms.MessageBoxIcon.Information,
                        button: Mbb.Windows.Forms.MessageBoxButtons.Ok);
                    ClientFinancialAccount(SearchClientID);
                    return;
                }
                else if (resultRemaining == 0)
                {
                    Mbb.Windows.Forms.MessageBox.Show
                        (text: $"{clientNameTextBox.Text} مبلغ {PaymentAmount_Int:#,0} تومان پرداخت و حساب تسویه گردید.",
                        caption: "تسویه",
                        icon: Mbb.Windows.Forms.MessageBoxIcon.Success,
                        button: Mbb.Windows.Forms.MessageBoxButtons.Ok);
                    ClientFinancialAccount(SearchClientID);
                    return;
                }
                else if (resultRemaining > 0)
                {
                    Mbb.Windows.Forms.MessageBox.Show
                        (text: $"{clientNameTextBox.Text} مبلغ {PaymentAmount_Int:#,0} تومان پرداخت و مبلغ \n {resultRemaining:#,0} تومان طلبکار میباشد.",
                        caption: "طلبکار",
                        icon: Mbb.Windows.Forms.MessageBoxIcon.Alert,
                        button: Mbb.Windows.Forms.MessageBoxButtons.Ok);
                    ClientFinancialAccount(SearchClientID);
                    return;
                }
            }
            catch (System.Exception ex1)
            {
                Infrastructure.Utility.ExceptionShow(ex1);
            }
            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;
                }
            }
        }