private void existingcategorieslist_SelectedIndexChanged(object sender, EventArgs e)
        {
            var i            = existingcategorieslist.GetItemText(existingcategorieslist.SelectedItem);
            var categoryname = i;

            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                //var products = dbCtx.products.ToList(x => x. == categoryname);
                var products = (from d in dbCtx.categories
                                join p in dbCtx.products on
                                d.CategoryID equals p.CategoryID
                                where d.CategoryName == categoryname
                                select new { ProductName = p.ProductName }).ToList();

                if (products != null)
                {
                    int a = 0;
                    existingproductlist.Items.Clear();
                    foreach (var item in products)
                    {
                        existingproductlist.Items.Add(item.ProductName);
                        if (a == 0)
                        {
                            existingproductlist.Text = item.ProductName;
                        }
                        a += 1;
                    }
                }
            }
        }
예제 #2
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            var suppliername = selectedSupplierName;

            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                var item = dbCtx.suppliers.SingleOrDefault(x => x.SupplierName == suppliername);
                if (item != null && suppliername.CompareTo(item.SupplierName) == 0)
                {
                    supplier c = (from x in dbCtx.suppliers
                                  where x.SupplierName == suppliername
                                  select x).First();
                    c.SupplierName    = SupplierNameField.Text;
                    c.SupplierAddress = SupplierAddressField.Text;
                    c.ContactName     = ContactPersonNameField.Text;
                    c.ContactNumber   = ContactPersonNumberField.Text;
                    dbCtx.SaveChanges();
                    MessageBox.Show("Changes Updated Successfully.");
                }
                else if (item == null)
                {
                    supplier c = (from x in dbCtx.suppliers
                                  where x.SupplierName == SupplierNameField.Text
                                  select x).SingleOrDefault();
                    if (c == null)
                    {
                        if (SupplierNameField.Text.Length > 0 && ContactPersonNameField.Text.Length > 0)
                        {
                            var r = new Model.supplier
                            {
                                SupplierName    = SupplierNameField.Text,
                                ContactName     = ContactPersonNameField.Text,
                                ContactNumber   = ContactPersonNumberField.Text,
                                SupplierAddress = SupplierAddressField.Text
                            };
                            dbCtx.suppliers.Add(r);
                            // call SaveChanges method to save student into database
                            dbCtx.SaveChanges();
                            MessageBox.Show("New Supplier " + SupplierNameField.Text + " Added.");
                            SuccessfulSupplierAddition();
                        }
                        else
                        {
                            MessageBox.Show("Please enter New supplier name and contact person name.");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Supplier with the same name already exists.");
                    }
                }
            }

            LoadExistingSuppliers();
        }
예제 #3
0
 public void deleteSupplier(string supplierName)
 {
     using (var dbCtx = new POSApplication.Model.posdbEntities())
     {
         var itemToRemove = dbCtx.suppliers.First(x => x.SupplierName == supplierName);
         if (itemToRemove != null)
         {
             dbCtx.suppliers.Remove(itemToRemove);
             dbCtx.SaveChanges();
             MessageBox.Show("Supplier Deleted.");
         }
     }
 }
        private void SuppliersList_SelectedIndexChanged(object sender, EventArgs e)
        {
            var supplierName = SuppliersList.GetItemText(SuppliersList.SelectedItem);

            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                var item = dbCtx.suppliers.SingleOrDefault(x => x.SupplierName == supplierName);
                if (item != null)
                {
                    SupplierContactLabel.Text = item.ContactNumber;
                }
            }
        }
 public int getProductID2(string productName)
 {
     using (var db = new POSApplication.Model.posdbEntities())
     {
         var query = (from c in db.products
                      where c.ProductName == productName
                      select new { ProductID = c.ProductID }).SingleOrDefault();
         if (query != null)
         {
             return(query.ProductID);
         }
     }
     return(0);
 }
예제 #6
0
        public void LoadExistingSuppliers()
        {
            SuppliersList.Items.Clear();
            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                var query = from d in dbCtx.suppliers
                            select new { SupplierName = d.SupplierName };

                foreach (var r in query)
                {
                    SuppliersList.Items.Add(r.SupplierName);
                }
            }
        }
        public void LoadSuppliersComboBox()
        {
            using (var db = new POSApplication.Model.posdbEntities())
            {
                var query = (from c in db.suppliers
                             select new { SupplierName = c.SupplierName, ContactNumber = c.ContactNumber }).ToList();

                SuppliersList.Items.Clear();
                foreach (var item in query)
                {
                    SuppliersList.Items.Add(item.SupplierName);
                }
            }
        }
        public void SetFieldBasedOnProduct(string selectedProductName)
        {
            using (var db = new POSApplication.Model.posdbEntities())
            {
                var a = (from p in db.products
                         where p.ProductName == selectedProductName
                         select new { ProductID = p.ProductID, BarCode = p.Barcode, ImagePath = p.ImageFileName }).SingleOrDefault();

                var q = (from d in db.inventories
                         where a.ProductID == d.ProductID && d.UpdateDt == null
                         select new { Quantity = d.Quantity, LastCostPrice = d.PurchasePrice, SalePrice = d.SalePrice, PurchaseDate = d.PurchaseDate, Barcode = a.BarCode, ImagePath = a.ImagePath }).SingleOrDefault();

                //var sumquantity = from r in db.inventories
                //                  where
                //                  group r by new
                //                  {
                //                      r.ProductID
                //                  } into g
                //                  select new
                //                  {
                //                      g.Key.ProductID,
                //                      SumQuantity = g.Sum(x => x.Quantity)
                //                  }.SumQuantity;

                if (a != null)
                {
                    if (a.ImagePath != null)
                    {
                        try
                        {
                            FileStream fs = new FileStream(q.ImagePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                            ProductImage.Image = Image.FromStream(fs);
                            fs.Close();
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("File is missing. Please reset the image for the product.");
                        }
                    }

                    QuantityField.Text = q.Quantity.ToString();
                    //ReOrderLevelField.Text = q.ReOrderLevel.ToString();
                    CostPriceField.Text    = q.LastCostPrice.ToString();
                    SalePriceField.Text    = q.SalePrice.ToString();
                    PurchaseDateField.Text = q.PurchaseDate.ToString();
                }
            }
        }
예제 #9
0
        private void SuppliersList_DoubleClick(object sender, EventArgs e)
        {
            string supplierName = SuppliersList.GetItemText(SuppliersList.SelectedItem);

            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                var item = dbCtx.suppliers.First(x => x.SupplierName == supplierName);
                if (item != null)
                {
                    SupplierNameField.Text        = item.SupplierName;
                    ContactPersonNameField.Text   = item.ContactName;
                    ContactPersonNumberField.Text = item.ContactNumber;
                    SupplierAddressField.Text     = item.SupplierAddress;
                    //setting global field
                    selectedSupplierName = item.SupplierName;
                }
            }
        }
        public void LoadExistingCategories()
        {
            using (var db = new POSApplication.Model.posdbEntities())
            {
                var query = (from d in db.categories
                             select new { CategoryName = d.CategoryName }).ToList();

                ExistingCategoryList.Items.Clear();
                int a = 0;
                foreach (var item in query)
                {
                    if (a == 0)
                    {
                        ExistingCategoryList.Text = "Select Category";
                    }
                    ExistingCategoryList.Items.Add(item.CategoryName);
                    a += 1;
                }
            }
        }
        public decimal?getPurchasePrice(int productID)
        {
            int purchasePrice = 0;

            using (var db = new POSApplication.Model.posdbEntities())
            {
                var query = (from c in db.inventories
                             where c.ProductID == productID && c.UpdateDt == null
                             orderby c.UpdateDt descending
                             select new { PurchasePrice = c.SalePrice }).FirstOrDefault();
                if (query == null)
                {
                    return(purchasePrice);
                }
                else
                {
                    return(query.PurchasePrice);
                }
                return(purchasePrice);
            }
        }
        private void ExistingCategoryList_SelectedIndexChanged(object sender, EventArgs e)
        {
            var SelectedCategory = ExistingCategoryList.GetItemText(ExistingCategoryList.SelectedItem);

            using (var db = new POSApplication.Model.posdbEntities())
            {
                var query = (from d in db.products
                             join c in db.categories on
                             d.CategoryID equals c.CategoryID
                             where c.CategoryName == SelectedCategory
                             select new
                {
                    CategoryName = c.CategoryName,
                    ProductName = d.ProductName
                }).ToList();
                ExistingProductsList.Items.Clear();
                foreach (var item in query)
                {
                    ExistingProductsList.Items.Add(item.ProductName);
                }
            }
        }
        public void loadProductsList()
        {
            using (var db = new POSApplication.Model.posdbEntities())
            {
                //var catID = (from c in db.categories
                //             where c.CategoryName == categoryname
                //             select new { CategoryID = c.CategoryID }).SingleOrDefault();

                var query = (from c in db.products
                             join p in db.inventories on c.ProductID equals p.ProductID
                             where p.UpdateDt == null
                             //&& c.CategoryID == catID.CategoryID
                             select new
                {
                    c.ProductName,
                    p.PurchasePrice,
                    c.ProductID,
                    p.SalePrice,
                    //p.TaxPaid,
                    c.Barcode,
                    c.ProductCode
                }).ToList();

                var query2 = query.GroupBy(p => p.ProductID).Select(a => a.First()).ToList();

                productPrices = new List <ProductPrices>();
                foreach (var d in query)
                {
                    var item = new ProductPrices(d.ProductName, d.PurchasePrice, d.SalePrice,
                                                 d.ProductID,
                                                 //d.TaxPaid,
                                                 d.Barcode,
                                                 d.ProductCode);
                    productPrices.Add(item);
                }
                LoadProductComboBox();
            }
        }
 public int getProductID(string productName)
 {
     try
     {
         using (var db = new POSApplication.Model.posdbEntities())
         {
             var query = (from d in db.products
                          //join  s in db.suppliers on
                          //d.SupplierID equals s.SupplierID
                          where d.ProductName == productName
                          select new
             {
                 productid = d.ProductID
             }).SingleOrDefault();
             return(query.productid);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
     return(0);
 }
        private void ExistingProductsList_DoubleClick(object sender, EventArgs e)
        {
            if (ExistingProductsList.SelectedItem != null)
            {
                clearFields();
                using (var db = new POSApplication.Model.posdbEntities())
                {
                    var ExistingProduct = ExistingProductsList.GetItemText(ExistingProductsList.SelectedItem);
                    int productid       = getProductID(ExistingProduct);
                    selectedProductName = ExistingProduct;
                    DateTime lowdate = DateTime.Parse("1111/11/11");
                    var      query   = (from d in db.inventories
                                        join p in db.products on
                                        d.ProductID equals p.ProductID
                                        join c in db.categories on
                                        p.CategoryID equals c.CategoryID
                                        where d.ProductID == productid && d.UpdateDt == null
                                        orderby d.PurchasePrice descending
                                        select new
                    {
                        CategoryName = c.CategoryName,
                        ProductName = p.ProductName,
                        Barcode = p.Barcode,
                        Quantity = d.SumQuantity,
                        //ReorderLevel = d.ReorderValue,
                        LastCostPrice = d.PurchasePrice,
                        SalePrice = d.SalePrice,
                        LastPurchaseDate = d.PurchaseDate,
                        Imagepath = p.ImageFileName
                    }).FirstOrDefault();
                    CategoryList.Text     = ExistingCategoryList.GetItemText(ExistingCategoryList.SelectedItem);
                    ProductNameField.Text = query.ProductName;
                    BarCodeField.Text     = query.Barcode;

                    var results =
                        (from item in db.inventories
                         where item.ProductID == productid && item.UpdateDt == null
                         group item by item.ProductID into g
                         select new { totalQuantity = g.Sum(item => item.SumQuantity) }).SingleOrDefault();

                    //QuantityField.Text = query.Quantity.ToString();
                    QuantityField.Text = results.totalQuantity.ToString();
                    //ReOrderLevelField.Text = query.ReorderLevel.ToString();
                    CostPriceField.Text    = query.LastCostPrice.ToString();
                    SalePriceField.Text    = query.SalePrice.ToString();
                    PurchaseDateField.Text = query.LastPurchaseDate.ToString();

                    if (query.Imagepath != null)
                    {
                        try
                        {
                            string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images");
                            Console.WriteLine(ImagesDirectory + "\\" + query.Imagepath);
                            FileStream fs = new FileStream(ImagesDirectory + "\\" + query.Imagepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                            ProductImage.Image = Image.FromStream(fs);
                            fs.Close();
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
        public void RecordSale(int checkoutOrHold, string modeOfPayment)
        {
            decimal discount   = 0;
            decimal taxapplied = 0;

            if (AmountPaidField.Text.Length > 0)
            {
                try
                {
                    var amountpaid = Decimal.Parse(AmountPaidField.Text);
                    var total      = Decimal.Parse(TotalSaleField.Text);
                    BalanceField.Text = decimal.Round(amountpaid - total, 2).ToString();
                    if (total <= amountpaid)
                    {
                        decimal balance = amountpaid - total;

                        //start creating db records
                        using (var db = new POSApplication.Model.posdbEntities())
                        {
                            if (TotalDiscountField.Text.Length > 0)
                            {
                                try
                                {
                                    discount = Decimal.Parse(TotalDiscountField.Text);
                                }
                                catch (Exception e1)
                                {
                                    MessageBox.Show(@"Enter numeric value for Discount");
                                }
                            }
                            if (TaxAppliedField.Text.Length > 0)
                            {
                                try
                                {
                                    taxapplied = Decimal.Parse(TaxAppliedField.Text);
                                }
                                catch (Exception e1)
                                {
                                    MessageBox.Show(@"Enter numeric value for Tax");
                                }
                            }
                            total = total + (total * (taxapplied / 100));
                            total = total - (total * (discount / 100));

                            BalanceField.Text = balance.ToString();
                            var so = new purchasesorder {
                                AmountPaid = amountpaid
                            };
                            currentSaleObject.AmountPaid = amountpaid;
                            so.Balance = balance;
                            currentSaleObject.Balance = decimal.Round((decimal)balance, 2);
                            so.Discount = discount;
                            currentSaleObject.Discount   = discount;
                            so.ModeOfPayment             = modeOfPayment;
                            so.PurchaseAmount            = Decimal.Parse(TotalSaleField.Text);
                            currentSaleObject.SaleAmount = decimal.Round((decimal)so.PurchaseAmount, 2);

                            //so.SaleDate = DateTime.Now.Date;
                            so.PurchaseDate = dateTimePicker1.Value.Date;
                            //so.Date_dateofmonth_int = DateTime.Now.Day;
                            so.Date_dateofmonth_int = dateTimePicker1.Value.Day;
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Sunday)
                            {
                                so.Date_Dayofweek_int = 7;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Monday)
                            {
                                so.Date_Dayofweek_int = 1;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Tuesday)
                            {
                                so.Date_Dayofweek_int = 2;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Wednesday)
                            {
                                so.Date_Dayofweek_int = 3;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Thursday)
                            {
                                so.Date_Dayofweek_int = 4;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Friday)
                            {
                                so.Date_Dayofweek_int = 5;
                            }
                            if (DateTime.Now.DayOfWeek == DayOfWeek.Saturday)
                            {
                                so.Date_Dayofweek_int = 6;
                            }
                            //so.Date_DayofWeek_string = DateTime.Now.DayOfWeek.ToString();
                            so.Date_DayofWeek_string = dateTimePicker1.Value.DayOfWeek.ToString();
                            //so.date_month_int = DateTime.Now.Month;
                            so.date_month_int = dateTimePicker1.Value.Month;

                            if (DateTime.Now.Month == 1)
                            {
                                so.date_month_string = "January";
                            }
                            if (DateTime.Now.Month == 2)
                            {
                                so.date_month_string = "February";
                            }
                            if (DateTime.Now.Month == 3)
                            {
                                so.date_month_string = "March";
                            }
                            if (DateTime.Now.Month == 4)
                            {
                                so.date_month_string = "April";
                            }
                            if (DateTime.Now.Month == 5)
                            {
                                so.date_month_string = "May";
                            }
                            if (DateTime.Now.Month == 6)
                            {
                                so.date_month_string = "June";
                            }
                            if (DateTime.Now.Month == 7)
                            {
                                so.date_month_string = "July";
                            }
                            if (DateTime.Now.Month == 8)
                            {
                                so.date_month_string = "August";
                            }
                            if (DateTime.Now.Month == 9)
                            {
                                so.date_month_string = "September";
                            }
                            if (DateTime.Now.Month == 10)
                            {
                                so.date_month_string = "October";
                            }
                            if (DateTime.Now.Month == 11)
                            {
                                so.date_month_string = "November";
                            }
                            if (DateTime.Now.Month == 12)
                            {
                                so.date_month_string = "December";
                            }

                            so.date_year_int = dateTimePicker1.Value.Year;
                            so.time_hour     = int.Parse(dateTimePicker1.Value.Hour.ToString());

                            so.PurchaseTime = dateTimePicker1.Value.TimeOfDay;
                            so.UserName     = AppConfig.loggedInUserName;

                            //setting the status to checkout or hold sale.
                            so.PurchaseStatus = checkoutOrHold;
                            so.TaxPercentage  = taxapplied;
                            currentSaleObject.TaxPercentage = taxapplied;
                            so.TerminalID = AppConfig.TerminalID;

                            //recording the purchase as purchase on hold
                            if (checkoutOrHold == 1)
                            {
                                so.HoldInvoice = 1;
                            }
                            else
                            {
                                so.HoldInvoice = 0;
                            }

                            so.InvoiceID = OrderIDField.Text;

                            db.purchasesorders.Add(so);
                            db.SaveChanges();
                            //Adding purchase Items
                            int orderid = so.OrderID;
                            foreach (var item in currentSaleObject.SaleItems)
                            {
                                decimal tax           = item.TaxPercentage / 100;
                                decimal purchaseprice = (item.PriceApplied * tax) + item.PriceApplied;
                                decimal itemdiscount  = item.Discount / 100;
                                purchaseprice = (purchaseprice * itemdiscount) + purchaseprice;
                                var s = new purchasesorderdetail
                                {
                                    ProductID     = item.ProductID,
                                    InvoiceID     = OrderIDField.Text,
                                    Discount      = item.Discount,
                                    PurchasePrice = item.PriceApplied,
                                    Quantity      = item.Quantity
                                };
                                s.PurchasePrice = purchaseprice;
                                s.TaxPercentage = item.TaxPercentage;
                                db.purchasesorderdetails.Add(s);
                                db.SaveChanges();

                                //////////////////////////////////////////////////////////////////////////////////
                                //closing previous inventory record.
                                //////////////////////////////////////////////////////////////////////////////////
                                Model.inventory c = (from x in db.inventories
                                                     where (x.ProductID == item.ProductID && x.UpdateDt == null && x.PurchasePrice == purchaseprice || (x.ProductID == item.ProductID && x.UpdateDt == null && x.PurchasePrice == 0 && x.SalePrice == 0))
                                                     select x).SingleOrDefault();

                                if (c != null)
                                {
                                    c.UpdateDt = dateTimePicker1.Value;
                                    db.SaveChanges();

                                    decimal existingQuantity;
                                    if (c.SumQuantity != null)
                                    {
                                        existingQuantity = (decimal)c.SumQuantity;
                                    }
                                    else
                                    {
                                        existingQuantity = 0;
                                    }

                                    var inv = new inventory
                                    {
                                        ProductID     = item.ProductID,
                                        CreateDt      = dateTimePicker1.Value,
                                        PurchaseDate  = dateTimePicker1.Value,
                                        PurchasePrice = purchaseprice,
                                        Quantity      = item.Quantity,
                                        //TaxPaid = item.TaxPercentage,
                                        //ReorderValue = c.ReorderValue,
                                        UpdateDt      = null,
                                        PackingTypeID = null,
                                        SumQuantity   = existingQuantity + item.Quantity,
                                        SalePrice     = c.SalePrice,
                                        InvoiceID     = so.InvoiceID
                                    };
                                    db.inventories.Add(inv);
                                    db.SaveChanges();
                                }
                                else
                                {
                                    decimal existingQuantity = 0;
                                    var     d = (from x in db.inventories
                                                 where x.ProductID == item.ProductID && x.UpdateDt == null
                                                 select x).FirstOrDefault();


                                    var inv = new inventory
                                    {
                                        ProductID     = item.ProductID,
                                        CreateDt      = dateTimePicker1.Value,
                                        PurchaseDate  = dateTimePicker1.Value,
                                        PurchasePrice = purchaseprice,
                                        Quantity      = item.Quantity,
                                        UpdateDt      = null,
                                        PackingTypeID = null,
                                        SumQuantity   = existingQuantity + item.Quantity,
                                        SalePrice     = 0,
                                        InvoiceID     = so.InvoiceID
                                    };
                                    db.inventories.Add(inv);
                                    db.SaveChanges();
                                }
                            }
                            /////////////////////////////////////////////////////////////////////

                            /////////////////////////////////////////////////////////////////////


                            if (checkoutOrHold == 1)
                            {
                                MessageBox.Show(@"Purchase is put on HOLD. You can open the Purchases on hold again from Invoices Form.");
                            }
                            else
                            {
                                PrintPage();

                                currentSaleObject           = new SaleClass();
                                currentSaleObject.SaleItems = new List <SaleItemClass>();
                                SaleItemsList.DataSource    = null;
                                SaleItemsList.Refresh();
                                clearFields();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"Amount Paid Value should be larger or equal to Total");
                    }
                }
                catch (Exception e1)
                {
                    MessageBox.Show(@"Enter numeric value for Amount Paid");
                }
            }
            else
            {
                MessageBox.Show(@"Enter value for Amount Paid");
            }
        }
        private void existingproductlist_DoubleClick(object sender, EventArgs e)
        {
            var i = existingproductlist.GetItemText(existingproductlist.SelectedItem);

            ProductList.Text = i.ToString();
            //loadProductsList(existingcategorieslist.GetItemText(existingcategorieslist.SelectedItem));

            //foreach (var item in productPrices)
            //{
            //    switch (item.productName.CompareTo(i))
            //    {
            //        case 0:
            //            QuantityField.Text = @"1";
            //            continue;
            //    }
            //}

            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                var pinv = (from inv in dbCtx.inventories
                            join p in dbCtx.products on
                            inv.ProductID equals p.ProductID
                            where p.ProductName == i && inv.UpdateDt == null
                            select new
                {
                    ProductName = p.ProductName,
                    LastPurchasePrice = inv.PurchasePrice,
                    Barcode = p.Barcode,
                    ProductCode = p.ProductCode
                }).FirstOrDefault();
                if (pinv != null)
                {
                    QuantityField.Text = @"1";
                    PriceField.Text    = pinv.LastPurchasePrice.ToString();
                    if (pinv.Barcode != null)
                    {
                        BarCodeField.Text = pinv.Barcode;
                    }
                    else
                    {
                        BarCodeField.Text = "No Barcode";
                    }
                    if (pinv.ProductCode != null)
                    {
                        ProductCodeField.Text = pinv.ProductCode;
                    }
                    else
                    {
                        ProductCodeField.Text = "No Product Code";
                    }
                }
            }



            //using (var dbCtx = new POSApplication.Model.posdbEntities())
            //{
            //var products = (from p in dbCtx.products
            //                where p.ProductName == productName
            //                select new { ProductName = p.ProductName }).ToList();

            //if (products != null)
            //{
            //int a = 0;
            //existingproductlist.Items.Clear();
            //foreach (var item in products)
            //{
            //    existingproductlist.Items.Add(item.ProductName);
            //    if (a == 0)
            //        existingproductlist.Text = item.ProductName;
            //    a += 1;
            //}
            //}
            //}
        }
        public void UpdateChanges()
        {
            string categoryName = CategoryList.Text;
            string productName  = ProductNameField.Text;
            string ReOrderLevel = ReOrderLevelField.Text;
            string SalePrice    = SalePriceField.Text;

            if (SalePrice.Length == 0)
            {
                SalePrice = "0";
            }
            if (ReOrderLevel.Length == 0)
            {
                ReOrderLevel = "0";
            }

            if (productName.Length != 0)
            {
                using (var db = new POSApplication.Model.posdbEntities())
                {
                    var product = db.products.SingleOrDefault(x => x.ProductName == productName);

                    //Model.inventory c = (from x in db.inventories
                    //                     where x.ProductID == item.ProductID && x.UpdateDt == null
                    //                     && x.PurchasePrice == saleprice || x.PurchasePrice == 0
                    //                     select x).FirstOrDefault();
                    decimal salepricedecimalvalue = Decimal.Parse(SalePrice);
                    var     items = db.inventories.Where(
                        x => x.ProductID == product.ProductID && x.UpdateDt == null ||
                        (x.PurchasePrice == 0 && x.ProductID == product.ProductID && x.UpdateDt == null)
                        ).ToList();

                    foreach (var item in items)
                    {
                        item.UpdateDt = DateTime.Now;
                        db.SaveChanges();

                        var a = new inventory
                        {
                            ProductID     = item.ProductID,
                            CreateDt      = DateTime.Now,
                            SaleDate      = null,
                            PurchasePrice = item.PurchasePrice,
                            Quantity      = 0,
                            UpdateDt      = null,
                            PackingTypeID = null,
                            SumQuantity   = item.SumQuantity,
                            SalePrice     = Decimal.Parse(SalePrice),
                            InvoiceID     = null
                        };
                        db.inventories.Add(a);
                        db.SaveChanges();
                    }
                    db.SaveChanges();

                    //resetting the categories and products list to stop user from making changes.
                    clearFields();
                    MessageBox.Show("Changes Saved");
                }
            }
            else
            {
                //write something for the else condition
            }
        }
예제 #19
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            DateTime todayDate   = DateTime.Now;
            DateTime expirayDate = DateTime.Parse("12/12/2016");

            if (todayDate >= expirayDate)
            {
                MessageBox.Show("The License has expired. Please purchase a new license.");
            }
            else
            {
                string username = "";
                string password = "";
                string userrole = "";

                if (loginnamefield.Text.Length > 0)
                {
                    username = loginnamefield.Text;
                }
                if (PasswordField.Text.Length > 0)
                {
                    password = PasswordField.Text;
                }

                userrole = RoleCombo.Text;

                if (username.Length > 0)
                {
                    using (var dbCtx = new POSApplication.Model.posdbEntities())
                    {
                        bool userexists      = false;
                        bool passwordcorrect = false;
                        bool correctrole     = false;
                        //var query = (from t1 in dbCtx.posusers
                        //             join t2 in dbCtx.roles
                        //             on new { t1.RoleID } equals
                        //                 new { t2.RoleID }
                        //             where t2.RoleName == userrole && t1.UserName == username && t1.Password == password
                        //             select new { RoleName = t2.RoleName, UserName = t1.UserName, UserID = t1.UserID }).SingleOrDefault();

                        var query = (from t2 in dbCtx.posusers
                                     where t2.UserName == username
                                     select new { Password = t2.Password }).SingleOrDefault();

                        if (query != null)
                        {
                            userexists = true;
                        }
                        else
                        {
                            userexists = false;
                        }

                        if (userexists)
                        {
                            if (query.Password == password)
                            {
                                var query1 = (from p1 in dbCtx.posusers
                                              join p2 in dbCtx.roles
                                              on p1.RoleID equals
                                              p2.RoleID
                                              where p1.UserName == username
                                              select new { RoleName = p2.RoleName, UserName = p1.UserName, UserID = p1.UserID }).SingleOrDefault();
                                if (query1.RoleName == userrole)
                                {
                                    AppConfig.loggedInUserID   = query1.UserID;
                                    AppConfig.loggedInUserName = query1.UserName;
                                    AppConfig.loggedInUserRole = query1.RoleName;
                                    AppConfig.loginTime        = DateTime.Now;
                                    //AppConfig static class variables set now
                                    SuccessfulUserLogin();

                                    this.Hide();

                                    MainForm mf = new MainForm(this);
                                    mf.Show();

                                    //this.Close();
                                }
                                else
                                {
                                    MessageBox.Show("Invalid Role Selected.");
                                }
                            }
                            else
                            {
                                MessageBox.Show("Invalid Password.");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Invalid Username.");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Enter UserName.");
                }
            }
        }