Пример #1
0
        private void btnMakePay_Click(object sender, EventArgs e)
        {
            var total = Convert.ToDecimal(lblAmount.Text);

            if (CheckFullPayment() == 1 && total > 0)
            {
                int inserted = SalesRepo.MakeSales(Login.username, Convert.ToDecimal(lblAmount.Text), DateTime.UtcNow, Convert.ToDecimal(txtDiscount.Text), CheckPayMethod());
                if (inserted > 0)
                {
                    int salesId = getId();
                    int i;//Iterator
                    for (i = 0; i < demo.Count; i++)
                    {
                        int success = ProductSalesRepo.add(salesId, demo[i].id, demo[i].quantity, demo[i].unit_price, System.DateTime.UtcNow, demo[i].unit_price / demo[i].quantity);
                        int insert  = ProductRepo.MinusProducts(demo[i].id, Convert.ToInt32(demo[i].quantity));
                    }
                    MessageBox.Show(i + " different product(s) sold");

                    PrintDoc();
                    CartGrid.DataSource = null;
                    demo.Clear();
                    lblAmount.Text = "0.00";
                    newPrice       = 0.00M;
                }
            }
            else
            {
                MessageBox.Show("Please Make Full Payment Before Checking Out");
            }
        }
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.dgvProductdetails.SelectedRows.Count < 1)
            {
                MessageBox.Show("No row selected");
                return;
            }

            string appId = this.dgvProductdetails.CurrentRow.Cells["appid"].Value.ToString();
            string title = this.dgvProductdetails.CurrentRow.Cells["title"].Value.ToString();

            if (MessageBox.Show($"Do you want to delete {title}?", "Confirmation", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            SalesRepo.DeleteByProductId(appId);
            if (InventoryRepo.Delete(appId))
            {
                MessageBox.Show(title + " has been deleted successfully");
                this.PopulateGridView();
                this.dgvProductdetails.ClearSelection();
                this.dgvProductdetails.Refresh();
                this.ClearInputs();
            }
            else
            {
                MessageBox.Show("Product couldn't be deleted");
            }
        }
Пример #3
0
        public void Start()
        {
            this.dgv_sales.DoubleBuffered(true);
            this.repo         = new SalesRepo();
            this.productsRepo = new ProductsRepo();

            this.lbl_work_day.Text  = this.date_picker_work_day.Value.ToString("ddd") + " " + this.date_picker_work_day.Value.ToString("yyyy/M/d");
            this.WorkDay            = this.date_picker_work_day.Value.ToString("yyyyMMdd");
            this.lbl_day_total.Text = "0";
            this.timer.Interval     = 10;
            this.timer.Tick        += this.TimerTick;
            this.timer.Start();

            this.date_picker_work_day.Value = DateTime.Now.Date;

            this.viewWorkDaySales();
            this.dgv_sales.CellValueChanged += this.dgv_sales_CellValueChanged;

            using (CategoriesRepo categoriesRepo = new CategoriesRepo())
            {
                this.combo_category_name.DataSource = categoriesRepo.GetCategories();
            }

            this.combo_category_name.SelectedValueChanged += this.combo_category_name_SelectedValueChanged;
            this.combo_category_name_SelectedValueChanged(this.combo_category_name, EventArgs.Empty);
            this.combo_product_name.SelectedValueChanged += this.combo_product_name_SelectedValueChanged;
            this.combo_product_name_SelectedValueChanged(this.combo_product_name, EventArgs.Empty);
        }
Пример #4
0
        private void SalesReportForm_Load(object sender, EventArgs e)
        {
            List <Sales> reports = SalesRepo.ProductSaleList();

            if (reports.Count == 0)
            {
                return;
            }

            foreach (Sales s in reports)
            {
                this.chartMostSoldProduct.Series["Sales"].Points.AddXY(s.Title, Convert.ToInt32(s.Quantity));
            }

            reports = SalesRepo.ProductSaleList("benefit");
            foreach (Sales s in reports)
            {
                this.chartMostBenefitProduct.Series["Benefit"].Points.AddXY(s.Title, Convert.ToInt32(s.Benefit));
            }


            try
            {
                string todayBenefit = SalesRepo.TodaysBenefit();

                if (todayBenefit == null)
                {
                    this.lblTodayBenefit.Text = "0 Tk";
                }
                else
                {
                    this.lblTodayBenefit.Text = todayBenefit + " tk";
                }
            }
            catch
            {
                this.lblTodayBenefit.Text = "0 Tk";
            }

            try
            {
                string thisMonthBenefit = SalesRepo.CurrentMonthBenefit();

                if (thisMonthBenefit == null)
                {
                    this.lblThisMonthBenefit.Text = "0 Tk";
                }
                else
                {
                    this.lblThisMonthBenefit.Text = thisMonthBenefit + " tk";
                }
            }
            catch
            {
                this.lblThisMonthBenefit.Text = "0 Tk";
            }
        }
 // Update product quantity in Products table of all the cart product
 private void UpdateProductsTable()
 {
     foreach (var row in this.cartListItems)
     {
         double updatedQuantity = Convert.ToDouble(row.SubItems[4].Text) - Convert.ToDouble(row.SubItems[1].Text);
         this.FillEntity(updatedQuantity, row);
         InventoryRepo.UpdateProductQuantity(this.Product);
         SalesRepo.Save(this.Sale);
     }
 }
Пример #6
0
 private void ControlAccountUserSearch_TextChanged(object sender, EventArgs e)
 {
     try
     {
         this.dgvDate.DataSource = SalesRepo.LiveSearchUser(this.ControlAccountUserSearch.Text, this.dateTimePickerStartsFrom.Value.ToString("yyyy/MM/dd"), this.dtpReport.Value.ToString("yyyy/MM/dd"));
     }
     catch (Exception exception)
     {
         Console.WriteLine("Something went wrong when searching!" + exception.Message);
     }
 }
        // Fill the product entity
        private void FillEntity(double quantity, ListViewItem data)
        {
            string productAppId = data.SubItems[5].Text;

            this.Product.AppId    = productAppId;
            this.Product.Quantity = Convert.ToString(quantity);

            this.Sale.AppId      = SalesRepo.GetAppId();
            this.Sale.TotalPrice = Convert.ToDouble(data.SubItems[3].Text);
            this.Sale.Quantity   = Convert.ToDouble(data.SubItems[1].Text);
            this.Sale.ProductId  = productAppId;
        }
Пример #8
0
        private void dgvSales_KeyDown(object sender, KeyEventArgs e)
        {
            var source         = new BindingSource();
            int id             = Convert.ToInt32(this.dgvSales.CurrentRow.Cells[0].Value);
            int ProdId         = Convert.ToInt32(this.dgvSales.CurrentRow.Cells[1].Value);
            int quantityBought = Convert.ToInt32(this.dgvSales.CurrentRow.Cells[3].Value);
            int amountPaid     = Convert.ToInt32(this.dgvSales.CurrentRow.Cells[4].Value);

            decimal original_Price = Convert.ToInt32(this.dgvSales.CurrentRow.Cells[6].Value);


            if (e.KeyData == Keys.Delete)
            {
                if (demo.Any(x => x.quantity == 1 && x.id == id))
                {
                    //Reduce Total
                    demo.Where(w => w.id == id).ToList().ForEach(s => temp = temp - Convert.ToDecimal(s.OriginalPrice));
                    total.Text = temp.ToString();

                    //Remove That Record from ProductSales Table and grid
                    ProductSalesRepo PSR = new ProductSalesRepo(context);
                    PSR.DelRecordById(id);

                    var x = demo.Where(p => p.id == id).FirstOrDefault <JointSalesProd>();
                    demo.Remove(x);

                    //Update Sales table to reflect the price
                    int SalesId = Convert.ToInt32(txtSearchId.Text);
                    SalesRepo.UpdateSalesPrice(SalesId, temp);

                    //Update Product Table to add retured product
                    ProductRepo.AddProductQuantity(ProdId, 1);
                    source.DataSource   = demo;   //Bind Demo to datasource
                    dgvSales.DataSource = source; ///Bind demo to grid
                }

                else if (demo.Any(x => x.quantity > 1 && x.id == id))
                {
                    demo.Clear();
                    temp = 0.00M;
                    BindGrid();
                    ClearControls();
                    editPanel.Visible   = true;
                    ProductId.Text      = ProdId.ToString();
                    ProdSalesId.Text    = id.ToString();
                    OriginalPrice.Text  = original_Price.ToString();
                    QuantityBought.Text = quantityBought.ToString();
                    AmountPaid.Text     = amountPaid.ToString();
                }
            }
        }
Пример #9
0
        private void dateTimePickerStartsFrom_ValueChanged(object sender, EventArgs e)
        {
            this.dgvDate.AutoGenerateColumns = false;
            try
            {
                this.dgvDate.DataSource = SalesRepo.UserSalesByDate(this.dateTimePickerStartsFrom.Value.ToString("yyyy/MM/dd"), this.dtpReport.Value.ToString("yyyy/MM/dd"));
            }
            catch (Exception exception)
            {
                MessageBox.Show("Something went wrong!" + exception.Message);
            }

            this.dgvDate.ClearSelection();
            this.dgvDate.Refresh();
        }
Пример #10
0
        private void FillUserSalesDataGridView()
        {
            this.dgvDate.AutoGenerateColumns = false;

            try
            {
                this.dgvDate.DataSource = SalesRepo.UserSalesByDate(DateTime.Now.ToString("yyyy/MM/dd"), DateTime.Now.ToString("yyyy/MM/dd"));
            }
            catch (Exception exception)
            {
                MessageBox.Show("Something went wrong when loading data!" + exception.Message);
            }

            this.dgvDate.ClearSelection();
            this.dgvDate.Refresh();
        }
Пример #11
0
        private void btnMakeReturns_Click(object sender, EventArgs e)
        {
            ProductSalesRepo PSR = new ProductSalesRepo(context);
            var     source       = new BindingSource();
            int     x            = Convert.ToInt32(ProdSalesId.Text);
            int     y            = Convert.ToInt32(QuantityReturned.Text);
            int     z            = Convert.ToInt32(ProductId.Text);
            int     c            = Convert.ToInt32(QuantityReturned.Text);
            decimal aP           = Convert.ToDecimal(AmountPaid.Text);//Convert The amount paid label into decimal and store it in aP.

            //totally deleting sales record of a particular product if all that product is totally Returned.
            if (aP > 0)
            {
                ProductSalesRepo.UpdateQuantityandNewPrice(x, y, Convert.ToDecimal(AmountPaid.Text));
            }
            else if (aP == 0)
            {
                PSR.DelRecordById(x);
            }


            //Update Sales table to reflect the price
            int SalesId = Convert.ToInt32(txtSearchId.Text);

            SalesRepo.UpdateSalesPrice(SalesId, Convert.ToDecimal(total.Text));

            //Update Product Table to add retured product
            ProductRepo.AddProductQuantity(z, c);

            ClearControls();//Clear the editPanels Control
            if (MessageBox.Show("Done Editing?", "Ok to continue", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                var newSalesRecord = PSR.CallSalesById(x);
                demo.Clear();
                temp = 0.00M;
                BindGrid();
                editPanel.Visible = false;
            }
        }
 private void SaveSalesAmount(string scheduleId)
 {
     try
     {
         string routeId            = ScheduleRepo.GetRouteId(scheduleId);
         int    ticketPrice        = RouteRepo.GetFare(routeId);
         int    currentSalesAmount = SalesRepo.CurrentSalesAmount(MainControl.cashierId);
         if (currentSalesAmount == 0)
         {
             int amount = ticketPrice * MainControl.selectedSeatCount;
             SalesRepo.Insert(MainControl.cashierId, amount);
         }
         else
         {
             int updatedAmount = currentSalesAmount + (ticketPrice * MainControl.selectedSeatCount);
             SalesRepo.Update(MainControl.cashierId, updatedAmount);
         }
     }catch (Exception e)
     {
         MessageBox.Show("Error!" + e.Message);
     }
 }
Пример #13
0
 public SalesController()
 {
     _salesRepository = new SalesRepo();
 }