Exemplo n.º 1
0
 private void DessertPriceTextBox_Validated(object sender, System.EventArgs e)
 {
     if (string.IsNullOrWhiteSpace(dessertPriceTextBox.Text) || string.Compare(dessertPriceTextBox.Text, "0 تومان") == 0)
     {
         DessertPrice = 0;
         Price        = string.Empty;
     }
     else
     {
         Price                    = dessertPriceTextBox.Text.Replace("تومان", string.Empty).Trim();
         DessertPrice             = decimal.Parse(Price);
         dessertPriceTextBox.Text = $"{DessertPrice.ToString("#,0")} تومان";
         Price                    = $"{DessertPrice.ToString("#,0")} تومان";
     }
 }
Exemplo n.º 2
0
        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;
                }
            }
        }