public void fillInfo(int id) { using (idkModel idk = new idkModel()) { try { var suppliers = (from ep in idk.Suppliers where ep.Id == id select ep).ToList(); foreach (Supplier i in suppliers) { textBox_name.Text = i.CompanyName; textBox_contName.Text = i.ContactName; textBox_title.Text = i.ContactTitle; textBox1_country.Text = i.Country; textBox2_city.Text = i.City; textBox_phone.Text = i.Phone; textBox_fax.Text = i.Fax; } } catch (Exception ee) { MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
void FillTextBox() { //textBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend; //textBox1.AutoCompleteSource = AutoCompleteSource.CustomSource; //AutoCompleteStringCollection coll = new AutoCompleteStringCollection(); var coll = new AutoCompleteStringCollection(); using (idkModel idk = new idkModel()) { var name = from a in idk.Products select a.ProductName; foreach (string i in name) { coll.Add(i); } } var textBox = new TextBox { AutoCompleteCustomSource = coll, AutoCompleteMode = AutoCompleteMode.SuggestAppend, AutoCompleteSource = AutoCompleteSource.CustomSource, Location = new Point(370, 115), Width = 150, Visible = true, Name = "textbox1" }; // Add the text box to the form. Controls.Add(textBox); }
public void fillInfo(int id) { using (idkModel idk = new idkModel()) { try { var pd = (from p in idk.Products join s in idk.Suppliers on p.SupplierId equals s.Id where p.Id == Id select p).ToList(); foreach (Product i in pd) { textBox_name.Text = i.ProductName; comboBox_supplier.SelectedIndex = comboBox_supplier.FindString(i.Supplier.CompanyName); numericUpDown_price.Value = Convert.ToDecimal(i.UnitPrice); textBox_package.Text = i.Package; checkBox_discontinued.Checked = i.IsDiscontinued; } } catch (Exception ee) { MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void btn_save_Click(object sender, EventArgs e) { using (idkModel idk = new idkModel()) { using (DbContextTransaction transaction = idk.Database.BeginTransaction()) { try { Order o; if (Id.HasValue) { o = (from odi in idk.Orders join pd in idk.OrderItems on odi.Id equals pd.OrderId where pd.Id == Id select odi).FirstOrDefault(); } else { o = new Order(); o.OrderDate = DateTime.Now; o.OrderNumber = numericUpDown2.Text; } o.CustomerId = (from ct in idk.Customers where ct.FirstName == comboBox1_customer.Text select ct.Id).FirstOrDefault(); o.OrderDate = dateTimePicker1.Value; o.OrderNumber = numericUpDown2.Text; o.TotalAmount = numericUpDown1.Value; if (!Id.HasValue) { idk.Orders.Add(o); } idk.Orders.Add(o); idk.SaveChanges(); transaction.Commit(); MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ee) { //transaction.Rollback(); MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Close(); } } } }
public void cust() { using (idkModel idk = new idkModel()) { try { comboBox1_customer.DataSource = idk.Customers.Select(i => i.FirstName).ToList(); comboBox1_customer.Text = comboBox1_customer.SelectedItem.ToString(); } catch (Exception ex) { MessageBox.Show("Error occured!"); } } }
public void sup() { using (idkModel idk = new idkModel()) { try { comboBox_supplier.DataSource = idk.Suppliers.Select(i => i.CompanyName).ToList(); comboBox_supplier.Text = comboBox_supplier.SelectedItem.ToString(); } catch (Exception ex) { MessageBox.Show("Error occured!"); } } }
private void button_add_Click(object sender, EventArgs e) { using (idkModel idk = new idkModel()) { try { Supplier sp; if (yn.HasValue) { sp = (from ep in idk.Suppliers where ep.Id == yn select ep).FirstOrDefault(); } else { sp = new Supplier(); } sp.CompanyName = textBox_name.Text; sp.ContactName = textBox_contName.Text; sp.ContactTitle = textBox_title.Text; sp.Country = textBox1_country.Text; sp.City = textBox2_city.Text; sp.Phone = textBox_phone.Text; sp.Fax = textBox_fax.Text; if (!yn.HasValue) { idk.Suppliers.Add(sp); } idk.Suppliers.Add(sp); idk.SaveChanges(); MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ee) { MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Close(); } } }
private void button_add_Click(object sender, EventArgs e) { using (idkModel idk = new idkModel()) { try { Product pd; if (Id.HasValue) { pd = (from p in idk.Products join s in idk.Suppliers on p.SupplierId equals s.Id where p.Id == Id select p).FirstOrDefault(); } else { pd = new Product(); } pd.ProductName = textBox_name.Text; pd.SupplierId = (from ct in idk.Suppliers where ct.CompanyName == comboBox_supplier.Text select ct.Id).FirstOrDefault(); pd.UnitPrice = numericUpDown_price.Value; pd.Package = textBox_package.Text; pd.IsDiscontinued = checkBox_discontinued.Checked; if (!Id.HasValue) { idk.Products.Add(pd); } idk.Products.Add(pd); idk.SaveChanges(); MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ee) { MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Close(); } } }
private void button1_Click(object sender, EventArgs e) { try { using (idkModel idk = new idkModel()) { Customer c; if (Id.HasValue) { c = (from cc in idk.Customers where cc.Id == Id select cc).FirstOrDefault(); } else { c = new Customer(); } c.FirstName = txtBox_fn.Text; c.LastName = txtBox_ln.Text; c.City = txtBox_ct.Text; c.Country = txtBox_cntry.Text; c.Phone = txtBox_ph.Text; if (!Id.HasValue) { idk.Customers.Add(c); } idk.Customers.Add(c); idk.SaveChanges(); } MessageBox.Show("ოპერაცია წარმატებით დასრულდა", "წარმატება", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "მოხდა შეცდომა", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.Close(); } }
public void ordR() { try { Random rand = new Random(); int orderNumber = rand.Next(1, 10000); using (idkModel idk = new idkModel()) { var orderNumMatch = idk.Orders.ToList().FirstOrDefault(i => i.OrderNumber.Equals(orderNumber)); while (orderNumMatch != null) { orderNumber = rand.Next(1, 10000); orderNumMatch = idk.Orders.ToList().FirstOrDefault(i => i.OrderNumber.Equals(orderNumber)); } } numericUpDown2.Text = orderNumber.ToString(); } catch (Exception ee) { MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void fillInfo(int id) { using (idkModel idk = new idkModel()) { try { var customers = (from ep in idk.Customers where ep.Id == id select ep).ToList(); foreach (Customer i in customers) { txtBox_fn.Text = i.FirstName; txtBox_ln.Text = i.LastName; txtBox_cntry.Text = i.Country; txtBox_ct.Text = i.City; txtBox_ph.Text = i.Phone; } } catch (Exception ee) { MessageBox.Show(ee.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }