示例#1
0
        private void btnQryProduct_Click(object sender, EventArgs e)
        {
            //開窗查詢商品編號
            TListProductID SelectProductID = new TListProductID();

            ProductIDTextBox.Text = SelectProductID.ProductID;
            ProductIDTextBox.Focus();
        }
        private void GroupTextBox_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.Key)
            {
            case Key.Enter: {
                if (!short.TryParse(this.GroupTextBox.Text, out short groupID))
                {
                    MessageBox.Show("Введите корректную группу!");
                    this.GroupTextBox.Focus();
                    return;
                }        //if

                try {
                    using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                        var group = context.Groups.FirstOrDefault(g => g.groupID == groupID);
                        if (group == null)
                        {
                            this.GroupTextBox.Focus();
                            return;
                        }    //if
                        this.GroupTitleLabel.Content = (object)group.groupTitle;
                    }        //using
                    ProductIDTextBox.Focus();
                }
                catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            break;

            case Key.F1: {
                ShowGroupWindow sw = new ShowGroupWindow();
                if (sw.ShowDialog() == true)
                {
                    this.GroupTextBox.Text = sw.number.ToString();

                    try {
                        using (SmallBusinessDBEntities context = new SmallBusinessDBEntities()) {
                            var group = context.Groups.FirstOrDefault(g => g.groupID == sw.number);
                            this.GroupTitleLabel.Content = (object)group.groupTitle;
                        }        //using
                        ProductIDTextBox.Focus();
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.Message);
                    }
                }        //if
            }
            break;

            default: break;
            }//switch
        }