예제 #1
0
        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;
                }
            }
        }
예제 #2
0
        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;
                    }
                }
            }
        }
예제 #3
0
        //-----
        #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;
                }
            }
        }
예제 #4
0
        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;
                }
            }
        }
예제 #5
0
        //-----Beginning of the codes.

        #region ClientsEditForm
        //-----
        #region ClientsEditForm_Load
        private void ClientsEditForm_Load(object sender, System.EventArgs e)
        {
            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)
                {
                    subscriptionCodeLabel.Text = client.SubscriptionCode.ToString();
                    clientNameTextBox.Text     = client.ClientName;
                    ClientName                = client.ClientName;
                    FirstValueName            = client.ClientName;
                    clientTelTextBox.Text     = client.ClientTel;
                    ClientTel                 = client.ClientTel;
                    FirstValueTel             = client.ClientTel;
                    clientAddressTextBox.Text = client.ClientAddress;
                    ClientAddress             = client.ClientAddress;
                    FirstValueAddress         = client.ClientAddress;
                }
            }
            catch (System.Exception ex)
            {
                Infrastructure.Utility.PopupNotification(ex);
            }

            finally
            {
                if (dataBaseContext != null)
                {
                    dataBaseContext.Dispose();
                    dataBaseContext = null;
                }
            }

            if (string.Compare(subscriptionCodeLabel.Text, "کد اشتراک") != 0)
            {
                subscriptionCodeLabel.ForeColor =
                    Infrastructure.Utility.WhiteColor();
            }
            else
            {
                subscriptionCodeLabel.ForeColor =
                    Infrastructure.Utility.DimGrayColor();
            }

            if (string.Compare(clientNameTextBox.Text, "نام مشکرت") != 0)
            {
                clientNameTextBox.ForeColor =
                    Infrastructure.Utility.WhiteColor();
            }
            else
            {
                clientNameTextBox.ForeColor =
                    Infrastructure.Utility.DimGrayColor();
            }

            if (string.Compare(clientTelTextBox.Text, "تلفن اشتراک") != 0)
            {
                clientTelTextBox.ForeColor =
                    Infrastructure.Utility.WhiteColor();
            }
            else
            {
                clientTelTextBox.ForeColor =
                    Infrastructure.Utility.DimGrayColor();
            }

            if (string.Compare(clientAddressTextBox.Text, "آدرس اشتراک") != 0)
            {
                clientAddressTextBox.ForeColor =
                    Infrastructure.Utility.WhiteColor();
            }
            else
            {
                clientAddressTextBox.ForeColor =
                    Infrastructure.Utility.DimGrayColor();
            }
        }
예제 #6
0
        //-----
        #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;
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Konstruktor
 /// </summary>
 public App()
 {
     Client = new Models.Client();
 }