Exemple #1
0
        private void saveToDB()
        {
            invoice.customer_name  = customerNameBox.Text;
            invoice.customer_phone = phoneNoBox.Text;
            invoice.date           = datePicker.Value;
            invoice.total          = decimal.Parse(total.ToString());

            if (newModel)
            {
                DB.Invoices.InsertOnSubmit(invoice);
            }
            else
            {
                foreach (var item in invoice.Invoice_Products.ToList())
                {
                    invoice.Invoice_Products.Remove(item);
                }
            }

            DB.SubmitChanges();

            //Complex stuff done here for invoice products generation
            List <Database.Product> tempList = this.invoiceList;

            this.DistinctItems = tempList.GroupBy(test => test.Id)
                                 .Select(grp => grp.First())
                                 .ToList();

            foreach (var item in DistinctItems)
            {
                var duplicates = this.invoiceList.Where(p => p.Id == item.Id);

                var invoiceProduct = new Database.Invoice_Product();

                invoiceProduct.invoice_id = invoice.Id;
                invoiceProduct.product_id = item.Id;
                invoiceProduct.quantity   = duplicates.Count();

                DB.Invoice_Products.InsertOnSubmit(invoiceProduct);
            }

            DB.SubmitChanges();
        }
Exemple #2
0
        public bool confirm()
        {
            if (nameBox.Text.Count() > 0)
            {
                this.category.name = nameBox.Text;

                if (iconHolderBox.ImageLocation != category.icon)
                {
                    if (category.icon != null)
                    {
                        System.IO.File.Delete(category.icon);
                    }

                    string toFile = System.IO.Path.Combine(
                        Program.CAT_ICONS_DIR,
                        DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(iconHolderBox.ImageLocation)
                        );

                    System.IO.File.Copy(iconHolderBox.ImageLocation, toFile, true);
                    this.category.icon = toFile;
                }


                if (this.newModel == true)
                {
                    DB.Categories.InsertOnSubmit(category);
                }

                DB.SubmitChanges();

                return(true);
            }
            else
            {
                nameBox.Focus();
                return(false);
            }
        }
Exemple #3
0
        public bool confirm()
        {
            if (nameBox.Text.Count() > 0)
            {
                this.product.name   = nameBox.Text;
                product.name        = this.nameBox.Text;
                product.price       = decimal.Parse(this.priceBox.Text);
                product.image       = this.iconHolderBox.ImageLocation;
                product.description = this.descBox.Text;

                this.product.expiry_date = this.datePicker.Value;


                foreach (var item in DB.Categories)
                {
                    if (categoryDropDown.selectedIndex != -1)
                    {
                        if (item.name.Equals(categoryDropDown.selectedValue))
                        {
                            product.Category = item;
                        }
                    }
                }

                if (iconHolderBox.ImageLocation != product.image)
                {
                    if (product.image != null)
                    {
                        System.IO.File.Delete(product.image);
                    }

                    string toFile = System.IO.Path.Combine(
                        Program.PRO_IMAGES_DIR,
                        DateTime.Now.ToString("yyyyMMddHHmmss") + System.IO.Path.GetExtension(iconHolderBox.ImageLocation)
                        );

                    System.IO.File.Copy(iconHolderBox.ImageLocation, toFile, true);
                    this.product.image = toFile;
                }


                if (this.newModel == true)
                {
                    if (categoryDropDown.selectedIndex != -1)
                    {
                        DB.Products.InsertOnSubmit(product);
                    }
                    else
                    {
                        MessageBox.Show("Please Select A Cateogory", "Problem saving item",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                }

                DB.SubmitChanges();

                return(true);
            }
            else
            {
                nameBox.Focus();
                return(false);
            }
        }