private void Btn_Insert_Item_Click(object sender, RoutedEventArgs e) { try { var _Price = Convert.ToInt32(TextBoxItemPrice.Text); var _Stock = Convert.ToInt32(TextBoxItemStock.Text); var _Supp = connection.Suppliers.Where(S => S.Id == cb_sup).FirstOrDefault(); if ((TextBoxItemName.Text == "") || (TextBoxItemPrice.Text == "") || (TextBoxItemStock.Text == "") || (Combo_Supplier.Text == "")) { if (TextBoxItemName.Text == "") { MessageBox.Show("Name is required", "Warning", MessageBoxButton.OK); TextBoxItemName.Focus(); } else if (TextBoxItemPrice.Text == "") { MessageBox.Show("Price is required", "Warning", MessageBoxButton.OK); TextBoxItemPrice.Focus(); } else if (TextBoxItemStock.Text == "") { MessageBox.Show("Stock is required", "Warning", MessageBoxButton.OK); TextBoxItemStock.Focus(); } else if (Combo_Supplier.Text == "") { MessageBox.Show("Supplier is required", "Warning", MessageBoxButton.OK); Combo_Supplier.Focus(); } } else { MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are You Sure?", "Insert Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { var input_item = new Item(TextBoxItemName.Text, _Price, _Stock, _Supp); connection.Items.Add(input_item); var insert = connection.SaveChanges(); MessageBox.Show(insert + " Item has been inserted"); reset_item(); TB_M_Item.ItemsSource = connection.Items.ToList(); } } } catch (Exception) { } }
/// <summary> /// 验证信息完整性 /// </summary> /// <returns></returns> private bool Check() { String str = String.Empty; str = TextBoxItemName.Text.Trim(); if (str.Length == 0) { MessageBox.Show("请设置【项目名称】!", "操作提示"); TextBoxItemName.Focus(); return(false); } if (ComboBoxMethod.SelectedIndex < 0) { MessageBox.Show("请设置【检测方法】!", "操作提示"); ComboBoxMethod.Focus(); return(false); } str = TextBoxSampleNum.Text.Trim(); if (str.Length == 0) { MessageBox.Show("请设置【样品编号】!", "操作提示"); TextBoxSampleNum.Focus(); return(false); } str = TextBoxInvalidC.Text.Trim(); if (str.Length == 0) { MessageBox.Show("请设置【C值】最小值!", "操作提示"); TextBoxInvalidC.Focus(); return(false); } str = TextBoxUnit.Text.Trim(); if (str.Length == 0) { MessageBox.Show("请设置【检测单位】!", "操作提示"); TextBoxUnit.Focus(); return(false); } List <CheckBox> listCheckBoxes = UIUtils.GetChildObjects <CheckBox>(StackPanelHole, typeof(CheckBox)); for (int i = 0; i < Global.deviceHole.SxtCount; ++i) { listCheckBoxes[i].IsChecked = true; } str = TextBoxPassword.Text.Trim(); if (str.Length == 0) { if (MessageBox.Show("【未设置密码】 确定保存无密码的检测项目吗?", "操作提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { this.TextBoxPassword.Focus(); return(false); } } return(true); }
/// <summary> /// 验证信息完整性 /// </summary> /// <returns></returns> private bool Check() { String str = String.Empty; str = TextBoxItemName.Text.Trim(); if (str.Length == 0) { MessageBox.Show(this, "请设置【项目名称】!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning); TextBoxItemName.Focus(); return(false); } if (ComboBoxMethod.SelectedIndex < 0) { MessageBox.Show(this, "请设置【检测方法】!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning); ComboBoxMethod.Focus(); return(false); } str = TextBoxUnit.Text.Trim(); if (str.Length == 0) { MessageBox.Show(this, "请设置【单位】!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning); TextBoxUnit.Focus(); return(false); } str = ComboBoxWave.Text.Trim(); if (str.Length == 0) { MessageBox.Show(this, "请设置【波长】!", "操作提示", MessageBoxButton.OK, MessageBoxImage.Warning); ComboBoxWave.Focus(); return(false); } str = TextBoxPassword.Text.Trim(); if (str.Length == 0) { if (MessageBox.Show("【未设置密码】 确定保存无密码的检测项目吗?", "操作提示", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No) { TextBoxPassword.Focus(); return(false); } } return(true); }