public void UpdateCategory()
        {
            m_UIControl.lbl_CategoryError.Text = string.Empty;
            if (!Validate())
            {
                MessageBox.Show("Name cannot be empty!");
                return;
            }
            var category = DataService.GetCategoryDataController().GetByName(m_UIControl.tb_categoryName.Text);

            if (category != null)
            {
                m_UIControl.lbl_CategoryError.Text = "Category with same name already exists!";
                return;
            }
            CategoryPost categoryPost = new CategoryPost();

            categoryPost.ID          = int.Parse(m_UIControl.tb_ID.Text);
            categoryPost.Name        = m_UIControl.tb_categoryName.Text;
            categoryPost.Description = m_UIControl.tb_categoryDescription.Text;

            m_Category = DataService.GetCategoryDataController().Put(categoryPost);

            string message = (m_Category == null) ? "Failed to Update Category Details!" : "Category Details updated successfully!";

            MessageBox.Show(m_UIControl, message);

            // fire category update event
            Event_EntryUpdated e = new Event_EntryUpdated(DBEntityType.CATEGORY, m_Category.ID);

            EventBroadcaster.Get().BroadcastEvent(e);

            m_UIControl.Close();
        }
コード例 #2
0
        public async Task <ActionResult <ProductOut> > AddNewProduct(ProductIn productIN)
        {
            try
            {
                ProductDTO productDTO = new ProductDTO(productIN);
                m_Context.Products.Add(productDTO);
                await m_Context.SaveChangesAsync();

                productDTO = m_HttpController.CreatedAtAction("GetProduct", new { id = productDTO.ID }, productDTO).Value as ProductDTO;

                // Save image with IformFile
                UpdateImage(productDTO, productIN);

                await m_HttpController.PutProduct(productDTO.ID, productDTO);

                // Fire New product added event
                Event_NewProductAdded e = new Event_NewProductAdded(productDTO.ID);
                EventBroadcaster.Get().BroadcastEvent(e);

                return(new ProductOut(m_Context, productDTO));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                throw;
            }
        }
        public void UpdateVendor()
        {
            if (!ValidateVendorDetails())
            {
                return;
            }
            VendorPost vendorPost = new VendorPost();

            vendorPost.ID           = int.Parse(m_UIControl.tb_vendorId.Text.Trim());
            vendorPost.CompanyName  = m_UIControl.tb_companyName.Text.Trim();
            vendorPost.Address      = m_UIControl.tb_address.Text.Trim();
            vendorPost.Email        = m_UIControl.tb_email.Text.Trim();
            vendorPost.MobileNumber = m_UIControl.tb_mobileNumber.Text.Trim();
            vendorPost.City         = m_UIControl.tb_city.Text.Trim();
            vendorPost.State        = m_UIControl.tb_state.Text.Trim();

            var vendorGet = DataService.GetVendorDataController().Put(vendorPost);

            if (vendorGet == null)
            {
                Assert.Do("Failed to edit vendor");
                return;
            }
            MessageBox.Show("Vendor Updated Successfully");
            ResetTextBoxes();
            m_UIControl.DialogResult = DialogResult.OK;

            // fire vendor updated event
            Event_EntryUpdated e = new Event_EntryUpdated(DBEntityType.VENDOR, vendorGet.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }
        public void SavePurchase()
        {
            if (GetTable().Rows.Count <= 0)
            {
                return;
            }

            if (m_UIControl.cb_vendorName.SelectedIndex < 0)
            {
                m_UIControl.lbl_vendorError.Text = "Please select vendor!";
                return;
            }
            var vendorId = DataService.GetVendorDataController().GetByName(m_UIControl.cb_vendorName.Text.Trim()).ID;

            string productIds        = string.Empty;
            string productQuantities = string.Empty;
            string buyingPrices      = string.Empty;
            string discounts         = string.Empty;

            int i = 0;

            for (i = 0; i < GetTable().Rows.Count - 1; ++i)
            {
                productIds        += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_ProductId"].Value.ToString()) + ",";
                buyingPrices      += double.Parse(GetTable().Rows[i].Cells["PurchaseTable_PurchasePrice"].Value.ToString()) + ",";
                productQuantities += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_Quantity"].Value.ToString()) + ",";
                discounts         += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_DiscountRate"].Value.ToString()) + ",";
            }
            productIds        += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_ProductId"].Value.ToString());
            buyingPrices      += double.Parse(GetTable().Rows[i].Cells["PurchaseTable_PurchasePrice"].Value.ToString());
            productQuantities += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_Quantity"].Value.ToString());
            discounts         += int.Parse(GetTable().Rows[i].Cells["PurchaseTable_DiscountRate"].Value.ToString());

            PurchasePost purchasePost = new PurchasePost
            {
                PurchaseDateTime  = m_UIControl.purchase_dateTime.Value,
                VendorID          = vendorId,
                ProductIDs        = productIds,
                ProductQuantities = productQuantities,
                BuyingPrices      = buyingPrices,
                Discounts         = discounts
            };

            var purchase = DataService.GetPurchaseDataController().Post(purchasePost);

            //Update stock details
            UpdateStockDetails();

            if (purchase == null)
            {
                MessageBox.Show("Purchase entry failed! Please try saving again.");
                return;
            }
            MessageBox.Show("Purchase entry saved successfully!");
            ResetUIControls();

            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.PURCHASE, purchase.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }
コード例 #5
0
        public void UpdateProductDetails()
        {
            if (!ValidateProductDetails())
            {
                return;
            }

            string barcode = m_UIControl.tf_ProductDetails_Barcode.Text.Trim();

            if (CheckIfBarcodeAlreadyInUse(barcode))
            {
                m_UIControl.lbl_Error.Text = "This Barcode is already in use!";
                return;
            }

            string name = m_UIControl.tf_ProductDetails_ProductName.Text.Trim();

            if (CheckIfProductNameAlreadyInUse(name))
            {
                m_UIControl.lbl_Error.Text = "This Name is already in use!";
                return;
            }

            ProductGet existingProduct = m_Product;

            ProductPost product = new ProductPost(existingProduct);

            product.ID             = int.Parse(m_UIControl.tf_ProductDetails_ProductID.Text.Trim());
            product.Barcode        = barcode;
            product.Name           = name;
            product.Description    = m_UIControl.tf_ProductDetails_Description.Text.Trim();
            product.Unit           = ProductUnit.GetUnitFromText(m_UIControl.cb_Unit.Text);
            product.RetailPrice    = int.Parse(m_UIControl.tf_ProductDetails_RetailPrice.Text.Trim());
            product.WholeSalePrice = int.Parse(m_UIControl.tf_ProductDetails_WholesalePrice.Text.Trim());
            product.Discount       = double.Parse(m_UIControl.tf_ProductDetails_Discount.Text.Trim());
            product.CGST           = double.Parse(m_UIControl.tf_ProductDetails_CGST.Text.Trim());
            product.SGST           = double.Parse(m_UIControl.tf_ProductDetails_SGST.Text.Trim());

            string categoryName = m_UIControl.cb_ProductDetails_Category.Text.Trim();

            product.CategoryID = DataService.GetCategoryDataController().GetByName(categoryName).ID;

            bool imageModified = false;

            if (m_UIControl.pictureBox_ProductImage.Tag != null)
            {
                product.ImagePath = m_UIControl.pictureBox_ProductImage.Tag.ToString();
                imageModified     = true;
            }

            m_Product = DataService.GetProductDataController().Put(product, imageModified);
            string message = (m_Product == null) ? "Failed to Update Product Details!" : "Product Details updated successfully!";

            MessageBox.Show(m_UIControl, message);

            // fire entry updated event
            Event_EntryUpdated e = new Event_EntryUpdated(DBEntityType.PRODUCT, m_Product.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }
        public void UpdateCustomer()
        {
            m_UIControl.lbl_customerErrorText.Text = string.Empty;

            if (!ValidateCustomerDetails())
            {
                return;
            }

            string name         = m_UIControl.tb_customerName.Text.Trim();
            string mobileNumber = m_UIControl.tb_customerMobileNumber.Text.Trim();

            if (CheckIfCustomerNameAlreadyExists(name))
            {
                m_UIControl.lbl_customerErrorText.Text = "Customer with the same Name already exists!";
                return;
            }

            if (CheckIfMobileNumberAlreadyExists(mobileNumber))
            {
                m_UIControl.lbl_customerErrorText.Text = "Customer with the same Mobile Number already exists!";
                return;
            }

            CustomerPost customerPost = new CustomerPost();

            customerPost.ID            = int.Parse(m_UIControl.tb_customerId.Text.Trim());
            customerPost.Name          = name;
            customerPost.MobileNumber  = mobileNumber;
            customerPost.Email         = m_UIControl.tb_customerEmail.Text.Trim();;
            customerPost.TotalAmount   = double.Parse(m_UIControl.tb_customerTotalPurchaseAmount.Text.Trim());
            customerPost.PendingAmount = double.Parse(m_UIControl.tb_customerPendingAmount.Text.Trim());

            m_Customer = DataService.GetCustomerDataController().Put(customerPost);
            if (m_Customer == null)
            {
                m_UIControl.DialogResult = DialogResult.No;
                return;
            }
            m_UIControl.DialogResult = DialogResult.Yes;
            ResetTextBoxes();

            // fire customer updated event
            Event_EntryUpdated e = new Event_EntryUpdated(DBEntityType.CUSTOMER, m_Customer.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }
コード例 #7
0
        private void btn_saveCategory_Click(object sender, EventArgs eventArgs)
        {
            if (!ValidateUI())
            {
                return;
            }

            lbl_CategoryError.Text = string.Empty;
            string name = tb_categoryName.Text.Trim();
            string desc = tb_categoryDescription.Text.Trim();

            var category = DataService.GetCategoryDataController().GetByName(name);

            if (category != null)
            {
                lbl_CategoryError.Text = "Category with same name already exists!";
                return;
            }
            CategoryPost categoryPost = new CategoryPost();

            categoryPost.Name        = name;
            categoryPost.Description = desc;

            m_Category = DataService.GetCategoryDataController().Post(categoryPost);
            if (m_Category == null)
            {
                Assert.Do("Failed to add category!");
                DialogResult = DialogResult.Cancel;
                return;
            }


            // broadcast new entry added event
            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.CATEGORY, m_Category.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
            MessageBox.Show("Category Added successfully!");

            ResetAll();

            if (!checkBox_AddAnotherCategory.Checked)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
        }
        public void SaveTransaction()
        {
            TransactionPost transactionPost = new TransactionPost
            {
                CustomerID          = m_TransactionSession.GetCustomer().ID,
                TransactionDateTime = DateTime.Now,
                TotalPrice          = double.Parse(m_TransactionSession.amountDue),
                TotalTax            = double.Parse(m_TransactionSession.totalTax)
            };
            string productIds      = string.Empty;
            string productQuantity = string.Empty;
            string buyingPrices    = string.Empty;
            string discounts       = string.Empty;

            foreach (var entry in m_TransactionSession.GetRowEntries())
            {
                var product = entry.Product;
                productIds      += product.ID + ",";
                productQuantity += entry.Quantity + ",";
                buyingPrices    += product.RetailPrice + ",";
                discounts       += product.Discount + ",";
            }

            //Removing last comma
            transactionPost.ProductIDs      = productIds.Substring(0, productIds.Length - 1);
            transactionPost.ProductQuantity = productQuantity.Substring(0, productQuantity.Length - 1);
            transactionPost.BuyingPrices    = buyingPrices.Substring(0, buyingPrices.Length - 1);
            transactionPost.Discounts       = discounts.Substring(0, discounts.Length - 1);

            var transaction = DataService.GetTransactionDataController().Post(transactionPost);

            UpdateCustomerDetails();
            UpdateStockDetails();

            // fire new transaction added event
            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.TRANSACTION, transaction.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }
        public VendorGet AddNewVendor()
        {
            if (!ValidateVendorDetails())
            {
                return(null);
            }

            VendorPost vendor = new VendorPost();

            vendor.CompanyName  = m_UIControl.tb_companyName.Text.Trim();
            vendor.Address      = m_UIControl.tb_address.Text.Trim();
            vendor.Email        = m_UIControl.tb_email.Text.Trim();
            vendor.MobileNumber = m_UIControl.tb_mobileNumber.Text.Trim();
            vendor.City         = m_UIControl.tb_city.Text.Trim();
            vendor.State        = m_UIControl.tb_state.Text.Trim();

            var vendorGet = DataService.GetVendorDataController().Post(vendor);

            if (vendorGet == null)
            {
                Assert.Do("Failed to add vendor");
                return(null);
            }

            MessageBox.Show("Vendor Added Successfully");
            ResetTextBoxes();

            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.VENDOR, vendorGet.ID);

            EventBroadcaster.Get().BroadcastEvent(e);

            if (!m_UIControl.checkBox_AddAnotherVendor.Checked)
            {
                m_UIControl.DialogResult = DialogResult.OK;
                m_UIControl.Close();
            }

            return(vendorGet);
        }
コード例 #10
0
        public void SaveCustomer()
        {
            m_UIControl.lbl_customerErrorText.Text = string.Empty;
            if (!ValidateCustomerDetails())
            {
                return;
            }

            CustomerPost customerPost = new CustomerPost();

            customerPost.Email         = m_UIControl.tb_customerEmail.Text.Trim();
            customerPost.Name          = m_UIControl.tb_CustomerName.Text.Trim();
            customerPost.MobileNumber  = m_UIControl.tb_customerMobile.Text.Trim();
            customerPost.PendingAmount = 0;
            m_Customer = DataService.GetCustomerDataController().Post(customerPost);

            m_UIControl.DialogResult = (m_Customer == null) ? DialogResult.No : DialogResult.Yes;

            // fire customer added event
            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.CUSTOMER, m_Customer.ID);

            EventBroadcaster.Get().BroadcastEvent(e);
        }
コード例 #11
0
 protected void RegisterEvent(EventType type)
 {
     EventBroadcaster.Get().RegisterListener(type, this);
 }
        public bool AddNewProduct()
        {
            var UI = m_UIControl;

            UI.DialogResult = DialogResult.None;

            UI.lbl_Error.Text = string.Empty;
            if (!ValidateProductDetails())
            {
                return(false);
            }

            string      categoryName = UI.cb_Category.Text.Trim();
            CategoryGet category     = DataService.GetCategoryDataController().GetByName(categoryName);

            int unit = UI.cb_Unit.SelectedIndex + 1;

            ProductPost productPost = new ProductPost();

            productPost.Name           = UI.tb_Name.Text.Trim();
            productPost.Barcode        = UI.tb_Barcode.Text.Trim();
            productPost.Description    = UI.tb_Description.Text.Trim();
            productPost.Unit           = unit;
            productPost.RetailPrice    = int.Parse(UI.tb_RetailPrice.Text.Trim());
            productPost.WholeSalePrice = int.Parse(UI.tb_WholeSalePrice.Text.Trim());
            productPost.CategoryID     = category.ID;
            productPost.CGST           = double.Parse(UI.tb_CGST.Text.Trim());
            productPost.SGST           = double.Parse(UI.tb_CGST.Text.Trim());
            productPost.Discount       = double.Parse(UI.tb_SGST.Text.Trim());

            productPost.ImagePath = GetImagePath();

            m_Product = DataService.GetProductDataController().Post(productPost);
            if (m_Product == null)
            {
                MessageBox.Show(UI, "Failed to Add Product!");
                return(false);
            }

            // post the Default details
            StockPost stock = new StockPost();

            stock.ProductID         = m_Product.ID;
            stock.AvailableQuantity = 0;
            stock.TotalQuantity     = 0;
            var stockPost = DataService.GetStockDataController().Post(stock);

            if (stockPost == null)
            {
                MessageBox.Show(UI, "Failed to Add Stock!");
                return(false);
            }

            // Broadcast NewProductAdded Event
            Event_NewEntryAdded e = new Event_NewEntryAdded(DBEntityType.PRODUCT, m_Product.ID);

            EventBroadcaster.Get().BroadcastEvent(e);

            MessageBox.Show(UI, "Product Added Successfully!");

            if (!m_UIControl.checkBox_AddAnotherProduct.Checked)
            {
                UI.DialogResult = DialogResult.OK;
                UI.Close();
            }

            return(true);
        }