Esempio n. 1
0
 private void btnSum_Click(object sender, EventArgs e)
 {
     try
     {
         AccountingDb = new AccountingEntities1();
         double money = AccountingDb.Invoice.Where(c => c.Client.Contains(txtSum.Text)).Sum(c => c.Money);
         MessageBox.Show(string.Format("Сума на всех счетах клиента {0} равна {1}", txtSum.Text, money.ToString()));
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString() + "\n\r");
     }
 }
Esempio n. 2
0
        private void btnSelect_Click(object sender, EventArgs e)
        {
            try
            {
                AccountingDb = new AccountingEntities1();

                AccountingDb.Invoice.Load();

                AccountingDataView.DataSource = AccountingDb.Invoice.Local.ToBindingList();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString() + "\n\r");
            }
        }
Esempio n. 3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     try
     {
         int id = Convert.ToInt32(AccountingDataView.CurrentRow.Cells[0].Value);
         AccountingDb = new AccountingEntities1();
         Invoice client = AccountingDb.Invoice.Find(id);
         AccountingDb.Invoice.Remove(client);
         AccountingDb.SaveChanges();
         MessageBox.Show("Выбраная строка удалена. Нажмите Select что бы обновить список");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString() + "\n\r");
     }
 }
Esempio n. 4
0
 private void btnSearch_Click(object sender, EventArgs e)
 {
     try
     {
         AccountingDb = new AccountingEntities1();
         var search = from c in AccountingDb.Invoice
                      where c.Client == txtSearch.Text
                      select c;
         var bindingList = search.ToList();
         AccountingDataView.DataSource = bindingList;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString() + "\n\r");
     }
 }
Esempio n. 5
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                AccountingDB = new AccountingEntities1();
                Invoice Client = new Invoice();

                Client.Client = txtName.Text;
                Client.Date   = txtDate.Text;
                Client.Money  = Convert.ToDouble(txtMoney.Text);

                AccountingDB.Invoice.Add(Client);
                AccountingDB.SaveChanges();

                MessageBox.Show(string.Format("Клиент {0} добавлен в базу данных", txtName.Text));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString() + "\r\n");
            }
        }
Esempio n. 6
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            AccountingDB = new AccountingEntities1();

            if (txtOldName.Text != string.Empty)
            {
                try
                {
                    Invoice client = AccountingDB.Invoice.First(c => c.Client == txtOldName.Text);
                    if (txtNewDate.Text != string.Empty)
                    {
                        client.Date = txtNewDate.Text;
                    }
                    if (txtNewName.Text != string.Empty)
                    {
                        client.Client = txtNewName.Text;
                    }
                    if (txtNewMoney.Text != string.Empty)
                    {
                        client.Money = Convert.ToDouble(txtNewMoney.Text);
                    }
                    AccountingDB.SaveChanges();
                    MessageBox.Show(string.Format("Данные о пользователе {0} обновлены успешоно!!!", txtOldName.Text));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString() + "\r\n");
                }
            }
            else if (txtID.Text != string.Empty)
            {
                try
                {
                    int     id     = Convert.ToInt32(txtID.Text);
                    Invoice client = AccountingDB.Invoice.First(c => c.ID == id);
                    if (txtNewDate.Text != string.Empty)
                    {
                        client.Date = txtNewDate.Text;
                    }
                    if (txtNewName.Text != string.Empty)
                    {
                        client.Client = txtNewName.Text;
                    }
                    if (txtNewMoney.Text != string.Empty)
                    {
                        client.Money = Convert.ToDouble(txtNewMoney.Text);
                    }
                    AccountingDB.SaveChanges();
                    MessageBox.Show(string.Format("Данные о пользователе с ID {0} обновлены успешоно!!!", txtID.Text));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString() + "\r\n");
                }
            }
            else if (txtID.Text != string.Empty && txtOldName.Text != string.Empty)
            {
                try
                {
                    int     id     = Convert.ToInt32(txtID.Text);
                    Invoice client = AccountingDB.Invoice.First(c => c.ID == id);
                    if (txtNewDate.Text != string.Empty)
                    {
                        client.Date = txtNewDate.Text;
                    }
                    if (txtNewName.Text != string.Empty)
                    {
                        client.Client = txtNewName.Text;
                    }
                    if (txtNewMoney.Text != string.Empty)
                    {
                        client.Money = Convert.ToDouble(txtNewMoney.Text);
                    }
                    AccountingDB.SaveChanges();
                    MessageBox.Show(string.Format("Данные о пользователе {0} обновлены успешоно!!!", txtOldName.Text));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString() + "\r\n");
                }
            }
            else
            {
                MessageBox.Show("Введите имя или ID пользователя!!!");
            }
        }