private void outputDocGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            using (var db = new PastryShopDbContext())
            {
                var senderGrid = (DataGridView)sender;

                if (senderGrid.Columns[e.ColumnIndex].Name == "show" &&
                    senderGrid.Columns[e.ColumnIndex] is DataGridViewButtonColumn &&
                    !senderGrid.Rows[e.RowIndex].IsNewRow)
                {
                    var docId     = int.Parse(senderGrid.Rows[e.RowIndex].Cells["id"].Value.ToString());
                    var outputDoc = db.OutputDocuments
                                    .Include("Lines.Dessert")
                                    .Include("Lines.OutputDocLineProducts.Product.ProductDetail")
                                    .FirstOrDefault(d => d.Id == docId);

                    if (outputDoc != null)
                    {
                        PdfMaker      pdfMaker = new PdfMaker();
                        DocumentModel docModel = DocumentModelMapper.CreateDocumentModel(outputDoc);
                        pdfMaker.CreatePdfDocumet(docModel);
                    }
                }
            }
            Cursor = Cursors.Default;
        }
Exemplo n.º 2
0
        private void createDocButton_Click(object sender, EventArgs e)
        {
            if (!this.GridViewIsFilled())
            {
                MessageBox.Show(this, "Задължителните полета не са попълнени!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            if (this.dessertDataGridView.RowCount < 2)
            {
                MessageBox.Show(this, "Таблицата за продукти е празна!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            var idsToQuantities   = new Dictionary <int, int>();
            OutputDocumentLine ol = new OutputDocumentLine();

            for (int i = 0; i < this.dessertDataGridView.RowCount - 1; i++)
            {
                var id       = int.Parse(this.dessertDataGridView.Rows[i].Cells["Product"].Value.ToString());
                var quantity = int.Parse(this.dessertDataGridView.Rows[i].Cells["Quantity"].Value.ToString());
                if (idsToQuantities.Keys.Contains(id))
                {
                    MessageBox.Show(this, "Има повтарящи се продукти", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
                idsToQuantities.Add(id, quantity);
            }

            var dlgResult = MessageBox.Show(this, "Сигурни ли сте, че искате да запишетe документа!", "",
                                            MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dlgResult == DialogResult.Yes)
            {
                try
                {
                    DocumentModel docModel = this.CreateDocumentModel(idsToQuantities);
                    PdfMaker      pdfMaker = new PdfMaker();
                    pdfMaker.CreatePdfDocumet(docModel);
                    this.dessertDataGridView.Rows.Clear();
                    this.Close();
                }
                catch (Exception ex)
                {
                    Cursor = Cursors.Default;
                    MessageBox.Show(ex.Message);
                }
            }
        }