예제 #1
0
        private void AddItemsToStock()
        {
            using (var context = new MegaEntities())
            {
                foreach (var p in addedList)
                {
                    var itemInStock = context.Stocks.Find(p.ItemCode);
                    if (itemInStock == null)
                    {
                        itemInStock = new Stock()
                        {
                            ItemCode = p.ItemCode,
                            Quantity = p.AddedQuantity
                        };
                        context.Stocks.Add(itemInStock);
                    }
                    else
                    {
                        itemInStock.Quantity += p.AddedQuantity;
                    }
                    context.SaveChanges();
                }

                var purchasing = context.Purchases.Find(purchaseId);
                purchasing.IsLock = true;
                context.SaveChanges();
            }
        }
예제 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (isEdit)
            {
                if (editInd > 0)
                {
                    return;
                }
                dgvList.Rows[editInd].Cells[1].Value = cboItem.SelectedValue;
                dgvList.Rows[editInd].Cells[2].Value = cboItem.Text;
                dgvList.Rows[editInd].Cells[3].Value = txtUnitPrice.Text;
                dgvList.Rows[editInd].Cells[4].Value = txtQty.Text;
                isEdit  = false;
                editInd = -1;
                ClearItem();
                return;
            }

            using (var context = new MegaEntities())
            {
                var item = context.Items.Find(cboItem.SelectedValue.ToString());
                dgvList.Rows.Add("", item.Code, item.Description, txtUnitPrice.Text, txtQty.Text);
                GenerateRowNo();
                ClearItem();
            }
        }
예제 #3
0
 private void LoadSuppliers()
 {
     using (var context = new MegaEntities())
     {
         cboSupplier.DataSource    = context.Suppliers.Where(s => s.IsActive).ToList();
         cboSupplier.DisplayMember = "Description";
         cboSupplier.ValueMember   = "Id";
     }
 }
예제 #4
0
 private void LoadItems()
 {
     using (var context = new MegaEntities())
     {
         cboItem.DataSource    = context.Items.Where(i => i.IsActive).ToList();
         cboItem.DisplayMember = "Description";
         cboItem.ValueMember   = "Code";
     }
 }
예제 #5
0
 private void LoadPurchasers()
 {
     using (var context = new MegaEntities())
     {
         cboPurchaser.DataSource    = context.Employees.Where(i => i.IsActive).ToList();
         cboPurchaser.DisplayMember = "EmployeeNameKh";
         cboPurchaser.ValueMember   = "Code";
     }
 }
예제 #6
0
 private void LoadCategories()
 {
     using (var context = new MegaEntities())
     {
         cboCategory.DataSource    = context.Categories.Where(c => c.IsActive == true).ToList();
         cboCategory.DisplayMember = "Description";
         cboCategory.ValueMember   = "Id";
         cboCategory.Invalidate();
     }
 }
예제 #7
0
 private void UpdateItem()
 {
     using (var context = new MegaEntities())
     {
         var item = context.Items.Find(itemCode);
         item.Description  = txtDescription.Text;
         item.EnglishName  = txtEnglishName.Text;
         item.CategoryId   = Convert.ToInt32(cboCategory.SelectedValue);
         item.CurrentPrice = newPrice;
         context.SaveChanges();
     }
 }
예제 #8
0
 private void LoadItemList()
 {
     using (var context = new MegaEntities())
     {
         itemList = new List <PurchaseDetail>();
         var query = context.PurchaseDetails.Include("Item").Where(p => p.MasterCode == purchaseId).ToList();
         foreach (var item in query)
         {
             itemList.Add(item);
         }
     }
 }
예제 #9
0
 private void cboItem_SelectedIndexChanged(object sender, EventArgs e)
 {
     using (var context = new MegaEntities())
     {
         var item = context.Items.Find(cboItem.SelectedValue);
         if (item != null)
         {
             decimal currentPrice = 0;
             decimal.TryParse(item.CurrentPrice + "", out currentPrice);
             txtUnitPrice.Text = currentPrice.ToString();
         }
     }
 }
예제 #10
0
        private void frmPurchase_Load(object sender, EventArgs e)
        {
            this.CenterToParent();
            this.lblAdded.Visible          = false;
            this.lblSaved.Visible          = false;
            this.btnAddItemToStock.Enabled = false;
            this.LoadPurchasers();
            this.LoadItems();
            this.LoadBuyFrom();
            this.LoadSuppliers();
            this.ControlOrdering();
            this.cboItem.SelectedIndex         = -1;
            this.cboItem.SelectedIndexChanged += new EventHandler(cboItem_SelectedIndexChanged);

            if (viewFlag)
            {
                lblAdded.Visible = lblSaved.Visible = true;
                btnAdd.Enabled   = btnClear.Enabled = btnSave.Enabled = false;

                using (var context = new MegaEntities())
                {
                    var purchase = context.Purchases.Find(purchaseId);
                    dtpPurchaseDate.Value      = purchase.PurchaseDate;
                    cboPurchaser.SelectedValue = purchase.PurchaserCode;
                    cboSupplier.SelectedValue  = purchase.SupplierId;
                    txtInvoiceNo.Text          = purchase.InvoiceNo;
                    txtPRNO.Text            = purchase.PRNO;
                    cboBuyFrom.SelectedItem = purchase.BuyFrom;
                    if (purchase.IsLock)
                    {
                        btnAddItemToStock.Enabled = false;
                        lblAdded.Visible          = true;
                    }
                    else
                    {
                        btnAddItemToStock.Enabled = true;
                        lblAdded.Visible          = false;
                    }

                    var detail = purchase.PurchaseDetails.ToList();
                    foreach (var item in detail)
                    {
                        dgvList.Rows.Add("", item.ItemCode, item.Item.Description, item.UnitPrice, item.Quantity);
                    }

                    this.GenerateRowNo();
                }
            }
        }
예제 #11
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var purchase = new Purchase()
            {
                PurchaseDate  = dtpPurchaseDate.Value,
                PurchaserCode = cboPurchaser.SelectedValue.ToString(),
                SupplierId    = Convert.ToInt32(cboSupplier.SelectedValue),
                InvoiceNo     = txtInvoiceNo.Text,
                PRNO          = txtPRNO.Text,
                BuyFrom       = cboBuyFrom.SelectedItem.ToString(),
                IsLock        = false,
                ComputerCode  = MegaService.GetComputerCode(),
                ComputeTime   = MegaService.GetComputeTime()
            };

            using (var context = new MegaEntities())
            {
                purchase = context.Purchases.Add(purchase);
                context.SaveChanges();
                purchaseId = purchase.Id;
            }

            for (int i = 0; i < dgvList.Rows.Count; i++)
            {
                decimal up       = Convert.ToDecimal(dgvList.Rows[i].Cells[3].Value);
                int     qty      = Convert.ToInt32(dgvList.Rows[i].Cells[4].Value);
                string  itemCode = dgvList.Rows[i].Cells[1].Value.ToString();

                var purchaseDetail = new PurchaseDetail()
                {
                    MasterCode     = purchase.Id,
                    ItemCode       = itemCode,
                    UnitPrice      = up,
                    Quantity       = qty,
                    AddedQuantity  = 0,
                    RemainQuantity = qty,
                    Amount         = up * qty
                };

                using (var context = new MegaEntities())
                {
                    context.PurchaseDetails.Add(purchaseDetail);
                    context.SaveChanges();
                }
            }

            this.btnSave.Enabled           = false;
            this.btnAddItemToStock.Enabled = true;
        }
예제 #12
0
        private void LoadData()
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Items.ToList().Where(item => item.IsActive);
                foreach (var item in query)
                {
                    dgvList.Rows.Add((no++), item.Code, item.EnglishName, item.Description, item.Category.Description, item.CurrentPrice.ToString("C2"));
                }
            }
        }
예제 #13
0
        private void LoadItemPrice(string code)
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.ItemPricings.ToList().Where(p => p.ItemCode == code);
                foreach (var pricing in query)
                {
                    dgvList.Rows.Add((no++), pricing.NotedDate, pricing.UnitPrice.ToString("C2"));
                }
            }
        }
예제 #14
0
        private void LoadData()
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Categories.ToList().Where(c => c.IsActive);
                foreach (var category in query)
                {
                    dgvList.Rows.Add((no++), category.Id, category.Description);
                }
            }
        }
예제 #15
0
        private void LoadData()
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Suppliers.ToList().Where(s => s.IsActive);
                foreach (var supplier in query)
                {
                    dgvList.Rows.Add((no++), supplier.Id, supplier.Description, supplier.Phone);
                }
            }
        }
예제 #16
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Categories.ToList().Where(c => (c.IsActive == true) && c.Description.ToLower().StartsWith(txtSearch.Text.ToLower()));
                foreach (var category in query)
                {
                    dgvList.Rows.Add((no++), category.Id, category.Description);
                }
            }
        }
예제 #17
0
        private void LoadData()
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Positions.ToList().Where(p => p.IsActive);
                foreach (var position in query)
                {
                    dgvList.Rows.Add((no++), position.Id, position.Description);
                }
            }
        }
예제 #18
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            int    no      = 1;
            string content = txtSearch.Text.ToLower();

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Suppliers.ToList().Where(s => s.IsActive && (s.Description.ToLower().StartsWith(content)));
                foreach (var supplier in query)
                {
                    dgvList.Rows.Add((no++), supplier.Id, supplier.Description, supplier.Phone);
                }
            }
        }
예제 #19
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            int no = 1;

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var content = txtSearch.Text.ToLower();
                var query   = context.Items.ToList().Where(i => (i.Code.ToLower().StartsWith(content) || i.EnglishName.ToLower().StartsWith(content) || i.Description.StartsWith(txtSearch.Text) || i.Category.Description.StartsWith(content)) && (i.IsActive));
                foreach (var item in query)
                {
                    dgvList.Rows.Add((no++), item.Code, item.EnglishName, item.Description, item.Category.Description, item.CurrentPrice.ToString("C2"));
                }
            }
        }
예제 #20
0
        private void txtSearch_TextChanged_1(object sender, EventArgs e)
        {
            int no = 1;

            this.dgvList.Rows.Clear();
            string content = txtSearch.Text.ToLower();

            using (var context = new MegaEntities())
            {
                var query = context.Positions.ToList().Where(p => p.Description.ToLower().StartsWith(content) && (p.IsActive == true));
                foreach (var position in query)
                {
                    dgvList.Rows.Add((no++), position.Id, position.Description);
                }
            }
        }
예제 #21
0
        private void txtSearch_TextChanged(object sender, EventArgs e)
        {
            int    no      = 1;
            string content = txtSearch.Text.ToLower();

            this.dgvList.Rows.Clear();

            using (var context = new MegaEntities())
            {
                var query = context.Projects.ToList().Where(p => p.IsActive && (p.Description.ToLower().StartsWith(content) || p.Location.ToLower().StartsWith(content)));
                foreach (var project in query)
                {
                    dgvList.Rows.Add((no++), project.Id, project.Description, project.Location);
                }
            }
        }
예제 #22
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var position = new Position()
            {
                Description = txtPositionName.Text,
                Remark      = txtRemark.Text,
                IsActive    = true
            };

            using (var context = new MegaEntities())
            {
                position = context.Positions.Add(position);
                context.SaveChanges();
            }

            dgvList.Rows.Add((dgvList.Rows.Count + 1), position.Id, position.Description);
        }
예제 #23
0
        private void AddNewItem()
        {
            var item = new Item()
            {
                Code         = txtCode.Text,
                EnglishName  = txtEnglishName.Text,
                Description  = txtDescription.Text,
                CategoryId   = Convert.ToInt32(cboCategory.SelectedValue),
                CurrentPrice = newPrice,
                IsActive     = true
            };

            using (var context = new MegaEntities())
            {
                context.Items.Add(item);
                context.SaveChanges();
            }
        }
예제 #24
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var supplier = new Supplier()
            {
                Description = txtSupplierName.Text,
                Phone       = txtPhone.Text,
                Remark      = txtRemark.Text,
                IsActive    = true
            };

            using (var context = new MegaEntities())
            {
                supplier = context.Suppliers.Add(supplier);
                context.SaveChanges();
            }

            this.Clear();
            this.dgvList.Rows.Add((dgvList.Rows.Count + 1), supplier.Id, supplier.Description, supplier.Phone);
        }
예제 #25
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var project = new Project()
            {
                Description = txtProjectName.Text,
                Location    = txtLocation.Text,
                Remark      = txtRemark.Text,
                IsActive    = true
            };

            using (var context = new MegaEntities())
            {
                project = context.Projects.Add(project);
                context.SaveChanges();
            }

            this.Clear();
            this.dgvList.Rows.Add((dgvList.Rows.Count + 1), project.Id, project.Description, project.Location);
        }
예제 #26
0
 private void frmAddItemToStock_Load(object sender, EventArgs e)
 {
     this.CenterToParent();
     this.LoadItemList();
     this.RefreshAllItems();
     this.lblSaved.Visible = false;
     using (var context = new MegaEntities())
     {
         var purchasing = context.Purchases.Find(purchaseId);
         if (purchasing.IsLock)
         {
             lblSaved.Visible          = true;
             btnSave.Enabled           = false;
             lblQty.Visible            = txtQty.Visible = false;
             btnSingleBackward.Visible = btnSingleForward.Visible = false;
             btnMultiBackward.Visible  = btnMultiForward.Visible = false;
         }
     }
 }
예제 #27
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            using (var context = new MegaEntities())
            {
                foreach (var pd in addedList)
                {
                    var p = context.PurchaseDetails.Find(pd.MasterCode, pd.ItemCode);
                    p.AddedQuantity  = pd.AddedQuantity;
                    p.RemainQuantity = pd.RemainQuantity;
                }
                context.SaveChanges();
            }

            AddItemsToStock();
            lblSaved.Visible          = true;
            btnSave.Enabled           = false;
            lblQty.Visible            = txtQty.Visible = false;
            btnSingleBackward.Visible = btnSingleForward.Visible = false;
            btnMultiBackward.Visible  = btnMultiForward.Visible = false;
        }
예제 #28
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvList.SelectedRows.Count > 0)
            {
                var          itemCode = dgvList.CurrentRow.Cells[1].Value.ToString();
                DialogResult action   = MessageBox.Show("Delete item \"" + itemCode + "\" ?", "Items", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (action == DialogResult.Yes)
                {
                    using (var context = new MegaEntities())
                    {
                        var item = context.Items.Find(itemCode);
                        item.IsActive = false;
                        context.SaveChanges();
                    }

                    this.LoadData();
                }
            }
        }
예제 #29
0
        private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int colInd = dgvList.CurrentCell.ColumnIndex;

            if (dgvList.Columns[colInd].HeaderText == "Delete")
            {
                DialogResult action = MessageBox.Show("Delete selected row?", "Position", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (action == DialogResult.Yes)
                {
                    var positionCode = Convert.ToInt32(dgvList.CurrentRow.Cells[1].Value);
                    using (var context = new MegaEntities())
                    {
                        var position = context.Positions.Find(positionCode);
                        position.IsActive = false;
                        context.SaveChanges();
                    }

                    dgvList.Rows.RemoveAt(dgvList.CurrentRow.Index);
                }
            }
        }
예제 #30
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dgvList.SelectedRows.Count > 0)
            {
                DialogResult action = MessageBox.Show("Delete selected row?", "Supplier", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (action != DialogResult.Yes)
                {
                    return;
                }

                int id = Convert.ToInt32(dgvList.CurrentRow.Cells[1].Value);
                using (var context = new MegaEntities())
                {
                    var supplier = context.Suppliers.Find(id);
                    supplier.IsActive = false;
                    context.SaveChanges();
                }

                this.dgvList.Rows.RemoveAt(dgvList.CurrentRow.Index);
            }
        }