Beispiel #1
0
        private void populateGearTable()
        {
            DataTable gearTable = new DataTable();

            gearTable.Columns.Add("ID", typeof(int));
            gearTable.Columns.Add("Naziv", typeof(string));
            gearTable.Columns.Add("Proizvođač", typeof(string));
            gearTable.Columns.Add("Kategorija", typeof(string));
            gearTable.Columns.Add("Opis", typeof(string));
            gearTable.Columns.Add("Veličina", typeof(string));
            gearTable.Columns.Add("Ukupno", typeof(int));
            gearTable.Columns.Add("Dostupno", typeof(int));

            allGear = GearDAO.getAllDetailed();

            foreach (var g in allGear)
            {
                gearTable.Rows.Add(g.gear_id,
                                   g.name,
                                   g.manufacturer_name,
                                   g.gear_category_name,
                                   g.description,
                                   g.size_value,
                                   g.quantity,
                                   g.available
                                   );
            }

            dataGridViewGear.DataSource = gearTable;
            cBoxGearSearchCategory.Items.AddRange(GearDAO.getAllCategories().ToArray());
        }
Beispiel #2
0
        private void AddGearForm_Load(object sender, EventArgs e)
        {
            manufacturers     = GearDAO.getAllManufacturers();
            categories        = GearDAO.getAllCategories();
            gearSizes         = GearDAO.getAllSizes();
            gearItemsDetailed = GearDAO.getAllDetailed();

            cBoxGearName.Items.AddRange(gearItemsDetailed.ToArray());
            cBoxGearCategory.Items.AddRange(categories.ToArray());
            cBoxGearManufacturer.Items.AddRange(manufacturers.ToArray());
            cBoxGearSize.Items.AddRange(gearSizes.ToArray());
        }
Beispiel #3
0
        private void ReportGearTotalLoad()
        {
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable("Gear");

            dt.Columns.Add("gear_id");
            dt.Columns.Add("name");
            dt.Columns.Add("manufacturer_name");
            dt.Columns.Add("category");
            dt.Columns.Add("description");
            dt.Columns.Add("size");
            dt.Columns.Add("total");

            ds.Tables.Add(dt);

            List <gear_detailed> gears =
                GearDAO.getAllDetailed();

            foreach (var gear in gears)
            {
                DataRow dr = ds.Tables[0].NewRow();
                dr["gear_id"]           = gear.gear_id;
                dr["name"]              = gear.name;
                dr["manufacturer_name"] = gear.manufacturer_name;
                dr["category"]          = gear.gear_category_name;
                dr["description"]       = gear.description;
                dr["size"]              = gear.size_value;
                dr["total"]             = gear.quantity;


                ds.Tables[0].Rows.Add(dr);
            }

            rptGearTotal1.SetDataSource(ds);
            rptGearTotal1.SetParameterValue("pDateFrom", dateFrom.ToString("dd.MM.yyyy."));
            rptGearTotal1.SetParameterValue("pDateTo", dateTo.ToString("dd.MM.yyyy."));
            rptGearTotal1.SetParameterValue("pDatum", DateTime.Now.ToString("dd.MM.yyyy."));
            crystalReportViewer.ReportSource = rptGearTotal1;
            crystalReportViewer.Refresh();
        }
Beispiel #4
0
        private void btnAddGearConfirm_Click(object sender, EventArgs e)
        {
            //If gear has sizes new object is made for every item size

            //If gear already exists in database - just update quantity

            var validData = true;
            var exist     = false;

            String gn           = "";
            String desc         = "";
            var    gc           = new gear_category();
            var    gm           = new manufacturer();
            var    existingItem = new gear();


            if (cBoxGearName.SelectedIndex == -1)
            {
                if (string.IsNullOrEmpty(cBoxGearName.Text))
                {
                    lblGearNameError.Text = "*unijeti naziv opereme";
                    validData             = false;
                }
                else
                {
                    gn = cBoxGearName.Text.Trim();
                }
                if (cBoxGearCategory.SelectedIndex == -1)
                {
                    lblGearCategoryError.Text = "*unijeti kategoriju";
                    validData = false;
                }
                else
                {
                    gc = (gear_category)cBoxGearCategory.SelectedItem;
                }
                if (cBoxGearManufacturer.SelectedIndex == -1)
                {
                    lblGearManufacturerError.Text = "*izabrati proizvođača";
                    validData = false;
                }
                else
                {
                    gm = (manufacturer)cBoxGearManufacturer.SelectedItem;
                }
            }
            else
            {
                //User has selected existring gear item - change only quantity
                existingItem = (gear)cBoxGearName.SelectedItem;
                exist        = true;
            }

            if (validData)
            {
                if (checkBoxMultipleSizes.Enabled == true)
                {
                    //This category item have sizes

                    if (checkBoxMultipleSizes.Checked)
                    {
                        //Multiple sizes selected
                    }
                    else
                    {
                        //Only one size is selected
                        if (cBoxGearSize.SelectedIndex == -1)
                        {
                            lblGearSizeError.Text = "*izabrati veličinu";
                        }
                        else
                        {
                            if (!exist)
                            {
                                var gs = (gear_size)cBoxGearSize.SelectedItem;
                                var gq = Convert.ToInt32(nUpDownGearQuantity.Value);
                                desc = rTextBoxGearDescription.Text.Trim();

                                var newGear = new gear()
                                {
                                    gear_category_id = gc.gear_category_id,
                                    manufacturer_id  = gm.manufacturer_id,
                                    name             = gn,
                                    descritption     = desc
                                };
                                var insertedGearId = GearDAO.insert(newGear);

                                var newGearSizeItem = new gear_size_items()
                                {
                                    gear_id      = insertedGearId,
                                    gear_size_id = gs.gear_size_id,
                                    quantity     = gq,
                                    available    = gq
                                };
                                GearDAO.insertGearSizeItem(newGearSizeItem);
                            }
                            else
                            {
                                //Item already exists update it - if specific size doesn't exist create it
                                var gs            = (gear_size)cBoxGearSize.SelectedItem;
                                var gq            = Convert.ToInt32(nUpDownGearQuantity.Value);
                                var gearSizeItems = GearDAO.getAllSizesByGearId(existingItem.gear_id);

                                var updated = false;
                                foreach (var gsi in gearSizeItems)
                                {
                                    if (gsi.gear_size_id == gs.gear_size_id)
                                    {
                                        gsi.quantity  += gq;
                                        gsi.available += gq;
                                        updated        = GearDAO.updateGearSizeItem(gsi);
                                    }
                                }
                                if (!updated)
                                {
                                    //Create new size for item
                                    var newGearSizeItem = new gear_size_items()
                                    {
                                        gear_id      = existingItem.gear_id,
                                        gear_size_id = gs.gear_size_id,
                                        quantity     = gq,
                                        available    = gq
                                    };
                                    GearDAO.insertGearSizeItem(newGearSizeItem);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                //This category items have no sizes
                var gq = Convert.ToInt32(nUpDownGearQuantity.Value);
            }
        }