Example #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            model.ItemName        = txtName.Text.Trim();
            model.ItemDescription = txtDescription.Text.Trim();

            decimal value;

            if (decimal.TryParse(txtStockPrice.Text, NumberStyles.Currency, new CultureInfo("si-LK").NumberFormat, out value))
            {
                model.ItemStockPrice = value;
            }
            if (decimal.TryParse(txtSellingPrice.Text, NumberStyles.Currency, new CultureInfo("si-LK").NumberFormat, out value))
            {
                model.ItemSellingPrice = value;
            }

            model.ItemAvailableQuantity = Convert.ToInt32(txtQuantity.Value);
            using (HarithmaSalesEntities db = new HarithmaSalesEntities())
            {
                if (model.ItemID == 0)
                {
                    db.Items.Add(model);
                }
                else
                {
                    db.Entry(model).State = EntityState.Modified;
                }
                db.SaveChanges();
            }
            Clear();
            Populate();
            lblStatus.Text = "Item Added";
        }
Example #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (HarithmaSalesEntities db = new HarithmaSalesEntities())
            {
                if (lblItemID.Text != "")
                {
                    discountModel.ItemID            = itemModel.ItemID;
                    discountModel.DiscountValue     = nudDiscount.Value;
                    discountModel.DiscountStartDate = dtpStartDate.Value;
                    discountModel.DiscountEndDate   = dtpEndDate.Value;
                    MessageBox.Show(dtpStartDate.Value.ToString());

                    db.Discounts.Add(discountModel);
                    db.SaveChanges();

                    itemModel.ItemDiscount    = nudDiscount.Value;
                    db.Entry(itemModel).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    lblStatus.Text = "Discount added.";

                    Reset();
                    Populate(itemModel.ItemID);
                }
                else
                {
                    lblStatus.BackColor.Equals(Color.Red);
                    lblStatus.Text = "Item not selected";
                }

                Reset();
                Populate(0);
            }
        }
        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (HarithmaSalesEntities db = new HarithmaSalesEntities())
            {
                if (lblItemID.Text != "")
                {
                    inventoryModel.ItemID       = itemModel.ItemID;
                    inventoryModel.StockPrice   = Decimal.Parse(txtStockPrice.Text);
                    inventoryModel.SellingPrice = Decimal.Parse(txtSellingPrice.Text);
                    inventoryModel.Quantity     = Convert.ToInt32(txtQuantity.Value);
                    inventoryModel.Remarks      = txtRemarks.Text.Trim();
                    db.Inventories.Add(inventoryModel);
                    db.SaveChanges();

                    itemModel.ItemAvailableQuantity = itemModel.ItemAvailableQuantity + inventoryModel.Quantity;
                    itemModel.ItemStockPrice        = inventoryModel.StockPrice;
                    itemModel.ItemSellingPrice      = inventoryModel.SellingPrice;
                    db.Entry(itemModel).State       = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();

                    lblStatus.Text = "Stock added.";

                    Reset();
                    Populate(itemModel.ItemID);
                }
                else
                {
                    lblStatus.BackColor.Equals(Color.Red);
                    lblStatus.Text = "Item not selected";
                }

                Reset();
                Populate(0);
            }
        }
Example #4
0
 void Populate()
 {
     dgvItem.AutoGenerateColumns = false;
     using (HarithmaSalesEntities db = new HarithmaSalesEntities())
     {
         dgvItem.DataSource = db.Items.ToList();
     }
 }
Example #5
0
 private void txtSearchName_TextChanged(object sender, EventArgs e)
 {
     dgvItem.AutoGenerateColumns = false;
     using (HarithmaSalesEntities db = new HarithmaSalesEntities())
     {
         dgvItem.DataSource = db.Items.Where(i => i.ItemName.Contains(txtSearchName.Text)).ToList();
     }
 }
Example #6
0
 void Search()
 {
     Clear();
     dgvItem.AutoGenerateColumns = false;
     using (HarithmaSalesEntities db = new HarithmaSalesEntities())
     {
         dgvItem.DataSource = db.Items.Where(i => i.ItemName.Contains(txtSearch.Text)).ToList();
     }
 }
Example #7
0
 private void dgvItem_DoubleClick(object sender, EventArgs e)
 {
     if (dgvItem.CurrentRow.Index != -1)
     {
         itemModel.ItemID = Convert.ToInt32(dgvItem.CurrentRow.Cells[0].Value);
         lblStatus.Text   = itemModel.ItemID.ToString();
         using (HarithmaSalesEntities db = new HarithmaSalesEntities())
         {
             itemModel      = db.Items.Where(x => x.ItemID == itemModel.ItemID).FirstOrDefault();
             lblItemID.Text = itemModel.ItemName;
         }
     }
 }
Example #8
0
 void Populate(int ItemID)
 {
     dgvItem.AutoGenerateColumns = false;
     using (HarithmaSalesEntities db = new HarithmaSalesEntities())
     {
         if (ItemID > 0)
         {
             dgvItem.DataSource = db.Items.Where(i => i.ItemID.Equals(ItemID)).ToList();
         }
         else
         {
             dgvItem.DataSource = db.Items.ToList();
         }
     }
 }
Example #9
0
 private void dgvItem_DoubleClick(object sender, EventArgs e)
 {
     if (dgvItem.CurrentRow.Index != -1)
     {
         model.ItemID = Convert.ToInt32(dgvItem.CurrentRow.Cells[0].Value);
         using (HarithmaSalesEntities db = new HarithmaSalesEntities())
         {
             model                = db.Items.Where(x => x.ItemID == model.ItemID).FirstOrDefault();
             txtName.Text         = model.ItemName;
             txtDescription.Text  = model.ItemDescription;
             txtStockPrice.Text   = model.ItemStockPrice.ToString();
             txtSellingPrice.Text = model.ItemSellingPrice.ToString();
             txtQuantity.Value    = model.ItemAvailableQuantity;
             btnAdd.Text          = "Edit";
             btnDelete.Enabled    = true;
         }
     }
 }
Example #10
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Delete " + model.ItemName + "?", "Delete Item", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         using (HarithmaSalesEntities db = new HarithmaSalesEntities())
         {
             var entry = db.Entry(model);
             if (entry.State == EntityState.Detached)
             {
                 db.Items.Attach(model);
             }
             db.Items.Remove(model);
             db.SaveChanges();
             Clear();
             Populate();
             lblStatus.Text = "Item Deleted";
         }
     }
 }