private void btnQryProduct_Click(object sender, EventArgs e) { //開窗查詢商品編號 TListProductID SelectProductID = new TListProductID(); ProductIDTextBox.Text = SelectProductID.ProductID; ProductIDTextBox.Focus(); }
// Private functions // ***************** private void DisplayProduct(product p) { if (p != null) { ProductIDTextBox.Text = p.productID.ToString(); ConditionTextBox.Text = p.condition; CostTextBox.Text = "$" + p.cost.ToString(); // Product Info PlatformTextBox.Text = p.platform; OSTextBox.Text = p.OS; ManufacturerTextBox.Text = p.manufacturer; ModelTextBox.Text = p.model; // Tech Specs MemoryTextBox.Text = p.RAM_size; LCDSizeTextBox.Text = p.screensize; HDDTextBox.Text = p.HDD_size; CPUBrandTextBox.Text = p.CPU_brand; CPUNumberTexBox.Text = p.CPU_number; GPUTypeTextBox.Text = p.GPU_Type; CPUTypeTextBox.Text = p.CPU_type; CPUSpeedTextBox.Text = p.CPU_speed; WebcamTextBox.Text = p.webcam; NextButton.Enabled = true; } else { ProductIDTextBox.Clear(); ConditionTextBox.Clear(); CostTextBox.Clear(); // Product Info PlatformTextBox.Clear(); OSTextBox.Clear(); ManufacturerTextBox.Clear(); // Tech Specs MemoryTextBox.Clear(); LCDSizeTextBox.Clear(); HDDTextBox.Clear(); CPUBrandTextBox.Clear(); CPUNumberTexBox.Clear(); GPUTypeTextBox.Clear(); CPUTypeTextBox.Clear(); CPUSpeedTextBox.Clear(); WebcamTextBox.Clear(); NextButton.Enabled = false; } }
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 }
// reset the form; private void ResetForm() { ProductIDTextBox.Clear(); ConditionTextBox.Clear(); CostTextBox.Clear(); PlatformTextBox.Clear(); OSTextBox.Clear(); ManufacturerTextBox.Clear(); ModelTextBox.Clear(); MemoryTextBox.Clear(); LCDSizeTextBox.Clear(); HDDTextBox.Clear(); CPUBrandTextBox.Clear(); CPUNumberTextBox.Clear(); GPUTypeTextBox.Clear(); CPUTypeTextBox.Clear(); CPUSpeedTextBox.Clear(); WebCamTextBox.Clear(); }
private void AddProoductButton_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(); con.ConnectionString = ConfigurationManager.ConnectionStrings["MassiveDynamic.Properties.Settings.MassiveDynamicConnectionString"].ConnectionString; string insertIntoProductId = "'" + ProductIDTextBox.Text + "'"; string insertIntoProductName = "'" + ProductNameTextBox.Text + "'"; string insertIntoCaegoryId = "'" + CategoryIdComboBox.Text + "'"; string insertIntoQPE = "'" + QuantityPerUnitTextBox.Text + "'"; string insertIntoUnitPrice = "'" + PriceTextBox.Text + "'"; string command = string.Format("insert into Products(ProductID,ProductName,CategoryID,QuantityPerUnit,UnitPrice) values ({0},{1},{2},{3},{4})", insertIntoProductId, insertIntoProductName, insertIntoCaegoryId, insertIntoQPE, insertIntoUnitPrice); SqlCommand com = new SqlCommand(command, con); com.CommandType = CommandType.Text; try { con.Open(); com.ExecuteNonQuery(); MessageBox.Show("Данните са добавени успешно!"); ProductIDTextBox.Clear(); ProductNameTextBox.Clear(); QuantityPerUnitTextBox.Clear(); PriceTextBox.Clear(); } catch (Exception exe) { //извеждаме съобщение с възникналото изключение MessageBox.Show(exe.ToString(), "Message/Съобщение:"); } finally { con.Close(); this.Close(); } }