private void FoodPriceTextBox_Validated(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text) || string.Compare(foodPriceTextBox.Text, "0 تومان") == 0) { FoodPrice = 0; Price = string.Empty; } else { Price = foodPriceTextBox.Text.Replace("تومان", string.Empty).Trim(); FoodPrice = decimal.Parse(Price); foodPriceTextBox.Text = $"{FoodPrice.ToString("#,0")} تومان"; Price = $"{FoodPrice.ToString("#,0")} تومان"; } }
private void FoodPriceTextBox_Leave(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text)) { foodPriceTextBox.Text = "مبلغ غذا"; foodPriceTextBox.ReadOnly = true; } else { foodPriceTextBox.ReadOnly = true; Price = foodPriceTextBox.Text.Replace("تومان", string.Empty).Trim(); FoodPrice = decimal.Parse(Price); foodPriceTextBox.Text = $"{FoodPrice.ToString("#,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(foodNameTextBox.Text) || string.Compare(foodNameTextBox.Text, "نام غذا") == 0) { errorMessage = "فیلد نام غذا تکمیل گردد!"; } if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text) || string.Compare(foodPriceTextBox.Text, "مبلغ غذا") == 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(foodNameTextBox.Text) || string.Compare(foodNameTextBox.Text, "نام غذا") == 0) { foodNameTextBox.Focus(); foodNameTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(foodPriceTextBox.Text) || string.Compare(foodPriceTextBox.Text, "مبلغ غذا") == 0) { foodPriceTextBox.Focus(); foodPriceTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(descriptionTextBox.Text) || string.Compare(descriptionTextBox.Text, "توضیحات") == 0) { descriptionTextBox.Focus(); descriptionTextBox.Clear(); } ErrorMessage(errorMessage); return; } if (string.IsNullOrEmpty(FoodImage)) { 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) { FoodImage = openFileDialog.FileName; foodImagePicturBox.Image = System.Drawing.Image.FromFile(FoodImage); } return; } //----- #endregion /Validation errorMessageLabel.Visible = false; errorMessage = string.Empty; System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: $"{FoodName} ثبت گردد؟", 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.Food food = dataBaseContext.Foods .Where(current => string.Compare(current.FoodName, FoodName, false) == 0) .FirstOrDefault(); if (food != null) { errorMessage = $"{FoodName} در سیستم موجود است!"; ErrorMessage(errorMessage); foodNameTextBox.Focus(); foodNameTextBox.SelectAll(); return; } else { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); food = new Models.Food { FoodName = FoodName, FoodPrice = $"{FoodPrice.ToString("#,0")} تومان", Description = Description, FoodImage = System.IO.File.ReadAllBytes(FoodImage), RegisterTime = RegisterDate + " " + RegisterTime, UpdateTime = UpdateTime, NumberUpdate = int.Parse(NumberUpdate), }; dataBaseContext.Foods.Add(food); dataBaseContext.SaveChanges(); //-----جهت بارگذاری اطلاعات غذا در جدول داده if (Resturant.MainForm.MenuListForm != null) { Resturant.MainForm.MenuListForm.FoodLoader(); } string message = $"{FoodName} ثبت گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: FoodImage); AllClear(); } } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }