Пример #1
0
 public void RegisterCustomer(Customer c)
 {
     try
     {
         if (PermissionController.CheckPermission(PermissionType.CUSTOMER_ADD))
         {
             if (Helper.MessageHelper.AlertRegisterConfirmation() == DialogResult.Yes)
             {
                 context.Customers.Add(c);
                 if (context.SaveChanges() == 1)
                 {
                     Helper.MessageHelper.AlertRegisterSuccess();
                 }
                 else
                 {
                     throw new Exception("Unknown Error Occured!");
                 }
             }
         }
         else
         {
             throw new Exception("Access Denied.!");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Пример #2
0
 public void Register(Employee emp)
 {
     try
     {
         if (emp.Name == "")
         {
             throw new Exception("Employee Name Cant be Empty");
         }
         else
         {
             if (emp.Mobile == "")
             {
                 emp.Mobile = "-";
             }
             if (emp.Address == "")
             {
                 emp.Address = "-";
             }
             if (Helper.MessageHelper.AlertRegisterConfirmation() == DialogResult.Yes)
             {
                 context.Employees.Add(emp);
                 context.SaveChanges();
             }
             else
             {
                 Helper.MessageHelper.AlertInfo("No Changes were made.");
             }
         }
     }
     catch (Exception ex)
     {
         Helper.MessageHelper.AlertError(ex.Message);
     }
 }
Пример #3
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are Sure Want to Continue!", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                sale.Representive = context.Employees.FirstOrDefault();
                sale.Customer     = customer;
                sale.Cashier      = SessionController.emp;
                try
                {
                    sale.Total      = decimal.Parse(txtTotal.Text);
                    sale.Discount   = decimal.Parse(txtDiscount.Text);
                    sale.GrandTotal = decimal.Parse(txtGrandTotal.Text);
                    sale.Balance    = decimal.Parse(txtBalance.Text);
                    sale.Paid       = decimal.Parse(txtPaid.Text);
                }
                catch (Exception exception)
                {
                }

                //First Deduct the stock
                foreach (var sd in SaleDetails)
                {
                    var xib = context.ProductBatches.FirstOrDefault(x => x.Id == sd.ProductBatch.Id);
                    xib.Stock = xib.Stock - sd.Qty;
                    context.SaveChanges();
                }


                //Add Sale Entry
                sale.SaleDetails = SaleDetails;
                context.Sales.Add(sale);
                context.SaveChanges();
            }

            if (MessageBox.Show("Do you want to print the receipt ?", "Print Bill", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                Reports.PosInvoice receipt = new Reports.PosInvoice();
                receipt.SetDatabaseLogon("cvpos", "CVPOS@1010809");
                receipt.RecordSelectionFormula = "{Sales.Id} = " + sale.Id;
                receipt.PrintToPrinter(1, false, 1, 1);
                ReportViewer viewer = new ReportViewer(receipt);
                viewer.TopMost = true;
                viewer.ShowDialog();
                reset();
            }
            else
            {
                reset();
            }
        }
Пример #4
0
 public void RegisterCategory(Category cat)
 {
     try
     {
         if (cat.Name != "")
         {
             if (Helper.MessageHelper.AlertRegisterConfirmation() == DialogResult.Yes)
             {
                 context.Categories.Add(cat);
                 context.SaveChanges();
                 Helper.MessageHelper.AlertRegisterSuccess();
             }
         }
         else
         {
             throw new Exception("Category Name Cannot be Empty.!");
         }
     }
     catch (Exception ex)
     {
         Helper.MessageHelper.AlertError(ex.Message);
     }
 }
Пример #5
0
 public void DeleteProduct(int id)
 {
     try
     {
         if (PermissionController.CheckPermission(PermissionType.PRODUCT_DELETE))
         {
             var p = context.Products.FirstOrDefault(x => x.Id == id);
             if (MessageHelper.AlertRemoveConfirmation() == DialogResult.Yes)
             {
                 context.Products.Remove(p);
                 context.SaveChanges();
             }
         }
         else
         {
             throw new Exception("Access Denied.! (PRODUCT_DELETE)");
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Пример #6
0
        public static bool Login(string username, string password)
        {
            try
            {
                if (username == "" || password == "")
                {
                    return(true);

                    throw new Exception("Username or Password Cannot be Empty!");
                }
                else
                {
                    var UserFromDB = context.Users.FirstOrDefault(x => x.Username == username);
                    if (UserFromDB == null)
                    {
                        throw new Exception("Username Cannot be Found!");
                    }
                    else
                    {
                        if (UserFromDB.IsActive == false)
                        {
                            throw new Exception("User is not Active!");
                        }
                        else
                        {
                            if (UserFromDB.Password == password)
                            {
                                UserFromDB.LastLogin = DateTime.Now;
                                SessionController.StartSession(UserFromDB.Employee, UserFromDB);
                                context.SaveChanges();
                                return(true);
                            }
                            else
                            {
                                throw new Exception("Invalid Username or Password!");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Helper.MessageHelper.AlertError(ex.Message);
                return(false);
            }
        }
Пример #7
0
        private void btnNew_Click(object sender, EventArgs e)
        {
            try
            {
                if (PermissionController.CheckPermission(PermissionType.PRODUCT_ADD))
                {
                    if (MessageHelper.AlertRegisterConfirmation() == DialogResult.Yes)
                    {
                        Product product = new Product();
                        product.Name         = txtName.Text;
                        product.Description  = txtDescription.Text;
                        product.Category     = (Category)cmbCategory.SelectedItem;
                        product.BarcodeData  = txtBarcode.Text;
                        product.ReOrderLevel = decimal.Parse(txtReOrder.Text);


                        ProductBatch batch = new ProductBatch();
                        batch.Cost   = CostCodeController.CodeToCost(txtCost.Text);
                        batch.Cash   = decimal.Parse(txtCash.Text);
                        batch.Credit = decimal.Parse(txtCredit.Text);
                        batch.Markup = decimal.Parse(txtMarkup.Text);
                        batch.Stock  = decimal.Parse(txtStock.Text);

                        if (product.BarcodeData == "")
                        {
                            context.Products.Add(product);
                            context.SaveChanges();
                            product.BarcodeData  = product.Id.ToString();
                            product.BarcodeImage = BarcodeController.GetBarcodeBytes(product.BarcodeData.ToString());
                            context.SaveChanges();
                            batch.Product = product;
                            context.ProductBatches.Add(batch);
                            context.SaveChanges();
                            MessageHelper.AlertRegisterSuccess();
                        }
                        else
                        {
                            context.Products.Add(product);
                            context.SaveChanges();
                            batch.Product = product;
                            context.ProductBatches.Add(batch);
                            context.SaveChanges();
                            MessageHelper.AlertRegisterSuccess();
                        }

                        if (MessageBox.Show("Do you want to print Labels", "Labels", MessageBoxButtons.YesNo) ==
                            DialogResult.Yes)
                        {
                            if (MessageBox.Show("Do you want to Double the Labels", "Labels", MessageBoxButtons.YesNo) ==
                                DialogResult.Yes)
                            {
                                BarcodeController.print_barcode(product.Id, int.Parse((batch.Stock * 2).ToString()));
                                // BarcodeController.print_barcode_preview(product.Id);
                            }
                            else
                            {
                                BarcodeController.print_barcode(product.Id, int.Parse(batch.Stock.ToString()));
                                //BarcodeController.print_barcode_preview(product.Id);
                            }
                        }

                        Helper.ClearForm.ClearAllTextFields(this);
                        txtDescription.Text = "-";
                        txtReOrder.Text     = "0";
                        txtName.Focus();
                    }
                }
                else
                {
                    throw new Exception("Access Denied! (PRODUCT_ADD)");
                }
            }
            catch (Exception ex)
            {
                MessageHelper.AlertError(ex.Message);
            }
        }
Пример #8
0
 public void update_stock()
 {
     context.SaveChanges();
 }