Beispiel #1
0
        //private void dataGridView2_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        //{


        //    if (dataGridView2.CurrentCell.ColumnIndex == 0)
        //    {
        //        // Check box column
        //        comboBox2 = e.Control as ComboBox;

        //        comboBox2.SelectedIndexChanged += new EventHandler(comboBox2_SelectedIndexChanged);

        //    }
        //}

        //void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    int selectedIndex = ((ComboBox)sender).SelectedIndex;
        //    //MessageBox.Show(selectedIndex.ToString());
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            Item      item       = new Item();
            DataTable _itemDT    = item.SelectTempItems();
            int       item_count = 0;

            if (dataGridView2.Rows.Count != 0)
            {
                //check comboboxes on datagrid if set to an item id
                for (int i = 0; i < dataGridView2.Rows.Count; i++)
                {
                    if (int.Parse(dataGridView2.Rows[i].Cells[0].Value.ToString()) == 0)
                    {
                        dataGridView2.Rows[i].Selected = true;
                        MessageBox.Show("Please select an Item on the selected row");
                        return;
                    }
                }
                //check if number of serial numbers matched the quantity of items on item grid
                foreach (DataRow itemDr in _itemDT.Rows)
                {
                    foreach (DataGridViewRow serialDgv in dataGridView2.Rows)
                    {
                        if (itemDr[0].ToString() == serialDgv.Cells[0].Value.ToString())
                        {
                            item_count++;
                        }
                    }
                    if (item_count.Equals(int.Parse(itemDr["quantity"].ToString())) || item_count.Equals(0))
                    {
                        item_count = 0;
                        //return;
                    }
                    else
                    {
                        MessageBox.Show("Please provide the correct quantity of Serial Numbers");
                        return;
                    }
                }
            }
            if (dataGridView1.Rows.Count == 0)
            {
                MessageBox.Show("No Items has been added");
                return;
            }
            // insert item on database
            try
            {
                foreach (DataRow row in _itemDT.Rows)
                {
                    //MessageBox.Show(row["item_id"].ToString());
                    if (int.Parse(row["item_id"].ToString()) == 0)
                    {
                        item.CategoryId    = int.Parse(row["category_id"].ToString());
                        item.SubCategoryId = int.Parse(row["sub_category_id"].ToString());
                        item.Brand         = row["brand"].ToString();
                        item.Model         = row["model"].ToString();
                        item.Description   = row["description"].ToString();
                        item.AddNewItem();
                        item_id = int.Parse(item.LastInsertedId().ToString());
                    }
                    else
                    {
                        item_id = int.Parse(row["item_id"].ToString());
                    }
                    //Add Receipts
                    Receipt receipt = new Receipt();
                    receipt.ItemId          = item_id;
                    receipt.VendorId        = int.Parse(metroComboBox1.SelectedValue.ToString());
                    receipt.OfficialReceipt = textBox1.Text;
                    receipt.Price           = double.Parse(row["price"].ToString());
                    receipt.Quantity        = int.Parse(row["quantity"].ToString());
                    DateTime datePurchased = Convert.ToDateTime(dateTimePicker1.Value.Date.ToString());
                    receipt.DatePurchased = datePurchased;
                    DateTime dateWarranty = Convert.ToDateTime(row["warranty"].ToString());
                    receipt.WarrantyDate = dateWarranty;
                    receipt.ItemReceipt();
                    int item_receipt = int.Parse(receipt.LastInsertedId().ToString());
                    //Add Serial Numbers Per Item//
                    foreach (DataGridViewRow rows in dataGridView2.Rows)
                    {
                        if (rows.Cells[0].Value.ToString() == row[0].ToString())
                        {
                            Serial serial = new Serial();
                            serial.ItemId       = item_id;
                            serial.ReceiptId    = item_receipt;
                            serial.SerialNumber = rows.Cells[1].Value.ToString();
                            serial.AddSerial();
                        }
                    }
                }
                MessageBox.Show("Item(s) has been saved");
                dataGridView1.DataSource = null;
                dataGridView2.Rows.Clear();
                textBox1.Clear();
                metroComboBox1.SelectedIndex = 0;
                item.DeleteTempItems();
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //create an Instance of Item Class
            Item item = new Item();

            //Save New Item
            try {
                if (_item_id == 0)
                {
                    item.CategoryId    = int.Parse(cb_cat.SelectedValue.ToString());
                    item.SubCategoryId = int.Parse(cb_sub_cat.SelectedValue.ToString());
                    item.Brand         = txt_brand.Text;
                    item.Model         = txt_model.Text;
                    item.CreateNewItem();
                    _id = int.Parse(item.LastInsertedId().ToString());
                    //MessageBox.Show(_id.ToString());
                }
                else
                {
                    _id = _item_id;
                }
                //Save Receipt
                Receipt receipt = new Receipt();
                receipt.ItemId          = this._id;
                receipt.VendorId        = int.Parse(cb_vendors.SelectedValue.ToString());
                receipt.OfficialReceipt = txt_or.Text;
                receipt.Price           = double.Parse(txt_price.Text);
                receipt.Quantity        = int.Parse(txt_quantity.Text);
                //receipt.ItemCondition = int.Parse()
                receipt.DatePurchased = this.dateTimePicker1.Value;
                receipt.WarrantyDate  = this.dateTimePicker2.Value;
                receipt.ItemReceipt();
                //receipt.LastInsertedId();
                //Add Serial
                if (!string.IsNullOrWhiteSpace(txt_serial.Text) && txt_quantity.Text.Equals("1"))
                {
                    Serial serial = new Serial();
                    serial.ItemId = _id;
                    //  serial.ReceiptId = int.Parse(receipt.LastInsertedId().ToString());
                    serial.SerialNumber = txt_serial.Text;
                    serial.AddSerial();
                }
                MessageBox.Show("New Item Saved");
                this.cb_cat.SelectedIndex     = 0;
                this.cb_sub_cat.SelectedIndex = 0;
                this.cb_vendors.SelectedIndex = 0;
                this.txt_brand.Clear();
                this.txt_model.Clear();
                this.txt_desc.Clear();
                this.txt_or.Clear();
                this.txt_quantity.Clear();
                this.txt_price.Clear();
                this.txt_serial.Clear();
                this.cb_cat.Enabled     = true;
                this.cb_sub_cat.Enabled = true;
                this.txt_brand.Enabled  = true;
                this.txt_desc.Enabled   = true;
                this.txt_model.Enabled  = true;
                this._item_id           = 0;
                this._id = 0;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }