Пример #1
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            SaleDetail tempSaleDetail = (SaleDetail)dgv.Rows[dgv.CurrentRow.Index].Tag;

            sale.SaleDetails.Remove(tempSaleDetail);
            dgv.Rows.RemoveAt(dgv.CurrentRow.Index);
        }
Пример #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (cmbProductName.Text == "")
            {
                MessageBox.Show("Please select product name");
                return;
            }
            if (txtQuantity.Value == 0)
            {
                MessageBox.Show("Please enter quantity");
                return;
            }
            SaleDetail saleDetail = new SaleDetail();
            Product    product    = form1.data.products.Where(p => p.Name == cmbProductName.Text).FirstOrDefault();

            saleDetail.ProductId    = product.Id;
            saleDetail.Quantity     = int.Parse(txtQuantity.Text);
            saleDetail.CostPrice    = decimal.Parse(txtSellingPrice.Tag.ToString());
            saleDetail.SellingPrice = decimal.Parse(txtSellingPrice.Text);
            saleDetail.TotalPrice   = decimal.Parse(txtTotalPrice.Text);

            sale.SaleDetails.Add(saleDetail);

            dgv.Rows.Add(dgv.Rows.Count + 1,
                         cmbProductName.Text,
                         saleDetail.Quantity,
                         product.Unit,
                         saleDetail.SellingPrice,
                         saleDetail.TotalPrice
                         );

            dgv.Rows[dgv.Rows.Count - 1].Tag = saleDetail;

            cmbProductName.Text  = "";
            txtQuantity.Value    = 0;
            txtSellingPrice.Text = "";
            txtTotalPrice.Text   = "";
            lblRemain.Text       = "";
            lblUnit.Text         = "";


            foreach (SaleDetail sd in sale.SaleDetails)
            {
                totalAmount += sd.TotalPrice;
            }
            totalAmountPaid     = totalAmount;
            lblTotalAmount.Text = totalAmount.ToString();
            txtTotalAmount.Text = totalAmount.ToString();
            txtAmountPaid.Value = totalAmount;
            txtBalance.Text     = (totalAmount - totalAmountPaid).ToString();
        }