public void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { decimal DrinkPrice; MySqlConnection connect = new MySqlConnection("server = localhost; database = mega; username = root; password=;"); string query = "select* from soda where Item = '" + comboBox1.Text + "' ;"; MySqlCommand Combodata = new MySqlCommand(query, connect); MySqlDataReader myreader; //decimal ReturnDecimalPrice(decimal price) //{ // return price; //} try { connect.Open(); myreader = Combodata.ExecuteReader(); while (myreader.Read()) { DrinkPrice = myreader.GetDecimal("Prices"); DirectDecimal = DrinkPrice; //DrinkPriceBox.Text = "$"+DrinkPrice; DrinkPriceBox.Text = "$" + DrinkPrice.ToString(); byte[] img = (byte[])(myreader["Image"]); if (img == null) { DrinkPictureBox.Image = null; } else { MemoryStream ImageStream = new MemoryStream(img); DrinkPictureBox.Image = System.Drawing.Image.FromStream(ImageStream); } } connect.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } //decimal ReturnDecimalPrice(decimal price) //{ // price = DrinkPrice; // return price; //} }
private void DrinkPriceTextBox_Validated(object sender, System.EventArgs e) { if (string.IsNullOrWhiteSpace(drinkPriceTextBox.Text) || string.Compare(drinkPriceTextBox.Text, "0 تومان") == 0) { DrinkPrice = 0; Price = string.Empty; } else { Price = drinkPriceTextBox.Text.Replace("تومان", string.Empty).Trim(); DrinkPrice = decimal.Parse(Price); drinkPriceTextBox.Text = $"{DrinkPrice.ToString("#,0")} تومان"; Price = $"{DrinkPrice.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(drinkNameTextBox.Text) || string.Compare(drinkNameTextBox.Text, "نام نوشیدنی") == 0) { errorMessage = "فیلد نام نوشیدنی تکمیل گردد!"; } if (string.IsNullOrWhiteSpace(drinkPriceTextBox.Text) || string.Compare(drinkPriceTextBox.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(drinkNameTextBox.Text) || string.Compare(drinkNameTextBox.Text, "نام غذا") == 0) { drinkNameTextBox.Focus(); drinkNameTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(drinkPriceTextBox.Text) || string.Compare(drinkPriceTextBox.Text, "مبلغ غذا") == 0) { drinkPriceTextBox.Focus(); drinkPriceTextBox.Clear(); } else if (string.IsNullOrWhiteSpace(descriptionTextBox.Text) || string.Compare(descriptionTextBox.Text, "توضیحات") == 0) { descriptionTextBox.Focus(); descriptionTextBox.Clear(); } ErrorMessage(errorMessage); } if (string.IsNullOrEmpty(DrinkImage)) { 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) { DrinkImage = openFileDialog.FileName; drinkImagePicturBox.Image = System.Drawing.Image.FromFile(DrinkImage); } } //----- #endregion /Validation errorMessageLabel.Visible = false; errorMessage = string.Empty; System.Windows.Forms.DialogResult dialogResult; dialogResult = Mbb.Windows.Forms.MessageBox.QuestionMessage (text: $"{DrinkName} ثبت گردد؟", 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) { RegisterDate = Infrastructure.Utility.PersianCalendar(System.DateTime.Now); RegisterTime = Infrastructure.Utility.ShowTime(); Models.Drink drink = dataBaseContext.Drinks .Where(current => string.Compare(current.DrinkName, DrinkName, false) == 0) .FirstOrDefault(); if (drink != null) { //errorMessage = // System.Environment.NewLine; errorMessage = $"{DrinkName} در سیستم موجود است!"; ErrorMessage(errorMessage); drinkNameTextBox.Focus(); drinkNameTextBox.SelectAll(); return; } else { drink = new Models.Drink { DrinkName = DrinkName, DrinkPrice = $"{DrinkPrice.ToString("#,0")} تومان", Description = Description, DrinkImage = System.IO.File.ReadAllBytes(DrinkImage), RegisterTime = RegisterDate + " " + RegisterTime, UpdateTime = UpdateTime, NumberUpdate = int.Parse(NumberUpdate), }; dataBaseContext.Drinks.Add(drink); dataBaseContext.SaveChanges(); //-----جهت بارگذاری اطلاعات غذا در جدول داده if (Resturant.MainForm.MenuListForm != null) { Resturant.MainForm.MenuListForm.DrinkLoader(); } string message = $"{DrinkName} ثبت گردید."; Infrastructure.Utility.WindowsNotification (message: message, caption: Infrastructure.PopupNotificationForm.Caption.موفقیت, picture: DrinkImage); AllClear(); } } else { return; } } catch (System.Exception ex) { Infrastructure.Utility.PopupNotification(ex); } finally { if (dataBaseContext != null) { dataBaseContext.Dispose(); dataBaseContext = null; } } }