Example #1
0
        public void CreateItem()
        {
            MySqlTransaction transaction = null;

            try {
                using (MySqlConnection connection = this._connection.GetConnection())
                {
                    using (transaction = connection.BeginTransaction())
                    {
                        ItemRepository itemRepository = new ItemRepository(this._connection, this._items);
                        switch (ItemExist())
                        {
                        case true:
                            Console.WriteLine("Item exist.");
                            itemRepository.UpdateItem();
                            Console.WriteLine("Item Quantity Updated.");
                            break;

                        case false:
                            Console.WriteLine("New Item.");
                            itemRepository.InsertItem();
                            Console.WriteLine("Item Details Created.");
                            break;

                        default:
                            break;
                        }
                        this._receipt.ItemId = itemRepository.LastInsertID;

                        ReceiptRepository receiptRepository = new ReceiptRepository(this._connection, this._receipt);
                        receiptRepository.InsertReceipt();
                        Console.WriteLine("Item receipts saved");
                        if (_items.HasSerial == 1)
                        {
                            SerialRepository serialRepository = new SerialRepository(this._connection, _serial_list);
                            serialRepository.InsertSerial();
                            Console.WriteLine("Serial Numbers saved.");
                        }
                        Console.WriteLine("Commit to DB");
                        transaction.Commit();
                    }
                }
            }
            catch (MySqlException ex) {
                transaction.Rollback();
                throw new ArgumentException(ex.ToString());
            }
            catch (Exception ex) {
                throw new ArgumentException(ex.Source);
            }
        }
Example #2
0
        private void CreateItemDetails()
        {
            itemRepository = new ItemRepository(_items);
            switch (itemRepository.itemExist())
            {
            case true:
                itemRepository.UpdateItem();
                break;

            case false:
                itemRepository.InsertItem();
                break;

            default:
                //
                break;
            }
        }
        private void btn_update_Click(object sender, EventArgs e)
        {
            try {
                Items items = new Items()
                {
                    Id            = _item_id,
                    CategoryId    = int.Parse(metroComboBox1.SelectedValue.ToString()),
                    SubCategoryId = int.Parse(metroComboBox2.SelectedValue.ToString()),
                    Model         = txt_model.Text,
                    Brand         = txt_brand.Text
                };
                ItemRepository itemRepository = new ItemRepository(items);
                itemRepository.UpdateItem();

                MessageBox.Show("Changes Has Been Saved");
                _item_list.Items();
                this.Close();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }