Beispiel #1
0
        private void deleteLot()
        {
            var          deleteLot = SelectedLot;
            DialogResult dr        = MessageBox.Show("Сигурни ли сте, че искате да изтриете избраната партида?", "Потвърждение", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                //delete row from database or datagridview...
                using (var db = new WereDesktopEntities())
                {
                    if (deleteLot != null)
                    {
                        foreach (var docRow in db.DocumentRow.Where(row => row.LotID == deleteLot.ID))
                        {
                            db.DocumentRow.Remove(docRow);
                        }
                        db.SaveChanges();

                        deleteLot.DocumentRow = null;

                        db.Lot.Attach(deleteLot);
                        db.Lot.Remove(deleteLot);
                        db.SaveChanges();

                        updateScreen(db);
                    }
                }
            }
            else if (dr == DialogResult.No)
            {
                //Nothing to do
            }
        }
        private void deleteDocument()
        {
            var documentToDelete = SelectedDocument;

            if (documentToDelete != null)
            {
                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete selected entry?", "Warning", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    using (var db = new WereDesktopEntities())
                    {
                        var rowsToDelete     = db.DocumentRow.Where(r => r.DocumentID == documentToDelete.ID).ToList();
                        var paymentsToDelete = db.DocumentPayment.Where(p => p.DocumentId == documentToDelete.ID).ToList();

                        foreach (DocumentPayment p in paymentsToDelete)
                        {
                            db.DocumentPayment.Attach(p);
                            db.DocumentPayment.Remove(p);
                            db.SaveChanges();
                        }

                        foreach (DocumentRow r in rowsToDelete)
                        {
                            using (var dbForLotUpdate = new WereDesktopEntities())
                            {
                                Lot lotToUpdate = new Lot();
                                var lots        = dbForLotUpdate.Lot.Where(l => l.ID == r.LotID).ToList();
                                foreach (Lot lot in lots)
                                {
                                    lotToUpdate = lot;
                                }
                                lotToUpdate.Quantity += r.Quantity;

                                dbForLotUpdate.Lot.AddOrUpdate(lotToUpdate);
                                dbForLotUpdate.SaveChanges();

                                db.DocumentRow.Attach(r);
                                db.DocumentRow.Remove(r);
                                db.SaveChanges();
                            }
                        }
                        using (var bd = new WereDesktopEntities())
                        {
                            var docs = bd.Document.Where(d => d.ID == documentToDelete.ID).ToList();
                            foreach (Document d in docs)
                            {
                                bd.Document.Attach(d);
                                bd.Document.Remove(d);
                                bd.SaveChanges();
                            }
                        }
                    }
                    using (var db = new WereDesktopEntities())
                    {
                        updateScreen(db);
                    }
                }
            }
        }
        private void addDocumentButton_Click(object sender, EventArgs e)
        {
            try
            {
                decimal input = decimal.Parse(inCashET.Text);
                if (input >= sum)
                {
                    using (var db = new WereDesktopEntities())
                    {
                        Document document = new Document();
                        Guid     id       = Guid.NewGuid();

                        document.ID             = id.ToString();
                        document.SourceID       = SelectedContragent.SourceContragentID;
                        document.DestinationID  = SelectedContragent.contragent.ID;
                        document.DocumentNumber = GenerateDocumentNumber.generateDocumentNumber();
                        document.Date           = DateTime.Now;

                        db.Document.AddOrUpdate(document);

                        db.SaveChanges();

                        foreach (DocumentRowCart dr in documentRowsList)
                        {
                            DocumentRow docRow = new DocumentRow();
                            docRow.ID         = dr.ID;
                            docRow.ProductID  = dr.ProductID;
                            docRow.LotID      = dr.LotID;
                            docRow.Quantity   = dr.Quantity;
                            docRow.Sum        = dr.Sum;
                            docRow.DocumentID = document.ID;

                            db.DocumentRow.Add(docRow);

                            db.SaveChanges();
                        }

                        DocumentPayment dp = new DocumentPayment();
                        id = Guid.NewGuid();

                        dp.ID              = id.ToString();
                        dp.DocumentId      = document.ID;
                        dp.MethodOfPayment = "cash";
                        dp.Price           = sum;

                        db.DocumentPayment.Add(dp);

                        db.SaveChanges();

                        this.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void deleteContragent()
        {
            using (var db = new WereDesktopEntities())
            {
                var contragentToDelete = SelectedContragent;

                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete selected entry?", "Warning", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    if (contragentToDelete != null)
                    {
                        foreach (var doc in db.Document.Where(d => d.SourceID == contragentToDelete.ID || d.DestinationID == contragentToDelete.ID))
                        {
                            foreach (var payment in db.DocumentPayment.Where(p => p.DocumentId == doc.ID).ToList())
                            {
                                db.DocumentPayment.Remove(payment);
                            }


                            foreach (var row in db.DocumentRow.Where(r => r.DocumentID == doc.ID).ToList())
                            {
                                using (var dbForLotUpdate = new WereDesktopEntities())
                                {
                                    Lot lotToUpdate = new Lot();
                                    var lots        = dbForLotUpdate.Lot.Where(l => l.ID == row.LotID).ToList();
                                    foreach (Lot lot in lots)
                                    {
                                        lotToUpdate = lot;
                                    }
                                    lotToUpdate.Quantity += row.Quantity;

                                    dbForLotUpdate.Lot.AddOrUpdate(lotToUpdate);
                                    dbForLotUpdate.SaveChanges();
                                }
                                db.DocumentRow.Remove(row);
                            }


                            doc.DocumentPayment = null;
                            doc.DocumentRow     = null;

                            db.Document.Remove(doc);
                        }
                        db.SaveChanges();
                        contragentToDelete.Document  = null;
                        contragentToDelete.Document1 = null;

                        db.Contragent.Attach(contragentToDelete);
                        db.Contragent.Remove(contragentToDelete);
                        db.SaveChanges();
                        updateScreen(db);
                    }
                }
            }
        }
Beispiel #5
0
        private void deleteProduct()
        {
            var deleteProduct = SelectedProduct;

            DialogResult dr = MessageBox.Show("Сигурни ли сте, че искате да изтриете избрания продукт", "Потвърждение", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                //delete row from database or datagridview...
                using (var db = new WereDesktopEntities())
                {
                    if (deleteProduct != null)
                    {
                        foreach (var docRow in db.DocumentRow.Where(row => row.ProductID == deleteProduct.ID))
                        {
                            db.DocumentRow.Remove(docRow);
                        }
                        db.SaveChanges();

                        foreach (var lot in db.Lot.Where(l => l.ProductID == deleteProduct.ID).ToList())
                        {
                            db.Lot.Remove(lot);
                        }
                        db.SaveChanges();

                        foreach (var barcode in db.Barcode.Where(b => b.ProductID == deleteProduct.ID).ToList())
                        {
                            db.Barcode.Remove(barcode);
                        }
                        db.SaveChanges();



                        deleteProduct.DocumentRow = null;
                        deleteProduct.Lot         = null;
                        deleteProduct.Barcode     = null;

                        db.Product.Attach(deleteProduct);
                        db.Product.Remove(deleteProduct);
                        db.SaveChanges();

                        updateScreen(db);
                    }
                }
            }
            else if (dr == DialogResult.No)
            {
                //Nothing to do
            }
        }
        private void deleteRowTab4()
        {
            var          deleteRow = SelectedRowTab1;
            DialogResult dr        = MessageBox.Show("Сигурни ли сте, че искате да изтриете избраната партида?", "Потвърждение", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                //delete row from database or datagridview...


                if (deleteRow != null)
                {
                    var lotID = deleteRow.LotID;
                    using (var db = new WereDesktopEntities())
                    {
                        var lots = db.Lot.Where(l => l.ID == lotID).ToList();
                        foreach (Lot lot in lots)
                        {
                            lot.Quantity = lot.Quantity + deleteRow.Quantity;
                            db.Lot.AddOrUpdate(lot);
                            db.SaveChanges();
                        }
                    }
                    tab4DocumentRowsList.Remove(deleteRow);

                    changeLabelValues();
                    documentRowCartBindingSource3.DataSource = tab4DocumentRowsList;
                    documentRowsTab4GridControl.RefreshDataSource();
                }
            }
            else if (dr == DialogResult.No)
            {
                //Nothing to do
            }
        }
Beispiel #7
0
        private void AddDocumentRowButton_Click(object sender, EventArgs e)
        {
            double quantity = double.Parse(quantityET.Text);

            var productID = productTreeListLookUpEdit.EditValue.ToString();
            var lotID     = lotTreeListLookUpEdit.EditValue.ToString();

            using (var db = new WereDesktopEntities())
            {
                var lots = db.Lot.Where(l => l.ID == lotID).ToList();
                foreach (Lot lot in lots)
                {
                    DocumentRow dr = new DocumentRow();
                    Guid        id = Guid.NewGuid();

                    dr.ID         = id.ToString();
                    dr.ProductID  = productID;
                    dr.LotID      = lotID;
                    dr.Quantity   = quantity;
                    dr.Sum        = Convert.ToDecimal(quantity) * lot.Product.Price;
                    dr.DocumentID = DocumentID;

                    lot.Quantity = lot.Quantity - quantity;

                    db.DocumentRow.AddOrUpdate(dr);
                    db.Lot.AddOrUpdate(lot);

                    db.SaveChanges();
                    this.Close();
                }
            }
        }
        private void ValidateForm()
        {
            bool bValidName   = ValidateProductName();
            bool bValidPrice  = ValidateProductPrice();
            bool bValidNumber = ValidateProductNumber();

            if (bValidName && bValidPrice && bValidNumber)
            {
                var name = productNameET.Text;

                var price = Convert.ToDecimal(productPriceET.Text);

                var productNumber = productNumberET.Text;

                using (var db = new WereDesktopEntities())
                {
                    Product prod = new Product();
                    Guid    id   = Guid.NewGuid();

                    prod.ID            = id.ToString();
                    prod.Name          = name;
                    prod.ProductNumber = productNumber;
                    prod.Price         = price;
                    prod.Quantity      = 0;


                    db.Product.AddOrUpdate(prod);

                    db.SaveChanges();

                    this.Close();
                }
            }
        }
Beispiel #9
0
        private void deleteBarcode()
        {
            var          deleteBarcode = SelectedBarcode;
            DialogResult dr            = MessageBox.Show("Сигурни ли сте, че искате да изтриете избрания баркод?", "Потвърждение", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                //delete row from database or datagridview...
                using (var db = new WereDesktopEntities())
                {
                    if (deleteBarcode != null)
                    {
                        db.Barcode.Attach(deleteBarcode);
                        db.Barcode.Remove(deleteBarcode);
                        db.SaveChanges();

                        updateScreen(db);
                    }
                }
            }
            else if (dr == DialogResult.No)
            {
                //Nothing to do
            }
        }
        private void ValidateForm()
        {
            bool bValidBarcode = ValidateBarcode();

            if (bValidBarcode)
            {
                if (Barcode.ID != null)
                {
                    var barcodeNumber = barcodeNumberET.Text;

                    using (var db = new WereDesktopEntities())
                    {
                        Barcode barcode = new Barcode();

                        barcode.ID            = Barcode.ID;
                        barcode.ProductID     = Barcode.ProductID;
                        barcode.BarcodeNumber = barcodeNumber;

                        db.Barcode.AddOrUpdate(barcode);

                        db.SaveChanges();
                        this.Close();
                    }
                }
            }
        }
        private void AddDocumentRowButton_Click(object sender, EventArgs e)
        {
            double quantity = double.Parse(quantityET.Text);

            var productID = productTreeListLookUpEdit.EditValue.ToString();
            var lotID     = lotTreeListLookUpEdit.EditValue.ToString();

            using (var db = new WereDesktopEntities())
            {
                var lots = db.Lot.Where(l => l.ID == lotID).ToList();
                foreach (Lot lot in lots)
                {
                    var products = db.Product.Where(p => p.ID == productID).ToList();
                    foreach (Product product in products)
                    {
                        if (lot.ID.Equals(lotID))
                        {
                            quantity = Convert.ToDouble(quantityET.Text);
                        }
                        DocumentRowCart dr = new DocumentRowCart();
                        Guid            id = Guid.NewGuid();

                        dr.ID          = id.ToString();
                        dr.ProductID   = productID;
                        dr.ProductName = product.Name;
                        dr.LotID       = lotID;
                        dr.LotNumber   = lot.LotNumber;
                        dr.Quantity    = quantity;
                        dr.Sum         = Convert.ToDecimal(quantity) * lot.Product.Price;
                        var lot1 = lotTreeListLookUpEdit.GetSelectedDataRow() as Lot;


                        db.SaveChanges();

                        lot.Quantity = lot.Quantity - quantity;


                        db.Lot.AddOrUpdate(lot);

                        db.SaveChanges();

                        documentRowsList.Add(dr);
                        this.Close();
                    }
                }
            }
        }
        private void addDocumentToDatabaseToBankAccount(List <Classes.DocumentRowCart> list, decimal sum)
        {
            using (var db = new WereDesktopEntities())
            {
                Document document = new Document();
                Guid     id       = Guid.NewGuid();

                document.ID             = id.ToString();
                document.SourceID       = SelectedContragent.SourceContragentID;
                document.DestinationID  = SelectedContragent.contragent.ID;
                document.DocumentNumber = GenerateDocumentNumber.generateDocumentNumber();
                document.Date           = DateTime.Now;

                db.Document.AddOrUpdate(document);

                db.SaveChanges();

                foreach (DocumentRowCart dr in list)
                {
                    DocumentRow docRow = new DocumentRow();
                    docRow.ID         = dr.ID;
                    docRow.ProductID  = dr.ProductID;
                    docRow.LotID      = dr.LotID;
                    docRow.Quantity   = dr.Quantity;
                    docRow.Sum        = dr.Sum;
                    docRow.DocumentID = document.ID;

                    db.DocumentRow.Add(docRow);

                    db.SaveChanges();
                }

                DocumentPayment dp = new DocumentPayment();
                id = Guid.NewGuid();

                dp.ID              = id.ToString();
                dp.DocumentId      = document.ID;
                dp.MethodOfPayment = "bank account";
                dp.Price           = sum;

                db.DocumentPayment.Add(dp);

                db.SaveChanges();
            }
        }
Beispiel #13
0
        private void editDocumentBtn_Click(object sender, EventArgs e)
        {
            document.DestinationID = editDocumentDestinationLookUpEdit.EditValue.ToString();
            document.SourceID      = editDocumentSourceLookUpEdit.EditValue.ToString();

            using (var db = new WereDesktopEntities())
            {
                db.Document.AddOrUpdate(document);
                db.SaveChanges();
            }
        }
Beispiel #14
0
        private void ValidateForm()
        {
            bool cValidName      = ValidateContragentName();
            bool cValidBulstat   = ValidateContragentBulstat();
            bool cValidVatNumber = ValidateContragentVatNumber();
            bool cValidCity      = ValidateContragentCity();
            bool cValidAdresss   = ValidateContragentAddress();
            bool cValidateMrp    = ValidateContragentMrp();
            bool cValidatePhone  = ValidateContragentPhoneNumber();

            if (cValidName && cValidBulstat && cValidVatNumber && cValidCity &&
                cValidAdresss && cValidateMrp && cValidatePhone)
            {
                var name = addContragentNameTE.Text;

                var bulstat = addContragentBulstatTE.Text;

                var vatNumber = addContragentVatNumberTE.Text;

                var city = addContragentCityTE.Text;

                var address = addContragentAddressTE.Text;

                var MRP = addContragentMrpTE.Text;

                var phoneNumber = addContragentPhoneNumberTE.Text;

                using (var db = new WereDesktopEntities())
                {
                    Contragent cont = new Contragent();
                    Guid       id   = Guid.NewGuid();

                    cont.ID          = id.ToString();
                    cont.Name        = name;
                    cont.Bulstat     = bulstat;
                    cont.VatNumber   = vatNumber;
                    cont.City        = city;
                    cont.Address     = address;
                    cont.Mrp         = MRP;
                    cont.PhoneNumber = phoneNumber;


                    db.Contragent.AddOrUpdate(cont);

                    db.SaveChanges();
                    this.Close();
                }
            }
        }
        private void deleteDocumentRow()
        {
            using (var db = new WereDesktopEntities())
            {
                var rowToDelete = SelectedDocumentRow;


                DialogResult dialogResult = MessageBox.Show("Are you sure you want to delete selected entry?", "Warning", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    if (rowToDelete != null)
                    {
                        using (var bd = new WereDesktopEntities())
                        {
                            Lot lotToUpdate = new Lot();
                            var lots        = bd.Lot.Where(l => l.ID == rowToDelete.LotID).ToList();
                            foreach (Lot lot in lots)
                            {
                                lotToUpdate = lot;
                            }

                            lotToUpdate.Quantity += rowToDelete.Quantity;
                            bd.Lot.AddOrUpdate(lotToUpdate);
                            bd.SaveChanges();
                        }


                        //var rows = db.DocumentRow.Where(r => r.ID == rowToDelete.LotID).ToList();
                        //foreach (DocumentRow row in rows)
                        //{
                        //rowToDelete = row;
                        //}

                        db.DocumentRow.Attach(rowToDelete);
                        db.DocumentRow.Remove(rowToDelete);
                        db.SaveChanges();
                        updateScreen(db);
                    }
                }
            }
        }
Beispiel #16
0
        private void editDocumentRowBtn_Click(object sender, EventArgs e)
        {
            var id = documentId;

            double quantity;

            double.TryParse(editDocumentRowQuantityTE.Text, out quantity);


            originalLot.Quantity = originalLot.Quantity + originalQuantity;
            using (var db = new WereDesktopEntities())
            {
                db.Lot.AddOrUpdate(originalLot);
                db.SaveChanges();
            }

            selectedRow.ProductID = editDocumentRowProductTreeListLookUpEdit.EditValue.ToString();
            selectedRow.LotID     = editDocumentRowLotTreeListLookUpEdit.EditValue.ToString();
            selectedRow.Quantity  = quantity;

            using (var db = new WereDesktopEntities())
            {
                var lotToUpdate = new Lot();

                var lots = db.Lot.Where(l => l.ID == selectedRow.LotID).ToList();
                foreach (Lot lot in lots)
                {
                    lotToUpdate = lot;
                }
                lotToUpdate.Quantity = lotToUpdate.Quantity - selectedRow.Quantity;

                selectedRow.Sum = Convert.ToDecimal(selectedRow.Quantity) * lotToUpdate.Product.Price;

                db.DocumentRow.AddOrUpdate(selectedRow);



                db.SaveChanges();
            }
        }
Beispiel #17
0
        private void editContragentEditBtn_Click(object sender, EventArgs e)
        {
            var id = contragent.ID;

            var name = editContragentNameTE.Text;

            var bulstat = editContragentBulstatTE.Text;

            var vatNumber = editContragentVatnumberTE.Text;

            var city = editContragentCityTE.Text;

            var address = editContragentAddressTE.Text;

            var MRP = editContragentMrpTE.Text;

            var phoneNumber = editContragentPhoneTE.Text;

            using (var db = new WereDesktopEntities())
            {
                Contragent cont = new Contragent();


                cont.ID          = id;
                cont.Name        = name;
                cont.Bulstat     = bulstat;
                cont.VatNumber   = vatNumber;
                cont.City        = city;
                cont.Address     = address;
                cont.Mrp         = MRP;
                cont.PhoneNumber = phoneNumber;


                db.Contragent.AddOrUpdate(cont);

                db.SaveChanges();
                this.Close();
            }
        }
Beispiel #18
0
        private void ValidateForm()
        {
            bool bValidQuantity = ValidateLotQuantity();
            bool bValidDate     = ValidateLotDate();
            bool bValidNumber   = ValidateLotNumber();

            if (bValidQuantity && bValidDate && bValidNumber)
            {
                if (Lot.ID != null)
                {
                    var id = Lot.ID;

                    double quantity = Convert.ToDouble(lotQuantityET.Text);

                    var date = DateTime.Parse(lotDateEdit.Text);

                    var lotNumber = lotNumberET.Text;

                    using (var db = new WereDesktopEntities())
                    {
                        Lot lot = new Lot();

                        lot.ID             = id.ToString();
                        lot.ProductID      = Lot.ProductID;
                        lot.Quantity       = quantity;
                        lot.ExpirationDate = date;
                        lot.LotNumber      = lotNumber;


                        db.Lot.AddOrUpdate(lot);

                        db.SaveChanges();
                        this.Close();
                    }
                }
            }
        }